From cs at cskk.id.au Fri Nov 1 00:13:18 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 1 Nov 2019 15:13:18 +1100 Subject: What's the difference between running a script under command box and interpreter? In-Reply-To: <68894b06-edfe-4b10-86f8-ab62005960a1@googlegroups.com> References: <68894b06-edfe-4b10-86f8-ab62005960a1@googlegroups.com> Message-ID: <20191101041318.GA73386@cskk.homeip.net> On 31Oct2019 20:44, Jach Fong wrote: >The script test.py is something like this: >-------test.py >from pyeds import fsm >... >... >class Rule_Parse: > def __init__(self): > ... > self.current_char = '' >... >... >def main(input_str): > for c in input_str: > ... > rule.current_char = c > ... > >if __name__ == '__main__': > input_str = '(NNS(acoustics) & RB(not)) | JJ(muted)' > rule = Rule_Parse() > main(input_str) > ... > >----------- >The test.py can run correctly under command box: >D:\Works\Python\pyeds-master\src>py test.py > >but fails when running under interpreter: >D:\Works\Python\pyeds-master\src>py >Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32 >Type "help", "copyright", "credits" or "license" for more information. >>>> from test import * >>>> input_str = "(NNS(acoustics) & RB(not)) | JJ(muted)" >>>> rule = Rule_Parse() >>>> main(input_str) >Traceback (most recent call last): > File "", line 1, in > File "D:\Works\Python\pyeds-master\src\test.py", line 229, in main > rule.current_char = c >NameError: name 'rule' is not defined >>>> > >I did check the globals using dir() and the 'rule' is there, no doubt. It matters how you checked this. This isn't apparent. >I also tried "py -m pdb test.py" and step through it, no problem too. This: py test.py and this: py -m pdb test both run test.py with __name__ set to "__main__" to indicate that test.py is the main programme. When you "import test", the module's __name__ is from the import ("test") i.e. not the main programme. The bottom of your module has an if statement whose body only runs when this is the main programme. The core issue is that the global "rule" is _only_ defined inside that if statement. You might set it unconditionally to None at the start of the file, but that would only change the failure mode. You might set it unconditionally to Rule_Parse() at the top of the file but that pointlessly instantiates an instance of Rule_Parse which might never be needed (maybe that is cheap, but many other classes are not). The basic intent of an import is to define various classes and other names, but _not_, generally, to create class instances and do significant work. This is really an example illustrating one reason why global variables are considered things to avoid almost all of the time. Had main() required "rule" as a parameter then it would not have been possible to call it without at least providing a rule. The same applies with most other functions: if they all require their external state via parameters then you can't miss things out. (You can, of course, always pass incorrect values, but that is usually easier to debug.) Avoid globals; they are usually a source of bugs. Cheers, Cameron Simpson From jfong at ms4.hinet.net Fri Nov 1 01:03:28 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Thu, 31 Oct 2019 22:03:28 -0700 (PDT) Subject: What's the difference between running a script under command box and interpreter? In-Reply-To: References: <68894b06-edfe-4b10-86f8-ab62005960a1@googlegroups.com> <20191101041318.GA73386@cskk.homeip.net> Message-ID: Cameron Simpson? 2019?11?1???? UTC+8??12?13?45???? > On 31Oct2019 20:44, Jach Fong wrote: > >The script test.py is something like this: > >-------test.py > >from pyeds import fsm > >... > >... > >class Rule_Parse: > > def __init__(self): > > ... > > self.current_char = '' > >... > >... > >def main(input_str): > > for c in input_str: > > ... > > rule.current_char = c > > ... > > > >if __name__ == '__main__': > > input_str = '(NNS(acoustics) & RB(not)) | JJ(muted)' > > rule = Rule_Parse() > > main(input_str) > > ... > > > >----------- > >The test.py can run correctly under command box: > >D:\Works\Python\pyeds-master\src>py test.py > > > >but fails when running under interpreter: > >D:\Works\Python\pyeds-master\src>py > >Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32 > >Type "help", "copyright", "credits" or "license" for more information. > >>>> from test import * > >>>> input_str = "(NNS(acoustics) & RB(not)) | JJ(muted)" > >>>> rule = Rule_Parse() > >>>> main(input_str) > >Traceback (most recent call last): > > File "", line 1, in > > File "D:\Works\Python\pyeds-master\src\test.py", line 229, in main > > rule.current_char = c > >NameError: name 'rule' is not defined > >>>> > > > >I did check the globals using dir() and the 'rule' is there, no doubt. > > It matters how you checked this. This isn't apparent. > > >I also tried "py -m pdb test.py" and step through it, no problem too. > > This: > py test.py > and this: > py -m pdb test > > both run test.py with __name__ set to "__main__" to indicate that > test.py is the main programme. > > When you "import test", the module's __name__ is from the import > ("test") i.e. not the main programme. > > The bottom of your module has an if statement whose body only runs when > this is the main programme. > > The core issue is that the global "rule" is _only_ defined inside that > if statement. > > You might set it unconditionally to None at the start of the file, but > that would only change the failure mode. > > You might set it unconditionally to Rule_Parse() at the top of the file > but that pointlessly instantiates an instance of Rule_Parse which might > never be needed (maybe that is cheap, but many other classes are not). > The basic intent of an import is to define various classes and other > names, but _not_, generally, to create class instances and do > significant work. > > This is really an example illustrating one reason why global variables > are considered things to avoid almost all of the time. Had main() > required "rule" as a parameter then it would not have been possible to > call it without at least providing a rule. The same applies with most > other functions: if they all require their external state via parameters > then you can't miss things out. (You can, of course, always pass > incorrect values, but that is usually easier to debug.) > > Avoid globals; they are usually a source of bugs. > > Cheers, > Cameron Simpson Yes, the 'if' body is not executed when I import test.py under interpreter, that's why I manually execute them there. What puzzles me is that the globals() has a 'rule' object in both cases. Why this one doesn't work? --Jach From python at mrabarnett.plus.com Fri Nov 1 00:47:51 2019 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 1 Nov 2019 04:47:51 +0000 Subject: Trouble trying to get started with pygame In-Reply-To: References: Message-ID: On 2019-11-01 03:47, originallmoney at gmail.com wrote: > It's been years since I've done anything with Python, and it wasn't a language I was terribly familiar with even then. I'm using Python 3.8 on my Windows 7 laptop. Python itself works so far as I can tell. I can get it to import pip without problems, but, when I try to get going with pygame, I hit a roadblock. > > I have pygame 1.9.6.tar.gz. Apparently, I don't have the means of unzipping it, yet, I think I've seen things on other forums suggesting that Python can do that for me. Is that true? > Actually, you do have the means: Python! But there's a simpler way. > I've been trying to use "pip install" (Written just like that, minus the quotes, of course), yet, it tells me that's a syntax error. > > Is there a way of inputting this that I'm not aware of? I've seen various versions of people calling the command, with things like "pip.install" or "-m pip install -U pygame -user" or something like that, are THOSE what I should be trying or...am I completely off-base right now? > Those commands are for the Windows command prompt. > Any help would be appreciated, as I'm losing patience with it at the moment. > Go to Christoph Gohlke's site at: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame Download one of these "wheel" files: pygame?1.9.6?cp38?cp38?win_amd64.whl for 64-bit or: pygame?1.9.6?cp38?cp38?win32.whl for 32-bit At the Windows command prompt type: py -3.8 -m pip install "path/to/wheel" From PythonList at DancesWithMice.info Fri Nov 1 01:40:06 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Fri, 1 Nov 2019 18:40:06 +1300 Subject: Friday finking: TDD and EAFP Message-ID: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> Is the practice of TDD fundamentally, if not philosophically, somewhat contrary to Python's EAFP approach? TDD = Test-Driven Development EAFP = it's easier to ask forgiveness than permission * WebRefs as footnote The practice of TDD* is that one writes test routines to prove a unit of code, eg method or function; BEFORE actually writing said function. The rationale is that TDD encourages proper identification and consideration of the routine's specification, and attempts to ensure that exceptions and "edge-cases" are not quietly forgotten. (in a broad-brush, nut-shell) However, I quite possibly like yourself, come from a time-before - before TDD, and before Python. So, have had to not only learn these things, but sometimes, un-learn points and habits (if not vices). Accordingly, I came (quite unknowing of the term, or that there might be an alternative) from the world of LBYL* (look before you leap). In other words, before you do anything with some data, check that it is what you think it is. Whereas in Python we "try" by assuming everything is compos-mentis* and handle the "except" when things are not how we'd like. That adaptation was not too difficult. After all, aren't programmers an optimistic bunch - I mean, I *never* introduce bugs into *my* code! Do you? Which brings us to TDD. Here we assume the likelihood of bugs, as-if (cue: manic giggling); and code a bunch of tests first - in an attempt to prove that the code is up-to-spec. In encouraging my mind to think about testing the code, I find myself searching for edge-cases, and attempting to anticipate the unusual. Accordingly to the gospel of TDD: so far, so good. The 'problem' is, that it puts my mind onto LBYL-rails before the Python-coding train (of thought) has even left the station. It then seems natural to start putting a bunch of if-then-else's up-front and before the 'main line' of code. Does TDD bend your mind in this (apparently) non-Pythonic fashion? Have you developed an answer? (other than: "@dn is 'nuts'*", which is not worthy of debate) WebRefs: https://duckduckgo.com/?q=TDD&ia=web https://devblogs.microsoft.com/python/idiomatic-python-eafp-versus-lbyl/ https://docs.python.org/3/glossary.html#term-eafp but: https://mail.python.org/pipermail/python-dev/2014-March/133118.html https://docs.python.org/3/glossary.html#term-lbyl Latin/legal term "compos mentis" https://www.thefreedictionary.com/compos+mentis English slang term "nuts": https://www.thefreedictionary.com/nuts -- Regards, =dn From cs at cskk.id.au Fri Nov 1 05:28:15 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 1 Nov 2019 20:28:15 +1100 Subject: What's the difference between running a script under command box and interpreter? In-Reply-To: References: Message-ID: <20191101092815.GA98493@cskk.homeip.net> On 31Oct2019 22:03, Jach Fong wrote: >Cameron Simpson? 2019?11?1???? UTC+8??12?13?45???? >> On 31Oct2019 20:44, Jach Fong wrote: >> >The script test.py is something like this: >> >-------test.py >> >from pyeds import fsm >> >... >> >class Rule_Parse: >> > def __init__(self): >> > ... >> > self.current_char = '' >> >... >> >def main(input_str): >> > for c in input_str: >> > ... >> > rule.current_char = c >> > ... >> > >> >if __name__ == '__main__': >> > input_str = '(NNS(acoustics) & RB(not)) | JJ(muted)' >> > rule = Rule_Parse() >> > main(input_str) >> > ... >> > >> >----------- >> >The test.py can run correctly under command box: >> >D:\Works\Python\pyeds-master\src>py test.py >> > >> >but fails when running under interpreter: >> >D:\Works\Python\pyeds-master\src>py >> >Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32 >> >Type "help", "copyright", "credits" or "license" for more information. >> >>>> from test import * >> >>>> input_str = "(NNS(acoustics) & RB(not)) | JJ(muted)" >> >>>> rule = Rule_Parse() >> >>>> main(input_str) >> >Traceback (most recent call last): >> > File "", line 1, in >> > File "D:\Works\Python\pyeds-master\src\test.py", line 229, in main >> > rule.current_char = c >> >NameError: name 'rule' is not defined >> >>>> >> > >> >I did check the globals using dir() and the 'rule' is there, no doubt. >> >> It matters how you checked this. This isn't apparent. [...] >Yes, the 'if' body is not executed when I import test.py under >interpreter, that's why I manually execute them there. >What puzzles me is that the globals() has a 'rule' object in both >cases. Why this one doesn't work? I think I have misinterpreted what you've done. The globals are your current module's namespace, and functions defines in a module are bound to that module's namespace. Strip your test.py back. A lot. Try this: def main(): print(rule) Now, let's use that: Python 3.7.4 (default, Sep 28 2019, 13:34:38) [Clang 8.0.0 (clang-800.0.42.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import test >>> test.main() Traceback (most recent call last): File "", line 1, in File "/Users/cameron/tmp/d1/test.py", line 2, in main print(rule) NameError: name 'rule' is not defined What's happening here? When we call main it tries to print "rule" from its module's globals. The first time you call it that doesn't exist, and we get your error. Setting rule=1 in the interpreter's space doesn't help (the stuff below if from the same session continued from above): >>> rule=1 >>> test.main() Traceback (most recent call last): File "", line 1, in File "/Users/cameron/tmp/d1/test.py", line 2, in main print(rule) NameError: name 'rule' is not defined But if we define rule in the "test" module things improve: >>> test.rule=2 >>> test.main() 2 Importing main from test doesn't change where it looks for its globals: >>> from test import main as my_main >>> my_main() 2 That value (2) is still coming out of the test module. Cheers, Cameron Simpson From jfong at ms4.hinet.net Fri Nov 1 07:24:38 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Fri, 1 Nov 2019 04:24:38 -0700 (PDT) Subject: What's the difference between running a script under command box and interpreter? In-Reply-To: References: <20191101092815.GA98493@cskk.homeip.net> Message-ID: Cameron Simpson? 2019?11?1???? UTC+8??5?28?42???? > On 31Oct2019 22:03, Jach Fong wrote: > >Cameron Simpson? 2019?11?1???? UTC+8??12?13?45???? > >> On 31Oct2019 20:44, Jach Fong wrote: > >> >The script test.py is something like this: > >> >-------test.py > >> >from pyeds import fsm > >> >... > >> >class Rule_Parse: > >> > def __init__(self): > >> > ... > >> > self.current_char = '' > >> >... > >> >def main(input_str): > >> > for c in input_str: > >> > ... > >> > rule.current_char = c > >> > ... > >> > > >> >if __name__ == '__main__': > >> > input_str = '(NNS(acoustics) & RB(not)) | JJ(muted)' > >> > rule = Rule_Parse() > >> > main(input_str) > >> > ... > >> > > >> >----------- > >> >The test.py can run correctly under command box: > >> >D:\Works\Python\pyeds-master\src>py test.py > >> > > >> >but fails when running under interpreter: > >> >D:\Works\Python\pyeds-master\src>py > >> >Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32 > >> >Type "help", "copyright", "credits" or "license" for more information. > >> >>>> from test import * > >> >>>> input_str = "(NNS(acoustics) & RB(not)) | JJ(muted)" > >> >>>> rule = Rule_Parse() > >> >>>> main(input_str) > >> >Traceback (most recent call last): > >> > File "", line 1, in > >> > File "D:\Works\Python\pyeds-master\src\test.py", line 229, in main > >> > rule.current_char = c > >> >NameError: name 'rule' is not defined > >> >>>> > >> > > >> >I did check the globals using dir() and the 'rule' is there, no doubt. > >> > >> It matters how you checked this. This isn't apparent. > [...] > >Yes, the 'if' body is not executed when I import test.py under > >interpreter, that's why I manually execute them there. > >What puzzles me is that the globals() has a 'rule' object in both > >cases. Why this one doesn't work? > > I think I have misinterpreted what you've done. > > The globals are your current module's namespace, and functions defines > in a module are bound to that module's namespace. > > Strip your test.py back. A lot. Try this: > > def main(): > print(rule) > > Now, let's use that: > > Python 3.7.4 (default, Sep 28 2019, 13:34:38) > [Clang 8.0.0 (clang-800.0.42.1)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import test > >>> test.main() > Traceback (most recent call last): > File "", line 1, in > File "/Users/cameron/tmp/d1/test.py", line 2, in main > print(rule) > NameError: name 'rule' is not defined > > What's happening here? > > When we call main it tries to print "rule" from its module's globals. > > The first time you call it that doesn't exist, and we get your error. > > Setting rule=1 in the interpreter's space doesn't help (the stuff below > if from the same session continued from above): > > >>> rule=1 > >>> test.main() > Traceback (most recent call last): > File "", line 1, in > File "/Users/cameron/tmp/d1/test.py", line 2, in main > print(rule) > NameError: name 'rule' is not defined > > But if we define rule in the "test" module things improve: > > >>> test.rule=2 > >>> test.main() > 2 > > Importing main from test doesn't change where it looks for its globals: > > >>> from test import main as my_main > >>> my_main() > 2 > > That value (2) is still coming out of the test module. > > Cheers, > Cameron Simpson I didn't noticed that the interpreter has its own globals. Thanks for reminding. --Jach From rhodri at kynesim.co.uk Fri Nov 1 08:36:16 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 1 Nov 2019 12:36:16 +0000 Subject: Calculations and Variables In-Reply-To: <41a661ca-49f6-b5cb-4df2-719c4610dc77@mrabarnett.plus.com> References: <41a661ca-49f6-b5cb-4df2-719c4610dc77@mrabarnett.plus.com> Message-ID: <7058211e-b531-5d6b-bcc8-cf2372f58c63@kynesim.co.uk> On 31/10/2019 20:14, MRAB wrote: > On 2019-10-31 18:46, ferzan saglam wrote: >> The code below which I have written should print the result of 43.6 >> with the given values I have included at the end of this question, but >> for some odd reason I get the result of 44.44. >> >> >> bill = (input("Enter the total cost of the meal: \n")) >> tip = (input("Enter how much the tip is: \n")) >> split = (input("Enter how many people there are: \n")) > > Why are there parentheses around the inputs? Have you omitted the > conversion to numbers? My guess is the OP is using Python2 rather than Python3. So my first piece of advice would be to switch to Python3 now so you don't have to re-learn oddities like input(), print() and string handling. -- Rhodri James *-* Kynesim Ltd From dandekar.tanay2000 at gmail.com Fri Nov 1 03:23:25 2019 From: dandekar.tanay2000 at gmail.com (Tanay Dandekar) Date: Fri, 1 Nov 2019 12:53:25 +0530 Subject: Fwd: python startup failure problem In-Reply-To: References: Message-ID: ---------- Forwarded message --------- From: Tanay Dandekar Date: Thu, Oct 31, 2019 at 10:30 PM Subject: python startup failure problem To: Dear Sir, Please find attached photo of Python failure detail. please solve this problem as soon as possible. thanking you, Regard tanay From shubham12tomar at gmail.com Fri Nov 1 04:29:04 2019 From: shubham12tomar at gmail.com (Shubham Tomar) Date: Fri, 1 Nov 2019 13:59:04 +0530 Subject: Fwd: jupyter not install sucessfully In-Reply-To: References: Message-ID: ---------- Forwarded message --------- From: Shubham Tomar Date: Fri, 1 Nov 2019 at 13:58 Subject: jupyter not install sucessfully To: Dear sir, i have installed python and then pip , after that i installed jupyter using pip in command prompt. But jupyter can't start and give " external and internal" error in cmd. I also install Anaconda but it shows Kernel error : DLL load failed - The specified procedure not found etc.I also use pip but didn't work yet. I am using Windows 7 but i was try this in windows 10 and still i faced this error. Kindly please help me. From mal at europython.eu Fri Nov 1 07:26:44 2019 From: mal at europython.eu (M.-A. Lemburg) Date: Fri, 1 Nov 2019 12:26:44 +0100 Subject: EuroPython 2020: Venue and location selected Message-ID: <5049479a-ffa1-e679-e3af-dfd696b5232e@europython.eu> After a work intense RFP over two months with more than 40 venues competing, 18 first round entries, and two rounds of refinements, we are now happy to announce the winner: EuroPython 2020 will be held at the CCD in Dublin, Ireland, from July 20 - 26 2020 We will now start work on the contracts and get the organization going, so that we can all enjoy another edition of EuroPython next year. 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://www.europython-society.org/post/188741002380/europython-2020-venue-and-location-selected Tweet: https://twitter.com/europythons/status/1190227133920100352 Enjoy, -- EuroPython Society https://www.europython-society.org/ From joel.goldstick at gmail.com Fri Nov 1 09:08:11 2019 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 1 Nov 2019 09:08:11 -0400 Subject: python startup failure problem In-Reply-To: References: Message-ID: On Fri, Nov 1, 2019 at 8:59 AM Tanay Dandekar wrote: > > ---------- Forwarded message --------- > From: Tanay Dandekar > Date: Thu, Oct 31, 2019 at 10:30 PM > Subject: python startup failure problem > To: > > > Dear Sir, > > Please find attached photo of Python failure detail. > > please solve this problem as soon as possible. > > thanking you, > > Regard > tanay > -- > https://mail.python.org/mailman/listinfo/python-list Dear Tanay, Some, perhaps most people, might find it rude to assume that people here will solve your problem! This is a mailing list where people will help you solve python problems. You need to do your part as well. Photos, or any attachments are removed before your message is sent to list members. Please copy and paste your traceback from when you run your code, and describe the problems you are having. Also nice is your OS, python version. -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From a at d-amo.re Fri Nov 1 11:19:30 2019 From: a at d-amo.re (Andrea D'Amore) Date: Fri, 1 Nov 2019 16:19:30 +0100 Subject: Jupyter Notebook -> PDF with A4 pages? In-Reply-To: References: Message-ID: On Thu, 31 Oct 2019 at 22:08, Martin Sch??n wrote: > Den 2019-10-16 skrev Piet van Oostrum : >> Why should that not work? > pip install --user pip broke pip. I have not been able to repair pip I guess that's just the local pip shadowing the system one when you let the command "pip" to be resolved by the shell. , try calling the absolute path /usr/bin/pip . I do keep pip updated in the user directory with on Ubuntu with no issue. -- Andrea From python at mrabarnett.plus.com Fri Nov 1 13:07:23 2019 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 1 Nov 2019 17:07:23 +0000 Subject: Calculations and Variables In-Reply-To: <7058211e-b531-5d6b-bcc8-cf2372f58c63@kynesim.co.uk> References: <41a661ca-49f6-b5cb-4df2-719c4610dc77@mrabarnett.plus.com> <7058211e-b531-5d6b-bcc8-cf2372f58c63@kynesim.co.uk> Message-ID: On 2019-11-01 12:36, Rhodri James wrote: > On 31/10/2019 20:14, MRAB wrote: >> On 2019-10-31 18:46, ferzan saglam wrote: >>> The code below which I have written should print the result of 43.6 >>> with the given values I have included at the end of this question, but >>> for some odd reason I get the result of 44.44. >>> >>> >>> bill = (input("Enter the total cost of the meal: \n")) >>> tip = (input("Enter how much the tip is: \n")) >>> split = (input("Enter how many people there are: \n")) >> >> Why are there parentheses around the inputs? Have you omitted the >> conversion to numbers? > > My guess is the OP is using Python2 rather than Python3. So my first > piece of advice would be to switch to Python3 now so you don't have to > re-learn oddities like input(), print() and string handling. > The OP says it prints 44.44. In Python 2, / does integer division, so it would print 44.00. From rhodri at kynesim.co.uk Fri Nov 1 13:15:54 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 1 Nov 2019 17:15:54 +0000 Subject: Calculations and Variables In-Reply-To: References: <41a661ca-49f6-b5cb-4df2-719c4610dc77@mrabarnett.plus.com> <7058211e-b531-5d6b-bcc8-cf2372f58c63@kynesim.co.uk> Message-ID: On 01/11/2019 17:07, MRAB wrote: > On 2019-11-01 12:36, Rhodri James wrote: >> On 31/10/2019 20:14, MRAB wrote: >>> On 2019-10-31 18:46, ferzan saglam wrote: >>>> The code below which I have written should print the result of 43.6 >>>> with the given values I have included at the end of this question, >>>> but for some odd reason I get the result of 44.44. >>>> >>>> >>>> bill = (input("Enter the total cost of the meal: \n")) >>>> tip = (input("Enter how much the tip is: \n")) >>>> split = (input("Enter how many people there are: \n")) >>> >>> Why are there parentheses around the inputs? Have you omitted the >>> conversion to numbers? >> >> My guess is the OP is using Python2 rather than Python3.? So my first >> piece of advice would be to switch to Python3 now so you don't have to >> re-learn oddities like input(), print() and string handling. >> > The OP says it prints 44.44. > > In Python 2, / does integer division, so it would print 44.00. Well, it's inconsistent one way or the other. We'll have to wait for more information. -- Rhodri James *-* Kynesim Ltd From jwdevel at gmail.com Fri Nov 1 12:48:37 2019 From: jwdevel at gmail.com (John W) Date: Fri, 1 Nov 2019 09:48:37 -0700 Subject: Full stack trace in pdb.post_mortem() ? Message-ID: I'm trying to understand pdb.post_mortem(), and why the backtrace available in the debugger session seems limited. I posted a similar question on stackoverflow[1], but figured I'd try here as well. Here's a simple program import pdb def inner(): raise Exception("bad stuff") def outer(): try: inner() except Exception as ex: pdb.post_mortem() # using breakpoint() gives the full stack trace, of course def main(): outer() main() When I run that, I get put in the debugger. Then, if I run the `bt` command to get a backtrace, I see: (Pdb) bt /path/to/script(10)outer() -> inner() > /path/to/script(6)inner() -> raise Exception("bad stuff") As you can see, the backtrace only has `outer()` and `inner()`. What happened to `main()`? I want the full stack available, so I can investigate variables, etc. at any point along the chain. (in a real example, there might be quite a lot of additional call frames of interest) For this contrived example, I can put `breakpoint()` instead of `post_mortem()`, and get what I want. But I feel like I'm misunderstanding post-mortem debugging. Is the full call stack simply not available? Note: I am aware that I can *print* the full stack trace (including `main()`), even if it takes some special effort. See these posts: * https://stackoverflow.com/questions/13210436/get-full-traceback/ * https://stackoverflow.com/questions/6086976/how-to-get-a-complete-exception-stack-trace-in-python ---- [1] https://stackoverflow.com/questions/58653016/get-full-backtrace-with-pdb-post-mortem From toon.knapen at gmail.com Fri Nov 1 13:46:22 2019 From: toon.knapen at gmail.com (Toon Knapen) Date: Fri, 1 Nov 2019 10:46:22 -0700 (PDT) Subject: asyncio event guarantees to notify all waiting? Message-ID: Hello, I'm wondering if set'ing an asyncio.Event guarantees to notify all tasks that are waiting for the event ? Thus even if I `set()` the event and directly `clear()` the event, considering that both thus instructions are no co-routines and thus will not return control to the event-loop, will the wait'ers be notified? I guess so because if I add a 'clear()' directly after the `set` in following example, the waiting task is still notified. However this guarantee is not in the documentation: ``` async def waiter(event): print('waiting for it ...') await event.wait() print('... got it!') async def main(): # Create an Event object. event = asyncio.Event() # Spawn a Task to wait until 'event' is set. waiter_task = asyncio.create_task(waiter(event)) # Sleep for 1 second and set the event. await asyncio.sleep(1) event.set() event.clear() # event directly cleared after being set # Wait until the waiter task is finished. await waiter_task asyncio.run(main()) ``` From address at not.available Fri Nov 1 15:15:55 2019 From: address at not.available (R.Wieser) Date: Fri, 1 Nov 2019 20:15:55 +0100 Subject: OOP - iterable class: how to delete one of its objects ? Message-ID: Hello all, I've created a class from which I can iterate all its instanciated objects (using an "instances" list). The problem is that I now cannot seem to delete an object anymore, AFAIK as a copy of its "self" is still inside the "instances" list. Object in question: - - - - - - - - - - - - - - - - class TheObject: instances = [] def __init__(self): self.instances.append(self) def __del__(self): print("Deleted!") - - - - - - - - - - - - - - - - The question: How can I keep the class iterable, but still have it delete itself when asked. Regards, Rudy Wieser From rhodri at kynesim.co.uk Fri Nov 1 15:40:10 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 1 Nov 2019 19:40:10 +0000 Subject: OOP - iterable class: how to delete one of its objects ? In-Reply-To: References: Message-ID: <2dda1f94-6f74-5c10-3965-18fc57e98e6b@kynesim.co.uk> On 01/11/2019 19:15, R.Wieser wrote: > Hello all, > > I've created a class from which I can iterate all its instanciated objects > (using an "instances" list). The problem is that I now cannot seem to > delete an object anymore, AFAIK as a copy of its "self" is still inside the > "instances" list. > > Object in question: > - - - - - - - - - - - - - - - - > class TheObject: > instances = [] > > def __init__(self): > self.instances.append(self) > > def __del__(self): > print("Deleted!") > - - - - - - - - - - - - - - - - > > The question: How can I keep the class iterable, but still have it delete > itself when asked. Use weak references. A WeakSet (https://docs.python.org/3/library/weakref.html#weakref.WeakSet) is probably what you want. The idea is that the reference to the instance kept by the WeakSet doesn't contribute to the reference count. This won't automatically delete the reference from the WeakSet when the instance goes away, you'll want to set a finalizer for that, but the documentation covers what you want to know fairly clearly. Trust me, I was doing exactly this a week or so ago, and it's pretty straightforward. -- Rhodri James *-* Kynesim Ltd From rosuav at gmail.com Fri Nov 1 15:48:07 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Nov 2019 06:48:07 +1100 Subject: OOP - iterable class: how to delete one of its objects ? In-Reply-To: References: Message-ID: On Sat, Nov 2, 2019 at 6:21 AM R.Wieser
wrote: > > Hello all, > > I've created a class from which I can iterate all its instanciated objects > (using an "instances" list). The problem is that I now cannot seem to > delete an object anymore, AFAIK as a copy of its "self" is still inside the > "instances" list. > > Object in question: > - - - - - - - - - - - - - - - - > class TheObject: > instances = [] > > def __init__(self): > self.instances.append(self) > > def __del__(self): > print("Deleted!") > - - - - - - - - - - - - - - - - > > The question: How can I keep the class iterable, but still have it delete > itself when asked. > Have a method to explicitly purge the instance. The "del" statement does NOT request that the object be deleted; it simply unbinds the name. Instead, try something like this: class TheObject: instances = [] def __init__(self): self.active = True self.instances.append(self) def destroy(self): if not self.active: return self.active = False # wipe any attributes you need to self.instances.remove(self) Then, instead of "del some_object", use "some_object.destroy()". You can also use weak references if you need to, but this technique is going to be a lot more reliable and dependable than something based on weakrefs. ChrisA From PythonList at DancesWithMice.info Fri Nov 1 18:34:08 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 2 Nov 2019 11:34:08 +1300 Subject: How can i stop this Infinite While Loop - Python In-Reply-To: References: Message-ID: <06f5ba54-f739-d96d-9068-9ba06efa438d@DancesWithMice.info> TLDR; declare if homework; doing someone's homework doesn't really help; Python is not ALGOL/Pascal/C/C++ by any other name; Python assignments should promote learning semantics as well as syntax; sometimes re-stating the problem leads to an alternate/better solution. On 31/10/19 12:55 AM, ferzan saglam wrote: > I have tried many ways to stop the infinite loop but my program doesn't seem to stop after 10 items! It keeps going...!) > > --------------------------- > total = 0 > while True: > > print('Cost of item') > item = input() > > if item != -1: > total += int(item) > else: > break > > print(total) > --------------------------- A critique of this thread, plus a suggested approach to a solution:- 1 the OP This is a contrived coding problem. Is it part of a course? To establish an honest relationship with your list-colleagues, should you have declared it as 'homework'? Remembering that no-one 'here' is paid to be helpful, did you politely respond with the clarification requested? (see also later threads) There is an interesting psychology that you will notice when working with other people who are happy to be helpful (per this list-community); that if one stops to think about *how* to pose a question, sometimes the answer 'appears' - a burst of inspiration in your mind. That can be difficult to remember if you've been struggling with a problem for hours with the resultant level of frustration. At least the title of the post: "How can i stop this Infinite While Loop" is descriptive. Compared with some first-time poster's titles, this is clear and competent. Thanks! Thinking about it though, is there a hint of the nature of the problem, or even then an answer, in there? ie pausing to think about it, is the problem actually the "stop" (as emphasised) or might it be the "while"? (more below) 2 respondents This was an 'easy answer' question, so "well done" and "thank you" for jumping-in with the intention of contributing something to the community - quite possibly a first post for some. I encourage you to participate and do NOT wish to criticise you for having the best of motivations. However, it is always a good idea to consider not only "the question", as asked, but to 'first ask why?' (which happens to (almost) be the title of a thoroughly-recommendable book for managers, potential-managers, and certainly coaches/mentors to read). You can see this in one respondent's <<>> If (and this is *my* assumption!), the OP is a student attempting to learn Python, cf an experienced pythonista; giving "the answer" is NOT as helpful as it might seem. That's why the "pseudo code" solution was 'better' than a Python equivalent. What should the OP learn? Given 'the answer', would the OP be able to solve a similar problem when next encountered? If the OP's learning-objective is 'Python', then the pseudo-code helped clarify the necessary thinking, without detracting from the OP's learning-opportunity. (cf an algorithms course) In fact, and quite coincidentally, the best learning-opportunity here, has probably been the "off by one" experience - which the OP did indeed learn for himself. (Well done!) 3 the question itself/the questioner The way the OP has attempted to solve this contrived-problem indicates a fundamental lack of understanding of the way Python works and/or the way pythonista think. However, the way the question has been posed indicates much the same! It smacks of an old, even ancient, ComSc problem; previously applied to other languages (something I might have written when learning/teaching FORTRAN more than four decades ago, for example). How does this coding-problem contribute to the *Python* learning process? (as well as contributing towards the learning ComSc principles, eg managing/terminating loops) Thus: > The output I am aiming for is for the code to stop asking 'Cost of item' after 10 inputs or until -1 is typed, but the code repeats itself on an infinite loop. I cannot seem to stop the infinite loop. expresses the problem, but in the manner of other languages. The focus has been put on the "-1" fact - how to "stop". (remember the OP's title!) Question: since we no longer present data as decks of punched-cards, what is today's more usual way to indicate EOF/EOD? ("end of file", "end of data") Is the minus-one "flag" a very good approach, or even particularly representative of work-place 'realities'? Towards a solution: OK, let's not argue the point - it's certainly beyond the OP's control, so we must consider it a "specification"... The advice for solving ComSc (and other) problems is always to 'break down the larger problem into smaller, sub-problems and solve them' (which may, in-turn, involve breaking the sub-problems into smaller...) Here 'the problem' may decompose into: 1 accept input value 2 accumulate (total) input data-values 3 count number of input data-values 4 terminate if have received ten data-values 5 decide if EOD/-1 6 display the total (warning - or is it a ComSc learning-opportunity? understand that (5) is NOT a data-value for the purposes of (2), (3), and/or (6)! ) An excellent piece of advice (seen earlier in this thread) is to use the Python REPR to formulate answers and test ideas - one line of code at a time. (OP: you could have made your life easier by applying that advice BEFORE posing more recent questions) First ensure the 'straight-line' is understood, coded, and tested. Sub-problems 1, 2, and 5 are (hopefully) quickly solved AND proven! (although accumulators/__iadd__/in-place operators) are also important ComSc and Python concepts to learn, in-time!) There's little point in looking at (3) without a loop. So let's defer that. The attempted solution says: start with a never-ending loop. Curiously-enough this seems exactly where the OP ran into problems: "I cannot seem to stop the infinite loop." Question: why start one in the first place? To avoid this problem, before starting something/anything, decide how it's going to end! (see also: signing cloud-computing contracts...) This loop has two termination-conditions: (4) ten data-values entered, as an "absolute maximum", and (5) the -1 flag, which may/not occur. Consider them separately. The OP had the right idea of an if-construct checking for the flag and breaking the loop. We could have coded that in the REPR and tested it very quickly. However, this is a variable-situation. The -1 flag could take the place of the very first data-item, it could appear instead of any other of the ten acceptable data-items, or it might not appear at all! Compare this with (4). The maximum is an absolute condition. The client-requirement doesn't seem to care how large or how small the total might be. The routine must stop accumulating data after the tenth item. No discussion! What happens/how does 'the picture' change if make this our 'primary' condition, ie code this first, and then worry about (5) later? Which leads to a learning-opportunity in Python: which Python construct is designed to manage a loop for a fixed number of repetitions? The next step in the REPR then, is to code a for-loop which repeats 10 times*. Hint: you don't need to include the solutions for (1), (2), and (5) within this test, print something ("hello world!" perhaps?) but test/ensure it happens ten times! This is an opportunity to read-up about Python's range(), which will also lead towards solving sub-problem 3! Now, we can worry about the variable termination (sub-problem 5), applying the same technique as employed in the OP's existing code ("break"). Thus, the -1-termination has become trivial, instead of being the major trial and headache that it was, leading up to this post. Which leaves us with (2), which was solved earlier in this conversation - and can be easily proven in the REPR. That said, experimenting with the REPR would quickly provide a learning-opportunity by illustrating the issue/error of data-items being read ("input") as strings, and needing to be converted to integer before performing any arithmetic. The value of Python's REPR *cannot* be under-stated, particularly to beginners - but when facing something for the first time, aren't we all 'beginners'? * sadly, we're back to critique nr3. Counting incidents and specifically the "off by one" bug, discovered here serendipitously, are amongst the most frequent, if not THE most frequent, errors found in code (using almost any common programming language) and dating right back to the aforementioned FORTRAN and beyond to the beginnings with Assemblers and machine language code! Python has a wonderful philosophy, that its "for" loop is NOT a means of counting repetitions from 'here' to 'there' eg zero?one to 10. It is a superior (IMHO) piece of language-design: a for-each construct. It is nicely illustrated as: for each element in a list, do 'something'. Accordingly, this perhaps-venerable ComSc problem is not helpful when learning Python, even if Python will (happily) solve said problem! WebRefs: https://simonsinek.com/product/start-with-why/ https://en.wikipedia.org/wiki/Functional_decomposition https://en.wikipedia.org/wiki/Eureka https://docs.python.org/3/reference/compound_stmts.html https://docs.python.org/3/library/operator.html -- Regards =dn From larry at hastings.org Fri Nov 1 20:52:03 2019 From: larry at hastings.org (Larry Hastings) Date: Fri, 1 Nov 2019 17:52:03 -0700 Subject: [RELEASED] Python 3.5.9 is released Message-ID: <5ca01a3f-50e9-9bef-340c-a4e55e6b7534@hastings.org> On behalf of the Python development community, I'm slightly chagrined to announce the availability of Python 3.5.9.? There were no new changes in version 3.5.9; 3.5.9 was released only because of a CDN caching problem, which resulted in some users downloading a prerelease version of the 3.5.8 .xz source tarball. Apart from the version number, 3.5.9 is identical to the proper 3.5.8 release. This new version is a source-only release. You can find Python 3.5.9 here: ??? https://www.python.org/downloads/release/python-359/ Happy Halloween, /arry From originallmoney at gmail.com Fri Nov 1 21:55:13 2019 From: originallmoney at gmail.com (originallmoney at gmail.com) Date: Fri, 1 Nov 2019 18:55:13 -0700 (PDT) Subject: Trouble trying to get started with pygame In-Reply-To: References: Message-ID: <412bf414-19a5-4937-90fd-3363cb78614b@googlegroups.com> On Friday, November 1, 2019 at 1:05:35 AM UTC-4, MRAB wrote: > On 2019-11-01 03:47, originallmoney at gmail.com wrote: > > It's been years since I've done anything with Python, and it wasn't a language I was terribly familiar with even then. I'm using Python 3.8 on my Windows 7 laptop. Python itself works so far as I can tell. I can get it to import pip without problems, but, when I try to get going with pygame, I hit a roadblock. > > > > I have pygame 1.9.6.tar.gz. Apparently, I don't have the means of unzipping it, yet, I think I've seen things on other forums suggesting that Python can do that for me. Is that true? > > > Actually, you do have the means: Python! > > But there's a simpler way. > > > I've been trying to use "pip install" (Written just like that, minus the quotes, of course), yet, it tells me that's a syntax error. > > > > Is there a way of inputting this that I'm not aware of? I've seen various versions of people calling the command, with things like "pip.install" or "-m pip install -U pygame -user" or something like that, are THOSE what I should be trying or...am I completely off-base right now? > > > Those commands are for the Windows command prompt. > > > Any help would be appreciated, as I'm losing patience with it at the moment. > > > > Go to Christoph Gohlke's site at: > > https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame > > Download one of these "wheel" files: > > pygame?1.9.6?cp38?cp38?win_amd64.whl for 64-bit > > or: > > pygame?1.9.6?cp38?cp38?win32.whl for 32-bit > > At the Windows command prompt type: > > py -3.8 -m pip install "path/to/wheel" Does it matter where I place pygame? I was going to put it into my Scripts folder, as I'm pretty sure I already have a path that goes there. From originallmoney at gmail.com Fri Nov 1 22:28:26 2019 From: originallmoney at gmail.com (originallmoney at gmail.com) Date: Fri, 1 Nov 2019 19:28:26 -0700 (PDT) Subject: Trouble trying to get started with pygame In-Reply-To: <412bf414-19a5-4937-90fd-3363cb78614b@googlegroups.com> References: <412bf414-19a5-4937-90fd-3363cb78614b@googlegroups.com> Message-ID: <9313ee4c-7250-4c8f-804b-f468a0dd3c5a@googlegroups.com> I tried what you suggested at the command prompt and (Despite being able to open Python from my start menu), it tells me Python isn't installed. I'm curious, and, I probably should have mentioned it earlier: I have Python on my D drive (Because it has more space). Is THAT why it says Python isn't installed? MUST I have it on the C drive? From python at mrabarnett.plus.com Fri Nov 1 23:14:10 2019 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 2 Nov 2019 03:14:10 +0000 Subject: Trouble trying to get started with pygame In-Reply-To: <412bf414-19a5-4937-90fd-3363cb78614b@googlegroups.com> References: <412bf414-19a5-4937-90fd-3363cb78614b@googlegroups.com> Message-ID: On 2019-11-02 01:55, originallmoney at gmail.com wrote: > On Friday, November 1, 2019 at 1:05:35 AM UTC-4, MRAB wrote: >> On 2019-11-01 03:47, originallmoney at gmail.com wrote: >> > It's been years since I've done anything with Python, and it wasn't a language I was terribly familiar with even then. I'm using Python 3.8 on my Windows 7 laptop. Python itself works so far as I can tell. I can get it to import pip without problems, but, when I try to get going with pygame, I hit a roadblock. >> > >> > I have pygame 1.9.6.tar.gz. Apparently, I don't have the means of unzipping it, yet, I think I've seen things on other forums suggesting that Python can do that for me. Is that true? >> > >> Actually, you do have the means: Python! >> >> But there's a simpler way. >> >> > I've been trying to use "pip install" (Written just like that, minus the quotes, of course), yet, it tells me that's a syntax error. >> > >> > Is there a way of inputting this that I'm not aware of? I've seen various versions of people calling the command, with things like "pip.install" or "-m pip install -U pygame -user" or something like that, are THOSE what I should be trying or...am I completely off-base right now? >> > >> Those commands are for the Windows command prompt. >> >> > Any help would be appreciated, as I'm losing patience with it at the moment. >> > >> >> Go to Christoph Gohlke's site at: >> >> https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame >> >> Download one of these "wheel" files: >> >> pygame?1.9.6?cp38?cp38?win_amd64.whl for 64-bit >> >> or: >> >> pygame?1.9.6?cp38?cp38?win32.whl for 32-bit >> >> At the Windows command prompt type: >> >> py -3.8 -m pip install "path/to/wheel" > > Does it matter where I place pygame? I was going to put it into my Scripts folder, as I'm pretty sure I already have a path that goes there. > It'll be installed into Python's site-packages folder. From python at mrabarnett.plus.com Fri Nov 1 23:17:22 2019 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 2 Nov 2019 03:17:22 +0000 Subject: Trouble trying to get started with pygame In-Reply-To: <9313ee4c-7250-4c8f-804b-f468a0dd3c5a@googlegroups.com> References: <412bf414-19a5-4937-90fd-3363cb78614b@googlegroups.com> <9313ee4c-7250-4c8f-804b-f468a0dd3c5a@googlegroups.com> Message-ID: <8fe30991-0ad2-632f-bb37-fc9881b8835f@mrabarnett.plus.com> On 2019-11-02 02:28, originallmoney at gmail.com wrote: > I tried what you suggested at the command prompt and (Despite being able to open Python from my start menu), it tells me Python isn't installed. > > I'm curious, and, I probably should have mentioned it earlier: I have Python on my D drive (Because it has more space). Is THAT why it says Python isn't installed? MUST I have it on the C drive? > Do you mean that it can't find "py" or that "py" can't find Python? If you used the installer to install Python on the D drive, then I'd expect it to just work. From robertvstepp at gmail.com Fri Nov 1 23:32:31 2019 From: robertvstepp at gmail.com (boB Stepp) Date: Fri, 1 Nov 2019 22:32:31 -0500 Subject: Friday finking: TDD and EAFP In-Reply-To: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> References: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> Message-ID: On Fri, Nov 1, 2019 at 12:42 AM DL Neil via Python-list wrote: > > Is the practice of TDD fundamentally, if not philosophically, somewhat > contrary to Python's EAFP approach? > [...] > > In encouraging my mind to think about testing the code, I find myself > searching for edge-cases, and attempting to anticipate the unusual. > Accordingly to the gospel of TDD: so far, so good. > > The 'problem' is, that it puts my mind onto LBYL-rails before the > Python-coding train (of thought) has even left the station. It then > seems natural to start putting a bunch of if-then-else's up-front and > before the 'main line' of code. > > Does TDD bend your mind in this (apparently) non-Pythonic fashion? > Have you developed an answer? > (other than: "@dn is 'nuts'*", which is not worthy of debate) As the pros have yet to chime in, I will attempt to add my amateurish thoughts. In my on again/off again efforts to self-study Python, sound software construction practices, etc., I have been endeavoring to adopt a TDD approach. I find that trying to do this forces upon me more clarity of thought which (hopefully) results in more expressive, simpler and understandable code. As I often find my initial efforts at writing tests murky and hard to understand, I (eventually) realize that the associated code I'm trying to test, which seemed so clear when I first wrote it, is hard to test. So I refactor/simplify the code, it becomes easier to write sensible test code, etc. It may just be me and my lack of experience, but I find this circular process ultimately leads to more Pythonic results -- easier to understand code that (I hope) others can easily read and understand. Though I am sure I am stating the obvious, instead of just thinking about edge cases, I like to have at least one test that proves that what I normally expect to get is, in fact, gotten. I often embarrassingly find myself caught in some sort of simple logic error that this type of test will catch, especially later if I am refactoring my code in the direction I am trying to coerce it to go for the end product. I am probably far from thinking/coding in a proper Pythonic fashion, but the TDD back-and-forth process seems to get me closer to being Pythonic. -- boB From random832 at fastmail.com Sat Nov 2 01:10:54 2019 From: random832 at fastmail.com (Random832) Date: Sat, 02 Nov 2019 01:10:54 -0400 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: <89b9fca2-5890-4d29-b5f7-6b0454b0f6d8@www.fastmail.com> On Sun, Oct 27, 2019, at 03:24, Steve White wrote: > Yes, there are several options, but they all involve an extra layer > that detracts between the interface I am building and my user's code. > In this situation, the objects being used as keys are conceptually the > unique entities that the user deals with, even if their data is > non-unique. And I do not want to subject the user to the un-pythonic > use of some operator other than '==' to determine their equivalence. I'm honestly a little bit confused as to what the type of the objects you are using which it's reasonable to do this with but doesn't already work that way > As near as I can tell, returning the id() in __hash__() results in a > perfect hash key. I really want to know if that is true. > Because if it is true, any further layer is simply covering for a > failing in the documentation. And if you can override __hash__ you can, obviously, also override __eq__ to do whatever you want. You can return id in both. In fact, that is the default behavior of objects, assuming your type is not inherited from another type that does something different. Regardless, __hash__ and __eq__ should be consistent with each other. From address at not.available Sat Nov 2 02:21:51 2019 From: address at not.available (R.Wieser) Date: Sat, 2 Nov 2019 07:21:51 +0100 Subject: OOP - iterable class: how to delete one of its objects ? References: Message-ID: Chris, > Have a method to explicitly purge the instance. I was thinking of that too but decided against it, as it would mean that my objects would need to be handled specially - which is not quite what I'm looking for. To be honest, I was thinking of/hoping that there would be a method which was called when an objects reference count was changed. Regards, Rudy Wieser From address at not.available Sat Nov 2 02:25:27 2019 From: address at not.available (R.Wieser) Date: Sat, 2 Nov 2019 07:25:27 +0100 Subject: OOP - iterable class: how to delete one of its objects ? References: Message-ID: Dennis, > In __init__() you are adding "self" to a classwide list. So in > your __del__() you need to remove the instance from the > same list. Something :-) Thats the problem: __del__ only gets called when the object is destroyed - which will never happen when the "instances" list still contains a reference to it. Its a catch-22 situation: __del__ needs to be executed to remove the reference from the "instances" list, but I need to remove the reference from that list before __del__ will be called ... Regards, Rudy Wieser From address at not.available Sat Nov 2 02:30:11 2019 From: address at not.available (R.Wieser) Date: Sat, 2 Nov 2019 07:30:11 +0100 Subject: OOP - iterable class: how to delete one of its objects ? References: <2dda1f94-6f74-5c10-3965-18fc57e98e6b@kynesim.co.uk> Message-ID: Rhodri, > Use weak references. A WeakSet > (https://docs.python.org/3/library/weakref.html#weakref.WeakSet) is > probably what you want. Most likely! As a fresh freshling in regard to python I was not even aware that a "copy object, but do not increment the reference count" existed. Thank you. Could cause some interresting "the object has disappeared!" problems when you're not carefull with it though ... :-) Regards, Rudy Wieser From 00jhenryg at gmail.com Sat Nov 2 16:25:48 2019 From: 00jhenryg at gmail.com (Jack Gilbert) Date: Sat, 2 Nov 2019 15:25:48 -0500 Subject: help with 3.8.0 Message-ID: Need help please just downloaded 3.8.0, can't get it to open the shell. Thanks in advance for helping me.. Jack From ikorot01 at gmail.com Sat Nov 2 17:09:10 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Sat, 2 Nov 2019 16:09:10 -0500 Subject: help with 3.8.0 In-Reply-To: References: Message-ID: Hi, What version did you downloaded? Was install successful? Which is do you use? What is an exact error message you received? Please copy and paste - NO ATTACHMENTS!!! Thank you. On Sat, Nov 2, 2019, 3:29 PM Jack Gilbert <00jhenryg at gmail.com> wrote: > Need help please just downloaded 3.8.0, can't get it to open the shell. > > Thanks in advance for helping me.. > > Jack > -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at danceswithmice.info Sun Nov 3 13:41:32 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Mon, 4 Nov 2019 07:41:32 +1300 Subject: Friday finking: TDD and EAFP In-Reply-To: <74263897-D40B-4EAD-957E-C1FF43A26F6F@gmail.com> References: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> <74263897-D40B-4EAD-957E-C1FF43A26F6F@gmail.com> Message-ID: <2500afa5-84ae-e5fc-a73c-4091681068e6@DancesWithMice.info> On 3/11/19 6:30 AM, Bev In TX wrote: >> On Nov 1, 2019, at 12:40 AM, DL Neil via Python-list >> > wrote: >> >> Is the practice of TDD fundamentally, if not philosophically, somewhat >> contrary to Python's EAFP approach? > I?m not an expert on either TDD or Python, but as no one else has > responded, I?ll put in my 2 cents worth... > You are mixing paradigms.? TDD is about testing code, regardless of the > style in which it was written. Agreed: (in theory) TDD is independent of language or style. However, I'm wondering if (in practice) it creates a mode of thinking that pushes one into an EAFP way of thinking? > Yes, exceptions can handle some edge cases; however, that does NOT mean > that ... > > * all code handles all edge cases. > * all bugs are only in edge cases. > * all exception handling code is perfectly written. > * Etc The preceding description was deliberately short and not intended as a definition of TDD, nor bug-hunting. Have I missed your point here? (apologies) -- Regards =dn From PythonList at danceswithmice.info Sun Nov 3 14:14:37 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Mon, 4 Nov 2019 08:14:37 +1300 Subject: Friday finking: TDD and EAFP In-Reply-To: References: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> Message-ID: On 2/11/19 4:32 PM, boB Stepp wrote: > On Fri, Nov 1, 2019 at 12:42 AM DL Neil via Python-list > wrote: >> >> Is the practice of TDD fundamentally, if not philosophically, somewhat >> contrary to Python's EAFP approach? > [...] >> In encouraging my mind to think about testing the code, I find myself >> searching for edge-cases, and attempting to anticipate the unusual. >> Accordingly to the gospel of TDD: so far, so good. >> >> The 'problem' is, that it puts my mind onto LBYL-rails before the >> Python-coding train (of thought) has even left the station. It then >> seems natural to start putting a bunch of if-then-else's up-front and >> before the 'main line' of code. >> >> Does TDD bend your mind in this (apparently) non-Pythonic fashion? >> Have you developed an answer? >> (other than: "@dn is 'nuts'*", which is not worthy of debate) > > As the pros have yet to chime in, I will attempt to add my amateurish Thanks! Because I have several r?les and spend only a proportion of my time actually coding, I fear that I should claim a less-than professional status. No matter. It's an interesting comment though: I've been wondering if many 'Python pros' actually use TDD - few of the people I work alongside (in programmer-mode) do. Thus there are TDD 'evangelists', loud detractors, and most 'in the middle' or simply not wanting to engage in such a debate. Perhaps 'Python pros' don't use TDD. Which in-and-of-itself, somewhat answers the question! > thoughts. In my on again/off again efforts to self-study Python, > sound software construction practices, etc., I have been endeavoring > to adopt a TDD approach. I find that trying to do this forces upon me > more clarity of thought which (hopefully) results in more expressive, > simpler and understandable code. As I often find my initial efforts > at writing tests murky and hard to understand, I (eventually) realize > that the associated code I'm trying to test, which seemed so clear > when I first wrote it, is hard to test. So I refactor/simplify the > code, it becomes easier to write sensible test code, etc. It may just > be me and my lack of experience, but I find this circular process > ultimately leads to more Pythonic results -- easier to understand code > that (I hope) others can easily read and understand. > > Though I am sure I am stating the obvious, instead of just thinking > about edge cases, I like to have at least one test that proves that > what I normally expect to get is, in fact, gotten. I often > embarrassingly find myself caught in some sort of simple logic error > that this type of test will catch, especially later if I am > refactoring my code in the direction I am trying to coerce it to go > for the end product. > > I am probably far from thinking/coding in a proper Pythonic fashion, > but the TDD back-and-forth process seems to get me closer to being > Pythonic. Yes, normally the first test(s) (eg for some method/function) would be the desired behavior(s) - testing that we will enjoy the expected benefits of the actual code/that the code does what it should. Thereafter it become a case of ensuring there's nothing 'else' or undesired... ie there's no point in worrying about (say) a "divide by zero" condition, if the formula doesn't already prove with valid data! Unlike yourself - and probably the circular approach described by most TDD advocates, my approach has been to write the method's (probably) signature and docstring + pass first. Then to transfer those objectives to Pytest code, where I write test-after-test - because I'm in the mode of thinking about 'what-ifs'. Once I'm reasonably satisfied that I've covered the specs, then it becomes time to write the code - during which I do follow a circular fashion - satisfy the first test, then satisfy the second... always ensuring that subsequent refactoring doesn't abrogate an earlier 'pass'. Hence the observation that an (attempt at an) exhaustive examination of the spec is rather LBYL; whereas the circular code-and-test might be more Pythonic if it were more EAFP, but that starting with a somewhat LBYL approach might tend to keep one thinking that way... (of course it is never quite a clean-cut the idealised two-stage description (above). There are always considerations which occur to me 'later', and changes/improvements to the spec which arise as the team 'burns down' the sprint...) -- Regards =dn From hjp-python at hjp.at Sun Nov 3 14:59:08 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 3 Nov 2019 20:59:08 +0100 Subject: What's the difference between running a script under command box and interpreter? In-Reply-To: References: <20191101092815.GA98493@cskk.homeip.net> Message-ID: <20191103195908.GA3944@hjp.at> On 2019-11-01 04:24:38 -0700, jfong at ms4.hinet.net wrote: > > The globals are your current module's namespace, and functions defines > > in a module are bound to that module's namespace. > > > > Strip your test.py back. A lot. Try this: > > > > def main(): > > print(rule) > > > > Now, let's use that: > > > > Python 3.7.4 (default, Sep 28 2019, 13:34:38) > > [Clang 8.0.0 (clang-800.0.42.1)] on darwin > > Type "help", "copyright", "credits" or "license" for more information. > > >>> import test > > >>> test.main() > > Traceback (most recent call last): > > File "", line 1, in > > File "/Users/cameron/tmp/d1/test.py", line 2, in main > > print(rule) > > NameError: name 'rule' is not defined [Explanation snipped] > I didn't noticed that the interpreter has its own globals. Thanks for reminding. It's not really "the interpreter" (I think you mean the REPL) which has it's own globals. Every module/file has its own globals. The same thing happens non-interactively: % cat test.py def main(): print(rule) % cat foo.py #!/usr/bin/python3 from test import * rule = 42 main() % ./foo.py Traceback (most recent call last): File "./foo.py", line 6, in main() File "/home/hjp/tmp/test.py", line 2, in main print(rule) NameError: name 'rule' is not defined The "rule" identifier in main() refers to a "rule" variable in the module test. If you set a variable "rule" somewhere else (in foo.py or the REPL, ...), that has no effect. How should python know that you want to set the rule variable in the test module? hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- 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 Nov 3 15:44:37 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 3 Nov 2019 21:44:37 +0100 Subject: Friday finking: TDD and EAFP In-Reply-To: <2500afa5-84ae-e5fc-a73c-4091681068e6@DancesWithMice.info> References: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> <74263897-D40B-4EAD-957E-C1FF43A26F6F@gmail.com> <2500afa5-84ae-e5fc-a73c-4091681068e6@DancesWithMice.info> Message-ID: <20191103204437.GB3944@hjp.at> On 2019-11-04 07:41:32 +1300, DL Neil via Python-list wrote: > On 3/11/19 6:30 AM, Bev In TX wrote: > > > On Nov 1, 2019, at 12:40 AM, DL Neil via Python-list > > > > wrote: > > > > > > Is the practice of TDD fundamentally, if not philosophically, > > > somewhat contrary to Python's EAFP approach? > > > I?m not an expert on either TDD or Python, but as no one else has > > responded, I?ll put in my 2 cents worth... > > You are mixing paradigms.? TDD is about testing code, regardless of the > > style in which it was written. > > Agreed: (in theory) TDD is independent of language or style. However, I'm > wondering if (in practice) it creates a mode of thinking that pushes one > into an EAFP way of thinking? This is exactly the opposite of what you proposed in your first mail, and I think it is closer to the truth: TDD does in my opinion encourage EAFP thinking. The TDD is usually: 1 Write a test 2 Write the minimal amount of code that makes the test pass 3 If you think you have covered the whole spec, stop, else repeat from 1 This is often (e.g. in [1]) exaggerated for pedagogic and humoristic reasons. For example, your first test for a sqrt function might be assert(sqrt(4) == 2) and then of course the minimal implementation is def sqrt(x): return 2 Which just means that we don't have enough test cases yet. But the point is that a test suite can only check a finite (and usually rather small) number of cases, while most interesting programs accept a very large (if not really infinite) number of inputs, so the test suite will always be incomplete. At some point you will have to decide thet the test suite is good enough and ship the code - and hope that the customer will forgive you if you have (inevitably) forgotten an important case. There is very little emphasis in TDD on verifying that the code is correct - only that it passes the tests. hp [1] Harry J.W. Percival, Test-Driven Development with Python, O'Reilly, 2017 -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- 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 Nov 3 16:04:20 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 3 Nov 2019 22:04:20 +0100 Subject: Friday finking: TDD and EAFP In-Reply-To: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> References: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> Message-ID: <20191103210420.GC3944@hjp.at> On 2019-11-01 18:40:06 +1300, DL Neil via Python-list wrote: > In other words, before you do anything with some data, check that it is what > you think it is. Whereas in Python we "try" by assuming everything is > compos-mentis* and handle the "except" when things are not how we'd like. > > That adaptation was not too difficult. After all, aren't programmers an > optimistic bunch - I mean, I *never* introduce bugs into *my* code! Do you? > > Which brings us to TDD. Here we assume the likelihood of bugs, as-if (cue: > manic giggling); and code a bunch of tests first - in an attempt to prove > that the code is up-to-spec. > > In encouraging my mind to think about testing the code, I find myself > searching for edge-cases, and attempting to anticipate the unusual. > Accordingly to the gospel of TDD: so far, so good. > > The 'problem' is, that it puts my mind onto LBYL-rails before the > Python-coding train (of thought) has even left the station. It then seems > natural to start putting a bunch of if-then-else's up-front and before the > 'main line' of code. I think you refer here to the practice of (for example) just opening a file and handling possible error cases (e.g. file doesn't exist, you don't have permission, etc.) in an exception handler instead of checking for possible problems first. Which is quite common in languages with exceptions (like Python or Java), but not exclusive to them (for example, this is also almost always what you should do in C). You feel that TDD discourages this style and pushes you to writting lots of checks up-front, correct? > Does TDD bend your mind in this (apparently) non-Pythonic fashion? No. I don't feel my mind bent in this fashion. TDD treats (at least conceptually, if not always in practice) the code as a black box. So it shouldn't matter whether (for example) I check some condition and raise an error, or rely on open() to raise the error for me. I do feel OTOH that TDD nudges me toward sloppyness in cases where I cannot easily write a test. I might then skip the test case ("It's unlikely to happen anyway") and - since the test suite passes - forget to implement it properly. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- 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 Nov 3 16:28:17 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 3 Nov 2019 22:28:17 +0100 Subject: Friday finking: TDD and EAFP In-Reply-To: References: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> Message-ID: <20191103212817.GD3944@hjp.at> On 2019-11-04 08:14:37 +1300, DL Neil via Python-list wrote: > Perhaps 'Python pros' don't use TDD. Which in-and-of-itself, somewhat > answers the question! A certain Youtube channel has T-shirts for sale with this text: DON'T TRY THIS AT HOME WE ARE PROFESSIONALS because we get paid to do this I get paid to write Python code, so I'm a Python professional, right? I never really used TDD, but I was quite used to writing tests when I was writing in Perl. The TAP framework is really simple (some might say primitive) and the entry barrier to writing tests is extremely low. Besides, everybody was doing it. When I switched to Python, I mostly lost this habit. Python testing felt clunky, Java-ish, and the other Python programmers weren't writing tests either. I have since tried to get into the habit of always writing tests again, but with limited success. unittest still feels clunky, The django framework only works well if your problem fits exactly into a rather narrow niche (which none of our project really fits into). I have recently started to use pytest. That feels a bit more comfortable. We'll see. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From tjreedy at udel.edu Sun Nov 3 18:51:25 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 3 Nov 2019 18:51:25 -0500 Subject: Friday finking: TDD and EAFP In-Reply-To: <20191103204437.GB3944@hjp.at> References: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> <74263897-D40B-4EAD-957E-C1FF43A26F6F@gmail.com> <2500afa5-84ae-e5fc-a73c-4091681068e6@DancesWithMice.info> <20191103204437.GB3944@hjp.at> Message-ID: Some general thoughts on core development and testing. For bugs.python.org issues, the first Stage choice is 'test needed'. All code patches *should* include new tests. This was not always so, and we are still paying off technical debt. One problem I have encountered with idlelib is that some refactoring is needed to make tests easier or even possible to write, while refactoring should be preceded by good tests. *Should* is not always enforced, but skipping them without doing adequate manual tests can lead to new bugs, and adequate manual tests are tedious and too easy to forget. I have learned this the hard way. On 11/3/2019 3:44 PM, Peter J. Holzer wrote: > On 2019-11-04 07:41:32 +1300, DL Neil via Python-list wrote: >> Agreed: (in theory) TDD is independent of language or style. However, I'm >> wondering if (in practice) it creates a mode of thinking that pushes one >> into an EAFP way of thinking? > > This is exactly the opposite of what you proposed in your first mail, > and I think it is closer to the truth: > > TDD does in my opinion encourage EAFP thinking. As in "use the code and if it fails, add a test and fix it" versus "if the code can be proven correct, use it". > The TDD is usually: > > 1 Write a test > 2 Write the minimal amount of code that makes the test pass > 3 If you think you have covered the whole spec, stop, else repeat > from 1 > > This is often (e.g. in [1]) exaggerated for pedagogic and humoristic > reasons. For example, your first test for a sqrt function might be > assert(sqrt(4) == 2) > and then of course the minimal implementation is > def sqrt(x): > return 2 The *is* exaggerated. For math functions, I usually start with a few cases, not just 1, to require something more of an implementation. See below. > Which just means that we don't have enough test cases yet. But the point > is that a test suite can only check a finite (and usually rather small) > number of cases, while most interesting programs accept a very large (if > not really infinite) number of inputs, so the test suite will always be > incomplete. I usually try to also test with larger 'normal' values. When possible, we could and I think should make more use of randomized testing. I got this from reading about the Hypothesis module. See below for one example. A similar example for multiplication might test assertEqual(a*b + b, (a+1)*b) where a and b are random ints. > At some point you will have to decide thet the test suite is > good enough and ship the code - and hope that the customer will forgive > you if you have (inevitably) forgotten an important case. Possible test for math.sqrt. from math import sqrt from random import randint import unittest class SqrtTest(unittest.TestCase): def test_small_counts(self): for i in range(3): with self.subTest(i=i): self.assertEqual(sqrt(i*i), i) def test_random_counts(self): for i in range(100): # Number of subtests. with self.subTest(): n = randint(0, 9999999) self.assertEqual(sqrt(n*n), float(n)) def test_negative_int(self): self.assertRaises(ValueError, sqrt, -1) unittest.main() > There is very little emphasis in TDD on verifying that the code is > correct - only that it passes the tests. For the kind of business (non-math) code that seems to be the stimulus for TDD ideas, there often is no global definition of 'correct'. -- Terry Jan Reedy From jfong at ms4.hinet.net Sun Nov 3 19:34:39 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sun, 3 Nov 2019 16:34:39 -0800 (PST) Subject: What's the difference between running a script under command box and interpreter? In-Reply-To: References: <20191101092815.GA98493@cskk.homeip.net> <20191103195908.GA3944@hjp.at> Message-ID: Peter J. Holzer? 2019?11?4???? UTC+8??3?59?36???? > On 2019-11-01 04:24:38 -0700, jfong at ms4.hinet.net wrote: > > > The globals are your current module's namespace, and functions defines > > > in a module are bound to that module's namespace. > > > > > > Strip your test.py back. A lot. Try this: > > > > > > def main(): > > > print(rule) > > > > > > Now, let's use that: > > > > > > Python 3.7.4 (default, Sep 28 2019, 13:34:38) > > > [Clang 8.0.0 (clang-800.0.42.1)] on darwin > > > Type "help", "copyright", "credits" or "license" for more information. > > > >>> import test > > > >>> test.main() > > > Traceback (most recent call last): > > > File "", line 1, in > > > File "/Users/cameron/tmp/d1/test.py", line 2, in main > > > print(rule) > > > NameError: name 'rule' is not defined > > [Explanation snipped] > > > I didn't noticed that the interpreter has its own globals. Thanks for reminding. > > It's not really "the interpreter" (I think you mean the REPL) which has > it's own globals. Every module/file has its own globals. > > The same thing happens non-interactively: > > % cat test.py > def main(): > print(rule) > > % cat foo.py > #!/usr/bin/python3 > > from test import * > > rule = 42 > main() > > % ./foo.py > Traceback (most recent call last): > File "./foo.py", line 6, in > main() > File "/home/hjp/tmp/test.py", line 2, in main > print(rule) > NameError: name 'rule' is not defined > > The "rule" identifier in main() refers to a "rule" variable in the > module test. If you set a variable "rule" somewhere else (in foo.py or > the REPL, ...), that has no effect. How should python know that you want > to set the rule variable in the test module? > > hp > > -- > _ | Peter J. Holzer | Story must make more sense than reality. > |_|_) | | > | | | hjp at hjp.at | -- Charles Stross, "Creative writing > __/ | http://www.hjp.at/ | challenge!" I innocently thought that when import module through "from test import *", I am working on test's globals under REPL. I didn't noticed the REPL has its own globals. >>> How should python know that you want to set the rule variable in the test module? My 'wrong' answer will be, at the time I raised my question, that when import two different modules either has 'rule' variable, REPL will see the second imported one. No kidding:-) --Jach From rosuav at gmail.com Sun Nov 3 19:42:39 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Nov 2019 11:42:39 +1100 Subject: What's the difference between running a script under command box and interpreter? In-Reply-To: References: <20191101092815.GA98493@cskk.homeip.net> <20191103195908.GA3944@hjp.at> Message-ID: On Mon, Nov 4, 2019 at 11:36 AM wrote: > > Peter J. Holzer? 2019?11?4???? UTC+8??3?59?36???? > > On 2019-11-01 04:24:38 -0700, jfong at ms4.hinet.net wrote: > > > > The globals are your current module's namespace, and functions defines > > > > in a module are bound to that module's namespace. > > > > > > > > Strip your test.py back. A lot. Try this: > > > > > > > > def main(): > > > > print(rule) > > > > > > > > Now, let's use that: > > > > > > > > Python 3.7.4 (default, Sep 28 2019, 13:34:38) > > > > [Clang 8.0.0 (clang-800.0.42.1)] on darwin > > > > Type "help", "copyright", "credits" or "license" for more information. > > > > >>> import test > > > > >>> test.main() > > > > Traceback (most recent call last): > > > > File "", line 1, in > > > > File "/Users/cameron/tmp/d1/test.py", line 2, in main > > > > print(rule) > > > > NameError: name 'rule' is not defined > > > > [Explanation snipped] > > > > > I didn't noticed that the interpreter has its own globals. Thanks for reminding. > > > > It's not really "the interpreter" (I think you mean the REPL) which has > > it's own globals. Every module/file has its own globals. > > > > The same thing happens non-interactively: > > > > % cat test.py > > def main(): > > print(rule) > > > > % cat foo.py > > #!/usr/bin/python3 > > > > from test import * > > > > rule = 42 > > main() > > > > % ./foo.py > > Traceback (most recent call last): > > File "./foo.py", line 6, in > > main() > > File "/home/hjp/tmp/test.py", line 2, in main > > print(rule) > > NameError: name 'rule' is not defined > > > > The "rule" identifier in main() refers to a "rule" variable in the > > module test. If you set a variable "rule" somewhere else (in foo.py or > > the REPL, ...), that has no effect. How should python know that you want > > to set the rule variable in the test module? > > > > hp > > > > -- > > _ | Peter J. Holzer | Story must make more sense than reality. > > |_|_) | | > > | | | hjp at hjp.at | -- Charles Stross, "Creative writing > > __/ | http://www.hjp.at/ | challenge!" > > > I innocently thought that when import module through "from test import *", I am working on test's globals under REPL. I didn't noticed the REPL has its own globals. > Ah, that's a fair point. If you specifically WANT that behaviour, what you can do is invoke the script interactively: python3 -i test.py That'll run the script as normal, and then drop you into the REPL. All your interactive globals *are* that module's globals. ChrisA From cs at cskk.id.au Sun Nov 3 20:17:26 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 4 Nov 2019 12:17:26 +1100 Subject: What's the difference between running a script under command box and interpreter? In-Reply-To: References: Message-ID: <20191104011726.GA5605@cskk.homeip.net> On 03Nov2019 16:34, Jach Fong wrote: >Peter J. Holzer? 2019?11?4???? UTC+8??3?59?36???? >> It's not really "the interpreter" (I think you mean the REPL) which >> has >> it's own globals. Every module/file has its own globals. >> >> The same thing happens non-interactively: >> >> % cat test.py >> def main(): >> print(rule) >> >> % cat foo.py >> #!/usr/bin/python3 >> >> from test import * >> >> rule = 42 >> main() >> >> % ./foo.py >> Traceback (most recent call last): >> File "./foo.py", line 6, in >> main() >> File "/home/hjp/tmp/test.py", line 2, in main >> print(rule) >> NameError: name 'rule' is not defined >> >> The "rule" identifier in main() refers to a "rule" variable in the >> module test. If you set a variable "rule" somewhere else (in foo.py or >> the REPL, ...), that has no effect. How should python know that you want >> to set the rule variable in the test module? [...] > >I innocently thought that when import module through "from test import *", I am working on test's globals under REPL. I didn't noticed the REPL has its own globals. Aye. An import statement is essentially a funny shaped assignment statement (aside from the side effect of loading the required module). When you go: from blah import foo You're getting a _local_ variable "foo" which references the same _value_ that "blah.foo" also references. But it is independent of "blah.foo"; assigning to it (changing what it references) does not change what "blah.foo" references. To take a concrete example, I've a tiny module "cs.x" which essentially supplies just a single function X() whose purpose it to write a debug message (no logging modules or other complications). So lots of my dev code has (while debugging): from cs.x import X and then: X("some message about %s", variable_name) X() normally just writes to sys.stderr, but it has some module level mode switches such X_via_tty which literally opens "/dev/tty" and writes to that, invented for situations where sys.stderr has been intercepted. Occasionally I need to set that mode (usually in a unit test I'm debugging). So I go: from cs.x import X # as normal import cs.x; cs.x.X_via_tty = True If I went: from cs.x import X, X_via_tty X_via_tty = True it wouldn't work. >>>> How should python know that you want to set the rule variable in the test module? > >My 'wrong' answer will be, at the time I raised my question, that when >import two different modules either has 'rule' variable, REPL will see >the second imported one. No kidding:-) Well: from mod1 import rule from mod2 import rule is like: import mod1 import mod2 rule = mod1.rule # copy reference rule = mod2.rule # copy the other reference Cheers, Cameron Simpson From originallmoney at gmail.com Sun Nov 3 20:52:07 2019 From: originallmoney at gmail.com (originallmoney at gmail.com) Date: Sun, 3 Nov 2019 17:52:07 -0800 (PST) Subject: Trouble trying to get started with pygame In-Reply-To: References: <412bf414-19a5-4937-90fd-3363cb78614b@googlegroups.com> <9313ee4c-7250-4c8f-804b-f468a0dd3c5a@googlegroups.com> <8fe30991-0ad2-632f-bb37-fc9881b8835f@mrabarnett.plus.com> Message-ID: <6798ae9c-8823-4dbb-ae16-06257e49d06a@googlegroups.com> On Friday, November 1, 2019 at 11:17:42 PM UTC-4, MRAB wrote: > On 2019-11-02 02:28, originallmoney at gmail.com wrote: > > I tried what you suggested at the command prompt and (Despite being able to open Python from my start menu), it tells me Python isn't installed. > > > > I'm curious, and, I probably should have mentioned it earlier: I have Python on my D drive (Because it has more space). Is THAT why it says Python isn't installed? MUST I have it on the C drive? > > > Do you mean that it can't find "py" or that "py" can't find Python? > > If you used the installer to install Python on the D drive, then I'd > expect it to just work. Sorry it took so long, I was working all day Saturday. Now, to answer your question: It's telling me that "py" can't find Python. Specifically, it says "No Installed Pythons Found". From jfong at ms4.hinet.net Sun Nov 3 20:56:04 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sun, 3 Nov 2019 17:56:04 -0800 (PST) Subject: What's the difference between running a script under command box and interpreter? In-Reply-To: References: <20191101092815.GA98493@cskk.homeip.net> <20191103195908.GA3944@hjp.at> Message-ID: <050695b7-4170-4e06-9be9-2a7ba25e785d@googlegroups.com> Chris Angelico? 2019?11?4???? UTC+8??8?43?07???? > On Mon, Nov 4, 2019 at 11:36 AM wrote: > > > > Peter J. Holzer? 2019?11?4???? UTC+8??3?59?36???? > > > On 2019-11-01 04:24:38 -0700, jfong at ms4.hinet.net wrote: > > > > > The globals are your current module's namespace, and functions defines > > > > > in a module are bound to that module's namespace. > > > > > > > > > > Strip your test.py back. A lot. Try this: > > > > > > > > > > def main(): > > > > > print(rule) > > > > > > > > > > Now, let's use that: > > > > > > > > > > Python 3.7.4 (default, Sep 28 2019, 13:34:38) > > > > > [Clang 8.0.0 (clang-800.0.42.1)] on darwin > > > > > Type "help", "copyright", "credits" or "license" for more information. > > > > > >>> import test > > > > > >>> test.main() > > > > > Traceback (most recent call last): > > > > > File "", line 1, in > > > > > File "/Users/cameron/tmp/d1/test.py", line 2, in main > > > > > print(rule) > > > > > NameError: name 'rule' is not defined > > > > > > [Explanation snipped] > > > > > > > I didn't noticed that the interpreter has its own globals. Thanks for reminding. > > > > > > It's not really "the interpreter" (I think you mean the REPL) which has > > > it's own globals. Every module/file has its own globals. > > > > > > The same thing happens non-interactively: > > > > > > % cat test.py > > > def main(): > > > print(rule) > > > > > > % cat foo.py > > > #!/usr/bin/python3 > > > > > > from test import * > > > > > > rule = 42 > > > main() > > > > > > % ./foo.py > > > Traceback (most recent call last): > > > File "./foo.py", line 6, in > > > main() > > > File "/home/hjp/tmp/test.py", line 2, in main > > > print(rule) > > > NameError: name 'rule' is not defined > > > > > > The "rule" identifier in main() refers to a "rule" variable in the > > > module test. If you set a variable "rule" somewhere else (in foo.py or > > > the REPL, ...), that has no effect. How should python know that you want > > > to set the rule variable in the test module? > > > > > > hp > > > > > > -- > > > _ | Peter J. Holzer | Story must make more sense than reality. > > > |_|_) | | > > > | | | hjp at hjp.at | -- Charles Stross, "Creative writing > > > __/ | http://www.hjp.at/ | challenge!" > > > > > > I innocently thought that when import module through "from test import *", I am working on test's globals under REPL. I didn't noticed the REPL has its own globals. > > > > Ah, that's a fair point. If you specifically WANT that behaviour, what > you can do is invoke the script interactively: > > python3 -i test.py > > That'll run the script as normal, and then drop you into the REPL. All > your interactive globals *are* that module's globals. > > ChrisA It surprises me that REPL has essential different behavior in these two situations. --Jach From rosuav at gmail.com Sun Nov 3 21:19:19 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Nov 2019 13:19:19 +1100 Subject: What's the difference between running a script under command box and interpreter? In-Reply-To: <050695b7-4170-4e06-9be9-2a7ba25e785d@googlegroups.com> References: <20191101092815.GA98493@cskk.homeip.net> <20191103195908.GA3944@hjp.at> <050695b7-4170-4e06-9be9-2a7ba25e785d@googlegroups.com> Message-ID: On Mon, Nov 4, 2019 at 1:01 PM wrote: > > Chris Angelico? 2019?11?4???? UTC+8??8?43?07???? > > Ah, that's a fair point. If you specifically WANT that behaviour, what > > you can do is invoke the script interactively: > > > > python3 -i test.py > > > > That'll run the script as normal, and then drop you into the REPL. All > > your interactive globals *are* that module's globals. > > > > ChrisA > > It surprises me that REPL has essential different behavior in these two situations. > Not really. In each case, the REPL lets you interactively execute code as part of a module. If you start with "-i somescript.py", it starts out by running the contents of that script; otherwise, you start with nothing (as if you ran "-i empty-file.py"). The REPL does the same thing every time; it's a difference between creating the functions directly and importing them. ChrisA From python at mrabarnett.plus.com Sun Nov 3 21:39:42 2019 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 4 Nov 2019 02:39:42 +0000 Subject: Trouble trying to get started with pygame In-Reply-To: <6798ae9c-8823-4dbb-ae16-06257e49d06a@googlegroups.com> References: <412bf414-19a5-4937-90fd-3363cb78614b@googlegroups.com> <9313ee4c-7250-4c8f-804b-f468a0dd3c5a@googlegroups.com> <8fe30991-0ad2-632f-bb37-fc9881b8835f@mrabarnett.plus.com> <6798ae9c-8823-4dbb-ae16-06257e49d06a@googlegroups.com> Message-ID: <3717e429-b1c3-8f6f-8dd3-50f89d2a21cc@mrabarnett.plus.com> On 2019-11-04 01:52, originallmoney at gmail.com wrote: > On Friday, November 1, 2019 at 11:17:42 PM UTC-4, MRAB wrote: >> On 2019-11-02 02:28, originallmoney at gmail.com wrote: >> > I tried what you suggested at the command prompt and (Despite being able to open Python from my start menu), it tells me Python isn't installed. >> > >> > I'm curious, and, I probably should have mentioned it earlier: I have Python on my D drive (Because it has more space). Is THAT why it says Python isn't installed? MUST I have it on the C drive? >> > >> Do you mean that it can't find "py" or that "py" can't find Python? >> >> If you used the installer to install Python on the D drive, then I'd >> expect it to just work. > > Sorry it took so long, I was working all day Saturday. > > Now, to answer your question: It's telling me that "py" can't find Python. Specifically, it says "No Installed Pythons Found". > I've just tried installing another version of Python on the D drive. It worked for me. Did you _install_ it onto drive D? When in doubt, uninstall and then re-install again. See if that fixes it. From jfong at ms4.hinet.net Sun Nov 3 23:14:15 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sun, 3 Nov 2019 20:14:15 -0800 (PST) Subject: What's the difference between running a script under command box and interpreter? In-Reply-To: References: <20191101092815.GA98493@cskk.homeip.net> <20191103195908.GA3944@hjp.at> <050695b7-4170-4e06-9be9-2a7ba25e785d@googlegroups.com> Message-ID: Chris Angelico? 2019?11?4???? UTC+8??10?19?50???? > On Mon, Nov 4, 2019 at 1:01 PM wrote: > > > > Chris Angelico? 2019?11?4???? UTC+8??8?43?07???? > > > Ah, that's a fair point. If you specifically WANT that behaviour, what > > > you can do is invoke the script interactively: > > > > > > python3 -i test.py > > > > > > That'll run the script as normal, and then drop you into the REPL. All > > > your interactive globals *are* that module's globals. > > > > > > ChrisA > > > > It surprises me that REPL has essential different behavior in these two situations. > > > > Not really. In each case, the REPL lets you interactively execute code > as part of a module. If you start with "-i somescript.py", it starts > out by running the contents of that script; otherwise, you start with > nothing (as if you ran "-i empty-file.py"). The REPL does the same > thing every time; it's a difference between creating the functions > directly and importing them. > > ChrisA I mean, taking this simple example: ---test.py--- def main(): print(rule) if __name__ == '__main__: rule = 1 main() --- case 1: py -i test.py 1 >>> globals() >>> main.__globals__ case 2: py >>> from test import * >>> globals() >>> main.__globals__ The result is much different. In case 1, the REPL and the module seems in the same global space:-) --Jach From rosuav at gmail.com Sun Nov 3 23:22:01 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Nov 2019 15:22:01 +1100 Subject: What's the difference between running a script under command box and interpreter? In-Reply-To: References: <20191101092815.GA98493@cskk.homeip.net> <20191103195908.GA3944@hjp.at> <050695b7-4170-4e06-9be9-2a7ba25e785d@googlegroups.com> Message-ID: On Mon, Nov 4, 2019 at 3:16 PM wrote: > > Chris Angelico? 2019?11?4???? UTC+8??10?19?50???? > > On Mon, Nov 4, 2019 at 1:01 PM wrote: > > > > > > Chris Angelico? 2019?11?4???? UTC+8??8?43?07???? > > > > Ah, that's a fair point. If you specifically WANT that behaviour, what > > > > you can do is invoke the script interactively: > > > > > > > > python3 -i test.py > > > > > > > > That'll run the script as normal, and then drop you into the REPL. All > > > > your interactive globals *are* that module's globals. > > > > > > > > ChrisA > > > > > > It surprises me that REPL has essential different behavior in these two situations. > > > > > > > Not really. In each case, the REPL lets you interactively execute code > > as part of a module. If you start with "-i somescript.py", it starts > > out by running the contents of that script; otherwise, you start with > > nothing (as if you ran "-i empty-file.py"). The REPL does the same > > thing every time; it's a difference between creating the functions > > directly and importing them. > > > > ChrisA > > I mean, taking this simple example: > ---test.py--- > def main(): > print(rule) > if __name__ == '__main__: > rule = 1 > main() > --- > > case 1: > py -i test.py > 1 > >>> globals() > >>> main.__globals__ > > case 2: > py > >>> from test import * > >>> globals() > >>> main.__globals__ > > The result is much different. In case 1, the REPL and the module seems in the same global space:-) > Yes. The difference is that one of them uses "import" and the other does not. ChrisA From ethan at stoneleaf.us Sun Nov 3 23:28:21 2019 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 3 Nov 2019 20:28:21 -0800 Subject: Friday finking: TDD and EAFP In-Reply-To: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> References: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> Message-ID: On 10/31/2019 10:40 PM, DL Neil via Python-list wrote: > Is the practice of TDD fundamentally, if not philosophically, somewhat contrary to Python's EAFP approach? Not at all. To use the maths example that's been going around: def sqrt(number): ... return some_value Your tests should do two things: - verify the function works for good values - verify the function fails for bad values Your sqrt function does not need to test input types -- just go through the algorithm and return the result. If an illegal operation occurs it will raise. EAFP means the caller of your sqrt function can pass in whatever values they want (float, int, fraction, whatever) and either get a good result, or deal with the raised exception. -- ~Ethan~ From originallmoney at gmail.com Mon Nov 4 00:21:45 2019 From: originallmoney at gmail.com (originallmoney at gmail.com) Date: Sun, 3 Nov 2019 21:21:45 -0800 (PST) Subject: Trouble trying to get started with pygame In-Reply-To: References: <412bf414-19a5-4937-90fd-3363cb78614b@googlegroups.com> <9313ee4c-7250-4c8f-804b-f468a0dd3c5a@googlegroups.com> <8fe30991-0ad2-632f-bb37-fc9881b8835f@mrabarnett.plus.com> <6798ae9c-8823-4dbb-ae16-06257e49d06a@googlegroups.com> <3717e429-b1c3-8f6f-8dd3-50f89d2a21cc@mrabarnett.plus.com> Message-ID: On Sunday, November 3, 2019 at 9:40:05 PM UTC-5, MRAB wrote: > On 2019-11-04 01:52, originallmoney at gmail.com wrote: > > On Friday, November 1, 2019 at 11:17:42 PM UTC-4, MRAB wrote: > >> On 2019-11-02 02:28, originallmoney at gmail.com wrote: > >> > I tried what you suggested at the command prompt and (Despite being able to open Python from my start menu), it tells me Python isn't installed. > >> > > >> > I'm curious, and, I probably should have mentioned it earlier: I have Python on my D drive (Because it has more space). Is THAT why it says Python isn't installed? MUST I have it on the C drive? > >> > > >> Do you mean that it can't find "py" or that "py" can't find Python? > >> > >> If you used the installer to install Python on the D drive, then I'd > >> expect it to just work. > > > > Sorry it took so long, I was working all day Saturday. > > > > Now, to answer your question: It's telling me that "py" can't find Python. Specifically, it says "No Installed Pythons Found". > > > I've just tried installing another version of Python on the D drive. It > worked for me. > > Did you _install_ it onto drive D? > > When in doubt, uninstall and then re-install again. See if that fixes it. I uninstalled, then reinstalled. However, when I tried to install pygame, it told me: "Neither 'setup.py' nor 'pyproject.toml' found". I even made sure the path was right (After I messed it up and it gave me an error telling me the path didn't exist). Fixed it. No more path error message, still tells me that neither setup nor pyproject were found. From dieter at handshake.de Mon Nov 4 01:19:15 2019 From: dieter at handshake.de (dieter) Date: Mon, 04 Nov 2019 07:19:15 +0100 Subject: Issue with running programs in Python and imports, probably directories messed up References: Message-ID: <878sow17vg.fsf@handshake.de> Vladyslav Verteletskyi writes: > I have stuck upon a problem with all of my attempts to import libraries to > Python. .... Find the > screenshots enclosed. This is a text only list: we (at least most of us) do not see attachments (such as attached screenshots). Use functions of your (windows) system to copy the text from your screen to your message. Do you mean with "import libraries" the import of Python modules/packages? In this case, "sys.path" controls where Python looks for them. Use: import sys print (sys.path) to check for those locations and put your "libraries" in one of those directories. From dieter at handshake.de Mon Nov 4 01:22:37 2019 From: dieter at handshake.de (dieter) Date: Mon, 04 Nov 2019 07:22:37 +0100 Subject: error with installing a package(matplotlib) References: Message-ID: <874kzk17pu.fsf@handshake.de> thodoris doultsinos writes: > I have been encountering problems with installing packages on python. I am > using windows 10, pycharm and pip install order in command prompt to > install packages.At first I had an error with installing numpy (something > with visual c++ so i downloaded them and it worked).Now i want to download > matplotlib and i have this error: > ... > /Tcsrc/checkdep_freetype2.c > /Fobuild\temp.win32-3.8\Release\src/checkdep_freetype2.obj > checkdep_freetype2.c > src/checkdep_freetype2.c(1): fatal error C1083: Cannot open include > file: 'ft2build.h': No such file or directory The error message likely indicates a missing external (= non-Python) dependency. Check the "matplotlib" installation instructions for its (non-Python) dependencies and ensure that your system can satify all of them. From dieter at handshake.de Mon Nov 4 01:35:37 2019 From: dieter at handshake.de (dieter) Date: Mon, 04 Nov 2019 07:35:37 +0100 Subject: Full stack trace in pdb.post_mortem() ? References: Message-ID: <87zhhcywqu.fsf@handshake.de> John W writes: > I'm trying to understand pdb.post_mortem(), and why the backtrace > available in the debugger session seems limited. > > I posted a similar question on stackoverflow[1], but figured I'd try > here as well. > > Here's a simple program > > import pdb > > def inner(): > raise Exception("bad stuff") > > def outer(): > try: > inner() > except Exception as ex: > pdb.post_mortem() > # using breakpoint() gives the full stack trace, of course > > def main(): > outer() > > main() > > When I run that, I get put in the debugger. > Then, if I run the `bt` command to get a backtrace, I see: > > (Pdb) bt > /path/to/script(10)outer() > -> inner() > > /path/to/script(6)inner() > -> raise Exception("bad stuff") > > As you can see, the backtrace only has `outer()` and `inner()`. > What happened to `main()`? "post_mortem" shows you the traceback from the frame where the exception occured until the current frame. Because you called "post_mortem" in "outer", the display will stop there (and do not include "main"). >I want the full stack available, so I can > investigate variables, etc. at any point along the chain. > (in a real example, there might be quite a lot of additional call > frames of interest) Then use "pdb.set_trace" instead of "pdb.post_mortem". From veek at dont-use-this.com Mon Nov 4 06:30:42 2019 From: veek at dont-use-this.com (Veek M) Date: Mon, 4 Nov 2019 11:30:42 -0000 (UTC) Subject: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run? Message-ID: 1. Why do I get True whenever i tuple the isinstance(f, (Bar, Foo)) (and why don't the print's run) The docs say that you can feed it a tuple and that the results are OR'd ---- The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut for isinstance(x, A) or isinstance(x, B) or ... (etc.). ----- which implies that the metaclasses are called for each class? class MyzMeta(type): def __instancecheck__(cls, other): print('MyzzzzzzMeta', other) return 0 class MyMeta(MyzMeta, object): def __instancecheck__(cls, other): print('MyMeta') print(cls, other) return 0 class Foo(list): __metaclass__ = MyzMeta pass class Miaow(object): pass class Bar(Foo, Miaow): __metaclass__ = MyMeta pass f = Foo() b = Bar() print(isinstance(f, (Bar, Foo))) raise SystemExit if isinstance(f, (Bar, Foo)): print('success') From nimbiotics at gmail.com Mon Nov 4 08:17:05 2019 From: nimbiotics at gmail.com (Mario R. Osorio) Date: Mon, 4 Nov 2019 05:17:05 -0800 (PST) Subject: Congratulations to @Chris In-Reply-To: References: <120f075d-9854-94e8-3fa2-3afa7d8a9b33@etelligence.info> Message-ID: <2dd64f1c-d4af-4b1f-a041-e95d8ddab556@googlegroups.com> On Thursday, October 24, 2019 at 4:29:59 PM UTC-4, Chris Angelico wrote: > On Fri, Oct 25, 2019 at 7:20 AM DL Neil via Python-list > wrote: > > > > Chris Angelico: [PSF's] 2019 Q2 Community Service Award Winner > > http://pyfound.blogspot.com/2019/10/chris-angelico-2019-q2-community.html > > > > ...and for the many assistances and pearls of wisdom he has contributed > > 'here'! > > Thanks! It's been great hanging out on these channels/lists/whatever > you call 'here'. I originally joined python-list in relation to a > project that moved away from Python, then got badly bogged down in > everyone's favourite problem, scope creep. And then it died. But in > the meantime, I was very much appreciating the community here, and > both learning and contributing. It's been an awesome ride, and I've > learned so much from so many people here. > > So, a big thank you to all the regulars here - you know who you are - > and also to the occasional contributors too. (I feel like I'm thanking > everyone at the end of a live stream or something, but it's true - > lurkers are important too.) > > ChrisA Enhorabuena! From rhodri at kynesim.co.uk Mon Nov 4 08:44:22 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 4 Nov 2019 13:44:22 +0000 Subject: OOP - iterable class: how to delete one of its objects ? In-Reply-To: References: <2dda1f94-6f74-5c10-3965-18fc57e98e6b@kynesim.co.uk> Message-ID: <1f2b6dc9-a29c-61b5-3127-d75f3185330f@kynesim.co.uk> On 02/11/2019 06:30, R.Wieser wrote: > Rhodri, > >> Use weak references. A WeakSet >> (https://docs.python.org/3/library/weakref.html#weakref.WeakSet) is >> probably what you want. > > Most likely! As a fresh freshling in regard to python I was not even > aware that a "copy object, but do not increment the reference count" > existed. Thank you. > > Could cause some interresting "the object has disappeared!" problems when > you're not carefull with it though ... :-) Yes, it can. That's why you want to create a finalizer to tidy up. -- Rhodri James *-* Kynesim Ltd From rhodri at kynesim.co.uk Mon Nov 4 09:10:06 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 4 Nov 2019 14:10:06 +0000 Subject: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run? In-Reply-To: References: Message-ID: <6bf1b099-c655-5c60-306a-612056c6c26d@kynesim.co.uk> On 04/11/2019 11:30, Veek M wrote: > 1. Why do I get True whenever i tuple the > isinstance(f, (Bar, Foo)) > (and why don't the print's run) I'm not very familiar with metaclasses, but I can answer the second part of your question. > > The docs say that you can feed it a tuple and that the results are OR'd > > ---- > The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut for > isinstance(x, A) or isinstance(x, B) or ... (etc.). > ----- > which implies that the metaclasses are called for each class? > > > class MyzMeta(type): > def __instancecheck__(cls, other): > print('MyzzzzzzMeta', other) > return 0 > > > class MyMeta(MyzMeta, object): > def __instancecheck__(cls, other): > print('MyMeta') > print(cls, other) > return 0 > > > class Foo(list): > __metaclass__ = MyzMeta > pass > > class Miaow(object): > pass > > class Bar(Foo, Miaow): > __metaclass__ = MyMeta > pass Aha. You're trying to fix up the metaclass after the fact, which is not the right way to do it. If you change the class definitions to: class Foo(list, metaclass=MyzMeta): pass class Bar(Foo, Miaow, metaclass=MyMeta): pass then you get the prints from MyMeta.__instancecheck__(). The isinstance() still returns True, though, and I don't know why. Then again, your definition of MyMeta is really weird. > > > f = Foo() > b = Bar() > > print(isinstance(f, (Bar, Foo))) -- Rhodri James *-* Kynesim Ltd From veek at dont-use-this.com Mon Nov 4 09:33:44 2019 From: veek at dont-use-this.com (Veek M) Date: Mon, 4 Nov 2019 14:33:44 -0000 (UTC) Subject: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run? References: <6bf1b099-c655-5c60-306a-612056c6c26d@kynesim.co.uk> Message-ID: > > Aha. You're trying to fix up the metaclass after the fact, which is not > the right way to do it. If you change the class definitions to: > __metaclass__ = whatever; # is python2.x syntax > then you get the prints from MyMeta.__instancecheck__(). The > isinstance() still returns True, though, and I don't know why. Then > again, your definition of MyMeta is really weird. weird how..? (I'm just trying to figure out what's going on with __instancecheck__ - no further higher purpose :p) example, when we do: isinstance(x, (A, B, C)) you expect from the docs that A.__instancecheck__(cls, x) is passed but x = [] also, B and C.__instancecheck__ is not called when I return False Also if I interchange (Bar, Foo), expecting that Foo.__instancecheck__ will be called, it's completely bypassed From rhodri at kynesim.co.uk Mon Nov 4 09:54:23 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 4 Nov 2019 14:54:23 +0000 Subject: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run? In-Reply-To: References: <6bf1b099-c655-5c60-306a-612056c6c26d@kynesim.co.uk> Message-ID: On 04/11/2019 14:33, Veek M wrote: >> >> Aha. You're trying to fix up the metaclass after the fact, which is not >> the right way to do it. If you change the class definitions to: >> > __metaclass__ = whatever; # is python2.x syntax But not Python3: see PEP 3115 >> then you get the prints from MyMeta.__instancecheck__(). The >> isinstance() still returns True, though, and I don't know why. Then >> again, your definition of MyMeta is really weird. > > weird how..? > (I'm just trying to figure out what's going on with __instancecheck__ - > no further higher purpose :p) > > example, when we do: isinstance(x, (A, B, C)) > you expect from the docs that > A.__instancecheck__(cls, x) is passed but x = [] > also, B and C.__instancecheck__ is not called when I return False > > Also if I interchange (Bar, Foo), expecting that Foo.__instancecheck__ > will be called, it's completely bypassed That must be what's responsible for the True result. Logically the problem must be to do with your MyzMeta class then. I have no idea what. -- Rhodri James *-* Kynesim Ltd From address at not.available Mon Nov 4 09:53:21 2019 From: address at not.available (R.Wieser) Date: Mon, 4 Nov 2019 15:53:21 +0100 Subject: OOP - iterable class: how to delete one of its objects ? References: <2dda1f94-6f74-5c10-3965-18fc57e98e6b@kynesim.co.uk> <1f2b6dc9-a29c-61b5-3127-d75f3185330f@kynesim.co.uk> Message-ID: Rhodri, > Yes, it can. That's why you want to create a finalizer to tidy up. AFAIKS in my case there is nothing to cleanup. As far as I understood the WeakSet will automagically purge the reference whe the object it references is destroyed. I could also try to do it in in the __del__ method though. Regards, Rudy Wieser From address at not.available Mon Nov 4 10:32:54 2019 From: address at not.available (R.Wieser) Date: Mon, 4 Nov 2019 16:32:54 +0100 Subject: OOP - how to abort an __init__ when the initialisation code fails ? Message-ID: Hello all, The whole question: How should I handle failed initialisation code inside the __init__ of an object ? I've seen an example doing a plain "return" (of the value "none""), but have no idea if that is all it takes. Also, I wonder what happens to the object itself. Does it still exist and only gets actually destroyed at the next garbage-collection (because of a zero reference count), or is it directly discarded (without having called the __del__ method) ? Regards, Rudy Wieser From veek at dont-use-this.com Mon Nov 4 11:11:17 2019 From: veek at dont-use-this.com (Veek M) Date: Mon, 4 Nov 2019 16:11:17 -0000 (UTC) Subject: What PEPs are worth reading after you've read a textbook/Beazley but want to understand details/innerworkings Message-ID: sez it all really, among the Finished PEPs, which ones should I pore through to teach Python competently! What PEPs are considered de rigueur? What PEPs do you guys consider note- worthy? https://www.python.org/dev/peps/ From grant.b.edwards at gmail.com Mon Nov 4 11:41:00 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 4 Nov 2019 16:41:00 -0000 (UTC) Subject: What's the difference between running a script under command box and interpreter? References: <20191101092815.GA98493@cskk.homeip.net> <20191103195908.GA3944@hjp.at> <21k0sehispcbakbe0cufc4tidarcngt3hh@4ax.com> Message-ID: On 2019-11-04, Dennis Lee Bieber wrote: > Using > > from module import * > > is often the worst thing one can do. I agree 100%. Unfortunately, most of the official standard library documentation is written assuming you do _exactly_that_. Though it makes the documetnation more succinct, I think it encourages bad behavior and causes a lot of problems. -- Grant Edwards grant.b.edwards Yow! I wonder if I could at ever get started in the gmail.com credit world? From rgaddi at highlandtechnology.invalid Mon Nov 4 12:26:08 2019 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Mon, 4 Nov 2019 09:26:08 -0800 Subject: OOP - how to abort an __init__ when the initialisation code fails ? In-Reply-To: References: Message-ID: On 11/4/19 7:32 AM, R.Wieser wrote: > Hello all, > > The whole question: How should I handle failed initialisation code inside > the __init__ of an object ? > > I've seen an example doing a plain "return" (of the value "none""), but have > no idea if that is all it takes. > > Also, I wonder what happens to the object itself. Does it still exist and > only gets actually destroyed at the next garbage-collection (because of a > zero reference count), or is it directly discarded (without having called > the __del__ method) ? > > Regards, > Rudy Wieser > > Raise an exception. Returning None will specifically NOT accomplish the thing you want; nothing ever checks the return value of __init__. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From luciano at ramalho.org Mon Nov 4 13:36:00 2019 From: luciano at ramalho.org (Luciano Ramalho) Date: Mon, 4 Nov 2019 15:36:00 -0300 Subject: OOP - how to abort an __init__ when the initialisation code fails ? In-Reply-To: References: Message-ID: Sorry, I responded only to the OP. My response: """A failed __init__ should raise an appropriate exception. A bare return or returning None is what any __init__ is expected to do in the normal case, so it signals success.""" Actually, the Python interpreter *does* check the return of __init__. If it is anything other than None, Python 3 raises TypeError when you try to create an instance: >>> class X: ... def __init__(self): ... return 1 ... >>> x = X() Traceback (most recent call last): File "", line 1, in TypeError: __init__() should return None, not 'int' Cheers, Luciano On Mon, Nov 4, 2019 at 2:31 PM Rob Gaddi wrote: > > On 11/4/19 7:32 AM, R.Wieser wrote: > > Hello all, > > > > The whole question: How should I handle failed initialisation code inside > > the __init__ of an object ? > > > > I've seen an example doing a plain "return" (of the value "none""), but have > > no idea if that is all it takes. > > > > Also, I wonder what happens to the object itself. Does it still exist and > > only gets actually destroyed at the next garbage-collection (because of a > > zero reference count), or is it directly discarded (without having called > > the __del__ method) ? > > > > Regards, > > Rudy Wieser > > > > > > Raise an exception. Returning None will specifically NOT accomplish the thing > you want; nothing ever checks the return value of __init__. > > -- > Rob Gaddi, Highland Technology -- www.highlandtechnology.com > Email address domain is currently out of order. See above to fix. > -- > https://mail.python.org/mailman/listinfo/python-list -- Luciano Ramalho | Author of Fluent Python (O'Reilly, 2015) | http://shop.oreilly.com/product/0636920032519.do | Technical Principal at ThoughtWorks | Twitter: @ramalhoorg From rgaddi at highlandtechnology.invalid Mon Nov 4 13:55:37 2019 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Mon, 4 Nov 2019 10:55:37 -0800 Subject: OOP - how to abort an __init__ when the initialisation code fails ? In-Reply-To: References: Message-ID: On 11/4/19 10:36 AM, Luciano Ramalho wrote: > Sorry, I responded only to the OP. My response: > > """A failed __init__ should raise an appropriate exception. A bare > return or returning None is what any __init__ is expected to do in the > normal case, so it signals success.""" > > Actually, the Python interpreter *does* check the return of __init__. > If it is anything other than None, Python 3 raises TypeError when you > try to create an instance: > >>>> class X: > ... def __init__(self): > ... return 1 > ... >>>> x = X() > Traceback (most recent call last): > File "", line 1, in > TypeError: __init__() should return None, not 'int' > > Cheers, > > Luciano > > > On Mon, Nov 4, 2019 at 2:31 PM Rob Gaddi > wrote: > >> [snip] >> Raise an exception. Returning None will specifically NOT accomplish the thing >> you want; nothing ever checks the return value of __init__. >> I'll be damned; you're right. Learn something new every day. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From address at not.available Mon Nov 4 13:59:06 2019 From: address at not.available (R.Wieser) Date: Mon, 4 Nov 2019 19:59:06 +0100 Subject: OOP - how to abort an __init__ when the initialisation code fails ? References: Message-ID: Rob, > Returning None will specifically NOT accomplish the thing you want; > nothing ever checks the return value of __init__. I thought to have read that when you return a none from it the object itself would return a placeholder singleton. > Raise an exception. Yeah, that was what I was thinking too - up until the moment I realized that the than-needed "try" around creating the object would catch /all/ errors in there, and not just the "can't initialize" one ... I might have misunderstood that though. Regards, Rudy Wieser From address at not.available Mon Nov 4 14:04:14 2019 From: address at not.available (R.Wieser) Date: Mon, 4 Nov 2019 20:04:14 +0100 Subject: OOP - how to abort an __init__ when the initialisation code fails ? References: Message-ID: Luciano, > """A failed __init__ should raise an appropriate exception. A bare > return or returning None is what any __init__ is expected to do in the > normal case, so it signals success.""" Ah, that settles it than. Somehow I thought that a return (of "none") there indicated an error result, causing the object to return .. something empty. Thanks. Regards, Rudy Wieser From python at mrabarnett.plus.com Mon Nov 4 14:11:44 2019 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 4 Nov 2019 19:11:44 +0000 Subject: Trouble trying to get started with pygame In-Reply-To: References: <412bf414-19a5-4937-90fd-3363cb78614b@googlegroups.com> <9313ee4c-7250-4c8f-804b-f468a0dd3c5a@googlegroups.com> <8fe30991-0ad2-632f-bb37-fc9881b8835f@mrabarnett.plus.com> <6798ae9c-8823-4dbb-ae16-06257e49d06a@googlegroups.com> <3717e429-b1c3-8f6f-8dd3-50f89d2a21cc@mrabarnett.plus.com> Message-ID: On 2019-11-04 05:21, originallmoney at gmail.com wrote: > On Sunday, November 3, 2019 at 9:40:05 PM UTC-5, MRAB wrote: >> On 2019-11-04 01:52, originallmoney at gmail.com wrote: >> > On Friday, November 1, 2019 at 11:17:42 PM UTC-4, MRAB wrote: >> >> On 2019-11-02 02:28, originallmoney at gmail.com wrote: >> >> > I tried what you suggested at the command prompt and (Despite being able to open Python from my start menu), it tells me Python isn't installed. >> >> > >> >> > I'm curious, and, I probably should have mentioned it earlier: I have Python on my D drive (Because it has more space). Is THAT why it says Python isn't installed? MUST I have it on the C drive? >> >> > >> >> Do you mean that it can't find "py" or that "py" can't find Python? >> >> >> >> If you used the installer to install Python on the D drive, then I'd >> >> expect it to just work. >> > >> > Sorry it took so long, I was working all day Saturday. >> > >> > Now, to answer your question: It's telling me that "py" can't find Python. Specifically, it says "No Installed Pythons Found". >> > >> I've just tried installing another version of Python on the D drive. It >> worked for me. >> >> Did you _install_ it onto drive D? >> >> When in doubt, uninstall and then re-install again. See if that fixes it. > > I uninstalled, then reinstalled. However, when I tried to install pygame, it told me: "Neither 'setup.py' nor 'pyproject.toml' found". > > I even made sure the path was right (After I messed it up and it gave me an error telling me the path didn't exist). Fixed it. No more path error message, still tells me that neither setup nor pyproject were found. > Can py find Python? Did you try to install pygame with: py -m pip install pygame From rosuav at gmail.com Mon Nov 4 14:36:12 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Nov 2019 06:36:12 +1100 Subject: What PEPs are worth reading after you've read a textbook/Beazley but want to understand details/innerworkings In-Reply-To: References: Message-ID: On Tue, Nov 5, 2019 at 3:16 AM Veek M wrote: > > sez it all really, among the Finished PEPs, which ones should I pore > through to teach Python competently! > > What PEPs are considered de rigueur? What PEPs do you guys consider note- > worthy? > > https://www.python.org/dev/peps/ That's a really awesome question! I would say that there are none that are absolutely essential, but quite a few that could be of interest. Famous PEPs: PEP 8 (style guide, often misunderstood), PEP 1 (info about PEPs themselves), PEP 20 (import this), PEP 393 Funny PEPs: PEP 404, PEP 628, PEP 313, PEP 666 Controversial PEPs: PEP 308, PEP 465 (kinda - it represents the culmination of a lot of years of discussion), PEP 479, PEP 498 PEPs that result in no changes: PEP 3099, PEP 240, PEPs 276 and 284, PEP 3142 This is from a bit of brainstorming, plus flipping through PEP 0 (the index of all PEPs) and recollecting or recognizing which ones keep getting referenced. I'm curious to see which PEPs get other people's recommendation. What are the glaringly obvious omissions from my collection? ChrisA From rgaddi at highlandtechnology.invalid Mon Nov 4 14:41:34 2019 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Mon, 4 Nov 2019 11:41:34 -0800 Subject: OOP - how to abort an __init__ when the initialisation code fails ? In-Reply-To: References: Message-ID: On 11/4/19 10:59 AM, R.Wieser wrote: > Rob, > >> Returning None will specifically NOT accomplish the thing you want; >> nothing ever checks the return value of __init__. > > I thought to have read that when you return a none from it the object itself > would return a placeholder singleton. > >> Raise an exception. > > Yeah, that was what I was thinking too - up until the moment I realized that > the than-needed "try" around creating the object would catch /all/ errors in > there, and not just the "can't initialize" one ... I might have > misunderstood that though. > > Regards, > Rudy Wieser > > A function with no explicit return returns None; every function returns something. __init__ is not an object creation function (that's __new__), it initializes an already created object that we traditionally call "self". When you exception out of __init__, it causes that initial assignment of the newly created (but only halfway initialized) object to fail, so no one winds up holding a reference to it. Because no one's holding a reference to it, it gets deleted (one day). That's why if you for instance, open a serial port in an __init__ routine, and something fails, you want to catch the exception there in __init__, explicitly close that serial port, and reraise the exception. Otherwise that port still has an object open against it until Python gets around to closing it. The exception you raise should indicate why it failed, such as a TypeError or ValueError if one of the arguments was some flavor of stupid, or a ConnectionRefusedError. Often the exception will already raise itself, and it's simply a matter of not getting in its way. But if the concern is the try..except block around the initialization catching too many things, then either a) your try block is too long and encompasses too many unrelated lines of code, or b) your except condition is too broad. Don't "except Exception". Only catch specific exceptions where you can provide benefit by doing do. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From address at not.available Mon Nov 4 15:45:28 2019 From: address at not.available (R.Wieser) Date: Mon, 4 Nov 2019 21:45:28 +0100 Subject: OOP - how to abort an __init__ when the initialisation code fails ? References: Message-ID: Rob, > That's why if you for instance, open a serial port in an __init__ routine, > and something fails, you want to catch the exception there in __init__, > explicitly close that serial port, and reraise the exception. Otherwise > that port still has an object open against it until Python gets around to > closing it. Thats pretty-much the situation I'm trying to jump into (Raspberry Pi, I2C related). > The exception you raise should indicate why it failed, such as a TypeError > or ValueError if one of the arguments was some flavor of stupid, or a > ConnectionRefusedError. I'll probably just play it safe, and just recast what the exception I just caught gave me. > But if the concern is the try..except block around the initialization > catching too many things, then either a) your try block is too long and > encompasses too many unrelated lines of code, or b) your except condition > is too broad I was thinking of (the needed) wrapping of the "newObject = classObject()" line in such a try..except block (to capture the re-casted exception). I take it that that that means that the full contents of the __init__ block are wrapped too. > or b) your except condition is too broad. Don't "except Exception". Only > catch specific exceptions where you can provide benefit by doing do. And that means I have to study the "try ... except" methodology a bit more, as I've currently got only a fleeting knowledge to how it works (including which error classes it can selectivily catch/filter). Regards, Rudy Wieser From hjp-python at hjp.at Mon Nov 4 16:05:21 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 4 Nov 2019 22:05:21 +0100 Subject: What's the difference between running a script under command box and interpreter? In-Reply-To: References: <20191101092815.GA98493@cskk.homeip.net> <20191103195908.GA3944@hjp.at> Message-ID: <20191104210521.GA8751@hjp.at> On 2019-11-03 16:34:39 -0800, jfong at ms4.hinet.net wrote: > I innocently thought that when import module through "from test import > *", I am working on test's globals under REPL. I didn't noticed the > REPL has its own globals. Well, you imported every global from test. So you are (kind of) working on those globals, or at least the objects they are referencing. In the real world, when you import a car from Germany, the car is now in your country, but you are not in Germany. Even if you import all the cars from Germany, you are still not in Germany. It's the same way in Python. Well, kind of. One important difference is that when you import a car from Germany, that car is no longer in Germany. But when you import a symbol from a Python module, that symbol still exists in that module. You just have a second symbol in your namespace referencing the same object (as Cameron pointed out). hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From python at mrabarnett.plus.com Mon Nov 4 16:18:36 2019 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 4 Nov 2019 21:18:36 +0000 Subject: What's the difference between running a script under command box and interpreter? In-Reply-To: <20191104210521.GA8751@hjp.at> References: <20191101092815.GA98493@cskk.homeip.net> <20191103195908.GA3944@hjp.at> <20191104210521.GA8751@hjp.at> Message-ID: <917a9630-0cd8-7109-b017-c86b5d9e35bc@mrabarnett.plus.com> On 2019-11-04 21:05, Peter J. Holzer wrote: > On 2019-11-03 16:34:39 -0800, jfong at ms4.hinet.net wrote: >> I innocently thought that when import module through "from test import >> *", I am working on test's globals under REPL. I didn't noticed the >> REPL has its own globals. > > Well, you imported every global from test. So you are (kind of) working > on those globals, or at least the objects they are referencing. > > In the real world, when you import a car from Germany, the car is now in > your country, but you are not in Germany. Even if you import all the > cars from Germany, you are still not in Germany. > > It's the same way in Python. > > Well, kind of. One important difference is that when you import a car > from Germany, that car is no longer in Germany. But when you import a > symbol from a Python module, that symbol still exists in that module. > You just have a second symbol in your namespace referencing the same > object (as Cameron pointed out). > The car itself isn't in Germany or your own country, it's just "somewhere". All you've imported is a (copy of a) reference to that car, under some name, and there can be other references to it in other places too, possibly under the same name, possibly under a different name. From luciano at ramalho.org Mon Nov 4 16:18:39 2019 From: luciano at ramalho.org (Luciano Ramalho) Date: Mon, 4 Nov 2019 18:18:39 -0300 Subject: OOP - how to abort an __init__ when the initialisation code fails ? In-Reply-To: References: Message-ID: On Mon, Nov 4, 2019 at 5:52 PM R.Wieser
wrote: > I was thinking of (the needed) wrapping of the "newObject = classObject()" > line in such a try..except block (to capture the re-casted exception). I > take it that that that means that the full contents of the __init__ block > are wrapped too. Python is not Java (also the title of a great post, look for it). In this context, what I mean by that quote is to say that Python never forces you to wrap anything in try/except blocks. Sometimes there is nothing your program can do to fix the issue, so let the exception run its course and terminate the program. The only reason to catch an exception prior to aborting is to provide a better error message, or log something. But in many situations aborting with a traceback is good enough, and it costs 0. In addition, as Rob said, it is usually a bad idea to wrap several lines of code in a single try/except block, because that makes it difficult to be specific when handling the different exceptions that may happen. You should strive to be as specific as possible in the exceptions that you choose to handle, and that pretty much requires wrapping few (often just one) line of code in a try/except block. > > or b) your except condition is too broad. Don't "except Exception". Only > > catch specific exceptions where you can provide benefit by doing do. > > And that means I have to study the "try ... except" methodology a bit more, > as I've currently got only a fleeting knowledge to how it works (including > which error classes it can selectivily catch/filter). Yes, you totally should learn how try/except works in Python, and also learn a bit of Python culture, "the way we do things around here" ;-). It is considered totally OK to use exception handling as a control flow mechanism in Python. The interpreter and the standard library have many examples of exceptions that do not signal errors, but merely that something happened. For example, at a low level, Python iterators/generators (pretty much synonyms around here) raise StopIteration to signal the iterating for loop that there are no more items. So the for statement implementation swallows StopIteration and cleanly ends the loop. Another example: the built-in function hasattr(obj, name) is actually implemented (in C) by calling getattr(obj, name) and returning True if no exception is raised, or False if AttributeError is raised. That is common Python style. Cheers, Luciano > > Regards, > Rudy Wieser > > > -- > https://mail.python.org/mailman/listinfo/python-list -- Luciano Ramalho | Author of Fluent Python (O'Reilly, 2015) | http://shop.oreilly.com/product/0636920032519.do | Technical Principal at ThoughtWorks | Twitter: @ramalhoorg From hjp-python at hjp.at Mon Nov 4 17:18:37 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 4 Nov 2019 23:18:37 +0100 Subject: Friday finking: TDD and EAFP In-Reply-To: References: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> <74263897-D40B-4EAD-957E-C1FF43A26F6F@gmail.com> <2500afa5-84ae-e5fc-a73c-4091681068e6@DancesWithMice.info> <20191103204437.GB3944@hjp.at> Message-ID: <20191104221837.GB8751@hjp.at> On 2019-11-03 18:51:25 -0500, Terry Reedy wrote: > On 11/3/2019 3:44 PM, Peter J. Holzer wrote: > > > On 2019-11-04 07:41:32 +1300, DL Neil via Python-list wrote: > > > Agreed: (in theory) TDD is independent of language or style. However, I'm > > > wondering if (in practice) it creates a mode of thinking that pushes one > > > into an EAFP way of thinking? > > > > This is exactly the opposite of what you proposed in your first mail, > > and I think it is closer to the truth: > > > > TDD does in my opinion encourage EAFP thinking. > > As in "use the code and if it fails, add a test and fix it" versus "if the > code can be proven correct, use it". Yup. > > The TDD is usually: > > > > 1 Write a test > > 2 Write the minimal amount of code that makes the test pass > > 3 If you think you have covered the whole spec, stop, else repeat > > from 1 > > > > This is often (e.g. in [1]) exaggerated for pedagogic and humoristic > > reasons. For example, your first test for a sqrt function might be > > assert(sqrt(4) == 2) > > and then of course the minimal implementation is > > def sqrt(x): > > return 2 > > The *is* exaggerated. Yes. But Percival at least (and he isn't the only one) makes a point that you really should do this. I think there are two reasons for this: * For the beginner, it's kind of a drill. Do something simple and mindless over and over, so that it becomes a habit. For the expert, it becomes a ritual: Puts you into the right mindset. * It prevents you from getting ahead of yourself: Without the reminder to keep the implementation minimal it is too easy to skip ahead: Write one simple test, then implement the whole function/class/program. Your function/class/program will pass the test, but it will include a lot of functionality which isn't tested (I plead guilty of having done this) > I usually try to also test with larger 'normal' values. When possible, we > could and I think should make more use of randomized testing. I got this > from reading about the Hypothesis module. See below for one example. A > similar example for multiplication might test > assertEqual(a*b + b, (a+1)*b) > where a and b are random ints. Yeah, randomizing inputs, cross-checks, etc. are important. I didn't want to give the impression that tests must be as simple as my example. > Possible test for math.sqrt. > > from math import sqrt > from random import randint > import unittest > > class SqrtTest(unittest.TestCase): > > def test_small_counts(self): > for i in range(3): > with self.subTest(i=i): > self.assertEqual(sqrt(i*i), i) > > def test_random_counts(self): > for i in range(100): # Number of subtests. > with self.subTest(): > n = randint(0, 9999999) > self.assertEqual(sqrt(n*n), float(n)) > > def test_negative_int(self): > self.assertRaises(ValueError, sqrt, -1) > > unittest.main() Interesting. Your test suite has only testcases where the result is an integer. So sqrt(5) or sqrt(3.14) might return completely wrong results or not even be implemented at all. I think this is a good example of what I was thinking of when I wrote this paragraph: > > There is very little emphasis in TDD on verifying that the code is > > correct - only that it passes the tests. > > For the kind of business (non-math) code that seems to be the stimulus for > TDD ideas, there often is no global definition of 'correct'. I'd say that there is some specification which defines what "correct" is (even if that specification exists only vaguely in the mind of the customer). The act of writing test cases necessarily reduces this holistic definition to a number of isolated points. The art of writing test cases is to write them in such a way that you can reason about having covered the whole problem space. The art of writing a program in TDD then consists in finding a solution which satisfies all test cases. This is not the same as trying to find a solution to the problem posed by the specification. Ideally, the solution will be the same, but the way to it is different and there is no guarantuee that the result will be tha same. Don't get me wrong - I think tests are very important and I'm trying to get into the same habit of writing tests in Python I had when I was writing Perl. And I think that it makes a lot of sense to write tests first and only make changes for which you have a test. But I can't help feeling that TDD encourages a "make random changes until all tests pass" style of programming instead of a "reason about the code" style of programming. (But the programmer I know who seems to hail from the school of random changes doesn't write tests, either, so it's probably unfair of me to hang that albatross around TDD's neck.) hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- 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 Nov 4 17:23:25 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 4 Nov 2019 23:23:25 +0100 Subject: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run? In-Reply-To: References: <6bf1b099-c655-5c60-306a-612056c6c26d@kynesim.co.uk> Message-ID: <20191104222325.GC8751@hjp.at> On 2019-11-04 14:54:23 +0000, Rhodri James wrote: > On 04/11/2019 14:33, Veek M wrote: > > __metaclass__ = whatever; # is python2.x syntax > > But not Python3: see PEP 3115 Doesn't "X is python2.x syntax" imply "X is not python3 syntax"? hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From hongyi.zhao at gmail.com Mon Nov 4 18:11:19 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Mon, 4 Nov 2019 23:11:19 +0000 (UTC) Subject: Is there some python libary for edit iso file drectly? Message-ID: Is there some python libary for edit iso file drectly? From jfong at ms4.hinet.net Mon Nov 4 20:05:05 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 4 Nov 2019 17:05:05 -0800 (PST) Subject: What's the difference between running a script under command box and interpreter? In-Reply-To: References: <20191101092815.GA98493@cskk.homeip.net> <20191103195908.GA3944@hjp.at> <21k0sehispcbakbe0cufc4tidarcngt3hh@4ax.com> Message-ID: <32c26f4d-7e7b-4e6c-b562-b4255d435e80@googlegroups.com> Grant Edwards? 2019?11?5???? UTC+8??12?41?24???? > On 2019-11-04, Dennis Lee Bieber wrote: > > Using > > > > from module import * > > > > is often the worst thing one can do. > > I agree 100%. > > Unfortunately, most of the official standard library documentation is > written assuming you do _exactly_that_. > > Though it makes the documetnation more succinct, I think it encourages > bad behavior and causes a lot of problems. > > -- > Grant Edwards grant.b.edwards Yow! I wonder if I could > at ever get started in the > gmail.com credit world? I don't use this phrase in my files, but sometime I use it under REPL. I don't think it's bad showing in the document, at least it will teach someone who was bitten by this phrase something unique in Python:-) --Jach From FvLieshout at outlook.com Mon Nov 4 16:56:25 2019 From: FvLieshout at outlook.com (Francois van Lieshout) Date: Mon, 4 Nov 2019 21:56:25 +0000 Subject: Fwd: permission denied using python 3.8 In-Reply-To: References: Message-ID: Outlook voor Android downloaden ________________________________ Van: Francois van Lieshout Verstuurd: maandag 4 november 2019 18:19 Aan: python-list at python.org Onderwerp: permission denied using python 3.8 Hi, i installed python 3.8 the latest version but it doesn?t work, i get ?permission denied? when trying to acces python in the CLI and also i can?t run my code from my python files in the command-line nor in IDLE. I?d like to know why this is so. I?ve tried the 64 bit and the 32 bit executable version of 3.8 but without succes. So i reinstalled version 3.7.2 and now everything works fine again. Can you tell me why i can?t use python 3.8, i?m using windows as OS. Thanks. From torriem at gmail.com Mon Nov 4 22:13:05 2019 From: torriem at gmail.com (Michael Torrie) Date: Mon, 4 Nov 2019 20:13:05 -0700 Subject: Is there some python libary for edit iso file drectly? In-Reply-To: References: Message-ID: <07e3d891-59a6-7588-45cd-2808693eb884@gmail.com> On 11/4/19 4:11 PM, Hongyi Zhao wrote: > Is there some python libary for edit iso file drectly? Isn't an ISO image a read-only sort of thing? If you want to modify files don't you have to create a whole new image? From dieter at handshake.de Tue Nov 5 01:42:13 2019 From: dieter at handshake.de (dieter) Date: Tue, 05 Nov 2019 07:42:13 +0100 Subject: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run? References: Message-ID: <87bltqese2.fsf@handshake.de> Veek M writes: I simplify your code to demonstrate what goes on: >>> class MA(type): ... def __instancecheck__(cls, inst): ... print "MA", cls, inst ... >>> class AM(list): __metaclass__ = MA ... >>> am = AM() >>> isinstance(am, AM) True As you can see, even with a class (rather than a tuple) as second argument to "isinstance", "MA.__instancecheck__" is not called. I suppose that "isinstance" (at least under Python 2) does not behave exactly as stated in PEP 3119. Instead, "isinstance" first directly checks for the instance to be an instance of the class *AND ONLY IF THIS FAILS* calls the class' "__instancecheck__". As PEP 3119 suggests, "__instancecheck__" has been introduced to support abstract base classes. The example given there is an abstract base class "Sequence" and concrete derived classes "list" and "tuple". For this use case, it is okay when "isinstance(inst, cls)" returns "True" whenever "inst" is a "cls" object and that "cls.__instancecheck__" is used only to result in "True" also for other cases. > 1. Why do I get True whenever i tuple the > isinstance(f, (Bar, Foo)) > (and why don't the print's run) > > The docs say that you can feed it a tuple and that the results are OR'd > > ---- > The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut for > isinstance(x, A) or isinstance(x, B) or ... (etc.). > ----- > which implies that the metaclasses are called for each class? > > > class MyzMeta(type): > def __instancecheck__(cls, other): > print('MyzzzzzzMeta', other) > return 0 > > > class MyMeta(MyzMeta, object): > def __instancecheck__(cls, other): > print('MyMeta') > print(cls, other) > return 0 > > > class Foo(list): > __metaclass__ = MyzMeta > pass > > class Miaow(object): > pass > > class Bar(Foo, Miaow): > __metaclass__ = MyMeta > pass > > > f = Foo() > b = Bar() > > print(isinstance(f, (Bar, Foo))) > raise SystemExit > > if isinstance(f, (Bar, Foo)): > print('success') From rosuav at gmail.com Tue Nov 5 02:18:53 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Nov 2019 18:18:53 +1100 Subject: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run? In-Reply-To: <87bltqese2.fsf@handshake.de> References: <87bltqese2.fsf@handshake.de> Message-ID: On Tue, Nov 5, 2019 at 5:43 PM dieter wrote: > I suppose that "isinstance" (at least under Python 2) does not > behave exactly as stated in PEP 3119. Instead, "isinstance" > first directly checks for the instance to be an instance of the > class *AND ONLY IF THIS FAILS* calls the class' "__instancecheck__". PEP 3119 is specifically about Python 3.0; I don't know how much, if any, was backported into Python 2. I strongly recommend using Python 3 when probing features like this. Not everything is supported on the legacy branch of Python. ChrisA From address at not.available Tue Nov 5 02:22:23 2019 From: address at not.available (R.Wieser) Date: Tue, 5 Nov 2019 08:22:23 +0100 Subject: OOP - how to abort an __init__ when the initialisation code fails ? References: Message-ID: Luciano, > In this context, what I mean by that quote is to say that Python > never forces you to wrap anything in try/except blocks. True. But /not/ doing it means that the casted exeption in the __init__ block will just abort the whole program - in a user unfriendly way. And thats normally not something I want. > The only reason to catch an exception prior to aborting is to > provide a better error message, :-) There you go. > In addition, as Rob said, it is usually a bad idea to wrap > several lines of code in a single try/except block I got that part. So, do you have, for the case I presented, something better to offer ? > Yes, you totally should learn how try/except works in Python, Well, with less than a week under my belt I'm not doing too bad, am I ? :-) (Remark: I've been programming for a while now. Its just Python thats new to me) > and alsolearn a bit of Python culture, "the way we do things around here" > ;-). :-) As long as I want to post questions here there will be no way to evade getting to know that culture. And I'm ofcourse open to suggestions, especially when they make my python programming life easier. > It is considered totally OK to use exception handling as a control > flow mechanism in Python. I'm not sure what exactly you mean with "a control flow mechanism", but as several methods throw exceptions themselves I will have no choice in having to deal with them. ... and as the topic of this thread has already shown, I'm not at all unwilling to learn about it. Quite the opposite actually. Regards, Rudy Wieser From rosuav at gmail.com Tue Nov 5 02:43:45 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Nov 2019 18:43:45 +1100 Subject: OOP - how to abort an __init__ when the initialisation code fails ? In-Reply-To: References: Message-ID: On Tue, Nov 5, 2019 at 6:26 PM R.Wieser
wrote: > > It is considered totally OK to use exception handling as a control > > flow mechanism in Python. > > I'm not sure what exactly you mean with "a control flow mechanism", but as > several methods throw exceptions themselves I will have no choice in having > to deal with them. > "Control flow" is anything that changes the order that your code runs. That can be as simple as an "if" statement, or as complicated as asynchronicity and yield points. In this context, exception handling is most definitely a form of control flow, but the point is that it is *normal* control flow. In a number of languages, exceptions always and only mean errors - you can catch them, but that always represents coping with an error in some way. In Python, they're an everyday occurrence. Consider: it = iter(range(5)) while True: try: i = next(it) except StopIteration: break print(i) This is more-or-less equivalent to: for i in range(5): print(i) The call to next() is going to either return the next value, or raise StopIteration to say "nothing more to see here". That's a common thing in Python. There are some contexts in which there's no possible "sentinel" object that could be returned - it's perfectly legal for the function to return literally any object at all - so it needs some other way to signal that it doesn't have anything to return, and that "other way" is to raise some specific exception. This is what's usually meant by "exceptions as a control flow mechanism" - that perfectly ordinary constructs like 'for' loops use exceptions to signal what they should do. ChrisA From address at not.available Tue Nov 5 04:42:15 2019 From: address at not.available (R.Wieser) Date: Tue, 5 Nov 2019 10:42:15 +0100 Subject: OOP - how to abort an __init__ when the initialisation code fails ? References: Message-ID: Chris, > "Control flow" is anything that changes the order that your code runs. My apologies, I should have said "a control flow mechanism" /in this context/ (though I assumed that as implicite, as I quoted the text from the OP). Case in point, the __init__ code (of a class object) can result in an exception, and I need to deal with it. But I should /not/ wrap whole blocks of code into a "try ... except" construction - which definitily is what will happen when I want to catch, in the calling program, exceptions thrown by the object while its initialising. So, I was wondering if the "a control flow mechanism" reference was aimed at something that would alleviate the above "you must, but you shouldn't" conundrum. Regards, Rudy Wieser From rosuav at gmail.com Tue Nov 5 05:28:53 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Nov 2019 21:28:53 +1100 Subject: OOP - how to abort an __init__ when the initialisation code fails ? In-Reply-To: References: Message-ID: On Tue, Nov 5, 2019 at 8:46 PM R.Wieser
wrote: > > Chris, > > > "Control flow" is anything that changes the order that your code runs. > > My apologies, I should have said "a control flow mechanism" /in this > context/ (though I assumed that as implicite, as I quoted the text from the > OP). > > Case in point, the __init__ code (of a class object) can result in an > exception, and I need to deal with it. But I should /not/ wrap whole blocks > of code into a "try ... except" construction - which definitily is what will > happen when I want to catch, in the calling program, exceptions thrown by > the object while its initialising. > > So, I was wondering if the "a control flow mechanism" reference was aimed at > something that would alleviate the above "you must, but you shouldn't" > conundrum. > Gotcha. The usual solution to this conundrum is a specific exception. You don't have to catch all arbitrary exceptions that might be thrown; you can define your own custom exception and catch only that. That way, you can use "raise SomeSpecificException" as a form of control flow, without disrupting the ability to detect other sorts of errors. ChrisA From rhodri at kynesim.co.uk Tue Nov 5 06:20:32 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 5 Nov 2019 11:20:32 +0000 Subject: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run? In-Reply-To: <20191104222325.GC8751@hjp.at> References: <6bf1b099-c655-5c60-306a-612056c6c26d@kynesim.co.uk> <20191104222325.GC8751@hjp.at> Message-ID: On 04/11/2019 22:23, Peter J. Holzer wrote: > On 2019-11-04 14:54:23 +0000, Rhodri James wrote: >> On 04/11/2019 14:33, Veek M wrote: >>> __metaclass__ = whatever; # is python2.x syntax >> >> But not Python3: see PEP 3115 > > Doesn't "X is python2.x syntax" imply "X is not python3 syntax"? Not necessarily, the OP might have (and apparently was) assuming that it was also Python3 syntax. Also it gave me an opportunity to point him to the appropriate PEP. That said, we've reached the limits of my knowledge here and I'm bowing out of the discussion. -- Rhodri James *-* Kynesim Ltd From grant.b.edwards at gmail.com Tue Nov 5 10:00:41 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 5 Nov 2019 15:00:41 -0000 (UTC) Subject: Is there some python libary for edit iso file drectly? References: <07e3d891-59a6-7588-45cd-2808693eb884@gmail.com> Message-ID: On 2019-11-05, Michael Torrie wrote: > On 11/4/19 4:11 PM, Hongyi Zhao wrote: >> Is there some python libary for edit iso file drectly? > > Isn't an ISO image a read-only sort of thing? Yes. > If you want to modify files don't you have to create a whole new > image? Yes. "Edit an ISO image" comprises the following steps. 1. Mount the ISO image[*]. 2. Copy the tree of files to a read-write filesystem. 3. Change the files in the read-write filesystem. 4. Create a new ISO image from the read-write filesystem. [*] IIRC, there are utilities that allow you to combine steps 1-2 into a single step: "Extract files from ISO image into a read-write filesystem". But, I can't ever remember how to do that, so I just do the two steps. -- Grant Edwards grant.b.edwards Yow! I invented skydiving at in 1989! gmail.com From wooethan14 at gmail.com Tue Nov 5 05:22:54 2019 From: wooethan14 at gmail.com (Ethan Woo) Date: Tue, 5 Nov 2019 18:22:54 +0800 Subject: Pip not available Message-ID: Dear person reading this, I was using Python 3.7.4 for a project, and I needed to install the *playsound* function. I looked through online and saw that I needed to use pip. However, it didn't work. I looked online and saw that I needed to install it through the application, however, now this problem pops up. [image: image.png] Can you help me with this? *P.S. I am a schoolkid who needs some help, not very experienced.* From pieter-l at vanoostrum.org Tue Nov 5 10:30:53 2019 From: pieter-l at vanoostrum.org (Pieter van Oostrum) Date: Tue, 05 Nov 2019 16:30:53 +0100 Subject: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run? References: <87bltqese2.fsf@handshake.de> Message-ID: Chris Angelico writes: > On Tue, Nov 5, 2019 at 5:43 PM dieter wrote: >> I suppose that "isinstance" (at least under Python 2) does not >> behave exactly as stated in PEP 3119. Instead, "isinstance" >> first directly checks for the instance to be an instance of the >> class *AND ONLY IF THIS FAILS* calls the class' "__instancecheck__". > > PEP 3119 is specifically about Python 3.0; I don't know how much, if > any, was backported into Python 2. Yes, it has been there since Python 2.6. I looked in the implementation, and isinstance(inst, cls) first checks if the class of ins is cls, then the result is True. There are a few other shortcut cases, and only at the end the __instancecheck__ method is called. You can check this with the original example: In [88]: class MA(type): ...: def __instancecheck__(cls, inst): ...: print "MA", cls, inst ...: ...: class AM(list): __metaclass__ = MA ...: class AM2(AM): pass ...: ...: am = AM2() In [89]: isinstance(am, AM) MA [] Out[89]: False It returns False because __instancecheck__ returns None Same for Python3: In [8]: class MA(type): ...: def __instancecheck__(cls, inst): ...: print ("MA", cls, inst) ...: ...: class AM(list, metaclass = MA): pass ...: class AM2(AM): pass ...: ...: am = AM2() In [9]: isinstance(am, AM) MA [] Out[9]: False -- Pieter van Oostrum WWW: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From pankaj.jangid at gmail.com Tue Nov 5 11:42:04 2019 From: pankaj.jangid at gmail.com (Pankaj Jangid) Date: Tue, 05 Nov 2019 22:12:04 +0530 Subject: Pip not available References: Message-ID: Ethan Woo writes: > I was using Python 3.7.4 for a project, and I needed to install the > *playsound* function. I looked through online and saw that I needed to use > pip. However, it didn't work. I looked online and saw that I needed to > install it through the application, however, now this problem pops up. > [image: image.png] > Can you help me with this? > python3 -m pip install -- Pankaj Jangid From about2mount at gmail.com Tue Nov 5 12:09:03 2019 From: about2mount at gmail.com (robin deatherage) Date: Tue, 5 Nov 2019 09:09:03 -0800 (PST) Subject: Is there some python libary for edit iso file drectly? In-Reply-To: References: Message-ID: On Tuesday, November 5, 2019 at 7:11:30 AM UTC+8, Hongyi Zhao wrote: > Is there some python libary for edit iso file drectly? You can use batch .bat files and have Python execute them. Honestly Batch will do all you are asking on MS Windows. Use its XCOPY to copy the IO file or the entire IO Directory, move or copy it to another directory as a non IO. Then have the batch make changes to the file then save it where and as you wish back to an IO. From about2mount at gmail.com Tue Nov 5 12:26:41 2019 From: about2mount at gmail.com (robin deatherage) Date: Tue, 5 Nov 2019 09:26:41 -0800 (PST) Subject: permission denied using python 3.8 In-Reply-To: References: Message-ID: <38cfe1d7-7d61-4d4f-a4a3-6a81b3dde126@googlegroups.com> On Tuesday, November 5, 2019 at 10:06:49 AM UTC+8, Francois van Lieshout wrote: > Hi, i installed python 3.8 the latest version but it doesn?t work, i get ?permission denied? when trying to acces python in the CLI and also i can?t run my code from my python files in the command-line nor in IDLE. I?d like to know why this is so. I?ve tried the 64 bit and the 32 bit executable version of 3.8 but without succes. So i reinstalled version 3.7.2 and now everything works fine again. > > Can you tell me why i can?t use python 3.8, i?m using windows as OS. YES---MS Windows uses a UAC User Control. So it is best to not add a package to an Admin user on Windows. Now in answer to this question first either your python interpreter remained in the system32 directory or you have an installed software using another version of an interpreter also located in the system directory interfering. And as pointed out with the UAC User Control on Windows. Log out of the current Windows User or Admin. Log into another Windows new user and add a different version of Python. But if you installed any Python in the Admin you will have to delete all traces of Python and or any interpreters to do so. Also there is no limit to how many different versions of Python you use on Windows---As long as you have a different UAC Control user logged in Windows for each one you add. I have 2.75, 3.5, 3.6, 3.7.0 and now 3.8 on my Windows now and all work fine. My user UAC logins may number five but that is is how it is suppose to be done anyways in Windows. From spencerdu at hotmail.co.uk Tue Nov 5 13:33:20 2019 From: spencerdu at hotmail.co.uk (Spencer Du) Date: Tue, 5 Nov 2019 10:33:20 -0800 (PST) Subject: How execute at least two python files at once when imported? Message-ID: Hi I want to execute at least two python files at once when imported but I dont know how to do this. Currently I can only import each file one after another but what i want is each file to be imported at the same time. Can you help me write the code for this? embedded.py is the main file to execute. embedded.py import paho.mqtt.client as mqtt from mqtt2 import * import os import time import json import configparser from threading import Thread def start(): try: os.remove("list_of_device(s)_currently_active.txt") os.remove("laser.ini") print("Awaiting device(s) to be activated") except: print("Awaiting device(s) to be activated") start() devices = list(map(str,input("Device(s) to be activated: ").split(","))) client = embedded() client.run() client.loop_start() print("Connected to broker") time.sleep(1) print("Subscribing to topic", "microscope/light_sheet_microscope/UI") client.subscribe("microscope/light_sheet_microscope/UI") print("Publishing message to topic", "microscope/light_sheet_microscope/UI") client.publish("microscope/light_sheet_microscope/UI", json.dumps({"type": "system", "payload":{"name": devices, "cmd": "activating device(s)"}}, indent=2)) time.sleep(1) def active_devices(): for item in devices: device = (item + "Embedded") deviceImport = __import__(device) with open("list_of_device(s)_currently_active.txt", "a+") as myfile: for item in devices: myfile.write(item + "\n") active_devices() def readFile(fname): print("List of device(s) currently active:") try: with open(fname, "r") as f: for item in f: print(item.rstrip("\n")) except: print("No device(s) added yet") readFile("list_of_device(s)_currently_active.txt") # print("Connected to broker") # time.sleep(1) # client.subscribe("microscope/light_sheet_microscope/UI/laser/#") # if os.path.exists: # parser = configparser.ConfigParser() # parser.read("laser.ini") # try: # subscriptions = dict(parser.items("Subscriptions")) # print("Subscribing to topics", subscriptions) # client.subscribe(subscriptions) # except: # pass # else: # pass client.loop_forever() laserEmbedded.py import random import asyncio from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference from mqtt2 import * class Laser(Actor): async def handle_message(self, message: Message): print("Laser") await asyncio.sleep(2) print("Unitialised") await asyncio.sleep(2) print("Initialising") await asyncio.sleep(2) print("Initialised") await asyncio.sleep(2) print("Configuring") await asyncio.sleep(2) print("Configured") await asyncio.sleep(2) await message.sender.tell(DataMessage(data="Hello World Im a laser!" + "\n", sender=self)) async def main(): # Let's create an instance of a Greeter actor and start it. async with Laser() as laser: # Then we'll just send it an empty message and wait for a response reply : DataMessage = await ask(laser, Message()) print(reply.data) asyncio.get_event_loop().run_until_complete(main()) def subscribe(): client = embedded() client.run() client.loop_start() client.subscribe("microscope/light_sheet_microscope/UI/laser/#") subscribe() camerasEmbedded.py import random import asyncio from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference class Cameras(Actor): async def handle_message(self, message: Message): print("Cameras") await asyncio.sleep(2) print("Unitialised") await asyncio.sleep(2) print("Initialising") await asyncio.sleep(2) print("Initialised") await asyncio.sleep(2) print("Configuring") await asyncio.sleep(2) print("Configured") await asyncio.sleep(2) await message.sender.tell(DataMessage(data="Hello World Im a camera!" + "\n", sender=self)) async def main(): # Let's create an instance of a Greeter actor and start it. async with Cameras() as cameras: # Then we'll just send it an empty message and wait for a response reply : DataMessage = await ask(cameras, Message()) print(reply.data) asyncio.get_event_loop().run_until_complete(main()) filterwheelEmbedded.py import random import asyncio from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference class FW(Actor): async def handle_message(self, message: Message): print("Filter wheel") await asyncio.sleep(2) print("Unitialised") await asyncio.sleep(2) print("Initialising") await asyncio.sleep(2) print("Initialised") await asyncio.sleep(2) print("Configuring") await asyncio.sleep(2) print("Configured") await asyncio.sleep(2) await message.sender.tell(DataMessage(data="Hello World Im a filter wheel!" + "\n", sender=self)) async def main(): # Let's create an instance of a Greeter actor and start it. async with FW() as fw: # Then we'll just send it an empty message and wait for a response reply : DataMessage = await ask(fw, Message()) print(reply.data) asyncio.get_event_loop().run_until_complete(main()) motorized_galvo_wheelEmbedded.py import random import asyncio from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference class Motorized_galvo_wheel(Actor): async def handle_message(self, message: Message): print("Motorized galvo wheel") await asyncio.sleep(2) print("Unitialised") await asyncio.sleep(2) print("Initialising") await asyncio.sleep(2) print("Initialised") await asyncio.sleep(2) print("Configuring") await asyncio.sleep(2) print("Configured") await asyncio.sleep(2) await message.sender.tell(DataMessage(data="Hello World Im a motorized galvo wheel!" + "\n", sender=self)) async def main(): # Let's create an instance of a Greeter actor and start it. async with Motorized_galvo_wheel() as motorized_galvo_wheel: # Then we'll just send it an empty message and wait for a response reply : DataMessage = await ask(motorized_galvo_wheel, Message()) print(reply.data) asyncio.get_event_loop().run_until_complete(main()) stagesEmbedded.py import random import asyncio from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference class Stages(Actor): async def handle_message(self, message: Message): print("Stages") await asyncio.sleep(2) print("Unitialised") await asyncio.sleep(2) print("Initialising") await asyncio.sleep(2) print("Initialised") await asyncio.sleep(2) print("Configuring") await asyncio.sleep(2) print("Configured") await asyncio.sleep(2) await message.sender.tell(DataMessage(data="Hello World Im a stage!" + "\n", sender=self)) async def main(): # Let's create an instance of a Greeter actor and start it. async with Stages() as stages: # Then we'll just send it an empty message and wait for a response reply : DataMessage = await ask(stages, Message()) print(reply.data) asyncio.get_event_loop().run_until_complete(main()) Thanks Spencer From Karsten.Hilbert at gmx.net Tue Nov 5 13:37:12 2019 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Tue, 5 Nov 2019 19:37:12 +0100 Subject: Aw: How execute at least two python files at once when imported? In-Reply-To: References: Message-ID: > I want to execute at least two python files at once when imported but I dont know how to do this. > Currently I can only import each file one after another but what i want is each file to be imported > at the same time. Can you explain why that seems necessary ? Karsten From bgailer at gmail.com Tue Nov 5 13:41:40 2019 From: bgailer at gmail.com (Bob Gailer) Date: Tue, 5 Nov 2019 13:41:40 -0500 Subject: How execute at least two python files at once when imported? In-Reply-To: References: Message-ID: On Nov 5, 2019 1:35 PM, "Spencer Du" wrote: > > Hi > > I want to execute at least two python files at once when imported but I dont know how to do this. Currently I can only import each file one after another but what i want is each file to be imported at the same time. Can you help me write the code for this? Please explain what you mean by "imported at the same time". As far as I know that is physically impossible. From rhodri at kynesim.co.uk Tue Nov 5 13:44:11 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 5 Nov 2019 18:44:11 +0000 Subject: How execute at least two python files at once when imported? In-Reply-To: References: Message-ID: <761c120d-dad6-ab36-5138-85461f3c1adc@kynesim.co.uk> On 05/11/2019 18:33, Spencer Du wrote: > I want to execute at least two python files at once when imported but > I dont know how to do this. Currently I can only import each file one > after another but what i want is each file to be imported at the same > time. That is a very odd requirement. Why would you want to do this? What exactly does "at the same time" mean here? -- Rhodri James *-* Kynesim Ltd From barry at barrys-emacs.org Tue Nov 5 14:01:59 2019 From: barry at barrys-emacs.org (Barry Scott) Date: Tue, 5 Nov 2019 19:01:59 +0000 Subject: Friday finking: TDD and EAFP In-Reply-To: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> References: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> Message-ID: <435DBBAC-4B69-4C81-AE9B-866B7AA8CF17@barrys-emacs.org> > On 1 Nov 2019, at 05:40, DL Neil via Python-list wrote: > > Is the practice of TDD fundamentally, if not philosophically, somewhat contrary to Python's EAFP approach? > > > TDD = Test-Driven Development > EAFP = it's easier to ask forgiveness than permission > * WebRefs as footnote > > > The practice of TDD* is that one writes test routines to prove a unit of code, eg method or function; BEFORE actually writing said function. > > The rationale is that TDD encourages proper identification and consideration of the routine's specification, and attempts to ensure that exceptions and "edge-cases" are not quietly forgotten. > (in a broad-brush, nut-shell) The practice of creating software is a social activity where those involved have foibles. Managing all the social interactions and foibles is what the methodologies are trying to help with. Any methodology that is easier to follow then avoid will tend to be taken up and provide a benefit. We all know that tests are a must have, but often those tests that we all know are a must have do not get written. It can often seem like a chore, after all the code works right? By starting with the tests the social engineering means that you make having the tests the easy part of the process. Methodologies like Agile address other foibles. Given a far off dead line the tendency is to delay getting the bulk of the work done until at the last moment. So is TDD contrary to EAFP? Not as such its two sorts of social engineering. TDD helps get the tests, EAPF give permission to take risks, necessary to innovate. Barry > > However, I quite possibly like yourself, come from a time-before - before TDD, and before Python. So, have had to not only learn these things, but sometimes, un-learn points and habits (if not vices). Accordingly, I came (quite unknowing of the term, or that there might be an alternative) from the world of LBYL* (look before you leap). > > In other words, before you do anything with some data, check that it is what you think it is. Whereas in Python we "try" by assuming everything is compos-mentis* and handle the "except" when things are not how we'd like. > > That adaptation was not too difficult. After all, aren't programmers an optimistic bunch - I mean, I *never* introduce bugs into *my* code! Do you? > > Which brings us to TDD. Here we assume the likelihood of bugs, as-if (cue: manic giggling); and code a bunch of tests first - in an attempt to prove that the code is up-to-spec. > > In encouraging my mind to think about testing the code, I find myself searching for edge-cases, and attempting to anticipate the unusual. Accordingly to the gospel of TDD: so far, so good. > > The 'problem' is, that it puts my mind onto LBYL-rails before the Python-coding train (of thought) has even left the station. It then seems natural to start putting a bunch of if-then-else's up-front and before the 'main line' of code. > > Does TDD bend your mind in this (apparently) non-Pythonic fashion? > Have you developed an answer? > (other than: "@dn is 'nuts'*", which is not worthy of debate) > > > WebRefs: > https://duckduckgo.com/?q=TDD&ia=web > https://devblogs.microsoft.com/python/idiomatic-python-eafp-versus-lbyl/ > https://docs.python.org/3/glossary.html#term-eafp > but: https://mail.python.org/pipermail/python-dev/2014-March/133118.html > https://docs.python.org/3/glossary.html#term-lbyl > Latin/legal term "compos mentis" https://www.thefreedictionary.com/compos+mentis > English slang term "nuts": https://www.thefreedictionary.com/nuts > -- > Regards, > =dn > -- > https://mail.python.org/mailman/listinfo/python-list > From hjp-python at hjp.at Tue Nov 5 14:52:59 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 5 Nov 2019 20:52:59 +0100 Subject: OOP - how to abort an __init__ when the initialisation code fails ? In-Reply-To: References: Message-ID: <20191105195259.GA11016@hjp.at> On 2019-11-04 18:18:39 -0300, Luciano Ramalho wrote: > In addition, as Rob said, it is usually a bad idea to wrap several > lines of code in a single try/except block I disagree with this. While it is sometimes useful to wrap a single line, in my experience it rarely is. The scope of the try ... except should be a unit from a semantic point of view. For example, if you open a file and write some data to it, you could write: try: f = open("a.file", "w") except OSError as e: ... handle exception try: f.write("some") except OSError as e: ... handle exception try: f.write("data") except OSError as e: ... handle exception try: close(f) except OSError as e: ... handle exception But not only is this hard to read and ugly as heck, what would be the point? Much better to write: try: with open("a.file", "w") as f: f.write("some") f.write("data") except OSError as e: ... handle exception Or maybe don't catch it here at all but just let it bubble up until it hits a level where dealing with it makes sense from the user's point of view (who may not care about an individual file, but about the task they instructed the program to perform). hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From tjreedy at udel.edu Tue Nov 5 15:04:25 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 5 Nov 2019 15:04:25 -0500 Subject: How execute at least two python files at once when imported? In-Reply-To: References: Message-ID: On 11/5/2019 1:33 PM, Spencer Du wrote: > I want to execute at least two python files at once when imported but I dont know how to do this. Currently I can only import each file one after another but what i want is each file to be imported at the same time. Can you help me write the code for this? embedded.py is the main file to execute. [snip about 150 lines of example code] We don't understand what you mean other than something impossible. Your example code is w a y too long. It should be the minimum needed to illustrate the idea. -- Terry Jan Reedy From tjreedy at udel.edu Tue Nov 5 15:11:10 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 5 Nov 2019 15:11:10 -0500 Subject: permission denied using python 3.8 In-Reply-To: <38cfe1d7-7d61-4d4f-a4a3-6a81b3dde126@googlegroups.com> References: <38cfe1d7-7d61-4d4f-a4a3-6a81b3dde126@googlegroups.com> Message-ID: On 11/5/2019 12:26 PM, robin deatherage wrote: > Also there is no limit to how many different versions of Python you use on Windows---As long as you have a different UAC Control user logged in Windows for each one you add. I have 2.75, 3.5, 3.6, 3.7.0 and now 3.8 on my Windows now and all work fine. My user UAC logins may number five but that is is how it is suppose to be done anyways in Windows. No it is not. I and many people have multiple versions of versions of Python on one user account installed either for just that user or for all users. The latter requires admin access. -- Terry Jan Reedy From tjreedy at udel.edu Tue Nov 5 15:13:30 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 5 Nov 2019 15:13:30 -0500 Subject: Pip not available In-Reply-To: References: Message-ID: On 11/5/2019 5:22 AM, Ethan Woo wrote: > [image: image.png] This, like most PSF lists, is text only. -- Terry Jan Reedy From rgaddi at highlandtechnology.invalid Tue Nov 5 15:27:10 2019 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Tue, 5 Nov 2019 12:27:10 -0800 Subject: OOP - how to abort an __init__ when the initialisation code fails ? In-Reply-To: References: <20191105195259.GA11016@hjp.at> Message-ID: On 11/5/19 11:52 AM, Peter J. Holzer wrote: > On 2019-11-04 18:18:39 -0300, Luciano Ramalho wrote: >> In addition, as Rob said, it is usually a bad idea to wrap several >> lines of code in a single try/except block > > I disagree with this. While it is sometimes useful to wrap a single > line, in my experience it rarely is. The scope of the try ... except > should be a unit from a semantic point of view. For example, if you > open a file and write some data to it, you could write: > > try: > f = open("a.file", "w") > except OSError as e: > ... handle exception > try: > f.write("some") > except OSError as e: > ... handle exception > try: > f.write("data") > except OSError as e: > ... handle exception > try: > close(f) > except OSError as e: > ... handle exception > > But not only is this hard to read and ugly as heck, what would be the > point? > > Much better to write: > > try: > with open("a.file", "w") as f: > f.write("some") > f.write("data") > except OSError as e: > ... handle exception > > Or maybe don't catch it here at all but just let it bubble up until it > hits a level where dealing with it makes sense from the user's point of > view (who may not care about an individual file, but about the task they > instructed the program to perform). > > hp > I mean, you sort of want "the right amount of stuff" in a try block. Lines that may exhibit a common failure, that you want to route to a common exception handler go into the same try block (per your example above). Things that are going to raise unrelated errors for unrelated reasons should be in different try blocks. Code that should only execute if the try block was error-free, but that you expect to not be able to raise errors itself, should go into the else block. Like most of programming, hard-and-fast rules turn out to be impossible. Reality has squishy edges. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From greg.ewing at canterbury.ac.nz Tue Nov 5 16:45:59 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Nov 2019 10:45:59 +1300 Subject: OOP - how to abort an __init__ when the initialisation code fails ? In-Reply-To: References: <20191105195259.GA11016@hjp.at> Message-ID: Peter J. Holzer wrote: > On 2019-11-04 18:18:39 -0300, Luciano Ramalho wrote: > >>In addition, as Rob said, it is usually a bad idea to wrap several >>lines of code in a single try/except block > > > I disagree with this. While it is sometimes useful to wrap a single > line, in my experience it rarely is. The scope of the try ... except > should be a unit from a semantic point of view. For example, if you > open a file and write some data to it, you could write: > > try: > f = open("a.file", "w") > except OSError as e: > ... handle exception > try: > f.write("some") > except OSError as e: > ... handle exception > try: > f.write("data") > except OSError as e: > ... handle exception > try: > close(f) > except OSError as e: > ... handle exception > > But not only is this hard to read and ugly as heck, what would be the > point? > > Much better to write: > > try: > with open("a.file", "w") as f: > f.write("some") > f.write("data") > except OSError as e: > ... handle exception > > Or maybe don't catch it here at all but just let it bubble up until it > hits a level where dealing with it makes sense from the user's point of > view Often it makes sense to do both -- catch the exception and re-raise it with a more informative error message, e.g. try: with open(filename, "w") as f: f.write("some") f.write("data") except OSError as e: raise OSError("Couldn't write fibble data to %s: %s" % (filename, e)) That way you don't get frustrating Microsoft style error messages which say "The system could not open the specified file" while giving no clue about *which* file was specified... aarggh! -- Greg From greg.ewing at canterbury.ac.nz Tue Nov 5 16:55:50 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Nov 2019 10:55:50 +1300 Subject: What PEPs are worth reading after you've read a textbook/Beazley but want to understand details/innerworkings In-Reply-To: References: Message-ID: Gilmeh Serda wrote: > Can't wait until we get to PEP 84657675, or PEP 3????3 PEP TREE(3) promises to be even more exciting! -- Greg From eryksun at gmail.com Tue Nov 5 19:10:55 2019 From: eryksun at gmail.com (Eryk Sun) Date: Tue, 5 Nov 2019 18:10:55 -0600 Subject: permission denied using python 3.8 In-Reply-To: <38cfe1d7-7d61-4d4f-a4a3-6a81b3dde126@googlegroups.com> References: <38cfe1d7-7d61-4d4f-a4a3-6a81b3dde126@googlegroups.com> Message-ID: On 11/5/19, robin deatherage wrote: > > MS Windows uses a UAC User Control. So it is best to not add a package > to an Admin user on Windows. The OP would have to install Python in a location that that's inaccessible to standard users and add this directory to the system PATH. It's dysfunctional to add directories to the system PATH that do not grant read and execute access to standard users, so that would be a simple installation error. (Unlike Unix, Windows does not keep searching PATH until it finds a file that it's allowed to execute. It tries to execute the first match it finds, even if it's not permitted to do so.) Also, this does not explain why the 3.7 installation works, assuming the OP follows a similar installation procedure in that case. For both 3.7 and 3.8, we need to know how Python is executed, including the fully-qualified path of python.exe (e.g. from running `where.exe python`). Also, from an administrator command prompt, we need the discretionary access control list (DACL) of the Python installation directory and executable (e.g. `icacls.exe ""` and `icacls.exe "\python.exe"`). Also, from a standard command prompt, we need the current user's list of groups (e.g. `whoami.exe /groups /fo list`). > Also there is no limit to how many different versions of Python you use on > Windows---As long as you have a different UAC Control user logged in Windows > for each one you add. I have 2.75, 3.5, 3.6, 3.7.0 and now 3.8 on my Windows > now and all work fine. My user UAC logins may number five but that is is how > it is suppose to be done anyways in Windows. Each minor release of Python can be installed to the same user profile and/or the system profile, and you can even install both the 32-bit and 64-bit builds of a minor release. An installation can also be updated in place to a newer micro release (e.g. 3.7.4 -> 3.7.5) since minor releases guarantee ABI compatibility for extension modules. There's no conflict with other installed releases as long as we use the py.exe launcher to run a particular version (e.g. `py -3.7` and `py -3.7-32`) and associate .py scripts with the launcher and use shebangs (e.g. "#!python3.7" and "#!python3.7-32"). If you need multiple micro releases (e.g. 3.7, 3.7.1, 3.7.2, ...), on the other hand, it's probably for continuous-integration testing, for which you can use the provided nuget packages instead of a standard installation. From eryksun at gmail.com Tue Nov 5 19:10:56 2019 From: eryksun at gmail.com (Eryk Sun) Date: Tue, 5 Nov 2019 18:10:56 -0600 Subject: permission denied using python 3.8 In-Reply-To: <38cfe1d7-7d61-4d4f-a4a3-6a81b3dde126@googlegroups.com> References: <38cfe1d7-7d61-4d4f-a4a3-6a81b3dde126@googlegroups.com> Message-ID: On 11/5/19, robin deatherage wrote: > > MS Windows uses a UAC User Control. So it is best to not add a package > to an Admin user on Windows. The OP would have to install Python in a location that that's inaccessible to standard users and add this directory to the system PATH. It's dysfunctional to add directories to the system PATH that do not grant read and execute access to standard users, so that would be a simple installation error. (Unlike Unix, Windows does not keep searching PATH until it finds a file that it's allowed to execute. It tries to execute the first match it finds, even if it's not permitted to do so.) Also, this does not explain why the 3.7 installation works, assuming the OP follows a similar installation procedure in that case. For both 3.7 and 3.8, we need to know how Python is executed, including the fully-qualified path of python.exe (e.g. from running `where.exe python`). Also, from an administrator command prompt, we need the discretionary access control list (DACL) of the Python installation directory and executable (e.g. `icacls.exe ""` and `icacls.exe "\python.exe"`). Also, from a standard command prompt, we need the current user's list of groups (e.g. `whoami.exe /groups /fo list`). > Also there is no limit to how many different versions of Python you use on > Windows---As long as you have a different UAC Control user logged in Windows > for each one you add. I have 2.75, 3.5, 3.6, 3.7.0 and now 3.8 on my Windows > now and all work fine. My user UAC logins may number five but that is is how > it is suppose to be done anyways in Windows. Each minor release of Python can be installed to the same user profile and/or the system profile, and you can even install both the 32-bit and 64-bit builds of a minor release. An installation can also be updated in place to a newer micro release (e.g. 3.7.4 -> 3.7.5) since minor releases guarantee ABI compatibility for extension modules. There's no conflict with other installed releases as long as we use the py.exe launcher to run a particular version (e.g. `py -3.7` and `py -3.7-32`) and associate .py scripts with the launcher and use shebangs (e.g. "#!python3.7" and "#!python3.7-32"). If you need multiple micro releases (e.g. 3.7, 3.7.1, 3.7.2, ...), on the other hand, it's probably for continuous-integration testing, for which you can use the provided nuget packages instead of a standard installation. From auriocus at gmx.de Wed Nov 6 03:05:27 2019 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 6 Nov 2019 09:05:27 +0100 Subject: How execute at least two python files at once when imported? In-Reply-To: References: Message-ID: Am 06.11.19 um 03:59 schrieb Dennis Lee Bieber: > On Tue, 5 Nov 2019 10:33:20 -0800 (PST), Spencer Du > declaimed the following: > >> Hi >> >> I want to execute at least two python files at once when imported but I dont know how to do this. Currently I can only import each file one after another but what i want is each file to be imported at the same time. Can you help me write the code for this? embedded.py is the main file to execute. > > > Short answer: you don't. > > When you import a module, the code for that module is parsed and > anything that is module level executable statement is done (note: "def" is > an executable statement -- it creates a function object contained the > parsed body and binds it to the provided name). When the parser gets to the > end of the module, it returns to the parent level and the next statement is > executed. > > Unless you use 1) threads; 2) subprocesses; or 3) multiprocess a Python > program only has one line of control, and that control is sequential. Since some of these example programs use asyncio, there is a 4th method. You convert all the programs to use asyncio, remove the event loop from these programs, i.e. remove the asyncio.get_event_loop().run_until_complete(main()) from the individual programs, and then you run a single event loop in your main program. Something like loop = asyncio.get_event_loop() loop.run_until_complete(asyncio.gather(laserembeded.main(), camerasembedded.main())) Christian From spencerdu at hotmail.co.uk Wed Nov 6 04:43:15 2019 From: spencerdu at hotmail.co.uk (Spencer Du) Date: Wed, 6 Nov 2019 01:43:15 -0800 (PST) Subject: How execute at least two python files at once when imported? In-Reply-To: References: Message-ID: On Wednesday, 6 November 2019 09:05:42 UTC+1, Christian Gollwitzer wrote: > Am 06.11.19 um 03:59 schrieb Dennis Lee Bieber: > > On Tue, 5 Nov 2019 10:33:20 -0800 (PST), Spencer Du > > declaimed the following: > > > >> Hi > >> > >> I want to execute at least two python files at once when imported but I dont know how to do this. Currently I can only import each file one after another but what i want is each file to be imported at the same time. Can you help me write the code for this? embedded.py is the main file to execute. > > > > > > Short answer: you don't. > > > > When you import a module, the code for that module is parsed and > > anything that is module level executable statement is done (note: "def" is > > an executable statement -- it creates a function object contained the > > parsed body and binds it to the provided name). When the parser gets to the > > end of the module, it returns to the parent level and the next statement is > > executed. > > > > Unless you use 1) threads; 2) subprocesses; or 3) multiprocess a Python > > program only has one line of control, and that control is sequential. > > Since some of these example programs use asyncio, there is a 4th method. > You convert all the programs to use asyncio, remove the event loop from > these programs, i.e. remove the > > asyncio.get_event_loop().run_until_complete(main()) > > from the individual programs, and then you run a single event loop in > your main program. Something like > > loop = asyncio.get_event_loop() > loop.run_until_complete(asyncio.gather(laserembeded.main(), > camerasembedded.main())) > > > Christian Ok I am interested in knowing how i can do it via either 1) threads; 2) subprocesses; or 3) multiprocess; depending on what you think is the best method. Thanks From spencerdu at hotmail.co.uk Wed Nov 6 04:50:45 2019 From: spencerdu at hotmail.co.uk (Spencer Du) Date: Wed, 6 Nov 2019 01:50:45 -0800 (PST) Subject: How execute at least two python files at once when imported? In-Reply-To: References: Message-ID: <3b41d84f-be49-45a2-9661-c2c3fbf94b04@googlegroups.com> On Tuesday, 5 November 2019 19:37:32 UTC+1, Karsten Hilbert wrote: > > I want to execute at least two python files at once when imported but I dont know how to do this. > > Currently I can only import each file one after another but what i want is each file to be imported > > at the same time. > > Can you explain why that seems necessary ? > > Karsten These are modules/files which are independent of each other and have no dependencies with one another. Because of this I want to run modules all at once. From spencerdu at hotmail.co.uk Wed Nov 6 04:51:04 2019 From: spencerdu at hotmail.co.uk (Spencer Du) Date: Wed, 6 Nov 2019 01:51:04 -0800 (PST) Subject: How execute at least two python files at once when imported? In-Reply-To: References: Message-ID: <76d7a0e0-6378-46f2-a096-bf4c162b21ba@googlegroups.com> On Tuesday, 5 November 2019 19:41:59 UTC+1, Bob Gailer wrote: > On Nov 5, 2019 1:35 PM, "Spencer Du" wrote: > > > > Hi > > > > I want to execute at least two python files at once when imported but I > dont know how to do this. Currently I can only import each file one after > another but what i want is each file to be imported at the same time. Can > you help me write the code for this? > > Please explain what you mean by "imported at the same time". As far as I > know that is physically impossible. These are modules/files which are independent of each other and have no dependencies with one another. Because of this I want to run modules all at once. From spencerdu at hotmail.co.uk Wed Nov 6 04:51:25 2019 From: spencerdu at hotmail.co.uk (Spencer Du) Date: Wed, 6 Nov 2019 01:51:25 -0800 (PST) Subject: How execute at least two python files at once when imported? In-Reply-To: References: <761c120d-dad6-ab36-5138-85461f3c1adc@kynesim.co.uk> Message-ID: On Tuesday, 5 November 2019 19:44:46 UTC+1, Rhodri James wrote: > On 05/11/2019 18:33, Spencer Du wrote: > > I want to execute at least two python files at once when imported but > > I dont know how to do this. Currently I can only import each file one > > after another but what i want is each file to be imported at the same > > time. > > That is a very odd requirement. Why would you want to do this? What > exactly does "at the same time" mean here? > > -- > Rhodri James *-* Kynesim Ltd These are modules/files which are independent of each other and have no dependencies with one another. Because of this I want to run modules all at once. From spencerdu at hotmail.co.uk Wed Nov 6 04:51:41 2019 From: spencerdu at hotmail.co.uk (Spencer Du) Date: Wed, 6 Nov 2019 01:51:41 -0800 (PST) Subject: How execute at least two python files at once when imported? In-Reply-To: References: Message-ID: <6d342231-1ea9-4b8f-99c0-217d4c496fc5@googlegroups.com> On Tuesday, 5 November 2019 21:05:02 UTC+1, Terry Reedy wrote: > On 11/5/2019 1:33 PM, Spencer Du wrote: > > > I want to execute at least two python files at once when imported but I dont know how to do this. Currently I can only import each file one after another but what i want is each file to be imported at the same time. Can you help me write the code for this? embedded.py is the main file to execute. > > [snip about 150 lines of example code] > > We don't understand what you mean other than something impossible. Your > example code is w a y too long. It should be the minimum > needed to illustrate the idea. > > -- > Terry Jan Reedy These are modules/files which are independent of each other and have no dependencies with one another. Because of this I want to run modules all at once. From rhodri at kynesim.co.uk Wed Nov 6 06:42:33 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 6 Nov 2019 11:42:33 +0000 Subject: How execute at least two python files at once when imported? In-Reply-To: References: <761c120d-dad6-ab36-5138-85461f3c1adc@kynesim.co.uk> Message-ID: <258dcd76-2355-db46-26d1-ec42f0f87077@kynesim.co.uk> On 06/11/2019 09:51, Spencer Du wrote: > On Tuesday, 5 November 2019 19:44:46 UTC+1, Rhodri James wrote: >> On 05/11/2019 18:33, Spencer Du wrote: >>> I want to execute at least two python files at once when imported but >>> I dont know how to do this. Currently I can only import each file one >>> after another but what i want is each file to be imported at the same >>> time. >> >> That is a very odd requirement. Why would you want to do this? What >> exactly does "at the same time" mean here? >> > These are modules/files which are independent of each other and have no dependencies with one another. Because of this I want to run modules all at once. > "All at once" still isn't a very meaningful phrase. If you want to import modules in parallel, don't. Not only is it hard work to do, it will come back and bite you. -- Rhodri James *-* Kynesim Ltd From rhodri at kynesim.co.uk Wed Nov 6 06:43:11 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 6 Nov 2019 11:43:11 +0000 Subject: How execute at least two python files at once when imported? In-Reply-To: <258dcd76-2355-db46-26d1-ec42f0f87077@kynesim.co.uk> References: <761c120d-dad6-ab36-5138-85461f3c1adc@kynesim.co.uk> <258dcd76-2355-db46-26d1-ec42f0f87077@kynesim.co.uk> Message-ID: <8d08c7db-663c-b22f-2567-8402ac351d0a@kynesim.co.uk> On 06/11/2019 11:42, Rhodri James wrote: > On 06/11/2019 09:51, Spencer Du wrote: >> On Tuesday, 5 November 2019 19:44:46 UTC+1, Rhodri James? wrote: >>> On 05/11/2019 18:33, Spencer Du wrote: >>>> I want to execute at least two python files at once when imported but >>>> I dont know how to do this. Currently I can only import each file one >>>> after another but what i want is each file to be imported at the same >>>> time. >>> >>> That is a very odd requirement.? Why would you want to do this?? What >>> exactly does "at the same time" mean here? >>> >> These are modules/files which are independent of each other and have >> no dependencies with one another. Because of this I want to run >> modules all at once. >> > > "All at once" still isn't a very meaningful phrase.? If you want to > import modules in parallel, don't.? Not only is it hard work to do, it > will come back and bite you. Also posting exactly the same answer word for word four different times isn't a very helpful thing to do. -- Rhodri James *-* Kynesim Ltd From antoon.pardon at vub.be Wed Nov 6 06:57:07 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 6 Nov 2019 12:57:07 +0100 Subject: How execute at least two python files at once when imported? In-Reply-To: References: Message-ID: On 5/11/19 19:33, Spencer Du wrote: > Hi > > I want to execute at least two python files at once when imported but I dont know how to do this. Currently I can only import each file one after another but what i want is each file to be imported at the same time. Can you help me write the code for this? embedded.py is the main file to execute. Your question is confusing. In the header and in your first sentence you talk about executing. But later you talk about importing. -- Antoon From spencerdu at hotmail.co.uk Wed Nov 6 11:02:41 2019 From: spencerdu at hotmail.co.uk (Spencer Du) Date: Wed, 6 Nov 2019 08:02:41 -0800 (PST) Subject: How execute at least two python files at once when imported? In-Reply-To: References: <761c120d-dad6-ab36-5138-85461f3c1adc@kynesim.co.uk> <258dcd76-2355-db46-26d1-ec42f0f87077@kynesim.co.uk> <8d08c7db-663c-b22f-2567-8402ac351d0a@kynesim.co.uk> Message-ID: <62e0e7b3-0d4b-49cf-aec1-a7e03f8f1fc2@googlegroups.com> Why is importing modules in parallel bad? Thanks Spencer From ikorot01 at gmail.com Wed Nov 6 11:12:39 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Wed, 6 Nov 2019 10:12:39 -0600 Subject: How execute at least two python files at once when imported? In-Reply-To: <62e0e7b3-0d4b-49cf-aec1-a7e03f8f1fc2@googlegroups.com> References: <761c120d-dad6-ab36-5138-85461f3c1adc@kynesim.co.uk> <258dcd76-2355-db46-26d1-ec42f0f87077@kynesim.co.uk> <8d08c7db-663c-b22f-2567-8402ac351d0a@kynesim.co.uk> <62e0e7b3-0d4b-49cf-aec1-a7e03f8f1fc2@googlegroups.com> Message-ID: Hi, I think what you are trying is a "chicken-egg" problem. You should clearly state you requirements in order for us to help you. If you have a problem with English I'm sure there is some python-related list/forum in your native language. Just google it. Thank you. On Wed, Nov 6, 2019 at 10:07 AM Spencer Du wrote: > > Why is importing modules in parallel bad? > > Thanks > Spencer > -- > https://mail.python.org/mailman/listinfo/python-list From spencerdu at hotmail.co.uk Wed Nov 6 11:16:07 2019 From: spencerdu at hotmail.co.uk (Spencer Du) Date: Wed, 6 Nov 2019 08:16:07 -0800 (PST) Subject: How execute at least two python files at once when imported? In-Reply-To: References: <761c120d-dad6-ab36-5138-85461f3c1adc@kynesim.co.uk> <258dcd76-2355-db46-26d1-ec42f0f87077@kynesim.co.uk> <8d08c7db-663c-b22f-2567-8402ac351d0a@kynesim.co.uk> <62e0e7b3-0d4b-49cf-aec1-a7e03f8f1fc2@googlegroups.com> Message-ID: <417ca0d2-cd5f-4415-b564-9edee18ba1b6@googlegroups.com> Hi Sorry if I haven't stated my requirements clearly. I just wanted a way to import at least two python files in parallel and I wanted to know how this can be done or a reason why its bad as stated in another post. Thanks Spencer From Karsten.Hilbert at gmx.net Wed Nov 6 11:28:10 2019 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Wed, 6 Nov 2019 17:28:10 +0100 Subject: How execute at least two python files at once when imported? In-Reply-To: <417ca0d2-cd5f-4415-b564-9edee18ba1b6@googlegroups.com> References: <761c120d-dad6-ab36-5138-85461f3c1adc@kynesim.co.uk> <258dcd76-2355-db46-26d1-ec42f0f87077@kynesim.co.uk> <8d08c7db-663c-b22f-2567-8402ac351d0a@kynesim.co.uk> <62e0e7b3-0d4b-49cf-aec1-a7e03f8f1fc2@googlegroups.com> <417ca0d2-cd5f-4415-b564-9edee18ba1b6@googlegroups.com> Message-ID: <20191106162810.GI4996@hermes.hilbert.loc> On Wed, Nov 06, 2019 at 08:16:07AM -0800, Spencer Du wrote: > Sorry if I haven't stated my requirements clearly. > > I just wanted a way to import at least two python files in parallel and I wanted to know how this can be done or a reason why its bad as stated in another post. You stated your *desire* but not which (external) *requirement* this desire comes from. Long answer short: if you want exactly what you say then you'll have to run two separate machines and overcome the Heisenberg Principle with regards to syncronizing their runtime behaviour. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From ikorot01 at gmail.com Wed Nov 6 11:34:04 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Wed, 6 Nov 2019 10:34:04 -0600 Subject: How execute at least two python files at once when imported? In-Reply-To: <417ca0d2-cd5f-4415-b564-9edee18ba1b6@googlegroups.com> References: <761c120d-dad6-ab36-5138-85461f3c1adc@kynesim.co.uk> <258dcd76-2355-db46-26d1-ec42f0f87077@kynesim.co.uk> <8d08c7db-663c-b22f-2567-8402ac351d0a@kynesim.co.uk> <62e0e7b3-0d4b-49cf-aec1-a7e03f8f1fc2@googlegroups.com> <417ca0d2-cd5f-4415-b564-9edee18ba1b6@googlegroups.com> Message-ID: Hi, On Wed, Nov 6, 2019 at 10:22 AM Spencer Du wrote: > > Hi > > Sorry if I haven't stated my requirements clearly. > > I just wanted a way to import at least two python files in parallel and I wanted to know how this can be done or a reason why its bad as stated in another post. This is not a requirements. Let me rephrase my question - what problem are you trying to solve? Also, as I said before - I believe there is a language barrier. Find some python forum in your native language and ask your question there. Thank you. > > Thanks > Spencer > -- > https://mail.python.org/mailman/listinfo/python-list From David.Raymond at tomtom.com Wed Nov 6 12:05:05 2019 From: David.Raymond at tomtom.com (David Raymond) Date: Wed, 6 Nov 2019 17:05:05 +0000 Subject: How execute at least two python files at once when imported? In-Reply-To: <62e0e7b3-0d4b-49cf-aec1-a7e03f8f1fc2@googlegroups.com> References: <761c120d-dad6-ab36-5138-85461f3c1adc@kynesim.co.uk> <258dcd76-2355-db46-26d1-ec42f0f87077@kynesim.co.uk> <8d08c7db-663c-b22f-2567-8402ac351d0a@kynesim.co.uk> <62e0e7b3-0d4b-49cf-aec1-a7e03f8f1fc2@googlegroups.com> Message-ID: "Why is importing modules in parallel bad?" In general I'd say that "import foo" is supposed to be there because you want the classes, functions, variables etc. in foo to be available in your current program. A module should never run a whole bunch of time consuming stuff when it's imported. If you want to "run foo" rather than import it, then inside foo all the "running" code should be in a function which can be called later. If you want foo to be runnable directly you can then call that function from the classic if __name__ == "__main__": construct. That lets foo be importable, and lets you pick when you want the actual long stuff to run. #In foo.py def run_long_task(): long_stuff_here if __name__ == "__main__": #foo.py is being called directly, not imported run_long_task() So your main program should look something like: import foo #quick as just the definitions are processed foo.run_long_task() Or to "run" multiple other things at once it should look more like: import threading #multiprocessing, or other module here import foo #quick as just the definitions are processed import bar #quick as just the definitions are processed kick off foo.run_long_task() as its own thread/process/task/etc kick off bar.run_long_task() as its own thread/process/task/etc wait for them to finish and process results, or do stuff while they're running So again, "import" should never be used to "run" another file, just to "bring in the stuff from" another file. And any file designed to be imported should not run extra stuff during that import. From oscar.j.benjamin at gmail.com Wed Nov 6 12:13:57 2019 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 6 Nov 2019 17:13:57 +0000 Subject: OOP - how to abort an __init__ when the initialisation code fails ? In-Reply-To: References: <20191105195259.GA11016@hjp.at> Message-ID: On Tue, 5 Nov 2019 at 21:52, Gregory Ewing wrote: > > Peter J. Holzer wrote: > > On 2019-11-04 18:18:39 -0300, Luciano Ramalho wrote: > > > > Or maybe don't catch it here at all but just let it bubble up until it > > hits a level where dealing with it makes sense from the user's point of > > view > > Often it makes sense to do both -- catch the exception and > re-raise it with a more informative error message, e.g. > > try: > with open(filename, "w") as f: > f.write("some") > f.write("data") > except OSError as e: > raise OSError("Couldn't write fibble data to %s: %s" % (filename, e)) > > That way you don't get frustrating Microsoft style error > messages which say "The system could not open the specified file" > while giving no clue about *which* file was specified... aarggh! Of course it doesn't apply to simples cases like above but my experience of catching and reraising is that it often is the *cause* of those kind of uninformative or even misleading error messages. In Python the original exception message plus traceback is often very informative (to a programmer!) about the problem. Catching and reraising can mean that you end up crafting an error message somewhere higher up where the filename isn't known any more. Even worse is if the author's assumption about the source of the exception is incorrect. The problem with trying to specify how much should go into a try block is that one line can be thousands of lines if it calls a function that calls another function and so on. Even if you have a very narrow lexical scope for the try block it can still cover the whole of your codebase (or even that of all the dependencies you use) so the danger of overly broad exception handling can not be understood in such simple terms. One thing that is clear though is that you should catch the most specific kind of exception possible. Ideally if the exception is raised in your code then it should be a dedicated exception class. If that exception is only raised in one specific place I see nothing wrong with wrapping all of your code in a try/except that catches that one exception: when the exception is caught you know exactly why and can handle appropriately. Oscar From address at not.available Wed Nov 6 12:15:36 2019 From: address at not.available (R.Wieser) Date: Wed, 6 Nov 2019 18:15:36 +0100 Subject: psutil.boot_time() ... doesn't ? Message-ID: Hello all, I was doing a "lets print some time-related data", and also diaplayed the result of "psutil.boot_time()". Somewhere while doing that I saw that my clock was off, so I used the "date" command to rectify it. The thing is, after that the result of "psutil.boot_time()" was changed - and that I did (and do) not expect. :-( (Remark: the difference was exactly the same as the change I made with the "date" command). Question: Is there a way to retrieve the "last boot" time /without/ it getting changed by ... whatever ? Regards, Rudy Wieser From maxischmeii at gmail.com Wed Nov 6 12:44:48 2019 From: maxischmeii at gmail.com (Maxime S) Date: Wed, 6 Nov 2019 18:44:48 +0100 Subject: psutil.boot_time() ... doesn't ? In-Reply-To: References: Message-ID: Hello, You may want to read PEP 418 which nicely summaries the different clock available on each platform and their limitations. It looks like CLOCK_BOOTTIME is what you want but it is only available on Linux. Regards, Maxime. Le mer. 6 nov. 2019 ? 18:23, R.Wieser
a ?crit : > Hello all, > > I was doing a "lets print some time-related data", and also diaplayed the > result of "psutil.boot_time()". > > Somewhere while doing that I saw that my clock was off, so I used the > "date" > command to rectify it. > > The thing is, after that the result of "psutil.boot_time()" was changed - > and that I did (and do) not expect. :-( > (Remark: the difference was exactly the same as the change I made with the > "date" command). > > Question: Is there a way to retrieve the "last boot" time /without/ it > getting changed by ... whatever ? > > Regards, > Rudy Wieser > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From rhodri at kynesim.co.uk Wed Nov 6 13:15:43 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 6 Nov 2019 18:15:43 +0000 Subject: How execute at least two python files at once when imported? In-Reply-To: <62e0e7b3-0d4b-49cf-aec1-a7e03f8f1fc2@googlegroups.com> References: <761c120d-dad6-ab36-5138-85461f3c1adc@kynesim.co.uk> <258dcd76-2355-db46-26d1-ec42f0f87077@kynesim.co.uk> <8d08c7db-663c-b22f-2567-8402ac351d0a@kynesim.co.uk> <62e0e7b3-0d4b-49cf-aec1-a7e03f8f1fc2@googlegroups.com> Message-ID: On 06/11/2019 16:02, Spencer Du wrote: > Why is importing modules in parallel bad? To put it as simply as I can: 1. The import mechanism is complicated, even the bits that are user-visible. Fiddling with it has a high chance of going wrong. 2. Multi-threading is less complicated than import, but still requires a lot of careful thought. For example you've asserted that the modules you want to import simultaneously, but you also need to consider the import mechanism itself. Put 1 and 2 together, and multi-threaded import sounds like a nightmare. -- Rhodri James *-* Kynesim Ltd From bob at mellowood.ca Wed Nov 6 13:36:58 2019 From: bob at mellowood.ca (Bob van der Poel) Date: Wed, 6 Nov 2019 11:36:58 -0700 Subject: How execute at least two python files at once when imported? In-Reply-To: References: <761c120d-dad6-ab36-5138-85461f3c1adc@kynesim.co.uk> <258dcd76-2355-db46-26d1-ec42f0f87077@kynesim.co.uk> <8d08c7db-663c-b22f-2567-8402ac351d0a@kynesim.co.uk> <62e0e7b3-0d4b-49cf-aec1-a7e03f8f1fc2@googlegroups.com> Message-ID: On Wed, Nov 6, 2019 at 11:15 AM Rhodri James wrote: > On 06/11/2019 16:02, Spencer Du wrote: > > Why is importing modules in parallel bad? > > To put it as simply as I can: > > 1. The import mechanism is complicated, even the bits that are > user-visible. Fiddling with it has a high chance of going wrong. > > 2. Multi-threading is less complicated than import, but still requires a > lot of careful thought. For example you've asserted that the modules > you want to import simultaneously, but you also need to consider the > import mechanism itself. > > Put 1 and 2 together, and multi-threaded import sounds like a nightmare. > > -- > Rhodri James *-* Kynesim Ltd > -- > https://mail.python.org/mailman/listinfo/python-list > After spending way too much time chasing my tail down the rabbit hole on a similar project I decided that using the work of others was more productive. I've been using parallel with good success. Depends on how much you need to share with the different components. For details see https://www.gnu.org/software/parallel/ -- **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW: http://www.mellowood.ca From address at not.available Wed Nov 6 14:06:22 2019 From: address at not.available (R.Wieser) Date: Wed, 6 Nov 2019 20:06:22 +0100 Subject: psutil.boot_time() ... doesn't ? References: Message-ID: Maxime, > You may want to read PEP 418 which nicely summaries the > different clock available on each platform and their limitations. You mean the CLOCK_REALTIME and CLOCK_MONOTONIC ones ? Yeah, that was what I was looking at :-) > It looks like CLOCK_BOOTTIME is what you want but it is only > available on Linux. While googeling for an explanation and/or solution to the behaviour of psutil.boot_time() I also came across it - and it was marked as depricated, with the above function as its successor. I did try to use it though, but Raspberry Pi's Python3 threw a "no idea what that is" error. :-\ I also tried to google "python BOOT_TIME", but got nowhere (the latter parts casing was ignored). Hence me posting here. Regards, Rudy Wieser From rosuav at gmail.com Wed Nov 6 14:31:21 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Nov 2019 06:31:21 +1100 Subject: psutil.boot_time() ... doesn't ? In-Reply-To: References: Message-ID: On Thu, Nov 7, 2019 at 6:11 AM R.Wieser
wrote: > > I also tried to google "python BOOT_TIME", but got nowhere (the latter parts > casing was ignored). Hence me posting here. > That's possibly because you're looking at psutil, which is a third party package. Here's its documentation: https://psutil.readthedocs.io/en/latest/#psutil.boot_time But I don't know what its definition is, whether it's "current time minus uptime" or "timestamp recorded during bootup". It might not even be consistent across platforms. ChrisA From address at not.available Wed Nov 6 15:09:58 2019 From: address at not.available (R.Wieser) Date: Wed, 6 Nov 2019 21:09:58 +0100 Subject: psutil.boot_time() ... doesn't ? References: Message-ID: Dennis, > Depends upon the OS... My apologies, its Linux (as on a Raspberry Pi). > You can easily look at the code used by psutil :-) I somehow assumed that those where build-in into the language itself. I'll have to take a peek at what else is available there too. > I read somewhere that the kernel calculates the btime from the > current gettimeofday minus the jiffies since boot converted to > seconds. That was also my guess to what happened. > last file system modification time > hardware RTC (if equipped) > NTP update (if networked) > what should your "boot time" be referenced against? The built-in clock ofcourse. :-) But I would not mind if it would be set to some believable time by the fake-hwclock. But granted, on a Raspberry thats a bit of a problem. On the other hand, just dragging the "last boot time" around by whatever time you now set feels like fakery. Oh man, I can already imagine a CSI plot where someone tries to use as linux machines boot time as an alibi, but summer time just arrived, causing it to appear an hour later .. :-) > but that boot time will depend on exactly when the CRON job ran > in relation to the three potential sources of clock time. I was already thinking of something similar (running a script at boot), but also saw such race-time problems. I might edit the fake-hwclock code though. Copying the clocks current date/time after it has just been set (or not, when an RTC is installed) would be enough for my purposes. ... Though I would rather not mess around in/with system files. Regards, Rudy Wieser From rosuav at gmail.com Wed Nov 6 15:19:13 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Nov 2019 07:19:13 +1100 Subject: psutil.boot_time() ... doesn't ? In-Reply-To: References: Message-ID: On Thu, Nov 7, 2019 at 7:16 AM R.Wieser
wrote: > But granted, on a Raspberry thats a bit of a problem. On the other hand, > just dragging the "last boot time" around by whatever time you now set feels > like fakery. > > Oh man, I can already imagine a CSI plot where someone tries to use as linux > machines boot time as an alibi, but summer time just arrived, causing it to > appear an hour later .. :-) https://www.youtube.com/watch?v=w45QkL9blG4 :) I don't think boot time would be affected by a DST switch, though. It should be recorded in UTC. ChrisA From address at not.available Wed Nov 6 15:18:29 2019 From: address at not.available (R.Wieser) Date: Wed, 6 Nov 2019 21:18:29 +0100 Subject: psutil.boot_time() ... doesn't ? References: Message-ID: Chris > That's possibly because you're looking at psutil, which is a third > party package. Here's its documentation: My info came frome here: https://www.programcreek.com/python/example/53873/psutil.boot_time Looking at example 1 it looks the be the same. > But I don't know what its definition is, whether it's "current time > minus uptime" or "timestamp recorded during bootup". It might > not even be consistent across platforms. Oh yoy ! :-\ Regards, Rudy Wieser From address at not.available Wed Nov 6 15:27:07 2019 From: address at not.available (R.Wieser) Date: Wed, 6 Nov 2019 21:27:07 +0100 Subject: psutil.boot_time() ... doesn't ? References: Message-ID: Chris, > I don't think boot time would be affected by a DST switch, though. > It should be recorded in UTC. The point is, it /isn't/ a recorded constant (at least not on my machine). Its just dragged around with the clocks current time (as in: current time minus uptime). And as such I could easily imagine a DST change will cause the "boot time" to change accordingly. Regards, Rudy Wieser From rosuav at gmail.com Wed Nov 6 15:37:01 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Nov 2019 07:37:01 +1100 Subject: psutil.boot_time() ... doesn't ? In-Reply-To: References: Message-ID: On Thu, Nov 7, 2019 at 7:21 AM R.Wieser
wrote: > > Chris > > > That's possibly because you're looking at psutil, which is a third > > party package. Here's its documentation: > > My info came frome here: > https://www.programcreek.com/python/example/53873/psutil.boot_time > > Looking at example 1 it looks the be the same. Yep, looks like that site probably cribbed the example from the docs, or similar. Your code is fine. > > But I don't know what its definition is, whether it's "current time > > minus uptime" or "timestamp recorded during bootup". It might > > not even be consistent across platforms. > > Oh yoy ! :-\ Yeah... welcome to the wonderful world of cross-platform libraries that depend on different facilities. Different OSes make different promises, and the library has to try to paper over those distinctions and give a consistent result. It's usually fine, but there WILL be edge cases. ChrisA From torriem at gmail.com Wed Nov 6 15:37:19 2019 From: torriem at gmail.com (Michael Torrie) Date: Wed, 6 Nov 2019 13:37:19 -0700 Subject: How execute at least two python files at once when imported? In-Reply-To: <417ca0d2-cd5f-4415-b564-9edee18ba1b6@googlegroups.com> References: <761c120d-dad6-ab36-5138-85461f3c1adc@kynesim.co.uk> <258dcd76-2355-db46-26d1-ec42f0f87077@kynesim.co.uk> <8d08c7db-663c-b22f-2567-8402ac351d0a@kynesim.co.uk> <62e0e7b3-0d4b-49cf-aec1-a7e03f8f1fc2@googlegroups.com> <417ca0d2-cd5f-4415-b564-9edee18ba1b6@googlegroups.com> Message-ID: <54198430-de28-f6dd-f2e4-a5c6e528469e@gmail.com> On 11/6/19 9:16 AM, Spencer Du wrote: > I just wanted a way to import at least two python files in parallel > and I wanted to know how this can be done or a reason why its bad as > stated in another post. It's not "bad," but it's also not possible. Nor does it make sense. That's why so many people are questioning what you are really trying to accomplish. By definition a Python script is a sequence of statements that are read and executed in sequence. You can't just run them all at once, nor would it make sense to do so. If you want to run multiple python functions in parallel, there are threads for that, multiprocessing, and also asynchronous scheduling. But no one can tell you what to do because none of us have any clue what you are trying to accomplish. From micromine15 at gmail.com Wed Nov 6 15:38:18 2019 From: micromine15 at gmail.com (Isaiah Foss) Date: Wed, 6 Nov 2019 12:38:18 -0800 (PST) Subject: Robot Drift correction help Message-ID: We have a robot needed coding, we succeeded however the left wheel has an issue with drift. This was compiled by a professor that requires drift correction. He is overseas and uncontactable.... the code is as follows. define a procedure to recalibrate rotational speeds when any wheel can be affected by random offset. import matplotlib.pyplot as plt #enables plotting capabilities for the robot #for this case this is the OUTPUT as the whole #robot is simulated through this notebook import numpy as np #Numerical Python library as described in the Intro Python Notebook import math #math module import scipy.constants as sc #shortcut for physical and mathematical constants #and units import sympy as sym #SymPy is a Python library for symbolic mathematics import decimal decimal.getcontext().prec = 100 from math import sin, cos class Robot(object): """Defines basic mobile robot properties. Defines __init__, step, print_xya, and plot_robot methods. Is called in the main class of DDRobot.""" def __init__(self): #initialization class. self.pos_x = 0.0 #placing bot at origin: (x,y) = (0,0) self.pos_y = 0.0 self.angle = 0.0 # IN RAD setting alpha = 0 self.plot = False #intializing no plot to show self._delta = 0.01 # self.step_plot = int(8) #plotting every 5 iterations self.mag_plot = 1.5 # arrow magnification self.angle_evol = [] # Movement def step(self): """ updates the x,y and alpha """ self.deltax() self.deltay() self.deltaa() self.angle_evol.append(self.angle) def move(self, seconds): """ Moves the robot for an 's' amount of seconds. Takes argument of seconds as type int""" for i in range(int(seconds/self._delta)): self.step() if i % self.step_plot == 0 and self.plot: # plot path every 5 steps self.plot_xya() #plots a dot in the position of the robot # Printing-and-plotting: def print_xya(self): """ prints the x,y position and angle """ print ("x = " + str(self.pos_x) +" "+ "y = " + str(self.pos_y)) print ("a = " + str(self.angle)) def plot_robot(self): """ plots an arrow representation of the robot. """ plt.arrow(self.pos_x, self.pos_y, 0.001 * cos(self.angle), 0.001 * sin(self.angle), head_width=self.mag_plot*self.length, head_length=self.mag_plot*self.length, fc='k', ec='k') def plot_xya(self): """ plots a dot in the position of the robot """ plt.scatter(self.pos_x, self.pos_y, c='r', edgecolors='r') class DDRobot(Robot): """Defines a differential drive robot. Is the main class. Moves the robot. Class Robot is effectively created within class DDRobot as many of the methods from Robot class are called within DDRobot class.""" def __init__(self): """__init__ : Initialization class (for DDRobot class)""" Robot.__init__(self) self.radius = 0.1 #radius of bot wheel as defined in Fig 3 self.length = 0.4 #length between bot wheels as defined in Fig 3 self.rt_spd_left = 0.0 #initializing rotation speed, left wheel to 0 self.rt_spd_right = 0.0 #initializing rotation speed, right wheel to 0 a = 0 while a == 0: a = np.random.randint(-1,2) self.drift = a*np.random.uniform(0.0,0.1) def deltax(self): """ update x position depending on L and R angular speeds """ self.pos_x += self._delta * (self.radius*0.5) \ * (self.rt_spd_right + (self.rt_spd_left + self.drift))*cos(self.angle) def deltay(self): """ update y position depending on l and r angular speeds """ self.pos_y += self._delta * (self.radius*0.5) \ * (self.rt_spd_right + (self.rt_spd_left + self.drift))*sin(self.angle) def deltaa(self): """ update angle depending on l and r angular speeds """ self.angle += self._delta * (self.radius/self.length) \ * (self.rt_spd_right - (self.rt_spd_left + self.drift)) def D2R(a): """function to convert degrees to radians. Takes single argument of degrees.""" return float(((math.pi)*float(a))/180.0) def R2D(a): """Function to convert radians to degrees. Takes single argument of radians.""" return float((180.0*float(a)/(math.pi))) plt.figure(figsize=(6,6)) pos_x_0 = 0 pos_y_0 = 0 wheelradius = 0.5 wheelseparation = 1 omega = 1 line_length = 10 Delta_t = 0.01 # Robot dimension and wheel rotation speed mybot = DDRobot() # enables methods to be passed to the Robot and DDRobot classes as objects mybot.radius = wheelradius mybot.length = wheelseparation #initialization block mybot.pos_x = pos_x_0 # calling pos_x method to set x initial position - in center of plot mybot.pos_y = pos_y_0 # calling pos_y method to set y initial position - in center of plot mybot.angle = float(D2R(0)) # initial starting direction: 0 radians mybot.plot = True # turning on plot mybot.mag_plot = 0.5 # coefficient of magnification of the arrow mybot.step_plot = int(50 * 0.01 / Delta_t) mybot.plot_robot() # plotting the robot! mybot._delta = Delta_t # straight line mybot.rt_spd_right = omega mybot.rt_spd_left = omega .011 t = time_for_line(line_length,omega,mybot.radius) mybot.move(t) mybot.plot_robot() # plot robot's entire path plt.xlim([-1, 11]) # axis limits plt.ylim([-11, 11]) plt.rc('font', family='serif') plt.rc('xtick', labelsize=20) plt.rc('ytick', labelsize=20) plt.show() print("final angle of the robot: %.5f" %R2D(mybot.angle)) ### your correction here #correction = ### Demonstration that your correction worked (please modify approprietly) mybot.pos_x = pos_x_0 # calling pos_x method to set x initial position - in center of plot mybot.pos_y = pos_y_0 # calling pos_y method to set y initial position - in center of plot mybot.angle = float(D2R(0)) mybot.rt_spd_right = omega mybot.rt_spd_left = omega # t = time_for_line(line_length,omega,mybot.radius) mybot.move(t) mybot.plot_robot() # plot robot's entire path plt.xlim([-1, 11]) # axis limits plt.ylim([-11, 11]) plt.rc('font', family='serif') plt.rc('xtick', labelsize=20) plt.rc('ytick', labelsize=20) plt.show() print("final angle of the robot: %.5f" %R2D(mybot.angle)) From micromine15 at gmail.com Wed Nov 6 15:40:32 2019 From: micromine15 at gmail.com (Isaiah Foss) Date: Wed, 6 Nov 2019 12:40:32 -0800 (PST) Subject: Robot Drift correction help In-Reply-To: References: Message-ID: Any pointers or help is appreciated, I'm not necessarily asking for answers but any response is appreciated From rosuav at gmail.com Wed Nov 6 15:46:56 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Nov 2019 07:46:56 +1100 Subject: psutil.boot_time() ... doesn't ? In-Reply-To: References: Message-ID: On Thu, Nov 7, 2019 at 7:31 AM R.Wieser
wrote: > > Chris, > > > I don't think boot time would be affected by a DST switch, though. > > It should be recorded in UTC. > > The point is, it /isn't/ a recorded constant (at least not on my machine). > Its just dragged around with the clocks current time (as in: current time > minus uptime). And as such I could easily imagine a DST change will cause > the "boot time" to change accordingly. > Yes, but even if it's not recorded as a timestamp but as an uptime counter, that counter can be referenced against the current time in UTC. A DST switch affects the displayed time, but not the internal definition of "current time" (at least, not on Linux, where the system clock should be in UTC - the rules are different on Windows, and may also be different on other Unix-like OSes); if your current UTC time is 1573072926 seconds and your uptime is 7469247.52 seconds, then you can deduce that your system booted at 1565603679, and then convert that to a displayable boot time in whatever timezone you like (for instance, "Mon Aug 12 19:54:39 2019\n" which is what my ctime() returns). A DST switch wouldn't affect any of this, assuming you have the correct tzdata to figure out whether the boot time was on summer or winter time. ChrisA From tjreedy at udel.edu Wed Nov 6 17:53:26 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 6 Nov 2019 17:53:26 -0500 Subject: psutil.boot_time() ... doesn't ? In-Reply-To: References: Message-ID: On 11/6/2019 3:09 PM, R.Wieser wrote: > Dennis, >> Depends upon the OS... > > My apologies, its Linux (as on a Raspberry Pi). I don't know how much Linux is customized for RP, but last I knew, Python on RP is MicroPython, not CPython. So I expect OS-related functions to not necessarily match Linux on a desktop. -- Terry Jan Reedy From rosuav at gmail.com Wed Nov 6 17:58:48 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Nov 2019 09:58:48 +1100 Subject: psutil.boot_time() ... doesn't ? In-Reply-To: References: Message-ID: On Thu, Nov 7, 2019 at 9:55 AM Terry Reedy wrote: > > On 11/6/2019 3:09 PM, R.Wieser wrote: > > Dennis, > >> Depends upon the OS... > > > > My apologies, its Linux (as on a Raspberry Pi). > > I don't know how much Linux is customized for RP, but last I knew, > Python on RP is MicroPython, not CPython. So I expect OS-related > functions to not necessarily match Linux on a desktop. > Fair point, although in this case, I think the interpreter won't make a difference - the psutil module is pure Python and depends on underlying OS facilities. ChrisA From python at mrabarnett.plus.com Wed Nov 6 18:36:43 2019 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 6 Nov 2019 23:36:43 +0000 Subject: psutil.boot_time() ... doesn't ? In-Reply-To: References: Message-ID: <120b4077-7276-b3cf-4644-3c5a37635189@mrabarnett.plus.com> On 2019-11-06 22:53, Terry Reedy wrote: > On 11/6/2019 3:09 PM, R.Wieser wrote: >> Dennis, >>> Depends upon the OS... >> >> My apologies, its Linux (as on a Raspberry Pi). > > I don't know how much Linux is customized for RP, but last I knew, > Python on RP is MicroPython, not CPython. So I expect OS-related > functions to not necessarily match Linux on a desktop. > MicroPython is for smaller systems. Raspberry Pi has a full Python implementation, as far as I can tell. I have one running Python 3.5 with the regex module installed, the module being downloaded via pip from PyPI and built from source on the RP. No changes were needed to make it work. From eryksun at gmail.com Wed Nov 6 19:51:17 2019 From: eryksun at gmail.com (Eryk Sun) Date: Wed, 6 Nov 2019 18:51:17 -0600 Subject: psutil.boot_time() ... doesn't ? In-Reply-To: References: Message-ID: On 11/6/19, Chris Angelico wrote: > > Yes, but even if it's not recorded as a timestamp but as an uptime > counter, that counter can be referenced against the current time in > UTC. A DST switch affects the displayed time, but not the internal > definition of "current time" (at least, not on Linux, where the system > clock should be in UTC - the rules are different on Windows, and may > also be different on other Unix-like OSes); Windows timestamps are UTC, but the epoch and base time unit are different from Unix. It uses the number of 100 ns intervals since 1601, instead of the number of seconds since 1970. psutil subtracts the value of GetTickCount64() from GetSystemTimeAsFileTime(), so changing the system time will change the reported boot time. But that's expected behavior. Even the kernel's KeBootTime value gets adjusted to account for the time delta when the system time is updated. Otherwise the system would be inconsistent. That said, the kernel (NT 5+) also also has a KeBootTimeBias value that tracks the net delta of KeBootTime from its original value. What psutil does should suffice, but if we need the kernel's exact boot time, without the expense and complexity of a WMI or perflib query, the native system call is NtQuerySystemInformation: SystemTimeOfDayInformation. This returns a SYSTEM_TIMEOFDAY_INFORMATION record, which includes BootTime and BootTimeBias fields. This query is implemented for internal use only, however. The fields and layout of the record are subject to change in future versions of Windows, so caveat emptor. To date, this record was only modified once, back in NT 5 (2000) to augment it with BootTimeBias and SleepTimeBias fields. From luciano at ramalho.org Wed Nov 6 20:07:46 2019 From: luciano at ramalho.org (Luciano Ramalho) Date: Wed, 6 Nov 2019 22:07:46 -0300 Subject: psutil.boot_time() ... doesn't ? In-Reply-To: References: Message-ID: On Wed, Nov 6, 2019 at 7:54 PM Terry Reedy wrote: > I don't know how much Linux is customized for RP, but last I knew, > Python on RP is MicroPython, not CPython. So I expect OS-related > functions to not necessarily match Linux on a desktop. The default OS on all Raspberry Pi models is Raspbian, a full-blown Debian Linux derivative, which comes with Python 2 and Python 3 installed -- CPython, to be clear. MicroPython was designed for microcontroller boards that are too small to run an OS. Popular boards are the BBC microbit and ESP8266. Those devices don't run Linux. To use MicroPython on them, you install firmware that boots directly into the MicroPython runtime, which includes a REPL. Cheers, Luciano > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list -- Luciano Ramalho | Author of Fluent Python (O'Reilly, 2015) | http://shop.oreilly.com/product/0636920032519.do | Technical Principal at ThoughtWorks | Twitter: @ramalhoorg From originallmoney at gmail.com Wed Nov 6 21:26:54 2019 From: originallmoney at gmail.com (originallmoney at gmail.com) Date: Wed, 6 Nov 2019 18:26:54 -0800 (PST) Subject: Trouble trying to get started with pygame In-Reply-To: References: <412bf414-19a5-4937-90fd-3363cb78614b@googlegroups.com> <9313ee4c-7250-4c8f-804b-f468a0dd3c5a@googlegroups.com> <8fe30991-0ad2-632f-bb37-fc9881b8835f@mrabarnett.plus.com> <6798ae9c-8823-4dbb-ae16-06257e49d06a@googlegroups.com> <3717e429-b1c3-8f6f-8dd3-50f89d2a21cc@mrabarnett.plus.com> Message-ID: <019fedd8-8c8e-453e-84aa-39dfa77d28c5@googlegroups.com> > Can py find Python? > > Did you try to install pygame with: > > py -m pip install pygame Well, "py -m pip install pygame" has come the closest so far to working. I saw it try to load it and everything, but then, it spat out a series of errors, but, the primary one seemed to be this: WARNING, No "Setup" File Exists, Running "buildconfig/config.py" From jfong at ms4.hinet.net Wed Nov 6 21:28:01 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Wed, 6 Nov 2019 18:28:01 -0800 (PST) Subject: How execute at least two python files at once when imported? In-Reply-To: References: <761c120d-dad6-ab36-5138-85461f3c1adc@kynesim.co.uk> <258dcd76-2355-db46-26d1-ec42f0f87077@kynesim.co.uk> <8d08c7db-663c-b22f-2567-8402ac351d0a@kynesim.co.uk> <62e0e7b3-0d4b-49cf-aec1-a7e03f8f1fc2@googlegroups.com> <417ca0d2-cd5f-4415-b564-9edee18ba1b6@googlegroups.com> Message-ID: <64d0098e-080c-4eb4-bc6a-df7f3179d937@googlegroups.com> Igor Korot? 2019?11?7???? UTC+8??12?34?35???? > Hi, > > On Wed, Nov 6, 2019 at 10:22 AM Spencer Du wrote: > > > > Hi > > > > Sorry if I haven't stated my requirements clearly. > > > > I just wanted a way to import at least two python files in parallel and I wanted to know how this can be done or a reason why its bad as stated in another post. > > This is not a requirements. > > Let me rephrase my question - what problem are you trying to solve? > > Also, as I said before - I believe there is a language barrier. > > Find some python forum in your native language and ask your question there. > > Thank you. > > > > > Thanks > > Spencer > > -- > > https://mail.python.org/mailman/listinfo/python-list If the OP is a Chinese, from my experience, I doubt there is a chance he can express his problem clearly enough for us who want to help to understand. There is not only the language barrier, but the causes of China education system. Starts from the very beginning in primary school, students are not allowed to think independently and logically. So after growing up, they just lost the ability of expressing things in a logic way. --Jach From veek at dont-use-this.com Wed Nov 6 22:24:37 2019 From: veek at dont-use-this.com (Veek M) Date: Thu, 7 Nov 2019 03:24:37 -0000 (UTC) Subject: SSL/TLS in Python using STARTTLS and ssl/ssltelnet and telnetlib Message-ID: Could someone suggest some introductory reading material that will allow me to use 'telnetlib' with 'ssl' or 'ssltelnet'. (currently using Pan since Knode is dropped on Debian) I'm trying to write something that will download the NNTP headers over TLS. The idea is to 1. telnet to port 119, send 'CAPABILITIES\r\n' using telnetlib 2. then switch to TLS using STARTTLS 3. I tried just connecting to port 119 using a new TLS connection NOT OVER telnet and it didn't work. Apparently you need to pass the TLS context to telnetlib or vice versa. Codes crap i've used bl_varname (bytes list) inconsistently - till I figure out what to do with TLS. import ssl, socket import sys, time from telnetlib import Telnet from ssltelnet import SslTelnet port = 119 server = 'news.eternal-september.org' user = 'v' passwd = 'b' class Response(object): def __init__(self, tn, cmds = '', wmsg = ''): self.tn = tn; self.total_data = []; self.wmsg = wmsg d = { 'r': self.read_server, 'w': self.write_server, 'p': self.bl_print } for c in cmds: d[c]() def read_server(self): tn = self.tn; total_data = []; count = 0 while True: data = tn.read_very_eager() if len(data): count = 0 total_data.append(data) else: time.sleep(1) count += 1 if count > 4: self.total_data = total_data return def write_server(self): tn = self.tn; txt = self.wmsg for line in txt.split('\n'): b_line = bytes(line + '\r\n', encoding='ascii') tn.write(b_line) def bl_print(self): data = self.total_data if len(data): for line in data: print(line.decode()) else: print('no data') def tls(): sock = socket.socket(family=AF_INET, type=SOCK_STREAM) ssl_sock = ssl.wrap_socket(sock) class Server(object): def __init__(self, server = server, port = port): with Telnet(server, port, timeout = 10) as tn: Response(tn = tn, cmds = 'rp') Response(tn = tn, cmds = 'wrp', wmsg='CAPABILITIES') Response(tn = tn, cmds = 'wrp', wmsg='STARTTLS') s = SslTelnet(force_ssl = False, telnet_tls = True, host = server, port = port) print(s.read_very_eager()) time.sleep(2) print(s.read_very_eager()) s = Server() From python at mrabarnett.plus.com Wed Nov 6 22:34:16 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 7 Nov 2019 03:34:16 +0000 Subject: Trouble trying to get started with pygame In-Reply-To: <019fedd8-8c8e-453e-84aa-39dfa77d28c5@googlegroups.com> References: <412bf414-19a5-4937-90fd-3363cb78614b@googlegroups.com> <9313ee4c-7250-4c8f-804b-f468a0dd3c5a@googlegroups.com> <8fe30991-0ad2-632f-bb37-fc9881b8835f@mrabarnett.plus.com> <6798ae9c-8823-4dbb-ae16-06257e49d06a@googlegroups.com> <3717e429-b1c3-8f6f-8dd3-50f89d2a21cc@mrabarnett.plus.com> <019fedd8-8c8e-453e-84aa-39dfa77d28c5@googlegroups.com> Message-ID: <207693a2-67ce-4fb1-4375-8933dd50a89b@mrabarnett.plus.com> On 2019-11-07 02:26, originallmoney at gmail.com wrote: >> Can py find Python? >> >> Did you try to install pygame with: >> >> py -m pip install pygame > > Well, "py -m pip install pygame" has come the closest so far to working. I saw it try to load it and everything, but then, it spat out a series of errors, but, the primary one seemed to be this: > > WARNING, No "Setup" File Exists, Running "buildconfig/config.py" > How about downloading the wheel from Christoph Gohlke's site and using pip on that, as I suggested on 2019-11-01? From Richard at Damon-Family.org Wed Nov 6 22:40:22 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Wed, 6 Nov 2019 22:40:22 -0500 Subject: How execute at least two python files at once when imported? In-Reply-To: <54198430-de28-f6dd-f2e4-a5c6e528469e@gmail.com> References: <761c120d-dad6-ab36-5138-85461f3c1adc@kynesim.co.uk> <258dcd76-2355-db46-26d1-ec42f0f87077@kynesim.co.uk> <8d08c7db-663c-b22f-2567-8402ac351d0a@kynesim.co.uk> <62e0e7b3-0d4b-49cf-aec1-a7e03f8f1fc2@googlegroups.com> <417ca0d2-cd5f-4415-b564-9edee18ba1b6@googlegroups.com> <54198430-de28-f6dd-f2e4-a5c6e528469e@gmail.com> Message-ID: On 11/6/19 3:37 PM, Michael Torrie wrote: > On 11/6/19 9:16 AM, Spencer Du wrote: >> I just wanted a way to import at least two python files in parallel >> and I wanted to know how this can be done or a reason why its bad as >> stated in another post. > It's not "bad," but it's also not possible. Nor does it make sense. > That's why so many people are questioning what you are really trying to > accomplish. By definition a Python script is a sequence of statements > that are read and executed in sequence. You can't just run them all at > once, nor would it make sense to do so. > > If you want to run multiple python functions in parallel, there are > threads for that, multiprocessing, and also asynchronous scheduling. > > But no one can tell you what to do because none of us have any clue what > you are trying to accomplish. I would disagree that it isn't possible, depending on exactly what is wanted, I can think of several ways to do it. Simplest option is fork off a separate process and run the second script from that process, that would work if the two scripts don't need much communication between themselves, and you would need to manually add what ever communication was needed. A second option is to create a second thread, and do one if the imports in that thread, and one in the main thread. This is likely the closest to the stated goal, but likely, due to the GIL, slower than doing one after the other. -- Richard Damon From originallmoney at gmail.com Thu Nov 7 01:01:20 2019 From: originallmoney at gmail.com (originallmoney at gmail.com) Date: Wed, 6 Nov 2019 22:01:20 -0800 (PST) Subject: Trouble trying to get started with pygame In-Reply-To: References: <412bf414-19a5-4937-90fd-3363cb78614b@googlegroups.com> <9313ee4c-7250-4c8f-804b-f468a0dd3c5a@googlegroups.com> <8fe30991-0ad2-632f-bb37-fc9881b8835f@mrabarnett.plus.com> <6798ae9c-8823-4dbb-ae16-06257e49d06a@googlegroups.com> <3717e429-b1c3-8f6f-8dd3-50f89d2a21cc@mrabarnett.plus.com> <019fedd8-8c8e-453e-84aa-39dfa77d28c5@googlegroups.com> <207693a2-67ce-4fb1-4375-8933dd50a89b@mrabarnett.plus.com> Message-ID: > > Well, "py -m pip install pygame" has come the closest so far to working. I saw it try to load it and everything, but then, it spat out a series of errors, but, the primary one seemed to be this: > > > > WARNING, No "Setup" File Exists, Running "buildconfig/config.py" > > > How about downloading the wheel from Christoph Gohlke's site and using > pip on that, as I suggested on 2019-11-01? What's the difference in syntax? Because, I DID notice that it seemed to be trying to open the other Pygame I had (The tar.gz version), so, I'm imagining there would be some difference somewhere. Or, could I simply switch out the tar.gz version with the wheel version inside the folder? From renesd at gmail.com Thu Nov 7 01:21:05 2019 From: renesd at gmail.com (=?UTF-8?Q?Ren=C3=A9_Dudfield?=) Date: Thu, 7 Nov 2019 07:21:05 +0100 Subject: Trouble trying to get started with pygame In-Reply-To: References: <412bf414-19a5-4937-90fd-3363cb78614b@googlegroups.com> <9313ee4c-7250-4c8f-804b-f468a0dd3c5a@googlegroups.com> <8fe30991-0ad2-632f-bb37-fc9881b8835f@mrabarnett.plus.com> <6798ae9c-8823-4dbb-ae16-06257e49d06a@googlegroups.com> <3717e429-b1c3-8f6f-8dd3-50f89d2a21cc@mrabarnett.plus.com> <019fedd8-8c8e-453e-84aa-39dfa77d28c5@googlegroups.com> <207693a2-67ce-4fb1-4375-8933dd50a89b@mrabarnett.plus.com> Message-ID: Hi, either use python 3.7, or use the pre-release of pygame 2. py -m pip install pygame==2.0.0.dev6 We're not going to do a python 3.8 release for pygame 1.9.x cheers, On Thu, Nov 7, 2019 at 7:06 AM wrote: > > > Well, "py -m pip install pygame" has come the closest so far to > working. I saw it try to load it and everything, but then, it spat out a > series of errors, but, the primary one seemed to be this: > > > > > > WARNING, No "Setup" File Exists, Running "buildconfig/config.py" > > > > > How about downloading the wheel from Christoph Gohlke's site and using > > pip on that, as I suggested on 2019-11-01? > > What's the difference in syntax? Because, I DID notice that it seemed to > be trying to open the other Pygame I had (The tar.gz version), so, I'm > imagining there would be some difference somewhere. Or, could I simply > switch out the tar.gz version with the wheel version inside the folder? > -- > https://mail.python.org/mailman/listinfo/python-list > From cs at cskk.id.au Thu Nov 7 02:25:39 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 7 Nov 2019 18:25:39 +1100 Subject: How execute at least two python files at once when imported? In-Reply-To: References: Message-ID: <20191107072539.GA41306@cskk.homeip.net> On 06Nov2019 18:15, Rhodri James wrote: >On 06/11/2019 16:02, Spencer Du wrote: >>Why is importing modules in parallel bad? > >To put it as simply as I can: > >1. The import mechanism is complicated, even the bits that are >user-visible. Fiddling with it has a high chance of going wrong. > >2. Multi-threading is less complicated than import, but still requires >a lot of careful thought. For example you've asserted that the >modules you want to import simultaneously, but you also need to >consider the import mechanism itself. > >Put 1 and 2 together, and multi-threaded import sounds like a >nightmare. The import machinery has an internal lock. Parallel import statements via threads is, of itself, a safe thing to do. But if the module does significant work on things outside itself (eg doing work beyond defining local classes, constants etc) that work needs to be thread safe. Provided the imported modules do only local work it should be safe. Spencer's modules run unconditional stuff in addition to defining classes. That may cause trouble. Cheers, Cameron Simpson From cs at cskk.id.au Thu Nov 7 02:31:35 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 7 Nov 2019 18:31:35 +1100 Subject: How execute at least two python files at once when imported? In-Reply-To: <417ca0d2-cd5f-4415-b564-9edee18ba1b6@googlegroups.com> References: <417ca0d2-cd5f-4415-b564-9edee18ba1b6@googlegroups.com> Message-ID: <20191107073135.GA54973@cskk.homeip.net> On 06Nov2019 08:16, Spencer Du wrote: >Sorry if I haven't stated my requirements clearly. >I just wanted a way to import at least two python files in parallel and >I wanted to know how this can be done or a reason why its bad as stated >in another post. Parallel imports can be fine. However, you want to avoid parallel code which works on shared data structures without the necessary synchronisation may be hazardous. Your modules look like this: import stuff ... define functions and classes inline code performing a kind of "main programme" That inline code gets run unconditionally, at import time. What would be better would be if your modules looked like this: import stuff ... define functions and classes def main(): inline code performing a kind of "main programme" Then your "real" main programme can go: import your_module1 import your_module2 start a thread running your_module1.main() start a thread running your_module2.main() which gets the imports done; they happen in series but just defining things (classes and functions) is very fast. Then dispatch some Threads to run your main functions from each module. If those main functions do not share data it will probably all just work. If they do share data then you may need to debug some synchronisation issues; it depends on the code itself. Cheers, Cameron Simpson From auriocus at gmx.de Thu Nov 7 03:17:00 2019 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 7 Nov 2019 09:17:00 +0100 Subject: OT language barrier, was: How execute at least two python files at once when imported? In-Reply-To: References: <761c120d-dad6-ab36-5138-85461f3c1adc@kynesim.co.uk> <258dcd76-2355-db46-26d1-ec42f0f87077@kynesim.co.uk> <8d08c7db-663c-b22f-2567-8402ac351d0a@kynesim.co.uk> <62e0e7b3-0d4b-49cf-aec1-a7e03f8f1fc2@googlegroups.com> <417ca0d2-cd5f-4415-b564-9edee18ba1b6@googlegroups.com> Message-ID: Am 06.11.19 um 17:34 schrieb Igor Korot: > On Wed, Nov 6, 2019 at 10:22 AM Spencer Du wrote: >> Sorry if I haven't stated my requirements clearly. >> >> I just wanted a way to import at least two python files in parallel and I wanted to know how this can be done or a reason why its bad as stated in another post. > > This is not a requirements. > > Let me rephrase my question - what problem are you trying to solve? > > Also, as I said before - I believe there is a language barrier. > > Find some python forum in your native language and ask your question there. > Off topic, but how do you conclude that the OP is a non-native English speaker or has inferior command of the English language? He sounds very English to me, and the name and email address also do not indicate non-English origin to me? My impression was that there IS a language barrier for technical terms, but not with English per se - he used the word "import" incorrectly, when he meant "run", because he abused "import lala" to run a Python program. Christian From address at not.available Thu Nov 7 04:23:19 2019 From: address at not.available (R.Wieser) Date: Thu, 7 Nov 2019 10:23:19 +0100 Subject: psutil.boot_time() ... doesn't ? References: <2it6se1runrc1ojqfuv4bf6hgq01vtb3nd@4ax.com> Message-ID: Dennis, > Which is probably... last file system modification time Nope. Its from a file it saves at shutdown, and which gets updated once an hour (I also thought of that one, but the once-an-hour update threw a wrench into it). > There is no way for a freshly booted system to differentiate between [snip] True. But 1) thats not likely the moment I will be looking at the "has the time been updated" 2) The same goes for having NTP (or any other such "wait for it ..." method) update the clock. > Except that "last boot time" is really "booted /n/ minutes ago > from /now/". Than thats the point where we disagree. Boot time is not just a gadget for the user to look and gawk at, it has (or /should/ have) its usages. Like allowing someone to determine which files have been altered since last boot. Besides, all you now get is uptime, just presented differently. :-( > http://man7.org/linux/man-pages/man5/crontab.5.html#EXTENSIONS > > The main concern is just how soon after reboot that @reboot executes. Yup. And in which order the different programs and scripts are ran .... > https://www.cyberciti.biz/faq/linux-execute-cron-job-after-system-reboot/ > has an example with a sleep... Thanks for those links. I'll have a look at them. Regards, Rudy Wieser From colin.mcphail at mac.com Thu Nov 7 05:18:30 2019 From: colin.mcphail at mac.com (Colin McPhail) Date: Thu, 7 Nov 2019 10:18:30 +0000 Subject: SSL/TLS in Python using STARTTLS and ssl/ssltelnet and telnetlib In-Reply-To: References: Message-ID: <9B3A06F2-634E-447A-B1AF-1C93F4195AD4@mac.com> > On 7 Nov 2019, at 03:24, Veek M wrote: > > Could someone suggest some introductory reading material that will allow > me to use 'telnetlib' with 'ssl' or 'ssltelnet'. > (currently using Pan since Knode is dropped on Debian) > > I'm trying to write something that will download the NNTP headers over > TLS. > > The idea is to > 1. telnet to port 119, send 'CAPABILITIES\r\n' using telnetlib > 2. then switch to TLS using STARTTLS > 3. I tried just connecting to port 119 using a new TLS connection NOT > OVER telnet and it didn't work. Apparently you need to pass the TLS > context to telnetlib or vice versa. > ... Any reason you're not using nntplib from the Python Standard Library? It supports the STARTTLS command. If you don't want to use nntplib you could look at its code to see how it works. -- Colin From jon+usenet at unequivocal.eu Thu Nov 7 06:17:24 2019 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Thu, 7 Nov 2019 11:17:24 -0000 (UTC) Subject: SSL/TLS in Python using STARTTLS and ssl/ssltelnet and telnetlib References: Message-ID: On 2019-11-07, Veek M wrote: > Could someone suggest some introductory reading material that will allow > me to use 'telnetlib' with 'ssl' or 'ssltelnet'. > (currently using Pan since Knode is dropped on Debian) > > I'm trying to write something that will download the NNTP headers over > TLS. As someone else has pointed out, nntplib would be the obvious choice for this. But even if you don't want to use that, you absolutely should not be using telnetlib. NNTP is not Telnet and there is no connection between the two protocols. (Don't get misled by the common practice of using the command-line telnet client as a convenient way for connecting to line-based TCP services for testing purposes.) From greg.ewing at canterbury.ac.nz Thu Nov 7 06:52:33 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 08 Nov 2019 00:52:33 +1300 Subject: How execute at least two python files at once when imported? In-Reply-To: References: <20191107072539.GA41306@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > Spencer's modules run unconditional stuff in addition to defining > classes. That may cause trouble. It will -- because of the import lock, they won't run simultaneously in the same process. -- Greg From greg.ewing at canterbury.ac.nz Thu Nov 7 07:06:05 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 08 Nov 2019 01:06:05 +1300 Subject: OOP - how to abort an __init__ when the initialisation code fails ? In-Reply-To: References: <20191105195259.GA11016@hjp.at> Message-ID: Oscar Benjamin wrote: > In Python the original exception message plus traceback is often very > informative (to a programmer!) about the problem. That's okay, exception chaining preserves the whole traceback if you want to dig down that far. > Catching and > reraising can mean that you end up crafting an error message somewhere > higher up where the filename isn't known any more. Well, the idea is to catch it some place where the filename *is* known. And when reraising, only add to the error message rather than replacing it altogether, so once the filename is in there it stays there, even if another catch-and-reraise occurs higher up. -- Greg From mail.stephen.waldron at gmail.com Thu Nov 7 08:36:04 2019 From: mail.stephen.waldron at gmail.com (Stephen Waldron) Date: Thu, 7 Nov 2019 05:36:04 -0800 (PST) Subject: Syntax Suggestion: Pass Function Definition as Argument Message-ID: <6da7c5f1-003e-4b19-b9e8-715ecba8624e@googlegroups.com> Hi, I'm new to the group and to Python, so forgive me if I make any faux-pas here. As I can tell, the only way to pass a function as an argument is to reference its name as follows: def foo1(message): print(message) def foo2(foo, message): print("Your function says:") foo(message) >>foo2(foo1, "Hello World!") Your function says: Hello World! This is how it is at the moment, however it may be more agreeable, especially if that is the only purpose of the function, for python users to be able to define new functions inside of function calls. The way I propose this may occur is using similar syntax as control structures, as exampled below: def foo2(foo): print("Message to print:", end = " ") foo() >>foo2(): ....print("Hello World!") Message to print: Hello World! In this proposal, it should be noted, that unlike control structures, the brackets are required for the function call. The "suite" or "annex" is defined as a function object by the compiler and passed inside the call. Here are some other examples of the proposal. *Non-Function Arguments with Annexed Functions* Non-Function Arguments should be placed in the brackets before annexed functions, and this should be reflected in the parameter order. If they are not, they won't be assigned to, which would cause an error unless a default value is given. These parameters could be available for passing in the annexed function if mentioned when the paramaeter is called. def myFoo (num1, num2, foo): return foo (num1, num2) >>myFoo(20, 30): ....return num1 + num2 50 *Annexing Multiple Functions or Out of Order Annex* To specify the order in which functions are annexed, or annex multiple functions, one could use the parameter name before the specific suite. class Book: def __init__(self, name, author): self.name = name self.author = author def doToBooks (bookList, first, then, book = None): for book in bookList first(book = book) then(book = book) myBooks = [ Book("The Way of the World", "Lucy Cole"), Book("To Live or To Love", "Georgio Dunham"), Book("Twelve Days of Success", "Anita Duvette") ] doToBooks (myBooks): print(book.name) then: print(" - " + book.author + "\n") > The Way of The World - Lucy Cole To Live or To Die - Georgio Dunham Twelve Days of Success - Anita Duvette This proposal does not detract from the core appearance and appeal of Python while creating an option for users and module makers who want themselves or the users of their modules not to have to previously define functions in order to use the code. This would make such code more aesthetic and compact, and take away the need for defining a new function, name and all, specifically for such which ultimately would be used only once as an argument. From duram at terra.com.br Thu Nov 7 08:52:00 2019 From: duram at terra.com.br (Daniel) Date: Thu, 7 Nov 2019 10:52:00 -0300 Subject: Python 3.8 install Message-ID: How to install Python 3.8 on top of Python 3.6? -- Este email foi escaneado pelo Avast antiv?rus. https://www.avast.com/antivirus From address at not.available Thu Nov 7 02:56:33 2019 From: address at not.available (R.Wieser) Date: Thu, 7 Nov 2019 08:56:33 +0100 Subject: psutil.boot_time() ... doesn't ? References: Message-ID: Chris, > Yes, but even if it's not recorded as a timestamp but as an > uptime counter, that counter can be referenced against the > current time in UTC. Absolutily. Though the keyword here is "can". My "could easily imagine" considers the other possibility. I guess I should sit down sometime and just flip the date back and forward (in-and-outof DST), and see how the result of psutil.boot_time() compares to the thanwhile current time. Regards, Rudy Wieser From antoon.pardon at vub.be Thu Nov 7 09:32:37 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 7 Nov 2019 15:32:37 +0100 Subject: Syntax Suggestion: Pass Function Definition as Argument In-Reply-To: <6da7c5f1-003e-4b19-b9e8-715ecba8624e@googlegroups.com> References: <6da7c5f1-003e-4b19-b9e8-715ecba8624e@googlegroups.com> Message-ID: <5ec2dbee-9228-4352-4f69-18639cde2f56@vub.be> On 7/11/19 14:36, Stephen Waldron wrote: > Hi, I'm new to the group and to Python, so forgive me if I make any faux-pas here. As I can tell, the only way to pass a function as an argument is to reference its name as follows: > > def foo1(message): > print(message) > > def foo2(foo, message): > print("Your function says:") > foo(message) No that is not true. "map" is a function that takes a function as its first argument. But I can do the following if I want to produce the inverses of a list of numbers. from operator import truediv from functools import partial ls = range(1, 11) for x in map(partial(truediv, 1), ls): print(x) In the code above "partial(truediv, 1)" will produce a function that will inverse its argument and I don't need to give this function a name to pass it as an argument in an other function. -- Antoon Pardon. From grant.b.edwards at gmail.com Thu Nov 7 10:54:39 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 7 Nov 2019 15:54:39 -0000 (UTC) Subject: SSL/TLS in Python using STARTTLS and ssl/ssltelnet and telnetlib References: Message-ID: On 2019-11-07, Jon Ribbens via Python-list wrote: > On 2019-11-07, Veek M wrote: >> Could someone suggest some introductory reading material that will allow >> me to use 'telnetlib' with 'ssl' or 'ssltelnet'. >> (currently using Pan since Knode is dropped on Debian) >> >> I'm trying to write something that will download the NNTP headers >> over TLS. > > As someone else has pointed out, nntplib would be the obvious choice > for this. But even if you don't want to use that, you absolutely > should not be using telnetlib. NNTP is not Telnet and there is no > connection between the two protocols. (Don't get misled by the common > practice of using the command-line telnet client as a convenient way > for connecting to line-based TCP services for testing purposes.) IIRC, the reason that you could test stuff like NNTP servers using the old Unix telnet client is because that client defaults to disabling all of the actual TELNET protocol and handshaking support when connected to a port other than 23. -- Grant Edwards grant.b.edwards Yow! PARDON me, am I at speaking ENGLISH? gmail.com From arnaud at sphaero.org Thu Nov 7 11:32:15 2019 From: arnaud at sphaero.org (Arnaud Loonstra) Date: Thu, 7 Nov 2019 17:32:15 +0100 Subject: return a ctypes object to C In-Reply-To: <7fcc81f2-c53c-e9c2-4fe5-1371b3bbea67@sphaero.org> References: <3a846468-b53a-eb1b-17ec-587cc8115ce0@sphaero.org> <44acf750-13eb-4049-1568-4ab43a95658a@sphaero.org> <296dd104-0039-c162-1f68-429464505465@tjol.eu> <7fcc81f2-c53c-e9c2-4fe5-1371b3bbea67@sphaero.org> Message-ID: <017eeddb-2b99-2025-7512-c04f1737307e@sphaero.org> On 31-10-2019 15:39, Arnaud Loonstra wrote: > On 31-10-2019 14:44, Thomas Jollans wrote: >> On 31/10/2019 14.13, Arnaud Loonstra wrote: >>> On 30-10-2019 09:32, Arnaud Loonstra wrote: >>>> Hi all, >>>> >>>> I'm trying to wrap my head around the ctypes API. I have a C >>>> structure I wish to create in Python and then return from python to C. >>>> >>>> So a python method is called from C and needs to return an object >>>> which we then process in C again. >>>> >>>> I have a binding to access and create the C methods and structures so >>>> in Python I can call the Zmsg() constructor. I now need to return this. >>>> >>>> My python test method is simply: >>>> >>>> def actor_test( *args, **kwargs): >>>> ????? print("test") >>>> ????? msg = Zmsg() >>>> ????? frame = Zframe(b"Hello", 5) >>>> ????? msg.prepend(frame) >>>> ????? return msg >>>> >>>> the method is called from C as follows: >>>> >>>> PyObject *pReturn = PyObject_CallObject(pFunc, NULL); >>>> >>>> This correctly calls the method. However the returned object is of >>>> course a PyObject*. The debugger says it's >>>> >>>> ""??? PyObject >>>> ????????????? [class]??? "" >>>> ????????????? [super class]??? "" >>>> ????????????? [meta type]??? "" >>>> ????????????? ob_refcnt??? 1??? Py_ssize_t >>>> >>>> However how I can I get it back to the original C type (zmsg_t *) >>>> >>>> Any help really appreciated. >>>> >>> >>> What I've found so far is that I can return the address of the ctypes >>> object. >>> >>> msg = Zmsg() >>> frame = Zframe(b"Hello", 5) >>> msg.prepend(frame) >>> return addressof(msg._as_parameter_.contents) >>> >>> In C I can then cast it back to the original type. >>> >>> PyObject *pReturn = PyObject_CallObject(pFunc, NULL); >>> assert(pReturn); >>> long bla = PyLong_AsLong(pReturn); >>> zmsg_t* test = (zmsg_t *)bla; >>> assert(test); >>> char *hello = zmsg_popstr(test); >>> assert(hello); >>> assert(streq(hello, "Hello")); >>> >>> This works, I'm not sure if this is the right way. It also creates a >>> complicated setup with the garbage collector. >>> >>> Anybody better ideas? >> >> You've already got a complicated setup with your ctypes objects... >> >> If you're using the Python C API anyway, why would you use ctypes at >> all? You can create custom Python types in C to wrap your C pointers. >> >> Alternatively: if you're using ctypes anyway, why use the Python C API >> at all? You can create C function pointers from Python functions with >> ctypes. >> >> If you're mixing two different ways of interfacing Python and C, the >> result will ALWAYS be messy. Better to stick to one. Personally, I >> prefer cffi or cython depending on the situation, as I find them clearer >> and easier to use than ctypes. Using the Python C API directly is >> usually the hardest to understand and the easiest to get wrong. >> >> -- Thomas > > Hi Thomas, > > I have an engine running which can call handlers. These handlers return > a zmsg_t (a message) which the engine then can process. > > In this engine we have Python embedded and I want to use a Python method > as a handler. To embed Python we need to use the Python C API. To > construct a zmsg_t type in Python we need to call the corresponding C > method and we use ctypes to do that. > > I'm using a ctypes binding because it already exists, it's here: > https://github.com/zeromq/czmq/blob/d6283985ba52fd8c3f8fbdc7cd5c08372ff69ca1/bindings/python/czmq/_czmq_ctypes.py#L4392 > > > I know I can use cffi for example but that's IMHO just a ctypes > alternative. > > Are you saying it's better to create some approach to create a zmsg_t > using the Python C API? > > Please enlighten me if this should be done differently. > > Rg, > > Arnaud Ok, you're reply triggered me to do some more reading into the C-API. I've found I can do it all using the C-API. Especially this guide was very helpful for my situation: https://docs.python.org/3/extending/newtypes_tutorial.html Thnx, Arnaud From python at mrabarnett.plus.com Thu Nov 7 11:59:27 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 7 Nov 2019 16:59:27 +0000 Subject: Python 3.8 install In-Reply-To: References: Message-ID: <00e134c7-2ad0-00af-2f41-03e48d9827d4@mrabarnett.plus.com> On 2019-11-07 13:52, Daniel wrote: > How to install Python 3.8 on top of Python 3.6? > Don't do that. If you're using Windows, you install into a separate folder, usually called Python36 for Python 3.6 and Python38 for Python 3.8. From mail.stephen.waldron at gmail.com Thu Nov 7 12:08:16 2019 From: mail.stephen.waldron at gmail.com (Stephen Waldron) Date: Thu, 7 Nov 2019 09:08:16 -0800 (PST) Subject: Syntax Suggestion: Pass Function Definition as Argument In-Reply-To: <6da7c5f1-003e-4b19-b9e8-715ecba8624e@googlegroups.com> References: <6da7c5f1-003e-4b19-b9e8-715ecba8624e@googlegroups.com> Message-ID: Thanks Antoon. I do suppose that it is kind of wrong to say the only way is to "reference its [the function's] name" as an argument, however the point I was trying to make was that you cannot pass a function that is either not in some way previously defined or a reference to something previously defined. In your example, you still make reference to the existing function `truediv` from the `operator` library, even though the `partial` function does create a new function. What I'm aiming for is the ability to, within a function call, pass a suite that would be there automatically defined by the compiler/interpreter. Another comment did mention lambda functions, which does to some degree provide that capability, but is restricted to well, lambda functions (only expressions, not statements). Your example does however suggest the possibilities of a function or expression that creates functions. For example, the `function` expression in JavaScript. ``` //Definition function myFoo (str1, str2, foo){ console.log( foo(str1), foo(str2) ); } //Call myFoo ("hello", "world!", function(str){ str[0] = str[0].toUpper(); return str; }); Output: Hello World! ``` However it does not seem that there would be any such expression in Python as is. In python, this code would be written: ``` #Definition def myFoo (str1, str2, foo): print( foo(str1), foo(str2) ) #Call def other_foo(str): str = list(str)[0].upper() + str[1:] return str myFoo ("hello", "world!", other_foo) ``` Here is it rewritten using the proposal: ``` #Definition def myFoo (str1, str2, foo, str = " "): print( foo(str = str1), foo(str = str2) ) #Call myFoo ("hello", "world!"): str = list(str)[0].upper() + str[1:] return str ``` Of course this example presents only a minor, though you can see the difference in the call, in which no new function needs be referenced. From mail.stephen.waldron at gmail.com Thu Nov 7 12:10:06 2019 From: mail.stephen.waldron at gmail.com (Stephen Waldron) Date: Thu, 7 Nov 2019 09:10:06 -0800 (PST) Subject: Syntax Suggestion: Pass Function Definition as Argument In-Reply-To: <6da7c5f1-003e-4b19-b9e8-715ecba8624e@googlegroups.com> References: <6da7c5f1-003e-4b19-b9e8-715ecba8624e@googlegroups.com> Message-ID: Thanks Antoon. I do suppose that it is kind of wrong to say the only way is to "reference its [the function's] name" as an argument, however the point I was trying to make was that it isn't possible to pass a function that is either not in some way previously defined or a reference to something previously defined. In your example, you still make reference to the existing function `truediv` from the `operator` library, even though the `partial` function does create a new function. What I'm aiming for is the ability to, within a function call, pass a suite that would be there automatically defined by the compiler/interpreter. Another comment did mention lambda functions, which does to some degree provide that capability, but is restricted to well, lambda functions (only expressions, not statements). Your example does however suggest the possibilities of a function or expression that creates functions. For example, the `function` expression in JavaScript. ``` //Definition function myFoo (str1, str2, foo){ console.log( foo(str1), foo(str2) ); } //Call myFoo ("hello", "world!", function(str){ str[0] = str[0].toUpper(); return str; }); Output: Hello World! ``` However it does not seem that there would be any such expression in Python as is. In python, this code would be written: ``` #Definition def myFoo (str1, str2, foo): print( foo(str1), foo(str2) ) #Call def other_foo(str): str = list(str)[0].upper() + str[1:] return str myFoo ("hello", "world!", other_foo) ``` Here is it rewritten using the proposal: ``` #Definition def myFoo (str1, str2, foo, str = " "): print( foo(str = str1), foo(str = str2) ) #Call myFoo ("hello", "world!"): str = list(str)[0].upper() + str[1:] return str ``` Of course this example presents only a minor, though you can see the difference in the call, in which no new function needs be referenced. From tjreedy at udel.edu Thu Nov 7 12:52:48 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 7 Nov 2019 12:52:48 -0500 Subject: Python 3.8 install In-Reply-To: <00e134c7-2ad0-00af-2f41-03e48d9827d4@mrabarnett.plus.com> References: <00e134c7-2ad0-00af-2f41-03e48d9827d4@mrabarnett.plus.com> Message-ID: On 11/7/2019 11:59 AM, MRAB wrote: > On 2019-11-07 13:52, Daniel wrote: >> How to install Python 3.8 on top of Python 3.6? >> > Don't do that. > > If you're using Windows, you install into a separate folder, usually > called Python36 for Python 3.6 and Python38 for Python 3.8. Both the Windows and macOS installers put each version in separate directories by default. On Windows, I change the patch to my Python directory but leave the final directory name, Pythonxy, alone. On macOS, I don't touch the path. -- Terry Jan Reedy From David.Raymond at tomtom.com Thu Nov 7 13:04:06 2019 From: David.Raymond at tomtom.com (David Raymond) Date: Thu, 7 Nov 2019 18:04:06 +0000 Subject: Syntax Suggestion: Pass Function Definition as Argument In-Reply-To: References: <6da7c5f1-003e-4b19-b9e8-715ecba8624e@googlegroups.com> Message-ID: Here is it rewritten using the proposal: ``` #Definition def myFoo (str1, str2, foo, str = " "): print( foo(str = str1), foo(str = str2) ) #Call myFoo ("hello", "world!"): str = list(str)[0].upper() + str[1:] return str ``` Are you looking for multi-line lambdas? Isn't this basically just defining a function... but without an argument list? How would that know what "str" is? Since you can already define functions inside of functions, what functionality does this give you that you can't already do with something like this: def myFoo(str1, str2, foo): print(foo(str1), foo(str2)) def main(): print("Stuff here") def f1(str): str = list(str)[0].upper() + str[1:] return str myFoo("hello", "world", f1) def f1(str): #yup, same name str = str[:-1] + list(str)[-1].upper() return str myFoo("hello", "world", f1) del f1 print("More stuff") main() Which results in: Stuff here Hello World hellO worlD More stuff From rosuav at gmail.com Thu Nov 7 13:31:13 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Nov 2019 05:31:13 +1100 Subject: psutil.boot_time() ... doesn't ? In-Reply-To: References: Message-ID: On Fri, Nov 8, 2019 at 1:24 AM R.Wieser
wrote: > > Chris, > > > Yes, but even if it's not recorded as a timestamp but as an > > uptime counter, that counter can be referenced against the > > current time in UTC. > > Absolutily. Though the keyword here is "can". My "could easily imagine" > considers the other possibility. > > I guess I should sit down sometime and just flip the date back and forward > (in-and-outof DST), and see how the result of psutil.boot_time() compares to > the thanwhile current time. > Yep! Nothing like experimentation! :) ChrisA From lists at vanderhoff.org Thu Nov 7 13:46:25 2019 From: lists at vanderhoff.org (tony van der Hoff) Date: Thu, 7 Nov 2019 18:46:25 +0000 Subject: can't install http module Message-ID: Hi, I'm attempting to install (among other things) the "http" module on my debian10 box, and am encountering the following problem: ########################## tony at tony-lx:~/_pycharm/pygallery$ python3 -m pip install http Collecting http ? Using cached https://files.pythonhosted.org/packages/e3/91/a9260805e532e33df273b8f7dffad5c51693f8f9ba5f86bedcf42a7f22eb/http-0.02.tar.gz ??? Complete output from command python setup.py egg_info: ??? Traceback (most recent call last): ????? File "", line 1, in ????? File "/tmp/pip-install-fr02g_f6/http/setup.py", line 3, in ??????? import http ????? File "/tmp/pip-install-fr02g_f6/http/http/__init__.py", line 17, in ??????? from request import Request ??? ModuleNotFoundError: No module named 'request' ??? ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-fr02g_f6/http/ ########################## So, I tried installing "request": ########################## tony at tony-lx:~/_pycharm/pygallery$ python3 -m pip install request Collecting request ? Downloading https://files.pythonhosted.org/packages/f1/27/7cbde262d854aedf217061a97020d66a63163c5c04e0ec02ff98c5d8f44e/request-2019.4.13.tar.gz Collecting get (from request) ? Downloading https://files.pythonhosted.org/packages/3f/ef/bb46f77f7220ac1b7edba0c76d810c89fddb24ddd8c08f337b9b4a618db7/get-2019.4.13.tar.gz Collecting post (from request) ? Downloading https://files.pythonhosted.org/packages/0f/05/bd79da5849ea6a92485ed7029ef97b1b75e55c26bc0ed3a7ec769af666f3/post-2019.4.13.tar.gz Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from request) (40.8.0) Collecting query_string (from get->request) ? Downloading https://files.pythonhosted.org/packages/12/3c/412a45daf5bea9b1d06d7de41787ec4168001dfa418db7ec8723356b119f/query-string-2019.4.13.tar.gz Collecting public (from query_string->get->request) ? Downloading https://files.pythonhosted.org/packages/54/4d/b40004cc6c07665e48af22cfe1e631f219bf4282e15fa76a5b6364f6885c/public-2019.4.13.tar.gz Building wheels for collected packages: request, get, post, query-string, public ? Running setup.py bdist_wheel for request ... done ? Stored in directory: /home/tony/.cache/pip/wheels/30/84/5f/484cfba678967ef58c16fce6890925d5c7172622f20111fbfd ? Running setup.py bdist_wheel for get ... done ? Stored in directory: /home/tony/.cache/pip/wheels/c1/e3/c1/d02c8c58538853e4c9b78cadb74f6d5c5c370b48a69a7271aa ? Running setup.py bdist_wheel for post ... done ? Stored in directory: /home/tony/.cache/pip/wheels/c3/c3/24/b5c132b537ab380c02d69e6bd4dec1f5db56b5fe19030473d7 ? Running setup.py bdist_wheel for query-string ... done ? Stored in directory: /home/tony/.cache/pip/wheels/d6/a4/78/01b20a9dc224dcc009fab669f7f27b943b8889c5150bd68d8a ? Running setup.py bdist_wheel for public ... done ? Stored in directory: /home/tony/.cache/pip/wheels/23/7c/6e/f5b4e09d6596c8b8802b347e48f149031e2363368048f1347a Successfully built request get post query-string public Installing collected packages: public, query-string, get, post, request Successfully installed get-2019.4.13 post-2019.4.13 public-2019.4.13 query-string-2019.4.13 request-2019.4.13 ########################## So far, so good; retry http: ########################## tony at tony-lx:~/_pycharm/pygallery$ python3 -m pip install http Collecting http ? Using cached https://files.pythonhosted.org/packages/e3/91/a9260805e532e33df273b8f7dffad5c51693f8f9ba5f86bedcf42a7f22eb/http-0.02.tar.gz ??? Complete output from command python setup.py egg_info: ??? Traceback (most recent call last): ????? File "", line 1, in ????? File "/tmp/pip-install-zwguez5m/http/setup.py", line 3, in ??????? import http ????? File "/tmp/pip-install-zwguez5m/http/http/__init__.py", line 17, in ??????? from request import Request ??? ImportError: cannot import name 'Request' from 'request' (/home/tony/.local/lib/python3.7/site-packages/request/__init__.py) ??? ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-zwguez5m/http/ ########################## So now I seem to have broken it. I'm not very savvy with the python packaging system, so perhaps someone here can help me as a numpty. Thanks in advance. -- Tony van der Hoff | mailto:tony at vanderhoff.org Buckinghamshire, England | From rosuav at gmail.com Thu Nov 7 14:00:39 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Nov 2019 06:00:39 +1100 Subject: can't install http module In-Reply-To: References: Message-ID: On Fri, Nov 8, 2019 at 5:47 AM tony van der Hoff wrote: > > Hi, > I'm attempting to install (among other things) the "http" module on my > debian10 box, and am encountering the following problem: > Can you link to the documentation for the package you're trying to install? Python already ships with a module called "http". You don't need to install it. ChrisA From sio.wtf at gmail.com Thu Nov 7 14:20:28 2019 From: sio.wtf at gmail.com (Vitaly Potyarkin) Date: Thu, 7 Nov 2019 22:20:28 +0300 Subject: Using Makefiles in Python projects Message-ID: What do you think of using Makefiles for automating common chores in Python projects? Like linting, type checking and testing? I've come up with a reusable Makefile for automating virtual environment management in Python projects. I think it can be useful for simplifying the onboarding of new developers (both new to project and new to Python) and for documenting project's development practices. Here it is: - Repo: https://github.com/sio/Makefile.venv - Demo screencast: https://asciinema.org/a/279646 What do you think? Is this useful or I'm just unaware of some tool that abstracts venv chores away better? -- Vitaly From lists at vanderhoff.org Thu Nov 7 14:32:52 2019 From: lists at vanderhoff.org (Tony van der Hoff) Date: Thu, 7 Nov 2019 19:32:52 +0000 Subject: can't install http module In-Reply-To: References: Message-ID: <7bcfdfa9-dcc7-4486-8988-24871d53be8a@vanderhoff.org> On 07/11/2019 19:00, Chris Angelico wrote: > On Fri, Nov 8, 2019 at 5:47 AM tony van der Hoff wrote: >> >> Hi, >> I'm attempting to install (among other things) the "http" module on my >> debian10 box, and am encountering the following problem: >> > > Can you link to the documentation for the package you're trying to > install? Python already ships with a module called "http". You don't > need to install it. > Thanks Chris, but it doesn't seem to be installed here, but maybe I'm doing something stupid: #!/usr/bin/env python # -*- coding: UTF-8 -*- import cgi import logging from http import cookies [Thu Nov 07 17:29:24.002303 2019] [cgi:error] [pid 30937] [client 127.0.0.1:41912] AH01215: Traceback (most recent call last):: /home/tony/public_html/private/pygallery/pygallery.py [Thu Nov 07 17:29:24.002455 2019] [cgi:error] [pid 30937] [client 127.0.0.1:41912] AH01215: File "/home/tony/public_html/private/pygallery/pygallery.py", line 6, in : /home/tony/public_html/private/pygallery/pygallery.py [Thu Nov 07 17:29:24.002480 2019] [cgi:error] [pid 30937] [client 127.0.0.1:41912] AH01215: from http import cookies: /home/tony/public_html/private/pygallery/pygallery.py [Thu Nov 07 17:29:24.002502 2019] [cgi:error] [pid 30937] [client 127.0.0.1:41912] AH01215: ImportError: No module named http: /home/tony/public_html/private/pygallery/pygallery.py From rosuav at gmail.com Thu Nov 7 14:39:19 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Nov 2019 06:39:19 +1100 Subject: can't install http module In-Reply-To: <7bcfdfa9-dcc7-4486-8988-24871d53be8a@vanderhoff.org> References: <7bcfdfa9-dcc7-4486-8988-24871d53be8a@vanderhoff.org> Message-ID: On Fri, Nov 8, 2019 at 6:34 AM Tony van der Hoff wrote: > > > > On 07/11/2019 19:00, Chris Angelico wrote: > > On Fri, Nov 8, 2019 at 5:47 AM tony van der Hoff wrote: > >> > >> Hi, > >> I'm attempting to install (among other things) the "http" module on my > >> debian10 box, and am encountering the following problem: > >> > > > > Can you link to the documentation for the package you're trying to > > install? Python already ships with a module called "http". You don't > > need to install it. > > > Thanks Chris, but it doesn't seem to be installed here, but maybe I'm > doing something stupid: > > #!/usr/bin/env python > # -*- coding: UTF-8 -*- > Ah. I wouldn't call this "something stupid", because this is a bit of a gotcha, but there is a small problem here. In your original post, you attempted to install using "python3 -m pip", but here your shebang just says "python", so you're running it in Python 2.7. Replace the shebang with "python3" (and then drop the coding cookie - Python 3 assumes UTF-8 by default) and you should be able to run your code. (At least the import lines you posted. No idea about anything else.) ChrisA From cl at isbd.net Thu Nov 7 16:38:32 2019 From: cl at isbd.net (Chris Green) Date: Thu, 7 Nov 2019 21:38:32 +0000 Subject: Can't run easy_install even though setuptools is installed Message-ID: I'm a bit flummoxed. I'm trying to install a Python package from pypi.org, it says it should be installed by running "easy_install onkyo-eiscp" but I just get "easy_install: command not found" when I try that. I do have setuptools installed on my system and I can see "easy_install.py" in the package installation area. This is on an xubuntu 19.04 Linux system. So what is wrong? -- Chris Green ? From cs at cskk.id.au Thu Nov 7 17:03:38 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 8 Nov 2019 09:03:38 +1100 Subject: Can't run easy_install even though setuptools is installed In-Reply-To: References: Message-ID: <20191107220338.GA22498@cskk.homeip.net> On 07Nov2019 21:38, Chris Green wrote: >I'm a bit flummoxed. > >I'm trying to install a Python package from pypi.org, it says it >should be installed by running "easy_install onkyo-eiscp" but I just >get "easy_install: command not found" when I try that. I do have >setuptools installed on my system and I can see "easy_install.py" in >the package installation area. > >This is on an xubuntu 19.04 Linux system. > >So what is wrong? Have you tried this? pip install onkyo-eiscp Using the pip associated with your intended Python executable. "python -m pip" should also work, where "python" is the python you're intending to use it with. Thus (using pip, the command line flavour of the module, should be preinstalled with Python 2 >=2.7.9 or Python 3 >=3.4): [~]fleet*> pip install onkyo-eiscp Collecting onkyo-eiscp Downloading https://files.pythonhosted.org/packages/05/7b/a25440e34d015237d1f68b8e353f06eaa3a90c1fa77a6621e5e15e4388de/onkyo-eiscp-1.2.7.tar.gz (48kB) |????????????????????????????????| 51kB 864kB/s Collecting docopt>=0.4.1 Downloading https://files.pythonhosted.org/packages/a2/55/8f8cab2afd404cf578136ef2cc5dfb50baa1761b68c9da1fb1e4eed343c9/docopt-0.6.2.tar.gz Collecting netifaces Downloading https://files.pythonhosted.org/packages/0d/18/fd6e9c71a35b67a73160ec80a49da63d1eed2d2055054cc2995714949132/netifaces-0.10.9.tar.gz Installing collected packages: docopt, netifaces, onkyo-eiscp Running setup.py install for docopt ... done Running setup.py install for netifaces ... done Running setup.py install for onkyo-eiscp ... done Successfully installed docopt-0.6.2 netifaces-0.10.9 onkyo-eiscp-1.2.7 Cheers, Cameron Simpson From skip.montanaro at gmail.com Thu Nov 7 17:07:28 2019 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 7 Nov 2019 16:07:28 -0600 Subject: Using Makefiles in Python projects In-Reply-To: References: Message-ID: On Thu, Nov 7, 2019 at 1:24 PM Vitaly Potyarkin wrote: > > What do you think of using Makefiles for automating common chores in > Python projects? Like linting, type checking and testing? Kinda unsure why this needs to be asked (says the guy who's used Make longer than Python and nearly as long as Emacs). :-) That said, I will answer in the affirmative. Make is a great tool. Every Makefile should have "test", "lint" and "clean" targets (where they make sense) in addition to something equating to "all" (the first target in the file). In short, if you have to type a command more than once, you need a Makefile. It will save you time and serve as documentation to yourself and others about how the various pieces of your project fit together. Skip From grant.b.edwards at gmail.com Thu Nov 7 17:41:26 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 7 Nov 2019 22:41:26 -0000 (UTC) Subject: Using Makefiles in Python projects References: Message-ID: On 2019-11-07, Skip Montanaro wrote: > In short, if you have to type a command more than once, you need a > Makefile. It will save you time and serve as documentation to > yourself and others about how the various pieces of your project fit > together. Definitely. Some of the projects I work on don't actually use "make" to build the software product. But they still have a Makefiles with targets for things like formatting documentation, installing the software on a target, tagging and archiving a version, generating a tarball of GPL sources, updating source trees from upstream, etc... -- Grant Edwards grant.b.edwards Yow! BARBARA STANWYCK makes at me nervous!! gmail.com From cs at cskk.id.au Thu Nov 7 17:41:31 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 8 Nov 2019 09:41:31 +1100 Subject: Using Makefiles in Python projects In-Reply-To: References: Message-ID: <20191107224131.GA51267@cskk.homeip.net> On 07Nov2019 22:20, Vitaly Potyarkin wrote: >What do you think of using Makefiles for automating common chores in >Python projects? Like linting, type checking and testing? I do use one for some things. (Not linting, which I'll describe lower down.) I do like to use it for what make's strength is: running actions based on updated files, but there are a few "action" targets too. Here's a slightly edited and trimmed excerpt from a Makefile (well, Mykefile, but the intent and syntax are very similar) from a current project: venv_dir = $./venv venv_reqs = requirements.txt venv_pip = $(venv_dir)/bin/pip py_static_bundle = $(py_app)/static/app.js fleet_dev = [ "$$HOST" = fleet -a "$$USER" = cameron ] _help: @echo '_build: make $(py_static_bundle)' @echo '_deploy_tip: formally deploy the current tip to the dev host dev tree:' @echo '_sync_dev: rsync the current working files into the dev tip tree' _build: make $(py_static_bundle) _venv: :make $(venv_dir) $(venv_dir): $(venv_reqs) python3 -m venv $(venv_dir) $(venv_pip) install -U pip $(venv_pip) install -U -r $(venv_reqs) $(py_static_bundle): $(app_js) env-dev browserify -t [ babelify --presets [ react ] ] $? >$@ _sync_dev: $(fleet_dev) || { echo "not cameron at fleet, refusing to rsync" >&2; exit 1; } :make $(py_static_bundle) $(sync_src(target_dev_host:releases/tip)) Things to note: "Virtual targets" are actions rather than result files, and start with an underscore. The default target is _help, which recites a description of the other targets. The _venv target makes the venv directory if missing, and that runs python3 -m venv and then pip to do the required packages. There's a traditional make rule i.e. an action based on a dependent file, gosh! for the static bundle (javascript compiled into a single file). You'll see that _sync_dev has a leading sanity check: it won't run unless I'm me on my personal machine; avoids accidents. This is important because it isn't running the formal deploy script, which builds a clean versioned tree at the far end, instead it just rsyncs my local code into a "live" dev tree at the far end. Obviously that is a very personal hack. >I've come up with a reusable Makefile for automating virtual >environment >management in Python projects. I think it can be useful for simplifying >the onboarding of new developers (both new to project and new to Python) >and for documenting project's development practices. These are laudable goals. I like the expose the dev practices in particular. >Here it is: >- Repo: https://github.com/sio/Makefile.venv >- Demo screencast: https://asciinema.org/a/279646 > >What do you think? Is this useful or I'm just unaware of some tool that >abstracts venv chores away better? There may be other tools. Linting can be personal. In my current team we have varying lint habits among the devs. OTOH a common "required lint before release" could be useful, covering off the project lint standards if they exist. I lint by hand, with 2 main levels of automation: 1: I have a personal "lint" script with runs my preferred linters with my preferred options, so I can just say "lint filenames..." and have it do the right thing. It is also multilanguage: python linters, shell linters, etc. 2: I have a few VCS related shell functions. One is named "lint". With arguments is invokes the above lint script directly. _Without_ arguments it lints the "modified" (== changed and not committed) files. So I can just say "lint" and it lints my changes, not all the files. Cheers, Cameron Simpson From cs at cskk.id.au Thu Nov 7 17:44:11 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 8 Nov 2019 09:44:11 +1100 Subject: How execute at least two python files at once when imported? In-Reply-To: References: Message-ID: <20191107224411.GA47291@cskk.homeip.net> On 08Nov2019 00:52, Greg Ewing wrote: >Cameron Simpson wrote: >>Spencer's modules run unconditional stuff in addition to defining >>classes. That may cause trouble. > >It will -- because of the import lock, they won't run simultaneously >in the same process. I was unsure as to how serialised this was: just the import data structures or the whole source-of-the-module. But I guess serialising the latter is essential anyway, now I think about it. Hence my separate post suggesting the OP move the "main task" into a function, runs the imports serailly (very cheap) and then kick off threads if that's what he wants. Thanks for the clarification. Cheers, Cameron Simpson From bouncingcats at gmail.com Thu Nov 7 18:30:28 2019 From: bouncingcats at gmail.com (David) Date: Fri, 8 Nov 2019 10:30:28 +1100 Subject: Using Makefiles in Python projects In-Reply-To: <20191107224131.GA51267@cskk.homeip.net> References: <20191107224131.GA51267@cskk.homeip.net> Message-ID: On Fri, 8 Nov 2019 at 09:43, Cameron Simpson wrote: [...] > _help: > @echo '_build: make $(py_static_bundle)' > @echo '_deploy_tip: formally deploy the current tip to the dev host dev tree:' > @echo '_sync_dev: rsync the current working files into the dev tip tree' [...] > Things to note: > > "Virtual targets" are actions rather than result files, and start with > an underscore. > > The default target is _help, which recites a description of the other > targets. Hi, as you might be aware, the above recipe will not be run if a file named '_help' exists. The Gnu make documentation term for what you call "virtual targets" is "phony targets", and it discusses them here: https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html#Phony-Targets I would add the line: .PHONY: _help And similar for all the other phony targets. Doing this has other advantages as described in the linked docs. In particular, it saves 'make' wasting time searching for built-in implicit rules that might build these never-built targets. 'make -d' will reveal this. From cs at cskk.id.au Thu Nov 7 19:14:31 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 8 Nov 2019 11:14:31 +1100 Subject: Using Makefiles in Python projects In-Reply-To: References: Message-ID: <20191108001431.GA81445@cskk.homeip.net> On 08Nov2019 10:30, David wrote: >On Fri, 8 Nov 2019 at 09:43, Cameron Simpson wrote: >[...] > >> _help: >> @echo '_build: make $(py_static_bundle)' >> @echo '_deploy_tip: formally deploy the current tip to the dev host dev tree:' >> @echo '_sync_dev: rsync the current working files into the dev tip tree' > >[...] > >> Things to note: >> >> "Virtual targets" are actions rather than result files, and start with >> an underscore. >> >> The default target is _help, which recites a description of the other >> targets. > >Hi, as you might be aware, the above recipe will not be run if a file >named '_help' exists. Hence the funny name. I don't make files whole names begin with underscores. >The Gnu make documentation term for what you call "virtual targets" >is "phony targets", and it discusses them here: >https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html#Phony-Targets > >I would add the line: >.PHONY: _help >And similar for all the other phony targets. If you're using GNU make, go right ahead. But that approach treats .PHONY like a label to be applied to _its_ dependents. Probably that's exactly what it does. However, that is the inverse of the normal target:dependent relationship one puts in Makefiles. My personal approach is this: _always: : _help: _always i.e. make the "phony" targets depend on "_always", which are thus always out of date and thus will always run. You've still to avoid making a "_always", but that is a smaller thing than the whole "_*" space, if that is a concern. Cheers, Cameron Simpson From mondwan at anywherenetworks.com Thu Nov 7 22:19:19 2019 From: mondwan at anywherenetworks.com (Mond Wan) Date: Fri, 8 Nov 2019 03:19:19 +0000 Subject: Questions on working with unittest.IsolatedAsyncioTestCase Message-ID: <02a172cf-a408-34ef-cd58-8fb154f21d6e@anywherenetworks.com> Hello all, I would like to ask for helps on working with **unittest.IsolatedAsyncioTestCase**. Q1: How to handle asyncio.CancelledError inside IsolatedAsyncioTestCase. My test is hanging up if there are futures being cancelled some how. Is there a way for me to configure IsolatedAsyncioTestCase to throw any exceptions to crash the main program such that I can read the line number? I have also issue a post on stackoverflow, which include the codes I have written for explaining the question. Stackoverflow: https://stackoverflow.com/questions/58744043/how-to-handle-cancellederror-with-python-3-8-unittest-isolatedasynciotestcase Q2: addAsyncCleanup vs asyncTearDown? In the py3.8 manual, there is a method **addAsyncCleanup** for cleaning up stuff in async way. Why we need this instead of merging them altogether into **asyncTearDown** at all? Q3: Is it possible to configure a timeout mechanism for IsolatedAsyncioTestCase? During my development, my tests always pending in somewhere. I cannot located them until I add print statements line by line. Is it possible to configure the IsolatedAsyncioTestCase to crash the test, with line number, after specific period if such future is not resolved? Thanks for your time -- Mond WAN Senior Engineer, Engineering Department Anywhere Networks Mobile/WhatsApp: +852 3899 1928 ?mondwa?n@?anywherenetworks.co?m? ?www.?AnywhereNetworks.com P2 Wireless Technologies is now Anywhere Networks! [Anywhere Networks] Disclaimer: This email and its attachment(s) are solely for the use of the intended addressee and may contain confidential information. If you are not the intended recipient, you must not use, distribute or copy this email. If you have received this email in error, please notify the sender immediately and delete this email. No employee or agent is authorized to bind the company or conclude a binding agreement on behalf of the company without express written approval by an authorized senior officer of the company. In no event will this email or its content be construed as written approval. From cl at isbd.net Fri Nov 8 04:14:08 2019 From: cl at isbd.net (Chris Green) Date: Fri, 8 Nov 2019 09:14:08 +0000 Subject: Can't run easy_install even though setuptools is installed References: <20191107220338.GA22498@cskk.homeip.net> Message-ID: <08of9g-9i4.ln1@esprimo.zbmc.eu> Cameron Simpson wrote: > On 07Nov2019 21:38, Chris Green wrote: > >I'm a bit flummoxed. > > > >I'm trying to install a Python package from pypi.org, it says it > >should be installed by running "easy_install onkyo-eiscp" but I just > >get "easy_install: command not found" when I try that. I do have > >setuptools installed on my system and I can see "easy_install.py" in > >the package installation area. > > > >This is on an xubuntu 19.04 Linux system. > > > >So what is wrong? > > Have you tried this? > > pip install onkyo-eiscp > I have now and it worked perfectly. So why do the install instructions for onkyo-eiscp say do "easy_install onkyo-eiscp"? It definitely means from the command line. I mean it's not even as if "easy_install" is fewer letters to type than "pip install"! :-) Anyway, thanks for the help, -- Chris Green ? From lists at vanderhoff.org Fri Nov 8 04:43:05 2019 From: lists at vanderhoff.org (Tony van der Hoff) Date: Fri, 8 Nov 2019 09:43:05 +0000 Subject: can't install http module In-Reply-To: References: <7bcfdfa9-dcc7-4486-8988-24871d53be8a@vanderhoff.org> Message-ID: On 07/11/2019 19:39, Chris Angelico wrote: > On Fri, Nov 8, 2019 at 6:34 AM Tony van der Hoff wrote: >> >> >> >> On 07/11/2019 19:00, Chris Angelico wrote: >>> On Fri, Nov 8, 2019 at 5:47 AM tony van der Hoff wrote: >>>> >>>> Hi, >>>> I'm attempting to install (among other things) the "http" module on my >>>> debian10 box, and am encountering the following problem: >>>> >>> >>> Can you link to the documentation for the package you're trying to >>> install? Python already ships with a module called "http". You don't >>> need to install it. >>> >> Thanks Chris, but it doesn't seem to be installed here, but maybe I'm >> doing something stupid: >> >> #!/usr/bin/env python >> # -*- coding: UTF-8 -*- >> > > Ah. I wouldn't call this "something stupid", because this is a bit of > a gotcha, but there is a small problem here. In your original post, > you attempted to install using "python3 -m pip", but here your shebang > just says "python", so you're running it in Python 2.7. Replace the > shebang with "python3" (and then drop the coding cookie - Python 3 > assumes UTF-8 by default) and you should be able to run your code. (At > least the import lines you posted. No idea about anything else.) > > ChrisA > Excellent catch, Chris. Thank you so much. I changed the version while tracking down another problem, and forgot to restore it. It should have been obvious, but somehow it escaped me. Thanks again, Tony. From greg.ewing at canterbury.ac.nz Fri Nov 8 06:40:57 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 09 Nov 2019 00:40:57 +1300 Subject: How execute at least two python files at once when imported? In-Reply-To: References: <20191107224411.GA47291@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > I was unsure as to how serialised this was: just the import data > structures or the whole source-of-the-module. It's the whole source. I found that out the hard way once -- I had a thread that imported a module whose main code ran an event processing loop. It stopped any other threads from running, since the import statement never finished. -- Greg From antoon.pardon at vub.be Fri Nov 8 06:54:53 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 8 Nov 2019 12:54:53 +0100 Subject: Syntax Suggestion: Pass Function Definition as Argument In-Reply-To: References: <6da7c5f1-003e-4b19-b9e8-715ecba8624e@googlegroups.com> Message-ID: On 7/11/19 18:10, Stephen Waldron wrote: > What I'm aiming for is the ability to, within a function call, pass a suite that would be there automatically defined by the compiler/interpreter. Another comment did mention lambda functions, which does to some degree provide that capability, but is restricted to well, lambda functions (only expressions, not statements). I don't think those restrictions are that limiting. Certainly not since python3.8 and python acquired an assigment operator. And you should also note that a list is an expression. So we could do something like the following. class Book: ? def __init__(self, name, author): self.name = name self.author = author def doToBooks (bookList, first, then, book = None): for book in bookList: first(book = book) then(book = book) myBooks = [ Book("The Way of the World", "Lucy Cole"), Book("To Live or To Love", "Georgio Dunham"), Book("Twelve Days of Success", "Anita Duvette") ] import sys write = sys.stdout.write doToBooks (myBooks, first = lambda book: [write(book.name), write("\n")], then = lambda book: [write(" - "), write(book.author), write("\n")] ) The above code will print the following: The Way of the World - Lucy Cole To Live or To Love - Georgio Dunham Twelve Days of Success - Anita Duvette -- Antoon. From rosuav at gmail.com Fri Nov 8 07:00:36 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Nov 2019 23:00:36 +1100 Subject: Syntax Suggestion: Pass Function Definition as Argument In-Reply-To: References: <6da7c5f1-003e-4b19-b9e8-715ecba8624e@googlegroups.com> Message-ID: On Fri, Nov 8, 2019 at 10:57 PM Antoon Pardon wrote: > > On 7/11/19 18:10, Stephen Waldron wrote: > > What I'm aiming for is the ability to, within a function call, pass a suite that would be there automatically defined by the compiler/interpreter. Another comment did mention lambda functions, which does to some degree provide that capability, but is restricted to well, lambda functions (only expressions, not statements). > I don't think those restrictions are that limiting. Certainly not since > python3.8 and python acquired an assigment operator. And you should also > note that a list is an expression. So we could do something like the > following. > If you're implying that you can rewrite any function using lambda and a list of expressions, then no, the ":=" operator won't help you: >>> (lambda: x := 1) File "", line 1 SyntaxError: cannot use named assignment with lambda ChrisA From antoon.pardon at vub.be Fri Nov 8 07:20:51 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 8 Nov 2019 13:20:51 +0100 Subject: Syntax Suggestion: Pass Function Definition as Argument In-Reply-To: References: <6da7c5f1-003e-4b19-b9e8-715ecba8624e@googlegroups.com> Message-ID: <0fd33d5b-2f86-ac68-a173-90c1cc913505@vub.be> On 8/11/19 13:00, Chris Angelico wrote: > On Fri, Nov 8, 2019 at 10:57 PM Antoon Pardon wrote: >> On 7/11/19 18:10, Stephen Waldron wrote: >>> What I'm aiming for is the ability to, within a function call, pass a suite that would be there automatically defined by the compiler/interpreter. Another comment did mention lambda functions, which does to some degree provide that capability, but is restricted to well, lambda functions (only expressions, not statements). >> I don't think those restrictions are that limiting. Certainly not since >> python3.8 and python acquired an assigment operator. And you should also >> note that a list is an expression. So we could do something like the >> following. >> > If you're implying that you can rewrite any function using lambda and > a list of expressions, then no, the ":=" operator won't help you: > >>>> (lambda: x := 1) > File "", line 1 > SyntaxError: cannot use named assignment with lambda Well I haven't had the time to install python3.8 myself but this is what I read in the PEP ??? * Unparenthesized assignment expressions are prohibited in lambda functions. Example: ??????? (lambda: x := 1) # INVALID ??????? lambda: (x := 1) # Valid, but unlikely to be useful ??????? (x := lambda: 1) # Valid ??????? lambda line: (m := re.match(pattern, line)) and m.group(1) # Valid This allows lambda to always bind less tightly than :=; having a name binding at the top level inside a lambda function is unlikely to be of value, as there is no way to make use of it. In cases where the name will be used more than once, the expression is likely to need parenthesizing anyway, so this prohibition will rarely affect code. So it seems you just forgot to use the parenthesis. -- Antoon Pardon From address at not.available Fri Nov 8 11:02:27 2019 From: address at not.available (R.Wieser) Date: Fri, 8 Nov 2019 17:02:27 +0100 Subject: psutil.boot_time() ... doesn't ? References: <2it6se1runrc1ojqfuv4bf6hgq01vtb3nd@4ax.com> Message-ID: Dennis, > Well... If it is the last file written during shutdown, it would be > the "last file system modification time" Yep ... up until the next hours cronjob overwriting it ... Currently I've got a (very) small init.d shellscript which copies the contents of that file into another one - which only gets altered on next boot (could not do it in the fake-hwclock script, as that gets first called when the filesystem is still in read-only mode). > The only time it would not be "last modification time" would be if > the system had the power pulled, and was not shut down cleanly. Only the first hour (not sure if that is clock or uptime ...), than it would be overwritten. I've also thought of letting the fake-hwclock write my file on shutdown too. But a bad shutdown would cause problems there. > Of course, in that situation, one has the potential of having a corrupted > file system -- and anything goes... Yup. And in such a case I do /not/ want to have to remember my programs little quirk ... :-( Regards, Rudy Wieser From address at not.available Fri Nov 8 11:13:03 2019 From: address at not.available (R.Wieser) Date: Fri, 8 Nov 2019 17:13:03 +0100 Subject: psutil.boot_time() ... doesn't ? References: Message-ID: Dennis, > However -- manually changing date/time is not going to illustrate this. > ANY change made to date/time will reflect a change in UTC time. It turns out that the get_uptime() does /not/ calculate the boottime from the current clock minus the uptime. Its a seconds-since-epoch (absolute!) value written into the /proc/stat file , *which gets fricking changed when you change the date/time*. In other words, all our "must be local time related" musings are not worth the paper they where written on. :-) Regards, Rudy Wieser From marko at pacujo.net Fri Nov 8 03:49:58 2019 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 08 Nov 2019 10:49:58 +0200 Subject: Using Makefiles in Python projects References: Message-ID: <87mud6wy4p.fsf@elektro.pacujo.net> Skip Montanaro : > On Thu, Nov 7, 2019 at 1:24 PM Vitaly Potyarkin wrote: >> >> What do you think of using Makefiles for automating common chores in >> Python projects? Like linting, type checking and testing? > > Kinda unsure why this needs to be asked (says the guy who's used Make > longer than Python and nearly as long as Emacs). :-) That said, I will > answer in the affirmative. Make is a great tool. I can't agree that make is a great tool. It's a tool a slight step better than unconditional build scripts, but it's really only suitable for projects involving a single directory (although baffling heroics have been achieved using GNU Make in particular). Of the more modern build systems, I have found SCons to be the best. It has a killer feature not found elsewhere: dependency checks are based on content, not timestamps. That way going back in time (which is very common in everyday development) won't confuse build dependencies. We have considered other advanced competitors to SCons, but the content-based type-checking feature is something I wouldn't give up. (If SCons developers are reading, thanks for your insight and efforts. SCons has gotten so many things right with very few blind spots. I've been a happy user since 2003.) Marko From rosuav at gmail.com Fri Nov 8 14:21:42 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Nov 2019 06:21:42 +1100 Subject: Using Makefiles in Python projects In-Reply-To: <87mud6wy4p.fsf@elektro.pacujo.net> References: <87mud6wy4p.fsf@elektro.pacujo.net> Message-ID: On Sat, Nov 9, 2019 at 3:31 AM Marko Rauhamaa wrote: > > Skip Montanaro : > > > On Thu, Nov 7, 2019 at 1:24 PM Vitaly Potyarkin wrote: > >> > >> What do you think of using Makefiles for automating common chores in > >> Python projects? Like linting, type checking and testing? > > > > Kinda unsure why this needs to be asked (says the guy who's used Make > > longer than Python and nearly as long as Emacs). :-) That said, I will > > answer in the affirmative. Make is a great tool. > > I can't agree that make is a great tool. It's a tool a slight step > better than unconditional build scripts, but it's really only suitable > for projects involving a single directory (although baffling heroics > have been achieved using GNU Make in particular). > Really? I've used make with multi-directory projects many times. Also, like Grant, I use a Makefile to document some things. For simple projects, I use a Makefile to precompile, compile, and deploy, all governed by a master "all" phony target. When I'm working in SourcePawn, I have a Python script that reads my source file and generates an include file from it (because SP doesn't have metaprogramming facilities), and I might have a script that reads an entirely separate file that isn't even under my control, and parse that to create an include file. Then there's the actual compilation command, and finally deployment (which is unconditional). That's a lot of commands, some of them very easy to forget, involving files inside and outside the project directory... and all done with a single "make" command. SCons is massive overkill for the project I'm doing. Why introduce a dependency like that? Honestly, SCons can be a pain even with a gigantic project, and there's no way that I want to use it for simple automation. ChrisA From rosuav at gmail.com Fri Nov 8 14:33:09 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Nov 2019 06:33:09 +1100 Subject: Syntax Suggestion: Pass Function Definition as Argument In-Reply-To: <0fd33d5b-2f86-ac68-a173-90c1cc913505@vub.be> References: <6da7c5f1-003e-4b19-b9e8-715ecba8624e@googlegroups.com> <0fd33d5b-2f86-ac68-a173-90c1cc913505@vub.be> Message-ID: On Fri, Nov 8, 2019 at 11:22 PM Antoon Pardon wrote: > > On 8/11/19 13:00, Chris Angelico wrote: > > On Fri, Nov 8, 2019 at 10:57 PM Antoon Pardon wrote: > >> On 7/11/19 18:10, Stephen Waldron wrote: > >>> What I'm aiming for is the ability to, within a function call, pass a suite that would be there automatically defined by the compiler/interpreter. Another comment did mention lambda functions, which does to some degree provide that capability, but is restricted to well, lambda functions (only expressions, not statements). > >> I don't think those restrictions are that limiting. Certainly not since > >> python3.8 and python acquired an assigment operator. And you should also > >> note that a list is an expression. So we could do something like the > >> following. > >> > > If you're implying that you can rewrite any function using lambda and > > a list of expressions, then no, the ":=" operator won't help you: > > > >>>> (lambda: x := 1) > > File "", line 1 > > SyntaxError: cannot use named assignment with lambda > > Well I haven't had the time to install python3.8 myself but this is what > I read in the PEP > > * Unparenthesized assignment expressions are prohibited in lambda > functions. Example: > (lambda: x := 1) # INVALID > lambda: (x := 1) # Valid, but unlikely to be useful > (x := lambda: 1) # Valid > lambda line: (m := re.match(pattern, line)) and m.group(1) # Valid > > This allows lambda to always bind less tightly than :=; having a > name binding at the top level inside a lambda function is unlikely > to be of value, as there is no way to make use of it. In cases where > the name will be used more than once, the expression is likely to > need parenthesizing anyway, so this prohibition will rarely affect code. > > So it seems you just forgot to use the parenthesis. > True, I could make it syntactically valid with parens. But as the paragraph shows, it's still not possible to use it outside that lambda function (there's no way to declare it nonlocal), and you can't assign to anything other than a simple name (no "x[1] := 1"), so you still can't use this as a true replacement for 'def' functions. I kinda shorthanded with the example but it's still a very tight limitation. Going back to looking at the way JavaScript does things, though: One of the main places that large functions are commonly used as arguments is asynchronous code. There are better ways to do that (async/await in both languages, threads and processes in Python), so that's not necessary. For event driven code, I would much prefer to use 'def' functions with decorators, rather than function arguments - compare a bit of Python/Flask code with a similar bit of JS/Express: @app.route("/foo/") def foo(id): return ... app.get("/foo/:id", (req, res) => { res.send(...) }); Pretty similar, but one very important distinction is that the Flask style extends easily to multi-routing, simply by decorating the function more than once. For event-driven code (this is for an HTTP server, and the same applies to a GUI), this is a way cleaner way to do things. I'd rather look into ways to make decorators do what you need (even if that involves an enhancement to decorator syntax) than try to create multi-line lambdas. ChrisA From mail.stephen.waldron at gmail.com Fri Nov 8 16:38:26 2019 From: mail.stephen.waldron at gmail.com (Stephen Waldron) Date: Fri, 8 Nov 2019 13:38:26 -0800 (PST) Subject: Syntax Suggestion: Pass Function Definition as Argument In-Reply-To: <6da7c5f1-003e-4b19-b9e8-715ecba8624e@googlegroups.com> References: <6da7c5f1-003e-4b19-b9e8-715ecba8624e@googlegroups.com> Message-ID: <7dd0abd0-c49b-4e36-b1e6-86493de9ba8b@googlegroups.com> Ok firstly, this idea was inspired specifically by a project I'm working on for school concerning linked lists, in which I was trying to create a method that performed a function on elements iteratively without having to navigate the list from the head each time (of course taking the function as a parameter). This project is intended to be a personal module for future use. In the process of this discourse here, however, I think I've found an alternative for this specific issue, (so thanks guys) but generally speaking, there were other times I've wanted to use functions as parameters, typically while making personal modules, like a purely Js button module I had made a few years back, and it was apparent that the only way to do so in Python was to define first, then pass, which I simply didn't like the idea of in the context of a module, short of defining each function before the module instances with `def temp(*args):` or some other generic name I won't use past the module function instance. Now yes, as many of you have pointed out, there may exist other workarounds for various instances in which one may think to use a function as an argument. Multi-line lambdas are a very intriguing method for the broad topic, (thanks, they will be useful in the future ^ ^b ++), but as @Chris Angelico mentioned, they can't really be used as replacements for def, and from what I've experienced trying them out, it wasn't always clear what could be done for some of the lines one would want to write. Finally, some clarification for @David Raymond > Isn't this basically just defining a function... but without an argument list? How would that know what "str" is? In my original post, I said: > If they are not, they won't be assigned to, which would cause an error unless a default value is given. These parameters could be available for passing in the annexed function if mentioned when the parameter is called. Nyeh, it's written poorly, but I guess I should clarify by saying that, per the proposal, arguments are inherent from the parent function to the annexed function if and only if that argument is assigned to when the annexed function is called as the parameter it fills in the parent function's definition. Of course it can also use all other variables within it's scope. In the example you're referring to, this is done on line 3: foo (str = str1) making foo inherit "str" from myFoo, which was given the default value " ". (I would suppose another viable alternative would be using nonlocal as I'll example below) Also you ask if it's just defining a function. In all of my examples, I use only one instance of the parent function (which is actually pretty useless), but the power in doing this actually lies in calling it in various locations and passing different arguments and annexing different functions (kinda what functions are for, haha). I might be hard-pressed to think of an example short of writing out a more complex program, but here is.. something?.. I guess simply assume runOpt(prompt, foo) is a previously defined function, and variables used in the annex are within the annexed function's scope, but prompt is not inherited: runOpt ("Play Game"): getUserData() chr[0].id = 0 time = 0 score = 0 scene = 1 runOpt ("How To Play"): nonlocal prompt loadBg() display(prompt) scene = 2 runOpt ("Settings"): checkDefaults() chr[0].id = 5 scene = 3 N.B. on everything (also some TLs you could skip): This is just a suggestion, I think it would be nice for previously stated reasons (ease, aesthetics, function, yadda-yadda). I would still love to hear ways I could currently achieve things similar, as that is one of the things I look for from suggestions since "I don't know how to do x right now and have not previously found a solution" is implied, but one trigger I do have is a reply of "that is not the way it is" to a "this is how I think it should be" statement; doesn't give me any hint as to the merits or demerits of my thought, as flawed as it may indeed be, in logistics, implementation, practice etc. Can't really say anyone has done that quite yet, but just making it known, so "What you can try" and "The suggestion is impractical because..." responses are welcome. Also, one of the reasons for my suggestions is ease. The structure used is fairly common in Python, and thus fairly intuitive (I hypothesize at least). I know from experience that once you learn something, it becomes fairly easy and intuitive for you, but not necessarily for others and you sometimes forget the struggle you endured to get there. Of course I'm not saying others shouldn't have to learn to, but if there's a way to make it easier for others, I'd push it. Now I am still going to learn all about async, await, yield (which I think deserves more cred from what I can see so far), and lambda (cuz I wanna) but if I think learning and utilizing these would be a hindrance however minor for future developers, I'm gonna try to push something easier to go alongside them. From shangitsystems at gmail.com Fri Nov 8 17:52:50 2019 From: shangitsystems at gmail.com (shangitsystems at gmail.com) Date: Fri, 8 Nov 2019 14:52:50 -0800 (PST) Subject: Help with JWT and Apple Connect API Message-ID: Hello All would welcome any advice on the following thank you I am trying to use Apple's Connect API to download reports (sales etc. the following code runs with out any error but I cant find an example of how to use the JWT [python] from datetime import datetime, timedelta import jwt KEY_ID = "mykey_id" ISSUER_ID = "issuse_id_string" PRIVATE_KEY = Auth key file on my pc.p8" TIMESTAMP = int( (datetime.now() - timedelta(minutes = 45)).timestamp() * 1000) claim = {"iss" : ISSUER_ID, "exp" : TIMESTAMP, "aud" : "appstoreconnect-v1"} header = { "alg": "ES256", "kid": KEY_ID, "typ": "JWT" } # Create the JWT jwttoken = jwt.encode(claim, PRIVATE_KEY, algorithm='ES256', headers=header) [\python] Would anyone know where i can find a simple example on using "jwttoken"?? I have also tried using appstoreconnect as follows however I get a token error [python] from appstoreconnect import Api KEY_ID = "mykey_id" ISSUER_ID = "issuse_id_string" PRIVATE_KEY = Auth key file on my pc.p8" api = Api(KEY_ID, PRIVATE_KEY, ISSUER_ID) print (api) apps = api.list_apps() for app in apps: print(app) [\python] Error follows Traceback (most recent call last): File "C:\src\Sandbox\python\test2.py", line 13, in for app in apps: File "C:\Users\DevUser\AppData\Local\Programs\Python\Python36\lib\site-packages\appstoreconnect\api.py", line 79, in __next__ self.fetch_page() File "C:\Users\DevUser\AppData\Local\Programs\Python\Python36\lib\site-packages\appstoreconnect\api.py", line 96, in fetch_page self.payload = self.api._api_call(self.url) File "C:\Users\DevUser\AppData\Local\Programs\Python\Python36\lib\site-packages\appstoreconnect\api.py", line 134, in _api_call raise APIError(payload.get('errors', [])[0].get('detail', 'Unknown error')) appstoreconnect.api.APIError: Provide a properly configured and signed bearer token, and make sure that it has not expired. Learn more about Generating Tokens for API Requests https://developer.apple.com/go/?id=api-g...ing-tokens From cs at cskk.id.au Fri Nov 8 21:15:46 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 9 Nov 2019 13:15:46 +1100 Subject: Can't run easy_install even though setuptools is installed In-Reply-To: <08of9g-9i4.ln1@esprimo.zbmc.eu> References: <08of9g-9i4.ln1@esprimo.zbmc.eu> Message-ID: <20191109021546.GA61304@cskk.homeip.net> On 08Nov2019 09:14, Chris Green wrote: >Cameron Simpson wrote: >> Have you tried this? >> >> pip install onkyo-eiscp >> >I have now and it worked perfectly. So why do the install >instructions for onkyo-eiscp say do "easy_install onkyo-eiscp"? It >definitely means from the command line. I mean it's not even as if >"easy_install" is fewer letters to type than "pip install"! :-) Probably the instructions are old. Cheers, Cameron Simpson From cs at cskk.id.au Fri Nov 8 22:19:16 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 9 Nov 2019 14:19:16 +1100 Subject: Can't run easy_install even though setuptools is installed In-Reply-To: <20191109021546.GA61304@cskk.homeip.net> References: <20191109021546.GA61304@cskk.homeip.net> Message-ID: <20191109031916.GA20761@cskk.homeip.net> On 09Nov2019 13:15, Cameron Simpson wrote: >On 08Nov2019 09:14, Chris Green wrote: >>Cameron Simpson wrote: >>>Have you tried this? >>> pip install onkyo-eiscp >>> >>I have now and it worked perfectly. So why do the install >>instructions for onkyo-eiscp say do "easy_install onkyo-eiscp"? It >>definitely means from the command line. I mean it's not even as if >>"easy_install" is fewer letters to type than "pip install"! :-) > >Probably the instructions are old. Indeed, go here: https://github.com/miracle2k/onkyo-eiscp/blame/master/README.rst you can see that that instruction is 7 years old. The commit message says "Added PyPI installation instructions.", and that means "pip" these days. Cheers, Cameron Simpson From originallmoney at gmail.com Sat Nov 9 00:01:56 2019 From: originallmoney at gmail.com (originallmoney at gmail.com) Date: Fri, 8 Nov 2019 21:01:56 -0800 (PST) Subject: Trouble trying to get started with pygame In-Reply-To: References: <412bf414-19a5-4937-90fd-3363cb78614b@googlegroups.com> <9313ee4c-7250-4c8f-804b-f468a0dd3c5a@googlegroups.com> <8fe30991-0ad2-632f-bb37-fc9881b8835f@mrabarnett.plus.com> <6798ae9c-8823-4dbb-ae16-06257e49d06a@googlegroups.com> <3717e429-b1c3-8f6f-8dd3-50f89d2a21cc@mrabarnett.plus.com> <019fedd8-8c8e-453e-84aa-39dfa77d28c5@googlegroups.com> <207693a2-67ce-4fb1-4375-8933dd50a89b@mrabarnett.plus.com> Message-ID: On Thursday, November 7, 2019 at 1:21:37 AM UTC-5, illume wrote: > Hi, > > either use python 3.7, or use the pre-release of pygame 2. > py -m pip install pygame==2.0.0.dev6 > > We're not going to do a python 3.8 release for pygame 1.9.x > > > cheers, Well, it seems like that did the trick! I got version 3.7.5, and it's telling me pygame is installed! Thank you both! This was really irritating me, I appreciate your help in figuring this out. From tjol at tjol.eu Sat Nov 9 10:08:31 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Sat, 9 Nov 2019 16:08:31 +0100 Subject: Using Makefiles in Python projects In-Reply-To: References: Message-ID: <407b8a4a-5921-c728-55a2-ba7ae07118ab@tjol.eu> On 07/11/2019 20:20, Vitaly Potyarkin wrote: > What do you think of using Makefiles for automating common chores in > Python projects? Like linting, type checking and testing? > > I've come up with a reusable Makefile for automating virtual environment > management in Python projects. I think it can be useful for simplifying > the onboarding of new developers (both new to project and new to Python) > and for documenting project's development practices. > > Here it is: > - Repo: https://github.com/sio/Makefile.venv > - Demo screencast: https://asciinema.org/a/279646 > > What do you think? Is this useful or I'm just unaware of some tool that > abstracts venv chores away better? > As others have said, make is a useful tool and many people use it for different purposes in their Python projects. Nothing wrong with that. HOWEVER, at risk of stating the obvious, using Makefiles written for/on *nix systems on Windows is a bit of a hassle. If, for some reason, your software is *nix-only anyway, that's fine. If not, using make means sacrificing some portability. If your software runs on Windows, of you think it might run on Windows in the future, maybe consider writing simple Python scripts for platform-independent tasks rather than makefiles and shell scripts. -- Thomas From rosuav at gmail.com Sat Nov 9 15:30:01 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Nov 2019 07:30:01 +1100 Subject: Using Makefiles in Python projects In-Reply-To: <407b8a4a-5921-c728-55a2-ba7ae07118ab@tjol.eu> References: <407b8a4a-5921-c728-55a2-ba7ae07118ab@tjol.eu> Message-ID: On Sun, Nov 10, 2019 at 2:10 AM Thomas Jollans wrote: > > On 07/11/2019 20:20, Vitaly Potyarkin wrote: > > What do you think of using Makefiles for automating common chores in > > Python projects? Like linting, type checking and testing? > > > > I've come up with a reusable Makefile for automating virtual environment > > management in Python projects. I think it can be useful for simplifying > > the onboarding of new developers (both new to project and new to Python) > > and for documenting project's development practices. > > > > Here it is: > > - Repo: https://github.com/sio/Makefile.venv > > - Demo screencast: https://asciinema.org/a/279646 > > > > What do you think? Is this useful or I'm just unaware of some tool that > > abstracts venv chores away better? > > > As others have said, make is a useful tool and many people use it for > different purposes in their Python projects. Nothing wrong with that. > > HOWEVER, at risk of stating the obvious, using Makefiles written for/on > *nix systems on Windows is a bit of a hassle. If, for some reason, your > software is *nix-only anyway, that's fine. If not, using make means > sacrificing some portability. > > If your software runs on Windows, of you think it might run on Windows > in the future, maybe consider writing simple Python scripts for > platform-independent tasks rather than makefiles and shell scripts. > Are you assuming that every Windows system has Python, but that you can't get make or bash? Because neither half of that is true. I've happily used makefiles on Windows, and these days, bash is as easy to get hold of as Python is. ChrisA From tjol at tjol.eu Sat Nov 9 18:50:20 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 10 Nov 2019 00:50:20 +0100 Subject: Using Makefiles in Python projects In-Reply-To: References: <407b8a4a-5921-c728-55a2-ba7ae07118ab@tjol.eu> Message-ID: <3c62dc25-255c-47d9-130c-3d0f735e3f9c@tjol.eu> On 09/11/2019 21:30, Chris Angelico wrote: > On Sun, Nov 10, 2019 at 2:10 AM Thomas Jollans wrote: >> On 07/11/2019 20:20, Vitaly Potyarkin wrote: >>> What do you think of using Makefiles for automating common chores in >>> Python projects? Like linting, type checking and testing? >>> >>> I've come up with a reusable Makefile for automating virtual environment >>> management in Python projects. I think it can be useful for simplifying >>> the onboarding of new developers (both new to project and new to Python) >>> and for documenting project's development practices. >>> >>> Here it is: >>> - Repo: https://github.com/sio/Makefile.venv >>> - Demo screencast: https://asciinema.org/a/279646 >>> >>> What do you think? Is this useful or I'm just unaware of some tool that >>> abstracts venv chores away better? >>> >> As others have said, make is a useful tool and many people use it for >> different purposes in their Python projects. Nothing wrong with that. >> >> HOWEVER, at risk of stating the obvious, using Makefiles written for/on >> *nix systems on Windows is a bit of a hassle. If, for some reason, your >> software is *nix-only anyway, that's fine. If not, using make means >> sacrificing some portability. >> >> If your software runs on Windows, of you think it might run on Windows >> in the future, maybe consider writing simple Python scripts for >> platform-independent tasks rather than makefiles and shell scripts. >> > Are you assuming that every Windows system has Python, but that you > can't get make or bash? Because neither half of that is true. I've > happily used makefiles on Windows, and these days, bash is as easy to > get hold of as Python is. > > ChrisA That's why I say "a bit of a hassle". You can get a MSYS set up (whether from Git for Windows or otherwise). You can get it to play nice with the right Python installation and the Python scripts you presumably want to call from the Makefile. But all of that is a bit of a hassle. From skip.montanaro at gmail.com Sat Nov 9 19:09:12 2019 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 9 Nov 2019 18:09:12 -0600 Subject: Using Makefiles in Python projects In-Reply-To: <3c62dc25-255c-47d9-130c-3d0f735e3f9c@tjol.eu> References: <407b8a4a-5921-c728-55a2-ba7ae07118ab@tjol.eu> <3c62dc25-255c-47d9-130c-3d0f735e3f9c@tjol.eu> Message-ID: (Sorry, not 100% sure of the credit for this quote, Vitaly, perhaps?) > >> If your software runs on Windows, of you think it might run on Windows > >> in the future, maybe consider writing simple Python scripts for > >> platform-independent tasks rather than makefiles and shell scripts. Maybe try SCons or CMake for cross-platform functionality? Chris: > > Are you assuming that every Windows system has Python, but that you > > can't get make or bash? Because neither half of that is true. I've > > happily used makefiles on Windows, and these days, bash is as easy to > > get hold of as Python is. Thomas: > That's why I say "a bit of a hassle". You can get a MSYS set up (whether > from Git for Windows or otherwise). You can get it to play nice with the > right Python installation and the Python scripts you presumably want to > call from the Makefile. But all of that is a bit of a hassle. I thought recent versions of Win10 had a full Ubuntu subsystem. Before that, doesn't something like Cygwin still exist/work? Disclaimer: I am not a Windows person, and managed to avoid it for my entire career. Skip From rosuav at gmail.com Sat Nov 9 19:21:54 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Nov 2019 11:21:54 +1100 Subject: Using Makefiles in Python projects In-Reply-To: References: <407b8a4a-5921-c728-55a2-ba7ae07118ab@tjol.eu> <3c62dc25-255c-47d9-130c-3d0f735e3f9c@tjol.eu> Message-ID: On Sun, Nov 10, 2019 at 11:09 AM Skip Montanaro wrote: > Thomas: > > > That's why I say "a bit of a hassle". You can get a MSYS set up (whether > > from Git for Windows or otherwise). You can get it to play nice with the > > right Python installation and the Python scripts you presumably want to > > call from the Makefile. But all of that is a bit of a hassle. > > I thought recent versions of Win10 had a full Ubuntu subsystem. Before > that, doesn't something like Cygwin still exist/work? You have to explicitly install it. But if you're doing any sort of development on Windows, you almost certainly want either WSL or Git for Windows, either of which will give you bash. There's almost no cross-platform option that doesn't need to be installed everywhere. But you can get close by using something that "comes for the ride" when you get something else that you'll need, and neither SCons nor CMake fits that description (neither on Windows nor on any of my Linux systems), but bash most certainly does. So I'd say that a bash script is, in a sense, more portable than a SCons system. ChrisA From pankaj.jangid at gmail.com Sat Nov 9 22:53:12 2019 From: pankaj.jangid at gmail.com (Pankaj Jangid) Date: Sun, 10 Nov 2019 09:23:12 +0530 Subject: Using Makefiles in Python projects References: <407b8a4a-5921-c728-55a2-ba7ae07118ab@tjol.eu> Message-ID: Chris Angelico writes: > On Sun, Nov 10, 2019 at 2:10 AM Thomas Jollans wrote: >> On 07/11/2019 20:20, Vitaly Potyarkin wrote: >> > What do you think of using Makefiles for automating common chores in >> > Python projects? Like linting, type checking and testing? >> > >> > I've come up with a reusable Makefile for automating virtual environment >> > management in Python projects. I think it can be useful for simplifying >> > the onboarding of new developers (both new to project and new to Python) >> > and for documenting project's development practices. >> > >> > Here it is: >> > - Repo: https://github.com/sio/Makefile.venv >> > - Demo screencast: https://asciinema.org/a/279646 >> > >> > What do you think? Is this useful or I'm just unaware of some tool that >> > abstracts venv chores away better? >> > >> As others have said, make is a useful tool and many people use it for >> different purposes in their Python projects. Nothing wrong with that. >> >> HOWEVER, at risk of stating the obvious, using Makefiles written for/on >> *nix systems on Windows is a bit of a hassle. If, for some reason, your >> software is *nix-only anyway, that's fine. If not, using make means >> sacrificing some portability. >> >> If your software runs on Windows, of you think it might run on Windows >> in the future, maybe consider writing simple Python scripts for >> platform-independent tasks rather than makefiles and shell scripts. >> > > Are you assuming that every Windows system has Python, but that you > can't get make or bash? Because neither half of that is true. I've > happily used makefiles on Windows, and these days, bash is as easy to > get hold of as Python is. Actually, the proposal to use Makefile is great. I have always been thinking about it and using it in my own projects. At my previous workplace there was compulsion to use Windows, so I had to setup Cygwin. And I had same level of difficulty setting up Python on Windows. So the difficulty level is same for Python and Make setup. Another advantage of using Make is that it is easy to configure portable mixed native programs with Python. To work on modern projects similar to NumPy, TensorFlow, PyCharm where half of the code is native and half Python, it is much easier to manage native part with Make. Autoconf, automake etc. utilities tells you in advance what native libraries are missing from the system - Windows or Linux. We should not forget that Data Science, Machine Learning etc. fields have helped in proliferation of Python lately. And the above mentioned libraries have great role. We should make it even more easier to manage mixed native projects portably. GNU Make is the way to go. Thanks for raising this. Regards, -- Pankaj Jangid From nixuser at nixu.ser Sun Nov 10 06:36:17 2019 From: nixuser at nixu.ser (nixuser) Date: Sun, 10 Nov 2019 11:36:17 +0000 (UTC) Subject: Looking for python pentest scripts Message-ID: Hello, can someone tell about good resource for python related pentesting scripts? any extensive list? Thanks From barry at barrys-emacs.org Sun Nov 10 08:37:06 2019 From: barry at barrys-emacs.org (Barry Scott) Date: Sun, 10 Nov 2019 13:37:06 +0000 Subject: Using Makefiles in Python projects In-Reply-To: References: <407b8a4a-5921-c728-55a2-ba7ae07118ab@tjol.eu> <3c62dc25-255c-47d9-130c-3d0f735e3f9c@tjol.eu> Message-ID: > On 10 Nov 2019, at 00:09, Skip Montanaro wrote: > > (Sorry, not 100% sure of the credit for this quote, Vitaly, perhaps?) > >>>> If your software runs on Windows, of you think it might run on Windows >>>> in the future, maybe consider writing simple Python scripts for >>>> platform-independent tasks rather than makefiles and shell scripts. > > Maybe try SCons or CMake for cross-platform functionality? > > Chris: > >>> Are you assuming that every Windows system has Python, but that you >>> can't get make or bash? Because neither half of that is true. I've >>> happily used makefiles on Windows, and these days, bash is as easy to >>> get hold of as Python is. > > Thomas: > >> That's why I say "a bit of a hassle". You can get a MSYS set up (whether >> from Git for Windows or otherwise). You can get it to play nice with the >> right Python installation and the Python scripts you presumably want to >> call from the Makefile. But all of that is a bit of a hassle. > > I thought recent versions of Win10 had a full Ubuntu subsystem. Before > that, doesn't something like Cygwin still exist/work? If you are working on native Windows apps then cygwin or WSL will not help you as they hide the Windows world from you. Personally I write .CMD files for the windows stuff I need to mirror the bash .sh scripts I use. They tend to bootstrap up python build tools I use. Barry > > Disclaimer: I am not a Windows person, and managed to avoid it for my > entire career. > > Skip > -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at DancesWithMice.info Sun Nov 10 17:36:29 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 11 Nov 2019 11:36:29 +1300 Subject: Looking for python pentest scripts In-Reply-To: References: Message-ID: <87ee9730-2cad-9be8-a906-070ca8b2945a@DancesWithMice.info> On 11/11/19 12:36 AM, nixuser wrote: > can someone tell about good resource for python related pentesting > scripts? > any extensive list? What is the purpose of such scripts/list? -- Regards =dn From rosuav at gmail.com Sun Nov 10 18:18:35 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Nov 2019 10:18:35 +1100 Subject: Looking for python pentest scripts In-Reply-To: <87ee9730-2cad-9be8-a906-070ca8b2945a@DancesWithMice.info> References: <87ee9730-2cad-9be8-a906-070ca8b2945a@DancesWithMice.info> Message-ID: On Mon, Nov 11, 2019 at 9:38 AM DL Neil via Python-list wrote: > > On 11/11/19 12:36 AM, nixuser wrote: > > can someone tell about good resource for python related pentesting > > scripts? > > any extensive list? > > > What is the purpose of such scripts/list? > C'mon Neil, isn't it obvious? Anyone who uses a pen needs to test it. I think normal unittest should be sufficient to test your pen, though. Assert that, when you remove the cap, press it against paper, and sweep it through a line, that the paper then has a discolouration on it. Or test that when you open the gate in the pen, put an animal inside it, and then close the gate, that the animal is only able to move around within the pen. Either of these should count as pen-testing. Someone just has to write the Python scripts for it. Of course, if the OP is thinking of something entirely different, then perhaps it would help to have a lot more details about WHAT s/he is trying to test... and why. ChrisA From bgailer at gmail.com Sun Nov 10 19:32:14 2019 From: bgailer at gmail.com (Bob Gailer) Date: Sun, 10 Nov 2019 19:32:14 -0500 Subject: Looking for python pentest scripts In-Reply-To: References: Message-ID: Try Googling python pentesting. That will give you some relevant links. On Nov 10, 2019 6:40 AM, "nixuser" wrote: > Hello, > > can someone tell about good resource for python related pentesting > scripts? > any extensive list? > > Thanks > -- > https://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Sun Nov 10 22:39:48 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 10 Nov 2019 22:39:48 -0500 Subject: Looking for python pentest scripts In-Reply-To: References: Message-ID: On 11/10/2019 7:32 PM, Bob Gailer wrote: > On Nov 10, 2019 6:40 AM, "nixuser" wrote: >> can someone tell about good resource for python related pentesting >> scripts? >> any extensive list? > Try Googling python pentesting. That will give you some relevant links. I had search 'pentest' to be reminded in this context that 'pentest' can mean 'penetration test', as in "an authorized simulated cyberattack on a computer system, performed to evaluate the security of the system." (Wikipedia (Google's Youtube has multiple sometimes interesting videos where people do penetration tests with bullets and arrows and such against various targets. It turns out the the 'funny-looking' extensions near the top of some medieval plate armor chest pieces serve to block arrow heads deflected up off the chest toward the chin.) -- Terry Jan Reedy From bluebox03 at gmail.com Sun Nov 10 22:45:57 2019 From: bluebox03 at gmail.com (tommy yama) Date: Mon, 11 Nov 2019 12:45:57 +0900 Subject: Looking for python pentest scripts In-Reply-To: References: Message-ID: http://pentestmonkey.net/ On Mon, Nov 11, 2019 at 12:42 PM Terry Reedy wrote: > On 11/10/2019 7:32 PM, Bob Gailer wrote: > > > On Nov 10, 2019 6:40 AM, "nixuser" wrote: > >> can someone tell about good resource for python related pentesting > >> scripts? > >> any extensive list? > > > Try Googling python pentesting. That will give you some relevant links. > > I had search 'pentest' to be reminded in this context that 'pentest' can > mean 'penetration test', as in "an authorized simulated cyberattack on a > computer system, performed to evaluate the security of the system." > (Wikipedia > > (Google's Youtube has multiple sometimes interesting videos where people > do penetration tests with bullets and arrows and such against various > targets. It turns out the the 'funny-looking' extensions near the top > of some medieval plate armor chest pieces serve to block arrow heads > deflected up off the chest toward the chin.) > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list > From torriem at gmail.com Sun Nov 10 22:57:09 2019 From: torriem at gmail.com (Michael Torrie) Date: Sun, 10 Nov 2019 20:57:09 -0700 Subject: Using Makefiles in Python projects In-Reply-To: References: <407b8a4a-5921-c728-55a2-ba7ae07118ab@tjol.eu> <3c62dc25-255c-47d9-130c-3d0f735e3f9c@tjol.eu> Message-ID: <908cb5d2-11f9-d883-e920-2fb3155876f4@gmail.com> On 11/9/19 5:09 PM, Skip Montanaro wrote: > I thought recent versions of Win10 had a full Ubuntu subsystem. Before > that, doesn't something like Cygwin still exist/work? Sure you can install Ubuntu into the WSL2 system, but it's not like you can use that to script things back into Windows land. The WSL2 is essentially a light-weight virtual machine. You can access the windows file system from within it, but so far as I know you can't interact with Windows processes, at least not easily. So no, the WSL is not like cygwin. > Disclaimer: I am not a Windows person, and managed to avoid it for my > entire career. From rhodri at kynesim.co.uk Mon Nov 11 08:05:01 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 11 Nov 2019 13:05:01 +0000 Subject: Syntax Suggestion: Pass Function Definition as Argument In-Reply-To: <6da7c5f1-003e-4b19-b9e8-715ecba8624e@googlegroups.com> References: <6da7c5f1-003e-4b19-b9e8-715ecba8624e@googlegroups.com> Message-ID: <76f8ca9f-8e36-321a-d1d2-431dd9d4ac6b@kynesim.co.uk> On 07/11/2019 13:36, Stephen Waldron wrote: > This is how it is at the moment, however it may be more agreeable, especially if that is the only purpose of the function, for python users to be able to define new functions inside of function calls. No, not seeing it. Sorry, I don't think "I don't want to use up a precious, precious name in this namespace" is a good enough reason to do anything, never mind something with a lot of implicit naming going on. Suppose you had been good and made a module of your Book example. What is someone reading your code supposed to make of this? import books my_books = [ books.Book("Triplanetary", 'E.E. "Doc" Smith'), books.Book("Foundation", "Isaac Asimov") ] books.doToBooks(my_books): print(book.name, ":", book.author) then: if book.name == "Foundation": print("READ THIS FIRST!") The name "book" has just appeared out of thin air, and without stopping and reading the code of your module they will have to guess at what it is. Now in this case their first guess is probably right, but this is a toy example and just as easily written with lambdas if you're that worried about using up names. -10 from me. -- Rhodri James *-* Kynesim Ltd From rhodri at kynesim.co.uk Mon Nov 11 08:23:05 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 11 Nov 2019 13:23:05 +0000 Subject: Using Makefiles in Python projects In-Reply-To: <3c62dc25-255c-47d9-130c-3d0f735e3f9c@tjol.eu> References: <407b8a4a-5921-c728-55a2-ba7ae07118ab@tjol.eu> <3c62dc25-255c-47d9-130c-3d0f735e3f9c@tjol.eu> Message-ID: On 09/11/2019 23:50, Thomas Jollans wrote: > On 09/11/2019 21:30, Chris Angelico wrote: >> On Sun, Nov 10, 2019 at 2:10 AM Thomas Jollans wrote: >>> On 07/11/2019 20:20, Vitaly Potyarkin wrote: >>>> What do you think of using Makefiles for automating common chores in >>>> Python projects? Like linting, type checking and testing? >>>> >>>> I've come up with a reusable Makefile for automating virtual >>>> environment >>>> management in Python projects. I think it can be useful for simplifying >>>> the onboarding of new developers (both new to project and new to >>>> Python) >>>> and for documenting project's development practices. >>>> >>>> Here it is: >>>> - Repo: https://github.com/sio/Makefile.venv >>>> - Demo screencast: https://asciinema.org/a/279646 >>>> >>>> What do you think? Is this useful or I'm just unaware of some tool that >>>> abstracts venv chores away better? >>>> >>> As others have said, make is a useful tool and many people use it for >>> different purposes in their Python projects. Nothing wrong with that. >>> >>> HOWEVER, at risk of stating the obvious, using Makefiles written for/on >>> *nix systems on Windows is a bit of a hassle. If, for some reason, your >>> software is *nix-only anyway, that's fine. If not, using make means >>> sacrificing some portability. >>> >>> If your software runs on Windows, of you think it might run on Windows >>> in the future, maybe consider writing simple Python scripts for >>> platform-independent tasks rather than makefiles and shell scripts. >>> >> Are you assuming that every Windows system has Python, but that you >> can't get make or bash? Because neither half of that is true. I've >> happily used makefiles on Windows, and these days, bash is as easy to >> get hold of as Python is. >> >> ChrisA > > That's why I say "a bit of a hassle". You can get a MSYS set up (whether > from Git for Windows or otherwise). You can get it to play nice with the > right Python installation and the Python scripts you presumably want to > call from the Makefile. But all of that is a bit of a hassle. If you've got almost any development environment for Windows, you've got a version of make. I quite like the NMake that comes with Visual Studio, for example, and use it in preference to the IDE when I can. Yes, it's a hassle, but it's a hassle you're going to go through anyway. -- Rhodri James *-* Kynesim Ltd From veek at dont-use-this.com Mon Nov 11 11:08:12 2019 From: veek at dont-use-this.com (Veek M) Date: Mon, 11 Nov 2019 16:08:12 -0000 (UTC) Subject: What is a backing store in the context of module io =?us-ascii?Q?https=3A=2F=2Fdocs=2Epython=2Eorg=2F3=2Flibrary=2Fio=2Eht?= =?us-ascii?Q?ml?= Message-ID: So i was making some notes and: https://i.imgur.com/UATAKXh.png I did not understand this https://docs.python.org/3/library/io.html 'Text I/O expects and produces str objects. This means that whenever the backing store is natively made of bytes (such as in the case of a file), encoding and decoding of data is made transparently as well as optional translation of platform-specific newline characters.' 1. What is a backing store? 2. How does it fit in/influence what we pass to the fileObject/stream/ filelikeObject.method() So I've drawn a small dia - but I cannot see a connection between the 'str' object or 'bytes' object being passed to .write() and the Backing Store? Google just says the backing store is secondary MEMORY - Harddisk cache or for paging.. but how does that relate to Python? I just concluded the backing store was a buffer? From veek at dont-use-this.com Mon Nov 11 11:26:44 2019 From: veek at dont-use-this.com (Veek M) Date: Mon, 11 Nov 2019 16:26:44 -0000 (UTC) Subject: What is a backing store in the context of module io =?us-ascii?Q?https=3A=2F=2Fdocs=2Epython=2Eorg=2F3=2Flibrary=2Fio=2Eht?= =?us-ascii?Q?ml?= References: Message-ID: On Mon, 11 Nov 2019 16:08:12 +0000, Veek M wrote: > So i was making some notes and: https://i.imgur.com/UATAKXh.png > > I did not understand this > > https://docs.python.org/3/library/io.html 'Text I/O expects and produces > str objects. This means that whenever the backing store is natively made > of bytes (such as in the case of a file), > encoding and decoding of data is made transparently as well as optional > translation of platform-specific newline characters.' > > 1. What is a backing store? > 2. How does it fit in/influence what we pass to the fileObject/stream/ > filelikeObject.method() > I was reading pydoc io and - how do I decipher the indentation? _io._BufferedIOBase(_io._IOBase) _io.BufferedRWPair _io.BufferedRandom #are these Derived Classes of BufferedIOBase? _io.BufferedReader _io.BufferedWriter _io.BytesIO BufferedIOBase(_io._BufferedIOBase, IOBase) #huh?? _io._IOBase(__builtin__.object) IOBase #huh??? BufferedIOBase(_io._BufferedIOBase, IOBase) RawIOBase(_io._RawIOBase, IOBase) TextIOBase(_io._TextIOBase, IOBase) _io._RawIOBase(_io._IOBase) _io.FileIO RawIOBase(_io._RawIOBase, IOBase) _io._TextIOBase(_io._IOBase) _io.StringIO _io.TextIOWrapper TextIOBase(_io._TextIOBase, IOBase) From __peter__ at web.de Mon Nov 11 11:46:53 2019 From: __peter__ at web.de (Peter Otten) Date: Mon, 11 Nov 2019 17:46:53 +0100 Subject: What is a backing store in the context of module io https://docs.python.org/3/library/io.html References: Message-ID: Veek M wrote: > I was reading pydoc io and - how do I decipher the indentation? $ cat demo.py class Base: pass class Sub(Base): pass class SubSub(Sub): pass class Other: pass class OtherSub(Other, Base): pass $ pydoc3.7 demo | head -n13 Help on module demo: NAME demo CLASSES builtins.object Base Sub SubSub Other OtherSub(Other, Base) So indentation illustrates the class hierarchy; where this fails because of multiple inheritance the base classes are listed explicitly. From tjol at tjol.eu Mon Nov 11 12:55:30 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 11 Nov 2019 18:55:30 +0100 Subject: Using Makefiles in Python projects In-Reply-To: References: <407b8a4a-5921-c728-55a2-ba7ae07118ab@tjol.eu> <3c62dc25-255c-47d9-130c-3d0f735e3f9c@tjol.eu> Message-ID: <4794a31d-53b8-c494-1995-028733fad278@tjol.eu> On 11/11/2019 14:23, Rhodri James wrote: > On 09/11/2019 23:50, Thomas Jollans wrote: >> On 09/11/2019 21:30, Chris Angelico wrote: >>> On Sun, Nov 10, 2019 at 2:10 AM Thomas Jollans wrote: >>>> On 07/11/2019 20:20, Vitaly Potyarkin wrote: >>>>> What do you think of using Makefiles for automating common chores in >>>>> Python projects? Like linting, type checking and testing? >>>>> >>>>> I've come up with a reusable Makefile for automating virtual >>>>> environment >>>>> management in Python projects. I think it can be useful for >>>>> simplifying >>>>> the onboarding of new developers (both new to project and new to >>>>> Python) >>>>> and for documenting project's development practices. >>>>> >>>>> Here it is: >>>>> - Repo: https://github.com/sio/Makefile.venv >>>>> - Demo screencast: https://asciinema.org/a/279646 >>>>> >>>>> What do you think? Is this useful or I'm just unaware of some tool >>>>> that >>>>> abstracts venv chores away better? >>>>> >>>> As others have said, make is a useful tool and many people use it for >>>> different purposes in their Python projects. Nothing wrong with that. >>>> >>>> HOWEVER, at risk of stating the obvious, using Makefiles written >>>> for/on >>>> *nix systems on Windows is a bit of a hassle. If, for some reason, >>>> your >>>> software is *nix-only anyway, that's fine. If not, using make means >>>> sacrificing some portability. >>>> >>>> If your software runs on Windows, of you think it might run on Windows >>>> in the future, maybe consider writing simple Python scripts for >>>> platform-independent tasks rather than makefiles and shell scripts. >>>> >>> Are you assuming that every Windows system has Python, but that you >>> can't get make or bash? Because neither half of that is true. I've >>> happily used makefiles on Windows, and these days, bash is as easy to >>> get hold of as Python is. >>> >>> ChrisA >> >> That's why I say "a bit of a hassle". You can get a MSYS set up >> (whether from Git for Windows or otherwise). You can get it to play >> nice with the right Python installation and the Python scripts you >> presumably want to call from the Makefile. But all of that is a bit >> of a hassle. > > If you've got almost any development environment for Windows, you've > got a version of make.? I quite like the NMake that comes with Visual > Studio, for example, and use it in preference to the IDE when I can. > Yes, it's a hassle, but it's a hassle you're going to go through anyway. > I'm sure it's possible to write Makefiles that work with both GNU make and NMake, but I imagine it's a rather limiting and thankless enterprise. Is that something you actually do? (Maybe it's great, I really wouldn't know. Do tell!) From joepareti54 at gmail.com Mon Nov 11 13:14:08 2019 From: joepareti54 at gmail.com (joseph pareti) Date: Mon, 11 Nov 2019 19:14:08 +0100 Subject: Hi there! We are here to answer any questions you have about Udacit... In-Reply-To: References: <9feebd73533a47dc1605998e06da50b527b66f0c@intercom> Message-ID: i have done the first 6 lessons of python --- https://classroom.udacity.com/courses/ud1110/lessons/bbacebc6-406a-4dc5-83f6-ef7ba3371da6/concepts/50247542-7933-4afe-9130-ff1dff429b03 what do you recommend next? My goal is ML/AI thank you --- Am Do., 7. Nov. 2019 um 22:01 Uhr schrieb joseph pareti < joepareti54 at gmail.com>: > > > ---------- Forwarded message --------- > Von: joseph pareti > Date: Do., 7. Nov. 2019 um 09:26 Uhr > Subject: Re: Hi there! We are here to answer any questions you have about > Udacit... > To: Sherry from Udacity > > > apologies if you are not the right person to ask: I am doing the python > tutorial at > https://classroom.udacity.com/courses/ud1110/lessons/8655bee4-19e1-4de0-8177-4f895a74b57b/concepts/44a22f87-f7ce-4a9a-a1f5-86024edb0f29 > > When I run the program in the provided environment I get an EOF exception > (see screen dump). > > However, in my environment, windows 10, miniconda3, python 3.* it runs > just fine. Why? > I am also sending the program source code. > --- > > > F:\x\finance-2019\AI\python\udacity\input>c:\Users\joepareti\Miniconda3\pkgs\python-3.6.8-h9f7ef89_0\python.exe > tmp_input.py > Enter a number: > 8 > your input is: 8 > corresponding int is: 8 > Oops! Your guess was too high. > > F:\x\finance-2019\AI\python\udacity\input>c:\Users\joepareti\Miniconda3\pkgs\python-3.6.8-h9f7ef89_0\python.exe > tmp_input.py > Enter a number: > 0 > your input is: 0 > corresponding int is: 0 > Oops! Your guess was too low. > > F:\x\finance-2019\AI\python\udacity\input>c:\Users\joepareti\Miniconda3\pkgs\python-3.6.8-h9f7ef89_0\python.exe > tmp_input.py > Enter a number: > 5 > your input is: 5 > corresponding int is: 5 > Nice! Your guess matched the answer! > > Am Di., 29. Okt. 2019 um 21:22 Uhr schrieb Sherry from Udacity < > sherry.cheng at udacity.com>: > >> Hi Joseph, I'm Sherry! >> >> It seems like we missed you. Before I go I would like to suggest you the >> path you should follow: >> If you're new to programming, we suggest starting your learning path by >> building a strong foundation in the basics with our Intro to Programming >> Nanodegree. Once you complete this course, you will have much better view >> of what to take next:) >> Intro to programming >> >> | Syllabus >> >> The course comes with a Certificate as well as Mentorship Program, Expert >> projects reviewers, Career Services and more! >> >> *Mentorship Program:* >> When you enroll in a Udacity Nanodegree program, you'll be matched with a >> 1-on-1 technical mentor. Mentors are individuals with strong subject matter >> knowledge who are there to help you succeed in your Nanodegree program. >> Your Mentor will >> >> -Respond to content-specific and project-specific questions you have >> about your Nanodegree program >> -Conduct 1-on-1 virtual meetings with you, at your request (you'll be >> able to schedule one 1-on-1 each week, if needed) >> -Motivate you to stay on track with your custom learning plan. >> >> *Career Services:* >> As a student enrolled in a Nanodegree program, you'll have access to the >> following career resources for 12 months after the graduation and during >> the class to help you reach your goals: >> >> -1:1 Career Coaching appointment >> -Career + Networking Events >> -GitHub, LinkedIn, Resume, Cover Letter Reviews >> -The Career Portal >> -Membership in the Udacity Talent Program with top tech employers upon >> graduation >> -Send students resume to over 95 companies that we are partners with. >> Let me know if you need to know anything else [image: +1] >> >> -- >> [image: Sherry] *Sherry* from Udacity >> On Tue, Oct 29, 2019 at 03:12 PM, "Joseph" >> wrote: >> >> udacity told me that I first need to have good python knowledge, right? >> On Tue, Oct 29, 2019 at 03:10 PM, "Carla" < >> operator at udacity-8fbceca20105.intercom-mail.com> wrote: >> >> *Great, we have advisors ready to answer your questions! To get started, >> please put in your email so we can follow up in case we get disconnected:* >> >> *By providing your information and clicking ?Submit,? you consent and >> agree to receive marketing emails from Udacity, and that your information >> will be used in accordance with the Udacity** Terms of Use* >> * and** Privacy Policy* >> *, including relevant opt out >> provisions therein.* >> >> * Thanks joseph! We can tell you more about our Nanodegree programs or >> answer anything else you want to know! We are here Monday - Friday, 24 >> hours . If we aren't here at the moment we will respond as soon as we can.* >> On Tue, Oct 29, 2019 at 03:10 PM, "Joseph" >> wrote: >> >> I?d like to learn more >> On Tue, Oct 29, 2019 at 03:10 PM, "Carla" < >> operator at udacity-8fbceca20105.intercom-mail.com> wrote: >> >> *Hi there! We are here to answer any questions you have about Udacity.How >> can we help you? * >> >> [image: intercom] >> > > > -- > Regards, > Joseph Pareti - Artificial Intelligence consultant > Joseph Pareti's AI Consulting Services > https://www.joepareti54-ai.com/ > cell +49 1520 1600 209 > cell +39 339 797 0644 > > > -- > Regards, > Joseph Pareti - Artificial Intelligence consultant > Joseph Pareti's AI Consulting Services > https://www.joepareti54-ai.com/ > cell +49 1520 1600 209 > cell +39 339 797 0644 > -- Regards, Joseph Pareti - Artificial Intelligence consultant Joseph Pareti's AI Consulting Services https://www.joepareti54-ai.com/ cell +49 1520 1600 209 cell +39 339 797 0644 From rhodri at kynesim.co.uk Mon Nov 11 13:14:43 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 11 Nov 2019 18:14:43 +0000 Subject: Using Makefiles in Python projects In-Reply-To: <4794a31d-53b8-c494-1995-028733fad278@tjol.eu> References: <407b8a4a-5921-c728-55a2-ba7ae07118ab@tjol.eu> <3c62dc25-255c-47d9-130c-3d0f735e3f9c@tjol.eu> <4794a31d-53b8-c494-1995-028733fad278@tjol.eu> Message-ID: On 11/11/2019 17:55, Thomas Jollans wrote: > I'm sure it's possible to write Makefiles that work with both GNU make > and NMake, but I imagine it's a rather limiting and thankless enterprise. > > Is that something you actually do? (Maybe it's great, I really wouldn't > know. Do tell!) Trying to work cross-platform with NMake/GNU make is every bit as horrid as you're imagining when you start getting clever, and I haven't tried doing it for years. Generally when I'm working on both Windows and Linux, Cygwin is involved anyway so I just use GNU make and be done with it. -- Rhodri James *-* Kynesim Ltd From grant.b.edwards at gmail.com Mon Nov 11 14:01:44 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 11 Nov 2019 19:01:44 -0000 (UTC) Subject: Using Makefiles in Python projects References: <407b8a4a-5921-c728-55a2-ba7ae07118ab@tjol.eu> <3c62dc25-255c-47d9-130c-3d0f735e3f9c@tjol.eu> <4794a31d-53b8-c494-1995-028733fad278@tjol.eu> Message-ID: On 2019-11-11, Rhodri James wrote: >> I'm sure it's possible to write Makefiles that work with both GNU make >> and NMake, but I imagine it's a rather limiting and thankless enterprise. >> >> Is that something you actually do? (Maybe it's great, I really wouldn't >> know. Do tell!) > > Trying to work cross-platform with NMake/GNU make is every bit as horrid > as you're imagining when you start getting clever, and I haven't tried > doing it for years. That's my experience as well. > Generally when I'm working on both Windows and Linux, Cygwin is > involved anyway so I just use GNU make and be done with it. And that's also what I usually do. I've been tempted to try msys make/bash instead of Cygwin, but that's probably not going to happen until something stops working under Cygwin or I run out of more entertaining projects before spring. -- Grant Edwards grant.b.edwards Yow! I want another at RE-WRITE on my CEASAR gmail.com SALAD!! From bill at baddogconsulting.com Mon Nov 11 14:05:58 2019 From: bill at baddogconsulting.com (Bill Deegan) Date: Mon, 11 Nov 2019 14:05:58 -0500 Subject: Using Makefiles in Python projects In-Reply-To: References: <407b8a4a-5921-c728-55a2-ba7ae07118ab@tjol.eu> <3c62dc25-255c-47d9-130c-3d0f735e3f9c@tjol.eu> <4794a31d-53b8-c494-1995-028733fad278@tjol.eu> Message-ID: You could use SCons (native python... ) On Mon, Nov 11, 2019 at 2:04 PM Grant Edwards wrote: > On 2019-11-11, Rhodri James wrote: > >> I'm sure it's possible to write Makefiles that work with both GNU make > >> and NMake, but I imagine it's a rather limiting and thankless > enterprise. > >> > >> Is that something you actually do? (Maybe it's great, I really wouldn't > >> know. Do tell!) > > > > Trying to work cross-platform with NMake/GNU make is every bit as horrid > > as you're imagining when you start getting clever, and I haven't tried > > doing it for years. > > That's my experience as well. > > > Generally when I'm working on both Windows and Linux, Cygwin is > > involved anyway so I just use GNU make and be done with it. > > And that's also what I usually do. I've been tempted to try msys > make/bash instead of Cygwin, but that's probably not going to happen > until something stops working under Cygwin or I run out of more > entertaining projects before spring. > > -- > Grant Edwards grant.b.edwards Yow! I want another > at RE-WRITE on my CEASAR > gmail.com SALAD!! > > -- > https://mail.python.org/mailman/listinfo/python-list > From 00jhenryg at gmail.com Mon Nov 11 14:07:25 2019 From: 00jhenryg at gmail.com (Jack Gilbert) Date: Mon, 11 Nov 2019 13:07:25 -0600 Subject: Help! Message-ID: Here's the deal, I have loaded both, one at a time, 3.7.2, and tried 3.8.0, separately, when I go to open the program to run I get the same message, Each time and for each version I get a Setup window. asking to modify, repair, or uninstall, I usu uninstall, I don't think it is the install, something with in my win 8.1 system that maybe causing this problem. Thanks in advance for helping me. Jack G. From tjreedy at udel.edu Mon Nov 11 14:29:17 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Nov 2019 14:29:17 -0500 Subject: What is a backing store in the context of module io https://docs.python.org/3/library/io.html In-Reply-To: References: Message-ID: On 11/11/2019 11:08 AM, Veek M wrote: > https://docs.python.org/3/library/io.html > 'Text I/O expects and produces str objects. This means that whenever the > backing store is natively made of bytes (such as in the case of a file), > encoding and decoding of data is made transparently as well as optional > translation of platform-specific newline characters.' > > 1. What is a backing store? Whatever you can read from or write to. Unix uses 'file' with the same extended sense. Reread the Overview section above. > 2. How does it fit in/influence what we pass to the fileObject/stream/ > filelikeObject.method() What the text you quote says is that if the source or destination for a text stream is actually bytes, you still receive or pass text because the translation is done for you (if you have opened the text stream with the right arguments. > Google just says the backing store is secondary MEMORY - Harddisk cache > or for paging.. but how does that relate to Python? Different languages have different data models of what one is manipulating. In assembly and C, one manipulates fixed-length blocks of main memory, which itself is a sequence of bytes numbered 0, ..., N. So a backup store is 'secondary memory'. Python manipulates 'information objects' in an 'object space'. Python objects of type str and bytes, and only those two types, can be input and output. Other objects are converted from or to one of those types for input and output. > I just concluded the backing store was a buffer? Text and binary streams use a buffer, raw streams do not. -- Terry Jan Reedy From joepareti54 at gmail.com Mon Nov 11 14:43:49 2019 From: joepareti54 at gmail.com (joseph pareti) Date: Mon, 11 Nov 2019 20:43:49 +0100 Subject: apologies for my latest email; it was not intended for this mailing list Message-ID: -- Regards, Joseph Pareti - Artificial Intelligence consultant Joseph Pareti's AI Consulting Services https://www.joepareti54-ai.com/ cell +49 1520 1600 209 cell +39 339 797 0644 From PythonList at DancesWithMice.info Mon Nov 11 15:04:52 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 12 Nov 2019 09:04:52 +1300 Subject: Looking for python pentest scripts In-Reply-To: References: Message-ID: On 11/11/19 4:39 PM, Terry Reedy wrote: > On 11/10/2019 7:32 PM, Bob Gailer wrote: >> On Nov 10, 2019 6:40 AM, "nixuser" wrote: >>> can someone tell about good resource for python related pentesting >>> scripts? >>> any extensive list? > > Try Googling python pentesting. That will give you some relevant links. > (Google's Youtube has multiple sometimes interesting videos where people > do penetration tests with bullets and arrows and such against various > targets.? It turns out the the 'funny-looking' extensions near the top > of some medieval plate armor chest pieces serve to block arrow heads > deflected up off the chest toward the chin.) TLDR? Last paragraph is most pertinent. I read this, whilst still chortling at the opus @Chris had pen-ned about testing. Then one of the guys from my old unit rang. He was grumbling (even though Americans are typically less familiar with the British expression: grumpy, old men - it suits us). He wanted to know if we have been "infected" over here (we have), his complaint was about the rising fashion for "Singles Day", and "doesn't 11 and 11 mean either 22 or 4? So, what's 'single' about that?". Guess he has a point, how come 'they' didn't at least 'downgrade' to choosing 1/1? Some (other) significance to the numbers perhaps? Evidently Remembrance Day/Veterans' Day can have different meanings, as per "pen-testing". Similarly, an irony: the OP hasn't fronted to say whether (s)he has 'white hat' or 'black hat' ambitions; just as the contemplation of war and peace brings one to consider how the motives behind the possibility of single-selfishness today, contrast markedly from those of accepting the suffering and sacrifice which helped to make this world what it is. To distract from the above conversational tone, I mentioned the 'armor' deflection-pieces (there's probably a name for these, but we didn't use "armor" (I'm not THAT old) - nor did we have kevlar vests!). The laconic reply was that "No, but when you're the target of attack, we'd burrow-down attempting to hide behind the smallest pebble". Almost the same thing then? However, we're here to discuss Python: A 'security' colleague commented that there is a Linux distro/distribution, "Kali" (another name with opportunity for ambiguity!). Apparently, "Kali is designed for pen-testing - and there are likely many associated Python scripts, because Python is a language so well suited to fast-developing situations!". YMMV... WebRefs: https://en.wikipedia.org/wiki/Remembrance_Day https://en.wikipedia.org/wiki/Kali https://www.kali.org/ -- Regards =dn From PythonList at danceswithmice.info Mon Nov 11 15:45:00 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Tue, 12 Nov 2019 09:45:00 +1300 Subject: Hi there! We are here to answer any questions you have about Udacit... In-Reply-To: References: <9feebd73533a47dc1605998e06da50b527b66f0c@intercom> Message-ID: <48349afd-e344-2289-c60f-aae530d80f77@DancesWithMice.info> On 12/11/19 7:14 AM, joseph pareti wrote: > i have done the first 6 lessons of python --- > https://classroom.udacity.com/courses/ud1110/lessons/bbacebc6-406a-4dc5-83f6-ef7ba3371da6/concepts/50247542-7933-4afe-9130-ff1dff429b03 > > what do you recommend next? My goal is ML/AI As with any professional field, there is no end to the learning... Probably some consolidation to provide a solid set of Python skills, would be a good idea; and then to dig-into ML - if you have the patience and long-term view. If you'd like to switch to books: There are plenty to choose from. My impression of the current crop of Python/ML/AI books is that they either start at a reasonably 'high' level or their 'intro to Python' chapters are rather perfunctory. Have you an assessment? Another impression, is that in the rush-to-publish/to be 'first', there is a very confusing coverage. Perhaps better to read non-specific books about ML/AI as preparation, and then focus on specifics (and thus applicable Python texts)? Meantime, build-up your Python skills - I've previously mentioned 'here' the The Python Craftsman series (Apprentice, Journeyman, Master), but there are others. If you're comfortable with MOOCs: I have found Udacity courses tend to be a little 'thin' (YMMV!). Coursera has a range of offerings, and you might review the multiple series from U.Michigan (have assessed some and are IMHO competent but not earth-shattering). U.Mich also offer a number of ML courses/quals, which may be of-interest (and hence the specific mention). Similarly, edX where I noted a number of IBM ML offerings both with and without Python and likely majoring on "Watson". (apologies, I'm biased against the multitude of MSFT's offerings, also present) WebRefs: https://leanpub.com/b/python-craftsman (per example) https://www.coursera.org/specializations/data-science-python https://www.edx.org Disclaimer: have no commercial connection to any of the above-mentioned, but do use the edX platform to offer (non-Python) training. -- Tsch?ss =dn From PythonList at danceswithmice.info Mon Nov 11 16:13:57 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Tue, 12 Nov 2019 10:13:57 +1300 Subject: apologies for my latest email; it was not intended for this mailing list In-Reply-To: References: Message-ID: <8b8b3080-4506-8bf2-d293-f6aa25b1de12@DancesWithMice.info> Because of something we said? (to upset you=joke!) -- Regards =dn From cs at cskk.id.au Mon Nov 11 16:21:49 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 12 Nov 2019 08:21:49 +1100 Subject: Help! In-Reply-To: References: Message-ID: <20191111212149.GA26212@cskk.homeip.net> On 11Nov2019 13:07, Jack Gilbert <00jhenryg at gmail.com> wrote: >Here's the deal, I have loaded both, one at a time, 3.7.2, and tried 3.8.0, >separately, when I go to open the program to run I get the same message, > Each time and for each version I get a Setup window. asking to modify, >repair, or uninstall, I usu uninstall, > >I don't think it is the install, something with in my win 8.1 system that >maybe causing this problem. This sounds to me like you are not starting Python, instead you are starting its installer. See if there's a programme called "IDLE". And I gather the command to run Python from a command line is "py" on Windows (I am not a Windows person, so my advice is vague). Cheers, Cameron Simpson From torriem at gmail.com Mon Nov 11 23:06:32 2019 From: torriem at gmail.com (Michael Torrie) Date: Mon, 11 Nov 2019 21:06:32 -0700 Subject: Help! In-Reply-To: References: Message-ID: <640f056b-9bc9-c37e-51d2-79d98ca0ba4b@gmail.com> On 11/11/19 12:07 PM, Jack Gilbert wrote: > Here's the deal, I have loaded both, one at a time, 3.7.2, and tried 3.8.0, > separately, when I go to open the program to run I get the same message, > Each time and for each version I get a Setup window. asking to modify, > repair, or uninstall, I usu uninstall, > > I don't think it is the install, something with in my win 8.1 system that > maybe causing this problem. > > Thanks in advance for helping me. This comes up fairly frequently on the mailing list. Sounds like you're not actually running Python, but rather trying to run the installer again. Python is an interpreter and as such it's not meant to be run directly from the start menu (it has no user interface other than the REPL command-line prompt). Usually you write a python script in an editor of your choice, and then manually run that with Python, either from the command line, or using the py.exe launcher (usually defined as an opener for the .py file type). If your installer installed the Idle IDE, you can use that to create and run python files. From arj.python at gmail.com Mon Nov 11 23:49:44 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 12 Nov 2019 08:49:44 +0400 Subject: Can we use Python for hacking? Message-ID: Greetings all, Someone requested my answer to the question: "Can we use Python for hacking?" I compiled some interesting tools and uses here . That's as far as i could see. If someone has more examples, he can share! Yours, Abdur-Rahmaan Janhangeer pythonmembers.club | github Mauritius From torriem at gmail.com Tue Nov 12 00:20:28 2019 From: torriem at gmail.com (Michael Torrie) Date: Mon, 11 Nov 2019 22:20:28 -0700 Subject: Can we use Python for hacking? In-Reply-To: References: Message-ID: <84933360-5c8d-0f66-f6a6-e7c8bb19ab0a@gmail.com> On 11/11/19 9:49 PM, Abdur-Rahmaan Janhangeer wrote: > Someone requested my answer to the question: "Can we use Python for > hacking?" Sigh. I suppose it's a lost battle to reclaim that word. Most of what I do with Python is hacking but likely not as you are using the word. Most recently I hacked together a little rsync snapshotting backup script using Python (well xonsh). I suspect most of the forum members hack things with Python on a regular basis. From pankaj.jangid at gmail.com Tue Nov 12 05:12:41 2019 From: pankaj.jangid at gmail.com (Pankaj Jangid) Date: Tue, 12 Nov 2019 15:42:41 +0530 Subject: Can we use Python for hacking? References: <84933360-5c8d-0f66-f6a6-e7c8bb19ab0a@gmail.com> Message-ID: >> Someone requested my answer to the question: "Can we use Python for >> hacking?" > Sigh. I suppose it's a lost battle to reclaim that word. So true. I still remember the ESR article that I used to share twenty years ago. -- Pankaj Jangid From rhodri at kynesim.co.uk Tue Nov 12 06:27:59 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 12 Nov 2019 11:27:59 +0000 Subject: Using Makefiles in Python projects In-Reply-To: References: <407b8a4a-5921-c728-55a2-ba7ae07118ab@tjol.eu> <3c62dc25-255c-47d9-130c-3d0f735e3f9c@tjol.eu> <4794a31d-53b8-c494-1995-028733fad278@tjol.eu> Message-ID: <64fefd37-2209-a238-9e4f-a4c339b63de2@kynesim.co.uk> On 11/11/2019 19:05, Bill Deegan wrote: > You could use SCons (native python... ) I could. But I'd have to learn how to first, and particularly for complex cross-platform working that involves learning a lot of stuff I already know how to do in Make. The time investment has never seemed that worthwhile. -- Rhodri James *-* Kynesim Ltd From pieter-l at vanoostrum.org Tue Nov 12 07:39:21 2019 From: pieter-l at vanoostrum.org (Pieter van Oostrum) Date: Tue, 12 Nov 2019 13:39:21 +0100 Subject: Funny behavior of IDLE 3.7.0 References: <3.8-20191111194144@ram.dialup.fu-berlin.de> Message-ID: ram at zedat.fu-berlin.de (Stefan Ram) writes: > When I enter > > i = 4 > x = 2.3 > s = 'abc' > print( f'{i=}' ) > > into a file window of IDLE 3.7.0, it marks the '=' > sign in the /first/ line and says 'invalid syntax'. > > Remove the ?f?, and the error will disappear. I did this in IDLE 3.7.5, and it gives a syntax error on the last line. This is correct, because the f-string is in error. Between the curly braces there should be an expression, possibly followed by a conversion (!...) and/or a format specification (:...). {i=} is not a correct expression. When you remove the ?f?, it becomes a normal string, where the {} don't have a special meaning. -- Pieter van Oostrum WWW: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From heindsight at kruger.dev Tue Nov 12 08:12:40 2019 From: heindsight at kruger.dev (Heinrich Kruger) Date: Tue, 12 Nov 2019 13:12:40 +0000 Subject: Funny behavior of IDLE 3.7.0 In-Reply-To: References: <3.8-20191111194144@ram.dialup.fu-berlin.de> Message-ID: ??????? Original Message ??????? On Tuesday, November 12, 2019 12:39 PM, Pieter van Oostrum wrote: > ram at zedat.fu-berlin.de">--protonSignature--ram at zedat.fu-berlin.de (Stefan Ram) writes: > > > When I enter > > i = 4 > > x = 2.3 > > s = 'abc' > > print( f'{i=}' ) > > into a file window of IDLE 3.7.0, it marks the '=' > > sign in the /first/ line and says 'invalid syntax'. > > Remove the ?f?, and the error will disappear. > > I did this in IDLE 3.7.5, and it gives a syntax error on the last line. > This is correct, because the f-string is in error. Between the curly > braces there should be an expression, possibly followed by a conversion > (!...) and/or a format specification (:...). {i=} is not a correct > expression. When you remove the ?f?, it becomes a normal string, where > the {} don't have a special meaning. What the OP was trying to do is valid in python 3.8 (see https://docs.python.org/3/whatsnew/3.8.html#f-strings-support-for-self-documenting-expressions-and-debugging) but not in older versions. To achieve the same result in python 3.7, you have to do something like print(f'i={i}') -- Heinrich Kruger From rosuav at gmail.com Tue Nov 12 08:29:44 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Nov 2019 00:29:44 +1100 Subject: Funny behavior of IDLE 3.7.0 In-Reply-To: References: <3.8-20191111194144@ram.dialup.fu-berlin.de> Message-ID: On Wed, Nov 13, 2019 at 12:14 AM Heinrich Kruger wrote: > > ??????? Original Message ??????? > On Tuesday, November 12, 2019 12:39 PM, Pieter van Oostrum wrote: > > > ram at zedat.fu-berlin.de">--protonSignature--ram at zedat.fu-berlin.de (Stefan Ram) writes: > > > > > When I enter > > > i = 4 > > > x = 2.3 > > > s = 'abc' > > > print( f'{i=}' ) > > > into a file window of IDLE 3.7.0, it marks the '=' > > > sign in the /first/ line and says 'invalid syntax'. > > > Remove the ?f?, and the error will disappear. > > > > I did this in IDLE 3.7.5, and it gives a syntax error on the last line. > > This is correct, because the f-string is in error. Between the curly > > braces there should be an expression, possibly followed by a conversion > > (!...) and/or a format specification (:...). {i=} is not a correct > > expression. When you remove the ?f?, it becomes a normal string, where > > the {} don't have a special meaning. > > What the OP was trying to do is valid in python 3.8 (see https://docs.python.org/3/whatsnew/3.8.html#f-strings-support-for-self-documenting-expressions-and-debugging) but not in older versions. To achieve the same result in python 3.7, you have to do something like > > print(f'i={i}') > The OP said that the equals sign in the *first* line was flagged as invalid syntax. Implication being that the error is being reported on the line "i = 4", not on the print at the end. And in fact, I can confirm this. Run | Check Module reports an error where i is assigned to. Here's how it looks in command-line Python: $ python3.7 demo.py File "", line 1 (i=) ^ SyntaxError: invalid syntax Newer Pythons are happy with this example, but if you replace the error with something else - say, f'{i+}' - then the same phenomenon occurs. Command-line Python reports the error on line 1 of "", and Idle misinterprets that as line 1 of the original file. This looks like an error reporting flaw in f-string handling. IMO it should just count the entire f-string as being at the line and file that the f-string starts; when working with triple-quoted f-strings, I was only able to get line numbers above 1 by having a multi-line braced expression, and that's not something we should be encouraging. This is also consistent with the way other errors in triple-quoted strings are handled: print('''hello world \N{ASDF} asdf qwer''') File "/home/rosuav/tmp/demo.py", line 1 print('''hello ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 12-19: unknown Unicode character name If it can find the position of the specific braced expression within the string, great! But at very least, it should report the location of the string in its original file. ChrisA From rosuav at gmail.com Tue Nov 12 08:50:16 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Nov 2019 00:50:16 +1100 Subject: Funny behavior of IDLE 3.7.0 In-Reply-To: References: <3.8-20191111194144@ram.dialup.fu-berlin.de> Message-ID: On Wed, Nov 13, 2019 at 12:29 AM Chris Angelico wrote: > If it can find the position of the specific braced expression within > the string, great! But at very least, it should report the location of > the string in its original file. Further to this: If a runtime (non-syntax) error occurs, it is correctly reported. This is handled by fstring_fix_node_location in ast.c, which adjusts the reported locations so future error handling gets things right. But that happens *after* any syntax errors get reported, which happens in pythonrun.c inside err_input(), I think. That doesn't get adjusted to the main file's locations, so it gets reported as "" line 1. ChrisA From marko at pacujo.net Tue Nov 12 09:46:30 2019 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 12 Nov 2019 16:46:30 +0200 Subject: Using Makefiles in Python projects References: <407b8a4a-5921-c728-55a2-ba7ae07118ab@tjol.eu> <3c62dc25-255c-47d9-130c-3d0f735e3f9c@tjol.eu> <4794a31d-53b8-c494-1995-028733fad278@tjol.eu> <64fefd37-2209-a238-9e4f-a4c339b63de2@kynesim.co.uk> Message-ID: <87sgmtw3sp.fsf@elektro.pacujo.net> Rhodri James : > On 11/11/2019 19:05, Bill Deegan wrote: >> You could use SCons (native python... ) > > I could. But I'd have to learn how to first, and particularly for > complex cross-platform working that involves learning a lot of stuff I > already know how to do in Make. The time investment has never seemed > that worthwhile. SCons can be learned by reading its man page in a single afternoon. That's how I learned it. The toughest part is to decide *how* to use it as SCons entices you with a plugin architecture. The temptation is to create a sentient monster out of your build specification. I have successfully applied a minimalistic style that is plain to a random bystander who doesn't know either Python or SCons. Here's a synopsis... At the root of your repository, you write a (Python) file called "SConstruct". In each source directory, you write a (Python) file called "SConscript". The SConstruct uses SCons primitives to call the individual SConscript files. The SCons primitives in the SCons* files don't execute build commands. Rather, they construct a dependency graph between all source and target files across the repository. (I favor a non-globbing style where every file is specified explicitly.) Each SConscript file starts with the command: Import('env') where "env" is short for "environment". An "environment" does *not* refer to environment variables but to a collection of build parameters (include paths, libraries, compilation flags etc). The SConscript file might contain this line: env.Program("hello", [ "hello.c", "world.c" ]) meaning: Using the build parameters stored in "env", compile the executable program "hello" out of two C source code files. SCons has builtin knowledge of some programming languages. So SCons knows how to preprocess the source files and can deduct the dependencies. Note that the above "env.Program()" command does not yet execute anything; it simply specifies a build node with associated explicit and implicit dependencies. Ad-hoc build rules are expressed using "env.Command()": env.Command("productivity.txt", [ "hello.c", "world.c" ], r"""cat $SOURCES | wc -l >$TARGET""") The tricky part is writing SConstruct. At its simplest, it could be something like this: def construct(): env = Environment() SConscript("src/SConscript", exports="env") if __name__ == "SCons.Script": construct() In my experience, all kinds of cross-compilation and variant-directory logic is placed in SConstruct. Marko From torriem at gmail.com Tue Nov 12 10:44:19 2019 From: torriem at gmail.com (Michael Torrie) Date: Tue, 12 Nov 2019 08:44:19 -0700 Subject: Help! In-Reply-To: References: <640f056b-9bc9-c37e-51d2-79d98ca0ba4b@gmail.com> Message-ID: As always, keep your messages on the mailing list so others can benefit. On 11/12/19 7:02 AM, Jack Gilbert wrote: > > . how do I get the PY program onto my desktop? Not quite sure what you mean. Python programs are saved into text files which you can store anywhere you want. Save them to the location you want them to be from your text editor. > . where might the idle be located If Idle is installed, a shortcut to it will be in your Windows start menu, just like most programs that are installed. It's been many years since I last used windows, but there's usually a list of programs installed, called "All Programs". > > I have no idea what I just did, but the python shell just appeared on my > desktop?????? > I pinned the shell to the taskbar.. A shortcut to the python shell, or the shell itself running in a window? Finally, it's most likely you'll find the best beginner help at the python-tutor mailing list[1]. [1] https://mail.python.org/mailman/listinfo/tutor From ianoda at hotmail.com Tue Nov 12 10:38:38 2019 From: ianoda at hotmail.com (Mike C) Date: Tue, 12 Nov 2019 15:38:38 +0000 Subject: Logistic Regression Define X and Y for Prediction Message-ID: Hi All, I have the below code. X = df.iloc[:, [4, 403]].values? y = df.iloc[:, 404].values Dummy Data looks like: host Mnemonic 12.234.13.6 start 22.22.44.67 something 23.44.44.14 begin When I define the X and Y values for prediction in the train and test data, should I capture all the columns that has been "OneHotEncoded" (that is all columns with 0 and 1) for the X and Y values??? import numpy as np import pandas as pd ? import os import matplotlib as mpl ? mpl.rcParams['figure.dpi'] = 400 ? import matplotlib.pyplot as plt ? ? # Importing the df? # Importing the df? os.chdir('c:\directory\data') # Location of data files? df = pd.read_csv('blahblahfile.csv')? ? from sklearn.preprocessing import LabelEncoder? hostip = LabelEncoder()? mnemonic = LabelEncoder()? df['host_encoded'] = hostip.fit_transform(df.reported_hostname)? df['mnemonic_encoded'] = mnemonic.fit_transform(df.mnemonic)? ? from sklearn.preprocessing import OneHotEncoder? hostip_ohe = OneHotEncoder()? mnemonic_ohe = OneHotEncoder()? X = hostip_ohe.fit_transform(df.host_encoded.values.reshape(-1,1)).toarray()? Y = mnemonic_ohe.fit_transform(df.mnemonic_encoded.values.reshape(-1,1)).toarray()? ## Add back X and Y into the original dataframe? dfOneHot = pd.DataFrame(X, columns = ["host_"+str(int(i)) for i in range(X.shape[1])])? df = pd.concat([df, dfOneHot], axis=1)? ? dfOneHot = pd.DataFrame(Y, columns = ["mnemonic_encoded"+str(int(i)) for i in range(Y.shape[1])])? df = pd.concat([df, dfOneHot], axis=1)? ? ########? here is where I am not sure if all "host_" and "mnemonic_encoded" values assigned to X and Y ? X = df.iloc[:, [4, 403]].values? y = df.iloc[:, 404].values? ? ? ? # Splitting the dataset into the Training set and Test set? from sklearn.model_selection import train_test_split? X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)? ? ? # Feature Scaling? from sklearn.preprocessing import StandardScaler? sc = StandardScaler()? X_train = sc.fit_transform(X_train)? X_test = sc.transform(X_test)? ? # Fitting Logistic Regression to the Training set? from sklearn.linear_model import LogisticRegression? classifier = LogisticRegression(random_state = 0)? classifier.fit(X_train, y_train)? ? # Predicting the Test set results? y_pred = classifier.predict(X_test)? ? # Making the Confusion Matrix? from sklearn.metrics import confusion_matrix? cm = confusion_matrix(y_test, y_pred)? ? # Visualising the Training set results? from matplotlib.colors import ListedColormap? X_set, y_set = X_train, y_train? X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01),? np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step = 0.01))? plt.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape),? alpha = 0.75, cmap = ListedColormap(('red', 'green')))? plt.xlim(X1.min(), X1.max())? plt.ylim(X2.min(), X2.max())? for i, j in enumerate(np.unique(y_set)):? plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1],? c = ListedColormap(('red', 'green'))(i), label = j)? plt.title('Logistic Regression (Training set)')? plt.xlabel('Age')? plt.ylabel('Estimated Salary')? plt.legend()? plt.show()? ? # Visualising the Test set results? from matplotlib.colors import ListedColormap? X_set, y_set = X_test, y_test? X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01),? np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step = 0.01))? plt.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape),? alpha = 0.75, cmap = ListedColormap(('red', 'green')))? plt.xlim(X1.min(), X1.max())? plt.ylim(X2.min(), X2.max())? for i, j in enumerate(np.unique(y_set)):? plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1],? c = ListedColormap(('red', 'green'))(i), label = j)? plt.title('Logistic Regression (Test set)')? plt.xlabel('Host IP')? plt.ylabel('Mnemonic')? plt.legend()? plt.show() From tjreedy at udel.edu Tue Nov 12 11:55:59 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Nov 2019 11:55:59 -0500 Subject: Funny behavior of IDLE 3.7.0 In-Reply-To: References: <3.8-20191111194144@ram.dialup.fu-berlin.de> Message-ID: On 11/12/2019 8:29 AM, Chris Angelico wrote: > The OP said that the equals sign in the *first* line was flagged as > invalid syntax. Implication being that the error is being reported on > the line "i = 4", not on the print at the end. And in fact, I can > confirm this. Run | Check Module reports an error where i is assigned > to. Here's how it looks in command-line Python: > > $ python3.7 demo.py > File "", line 1 > (i=) > ^ > SyntaxError: invalid syntax > > Newer Pythons are happy with this example, but if you replace the > error with something else - say, f'{i+}' - then the same phenomenon > occurs. Command-line Python reports the error on line 1 of > "", and Idle misinterprets that as line 1 of the original > file. > > This looks like an error reporting flaw in f-string handling. Can you open a bug issue (if not one already) and nosy me? This is awful for any IDE that processes error messages. Replacing {} with () is a secondary bug. The actual code {i=} would be clearer, and make it easier for an IDE to search for the real line. > IMO it > should just count the entire f-string as being at the line and file > that the f-string starts; when working with triple-quoted f-strings, I > was only able to get line numbers above 1 by having a multi-line > braced expression, and that's not something we should be encouraging. > This is also consistent with the way other errors in triple-quoted > strings are handled: > > print('''hello > world > \N{ASDF} > asdf > qwer''') > > File "/home/rosuav/tmp/demo.py", line 1 > print('''hello > ^ > SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes > in position 12-19: unknown Unicode character name > > If it can find the position of the specific braced expression within > the string, great! But at very least, it should report the location of > the string in its original file. -- Terry Jan Reedy From rosuav at gmail.com Tue Nov 12 12:00:21 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Nov 2019 04:00:21 +1100 Subject: Funny behavior of IDLE 3.7.0 In-Reply-To: References: <3.8-20191111194144@ram.dialup.fu-berlin.de> Message-ID: On Wed, Nov 13, 2019 at 3:57 AM Terry Reedy wrote: > > On 11/12/2019 8:29 AM, Chris Angelico wrote: > > > The OP said that the equals sign in the *first* line was flagged as > > invalid syntax. Implication being that the error is being reported on > > the line "i = 4", not on the print at the end. And in fact, I can > > confirm this. Run | Check Module reports an error where i is assigned > > to. Here's how it looks in command-line Python: > > > > $ python3.7 demo.py > > File "", line 1 > > (i=) > > ^ > > SyntaxError: invalid syntax > > > > Newer Pythons are happy with this example, but if you replace the > > error with something else - say, f'{i+}' - then the same phenomenon > > occurs. Command-line Python reports the error on line 1 of > > "", and Idle misinterprets that as line 1 of the original > > file. > > > > This looks like an error reporting flaw in f-string handling. > > Can you open a bug issue (if not one already) and nosy me? > This is awful for any IDE that processes error messages. > > Replacing {} with () is a secondary bug. The actual code > {i=} > would be clearer, and make it easier for an IDE to search for the real line. > I can do that, but I actually think the correct fix isn't inside Idle. See the followup regarding the difference between SyntaxError and NameError; in the latter case, the error is more usefully reported. ChrisA From best_lay at yahoo.com Tue Nov 12 13:06:00 2019 From: best_lay at yahoo.com (Wildman) Date: Tue, 12 Nov 2019 12:06:00 -0600 Subject: Launching a Script on the Linux Platform Message-ID: What is the best approach for launching a Python GUI program on a Linux platform. The program will be distributed in .deb format. So the .deb will contain a menu file as well as a .desktop file. The post install script will update the system menu. My question is how should the program be executed? Here are two choices for the "command=" entry in the menu file... command="/path/to/program.py" In this case the hash-bang would have to be included in the program script... #!/usr/bin/env python3 The other choice is this... command="python3 /path/to/program.py" (Of course, the Exec command in the .desktop file should match.) Is one method better than the other or does it acutally matter? -- GNU/Linux user #557453 "There are only 10 types of people in the world... those who understand Binary and those who don't." -Spike From rgaddi at highlandtechnology.invalid Tue Nov 12 13:25:57 2019 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Tue, 12 Nov 2019 10:25:57 -0800 Subject: Launching a Script on the Linux Platform In-Reply-To: References: Message-ID: On 11/12/19 10:06 AM, Wildman wrote: > What is the best approach for launching a Python GUI program > on a Linux platform. The program will be distributed in .deb > format. So the .deb will contain a menu file as well as a > .desktop file. The post install script will update the system > menu. > > My question is how should the program be executed? Here are > two choices for the "command=" entry in the menu file... > > command="/path/to/program.py" > > In this case the hash-bang would have to be included in the > program script... #!/usr/bin/env python3 > > The other choice is this... > > command="python3 /path/to/program.py" > > (Of course, the Exec command in the .desktop file should match.) > > Is one method better than the other or does it acutally matter? > I will note that without the shebang (and setting the execute bit), the program is only executable from the GUI menu, not the command prompt. I personally start even GUI programs far more often from a prompt. To follow Linux conventions you'd put the shebang, make the file executable, and put the executable somewhere on the PATH. I'd stick to those conventions barring a particular reason not to. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From rhodri at kynesim.co.uk Tue Nov 12 13:39:38 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 12 Nov 2019 18:39:38 +0000 Subject: Launching a Script on the Linux Platform In-Reply-To: References: Message-ID: On 12/11/2019 18:25, Rob Gaddi wrote: > On 11/12/19 10:06 AM, Wildman wrote: >> What is the best approach for launching a Python GUI program >> on a Linux platform.? The program will be distributed in .deb >> format.? So the .deb will contain a menu file as well as a >> .desktop file.? The post install script will update the system >> menu. >> >> My question is how should the program be executed?? Here are >> two choices for the "command=" entry in the menu file... >> >> command="/path/to/program.py" >> >> In this case the hash-bang would have to be included in the >> program script... #!/usr/bin/env python3 >> >> The other choice is this... >> >> command="python3 /path/to/program.py" >> >> (Of course, the Exec command in the .desktop file should match.) >> >> Is one method better than the other or does it acutally matter? >> > > I will note that without the shebang (and setting the execute bit), the > program is only executable from the GUI menu, not the command prompt.? I > personally start even GUI programs far more often from a prompt. > > To follow Linux conventions you'd put the shebang, make the file > executable, and put the executable somewhere on the PATH.? I'd stick to > those conventions barring a particular reason not to. Wildman is talking about launching his program from a menu, so putting it on the PATH is unnecessary. It may even be a bad idea, depending on exactly what he's done :-) As to the original question, there shouldn't really be much of a difference. The original idea of the shebang line invoking env, as far I recall, was that you'd get the "proper" system python3 wherever it had been put rather than something random and possibly malicious. I guess that means to go for your first option. -- Rhodri James *-* Kynesim Ltd From originallmoney at gmail.com Tue Nov 12 14:32:23 2019 From: originallmoney at gmail.com (originallmoney at gmail.com) Date: Tue, 12 Nov 2019 11:32:23 -0800 (PST) Subject: Trouble trying to get started with pygame In-Reply-To: References: <412bf414-19a5-4937-90fd-3363cb78614b@googlegroups.com> <9313ee4c-7250-4c8f-804b-f468a0dd3c5a@googlegroups.com> <8fe30991-0ad2-632f-bb37-fc9881b8835f@mrabarnett.plus.com> <6798ae9c-8823-4dbb-ae16-06257e49d06a@googlegroups.com> <3717e429-b1c3-8f6f-8dd3-50f89d2a21cc@mrabarnett.plus.com> <019fedd8-8c8e-453e-84aa-39dfa77d28c5@googlegroups.com> <207693a2-67ce-4fb1-4375-8933dd50a89b@mrabarnett.plus.com> Message-ID: I'm curious: I've been seeing people having multiple pygame programs open at once (Where each one is a component of a main program, obviously). If I'm making a larger game, do I NEED to do that? I'm assuming I'd need a Visual Studio extension for Python in order to do that. From best_lay at yahoo.com Tue Nov 12 15:24:25 2019 From: best_lay at yahoo.com (Wildman) Date: Tue, 12 Nov 2019 14:24:25 -0600 Subject: Launching a Script on the Linux Platform References: Message-ID: On Tue, 12 Nov 2019 18:39:38 +0000, Rhodri James wrote: > On 12/11/2019 18:25, Rob Gaddi wrote: >> On 11/12/19 10:06 AM, Wildman wrote: >>> What is the best approach for launching a Python GUI program >>> on a Linux platform.? The program will be distributed in .deb >>> format.? So the .deb will contain a menu file as well as a >>> .desktop file.? The post install script will update the system >>> menu. >>> >>> My question is how should the program be executed?? Here are >>> two choices for the "command=" entry in the menu file... >>> >>> command="/path/to/program.py" >>> >>> In this case the hash-bang would have to be included in the >>> program script... #!/usr/bin/env python3 >>> >>> The other choice is this... >>> >>> command="python3 /path/to/program.py" >>> >>> (Of course, the Exec command in the .desktop file should match.) >>> >>> Is one method better than the other or does it acutally matter? >>> >> >> I will note that without the shebang (and setting the execute bit), the >> program is only executable from the GUI menu, not the command prompt.? I >> personally start even GUI programs far more often from a prompt. >> >> To follow Linux conventions you'd put the shebang, make the file >> executable, and put the executable somewhere on the PATH.? I'd stick to >> those conventions barring a particular reason not to. > > Wildman is talking about launching his program from a menu, so putting > it on the PATH is unnecessary. It may even be a bad idea, depending on > exactly what he's done :-) Yes, that is correct. My program would be installed using a deb package manager such as apt and an entry placed in the desktop menu to launch the program. Thank you for the reply Rob. > As to the original question, there shouldn't really be much of a > difference. The original idea of the shebang line invoking env, as far > I recall, was that you'd get the "proper" system python3 wherever it had > been put rather than something random and possibly malicious. I guess > that means to go for your first option. Shebang! Yea, that is the correct term. All I could think of was hashbang. I knew that wasn't quite right. Yes, I prefer to envoke env in the shebang line instead of depending on the path. Paths can change especially in a multi-user system but env will always know where to find the executable. Thank you for your input. Shebang is the logical answer with all else being equal. -- GNU/Linux user #557453 "Setting a good example is a far better way to spread ideals than through force of arms." -Ron Paul From PythonList at danceswithmice.info Tue Nov 12 16:36:29 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Wed, 13 Nov 2019 10:36:29 +1300 Subject: Hi there! We are here to answer any questions you have about Udacit... In-Reply-To: References: <9feebd73533a47dc1605998e06da50b527b66f0c@intercom> <48349afd-e344-2289-c60f-aae530d80f77@DancesWithMice.info> Message-ID: <4673dc96-ae2a-ad50-944d-001f15b40f63@DancesWithMice.info> On 12/11/19 9:48 PM, joseph pareti wrote: > great, thank you so much for the advice. In fact, I sent this mail to > the python mailing list by mistake, but now I am glad I did ... There's plenty of over-lap between lists - PyTutor is another. Meantime I've received email from IBM about their ML/AI video series, which may also interest you. Today/tomorrow they are offering a web-cast: An Introduction to Visual Recognition. https://developer.ibm.com/events/an-introduction-to-visual-recognition-11-13-2019/ This invitation came from one of their email subscriptions to which you could also subscribe. Undoubtedly their bias is towards "Watson". Some activities enable free access to a Watson cloud... -- Regards =dn From tjreedy at udel.edu Tue Nov 12 18:58:58 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Nov 2019 18:58:58 -0500 Subject: Funny behavior of IDLE 3.7.0 In-Reply-To: References: <3.8-20191111194144@ram.dialup.fu-berlin.de> Message-ID: On 11/12/2019 12:00 PM, Chris Angelico wrote: > On Wed, Nov 13, 2019 at 3:57 AM Terry Reedy wrote: >> >> On 11/12/2019 8:29 AM, Chris Angelico wrote: >> >>> The OP said that the equals sign in the *first* line was flagged as >>> invalid syntax. Implication being that the error is being reported on >>> the line "i = 4", not on the print at the end. And in fact, I can >>> confirm this. Run | Check Module reports an error where i is assigned >>> to. Here's how it looks in command-line Python: >>> >>> $ python3.7 demo.py >>> File "", line 1 >>> (i=) >>> ^ >>> SyntaxError: invalid syntax >>> >>> Newer Pythons are happy with this example, but if you replace the >>> error with something else - say, f'{i+}' - then the same phenomenon >>> occurs. Command-line Python reports the error on line 1 of >>> "", and Idle misinterprets that as line 1 of the original >>> file. >>> >>> This looks like an error reporting flaw in f-string handling. >> >> Can you open a bug issue (if not one already) and nosy me? >> This is awful for any IDE that processes error messages. >> >> Replacing {} with () is a secondary bug. The actual code >> {i=} >> would be clearer, and make it easier for an IDE to search for the real line. >> > > I can do that, but I actually think the correct fix isn't inside Idle. Right. I meant a bug report against core Python. If the real bug is not fixed, I might do a workaround for IDLE, but I would prefer not. > See the followup regarding the difference between SyntaxError and > NameError; in the latter case, the error is more usefully reported. > > ChrisA > -- Terry Jan Reedy From tjreedy at udel.edu Tue Nov 12 19:01:09 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Nov 2019 19:01:09 -0500 Subject: Trouble trying to get started with pygame In-Reply-To: References: <8fe30991-0ad2-632f-bb37-fc9881b8835f@mrabarnett.plus.com> <6798ae9c-8823-4dbb-ae16-06257e49d06a@googlegroups.com> <3717e429-b1c3-8f6f-8dd3-50f89d2a21cc@mrabarnett.plus.com> <019fedd8-8c8e-453e-84aa-39dfa77d28c5@googlegroups.com> <207693a2-67ce-4fb1-4375-8933dd50a89b@mrabarnett.plus.com> Message-ID: On 11/12/2019 2:32 PM, originallmoney at gmail.com wrote: > I'm curious: I've been seeing people having multiple pygame programs open at once (Where each one is a component of a main program, obviously). Multiple programs open at once on modern machines is normal. Do you mean multiple windows for one program? As is possible with IDLE? -- Terry Jan Reedy From rosuav at gmail.com Tue Nov 12 19:14:27 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Nov 2019 11:14:27 +1100 Subject: Funny behavior of IDLE 3.7.0 In-Reply-To: References: <3.8-20191111194144@ram.dialup.fu-berlin.de> Message-ID: On Wed, Nov 13, 2019 at 11:00 AM Terry Reedy wrote: > > On 11/12/2019 12:00 PM, Chris Angelico wrote: > > On Wed, Nov 13, 2019 at 3:57 AM Terry Reedy wrote: > >> > >> On 11/12/2019 8:29 AM, Chris Angelico wrote: > >> > >>> The OP said that the equals sign in the *first* line was flagged as > >>> invalid syntax. Implication being that the error is being reported on > >>> the line "i = 4", not on the print at the end. And in fact, I can > >>> confirm this. Run | Check Module reports an error where i is assigned > >>> to. Here's how it looks in command-line Python: > >>> > >>> $ python3.7 demo.py > >>> File "", line 1 > >>> (i=) > >>> ^ > >>> SyntaxError: invalid syntax > >>> > >>> Newer Pythons are happy with this example, but if you replace the > >>> error with something else - say, f'{i+}' - then the same phenomenon > >>> occurs. Command-line Python reports the error on line 1 of > >>> "", and Idle misinterprets that as line 1 of the original > >>> file. > >>> > >>> This looks like an error reporting flaw in f-string handling. > >> > >> Can you open a bug issue (if not one already) and nosy me? > >> This is awful for any IDE that processes error messages. > >> > >> Replacing {} with () is a secondary bug. The actual code > >> {i=} > >> would be clearer, and make it easier for an IDE to search for the real line. > >> > > > > I can do that, but I actually think the correct fix isn't inside Idle. > > Right. I meant a bug report against core Python. > > If the real bug is not fixed, I might do a workaround for IDLE, but I > would prefer not. > Gotcha! Turns out there is actually an open bug: https://bugs.python.org/issue34364 But it cites a GitHub PR that has been merged already: https://github.com/python/cpython/pull/10021 So I'm not sure what status actually is, since the current master branch still has the problem. ChrisA From PythonList at DancesWithMice.info Tue Nov 12 21:16:55 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 13 Nov 2019 15:16:55 +1300 Subject: Friday finking: TDD and EAFP In-Reply-To: <20191103204437.GB3944@hjp.at> References: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> <74263897-D40B-4EAD-957E-C1FF43A26F6F@gmail.com> <2500afa5-84ae-e5fc-a73c-4091681068e6@DancesWithMice.info> <20191103204437.GB3944@hjp.at> Message-ID: <72492bd0-5789-b87d-2cb6-8f7c4ae19f20@DancesWithMice.info> Apologies for lateness - stuff happened... On 4/11/19 9:44 AM, Peter J. Holzer wrote: > On 2019-11-04 07:41:32 +1300, DL Neil via Python-list wrote: >> On 3/11/19 6:30 AM, Bev In TX wrote: >>>> On Nov 1, 2019, at 12:40 AM, DL Neil via Python-list >>>> > wrote: >>>> >>>> Is the practice of TDD fundamentally, if not philosophically, >>>> somewhat contrary to Python's EAFP approach? >> Agreed: (in theory) TDD is independent of language or style. However, I'm >> wondering if (in practice) it creates a mode of thinking that pushes one >> into an EAFP way of thinking? > > This is exactly the opposite of what you proposed in your first mail, > and I think it is closer to the truth: It is a while ago, and I cannot honesty remember if I was attempting to provoke discussion/debate/illustration by switching things around, or if I simply confused the abbreviations. > TDD does in my opinion encourage EAFP thinking. > > The TDD is usually: > > 1 Write a test > 2 Write the minimal amount of code that makes the test pass > 3 If you think you have covered the whole spec, stop, else repeat > from 1 > > This is often (e.g. in [1]) exaggerated for pedagogic and humoristic > reasons. For example, your first test for a sqrt function might be > assert(sqrt(4) == 2) > and then of course the minimal implementation is > def sqrt(x): > return 2 I have seen this sort of thing in spreadsheet training - someone pulling-out a calculator, summing a column of numbers, and typing 'the answer' in the "Total" cell (instead of using the Sigma button or @SUM() ). However, I've never seen anyone attempt to pass-off this sort of code outside of desperate (and likely, far too late) floundering during a 101 assignment - FAILED! Who would begin to believe that such code implements sqrt, or that it meets with the function's objectives as laid-out in the spec AND the docstring? So, anyone can prove anything - if they leave reality/reason far-enough behind. Unfortunately the phrase "test pass" (as above) can be misused?abused in this way; but nowhere in your or my descriptions of TDD did *we* feel it necessary to point-out that the/any/every test should be true to the spec. It's unnecessary. Great joke, but its proponents are delaying a proper consideration of TDD. Perhaps they are hiding behind something? > Which just means that we don't have enough test cases yet. But the point > is that a test suite can only check a finite (and usually rather small) > number of cases, while most interesting programs accept a very large (if > not really infinite) number of inputs, so the test suite will always be > incomplete. At some point you will have to decide thet the test suite is > good enough and ship the code - and hope that the customer will forgive > you if you have (inevitably) forgotten an important case. Which highlights a difference between the description (above) and the approach I described: I tend to write 'all' the tests first - which, now that I type it, really does sound LBYL! Why? Because testing is what we might call a diagnostic mode of thinking - what is happening here and why? Well, nothing is actually happening in terms of the application's code; but I'm trying to think-ahead and imagine the cases where things might not go according to plan. Later, I shift to (what?) code-authoring/creative mode (yes, someone's going to point-out the apparent dichotomy in these words - please go-ahead) and 'bend the computer to my will'. It is the tests which (hopefully) prove the success or otherwise of my output. I'm not coding to the test(s) - sometimes I deliberately take a meal-break or overnight-break between writing tests and writing code. Why not follow 'the letter of the law'? Because it seems to me that they require different ways of looking (at the same problem). My fear of doing them one-at-a-time is that I'll conclude (too early) exactly as you say - that's enough testing, 'it works'! Returning to my possible re-interpretation/misuse of the TDD paradigm: I'm only officially 'testing' one test at a time, but if 'this iteration of the code' passes two or more of the next tests in the series, well... ("oh what a good boy am I"!) In practice, I'll review this iteration's test and its motivation(s) to ensure that the code hasn't passed 'by accident' (or should that be, by "bi-product"). Now, reviewing the: write one (useful/meaningful) test, then write the code until it passes (this and all previous tests), then re-factor (tests and application code), rinse-and-repeat. The question is: might the 'diagnostic' mode of thought 'infect' the 'creative' and thereby encourage writing more "defensive code" than is EAFP/pythonic? > There is very little emphasis in TDD on verifying that the code is > correct - only that it passes the tests. Relationship of both to spec, discussed above. Agreed, that the spec must be held in the mind(s) of the test and code writer(s)! Also agreed that code has an asymptotic relationship with "100% tested". I don't think any (serious) testing paradigm claims omniscience. The question will always be 'what is enough?'. On the other hand, the number of tests written/tested is no guide or guarantee, either. Some parts of programming are "science" but some really are "art"! > hp Hah, the same initials as Harry:- > [1] Harry J.W. Percival, Test-Driven Development with Python, O'Reilly, > 2017 I've lost track of our friendly 'testing goat' since we both 'moved-on'. You are right, I should take another look at the book (in fact, IIRC there's been a 'new' edition). Thanks! -- Regards =dn From PythonList at danceswithmice.info Tue Nov 12 21:23:38 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Wed, 13 Nov 2019 15:23:38 +1300 Subject: Friday finking: TDD and EAFP In-Reply-To: <435DBBAC-4B69-4C81-AE9B-866B7AA8CF17@barrys-emacs.org> References: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> <435DBBAC-4B69-4C81-AE9B-866B7AA8CF17@barrys-emacs.org> Message-ID: <569fdf93-50f5-2734-99f3-f7a5ff5a8783@DancesWithMice.info> On 6/11/19 8:01 AM, Barry Scott wrote: >> On 1 Nov 2019, at 05:40, DL Neil via Python-list wrote: >> >> Is the practice of TDD fundamentally, if not philosophically, somewhat contrary to Python's EAFP approach? >> The practice of TDD* is that one writes test routines to prove a unit of code, eg method or function; BEFORE actually writing said function. >> The rationale is that TDD encourages proper identification and consideration of the routine's specification, and attempts to ensure that exceptions and "edge-cases" are not quietly forgotten. >> (in a broad-brush, nut-shell) > > The practice of creating software is a social activity where those involved > have foibles. Managing all the social interactions and foibles is what > the methodologies are trying to help with. Any methodology that is easier > to follow then avoid will tend to be taken up and provide a benefit. > > We all know that tests are a must have, but often those tests that we all > know are a must have do not get written. It can often seem like a chore, > after all the code works right? > > By starting with the tests the social engineering means that you make having > the tests the easy part of the process. > > Methodologies like Agile address other foibles. Given a far off dead line > the tendency is to delay getting the bulk of the work done until at the last > moment. > > So is TDD contrary to EAFP? Not as such its two sorts of social engineering. > TDD helps get the tests, EAPF give permission to take risks, necessary to > innovate. +1 -- Regards =dn From address at not.available Wed Nov 13 09:02:53 2019 From: address at not.available (R.Wieser) Date: Wed, 13 Nov 2019 15:02:53 +0100 Subject: How to delay until a next increment of time occurs ? Message-ID: Hello all, I'm writing some code to toggle a pin on a Raspberry Pi, and would like to have that happen at (multiples of) 300 uSec increments. I tried time.sleep(), but that one disregards the time after the last one ends and the new one is started. In other words, all the time spend in code (or being interrupted by another thread!) between the end of the previous and the start of the current sleep throws the whole repetitive timing off. So, I'm looking for a method that will allow me to wait for a "last time plus increment". Is there one with the properties of sleep() (not just burning processor cycles way, blocking all threads), but referencing a previous time. Regards, Rudy Wieser From skip.montanaro at gmail.com Wed Nov 13 09:25:21 2019 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 13 Nov 2019 08:25:21 -0600 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: Message-ID: > So, I'm looking for a method that will allow me to wait for a "last time > plus increment". Is there one with the properties of sleep() (not just > burning processor cycles way, blocking all threads), but referencing a > previous time. Take a look at threading.Timer. Skip From address at not.available Wed Nov 13 11:11:44 2019 From: address at not.available (R.Wieser) Date: Wed, 13 Nov 2019 17:11:44 +0100 Subject: How to delay until a next increment of time occurs ? References: Message-ID: Skip, > Take a look at threading.Timer. Thanks. It seems to solve the problem by calling it at the start of the executed code (instead of the end), but costs thread usage ... Regards, Rudy Wieser From David.Raymond at tomtom.com Wed Nov 13 11:31:48 2019 From: David.Raymond at tomtom.com (David Raymond) Date: Wed, 13 Nov 2019 16:31:48 +0000 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: Message-ID: Maybe something along the lines of this? timeInterval = 0.0003 time.sleep(timeInterval - (time.perf_counter() % timeInterval)) -----Original Message----- From: Python-list On Behalf Of R.Wieser Sent: Wednesday, November 13, 2019 11:12 AM To: python-list at python.org Subject: Re: How to delay until a next increment of time occurs ? Skip, > Take a look at threading.Timer. Thanks. It seems to solve the problem by calling it at the start of the executed code (instead of the end), but costs thread usage ... Regards, Rudy Wieser -- https://mail.python.org/mailman/listinfo/python-list From address at not.available Wed Nov 13 13:00:25 2019 From: address at not.available (R.Wieser) Date: Wed, 13 Nov 2019 19:00:25 +0100 Subject: How to delay until a next increment of time occurs ? References: Message-ID: David, > timeInterval = 0.0003 > time.sleep(timeInterval - (time.perf_counter() % timeInterval)) Possibly: any reason for the performance counter modulo the interval ? Regards, Rudy Wieser From address at not.available Wed Nov 13 13:21:11 2019 From: address at not.available (R.Wieser) Date: Wed, 13 Nov 2019 19:21:11 +0100 Subject: How to delay until a next increment of time occurs ? References: Message-ID: Dennis, > So... you need to adjust for the time spent in processing between > calls to sleep(). That was my first thought too, but any code calculating that adjustment before ultimatily calling sleep itself can also be interrupted. With that in mind I was aiming/hoping for something with a /very/ short path between the calculation and executing the sleep (as in: none at all, done by the system itself). > The creep could be mitigated some by having the handler's first > action being to start the next timer instance, and then doing "stuff". Yup. But the cost of using that command is generating threads - which some search results warned against (not sure why though). The best solution I can think of would be a build-in (hardware?) timer which would generate "ticks" until its stopped. Regards, Rudy Wieser From rgaddi at highlandtechnology.invalid Wed Nov 13 13:30:14 2019 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Wed, 13 Nov 2019 10:30:14 -0800 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: Message-ID: On 11/13/19 6:02 AM, R.Wieser wrote: > Hello all, > > I'm writing some code to toggle a pin on a Raspberry Pi, and would like to > have that happen at (multiples of) 300 uSec increments. > > I tried time.sleep(), but that one disregards the time after the last one > ends and the new one is started. In other words, all the time spend in code > (or being interrupted by another thread!) between the end of the previous > and the start of the current sleep throws the whole repetitive timing off. > > So, I'm looking for a method that will allow me to wait for a "last time > plus increment". Is there one with the properties of sleep() (not just > burning processor cycles way, blocking all threads), but referencing a > previous time. > > Regards, > Rudy Wieser > > 300us is getting on towards realtime. Depending on how rigorous you need to be, Python may not be the right tool for the job; I've never tried it that fast. That said, I'll throw out a different option than the threading based ones people have suggested. Trap SIGALRM with signal.signal and use signal.setitimer to create an interval timer. I can't tell you offhand that signals will give you better realtime performance than threads or vice versa. There's also async in the mix, which I still have no idea how to use. But this way if you strike out on one approach you've got some others to consider. Also, does the rPi have any PWM or counter pins that you can just set and forget, rather than trying to keep it going yourself? -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From maillist at schwertberger.de Wed Nov 13 13:41:27 2019 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Wed, 13 Nov 2019 19:41:27 +0100 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: Message-ID: On 13.11.2019 19:21, R.Wieser wrote: > Yup. But the cost of using that command is generating threads - which > some > search results warned against (not sure why though). I'm currently looking for a way to have short breaks (in the range of 10us to some ms) on Windows and time.sleep() always seems to be too long, probably due to thread switching. From looking at the source code, it could behave better with Linux, but anyway such solutions will always create a lot of Jitter. > The best solution I can think of would be a build-in (hardware?) timer which > would generate "ticks" until its stopped. Actually, with such requirements you're usually better off with a microcontroller. These have timers and interrupts available. Maybe the PyBoard with Micropython is the right tool for you. I'm using it for some measurement and control applications and it's really great. Regards, Dietmar From David.Raymond at tomtom.com Wed Nov 13 14:06:34 2019 From: David.Raymond at tomtom.com (David Raymond) Date: Wed, 13 Nov 2019 19:06:34 +0000 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: Message-ID: I just used .perf_counter() as it's "a clock with the highest available resolution to measure a short duration" The general simplified idea was run it whenever the time is 0 modulo your interval. So you ask how long until that next time. Run whenever the time is 0 modulo .0003 Current time is 33.0143379 So I'm 0.0002379 into the cycle (33.0143379 % .0003) And I've got .0000621 to sleep until the next mark (.0003 - .0002379) -----Original Message----- From: Python-list On Behalf Of R.Wieser Sent: Wednesday, November 13, 2019 1:00 PM To: python-list at python.org Subject: Re: How to delay until a next increment of time occurs ? David, > timeInterval = 0.0003 > time.sleep(timeInterval - (time.perf_counter() % timeInterval)) Possibly: any reason for the performance counter modulo the interval ? Regards, Rudy Wieser -- https://mail.python.org/mailman/listinfo/python-list From luciano at ramalho.org Wed Nov 13 14:22:40 2019 From: luciano at ramalho.org (Luciano Ramalho) Date: Wed, 13 Nov 2019 16:22:40 -0300 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: Message-ID: Mr. Wieser, I haven't seen you mention which library you're using to write to GPIO with Python. I know of two options: 1) RPi.GPIO: https://sourceforge.net/projects/raspberry-gpio-python/ -- the more popular option 2) WiringPy: https://github.com/WiringPi/WiringPi-Python -- an alternative with better performance See (7 year old) benchmarks here: https://codeandlife.com/2012/07/03/benchmarking-raspberry-pi-gpio-speed/ WiringPy has it's own delay function, which may have better performance than using any Python alternative. See an example here: https://github.com/WiringPi/WiringPi-Python/blob/master/examples/softpwm.py RPi.GPIO has dedicated PWM functions, which may or may not solve your problem. See docs here: https://sourceforge.net/p/raspberry-gpio-python/wiki/PWM/ Cheers, Luciano On Wed, Nov 13, 2019 at 3:27 PM R.Wieser
wrote: > > Dennis, > > > So... you need to adjust for the time spent in processing between > > calls to sleep(). > > That was my first thought too, but any code calculating that adjustment > before ultimatily calling sleep itself can also be interrupted. With that > in mind I was aiming/hoping for something with a /very/ short path between > the calculation and executing the sleep (as in: none at all, done by the > system itself). > > > The creep could be mitigated some by having the handler's first > > action being to start the next timer instance, and then doing "stuff". > > Yup. But the cost of using that command is generating threads - which some > search results warned against (not sure why though). > > The best solution I can think of would be a build-in (hardware?) timer which > would generate "ticks" until its stopped. > > Regards, > Rudy Wieser > > > -- > https://mail.python.org/mailman/listinfo/python-list -- Luciano Ramalho | Author of Fluent Python (O'Reilly, 2015) | http://shop.oreilly.com/product/0636920032519.do | Technical Principal at ThoughtWorks | Twitter: @ramalhoorg From address at not.available Wed Nov 13 15:20:46 2019 From: address at not.available (R.Wieser) Date: Wed, 13 Nov 2019 21:20:46 +0100 Subject: How to delay until a next increment of time occurs ? References: Message-ID: Rob, > 300us is getting on towards realtime. Not really. Translated to a frequency (toggeling the pin) it would be just 1.6 KHz. Thats rather slow for an ARM machine running on 1.4 Ghz (about a million times as fast). > I've never tried it that fast. I've already got it running it using the standard sleep() command, but I would like to make the used delay value independant of the Pi board it runs on (had to tweak it when I went from a C++ program on a 3B to a python program on a 3B+). And possibly get a bit more stability of the output signal. > That said, I'll throw out a different option than the threading based ones > people have suggested. Trap SIGALRM with signal.signal and use > signal.setitimer to create an interval timer. (googeling it) Yup, looks like I have to try that out. Thanks. And that automaticaly repeating signal is pretty-much the best solution I can think of. > Also, does the rPi have any PWM or counter pins that you can just set and > forget, rather than trying to keep it going yourself? Not possible: the 300 uSec is the basic timing, but the pin isn't always changed on every tick of it (the result is a code train). Regards, Rudy Wieser From address at not.available Wed Nov 13 15:30:42 2019 From: address at not.available (R.Wieser) Date: Wed, 13 Nov 2019 21:30:42 +0100 Subject: How to delay until a next increment of time occurs ? References: Message-ID: David, > The general simplified idea was run it whenever the time is 0 modulo > your interval. So you ask how long until that next time. Ah, using the perf_counter() as its own reference (no "last time fired" storage needed). Thanks for the explanation. Regards, Rudy Wieser From address at not.available Wed Nov 13 16:20:14 2019 From: address at not.available (R.Wieser) Date: Wed, 13 Nov 2019 22:20:14 +0100 Subject: How to delay until a next increment of time occurs ? References: Message-ID: Dietmar, > Actually, with such requirements you're usually better off with a > microcontroller. Probably, yes. /Anything/ is better than a multi process mini 'puter for tasks like these. Doesn't mean I'm not going to try though. But honestly, generating a "modulated" 1.6 KHz square-wave signal on a 1.4 GHz ARM processor is going towards the limits of what it can do ? Cricky ... > Maybe the PyBoard with Micropython is the right tool for you. Currently I just want to know how the Pi and Python on it handles itself. But thanks for the suggestion nonetheless. Regards, Rudy Wieser From tjreedy at udel.edu Wed Nov 13 16:25:21 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Nov 2019 16:25:21 -0500 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: Message-ID: On 11/13/2019 9:02 AM, R.Wieser wrote: > I'm writing some code to toggle a pin on a Raspberry Pi, and would like to > have that happen at (multiples of) 300 uSec increments. If you were looking at increments of multiple milleseconds, such as 1/60 == 16.6..., I would suggest using tkinter's root.after, with a minimum non-zero delay of 1 millesecond. I believe one can do better with async as its default loop runs a bit faster and there is a C-coded replacement available, which should be faster yet. It has delay-until(time) as well as delay-for(interval). -- Terry Jan Reedy From address at not.available Wed Nov 13 16:33:01 2019 From: address at not.available (R.Wieser) Date: Wed, 13 Nov 2019 22:33:01 +0100 Subject: How to delay until a next increment of time occurs ? References: Message-ID: Luciano, > Mr. Wieser, I haven't seen you mention which library you're using > to write to GPIO with Python. To be honest, I took a "blink.py" example as a base, and just went with it. So, I had to look it up. Its the first one you mentioned, RPi.GPIO. Thanks for telling me about WiringPi's better performance. I like having multiple options available, and most likely try them al out. > RPi.GPIO has dedicated PWM functions, which may or may not solve > your problem. Probably not, as the clock signal is only used to keep the software-controlled pin-switching synchronised. Regards, Rudy Wieser From maillist at schwertberger.de Wed Nov 13 17:36:45 2019 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Wed, 13 Nov 2019 23:36:45 +0100 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: Message-ID: <5423bc5d-3ba9-01cc-85e8-c3a0d00cb33d@schwertberger.de> On 13.11.2019 23:20, Dennis Lee Bieber wrote: > For Windows it may require coding a busy-wait sleep function using the > high-performance counter and computing a counter value (modulo?) on which > to exit the loop. time.perf_counter() is using this on Windows. I'm just worried about floating point limitations on older Python versions. From Python 3.7 onwards, there's time.perf_counter_ns(), but even then it would be nice if it was just possible to reset the perf_counter. Regards, Dietmar From jsf80238 at gmail.com Wed Nov 13 19:19:17 2019 From: jsf80238 at gmail.com (Jason Friedman) Date: Wed, 13 Nov 2019 17:19:17 -0700 Subject: Logistic Regression Define X and Y for Prediction In-Reply-To: References: Message-ID: > > > When I define the X and Y values for prediction in the train and test > data, should I capture all the columns that has been "OneHotEncoded" (that > is all columns with 0 and 1) for the X and Y values??? > You might have better luck asking on Stackoverflow, per the Pandas instructions: https://pandas.pydata.org/community.html. From maillist at schwertberger.de Wed Nov 13 16:26:25 2019 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Wed, 13 Nov 2019 22:26:25 +0100 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: Message-ID: <83afdf83-f859-df42-05c3-11cdc2e14832@schwertberger.de> On 13.11.2019 21:20, R.Wieser wrote: >> 300us is getting on towards realtime. > Not really. Translated to a frequency (toggeling the pin) it would be just > 1.6 KHz. Thats rather slow for an ARM machine running on 1.4 Ghz (about a > million times as fast). It *is* real-time... Real-time is not about speed, but about guaranteed timing. > Not possible: the 300 uSec is the basic timing, but the pin isn't always > changed on every tick of it (the result is a code train). With Micropython I did successfully use timer and DMA to accomplish something like that (in the 100ns range, though). With a mainloop and delays you can't guarantee to meet your requirements, at least not on a multitasking non-realtime system. Regards, Dietmar From dave at cinege.com Wed Nov 13 20:43:38 2019 From: dave at cinege.com (Dave Cinege) Date: Wed, 13 Nov 2019 20:43:38 -0500 Subject: ANNOUNCE: Thesaurus and ThesaurusCfg - recursive mapping and cfg file data types Message-ID: <56450e1e-73ae-141e-8fd4-210ea4a6186c@cinege.com> This announcement is for a pre-release that I would like people to comment on structure, naming, etc. (Code review maybe not yet. :-) Before you say "It's all been done before." I suggest you take a closer look and I think you may conclude that what I've revised over 7 years is now interesting. --- Thesaurus is a mapping data type with key recursion and attribute aliasing. It is a subclass of dict() and compatible as a dictionary replacement baring where key path recursion may take place. ThesaurusExtended is a subclass of Thesaurus providing additional usability methods. ThesaurusCfg is a subclass of ThesaurusExtended providing a configuration file parser and per key data coercion methods. The Thesaurus family works with Python 2.6+ to 3.8+. A simple example of ThesaurusCfg -- cfgs = ''' prog.version(static_int) = 123 opt.verbose (str_to_bool) = yes hi = Hello ''' from thesauruscfg import thescfg cfg = thescfg() >>> cfg.parse(cfgs) {'prog': {'version': 123}, 'opt': {'verbose': True}, 'hi': 'Hello'} >>> cfg.opt.verbose True import json >>> print(json.dumps(cfg, indent=4, separators=(',', ': '))) { "prog": { "version": 123 }, "opt": { "verbose": true }, "hi": "Hello" } browse: https://git.cinege.com/thesaurus/ or git clone https://git.cinege.com/thesaurus/ --- Dave From address at not.available Thu Nov 14 03:31:34 2019 From: address at not.available (R.Wieser) Date: Thu, 14 Nov 2019 09:31:34 +0100 Subject: How to delay until a next increment of time occurs ? References: <83afdf83-f859-df42-05c3-11cdc2e14832@schwertberger.de> Message-ID: Dietmar, > It *is* real-time... > Real-time is not about speed, but about guaranteed timing. What I tried to indicate is that the Pi has 500,000 cycles to work with between two of those time events. I consider that to be quite a few. > at least not on a multitasking non-realtime system. Yep, that's ofcourse the killer in this game. Regards, Rudy Wieser From address at not.available Thu Nov 14 03:44:58 2019 From: address at not.available (R.Wieser) Date: Thu, 14 Nov 2019 09:44:58 +0100 Subject: How to delay until a next increment of time occurs ? References: Message-ID: Dennis, > Avoiding drift still comes down to computing the time (in some unit) > at which the interval is to expire, and then delaying for the difference > between that time and current time. Yep. And although that can be done with Python, I had hoped to be able to shift all that to lower-level function to forgo the possibility that the calculation itself gets interrupted by task switching. In short, I was looking for a possibly existing command that would solve this (imaginary?) problem, before trying to implementing it in Python itself. Regards, Rudy Wieser From address at not.available Thu Nov 14 04:00:05 2019 From: address at not.available (R.Wieser) Date: Thu, 14 Nov 2019 10:00:05 +0100 Subject: How to delay until a next increment of time occurs ? References: Message-ID: Dennis, > Let's see if I can remember how to use my BK Precision > 2542 scope... :-) You didn't have to do that. I was already planning to put my TDS 210 (tektronics) scope to work today, if only to see what the effect of drift-compensated sleeps would be (inserting some print commands here and there, maybe doing a search and/or grep at the same time too) > O'scope screen grabs at: The connection times out ... Though that could be an effect of me using FF 52 (on XPsp3), which seems to lack the newest encryption standards. > I had to use the max() function in the sleep() call as it was > periodically failing with a negative sleep value, It does ? I was already thinking about that problem (some task might run longer that the delta), but imagined the sleep would than just return directly. Oh well. Regards, Rudy Wieser From address at not.available Thu Nov 14 04:13:05 2019 From: address at not.available (R.Wieser) Date: Thu, 14 Nov 2019 10:13:05 +0100 Subject: How to delay until a next increment of time occurs ? References: <0p6pse9jbdr4l8tpf25c8n4auk80ndanmd@4ax.com> Message-ID: Dennis, > You know... I never finished my thought there... :-) I already got the feeling I missed something there. > ... 1.6kHz appears to just be viable (there may still be a context > switch but it wasn't visible on my o'scope) Thats ... slow. And a limitation I definitily have to remember. Than again, its Python, not Cpp or alike. Too bad that the Pi has no free hardware that can be abused for stuff like this (like a serial port in synchronous mode). Regards, Rudy Wieser From address at not.available Thu Nov 14 08:06:47 2019 From: address at not.available (R.Wieser) Date: Thu, 14 Nov 2019 14:06:47 +0100 Subject: nonlocal fails ? Message-ID: Hello all, I've just tried to use a "nonlocal MyVar" statement in a procedure defenition, but it throws an error saying "Syntax error: no binding for nonlocal 'MyVar' found. According to platform.python_version() I'm running version 3.8.3 Why am I getting that error ? (already googeled ofcourse) Testcode: - - - - - - - - - - - - Def Proc1() nonlocal MyVar MyVar = 5 MyVar = 7 Proc1() print(MyVar) - - - - - - - - - - - - I've also tried moving "MyVar = 7" to the first line, but that doesn't change anything. Using "global MyVar" works.. Regards, Rudy Wieser From lists at mostrom.pp.se Thu Nov 14 08:21:45 2019 From: lists at mostrom.pp.se (Jan Erik =?utf-8?q?Mostr=C3=B6m?=) Date: Thu, 14 Nov 2019 14:21:45 +0100 Subject: nonlocal fails ? In-Reply-To: References: Message-ID: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> On 14 Nov 2019, at 14:06, R.Wieser wrote: > I've also tried moving "MyVar = 7" to the first line, but that doesn't > change anything. Using "global MyVar" works.. Try def outer(): MyVar = 10 def Proc1(): nonlocal MyVar MyVar = 5 Proc1() MyVar = 7 outer() print(MyVar) From the documentation The nonlocal statement causes the listed identifiers to refer to previously bound variables in the nearest ******enclosing scope excluding globals******. This is important because the default behavior for binding is to search the local namespace first. The statement allows encapsulated code to rebind variables outside of the local scope besides the global (module) scope. Names listed in a nonlocal statement, unlike those listed in a global statement, must refer to pre-existing bindings in an enclosing scope (the scope in which a new binding should be created cannot be determined unambiguously). Names listed in a nonlocal statement must not collide with pre-existing bindings in the local scope. From python at mrabarnett.plus.com Thu Nov 14 08:44:30 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Nov 2019 13:44:30 +0000 Subject: nonlocal fails ? In-Reply-To: References: Message-ID: <27b0ea06-7e7f-1e3e-4ef8-80e12c8721d3@mrabarnett.plus.com> On 2019-11-14 13:06, R.Wieser wrote: > Hello all, > > I've just tried to use a "nonlocal MyVar" statement in a procedure > defenition, but it throws an error saying "Syntax error: no binding for > nonlocal 'MyVar' found. > > According to platform.python_version() I'm running version 3.8.3 > > Why am I getting that error ? (already googeled ofcourse) > > Testcode: > - - - - - - - - - - - - > Def Proc1() > nonlocal MyVar > MyVar = 5 > > MyVar = 7 > Proc1() > print(MyVar) > - - - - - - - - - - - - > I've also tried moving "MyVar = 7" to the first line, but that doesn't > change anything. Using "global MyVar" works.. > In section 7.13 of the Help it says: """The nonlocal statement causes the listed identifiers to refer to previously bound variables in the nearest enclosing scope excluding globals.""" 'nonlocal' is used where the function is nested in another function and you want to be able to bind to the variables in the enclosing function. In your code, there's no enclosing function. Instead, you want to be able to bind to the module's global variables. For that, you should use 'global' instead. def Proc1(): global MyVar MyVar = 5 MyVar = 7 Proc1() print(MyVar) From rhodri at kynesim.co.uk Thu Nov 14 08:24:26 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 14 Nov 2019 13:24:26 +0000 Subject: nonlocal fails ? In-Reply-To: References: Message-ID: On 14/11/2019 13:06, R.Wieser wrote: > Hello all, > > I've just tried to use a "nonlocal MyVar" statement in a procedure > defenition, but it throws an error saying "Syntax error: no binding for > nonlocal 'MyVar' found. > > According to platform.python_version() I'm running version 3.8.3 > > Why am I getting that error ? (already googeled ofcourse) > > Testcode: > - - - - - - - - - - - - > Def Proc1() > nonlocal MyVar > MyVar = 5 > > MyVar = 7 > Proc1() > print(MyVar) > - - - - - - - - - - - - > I've also tried moving "MyVar = 7" to the first line, but that doesn't > change anything. Using "global MyVar" works.. The Language Reference says (https://docs.python.org/3/reference/simple_stmts.html#the-nonlocal-statement): "The nonlocal statement causes the listed identifiers to refer to previously bound variables in the nearest enclosing scope *excluding globals.*" (my emphasis.) MyVar is a global here, so nonlocal explicitly doesn't pick it up. -- Rhodri James *-* Kynesim Ltd From address at not.available Thu Nov 14 09:15:14 2019 From: address at not.available (R.Wieser) Date: Thu, 14 Nov 2019 15:15:14 +0100 Subject: nonlocal fails ? References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> Message-ID: Jan, > The nonlocal statement causes the listed identifiers to refer to > previously bound variables in the nearest ******enclosing scope excluding > globals******. I read that too, but didn't get from it that the main scope is excluded (I assumed the"excluding globals" was ment at as such declared variables) . Thanks the clarification. Too bad though, it means that procedures that want to share/use its callers variables using nonlocal can never be called from main. And that a caller of a procedure using nonlocal cannot have the variable declared as global (just tested it). Regards, Rudy Wieser From lists at mostrom.pp.se Thu Nov 14 09:58:26 2019 From: lists at mostrom.pp.se (Jan Erik =?utf-8?q?Mostr=C3=B6m?=) Date: Thu, 14 Nov 2019 15:58:26 +0100 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> Message-ID: On 14 Nov 2019, at 15:15, R.Wieser wrote: > Too bad though, it means that procedures that want to share/use its > callers > variables using nonlocal can never be called from main. And that a > caller > of a procedure using nonlocal cannot have the variable declared as > global > (just tested it). So what you want to do is dynamic scope? https://www.geeksforgeeks.org/static-and-dynamic-scoping/ = jem From jamtlu at gmail.com Thu Nov 14 10:24:25 2019 From: jamtlu at gmail.com (James Lu) Date: Thu, 14 Nov 2019 10:24:25 -0500 Subject: A more Message-ID: Where do I go to find a more complete specification for Python? I want to learn about common semi-internal language features used by popular libraries, because I am reimplementing Python. The reference guide says: > While I am trying to be as precise as possible, I chose to use English > rather than formal specifications for everything except syntax and lexical > analysis. This should make the document more understandable to the average > reader, but will leave room for ambiguities. *Consequently, if you were > coming from Mars and tried to re-implement Python from this document alone, > you might have to guess things and in fact you would probably end up > implementing quite a different language. * > So I would like some additional help. From dave at cinege.com Wed Nov 13 21:42:46 2019 From: dave at cinege.com (Dave Cinege) Date: Wed, 13 Nov 2019 21:42:46 -0500 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: Message-ID: <97c573af-e6cb-e33b-82af-e19e12e84784@cinege.com> Can you expand on what you are trying to accomplish with this? It seems a small C program or library you interface python too is a better solution. With that said, as others mentioned you might need a real time OS or micro controller if this needs to be dead on timing. Dave On 2019/11/13 09:02, R.Wieser wrote: > Hello all, > > I'm writing some code to toggle a pin on a Raspberry Pi, and would like to > have that happen at (multiples of) 300 uSec increments. > > I tried time.sleep(), but that one disregards the time after the last one > ends and the new one is started. In other words, all the time spend in code > (or being interrupted by another thread!) between the end of the previous > and the start of the current sleep throws the whole repetitive timing off. > > So, I'm looking for a method that will allow me to wait for a "last time > plus increment". Is there one with the properties of sleep() (not just > burning processor cycles way, blocking all threads), but referencing a > previous time. > > Regards, > Rudy Wieser > > From ianoda at hotmail.com Thu Nov 14 10:37:19 2019 From: ianoda at hotmail.com (Mike C) Date: Thu, 14 Nov 2019 15:37:19 +0000 Subject: Logistic Regression Define X and Y for Prediction In-Reply-To: References: , Message-ID: Hi Jason, I will try it out... Nothing in the documentation tells a person. Thanks ________________________________ From: Python-list on behalf of Jason Friedman Sent: Wednesday, November 13, 2019 7:19 PM Cc: python-list at python.org Subject: Re: Logistic Regression Define X and Y for Prediction > > > When I define the X and Y values for prediction in the train and test > data, should I capture all the columns that has been "OneHotEncoded" (that > is all columns with 0 and 1) for the X and Y values??? > You might have better luck asking on Stackoverflow, per the Pandas instructions: https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpandas.pydata.org%2Fcommunity.html&data=02%7C01%7C%7Ce4fa0935f3b0443c3b0f08d768988e72%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637092876737703023&sdata=%2BO6zx05Szg3TeGdtusSaLU1GhXKp7PEL7beHpqg1hcQ%3D&reserved=0. -- https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-list&data=02%7C01%7C%7Ce4fa0935f3b0443c3b0f08d768988e72%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637092876737703023&sdata=tDAC3St0kqFfN3rLqBBg9cTsykel5Hhj6MUjzFxZc7I%3D&reserved=0 From torriem at gmail.com Thu Nov 14 10:54:28 2019 From: torriem at gmail.com (Michael Torrie) Date: Thu, 14 Nov 2019 08:54:28 -0700 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> Message-ID: On 11/14/19 7:15 AM, R.Wieser wrote: > Too bad though, it means that procedures that want to share/use its callers > variables using nonlocal can never be called from main. And that a caller > of a procedure using nonlocal cannot have the variable declared as global > (just tested it). nonlocal does not share or use its *caller's* variables. Rather it reaches into the scope of the outer function where it was defined. That's a very different concept than what you're proposing. I know of no sane way that a function could work with the scope of any arbitrary caller. Remember that even inner functions can be returned and called from anywhere, even other functions or modules. What would happen if the caller's scope didn't have any names that the function was looking for? What are you trying to accomplish? From address at not.available Thu Nov 14 12:11:36 2019 From: address at not.available (R.Wieser) Date: Thu, 14 Nov 2019 18:11:36 +0100 Subject: nonlocal fails ? References: Message-ID: Rhodri, > MyVar is a global here, so nonlocal explicitly doesn't pick it up. I do not agree with you there (the variable being global). If it where than I would have been able to alter the variable inside the procedure without having to resort to a "global" override (an override which is only valid for the context its used in by the way, not anywhere else) Than again, that is how it works in a few other languages, so I might have been poisonned by them. :-) Regards, Rudy Wieser From address at not.available Thu Nov 14 12:14:36 2019 From: address at not.available (R.Wieser) Date: Thu, 14 Nov 2019 18:14:36 +0100 Subject: nonlocal fails ? References: <27b0ea06-7e7f-1e3e-4ef8-80e12c8721d3@mrabarnett.plus.com> Message-ID: MRAB, > 'nonlocal' is used where the function is nested in another function The problem is that that was not clear to me from the description - nor is it logical to me why it exludes the main context from its use. Regards, Rudy Wieser From rgaddi at highlandtechnology.invalid Thu Nov 14 12:21:57 2019 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Thu, 14 Nov 2019 09:21:57 -0800 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: <83afdf83-f859-df42-05c3-11cdc2e14832@schwertberger.de> Message-ID: On 11/13/19 1:26 PM, Dietmar Schwertberger wrote: > On 13.11.2019 21:20, R.Wieser wrote: >>> 300us is getting on towards realtime. >> Not really.? Translated to a frequency (toggeling the pin) it would be just >> 1.6 KHz.?? Thats rather slow for an ARM machine running on 1.4 Ghz (about a >> million times as fast). > > It *is* real-time... > Real-time is not about speed, but about guaranteed timing. > Yeah, that's always the conversation, but at the end of the day "realtime" is always a question of "by how much". Do you really need to be hard periodic with 0 ns slop in either direction? Can you afford to come in early but not late? By 10%? By 1%? By .01%? If you can afford 1% and you need a 1 second interval, you're only asking for 10 ms and in practice even a giant preemptive non-RT OS like Linux can do it for you. If you can only afford 1% on a 300 us interval then your lack of rigid control over what happens on your processor is a real problem and you're better off bare metal on a dedicated $2 Cortex-M than with random timeslices of the 1.4GHz beast on the rPi. Is what I was shorthanding with "realtime". -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From richard.damon at gmail.com Thu Nov 14 12:40:40 2019 From: richard.damon at gmail.com (Richard Damon) Date: Thu, 14 Nov 2019 12:40:40 -0500 Subject: nonlocal fails ? Message-ID: <432F4E9A-D2AB-4BEC-B9CE-D5533FB25AE9@gmail.com> ?On Nov 14, 2019, at 12:18 PM, R.Wieser
wrote: > > ?Rhodri, > >> MyVar is a global here, so nonlocal explicitly doesn't pick it up. > > I do not agree with you there (the variable being global). If it where than > I would have been able to alter the variable inside the procedure without > having to resort to a "global" override (an override which is only valid for > the context its used in by the way, not anywhere else) > > Than again, that is how it works in a few other languages, so I might have > been poisonned by them. :-) > > Regards, > Rudy Wieser Assuming that one language works like another is a danger. It really pays to learn the base concepts of a language if you are going to be using it. First, Python doesn?t really have ?Variables? like a lot of other languages (they don?t hold a bag of bytes), as Python names don?t hold values, but are just references to objects which actually hold the value (this can be important when several names all reference the same object, that means that if you mutate the object through one name they all see the change) Also, for name lookup, the Python Compiler looks to see if the name is bound to an object (via assignment, etc) in the function, if so the name is by default local, (changeable by using a global or non local statement). If the name is never bound to something, then the name will be also looked for in the global namespace. Yes, this is different than many other languages. From address at not.available Thu Nov 14 12:46:29 2019 From: address at not.available (R.Wieser) Date: Thu, 14 Nov 2019 18:46:29 +0100 Subject: nonlocal fails ? References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> Message-ID: Jan, > So what you want to do is dynamic scope? No, not really. I was looking for method to let one procedure share a variable with its caller - or callers, selectable by me. And as a "by reference" argument does not seem to exist in Python ... And yes, I am a ware that procedures can return multiple results. I just didn'want to go that way (using the same variable twice in a single calling). Regards, Rudy Wieser From Richard at Damon-family.org Thu Nov 14 12:53:35 2019 From: Richard at Damon-family.org (Richard Damon) Date: Thu, 14 Nov 2019 12:53:35 -0500 Subject: nonlocal fails ? In-Reply-To: References: Message-ID: <817471B0-5F89-4341-8C36-F61056B33BFC@Damon-family.org> > > On Nov 14, 2019, at 12:20 PM, R.Wieser
wrote: > > ?MRAB, > >> 'nonlocal' is used where the function is nested in another function > > The problem is that that was not clear to me from the description - nor is > it logical to me why it exludes the main context from its use. > > Regards, > Rudy Wieser Module ?main? content is already available via ?global?, nonlocal was likely added later to get to enclosing function scope, which isn?t global, nor is it local. From address at not.available Thu Nov 14 12:57:24 2019 From: address at not.available (R.Wieser) Date: Thu, 14 Nov 2019 18:57:24 +0100 Subject: nonlocal fails ? References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> Message-ID: Michael, > nonlocal does not share or use its *caller's* variables. Rather it > reaches into the scope of the outer function where it was defined. > That's a very different concept than what you're proposing. Oh blimy! You're right. Its an at compile-time thing, not a runtime one. Thanks for the heads-up. > I know of no sane way that a function could work with the scope of > any arbitrary caller. The trick seems to be to emulate a "by reference" call, by using a mutable object as the argument and stuff the value inside of it (IIRC a tuple with a single element). > What would happen if the caller's scope didn't have any > names that the function was looking for? Handle it the same as any other mistake, and throw an error ? Regards, Rudy Wieser From tjreedy at udel.edu Thu Nov 14 13:14:14 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Nov 2019 13:14:14 -0500 Subject: A more In-Reply-To: References: Message-ID: On 11/14/2019 10:24 AM, James Lu wrote: > Where do I go to find a more complete specification for Python? The Cpython code, the tests, and its actual behavior. > I want to > learn about common semi-internal language features used by popular > libraries, because I am reimplementing Python. > > The reference guide says: > >> While I am trying to be as precise as possible, I chose to use English >> rather than formal specifications for everything except syntax and lexical >> analysis. This should make the document more understandable to the average >> reader, but will leave room for ambiguities. *Consequently, if you were >> coming from Mars and tried to re-implement Python from this document alone, >> you might have to guess things and in fact you would probably end up >> implementing quite a different language. * I suspect that this is less true than when Guido wrote it. There have been other implementations since, and the implementers have occasionally asked questions that resulted in the docs being clarified. -- Terry Jan Reedy From rhodri at kynesim.co.uk Thu Nov 14 13:28:52 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 14 Nov 2019 18:28:52 +0000 Subject: nonlocal fails ? In-Reply-To: References: Message-ID: <5f72d842-71a7-0a8c-fbf6-372080245d75@kynesim.co.uk> On 14/11/2019 17:11, R.Wieser wrote: > Rhodri, > >> MyVar is a global here, so nonlocal explicitly doesn't pick it up. > I do not agree with you there (the variable being global). If it where than > I would have been able to alter the variable inside the procedure without > having to resort to a "global" override (an override which is only valid for > the context its used in by the way, not anywhere else) > > Than again, that is how it works in a few other languages, so I might have > been poisonned by them.:-) You have been. # This is at the top level of a module # I.e. it's a global variable my_global_variable = 5 # You can read globals from within a function without declaring them def show_my_global(): print(my_global_variable) # If you try setting it, you get a local instead def fudge_my_global(n): my_global_variable = n show_my_global() # prints '5' fudge_my_global(2) show_my_global() # prints '5' # If you read the variable before setting it, you get an exception def mess_up_my_global(n): print(my_global_variable) my_global_variable = n mess_up_my_global(2) # UnboundLocalError! # ...because it must be a local because of the assignment, but it # doesn't have a value at the time print() is called. # To do it right, declare you want the global from the get go def love_my_global(n): global my_global_variable print("It was ", my_global_variable) my_global_variable = n love_my_global(3) # prints 'It was 5' show_my_global() # prints '3' -- Rhodri James *-* Kynesim Ltd From Richard at Damon-family.org Thu Nov 14 13:37:40 2019 From: Richard at Damon-family.org (Richard Damon) Date: Thu, 14 Nov 2019 13:37:40 -0500 Subject: nonlocal fails ? In-Reply-To: References: Message-ID: <1613CC0E-83B1-40B9-8F72-98BA34E75F9C@Damon-family.org> > On Nov 14, 2019, at 12:56 PM, R.Wieser
wrote: > > ?Jan, > >> So what you want to do is dynamic scope? > > No, not really. I was looking for method to let one procedure share a > variable with its caller - or callers, selectable by me. And as a "by > reference" argument does not seem to exist in Python ... > > And yes, I am a ware that procedures can return multiple results. I just > didn'want to go that way (using the same variable twice in a single > calling). > > Regards, > Rudy Wieser Watch out about thinking about ?Variables? because Python doesn?t really have them. In one sense EVERYTHING in Python is by reference, as names are just references bound to objects. If you are pass a mutable object to a function, and the function uses the parameter that was bound to the object to mutate the object, that same object referenced in the caller has changed. (Note that strings, number, and tupples are not mutable, but lists, dictionaries and most class objects are). The key is that the function should use assignment to the parameter name to try and change the object, but use mutating methods on the object to change it. Thus if the caller creates a list and binds it to a name, and passes that to the function, then the function can manipulate the list (things like parm[0] = 5) and that change will be see by the caller. The function just needs to be careful not to do a parm = statement that would rebind the name and thus lose the reference to the callers object. From address at not.available Thu Nov 14 13:43:42 2019 From: address at not.available (R.Wieser) Date: Thu, 14 Nov 2019 19:43:42 +0100 Subject: nonlocal fails ? References: <432F4E9A-D2AB-4BEC-B9CE-D5533FB25AE9@gmail.com> Message-ID: Richard, > Assuming that one language works like another is a danger Abitrarily redefining words and using misnomers is another ... ("global" and "nonlocal" respecivily if you wonder) > First, Python doesn't really have 'Variables' like a lot of other > languages > (they don't hold a bag of bytes), as Python names don't hold values, but > are just references to objects which actually hold the value That's a principle as old as programming languages itself I believe. > If the name is never bound to something, then the name will be also looked > for in the global namespace. Can you give an example of that ? I currently cannot wrap my head around what you could be meaning there - anything I can imagine simply doesn't make any sense ... Regards, Rudy Wieser From rosuav at gmail.com Thu Nov 14 13:53:50 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Nov 2019 05:53:50 +1100 Subject: nonlocal fails ? In-Reply-To: References: <432F4E9A-D2AB-4BEC-B9CE-D5533FB25AE9@gmail.com> Message-ID: On Fri, Nov 15, 2019 at 5:46 AM R.Wieser
wrote: > > Richard, > > > Assuming that one language works like another is a danger > > Abitrarily redefining words and using misnomers is another ... ("global" > and "nonlocal" respecivily if you wonder) Every language that has a concept of "global" still has some sort of limitation on it. If you look up that word in a dictionary, it won't say "within the currently-running program" or anything. Yet, we programmers are quite happy for global variables in one program to be isolated from another - in fact, I think you'd be seriously disconcerted if that were NOT the case. Is that "arbitrarily redefining" the word global? > > First, Python doesn't really have 'Variables' like a lot of other > > languages > > (they don't hold a bag of bytes), as Python names don't hold values, but > > are just references to objects which actually hold the value > > That's a principle as old as programming languages itself I believe. True, and it's also largely irrelevant here, so let's move on. > > If the name is never bound to something, then the name will be also looked > > for in the global namespace. > > Can you give an example of that ? I currently cannot wrap my head around > what you could be meaning there - anything I can imagine simply doesn't make > any sense ... > def foo(): x = 1 print("x is", x) Inside this function, you have one local name (x), and one name reference that isn't local (print). When the function looks for print, it looks in the globals, and then in the built-ins. ChrisA From gheskett at shentel.net Thu Nov 14 13:47:14 2019 From: gheskett at shentel.net (Gene Heskett) Date: Thu, 14 Nov 2019 13:47:14 -0500 Subject: How to delay until a next increment of time occurs ? In-Reply-To: <3d4rsedrb4r45mggmg7b0ra0u5ug3ukaul@4ax.com> References: <3d4rsedrb4r45mggmg7b0ra0u5ug3ukaul@4ax.com> Message-ID: <201911141347.14338.gheskett@shentel.net> On Thursday 14 November 2019 13:05:06 Dennis Lee Bieber wrote: > On Thu, 14 Nov 2019 09:31:34 +0100, "R.Wieser"
> > declaimed the following: > >What I tried to indicate is that the Pi has 500,000 cycles to work > > with between two of those time events. I consider that to be quite > > a few. > > But the ARM instruction set is not a 1:1 with clock cycles. Loading > the program counter (in effect, jumps and subroutine calls) takes 5 > cycles on an older ARM 9 core. ARM apparently no longer provides > instruction cycle data for processors (and suggests one should use > performance counters to profile sections of code). > > And then one needs to take into account that Python is a byte-code > interpreted language, wherein an instruction may invoke whole > subroutines of native code. > > The R-Pi has never, to my knowledge, been billed as suitable for > industrial/real-time/process-control... It was billed as a device for > learning -- using Python and simple digital GPIO. The newer ones are > getting closer to serving as a general desktop computer. > Gee I hate to burst your bubble Dennis, but I am currently running a cnc'd, 70 yo, 1500 lb, Sheldon 11x54 lathe with a 2GB rpi4. And if it wasn't for the cost of changing the interfaces, I am considering replacing all my intel stuff running 3 more such machines, with rpi4's. The pi's all use an spi interface running at several tens of megabites a second, where the wintels are using some variation of the old parport at about 5 mb/sec. I think its called progress. But at 85 the grim reaper has come calling twice, and blinked twice. I'll get a new aortic valve in December, which should lengthen my visit here, but who knows for sure? > > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com http://wlfraed.microdiversity.freeddns.org/ Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page From tjreedy at udel.edu Thu Nov 14 14:01:01 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Nov 2019 14:01:01 -0500 Subject: nonlocal fails ? In-Reply-To: <817471B0-5F89-4341-8C36-F61056B33BFC@Damon-family.org> References: <817471B0-5F89-4341-8C36-F61056B33BFC@Damon-family.org> Message-ID: On 11/14/2019 12:53 PM, Richard Damon wrote: >> >> On Nov 14, 2019, at 12:20 PM, R.Wieser
wrote: >> >> ?MRAB, >> >>> 'nonlocal' is used where the function is nested in another function >> >> The problem is that that was not clear to me from the description - nor is >> it logical to me why it exludes the main context from its use. >> >> Regards, >> Rudy Wieser > > Module ?main? content is already available via ?global?, nonlocal was likely added later to get to enclosing function scope, which isn?t global, nor is it local. Correct, and the addition was in two stages. At first, automatically *accessing* non-locals was added. Note that no declaration is needed, just as no declaration is needed to access globals. >>> >>> f(3) 3 The 'nonlocal' keyward to *rebind* nonlocals, analogous to the 'global' keyword to rebind module globals, was added later, for 3.0, after considerable bikeshedding on the new keyword. The access mechanism is quite different. Function f accesses globals through f.__globals__, which points to the global dict. In CPython, at least, it accesses nonlocals through f.__closure__, a tuple of 'cells'. >>> def f(a): b = 'b outer' def g(): nonlocal b print(a, b) b = 'b inner' print(a, b) print(g.__closure__) g() >>> f(0) (, ) 0 b outer 0 b inner >>> print(f.__closure__) None Closures are used in functional programs, instead of classes, to create 'groups' of functions than share 'group' variables. -- Terry Jan Reedy From Karsten.Hilbert at gmx.net Thu Nov 14 14:22:52 2019 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Thu, 14 Nov 2019 20:22:52 +0100 Subject: py2 vs py3: zlib.adler32/crc32 In-Reply-To: <5f72d842-71a7-0a8c-fbf6-372080245d75@kynesim.co.uk> References: <5f72d842-71a7-0a8c-fbf6-372080245d75@kynesim.co.uk> Message-ID: Hi all, I am unsure how to solve: I use adler32/crc32 to generate integer values from data for setting up an advisory lock in PostgreSQL. The PG function pg_try_advisory_lock() https://www.postgresql.org/docs/12/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS takes two PG ints which are defined as: integer 4 bytes typical choice for integer -2147483648 to +2147483647 Now, in Py > 2.5 zlib.adler32/crc32 will return suitable integers. However, in Py3 the return range has been changed to The return value is unsigned and in the range [0, 2**32-1] regardless of platform. which will overflow the PostgreSQL function. Is there a way to convert/modify/shift the py3 value such that it shows the same representation as the py2 value ? What I am looking for is: v2 = py2.zlib.adler32(data) v3 = some_magic(py3.zlib.adler32(data)) if v2 == v3: print('same') I am sure there's something obvious with struct/<, ... Message-ID: Greetings, Using this code to read mail. I'm printing to file only mails sent by some people. For some mails i get the body as the below instead of actual text: [, ] instead of the actual mail body. Here is the code: # # import imaplib import email import time my_senders = ['you at x.com ', 'you at y.com', 'you at z.com'] my_mail_count = 1 open('data.txt', 'w+') def read_email_from_gmail(): global my_mail_count, my_senders mail = imaplib.IMAP4_SSL('imap.gmail.com') mail.login('mymail at gmail.com','password') mail.select('inbox') result, data = mail.search(None, 'ALL') mail_ids = data[0] id_list = mail_ids.split() first_email_id = int(id_list[0]) latest_email_id = int(id_list[-1]) for i in range(latest_email_id,first_email_id, -1): #pypi # need str(i) result, data = mail.fetch(str(i), '(RFC822)' ) for response_part in data: if isinstance(response_part, tuple): # from_bytes, not from_string msg = email.message_from_bytes(response_part[1]) email_subject = msg['subject'] email_from = msg['from'] print ('{} {}'.format(my_mail_count, email_subject)) print(' {}'.format(email_from)) my_mail_count += 1 #email_body = msg.get_payload(decode=True) for m in my_senders: if m in email_from: if msg.is_multipart(): for part in msg.get_payload(): print(msg.get_payload(), file=open('data.txt', 'a')) if isinstance(msg.get_payload(), list): print(dir(msg.get_payload()[0])) else: print(msg.get_payload(), file=open('data.txt', 'a')) if isinstance(msg.get_payload(), list): print(dir(msg.get_payload()[0])) read_email_from_gmail() # # Any idea? Yours, Abdur-Rahmaan Janhangeer pythonmembers.club | github Mauritius From address at not.available Thu Nov 14 15:00:59 2019 From: address at not.available (R.Wieser) Date: Thu, 14 Nov 2019 21:00:59 +0100 Subject: How to delay until a next increment of time occurs ? References: <97c573af-e6cb-e33b-82af-e19e12e84784@cinege.com> Message-ID: Dave, > Can you expand on what you are trying to accomplish with this? There is a small 433 MHz rf transmitter connected to the pin, and when I send the right pattern a wireless wall-wart will respond and switch a lamp on or off. Its just ment as an example of a real-world application of Python, nothing serious. Ofcourse, by doing so I'm learning about how to use python (and the Pi) myself too. :-) > It seems a small C program or library you interface python too is a better > solution. :-) I already wrote that program in C{something} (I'm not sure what my Pi offers by default) a while ago, but "ported" it to python. For the above mentioned "example" reason. ... Which is also why I didn't even try to just shell to that program, or try to interface with a C{something} library. Though doing such interfacing is in the pipeline (I've already found-and-stored some documentation about it). Regards, Rudy Wieser From torriem at gmail.com Thu Nov 14 15:17:53 2019 From: torriem at gmail.com (Michael Torrie) Date: Thu, 14 Nov 2019 13:17:53 -0700 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> Message-ID: <314545d2-2d42-18ed-6173-f6bf523cb6bd@gmail.com> On 11/14/19 10:57 AM, R.Wieser wrote: >> I know of no sane way that a function could work with the scope of >> any arbitrary caller. > > The trick seems to be to emulate a "by reference" call, by using a mutable > object as the argument and stuff the value inside of it (IIRC a tuple with a > single element). Right. You could pass in a dict as an argument. You could even pass in the caller's locals() dictionary. I'm not sure I recommend the latter approach, however. > Handle it the same as any other mistake, and throw an error ? Sure. I'm coming more and more around to some of the ideas of functional programming. Doing as you suggest, reaching back to the caller's variables, sounds extremely messy to me. And very fragile, hard to test, and doesn't lend itself to easily extended functionality by chaining(think unix-style piping). I find Python's ability to return tuples virtually eliminates any need I have to "pass by reference." I'm coming around to the idea that wherever possible, functions should have no side effects. Those things that need side effects should be isolated so they are easy to maintain. I believe they call this "push side effects to the edges." From torriem at gmail.com Thu Nov 14 15:22:06 2019 From: torriem at gmail.com (Michael Torrie) Date: Thu, 14 Nov 2019 13:22:06 -0700 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> Message-ID: <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> On 11/14/19 10:57 AM, R.Wieser wrote: > The trick seems to be to emulate a "by reference" call, by using a mutable > object as the argument and stuff the value inside of it (IIRC a tuple with a > single element). I note that you didn't answer the question, what are you trying to accomplish? In other words, what problem are you trying to solve. It looks to me like you're trying to write a program in a different language here, not Python. Although come to that I can't think of very many reasons to do what you propose in any language. If you mentioned what problem you are trying to solve, I'm sure folks can suggest cleaner, more idiomatic ways of doing it in Python. From rosuav at gmail.com Thu Nov 14 15:27:20 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Nov 2019 07:27:20 +1100 Subject: nonlocal fails ? In-Reply-To: <314545d2-2d42-18ed-6173-f6bf523cb6bd@gmail.com> References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <314545d2-2d42-18ed-6173-f6bf523cb6bd@gmail.com> Message-ID: On Fri, Nov 15, 2019 at 7:19 AM Michael Torrie wrote: > > On 11/14/19 10:57 AM, R.Wieser wrote: > >> I know of no sane way that a function could work with the scope of > >> any arbitrary caller. > > > > The trick seems to be to emulate a "by reference" call, by using a mutable > > object as the argument and stuff the value inside of it (IIRC a tuple with a > > single element). > > Right. You could pass in a dict as an argument. You could even pass in > the caller's locals() dictionary. I'm not sure I recommend the latter > approach, however. The locals() dict isn't guaranteed to be mutable. At the moment, there are very very few actual language guarantees regarding changes to locals(), but there's currently a WIP to define things a little more tightly: https://www.python.org/dev/peps/pep-0558/ Neither in the current wording nor in the proposed wording is any sort of promise that you could pass locals() to another function and have it usefully modify that. > I'm coming more and more around to some of the ideas of functional > programming. Doing as you suggest, reaching back to the caller's > variables, sounds extremely messy to me. And very fragile, hard to > test, and doesn't lend itself to easily extended functionality by > chaining(think unix-style piping). > > I find Python's ability to return tuples virtually eliminates any need I > have to "pass by reference." Agreed. Or Python's ability to return strings. Most of the pass-by-reference that I do in languages like SourcePawn is just to get around the problem that strings aren't first-class values. > I'm coming around to the idea that wherever possible, functions should > have no side effects. Those things that need side effects should be > isolated so they are easy to maintain. I believe they call this "push > side effects to the edges." Something like that. Ideally, a function should be pure - having no side effects, being unaffected by external state, and having a return value determined entirely by its arguments. Not every function can be pure, of course (for instance, print() is most certainly NOT a pure function), but the more of your functions that are pure, and the purer your other functions are, the easier it is to reason about your code and refactor things. ChrisA From address at not.available Thu Nov 14 15:25:39 2019 From: address at not.available (R.Wieser) Date: Thu, 14 Nov 2019 21:25:39 +0100 Subject: How to delay until a next increment of time occurs ? References: <5quqsep867ca775s10tah1jq1mktqu70mh@4ax.com> Message-ID: Dennis, > Ugh -- let's try Google Drive... I was able to download them, thanks. All but the 100uSec one seemed to be rather stable. > That is what I'd thought, but if you've looked at that simple program I > used, apparently the "run longer" was taking place between the > > t += > > and the > > t - time.time() I don't think so, as that "t +=" is relative and depends on the end time of the last sleep - just as it should I might say. And that means that that "run longer" can have been taking place anywhere between the end of the last sleep and the "t - time.time()" in the new one. By the way, on my scope the "wrap around" time seemed to be quite long, in the neighborhood of 80 uSec Alas, the drift-compensated sleep did not seem to make the output any more dependable - though I hope it means that I do not need to re-tweak the delay when running on another Pi than my current one (a 3B+). Regards, Rudy Wieser From address at not.available Thu Nov 14 15:34:04 2019 From: address at not.available (R.Wieser) Date: Thu, 14 Nov 2019 21:34:04 +0100 Subject: How to delay until a next increment of time occurs ? References: <83afdf83-f859-df42-05c3-11cdc2e14832@schwertberger.de> <3d4rsedrb4r45mggmg7b0ra0u5ug3ukaul@4ax.com> Message-ID: Dennis, > The R-Pi has never, to my knowledge, been billed as suitable > for industrial/real-time/process-control... I have not read those specs to be honest. But for some reason I assumed that a 1.4 GHz machine should easily be able to generate a 1.6 KHz signal, even using Python. I was wrong. It can, but just barily and not without jitter and hickups. Lesson learned. Regards, Rudy Wieser From dave at cinege.com Thu Nov 14 15:34:52 2019 From: dave at cinege.com (Dave Cinege) Date: Thu, 14 Nov 2019 15:34:52 -0500 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: <97c573af-e6cb-e33b-82af-e19e12e84784@cinege.com> Message-ID: <43798fb8-34e6-9930-c174-038f6ce35894@cinege.com> Rudy, OK I'm old enough cancer to know what X10 is. :-) I wouldn't think this is too difficult to do as you're only sending. For this application IMO there is too much going on inside python that can interrupt the cycle of modulation. (Intra and Extra python; garbage collection, other processes, etc) I would drop back to a simple program in C that you execute from python to do the actual sending putting your 'message' on the command line to that program (or use a tmpfile). I think your solution will be to execute this program from python. Let me stress, my advise is doing this *reliably*. In that regard you might need look at locking your C process to 1 CPU and giving it highest priority. (man nice) Once you have this working reliably, you could then look to convert it to a python c-module to more tightly integrate it. Dave On 2019/11/14 15:00, R.Wieser wrote: > Dave, > >> Can you expand on what you are trying to accomplish with this? > > There is a small 433 MHz rf transmitter connected to the pin, and when I > send the right pattern a wireless wall-wart will respond and switch a lamp > on or off. Its just ment as an example of a real-world application of > Python, nothing serious. > > Ofcourse, by doing so I'm learning about how to use python (and the Pi) > myself too. :-) > >> It seems a small C program or library you interface python too is a better >> solution. > > :-) I already wrote that program in C{something} (I'm not sure what my Pi > offers by default) a while ago, but "ported" it to python. For the above > mentioned "example" reason. > > ... Which is also why I didn't even try to just shell to that program, or > try to interface with a C{something} library. > > Though doing such interfacing is in the pipeline (I've already > found-and-stored some documentation about it). > > Regards, > Rudy Wieser > > From python at mrabarnett.plus.com Thu Nov 14 16:06:09 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Nov 2019 21:06:09 +0000 Subject: Reading mail getting [, ... In-Reply-To: References: Message-ID: On 2019-11-14 19:43, Abdur-Rahmaan Janhangeer wrote: > Greetings, > > Using this code to read mail. I'm printing to file only mails sent by some > people. For some mails i get the body as the below instead of actual text: > > [, object at 0x021ECB30>] > > instead of the actual mail body. > > Here is the code: > > # > # > import imaplib > import email > import time > > my_senders = ['you at x.com ', 'you at y.com', 'you at z.com'] > my_mail_count = 1 > open('data.txt', 'w+') > def read_email_from_gmail(): > global my_mail_count, my_senders > > mail = imaplib.IMAP4_SSL('imap.gmail.com') > mail.login('mymail at gmail.com','password') > mail.select('inbox') > > result, data = mail.search(None, 'ALL') > mail_ids = data[0] > > id_list = mail_ids.split() > first_email_id = int(id_list[0]) > latest_email_id = int(id_list[-1]) > > for i in range(latest_email_id,first_email_id, -1): > #pypi # need str(i) > result, data = mail.fetch(str(i), '(RFC822)' ) > > for response_part in data: > if isinstance(response_part, tuple): > # from_bytes, not from_string > msg = email.message_from_bytes(response_part[1]) > > email_subject = msg['subject'] > email_from = msg['from'] > print ('{} {}'.format(my_mail_count, email_subject)) > print(' {}'.format(email_from)) > my_mail_count += 1 > > #email_body = msg.get_payload(decode=True) > > for m in my_senders: > if m in email_from: > if msg.is_multipart(): > for part in msg.get_payload(): > print(msg.get_payload(), > file=open('data.txt', 'a')) > if isinstance(msg.get_payload(), list): > print(dir(msg.get_payload()[0])) > else: > print(msg.get_payload(), file=open('data.txt', > 'a')) > if isinstance(msg.get_payload(), list): > print(dir(msg.get_payload()[0])) > > read_email_from_gmail() > # > # > > Any idea? > The payload is sometimes split into parts that are encoded. Do something like this: from email.header import decode_header def decode_payload(header, default_encoding='utf-8'): parts = [] for data, encoding in decode_header(header): if isinstance(data, str): parts.append(data) else: parts.append(data.decode(encoding or default_encoding)) return ' '.join(parts) From python at mrabarnett.plus.com Thu Nov 14 16:11:37 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Nov 2019 21:11:37 +0000 Subject: py2 vs py3: zlib.adler32/crc32 In-Reply-To: References: <5f72d842-71a7-0a8c-fbf6-372080245d75@kynesim.co.uk> Message-ID: On 2019-11-14 19:22, Karsten Hilbert wrote: > Hi all, > > I am unsure how to solve: I use adler32/crc32 to generate integer values from data > for setting up an advisory lock in PostgreSQL. > > The PG function pg_try_advisory_lock() > > https://www.postgresql.org/docs/12/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS > > takes two PG ints which are defined as: > > integer 4 bytes typical choice for integer -2147483648 to +2147483647 > > Now, in Py > 2.5 zlib.adler32/crc32 will return suitable integers. > > However, in Py3 the return range has been changed to > > The return value is unsigned and in the range [0, 2**32-1] regardless of platform. > > which will overflow the PostgreSQL function. > > Is there a way to convert/modify/shift the py3 value such that it shows the > same representation as the py2 value ? What I am looking for is: > > v2 = py2.zlib.adler32(data) > v3 = some_magic(py3.zlib.adler32(data)) > if v2 == v3: > print('same') > > I am sure there's something obvious with struct/< such like which I am overlooking. > > Note that I can't simply do > > v2 = py2.zlib.adler32(data) & 0xffffffff > > because that can overflow the PostgreSQL integer. I think I need > the reverse, in a sense, but I am too dense, ATM. > Unsigned 32-bit to signed 32-bit: unsigned - (unsigned & 0x80000000) * 2 Signed 32-bit to unsigned 32-bit: signed & 0xFFFFFFFF From python at mrabarnett.plus.com Thu Nov 14 16:19:20 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Nov 2019 21:19:20 +0000 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: <97c573af-e6cb-e33b-82af-e19e12e84784@cinege.com> Message-ID: <4ce3bd41-bdb9-f30e-1108-c5fd7e25ad83@mrabarnett.plus.com> On 2019-11-14 20:00, R.Wieser wrote: > Dave, > >> Can you expand on what you are trying to accomplish with this? > > There is a small 433 MHz rf transmitter connected to the pin, and when I > send the right pattern a wireless wall-wart will respond and switch a lamp > on or off. Its just ment as an example of a real-world application of > Python, nothing serious. > > Ofcourse, by doing so I'm learning about how to use python (and the Pi) > myself too. :-) > >> It seems a small C program or library you interface python too is a better >> solution. > > :-) I already wrote that program in C{something} (I'm not sure what my Pi > offers by default) a while ago, but "ported" it to python. For the above > mentioned "example" reason. > > ... Which is also why I didn't even try to just shell to that program, or > try to interface with a C{something} library. > > Though doing such interfacing is in the pipeline (I've already > found-and-stored some documentation about it). > Not everything needs to be done in Python. You should use an extension for that kind of thing and then tell it what to do from Python. From address at not.available Thu Nov 14 16:16:13 2019 From: address at not.available (R.Wieser) Date: Thu, 14 Nov 2019 22:16:13 +0100 Subject: nonlocal fails ? References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> Message-ID: Michael, > I note that you didn't answer the question, what are you trying > to accomplish? I think I did - though implicitily. What do normal people use "by reference" arguments for ? Yep, that is what I wanted too. > It looks to me like you're trying to write a program in a different > language here, not Python. I'm trying to learn how Python works, and for that I (ofcourse) compare it to other languages. What-and-how it does something different (or equal!) in regard to them. >Although come to that I can't think of very many reasons to do > what you propose in any language. I made propositions to its functioning ? And I was thinking that I just pointed out oddities in it ... > If you mentioned what problem you are trying to solve 1) Have value 2) use value in procedure 1 3) use updated value in procedure 2 4) use again updated value in procedure 1, 2 or maybe 3 For the sake of learning I'm now going over all of the possibilities to see if and how they work. For that I've already excluded globals and the practice of feeding the value as an argument to the procedure and than store its result as the new one. I've also excluded using a class object and put the code in there, as well as faking a "by reference" passing by using a tuple. "nonlocal" looked to be another option, but it appears to be rather limited in its application. In short, the /ways to the goal/ are (currently) important to me, not the goal itself (I'm sure that apart from the "nonlocal" one all of the above are viable, and I thus can get /something/ to work) Yeah, I'm weird like that. Sorry. Regards, Rudy Wieser From rosuav at gmail.com Thu Nov 14 16:23:44 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Nov 2019 08:23:44 +1100 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> Message-ID: On Fri, Nov 15, 2019 at 8:21 AM R.Wieser
wrote: > > Michael, > > > I note that you didn't answer the question, what are you trying > > to accomplish? > > I think I did - though implicitily. What do normal people use "by > reference" arguments for ? Yep, that is what I wanted too. > That doesn't really answer the question. It's like you just bought a self-driving car and then ask people how you push the accelerator pedal. What are you trying to do? Well, what normal people use the accelerator pedal for! Only, that's irrelevant. The point of your new car isn't to push the pedal - it's to get you some place. Where are you trying to get to? ChrisA From rgaddi at highlandtechnology.invalid Thu Nov 14 16:22:01 2019 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Thu, 14 Nov 2019 13:22:01 -0800 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: <83afdf83-f859-df42-05c3-11cdc2e14832@schwertberger.de> <3d4rsedrb4r45mggmg7b0ra0u5ug3ukaul@4ax.com> Message-ID: On 11/14/19 12:34 PM, R.Wieser wrote: > Dennis, > >> The R-Pi has never, to my knowledge, been billed as suitable >> for industrial/real-time/process-control... > > I have not read those specs to be honest. But for some reason I assumed > that a 1.4 GHz machine should easily be able to generate a 1.6 KHz signal, > even using Python. I was wrong. It can, but just barily and not without > jitter and hickups. Lesson learned. > > Regards, > Rudy Wieser > The machine itself would be fine. But between Python and Linux (probably the bigger culprit), there are lots of things that aren't interested in your deterministicity. Just run it bare-metal; I'm sure that's straightforward on an rPi and has no gotchas or complications that would lead to days/weeks of frustration. On an actually practical note; ever since they started baking the quasi-realtime stuff into the Linux kernel, you've been able to use the whole sched_setscheduler(2) family of calls (from C) to set a process's real-time priority. That might get things good enough to do the job, though how one gets there from Python I couldn't tell you. Na?vely I'd say to just use ctypes to wrap those calls, but that's some low-level stuff to be getting into from a very high-level language. Might work? -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From tjreedy at udel.edu Thu Nov 14 18:22:35 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Nov 2019 18:22:35 -0500 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> Message-ID: On 11/14/2019 4:16 PM, R.Wieser wrote: >> If you mentioned what problem you are trying to solve > > 1) Have value > 2) use value in procedure 1 > 3) use updated value in procedure 2 > 4) use again updated value in procedure 1, 2 or maybe 3 > For the sake of learning I'm now going over all of the possibilities to see > if and how they work. > For that I've already excluded globals and the > practice of feeding the value as an argument to the procedure and than store > its result as the new one. This is discouraged for anything very complex. > I've also excluded using a class object and put > the code in there, This is the standard way in Python and other OO languages. By 'excluded', do you mean 'rejected', or 'tried that, what else is there?' > as well as faking a "by reference" passing by using a tuple. One has to pass a mutable, such as list, set, dict, or user class instance. "nonlocal" looked to be another option, but it appears to be rather > limited in its application. Closures are standard in functional languages and are less limited than you seem to think. But you have to enclose (nest) many or all of the functions that directly rebind 'val' (else one might as well use a global value). def valclass(val): def set(newval): # For functions not defined within valclass. nonlocal val val = newval def get() return val def proc1(args) nonlocal val ... dev proc2(args) nonlocal val ... return setval, getval, proc1, proc2 # return {'set':set, 'get':get, 'proc1':proc1, 'proc2':proc2} setval, getval, proc1, proc2 = valclass(3) # val = valclass(3) > In short, the /ways to the goal/ are (currently) important to me, not the > goal itself (I'm sure that apart from the "nonlocal" one all of the above > are viable, and I thus can get /something/ to work) -- Terry Jan Reedy From torriem at gmail.com Thu Nov 14 19:11:56 2019 From: torriem at gmail.com (Michael Torrie) Date: Thu, 14 Nov 2019 17:11:56 -0700 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> Message-ID: <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> On 11/14/19 2:16 PM, R.Wieser wrote: > I think I did - though implicitily. What do normal people use "by > reference" arguments for ? Yep, that is what I wanted too. Well I've only seen this done in languages where other mechanisms for returning complex types are not present. For example in C. Chris talked about dealing with languages where strings are not first-class citizens, for example. In C you can either return a pointer to the string (and remember who's responsibility it is to free the memory!), or you can allocate memory yourself and pass the pointer to a function, like strcpy. In Python there is no similar equivalent, other than hacks involving passing in mutable objects and using those objects to save the state. State is maintained either by returning everything from the function you need to maintain state (in a tuple, for example), or by using OOP. Another mechanism Python has for doing certain types of state keeping between calls is the generator idea. > I'm trying to learn how Python works, and for that I (ofcourse) compare it > to other languages. What-and-how it does something different (or equal!) > in regard to them. Fair enough, but trying to do 1:1 transliterations isn't going to help you learn idiomatic Python. > 1) Have value > 2) use value in procedure 1 > 3) use updated value in procedure 2 > 4) use again updated value in procedure 1, 2 or maybe 3 A clear case for using an object and placing your procedures as methods to the object. Everything in Python is OO under the hood, even if you are not forced to use a particular paradigm. Even a module is an object. It's a sort of singleton really. functions are like a static method in other languages. The beauty of Python's organization, though, is you don't have to use a forced class structure as your namespace. Modules and packages provide a nicer namespace than Java or C#'s method. But I digress. > For the sake of learning I'm now going over all of the possibilities to see > if and how they work. For that I've already excluded globals and the > practice of feeding the value as an argument to the procedure and than store > its result as the new one. I've also excluded using a class object and put > the code in there, as well as faking a "by reference" passing by using a > tuple. "nonlocal" looked to be another option, but it appears to be rather> limited in its application. Well be sure to add Python's classes and objects to your list of possibilities. And also explore generators (coroutines). > In short, the /ways to the goal/ are (currently) important to me, not the > goal itself (I'm sure that apart from the "nonlocal" one all of the above > are viable, and I thus can get /something/ to work) > > Yeah, I'm weird like that. Sorry. Okay I just was wondering if there is a particular task at hand. Often that's the best way to learn a language. You have a specific task you want to accomplish, or program you need to write, and then find out the best way to do it within the abilities and strengths of the language. Years ago I was taught Prolog and man I fought that language because I never really grasped the concepts and wanted to program in C or Pascal instead of Prolog. If I knew then what I know now I would have probably had an easier time of it. From torriem at gmail.com Thu Nov 14 20:34:27 2019 From: torriem at gmail.com (Michael Torrie) Date: Thu, 14 Nov 2019 18:34:27 -0700 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: <0p6pse9jbdr4l8tpf25c8n4auk80ndanmd@4ax.com> Message-ID: On 11/14/19 2:13 AM, R.Wieser wrote: > Too bad that the Pi has no free hardware that can be abused for stuff like > this (like a serial port in synchronous mode). An arduino working in conjunction with the Pi can fill in the gaps. At one time you could buy an arduino board that was also a Pi hat. Python on the Pi and C on the arduino seemed like a good idea to me. Also there are microprocessor boards that can run MicroPython which does offer some real-time functionality with a nice Python script front end. From originallmoney at gmail.com Thu Nov 14 21:30:30 2019 From: originallmoney at gmail.com (originallmoney at gmail.com) Date: Thu, 14 Nov 2019 18:30:30 -0800 (PST) Subject: Trouble trying to get started with pygame In-Reply-To: References: <8fe30991-0ad2-632f-bb37-fc9881b8835f@mrabarnett.plus.com> <6798ae9c-8823-4dbb-ae16-06257e49d06a@googlegroups.com> <3717e429-b1c3-8f6f-8dd3-50f89d2a21cc@mrabarnett.plus.com> <019fedd8-8c8e-453e-84aa-39dfa77d28c5@googlegroups.com> <207693a2-67ce-4fb1-4375-8933dd50a89b@mrabarnett.plus.com> Message-ID: On Tuesday, November 12, 2019 at 7:05:16 PM UTC-5, Terry Reedy wrote: > On 11/12/2019 2:32 PM, originallmoney at gmail.com wrote: > > I'm curious: I've been seeing people having multiple pygame programs open at once (Where each one is a component of a main program, obviously). > > Multiple programs open at once on modern machines is normal. Do you > mean multiple windows for one program? As is possible with IDLE? > > -- > Terry Jan Reedy Well, the example I was seeing, the person had one window which contained a portion of the larger pygame program controlling the display, another for controlling the characters, and another for the main program (Plus, I think, two others whose purpose I forget). I'm just concerned because, I can't imagine that's possible from the command prompt, but, I don't know what they had that would allow them to have multiple subprograms open at once in Python. I'm used to that in Visual Studio C++, but, I don't know of such a thing for Python. From python at mrabarnett.plus.com Thu Nov 14 21:42:31 2019 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 15 Nov 2019 02:42:31 +0000 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: <97c573af-e6cb-e33b-82af-e19e12e84784@cinege.com> Message-ID: <82660127-1fdf-2bb0-2491-8868c7cf1480@mrabarnett.plus.com> On 2019-11-15 00:37, Dennis Lee Bieber wrote: > On Thu, 14 Nov 2019 21:00:59 +0100, "R.Wieser"
> declaimed the following: > > >>:-) I already wrote that program in C{something} (I'm not sure what my Pi >>offers by default) a while ago, but "ported" it to python. For the above >>mentioned "example" reason. >> > > "by default" pretty much any Linux distribution provides gcc > (supporting both "plain C" and "C++"). With apt-get one can augment with > Fortran, Ada (GNAT), "D", Go, Objective-C and Objective-C++. Outside of gcc > one can install free-pascal and Lazarus IDE. There is even a COBOL > compiler. > Objective-C++? I knew that Objective-C is C with objects. I knew that C++ is C with objects. But C with both? From Richard at Damon-Family.org Thu Nov 14 23:17:44 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 14 Nov 2019 23:17:44 -0500 Subject: nonlocal fails ? In-Reply-To: References: <432F4E9A-D2AB-4BEC-B9CE-D5533FB25AE9@gmail.com> Message-ID: On 11/14/19 1:43 PM, R.Wieser wrote: > Richard, > >> Assuming that one language works like another is a danger > Abitrarily redefining words and using misnomers is another ... ("global" > and "nonlocal" respecivily if you wonder) > >> First, Python doesn't really have 'Variables' like a lot of other >> languages >> (they don't hold a bag of bytes), as Python names don't hold values, but >> are just references to objects which actually hold the value > That's a principle as old as programming languages itself I believe. There are at least two very different concepts that act like variables in different languages. In a language like C, a variable is a 'bucket of byte' that holds some value. If you assign the value of one variable to another, that byte pattern is copied from one to another. That representation might include a pointer to some other block (a pointer or reference), but generally this is something explicit. In this sort of language your names represent variables that actually hold values. In Python, the name for your 'variable' doesn't actually hold the value that is assigned to it, but instead the bucket of bytes associated with the name is ALWAYS a pointer to a bucket of bytes that represents the value. Multiple names are allowed to point to the same value object, so assigning one name to another just copies that pointer, and they share the same value object. You shouldn't really think of names as holding 'values' but the names are 'bound' to the value objects (which aren't tied to a given name). > >> If the name is never bound to something, then the name will be also looked >> for in the global namespace. > Can you give an example of that ? I currently cannot wrap my head around > what you could be meaning there - anything I can imagine simply doesn't make > any sense ... > > Regards, > Rudy Wieser > #This Function creates a local name and updates it. str will be created locally and looked up locally def useslocal(): ??? str = "String" ??? str = str + " Added" gstr = "Global" # This function never binds a value to gstr, so it will look in the 'global' space to find the name def useglobal(): ?? str = gstr + " Seen" # This function include a binding to gstr, so it is only looked for locally, #so this use will create an error that it can't find gstr, # even though it was defined in the global name space def getserror(): ??? str = gstr + " Error" ??? gstr = str # This works because of the global statement, and updates the global def workingglobal(): ??? global gstr ??? str = gstr + " Error" ??? gstr = str -- Richard Damon From Richard at Damon-Family.org Thu Nov 14 23:36:58 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 14 Nov 2019 23:36:58 -0500 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> Message-ID: On 11/14/19 12:57 PM, R.Wieser wrote: > Michael, > >> nonlocal does not share or use its *caller's* variables. Rather it >> reaches into the scope of the outer function where it was defined. >> That's a very different concept than what you're proposing. > Oh blimy! You're right. Its an at compile-time thing, not a runtime > one. > > Thanks for the heads-up. > >> I know of no sane way that a function could work with the scope of >> any arbitrary caller. > The trick seems to be to emulate a "by reference" call, by using a mutable > object as the argument and stuff the value inside of it (IIRC a tuple with a > single element). tuples are immutable, use a list or a dictionary. >> What would happen if the caller's scope didn't have any >> names that the function was looking for? > Handle it the same as any other mistake, and throw an error ? > > Regards, > Rudy Wieser > > -- Richard Damon From renesd at gmail.com Fri Nov 15 03:12:14 2019 From: renesd at gmail.com (=?UTF-8?Q?Ren=C3=A9_Dudfield?=) Date: Fri, 15 Nov 2019 09:12:14 +0100 Subject: Trouble trying to get started with pygame In-Reply-To: References: <8fe30991-0ad2-632f-bb37-fc9881b8835f@mrabarnett.plus.com> <6798ae9c-8823-4dbb-ae16-06257e49d06a@googlegroups.com> <3717e429-b1c3-8f6f-8dd3-50f89d2a21cc@mrabarnett.plus.com> <019fedd8-8c8e-453e-84aa-39dfa77d28c5@googlegroups.com> <207693a2-67ce-4fb1-4375-8933dd50a89b@mrabarnett.plus.com> Message-ID: Hi, it's possible to have multiple processes running with separate pygame windows. However you need to communicate with an inter process mechanism. For example by running a web server over TCP/ip/sockets, or UDP with OSC, or shared memory with mmap, or even via clipboard copy/paste, the humble file, or a database (Sqlite, PostgreSQL). Each method has different trade offs. However with pygame > pygame version 2 it is possible to have multiple OS windows controlled by a single process. The reason SDL and pygame do this is they come from a world where taking over the whole screen (and OS) was common. Also having multiple windows is mostly bad UX. If people are paying for your UX, then probably you want good UX. Note, that you can split the screen up inside a single OS window. In pygame this is done easily with a subsurface, or by manually positioning things with rects. cheerio, On Fri, Nov 15, 2019 at 3:36 AM wrote: > On Tuesday, November 12, 2019 at 7:05:16 PM UTC-5, Terry Reedy wrote: > > On 11/12/2019 2:32 PM, originallmoney at gmail.com wrote: > > > I'm curious: I've been seeing people having multiple pygame programs > open at once (Where each one is a component of a main program, obviously). > > > > Multiple programs open at once on modern machines is normal. Do you > > mean multiple windows for one program? As is possible with IDLE? > > > > -- > > Terry Jan Reedy > > Well, the example I was seeing, the person had one window which contained > a portion of the larger pygame program controlling the display, another for > controlling the characters, and another for the main program (Plus, I > think, two others whose purpose I forget). I'm just concerned because, I > can't imagine that's possible from the command prompt, but, I don't know > what they had that would allow them to have multiple subprograms open at > once in Python. I'm used to that in Visual Studio C++, but, I don't know of > such a thing for Python. > -- > https://mail.python.org/mailman/listinfo/python-list > From pieter-l at vanoostrum.org Fri Nov 15 03:59:52 2019 From: pieter-l at vanoostrum.org (Pieter van Oostrum) Date: Fri, 15 Nov 2019 09:59:52 +0100 Subject: nonlocal fails ? References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> Message-ID: "R.Wieser"
writes: > Jan, > >> So what you want to do is dynamic scope? > > No, not really. I was looking for method to let one procedure share a > variable with its caller - or callers, selectable by me. And as a "by > reference" argument does not seem to exist in Python ... > > And yes, I am a ware that procedures can return multiple results. I just > didn'want to go that way (using the same variable twice in a single > calling). Do you mean, if Proc1() is called from Func1, it uses MyVar defined in Func1, and if it is called from Func2, it uses MyVar from Func2? If that is what you mean, that would be dynamic scope. -- Pieter van Oostrum WWW: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From countryone77 at gmail.com Fri Nov 15 04:07:27 2019 From: countryone77 at gmail.com (Bev In TX) Date: Fri, 15 Nov 2019 03:07:27 -0600 Subject: How to delay until a next increment of time occurs ? In-Reply-To: <82660127-1fdf-2bb0-2491-8868c7cf1480@mrabarnett.plus.com> References: <97c573af-e6cb-e33b-82af-e19e12e84784@cinege.com> <82660127-1fdf-2bb0-2491-8868c7cf1480@mrabarnett.plus.com> Message-ID: <0603F2AD-DDD5-4CFD-B7B7-0368AB684BC0@gmail.com> > On Nov 14, 2019, at 8:42 PM, MRAB wrote: > > Objective-C++? > > I knew that Objective-C is C with objects. > > I knew that C++ is C with objects. > > But C with both? Per Wikipedia... Objective-C++ is a language variant accepted by the front-end to the GNU Compiler Collection and Clang, which can compile source files that use a combination of C++ and Objective-C syntax. Objective-C++ adds to C++ the extensions that Objective-C adds to C. As nothing is done to unify the semantics behind the various language features, certain restrictions apply: Bev in TX From address at not.available Fri Nov 15 04:08:00 2019 From: address at not.available (R.Wieser) Date: Fri, 15 Nov 2019 10:08:00 +0100 Subject: How to delay until a next increment of time occurs ? References: <97c573af-e6cb-e33b-82af-e19e12e84784@cinege.com> <43798fb8-34e6-9930-c174-038f6ce35894@cinege.com> Message-ID: Dave, > OK I'm old enough cancer to know what X10 is. :-) Ah, so that is the name I forgot. :-) > I wouldn't think this is too difficult to do as you're only sending. You're right, codewise it isn't. > For this application IMO there is too much going on inside python that can > interrupt the cycle of modulation. (Intra and Extra python; garbage > collection, other processes, etc) Actually, it seems to work rather well. Ofcourse, that is with just the python program running, and sending the code a couple of times for good measure. > I would drop back to a simple program in C that you execute from python A program I wrote before even thinking of doing the same in Python. :-) My goal here was to see if I could do the same in pure python. I can, but barily. > Let me stress, my advise is doing this *reliably*. :-) Not possible without any kind of "is it on?" checking/feed-back mechanism. As such a one-way signalling as is used for those wall-warts is "best effort" at best. > Once you have this working reliably, you could then look to convert > it to a python c-module to more tightly integrate it. Interfacing Python with C{something} was already on the agenda. Using this as a goal is a likely candidate. :-) Regards, Rudy Wieser From antoon.pardon at vub.be Fri Nov 15 04:21:42 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 15 Nov 2019 10:21:42 +0100 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> Message-ID: <00028586-fafe-9e92-1ea6-0166ffb80916@vub.be> On 14/11/19 18:46, R.Wieser wrote: > Jan, > >> So what you want to do is dynamic scope? > No, not really. I was looking for method to let one procedure share a > variable with its caller - or callers, selectable by me. And as a "by > reference" argument does not seem to exist in Python ... If you start thinking about what kind of argument passing mechanisme Python has, you should first think about what kind of assignment semantics Python has. In some sense all parameter passing in Python is by reference, but it is the assignment semantics that cause it to not have the effect people expect. The preffered terminology is call by sharing, but if you mutate the parameter it has the same effect as call by reference. -- Antoon. From address at not.available Fri Nov 15 04:24:56 2019 From: address at not.available (R.Wieser) Date: Fri, 15 Nov 2019 10:24:56 +0100 Subject: How to delay until a next increment of time occurs ? References: <83afdf83-f859-df42-05c3-11cdc2e14832@schwertberger.de> <3d4rsedrb4r45mggmg7b0ra0u5ug3ukaul@4ax.com> Message-ID: Rob, > On an actually practical note; ever since they started baking the > quasi-realtime stuff into the Linux kernel, you've been able to use the > whole sched_setscheduler(2) family of calls (from C) to set a process's > real-time priority. Its something worth to look into. Thanks. Regards, Rudy Wieser From Karsten.Hilbert at gmx.net Fri Nov 15 04:39:33 2019 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Fri, 15 Nov 2019 10:39:33 +0100 Subject: py2 vs py3: zlib.adler32/crc32 In-Reply-To: References: <5f72d842-71a7-0a8c-fbf6-372080245d75@kynesim.co.uk> Message-ID: <20191115093933.GB2080@hermes.hilbert.loc> Hello MRAB, yes, like that :-) Thanks, Karsten On Thu, Nov 14, 2019 at 09:11:37PM +0000, MRAB wrote: > Date: Thu, 14 Nov 2019 21:11:37 +0000 > From: MRAB > To: python-list at python.org > Subject: Re: py2 vs py3: zlib.adler32/crc32 > User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 > Thunderbird/60.9.1 > > On 2019-11-14 19:22, Karsten Hilbert wrote: > > Hi all, > > > > I am unsure how to solve: I use adler32/crc32 to generate integer values from data > > for setting up an advisory lock in PostgreSQL. > > > > The PG function pg_try_advisory_lock() > > > > https://www.postgresql.org/docs/12/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS > > > > takes two PG ints which are defined as: > > > > integer 4 bytes typical choice for integer -2147483648 to +2147483647 > > > > Now, in Py > 2.5 zlib.adler32/crc32 will return suitable integers. > > > > However, in Py3 the return range has been changed to > > > > The return value is unsigned and in the range [0, 2**32-1] regardless of platform. > > > > which will overflow the PostgreSQL function. > > > > Is there a way to convert/modify/shift the py3 value such that it shows the > > same representation as the py2 value ? What I am looking for is: > > > > v2 = py2.zlib.adler32(data) > > v3 = some_magic(py3.zlib.adler32(data)) > > if v2 == v3: > > print('same') > > > > I am sure there's something obvious with struct/< > such like which I am overlooking. > > > > Note that I can't simply do > > > > v2 = py2.zlib.adler32(data) & 0xffffffff > > > > because that can overflow the PostgreSQL integer. I think I need > > the reverse, in a sense, but I am too dense, ATM. > > > Unsigned 32-bit to signed 32-bit: > > unsigned - (unsigned & 0x80000000) * 2 > > Signed 32-bit to unsigned 32-bit: > > signed & 0xFFFFFFFF > -- > https://mail.python.org/mailman/listinfo/python-list -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From address at not.available Fri Nov 15 05:12:47 2019 From: address at not.available (R.Wieser) Date: Fri, 15 Nov 2019 11:12:47 +0100 Subject: nonlocal fails ? References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> Message-ID: Chris, > That doesn't really answer the question. The problem is that you want to solve /this/ problem, while I'm looking for replies that are applicable to similar ones too. To be blunt about it: I consider solutions that only solve a single problem most always as a waste of my time (exceptions to the rule, yadayadayada). Solutions that I can expand and build upon are the ones I'm looking for (read: learn from). But as lot of people will respond like you and than pick something from the /supporting information/ and go off on a tangent with it that doesn't aim to answer /my/ question I have become rather carefull about what I post in regard to specifics. > The point of your new car isn't to push the pedal - it's to get you some > place. And thats your problem in a nutshell: You think in forms of "get you some place". What about just /learning how to drive/ ? Regards, Rudy Wieser From address at not.available Fri Nov 15 05:48:06 2019 From: address at not.available (R.Wieser) Date: Fri, 15 Nov 2019 11:48:06 +0100 Subject: nonlocal fails ? References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> Message-ID: Terry, > This is discouraged for anything very complex. Complex things do not exist. If you think you have something like it you've just not yet broken it down in its components yet. :-) > This is the standard way in Python and other OO languages. By 'excluded', > do you mean 'rejected', or 'tried that, what else is there?' The latter. Although I've pretty-much rejected the "global" method. > Closures are standard in functional languages and are less limited than > you seem to think. I was talking about the "nonlocal" method of variable inheritance, not closures. I'm not going to comment (much) on the latter until I've had a chance to play with them. Regards, Rudy Wieser From address at not.available Fri Nov 15 06:11:31 2019 From: address at not.available (R.Wieser) Date: Fri, 15 Nov 2019 12:11:31 +0100 Subject: How to delay until a next increment of time occurs ? References: <5quqsep867ca775s10tah1jq1mktqu70mh@4ax.com> Message-ID: Dennis, > No, that addition is a fixed increment on the initial starting > time, and is NOT relative to the ending of a sleep. > No, that addition is a fixed increment Yep. > on the initial starting time Nope. If pythons sleep is worth its salt it ends exactly on the time provided in "t". Thus the subsequent addition to that "t" is releative to the end of the sleep just before it. > The subtraction in the sleep call is what adjusts for the processing > time between sleeps Yep. /All/ the time in between them. Not just from the "t +=" you mentioned onwards (ignoring the time spend on switching the pin and the loops jumping-back). > ??? Not sure what you describe here My apologies, I should have been clearer. Its the time difference I saw when using a hard 300 uSec delay in the loop (cycle-time longer that 300 uSec), compared to a drift-compensated delay of the same (cycle time exactly 300 uSec). I attributed the difference to the time as spend in the code between sleeps (loop jumping, toggeling of the pin and calculation of the new end time - possibly the sleeps argument calculation too) Regards, Rudy Wieser From address at not.available Fri Nov 15 06:56:02 2019 From: address at not.available (R.Wieser) Date: Fri, 15 Nov 2019 12:56:02 +0100 Subject: nonlocal fails ? References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> Message-ID: Michael, > Well I've only seen this done in languages where other mechanisms >for returning complex types are not present. :-) Than you have not seen to many languages I'm afraid. There are quite a number of languages where /every/ type of argument (including values) can be transfered "by reference". Though some default to "by value", where others default to "by reference". As for "complex types" ? I don't think a(n ASCII) string can be considered any kind of a complex type, but most all languages I know of transfer them "by reference" only (though some fake "by value" by using a copy-on-write mechanism). > In C you can either return a pointer to the string (and remember who's > responsibility it is to free the memory!), or you can allocate memory > yourself and pass the pointer to a function, like strcpy. Or pass a reference to an empty pointer, have the procedure allocate the memory and return the address of it in that pointer. And only the second one comes near to what I indicated I asked about: a mutable value stored outside the current procedure. > In Python there is no similar equivalent, It looks like it > other than hacks involving passing in mutable objects The only "hack" I see here is to transfer /mutable/ object, instead of a non-mutable one. > Fair enough, but trying to do 1:1 transliterations isn't going to > help you learn idiomatic Python. If I would have wanted that, why would I post here with open questions ? But yes, I often refer to how other languages work, in an attempt to get the other to tell me whats so special/different about the current languages solution for it. Regards, Rudy Wieser From rosuav at gmail.com Fri Nov 15 07:00:26 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Nov 2019 23:00:26 +1100 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> Message-ID: On Fri, Nov 15, 2019 at 9:16 PM R.Wieser
wrote: > > Chris, > > > That doesn't really answer the question. > > The problem is that you want to solve /this/ problem, while I'm looking for > replies that are applicable to similar ones too. > > To be blunt about it: I consider solutions that only solve a single problem > most always as a waste of my time (exceptions to the rule, yadayadayada). > Solutions that I can expand and build upon are the ones I'm looking for > (read: learn from). > > But as lot of people will respond like you and than pick something from the > /supporting information/ and go off on a tangent with it that doesn't aim to > answer /my/ question I have become rather carefull about what I post in > regard to specifics. > > > The point of your new car isn't to push the pedal - it's to get you some > > place. > > And thats your problem in a nutshell: You think in forms of "get you some > place". > > What about just /learning how to drive/ ? > The purpose of a car is not to learn how to ride a bicycle. Yes, I am thinking in terms of an ultimate goal, because the point of coding is to achieve something. Maybe your goal *right now* is to learn rather than to create, but surely the purpose of the learning is to be able to achieve things later? Rather than try to implement pass-by-reference semantics in Python, figure out what abstract concept you're actually trying to implement. Otherwise, all you'll do is come up with convoluted methods of implementing some other language's semantics in Python, and then write your code using that other language's idioms, and run it in a Python interpreter. Far better to actually learn Python's semantics, and how they can be used to represent your actual goals. ChrisA From rosuav at gmail.com Fri Nov 15 07:07:49 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Nov 2019 23:07:49 +1100 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> Message-ID: On Fri, Nov 15, 2019 at 11:01 PM R.Wieser
wrote: > > As for "complex types" ? I don't think a(n ASCII) string can be considered > any kind of a complex type, but most all languages I know of transfer them > "by reference" only (though some fake "by value" by using a copy-on-write > mechanism). "Pass by value" and "pass by reference" become largely irrelevant when your strings are immutable objects; so I would say that a large number of languages have broadly "pass-by-value" semantics for strings, treating them as first-class objects that are defined by value, not identity. > > In C you can either return a pointer to the string (and remember who's > > responsibility it is to free the memory!), or you can allocate memory > > yourself and pass the pointer to a function, like strcpy. > > Or pass a reference to an empty pointer, have the procedure allocate the > memory and return the address of it in that pointer. I don't know why you'd do that rather than simply return the new pointer, but whatever. It's still a lot clunkier than simply returning a string, which is what happens in all sane high-level languages. > > In Python there is no similar equivalent, > > It looks like it > > > other than hacks involving passing in mutable objects > > The only "hack" I see here is to transfer /mutable/ object, instead of a > non-mutable one. Yes, Python has no concept of pass-by-reference. Python *always* passes objects around, not variables. But everything that you could do with "pass by reference" can be done by passing a mutable object, and everything that you could do by passing mutable objects around can be done by passing pointers to data structures, or (equivalently) passing data structures by reference. There's no real difference. ChrisA From address at not.available Fri Nov 15 07:28:50 2019 From: address at not.available (R.Wieser) Date: Fri, 15 Nov 2019 13:28:50 +0100 Subject: nonlocal fails ? References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> Message-ID: Dennis, > The first thing one needs to learn is that Python does NOT follow the > common post-office mailbox concept where > > x = y > > means the /value/ stored at location identified by "y" is /copied/ to the > location identified by "x". :-) Although that is how we humans remember the effect of what we do, there is no reason for a programming language to do it exactly like that. And sometimes they don't. > means /find/ the object (somewhere in memory) that has a note "y" > stuck to it. Without moving the "y" note, attach an "x" note to that > same object. Which you can find back in any language which allows a "by reference" passing of arguments to a procedure (and do remember how strings are often /only/ passed as such). The caller often uses one name for the "value" passed as an argument but in the procedure uses a different one - both accessing the same contents. > In software engineering as I learned it, it is preferable to decouple ... not because its so good for us humans, but that way you can mathematically prove that the finished program should work as designed. ... which some languages (mostly the ones which allow only single results returned from a function) are starting to turn back from (allowing "by reference" access back in - its just too damn usefull). > All depends upon the scope of those procedures. I have no idea which circumstances you're hinting at. But just take it that the scope is local - apart from that externally referenced value ofcourse. > The simplest is to use a mutable object as a container at the > module level. With some variation of "simple" I guess. :-) Personally I think I would sooner go for a single-element tuple. Regards, Rudy Wieser From address at not.available Fri Nov 15 07:34:53 2019 From: address at not.available (R.Wieser) Date: Fri, 15 Nov 2019 13:34:53 +0100 Subject: nonlocal fails ? References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> Message-ID: Pieter, > Do you mean, if Proc1() is called from Func1, it uses MyVar defined >in Func1, and if it is called from Func2, it uses MyVar from Func2? Yep. > If that is what you mean, that would be dynamic scope. Thanks for pointing that out (I've learned a new definition today! :-) ). Regards, Rudy Wieser From Richard at Damon-Family.org Fri Nov 15 10:48:58 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 15 Nov 2019 10:48:58 -0500 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> Message-ID: <0b2ba947-38ad-8e4d-782e-7a96a5d913b3@Damon-Family.org> On 11/15/19 6:56 AM, R.Wieser wrote: > There are quite a number of languages where /every/ type of argument > (including values) can be transfered "by reference". Though some default to > "by value", where others default to "by reference". It seems you are stuck in a programming model different than what Python provides, In a very real sense, the terms call "By Reference" and "By Value" don't apply to Python. Those concepts presume that a variable name represents a bucket of bytes that holds some value, and call by value copies those bytes into a new variable for the subroutine, and call by Reference creates a pointer value back to original value, and all uses of that parameter work indirect that pointer. That is NOT how Python works. In Python, in effect, every name in your code is just a reference which points to some object (This is called binding). Multiple names can point to the same object (or no names, at which point the object is subject to being garbage collected). Names themselves aren't objects, so you can't really make one name refer to another, only to the same object that the other one does. (In actuality, these collections of names are implemented basically in a Dictionary, so using this sort of implementation details you can sort of get that result, but I don't think that is defined to work in the language). In the more classical languages, to draw a model of the variables you have in memory, you take a big sheet of paper, put down each variable name, and next to it a box where you put what value is stored in the variable, and that value is intimately associated with that variable name. You might have some objects being or containing pointers/references and in that case you can represent it by an arrow from the box representing the pointer to the object it is pointing to. There may be some object that are created without a name (like on the heap), but many of the objects are directly tied to a name. In Python you do this differently. On one side of your paper, you put your variable names, and on the other (perhaps a larger side) all the values/objects you are working with. Each name gets an arrow to an object to show what object it is currently bound to. Objects store the values they hold, and some, like collections) also have arrows to other objects they reference. An arrow always points to an object, never to a name on the left side. An assignment just changes what object a reference points to. If it is a 'top level' name being assigned to (as opposed to referring to a member of an object or element of a collection), that is changing one of the names on the left side of the page. This difference in value model means you have to think about things differently, and in a very real sense makes the terms 'by value' and 'by reference' not applicable. You don't get values 'By Value', because you didn't get a copy of the object reference, so if you mutate it, the caller sees the change, but also it isn't by reference, as you can't rebind the callers reference to point to a different object. This isn't 'Wrong' just 'Different'. It takes some getting used to a different model, and I think it helps to accept that it is different rather than trying to keep trying to translate how Python does things into how some other language does it, as the latter make you focus on the things it can't do, not the things it can. -- Richard Damon From torriem at gmail.com Fri Nov 15 11:03:13 2019 From: torriem at gmail.com (Michael Torrie) Date: Fri, 15 Nov 2019 09:03:13 -0700 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> Message-ID: On 11/15/19 4:56 AM, R.Wieser wrote: >> Well I've only seen this done in languages where other mechanisms >> for returning complex types are not present. > > :-) Than you have not seen to many languages I'm afraid. Careful there. > If I would have wanted that, why would I post here with open questions ? > But yes, I often refer to how other languages work, in an attempt to get the > other to tell me whats so special/different about the current languages > solution for it. Yes you can learn a certain amount about a language by doing such 1:1 transliteration exercises. But you can only go so far. For example you'll never master such powerful concepts as generators, closures, list comprehensions, and so forth by doing this. I've found a far better way is to do a project in a language, either something you've done already in another language, or something new. Instead of doing a low-level transliteration, look at the problem at the high level, and find out how the language at hand best works to solve the problem. That's why I and others asked what problem you're trying to solve. Also you seem to be comparing traditional, compiled with statically- but often weakly-typed languages such as C, C++, Pascal, etc, with Python, which is an interpreted, dynamically-typed language. They are very different beasts with different strengths and weaknesses and very different performance characteristics. The reason you're getting such push back is that over the years on this list we've seen dozens of new users arrive at Python but never really learn how to program in Python. These users insisted on coding in Java, C#, or C++ (or whatever) in Python. Some resist strongly when we suggest this is a recipe for failure. It was an exercise in frustration and most of them left thinking what a horrible, limited language Python is, and unable to understand what makes Python so productive, expressive, and powerful. From random832 at fastmail.com Fri Nov 15 11:04:47 2019 From: random832 at fastmail.com (Random832) Date: Fri, 15 Nov 2019 11:04:47 -0500 Subject: nonlocal fails ? In-Reply-To: <0b2ba947-38ad-8e4d-782e-7a96a5d913b3@Damon-Family.org> References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> <0b2ba947-38ad-8e4d-782e-7a96a5d913b3@Damon-Family.org> Message-ID: <2313f803-8453-44cf-977d-30e4694d4950@www.fastmail.com> On Fri, Nov 15, 2019, at 10:48, Richard Damon wrote: > On 11/15/19 6:56 AM, R.Wieser wrote: > > There are quite a number of languages where /every/ type of argument > > (including values) can be transfered "by reference". Though some default to > > "by value", where others default to "by reference". > > It seems you are stuck in a programming model different than what Python > provides, In a very real sense, the terms call "By Reference" and "By > Value" don't apply to Python. Those concepts presume that a variable > name represents a bucket of bytes that holds some value, and call by > value copies those bytes into a new variable for the subroutine, and > call by Reference creates a pointer value back to original value, and > all uses of that parameter work indirect that pointer. > > That is NOT how Python works. In Python, in effect, every name in your > code is just a reference which points to some object (This is called > binding). Multiple names can point to the same object (or no names, at > which point the object is subject to being garbage collected). Names > themselves aren't objects, so you can't really make one name refer to > another, only to the same object that the other one does. (In actuality, > these collections of names are implemented basically in a Dictionary, so > using this sort of implementation details you can sort of get that > result, but I don't think that is defined to work in the language). Being abstractly typed objects rather than a bucket of bytes, and having the values themselves be a kind of reference or pointer (though to immutable data in some important cases), does not in fact change the meaning of the "call by reference" concept or its applicability. It would be entirely reasonable, I think, in the python model, to provide a way for making a variable a cell variable, passing the cell object around explicitly, and having the called function automatically set/get the value when the argument is accessed. I don't think it would solve the OP's problem, since his talk about automatically "inheriting" the caller's variable of the same name sounds a lot more like dynamic scope than call by reference. From torriem at gmail.com Fri Nov 15 11:19:08 2019 From: torriem at gmail.com (Michael Torrie) Date: Fri, 15 Nov 2019 09:19:08 -0700 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> Message-ID: On 11/15/19 5:28 AM, R.Wieser wrote: > :-) Although that is how we humans remember the effect of what we do, there > is no reason for a programming language to do it exactly like that. And > sometimes they don't. So, in effect he's saying not all languages use the classic variable model, which you then agree with but then go on to insist that there must be a way in Python to implement the classic, traditional language variable model? I don't understand your point. > Which you can find back in any language which allows a "by reference" > passing of arguments to a procedure (and do remember how strings are often > /only/ passed as such). The caller often uses one name for the "value" > passed as an argument but in the procedure uses a different one - both > accessing the same contents. Again, which isn't Python. And come to that such mechanisms should be used sparingly in languages which offer/require them. > With some variation of "simple" I guess. :-) > > Personally I think I would sooner go for a single-element tuple. To each his own. I rather suspect Python is not a good a fit for you. Quite a few folks here have showed a lot of patience with your questions, and posted very insightful and educational comments, which is a part of the list that I enjoy very much and learn a great deal from. But you seem to unwilling to internalize any of it. However, I appreciate that you have kept the tone civil and polite. Thank you. From Richard at Damon-Family.org Fri Nov 15 11:47:40 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 15 Nov 2019 11:47:40 -0500 Subject: nonlocal fails ? In-Reply-To: <2313f803-8453-44cf-977d-30e4694d4950@www.fastmail.com> References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> <0b2ba947-38ad-8e4d-782e-7a96a5d913b3@Damon-Family.org> <2313f803-8453-44cf-977d-30e4694d4950@www.fastmail.com> Message-ID: <516da304-39c0-f75e-4b51-7aea584902c7@Damon-Family.org> On 11/15/19 11:04 AM, Random832 wrote: > On Fri, Nov 15, 2019, at 10:48, Richard Damon wrote: >> On 11/15/19 6:56 AM, R.Wieser wrote: >>> There are quite a number of languages where /every/ type of argument >>> (including values) can be transfered "by reference". Though some default to >>> "by value", where others default to "by reference". >> It seems you are stuck in a programming model different than what Python >> provides, In a very real sense, the terms call "By Reference" and "By >> Value" don't apply to Python. Those concepts presume that a variable >> name represents a bucket of bytes that holds some value, and call by >> value copies those bytes into a new variable for the subroutine, and >> call by Reference creates a pointer value back to original value, and >> all uses of that parameter work indirect that pointer. >> >> That is NOT how Python works. In Python, in effect, every name in your >> code is just a reference which points to some object (This is called >> binding). Multiple names can point to the same object (or no names, at >> which point the object is subject to being garbage collected). Names >> themselves aren't objects, so you can't really make one name refer to >> another, only to the same object that the other one does. (In actuality, >> these collections of names are implemented basically in a Dictionary, so >> using this sort of implementation details you can sort of get that >> result, but I don't think that is defined to work in the language). > Being abstractly typed objects rather than a bucket of bytes, and having the values themselves be a kind of reference or pointer (though to immutable data in some important cases), does not in fact change the meaning of the "call by reference" concept or its applicability. > > It would be entirely reasonable, I think, in the python model, to provide a way for making a variable a cell variable, passing the cell object around explicitly, and having the called function automatically set/get the value when the argument is accessed. I don't think it would solve the OP's problem, since his talk about automatically "inheriting" the caller's variable of the same name sounds a lot more like dynamic scope than call by reference. It isn't hard to explicitly do this in Python. The caller just puts it value into a 1 element list, and then the called function mutates that list (setting parm[0] instead of parm). This appears to align with standard Python idioms. The issue with calling it a Reference, is that part of the meaning of a Reference is that it refers to a Object, and in Python, Names are conceptually something very much different than an Object. Yes, in the implementation details, a name is basically a dictionary entry, so it could be done, the question is should it. I have learned many computer languages over the years, and can say that while figuring out how to map constructs from one language to another has some value to start, you really do want to learn how the language really working in itself. There is an old saying that you can write FORTRAN in any language, and in a real sense it is true, and applies to many languages. In a general sense you can generally take a programming style from language X, and use it in language Y, and often be able to get a 'working' and 'valid' program, but your really should be using language X structures and use them in language X, write language Y using the normal style for language Y. In general, if you want to write a 'x' program, use language x, not language y. The major exception is if language x isn't available on the platform, but Python is usually the fallback language to go to, that will more likely be C or C++ as those are what are most often the first languages that are brought to a platform. (So maybe learning how to write Python is C is useful, but writing C in Python has less need), -- Richard Damon From Richard at Damon-Family.org Fri Nov 15 11:54:50 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 15 Nov 2019 11:54:50 -0500 Subject: nonlocal fails ? In-Reply-To: References: <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> Message-ID: On 11/15/19 11:26 AM, Dennis Lee Bieber wrote: > On Fri, 15 Nov 2019 12:56:02 +0100, "R.Wieser"
> declaimed the following: > >> There are quite a number of languages where /every/ type of argument >> (including values) can be transfered "by reference". Though some default to >> "by value", where others default to "by reference". >> > Yes -- and in those languages the concept of value vs reference is > visible at the source code level. In C, everything is passed by value -- > and the programmer uses & to pass (by value) the address of the argument, > and uses * in the called function to dereference that address back to the > data item itself. C++ added reference arguments (where the & is used in the > function declaration) in which the compiler automatically applies the > "address" and "dereference" operations. There are languages where pass by reference is the default and not explicit. I remember in early FORTRAN being able to do something like this (its been years since I have done this so syntax is probably a bit off) PROCEDURE foo(i) i = 2 return then elsewhere you could do foo(j) and after that j is 2 you also could do foo(1) and after that if you did j = 1 then now j might have the value 2 as the constant 1 was changed to the value 2 (this can cause great confusion) later I believe they added the ability to specify by value and by reference, and you weren't allowed to pass constants by reference, -- Richard Damon From python at python.invalid Fri Nov 15 12:11:23 2019 From: python at python.invalid (Python) Date: Fri, 15 Nov 2019 18:11:23 +0100 Subject: nonlocal fails ? In-Reply-To: References: <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> Message-ID: <5dcedc25$0$31434$426a74cc@news.free.fr> Richard Damon wrote: ... > then elsewhere you could do > > foo(j) > > and after that j is 2 > > you also could do > > foo(1) > > and after that if you did > > j = 1 > > then now j might have the value 2 as the constant 1 was changed to the > value 2 (this can cause great confusion) Wow! So fubar that such a feature should definitely makes its way into PHP! From random832 at fastmail.com Fri Nov 15 12:21:37 2019 From: random832 at fastmail.com (Random832) Date: Fri, 15 Nov 2019 12:21:37 -0500 Subject: nonlocal fails ? In-Reply-To: <516da304-39c0-f75e-4b51-7aea584902c7@Damon-Family.org> References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> <0b2ba947-38ad-8e4d-782e-7a96a5d913b3@Damon-Family.org> <2313f803-8453-44cf-977d-30e4694d4950@www.fastmail.com> <516da304-39c0-f75e-4b51-7aea584902c7@Damon-Family.org> Message-ID: On Fri, Nov 15, 2019, at 11:47, Richard Damon wrote: > The issue with calling it a Reference, is that part of the meaning of a > Reference is that it refers to a Object, and in Python, Names are > conceptually something very much different than an Object. Yes, in the > implementation details, a name is basically a dictionary entry, so it > could be done, the question is should it. C# has basically the same issue and does fine calling its thing 'ref'. But that's not really the point - my point was that the concept of being able to have a function change the value of a variable specified by its caller doesn't magically cease being applicable just because the value is a "reference" and the variable is a "name binding". [Similarly, the fact that values are "references" to mutable objects doesn't mean that python, or Java or C#, isn't call-by-value. The value is the "reference" itself, the fact that it can be used to change data that exists elsewhere is beside the point.] From arj.python at gmail.com Fri Nov 15 12:37:00 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Fri, 15 Nov 2019 21:37:00 +0400 Subject: What do you use for slides? Message-ID: Greetings all, For slides i use https://yhatt.github.io/marp/, but sometimes i want a more stylish tool. What do you use for slides? (besides powerpoint + syntax highlighting included) Thanks! Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius From grant.b.edwards at gmail.com Fri Nov 15 13:01:37 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 15 Nov 2019 18:01:37 -0000 (UTC) Subject: What do you use for slides? References: Message-ID: On 2019-11-15, Abdur-Rahmaan Janhangeer wrote: > For slides i use https://yhatt.github.io/marp/, but sometimes i want a more > stylish tool. > > What do you use for slides? (besides powerpoint + syntax highlighting > included) Last time I made slides it was four a 3-day course I was teaching. I used a package for TeX/LaTeX and produced PDF output for around 200 "slides". That worked brilliantly. It may have been SliTeX, but I'm not sure. Yikes, that was almost 20 years ago. :/ It looks like "Beamer" is a sligtly more modern apparoach using LaTeX: https://ctan.org/pkg/beamer The typesetting quality of TeX is still impossible to beat... -- Grant From arj.python at gmail.com Fri Nov 15 13:07:47 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Fri, 15 Nov 2019 22:07:47 +0400 Subject: What do you use for slides? In-Reply-To: References: Message-ID: Woops latex seems me programming the slides. yaps thanks for sharing. See this pycon vid for example: https://youtu.be/6uAvHOKofws It's simple and flexible ( you can add images, coloured syntax and cool text ) and that's all we need. Don't know what he used. Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius From Richard at Damon-Family.org Fri Nov 15 13:15:39 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 15 Nov 2019 13:15:39 -0500 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> <0b2ba947-38ad-8e4d-782e-7a96a5d913b3@Damon-Family.org> <2313f803-8453-44cf-977d-30e4694d4950@www.fastmail.com> <516da304-39c0-f75e-4b51-7aea584902c7@Damon-Family.org> Message-ID: On 11/15/19 12:21 PM, Random832 wrote: > On Fri, Nov 15, 2019, at 11:47, Richard Damon wrote: >> The issue with calling it a Reference, is that part of the meaning of a >> Reference is that it refers to a Object, and in Python, Names are >> conceptually something very much different than an Object. Yes, in the >> implementation details, a name is basically a dictionary entry, so it >> could be done, the question is should it. > C# has basically the same issue and does fine calling its thing 'ref'. But that's not really the point - my point was that the concept of being able to have a function change the value of a variable specified by its caller doesn't magically cease being applicable just because the value is a "reference" and the variable is a "name binding". > > [Similarly, the fact that values are "references" to mutable objects doesn't mean that python, or Java or C#, isn't call-by-value. The value is the "reference" itself, the fact that it can be used to change data that exists elsewhere is beside the point.] My understanding is the C# is like the rest of the C* family that defining a variable x in the code, binds the name x to a specific object in memory at compile time. That name will ALWAYS refer to that object and that object can be thought to have that name, and no others in the same way. The object may be/have a reference to another variable. (C++ references are a bit different at the language level, a reference itself isn't an object, and taking the address of the reference 'object' give the address of the object that the reference refers to, C++ references are still compile time bound to a single object, but that object still has a concept of the name it was created through) (I will admit that I don't really know C#, but going from what I understand it as) This is NOT true in Python. A 'Variable Name' in Python is not statically bound to given object, but every assignment rebind the name to object mapping. Python does NOT use call by value, because a key feature of call by value is that the value being passed is copied, and the new copy is used in the subroutine. Name bindings are NOT values, objects have values, and the value of the object passed is NOT copied to somewhere else. It is only by misunderstanding the language, and trying to define a name as being some sort of pointer object that points to the 'real' value of object that you can create such an idea. This is NOT the model Python is defined with, and while it might help a bit when starting to understand how things work, you do need to move from that 'wrong' understanding to starting to think of it the way Python is defined, or many things in Python won't make sense. -- Richard Damon From countryone77 at gmail.com Fri Nov 15 13:43:40 2019 From: countryone77 at gmail.com (Bev In TX) Date: Fri, 15 Nov 2019 12:43:40 -0600 Subject: nonlocal fails ? In-Reply-To: <5dcedc25$0$31434$426a74cc@news.free.fr> References: <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> <5dcedc25$0$31434$426a74cc@news.free.fr> Message-ID: > On Nov 15, 2019, at 11:11 AM, Python wrote: > > Richard Damon wrote: > ... >> then elsewhere you could do >> foo(j) >> and after that j is 2 >> you also could do >> foo(1) >> and after that if you did >> j = 1 >> then now j might have the value 2 as the constant 1 was changed to the >> value 2 (this can cause great confusion) > > Wow! So fubar that such a feature should definitely makes its > way into PHP! I remember fixing a bug caused by this. Bev in TX From luciano at ramalho.org Fri Nov 15 14:15:57 2019 From: luciano at ramalho.org (Luciano Ramalho) Date: Fri, 15 Nov 2019 16:15:57 -0300 Subject: nonlocal fails ? In-Reply-To: <3cstselr3975og769d3paiftjpn7nuv20u@4ax.com> References: <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> <3cstselr3975og769d3paiftjpn7nuv20u@4ax.com> Message-ID: Re: the whole pass by reference discussion. I've seen Python's argument passing described as "call by value, except that all values are references". This makes sense, but is confusing. Michael Scott, in his textbook Programming Language Pragmatics (4e) terms the Python way "call by sharing". That is the same mode used in most OO languages that don't have pointers, including Ruby, SmallTalk, and Java (this applies to Java reference types; primitive types use call by value). Call by sharing means that each formal parameter of the function gets a copy of each reference in the arguments. Cheers, Luciano On Fri, Nov 15, 2019 at 3:58 PM Dennis Lee Bieber wrote: > > On Fri, 15 Nov 2019 11:54:50 -0500, Richard Damon > declaimed the following: > > > > >I remember in early FORTRAN being able to do something like this (its > >been years since I have done this so syntax is probably a bit off) > > > > > > > >foo(1) > > > >and after that if you did > > > >j = 1 > > > >then now j might have the value 2 as the constant 1 was changed to the > >value 2 (this can cause great confusion) > > > > It was a very early FORTRAN that did that, since literals were stored > in general R/W memory and the address was passed. Later FORTRAN compilers > would flag a section of memory for R/O and stored literals in that section > -- so attempts at modification would result in an error. > > >later I believe they added the ability to specify by value and by > >reference, and you weren't allowed to pass constants by reference, > > Many compilers added extensions for interfacing to other languages (DEC > is famous for %val(), %ref(), %descr() for controlling parameters, and > %loc() external to parameters. %ref wasn't really useful in FORTRAN since > that is the native method. %loc returned the address of the target item. > %descr was a weird one -- things like character strings were passed by > descriptor: first word was the address [standard reference model], second > word encapsulated information like the length allocated to the string [not > the length used, but the size of the memory allocation]. > > Literals were still passed by reference -- just to read-only memory > block. Otherwise the called function wouldn't know how to behave! > > subroutine xyz(parm) > integer parm > > ... > > call xyz(1) > call xyz(abc) > > if the first was passed by value and the second by reference, what was > "parm" in the called function to do > > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com http://wlfraed.microdiversity.freeddns.org/ > > -- > https://mail.python.org/mailman/listinfo/python-list -- Luciano Ramalho | Author of Fluent Python (O'Reilly, 2015) | http://shop.oreilly.com/product/0636920032519.do | Technical Principal at ThoughtWorks | Twitter: @ramalhoorg From rosuav at gmail.com Fri Nov 15 14:22:41 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Nov 2019 06:22:41 +1100 Subject: nonlocal fails ? In-Reply-To: References: <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> <3cstselr3975og769d3paiftjpn7nuv20u@4ax.com> Message-ID: On Sat, Nov 16, 2019 at 6:20 AM Luciano Ramalho wrote: > > Re: the whole pass by reference discussion. > > I've seen Python's argument passing described as "call by value, > except that all values are references". This makes sense, but is > confusing. That's the typical sort of description you get from someone who mostly understands Python's semantics, but is hung up on the idea that everything is either call-by-value or call-by-reference, and is trying to figure out which box Python fits into. > Michael Scott, in his textbook Programming Language Pragmatics (4e) > terms the Python way "call by sharing". That is the same mode used in > most OO languages that don't have pointers, including Ruby, SmallTalk, > and Java (this applies to Java reference types; primitive types use > call by value). Call by sharing means that each formal parameter of > the function gets a copy of each reference in the arguments. > I don't think anyone's yet linked to this: https://nedbatchelder.com/text/names1.html ChrisA From info at wingware.com Fri Nov 15 14:58:21 2019 From: info at wingware.com (Wingware) Date: Fri, 15 Nov 2019 14:58:21 -0500 Subject: ANN: Wing Python IDE 7.1.3 Message-ID: <5DCF035D.6050000@wingware.com> Wing 7.1.3 has been released. This version adds improved and expanded documentation and support for matplotlib, improves the accuracy of code warnings, fixes automatically debugging child processes on Windows with Python 3.8, fixes installing the remote agent from .rpm or .deb installations, solves several issues with runtime type introspection, allows Open from Project and similar navigation commands from non-Browse vi mode, improves debugger reliability, and fixes about 30 other minor usability issues. == Some Highlights of Wing 7.1 == * Support for Python 3.8: Wing 7.1 supports editing, testing, and debugging code written for Python 3.8, so you can take advantage of assignment expressions and other improvements introduced in this new version of Python. * Improved Code Warnings: Wing 7.1 adds unused symbol warnings for imports, variables, and arguments found in Python code. This release also improves code warnings configuration, making it easier to disable unwanted warnings. * Cosmetic Improvements: Wing 7.1 improves the auto-completer, project tool, and code browser with redesigned icons that make use of Wing's icon color configuration. This release also improves text display on some Linux systems, supports Dark Mode on macOS, and improves display of Python code and icons found in documentation. * And More: Wing 7.1 also adds support for Windows 10 native OpenSSH installations for remote development, and makes a number of other minor improvements. This release drops support for macOS 10.11. System requirements remain unchanged on Windows and Linux. For details see the change log: https://wingware.com/pub/wingpro/7.1.3.0/CHANGELOG.txt For a complete list of new features in Wing 7, see What's New in Wing 7: https://wingware.com/wingide/whatsnew == Downloads == Wing Pro: https://wingware.com/downloads/wing-pro/7.1/binaries Wing Personal: https://wingware.com/downloads/wing-personal/7.1/binaries Wing 101: https://wingware.com/downloads/wing-101/7.1/binaries Compare Products: https://wingware.com/downloads See Upgrading https://wingware.com/doc/install/upgrading for details on upgrading from Wing 6 and earlier, and Migrating from Older Versions https://wingware.com/doc/install/migrating for a list of compatibility notes. From tjreedy at udel.edu Fri Nov 15 16:06:46 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 15 Nov 2019 16:06:46 -0500 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> Message-ID: On 11/15/2019 5:48 AM, R.Wieser wrote: >> Closures are standard in functional languages and are less limited than >> you seem to think. > > I was talking about the "nonlocal" method of variable inheritance, not > closures. You cannot really separate the two. A 'nonlocal' declaration can only be used in a nested function, and when you do, the function becomes a closure (a function with a '__closure__' attribute that is not None). -- Terry Jan Reedy From drsalists at gmail.com Fri Nov 15 16:11:19 2019 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 15 Nov 2019 13:11:19 -0800 Subject: Speeding up a test process with a local pypi and/or web proxy? Message-ID: Hi folks. I'm looking at a test process that takes about 16 minutes for a full run. Naturally, I'd like to speed it up. We've already parallelized it - mostly. It seems like the next thing to look at is setting up a local pypi, and building some of the packages that're compiled from C/C++ every time we do a full test run. (We're using docker and building dependencies for each full test run) Also, we could conceivably set up a web proxy...? Does having a local pypi obviate the web proxy? And what local pypi servers do folks recommend for speed? We need support mostly for CPython 3.x, but we still have a little CPython 2.x we require, and it's possible we'll need the 2.x for a while. Thanks! From drsalists at gmail.com Fri Nov 15 16:34:26 2019 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 15 Nov 2019 13:34:26 -0800 Subject: What do you use for slides? In-Reply-To: References: Message-ID: I mostly use Libreoffice Impress, but I've also tried Google Slides. I don't think Impress does syntax highlighting out of the box, but there's a plugin that claims to. Also, Google Slides purportedly supports highlighting just by cut-and-pasting from a GUI editor/IDE with syntax highlighting. HTH. On Fri, Nov 15, 2019 at 9:38 AM Abdur-Rahmaan Janhangeer < arj.python at gmail.com> wrote: > Greetings all, > > For slides i use https://yhatt.github.io/marp/, but sometimes i want a > more > stylish tool. > > What do you use for slides? (besides powerpoint + syntax highlighting > included) > > Thanks! > > Abdur-Rahmaan Janhangeer > http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ > Mauritius > -- > https://mail.python.org/mailman/listinfo/python-list > From maillist at schwertberger.de Fri Nov 15 14:32:44 2019 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Fri, 15 Nov 2019 20:32:44 +0100 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: <97c573af-e6cb-e33b-82af-e19e12e84784@cinege.com> Message-ID: On 14.11.2019 21:00, R.Wieser wrote: > There is a small 433 MHz rf transmitter connected to the pin, and when I > send the right pattern a wireless wall-wart will respond and switch a lamp > on or off. Its just ment as an example of a real-world application of > Python, nothing serious. I would assume that this is not an application that needs to output a 100% correct pulse train every time. (Based on the assumption that the telegrams for on and off are different enough.) You may just repeat the pattern ten times to be safe enough. Combine it with a light sensor for feedback ;-) Btw. you may want to increase the priority of your task. I'm using this code on my Raspi to reduce the interference of other processes with my media player using Python with gstreamer: os.system( "sudo renice -15 -p %d"%os.getpid() ) Anyway, Micropython on a microcontroller would probably be the best solution. Regards, Dietmar From greg.ewing at canterbury.ac.nz Sat Nov 16 01:36:19 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 16 Nov 2019 19:36:19 +1300 Subject: nonlocal fails ? In-Reply-To: References: <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> <3cstselr3975og769d3paiftjpn7nuv20u@4ax.com> Message-ID: On 16/11/19 8:22 am, Chris Angelico wrote: > That's the typical sort of description you get from someone who mostly > understands Python's semantics, but is hung up on the idea that > everything is either call-by-value or call-by-reference, and is trying > to figure out which box Python fits into. Or they may have read the definition of "call by value" in the Algol60 report, which says that "The actual parameter expression is evaluated and the result is assigned to the formal parameter." Which is exactly what Python does... (Notably, that definition doesn't contain the word "value" at all. So people who argue about the meaning of "call by value" based on the meaning of "value" are barking in the wrong direction.) -- Greg From rosuav at gmail.com Sat Nov 16 02:11:36 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Nov 2019 18:11:36 +1100 Subject: nonlocal fails ? In-Reply-To: References: <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> <3cstselr3975og769d3paiftjpn7nuv20u@4ax.com> Message-ID: On Sat, Nov 16, 2019 at 5:41 PM Gregory Ewing wrote: > > On 16/11/19 8:22 am, Chris Angelico wrote: > > That's the typical sort of description you get from someone who mostly > > understands Python's semantics, but is hung up on the idea that > > everything is either call-by-value or call-by-reference, and is trying > > to figure out which box Python fits into. > > Or they may have read the definition of "call by value" in the > Algol60 report, which says that "The actual parameter expression > is evaluated and the result is assigned to the formal parameter." > Which is exactly what Python does... > This is 100% true, but actually just punts on the question of "call-by-X". All the subtleties are bound up in this little bit: > the result is **assigned** to the formal parameter Which is actually a really REALLY good way to start peeling things back. In Python - and in many many other languages - the semantics of function calls can be summarized as assignment. You evaluate an expression in the caller's context, and assign the result to a local name in the callee's context. So far, C and Python both have the exact same semantics. So the real question is: What is assignment? And that's where everything about name binding comes in. In C, that assignment operates on a bit-copying level, cloning some value (which might be a pointer). In Python, that same assignment operates as a name binding, giving the target a reference to some particular object. ChrisA From address at not.available Sat Nov 16 02:12:22 2019 From: address at not.available (R.Wieser) Date: Sat, 16 Nov 2019 08:12:22 +0100 Subject: How to delay until a next increment of time occurs ? References: <97c573af-e6cb-e33b-82af-e19e12e84784@cinege.com> Message-ID: Dietmar, > I would assume that this is not an application that needs to output a 100% > correct pulse train every time. Correct. Thats in the design of the pulses themselves (25% duticycle for one state, 75% for the other. Lots of leeway, and self synchronising) > You may just repeat the pattern ten times to be safe enough. :-) I was already doing exactly that. > Combine it with a light sensor for feedback ;-) Well ... I see a few problems with that. Some when I would keep the light sensor next to the Pi, and others when I place it next to the lamp. :-p > Btw. you may want to increase the priority of your task. ... > os.system( "sudo renice -15 -p %d"%os.getpid() ) Thanks. That should help the reduce the jitter. > Anyway, Micropython on a microcontroller would probably be the best > solution. My language of choice would probably be Assembly, but yes. An (atmel) attiny16 (8 pin, 5 free to use) should be enough for it. But .... first experiment the heck outof the Pi to see how well it can do on its own. :-) Regards, Rudy Wieser From veek at dont-use-this.com Sat Nov 16 09:19:09 2019 From: veek at dont-use-this.com (Veek M) Date: Sat, 16 Nov 2019 14:19:09 -0000 (UTC) Subject: multiprocessing article on PYMOTW - subclassing with 'def run' and 'logging' Message-ID: https://pymotw.com/2/multiprocessing/basics.html https://pymotw.com/2/threading/ I didn't follow this 1. >The logger can also be configured through the logging configuration file >API, using the name multiprocessing. and 2. >it is also possible to use a custom subclass. > import multiprocessing > class Worker(multiprocessing.Process): > def run(self): > print 'In %s' % self.name > return therefore, how is 'def run' going to start a process? 'run' may be autocalled same as in 'threading' but in threading, the function is the Thread.. so you can do your work in def run: and expect it to be suitably threaded whereas here.. does he somehow magically convert a function to a process? From m.navti at gmail.com Sat Nov 16 09:20:23 2019 From: m.navti at gmail.com (m.navti at gmail.com) Date: Sat, 16 Nov 2019 06:20:23 -0800 (PST) Subject: Storing data in queue Message-ID: <080ca037-f8ca-4216-b9ab-5912bfdf65c5@googlegroups.com> Hello guys I am struggling here and need help. How can I store sqlite3 database or a table in a queue. #help From george at fischhof.hu Sat Nov 16 14:07:15 2019 From: george at fischhof.hu (George Fischhof) Date: Sat, 16 Nov 2019 20:07:15 +0100 Subject: What do you use for slides? In-Reply-To: References: Message-ID: Dan Stromberg ezt ?rta (id?pont: 2019. nov. 15., P, 22:36): > I mostly use Libreoffice Impress, but I've also tried Google Slides. > > I don't think Impress does syntax highlighting out of the box, but there's > a plugin that claims to. > > Also, Google Slides purportedly supports highlighting just by > cut-and-pasting from a GUI editor/IDE with syntax highlighting. > > HTH. > > On Fri, Nov 15, 2019 at 9:38 AM Abdur-Rahmaan Janhangeer < > arj.python at gmail.com> wrote: > > > Greetings all, > > > > For slides i use https://yhatt.github.io/marp/, but sometimes i want a > > more > > stylish tool. > > > > What do you use for slides? (besides powerpoint + syntax highlighting > > included) > > > > Thanks! > > > > Abdur-Rahmaan Janhangeer > > http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ > > Mauritius > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list Hi I use Google drive's slides, plus https://revealjs.com/ br, George From cs at cskk.id.au Sat Nov 16 17:30:37 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 17 Nov 2019 09:30:37 +1100 Subject: Storing data in queue In-Reply-To: <080ca037-f8ca-4216-b9ab-5912bfdf65c5@googlegroups.com> References: <080ca037-f8ca-4216-b9ab-5912bfdf65c5@googlegroups.com> Message-ID: <20191116223037.GA64821@cskk.homeip.net> On 16Nov2019 06:20, m.navti at gmail.com wrote: >Hello guys I am struggling here and need help. How can I store sqlite3 database or a table in a queue. #help You need to provide more information here. Are you talking about a python stdlib Queue object, for queuing in-memory objects for processing (eg to process them, maybe to apply their state to a database)? Are you trying to use a database table as a queue? Please describe the larger problem you're solving, and ideally a piece of code you've written which isn't solving your problem (unless you have no idea where to start, in which case: describe the problem in more detail). Remember that this is a text only list, so no attachments. Code should be pasted inline in the message. Cheers, Cameron Simpson From veek at dont-use-this.com Sun Nov 17 00:47:49 2019 From: veek at dont-use-this.com (Veek M) Date: Sun, 17 Nov 2019 05:47:49 -0000 (UTC) Subject: multiprocessing article on PYMOTW - subclassing with 'def run' and 'logging' References: Message-ID: answered here https://www.reddit.com/r/Python/comments/dxhgec/ how_does_multiprocessing_convert_a_methodrun_in/ basically starts two PVMs - the whole fork, check 'pid' trick.. one process continues as the main thread and the other calls 'run' From random832 at fastmail.com Sun Nov 17 01:33:35 2019 From: random832 at fastmail.com (Random832) Date: Sun, 17 Nov 2019 01:33:35 -0500 Subject: nonlocal fails ? In-Reply-To: References: <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> <0b2ba947-38ad-8e4d-782e-7a96a5d913b3@Damon-Family.org> <2313f803-8453-44cf-977d-30e4694d4950@www.fastmail.com> <516da304-39c0-f75e-4b51-7aea584902c7@Damon-Family.org> Message-ID: <9f1d62e3-24c6-4959-acd6-15d26d6e0567@www.fastmail.com> On Fri, Nov 15, 2019, at 13:41, Dennis Lee Bieber wrote: > C# documents those as something visible to the user at the language > level... > https://www.infoworld.com/article/3043992/a-deep-dive-value-and-reference-types-in-net.html > """ > Types in Microsoft .Net can be either value type or reference type. > """ I was strictly talking about how reference types work (which are just like python or Java objects), and how that is completely distinct from the "ref" of call-by-reference arguments which are also supported, and that both features coexist just fine in the same language. The existence of value types wasn't really relevant to my point. I'm not sure if you were left with the impression that you can't have a "ref" argument that points to a variable of reference type (and which does *not* point directly to the object), but that is false. > Similar to Java. Well, Java doesn't have user-defined value types, but again, value types are beside the point. From iranna.gani28 at gmail.com Sun Nov 17 01:56:53 2019 From: iranna.gani28 at gmail.com (Iranna Mathapati) Date: Sun, 17 Nov 2019 12:26:53 +0530 Subject: how to remove duplicates dict from the list of dictionary based on one of the elements is duplicate in list of dict Message-ID: Hi, How to remove duplicates dict from the list of dictionary based on one of the duplicate elements in the dictionary, l = [{"component":"software", "version":"1.2" }, {"component":"hardware", "version":"2.2",}, {"component":"driver", "version":"3.2",}, {"component":"firmware", "version":"4.2",}, {"component":"software", "version":"1.9",}, {"component":"hardware", "version":"2.7",} ] need to remove the dict if having same components [in the above example components "software" and "hardware" is duplicated twice expected output: [{"component":"software", "version":"1.2" }, {"component":"hardware", "version":"2.2",}, {"component":"driver", "version":"3.2",}, {"component":"firmware", "version":"4.2",} ] From cs at cskk.id.au Sun Nov 17 02:12:48 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 17 Nov 2019 18:12:48 +1100 Subject: how to remove duplicates dict from the list of dictionary based on one of the elements is duplicate in list of dict In-Reply-To: References: Message-ID: <20191117071248.GA71009@cskk.homeip.net> On 17Nov2019 12:26, Iranna Mathapati wrote: >How to remove duplicates dict from the list of dictionary based on one >of >the duplicate elements in the dictionary, > >l = [{"component":"software", "version":"1.2" }, > {"component":"hardware", "version":"2.2",}, > {"component":"driver", "version":"3.2",}, > {"component":"firmware", "version":"4.2",}, > {"component":"software", "version":"1.9",}, > {"component":"hardware", "version":"2.7",} > ] > >need to remove the dict if having same components [in the above example >components "software" and "hardware" is duplicated twice > >expected output: > > [{"component":"software", "version":"1.2" }, > {"component":"hardware", "version":"2.2",}, > {"component":"driver", "version":"3.2",}, > {"component":"firmware", "version":"4.2",} > ] I would be inclined to keep a mapping (eg another dict) keyed on the value of "component". When you process these lists, put the component/version dicts into the appropriate entry in the new dict. If an entry is already there, act appropriately (eg keep the existing entry, keep the new entry, compare the entries in some way and keep the "better" one, etc). Then at the end, walk the new dict and make a fresh list. Not providing example code because this feels a little homeworky, so we expect you to attempt the code first. Cheers, Cameron Simpson From Richard at Damon-Family.org Sun Nov 17 07:26:28 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 17 Nov 2019 07:26:28 -0500 Subject: nonlocal fails ? In-Reply-To: <9f1d62e3-24c6-4959-acd6-15d26d6e0567@www.fastmail.com> References: <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> <0b2ba947-38ad-8e4d-782e-7a96a5d913b3@Damon-Family.org> <2313f803-8453-44cf-977d-30e4694d4950@www.fastmail.com> <516da304-39c0-f75e-4b51-7aea584902c7@Damon-Family.org> <9f1d62e3-24c6-4959-acd6-15d26d6e0567@www.fastmail.com> Message-ID: On 11/17/19 1:33 AM, Random832 wrote: > On Fri, Nov 15, 2019, at 13:41, Dennis Lee Bieber wrote: >> C# documents those as something visible to the user at the language >> level... >> https://www.infoworld.com/article/3043992/a-deep-dive-value-and-reference-types-in-net.html >> """ >> Types in Microsoft .Net can be either value type or reference type. >> """ > I was strictly talking about how reference types work (which are just like python or Java objects), and how that is completely distinct from the "ref" of call-by-reference arguments which are also supported, and that both features coexist just fine in the same language. The existence of value types wasn't really relevant to my point. > > I'm not sure if you were left with the impression that you can't have a "ref" argument that points to a variable of reference type (and which does *not* point directly to the object), but that is false. I am not sure about C#, but in C++, a base language for C#, you can not take the address of a variable of reference type, if you do, you get the objected referred to, not the reference. References are essentially constant pointers, and can not be re-seated to reference another object. I suppose one way at looking at Python's name binding system (maybe not entirely accurate) would be to say that all Python names act like references, but that assignment, rather than being applied to the referred to object, re-seat the reference to point to the new object. As such, you can't get a reference to the name, to let one name re-seat where another name refers to. -- Richard Damon From antoon.pardon at rece.vub.ac.be Sun Nov 17 08:18:42 2019 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Sun, 17 Nov 2019 14:18:42 +0100 Subject: low-level csv Message-ID: <3e06da21-0714-4add-6441-a594e26ed42c@rece.vub.ac.be> This is python 2.6->2.7 and 3.5->3.7 I need to convert a string that is a csv line to a list and vice versa. I thought to find functions doing this in the csv module but that doesn't seem to be the case. I can of course write special classes that would allow for this using a csv.reader and csv.writer but that would be some convoluted code. Anyone some suggestions? -- Antoon Pardon. From 2QdxY4RzWzUUiLuE at potatochowder.com Sun Nov 17 09:28:58 2019 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Sun, 17 Nov 2019 08:28:58 -0600 Subject: low-level csv In-Reply-To: <3e06da21-0714-4add-6441-a594e26ed42c@rece.vub.ac.be> References: <3e06da21-0714-4add-6441-a594e26ed42c@rece.vub.ac.be> Message-ID: On 11/17/19 7:18 AM, Antoon Pardon wrote: > This is python 2.6->2.7 and 3.5->3.7 > > I need to convert a string that is a csv line to a list and vice versa. > I thought to find functions doing this in the csv module but that doesn't > seem to be the case. > > I can of course write special classes that would allow for this using > a csv.reader and csv.writer but that would be some convoluted code. > > Anyone some suggestions? Wrap your string in a list; csv.reader takes an iterator: s = "some, string, with, commas" r = csv.reader([s]) for x in r: print x Dan From skip.montanaro at gmail.com Sun Nov 17 09:50:11 2019 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sun, 17 Nov 2019 08:50:11 -0600 Subject: low-level csv In-Reply-To: <3e06da21-0714-4add-6441-a594e26ed42c@rece.vub.ac.be> References: <3e06da21-0714-4add-6441-a594e26ed42c@rece.vub.ac.be> Message-ID: On Sun, Nov 17, 2019 at 7:23 AM Antoon Pardon wrote: > > This is python 2.6->2.7 and 3.5->3.7 > > I need to convert a string that is a csv line to a list and vice versa. > I thought to find functions doing this in the csv module but that doesn't > seem to be the case. Take a look at the test cases for the csv module. I'm fairly sure all the inputs for the tests are actually embedded strings. Basically, just initialize a StringIO object with your string and pass it to the csv.reader() call. Here's a quick example from the REPL (Python 3.7): >>> raw = "a,b,c\r\n1,2,3\r\nhowdy,neighbor!\n" >>> raw 'a,b,c\r\n1,2,3\r\nhowdy,neighbor!\n' >>> import io >>> inp = io.StringIO(raw) >>> import csv >>> for row in csv.reader(inp): ... print(row) ... ['a', 'b', 'c'] ['1', '2', '3'] ['howdy', 'neighbor!'] Skip From hongyi.zhao at gmail.com Sun Nov 17 09:50:56 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Sun, 17 Nov 2019 14:50:56 +0000 (UTC) Subject: revise "([^/]+)$" into '([^/]+)$' in a lot of files under a directory. Message-ID: Hi, I have a lot of files which resides under a directory, and I want to resive all of the content "([^/]+)$" in these files into '([^/]+)$'. I have tried with sed/xargs, but it seems so difficult for dealing with the \ , is there any convinent method to to this job with python? Regards From pieter-l at vanoostrum.org Sun Nov 17 12:39:56 2019 From: pieter-l at vanoostrum.org (Pieter van Oostrum) Date: Sun, 17 Nov 2019 18:39:56 +0100 Subject: revise "([^/]+)$" into '([^/]+)$' in a lot of files under a directory. References: Message-ID: Hongyi Zhao writes: > Hi, > > I have a lot of files which resides under a directory, and I want to > resive all of the content "([^/]+)$" in these files into '([^/]+)$'. > > I have tried with sed/xargs, but it seems so difficult for dealing with > the \ , is there any convinent method to to this job with python? > > Regards It isn't that difficult with sed, only you have to chose a different character than / in the substitute command, one that is not present in both texts, e.g instead of s/a/b/ use s=a=b=. And then the special characters " ' () [ and $ must be escaped for the shell, and [ and $ also for the regexp. Then it comes down to sed -e s=\"\(\\[^/]+\)\\$\"=\'\(\[^/]+\)\$\'= file -- Pieter van Oostrum WWW: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From barry at barrys-emacs.org Sun Nov 17 13:30:46 2019 From: barry at barrys-emacs.org (Barry Scott) Date: Sun, 17 Nov 2019 18:30:46 +0000 Subject: How to delay until a next increment of time occurs ? In-Reply-To: <5423bc5d-3ba9-01cc-85e8-c3a0d00cb33d@schwertberger.de> References: <5423bc5d-3ba9-01cc-85e8-c3a0d00cb33d@schwertberger.de> Message-ID: <312FB0CF-9650-453A-800C-9A627A29240A@barrys-emacs.org> > On 13 Nov 2019, at 22:36, Dietmar Schwertberger wrote: > > On 13.11.2019 23:20, Dennis Lee Bieber wrote: >> For Windows it may require coding a busy-wait sleep function using the >> high-performance counter and computing a counter value (modulo?) on which >> to exit the loop. > time.perf_counter() is using this on Windows. I'm just worried about floating point limitations on older Python versions. > > From Python 3.7 onwards, there's time.perf_counter_ns(), but even then it would be nice if it was just possible to reset the perf_counter. Reseting things like timers is often a problem. What if there are two pieces of code using the value of the perf_counter? If one use resets the timer then the other user will be broken. Barry > > Regards, > > Dietmar > > -- > https://mail.python.org/mailman/listinfo/python-list > From barry at barrys-emacs.org Sun Nov 17 13:27:45 2019 From: barry at barrys-emacs.org (Barry Scott) Date: Sun, 17 Nov 2019 18:27:45 +0000 Subject: Launching a Script on the Linux Platform In-Reply-To: References: Message-ID: > On 12 Nov 2019, at 20:24, Wildman via Python-list wrote: > > Yes, I prefer to envoke env in the shebang line instead of > depending on the path. Paths can change especially in a > multi-user system but env will always know where to find > the executable. The path to python will not change surely? Because you are installing from a deb you know the exact path to the python you need to use. There is no need to use the /usr/bin/env to search the path and potential break your code, because a version of python that you do not expect is on the path. Barry From pieter-l at vanoostrum.org Sun Nov 17 14:28:55 2019 From: pieter-l at vanoostrum.org (Pieter van Oostrum) Date: Sun, 17 Nov 2019 20:28:55 +0100 Subject: revise "([^/]+)$" into '([^/]+)$' in a lot of files under a directory. References: Message-ID: Pieter van Oostrum writes: > It isn't that difficult with sed, only you have to chose a different > character than / in the substitute command, one that is not present in > both texts, e.g instead of s/a/b/ use s=a=b=. > > And then the special characters " ' () [ and $ must be escaped for the > shell, and [ and $ also for the regexp. > Then it comes down to > sed -e s=\"\(\\[^/]+\)\\$\"=\'\(\[^/]+\)\$\'= file To be honest, I myself would use Emacs, with rgrep and wgrep to do this. -- Pieter van Oostrum WWW: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From dave at cinege.com Sun Nov 17 15:30:07 2019 From: dave at cinege.com (Dave Cinege) Date: Sun, 17 Nov 2019 15:30:07 -0500 Subject: low-level csv In-Reply-To: <3e06da21-0714-4add-6441-a594e26ed42c@rece.vub.ac.be> References: <3e06da21-0714-4add-6441-a594e26ed42c@rece.vub.ac.be> Message-ID: The few times I looked at CSV module it never looked useful to me. I seem to use shlex for everything. For example: def csv_split (s): lex = shlex.shlex(s, posix=True) lex.whitespace_split = True lex.whitespace = ',' return list(lex) will split on commas while honoring quoted values (and stripping out the quotes) Dave On 2019/11/17 08:18, Antoon Pardon wrote: > This is python 2.6->2.7 and 3.5->3.7 > > I need to convert a string that is a csv line to a list and vice versa. > I thought to find functions doing this in the csv module but that doesn't > seem to be the case. > > I can of course write special classes that would allow for this using > a csv.reader and csv.writer but that would be some convoluted code. > > Anyone some suggestions? > From greg.ewing at canterbury.ac.nz Sun Nov 17 17:58:13 2019 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 18 Nov 2019 11:58:13 +1300 Subject: low-level csv In-Reply-To: References: <3e06da21-0714-4add-6441-a594e26ed42c@rece.vub.ac.be> Message-ID: On 18/11/19 9:30 am, Dave Cinege wrote: > The few times I looked at CSV module it never looked useful to me. I > seem to use shlex for everything. For example: > > def csv_split (s): > ????lex = shlex.shlex(s, posix=True) > ????lex.whitespace_split = True > ????lex.whitespace = ',' > ????return list(lex) That won't always work. CSV and sh are not quite the same language. For example, Excel embeds quotes in quoted fields by doubling them, whereas in sh you escape them with backslashes. You can get away with it if you know your data doesn't contain any of these cases, but generally it's easier and safer to use the csv module for csv. -- Greg From hongyi.zhao at gmail.com Sun Nov 17 23:58:02 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Mon, 18 Nov 2019 04:58:02 +0000 (UTC) Subject: revise "([^/]+)$" into '([^/]+)$' in a lot of files under a directory. References: Message-ID: On Sun, 17 Nov 2019 20:28:55 +0100, Pieter van Oostrum wrote: > To be honest, I myself would use Emacs, with rgrep and wgrep to do this. Are these tools superior to grep? Regards From random832 at fastmail.com Mon Nov 18 02:44:39 2019 From: random832 at fastmail.com (Random832) Date: Mon, 18 Nov 2019 02:44:39 -0500 Subject: nonlocal fails ? In-Reply-To: References: <1b91d027-0a25-538d-02f1-486dc011a8e4@gmail.com> <0b2ba947-38ad-8e4d-782e-7a96a5d913b3@Damon-Family.org> <2313f803-8453-44cf-977d-30e4694d4950@www.fastmail.com> <516da304-39c0-f75e-4b51-7aea584902c7@Damon-Family.org> <9f1d62e3-24c6-4959-acd6-15d26d6e0567@www.fastmail.com> Message-ID: <3540b186-0b60-40aa-8fed-52cededcfbaa@www.fastmail.com> On Sun, Nov 17, 2019, at 07:26, Richard Damon wrote: > I am not sure about C#, but in C++, a base language for C#, you can not > take the address of a variable of reference type, if you do, you get the > objected referred to, not the reference. References are essentially > constant pointers, and can not be re-seated to reference another object. C# is not very closely related to C++, calling it "a base language" would be inaccurate IMO. It's much more similar to Java in many ways. In particular, its "reference types" have absolutely nothing to do with C++'s references. They're much more similar to Java or Python object types. The "ref" references used for call-by-reference arguments are much more similar to C++ references [and there's no analogous feature in Java], but somewhat more restricted (they can't be used as a member of a class, for example) The ability to make a "ref" reference to a variable of reference type is analogous to being able to make a reference to a pointer in C++, even though C#/Java/Python object references are not really the same things as pointers due to e.g. not having pointer arithmetic, etc. (the C++ .NET compatibility layer calls these 'handles', and uses the ^ character for them. The "ref" variables themselves use a % character, since they have to be distinct from &-references due to their role in the .NET garbage collection system) > I suppose one way at looking at Python's name binding system (maybe not > entirely accurate) would be to say that all Python names act like > references, but that assignment, rather than being applied to the > referred to object, re-seat the reference to point to the new object. As > such, you can't get a reference to the name, to let one name re-seat > where another name refers to. I guess if anything this discussion has proven to me that C#'s decision to use "reference" for two unrelated concepts in fact causes more confusion than I thought it would from the perspective of the amount of .NET experience I have. However, my point was that the basic idea of pass by reference, even if it should be called something else (if implemented in Python it would probably use cell objects as "references", with some other kind of wrapper object being needed to handle the case of the target not being a local variable) is not fundamentally inapplicable to Python just because of the object reference model. Call by cell? Call by getter/setter? There's an old saying that one of the hardest problems in computer science is naming things. From address at not.available Mon Nov 18 02:52:07 2019 From: address at not.available (R.Wieser) Date: Mon, 18 Nov 2019 08:52:07 +0100 Subject: Writing a CPython extension - calling another sibbling method ? Message-ID: Hello all, I'm trying to edit a binary extension to Python, and have a situation where I would like to create method which adds a single argument, and than jumps to / calls another method. Like this: static PyObject *py_proc1(PyObject *self, PyObject *args) { .... Py_RETURN_NONE } static PyObject *py_proc2(PyObject *self, PyObject *args) { // call py_proc1 to with "foo" prepended to "args" } I have no idea how I should do either the call or the adding of that argument (and going to a few examples I've found googeling didn't show me the answer either). Than again, I'm not even sure if the "foo" needs to be prepended, or if that "py_proc1" method can receive more than a single "args" argument ... Like this perhaps: static PyObject *py_proc1(PyObject *self, int MyNewArgument, PyObject *args) { .... } I've also tried to go the C way (just calling, from "py_proc2", a C function containing "py_proc1"s code), but I got lots of errors, most of them in the realm of the different returns not being of the same type (no idea why it doesn't complain about it in the origional "py_proc1" code itself though). tl;dr: I could use some examples that show how to work withl PyObject subfunctions. Regards, Rudy Wieser P.s. Yes, this is related to my earlier questions and problems. From pieter-l at vanoostrum.org Mon Nov 18 05:04:46 2019 From: pieter-l at vanoostrum.org (Pieter van Oostrum) Date: Mon, 18 Nov 2019 11:04:46 +0100 Subject: revise "([^/]+)$" into '([^/]+)$' in a lot of files under a directory. References: Message-ID: Hongyi Zhao writes: > On Sun, 17 Nov 2019 20:28:55 +0100, Pieter van Oostrum wrote: > >> To be honest, I myself would use Emacs, with rgrep and wgrep to do this. > > Are these tools superior to grep? They are based on grep. But rgrep does a grep through a whole directory tree, or a selection thereof, specified by a file pattern. The wgrep allows you to edit the grep output, for example just changing "([^/]+)$" to '([^/]+)$'. And then you let it write the changes back to those files. The advantage is that you see what you are doing. But now this has become off-topic with regard to Python. -- Pieter van Oostrum WWW: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From best_lay at yahoo.com Mon Nov 18 13:04:01 2019 From: best_lay at yahoo.com (Wildman) Date: Mon, 18 Nov 2019 12:04:01 -0600 Subject: Launching a Script on the Linux Platform References: Message-ID: On Sun, 17 Nov 2019 18:27:45 +0000, Barry Scott wrote: >> On 12 Nov 2019, at 20:24, Wildman via Python-list wrote: >> >> Yes, I prefer to envoke env in the shebang line instead of >> depending on the path. Paths can change especially in a >> multi-user system but env will always know where to find >> the executable. > > The path to python will not change surely? In Linux, being a multi-user OS, the path is not global or system wide. The path can be different for different users. This is done by adding an EXPORT command to ~/.bashrc. > Because you are installing from a deb you know the exact path to the python you > need to use. There is no need to use the /usr/bin/env to search the path and > potential break your code, because a version of python that you do not expect is on > the path. > > Barry I don't understand. The deb does not install python so I fail to see how I would know the exact path. As to env breaking my code, never heard of such a thing. -- GNU/Linux user #557453 "There are only 10 types of people in the world... those who understand Binary and those who don't." -Spike From rosuav at gmail.com Mon Nov 18 13:09:07 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Nov 2019 05:09:07 +1100 Subject: Launching a Script on the Linux Platform In-Reply-To: References: Message-ID: On Tue, Nov 19, 2019 at 5:06 AM Wildman via Python-list wrote: > > On Sun, 17 Nov 2019 18:27:45 +0000, Barry Scott wrote: > > >> On 12 Nov 2019, at 20:24, Wildman via Python-list wrote: > >> > >> Yes, I prefer to envoke env in the shebang line instead of > >> depending on the path. Paths can change especially in a > >> multi-user system but env will always know where to find > >> the executable. > > > > The path to python will not change surely? > > In Linux, being a multi-user OS, the path is not global or > system wide. The path can be different for different users. > This is done by adding an EXPORT command to ~/.bashrc. > > > Because you are installing from a deb you know the exact path to the python you > > need to use. There is no need to use the /usr/bin/env to search the path and > > potential break your code, because a version of python that you do not expect is on > > the path. > > > > Barry > > I don't understand. The deb does not install python so I > fail to see how I would know the exact path. > > As to env breaking my code, never heard of such a thing. > The deb should depend on an appropriate Python package. Then you can assume and expect that this version of Python is installed. ChrisA From python at mrabarnett.plus.com Mon Nov 18 14:32:22 2019 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 18 Nov 2019 19:32:22 +0000 Subject: Writing a CPython extension - calling another sibbling method ? In-Reply-To: References: Message-ID: <47e7cf54-51ed-1a92-f284-5e95a7a03396@mrabarnett.plus.com> On 2019-11-18 07:52, R.Wieser wrote: > Hello all, > > I'm trying to edit a binary extension to Python, and have a situation where > I would like to create method which adds a single argument, and than jumps > to / calls another method. Like this: > > static PyObject *py_proc1(PyObject *self, PyObject *args) > { > .... > Py_RETURN_NONE > } > > static PyObject *py_proc2(PyObject *self, PyObject *args) > { > // call py_proc1 to with "foo" prepended to "args" > } > > I have no idea how I should do either the call or the adding of that > argument (and going to a few examples I've found googeling didn't show me > the answer either). > > Than again, I'm not even sure if the "foo" needs to be prepended, or if that > "py_proc1" method can receive more than a single "args" argument ... Like > this perhaps: > > static PyObject *py_proc1(PyObject *self, int MyNewArgument, PyObject *args) > { > .... > } > > I've also tried to go the C way (just calling, from "py_proc2", a C function > containing "py_proc1"s code), but I got lots of errors, most of them in the > realm of the different returns not being of the same type (no idea why it > doesn't complain about it in the origional "py_proc1" code itself though). > > tl;dr: > I could use some examples that show how to work withl PyObject subfunctions. > > Regards, > Rudy Wieser > > P.s. > Yes, this is related to my earlier questions and problems. > One possibility is to refactor the code so that py_proc1 and py_proc2 themselves just handle their arguments and then call the function that does the actual work. A clunkier way would be to make a new tuple that consists of the prepended item and the items of args and pass that to py_proc1 as its args. When py_proc1 returns its result object, DECREF the new tuple to clean up and then return the result object. From address at not.available Mon Nov 18 15:15:27 2019 From: address at not.available (R.Wieser) Date: Mon, 18 Nov 2019 21:15:27 +0100 Subject: Writing a CPython extension - calling another sibbling method ? References: <47e7cf54-51ed-1a92-f284-5e95a7a03396@mrabarnett.plus.com> Message-ID: MRAB, > One possibility is to refactor the code so that py_proc1 and py_proc2 > themselves just handle their arguments and then call the function that > does the actual work. The thing is that the arguments of py_proc1 and py_proc2 are the same, but for a single argument. Which means that letting both of them first parse their own arguments means duplicated code. Which I do not really want and thus try to evade But yes, that is a possibility too. The "the function that does the actual work" part is what I tried to describe with my second example. > A clunkier way would be to make a new tuple that consists of the prepended > item and the items of args and pass that to py_proc1 as its args. That is what I tried to describe with my first example. The thing is I have no clue about what the above calling should look like (though I think I already found how to append my argument to the "args" string-object). In other words, do you have any idea of what either of those calling methods should look like ? An example perhaps ? Having only encountered the CPython API two days ago I'm still fumbling in the dark I'm afraid. Regards, Rudy Wieser From best_lay at yahoo.com Mon Nov 18 16:01:57 2019 From: best_lay at yahoo.com (Wildman) Date: Mon, 18 Nov 2019 15:01:57 -0600 Subject: Launching a Script on the Linux Platform References: Message-ID: On Tue, 19 Nov 2019 05:09:07 +1100, Chris Angelico wrote: > On Tue, Nov 19, 2019 at 5:06 AM Wildman via Python-list > wrote: >> >> On Sun, 17 Nov 2019 18:27:45 +0000, Barry Scott wrote: >> >> >> On 12 Nov 2019, at 20:24, Wildman via Python-list wrote: >> >> >> >> Yes, I prefer to envoke env in the shebang line instead of >> >> depending on the path. Paths can change especially in a >> >> multi-user system but env will always know where to find >> >> the executable. >> > >> > The path to python will not change surely? >> >> In Linux, being a multi-user OS, the path is not global or >> system wide. The path can be different for different users. >> This is done by adding an EXPORT command to ~/.bashrc. >> >> > Because you are installing from a deb you know the exact path to the python you >> > need to use. There is no need to use the /usr/bin/env to search the path and >> > potential break your code, because a version of python that you do not expect is on >> > the path. >> > >> > Barry >> >> I don't understand. The deb does not install python so I >> fail to see how I would know the exact path. >> >> As to env breaking my code, never heard of such a thing. >> > > The deb should depend on an appropriate Python package. Then you can > assume and expect that this version of Python is installed. > > ChrisA Yes, of course, python(3) is listed as a "depends" in the deb control file. That does insure that python is installed but in no way does that tell me the path of the python executable. -- GNU/Linux user #557453 "Be at war with your vices, at peace with your neighbors and let every new year find you a better man." -Benjamin Franklin From python at mrabarnett.plus.com Mon Nov 18 16:11:02 2019 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 18 Nov 2019 21:11:02 +0000 Subject: Writing a CPython extension - calling another sibbling method ? In-Reply-To: References: <47e7cf54-51ed-1a92-f284-5e95a7a03396@mrabarnett.plus.com> Message-ID: <113c4444-b0d6-bc55-6f60-47f691dcb6b1@mrabarnett.plus.com> On 2019-11-18 20:15, R.Wieser wrote: > MRAB, > >> One possibility is to refactor the code so that py_proc1 and py_proc2 >> themselves just handle their arguments and then call the function that >> does the actual work. > > The thing is that the arguments of py_proc1 and py_proc2 are the same, but > for a single argument. Which means that letting both of them first parse > their own arguments means duplicated code. Which I do not really want and > thus try to evade > > But yes, that is a possibility too. The "the function that does the actual > work" part is what I tried to describe with my second example. > >> A clunkier way would be to make a new tuple that consists of the prepended >> item and the items of args and pass that to py_proc1 as its args. > > That is what I tried to describe with my first example. > > The thing is I have no clue about what the above calling should look like > (though I think I already found how to append my argument to the "args" > string-object). > > In other words, do you have any idea of what either of those calling methods > should look like ? An example perhaps ? Having only encountered the > CPython API two days ago I'm still fumbling in the dark I'm afraid. > It could be something like this: static PyObject *py_proc2(PyObject *self, PyObject *args) { /*** TODO: Add error checking. ***/ PyObject* prepend_arg; PyObject* prepend_tuple; PyObject* new_args; PyObject* result; /* The object to be prepended. */ prepend_arg = PyUnicode_FromString("foo"); /* Make a tuple from the prepended object. */ prepend_tuple = BuildValue("(O)", prepend_arg); /* No longer need prepend_arg. */ Py_DECREF(prepend_arg); /* Make the new argument list. */ new_args = PySequence_Concat(prepend, args); /* No longer need prepend_tuple. */ Py_DECREF(prepend_tuple); /* Call the other method. */ result = py_proc1(self, new_args); /* No longer need new_args. */ Py_DECREF(new_args); return result; } From hjp-python at hjp.at Mon Nov 18 16:15:31 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 18 Nov 2019 22:15:31 +0100 Subject: Launching a Script on the Linux Platform In-Reply-To: References: Message-ID: <20191118211531.GB4863@hjp.at> On 2019-11-18 15:01:57 -0600, Wildman via Python-list wrote: > On Tue, 19 Nov 2019 05:09:07 +1100, Chris Angelico wrote: > > On Tue, Nov 19, 2019 at 5:06 AM Wildman via Python-list > > wrote: > >> On Sun, 17 Nov 2019 18:27:45 +0000, Barry Scott wrote: > >> > Because you are installing from a deb you know the exact path to the python you > >> > need to use. There is no need to use the /usr/bin/env to search the path and > >> > potential break your code, because a version of python that you do not expect is on > >> > the path. > >> > >> I don't understand. The deb does not install python so I > >> fail to see how I would know the exact path. > >> > >> As to env breaking my code, never heard of such a thing. > >> > > > > The deb should depend on an appropriate Python package. Then you can > > assume and expect that this version of Python is installed. > > Yes, of course, python(3) is listed as a "depends" in the deb > control file. That does insure that python is installed but > in no way does that tell me the path of the python executable. The debian packaging guidelines tell you where the execuable has to be. If you install the python package you can be very sure that the executable will be in /usr/bin. And this is the executable you want to use. You don't want to use some other random program called "python" (which may or may not be an interpreter for some version of the Python language) which just happens to be in the user's path. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- 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 Nov 18 16:07:21 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 18 Nov 2019 22:07:21 +0100 Subject: Friday finking: TDD and EAFP In-Reply-To: <72492bd0-5789-b87d-2cb6-8f7c4ae19f20@DancesWithMice.info> References: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> <74263897-D40B-4EAD-957E-C1FF43A26F6F@gmail.com> <2500afa5-84ae-e5fc-a73c-4091681068e6@DancesWithMice.info> <20191103204437.GB3944@hjp.at> <72492bd0-5789-b87d-2cb6-8f7c4ae19f20@DancesWithMice.info> Message-ID: <20191118210721.GA4863@hjp.at> On 2019-11-13 15:16:55 +1300, DL Neil via Python-list wrote: > On 4/11/19 9:44 AM, Peter J. Holzer wrote: > > TDD does in my opinion encourage EAFP thinking. > > > > The TDD is usually: > > > > 1 Write a test > > 2 Write the minimal amount of code that makes the test pass > > 3 If you think you have covered the whole spec, stop, else repeat > > from 1 > > > > This is often (e.g. in [1]) exaggerated for pedagogic and humoristic > > reasons. For example, your first test for a sqrt function might be > > assert(sqrt(4) == 2) > > and then of course the minimal implementation is > > def sqrt(x): > > return 2 > > I have seen this sort of thing in spreadsheet training - someone pulling-out > a calculator, summing a column of numbers, and typing 'the answer' in the > "Total" cell (instead of using the Sigma button or @SUM() ). > > However, I've never seen anyone attempt to pass-off this sort of code > outside of desperate (and likely, far too late) floundering during a 101 > assignment - FAILED! > > Who would begin to believe that such code implements sqrt, or that it meets > with the function's objectives as laid-out in the spec AND the docstring? > So, anyone can prove anything - if they leave reality/reason far-enough > behind. I'm not a TDD expert, but my understanding is that this kind of thing is meant seriously. But of course it is not meant as a finished program. It is meant as a first step. And there is a reason for starting with an obviously incomplete solution: It makes you aware that your test suite is incomplete and your program is incomplete, and that you will have to improve both. If you write this simple test and then write a complete implementation of sqrt, there is a strong temptation to say "the code is complete, it looks correct, I have a test and 100 % code coverage; therefore I'm done". But of course you aren't - that one test case is woefully inadequate. As is demonstrated by writing a completely bogus implementation which passes the test. You say you write all the tests in advance (I read that as "try to write a reasonably complete test suite in advance"). That prevents the pitfall of writing only a few alibi tests. It also has the advantage that you are in a different mind set when writing tests than when writing code (almost as good as having someone else write the code). However, it means that you consider your tests to be complete when you start to write the code. So there is no feedback. If you forgot to include tests with non-integer results in your test suite (yes, I'm aware you wrote that quickly for a mailing-list posting and probably wouldn't make that mistake if you really wanted to implement sqrt), you probably won't think of it while writing the code, because now you are in the code-writing mindset, not the test-devising mindset. I think that tight feedback loop between writing a test and writing the *minimal* code which will pass the test has some value: You are constantly trying to outsmart yourself: When you are writing tests you try to cover a few more additional potential mistakes and when you are writing code you try to find loop-holes in your tests. > Great joke, but its proponents are delaying a proper consideration of TDD. I don't know what "proper" TDD is (and even less "proper consideration" of TDD), but TDD is in my opinion very much rooted in the agile mindset. And that means frequent iteration and improvement. So I think the micro-iteration technique is closer to philosophically pure TDD (if such a thing exists) than your waterfally "write complete spec, then write all tests, then write code" technique (That doesn't mean that your technique is bad - it's just not what I think people are talking about when they say "TDD"). hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- 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 Nov 18 16:41:03 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 18 Nov 2019 22:41:03 +0100 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: <5quqsep867ca775s10tah1jq1mktqu70mh@4ax.com> Message-ID: <20191118214103.GC4863@hjp.at> On 2019-11-15 12:11:31 +0100, R.Wieser wrote: > Dennis, > > No, that addition is a fixed increment on the initial starting > > time, and is NOT relative to the ending of a sleep. > > > No, that addition is a fixed increment > > Yep. > > > on the initial starting time > > Nope. > > If pythons sleep is worth its salt it ends exactly on the time provided in > "t". No. There are many reasons why sleep() might return after t (If I wanted to be picky, I'd point out that sleep() will never end *exactly* at t, but let's read "exactly" as "so close it doesn't make a difference"). Very few of those reasons have anything to do with Python: They may be inherent in the OS (which simply doesn't guarantee that and may not be able to switch to any process at any time) to the hardware (there may not be a timer with sufficient resolution, or the interrupt may be masked, and of course there are context-switch times) to the state of the system (the system may be busy with a higher priority task, or the page of your program may not be in RAM and have to be read from disk first), etc. > Thus the subsequent addition to that "t" is releative to the end of > the sleep just before it. No, because you get the actual time at some time between the the previous and the next sleep and use that to compute how long to sleep. So even if sleep() always returned at exactly the intended time, the time used to compute the sleep time would be a little later. But of course sleep is never that punctual, but that doesn't matter since that just adds to that "a little later". hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From best_lay at yahoo.com Mon Nov 18 17:39:08 2019 From: best_lay at yahoo.com (Wildman) Date: Mon, 18 Nov 2019 16:39:08 -0600 Subject: Launching a Script on the Linux Platform References: <20191118211531.GB4863@hjp.at> Message-ID: <4KCdnblmNcgRgE7AnZ2dnUU7-XednZ2d@giganews.com> On Mon, 18 Nov 2019 22:15:31 +0100, Peter J. Holzer wrote: > On 2019-11-18 15:01:57 -0600, Wildman via Python-list wrote: >> On Tue, 19 Nov 2019 05:09:07 +1100, Chris Angelico wrote: >> > On Tue, Nov 19, 2019 at 5:06 AM Wildman via Python-list >> > wrote: >> >> On Sun, 17 Nov 2019 18:27:45 +0000, Barry Scott wrote: >> >> > Because you are installing from a deb you know the exact path to the python you >> >> > need to use. There is no need to use the /usr/bin/env to search the path and >> >> > potential break your code, because a version of python that you do not expect is on >> >> > the path. >> >> >> >> I don't understand. The deb does not install python so I >> >> fail to see how I would know the exact path. >> >> >> >> As to env breaking my code, never heard of such a thing. >> >> >> > >> > The deb should depend on an appropriate Python package. Then you can >> > assume and expect that this version of Python is installed. >> >> Yes, of course, python(3) is listed as a "depends" in the deb >> control file. That does insure that python is installed but >> in no way does that tell me the path of the python executable. > > The debian packaging guidelines tell you where the execuable has to be. > If you install the python package you can be very sure that the > executable will be in /usr/bin. And this is the executable you want to > use. You don't want to use some other random program called "python" > (which may or may not be an interpreter for some version of the Python > language) which just happens to be in the user's path. > > hp Yes, /usr/bin is the likely place to find the python executable but a guideline is not a guarantee. I have always been taught it is never a good idea to use a hard path unless it is something installed with your program or something created by your program. That approach has not failed me. -- GNU/Linux user #557453 The cow died so I don't need your bull! From mturner865 at gmail.com Mon Nov 18 19:00:41 2019 From: mturner865 at gmail.com (Mark Turner) Date: Mon, 18 Nov 2019 19:00:41 -0500 Subject: Friday finking: TDD and EAFP In-Reply-To: <20191118210721.GA4863@hjp.at> References: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> <74263897-D40B-4EAD-957E-C1FF43A26F6F@gmail.com> <2500afa5-84ae-e5fc-a73c-4091681068e6@DancesWithMice.info> <20191103204437.GB3944@hjp.at> <72492bd0-5789-b87d-2cb6-8f7c4ae19f20@DancesWithMice.info> <20191118210721.GA4863@hjp.at> Message-ID: <6C869A3E-5242-44D4-A972-FACF0B0C3AF7@gmail.com> > On Nov 18, 2019, at 4:07 PM, Peter J. Holzer wrote: > > On 2019-11-13 15:16:55 +1300, DL Neil via Python-list wrote: >> On 4/11/19 9:44 AM, Peter J. Holzer wrote: >>> TDD does in my opinion encourage EAFP thinking. >>> >>> The TDD is usually: >>> >>> 1 Write a test >>> 2 Write the minimal amount of code that makes the test pass >>> 3 If you think you have covered the whole spec, stop, else repeat >>> from 1 >>> >>> This is often (e.g. in [1]) exaggerated for pedagogic and humoristic >>> reasons. For example, your first test for a sqrt function might be >>> assert(sqrt(4) == 2) >>> and then of course the minimal implementation is >>> def sqrt(x): >>> return 2 >> I think this simple test like has value. It?s just not where you expect it to be. In order to get this test to pass you have to have your development environment set up, your testing environment set up and perhaps some basic dependencies resolved. If this test doesn?t pass then it?s not the code that needs debugging, it?s the environment. Later on, after this module of code is finished, if a lot of tests start failing for some reason and this simple test is one of them, then a good place to start debugging is the environment. - Mark From torriem at gmail.com Mon Nov 18 19:18:50 2019 From: torriem at gmail.com (Michael Torrie) Date: Mon, 18 Nov 2019 17:18:50 -0700 Subject: Writing a CPython extension - calling another sibbling method ? In-Reply-To: References: <47e7cf54-51ed-1a92-f284-5e95a7a03396@mrabarnett.plus.com> Message-ID: <54e727fc-c58d-c844-d4f8-bcd3d5282735@gmail.com> On 11/18/19 1:15 PM, R.Wieser wrote: > The thing is that the arguments of py_proc1 and py_proc2 are the same, but > for a single argument. Does this have to be done in the C API? Depending on how this class is used in your Python code, I would just create a new Python class that extends this class defined in the C code. Then it's more a matter of: import cmodule class NewClass(cmodule.OldClass): def my_proc2(self, *args): b=3 self.my_proc1( *((b,) + args) ) #OldClass.my_proc1 Now any instance of NewClass has a method called my_proc2 which calls the my_proc1 from the C API defined class with the extra argument prepended. The "*" notation is to unpack the tuple, which is used when calling another function that takes positional arguments. From pahome.chen at mirlab.org Mon Nov 18 22:23:36 2019 From: pahome.chen at mirlab.org (lampahome) Date: Tue, 19 Nov 2019 11:23:36 +0800 Subject: Any socket library to communicate with kernel via netlink? Message-ID: As title, I tried to communicate with kernel via netlink. But I failed when I receive msg from kernel. The weird point is sending successfully from user to kernel, failed when receiving from kernel. So I want to check code in 3rd library and dig in, but always found library called netlinkg but it actually does something like modify network address or check network card... Any idea is welcome From robertvstepp at gmail.com Mon Nov 18 23:05:28 2019 From: robertvstepp at gmail.com (boB Stepp) Date: Mon, 18 Nov 2019 22:05:28 -0600 Subject: Friday finking: TDD and EAFP In-Reply-To: <20191118210721.GA4863@hjp.at> References: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> <74263897-D40B-4EAD-957E-C1FF43A26F6F@gmail.com> <2500afa5-84ae-e5fc-a73c-4091681068e6@DancesWithMice.info> <20191103204437.GB3944@hjp.at> <72492bd0-5789-b87d-2cb6-8f7c4ae19f20@DancesWithMice.info> <20191118210721.GA4863@hjp.at> Message-ID: On Mon, Nov 18, 2019 at 3:23 PM Peter J. Holzer wrote: > > I don't know what "proper" TDD is (and even less "proper consideration" > of TDD), but TDD is in my opinion very much rooted in the agile mindset. > And that means frequent iteration and improvement. So I think the > micro-iteration technique is closer to philosophically pure TDD (if such > a thing exists) than your waterfally "write complete spec, then write > all tests, then write code" technique (That doesn't mean that your > technique is bad - it's just not what I think people are talking about > when they say "TDD"). Your comments brought to mind a book recommended to me, "Test-Driven Development by Example" by Kent Beck. On the intro page to part one, he says: "...My goal is for you to see the rhythm of Test-Driven Development (TDD), which can be summed up as follows. 1. Quickly add a test. 2. Run all tests and see the new one fail. 3. Make a little change. 4. Run all tests and see them all succeed. 5. Refactor to remove duplication. The surprises are likely to include -- How each test can cover a small increment of functionality -- How small and ugly the changes can be to make the new tests run -- How often the tests are run -- How many teensy-weensy steps make up the refactorings" -- boB From address at not.available Tue Nov 19 02:57:23 2019 From: address at not.available (R.Wieser) Date: Tue, 19 Nov 2019 08:57:23 +0100 Subject: How to delay until a next increment of time occurs ? References: <5quqsep867ca775s10tah1jq1mktqu70mh@4ax.com> <20191118214103.GC4863@hjp.at> Message-ID: Peter, First things first: For some reason I see your message coming in empty, but with two attachments. An "att*.txt" one with the actual message contents, and a "signature.asc". Makes it kind of hard to read ... > No. There are many reasons why sleep() might return after t Not /that/ many, but true. But do you think that adding all of those if-when-but reasons to the issue I tried to explain would be a good idea ? I don't. I would just drown the actual issue with it. :-\ > No, because you get the actual time at some time between the the > previous and the next sleep No, you don't. Thats the whole trick. The only place where you ask for the time (and subtract it from the desired one) is directly infront of actually doing the sleep. (dotting i's works two ways I'm afraid :-) ). And the /asked for/ time (before subtraction of the current time I mean - ghah! I hate needing to specify every fricking detail) will be exactly the specified increment away from the (calculated!) last one. And yes, that thus also tries to negate a previous sleep having ended late. In short: The calculated(!) next sleeps termination time is not dependant on how well the previous sleeps and code between them behaved. > the time used to compute the sleep time would be a little later. That doesn't matter, as that "a little later" time would be the same for all the sleeps. In short, the /whole/ output would be delayed a bit. Which, in this case, is of no consequence. Regards, Rudy Wieser From address at not.available Tue Nov 19 03:09:39 2019 From: address at not.available (R.Wieser) Date: Tue, 19 Nov 2019 09:09:39 +0100 Subject: Writing a CPython extension - calling another sibbling method ? References: <47e7cf54-51ed-1a92-f284-5e95a7a03396@mrabarnett.plus.com> <54e727fc-c58d-c844-d4f8-bcd3d5282735@gmail.com> Message-ID: Michael > Does this have to be done in the C API? As far as I can tell, yes. What I need to do is not exposed by the extension itself, meaning that a wrapper class can't get access to it either. And its just a syntax problem. I currently simply have not enough knowledge about the CPython API lanuages one to be able to even do a simple call ... :-\ Regards, Rudy Wieser From address at not.available Tue Nov 19 06:14:42 2019 From: address at not.available (R.Wieser) Date: Tue, 19 Nov 2019 12:14:42 +0100 Subject: Writing a CPython extension - calling another sibbling method ? References: <47e7cf54-51ed-1a92-f284-5e95a7a03396@mrabarnett.plus.com> <113c4444-b0d6-bc55-6f60-47f691dcb6b1@mrabarnett.plus.com> Message-ID: MRAB, > It could be something like this: [snip example code] Thank you very much. Your "Call the other method" line shows me that I've been overthinking things. :-( After that I decided to see if I could give the "py_proc1" function two arguments, which worked. That means that the prepending of "foo" (to the origional one) has been changed into transferring it on its own (much easier for both the caller as well as the callee). Regards, Rudy Wieser From jezkator at gmail.com Tue Nov 19 06:47:01 2019 From: jezkator at gmail.com (jezkator at gmail.com) Date: Tue, 19 Nov 2019 03:47:01 -0800 (PST) Subject: wordsearch Message-ID: Hi, I have got a problem in my searchword. Everything runs properly. Output writes word, coordinates and direction, but i need, that output have same arrangement as second file First file includes board, where program search: xmuinjekci evelkochov cadvouhrac feminizaci pyzlanpbik ldvojlinky osvrhloubd dqldrvandy yevergreen olympskout and second includes words: dvojlinky feminizaci velkochov dvouhra olympskou plody dyn rab svrhlou np jo lordem velko injekci skout mva vandy dvou evergreen ech zla kb un hrr aj ona Python Code: def find_words(file_inputs, words): with open(file_inputs) as file: for line in file: line = line.replace('\n', '') line = line.lower() words.append(line) def get_search_board(file_inputs, search_board): with open(file_inputs) as file: for line in file: if len(line) > 6: line = line.lower() search_board += line length = search_board.index('\n') + 1 return search_board, length def main(): words = [] search_board = '' z = input().split() file_input = z[0] file_inputs = z[1] find_words(file_inputs, words) search_board, length = get_search_board(file_input, search_board) lines = {} lines["1"] = [] letters = [(letter, divmod(index, length)) for index, letter in enumerate(search_board)] lines['0'] = letters for i in range(length): for j in range(i, len(letters), length): lines["1"].append(letters[j]) for direction, tuple in lines.items(): string = ''.join([i[0] for i in tuple]) for word in words: if word in string: coordinates = tuple[string.index(word)][1] print(word,coordinates[0], coordinates[1], direction) main() Output: plody 4 0 1 dyn 6 9 1 rab 2 7 1 jo 0 5 1 lordem 4 3 1 mva 0 1 1 ech 0 6 1 kb 5 8 1 un 6 7 1 hrr 6 4 1 aj 4 4 1 ona 2 4 1 dvojlinky 5 1 0 feminizaci 3 0 0 velkochov 1 1 0 dvouhra 2 2 0 olympskou 9 0 0 svrhlou 6 1 0 np 4 5 0 velko 1 1 0 injekci 0 3 0 skout 9 5 0 vandy 7 5 0 dvou 2 2 0 evergreen 8 1 0 zla 4 2 0 but i need output like this Output: dvojlinky 5 1 0 feminizaci 3 0 0 velkochov 1 1 0 dvouhra 2 2 0 olympskou 9 0 0 plody 4 0 1 dyn 6 9 1 rab 2 7 1 svrhlou 6 9 0 np 4 5 0 jo 0 5 1 lordem 4 3 1 velko 1 1 0 injekci 0 3 0 skout 9 5 0 mva 0 1 1 vandy 7 5 0 dvou 2 2 0 evergreen 8 1 0 ech 0 6 1 zla 4 2 0 kb 5 8 1 un 6 7 1 hrr 6 4 1 aj 4 4 1 ona 2 4 1 Can u help me please? From Richard at Damon-Family.org Tue Nov 19 07:33:34 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Tue, 19 Nov 2019 07:33:34 -0500 Subject: wordsearch In-Reply-To: References: Message-ID: <610425a5-6245-b1de-238d-9553d43b151a@Damon-Family.org> On 11/19/19 6:47 AM, jezkator at gmail.com wrote: > Hi, I have got a problem in my searchword. Everything runs properly. Output writes word, coordinates and direction, but i need, that output have same arrangement as second file > First file includes board, where program search: Look at our code, and what controls the order you data is output. Change it so that the data is processed in the order you want the output. -- Richard Damon From veek at dont-use-this.com Tue Nov 19 09:08:52 2019 From: veek at dont-use-this.com (Veek M) Date: Tue, 19 Nov 2019 14:08:52 -0000 (UTC) Subject: Is there a piece of code ('inspect') that displays all/most of the attributes/methods in a frame, traceback, generator object in a readable fashion Message-ID: Basically I want to call a method and pretty print the object contents for some code I'm playing with. Instead of manually writing all this crud. Something like a python object explorer. def foo(a, x = 10): 2 + 2 def bar(): pass class A: pass class Foo(A, object): def __init__(self): 2 + 2 def mymethod(self): 2 + 2 f = Foo() import inspect f = inspect.currentframe() print f.f_locals, '\n\n', f.f_globals print f.f_lasti, f.f_back, f.f_code, f.f_lineno print f.f_trace #print f.f_builtins print f.f_code.co_name print f.f_code.co_filename print f.f_code.co_argcount print f.f_code.co_varnames print f.f_code.co_nlocals From barry at barrys-emacs.org Tue Nov 19 09:08:08 2019 From: barry at barrys-emacs.org (Barry) Date: Tue, 19 Nov 2019 14:08:08 +0000 Subject: Launching a Script on the Linux Platform In-Reply-To: <4KCdnblmNcgRgE7AnZ2dnUU7-XednZ2d@giganews.com> References: <4KCdnblmNcgRgE7AnZ2dnUU7-XednZ2d@giganews.com> Message-ID: <3852BBE0-7161-494C-AB4D-ABF09D803F81@barrys-emacs.org> > On 18 Nov 2019, at 22:42, Wildman via Python-list wrote: > > ?On Mon, 18 Nov 2019 22:15:31 +0100, Peter J. Holzer wrote: > >>> On 2019-11-18 15:01:57 -0600, Wildman via Python-list wrote: >>> On Tue, 19 Nov 2019 05:09:07 +1100, Chris Angelico wrote: >>>> On Tue, Nov 19, 2019 at 5:06 AM Wildman via Python-list >>>> wrote: >>>>> On Sun, 17 Nov 2019 18:27:45 +0000, Barry Scott wrote: >>>>>> Because you are installing from a deb you know the exact path to the python you >>>>>> need to use. There is no need to use the /usr/bin/env to search the path and >>>>>> potential break your code, because a version of python that you do not expect is on >>>>>> the path. >>>>> >>>>> I don't understand. The deb does not install python so I >>>>> fail to see how I would know the exact path. >>>>> >>>>> As to env breaking my code, never heard of such a thing. >>>>> >>>> >>>> The deb should depend on an appropriate Python package. Then you can >>>> assume and expect that this version of Python is installed. >>> >>> Yes, of course, python(3) is listed as a "depends" in the deb >>> control file. That does insure that python is installed but >>> in no way does that tell me the path of the python executable. >> >> The debian packaging guidelines tell you where the execuable has to be. >> If you install the python package you can be very sure that the >> executable will be in /usr/bin. And this is the executable you want to >> use. You don't want to use some other random program called "python" >> (which may or may not be an interpreter for some version of the Python >> language) which just happens to be in the user's path. >> >> hp > > Yes, /usr/bin is the likely place to find the python executable > but a guideline is not a guarantee. It will be in /usr/bin because the python package cannot change that with users getting very upset. > I have always been taught > it is never a good idea to use a hard path unless it is something > installed with your program or something created by your program. > That approach has not failed me. That is not true for packagers, the reverse is true use exact paths. The use of env to find a program on the path is reasonable if you cannot know where python might be installed. Often the case when publishing scripts. Barry > > -- > GNU/Linux user #557453 > The cow died so I don't need your bull! > -- > https://mail.python.org/mailman/listinfo/python-list > From antoon.pardon at vub.be Tue Nov 19 09:37:06 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 19 Nov 2019 15:37:06 +0100 Subject: Is there a piece of code ('inspect') that displays all/most of the attributes/methods in a frame, traceback, generator object in a readable fashion In-Reply-To: References: Message-ID: Maybe you should have a look at: http://code.activestate.com/recipes/52215-get-more-information-from-tracebacks/ On 19/11/19 15:08, Veek M wrote: > Basically I want to call a method and pretty print the object contents > for some code I'm playing with. > > Instead of manually writing all this crud. Something like a python object > explorer. > > > > def foo(a, x = 10): > 2 + 2 > > def bar(): > pass > > class A: > pass > > class Foo(A, object): > def __init__(self): > 2 + 2 > > def mymethod(self): > 2 + 2 > > f = Foo() > > import inspect > f = inspect.currentframe() > print f.f_locals, '\n\n', f.f_globals > > print f.f_lasti, f.f_back, f.f_code, f.f_lineno > > print f.f_trace > #print f.f_builtins > > print f.f_code.co_name > print f.f_code.co_filename > print f.f_code.co_argcount > print f.f_code.co_varnames > print f.f_code.co_nlocals From jezkator at gmail.com Tue Nov 19 10:44:59 2019 From: jezkator at gmail.com (jezkator at gmail.com) Date: Tue, 19 Nov 2019 07:44:59 -0800 (PST) Subject: wordsearch In-Reply-To: References: <610425a5-6245-b1de-238d-9553d43b151a@Damon-Family.org> Message-ID: Dne ?ter? 19. listopadu 2019 13:33:53 UTC+1 Richard Damon napsal(a): > On 11/19/19 6:47 AM, jezkator at gmail.com wrote: > > Hi, I have got a problem in my searchword. Everything runs properly. Output writes word, coordinates and direction, but i need, that output have same arrangement as second file > > First file includes board, where program search: > > Look at our code, and what controls the order you data is output. Change > it so that the data is processed in the order you want the output. > > -- > Richard Damon I know, that the best way, how i can learn that is by myself, but can u do that with my code and post here, please? From rosuav at gmail.com Tue Nov 19 10:51:36 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Nov 2019 02:51:36 +1100 Subject: wordsearch In-Reply-To: References: <610425a5-6245-b1de-238d-9553d43b151a@Damon-Family.org> Message-ID: On Wed, Nov 20, 2019 at 2:46 AM wrote: > > Dne ?ter? 19. listopadu 2019 13:33:53 UTC+1 Richard Damon napsal(a): > > On 11/19/19 6:47 AM, jezkator at gmail.com wrote: > > > Hi, I have got a problem in my searchword. Everything runs properly. Output writes word, coordinates and direction, but i need, that output have same arrangement as second file > > > First file includes board, where program search: > > > > Look at our code, and what controls the order you data is output. Change > > it so that the data is processed in the order you want the output. > > > > -- > > Richard Damon > > I know, that the best way, how i can learn that is by myself, but can u do that with my code and post here, please? Nope. ChrisA From torriem at gmail.com Tue Nov 19 11:00:26 2019 From: torriem at gmail.com (Michael Torrie) Date: Tue, 19 Nov 2019 09:00:26 -0700 Subject: Writing a CPython extension - calling another sibbling method ? In-Reply-To: References: <47e7cf54-51ed-1a92-f284-5e95a7a03396@mrabarnett.plus.com> <54e727fc-c58d-c844-d4f8-bcd3d5282735@gmail.com> Message-ID: <23ec4834-9dea-978c-01e8-87bf28a6550f@gmail.com> On 11/19/19 1:09 AM, R.Wieser wrote: > Michael > >> Does this have to be done in the C API? > > As far as I can tell, yes. What I need to do is not exposed by the > extension itself, meaning that a wrapper class can't get access to it > either. Sure but the Python methods themselves are exposed and accessible and according to your previous posts, all you want to do is add an argument to a call to the existing method. If that's true, then you should be able to do that part from pure Python. The beauty of the C API is that anything you define there should be visible and accessible from pure Python world. I can understand that the pure C stuff is not accessible of course. But the snippets you've shown so far don't show any of that. > And its just a syntax problem. I currently simply have not enough knowledge > about the CPython API lanuages one to be able to even do a simple call ... > :-\ Are you able to post the C code, or at least enough of it that can actually compile? It'd be much easier to help if we had something to work with. We're working in the dark here so it's difficult to know exactly where to direct you. It's always best on the list to work with complete, standalone, minimal examples. Looking at existing examples, as well as the C API documentation, are how I figured out how to use it some years back when I needed to do a small thing in C, although I've forgotten most of it now. From torriem at gmail.com Tue Nov 19 11:05:57 2019 From: torriem at gmail.com (Michael Torrie) Date: Tue, 19 Nov 2019 09:05:57 -0700 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: <5quqsep867ca775s10tah1jq1mktqu70mh@4ax.com> <20191118214103.GC4863@hjp.at> Message-ID: On 11/19/19 12:57 AM, R.Wieser wrote: > First things first: For some reason I see your message coming in empty, but > with two attachments. An "att*.txt" one with the actual message contents, > and a "signature.asc". Makes it kind of hard to read ... His message is a (standard) PGP-signed message. Perhaps your email client or news reader doesn't deal with PGP signatures? From torriem at gmail.com Tue Nov 19 11:06:42 2019 From: torriem at gmail.com (Michael Torrie) Date: Tue, 19 Nov 2019 09:06:42 -0700 Subject: Writing a CPython extension - calling another sibbling method ? In-Reply-To: <23ec4834-9dea-978c-01e8-87bf28a6550f@gmail.com> References: <47e7cf54-51ed-1a92-f284-5e95a7a03396@mrabarnett.plus.com> <54e727fc-c58d-c844-d4f8-bcd3d5282735@gmail.com> <23ec4834-9dea-978c-01e8-87bf28a6550f@gmail.com> Message-ID: On 11/19/19 9:00 AM, Michael Torrie wrote: > Sure but the Python methods themselves are exposed and accessible and > according to your previous posts, I meant to say the class methods defined by the C code. From Richard at Damon-family.org Tue Nov 19 11:07:16 2019 From: Richard at Damon-family.org (Richard Damon) Date: Tue, 19 Nov 2019 11:07:16 -0500 Subject: wordsearch In-Reply-To: References: Message-ID: On Nov 19, 2019, at 10:56 AM, Chris Angelico wrote: > > ?On Wed, Nov 20, 2019 at 2:46 AM wrote: >> >> Dne ?ter? 19. listopadu 2019 13:33:53 UTC+1 Richard Damon napsal(a): >>>> On 11/19/19 6:47 AM, jezkator at gmail.com wrote: >>>>> Hi, I have got a problem in my searchword. Everything runs properly. Output writes word, coordinates and direction, but i need, that output have same arrangement as second file >>>>> First file includes board, where program search: >>> >>> Look at our code, and what controls the order you data is output. Change >>> it so that the data is processed in the order you want the output. >>> >>> -- >>> Richard Damon >> >> I know, that the best way, how i can learn that is by myself, but can u do that with my code and post here, please? > > Nope. > > ChrisA > Think what order you want your output. Make your main loop go through the data in that order For each of the data, find the answer for that data Print the results. You should be able to figure this out. From jezkator at gmail.com Tue Nov 19 11:13:47 2019 From: jezkator at gmail.com (jezkator at gmail.com) Date: Tue, 19 Nov 2019 08:13:47 -0800 (PST) Subject: wordsearch In-Reply-To: References: Message-ID: Dne ?ter? 19. listopadu 2019 17:07:36 UTC+1 Richard Damon napsal(a): > On Nov 19, 2019, at 10:56 AM, Chris Angelico wrote: > > > > ?On Wed, Nov 20, 2019 at 2:46 AM wrote: > >> > >> Dne ?ter? 19. listopadu 2019 13:33:53 UTC+1 Richard Damon napsal(a): > >>>> On 11/19/19 6:47 AM, jezkator at gmail.com wrote: > >>>>> Hi, I have got a problem in my searchword. Everything runs properly. Output writes word, coordinates and direction, but i need, that output have same arrangement as second file > >>>>> First file includes board, where program search: > >>> > >>> Look at our code, and what controls the order you data is output. Change > >>> it so that the data is processed in the order you want the output. > >>> > >>> -- > >>> Richard Damon > >> > >> I know, that the best way, how i can learn that is by myself, but can u do that with my code and post here, please? > > > > Nope. > > > > ChrisA > > > > Think what order you want your output. > Make your main loop go through the data in that order > For each of the data, find the answer for that data > Print the results. > > You should be able to figure this out. Ok, so first (outer) loop will be for word in words, than for direction, tuple ... But now is problem that it prints 10 times but just the last one is complete and ok From drsalists at gmail.com Tue Nov 19 11:24:30 2019 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 19 Nov 2019 08:24:30 -0800 Subject: Speeding up a test process with a local pypi and/or web proxy? In-Reply-To: References: Message-ID: On Fri, Nov 15, 2019 at 1:11 PM Dan Stromberg wrote: > Hi folks. > > I'm looking at a test process that takes about 16 minutes for a full run. > Anyone? > Naturally, I'd like to speed it up. We've already parallelized it - > mostly. > > It seems like the next thing to look at is setting up a local pypi, and > building some of the packages that're compiled from C/C++ every time we do > a full test run. (We're using docker and building dependencies for each > full test run) > > Also, we could conceivably set up a web proxy...? > > Does having a local pypi obviate the web proxy? > > And what local pypi servers do folks recommend for speed? > > We need support mostly for CPython 3.x, but we still have a little CPython > 2.x we require, and it's possible we'll need the 2.x for a while. > > Thanks! > From jezkator at gmail.com Tue Nov 19 11:23:53 2019 From: jezkator at gmail.com (jezkator at gmail.com) Date: Tue, 19 Nov 2019 08:23:53 -0800 (PST) Subject: wordsearch In-Reply-To: References: Message-ID: <07642f09-bb56-4521-bf37-9a36ae3afa22@googlegroups.com> Dne ?ter? 19. listopadu 2019 17:14:06 UTC+1 jezk... at gmail.com napsal(a): > Dne ?ter? 19. listopadu 2019 17:07:36 UTC+1 Richard Damon napsal(a): > > On Nov 19, 2019, at 10:56 AM, Chris Angelico wrote: > > > > > > ?On Wed, Nov 20, 2019 at 2:46 AM wrote: > > >> > > >> Dne ?ter? 19. listopadu 2019 13:33:53 UTC+1 Richard Damon napsal(a): > > >>>> On 11/19/19 6:47 AM, jezkator at gmail.com wrote: > > >>>>> Hi, I have got a problem in my searchword. Everything runs properly. Output writes word, coordinates and direction, but i need, that output have same arrangement as second file > > >>>>> First file includes board, where program search: > > >>> > > >>> Look at our code, and what controls the order you data is output. Change > > >>> it so that the data is processed in the order you want the output. > > >>> > > >>> -- > > >>> Richard Damon > > >> > > >> I know, that the best way, how i can learn that is by myself, but can u do that with my code and post here, please? > > > > > > Nope. > > > > > > ChrisA > > > > > > > Think what order you want your output. > > Make your main loop go through the data in that order > > For each of the data, find the answer for that data > > Print the results. > > > > You should be able to figure this out. > > > Ok, so first (outer) loop will be for word in words, than for direction, tuple > ... But now is problem that it prints 10 times but just the last one is complete and ok OK, I got it, thnx for help From address at not.available Tue Nov 19 12:12:35 2019 From: address at not.available (R.Wieser) Date: Tue, 19 Nov 2019 18:12:35 +0100 Subject: Writing a CPython extension - calling another sibbling method ? References: <47e7cf54-51ed-1a92-f284-5e95a7a03396@mrabarnett.plus.com> <54e727fc-c58d-c844-d4f8-bcd3d5282735@gmail.com> <23ec4834-9dea-978c-01e8-87bf28a6550f@gmail.com> Message-ID: Michael, > Sure but the Python methods* themselves are exposed and accessible > and according to your previous posts, all you want to do is add an > argument to a call to the existing method. If that's true, then you > should be able to do that part from pure Python. >* class methods defined by the C code Feel free to post code showing that it can be done. The extension is RPi.GPIO, the method is "output", and the extra argument is the pinnaming scheme (BCM or BOARD). Success! :-p > I can understand that the pure C stuff is not accessible of course. > But the snippets you've shown so far don't show any of that. Where did you think that "static PyObject *py_proc1(PyObject *self, PyObject *args)" came from, or why I said "I've also tried to go the C way" ? Besides that, the subject line should have been a dead giveaway by itself ... > We're working in the dark here Are you sure ? MRAB didn't seem to have too much problems with both recognising and understanding what I was busy with - he posted a spot-on example, containing not more, but also not anything less than what I was asking for. > Looking at existing examples, as well as the C API documentation I did not find any example that showed me what I needed to know - simply one CPython function calling another one. And yes, I've found multiple documentation pages, including the "Extending and Embedding the Python Interpreter" ones. Alas, no dice. Most of that documentation is only good when you already know what you are looking for, and need to make sure of its exact usage. Not so much the other way around, when you have no clue and are searching for what you need to use to solve a particular problem (even one as stupid as just calling another method) By the way, the whole solution consists outof the following: static PyObject *py_proc1(PyObject *self, int ExtraArg, PyObject *args) { .... Py_RETURN_NONE } static PyObject *py_proc2(PyObject *self, PyObject *args) { return py_proc1(self, 42, args) } Regards, Rudy Wieser From luciano at ramalho.org Tue Nov 19 15:13:48 2019 From: luciano at ramalho.org (Luciano Ramalho) Date: Tue, 19 Nov 2019 17:13:48 -0300 Subject: Writing a CPython extension - calling another sibbling method ? In-Reply-To: References: <47e7cf54-51ed-1a92-f284-5e95a7a03396@mrabarnett.plus.com> <54e727fc-c58d-c844-d4f8-bcd3d5282735@gmail.com> <23ec4834-9dea-978c-01e8-87bf28a6550f@gmail.com> Message-ID: Now that?s a novel approach to asking for free help: pretending to be smarter than the people who are trying to help you. On Tue, 19 Nov 2019 at 14:17 R.Wieser
wrote: > Michael, > > > Sure but the Python methods* themselves are exposed and accessible > > and according to your previous posts, all you want to do is add an > > argument to a call to the existing method. If that's true, then you > > should be able to do that part from pure Python. > > >* class methods defined by the C code > > Feel free to post code showing that it can be done. The extension is > RPi.GPIO, the method is "output", and the extra argument is the pinnaming > scheme (BCM or BOARD). Success! :-p > > > I can understand that the pure C stuff is not accessible of course. > > But the snippets you've shown so far don't show any of that. > > Where did you think that "static PyObject *py_proc1(PyObject *self, > PyObject > *args)" came from, or why I said "I've also tried to go the C way" ? > Besides that, the subject line should have been a dead giveaway by > itself ... > > > We're working in the dark here > > Are you sure ? MRAB didn't seem to have too much problems with both > recognising and understanding what I was busy with - he posted a spot-on > example, containing not more, but also not anything less than what I was > asking for. > > > Looking at existing examples, as well as the C API documentation > > I did not find any example that showed me what I needed to know - simply > one > CPython function calling another one. And yes, I've found multiple > documentation pages, including the "Extending and Embedding the Python > Interpreter" ones. Alas, no dice. > > Most of that documentation is only good when you already know what you are > looking for, and need to make sure of its exact usage. Not so much the > other way around, when you have no clue and are searching for what you need > to use to solve a particular problem (even one as stupid as just calling > another method) > > > By the way, the whole solution consists outof the following: > > static PyObject *py_proc1(PyObject *self, int ExtraArg, PyObject *args) > { > .... > Py_RETURN_NONE > } > > static PyObject *py_proc2(PyObject *self, PyObject *args) > { > return py_proc1(self, 42, args) > } > > Regards, > Rudy Wieser > > > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Luciano Ramalho | Author of Fluent Python (O'Reilly, 2015) | http://shop.oreilly.com/product/0636920032519.do | Technical Principal at ThoughtWorks | Twitter: @ramalhoorg From luciano at ramalho.org Tue Nov 19 15:20:24 2019 From: luciano at ramalho.org (Luciano Ramalho) Date: Tue, 19 Nov 2019 17:20:24 -0300 Subject: Writing a CPython extension - calling another sibbling method ? In-Reply-To: References: <47e7cf54-51ed-1a92-f284-5e95a7a03396@mrabarnett.plus.com> <54e727fc-c58d-c844-d4f8-bcd3d5282735@gmail.com> <23ec4834-9dea-978c-01e8-87bf28a6550f@gmail.com> Message-ID: I apologize to all but the intended recipient for this. I?d have given him feedback in private if I knew his email. I will take leave from the list now. Keep up the good work, friendly responders. On Tue, 19 Nov 2019 at 17:13 Luciano Ramalho wrote: > Now that?s a novel approach to asking for free help: pretending to be > smarter than the people who are trying to help you. > > On Tue, 19 Nov 2019 at 14:17 R.Wieser
wrote: > >> Michael, >> >> > Sure but the Python methods* themselves are exposed and accessible >> > and according to your previous posts, all you want to do is add an >> > argument to a call to the existing method. If that's true, then you >> > should be able to do that part from pure Python. >> >> >* class methods defined by the C code >> >> Feel free to post code showing that it can be done. The extension is >> RPi.GPIO, the method is "output", and the extra argument is the pinnaming >> scheme (BCM or BOARD). Success! :-p >> >> > I can understand that the pure C stuff is not accessible of course. >> > But the snippets you've shown so far don't show any of that. >> >> Where did you think that "static PyObject *py_proc1(PyObject *self, >> PyObject >> *args)" came from, or why I said "I've also tried to go the C way" ? >> Besides that, the subject line should have been a dead giveaway by >> itself ... >> >> > We're working in the dark here >> >> Are you sure ? MRAB didn't seem to have too much problems with both >> recognising and understanding what I was busy with - he posted a spot-on >> example, containing not more, but also not anything less than what I was >> asking for. >> >> > Looking at existing examples, as well as the C API documentation >> >> I did not find any example that showed me what I needed to know - simply >> one >> CPython function calling another one. And yes, I've found multiple >> documentation pages, including the "Extending and Embedding the Python >> Interpreter" ones. Alas, no dice. >> >> Most of that documentation is only good when you already know what you are >> looking for, and need to make sure of its exact usage. Not so much the >> other way around, when you have no clue and are searching for what you >> need >> to use to solve a particular problem (even one as stupid as just calling >> another method) >> >> >> By the way, the whole solution consists outof the following: >> >> static PyObject *py_proc1(PyObject *self, int ExtraArg, PyObject *args) >> { >> .... >> Py_RETURN_NONE >> } >> >> static PyObject *py_proc2(PyObject *self, PyObject *args) >> { >> return py_proc1(self, 42, args) >> } >> >> Regards, >> Rudy Wieser >> >> >> >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- > Luciano Ramalho > | Author of Fluent Python (O'Reilly, 2015) > | http://shop.oreilly.com/product/0636920032519.do > | Technical Principal at ThoughtWorks > | Twitter: @ramalhoorg > -- Luciano Ramalho | Author of Fluent Python (O'Reilly, 2015) | http://shop.oreilly.com/product/0636920032519.do | Technical Principal at ThoughtWorks | Twitter: @ramalhoorg From torriem at gmail.com Tue Nov 19 15:38:07 2019 From: torriem at gmail.com (Michael Torrie) Date: Tue, 19 Nov 2019 13:38:07 -0700 Subject: Writing a CPython extension - calling another sibbling method ? In-Reply-To: References: <47e7cf54-51ed-1a92-f284-5e95a7a03396@mrabarnett.plus.com> <54e727fc-c58d-c844-d4f8-bcd3d5282735@gmail.com> <23ec4834-9dea-978c-01e8-87bf28a6550f@gmail.com> Message-ID: On 11/19/19 10:12 AM, R.Wieser wrote: > Feel free to post code showing that it can be done. The extension is > RPi.GPIO, the method is "output", and the extra argument is the pinnaming > scheme (BCM or BOARD). Success! :-p If you mentioned RPi.GPIO before, I apologize for my mistake. That's very helpful to know. As for posting code to show it can be done, If I knew what the pin naming scheme was (how do you use it from python?), and if I knew how you modified py_output_gpio to do something with that, I sure would give it a shot. >> We're working in the dark here > > Are you sure ? > MRAB didn't seem to have too much problems with both > recognising and understanding what I was busy with - he posted a spot-on > example, containing not more, but also not anything less than what I was > asking for. MRAB understood and answered the specific question, yes. But I thought, and remain convinced, that there were probably other ways of solving it that didn't involve mucking with C code. Because forking the RPi.GPIO code means that every time there's a change or update to it you know have to redo everything each time. You mentioned you're working with RPi.GPIO, so why not just use the real function names in your questions? After grepping I've determined that you are really wanting to work with the C function py_output_gpio(). Why not just say that? Doesn't take very much extra time but will get more people willing to respond who might know. > I did not find any example that showed me what I needed to know - simply one > CPython function calling another one. And yes, I've found multiple > documentation pages, including the "Extending and Embedding the Python > Interpreter" ones. Alas, no dice. Fair enough. > By the way, the whole solution consists outof the following: > > static PyObject *py_proc1(PyObject *self, int ExtraArg, PyObject *args) > { > .... > Py_RETURN_NONE > } > > static PyObject *py_proc2(PyObject *self, PyObject *args) > { > return py_proc1(self, 42, args) > } Glad it worked out for you. That "int ExtraArg" bit looks a bit strange; I thought everything that was exposed to the Python side of things had to be wrapped in PyObject. Guess I'm wrong? From PythonList at DancesWithMice.info Tue Nov 19 18:04:27 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 20 Nov 2019 12:04:27 +1300 Subject: Writing a CPython extension - calling another sibbling method ? In-Reply-To: References: <47e7cf54-51ed-1a92-f284-5e95a7a03396@mrabarnett.plus.com> <54e727fc-c58d-c844-d4f8-bcd3d5282735@gmail.com> <23ec4834-9dea-978c-01e8-87bf28a6550f@gmail.com> Message-ID: On 20/11/19 9:20 AM, Luciano Ramalho wrote: > I apologize to all but the intended recipient for this. I?d have given him > feedback in private if I knew his email. > > I will take leave from the list now. Keep up the good work, friendly > responders. Please reconsider. Should your relationship with the 'good folks' be governed by someone/anyone else? There is no need to tell you that are many innocent reasons why we misunderstand each other's motives or intent, particularly in a multi-cultural context; just as there are folk who attempt to 'take advantage'. Grossly generalised examples - each academic year a new crop of PyStudents seems to crop-up, thinking we'll *do* their 'homework' for them... - some parts of British humor is impenetrable to those born south of Dover - Dutch/German positivity can be interpreted as brusque or even arrogant, in some parts of the world - Kiwi/Aussie humor as often involves insult (which is not meant to be taken seriously) as it does self-deprecation - Self-deprecation is not 'the American way'... - Monty Python humor is its own (lack of) explanation! That said, I am asking (elsewhere, but please feel free...'here') if the standards and conventions of the Python Foundation apply to this/these list(s)? Such requires a balance between an individual's right to privacy, and the open-ness with which we conduct Python-business, ie without insult, derision, victimisation, etc, etc... -- Regards =dn From hjp-python at hjp.at Tue Nov 19 18:56:51 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 20 Nov 2019 00:56:51 +0100 Subject: Friday finking: TDD and EAFP In-Reply-To: <6C869A3E-5242-44D4-A972-FACF0B0C3AF7@gmail.com> References: <13b27350-570d-b157-87da-c794fc2a4c1e@etelligence.info> <74263897-D40B-4EAD-957E-C1FF43A26F6F@gmail.com> <2500afa5-84ae-e5fc-a73c-4091681068e6@DancesWithMice.info> <20191103204437.GB3944@hjp.at> <72492bd0-5789-b87d-2cb6-8f7c4ae19f20@DancesWithMice.info> <20191118210721.GA4863@hjp.at> <6C869A3E-5242-44D4-A972-FACF0B0C3AF7@gmail.com> Message-ID: <20191119235651.GA11059@hjp.at> On 2019-11-18 19:00:41 -0500, Mark Turner wrote: [trivial test] > I think this simple test like has value. It?s just not where you > expect it to be. In order to get this test to pass you have to have > your development environment set up, your testing environment set up > and perhaps some basic dependencies resolved. That's a good point. Especially if your environment is a bit complex (as it invariably is when you want to test web applications, for example), it is a very good idea to start really simple just to make sure you have your environment set up correctly. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From lukasz at langa.pl Tue Nov 19 20:08:16 2019 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Wed, 20 Nov 2019 02:08:16 +0100 Subject: [RELEASE] Python 3.9.0a1 available for testing Message-ID: <45EA849C-028E-47A7-96BC-1A03576C1630@langa.pl> Go get it here: https://www.python.org/downloads/release/python-390a1/ This is an early developer preview of Python 3.9 Python 3.9 is still in development. This releasee, 3.9.0a1 is the first of six planned alpha releases. Alpha releases are intended to make it easier to test the current state of new features and bug fixes and to test the release process. During the alpha phase, features may be added up until the start of the beta phase (2020-05-18) and, if necessary, may be modified or deleted up until the release candidate phase (2020-08-10). Please keep in mind that this is a preview release and its use is not recommended for production environments. Major new features of the 3.9 series, compared to 3.8 Many new features for Python 3.9 are still being planned and written. Among the new major new features and changes so far: PEP 602 , Python adopts a stable annual release cadence BPO 38379 , garbage collection does not block on resurrected objects; BPO 38692 , os.pidfd_open added that allows process management without races and signals; A number of standard library modules (audioop, ast, grp, _hashlib, pwd, _posixsubprocess, random, select, struct, termios, zlib) are now using the stable ABI defined by PEP 384 . (Hey, fellow core developer, if a feature you find important is missing from this list, let ?ukasz know .) The next pre-release of Python 3.9 will be 3.9.0a2, currently scheduled for 2019-12-16. - ? -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: Message signed with OpenPGP URL: From pahome.chen at mirlab.org Tue Nov 19 21:23:04 2019 From: pahome.chen at mirlab.org (lampahome) Date: Wed, 20 Nov 2019 10:23:04 +0800 Subject: Pickle failed __getstate__ on my customized class inherited dict Message-ID: I make a class Wrapper inherited from dict and met problem when I want to pickle it. Is there anyway to make __getstate__ of Wrapper to output a normal dict?(Output a dict will help pickleing easily) === code === import pickle class Wrapper(dict): def __getattr__(self, attr): return self[attr] def __getstate__(self): # blablabla d=Wrapper(zip((1,2), (3,4))) pickle.dumps(d) === code === When I tried overwrite __getstate__ to below: def __getstate__(self): return self.__repr__() pickle it will shows: b'\x80...__main__...Wrapper...' <- I don't know why it shows the class name. That makes me confused. From dieter at handshake.de Wed Nov 20 01:58:06 2019 From: dieter at handshake.de (dieter) Date: Wed, 20 Nov 2019 07:58:06 +0100 Subject: Pickle failed __getstate__ on my customized class inherited dict References: Message-ID: <87mucrghkx.fsf@handshake.de> lampahome writes: > I make a class Wrapper inherited from dict and met problem when I want to > pickle it. > > Is there anyway to make __getstate__ of Wrapper to output a normal > dict?(Output a dict will help pickleing easily) > > > === code === > import pickle > class Wrapper(dict): > def __getattr__(self, attr): > return self[attr] > def __getstate__(self): > # blablabla > > d=Wrapper(zip((1,2), (3,4))) > pickle.dumps(d) > === code === You have forgotten to tell us which problem the code above revealed. > When I tried overwrite __getstate__ to below: > def __getstate__(self): > return self.__repr__() > pickle it will shows: > b'\x80...__main__...Wrapper...' <- I don't know why it shows the class name. > That makes me confused. It should not: pickling a class instance entails pickling a class reference and the instance's state. The class name is part of the class reference. From address at not.available Wed Nov 20 03:04:28 2019 From: address at not.available (R.Wieser) Date: Wed, 20 Nov 2019 09:04:28 +0100 Subject: Writing a CPython extension - calling another sibbling method ? References: <47e7cf54-51ed-1a92-f284-5e95a7a03396@mrabarnett.plus.com> <54e727fc-c58d-c844-d4f8-bcd3d5282735@gmail.com> <23ec4834-9dea-978c-01e8-87bf28a6550f@gmail.com> Message-ID: Luciano, > Now that's a novel approach to asking for free help: pretending > to be smarter than the people who are trying to help you. What makes you think I'm /pretending/ ? *Ofcourse* I'm smarter than anyone on this earth, didn't you know ? :-D But I'll let you in on a secret: I'm rather aware that my knowledge, even on subjects I've spend most of my time on, is rather limited. There is /always/ someone who knows more about a particular subject (better memory, hands-on experience, you name it). Though that doesn't mean I take anyones word as gods gospell - which you might have noticed and taken offense to. And pray tell: How is me pointing out stuff that anyone can have read in this thread any indication that I would be smarter ? I wrote those questions, so it stands to reason that I know a bit more about whats in them than someone who just read (skimmed?) them. Regards, Rudy Wieser From __peter__ at web.de Wed Nov 20 04:00:03 2019 From: __peter__ at web.de (Peter Otten) Date: Wed, 20 Nov 2019 10:00:03 +0100 Subject: Pickle failed __getstate__ on my customized class inherited dict References: Message-ID: lampahome wrote: > I make a class Wrapper inherited from dict and met problem when I want to > pickle it. > > Is there anyway to make __getstate__ of Wrapper to output a normal > dict?(Output a dict will help pickleing easily) > > > === code === > import pickle > class Wrapper(dict): > def __getattr__(self, attr): > return self[attr] > def __getstate__(self): > # blablabla > > d=Wrapper(zip((1,2), (3,4))) > pickle.dumps(d) > === code === > > When I tried overwrite __getstate__ to below: > def __getstate__(self): > return self.__repr__() > pickle it will shows: > b'\x80...__main__...Wrapper...' <- I don't know why it shows the class > name. That makes me confused. The class has to be remembered for unpickling. If you replace Wrapper with dict -- which is possible with __reduce__() -- the unpickled object will be a plain dict: >>> class Wrapper(dict): ... def __reduce__(self): ... return dict, (dict(self),) ... >>> w = Wrapper("ab cd ef".split()) >>> w {'a': 'b', 'c': 'd', 'e': 'f'} >>> type(w) >>> import pickle >>> pickle.dumps(w) b'\x80\x03cbuiltins\ndict\nq\x00}q\x01(X\x01\x00\x00\x00aq\x02X\x01\x00\x00\x00bq\x03X\x01\x00\x00\x00cq\x04X\x01\x00\x00\x00dq\x05X\x01\x00\x00\x00eq\x06X\x01\x00\x00\x00fq\x07u\x85q\x08Rq\t.' >>> v = pickle.loads(_) >>> v {'a': 'b', 'c': 'd', 'e': 'f'} >>> type(v) From address at not.available Wed Nov 20 04:02:48 2019 From: address at not.available (R.Wieser) Date: Wed, 20 Nov 2019 10:02:48 +0100 Subject: Writing a CPython extension - calling another sibbling method ? References: <47e7cf54-51ed-1a92-f284-5e95a7a03396@mrabarnett.plus.com> <54e727fc-c58d-c844-d4f8-bcd3d5282735@gmail.com> <23ec4834-9dea-978c-01e8-87bf28a6550f@gmail.com> Message-ID: Michael, > If you mentioned RPi.GPIO before, I apologize for my mistake. No I didn't, there is nothing to apologize for. > That's very helpful to know. I have no clue to why it would be, as my question has got *zero* to do with it - its valid for /any/ extension using the CPython C API. Just look at the "this is what I'm using" code in my previous message. > If I knew what the pin naming scheme was (how do you use it from python?) :-) You can't (use it from python). That was the whole problem I started with. Its simply not exposed to the user. > But I thought, and remain convinced, that there were probably other > ways of solving it that didn't involve mucking with C code. I already asked that question in "comp.sys.raspberry-py", in a thread named "Accessing GPIO pins using the two different numering schemes (BCM and BOARD) at the same time ?". You know what most of the answers boiled down to ? 'Use another extension'. Most likely well-ment, but not something I tend to accept/do before doing an in-depth search for possibilities (for multiple reasons, also stated there). > You mentioned you're working with RPi.GPIO, so why not just use the > real function names in your questions? Because my question was-and-is not about that extension. Its as simple as that. And ofcourse because I did not want yet another "just use a different entextension" slew of non-answers (once bitten, twice shy). > After grepping I've determined that you are really wanting to work > with the C function py_output_gpio(). That one, and a number of others that cannot be used before & get locked into place by the "py_setmode()" call. > Why not just say that? Doesn't take very much extra time but will > get more people willing to respond who might know. See above: My experience tells me that I would have gotten a jumble of people who would just tell me to forget about my question and use something completely different - possibly stopping someone from posting the answer I needed. Yep, that latter part is the other side of your coin. Part of the problem might also be that I am here to enjoy the journey, with the goal as a kind of extra. Heck, everytime I reach a goal I need to find myself another journey ... :-) >That "int ExtraArg" bit looks a bit strange; I thought everything that > was exposed to the Python side of things had to be wrapped in > PyObject. Guess I'm wrong? Yes, it did and still does look a bit strange, and I was even worse off: I somehow assumed that a PyObject method would only accept a single argument, hence my question to how to prepend that "foo" string to the origional one. But with me being me I also tried to transfer the PyObject containing that "foo" string by itself as a second argument, and it worked. Score one, and much easier to work with. Than I simply tried to replace that PyObject string with a C-style argument. Which also worked and made the solution even simpler. Score two. Changing "foo" into a numeric argument was just the last step - all I needed to transfer was either the BCM or BOARD constants. And that was "game over". Regards, Rudy Wieser From address at not.available Wed Nov 20 04:59:15 2019 From: address at not.available (R.Wieser) Date: Wed, 20 Nov 2019 10:59:15 +0100 Subject: Writing a CPython extension - calling another sibbling method ? References: Message-ID: Dennis, > So... extract the original args, then build a new args object with your > added argument, then call your new function with that... I wanted to respond that prepending a string to an existing argument sounds quite a bit easier than what you are describing, but than I realized that I just flatout assumed that the origional "args" would be a string too .. Thanks for the links. And yes, thats one of the six related pages I've saved. I blame me being focussed on calling another method, (pretty-much) ignoring the arguments til after I found it (arguments without being able to call would have had a zero value to me). Looking back I can now see their value. > {Personally, I still think you are looking for a solution to a problem > that doesn't exist. I for my part still think that my "lets dig into it" has been worthwhile to me - much more than just grabbing another extension. I've learned a few things along the way, which is really all that matters to me. > The proper way to handle this is to NOT hard-code any pin numbers > in your module, but instead provide an initialization/setup function which > the end-user calls, passing in pin numbers in their preferred scheme. Absolutily. But instead of requiring the (noobie) user to provide those I tend to make that optional by using defaults. > they provided the pins in that scheme and your code doesn't > have to worry about it. Yep, thats one way to solve the problem. :-) Regards, Rudy Wieser From pahome.chen at mirlab.org Wed Nov 20 05:51:31 2019 From: pahome.chen at mirlab.org (lampahome) Date: Wed, 20 Nov 2019 18:51:31 +0800 Subject: Use epoll but still lose packet Message-ID: I use epoll to listen events to receive packet from remote client via tcp socket And I found it still lose packet from remote client when client sends 128 messages to me. Is there any tips to avoid this? thx I only use a while loop to catch events like below: import select, socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind() sock.listen(10) epoll = select.epoll() epoll.register(sock.fileno(), select.EPOLLIN) while True: events = epoll.poll(10) # timeout=10 sec if not events: continue for fd,event in events: if event & select.EPOLLIN: sock.recv(1024) ... From arequipeno at gmail.com Wed Nov 20 09:54:19 2019 From: arequipeno at gmail.com (Ian Pilcher) Date: Wed, 20 Nov 2019 08:54:19 -0600 Subject: Any socket library to communicate with kernel via netlink? In-Reply-To: References: Message-ID: On 11/18/19 9:23 PM, lampahome wrote: > As title, I tried to communicate with kernel via netlink. But I failed when > I receive msg from kernel. > > The weird point is sending successfully from user to kernel, failed when > receiving from kernel. > > So I want to check code in 3rd library and dig in, but always found library > called netlinkg but it actually does something like modify network address > or check network card... > > Any idea is welcome > https://pypi.org/project/pyroute2/ -- ======================================================================== Ian Pilcher arequipeno at gmail.com -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== From self at gkayaalp.com Wed Nov 20 11:09:24 2019 From: self at gkayaalp.com (=?utf-8?Q?G=C3=B6ktu=C4=9F_Kayaalp?=) Date: Wed, 20 Nov 2019 19:09:24 +0300 Subject: Recommendations for intro to python+programming lecture to Humanities MA students Message-ID: Hi all, I am responsible of giving my colleagues in from linguistics MA programme an intro to Python, and programming, with a focus on statistics. It?ll be a single lecture, and I probably won?t be able to do more than give some demos and then some pointers to actually properly learn how to use the tools. The problem is I?m a rather techie power user and my audience the exact opposite, so I feel like I could make use of some guidance as to how to bridge the gap and be useful. I want to stick to Python 3, demo them a few basics of programming, then how to use matplotlib, Jupyter notebooks (is this what IPyNBs became?), and some descriptive statistics. All this needs to happen within the span of a single lecture (tho if people are interested I?ll offer to do a few more in our own time), so 45min~1h. The first problem is installation: apart from me, a Debian user, everybody has Windows or Mac laptops, and IDK how you install Python on them. I feel like choosing one of the distros is a good idea: I could just put the installers on a USB and hand it out, or just send them a message with simple steps to follow and set themselves up beforehand. Thing is, IDK nothing about distros. Anaconda seems to be the best options, but comes with complications like an IDE, as opposed to just working with notebooks, and is huge. Also, seems to include R stuff. Spyder looks nice, but I don?t want to freak people out with such an unfamiliar environment as an IDE just within the first few moments they encounter programming. These are all humanities people. Another problem is that Anaconda has ?conda?, a non-standard package manager, and I?m kinda vary of introducing that to people: should I talk of pip, should I leave it out? I feel like I should just stick to pip and leave conda out, but IDK. Python(x,y) is interesting, but it?s apparently Py2k only, and that?s a no-no. So, am I better off telling people to install Anaconda, or plain Py3k + a selection of packages (which maybe I make into a .zip or something)? Then, I need good pointers to hand out: links to good introductions to Python, programming, and statistical use of Python. Thing is, I?ve always learned the hacker way, i.e. skip the docs, tinker with stuff. Thus, IDK of any good resources out of experience, and I want to ask you all for some recommendations. I prefer free and tutorial-like stuff, but I?ll teach them how to use the stdlib reference too. What are some good self-teaching material for those who are new to programming and Python, and need to mainly do statistics with experimental data? Finally, I?m looking for recommendations on what to show and how. My current master plan is - what?s the use of programming for a linguist - an abstract idea of what programming is - basic intro to Python syntax - demo how to load and clean up some data - demo matplotlib - demo jupyter notebooks - compare with alternatives: R, SPSS, other? - briefly refer to libraries for - NLP - AI? - lots of links on - how to learn enough coding for number crunching and plotmaking - how to make use of stdlib reference - how to find and utilise packages and their docs - ...? I plan to produce a handout with all this info neatly organised, and just go with a (few) Jupyter notebooks for the rest (resisting hard the urge to go in with Emacs Org Mode instead :)). I?m looking forward to any recommendations from youse. The deadline is about a month and a half away, and I really want to give people something operationable. People are stuck with BS like SPSS, too simple and too pricy, when a few lines of Python (or R) is all they need. I came here because IDK teaching about this stuff, and I haven?t left the comfort zones of a programmer ever before, so this is some new experience for me and I don?t want to botch it. Thanks a lot in advance, G?ktu?. -- ?. G?ktu? Kayaalp 024C 30DD 597D 142B 49AC 40EB 465C D949 B101 2427 From formisc at gmail.com Wed Nov 20 12:05:38 2019 From: formisc at gmail.com (Andrew Z) Date: Wed, 20 Nov 2019 12:05:38 -0500 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: References: Message-ID: Goktug, Im not clear what is the objective of the lecture? I understand it is an intro, but what are you trying to achieve? I didnt read all the details, but maybe you can look into creating a docker/virtual box image with everything preinstalled. Good luck. On Wed, Nov 20, 2019, 11:54 G?ktu? Kayaalp wrote: > Hi all, > > I am responsible of giving my colleagues in from linguistics MA > programme an intro to Python, and programming, with a focus on > statistics. It?ll be a single lecture, and I probably won?t be able to > do more than give some demos and then some pointers to actually properly > learn how to use the tools. > > The problem is I?m a rather techie power user and my audience the exact > opposite, so I feel like I could make use of some guidance as to how to > bridge the gap and be useful. > > I want to stick to Python 3, demo them a few basics of programming, then > how to use matplotlib, Jupyter notebooks (is this what IPyNBs became?), > and some descriptive statistics. All this needs to happen within the > span of a single lecture (tho if people are interested I?ll offer to do > a few more in our own time), so 45min~1h. > > The first problem is installation: apart from me, a Debian user, > everybody has Windows or Mac laptops, and IDK how you install Python on > them. I feel like choosing one of the distros is a good idea: I could > just put the installers on a USB and hand it out, or just send them a > message with simple steps to follow and set themselves up beforehand. > Thing is, IDK nothing about distros. Anaconda seems to be the best > options, but comes with complications like an IDE, as opposed to just > working with notebooks, and is huge. Also, seems to include R stuff. > Spyder looks nice, but I don?t want to freak people out with such an > unfamiliar environment as an IDE just within the first few moments they > encounter programming. These are all humanities people. Another > problem is that Anaconda has ?conda?, a non-standard package manager, > and I?m kinda vary of introducing that to people: should I talk of pip, > should I leave it out? I feel like I should just stick to pip and leave > conda out, but IDK. Python(x,y) is interesting, but it?s apparently > Py2k only, and that?s a no-no. > > So, am I better off telling people to install Anaconda, or plain Py3k + > a selection of packages (which maybe I make into a .zip or something)? > > Then, I need good pointers to hand out: links to good introductions to > Python, programming, and statistical use of Python. Thing is, I?ve > always learned the hacker way, i.e. skip the docs, tinker with stuff. > Thus, IDK of any good resources out of experience, and I want to ask you > all for some recommendations. I prefer free and tutorial-like stuff, > but I?ll teach them how to use the stdlib reference too. > > What are some good self-teaching material for those who are new to > programming and Python, and need to mainly do statistics with > experimental data? > > Finally, I?m looking for recommendations on what to show and how. My > current master plan is > > - what?s the use of programming for a linguist > - an abstract idea of what programming is > - basic intro to Python syntax > - demo how to load and clean up some data > - demo matplotlib > - demo jupyter notebooks > - compare with alternatives: R, SPSS, other? > - briefly refer to libraries for > - NLP > - AI? > - lots of links on > - how to learn enough coding for number crunching and plotmaking > - how to make use of stdlib reference > - how to find and utilise packages and their docs > - ...? > > I plan to produce a handout with all this info neatly organised, and > just go with a (few) Jupyter notebooks for the rest (resisting hard the > urge to go in with Emacs Org Mode instead :)). > > I?m looking forward to any recommendations from youse. The deadline is > about a month and a half away, and I really want to give people > something operationable. People are stuck with BS like SPSS, too simple > and too pricy, when a few lines of Python (or R) is all they need. I > came here because IDK teaching about this stuff, and I haven?t left the > comfort zones of a programmer ever before, so this is some new > experience for me and I don?t want to botch it. > > Thanks a lot in advance, > > G?ktu?. > > -- > ?. G?ktu? Kayaalp > 024C 30DD 597D 142B 49AC > 40EB 465C D949 B101 2427 > -- > https://mail.python.org/mailman/listinfo/python-list > From nick.a.sarbicki at gmail.com Wed Nov 20 12:41:13 2019 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Wed, 20 Nov 2019 17:41:13 +0000 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: References: Message-ID: Hi Goktug, Firstly good luck, inspiring a crowd of people who have never learnt to code (and probably never expected to) to want to code sounds like a daunting task. I think you have broadly the right idea in that you want to spend only a little bit of time on the basic syntax before demoing what you can do with the language. I would spend the beginning of the lecture focusing on how readable code can be - an attempt to make it less scary to people who haven't touched code before - and then spend the rest of the time showing the fun things you can do with it. I can't see trying to take students from no code to competent SciPy users in one lecture as a possible feat. So it would be best to simply inspire them to want to learn more themselves. In which case I'd encourage you to have a think as to what would be the most inspiring examples? Are jupyter notebooks on their own something that inspires? Probably not - although they are nice for showcasing code in. Is ETL exciting? Maybe in extremely rare cases... NLP, AI etc can be pretty fun and powerful. Graphing libraries such as MatPlotLib as they are visual is always good as well. Can demo some (probably useless) 3D charts or XKCD mode if you want. RE Conda and distros - I'd forget about them, in my experience you may as well learn to use pip and install what you need that way, in the long term it is faster and more flexible. Python generally supplies a perfectly good installer for most operating systems at python.org - no need for anything else. Keeping it to just standard python (+ some libs you don't explicitly need to explain) makes it less complex. Also - as biased as it sounds coming from a Python developer - I'm not sure I'd want to discuss alternatives (R, SPSS etc.) as it just provides more confusing choices. In summary I'd aim to inspire not to teach - so show some basics at the beginning to show how accessible it can be, and then feel free to jump off into advanced python land to showcase what is possible using whatever you are most comfortable with. Essentially show them they can learn python, and then inspire them to want to learn python. Feel free to ignore all of these thoughts, they are highly subjective. On Wed, Nov 20, 2019 at 5:07 PM Andrew Z wrote: > Goktug, > Im not clear what is the objective of the lecture? I understand it is an > intro, but what are you trying to achieve? > > I didnt read all the details, but maybe you can look into creating a > docker/virtual box image with everything preinstalled. > Good luck. > > On Wed, Nov 20, 2019, 11:54 G?ktu? Kayaalp wrote: > > > Hi all, > > > > I am responsible of giving my colleagues in from linguistics MA > > programme an intro to Python, and programming, with a focus on > > statistics. It?ll be a single lecture, and I probably won?t be able to > > do more than give some demos and then some pointers to actually properly > > learn how to use the tools. > > > > The problem is I?m a rather techie power user and my audience the exact > > opposite, so I feel like I could make use of some guidance as to how to > > bridge the gap and be useful. > > > > I want to stick to Python 3, demo them a few basics of programming, then > > how to use matplotlib, Jupyter notebooks (is this what IPyNBs became?), > > and some descriptive statistics. All this needs to happen within the > > span of a single lecture (tho if people are interested I?ll offer to do > > a few more in our own time), so 45min~1h. > > > > The first problem is installation: apart from me, a Debian user, > > everybody has Windows or Mac laptops, and IDK how you install Python on > > them. I feel like choosing one of the distros is a good idea: I could > > just put the installers on a USB and hand it out, or just send them a > > message with simple steps to follow and set themselves up beforehand. > > Thing is, IDK nothing about distros. Anaconda seems to be the best > > options, but comes with complications like an IDE, as opposed to just > > working with notebooks, and is huge. Also, seems to include R stuff. > > Spyder looks nice, but I don?t want to freak people out with such an > > unfamiliar environment as an IDE just within the first few moments they > > encounter programming. These are all humanities people. Another > > problem is that Anaconda has ?conda?, a non-standard package manager, > > and I?m kinda vary of introducing that to people: should I talk of pip, > > should I leave it out? I feel like I should just stick to pip and leave > > conda out, but IDK. Python(x,y) is interesting, but it?s apparently > > Py2k only, and that?s a no-no. > > > > So, am I better off telling people to install Anaconda, or plain Py3k + > > a selection of packages (which maybe I make into a .zip or something)? > > > > Then, I need good pointers to hand out: links to good introductions to > > Python, programming, and statistical use of Python. Thing is, I?ve > > always learned the hacker way, i.e. skip the docs, tinker with stuff. > > Thus, IDK of any good resources out of experience, and I want to ask you > > all for some recommendations. I prefer free and tutorial-like stuff, > > but I?ll teach them how to use the stdlib reference too. > > > > What are some good self-teaching material for those who are new to > > programming and Python, and need to mainly do statistics with > > experimental data? > > > > Finally, I?m looking for recommendations on what to show and how. My > > current master plan is > > > > - what?s the use of programming for a linguist > > - an abstract idea of what programming is > > - basic intro to Python syntax > > - demo how to load and clean up some data > > - demo matplotlib > > - demo jupyter notebooks > > - compare with alternatives: R, SPSS, other? > > - briefly refer to libraries for > > - NLP > > - AI? > > - lots of links on > > - how to learn enough coding for number crunching and plotmaking > > - how to make use of stdlib reference > > - how to find and utilise packages and their docs > > - ...? > > > > I plan to produce a handout with all this info neatly organised, and > > just go with a (few) Jupyter notebooks for the rest (resisting hard the > > urge to go in with Emacs Org Mode instead :)). > > > > I?m looking forward to any recommendations from youse. The deadline is > > about a month and a half away, and I really want to give people > > something operationable. People are stuck with BS like SPSS, too simple > > and too pricy, when a few lines of Python (or R) is all they need. I > > came here because IDK teaching about this stuff, and I haven?t left the > > comfort zones of a programmer ever before, so this is some new > > experience for me and I don?t want to botch it. > > > > Thanks a lot in advance, > > > > G?ktu?. > > > > -- > > ?. G?ktu? Kayaalp > > 024C 30DD 597D 142B 49AC > > 40EB 465C D949 B101 2427 > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Wed Nov 20 12:59:43 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Nov 2019 04:59:43 +1100 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: References: Message-ID: On Thu, Nov 21, 2019 at 4:42 AM Nick Sarbicki wrote: > RE Conda and distros - I'd forget about them, in my experience you may as > well learn to use pip and install what you need that way, in the long term > it is faster and more flexible. Python generally supplies a perfectly good > installer for most operating systems at python.org - no need for anything > else. Keeping it to just standard python (+ some libs you don't explicitly > need to explain) makes it less complex. Agreed. In fact, given the tight context here, I would go even further and stick to JUST the standard library - there's already way more in there than you need for a single lecture. Maybe just name-drop pip and hint at the fact that there's a lot more to Python than just what you see here, but other than that, keep it really simple. > In summary I'd aim to inspire not to teach - so show some basics at the > beginning to show how accessible it can be, and then feel free to jump off > into advanced python land to showcase what is possible using whatever you > are most comfortable with. Essentially show them they can learn python, and > then inspire them to want to learn python. > Absolutely agreed. Your job is not to turn them into programmers. Your job is just to inspire them - to show them possibilities, to excite them, to empower them to play. ChrisA From marko at pacujo.net Wed Nov 20 14:25:03 2019 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 20 Nov 2019 21:25:03 +0200 Subject: Use epoll but still lose packet References: Message-ID: <87eey2fj00.fsf@elektro.pacujo.net> Dennis Lee Bieber : > (though as I don't really understand the use of this function, that > may just mean that all the events will be in the one return structure, > and not that there is only one event). I use epoll almost every day. You've done a good job explaining it. > Given that your code only has one socket/file-descriptor I have > to ponder why a simple select() isn't usable; nor do I see anything > that detects who is sending the packet (there is no .accept() or > .recv_from() which would provide the remote host information). The main driver for epoll vs select is that every call to select causes the kernel to parse the event specification from the arguments, which can be slow if there are a lot of file descriptors to monitor. With epoll, the event specification is loaded to the kernel only once. To get a full benefit from epoll, you call it with the EPOLLET flag. One nasty problem with epoll's predecessors (select and poll) is that when output buffers are full, you have to turn on output monitoring separately, and when the output buffers have room again, you need to turn output monitoring off. That can create annoying code and silly traffic between the process and the kernel. The EPOLLET flag only gives you a notification when the situation changes. Thus, you would monitor for EPOLLIN|EPOLLOUT|EPOLLET and forget the file descriptor. epoll_wait will return whenever the input or output status changes. Really economical. You must be careful, though, if you forget to react to an event, you won't get another notification before the status changes again. Marko From akkana at shallowsky.com Wed Nov 20 15:29:26 2019 From: akkana at shallowsky.com (Akkana Peck) Date: Wed, 20 Nov 2019 13:29:26 -0700 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: References: Message-ID: <20191120202926.GA1901@shallowsky.com> Chris Angelico writes: > On Thu, Nov 21, 2019 at 4:42 AM Nick Sarbicki wrote: > > RE Conda and distros - I'd forget about them, in my experience you may as > > well learn to use pip and install what you need that way, in the long term > > Agreed. More agreement. Someone at the local makerspace recently tried to teach a beginning Python class; the first hour and a half lecture was entirely devoted to trying to get Anaconda installed on everyone's machines, and most of the people still didn't have it installed by the end. I heard a lot of the people from the first lecture gave up and didn't come back for the second lecture because they still didn't have a working environment. Of the people who did return, I saw some of them (fairly technical users to begin with, just not in Python) later struggling with conda updates that went wrong. Installing Python on Windows isn't trivial, but if you lead them through each of the steps (hint: be sure not to miss the small checkbox about adding Python to the path -- you have to scroll down to the bottom of the options list to see it, and it's not checked by default) it shouldn't be too bad. Also, have a copy of the installer available on a USB stick or three unless the lecture hall is guaranteed to have flawless wi-fi. Can you get a couple of Windows and Mac using friends (who don't already have Python) to help you try out the installers before the class? Or, for Windows, you could try one of these virtualbox images: https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/ > In fact, given the tight context here, I would go even further > and stick to JUST the standard library - there's already way more in > there than you need for a single lecture. Maybe just name-drop pip and For a general Python class I'd agree, but since these are linguists, it will help to have a linguistics package or two to show how Python can help them in their work. That means that if you don't use conda, you should probably have them create a virtualenv so they can run pip safely. > > In summary I'd aim to inspire not to teach - so show some basics at the > > beginning to show how accessible it can be, and then feel free to jump off > > into advanced python land to showcase what is possible using whatever you > > are most comfortable with. Essentially show them they can learn python, and > > then inspire them to want to learn python. > > Absolutely agreed. Your job is not to turn them into programmers. Your > job is just to inspire them - to show them possibilities, to excite > them, to empower them to play. More agreement. But that's why it's important to have linguistics packages. If you can give them a simple program that actually does something useful and relevant to their jobs, that will be a lot more inspiring than implementing Hello World or Fibonacci numbers or even web scraping. ...Akkana From self at gkayaalp.com Wed Nov 20 15:41:00 2019 From: self at gkayaalp.com (=?utf-8?Q?G=C3=B6ktu=C4=9F_Kayaalp?=) Date: Wed, 20 Nov 2019 23:41:00 +0300 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: Message-ID: Andrew Z wrote: > Goktug, > Im not clear what is the objective of the lecture? I understand it is an > intro, but what are you trying to achieve? Basically I need to introduce my non-programmer friends to Python and show them that they can easily learn to do their statistics with it, produce nice graphs, etc. And I need to give them nice pointers so that they can self-teach w/o much friction. > I didnt read all the details, but maybe you can look into creating a > docker/virtual box image with everything preinstalled. > Good luck. That?d definitely be my cup of tea, but sadly also too involved / technical for my audience of absolute non-techies. Cheers, -gk. -- ?. G?ktu? Kayaalp 024C 30DD 597D 142B 49AC 40EB 465C D949 B101 2427 From arj.python at gmail.com Wed Nov 20 15:49:23 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 21 Nov 2019 00:49:23 +0400 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: References: Message-ID: I have a draft of a concise py book for data people which i am preparing, might be useful to you. https://drive.google.com/file/d/1IKLBuJJWQKvcTWu-REsgm-JUGSvytBUu/view?usp=drivesdk Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius On Wed, 20 Nov 2019, 20:54 G?ktu? Kayaalp, wrote: > Hi all, > > I am responsible of giving my colleagues in from linguistics MA > programme an intro to Python, and programming, with a focus on > statistics. It?ll be a single lecture, and I probably won?t be able to > do more than give some demos and then some pointers to actually properly > learn how to use the tools. > > The problem is I?m a rather techie power user and my audience the exact > opposite, so I feel like I could make use of some guidance as to how to > bridge the gap and be useful. > > I want to stick to Python 3, demo them a few basics of programming, then > how to use matplotlib, Jupyter notebooks (is this what IPyNBs became?), > and some descriptive statistics. All this needs to happen within the > span of a single lecture (tho if people are interested I?ll offer to do > a few more in our own time), so 45min~1h. > > The first problem is installation: apart from me, a Debian user, > everybody has Windows or Mac laptops, and IDK how you install Python on > them. I feel like choosing one of the distros is a good idea: I could > just put the installers on a USB and hand it out, or just send them a > message with simple steps to follow and set themselves up beforehand. > Thing is, IDK nothing about distros. Anaconda seems to be the best > options, but comes with complications like an IDE, as opposed to just > working with notebooks, and is huge. Also, seems to include R stuff. > Spyder looks nice, but I don?t want to freak people out with such an > unfamiliar environment as an IDE just within the first few moments they > encounter programming. These are all humanities people. Another > problem is that Anaconda has ?conda?, a non-standard package manager, > and I?m kinda vary of introducing that to people: should I talk of pip, > should I leave it out? I feel like I should just stick to pip and leave > conda out, but IDK. Python(x,y) is interesting, but it?s apparently > Py2k only, and that?s a no-no. > > So, am I better off telling people to install Anaconda, or plain Py3k + > a selection of packages (which maybe I make into a .zip or something)? > > Then, I need good pointers to hand out: links to good introductions to > Python, programming, and statistical use of Python. Thing is, I?ve > always learned the hacker way, i.e. skip the docs, tinker with stuff. > Thus, IDK of any good resources out of experience, and I want to ask you > all for some recommendations. I prefer free and tutorial-like stuff, > but I?ll teach them how to use the stdlib reference too. > > What are some good self-teaching material for those who are new to > programming and Python, and need to mainly do statistics with > experimental data? > > Finally, I?m looking for recommendations on what to show and how. My > current master plan is > > - what?s the use of programming for a linguist > - an abstract idea of what programming is > - basic intro to Python syntax > - demo how to load and clean up some data > - demo matplotlib > - demo jupyter notebooks > - compare with alternatives: R, SPSS, other? > - briefly refer to libraries for > - NLP > - AI? > - lots of links on > - how to learn enough coding for number crunching and plotmaking > - how to make use of stdlib reference > - how to find and utilise packages and their docs > - ...? > > I plan to produce a handout with all this info neatly organised, and > just go with a (few) Jupyter notebooks for the rest (resisting hard the > urge to go in with Emacs Org Mode instead :)). > > I?m looking forward to any recommendations from youse. The deadline is > about a month and a half away, and I really want to give people > something operationable. People are stuck with BS like SPSS, too simple > and too pricy, when a few lines of Python (or R) is all they need. I > came here because IDK teaching about this stuff, and I haven?t left the > comfort zones of a programmer ever before, so this is some new > experience for me and I don?t want to botch it. > > Thanks a lot in advance, > > G?ktu?. > > -- > ?. G?ktu? Kayaalp > 024C 30DD 597D 142B 49AC > 40EB 465C D949 B101 2427 > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Wed Nov 20 15:51:04 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Nov 2019 07:51:04 +1100 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: References: Message-ID: On Thu, Nov 21, 2019 at 7:44 AM G?ktu? Kayaalp wrote: > > > Andrew Z wrote: > > Goktug, > > Im not clear what is the objective of the lecture? I understand it is an > > intro, but what are you trying to achieve? > > Basically I need to introduce my non-programmer friends to Python and > show them that they can easily learn to do their statistics with it, > produce nice graphs, etc. And I need to give them nice pointers so that > they can self-teach w/o much friction. > Oh, okay. Producing graphs can't really be done with just the standard library, so I withdraw my earlier recommendation to minimize dependencies. It means you're going to need to spend a bit of your time making sure they can pip-install things, but on the upside, you're going to have way more "wow" factor from a few simple lines of pyplot code that pop up a pretty little graph. ChrisA From self at gkayaalp.com Wed Nov 20 16:01:18 2019 From: self at gkayaalp.com (=?utf-8?Q?G=C3=B6ktu=C4=9F_Kayaalp?=) Date: Thu, 21 Nov 2019 00:01:18 +0300 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: Message-ID: Nick Sarbicki wrote: > Hi Goktug, > > Firstly good luck, inspiring a crowd of people who have never learnt to > code (and probably never expected to) to want to code sounds like a > daunting task. > > I think you have broadly the right idea in that you want to spend only a > little bit of time on the basic syntax before demoing what you can do with > the language. I would spend the beginning of the lecture focusing on how > readable code can be - an attempt to make it less scary to people who > haven't touched code before - and then spend the rest of the time showing > the fun things you can do with it. I?m lucky that when I introduced the idea, my peers were really excited about it. Readability is indeed a nice idea, because they are not familiar with coding and don?t really know how straight forward a thing it actually is, at least when all you?re trying to do is load some CSV files and do some t-tests, chi^2, correlation, and plots. > I can't see trying to take students from no code to competent SciPy users > in one lecture as a possible feat. So it would be best to simply inspire > them to want to learn more themselves. In which case I'd encourage you to > have a think as to what would be the most inspiring examples? Are jupyter > notebooks on their own something that inspires? Probably not - although > they are nice for showcasing code in. Is ETL exciting? Maybe in extremely > rare cases... NLP, AI etc can be pretty fun and powerful. Graphing > libraries such as MatPlotLib as they are visual is always good as well. Can > demo some (probably useless) 3D charts or XKCD mode if you want. If I could demo say an NN, that?d be crazy interesting, but sadly IDK nothing about the practicalities of AI in general. It comes up a lot and people know nothing about it. If you have some pointers for a good tutorial tho, I?d try my hand at it. I haven?t used notebooks before, and I?m not really a fan: they look heavy-weight and not much better than Org Mode codeblocks to me. But I can?t risk introducing these people to Emacs, they look at it in weid ways when they see it on my laptop already :) My plan is, mostly focus on graphs. We?ll have just learned some advanced-ish statistics stuff by the time I?ll present, so that?d probably be very interesting to everybody. > RE Conda and distros - I'd forget about them, in my experience you may as > well learn to use pip and install what you need that way, in the long term > it is faster and more flexible. Python generally supplies a perfectly good > installer for most operating systems at python.org - no need for anything > else. Keeping it to just standard python (+ some libs you don't explicitly > need to explain) makes it less complex. Also - as biased as it sounds > coming from a Python developer - I'm not sure I'd want to discuss > alternatives (R, SPSS etc.) as it just provides more confusing choices. This was the confirmation I was looking for :) Then I?ll just install SciPy packages on a plain Python and call it done. Is there a way I distribute an installer / a portable zipball that comes with these packages? Or do you think a non-programmer could follow the instructions to install? I have friends with Macs and PCs that I think I can use for testing procedures. W.r.t. alternatives, I?ve already heard the statistician that helps us with learning stats mention it, so my idea was that I could introduce some alts and explain why Python is a good choice. But if that?s going to be confusing, I can skip that. > In summary I'd aim to inspire not to teach - so show some basics at the > beginning to show how accessible it can be, and then feel free to jump off > into advanced python land to showcase what is possible using whatever you > are most comfortable with. Essentially show them they can learn python, and > then inspire them to want to learn python. That?s kinda my goal: inspire, excite, and give good links so that they can get on with learning quickly. BTW, FWIW, I?ll make the material and code for these lectures available on GitHub once I?ll have them prepared. If anybody will be interested, I may even try to make a video version and put it up somewhere. > Feel free to ignore all of these thoughts, they are highly subjective. Thanks a lot for your thoughts! I really appreciate your help. Cheers, -gk. -- ?. G?ktu? Kayaalp 024C 30DD 597D 142B 49AC 40EB 465C D949 B101 2427 From formisc at gmail.com Wed Nov 20 16:03:05 2019 From: formisc at gmail.com (Andrew Z) Date: Wed, 20 Nov 2019 16:03:05 -0500 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: References: Message-ID: Look into https://repl.it On Wed, Nov 20, 2019, 15:43 G?ktu? Kayaalp wrote: > > Andrew Z wrote: > > Goktug, > > Im not clear what is the objective of the lecture? I understand it is > an > > intro, but what are you trying to achieve? > > Basically I need to introduce my non-programmer friends to Python and > show them that they can easily learn to do their statistics with it, > produce nice graphs, etc. And I need to give them nice pointers so that > they can self-teach w/o much friction. > > > I didnt read all the details, but maybe you can look into creating a > > docker/virtual box image with everything preinstalled. > > Good luck. > > That?d definitely be my cup of tea, but sadly also too involved / > technical for my audience of absolute non-techies. > > Cheers, > > -gk. > > -- > ?. G?ktu? Kayaalp > 024C 30DD 597D 142B 49AC > 40EB 465C D949 B101 2427 > -- > https://mail.python.org/mailman/listinfo/python-list > From self at gkayaalp.com Wed Nov 20 16:06:17 2019 From: self at gkayaalp.com (=?utf-8?Q?G=C3=B6ktu=C4=9F_Kayaalp?=) Date: Thu, 21 Nov 2019 00:06:17 +0300 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: Message-ID: Chris Angelico wrote: >On Thu, Nov 21, 2019 at 4:42 AM Nick Sarbicki wrote: >> RE Conda and distros - I'd forget about them, in my experience you may as >> well learn to use pip and install what you need that way, in the long term >> it is faster and more flexible. Python generally supplies a perfectly good >> installer for most operating systems at python.org - no need for anything >> else. Keeping it to just standard python (+ some libs you don't explicitly >> need to explain) makes it less complex. > >Agreed. In fact, given the tight context here, I would go even further >and stick to JUST the standard library - there's already way more in >there than you need for a single lecture. Maybe just name-drop pip and >hint at the fact that there's a lot more to Python than just what you >see here, but other than that, keep it really simple. I?d be extatic if I could do that, but AFAIK there are no plotting libraries in the stdlib. ?statistics? is nice, but lacks stuff we need often as linguists, like chi^2, t-tests, correlations, (m)anova, &c. >> In summary I'd aim to inspire not to teach - so show some basics at the >> beginning to show how accessible it can be, and then feel free to jump off >> into advanced python land to showcase what is possible using whatever you >> are most comfortable with. Essentially show them they can learn python, and >> then inspire them to want to learn python. >> > >Absolutely agreed. Your job is not to turn them into programmers. Your >job is just to inspire them - to show them possibilities, to excite >them, to empower them to play. Thanks! -gk. -- ?. G?ktu? Kayaalp 024C 30DD 597D 142B 49AC 40EB 465C D949 B101 2427 From self at gkayaalp.com Wed Nov 20 16:21:25 2019 From: self at gkayaalp.com (=?utf-8?Q?G=C3=B6ktu=C4=9F_Kayaalp?=) Date: Thu, 21 Nov 2019 00:21:25 +0300 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: <20191120202926.GA1901@shallowsky.com> (message from Akkana Peck on Wed, 20 Nov 2019 13:29:26 -0700) Message-ID: On 2019-11-20 13:29 -07, Akkana Peck wrote: > Chris Angelico writes: >> On Thu, Nov 21, 2019 at 4:42 AM Nick Sarbicki wrote: >> > RE Conda and distros - I'd forget about them, in my experience you may as >> > well learn to use pip and install what you need that way, in the long term >> >> Agreed. > > More agreement. Someone at the local makerspace recently tried to > teach a beginning Python class; the first hour and a half lecture > was entirely devoted to trying to get Anaconda installed on > everyone's machines, and most of the people still didn't have it > installed by the end. I heard a lot of the people from the first > lecture gave up and didn't come back for the second lecture because > they still didn't have a working environment. Of the people who did > return, I saw some of them (fairly technical users to begin with, just > not in Python) later struggling with conda updates that went wrong. Wow. This was good to know, thanks a lot! > Installing Python on Windows isn't trivial, but if you lead them > through each of the steps (hint: be sure not to miss the small > checkbox about adding Python to the path -- you have to scroll down > to the bottom of the options list to see it, and it's not checked by > default) it shouldn't be too bad. Also, have a copy of the installer > available on a USB stick or three unless the lecture hall is > guaranteed to have flawless wi-fi. Again, great tip, thanks! > Can you get a couple of Windows and Mac using friends (who don't > already have Python) to help you try out the installers before the class? > Or, for Windows, you could try one of these virtualbox images: > https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/ I?ve just asked my brother to try it out for me. Later on, I?ll try with my friends. Thanks a lot for the link, I?ll try it out. Cheers, -gk. -- ?. G?ktu? Kayaalp 024C 30DD 597D 142B 49AC 40EB 465C D949 B101 2427 From self at gkayaalp.com Wed Nov 20 16:41:51 2019 From: self at gkayaalp.com (=?utf-8?Q?G=C3=B6ktu=C4=9F_Kayaalp?=) Date: Thu, 21 Nov 2019 00:41:51 +0300 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: (message from Andrew Z on Wed, 20 Nov 2019 16:03:05 -0500) Message-ID: On 2019-11-20 16:03 -05, Andrew Z wrote: > Look into https://repl.it Sadly this apparaently can?t do plots. > On Wed, Nov 20, 2019, 15:43 G?ktu? Kayaalp wrote: > >> >> Andrew Z wrote: >> > Goktug, >> > Im not clear what is the objective of the lecture? I understand it is >> an >> > intro, but what are you trying to achieve? >> >> Basically I need to introduce my non-programmer friends to Python and >> show them that they can easily learn to do their statistics with it, >> produce nice graphs, etc. And I need to give them nice pointers so that >> they can self-teach w/o much friction. >> >> > I didnt read all the details, but maybe you can look into creating a >> > docker/virtual box image with everything preinstalled. >> > Good luck. >> >> That?d definitely be my cup of tea, but sadly also too involved / >> technical for my audience of absolute non-techies. >> >> Cheers, >> >> -gk. >> >> -- >> ?. G?ktu? Kayaalp >> 024C 30DD 597D 142B 49AC >> 40EB 465C D949 B101 2427 >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > [2:text/html Show Save:noname (5kB)] > -- ?. G?ktu? Kayaalp 024C 30DD 597D 142B 49AC 40EB 465C D949 B101 2427 From tjreedy at udel.edu Wed Nov 20 16:58:11 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 20 Nov 2019 16:58:11 -0500 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: References: Message-ID: On 11/20/2019 11:09 AM, G?ktu? Kayaalp wrote: > The first problem is installation: apart from me, a Debian user, > everybody has Windows or Mac laptops, and IDK how you install Python on > them. The simplest thing is to use the 3.8.0 python.org installers. This use pip to add anything you consider essential. -- Terry Jan Reedy From arj.python at gmail.com Wed Nov 20 17:02:20 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 21 Nov 2019 02:02:20 +0400 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: References: Message-ID: Besides the mistakes in the pdf (random.shuffle) the idea is to get the right environment then py basics then numpy+pandas then viz seaborn or minimal matplotlib Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius On Thu, 21 Nov 2019, 00:49 Abdur-Rahmaan Janhangeer, wrote: > I have a draft of a concise py book for data people which i am preparing, > might be useful to you. > > > https://drive.google.com/file/d/1IKLBuJJWQKvcTWu-REsgm-JUGSvytBUu/view?usp=drivesdk > > Abdur-Rahmaan Janhangeer > http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ > Mauritius > > On Wed, 20 Nov 2019, 20:54 G?ktu? Kayaalp, wrote: > >> Hi all, >> >> I am responsible of giving my colleagues in from linguistics MA >> programme an intro to Python, and programming, with a focus on >> statistics. It?ll be a single lecture, and I probably won?t be able to >> do more than give some demos and then some pointers to actually properly >> learn how to use the tools. >> >> The problem is I?m a rather techie power user and my audience the exact >> opposite, so I feel like I could make use of some guidance as to how to >> bridge the gap and be useful. >> >> I want to stick to Python 3, demo them a few basics of programming, then >> how to use matplotlib, Jupyter notebooks (is this what IPyNBs became?), >> and some descriptive statistics. All this needs to happen within the >> span of a single lecture (tho if people are interested I?ll offer to do >> a few more in our own time), so 45min~1h. >> >> The first problem is installation: apart from me, a Debian user, >> everybody has Windows or Mac laptops, and IDK how you install Python on >> them. I feel like choosing one of the distros is a good idea: I could >> just put the installers on a USB and hand it out, or just send them a >> message with simple steps to follow and set themselves up beforehand. >> Thing is, IDK nothing about distros. Anaconda seems to be the best >> options, but comes with complications like an IDE, as opposed to just >> working with notebooks, and is huge. Also, seems to include R stuff. >> Spyder looks nice, but I don?t want to freak people out with such an >> unfamiliar environment as an IDE just within the first few moments they >> encounter programming. These are all humanities people. Another >> problem is that Anaconda has ?conda?, a non-standard package manager, >> and I?m kinda vary of introducing that to people: should I talk of pip, >> should I leave it out? I feel like I should just stick to pip and leave >> conda out, but IDK. Python(x,y) is interesting, but it?s apparently >> Py2k only, and that?s a no-no. >> >> So, am I better off telling people to install Anaconda, or plain Py3k + >> a selection of packages (which maybe I make into a .zip or something)? >> >> Then, I need good pointers to hand out: links to good introductions to >> Python, programming, and statistical use of Python. Thing is, I?ve >> always learned the hacker way, i.e. skip the docs, tinker with stuff. >> Thus, IDK of any good resources out of experience, and I want to ask you >> all for some recommendations. I prefer free and tutorial-like stuff, >> but I?ll teach them how to use the stdlib reference too. >> >> What are some good self-teaching material for those who are new to >> programming and Python, and need to mainly do statistics with >> experimental data? >> >> Finally, I?m looking for recommendations on what to show and how. My >> current master plan is >> >> - what?s the use of programming for a linguist >> - an abstract idea of what programming is >> - basic intro to Python syntax >> - demo how to load and clean up some data >> - demo matplotlib >> - demo jupyter notebooks >> - compare with alternatives: R, SPSS, other? >> - briefly refer to libraries for >> - NLP >> - AI? >> - lots of links on >> - how to learn enough coding for number crunching and plotmaking >> - how to make use of stdlib reference >> - how to find and utilise packages and their docs >> - ...? >> >> I plan to produce a handout with all this info neatly organised, and >> just go with a (few) Jupyter notebooks for the rest (resisting hard the >> urge to go in with Emacs Org Mode instead :)). >> >> I?m looking forward to any recommendations from youse. The deadline is >> about a month and a half away, and I really want to give people >> something operationable. People are stuck with BS like SPSS, too simple >> and too pricy, when a few lines of Python (or R) is all they need. I >> came here because IDK teaching about this stuff, and I haven?t left the >> comfort zones of a programmer ever before, so this is some new >> experience for me and I don?t want to botch it. >> >> Thanks a lot in advance, >> >> G?ktu?. >> >> -- >> ?. G?ktu? Kayaalp >> 024C 30DD 597D 142B 49AC >> 40EB 465C D949 B101 2427 >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From python at mrabarnett.plus.com Wed Nov 20 18:31:39 2019 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 20 Nov 2019 23:31:39 +0000 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: References: Message-ID: <3737dbd9-10ba-d6f8-50ad-066127651ee4@mrabarnett.plus.com> On 2019-11-20 21:58, Terry Reedy wrote: > On 11/20/2019 11:09 AM, G?ktu? Kayaalp wrote: > >> The first problem is installation: apart from me, a Debian user, >> everybody has Windows or Mac laptops, and IDK how you install Python on >> them. > > The simplest thing is to use the 3.8.0 python.org installers. This use > pip to add anything you consider essential. > For Windows, I use "Windows x86-64 executable installer" for 64-bit and "Windows x86 executable installer" for 32-bit from https://www.python.org/downloads/windows/. From user at us.er Wed Nov 20 18:35:31 2019 From: user at us.er (user) Date: Wed, 20 Nov 2019 23:35:31 +0000 (UTC) Subject: Can we use Python for hacking? References: Message-ID: On Tue, 12 Nov 2019 08:49:44 +0400, Abdur-Rahmaan Janhangeer wrote: > Greetings all, > > Someone requested my answer to the question: "Can we use Python for > hacking?" > > I compiled some interesting tools and uses here . > That's as far as i could see. If someone has more examples, he can > share! > > Yours, > > Abdur-Rahmaan Janhangeer pythonmembers.club > | github > > Mauritius can you post more links for python interesting tools and uses? any resource related with python and pentesting? Thank you From pahome.chen at mirlab.org Wed Nov 20 20:46:32 2019 From: pahome.chen at mirlab.org (lampahome) Date: Thu, 21 Nov 2019 09:46:32 +0800 Subject: Use epoll but still lose packet In-Reply-To: References: Message-ID: Dennis Lee Bieber ? 2019?11?21? ?? ??2:17??? > On Wed, 20 Nov 2019 18:51:31 +0800, lampahome > declaimed the following: > > > > >I only use a while loop to catch events like below: > >import select, socket > >sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > >sock.bind() > > Documentation indicates that one must provide an address (ip, > port) for > the bind -- there is no default described. > > sorry, I just write a brief code so I don't write whole detail ex: (ip, port). But it can receive any connection and bind successfully. > >sock.listen(10) > > You've specified that 10 connections can be held in the backlog, > any > beyond that will be refused. > > But there's one client and it send 128 messages with different length. > for fd,event in events: > > if event & select.EPOLLIN: > > sock.recv(1024) > >... > > Documentation is a bit week -- there is no description of what > .poll() > returns in the help file. > > Point #1: you are using STREAM => implies TCP. TCP is not a > "message" > related protocol. Multiple "sends" can be one "receive" packet. One "send" > can also be multiple "receive" packets. You truncated anything that would > show if your processing is parsing out some high-level protocol showing the > handling of such combined or split packets. > > Maybe this is the point! Multiple sends which doesn't full a 1024-length buffer will make me receive one packet. > Also, the help system links to > https://linux.die.net/man/4/epoll > which has > """ > Q7 > If more than one event comes in between epoll_wait(2) calls, are they > combined or reported separately? > A7 > They will be combined. > """ > From nick.a.sarbicki at gmail.com Thu Nov 21 05:02:03 2019 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Thu, 21 Nov 2019 10:02:03 +0000 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: <3737dbd9-10ba-d6f8-50ad-066127651ee4@mrabarnett.plus.com> References: <3737dbd9-10ba-d6f8-50ad-066127651ee4@mrabarnett.plus.com> Message-ID: > The simplest thing is to use the 3.8.0 python.org installers. This use > pip to add anything you consider essential. As mentioned previously, you do need to make sure that they tick the box to add Python to the PATH on windows. It is almost guaranteed someone will not do that and will then have a very hard time figuring out what has gone wrong (happens to me every time I teach). Considering that this is a lecture and not a workshop I'm assuming the students aren't actively installing and running python while you are teaching. In which case, whilst I would mention pip, I would probably just have the required libs preinstalled on my computer ready to go. Learning pip is easy to do and if they're interested later can be taught separately. But watching someone installing packages on the terminal is not very interesting. On the other hand if the students are actively following along and running python within the lecture then they will obviously need to be shown how to do this. Also whilst the remit of the lecture is to showcase how to do statistics in Python, I wouldn't take this as an absolute limit. I would go through examples of graphs, probably taking inspiration from https://www.tylervigen.com/spurious-correlations and using something like dash (https://dash.plot.ly/). I would also try to show more creative ways of playing with data - for instance I worked on this project dedicated to showing data using GIFs ( https://datagifmaker.withgoogle.com/editor/racetrack - don't look too hard at the representations though). But instead of spending a whole lecture explicitly on statistics I would probably use the last 10 minutes showcasing other uses of Python which are (apologies to those who find statistics utterly encapsulating) a bit more interesting. For instance I have a <200 LOC game of pong (technically a _graphical_ user interface) which is usually fun to showcase ( https://gitlab.com/ndevox/pygame-pong/blob/master/pong.py). I'd also be tempted to show off things like websites (which could display statistics publicly), chatbots (which, if using something like an NLTK classifier, are essentially statistical machines) etc. Think about what interests you the most and see if you can display it on the screen in some way. Essentially whilst it is very important to show them to make graphs in various ways, you'll probably struggle to captivate the entire audience with this. Whereas ending with some slightly wilder but more enticing examples can make those who weren't interested in the statistics want to pay more attention to what you have been saying. - Nick On Wed, Nov 20, 2019 at 11:33 PM MRAB wrote: > On 2019-11-20 21:58, Terry Reedy wrote: > > On 11/20/2019 11:09 AM, G?ktu? Kayaalp wrote: > > > >> The first problem is installation: apart from me, a Debian user, > >> everybody has Windows or Mac laptops, and IDK how you install Python on > >> them. > > > > The simplest thing is to use the 3.8.0 python.org installers. This use > > pip to add anything you consider essential. > > > For Windows, I use "Windows x86-64 executable installer" for 64-bit and > "Windows x86 executable installer" for 32-bit from > https://www.python.org/downloads/windows/. > -- > https://mail.python.org/mailman/listinfo/python-list > From harirammanohar159 at gmail.com Thu Nov 21 07:03:06 2019 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Thu, 21 Nov 2019 04:03:06 -0800 (PST) Subject: Unable to retrieve data from Juypter notebook Message-ID: <1616c909-5788-4b71-bf5a-0adfefadca25@googlegroups.com> Trying to load cifar10 dataset from keras library using juypter notebook, but i am getting below error SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1051) During handling of the above exception, another exception occurred: Exception: URL fetch failure on https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz: None -- [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1051) So i tried to remove https in the source file cifar10.py, then i am getting forbidden Exception: URL fetch failure on http://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz: 403 -- Forbidden But if i use the same url from the browser i am able to download without any issues.. can any one please help me out !! Thanks in Advance. From self at gkayaalp.com Thu Nov 21 07:27:56 2019 From: self at gkayaalp.com (=?utf-8?Q?G=C3=B6ktu=C4=9F_Kayaalp?=) Date: Thu, 21 Nov 2019 15:27:56 +0300 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: (message from Nick Sarbicki on Thu, 21 Nov 2019 10:02:03 +0000) Message-ID: On 2019-11-21 10:02 GMT, Nick Sarbicki wrote: >> The simplest thing is to use the 3.8.0 python.org installers. This use >> pip to add anything you consider essential. > > As mentioned previously, you do need to make sure that they tick the box to > add Python to the PATH on windows. It is almost guaranteed someone will not > do that and will then have a very hard time figuring out what has gone > wrong (happens to me every time I teach). > > Considering that this is a lecture and not a workshop I'm assuming the > students aren't actively installing and running python while you are > teaching. In which case, whilst I would mention pip, I would probably just > have the required libs preinstalled on my computer ready to go. Learning > pip is easy to do and if they're interested later can be taught separately. > But watching someone installing packages on the terminal is not very > interesting. On the other hand if the students are actively following along > and running python within the lecture then they will obviously need to be > shown how to do this. So I asked someone to try test installing Python 3 and using pip to install SciPy, and it failed even with my remote guidance. Hopefully I?ll have some time with a Windows PC in the coming weeks to test myself, but yeah, installation seems like it?ll be a problem. In our case we failed twice b/c we didn?t have vcredist and vc++ build tools, but still failed when we instaled them: IDK if it wants the entire Visual Studio, which is a whopping 20G of download. My plan is to prepare a guide for them to get set up on their computers, but not for the lecture. It?s informal, but I don?t really want to lose time with a small installfest. The instructions are aimed at easy set up after or before class only. Guess I can help those who fail later on private time... > Also whilst the remit of the lecture is to showcase how to do statistics in > Python, I wouldn't take this as an absolute limit. I would go through > examples of graphs, probably taking inspiration from > https://www.tylervigen.com/spurious-correlations and using something like > dash (https://dash.plot.ly/). I would also try to show more creative ways > of playing with data - for instance I worked on this project dedicated to > showing data using GIFs ( > https://datagifmaker.withgoogle.com/editor/racetrack - don't look too hard > at the representations though). These are some beautiful links, and especially that first one I?ll definitely use it for my Pearson Correlation mini-lesson next week, so thanks a lot! > But instead of spending a whole lecture explicitly on statistics I would > probably use the last 10 minutes showcasing other uses of Python which are > (apologies to those who find statistics utterly encapsulating) a bit more > interesting. For instance I have a <200 LOC game of pong (technically a > _graphical_ user interface) which is usually fun to showcase ( > https://gitlab.com/ndevox/pygame-pong/blob/master/pong.py). I'd also be > tempted to show off things like websites (which could display statistics > publicly), chatbots (which, if using something like an NLTK classifier, are > essentially statistical machines) etc. Think about what interests you the > most and see if you can display it on the screen in some way. > > Essentially whilst it is very important to show them to make graphs in > various ways, you'll probably struggle to captivate the entire audience > with this. Whereas ending with some slightly wilder but more enticing > examples can make those who weren't interested in the statistics want to > pay more attention to what you have been saying. > > - Nick > > On Wed, Nov 20, 2019 at 11:33 PM MRAB wrote: > >> On 2019-11-20 21:58, Terry Reedy wrote: >> > On 11/20/2019 11:09 AM, G?ktu? Kayaalp wrote: >> > >> >> The first problem is installation: apart from me, a Debian user, >> >> everybody has Windows or Mac laptops, and IDK how you install Python on >> >> them. >> > >> > The simplest thing is to use the 3.8.0 python.org installers. This use >> > pip to add anything you consider essential. >> > >> For Windows, I use "Windows x86-64 executable installer" for 64-bit and >> "Windows x86 executable installer" for 32-bit from >> https://www.python.org/downloads/windows/. >> -- >> https://mail.python.org/mailman/listinfo/python-list >> -- ?. G?ktu? Kayaalp 024C 30DD 597D 142B 49AC 40EB 465C D949 B101 2427 From Emmanuel.Coirier at caissedesdepots.fr Thu Nov 21 11:41:29 2019 From: Emmanuel.Coirier at caissedesdepots.fr (Coirier, Emmanuel) Date: Thu, 21 Nov 2019 16:41:29 +0000 Subject: Inconsistent binary link creation when creating virtual environment with venv module Message-ID: Hello everyone, I'm currently creating virtual environments with the venv module included in Python ("python -m venv "). I've noticed that the environment is not always consistent when using the same base interpreter with different names. When I use the alias python3.n (python3.6 / python3.7 / python3.8) to create the environment like this example : python3.7 -m venv venv37 The environment is created with 3 links to the python binary : lrwxrwxrwx 1 root root 9 21 nov. 17:29 python -> python3.7 lrwxrwxrwx 1 root root 9 21 nov. 17:29 python3 -> python3.7 lrwxrwxrwx 1 root root 43 21 nov. 17:29 python3.7 -> /place/to/real/bin/python3.7 But when I use the bare python interpreter (python without version number in its name) like this : python -m venv venv37 The environment is only created with 2 links to the python binary : lrwxrwxrwx 1 root root 40 21 nov. 17:33 python -> /place/to/real/bin/python lrwxrwxrwx 1 root root 6 21 nov. 17:33 python3 -> python The python3.7 link is missing. This behavior is not observed with the pip installer which is always shipped in 3 flavors (pip, pip3, pip3.7) Beside how this is coded, is there any functionnal reason to explain this behavior ? Shouldn't the 3 links be always created, regardless of which alias is used ? Best regards, -- Emmanuel Coirier Informatique CDC Interne Ce message et toutes les pi?ces jointes (ci-apr?s le ?message?) sont confidentiels et ?tablis ? l?intention exclusive de ses destinataires. Toute utilisation de ce message non conforme ? sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. Si vous recevez ce message par erreur, merci de le d?truire sans en conserver de copie et d?en avertir imm?diatement l?exp?diteur. Internet ne permettant pas de garantir l?int?grit? de ce message, la Caisse des D?p?ts et Consignations d?cline toute responsabilit? au titre de ce message s?il a ?t? modifi?, alt?r?, d?form? ou falsifi?. Par ailleurs et malgr? toutes les pr?cautions prises pour ?viter la pr?sence de virus dans nos envois, nous vous recommandons de prendre, de votre c?t?, les mesures permettant d'assurer la non-introduction de virus dans votre syst?me informatique. This email message and any attachments (?the email?) are confidential and intended only for the recipient(s) indicated. If you are not an intended recipient, please be advised that any use, dissemination, forwarding or copying of this email whatsoever is prohibited without prior written consent of Caisse des Depots et Consignations. If you have received this email in error, please delete it without saving a copy and notify the sender immediately. Internet emails are not necessarily secure, and Caisse des Depots et Consignations declines responsibility for any changes that may have been made to this email after it was sent. While we take all reasonable precautions to ensure that viruses are not transmitted via emails, we recommend that you take your own measures to prevent viruses from entering your computer system. From gheskett at shentel.net Thu Nov 21 13:14:35 2019 From: gheskett at shentel.net (Gene Heskett) Date: Thu, 21 Nov 2019 13:14:35 -0500 Subject: Recommendations for intro to python+programming lecture to Humanities MA students In-Reply-To: References: <20191120202926.GA1901@shallowsky.com> Message-ID: <201911211314.35526.gheskett@shentel.net> On Thursday 21 November 2019 11:27:11 Dennis Lee Bieber wrote: > The only time I had to do less than "automated" installs was my first > Python -- v1.4 (maybe 1.3) on a Commodore Amiga. > That takes us back up the log quite a ways, but it also puts early python up against Bill Hawes and his truly did it all, Arexx. All others fell by the wayside once we had a compiler for Arexx. But for all the time it took Bill to write that, commode-door stiffed him, never paying him a dime. He wasn't the only one they stiffed of course. > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com http://wlfraed.microdiversity.freeddns.org/ Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page From hjp-python at hjp.at Thu Nov 21 18:02:52 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 22 Nov 2019 00:02:52 +0100 Subject: How to delay until a next increment of time occurs ? In-Reply-To: References: <5quqsep867ca775s10tah1jq1mktqu70mh@4ax.com> <20191118214103.GC4863@hjp.at> Message-ID: <20191121230252.GA21556@hjp.at> On 2019-11-19 08:57:23 +0100, R.Wieser wrote: > First things first: For some reason I see your message coming in empty, but > with two attachments. An "att*.txt" one with the actual message contents, > and a "signature.asc". Makes it kind of hard to read ... You seem to be using MS Outlook Express 6.0. That program was never known for great standards conformance and has been discontinued by MS 11 years ago. > > No. There are many reasons why sleep() might return after t > > Not /that/ many, but true. But do you think that adding all of those > if-when-but reasons to the issue I tried to explain would be a good idea ? It does when it determines whether your program is correct or not. > I don't. Well, then don't. But then don't complain that your programs don't work as expected either. > > No, because you get the actual time at some time between the the > > previous and the next sleep > > No, you don't. Thats the whole trick. The only place where you ask for the > time (and subtract it from the desired one) is directly infront of actually > doing the sleep. You were talking about the end of the previous sleep, not the start of the next one in your previous message, but it doesn't matter. The call to perf_counter still happens at some time between the previous and the next sleep. Here is a disassembly of the line time.sleep(timeInterval - (time.perf_counter() % timeInterval)) : 10 8 LOAD_GLOBAL 1 (time) 10 LOAD_METHOD 2 (sleep) 12 LOAD_GLOBAL 3 (timeInterval) 14 LOAD_GLOBAL 1 (time) 16 LOAD_METHOD 4 (perf_counter) 18 CALL_METHOD 0 20 LOAD_GLOBAL 3 (timeInterval) 22 BINARY_MODULO 24 BINARY_SUBTRACT 26 CALL_METHOD 1 28 POP_TOP So there are three instructions between the return of perf_counter and the call to sleep: LOAD_GLOBAL, BINARY_MODULO and BINARY_SUBTRACT. They shouldn't take much time, but they do take time. > (dotting i's works two ways I'm afraid :-) ). And the > /asked for/ time (before subtraction of the current time I mean - ghah! I > hate needing to specify every fricking detail) will be exactly the specified > increment away from the (calculated!) last one. And yes, that thus also > tries to negate a previous sleep having ended late. > > In short: The calculated(!) next sleeps termination time is not dependant on > how well the previous sleeps and code between them behaved. Correct. That's the intention of this code. From your previous postings it wasn't apparent that you had understood this. In fact you seemed to be arguing that this either wasn't necessary or couldn't possibly be working. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From martin.schoon at gmail.com Fri Nov 22 15:23:10 2019 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 22 Nov 2019 20:23:10 GMT Subject: Jupyter Notebook -> PDF with A4 pages? References: Message-ID: Den 2019-11-01 skrev Andrea D'Amore : > On Thu, 31 Oct 2019 at 22:08, Martin Sch??n wrote: >> Den 2019-10-16 skrev Piet van Oostrum : >>> Why should that not work? >> pip install --user pip broke pip. I have not been able to repair pip > > I guess that's just the local pip shadowing the system one when you > let the command "pip" to be resolved by the shell. > , try calling the absolute path /usr/bin/pip . > Thanks, that seems to work -- "seems" because I have only had time try out list and search functions. Which explains the slow response on my part... /Martin From jacksonhaenchen at gmail.com Fri Nov 22 18:35:24 2019 From: jacksonhaenchen at gmail.com (jacksonhaenchen at gmail.com) Date: Fri, 22 Nov 2019 15:35:24 -0800 (PST) Subject: Global variable is undefined at the module level In-Reply-To: References: <87twdk2f4d.fsf@handshake.de> Message-ID: This is not accurate. I just tested this in python3 and using the global keyword allowed me to declare a variable inside the function that was then visible from the outer scope. On Tuesday, September 13, 2016 at 6:50:39 AM UTC-5, dieter wrote: > Daiyue Weng writes: > > > Hi, I defined a global variable in some function like this, > > > > def some_function(self): > > > > global global_var > > > > PyCharm inspection gave me, > > > > Global variable is undefined at the module level > > > > How to fix this? > > You define the global variable at the module level. > > "global VVV" (in a function) actually does not define "VVV" > as a global variable. Instead, it tells the interpreter that > "VVV" should not be treated as a local variable but be looked up > in the "global" (usually module) namespace. > > In order to define "VVV", you must assign a value to it -- either > directly in the "global" (i.e. module) namespace or in your function > (together with a "global VVV" declaration). From antoon.pardon at rece.vub.ac.be Sat Nov 23 07:03:26 2019 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Sat, 23 Nov 2019 13:03:26 +0100 Subject: Would like some design feedback. Message-ID: <1d7e3591-0582-d687-c724-09889451c666@rece.vub.ac.be> I am working on a module that works out this idea of a piline in python http://code.activestate.com/recipes/580625-collection-pipeline-in-python I have a number of design questions I would like some feedback on. 1) In the recipe the '|' is used as the pipe line operator. I like that for its similar use in unix-shells. However I have been thinking about using '>>' instead. What would your preference be and why. 2) I also want these classes to be composable. So that if I would do something like: Process = Map(double) @ Map(add1) range(10) | Process would act the same as range(10) | Map(double) | Map(add1) What operator would I use for this? Should I use the same operator as for question 1 or a different one? If a different one which one? -- Antoon. From pieter-l at vanoostrum.org Sat Nov 23 07:41:15 2019 From: pieter-l at vanoostrum.org (Pieter van Oostrum) Date: Sat, 23 Nov 2019 13:41:15 +0100 Subject: Global variable is undefined at the module level References: <87twdk2f4d.fsf@handshake.de> Message-ID: jacksonhaenchen at gmail.com writes: > This is not accurate. I just tested this in python3 and using the global > keyword allowed me to declare a variable inside the function that was > then visible from the outer scope. What do you mean by that? Anything other than what was said here? > On Tuesday, September 13, 2016 at 6:50:39 AM UTC-5, dieter wrote: >> In order to define "VVV", you must assign a value to it -- either >> directly in the "global" (i.e. module) namespace or in your function >> (together with a "global VVV" declaration). Without assignment the variable will not exist in the module namespace: >>> def testfunc(): ... global globvar ... pass ... >>> globvar Traceback (most recent call last): File "", line 1, in NameError: name 'globvar' is not defined >>> testfunc() >>> globvar Traceback (most recent call last): File "", line 1, in NameError: name 'globvar' is not defined >>> def testfunc(): ... global globvar ... globvar = 1 ... >>> globvar Traceback (most recent call last): File "", line 1, in NameError: name 'globvar' is not defined >>> testfunc() >>> globvar 1 -- Pieter van Oostrum www: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From Pycode at Pyc.ode Sat Nov 23 14:18:13 2019 From: Pycode at Pyc.ode (Pycode) Date: Sat, 23 Nov 2019 19:18:13 +0000 (UTC) Subject: Python Resources related with web security Message-ID: Hello, can anyone post links for python resources that contain tools and scripts related with security and pentesting? not looking for the obvious such as OWASP,etc can anyone post a list of interesting links? you can also include blogs and forums.. Thanks From hjp-python at hjp.at Sat Nov 23 16:18:13 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 23 Nov 2019 22:18:13 +0100 Subject: nonlocal fails ? In-Reply-To: References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> Message-ID: <20191123211813.GA5826@hjp.at> On 2019-11-14 20:29:01 -0500, Dennis Lee Bieber wrote: > Instead, at a simple level (a common description invokes "Post-It" > notes) > > x = y > > means /find/ the object (somewhere in memory) that has a note "y" stuck to > it. Without moving the "y" note, attach an "x" note to that same object. > The object now has two names bound to it. If the "x" note used to be > attached to an object, the old object no longer has that name -- and if the > object has NO names attached, it is garbage collected. Frankly, I find that model very unsatisfying. It's not just that it doesn't describe any existing or even plausibly possible implementation or that it implies a complexity that isn't there (search for an object with a note attached to it?). It starts to break down even for simple cases: There may be several variables called "x" in a program. How does the system distinguish between multiple objects with an "x" note? What about objects which have no name, like members of a tuple or the return value of a function? Sure, you can come up with arcane rules to on how to label a post-it to reference an object referenced by the x parameter of the lamba on line 7 of the third recursive invocation of function foo within the method bar of the Gazonk class in the fred packagerbut called from Bobble ... (ok, I'll stop now). But why would you? It's much simpler to talk about references or pointers or whatever you want to call them. You can nicely visualize them with arrows (or pieces of string, if you want, but arrows have the advantage of having a direction) and it describes directly and without any mental gymnastics what is going on (on a conceptual level - actual implementations might be somewhat different, as long as they behave the same). hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From PythonList at DancesWithMice.info Sat Nov 23 16:41:29 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 24 Nov 2019 10:41:29 +1300 Subject: Python Resources related with web security In-Reply-To: References: Message-ID: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> Curiosity: why have recent similar enquiries also come from non-resolving domain names? Recently we've seen security-related enquiries (on more than one Python Discussion List) which don't explicitly claim to come from 'white hat hackers' but which do have the potential to have less-than productive aims or interests. Are such email addresses 'open' and honest? Do they create extra and unnecessary scut-work for ListAdmins? Does such meet PSF 'standards' for honest and respectful interchange? WebRef: https://www.python.org/psf/conduct/ On 24/11/19 8:18 AM, Pycode wrote: > Hello, > > can anyone post links for python resources that contain tools and scripts > related with security and pentesting? > not looking for the obvious such as OWASP,etc > > can anyone post a list of interesting links? you can also include blogs > and forums.. > > Thanks > -- Regards =dn From Richard at Damon-Family.org Sat Nov 23 18:18:16 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 23 Nov 2019 18:18:16 -0500 Subject: nonlocal fails ? In-Reply-To: <20191123211813.GA5826@hjp.at> References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <20191123211813.GA5826@hjp.at> Message-ID: <07c191f9-3a5b-0ba9-b2a4-1f14cdcdd276@Damon-Family.org> On 11/23/19 4:18 PM, Peter J. Holzer wrote: > On 2019-11-14 20:29:01 -0500, Dennis Lee Bieber wrote: >> Instead, at a simple level (a common description invokes "Post-It" >> notes) >> >> x = y >> >> means /find/ the object (somewhere in memory) that has a note "y" stuck to >> it. Without moving the "y" note, attach an "x" note to that same object. >> The object now has two names bound to it. If the "x" note used to be >> attached to an object, the old object no longer has that name -- and if the >> object has NO names attached, it is garbage collected. > Frankly, I find that model very unsatisfying. > > It's not just that it doesn't describe any existing or even plausibly > possible implementation or that it implies a complexity that isn't there > (search for an object with a note attached to it?). It starts to break > down even for simple cases: There may be several variables called "x" in > a program. How does the system distinguish between multiple objects with > an "x" note? What about objects which have no name, like members of a > tuple or the return value of a function? Sure, you can come up with > arcane rules to on how to label a post-it to reference an object > referenced by the x parameter of the lamba on line 7 of the third > recursive invocation of function foo within the method bar of the Gazonk > class in the fred packagerbut called from Bobble ... (ok, I'll stop > now). But why would you? > > It's much simpler to talk about references or pointers or whatever you > want to call them. You can nicely visualize them with arrows (or pieces > of string, if you want, but arrows have the advantage of having a > direction) and it describes directly and without any mental gymnastics > what is going on (on a conceptual level - actual implementations might > be somewhat different, as long as they behave the same). > > hp A post-it note analogy is a very good description to allow a non-technical person to understand how it works. Yes, as presented, it doesn't handle the concept of scope of variables, but that starts to get into more complexity than you might want for a simple model, and it is simple to extend to handle it, either every scope gets a different color post-it note, or when you write the name of the variable, you include the scope. To a non-techie, a 'Pointer' is either a breed of dog or an arrow pointing in a general direction. The key is that you are showing something fundamentally different than a box to hold a value. If you show names as boxes with arrows in them, someone is going to ask how to get one name point to another name (re the discussion about is it call by value or call by reference) -- Richard Damon From rosuav at gmail.com Sat Nov 23 18:34:11 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Nov 2019 10:34:11 +1100 Subject: nonlocal fails ? In-Reply-To: <07c191f9-3a5b-0ba9-b2a4-1f14cdcdd276@Damon-Family.org> References: <48C80700-7449-4292-8930-22CA117EB729@mostrom.pp.se> <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <20191123211813.GA5826@hjp.at> <07c191f9-3a5b-0ba9-b2a4-1f14cdcdd276@Damon-Family.org> Message-ID: On Sun, Nov 24, 2019 at 10:19 AM Richard Damon wrote: > Yes, as presented, it doesn't handle the concept of scope of variables, > but that starts to get into more complexity than you might want for a > simple model, and it is simple to extend to handle it, either every > scope gets a different color post-it note, or when you write the name of > the variable, you include the scope. Or you can try to describe a scope as like a notebook where you say "x is Blue K12" where the thing is identified by a matching note (think raffle tickets). Not sure how useful it'd be, but the concept does at least scale. Recursion means setting down one notebook and picking up another (with most/all of the same names). ChrisA From hjp-python at hjp.at Sun Nov 24 07:03:16 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 24 Nov 2019 13:03:16 +0100 Subject: nonlocal fails ? In-Reply-To: <07c191f9-3a5b-0ba9-b2a4-1f14cdcdd276@Damon-Family.org> References: <19338008-c1b3-ce54-0b13-89e7b6174b3f@gmail.com> <20191123211813.GA5826@hjp.at> <07c191f9-3a5b-0ba9-b2a4-1f14cdcdd276@Damon-Family.org> Message-ID: <20191124120316.GA3705@hjp.at> On 2019-11-23 18:18:16 -0500, Richard Damon wrote: > On 11/23/19 4:18 PM, Peter J. Holzer wrote: > > On 2019-11-14 20:29:01 -0500, Dennis Lee Bieber wrote: > >> Instead, at a simple level (a common description invokes "Post-It" > >> notes) > >> > >> x = y > >> > >> means /find/ the object (somewhere in memory) that has a note "y" stuck to > >> it. Without moving the "y" note, attach an "x" note to that same object. > >> The object now has two names bound to it. If the "x" note used to be > >> attached to an object, the old object no longer has that name -- and if the > >> object has NO names attached, it is garbage collected. > > Frankly, I find that model very unsatisfying. [... reasons elided ...] > > It's much simpler to talk about references or pointers or whatever you > > want to call them. You can nicely visualize them with arrows (or pieces > > of string, if you want, but arrows have the advantage of having a > > direction) and it describes directly and without any mental gymnastics > > what is going on (on a conceptual level - actual implementations might > > be somewhat different, as long as they behave the same). > > > > A post-it note analogy is a very good description to allow a > non-technical person to understand how it works. It may allow a non-technical person to understand how it doesn't work. I doubt this is very useful. > Yes, as presented, it doesn't handle the concept of scope of variables, > but that starts to get into more complexity than you might want for a > simple model, Yeah, that's exactly the problem. In an attempt to avoid being "technical", it becomes needlessly complex. There seems to be a wide-spread notion that goes something like this: This is how it really works, therefore it is technical, and non-technical people don't understand technical stuff. Therefore we must make up another explanation. It will be more complicated and it will be wrong, but because it is wrong it is non-technical, therefore non-technical people will understand it. > To a non-techie, a 'Pointer' is either a breed of dog or an arrow > pointing in a general direction. Ok, I apparently wasn't thinking straight yesterday. The real world analogy is of course the address. Everybody knows what an address is (and non-technical people won't have all that cognitive baggage either which can lead programmers down endless rabbit holes). Adresses work slightly differently in different countries (and sometimes even different communities in the same country), but the differences won't matter here. Let's just assume the street/house number system as it is common in many western countries (if you are Japanese, think of blocks and buildings instead). So our objects live in houses on a street. When an object is created it just plops into existence in an empty house (And they never leave their house until they die, so the poor things are a pretty lonely bunch). You don't tack post-it notes to the house-doors. Instead you have a notebook[1] (or rather a bunch of them). So when you write something like 1 x = "spam" 2 y = "eggs" 3 z = x + y 4 ? = z 5 x = "ham" what happens is this: 1 You create a new object with the value "spam": Let's say this is now in Basil Street 42 You write into your notebook: "x: Basil Street 42" 2 You create a new object with the value "eggs" in Basil Street 3 You write into your notebook: "y: Basil Street 3" 3 You look into your notebook for the notes "x" and "y", find the adresses "Basil Street 42" and "Basil Street 3" there, go to those addresses to ask the objects for their values, create a new combined object from them ("spameggs"), put it into a free house (Basil Street 23) and write that into your notebook: "z: Basil Street 23". (Oof, that was quite a mouthful for such a short line) 4 You look up the address of "z" in your notebook and copy it into the entry for ?: "?: Basil Street 23". 5 You create yet another object ("ham") in Basil Street 52. You cross out your entry for "x" and write a new entry "x: Basil Street 52" (At this point there is no entry for Basil Street 42 in your notebook any more. Eventually the object at that house will notice that nobody loves it any more and die out of desparation) This is quite close to what really happens, it generalizes nicely (e.g, if you call a function, you just hand it a new notebook with just the parameters filled in; An object (e.g. a tuple or a dict) may itself possess a notebook; etc.) and it doesn't use any terms (except object) that the "non-technical person" won't be familiar with. > The key is that you are showing something fundamentally different than a > box to hold a value. If you show names as boxes with arrows in them, > someone is going to ask how to get one name point to another name (re > the discussion about is it call by value or call by reference) Which is a legitimate question. The answer is that Python's inventors thought that it would be useful to make two kinds of boxes and arrows can only originate on one kind and end at the other kind. You might get a very similar question for post-its: Why can't I put a post-it on another post-it? I can in real-life. (And of course the notebook metaphor doesn't avoid this either: Why can't I write "Notebook 3, entry foo" instead of a street address? Or draw a picture of a man-eating rabbit? Any metaphor breaks down at some point) hp [1] Thanks, Chris. The notebook is the perfect companion to the address metaphor. -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From darthdeus at gmail.com Sun Nov 24 06:15:11 2019 From: darthdeus at gmail.com (darthdeus at gmail.com) Date: Sun, 24 Nov 2019 12:15:11 +0100 Subject: Awaiting coroutines inside the debugger (PDB) Message-ID: <20191124111511.otx2hrkvljd657fi@koblih.localdomain> Hi everyone, this question is sort of in response to this issue https://github.com/gotcha/ipdb/issues/174. I've noticed that there was recently added support for an asyncio repl (run via `python -m asyncio`), which allows the use of `await` directly on coroutine objects in the REPL. But this does not seem to work when in PDB (and consequently in iPDB) when running `import pdb; pdb.set_trace()`. Is there any workaround to get `await` working in PDB, or any simple way to synchronously wait while in the debugger? From arjun0087 at gmail.com Sun Nov 24 10:11:35 2019 From: arjun0087 at gmail.com (Arjun Chandran) Date: Sun, 24 Nov 2019 20:41:35 +0530 Subject: Python for speech recognition Message-ID: I would like to create a python program for converting speech to text. I am not getting the best results by using google API , SpeechRecognition class. Anybody please provide the best way possible to do this. I have attached the program i used. From ugo.donini at gmail.com Sun Nov 24 12:26:35 2019 From: ugo.donini at gmail.com (Ugo Donini) Date: Sun, 24 Nov 2019 18:26:35 +0100 Subject: Python 3.8 with Anaconda Message-ID: <5ddabd4d.1c69fb81.e3675.b3b6@mx.google.com> It is lossible to update Anaconda to Pytho. 3.8? Sincerely Ugo Donini From PythonList at DancesWithMice.info Sun Nov 24 18:12:24 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 25 Nov 2019 12:12:24 +1300 Subject: Python 3.8 with Anaconda In-Reply-To: <5ddabd4d.1c69fb81.e3675.b3b6@mx.google.com> References: <5ddabd4d.1c69fb81.e3675.b3b6@mx.google.com> Message-ID: On 25/11/19 6:26 AM, Ugo Donini wrote: > It is lossible to update Anaconda to Pytho. 3.8? First 'hit' on DuckDuckGo.com: https://www.anaconda.com/keeping-anaconda-date/ If it is not yet available, they are the ones to ask if/when a 3.8 collection will be assembled... -- Regards =dn From wooethan14 at gmail.com Mon Nov 25 03:57:59 2019 From: wooethan14 at gmail.com (Ethan Woo) Date: Mon, 25 Nov 2019 16:57:59 +0800 Subject: python-docx Message-ID: Hi everyone, I am currently using Python 3.7.4, and have used pip to install python docx. I have looked up on many tutorials on how to use it, but they are all mostly the same. doc.add_heading("Test") when i type that line, i get this: KeyError: "no style with name 'Heading 1'" can help? From noah at neo.co.tz Mon Nov 25 08:31:39 2019 From: noah at neo.co.tz (Noah) Date: Mon, 25 Nov 2019 16:31:39 +0300 Subject: Library Generate a diff between two text files Message-ID: Hi Folks, >From experience, could someone point me to a library that can do a diff between two separate text files... *difflib* doesn't seem to cut it to this end.... *./noah* neo - network engineering and operations From mkolstein at ifae.es Mon Nov 25 08:36:32 2019 From: mkolstein at ifae.es (Machiel Kolstein) Date: Mon, 25 Nov 2019 05:36:32 -0800 (PST) Subject: Fit to function values with numpy/scipy Message-ID: <22e8cf36-734f-472f-800e-bde86e19e2da@googlegroups.com> If I have an array with values, which are distributed according to a Gaussian function, then I can fit with: (fit_mu, fit_sigma) = stats.norm.fit(x_array) However, now, I have one array with values for the xbins (e.g., 0.0, 0.1, 0.2, 0.3, ..., up till 1.0) and one value for the corresponding y-value (e.g. 0.0, 0.3, 0.6, 1.2, 5.0, 10.0, 5.0, 1.2, 0.6, 0.3, 0.0). (These values are just an example). Now I want to fit this, with a Gauss. So, obviously I don't want to fit over neither the values in xbins, nor the y_array (neither of which is normal distributed) but over the y values for each x bin. The only thing I can think of is looping over all bins, and then filling an artificial array: for i in range(0, Nbins): x = xbinvalue(i) weight = y_value_for_this_x(x) for w in range(0, weight) numpy.vstack((tmp_array, x) (fit_mu, fit_sigma) = scipy.stats.norm.fit(tmp_array) But this seems a rather silly way of doing this. Is there an other way? Cheers, Machiel -- Av?s - Aviso - Legal Notice - (LOPD) - http://legal.ifae.es From mkolstein at ifae.es Mon Nov 25 12:31:44 2019 From: mkolstein at ifae.es (Machiel Kolstein) Date: Mon, 25 Nov 2019 09:31:44 -0800 (PST) Subject: Fit to function values with numpy/scipy In-Reply-To: <22e8cf36-734f-472f-800e-bde86e19e2da@googlegroups.com> References: <22e8cf36-734f-472f-800e-bde86e19e2da@googlegroups.com> Message-ID: Okay, I found some answer myself: use scipy.optimize.curve_fit However, I still find it strange that I have to define a gauss function myself instead of it being readily available. I did this: # Define model function to be used to fit to the data def gauss(x, *p): A, mu, sigma = p return A*np.exp(-(x-mu)**2/(2.*sigma**2)) p0 = [1., 0., 1.] # Fit the histogram ----------------------------- coeff, var_matrix = curve_fit(gauss, x_array, y_array, p0=p0) amplitude, mu, sigma = coeff print "amplitude, mu, sigma = ", amplitude, mu, sigma # Get the fitted curve hist_fit = gauss(x_array, *coeff) plt.plot(x_array, hist_fit, color='red', linewidth=5, label='Fitted data') plt.show() -- Av?s - Aviso - Legal Notice - (LOPD) - http://legal.ifae.es From Pycode at Pyc.ode Mon Nov 25 16:25:12 2019 From: Pycode at Pyc.ode (Pycode) Date: Mon, 25 Nov 2019 21:25:12 +0000 (UTC) Subject: Python Resources related with web security References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> Message-ID: On Sun, 24 Nov 2019 10:41:29 +1300, DL Neil wrote: > Curiosity: why have recent similar enquiries also come from > non-resolving domain names? > > > Recently we've seen security-related enquiries (on more than one Python > Discussion List) which don't explicitly claim to come from 'white hat > hackers' but which do have the potential to have less-than productive > aims or interests. > > Are such email addresses 'open' and honest? > Do they create extra and unnecessary scut-work for ListAdmins? > Does such meet PSF 'standards' for honest and respectful interchange? > > WebRef: > https://www.python.org/psf/conduct/ > > > > On 24/11/19 8:18 AM, Pycode wrote: >> Hello, >> >> can anyone post links for python resources that contain tools and >> scripts related with security and pentesting? >> not looking for the obvious such as OWASP,etc >> >> can anyone post a list of interesting links? you can also include blogs >> and forums.. >> >> Thanks >> you are not being helpful or answer the question.. can someone answer? maybe should i ask on the mailing list? Thank you! From musbur at posteo.org Mon Nov 25 15:13:46 2019 From: musbur at posteo.org (Musbur) Date: Mon, 25 Nov 2019 21:13:46 +0100 Subject: Why isn't =?UTF-8?Q?=22-std=3Dc=39=39=22=20=28and=20others=29=20n?= =?UTF-8?Q?ot=20part=20of=20python=33-config=27s=20output=3F?= Message-ID: <06becbd43ba88f1923f56f9c118bfb4e@posteo.de> I've successfully built and installed a copy of Python3.6.8 (replacing a probably buggy installation on my RHEL system, different story). Also I set up a virtualenv by doing "$ /usr/local/bin/python3.6dm -m venv /usr/local/pyenv36" In my activated virtualenv, I try "$ pip install numpy" but it fails with lots of errors about something that is valid only in C99. Obviously numpy relies on -std=c99 (pyenv36)$ /usr/local/bin/python3.6dm-config --cflags -I/usr/local/include/python3.6dm -I/usr/local/include/python3.6dm -Wno-unused-result -Wsign-compare -g -Og -Wall (pyenv36)$ This surprises me, because "my" /usr/local/bin/python3.6m itself was built -std=c99, as seen in these sysconfig entries: 'CONFIGURE_CFLAGS_NODIST': '-std=c99 -Wextra -Wno-unused-result ' 'PY_CFLAGS_NODIST': '-std=c99 -Wextra -Wno-unused-result ' 'PY_CORE_CFLAGS': '-Wno-unused-result -Wsign-compare -g -Og -Wall -std=c99 ' I can install numpy on the system Python3, and not surprisingly, there is -std=c99 among tons of other CFLAGS: $ /usr/bin/python3.6m-config --cflags -I/usr/include/python3.6m -I/usr/include/python3.6m -Wno-unused-result -Wsign-compare -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv $ My questions are: 1) Why does the output of /usr/local/bin/python3.6m-config --cflags differ from the CFLAGS in sysconfig.get_config_vars() ? I've confirmed that the /usr/local/bin/python3.6m binary and /usr/local/bin/python3.6m-config are really from the same build. 2) How does one activate the necessary CFLAGs for extension building? 3) Where do all the extra flags in the system /usr/bin/python3.6m-config --cflags come from? 4) Why isn't the config script installed into the /bin of a virtualenv? This is super annoying when building extensions on a multi-version system because it may lead to version mix-ups A bit of background on this: I've written a C extension that leaks memory like a sieve on my production RHEL7's system python3 but neither on my Debian development system nor on my "self-built" Python on the production server. So I'd like to install the self-built Python on the production server, but for that I need a bunch of other packages to work as well, including numpy. Thanks! From python.list at tim.thechases.com Mon Nov 25 17:48:59 2019 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 25 Nov 2019 16:48:59 -0600 Subject: Python Resources related with web security In-Reply-To: References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> Message-ID: <20191125164859.0356b190@bigbox.attlocal.net> On 2019-11-25 21:25, Pycode wrote: > On Sun, 24 Nov 2019 10:41:29 +1300, DL Neil wrote: >> Are such email addresses 'open' and honest? > > you are not being helpful or answer the question.. What DL Neil seems to be getting at is that there's been an uptick in questions 1) where we don't know who you (and several other recent posters) are: - The pyc.ode domain-name of your email address isn't a real/registered domain - there doesn't seem to be much evidence of you being part of the Python community with a history of other messages Neither factor inspires much confidence. 2) you (and others) are asking to be spoonfed example code that could cause problems on the internet. >>> can anyone post links for python resources that contain tools and >>> scripts related with security and pentesting? They're the sorts of tools that, if the community deems you a non-threatening-actor, they might point you in the right direction. But not knowing who you are (see point #1 above), I imagine folks here are hesitant. And almost certainly not going to spoon-feed example code that could then end up attacking sites on the web. So I suspect DL Neil was raising awareness to make sure that anybody who *did* answer your questions might take the time to think about the potential consequences of the actions. So DL *is* being helpful, but rather to the community, even if not necessarily to you in particular. > can someone answer? maybe should i ask on the mailing list? You did. The usenet & mailing lists are mirrored. Though perhaps if you post from a legit mail identity/address (whether to the mailing list or usenet), it might help folks evaluate whether you're a "white hat" or a "black hat" (or somewhere in between). As to your questions, all the basics are available: materials on security & pentesting are a web-search away, and Python provides libraries for both socket-level interfaces & application-specific protocols. How you choose to combine them is up to you. How the community chooses to assist you in combining them largely depends on how much they trust you. -tkc From PythonList at DancesWithMice.info Mon Nov 25 18:33:47 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 26 Nov 2019 12:33:47 +1300 Subject: Python Resources related with web security In-Reply-To: <20191125164859.0356b190@bigbox.attlocal.net> References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> <20191125164859.0356b190@bigbox.attlocal.net> Message-ID: <73ea5220-8aee-fd3d-7ea9-328456f2bb57@DancesWithMice.info> On 26/11/19 11:48 AM, Tim Chase wrote: > On 2019-11-25 21:25, Pycode wrote: >> On Sun, 24 Nov 2019 10:41:29 +1300, DL Neil wrote: >>> Are such email addresses 'open' and honest? >> >> you are not being helpful or answer the question.. > > What DL Neil seems to be getting at is that there's been an uptick in > questions > > 1) where we don't know who you (and several other recent posters) are: > > - The pyc.ode domain-name of your email address isn't a > real/registered domain > > - there doesn't seem to be much evidence of you being part of the > Python community with a history of other messages +other consideration regarding the best use of mail-lists and respecting people's time. For reference: an attempt to contact the OP directly, in a bid to refine his questions/assist the production of answers (perhaps), failed - due to the problem mentioned, ie one of his/her own making! > Neither factor inspires much confidence. > > 2) you (and others) are asking to be spoonfed example code that could > cause problems on the internet. ... > So I suspect DL Neil was raising awareness to make sure that anybody > who *did* answer your questions might take the time to think about > the potential consequences of the actions. So DL *is* being helpful, > but rather to the community, even if not necessarily to you in > particular.... Thanks @tkc. Yes! Given that the OP may have legitimate (and legal) reasons for the question, I was reluctant to express direct criticism (which, ironically-enough) is contrary to 'open' etc behavior. Previous to this, had discussed such concerns with a ListAdmin, who is taking it further. I hope we'll (soon) see something further from the Python-/List-gods... As a student of irony, I was amused at being told that I wasn't answering questions - by someone who didn't even acknowledge, and certainly didn't attempt to address, concerns raised. Colors += mast? -- Regards =dn From Richard at Damon-Family.org Mon Nov 25 19:53:14 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Mon, 25 Nov 2019 19:53:14 -0500 Subject: Fit to function values with numpy/scipy In-Reply-To: References: <22e8cf36-734f-472f-800e-bde86e19e2da@googlegroups.com> Message-ID: <9cdf426f-f391-ef22-cc8a-ac8c9aa0e2db@Damon-Family.org> On 11/25/19 12:31 PM, Machiel Kolstein wrote: > Okay, I found some answer myself: use scipy.optimize.curve_fit > However, I still find it strange that I have to define a gauss function myself instead of it being readily available. I did this: > > # Define model function to be used to fit to the data > def gauss(x, *p): > A, mu, sigma = p > return A*np.exp(-(x-mu)**2/(2.*sigma**2)) > p0 = [1., 0., 1.] > > # Fit the histogram ----------------------------- > coeff, var_matrix = curve_fit(gauss, x_array, y_array, p0=p0) > amplitude, mu, sigma = coeff > print "amplitude, mu, sigma = ", amplitude, mu, sigma > > # Get the fitted curve > hist_fit = gauss(x_array, *coeff) > plt.plot(x_array, hist_fit, color='red', linewidth=5, label='Fitted data') > > plt.show() > That actually solves a slightly different problem. norm.fit basically computes the mean and standard deviation of the data (and if you know what the mean should be, you can provide that to get a better estimate of the standard deviation). If you problem really is a weighted data problem, then it isn't hard to compute a weighted average or weighted standard deviation, I don't know scipy to know if it has something like that built in. A quick scan shows that numpy.average allows a weighting array to be provided, so it shouldn't be hard to look at the code for sci[y.norm.fit and convert it to use weighted averages. -- Richard Damon From Pycode at Pyc.ode Mon Nov 25 21:51:36 2019 From: Pycode at Pyc.ode (Pycode) Date: Tue, 26 Nov 2019 02:51:36 +0000 (UTC) Subject: Python Resources related with web security References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> <20191125164859.0356b190@bigbox.attlocal.net> Message-ID: On Mon, 25 Nov 2019 16:48:59 -0600, Tim Chase wrote: > On 2019-11-25 21:25, Pycode wrote: >> On Sun, 24 Nov 2019 10:41:29 +1300, DL Neil wrote: >>> Are such email addresses 'open' and honest? >> >> you are not being helpful or answer the question.. > > What DL Neil seems to be getting at is that there's been an uptick in > questions > > 1) where we don't know who you (and several other recent posters) are: > > - The pyc.ode domain-name of your email address isn't a > real/registered domain > > - there doesn't seem to be much evidence of you being part of the > Python community with a history of other messages > > Neither factor inspires much confidence. > > 2) you (and others) are asking to be spoonfed example code that could > cause problems on the internet. > >>>> can anyone post links for python resources that contain tools and >>>> scripts related with security and pentesting? > > They're the sorts of tools that, if the community deems you a > non-threatening-actor, they might point you in the right direction. But > not knowing who you are (see point #1 above), I imagine folks here are > hesitant. And almost certainly not going to spoon-feed example code > that could then end up attacking sites on the web. > > So I suspect DL Neil was raising awareness to make sure that anybody who > *did* answer your questions might take the time to think about the > potential consequences of the actions. So DL *is* being helpful, but > rather to the community, even if not necessarily to you in particular. > >> can someone answer? maybe should i ask on the mailing list? > > You did. The usenet & mailing lists are mirrored. Though perhaps if > you post from a legit mail identity/address (whether to the mailing list > or usenet), it might help folks evaluate whether you're a "white hat" or > a "black hat" (or somewhere in between). > > > As to your questions, all the basics are available: materials on > security & pentesting are a web-search away, and Python provides > libraries for both socket-level interfaces & application-specific > protocols. How you choose to combine them is up to you. How the > community chooses to assist you in combining them largely depends on how > much they trust you. > > -tkc which keywords should i use for web-search? do you have a list? what is the best "manual" for the specific security topic? Thank you From Pycode at Pyc.ode Mon Nov 25 21:51:51 2019 From: Pycode at Pyc.ode (Pycode) Date: Tue, 26 Nov 2019 02:51:51 +0000 (UTC) Subject: Python Resources related with web security References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> Message-ID: On Mon, 25 Nov 2019 17:32:50 -0500, Dennis Lee Bieber wrote: > On Mon, 25 Nov 2019 21:25:12 +0000 (UTC), Pycode > declaimed the following: > > >>you are not being helpful or answer the question.. >>can someone answer? maybe should i ask on the mailing list? > > Why? > > comp.lang.python gmane.comp.python.general > > and "the mailing list" > > are all cross-gatewayed to each other (we don't speak of what Google > Groups is doing). can you recommend some forums and blogs? Thanks From rosuav at gmail.com Mon Nov 25 22:01:54 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Nov 2019 14:01:54 +1100 Subject: Python Resources related with web security In-Reply-To: References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> <20191125164859.0356b190@bigbox.attlocal.net> Message-ID: On Tue, Nov 26, 2019 at 1:56 PM Pycode wrote: > > which keywords should i use for web-search? do you have a list? > what is the best "manual" for the specific security topic? https://lmgtfy.com/?q=How+to+search+the+web ChrisA From Pycode at Pyc.ode Tue Nov 26 12:23:19 2019 From: Pycode at Pyc.ode (Pycode) Date: Tue, 26 Nov 2019 17:23:19 +0000 (UTC) Subject: Python Resources related with web security References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> <20191125164859.0356b190@bigbox.attlocal.net> Message-ID: On Tue, 26 Nov 2019 14:01:54 +1100, Chris Angelico wrote: > On Tue, Nov 26, 2019 at 1:56 PM Pycode wrote: >> >> which keywords should i use for web-search? do you have a list? >> what is the best "manual" for the specific security topic? > > https://lmgtfy.com/?q=How+to+search+the+web > > ChrisA asking offtopic question, can you give a few guides that teach how to search the web? Thanks From Pycode at Pyc.ode Tue Nov 26 12:24:04 2019 From: Pycode at Pyc.ode (Pycode) Date: Tue, 26 Nov 2019 17:24:04 +0000 (UTC) Subject: Python Resources related with web security References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> <20191125164859.0356b190@bigbox.attlocal.net> <99gqte94lqpmi8vrq6cjvt6aesf11vr0pq@4ax.com> Message-ID: On Tue, 26 Nov 2019 10:20:11 -0500, Dennis Lee Bieber wrote: > On Tue, 26 Nov 2019 02:51:36 +0000 (UTC), Pycode > declaimed the following: > >>which keywords should i use for web-search? do you have a list? >>what is the best "manual" for the specific security topic? > > Given the nature of what you are asking -- have you considered that > much of it might be considered proprietary information by any firm(s) > that already do such stuff. > > Maybe see about attending https://www.blackhat.com/ > > As for general searching > https://www.google.com/search?q=network+security+testing+tools can you give a few more general searching keywords? Thanks From rosuav at gmail.com Tue Nov 26 12:35:10 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Nov 2019 04:35:10 +1100 Subject: Python Resources related with web security In-Reply-To: References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> <20191125164859.0356b190@bigbox.attlocal.net> Message-ID: On Wed, Nov 27, 2019 at 4:26 AM Pycode wrote: > asking offtopic question, > can you give a few guides that teach how to search the web? > At this point, I'm starting to be quite confused as to whether this is a genuine question or a parody. I'd love to respond to it as a parody, meeting you joke for joke, and entertaining ourselves and everyone who reads it... but I'm worried that you might actually be for real here. Allow me to offer one serious suggestion. Go learn. Stop asking for help and go do some research. Try typing things into Google or DuckDuckGo or AskJeeves and look at the results you get back. You don't need immense skill to be able to get some sort of result. (Skill does help you get there more efficiently, though.) ChrisA From Pycode at Pyc.ode Tue Nov 26 13:57:07 2019 From: Pycode at Pyc.ode (Pycode) Date: Tue, 26 Nov 2019 18:57:07 +0000 (UTC) Subject: Python Resources related with web security References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> <20191125164859.0356b190@bigbox.attlocal.net> Message-ID: On Wed, 27 Nov 2019 04:35:10 +1100, Chris Angelico wrote: > On Wed, Nov 27, 2019 at 4:26 AM Pycode wrote: >> asking offtopic question, >> can you give a few guides that teach how to search the web? >> >> > At this point, I'm starting to be quite confused as to whether this is a > genuine question or a parody. I'd love to respond to it as a parody, > meeting you joke for joke, and entertaining ourselves and everyone who > reads it... but I'm worried that you might actually be for real here. > > Allow me to offer one serious suggestion. Go learn. Stop asking for help > and go do some research. Try typing things into Google or DuckDuckGo or > AskJeeves and look at the results you get back. You don't need immense > skill to be able to get some sort of result. (Skill does help you get > there more efficiently, though.) > > ChrisA what skills do i need? any manual or reference guide that teach how to search the web? Which Python scripts can be used to search the web? Thanks From python at mrabarnett.plus.com Tue Nov 26 14:15:04 2019 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 26 Nov 2019 19:15:04 +0000 Subject: =?UTF-8?Q?=5bOT=5d_A_conversation_with_the_creator_of_the_world?= =?UTF-8?Q?=e2=80=99s_most_popular_programming_language_on_removing_brain_fr?= =?UTF-8?Q?iction_for_better_work=2e?= Message-ID: Off-topic, but might be of interest: A conversation with the creator of the world?s most popular programming language on removing brain friction for better work. https://blog.dropbox.com/topics/work-culture/-the-mind-at-work--guido-van-rossum-on-how-python-makes-thinking From mrgentooer at cock.li Tue Nov 26 13:17:12 2019 From: mrgentooer at cock.li (Mr. Gentooer) Date: Tue, 26 Nov 2019 19:17:12 +0100 Subject: Python Resources related with web security In-Reply-To: References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> Message-ID: <20191126181712.esimxzycqsdmfv4v@koblih.localdomain> > > On Mon, 25 Nov 2019 21:25:12 +0000 (UTC), Pycode > > declaimed the following: > > > > comp.lang.python gmane.comp.python.general how do you access these in a reasonable way? From joel.goldstick at gmail.com Tue Nov 26 15:29:48 2019 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 26 Nov 2019 15:29:48 -0500 Subject: Python Resources related with web security In-Reply-To: <20191126181712.esimxzycqsdmfv4v@koblih.localdomain> References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> <20191126181712.esimxzycqsdmfv4v@koblih.localdomain> Message-ID: On Tue, Nov 26, 2019 at 2:23 PM Mr. Gentooer wrote: > > > > On Mon, 25 Nov 2019 21:25:12 +0000 (UTC), Pycode > > > declaimed the following: > > > > > > comp.lang.python gmane.comp.python.general > > how do you access these in a reasonable way? > > -- > https://mail.python.org/mailman/listinfo/python-list I'm thinking this is a troll or a turing machine experiment? -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From grant.b.edwards at gmail.com Tue Nov 26 15:41:31 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 26 Nov 2019 20:41:31 -0000 (UTC) Subject: Python Resources related with web security References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> <20191126181712.esimxzycqsdmfv4v@koblih.localdomain> Message-ID: On 2019-11-26, Joel Goldstick wrote: > I'm thinking this is a troll or a turing machine experiment? Yea, many of the posts remind me of ELIZA. -- Grant Edwards grant.b.edwards Yow! Hmmm ... A hash-singer at and a cross-eyed guy were gmail.com SLEEPING on a deserted island, when ... From rgaddi at highlandtechnology.invalid Tue Nov 26 16:35:59 2019 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Tue, 26 Nov 2019 13:35:59 -0800 Subject: Python Resources related with web security In-Reply-To: References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> <20191126181712.esimxzycqsdmfv4v@koblih.localdomain> Message-ID: On 11/26/19 12:41 PM, Grant Edwards wrote: > On 2019-11-26, Joel Goldstick wrote: > >> I'm thinking this is a troll or a turing machine experiment? > > Yea, many of the posts remind me of ELIZA. > How do you feel about many of the posts remind you of ELIZA? -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From none at invalid.com Tue Nov 26 17:50:48 2019 From: none at invalid.com (mm0fmf) Date: Tue, 26 Nov 2019 22:50:48 +0000 Subject: Python Resources related with web security In-Reply-To: References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> <20191126181712.esimxzycqsdmfv4v@koblih.localdomain> Message-ID: On 26/11/2019 21:35, Rob Gaddi wrote: > On 11/26/19 12:41 PM, Grant Edwards wrote: >> On 2019-11-26, Joel Goldstick wrote: >> >>> I'm thinking this is a troll or a turing machine experiment? >> >> Yea, many of the posts remind me of ELIZA. >> > > How do you feel about many of the posts remind you of ELIZA? > +1 LOL! From mrgentooer at cock.li Tue Nov 26 16:54:19 2019 From: mrgentooer at cock.li (Mr. Gentooer) Date: Tue, 26 Nov 2019 22:54:19 +0100 Subject: Python Resources related with web security In-Reply-To: References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> <20191126181712.esimxzycqsdmfv4v@koblih.localdomain> Message-ID: <20191126215419.bmvwvg6bcuzf3bom@koblih.localdomain> On Tue, Nov 26, 2019 at 03:29:48PM -0500, Joel Goldstick wrote: > On Tue, Nov 26, 2019 at 2:23 PM Mr. Gentooer wrote: > > > > > > On Mon, 25 Nov 2019 21:25:12 +0000 (UTC), Pycode > > > > declaimed the following: > > > > > > > > comp.lang.python gmane.comp.python.general > > > > how do you access these in a reasonable way? > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > I'm thinking this is a troll or a turing machine experiment? why would I be a troll? I have never used usenet. I am honestly and genuinely curious. From python.list at tim.thechases.com Tue Nov 26 20:24:32 2019 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 26 Nov 2019 19:24:32 -0600 Subject: increasing the page size of a dbm store? Message-ID: <20191126192432.535ee241@bigbox.attlocal.net> Working with the dbm module (using it as a cache), I've gotten the following error at least twice now: HASH: Out of overflow pages. Increase page size Traceback (most recent call last): [snip] File ".py", line 83, in get_data db[key] = data _dbm.error: cannot add item to database I've read over the py3 docs on dbm https://docs.python.org/3/library/dbm.html but don't see anything about either "page" or "size" contained therein. There's nothing particularly complex as far as I can tell. Nothing more than a straightforward import dbm with dbm.open("cache", "c") as db: for thing in source: key = extract_key_as_bytes(thing) if key in db: data = db[key] else: data = long_process(thing) db[key] = data The keys can get a bit large (think roughly book-title length), but not huge. I have 11k records so it seems like it shouldn't be overwhelming, but this is the second batch where I've had to nuke the cache and start afresh. Fortunately I've tooled the code so it can work incrementally and no more than a hundred or so requests have to be re-performed. How does one increas the page-size in a dbm mapping? Or are there limits that I should be aware of? Thanks, -tkc PS: FWIW, this is Python 3.6 on FreeBSD in case that exposes any germane implementation details. From torriem at gmail.com Tue Nov 26 21:07:15 2019 From: torriem at gmail.com (Michael Torrie) Date: Tue, 26 Nov 2019 19:07:15 -0700 Subject: Python Resources related with web security In-Reply-To: References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> <20191125164859.0356b190@bigbox.attlocal.net> Message-ID: <66d009b8-554c-e607-441f-24442b0d284e@gmail.com> On 11/26/19 11:57 AM, Pycode wrote: > On Wed, 27 Nov 2019 04:35:10 +1100, Chris Angelico wrote: >> On Wed, Nov 27, 2019 at 4:26 AM Pycode wrote: >>> asking offtopic question, >>> can you give a few guides that teach how to search the web? >>> >> At this point, I'm starting to be quite confused as to whether this is a >> genuine question or a parody. I'd love to respond to it as a parody, >> meeting you joke for joke, and entertaining ourselves and everyone who >> reads it... but I'm worried that you might actually be for real here. >> >> Allow me to offer one serious suggestion. Go learn. Stop asking for help >> and go do some research. Try typing things into Google or DuckDuckGo or >> AskJeeves and look at the results you get back. You don't need immense >> skill to be able to get some sort of result. (Skill does help you get >> there more efficiently, though.) >> >> ChrisA > > what skills do i need? any manual or reference guide that teach how to > search the web? If you have to ask that question then you are definitely not ready for working in web security, letalone Python itself. I can only assume you're trolling. > Which Python scripts can be used to search the web? Wait, what? From torriem at gmail.com Tue Nov 26 21:07:58 2019 From: torriem at gmail.com (Michael Torrie) Date: Tue, 26 Nov 2019 19:07:58 -0700 Subject: Python Resources related with web security In-Reply-To: References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> <20191125164859.0356b190@bigbox.attlocal.net> <99gqte94lqpmi8vrq6cjvt6aesf11vr0pq@4ax.com> Message-ID: On 11/26/19 10:24 AM, Pycode wrote: > On Tue, 26 Nov 2019 10:20:11 -0500, Dennis Lee Bieber wrote: > >> On Tue, 26 Nov 2019 02:51:36 +0000 (UTC), Pycode >> declaimed the following: >> >>> which keywords should i use for web-search? do you have a list? >>> what is the best "manual" for the specific security topic? >> >> Given the nature of what you are asking -- have you considered > that >> much of it might be considered proprietary information by any firm(s) >> that already do such stuff. >> >> Maybe see about attending https://www.blackhat.com/ >> >> As for general searching >> https://www.google.com/search?q=network+security+testing+tools > > can you give a few more general searching keywords? No. I'm sure as you begin learning you'll come up with words on your own. From harirammanohar159 at gmail.com Wed Nov 27 00:17:57 2019 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Tue, 26 Nov 2019 21:17:57 -0800 (PST) Subject: Unable to retrieve data from Juypter notebook In-Reply-To: <1616c909-5788-4b71-bf5a-0adfefadca25@googlegroups.com> References: <1616c909-5788-4b71-bf5a-0adfefadca25@googlegroups.com> Message-ID: Any help is appreciated.. Thanks in Advance.. From __peter__ at web.de Wed Nov 27 06:50:54 2019 From: __peter__ at web.de (Peter Otten) Date: Wed, 27 Nov 2019 12:50:54 +0100 Subject: increasing the page size of a dbm store? References: <20191126192432.535ee241@bigbox.attlocal.net> Message-ID: Tim Chase wrote: > Working with the dbm module (using it as a cache), I've gotten the > following error at least twice now: > > HASH: Out of overflow pages. Increase page size > Traceback (most recent call last): > [snip] > File ".py", line 83, in get_data > db[key] = data > _dbm.error: cannot add item to database > > I've read over the py3 docs on dbm > > https://docs.python.org/3/library/dbm.html > > but don't see anything about either "page" or "size" contained > therein. > > There's nothing particularly complex as far as I can tell. Nothing > more than a straightforward > > import dbm > with dbm.open("cache", "c") as db: > for thing in source: > key = extract_key_as_bytes(thing) > if key in db: > data = db[key] > else: > data = long_process(thing) > db[key] = data > > The keys can get a bit large (think roughly book-title length), but > not huge. I have 11k records so it seems like it shouldn't be > overwhelming, but this is the second batch where I've had to nuke the > cache and start afresh. Fortunately I've tooled the code so it can > work incrementally and no more than a hundred or so requests have to > be re-performed. > > How does one increas the page-size in a dbm mapping? Or are there > limits that I should be aware of? > > Thanks, > > -tkc > > PS: FWIW, this is Python 3.6 on FreeBSD in case that exposes any > germane implementation details. I found the message here https://github.com/lattera/freebsd/blob/master/lib/libc/db/hash/hash_page.c#L695 but it's not immedately obvious how to increase the page size, and the readme https://github.com/lattera/freebsd/tree/master/lib/libc/db/hash only states """ "bugs" or idiosyncracies If you have a lot of overflows, it is possible to run out of overflow pages. Currently, this will cause a message to be printed on stderr. Eventually, this will be indicated by a return error code. """ what you learned the hard way. Python has its own "dumb and slow but simple dbm clone" dbm.dump -- maybe it's smart and fast enough for your purpose? From p4j at j4d.net Wed Nov 27 08:54:45 2019 From: p4j at j4d.net (Pankaj Jangid) Date: Wed, 27 Nov 2019 19:24:45 +0530 Subject: Unable to retrieve data from Juypter notebook References: <1616c909-5788-4b71-bf5a-0adfefadca25@googlegroups.com> Message-ID: > Any help is appreciated.. Could you please elaborate a little bit? I didn't get from where you want to retrieve data? Is this somewhere hosted? Or you want to see raw files from your own Jupyter notebook running on your own machine. Regards, -- Pankaj Jangid From barry at barrys-emacs.org Wed Nov 27 16:13:28 2019 From: barry at barrys-emacs.org (Barry) Date: Wed, 27 Nov 2019 21:13:28 +0000 Subject: increasing the page size of a dbm store? In-Reply-To: <20191126192432.535ee241@bigbox.attlocal.net> References: <20191126192432.535ee241@bigbox.attlocal.net> Message-ID: <0EAFC9E0-02D2-4745-99B7-654B7A445EDD@barrys-emacs.org> Maybe port to SQLite? I would not choose dbm these days. Barry > On 27 Nov 2019, at 01:48, Tim Chase wrote: > > ?Working with the dbm module (using it as a cache), I've gotten the > following error at least twice now: > > HASH: Out of overflow pages. Increase page size > Traceback (most recent call last): > [snip] > File ".py", line 83, in get_data > db[key] = data > _dbm.error: cannot add item to database > > I've read over the py3 docs on dbm > > https://docs.python.org/3/library/dbm.html > > but don't see anything about either "page" or "size" contained > therein. > > There's nothing particularly complex as far as I can tell. Nothing > more than a straightforward > > import dbm > with dbm.open("cache", "c") as db: > for thing in source: > key = extract_key_as_bytes(thing) > if key in db: > data = db[key] > else: > data = long_process(thing) > db[key] = data > > The keys can get a bit large (think roughly book-title length), but > not huge. I have 11k records so it seems like it shouldn't be > overwhelming, but this is the second batch where I've had to nuke the > cache and start afresh. Fortunately I've tooled the code so it can > work incrementally and no more than a hundred or so requests have to > be re-performed. > > How does one increas the page-size in a dbm mapping? Or are there > limits that I should be aware of? > > Thanks, > > -tkc > > PS: FWIW, this is Python 3.6 on FreeBSD in case that exposes any > germane implementation details. > > > > > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From greg.ewing at canterbury.ac.nz Wed Nov 27 16:56:58 2019 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 28 Nov 2019 10:56:58 +1300 Subject: Python Resources related with web security In-Reply-To: References: <28f6ae8a-be03-067f-2a7f-3436aa3c0b58@DancesWithMice.info> <20191126181712.esimxzycqsdmfv4v@koblih.localdomain> <20191126215419.bmvwvg6bcuzf3bom@koblih.localdomain> Message-ID: On 27/11/19 10:54 am, Mr. Gentooer wrote: > why would I be a troll? I have never used usenet. I am honestly and > genuinely curious. The reason people are asking is that wanting a manual on how to search the Web is a bit like wanting a manual on how to walk. Most people pick it up by watching others and doing it themselves, so nobody writes anything down about it. -- Greg From hjp-python at hjp.at Wed Nov 27 19:47:50 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Thu, 28 Nov 2019 01:47:50 +0100 Subject: Python Resources related with web security In-Reply-To: References: <20191126181712.esimxzycqsdmfv4v@koblih.localdomain> <20191126215419.bmvwvg6bcuzf3bom@koblih.localdomain> Message-ID: <20191128004750.GA20033@hjp.at> On 2019-11-28 10:56:58 +1300, Greg Ewing wrote: > On 27/11/19 10:54 am, Mr. Gentooer wrote: > > why would I be a troll? I have never used usenet. I am honestly and > > genuinely curious. > > The reason people are asking is that wanting a manual on how to > search the Web is a bit like wanting a manual on how to walk. He asked about Usenet, not the web. Specifically, about the usenet groups comp.lang.python and gmane.comp.python.general. (I suspect he was called a troll because he was mixed up with "Pycode" ("Mr. Gentooer" and "Pycode" may or may not be the same person, the Elize-lika posting style is certainly similar, but in the absence of evidence I will assume that they are not).) Usenet used to be very popular in the late 1990s and early 2000s. Even then you did get instructions on how to install and configure a Usenet client and get access to a Usenet server, it wasn't assumed that you would pick that up by osmosis. These days such information is probably harder to come by (especially since Usenet seems to have splintered into a text-only discussion Usenet and a file-sharing Usenet, so simply asking your favourite search engine might get you lots of information about the wrong Usenet). For general Usenet access I would recommend using a client like Thunderbird or Pan (unless you like text-only interfaces like slrn (which I use)) and getting an account with a reputable free provider like albasani.net. Don't use google groups, don't use aeiou. That said, I wouldn't recommend comp.lang.python in particular. Not only is it infested with spammers (those can be dealt with a few killfile rules), but the gateway to the mailing-list is broken: It rewrites message-ids which makes it very hard to follow threads. And of course most of the messages come from the mailinglist, so you get all the diversity that implies. In short, you get the disadvantages of a newsgroup, but not the advantages. (At least that was the situation when I gave up on comp.lang.python and subscribed the mailinglist instead.) Gmane isn't part of usenet proper. It's more like a mailinglist to nntp gateway. I'm not sure how functional it currently is. It has been down and up again over the last few years. The website is currently down, which doesn't bode well. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From harirammanohar159 at gmail.com Thu Nov 28 01:17:29 2019 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Wed, 27 Nov 2019 22:17:29 -0800 (PST) Subject: Unable to retrieve data from Juypter notebook In-Reply-To: References: <1616c909-5788-4b71-bf5a-0adfefadca25@googlegroups.com> Message-ID: <2559364e-d239-4363-93c1-bf1906385470@googlegroups.com> I launch Jupyter notebook directly from the windows machine where its installed, after launching background python.exe will be running and automatically browser will redirect to http://localhost:8888/tree ==log== [I 11:36:26.234 NotebookApp] JupyterLab extension loaded from C:\asdf\AppData\Local\Continuum\anaconda3\lib\site-packages\jupyterlab [I 11:36:26.238 NotebookApp] JupyterLab application directory is C:\asdf\AppData\Local\Continuum\anaconda3\share\jupyter\lab [I 11:36:26.242 NotebookApp] Serving notebooks from local directory: C:\asdf [I 11:36:26.242 NotebookApp] The Jupyter Notebook is running at: [I 11:36:26.242 NotebookApp] http://localhost:8888/?token=xxxxxxxxxxxxxxxxxxxxxxxxxx [I 11:36:26.243 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 11:36:27.633 NotebookApp] To access the notebook, open this file in a browser: file:///C:/asdf/AppData/Roaming/jupyter/runtime/nbserver-9196-open.html Or copy and paste one of these URLs: http://localhost:8888/?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxx ======= code: from keras.datasets import cifar10 (x_train, y_train), (x_test, y_test) = cifar10.load_data() print(x_train.shape) print(y_train.shape) ========= from the jupyter notebook when i click on Run, its throwing me the mentioned error, but able to download the file from the browser Please let me know if any more info is needed to help out. From ml at fam-goebel.de Thu Nov 28 05:05:40 2019 From: ml at fam-goebel.de (Ulrich Goebel) Date: Thu, 28 Nov 2019 11:05:40 +0100 Subject: os.system vs subrocess.call Message-ID: Hi, I have to call commands from inside a python skript. These commands are in fact other python scripts. So I made os.system('\.Test.py') That works. Now I tried to use supprocess.call(['.\', 'test.py']) That doesn't work but ends in an error: Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.5/subprocess.py", line 557, in call with Popen(*popenargs, **kwargs) as p: File "/usr/lib/python3.5/subprocess.py", line 947, in __init__ restore_signals, start_new_session) File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child raise child_exception_type(errno_num, err_msg) PermissionError: [Errno 13] Permission denied Using subprocess.call(['./', 'Test.py'], shell=True) I get Test.py: 1: Test.py: ./: Permission denied Is there a simple way to use subprocess in this usecase? Best regards Ulrich -- Ulrich Goebel Am B?chel 57, 53173 Bonn From __peter__ at web.de Thu Nov 28 05:48:30 2019 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 Nov 2019 11:48:30 +0100 Subject: os.system vs subrocess.call References: Message-ID: Ulrich Goebel wrote: > Hi, > > I have to call commands from inside a python skript. These commands are > in fact other python scripts. So I made > > os.system('\.Test.py') > > That works. > > Now I tried to use > > supprocess.call(['.\', 'test.py']) Remember to use cut and paste for code and traceback. The above triggers a syntax error because the backslash escapes the ending ' of the first argument. Also: is it Test.py or test.py? > > That doesn't work but ends in an error: > > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python3.5/subprocess.py", line 557, in call > with Popen(*popenargs, **kwargs) as p: > File "/usr/lib/python3.5/subprocess.py", line 947, in __init__ > restore_signals, start_new_session) > File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child > raise child_exception_type(errno_num, err_msg) > PermissionError: [Errno 13] Permission denied > > Using > > subprocess.call(['./', 'Test.py'], shell=True) > > I get > > Test.py: 1: Test.py: ./: Permission denied > > Is there a simple way to use subprocess in this usecase? You must not split the path into directory and name. If you are on Linux or similar, your script is executable, and your file system is case sensitive: $ echo -e '#!/usr/bin/python3\nprint("hello")' > test.py $ chmod u+x test.py $ cat test.py #!/usr/bin/python3 print("hello") $ python3 Python 3.4.3 (default, Nov 12 2018, 22:25:49) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess >>> subprocess.call(["./test.py"]) hello 0 From ml at fam-goebel.de Thu Nov 28 06:07:40 2019 From: ml at fam-goebel.de (Ulrich Goebel) Date: Thu, 28 Nov 2019 12:07:40 +0100 Subject: os.system vs subrocess.call In-Reply-To: References: Message-ID: <4da3b35f-372f-9a5f-eb07-fe63819692cc@fam-goebel.de> Sorry for the wrong spelling. In fact subprocess.call('./Test.py') works. The raising error was my error too, using ['./', 'Test.py'] instead of './Test.py' Sorry... Am 28.11.19 um 11:05 schrieb Ulrich Goebel: > Hi, > > I have to call commands from inside a python skript. These commands are > in fact other python scripts. So I made > > ??? os.system('\.Test.py') > > That works. > > Now I tried to use > > ??? supprocess.call(['.\', 'test.py']) > > That doesn't work but ends in an error: > > Traceback (most recent call last): > ? File "", line 1, in > ? File "/usr/lib/python3.5/subprocess.py", line 557, in call > ??? with Popen(*popenargs, **kwargs) as p: > ? File "/usr/lib/python3.5/subprocess.py", line 947, in __init__ > ??? restore_signals, start_new_session) > ? File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child > ??? raise child_exception_type(errno_num, err_msg) > PermissionError: [Errno 13] Permission denied > > Using > > ??? subprocess.call(['./', 'Test.py'], shell=True) > > I get > > Test.py: 1: Test.py: ./: Permission denied > > Is there a simple way to use subprocess in this usecase? > > Best regards > Ulrich > -- Ulrich Goebel Am B?chel 57, 53173 Bonn From pieter-l at vanoostrum.org Thu Nov 28 06:30:27 2019 From: pieter-l at vanoostrum.org (Pieter van Oostrum) Date: Thu, 28 Nov 2019 12:30:27 +0100 Subject: os.system vs subrocess.call References: Message-ID: Ulrich Goebel writes: > Hi, > > I have to call commands from inside a python skript. These commands are > in fact other python scripts. So I made > > os.system('\.Test.py') > > That works. In a string \. is the same as . So this should execute the command '.Test.py'. Is that really what you did? Or did you mean os.system('./Test.py') which is much more probable. NOTE: Never retype the commands that you used, but copy and paste them. > > Now I tried to use > > supprocess.call(['.\', 'test.py']) > That can't have given the error below, as it would have to be subprocess.call, not supprocess.call. And then also '.\' would have given a syntax error. NOTE: Never retype the commands that you used, but copy and paste them. > That doesn't work but ends in an error: > > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python3.5/subprocess.py", line 557, in call > with Popen(*popenargs, **kwargs) as p: > File "/usr/lib/python3.5/subprocess.py", line 947, in __init__ > restore_signals, start_new_session) > File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child > raise child_exception_type(errno_num, err_msg) > PermissionError: [Errno 13] Permission denied > > Using > > subprocess.call(['./', 'Test.py'], shell=True) > > I get > > Test.py: 1: Test.py: ./: Permission denied > Why would you do that, splitting './Test.py' in two parts? That doesn't work. > Is there a simple way to use subprocess in this usecase? > subprocess.call(['./Test.py']) -- Pieter van Oostrum www: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From blmadhavan at gmail.com Thu Nov 28 06:51:38 2019 From: blmadhavan at gmail.com (Madhavan Bomidi) Date: Thu, 28 Nov 2019 03:51:38 -0800 (PST) Subject: How to convert the following IDL program lines to equivalent Python program lines? Message-ID: <954338a7-d792-4bd7-95fd-b59ab87ff3b9@googlegroups.com> Hi, I have the following IDL program lines. I want to write equivalent Python program lines. Can anyone suggest me equivalent Pythons program lines? # ------------------- 1 ----------------------- # How to handle the format in IDL to Python? IDL program line: print,'Column ',J,' of product matrix A*AINV:',format='(1X,A7,I3,A27)' Python program line written by me: print('Column '+str(j)+' of product matrix A*AINV:') #-------------------2 ------------------------ # How the JMP can be transformed in Python? IDL program lines: FOR K=1,M DO BEGIN FOR I=1,M DO BEGIN IF I NE K THEN BEGIN IF WK(K-1,K-1) EQ 0 THEN BEGIN L=1 JMP: IF WK(L-1,K-1) EQ 0 THEN BEGIN L=L+1 GOTO, JMP ENDIF FOR J=K,2*M DO BEGIN WK(K-1,J-1)=WK(K-1,J-1)+WK(L-1,J-1) ENDFOR ENDIF U=-WK(I-1,K-1)/WK(K-1,K-1) FOR J=K+1,2*M DO BEGIN WK(I-1,J-1)=WK(I-1,J-1)+U*WK(K-1,J-1) ENDFOR ENDIF ENDFOR ENDFOR JMP: RETURN Python program lines: for k in np.arange(1,M+1,dtype=int): for i in np.arange(1,M+1,dtype=int): if (i != k): if (WK[k-1,k-1] == 0): L = 1 if (WK[k-1,L-1] == 0): # JMP L = L+1 for j in np.arange(k,2*M+1,dtype=int): WK[j-1,k-1] = WK[j-1,k-1] + WK[j-1,L-1] U = -WK[k-1,i-1]/WK[k-1,k-1] for j in np.arange(k+1,2*M+1,dtype=int): WK[j-1,i-1] = WK[j-1,i-1]+U*WK[j-1,k-1] Can someone provide their feedback on whether I have done the correct transformation of the above IDL program lines to python program lines? Look forward to the suggestions. From ben.usenet at bsb.me.uk Thu Nov 28 07:45:27 2019 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Thu, 28 Nov 2019 12:45:27 +0000 Subject: How to convert the following IDL program lines to equivalent Python program lines? References: <954338a7-d792-4bd7-95fd-b59ab87ff3b9@googlegroups.com> Message-ID: <87imn441aw.fsf@bsb.me.uk> Madhavan Bomidi writes: > I have the following IDL program lines. I want to write equivalent > Python program lines. Can anyone suggest me equivalent Pythons program > lines? > > # ------------------- 1 ----------------------- # > How to handle the format in IDL to Python? > > IDL program line: > > print,'Column ',J,' of product matrix A*AINV:',format='(1X,A7,I3,A27)' > > > Python program line written by me: > > print('Column '+str(j)+' of product matrix A*AINV:') You could just use print('Column', j, 'of product matrix A*AINV:') but if you need to copy the I3 format: print('Column {0:3} of product matrix A*AINV:'.format(j)) I don't know what the 1X format does. The A7 and A27 formats just seem to involve the programmer counting the strings. Very odd. > #-------------------2 ------------------------ # > How the JMP can be transformed in Python? > > IDL program lines: > > FOR K=1,M DO BEGIN > FOR I=1,M DO BEGIN > IF I NE K THEN BEGIN > IF WK(K-1,K-1) EQ 0 THEN BEGIN > L=1 > JMP: IF WK(L-1,K-1) EQ 0 THEN BEGIN > L=L+1 > GOTO, JMP > ENDIF > FOR J=K,2*M DO BEGIN > WK(K-1,J-1)=WK(K-1,J-1)+WK(L-1,J-1) > ENDFOR > ENDIF > U=-WK(I-1,K-1)/WK(K-1,K-1) > FOR J=K+1,2*M DO BEGIN > WK(I-1,J-1)=WK(I-1,J-1)+U*WK(K-1,J-1) > ENDFOR > ENDIF > ENDFOR > ENDFOR > > JMP: RETURN This is very odd. What does it mean when a label is duplicated in IDL? If the second one were not there, this: JMP: IF WK(L-1,K-1) EQ 0 THEN BEGIN L=L+1 GOTO, JMP ENDIF would just be a while loop: while WK[L-1,K-1] == 0: L=L+1 By the way, all those -1s suggest that the IDL was itself a translation from a language with 1-based array indexing. All that might be able to be tidied up. -- Ben. From voodoo.bender at gmail.com Thu Nov 28 10:44:54 2019 From: voodoo.bender at gmail.com (alberto) Date: Thu, 28 Nov 2019 07:44:54 -0800 (PST) Subject: install software Message-ID: <5a1ee040-ffe0-4e75-a1cd-c39b7bec909d@googlegroups.com> Hi, I'm trying to install a python source https://github.com/peteboyd/lammps_interface when I run the example test I receive this error AttributeError: 'NoneType' object has no attribute 'copy' How could I fix it? regards lammps-interface /home/alberto/Scaricati/lammps_interface-master/test_struct/IRMOF-1.cif fatal: Not a git repository (or any of the parent directories): .git No bonds reported in cif file - computing bonding.. Molecules found in the framework, separating. Traceback (most recent call last): File "/usr/local/bin/lammps-interface", line 4, in __import__('pkg_resources').run_script('lammps-interface==0.1.1', 'lammps-interface') File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 719, in run_script self.require(requires)[0].run_script(script_name, ns) File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1504, in run_script exec(code, namespace, namespace) File "/usr/local/lib/python3.5/dist-packages/lammps_interface-0.1.1-py3.5.egg/EGG-INFO/scripts/lammps-interface", line 13, in sim.split_graph() File "/usr/local/lib/python3.5/dist-packages/lammps_interface-0.1.1-py3.5.egg/lammps_interface/lammps_main.py", line 398, in split_graph sg = self.cut_molecule(molecule) File "/usr/local/lib/python3.5/dist-packages/lammps_interface-0.1.1-py3.5.egg/lammps_interface/lammps_main.py", line 1535, in cut_molecule mgraph.distance_matrix = self.graph.distance_matrix.copy() AttributeError: 'NoneType' object has no attribute 'copy' the installetion seems completed correctly sudo python3 setup.py install /usr/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type' warnings.warn(msg) running install Checking .pth file support in /usr/local/lib/python3.5/dist-packages/ /usr/bin/python3 -E -c pass TEST PASSED: /usr/local/lib/python3.5/dist-packages/ appears to support .pth files running bdist_egg running egg_info creating lammps_interface.egg-info writing requirements to lammps_interface.egg-info/requires.txt writing dependency_links to lammps_interface.egg-info/dependency_links.txt writing lammps_interface.egg-info/PKG-INFO writing top-level names to lammps_interface.egg-info/top_level.txt writing manifest file 'lammps_interface.egg-info/SOURCES.txt' reading manifest file 'lammps_interface.egg-info/SOURCES.txt' writing manifest file 'lammps_interface.egg-info/SOURCES.txt' installing library code to build/bdist.linux-x86_64/egg running install_lib running build_py creating build creating build/lib creating build/lib/lammps_interface copying lammps_interface/mof_sbus.py -> build/lib/lammps_interface copying lammps_interface/Dubbeldam.py -> build/lib/lammps_interface copying lammps_interface/gas_models.py -> build/lib/lammps_interface copying lammps_interface/lammps_main.py -> build/lib/lammps_interface copying lammps_interface/structure_data.py -> build/lib/lammps_interface copying lammps_interface/Molecules.py -> build/lib/lammps_interface copying lammps_interface/water_models.py -> build/lib/lammps_interface copying lammps_interface/lammps_potentials.py -> build/lib/lammps_interface copying lammps_interface/BTW.py -> build/lib/lammps_interface copying lammps_interface/dreiding.py -> build/lib/lammps_interface copying lammps_interface/CIFIO.py -> build/lib/lammps_interface copying lammps_interface/__init__.py -> build/lib/lammps_interface copying lammps_interface/generic_raspa.py -> build/lib/lammps_interface copying lammps_interface/atomic.py -> build/lib/lammps_interface copying lammps_interface/ccdc.py -> build/lib/lammps_interface copying lammps_interface/uff_nonbonded.py -> build/lib/lammps_interface copying lammps_interface/MOFFF.py -> build/lib/lammps_interface copying lammps_interface/uff.py -> build/lib/lammps_interface copying lammps_interface/InputHandler.py -> build/lib/lammps_interface copying lammps_interface/uff4mof.py -> build/lib/lammps_interface copying lammps_interface/ForceFields.py -> build/lib/lammps_interface creating build/bdist.linux-x86_64 creating build/bdist.linux-x86_64/egg creating build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/mof_sbus.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/Dubbeldam.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/gas_models.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/lammps_main.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/structure_data.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/Molecules.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/water_models.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/lammps_potentials.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/BTW.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/dreiding.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/CIFIO.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/__init__.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/generic_raspa.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/atomic.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/ccdc.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/uff_nonbonded.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/MOFFF.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/uff.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/InputHandler.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/uff4mof.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/ForceFields.py -> build/bdist.linux-x86_64/egg/lammps_interface byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/mof_sbus.py to mof_sbus.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/Dubbeldam.py to Dubbeldam.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/gas_models.py to gas_models.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/lammps_main.py to lammps_main.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/structure_data.py to structure_data.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/Molecules.py to Molecules.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/water_models.py to water_models.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/lammps_potentials.py to lammps_potentials.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/BTW.py to BTW.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/dreiding.py to dreiding.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/CIFIO.py to CIFIO.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/__init__.py to __init__.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/generic_raspa.py to generic_raspa.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/atomic.py to atomic.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/ccdc.py to ccdc.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/uff_nonbonded.py to uff_nonbonded.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/MOFFF.py to MOFFF.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/uff.py to uff.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/InputHandler.py to InputHandler.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/uff4mof.py to uff4mof.cpython-35.pyc byte-compiling build/bdist.linux-x86_64/egg/lammps_interface/ForceFields.py to ForceFields.cpython-35.pyc creating build/bdist.linux-x86_64/egg/EGG-INFO installing scripts to build/bdist.linux-x86_64/egg/EGG-INFO/scripts running install_scripts running build_scripts creating build/scripts-3.5 copying and adjusting lammps-interface -> build/scripts-3.5 changing mode of build/scripts-3.5/lammps-interface from 644 to 755 creating build/bdist.linux-x86_64/egg/EGG-INFO/scripts copying build/scripts-3.5/lammps-interface -> build/bdist.linux-x86_64/egg/EGG-INFO/scripts changing mode of build/bdist.linux-x86_64/egg/EGG-INFO/scripts/lammps-interface to 755 copying lammps_interface.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO copying lammps_interface.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying lammps_interface.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying lammps_interface.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying lammps_interface.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO zip_safe flag not set; analyzing archive contents... lammps_interface.__pycache__.InputHandler.cpython-35: module references __file__ creating dist creating 'dist/lammps_interface-0.1.1-py3.5.egg' and adding 'build/bdist.linux-x86_64/egg' to it removing 'build/bdist.linux-x86_64/egg' (and everything under it) Processing lammps_interface-0.1.1-py3.5.egg removing '/usr/local/lib/python3.5/dist-packages/lammps_interface-0.1.1-py3.5.egg' (and everything under it) creating /usr/local/lib/python3.5/dist-packages/lammps_interface-0.1.1-py3.5.egg Extracting lammps_interface-0.1.1-py3.5.egg to /usr/local/lib/python3.5/dist-packages lammps-interface 0.1.1 is already the active version in easy-install.pth Installing lammps-interface script to /usr/local/bin Installed /usr/local/lib/python3.5/dist-packages/lammps_interface-0.1.1-py3.5.egg Processing dependencies for lammps-interface==0.1.1 Searching for matplotlib==3.0.3 Best match: matplotlib 3.0.3 Processing matplotlib-3.0.3-py3.5-linux-x86_64.egg matplotlib 3.0.3 is already the active version in easy-install.pth Using /usr/local/lib/python3.5/dist-packages/matplotlib-3.0.3-py3.5-linux-x86_64.egg Searching for networkx==2.4 Best match: networkx 2.4 Processing networkx-2.4-py3.5.egg networkx 2.4 is already the active version in easy-install.pth Using /usr/local/lib/python3.5/dist-packages/networkx-2.4-py3.5.egg Searching for scipy==1.3.3 Best match: scipy 1.3.3 Adding scipy 1.3.3 to easy-install.pth file Using /home/alberto/.local/lib/python3.5/site-packages Searching for numpy==1.17.4 Best match: numpy 1.17.4 Processing numpy-1.17.4-py3.5-linux-x86_64.egg numpy 1.17.4 is already the active version in easy-install.pth Installing f2py3 script to /usr/local/bin Installing f2py3.5 script to /usr/local/bin Installing f2py script to /usr/local/bin Using /usr/local/lib/python3.5/dist-packages/numpy-1.17.4-py3.5-linux-x86_64.egg Searching for python-dateutil==2.4.2 Best match: python-dateutil 2.4.2 python-dateutil 2.4.2 is already the active version in easy-install.pth Using /usr/lib/python3/dist-packages Searching for pyparsing==2.0.3 Best match: pyparsing 2.0.3 pyparsing 2.0.3 is already the active version in easy-install.pth Using /usr/lib/python3/dist-packages Searching for kiwisolver==1.1.0 Best match: kiwisolver 1.1.0 Processing kiwisolver-1.1.0-py3.5-linux-x86_64.egg kiwisolver 1.1.0 is already the active version in easy-install.pth Using /usr/local/lib/python3.5/dist-packages/kiwisolver-1.1.0-py3.5-linux-x86_64.egg Searching for cycler==0.10.0 Best match: cycler 0.10.0 Processing cycler-0.10.0-py3.5.egg Removing cycler 0.9.0 from easy-install.pth file cycler 0.10.0 is already the active version in easy-install.pth Using /usr/local/lib/python3.5/dist-packages/cycler-0.10.0-py3.5.egg Searching for decorator==4.4.1 Best match: decorator 4.4.1 Processing decorator-4.4.1-py3.5.egg decorator 4.4.1 is already the active version in easy-install.pth Using /usr/local/lib/python3.5/dist-packages/decorator-4.4.1-py3.5.egg Searching for setuptools==20.7.0 Best match: setuptools 20.7.0 Adding setuptools 20.7.0 to easy-install.pth file Installing easy_install script to /usr/local/bin Using /usr/lib/python3/dist-packages Searching for six==1.10.0 Best match: six 1.10.0 six 1.10.0 is already the active version in easy-install.pth Using /usr/lib/python3/dist-packages Finished processing dependencies for lammps-interface==0.1.1 From countryone77 at gmail.com Thu Nov 28 12:03:55 2019 From: countryone77 at gmail.com (Bev In TX) Date: Thu, 28 Nov 2019 11:03:55 -0600 Subject: How to convert the following IDL program lines to equivalent Python program lines? In-Reply-To: <3cpvtelb6jk7bau8iq1i4pkuc90nivtofh@4ax.com> References: <954338a7-d792-4bd7-95fd-b59ab87ff3b9@googlegroups.com> <87imn441aw.fsf@bsb.me.uk> <3cpvtelb6jk7bau8iq1i4pkuc90nivtofh@4ax.com> Message-ID: <2CCA1043-55A6-4305-B3E2-1709FE2FD199@gmail.com> > On Nov 28, 2019, at 9:35 AM, Dennis Lee Bieber wrote: > > Channeling ancient FORTRAN, I'd interpret it as > > 1X Skip one space > A7 Seven character alpha > I3 Three digit integer > A27 27 character alpha > > and it is rather painful when the arguments are literals of those sizes. > Makes more sense if the arguments are strings of various widths yet column > alignment is required. > > Since I still favor string interpolation for formatting, I'd probably > just end up with > > print(" Column %3d of product matrix A*AINV:") > > {Odd that the original uses a 1X format, when the literals have white space > at the adjoining ends... Why not " Column " with A8 format?} Still channeling Fortran, 1X ensured a blank in column 1, which was used strictly for carriage control on a line printer. A8 may, or may not leave a blank in column 1, which could have caused erroneous carriage controls. Bev in TX From python at mrabarnett.plus.com Thu Nov 28 12:13:35 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 28 Nov 2019 17:13:35 +0000 Subject: How to convert the following IDL program lines to equivalent Python program lines? In-Reply-To: <3cpvtelb6jk7bau8iq1i4pkuc90nivtofh@4ax.com> References: <954338a7-d792-4bd7-95fd-b59ab87ff3b9@googlegroups.com> <87imn441aw.fsf@bsb.me.uk> <3cpvtelb6jk7bau8iq1i4pkuc90nivtofh@4ax.com> Message-ID: <1b6fb769-8e55-0bb5-4fcb-f2c268bcceff@mrabarnett.plus.com> On 2019-11-28 15:35, Dennis Lee Bieber wrote: > On Thu, 28 Nov 2019 12:45:27 +0000, Ben Bacarisse > declaimed the following: > >>Madhavan Bomidi writes: >>> >>> print,'Column ',J,' of product matrix A*AINV:',format='(1X,A7,I3,A27)' >>> > >> >>I don't know what the 1X format does. The A7 and A27 formats just seem >>to involve the programmer counting the strings. Very odd. >> > > Channeling ancient FORTRAN, I'd interpret it as > > 1X Skip one space > A7 Seven character alpha > I3 Three digit integer > A27 27 character alpha > > and it is rather painful when the arguments are literals of those sizes. > Makes more sense if the arguments are strings of various widths yet column > alignment is required. > > Since I still favor string interpolation for formatting, I'd probably > just end up with > > print(" Column %3d of product matrix A*AINV:") > > {Odd that the original uses a 1X format, when the literals have white space > at the adjoining ends... Why not " Column " with A8 format?} > In Fortran, if the first character printed is a space, then the remainder is printed on a new line, else the remainder is printed as a continuation of the previous line. Thus, the initial 1X is making it start on a new line. > > > >> >>This is very odd. What does it mean when a label is duplicated in IDL? >>If the second one were not there, this: >> >> JMP: IF WK(L-1,K-1) EQ 0 THEN BEGIN >> L=L+1 >> GOTO, JMP >> ENDIF >> >>would just be a while loop: >> >> while WK[L-1,K-1] == 0: >> L=L+1 >> >> >> Did you notice that "JMP:" occurs twice? Very strange! >>By the way, all those -1s suggest that the IDL was itself a translation >>from a language with 1-based array indexing. All that might be able to >>be tidied up. > > Heck -- the IDL could be tidied up... All those loop indices could be > configured to run 0..n-1, rather than 1..n > > Looks a lot like a garbaged form of FORTRAN that has removed the . from > relational operators, and tried to use blocked syntax. > > EQ => .eq. > NE => .ne. > > FOR i = s, e DO BEGIN > > => > DO lbl i=s, e > stuff > lbl CONTINUE > > From stephan.lukits at gmail.com Thu Nov 28 05:44:50 2019 From: stephan.lukits at gmail.com (Stephan Lukits) Date: Thu, 28 Nov 2019 12:44:50 +0200 Subject: os.system vs subrocess.call In-Reply-To: References: Message-ID: > On 28. Nov 2019, at 12:05, Ulrich Goebel wrote: > > Hi, > > I have to call commands from inside a python skript. These commands are in fact other python scripts. So I made > > os.system('\.Test.py') > > That works. > > Now I tried to use > > supprocess.call(['.\', 'test.py']) [ins] In [1]: from os import system [ins] In [2]: system('./test.py') hallo world Out[2]: 0 [ins] In [3]: from subprocess import call [ins] In [4]: call('./test.py') hallo world Out[4]: 0 In the first call you call ?.Test.py? In the second call you call ?test.py? ?supprocess? doesn?t exist How about subprocess.call(?\.Test.py?) Or subprocess.call([?\.Test.py?]) Whereas the later makes more sense if you want to pass arguments to Test.py Greetings Stephan From pahome.chen at mirlab.org Thu Nov 28 22:46:07 2019 From: pahome.chen at mirlab.org (lampahome) Date: Fri, 29 Nov 2019 11:46:07 +0800 Subject: Does module socketserver using epoll in python3? Message-ID: As title, I want to use socketserver to replace my own server code to maintain ealsier. But I don't found any info about tech. detail of socketserver, epoll is important. Can anyone tell me? From torriem at gmail.com Thu Nov 28 23:03:41 2019 From: torriem at gmail.com (Michael Torrie) Date: Thu, 28 Nov 2019 21:03:41 -0700 Subject: Does module socketserver using epoll in python3? In-Reply-To: References: Message-ID: <87bb2eba-efdf-c69f-226e-ab3e42ff97b9@gmail.com> On 11/28/19 8:46 PM, lampahome wrote: > As title, > > I want to use socketserver to replace my own server code to > maintain ealsier. > > But I don't found any info about tech. detail of socketserver, epoll is > important. > > Can anyone tell me? The source code is here: https://github.com/python/cpython/blob/master/Lib/socketserver.py . You should find all the technical details you are looking for in it. From pahome.chen at mirlab.org Thu Nov 28 23:11:22 2019 From: pahome.chen at mirlab.org (lampahome) Date: Fri, 29 Nov 2019 12:11:22 +0800 Subject: Does module socketserver using epoll in python3? In-Reply-To: <87bb2eba-efdf-c69f-226e-ab3e42ff97b9@gmail.com> References: <87bb2eba-efdf-c69f-226e-ab3e42ff97b9@gmail.com> Message-ID: > > The source code is here: > https://github.com/python/cpython/blob/master/Lib/socketserver.py . You > should find all the technical details you are looking for in it. > > # poll/select have the advantage of not requiring any extra file > descriptor,# contrarily to epoll/kqueue (also, they require a single > syscall). > if hasattr(selectors, 'PollSelector'): > _ServerSelector = selectors.PollSelector > else: > _ServerSelector = selectors.SelectSelector Oh..no It uses poll or select ranther than epoll. Maybe it suffer some performance degrading. thx lot. From p4j at j4d.net Fri Nov 29 01:53:18 2019 From: p4j at j4d.net (Pankaj Jangid) Date: Fri, 29 Nov 2019 12:23:18 +0530 Subject: tab replace to space 4 References: Message-ID: ??? writes: > usally i write python code in gnu emacs on ubuntu 18.04 sometimes i > re-edit the code vim in same machine so often when i do run the code in > shell like as ./test.py i meet consol error -- which line wrong! > > so i am considering how can i replace all tab to space 4 within python > code. if there is solution in google i am very sorry. In Emacs, use "M-x untabify". And "M-x tabify" if you want to do the reverse. Regards, -- Pankaj Jangid From tjreedy at udel.edu Fri Nov 29 03:12:07 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Nov 2019 03:12:07 -0500 Subject: tab replace to space 4 In-Reply-To: References: Message-ID: On 11/29/2019 1:53 AM, Pankaj Jangid wrote: > ??? writes: >> usally i write python code in gnu emacs on ubuntu 18.04 sometimes i >> re-edit the code vim in same machine so often when i do run the code in >> shell like as ./test.py i meet consol error -- which line wrong! >> >> so i am considering how can i replace all tab to space 4 within python >> code. if there is solution in google i am very sorry. > > In Emacs, use "M-x untabify". And "M-x tabify" if you want to do the > reverse. IDLE has entries on the Format menu to do the same. -- Terry Jan Reedy From address at not.available Fri Nov 29 04:34:49 2019 From: address at not.available (R.Wieser) Date: Fri, 29 Nov 2019 10:34:49 +0100 Subject: tab replace to space 4 References: Message-ID: Moi, > tkinter/IDLE in py380 : completely buggy. Example code please ? (plus a description of what should happen and what happens instead if you have it) Regards, Rudy Wieser From self at gkayaalp.com Fri Nov 29 06:29:45 2019 From: self at gkayaalp.com (=?utf-8?Q?G=C3=B6ktu=C4=9F_Kayaalp?=) Date: Fri, 29 Nov 2019 14:29:45 +0300 Subject: Library Generate a diff between two text files In-Reply-To: (message from Noah on Mon, 25 Nov 2019 16:31:39 +0300) Message-ID: On 2019-11-25 16:31 +03, Noah wrote: >>From experience, could someone point me to a library that can do a diff > between two separate text files... > > *difflib* doesn't seem to cut it to this end.... Kinda simplistic idea, but would shelling out to diff(1) work for you? GNU diff is probably one of the most sophisticated tools for generating diffs out there, if not the one, given the sheer amount of usage and care it?s subject to. Cheers, -gk. From soyeomul at doraji.xyz Thu Nov 28 23:46:38 2019 From: soyeomul at doraji.xyz (=?utf-8?B?7Zmp67OR7Z2s?=) Date: Fri, 29 Nov 2019 13:46:38 +0900 Subject: tab replace to space 4 Message-ID: [i am writing question on comp.lang.python] usally i write python code in gnu emacs on ubuntu 18.04 sometimes i re-edit the code vim in same machine so often when i do run the code in shell like as ./test.py i meet consol error -- which line wrong! so i am considering how can i replace all tab to space 4 within python code. if there is solution in google i am very sorry. thanks all and any comments welcome^^^ -- ^????? _????_ ?????_^))// From soyeomul at doraji.xyz Fri Nov 29 10:42:25 2019 From: soyeomul at doraji.xyz (=?utf-8?B?7Zmp67OR7Z2s?=) Date: Sat, 30 Nov 2019 00:42:25 +0900 Subject: tab replace to space 4 References: Message-ID: Hello, Pankaj^^^ > In Emacs, use "M-x untabify". [...] Then i solved problem You nice guy! Sincerely, -- ^????? _????_ ?????_^))// From tjreedy at udel.edu Fri Nov 29 14:45:46 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Nov 2019 14:45:46 -0500 Subject: tab replace to space 4 In-Reply-To: References: Message-ID: On 11/29/2019 4:34 AM, R.Wieser wrote: > > Moi, > >> tkinter/IDLE in py380 : completely buggy. That troll post is not in the python-list archive (whereas RW's response is), so it is likely from someone banned on the list itself. R.W., are you reading via c.l.p, or the python google group? > Example code please ? (plus a description of what should happen and what > happens instead if you have it) Don't hold your breath. A similar poster I challenged on StackOverflow was honest enough to admit that he had not touched IDLE for a decade. -- Terry Jan Reedy From address at not.available Fri Nov 29 15:05:33 2019 From: address at not.available (R.Wieser) Date: Fri, 29 Nov 2019 21:05:33 +0100 Subject: tab replace to space 4 References: Message-ID: Terry, > R.W., are you reading via c.l.p, or the python google group? The first, using nntp.aioe.org > Don't hold your breath. A similar poster I challenged on StackOverflow > was honest enough to admit that he had not touched IDLE for a decade. Its just that I've just began to touch tkinter, and would like to know of bug-related pitfalls before I waste energy on trying to figure out what I did wrong. :-\ Also, not asking at all makes sure my chances of getting an answer is zero. :-) Regards, Rudy Wieser From tjreedy at udel.edu Fri Nov 29 17:03:19 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Nov 2019 17:03:19 -0500 Subject: tab replace to space 4 In-Reply-To: References: Message-ID: On 11/29/2019 3:05 PM, R.Wieser wrote: > Terry, > Its just that I've just began to touch tkinter, and would like to know of > bug-related pitfalls before I waste energy on trying to figure out what I > did wrong. :-\ I have been using tk/tkinter based IDLE for over a decade on Windows with very few issues. I think they are similarly stable on linux, etc. macOS has been more problematical since Apple a) still provides the ancient (15 years old?) and buggy tcl/tk 8.5.9 and b) keeps changing things in its Aqua graphics, so that different tk releases has different bugs. tcl/tk on macOS has gotten lots of work in the last few years and the devs claim that the brand new 8.6.10 should solve most of the problems. Since 8.7.0, our macOS installer has included a recent 8.6.x. It is possible that the upcoming 3.8.1 will include tk 8.6.10 if our tests verify the claims. -- Terry Jan Reedy From address at not.available Sat Nov 30 01:59:43 2019 From: address at not.available (R.Wieser) Date: Sat, 30 Nov 2019 07:59:43 +0100 Subject: tab replace to space 4 References: Message-ID: Terry, > I have been using tk/tkinter based IDLE for over a decade on Windows with > very few issues. I think they are similarly stable on linux, etc. [Snip] Thanks for that explanation. And I see that, in my question, I should have asked for the involved OS too. Regards, Rudy Wieser From tim at akwebsoft.com Sat Nov 30 14:49:01 2019 From: tim at akwebsoft.com (Tim Johnson) Date: Sat, 30 Nov 2019 10:49:01 -0900 Subject: ModuleNotFoundError with click module Message-ID: <32cc3ffc-bb43-284f-dfd8-7451ba100ec7@akwebsoft.com> Using linux ubuntu 16.04 with bash shell. Am retired python programmer, but not terribly current. I have moderate bash experience. When trying to install pgadmin4 via apt I get the following error traceback when pgadmin4 is invoked: Traceback (most recent call last): ? File "setup.py", line 17, in ??? from pgadmin.model import db, User, Version, ServerGroup, Server, \ ? File "/usr/share/pgadmin4/web/pgadmin/__init__.py", line 19, in ??? from flask import Flask, abort, request, current_app, session, url_for ? File "/usr/local/lib/python3.7/site-packages/flask/__init__.py", line 21, in ??? from .app import Flask ? File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 34, in ??? from . import cli File "/usr/local/lib/python3.7/site-packages/flask/cli.py", line 25, in import click ModuleNotFoundError: No module named 'click' If I invoke python3 (/usr/local/bin/python3), version 3.7.2 and invoke >>> import click click is imported successfully. In this invocation, sys.path is: ['', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/home/tim/.local/lib/python3.7/site-packages', '/usr/local/lib/python3.7/site-packages'] $PYTHONPATH is empty when the bash shell is invoked $PATH as follows: /home/tim/bin:/home/tim/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin click.py can be found at /usr/local/lib/python3.7/site-packages/pipenv/patched/piptools/ in turn click.py imports click, presumably as the package, which appears to be at /usr/local/lib/python3.7/site-packages/pipenv/vendor/click Any number of settings of PYTHONPATH to the various paths above has failed to resolve the ModuleNotFoundError Same issues with attempting install from a virtual environment. Any help will be appreciated. thanks tim From skip.montanaro at gmail.com Sat Nov 30 15:51:08 2019 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 30 Nov 2019 14:51:08 -0600 Subject: Mixed Python/C debugging Message-ID: After at least ten years away from Python's run-time interpreter & byte code compiler, I'm getting set to familiarize myself with that again. This will, I think, entail debugging a mixed Python/C environment. I'm an Emacs user and am aware that GDB since 7.0 has support for debugging at the Python code level. Is Emacs+GDB my best bet? Are there any Python IDEs which support C-level breakpoints and debugging? Thanks, Skip From chema at rinzewind.org Sat Nov 30 17:05:45 2019 From: chema at rinzewind.org (=?iso-8859-1?Q?Jos=E9_Mar=EDa?= Mateos) Date: Sat, 30 Nov 2019 17:05:45 -0500 Subject: Pickle caching objects? Message-ID: <20191130220545.GA12875@equipaje> Hi, I just asked this question on the IRC channel but didn't manage to get a response, though some people replied with suggestions that expanded this question a bit. I have a program that has to read some pickle files, perform some operations on them, and then return. The pickle objects I am reading all have the same structure, which consists of a single list with two elements: the first one is a long list, the second one is a numpy object. I found out that, after calling that function, the memory taken by the Python executable (monitored using htop -- the entire thing runs on Python 3.6 on an Ubuntu 16.04, pretty standard conda installation with a few packages installed directly using `conda install`) increases in proportion to the size of the pickle object being read. My intuition is that that memory should be free upon exiting. Does pickle keep a cache of objects in memory after they have been returned? I thought that could be the answer, but then someone suggested to measure the time it takes to load the objects. This is a script I wrote to test this; nothing(filepath) just loads the pickle file, doesn't do anything with the output and returns how long it took to perform the load operation. --- import glob import pickle import timeit import os import psutil def nothing(filepath): start = timeit.default_timer() with open(filepath, 'rb') as f: _ = pickle.load(f) return timeit.default_timer() - start if __name__ == "__main__": filelist = glob.glob('/tmp/test/*.pk') for i, filepath in enumerate(filelist): print("Size of file {}: {}".format(i, os.path.getsize(filepath))) print("First call:", nothing(filepath)) print("Second call:", nothing(filepath)) print("Memory usage:", psutil.Process(os.getpid()).memory_info().rss) print() --- This is the output of the second time the script was run, to avoid any effects of potential IO caches: --- Size of file 0: 11280531 First call: 0.1466723980847746 Second call: 0.10044755204580724 Memory usage: 49418240 Size of file 1: 8955825 First call: 0.07904054620303214 Second call: 0.07996074995025992 Memory usage: 49831936 Size of file 2: 43727266 First call: 0.37741047400049865 Second call: 0.38176894187927246 Memory usage: 49758208 Size of file 3: 31122090 First call: 0.271301960805431 Second call: 0.27462846506386995 Memory usage: 49991680 Size of file 4: 634456686 First call: 5.526095286011696 Second call: 5.558765463065356 Memory usage: 539324416 Size of file 5: 3349952658 First call: 29.50982437795028 Second call: 29.461691531119868 Memory usage: 3443597312 Size of file 6: 9384929 First call: 0.0826977719552815 Second call: 0.08362263604067266 Memory usage: 3443597312 Size of file 7: 422137 First call: 0.0057482069823890924 Second call: 0.005949910031631589 Memory usage: 3443597312 Size of file 8: 409458799 First call: 3.562588643981144 Second call: 3.6001368327997625 Memory usage: 3441451008 Size of file 9: 44843816 First call: 0.39132978999987245 Second call: 0.398518088972196 Memory usage: 3441451008 --- Notice that memory usage increases noticeably specially on files 4 and 5, the biggest ones, and doesn't come down as I would expect it to. But the loading time is constant, so I think I can disregard any pickle caching mechanisms. So I guess now my question is: can anyone give me any pointers as to why is this happening? Any help is appreciated. Thanks, -- Jos? Mar?a (Chema) Mateos || https://rinzewind.org/ From rosuav at gmail.com Sat Nov 30 20:26:15 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Dec 2019 12:26:15 +1100 Subject: Pickle caching objects? In-Reply-To: <20191130220545.GA12875@equipaje> References: <20191130220545.GA12875@equipaje> Message-ID: On Sun, Dec 1, 2019 at 12:15 PM Jos? Mar?a Mateos wrote: > print("Memory usage:", psutil.Process(os.getpid()).memory_info().rss) > > Notice that memory usage increases noticeably specially on files 4 and > 5, the biggest ones, and doesn't come down as I would expect it to. But > the loading time is constant, so I think I can disregard any pickle > caching mechanisms. > > So I guess now my question is: can anyone give me any pointers as to why > is this happening? Any help is appreciated. > I can't answer your question authoritatively, but I can suggest a place to look. Python's memory allocator doesn't always return memory to the system when the objects are freed up, for various reasons including the way that memory pages get allocated from. But it internally knows which parts are in use and which parts aren't. You're seeing the RSS go down slightly at some points, which would be the times when entire pages can be released; but other than that, what you'll end up with is a sort of high-water-mark with lots of unused space inside it. So what you're seeing isn't actual objects being cached, but just memory ready to be populated with future objects. ChrisA From Richard at Damon-Family.org Sat Nov 30 20:31:35 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 30 Nov 2019 20:31:35 -0500 Subject: Pickle caching objects? In-Reply-To: <20191130220545.GA12875@equipaje> References: <20191130220545.GA12875@equipaje> Message-ID: On 11/30/19 5:05 PM, Jos? Mar?a Mateos wrote: > Hi, > > I just asked this question on the IRC channel but didn't manage to get > a response, though some people replied with suggestions that expanded > this question a bit. > > I have a program that has to read some pickle files, perform some > operations on them, and then return. The pickle objects I am reading > all have the same structure, which consists of a single list with two > elements: the first one is a long list, the second one is a numpy object. > > I found out that, after calling that function, the memory taken by the > Python executable (monitored using htop -- the entire thing runs on > Python 3.6 on an Ubuntu 16.04, pretty standard conda installation with > a few packages installed directly using `conda install`) increases in > proportion to the size of the pickle object being read. My intuition > is that that memory should be free upon exiting. > > Does pickle keep a cache of objects in memory after they have been > returned? I thought that could be the answer, but then someone > suggested to measure the time it takes to load the objects. This is a > script I wrote to test this; nothing(filepath) just loads the pickle > file, doesn't do anything with the output and returns how long it took > to perform the load operation. > > Notice that memory usage increases noticeably specially on files 4 and > 5, the biggest ones, and doesn't come down as I would expect it to. > But the loading time is constant, so I think I can disregard any > pickle caching mechanisms. > > So I guess now my question is: can anyone give me any pointers as to > why is this happening? Any help is appreciated. > > Thanks, > Python likely doesn't return the memory it has gotten from the OS back to the OS just because it isn't using it at the moment. This is actually very common behavior as getting new memory from the OS is somewhat expensive, and it is common that memory release will be used again shortly. There is also the fact that to return the memory, the block needs to be totally unused, and it isn't hard for a few small pieces to still be left in use. You are asking for the information about how much memory Python has gotten from the OS, which is different than how much it is actively using, as when objects go away there memory is returned to the free pool INSIDE Python, to be used for other requests before asking the OS for more. -- Richard Damon From john_ladasky at sbcglobal.net Sat Nov 30 23:42:21 2019 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sat, 30 Nov 2019 20:42:21 -0800 (PST) Subject: "Don't install on the system Python" Message-ID: <0a065288-f851-4afc-9104-f5b5ca5188f9@googlegroups.com> Long-time Ubuntu user here. For years, I've read warnings about not installing one's personal stack of Python modules on top of the system Python. It is possible to corrupt the OS, or so I've gathered. Well, I've never heeded this advice, and so far nothing bad has happened to me. I don't like Anaconda, or virtual environments in general. I don't like heavyweight IDE's. I like to be able to type "python3" at the command prompt and be sure what I'll be getting. I have multiple user accounts on a system that I manage, and I want every user account to have access to the same modules. Maybe the modules that I require are safe to install on the system Python, I'm not sure. My must-haves are mostly scientific computing and data management modules: Numpy, Scipy, Scikit-learn, Matplotlib, Pandas, Biopython, and Tensorflow. I also use PyQt5 from time to time. Can anyone provide concrete examples of problems arising from installing modules on top of the system Python? Am I courting disaster? Thanks for your advice.