From rantingrickjohnson at gmail.com Sat Apr 1 00:38:05 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 31 Mar 2017 21:38:05 -0700 (PDT) Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58dd12d2$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dd12d2$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <04f771fe-1c40-48e9-85d7-3b743108c5eb@googlegroups.com> On Thursday, March 30, 2017 at 9:14:54 AM UTC-5, Steve D'Aprano wrote: > On Thu, 30 Mar 2017 03:21 pm, Rick Johnson wrote: > > > On Sunday, March 26, 2017 at 2:53:49 PM UTC-5, Chris Angelico wrote: > >> On Mon, Mar 27, 2017 at 6:25 AM, Mikhail V wrote: > >> > On 26 March 2017 at 20:10, Steve D'Aprano > >> > wrote: > >> >> On Mon, 27 Mar 2017 03:57 am, Mikhail V wrote: > Don't be silly. You don't have to be fluent in a language > in order for your program to support users who are. All you > have to do is not stop them from using their own native > language by forcing them to use ASCII and nothing but > ASCII. Of course, if you want to *localise* your UI to > their language, then you need somebody to translate error > messages, menus, window titles, etc. I'll grant that's not > always an easy job. And thats my point. Unicode may allow my French girlfriend Zoe to spell her name using chars that are familiar to her, but Unicode is not a langauge translator. Zoe can still intuit her name in ASCII, but if she's unable to read English, Unicode is of no help to her. > But aren't you lucky, you speak one of a handful of lingua > francas in the world, so the chances are your users will be > pathetically grateful if all you do is let them type in > their own language. Actual UI localisation is a bonus. A bonus for the foreign user, perhaps, but an onerous for the developer. > Now you're just being absurd. Supporting diacritics doesn't > mean you are responsible for teaching your users what > they're for. They already know. That's why they want to use > them. > > Diacritics are for: > > - distinguishing between words which look the same, but > have different pronunciation; I wonder how those poor English readers manage without syntactical clues? it boggles the mind. > - distinguishing between different letters of the alphabet, > like dotted-i and dotless-? (or ? and ?-with-a-dot, if you > prefer), or a and ?; Sounds like the "encoding in question" could use a few more glyphs. > - distinguishing between words which look and sound the > same but mean something different; Oh, you mean like mean people? "In a pale attempt to protect the homestead, the owner smacked an intruder in the face with a large metal pail only to become pale as sheet when the intruder was unaffected by the assault. Do you think the owner's actions were beyond the pale? Or do all other options pale by comparison?" > - and making band names look ???? and annoy old fuddy- > duddies. So now we've even included graffiti artists in our little "inclusivity project". My, my... we are so _not_ mean! From rosuav at gmail.com Sat Apr 1 00:54:03 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Apr 2017 15:54:03 +1100 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <04f771fe-1c40-48e9-85d7-3b743108c5eb@googlegroups.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dd12d2$0$1611$c3e8da3$5496439d@news.astraweb.com> <04f771fe-1c40-48e9-85d7-3b743108c5eb@googlegroups.com> Message-ID: On Sat, Apr 1, 2017 at 3:38 PM, Rick Johnson wrote: >> - distinguishing between different letters of the alphabet, >> like dotted-i and dotless-? (or ? and ?-with-a-dot, if you >> prefer), or a and ?; > > Sounds like the "encoding in question" could use a few more > glyphs. How many glyphs do you think you need? ChrisA From iranna.gani28 at gmail.com Sat Apr 1 02:58:08 2017 From: iranna.gani28 at gmail.com (Iranna Mathapati) Date: Sat, 1 Apr 2017 12:28:08 +0530 Subject: Thread within for loop Message-ID: Hi team, I tried to run fallowing run, *jobs = []* * sniffer1 = threading.Thread(target=validate_traffic_stats_dy,args= (FT_item_dy,RT_item_dy,forward_path_list_dy,return_path_list_dy,nat_type_list_dy,pkt_dy_1,))* * jobs.append(sniffer1)* * sniffer2 = threading.Thread(target=validate_traffic_stats_st,args=(FT_item_st,RT_item_st,forward_path_list_st,return_path_list_st,nat_type_list_st,pkt_st,))* * jobs.append(sniffer2)* * for local_ip, global_ip in zip(src_ipv4_local_list_st_in_new, src_ipv4_global_list_st_in_new):* * sniffer3 = threading.Thread(target=create_static_nat_entries,args = (uut2_hdl2, direction_in, local_ip,global_ip,))* * jobs.append(sniffer3) * * # Start the threads* * for j in jobs:* * j.start()* * time.sleep(2)* * # Ensure all of the threads have finished* * for j in jobs:* * j.join()* while runing i got below error and hitting in sniffer3 thread Exception in thread Thread-5: Traceback (most recent call last): File "/auto/pysw/cel55/python/2.7.8/lib/python2.7/threading.py", line 810, in __bootstrap_inner self.run() File "/auto/pysw/cel55/python/2.7.8/lib/python2.7/threading.py", line 763, in run self.__target(*self.__args, **self.__kwargs) File "/auto/n3k-qa/regression/pyATS2/hlite/eor/systest/scripts/NAT/feature_nat_lib.py", line 50, in create_static_nat_entries {2} add-route'.format(protocol, inside_local_ip, inside_global_ip)) File "../../lib/icon.py", line 899, in iconfig self.hdl.expect('# $') File "/auto/n3k-qa/CODC/ianandan/pyATS2.7/lib/python2.7/site-packages/pexpect/__init__.py", line 1451, in expect timeout, searchwindowsize) File "/auto/n3k-qa/CODC/ianandan/pyATS2.7/lib/python2.7/site-packages/pexpect/__init__.py", line 1466, in expect_list timeout, searchwindowsize) File "/auto/n3k-qa/CODC/ianandan/pyATS2.7/lib/python2.7/site-packages/pexpect/__init__.py", line 1568, in expect_loop raise TIMEOUT(str(err) + '\n' + str(self)) TIMEOUT: Timeout exceeded. version: 3.3 command: /usr/bin/telnet args: ['/usr/bin/telnet', '172.31.205.170', '2025'] searcher: buffer (last 100 chars): '\rSeoul(config)# config terminal\r\r\n\r\r\nend\r\r\n' before (last 100 chars): '\rSeoul(config)# config terminal\r\r\n\r\r\nend\r\r\n' after: match: None match_index: None exitstatus: None flag_eof: False pid: 17297 child_fd: 8 closed: False timeout: 500 delimiter: logfile: logfile_read: None logfile_send: None maxread: 2000 ignorecase: False searchwindowsize: None delaybeforesend: 0.05 delayafterclose: 0.1 delayafterterminate: 0.1 Can you please let me know what is the issue. Thanks, Iranna M From dieter at handshake.de Sat Apr 1 03:38:54 2017 From: dieter at handshake.de (dieter) Date: Sat, 01 Apr 2017 09:38:54 +0200 Subject: Developing a Python JIT and have trouble References: Message-ID: <8737dsziep.fsf@handshake.de> Yuheng Zou writes: > ... > I built a C++ library which contains EvalFrame function, and then use dlopen and dlsym to use it. It looks like this: > > extern "C" PyObject *EvalFrame(PyFrameObject *f, int throwflag) { > return _PyEval_EvalFrameDefault(f, throwflag); > } > I added following code to Python/pylifecycle.c at function _Py_InitializeEx_Private(Python version is 3.6.1): > > void *pyjit = NULL; > pyjit = dlopen("../cmake-build-debug/libPubbon.dylib", 0); > if (pyjit != NULL) { > interp->eval_frame = (_PyFrameEvalFunction)dlsym(pyjit, "EvalFrame"); > //interp->eval_frame = _PyEval_EvalFrameDefault; > } > Then something strange happened. I used LLDB to trace the variables. When it ran at EvalFrame, the address of f pointer didn't change, but f->f_lineno changed. > It may not be very surprising that the lineno changes during execution. It should correspond to the line of the code currently executed. > Then when I ran python.exe, I got Segmentation Fault. > > Why the address of the pointer didn't change, but the context change? Some structure fields (such as lineno) may be expected to change. In addition, the interpreter is using some global variables to maintain state - variables that may change e.g. during thread switches. The "SIGSEGV" might indicate that the structure has been freed -- and is now used for different things. From dieter at handshake.de Sat Apr 1 03:45:00 2017 From: dieter at handshake.de (dieter) Date: Sat, 01 Apr 2017 09:45:00 +0200 Subject: Thread within for loop References: Message-ID: <87y3vky3k3.fsf@handshake.de> Iranna Mathapati writes: > ... > Exception in thread Thread-5: > Traceback (most recent call last): > ... > File > "/auto/n3k-qa/CODC/ianandan/pyATS2.7/lib/python2.7/site-packages/pexpect/__init__.py", > line 1466, in expect_list > timeout, searchwindowsize) > File > "/auto/n3k-qa/CODC/ianandan/pyATS2.7/lib/python2.7/site-packages/pexpect/__init__.py", > line 1568, in expect_loop > raise TIMEOUT(str(err) + '\n' + str(self)) > TIMEOUT: Timeout exceeded. "Timeout" means that the "pexpect" partner did not respond sufficiently fast. From No_spamming at noWhere_7073.org Sat Apr 1 04:13:34 2017 From: No_spamming at noWhere_7073.org (Robert L.) Date: Sat, 1 Apr 2017 08:13:34 +0000 (UTC) Subject: Better way to do this dict comprehesion References: Message-ID: On 3/7/2017, Sayth Renshaw wrote: > I have got this dictionary comprehension and it > works but how can I do it better? > > from collections import Counter > > def find_it(seq): > counts = dict(Counter(seq)) > a = [(k, v) for k,v in counts.items() if v % 3 == 0] > return a[0][0] > > test_seq = [20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5] > > so this returns 5 which is great and the point > of the problem I was doing. > > Can also do it like this > def find_it(seq): > counts = dict(Counter(seq)) > a = [(k) for k,v in counts.items() if v % 3 == 0] > return a[0] > > But the given problem states there will always > only be one number appearing an odd number of > times given that is there a neater way to get > the answer? [20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5].group_by{|x| x}. find{|k,v| v.size.odd?}.first ===> 5 -- sig redacted From iranna.gani28 at gmail.com Sat Apr 1 04:23:35 2017 From: iranna.gani28 at gmail.com (Iranna Mathapati) Date: Sat, 1 Apr 2017 13:53:35 +0530 Subject: Thread within for loop In-Reply-To: <87y3vky3k3.fsf@handshake.de> References: <87y3vky3k3.fsf@handshake.de> Message-ID: Hi , How to fix it and now i got below error for same script *runtimeerror threads can only be started once then* *Thanks,* On Sat, Apr 1, 2017 at 1:15 PM, dieter wrote: > Iranna Mathapati writes: > > ... > > Exception in thread Thread-5: > > Traceback (most recent call last): > > ... > > File > > "/auto/n3k-qa/CODC/ianandan/pyATS2.7/lib/python2.7/site- > packages/pexpect/__init__.py", > > line 1466, in expect_list > > timeout, searchwindowsize) > > File > > "/auto/n3k-qa/CODC/ianandan/pyATS2.7/lib/python2.7/site- > packages/pexpect/__init__.py", > > line 1568, in expect_loop > > raise TIMEOUT(str(err) + '\n' + str(self)) > > TIMEOUT: Timeout exceeded. > > "Timeout" means that the "pexpect" partner did not respond sufficiently > fast. > > -- > https://mail.python.org/mailman/listinfo/python-list > From bintacomputers at gmail.com Sat Apr 1 06:20:59 2017 From: bintacomputers at gmail.com (Umar Yusuf) Date: Sat, 1 Apr 2017 03:20:59 -0700 (PDT) Subject: Read JSON file correctly Message-ID: <44f41152-e94b-4619-b6e4-d4a5a7d8eb63@googlegroups.com> How do I read this json file correctly? Details at: http://stackoverflow.com/questions/43152368/python-unicodedecodeerror-charmap-codec-cant-decode-byte-0x81-in-position From __peter__ at web.de Sat Apr 1 08:43:05 2017 From: __peter__ at web.de (Peter Otten) Date: Sat, 01 Apr 2017 14:43:05 +0200 Subject: Read JSON file correctly References: <44f41152-e94b-4619-b6e4-d4a5a7d8eb63@googlegroups.com> Message-ID: Umar Yusuf wrote: > How do I read this json file correctly? Details at: > > http://stackoverflow.com/questions/43152368/python-unicodedecodeerror-charmap-codec-cant-decode-byte-0x81-in-position Should you ever come back please take the time to post the "details" here. Also, provide the traceback as text rather than an image. Thank you. As the answer on stackoverflow says, the file is opened using the cp1252 encoding when it should be utf-8. While I don't know how to make that the default on Windows here's a workaround: import pandas with open("input.json", encoding="utf-8") as infile: df = pandas.read_json(infile) From specx at mynet.com Sat Apr 1 10:36:29 2017 From: specx at mynet.com (specx at mynet.com) Date: Sat, 1 Apr 2017 17:36:29 +0300 Subject: Tcp Socket Receive Message-ID: <5a7e89f5bff49f25b1b69d2c9278e98e@webmail5611.mynet.com> Hello, ? I have a tcp server coded with python and my packets include a 2 bytes header which is just the length of the following data. The problem is how can I be sure I received 2 bytes and not just one byte. In Qt, I use bytesAvailable function. However, here I just use sock.recv(2) but it can fetch less than 2 since the parameter is the maximum length. Do we have any method? ? Greetz From steve+python at pearwood.info Sat Apr 1 12:00:33 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 02 Apr 2017 02:00:33 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> Message-ID: <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> On Sat, 1 Apr 2017 12:17 pm, Rick Johnson wrote: > Most people just quietly change the filename and move on There are over a billion people in China, almost a billion more in India, about 140 million people in Russia, nearly 130 million people in Japan, 250 million in Indonesia, about 290 million native Arabic speakers, and even 9 million speakers of Hebrew. If you think that all these people, and hundreds of millions more, will just "quietly change the filename" to ASCII because you're too lazy, self-centred and arrogant to move on from 1963, then you truly are an example of the Ugly American. To say nothing of the hundreds of millions who use Latin character sets that ASCII cannot handle, including around 65 million British. Open your eyes, there is a whole world past the borders of your insular, close-minded little country. 95% of the world is not American, and there are millions of Americans who want to use non-ASCII characters in their file names, even non-Latin characters. You talk about a fraction of that 5%, the tiny minority who care only about ASCII, and describe them as "most people". That demonstrates the smallness of your world-view and the enormity of your ignorance. Wake up. The world is not Smallville USA, it never has been, and never will be. Either adapt, or get out of the way of those who have. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Apr 1 12:11:31 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 02 Apr 2017 02:11:31 +1000 Subject: Moderator please remove [Re: Better way to do this dict comprehesion] References: Message-ID: <58dfd134$0$1585$c3e8da3$5496439d@news.astraweb.com> Can one of the mailing list moderators please remove this person's post for including a link to an anti-Semitic video by David Duke? On Sat, 1 Apr 2017 07:13 pm, Robert L. wrote: Goyim were born [...] web.archive.org/web/20101020044210/http://www.jpost.com/JewishWorld[...] archive.org/download/DavidDuke_videos/[...] I've left in just enough of the original content so the moderator can see what I'm objecting to. Robert, if you're reading this, take your anti-semitism elsewhere, we're not interested. If you want to discuss Python, you are welcome here, but if you use it as a platform for bigotry, you aren't. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From marko at pacujo.net Sat Apr 1 12:43:34 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 01 Apr 2017 19:43:34 +0300 Subject: Text-mode apps (Was :Who are the "spacists"?) References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r31ct6x5.fsf@elektro.pacujo.net> Steve D'Aprano : > Open your eyes, there is a whole world past the borders of your insular, > close-minded little country. 95% of the world is not American, and there > are millions of Americans who want to use non-ASCII characters in their > file names, even non-Latin characters. It would be nice to be able to use a / in my file names. Funny enough, I'm allowed to use a zillion unprintable characters in my file names but no slashes allowed. Example: results-Q2/2017.json Marko From rosuav at gmail.com Sat Apr 1 12:55:06 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Apr 2017 02:55:06 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <87r31ct6x5.fsf@elektro.pacujo.net> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> Message-ID: On Sun, Apr 2, 2017 at 2:43 AM, Marko Rauhamaa wrote: > Steve D'Aprano : > >> Open your eyes, there is a whole world past the borders of your insular, >> close-minded little country. 95% of the world is not American, and there >> are millions of Americans who want to use non-ASCII characters in their >> file names, even non-Latin characters. > > It would be nice to be able to use a / in my file names. Funny enough, > I'm allowed to use a zillion unprintable characters in my file names but > no slashes allowed. > > Example: > > results-Q2/2017.json But how do you distinguish between that file, and a file called 2017.json in a subdirectory called results-Q2? ChrisA From saxri89 at gmail.com Sat Apr 1 12:59:37 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Sat, 1 Apr 2017 09:59:37 -0700 (PDT) Subject: django add images to models.py from views.py Message-ID: I create a simple Django authentication app and work fine. now I want to add a python script where to can do some simple image processing. my python script for processing work fine and I put in the views.py. my question is the new image created from the script how to can add back to image from mymodel ?first must be save temporarily ? can I do this ? sorry I am new. class MyModel(models.Model): user = models.ForeignKey(to=settings.AUTH_USER_MODEL) image = models.ImageField(upload_to=generate_path(self.user)) forms.py @login_required class CronForm(forms.Form): days = forms.ModelChoiceField(queryset=MyModel.objects.all) views.py @login_required def show_something(request,user_id): user = UserProfile.objects.get(user__id=user_id) form = CronForm() if request.method == "POST": form = CronForm(request.POST) if form.is_valid: # do image processing # do image processing # and finaly ta ke new image from the image processing like newim='newim.tif' return HttpResponseRedirect(...) errors = form.errors or None return render(request, 'path/to/template.html',{ 'form': form, 'errors': errors, }) From marko at pacujo.net Sat Apr 1 13:08:44 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 01 Apr 2017 20:08:44 +0300 Subject: Text-mode apps (Was :Who are the "spacists"?) References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> Message-ID: <87h928t5r7.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Apr 2, 2017 at 2:43 AM, Marko Rauhamaa wrote: >> It would be nice to be able to use a / in my file names. Funny >> enough, I'm allowed to use a zillion unprintable characters in my >> file names but no slashes allowed. >> >> Example: >> >> results-Q2/2017.json > > But how do you distinguish between that file, and a file called > 2017.json in a subdirectory called results-Q2? When there's a will, there's a way: * Show a folder icon for a directory and a file icon for a file. * Do it URI style: path/to/results-Q2%2F2017.json * Do it C style: path/to/results-Q2\/2017.json * Do it Python style: [ "path", "to", "results-Q2/2017.json" ] * Do it Lisp style: (path to results-Q2/2017.json) I'm sure you can come up with several other workable solutions. Marko From skip.montanaro at gmail.com Sat Apr 1 13:09:06 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 1 Apr 2017 12:09:06 -0500 Subject: Moderator please remove [Re: Better way to do this dict comprehesion] In-Reply-To: <58dfd134$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <58dfd134$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: Passed along to postmaster at python.org, who generally takes care of this sort of thing. Skip On Apr 1, 2017 11:19 AM, "Steve D'Aprano" wrote: > Can one of the mailing list moderators please remove this person's post for > including a link to an anti-Semitic video by David Duke? > > > > On Sat, 1 Apr 2017 07:13 pm, Robert L. wrote: > > Goyim were born [...] > web.archive.org/web/20101020044210/http://www.jpost.com/JewishWorld[...] > archive.org/download/DavidDuke_videos/[...] > > I've left in just enough of the original content so the moderator can see > what I'm objecting to. > > Robert, if you're reading this, take your anti-semitism elsewhere, we're > not > interested. If you want to discuss Python, you are welcome here, but if you > use it as a platform for bigotry, you aren't. > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list > From steve+python at pearwood.info Sat Apr 1 13:09:44 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 02 Apr 2017 03:09:44 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> Message-ID: <58dfdeda$0$1611$c3e8da3$5496439d@news.astraweb.com> On Sun, 2 Apr 2017 02:43 am, Marko Rauhamaa wrote: > Steve D'Aprano : > >> Open your eyes, there is a whole world past the borders of your insular, >> close-minded little country. 95% of the world is not American, and there >> are millions of Americans who want to use non-ASCII characters in their >> file names, even non-Latin characters. > > It would be nice to be able to use a / in my file names. Yes it would. Obviously the solution is to use colons as the path separator, like in Classic Mac OS (and a few others). And then, as sure as water is wet, you'll complain that you want to use : in your file names. *Whatever* record separator you choose to use, whether it is slash / or backslash \ or colon : or Ctrl-^ RS or U+113A HANGUL CHOSEONG SIOS-PHIEUPH, you can't *also* use it as a non-record separator. I suppose one might invent an escaping scheme, so that you can escape the record separator, and another escaping scheme so you can escape the escape and prevent it from escaping the record separator. That would work. But it's complex and error prone and people will get it wrong, and the people who designed the Unix file system didn't think the extra complexity was worth the benefit. If you disagree, feel free to design your own file system, and if people prefer yours, they'll use it. Its not just Unix. As far as I know, *no* file system, from any operating system, has bothered to introduce an escape character so that file names can include the path record separator. Not Unix, not Windows, not OS X, not classic Mac OS, not Solaris. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From eryksun at gmail.com Sat Apr 1 13:14:14 2017 From: eryksun at gmail.com (eryk sun) Date: Sat, 1 Apr 2017 17:14:14 +0000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> Message-ID: On Sat, Apr 1, 2017 at 4:55 PM, Chris Angelico wrote: > On Sun, Apr 2, 2017 at 2:43 AM, Marko Rauhamaa wrote: >> Steve D'Aprano : >> >>> Open your eyes, there is a whole world past the borders of your insular, >>> close-minded little country. 95% of the world is not American, and there >>> are millions of Americans who want to use non-ASCII characters in their >>> file names, even non-Latin characters. >> >> It would be nice to be able to use a / in my file names. Funny enough, >> I'm allowed to use a zillion unprintable characters in my file names but >> no slashes allowed. >> >> Example: >> >> results-Q2/2017.json > > But how do you distinguish between that file, and a file called > 2017.json in a subdirectory called results-Q2? You could use a PUA code or the replacement character (U+FFFD) as an escape code. I don't think this is possible in Linux or Unix in general because I think POSIX mandates that '/' is reserved. It *may* be possible in Windows if you're creating a custom file system and can get away with requiring users to use \\?\ paths in this case. The system parses the path up to the volume device, so that part cannot use backslash. Beyond that, path parsing is up to file-system device that manages the volume. If the volume is mounted in the object namespace, then the whole path, including the device name, can use forward slash, since that's just a normal name character to the object manager. For example, you can create a device named "My/Device". From alain at universite-de-strasbourg.fr.invalid Sat Apr 1 13:18:55 2017 From: alain at universite-de-strasbourg.fr.invalid (Alain Ketterlin) Date: Sat, 01 Apr 2017 19:18:55 +0200 Subject: Text-mode apps (Was :Who are the "spacists"?) References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> Message-ID: <87fuhst5a8.fsf@universite-de-strasbourg.fr.invalid> Marko Rauhamaa writes: > It would be nice to be able to use a / in my file names. Funny enough, > I'm allowed to use a zillion unprintable characters in my file names but > no slashes allowed. > > Example: > > results-Q2/2017.json Use U+2215 (DIVISION SLASH). I have tried this once. "Next time you're fired/dead" (and less pleasant variants) was the only comment I got from people I shared files with. -- Alain. From steve+python at pearwood.info Sat Apr 1 13:38:57 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 02 Apr 2017 03:38:57 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> <87h928t5r7.fsf@elektro.pacujo.net> Message-ID: <58dfe5b3$0$1616$c3e8da3$5496439d@news.astraweb.com> On Sun, 2 Apr 2017 03:08 am, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sun, Apr 2, 2017 at 2:43 AM, Marko Rauhamaa wrote: >>> It would be nice to be able to use a / in my file names. Funny >>> enough, I'm allowed to use a zillion unprintable characters in my >>> file names but no slashes allowed. >>> >>> Example: >>> >>> results-Q2/2017.json >> >> But how do you distinguish between that file, and a file called >> 2017.json in a subdirectory called results-Q2? > > When there's a will, there's a way: > > * Show a folder icon for a directory and a file icon for a file. I'm blind, and need a text reader. How do I see your folder icon? Or more importantly, how do I *input* your folder icon? Or I'm using a text-only interface, because I'm SSH'ed into the computer over a 2400 baud modem going through a noisy line. > * Do it URI style: path/to/results-Q2%2F2017.json Wait, I see no slash in the file name. How am I supposed to tell my mum to open the file "results-Q2/2017.json" when it doesn't display the slash? Do I have to memorise the hex code for / in some obscure system? How do I distinguish between results-Q2%2F2017.json and results-Q2/2017.json if the later displays like the former? > * Do it C style: path/to/results-Q2\/2017.json That can't be right. The file name is supposed to be results-Q2/2017.json, not results-Q2V2017.json. You're deliberately trying to make things hard for my dear ole mum, aren't you? You know she doesn't wear her glasses when reading file names. > * Do it Python style: [ "path", "to", "results-Q2/2017.json" ] You got the path wrong. The directory portion is a single directory called literally: ["path", "to", (ending with a space, and don't ask me who named this directory, but they are legal characters so you have to expect them to be used...) and the filename portion is actually "results-Q2/2017.json" ] so you actually have to write: ['["path", "to", ', '"results-Q2/2017.json" ]'] My dear ole mum just had a stroke trying to understand that, I hope you're happy now. You brute. > * Do it Lisp style: (path to results-Q2/2017.json) > > I'm sure you can come up with several other workable solutions. You left the prefix "un" out of that adjective. But all joking aside, of course you can create a complex, fragile, hard to use system for escaping the record separator character in file names. Do you imagine that you're the first person who thought of that? But what does it buy you? *One more character*. Or, for Windows, I suppose a dozen or so more characters: https://support.office.com/en-us/article/Invalid-characters-in-file-or-folder-names-or-invalid-file-types-in-OneDrive-for-Business-64883A5D-228E-48F5-B3D2-EB39E07630FA Either way, you're creating a world of pain for your users, for buggar all extra benefit. But if I could borrow Guido's time machine, I'd go back and convince the file system people to use ^ as the record separator, rather than slash or backslash or colon. Caret is *much* less likely to be useful in file names than forward slash (often used for dates) or colon, or even backslash. ^home^steve^document.txt I'm sure I'd get used to it in a few years... Next: convince keyboard manufacturers to move the caret from SHIFT-6 to a plain, unshifted key. Buggared if I'm going to hit shift every time I want to use an absolute path... -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Apr 1 13:43:03 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 02 Apr 2017 03:43:03 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> <87fuhst5a8.fsf@universite-de-strasbourg.fr.invalid> Message-ID: <58dfe6a9$0$1616$c3e8da3$5496439d@news.astraweb.com> On Sun, 2 Apr 2017 03:18 am, Alain Ketterlin wrote: > Marko Rauhamaa writes: > >> It would be nice to be able to use a / in my file names. Funny enough, >> I'm allowed to use a zillion unprintable characters in my file names but >> no slashes allowed. >> >> Example: >> >> results-Q2/2017.json > > Use U+2215 (DIVISION SLASH). That is *deliciously* evil. I like it. > I have tried this once. "Next time you're fired/dead" (and less pleasant > variants) was the only comment I got from people I shared files with. :-) ?home?steve?document I'm sure you deserved everything they did to you :-) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From python.list at tim.thechases.com Sat Apr 1 13:53:02 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 1 Apr 2017 12:53:02 -0500 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58dfdeda$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> <58dfdeda$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20170401125302.4d587feb@bigbox.christie.dr> On 2017-04-02 03:09, Steve D'Aprano wrote: > *Whatever* record separator you choose to use, whether it is > slash / or backslash \ or colon : or Ctrl-^ RS or U+113A HANGUL > CHOSEONG SIOS-PHIEUPH, you can't *also* use it as a non-record > separator. Well, one could use 0x1C (FS=File Separator) which at least has the semantic meaning and would be far less likely to be desired in file-names. That said, I'm not sure I want to try and enter 0x1C every time I intend to compose a complex path. But that's an interface problem, right? ;-) -tkc From python.list at tim.thechases.com Sat Apr 1 13:57:18 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 1 Apr 2017 12:57:18 -0500 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <87r31ct6x5.fsf@elektro.pacujo.net> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> Message-ID: <20170401125718.05eabdab@bigbox.christie.dr> On 2017-04-01 19:43, Marko Rauhamaa wrote: > It would be nice to be able to use a / in my file names. Funny > enough, I'm allowed to use a zillion unprintable characters in my > file names but no slashes allowed. > > Example: > > results-Q2/2017.json You can: $ touch $(/usr/bin/printf "results-Q2\u22152017.") Now, whether one would find it *prudent*, that's another matter. ;-) -tkc From eryksun at gmail.com Sat Apr 1 14:45:03 2017 From: eryksun at gmail.com (eryk sun) Date: Sat, 1 Apr 2017 18:45:03 +0000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58dfe5b3$0$1616$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> <87h928t5r7.fsf@elektro.pacujo.net> <58dfe5b3$0$1616$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 1, 2017 at 5:38 PM, Steve D'Aprano wrote: > Or, for Windows, I suppose a dozen or so more characters: > > https://support.office.com/en-us/article/Invalid-characters-in-file-or-folder-names-or-invalid- > file-types-in-OneDrive-for-Business-64883A5D-228E-48F5-B3D2-EB39E07630FA It's more than a dozen reserved characters. If we're strictly following the file-system runtime library conventions, then all ASCII control characters (0-31) are reserved as well as pipe; the path separators slash, backslash, and colon (named streams); and the wildcard characters asterisk, question mark, less than, greater than, and double quote. Except for backslash, which is reserved by the object manager, these reservations are imposed by the FsRtl, and in theory I think a custom file system *could* ignore this. This would require using the \\?\ prefix and, in some cases, it would also require applications to use the native NT API in order to avoid DOS conventions. It would also need some private escape sequence to tell the file system, for example, that an asterisk in a directory listing filter isn't supposed to be a wildcard. These constraints would be too cumbersome, confusing, and unworkable in general, so the system's use would probably need to be restricted to a specific set of applications or an NT subsystem that can hide the implementation details. For a real-world example, the Linux subsystem in Windows 10 (WSL) stores the POSIX namespace files that it creates using regular files in a hidden folder in the user's profile. It has to escape characters that are reserved: $ touch 'test*?<>":\|.txt' C:\>dir /b %localappdata%\lxss\home\%username%\test* test#002A#003F#003C#003E#0022#003A#005C#007C.txt From python at mrabarnett.plus.com Sat Apr 1 14:54:32 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 1 Apr 2017 19:54:32 +0100 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <87r31ct6x5.fsf@elektro.pacujo.net> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> Message-ID: On 2017-04-01 17:43, Marko Rauhamaa wrote: > Steve D'Aprano : > >> Open your eyes, there is a whole world past the borders of your insular, >> close-minded little country. 95% of the world is not American, and there >> are millions of Americans who want to use non-ASCII characters in their >> file names, even non-Latin characters. > > It would be nice to be able to use a / in my file names. Funny enough, > I'm allowed to use a zillion unprintable characters in my file names but > no slashes allowed. > > Example: > > results-Q2/2017.json > > Try this instead: results-Q2?2017.json :-) (It's U+2215 "DIVISION SLASH"). From nimbiotics at gmail.com Sat Apr 1 15:15:41 2017 From: nimbiotics at gmail.com (Mario R. Osorio) Date: Sat, 1 Apr 2017 12:15:41 -0700 (PDT) Subject: Spam user In-Reply-To: References: <058a9744-44bf-4e6b-ae1d-28e1e348e60b@googlegroups.com> Message-ID: I'm not in the business of starting an argument about best/worse newsreader, Ammammata, but could you please recommend a few? TIA From mikhailwas at gmail.com Sat Apr 1 16:07:48 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sat, 1 Apr 2017 22:07:48 +0200 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <04f771fe-1c40-48e9-85d7-3b743108c5eb@googlegroups.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dd12d2$0$1611$c3e8da3$5496439d@news.astraweb.com> <04f771fe-1c40-48e9-85d7-3b743108c5eb@googlegroups.com> Message-ID: On 1 April 2017 at 06:38, Rick Johnson wrote: > On Thursday, March 30, 2017 at 9:14:54 AM UTC-5, Steve D'Aprano wrote: >> - and making band names look ???? and annoy old fuddy- >> duddies. > > So now we've even included graffiti artists in our little > "inclusivity project". My, my... we are so _not_ mean! Lol :) First we'll wait for Unicode version with table-drawing character for all possible corner styles and line weights, and monospaced legible Arabic for Chris' MUDs. From No_spamming at noWhere_7073.org Sat Apr 1 16:22:59 2017 From: No_spamming at noWhere_7073.org (Robert L.) Date: Sat, 1 Apr 2017 20:22:59 +0000 (UTC) Subject: How to flatten only one sub list of list of lists References: <2c513652-c365-4a92-b204-d986fa41b7a0@googlegroups.com> Message-ID: On 3/1/2017, Sayth Renshaw wrote: > How can I flatten just a specific sublist of each list in a list of lists? > > So if I had this data > > > [ ['46295', 'Montauk', '3', '60', '85', ['19', '5', '1', '0 $277790.00']], > ['46295', 'Dark Eyes', '5', '59', '83', ['6', '4', '1', '0 $105625.00']], > ['46295', 'Machinegun Jubs', '6', '53', '77', ['6', '2', '1', '1 $71685.00']], > ['46295', 'Zara Bay', '1', '53', '77', ['12', '2', '3', '3 $112645.00']]] > > > How can I make it be > > > [ ['46295', 'Montauk', '3', '60', '85', '19', '5', '1', '0 $277790.00'], > ['46295', 'Dark Eyes', '5', '59', '83', '6', '4', '1', '0 $105625.00'], > ['46295', 'Machinegun Jubs', '6', '53', '77', '6', '2', '1', '1 $71685.00'], > ['46295', 'Zara Bay', '1', '53', '77', '12', '2', '3', '3 $112645.00']] > > Been looking around but most solutions just entirely flatten everything. > This was popular on SO but yeah it flattens everything I want to be more selective > > def flatten(lst): > for elem in lst: > if type(elem) in (tuple, list): > for i in flatten(elem): > yield i > else: > yield elem > [['46295', 'Montauk', '3', '60', '85', ['19', '5', '1', '0 $277790.00']], ['46295', 'Dark Eyes', '5', '59', '83', ['6', '4', '1', '0 $105625.00']], ['46295', 'Machinegun Jubs', '6', '53', '77', ['6', '2', '1', '1 $71685.00']], ['46295', 'Zara Bay', '1', '53', '77', ['12', '2', '3', '3 $112645.00']]]. map( &:flatten ) ===> [["46295", "Montauk", "3", "60", "85", "19", "5", "1", "0 $277790.00"], ["46295", "Dark Eyes", "5", "59", "83", "6", "4", "1", "0 $105625.00"], ["46295", "Machinegun Jubs", "6", "53", "77", "6", "2", "1", "1 $71685.00"], ["46295", "Zara Bay", "1", "53", "77", "12", "2", "3", "3 $112645.00"]] -- [T]he driving force behind mass immigration is the organized Jewish community, which feels its interests are best served by a "diverse" society divided between antagonistic groups that can be easily dominated by their cohesive and privileged tribe. http://www.renseradioarchives.com/dduke/ From marko at pacujo.net Sat Apr 1 16:47:47 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 01 Apr 2017 23:47:47 +0300 Subject: Text-mode apps (Was :Who are the "spacists"?) References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> <87h928t5r7.fsf@elektro.pacujo.net> <58dfe5b3$0$1616$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87a87zua6k.fsf@elektro.pacujo.net> Steve D'Aprano : > But if I could borrow Guido's time machine, I'd go back and convince > the file system people to use ^ as the record separator, rather than > slash or backslash or colon. Caret is *much* less likely to be useful > in file names than forward slash (often used for dates) or colon, or > even backslash. You are stuck with the axiom that pathname and its representation are one and the same thing. URI's make the distinction clear. Say you wanted to express a resource p??ty?/2 as part of a URI. URIs are to contain a subset of ASCII only so an encoding scheme has been devised. That resource is expressed like this: p%c3%a4%c3%a4ty%c3%b6%2f2 A far more convenient escaping scheme could have been devised for pathnames. Marko From rosuav at gmail.com Sat Apr 1 16:57:15 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Apr 2017 06:57:15 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dd12d2$0$1611$c3e8da3$5496439d@news.astraweb.com> <04f771fe-1c40-48e9-85d7-3b743108c5eb@googlegroups.com> Message-ID: On Sun, Apr 2, 2017 at 6:07 AM, Mikhail V wrote: > On 1 April 2017 at 06:38, Rick Johnson wrote: >> On Thursday, March 30, 2017 at 9:14:54 AM UTC-5, Steve D'Aprano wrote: > >>> - and making band names look ???? and annoy old fuddy- >>> duddies. >> >> So now we've even included graffiti artists in our little >> "inclusivity project". My, my... we are so _not_ mean! > > Lol :) First we'll wait for Unicode version with > table-drawing character for all possible corner styles > and line weights, and monospaced legible Arabic for > Chris' MUDs. Not sure what you mean by monospaced, given that Arabic is RTL anyway. I mean, when your code is capable of handling all the oddities of mixed LTR and RTL text, variable-width characters are almost trivially easy to handle. (And yes, I do indeed handle them just fine.) ChrisA From rosuav at gmail.com Sat Apr 1 17:00:49 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Apr 2017 07:00:49 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <87a87zua6k.fsf@elektro.pacujo.net> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> <87h928t5r7.fsf@elektro.pacujo.net> <58dfe5b3$0$1616$c3e8da3$5496439d@news.astraweb.com> <87a87zua6k.fsf@elektro.pacujo.net> Message-ID: On Sun, Apr 2, 2017 at 6:47 AM, Marko Rauhamaa wrote: > You are stuck with the axiom that pathname and its representation are > one and the same thing. > > URI's make the distinction clear. Say you wanted to express a resource > > p??ty?/2 > > as part of a URI. URIs are to contain a subset of ASCII only so an > encoding scheme has been devised. That resource is expressed like this: > > p%c3%a4%c3%a4ty%c3%b6%2f2 > > A far more convenient escaping scheme could have been devised for > pathnames. Definitely. We should treat file names like domain names. "B?cher.ch" gets represented internally as "xn--bcher-kva.ch". That would solve all the problems, and there's no way that it could create more. ChrisA From marko at pacujo.net Sat Apr 1 17:06:44 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 02 Apr 2017 00:06:44 +0300 Subject: Text-mode apps (Was :Who are the "spacists"?) References: <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> <87h928t5r7.fsf@elektro.pacujo.net> <58dfe5b3$0$1616$c3e8da3$5496439d@news.astraweb.com> <87a87zua6k.fsf@elektro.pacujo.net> Message-ID: <871stbu9az.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Apr 2, 2017 at 6:47 AM, Marko Rauhamaa wrote: >> A far more convenient escaping scheme could have been devised for >> pathnames. > > Definitely. We should treat file names like domain names. "B?cher.ch" > gets represented internally as "xn--bcher-kva.ch". That would solve > all the problems, and there's no way that it could create more. Note that Python can express any text string, including one with a quote character. I don't know if Python's escaping scheme is creating more problems than it is solving. Marko From No_spamming at noWhere_7073.org Sat Apr 1 17:12:34 2017 From: No_spamming at noWhere_7073.org (Robert L.) Date: Sat, 1 Apr 2017 21:12:34 +0000 (UTC) Subject: sorting list python References: Message-ID: On 1/18/2017, Peter Otten wrote: > with partite.txt looking like this > > > 74' Kessie' > > 90' + 4' D'alessandro > > 51' Mchedlidze > > 54' Banega > > 56' Icardi > > 65' Icardi > > 14' Sau > > > Assuming you want to perform a numerical sort on the numbers before the ' > you can just apply sorted > > with open(...) as f: > print("".join(sorted(f)) > > as long as all number strings have the same length. > > If that's not the case python's sorted() has decorate-sort-undecorate > capabilities built in -- no need to do it manually: > > with open("partite.txt") as f: > by_number = sorted(f, key=lambda line: int(line.partition("'")[0])) > print("".join(by_number)) puts IO.readlines('foo.txt').sort_by( &:to_i ) 14' Sau 51' Mchedlidze 54' Banega 56' Icardi 65' Icardi 74' Kessie' 90' + 4' D'alessandro ==>nil -- Jews totally run Hollywood.... But I don't care if Americans think we're running the news media, Hollywood, Wall Street, or the government. I just care that we get to keep running them. --- Joel Stein articles.latimes.com/2008/dec/19/opinion/oe-stein19 archive.org/download/DavidDukeTv/DoJewsControlTheMediaTheLaTimesSaysYes.flv From rosuav at gmail.com Sat Apr 1 17:22:21 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Apr 2017 07:22:21 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <871stbu9az.fsf@elektro.pacujo.net> References: <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> <87h928t5r7.fsf@elektro.pacujo.net> <58dfe5b3$0$1616$c3e8da3$5496439d@news.astraweb.com> <87a87zua6k.fsf@elektro.pacujo.net> <871stbu9az.fsf@elektro.pacujo.net> Message-ID: On Sun, Apr 2, 2017 at 7:06 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sun, Apr 2, 2017 at 6:47 AM, Marko Rauhamaa wrote: >>> A far more convenient escaping scheme could have been devised for >>> pathnames. >> >> Definitely. We should treat file names like domain names. "B?cher.ch" >> gets represented internally as "xn--bcher-kva.ch". That would solve >> all the problems, and there's no way that it could create more. > > Note that Python can express any text string, including one with a quote > character. I don't know if Python's escaping scheme is creating more > problems than it is solving. Yes it can; however, there is no way within Python to have a string that can represent two strings, which is what directory separators do. Ultimately, all you really get by referencing Python's string literals is an escaping system: "\\" for a backslash, and then you can use "\?" for various special symbols to change their meaning. ChrisA From marko at pacujo.net Sat Apr 1 17:35:48 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 02 Apr 2017 00:35:48 +0300 Subject: Text-mode apps (Was :Who are the "spacists"?) References: <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> <87h928t5r7.fsf@elektro.pacujo.net> <58dfe5b3$0$1616$c3e8da3$5496439d@news.astraweb.com> <87a87zua6k.fsf@elektro.pacujo.net> <871stbu9az.fsf@elektro.pacujo.net> Message-ID: <87wpb3ste3.fsf@elektro.pacujo.net> Chris Angelico : > there is no way within Python to have a string that can represent two > strings, which is what directory separators do. Really? Try: >>> repr(("a", "b")) "('a', 'b')" There! A string that represents two strings. Note, however, that Python programs generally don't restrict themselves to expressing objects via strings. There are even objects with no string representation at all. A pathname is a list of strings. Python could naturally express it as just that: [ "usr", "bin", "python3" ] I'm not really proposing any change to the status quo. What's done is done. However, I do think it is awkward to ban one particular, very common character while allowing all the rest. Marko From mikhailwas at gmail.com Sat Apr 1 17:40:33 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sat, 1 Apr 2017 23:40:33 +0200 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dd12d2$0$1611$c3e8da3$5496439d@news.astraweb.com> <04f771fe-1c40-48e9-85d7-3b743108c5eb@googlegroups.com> Message-ID: On 1 April 2017 at 22:57, Chris Angelico wrote: > On Sun, Apr 2, 2017 at 6:07 AM, Mikhail V wrote: >> On 1 April 2017 at 06:38, Rick Johnson wrote: >>> On Thursday, March 30, 2017 at 9:14:54 AM UTC-5, Steve D'Aprano wrote: >> >>>> - and making band names look ???? and annoy old fuddy- >>>> duddies. >>> >>> So now we've even included graffiti artists in our little >>> "inclusivity project". My, my... we are so _not_ mean! >> >> Lol :) First we'll wait for Unicode version with >> table-drawing character for all possible corner styles >> and line weights, and monospaced legible Arabic for >> Chris' MUDs. > > Not sure what you mean by monospaced, given that Arabic is RTL anyway. > I mean, when your code is capable of handling all the oddities of > mixed LTR and RTL text, variable-width characters are almost trivially > easy to handle. (And yes, I do indeed handle them just fine.) Monospaced text = each glyph appears in a constant-width box (the whole thread is about this). Nothing to do with writing direction. Both Windows and Linux default console renders monospaced text only. Unless you use something else, which can render both monospaced and proportional text, Arabic is not adequatly presentable there. Eg alef's width is ca 0,2 sheen's width. So one gets piles of poo instead of normal Arabic text in console. From rosuav at gmail.com Sat Apr 1 17:45:43 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Apr 2017 07:45:43 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <87wpb3ste3.fsf@elektro.pacujo.net> References: <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> <87h928t5r7.fsf@elektro.pacujo.net> <58dfe5b3$0$1616$c3e8da3$5496439d@news.astraweb.com> <87a87zua6k.fsf@elektro.pacujo.net> <871stbu9az.fsf@elektro.pacujo.net> <87wpb3ste3.fsf@elektro.pacujo.net> Message-ID: On Sun, Apr 2, 2017 at 7:35 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> there is no way within Python to have a string that can represent two >> strings, which is what directory separators do. > > Really? Try: > > >>> repr(("a", "b")) > "('a', 'b')" > > There! A string that represents two strings. In the arbitrary sense that you can encode anything in any way and then treat it as a string, yes, of course you can devise a system that lets you represent two strings. But you were talking about the nature of the string literal in Python, and what you have here is not a string literal - it's a tuple. You do NOT want to allow file names to be arbitrary code, nor even "something acceptable by ast.literal_eval"; they should be simple strings. Otherwise, there's no point even having them - just use file reference numbers (eg inodes) instead, and force people to select them from a GUI menu every time they want to work with a file. ChrisA From rosuav at gmail.com Sat Apr 1 17:54:21 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Apr 2017 07:54:21 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <871stbu9az.fsf@elektro.pacujo.net> Message-ID: On Sun, Apr 2, 2017 at 7:49 AM, Stefan Ram wrote: > Chris Angelico writes: >>Yes it can; however, there is no way within Python to have a string >>that can represent two strings, which is what directory separators do. > > To represent two strings, /internally/ ("within Python"), > a straightforward way would be a list of two strings. > > If one wants to represent this list /as a single string/, > one can use any serialization of this list, for example, > using JSON. > > (I have not read the whole thread, so I might have missed > some context here. I am just responding to what is quoted > above.) The context is a file name, in which you need something that a user can input which is capable of representing path components that contain arbitrary characters. Currently, a Unix path always interprets a slash as a directory separator, so there's no way to have a slash in a file or directory name. If you want to have *every* component capable of containing *any* character, you either need a string to be able to represent two strings, or you need some sort of escaping mechanism. ChrisA From mikhailwas at gmail.com Sat Apr 1 18:16:24 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sun, 2 Apr 2017 00:16:24 +0200 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1 April 2017 at 18:00, Steve D'Aprano wrote: > On Sat, 1 Apr 2017 12:17 pm, Rick Johnson wrote: > >> Most people just quietly change the filename and move on > > > There are over a billion people in China, almost a billion more in India, > about 140 million people in Russia, nearly 130 million people in Japan, 250 > million in Indonesia, about 290 million native Arabic speakers, and even 9 > million speakers of Hebrew. > Well, this is obvious, different characters in different parts of the world, ministries of education, etc. But will the sky fall if people name files using latin letters? Look, I am Russian, nothing to do with Ugly American :) At my work I quietly change all filenames to translit. This is for _simplification_ of all automation processes and some other purposes. It makes my work with digital materials seamless and as a positive side-effect makes it easier for external service-providers to avoid different surprises. So it is _not_ in the first place because some software cope badly with unicode, but because it is natural and logical to use same glyphs for any language (but strangely, many have difficulties with understanding this, well.. the time has not come yet, let's wait few hundreds years more) BTW, why do you think people in China do not want to use latin letters? I suppose there are a lot of haters for those bizarre systems among natives and indeed, many people stay illiterate simply because it is too hard to learn and many have problems reading those. Let's go back in Europe, e.g. in Germany there were many movements against those silly spelling rules and many younger people ignore those in informal writing, e.g. they write 'were' intead of 'w?re', 'fur' instead of 'f?r' and do not capitalise nouns, and they are damn right about it. So this all is just your personal view on the problem. This reminds me of one anecdote: A Pole and a Russian talk about languages: Russian: our language is better, we have more letters in our alphabet! Pole: no, ours is better - we have more grammatical cases! Also I never install any language packages with software and use only english versions, anyway most tutorials will be in english and one can't force developers to make turorials with screenshots for all languages. And english UI looks for me always better and more intuitive. > One of the excellent ways the PUAs have been used is by > medieval researchers. They have been collecting the various > special characters used by medieval scribes, and by private > agreement putting them into a PUA area where special > purpose software can use it. That way they can determine > which of the thousands of special characters used by > medieval monks are actually significant enough to graduate > to genuine Unicode characters, and which are best handled > some other way. Now I don't see who wrote this ^ initially. Suppose Steve? So IMO this is not an 'exellent' way. If I want to make e.g. analysis of Voynich manuscript, I'll do following: extract/draw glyphs and encode them, say with integers 0..26. And all rendering and analysis will be performed on those integers. For multiple-alphabet rendering I will use some custom text format, e.g. with tags ... , and for latin ... and etc. Simple and effective. Mikhail From rosuav at gmail.com Sat Apr 1 18:22:23 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Apr 2017 08:22:23 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 2, 2017 at 8:16 AM, Mikhail V wrote: > For multiple-alphabet rendering I will use some > custom text format, e.g. with tags > ... , and for latin > ... and etc. > > Simple and effective. For multi-alphabet rendering, I would rather use an even simpler format: Remove the tags and use a consistent encoding. Oh right, that's what Unicode is. Have you ever actually *used* a system of tagged encodings? It is an abomination. ChrisA From cs at zip.com.au Sat Apr 1 18:28:42 2017 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 2 Apr 2017 08:28:42 +1000 Subject: python installs on OSX missing dbm.gnu Message-ID: <20170401222842.GA25369@cskk.homeip.net> I've got three different installs of Python 3.6.1 on my El Capitan Mac: MacPorts, homebrew and the .pkg from python.org. For reasons I haven't divined, the homebrew and MacPorts ones abort with malloc related errors. So I went to install the distro from python.org, which happily does not. However, both the homebrew and python.org installs lack "dbm.gnu", upon which my main project relies. Well, fair enough. However, I do not know how to make it available to either. MacPorts has a py36-gdbm package which binds the gdbm library to Python. homebrew seems not to have such a thing and of course the python.org install is standalone. PyPI seems not forthcoming either. What should I be doing about this? Cheers, Cameron Simpson From cs at zip.com.au Sat Apr 1 18:32:57 2017 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 2 Apr 2017 08:32:57 +1000 Subject: VirtualEnvs (venv) and Powershell In-Reply-To: References: Message-ID: <20170401223257.GA51091@cskk.homeip.net> On 31Mar2017 19:03, Carl Caulkett wrote: >I've just started to investigate VirtualEnvironments as a means of >preventing my 3rd party code becoming chaotic. I've discovered that >venv's can be managed quite effectively using Powershell. When >Activate.ps1 is run, the PowerShell changes to indicate that the venv >is active which is nice. However despite the official documention, >there doesn't seem to be a corresponding Deactivate.ps1. There is a >deactivate.bat but that doesn't appear to switch the paths back to >their pre-env state. > What I would really like is a Git-Bash based alternative to >Powershell to manage my Virtual Environments. Has anyone dicovered >tools or techniques to achieve this? Well, in a UNIX environment the natural things is simply to start a shell using the target venv. Thus: sh -c '. /path/to/the/venv/bin/activate; exec $SHELL' or even simpler: ( . /path/to/the/venv/bin/activate; exec $SHELL ) That would get you a prompt using the virtualenv by default. To reset to the old settings, exit that subshell. Maybe I misunderstand your needs. Cheers, Cameron Simpson From rantingrickjohnson at gmail.com Sat Apr 1 19:11:02 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 1 Apr 2017 16:11:02 -0700 (PDT) Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, April 1, 2017 at 11:01:03 AM UTC-5, Steve D'Aprano wrote: > On Sat, 1 Apr 2017 12:17 pm, Rick Johnson wrote: > > > Most people just quietly change the filename and move on > > There are over a billion people in China, almost a billion > more in India, about 140 million people in Russia, nearly > 130 million people in Japan, 250 million in Indonesia, > about 290 million native Arabic speakers, and even 9 > million speakers of Hebrew. If you think that all these > people, and hundreds of millions more, will just "quietly > change the filename" The majority of the populations you reference are illiterate. Have you ever seen the endless slums in India? > To say nothing of the hundreds of millions who use Latin > character sets that ASCII cannot handle, including around > 65 million British. Open your eyes, there is a whole world > past the borders of your insular, close-minded little > country. Then create whatever encodings you so desire and then STFU about it. Why are you whining to me? Contrary to your beliefs, America does not exist to satisfy the whims of non- americans. If you are British, then America does not exist for you. Go request an audience from your beloved Queen Mother; and if she's too busy, perhaps Mother Mary will entertain you; and if she's too busy, there is always Sir Paul McCartney to sing you a lullaby. And since he's not toting around that one legged girl anymore, he probably has quite a bit of free time, even for someone as unimportant as you. When i find myself in times of trouble, Mother ASK-EEE comes to me, Speaking codes of pragmatism, let it be And when the broken hearted people, Living in the world agree, There will be an answer -> "ASS-KEE" For though they may be parted There is still a chance that they will see There will be an answer -> "ASK__EEE" ASS-KEE, ASS-KEE, Oh ASS-KEE, ASS-KEE There will be an answer -> "ASS-KEE" Hey, Steve! Don't be so sad, We'll take a bad encoding, And make it bettuh! Because we're 'mericans. And failure is not an option. > 95% of the world is not American, And yet America continues to be emulated by 100% of the world. A small country that has hardly existed for a few hundred years, has not only created a social transformation that has reverberanted around the world, we continue to define popular culture. If you hate us so much, then why do you try so much to emulate us? > and there are millions of Americans who want to use non- > ASCII characters in their file names, even non-Latin > characters. Great. More reason for you to create your beloved encoding so you can become their hero. Perhaps you can convince a remote island tribe to worship you as god. > You talk about a fraction of that 5%, the tiny minority who > care only about ASCII, and describe them as "most people". Most people don't even know what Unicode and ASCII are, and even if you had the time to educate them, they could care less. I'm talking about technical folk, not idiots off the street; i'm talking about people who write software and advanced users of technical softwares; not some drooling twit who downloaded the latest version of angry birds from the apple store. > That demonstrates the smallness of your world-view and the > enormity of your ignorance. Wake up. The world is not > Smallville USA, it never has been, and never will be. > Either adapt, or get out of the way of those who have. I am more than willing to provide whatever features the _majority_ of my clients request, but what i am not willing to do, is expend my labor capital on your pet social justice project that caters to large concentrations of illiterates and non-technical folk. *YOU* may ascribe to the religion of imperialism, but i do not; if i am to ascribe to any religion, that religion would be pragmatism. And even if we cull the geographic Set you provided to include only the literates of that Set, it would simply be impractical for small or even medium sized developers to devote the time needed to cater to all those foreign markets. Does that mean i don't care about these people -- no. Does that mean i look down on these people -- no. It just means that my time is very important to me. And for you to suggest that those who do not support your pet "inclusivity project" are intolerant (or whatever pejorative you want to use), well, that discloses more about your personality than does it mine. So let the bright lads in those counties rise up and provide their own people with great localized products. My market includes the entire Western culture; spanning multiple continents and even some of the more advanced areas of the undeveloped nations you mentioned. That's a large enough market to make billions. Why should i take anymore? Sheesh. Out of one side your face you people whine because major american corporations like Mcdonalds and Coca-Cola have invaded just about every market on the face of the earth -- and i agree, those companies should not be there! -- then, out of the other side of your face, you whine because America has not invaded _enough_. So which is it? You can't have both ways. It is every nation's own responsibility to care for their people, to provide an education for their people, and to provide an economic system that can support their people. And just as America has no business telling you Brits what to do, you have no business telling us what to do. The days of King George are gone forever. Wake up and smell the spam. From mikhailwas at gmail.com Sat Apr 1 19:25:34 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sun, 2 Apr 2017 01:25:34 +0200 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2 April 2017 at 00:22, Chris Angelico wrote: > On Sun, Apr 2, 2017 at 8:16 AM, Mikhail V wrote: >> For multiple-alphabet rendering I will use some >> custom text format, e.g. with tags >> ... , and for latin >> ... and etc. >> >> Simple and effective. > > For multi-alphabet rendering, I would rather use an even simpler > format: Remove the tags and use a consistent encoding. No, flat encoding would not be simpler, it would be simpler only and only if you take a text with several alphabets, and mix the data randomly. In real situation, data chunks that use different glyph sets for representation are not mixed in a random manner. Also for different processing purposes tagged structure will be way more effective, e.g. if I want to extract all chunks in alphabet A in a single list with strings, or use advanced search, etc. > > Have you ever actually *used* a system of tagged encodings? It is an > abomination. Not with such encodings (exept my own experiments), but in some sense, I use it every day, e.g. in rich text format (Word, InDesign), you have bold text or italics text - in internal representation it is like tagged text, and adresses different glyph sets. Yes those are [probably] unicode values, but the application deals with those tags at rendering and copy-pasting. IOW such applications technically could cope with encodings in similar manner without problems. From eryksun at gmail.com Sat Apr 1 19:45:59 2017 From: eryksun at gmail.com (eryk sun) Date: Sat, 1 Apr 2017 23:45:59 +0000 Subject: VirtualEnvs (venv) and Powershell In-Reply-To: References: Message-ID: On Sat, Apr 1, 2017 at 12:03 AM, Carl Caulkett wrote: > I've just started to investigate VirtualEnvironments as a means of > preventing my 3rd party code becoming chaotic. I've discovered that > venv's can be managed quite effectively using Powershell. When > Activate.ps1 is run, the PowerShell changes to indicate that the venv > is active which is nice. However despite the official documention, > there doesn't seem to be a corresponding Deactivate.ps1. There is a > deactivate.bat but that doesn't appear to switch the paths back to > their pre-env state. Please read the contents of Activate.ps1. The way the `deactivate` function works should be obvious. From rosuav at gmail.com Sat Apr 1 20:01:25 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Apr 2017 10:01:25 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 2, 2017 at 9:25 AM, Mikhail V wrote: > On 2 April 2017 at 00:22, Chris Angelico wrote: >> On Sun, Apr 2, 2017 at 8:16 AM, Mikhail V wrote: >>> For multiple-alphabet rendering I will use some >>> custom text format, e.g. with tags >>> ... , and for latin >>> ... and etc. >>> >>> Simple and effective. >> >> For multi-alphabet rendering, I would rather use an even simpler >> format: Remove the tags and use a consistent encoding. > > No, flat encoding would not be simpler, it would be simpler only and only > if you take a text with several alphabets, and mix the data randomly. > In real situation, data chunks that use different glyph sets for > representation are not mixed in a random manner. > Also for different processing purposes tagged structure will be way > more effective, e.g. if I want to extract all chunks in alphabet A > in a single list with strings, or use advanced search, etc. https://github.com/Rosuav/LetItTrans/blob/master/25%20languages.srt Not exactly random, but that's a single file, a single document, using characters from several different scripts. And this is far from the only case of this sort of thing happening. ChrisA From No_spamming at noWhere_7073.org Sat Apr 1 20:08:05 2017 From: No_spamming at noWhere_7073.org (Robert L.) Date: Sun, 2 Apr 2017 00:08:05 +0000 (UTC) Subject: Temporary variables in list comprehensions References: <58730938$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/8/2017, Steven D'Aprano wrote: > Suppose you have an expensive calculation that gets used two or > more times in a loop. The obvious way to avoid calculating it > twice in an ordinary loop is with a temporary variable: > > result = [] > for x in data: > tmp = expensive_calculation(x) > result.append((tmp, tmp+1)) > > > But what if you are using a list comprehension? Alas, list comps > don't let you have temporary variables, so you have to write > this: > > [(expensive_calculation(x), expensive_calculation(x) + 1) for x in data] > > Or do you? ... no, you don't! > > [(tmp, tmp + 1) for x in data for tmp in [expensive_calculation(x)]] [2,3,5].map{|n| tmp = Math.sqrt n; [tmp, tmp+1]} ===> [[1.4142135623730951, 2.414213562373095], [1.7320508075688772, 2.732050807568877], [2.23606797749979, 3.23606797749979]] -- I don't believe in western morality, i.e. don't kill civilians or children.... The only way to fight a moral war is the Jewish way: Destroy their holy sites. Kill men, women, and children (and cattle). --- Rabbi Manis Friedman web.archive.org/web/20090605154706/http://www.momentmag.com/Exclusive/2009/2009-06/200906-Ask_Rabbis.html archive.org/download/DavidDukeVideo/TheZionistMatrixOfPowerddhd.ogv From matt.mailinglists at gmail.com Sat Apr 1 20:39:53 2017 From: matt.mailinglists at gmail.com (Matt) Date: Sat, 1 Apr 2017 19:39:53 -0500 Subject: net-snmp-python Message-ID: Does anyone have an example of using netsnmp library to do a snmpset on a snmp v2 device? I have gotten snmpget to work fine with python I just cannot get snmpset to work. I know I have the snmp device configured correctly with read/write access since I can use snmpset on the linux(centos7) command line to successfully make changes to the device. This is on python 2.7.5 stock version included with Centos 7. The below works fine to do a snmpwalk but I need to do a snmpset on different variable. import netsnmp oid = netsnmp.Varbind('sysDescr') result = netsnmp.snmpwalk(oid, Version = 2, DestHost="localhost", Community="public") print result From mikhailwas at gmail.com Sat Apr 1 21:33:26 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sun, 2 Apr 2017 03:33:26 +0200 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2 April 2017 at 02:01, Chris Angelico wrote: > On Sun, Apr 2, 2017 at 9:25 AM, Mikhail V wrote: >> On 2 April 2017 at 00:22, Chris Angelico wrote: >>> On Sun, Apr 2, 2017 at 8:16 AM, Mikhail V wrote: >>>> For multiple-alphabet rendering I will use some >>>> custom text format, e.g. with tags >>>> ... , and for latin >>>> ... and etc. >>>> >>>> Simple and effective. >>> >>> For multi-alphabet rendering, I would rather use an even simpler >>> format: Remove the tags and use a consistent encoding. >> >> No, flat encoding would not be simpler, it would be simpler only and only >> if you take a text with several alphabets, and mix the data randomly. >> In real situation, data chunks that use different glyph sets for >> representation are not mixed in a random manner. >> Also for different processing purposes tagged structure will be way >> more effective, e.g. if I want to extract all chunks in alphabet A >> in a single list with strings, or use advanced search, etc. > > https://github.com/Rosuav/LetItTrans/blob/master/25%20languages.srt > > Not exactly random, but that's a single file, a single document, using > characters from several different scripts. And this is far from the > only case of this sort of thing happening. > So you propose that I automatically convert this content to tagged format? Heh, no thanks, and this does not refer to the above discussed problem. If you will make a publishing layout of multi-lingual document, you will have to do that manually anyway. (however e.g. in Adobe InDesign there is automatical assistance for this task, which tries to guess the language of chunks) So this speaks merely against spawning of such content than towards unicode. From rantingrickjohnson at gmail.com Sat Apr 1 21:38:30 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 1 Apr 2017 18:38:30 -0700 (PDT) Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dd12d2$0$1611$c3e8da3$5496439d@news.astraweb.com> <04f771fe-1c40-48e9-85d7-3b743108c5eb@googlegroups.com> Message-ID: On Saturday, April 1, 2017 at 3:08:20 PM UTC-5, Mikhail V wrote: > On 1 April 2017 at 06:38, Rick Johnson wrote: > > On Thursday, March 30, 2017 at 9:14:54 AM UTC-5, Steve D'Aprano wrote: > > > > - and making band names look ???? and annoy old fuddy- > > > duddies. > > > > So now we've even included graffiti artists in our little > > "inclusivity project". My, my... we are so _not_ mean! > > Lol :) First we'll wait for Unicode version with table- > drawing character for all possible corner styles and line > weights, and monospaced legible Arabic for Chris' MUDs. Urm, don't mention MUDs around Chris. That's like a dog whistle to him. He could go on and on for hours yelping about them. To be honest, between his MUD ramblings and his incessant plugging of the Pike language, i don't know which is worse @_ at . But we tolerate Chris. In fact, noticing that Pike is statically typed, i'm beginning to wonder if Chris may have poured pike oil in GvR's ear thereby convincing him to introduce type-hints. Whaddaya got next Chris, braces? But the more i think about it, the more i realize the _true_ culprit of this type-hints conundrum may just be the Go language. Sure, Ruby was the "classic foe", however, Ruby was never a _real_ threat to Python. And not because Ruby was an inferior language, but because Ruby did not outshine Python. For both of their natural lives, Ruby and Python have existed in their own little nitches, and so, neither became an existential threat to the other. But then, Google's pet language named "Go" arrived on the scene, and now we had a statically typed compiled language with many of the sugary syntactical features and intuitive structural architecture of Python scripts. Go is basically an evolution of Python, and when Guido first noticed Go he became intimidated and then frightened, and so, hastily decided he had to compete with it. And since he knew that true static typing would be impossible in Python, he made the compromise of implementing "type-hints". And so, now the entire community has been saddled with this type-hints mess, just because a few of his peers at Google-plex decided to give Go, well, a go. Our emotions can be powerful opponents. Sometimes, so powerful, that even the wise cannot control them. Of course, this is the same man who proudly claimed (when asked in an interview if he would take a flight in a aeroplane that was controlled by a dynamic language such as Python), "Yes!". Of course, with the caveat that he would be allowed to "write all the code himself". But what kind person would make such a foolish claim? And whether this loose thinking was a matter of overwhelming emotions or just pure stupidity, has been hotly debated by many people in community ever since. But, as for me, i don't think the man is stupid -- no, the Python language stands as a testament to his intellectual prowess -- however, my observations have led me to believe that he's unable to control his emotions. In fact, he is a man ruled by emotions. His famously foolish and braggadocious claim exposes a deeply inflated sense of his own abilities brought to the surface by powerful feelings of superiority over others. He believes himself infallible. Could this be a result of malignant narcissism? Megalomania? Possibly all the above sprinkled lightly with sadistic tendencious? Who knows... I'm not sure if our dear leader has conceded to the foolish nature of his famous "Python Drone Idea", but what i am sure of, is that the existence of type-hints is evidence of his emotions (once again!) overriding his rational mind and causing him to make a poor decision. Last time it was pride. This time it is jealously. What will it be next time? He is a man who is unable to be humble in the reality of his own accomplishments, and unable to concede that his intellectual powers are merely that of a mortal. Powers that are subject to fallibility and stubborn headedness. Powers that cannot reach full potential unless they are supplemented by a strong and open community. This realization is for me, and many in this fine community, both sad and terrifying. It is as though we are witnessing a beloved relative slowly drift away into the clutches of dementia. Racked with horrific pain and dehumanized by the embarrassing bouts of incontinence. And we are powerless to do anything to stop it. And although we'd rather hold our noses and look away, we cannot. It is a strange irony that we are forced by a "sense of duty" to become unwilling spectators to this downward spiral. From steve+python at pearwood.info Sat Apr 1 21:53:11 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 02 Apr 2017 11:53:11 +1000 Subject: Temporary variables in list comprehensions References: <58730938$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58e05988$0$1601$c3e8da3$5496439d@news.astraweb.com> Robert, I've asked you once to stop posting anti-Semitic signatures in your posts. You've now posted four times, and each one has included racist material in the signature. You are welcome to participate here if you discuss Python, or even to discuss general programming techniques, but if you continue to post anti-Semitic or other racist links and so-called "quotes" (usually invented or made up), you will be reported for a CoC violation and banned from the mailing list and kill-filed on the newsgroup. On Sun, 2 Apr 2017 10:08 am, Robert L. wrote: > I don't believe in western morality[...] > archive.org/download/DavidDukeVideo/[...] -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sat Apr 1 22:08:03 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Apr 2017 12:08:03 +1000 Subject: Temporary variables in list comprehensions In-Reply-To: <58e05988$0$1601$c3e8da3$5496439d@news.astraweb.com> References: <58730938$0$1597$c3e8da3$5496439d@news.astraweb.com> <58e05988$0$1601$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 2, 2017 at 11:53 AM, Steve D'Aprano wrote: > Robert, I've asked you once to stop posting anti-Semitic signatures in your > posts. You've now posted four times, and each one has included racist > material in the signature. > > You are welcome to participate here if you discuss Python, or even to > discuss general programming techniques, but if you continue to post > anti-Semitic or other racist links and so-called "quotes" (usually invented > or made up), you will be reported for a CoC violation and banned from the > mailing list and kill-filed on the newsgroup. If you were responding to something in this thread, I didn't even see it, which quite possibly means he's already banned from the mailing list. ChrisA From steve+python at pearwood.info Sat Apr 1 22:18:03 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 02 Apr 2017 12:18:03 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58e05f5d$0$1590$c3e8da3$5496439d@news.astraweb.com> On Sun, 2 Apr 2017 09:11 am, Rick Johnson wrote: > The majority of the populations you reference are > illiterate. /face-palm The majority of Chinese and Japanese are illiterate. Really? Even India has a literacy rate of 74%, which is not far off the functional literacy rate in the US of 86%. http://www.huffingtonpost.com/2013/09/06/illiteracy-rate_n_3880355.html (I know I'm comparing apples with oranges. But when 14% of the adult population can *effectively* not read, despite being educated in the wealthiest economy in the world, you don't get to point the finger at other, poorer, countries and nations for their literacy problems.) You're entitled to your own opinions, you're not entitled to your own facts. Until you learn some actual facts, instead of the prejudices and self- serving ignorance that you are currently operating on, your opinions are based on fantasy, and you alternate between laughably obnoxious and just obnoxious. > Then create whatever encodings you so desire and then STFU about it. The necessary encoding exists. Its called Unicode. > Go request an audience from your beloved Queen Mother My "beloved" Queen Mother? Oh dear, you really don't know me very well. Besides, the old girl died in 2002. > And yet America continues to be emulated by 100% of the world. Well, at least 100% of the world that you know of. Which isn't saying much. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From python at mrabarnett.plus.com Sat Apr 1 22:32:01 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 2 Apr 2017 03:32:01 +0100 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dd12d2$0$1611$c3e8da3$5496439d@news.astraweb.com> <04f771fe-1c40-48e9-85d7-3b743108c5eb@googlegroups.com> Message-ID: On 2017-04-02 02:38, Rick Johnson wrote: > On Saturday, April 1, 2017 at 3:08:20 PM UTC-5, Mikhail V wrote: >> On 1 April 2017 at 06:38, Rick Johnson wrote: >> > On Thursday, March 30, 2017 at 9:14:54 AM UTC-5, Steve D'Aprano wrote: >> >> > > - and making band names look ???? and annoy old fuddy- >> > > duddies. >> > >> > So now we've even included graffiti artists in our little >> > "inclusivity project". My, my... we are so _not_ mean! >> >> Lol :) First we'll wait for Unicode version with table- >> drawing character for all possible corner styles and line >> weights, and monospaced legible Arabic for Chris' MUDs. > > Urm, don't mention MUDs around Chris. That's like a dog > whistle to him. He could go on and on for hours yelping > about them. To be honest, between his MUD ramblings and his > incessant plugging of the Pike language, i don't know which > is worse @_ at . > > But we tolerate Chris. > [snip] Sometimes he mentions MUDs, sometimes he mentions Pike, but at least he doesn't rant. From rantingrickjohnson at gmail.com Sat Apr 1 22:42:12 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 1 Apr 2017 19:42:12 -0700 (PDT) Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58e05f5d$0$1590$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <58e05f5d$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, April 1, 2017 at 9:18:14 PM UTC-5, Steve D'Aprano wrote: [...] > Even India has a literacy rate of 74%, which is not far off > the functional literacy rate in the US of 86%. > > http://www.huffingtonpost.com/2013/09/06/illiteracy-rate_n_3880355.html And your source is the HuffPo? Seriously? With that in mind, i think i'll wander on over to the TIOBE index and gawk at the python position for a while. Gawd knows that google searches and spam hits are the only true test for judging the worthiness of programming language. > The necessary encoding exists. Its called Unicode. Great. Now let the evolutionary forces of the free market decide if it will live or die. Why do you feel compelled to intervene in this natural process? From torriem at gmail.com Sat Apr 1 22:44:19 2017 From: torriem at gmail.com (Michael Torrie) Date: Sat, 1 Apr 2017 20:44:19 -0600 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58e05f5d$0$1590$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <58e05f5d$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7d73a2c0-880d-77bb-b97b-c1c0d0281b84@gmail.com> On 04/01/2017 08:18 PM, Steve D'Aprano wrote: >> And yet America continues to be emulated by 100% of the world. > > Well, at least 100% of the world that you know of. Which isn't saying much. I plonked RR a long time ago, but this little doozie requires a reply! Having just traveled half way across the globe to two different continents last month, I can say very clearly that those places do not wish to or strive to emulate the US. Especially lately with the current, unprecedented level of belligerence emanating from its highest office. And certainly not in language... The countries I visited are extremely proud of their languages and cultures. Anyway, just wow. From steve+python at pearwood.info Sun Apr 2 00:29:39 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 02 Apr 2017 14:29:39 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <58e05f5d$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58e07e35$0$1598$c3e8da3$5496439d@news.astraweb.com> On Sun, 2 Apr 2017 12:42 pm, Rick Johnson wrote: > On Saturday, April 1, 2017 at 9:18:14 PM UTC-5, Steve D'Aprano wrote: > [...] >> Even India has a literacy rate of 74%, which is not far off >> the functional literacy rate in the US of 86%. >> >> http://www.huffingtonpost.com/2013/09/06/illiteracy-rate_n_3880355.html > > And your source is the HuffPo? Seriously? No. My sources are the National Assessment of Adult Literacy, and the U.S. Department of Education. HuffPo is just the middle man reporting the facts. Hint: in the HuffPo article, you will see underlined phrases. These are called "hyperlinks", or just "links", and clicking on some of them will take you to the original source of the data. >> The necessary encoding exists. Its called Unicode. > > Great. Now let the evolutionary forces of the free market > decide if it will live or die. Why do you feel compelled to > intervene in this natural process? I'm just as much a part of the "evolutionary forces of the free market" as you. If you're allowed to complain about people using Unicode and loudly rant about how its not necessary, I'm allowed to disagree. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From tjreedy at udel.edu Sun Apr 2 02:41:53 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 2 Apr 2017 02:41:53 -0400 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/1/2017 12:00 PM, Steve D'Aprano wrote: > example of the Ugly American. As an American I resent your promotion and perpetuation of an ugly ethno-centric stereotype. -- Terry Jan Reedy From rosuav at gmail.com Sun Apr 2 03:14:20 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Apr 2017 17:14:20 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 2, 2017 at 4:41 PM, Terry Reedy wrote: > On 4/1/2017 12:00 PM, Steve D'Aprano wrote: > >> example of the Ugly American. > > > As an American I resent your promotion and perpetuation of an ugly > ethno-centric stereotype. There are ugly Americans and there are non-ugly Americans. Rick is a prime example of the former. ChrisA From auriocus at gmx.de Sun Apr 2 04:03:32 2017 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 2 Apr 2017 10:03:32 +0200 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58dfe5b3$0$1616$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> <87h928t5r7.fsf@elektro.pacujo.net> <58dfe5b3$0$1616$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 01.04.17 um 19:38 schrieb Steve D'Aprano: > ^home^steve^document.txt > > > I'm sure I'd get used to it in a few years... > > Next: convince keyboard manufacturers to move the caret from SHIFT-6 to a > plain, unshifted key. Buggared if I'm going to hit shift every time I want > to use an absolute path... ...which is reality for a lot more people than you might think. On a German keyboard, / is Shift-7. Same for \ {} [] which require carpal-tunneling combinations with the right Alt key "Alt Gr". Especially bad are shortcutrs like Ctrl+\ which appear in some software. Christian From marko at pacujo.net Sun Apr 2 05:15:41 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 02 Apr 2017 12:15:41 +0300 Subject: Text-mode apps (Was :Who are the "spacists"?) References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> <87h928t5r7.fsf@elektro.pacujo.net> <58dfe5b3$0$1616$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r31b5fwi.fsf@elektro.pacujo.net> Christian Gollwitzer : > Am 01.04.17 um 19:38 schrieb Steve D'Aprano: >> Next: convince keyboard manufacturers to move the caret from SHIFT-6 >> to a plain, unshifted key. Buggared if I'm going to hit shift every >> time I want to use an absolute path... > > ...which is reality for a lot more people than you might think. On a > German keyboard, / is Shift-7. Same for \ {} [] which require > carpal-tunneling combinations with the right Alt key "Alt Gr". > Especially bad are shortcutrs like Ctrl+\ which appear in some > software. Same with the Finnish keyboard. It's a crime against ergonomy. That's why I have remapped my keyboard for my personal needs (languages, programming). Marko From bc at freeuk.com Sun Apr 2 07:12:10 2017 From: bc at freeuk.com (bartc) Date: Sun, 2 Apr 2017 12:12:10 +0100 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <87wpb3ste3.fsf@elektro.pacujo.net> References: <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> <87h928t5r7.fsf@elektro.pacujo.net> <58dfe5b3$0$1616$c3e8da3$5496439d@news.astraweb.com> <87a87zua6k.fsf@elektro.pacujo.net> <871stbu9az.fsf@elektro.pacujo.net> <87wpb3ste3.fsf@elektro.pacujo.net> Message-ID: On 01/04/2017 22:35, Marko Rauhamaa wrote: > Chris Angelico : > >> there is no way within Python to have a string that can represent two >> strings, which is what directory separators do. > > Really? Try: > > >>> repr(("a", "b")) > "('a', 'b')" > > There! A string that represents two strings. > > Note, however, that Python programs generally don't restrict themselves > to expressing objects via strings. There are even objects with no string > representation at all. > > A pathname is a list of strings. Python could naturally express it as > just that: > > [ "usr", "bin", "python3" ] > > > I'm not really proposing any change to the status quo. What's done is > done. However, I do think it is awkward to ban one particular, very > common character while allowing all the rest. Space is quite common as well, especially in titles of things chosen by non-technical users. That also needs special treatment. There are quite a few other characters with special meanings that people might want to use. It's not just stroke. But people, when unrestrained, will /always/ want to do something that may not be practical. For example, why bother with the separate concepts 'filename' and 'file'; just have the file contents /as/ the filename! If there are no limits on how long a filename is or what characters it can have, then people will take advantage. Or they will want to use the full path of one file, as the part of the filename of another; is each "/" a separator, or part of the embedded path? Anyway, I'm sure out of the million unicode characters, there must be something that /looks/ like a stroke, but isn't a stroke. Just to add to the confusion. -- bartc From rosuav at gmail.com Sun Apr 2 07:21:49 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Apr 2017 21:21:49 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87r31ct6x5.fsf@elektro.pacujo.net> <87h928t5r7.fsf@elektro.pacujo.net> <58dfe5b3$0$1616$c3e8da3$5496439d@news.astraweb.com> <87a87zua6k.fsf@elektro.pacujo.net> <871stbu9az.fsf@elektro.pacujo.net> <87wpb3ste3.fsf@elektro.pacujo.net> Message-ID: On Sun, Apr 2, 2017 at 9:12 PM, bartc wrote: > But people, when unrestrained, will /always/ want to do something that may > not be practical. For example, why bother with the separate concepts > 'filename' and 'file'; just have the file contents /as/ the filename! If > there are no limits on how long a filename is or what characters it can > have, then people will take advantage. > This is possible. It's called a "content-based file system", and it's the basis of tools like git, for example. But it's not the entire solution; you still need some way to tell a program which blob to react to. ChrisA From ganesh1pal at gmail.com Sun Apr 2 12:13:14 2017 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Sun, 2 Apr 2017 21:43:14 +0530 Subject: Basic Nested Dictionary in a Loop Message-ID: Dear Python friend I have a nested data dictonary in the below format and I need to store 1000 of entries which are in teh below format >>> X['emp_01']['salary3'] = dict(sex="f", status="single", exp="4", grade="A",payment="200") >>> X['emp_01']['salary4'] = dict(sex="f", status="single", exp="4", grade="A",payment="400") >>> X['emp_01']['salary5'] = dict(sex="f", status="single", exp="4", grade="A",payment="400") I only thing thats is changing is payment and I have payment_list as a list [100,200,400,500]: The value salary3 ,salary4,salary4 is to be generated in the loop . Iam trying to optimize the above code , by looping as shown below >>> X = {} >>> X['emp_01'] ={} >>> for salary in range(len(payment_list)): ... X['emp_01'][salary] = dict(sex="f", status="single", exp="4", grade="A",payment=payment_list[salary]) ... >>> X {'emp_01': {0: {'grade': 'A', 'status': 'single', 'payment': 100, 'exp': '4', 'sex': 'f'}, 1: {'grade': 'A', 'status': 'single', 'payment': 200, 'exp': '4', 'sex': 'f'}, 2: {'grade': 'A', 'status': 'single', 'payment': 400, 'exp': '4', 'sex': 'f'}, 3: {'grade': 'A', 'status': 'single', 'payment': 500, 'exp': '4', 'sex': 'f'}}} >>> Any other suggestion , Please let me know I am on python 2.7 and Linux Regards, Ganesh From steve+python at pearwood.info Sun Apr 2 12:26:40 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 03 Apr 2017 02:26:40 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58e12641$0$1597$c3e8da3$5496439d@news.astraweb.com> On Sun, 2 Apr 2017 04:41 pm, Terry Reedy wrote: > On 4/1/2017 12:00 PM, Steve D'Aprano wrote: > >> example of the Ugly American. > > As an American I resent your promotion and perpetuation of an ugly > ethno-centric stereotype. I'm glad you didn't try to describe it as a *unfair* or *unjustified* stereotype, because (let's face it) after November 8th 2016, that simply wouldn't fly. Not all Americans, perhaps not even a majority or a plurality, are Ugly Americans, but there are enough of them to screw it up for everyone else. It's an ugly stereotype, not because it is a stereotype, but because it embodies a set of ugly attitudes and behaviours. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From i.am.songoku at gmail.com Sun Apr 2 12:47:49 2017 From: i.am.songoku at gmail.com (Krishnan Shankar) Date: Sun, 2 Apr 2017 22:17:49 +0530 Subject: In Python and Windows environment how to supress certain key press and send some other key event for it Message-ID: Hi All, I was trying to build a VIM like shortcuts in windows. For example, IF i press CAPSLOCK & h: It should "{Left}" move one to left. If CAPSLOCK & b: It should "{Ctrl Down}{Left}{Ctrl Up}" move one word left etc. I was successful in sending the key event. I used libraries like, 1. pynput 2. keyboard for the same. But i was unable to supress the Initial key event (ex: Caplock & h) I tried using the keyboard to listen for key press events and supress them as below. >>>>> import keyboard def move_one_left(): """ Wrapper for CAPS LOCK + b. The function sends LEFT ARROW Event :return: """ keyboard.send(75) def move_one_word_left(): """ Wrapper for CAPS LOCK + b. The function sends LEFT ARROW Event :return: """ keyboard.send('ctrl+left') def main(): """ This is the main loop which reads the key pressed. According to the hotkey registered the function hooked is called. The corresponding function will be the wrapped combination send back. For example: CAPS + b is wrapped to Moving to left. The main loop exits when Ctrl + c is done. So that is not registered. :return: """ try: # Start of the main loop # Registering the hotkeys # CAPS LOCK + H keyboard.add_hotkey('caps lock+h', move_one_left, suppress=True) # CAPS LOCK + B keyboard.add_hotkey('caps lock+b', move_one_word_left, suppress=True) while True: # Read the key pressed print (keyboard.read_key()) except KeyboardInterrupt: print("User has exited the program") if __name__ == "__main__": main() <<<<< This is working for sending the event for key press but the initial keypress is also being send. The supress=True is not working. Am I doing something wrong or is there any better way to supress the initial key event and send another key event in place of that. Regards, Krishnan From __peter__ at web.de Sun Apr 2 13:02:17 2017 From: __peter__ at web.de (Peter Otten) Date: Sun, 02 Apr 2017 19:02:17 +0200 Subject: Basic Nested Dictionary in a Loop References: Message-ID: Ganesh Pal wrote: > Dear Python friend > > > I have a nested data dictonary in the below format and I need to store > 1000 of entries which are in teh below format > > >>>> X['emp_01']['salary3'] = dict(sex="f", status="single", exp="4", > grade="A",payment="200") >>>> X['emp_01']['salary4'] = dict(sex="f", status="single", exp="4", > grade="A",payment="400") >>>> X['emp_01']['salary5'] = dict(sex="f", status="single", exp="4", > grade="A",payment="400") > > > I only thing thats is changing is payment and I have payment_list as a > list > [100,200,400,500]: > > > The value salary3 ,salary4,salary4 is to be generated in the loop . Iam > trying to optimize the above code , by looping as shown below > > >>>> X = {} >>>> X['emp_01'] ={} >>>> for salary in range(len(payment_list)): Whenever you feel the urge to write range(len(whatever)) -- resist that temptation, and you'll end up with better Python code ;) > ... X['emp_01'][salary] = dict(sex="f", status="single", exp="4", > grade="A",payment=payment_list[salary]) > ... >>>> X > {'emp_01': {0: {'grade': 'A', 'status': 'single', 'payment': 100, 'exp': > '4', 'sex': 'f'}, 1: {'grade': 'A', 'status': 'single', 'payment': 200, > 'exp': '4', 'sex': 'f'}, 2: {'grade': 'A', 'status': 'single', 'payment': > 400, 'exp': '4', 'sex': 'f'}, 3: {'grade': 'A', 'status': 'single', > 'payment': 500, 'exp': '4', 'sex': 'f'}}} >>>> > > > Any other suggestion , Please let me know I am on python 2.7 and Linux Instead of artificially blowing up your database change its structure. For example: X["emp_01"] = dict( sex="f", status="single", exp="4", grade="A", payments=[100, 200, 400, 500] ) From steve+python at pearwood.info Sun Apr 2 13:05:07 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 03 Apr 2017 03:05:07 +1000 Subject: Basic Nested Dictionary in a Loop References: Message-ID: <58e12f46$0$1618$c3e8da3$5496439d@news.astraweb.com> On Mon, 3 Apr 2017 02:13 am, Ganesh Pal wrote: > Dear Python friend > > > I have a nested data dictonary in the below format and I need to store > 1000 of entries which are in teh below format > > >>>> X['emp_01']['salary3'] = dict(sex="f", status="single", exp="4", > grade="A",payment="200") >>>> X['emp_01']['salary4'] = dict(sex="f", status="single", exp="4", > grade="A",payment="400") >>>> X['emp_01']['salary5'] = dict(sex="f", status="single", exp="4", > grade="A",payment="400") Why is payment a string? > I only thing thats is changing is payment and I have payment_list as a > list > [100,200,400,500]: And here payment is an int. > The value salary3 ,salary4,salary4 is to be generated in the loop . Iam > trying to optimize the above code , by looping as shown below In the above example, you have strings "salary3", "salary4", "salary5", but in the code below, you use 0, 1, 2 instead. Which do you intend to use? >>>> X = {} >>>> X['emp_01'] ={} >>>> for salary in range(len(payment_list)): > ... X['emp_01'][salary] = dict(sex="f", status="single", exp="4", > grade="A",payment=payment_list[salary]) You should almost never need to write `range(len(payment_list))`. payment_list = [100, 200, 400, 500] employees = {} employees['emp_01'] = {} for salary, payment in enumerate(payment_list, 3): # I don't know why salary starts at 3 instead of 1 or 0. salary = 'salary' + str(salary) employees['emp_01'][salary] = dict( sex="f", status="single", exp="4", grade="A", payment=payment ) from pprint import pprint pprint(employees) {'emp_01': {'salary3': {'exp': '4', 'grade': 'A', 'payment': 100, 'sex': 'f', 'status': 'single'}, 'salary4': {'exp': '4', 'grade': 'A', 'payment': 200, 'sex': 'f', 'status': 'single'}, 'salary5': {'exp': '4', 'grade': 'A', 'payment': 400, 'sex': 'f', 'status': 'single'}, 'salary6': {'exp': '4', 'grade': 'A', 'payment': 500, 'sex': 'f', 'status': 'single'}}} -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From gheskett at shentel.net Sun Apr 2 13:30:44 2017 From: gheskett at shentel.net (Gene Heskett) Date: Sun, 2 Apr 2017 13:30:44 -0400 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58e12641$0$1597$c3e8da3$5496439d@news.astraweb.com> References: <58e12641$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201704021330.44532.gheskett@shentel.net> On Sunday 02 April 2017 12:26:40 Steve D'Aprano wrote: > On Sun, 2 Apr 2017 04:41 pm, Terry Reedy wrote: > > On 4/1/2017 12:00 PM, Steve D'Aprano wrote: > >> example of the Ugly American. > > > > As an American I resent your promotion and perpetuation of an ugly > > ethno-centric stereotype. > > I'm glad you didn't try to describe it as a *unfair* or *unjustified* > stereotype, because (let's face it) after November 8th 2016, that > simply wouldn't fly. While I too detest that label, I will have to admit that I am one of the conservatives, believing our Constitution and Bill of Rights have been used as TP by the "establishment" over the last 65+ years, who enabled that surprise. Wash., DC has been turned into a polluted swamp that needed drained and cleaned up, and the Donald was the only one that wasn't part of the same old, same old, bull crap establishment, and with enough money to run. However, I'll be the first to admit I am less than impressed with his efforts vis-a-vis global warming. He, I suspect, will be a 1 term president unless he starts listening to the technical people's warnings. I'd also make the prediction that the 2020 winner will _not_ be from the establishment. Maybe not even from the two party system. I am hoping that this will cause all (surviving) parties to do some navel gazing, and contemplating not how to enrich the constituent businesses they own under the table, but maybe, actually work for the common good. Taking money completely out of the equation would be one way, but you could hear the gored oxen that would wound fatally clear out to Pluto, without a radio. Human avarice being what it is, whether I'll live long enough to see that happen isn't up to me. At 82, it doesn't look like near as big a chance as it did when I was 60. > > Not all Americans, perhaps not even a majority or a plurality, are > Ugly Americans, but there are enough of them to screw it up for > everyone else. > Generally, I try to stay out of the Ugly camp. Then I look in the mirror and know its hopeless. :( [...] Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From ganesh1pal at gmail.com Sun Apr 2 13:46:52 2017 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Sun, 2 Apr 2017 23:16:52 +0530 Subject: Basic Nested Dictionary in a Loop In-Reply-To: <58e12f46$0$1618$c3e8da3$5496439d@news.astraweb.com> References: <58e12f46$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 2, 2017 at 10:35 PM, Steve D'Aprano wrote: > > Why is payment a string? > > Yes it should be int > > > The value salary3 ,salary4,salary4 is to be generated in the loop . Iam > > trying to optimize the above code , by looping as shown below > > In the above example, you have strings "salary3", "salary4", "salary5", but > in the code below, you use 0, 1, 2 instead. > > Which do you intend to use? > > It must be Salary1,Salary2 > payment_list = [100, 200, 400, 500] > > employees = {} > employees['emp_01'] = {} > for salary, payment in enumerate(payment_list, 3): > # I don't know why salary starts at 3 instead of 1 or 0. > salary = 'salary' + str(salary) > employees['emp_01'][salary] = dict( > sex="f", status="single", exp="4", grade="A", payment=payment > ) > > from pprint import pprint > pprint(employees) > > > {'emp_01': {'salary3': {'exp': '4', > 'grade': 'A', > 'payment': 100, > 'sex': 'f', > 'status': 'single'}, > 'salary4': {'exp': '4', > 'grade': 'A', > 'payment': 200, > 'sex': 'f', > 'status': 'single'}, > 'salary5': {'exp': '4', > 'grade': 'A', > 'payment': 400, > 'sex': 'f', > 'status': 'single'}, > 'salary6': {'exp': '4', > 'grade': 'A', > 'payment': 500, > 'sex': 'f', > 'status': 'single'}}} > > > > Thanks ; Ganesh From ganesh1pal at gmail.com Sun Apr 2 13:59:36 2017 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Sun, 2 Apr 2017 23:29:36 +0530 Subject: Basic Nested Dictionary in a Loop In-Reply-To: References: Message-ID: > > > Whenever you feel the urge to write range(len(whatever)) -- resist that > temptation, and you'll end up with better Python code ;) > > Thanks for this suggestion but for my better understanding can explain this further even Steve did point the same mistake. > > Instead of artificially blowing up your database change its structure. For > example: > > Good point Actually , I might be heading towards this, let me ask this in a fresh email thread From phd at phdru.name Sun Apr 2 15:01:50 2017 From: phd at phdru.name (Oleg Broytman) Date: Sun, 2 Apr 2017 21:01:50 +0200 Subject: Cheetah 3.0.0a1 Message-ID: <20170402190150.GA20413@phdru.name> Hello! I'm happy to announce I revived development of Cheetah. Unfortunately I have to fork the project. I'm pleased to announce version 3.0.0a1, the first alpha of the upcoming release of branch 3.0 of CheetahTemplate3. What's new in CheetahTemplate3 ============================== Contributors for this release are Adam Karpierz and Jonathan Ross Rogers. - !!!THIS RELEASE REQUIRES RECOMPILATION OF ALL COMPILED CHEETAH TEMPLATES!!! - Stop supporting Python older than 2.7. - Update code to work with Python 3.3+. Tested with 3.3, 3.4, 3.5 and 3.6. - Run tests at Travis (Linux) and AppVeyor (w32) with Python 2.7, 3.3, 3.4, 3.5 and 3.6; x86 and x64. - Fix a bug in multiple inheritance (#extend Parent1, Parent2). Pull request by Jonathan Ross Rogers. What is CheetahTemplate3 ======================== Cheetah3 is a free and open source template engine. It's a fork of the original CheetahTemplate library. Python 2.7 or 3.3+ is required. Where is CheetahTemplate3 ========================= Site: http://cheetahtemplate.org/ Development: https://github.com/CheetahTemplate3 Download: https://pypi.python.org/pypi/Cheetah3/3.0.0a1 News and changes: http://cheetahtemplate.org/news.html Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From breamoreboy at gmail.com Sun Apr 2 17:52:00 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sun, 2 Apr 2017 14:52:00 -0700 (PDT) Subject: Temporary variables in list comprehensions In-Reply-To: References: <58730938$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sunday, April 2, 2017 at 1:08:17 AM UTC+1, Robert L. wrote: > I don't believe in western morality, i.e. don't kill civilians or children.... > The only way to fight a moral war is the Jewish way: Destroy their holy sites. > Kill men, women, and children (and cattle). --- Rabbi Manis Friedman > web.archive.org/web/20090605154706/http://www.momentmag.com/Exclusive/2009/2009-06/200906-Ask_Rabbis.html > archive.org/download/DavidDukeVideo/TheZionistMatrixOfPowerddhd.ogv Completely agree with Steven D'Aprano so would the moderators please ban Robert L with immediate effect. Kindest regards. Mark Lawrence. From tjreedy at udel.edu Sun Apr 2 18:31:09 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 2 Apr 2017 18:31:09 -0400 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58e12641$0$1597$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <58e12641$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/2/2017 12:26 PM, Steve D'Aprano wrote: > On Sun, 2 Apr 2017 04:41 pm, Terry Reedy wrote: > >> On 4/1/2017 12:00 PM, Steve D'Aprano wrote: >> >>> example of the Ugly American. >> >> As an American I resent your promotion and perpetuation of an ugly >> ethno-centric stereotype. > > I'm glad you didn't try to describe it as a *unfair* or *unjustified* I refrained because it would be off-topic and a diversion from my point: all bigotry is inappropriate here on this list, including anti-Americanism. (I actually think raw bigoty is inappropriate everywhere. While there are places to discuss the relative average beauty and niceness of various groups of people, this is not one of them. Even comparisons of computer languages is not the main focus of this list.) > stereotype, because (let's face it) after November 8th 2016, that simply > wouldn't fly. The 'Ugly American' meme is at least 60 years old. National bigotry is as old as nations. Yesterday, Chris Angelico, I believe it was, asked someone to stop including anti-Jew messages in posts here. So I asked the same of you regarding your anti-American expression. > Not all Americans, perhaps not even a majority or a plurality, are Ugly > Americans, but there are enough of them to screw it up for everyone else. Shall we discuss Ugly Australians, or whatever the appropriate epithet would be? > It's an ugly stereotype, not because it is a stereotype, but because it > embodies a set of ugly attitudes and behaviours. I am sure I have seen similar things written by various other people justifying their prejudices. -- Terry Jan Reedy From tjreedy at udel.edu Sun Apr 2 18:51:14 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 2 Apr 2017 18:51:14 -0400 Subject: Basic Nested Dictionary in a Loop In-Reply-To: References: Message-ID: On 4/2/2017 1:59 PM, Ganesh Pal wrote: > 'someone' wrote >> Whenever you feel the urge to write range(len(whatever)) -- resist that >> temptation, and you'll end up with better Python code ;) > Thanks for this suggestion but for my better understanding can explain > this further even Steve did point the same mistake. Before 2.2, one could only iterate through a sequence of integers, or something that pretended to be such. So the way to iterate though a finite sequence of non-ints was for i in range(len(seq)): item = seq[i] The current iterator protocol allows one to separate item access or generation from item processing and to hide the former in an iterator. One then says in the header what collection of items one want to process and in what order (one at a time) and in the body what one wants to do with them. for item in seq: # items of seq in normal order for item in iterable: # not restricted to sequences, default order Some other variations in the new form. for item in reversed(iterable): # finite collection in reversed order for i, item in enumerate(seq): for item1, item2 in zip(seq1, seq2): -- Terry Jan Reedy From ben+python at benfinney.id.au Sun Apr 2 19:10:54 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 03 Apr 2017 09:10:54 +1000 Subject: All people deserve respect. Ideas are not people. (was: Text-mode apps) References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <58e12641$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85y3vie77l.fsf_-_@benfinney.id.au> Terry Reedy writes: > On 4/2/2017 12:26 PM, Steve D'Aprano wrote: > > Not all Americans, perhaps not even a majority or a plurality, are Ugly > > Americans, but there are enough of them to screw it up for everyone else. > > Shall we discuss Ugly Australians, or whatever the appropriate epithet > would be? Provided that, just as Steven has done, the discussion criticises ideas, attitudes, and behaviours: that would not be bigotry nor prejudice at all. It's a difficult distinction, but an essential one: we *must* be free always to hold ideas and behaviours to harsh criticism when warranted, no matter who holds or does them, while respecting the dignity and rights and individuality of all persons. > > It's an ugly stereotype, not because it is a stereotype, but because > > it embodies a set of ugly attitudes and behaviours. > > I am sure I have seen similar things written by various other people > justifying their prejudices. Prejudice on the basis of a person's innate traits has no place in civil society. Ideas are not people, and are not innate to the person who holds them. An idea is not deserving of respect; that respect must not be assumed, it must be earned. More importantly, ideas inform behaviour. That is what makes robust criticism of bad ideas so important. Once an idea is expressed or demonstrated through behaviour, that idea or behaviour is not innately deserving of respect, and it becomes fair game for open criticism. What we need to always keep in mind is that the *idea* should be criticised, without attacking the *person*. -- \ ?Value your freedom or you will lose it, teaches history. | `\ ?Don't bother us with politics,? respond those who don't want | _o__) to learn.? ?Richard M. Stallman, 2002 | Ben Finney From torriem at gmail.com Sun Apr 2 19:39:19 2017 From: torriem at gmail.com (Michael Torrie) Date: Sun, 2 Apr 2017 17:39:19 -0600 Subject: All people deserve respect. Ideas are not people. In-Reply-To: <85y3vie77l.fsf_-_@benfinney.id.au> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <58e12641$0$1597$c3e8da3$5496439d@news.astraweb.com> <85y3vie77l.fsf_-_@benfinney.id.au> Message-ID: <908f9d7d-063f-cb52-1d47-d959db27a092@gmail.com> On 04/02/2017 05:10 PM, Ben Finney wrote: > > Ideas are not people, and are not innate to the person who holds them. > An idea is not deserving of respect; that respect must not be assumed, > it must be earned. > > More importantly, ideas inform behaviour. That is what makes robust > criticism of bad ideas so important. > > Once an idea is expressed or demonstrated through behaviour, that idea > or behaviour is not innately deserving of respect, and it becomes fair > game for open criticism. > > What we need to always keep in mind is that the *idea* should be > criticised, without attacking the *person*. Very well said. Thank you. From torriem at gmail.com Sun Apr 2 20:06:21 2017 From: torriem at gmail.com (Michael Torrie) Date: Sun, 2 Apr 2017 18:06:21 -0600 Subject: All people deserve respect. Ideas are not people. In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <58e12641$0$1597$c3e8da3$5496439d@news.astraweb.com> <85y3vie77l.fsf_-_@benfinney.id.au> <908f9d7d-063f-cb52-1d47-d959db27a092@gmail.com> Message-ID: <1e96feb3-0ba7-ff5b-eafa-0987de6d7ff6@gmail.com> On 04/02/2017 06:00 PM, Alex Kaye wrote: > Michael, Thanks for your comment. > > However, If one derails from the core subject > > they need to be in another stream. Alex I think you'll find that the subject line was changed by Ben Finney to reflect the new direction he was taking it, which is the usual and expected list etiquette. The change of subject line puts it in "another stream" as you say. Steve D'Aprano should have probably changed it a long time ago. And of course RR should have been plonked by Steven and others a long time ago also. But I digress. Again I am very glad Ben posted what he did and glad to show my support for what he said, though it will likely fall on deaf ears. thanks. From python at deborahswanson.net Sun Apr 2 21:26:07 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Sun, 2 Apr 2017 18:26:07 -0700 Subject: Two variable dictionary comprehension Message-ID: <001701d2ac19$45fbdea0$27b23dae@sambora> It seems like this should be easy to rewrite as a dict comprehension: records_idx = {} for idx, label in enumerate(records[0]): records_idx[label] = idx Maybe I'm having another "dumb day", or maybe I've just been struggling with this (larger) problem for too long, but eveything I try to get an equivalent dict comprehension for the 3 lines above is not working. From rosuav at gmail.com Sun Apr 2 21:36:54 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Apr 2017 11:36:54 +1000 Subject: Two variable dictionary comprehension In-Reply-To: <001701d2ac19$45fbdea0$27b23dae@sambora> References: <001701d2ac19$45fbdea0$27b23dae@sambora> Message-ID: On Mon, Apr 3, 2017 at 11:26 AM, Deborah Swanson wrote: > It seems like this should be easy to rewrite as a dict comprehension: > > records_idx = {} > for idx, label in enumerate(records[0]): > records_idx[label] = idx > > Maybe I'm having another "dumb day", or maybe I've just been struggling > with this (larger) problem for too long, but eveything I try to get an > equivalent dict comprehension for the 3 lines above is not working. Should be this: records_idx = {label: idx for idx, label in enumerate(records[0])} That's a direct translation of your code. ChrisA From ben+python at benfinney.id.au Sun Apr 2 21:37:45 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 03 Apr 2017 11:37:45 +1000 Subject: Two variable dictionary comprehension References: <001701d2ac19$45fbdea0$27b23dae@sambora> Message-ID: <85r31ae0eu.fsf@benfinney.id.au> "Deborah Swanson" writes: > It seems like this should be easy to rewrite as a dict comprehension: > > records_idx = {} > for idx, label in enumerate(records[0]): > records_idx[label] = idx How about this:: records_idx = { label: idx for (idx, label) in enumerate(collection_of_labels) } You may have tripped on the ambiguity of the comma in its surrounding context. I always prefer to put parens around the items I intend to be comma-separated, to remove that ambiguity. -- \ ?[It's] best to confuse only one issue at a time.? ?Brian W. | `\ Kernighan, Dennis M. Ritchie, _The C programming language_, 1988 | _o__) | Ben Finney From r.bryan.smith at gmail.com Sun Apr 2 21:46:07 2017 From: r.bryan.smith at gmail.com (R. Bryan Smith) Date: Sun, 2 Apr 2017 18:46:07 -0700 Subject: Traversal help Message-ID: Hello, I am working with Python 3.6. I?ve been trying to figure out a solution to my question for about 40 hrs with no success and hundreds of failed attempts. Essentially, I have bitten off way more than I can chew with processing this file. Most of what follows, is my attempt to inform as best I can figure. I have a JSONL (new line) file that I downloaded using requests and the following code: with open(fname, 'wb') as fd: for chunk in r.iter_content(chunk_size=1024): fd.write(chunk) The file was in gzip format (the encoding on the API says - UTF-8) to a windows 8 (it?s current, but 8) machine. These files are rather large, maybe around 4GB. I used the ?shebang' for ?UTF-8? at the top of my Python program: # -*- encoding: utf-8 -*- After I save the file, I read it using this: def read_json(path): '''Turns a normal json LINES (cr) file into an array of objects''' temp_array = [] f = codecs.open(path, 'r', 'utf-8', ?backslashreplace') for line in f: record = json.loads(line.strip('\n|\r')) temp_array.append(record) return temp_array I am working on a Linux server to partitioning the List returned above, there are three linked levels of detail (A, B, C) that can exist in any collection within the JSON and each Collection can contain wildly varying and/or repeating fields. The data contained within is scraped from websites all over the world. I wanted to ?traverse' the file structure and found an algorithm that I think will work: def traverser(obj, path=None, callback=None): if path is None: path = [] if isinstance(obj, dict): value = {k: traverser(v, path+[k], callback) for k, v in obj.items()} elif isinstance(obj, list): value = [traverser(elem, path+[[]], callback) for elem in obj] else: value = obj if callback is None: return value else: return callback(path, value) The only problem and the subsequent question that follows is: I have yet to successfully decode / How do I then ?collect? each of these objects while I am traversing the JSON New Line Collection into some sort of container (handling encoding errors) so that I can then write to a csv file (w/ ?utf-8? and won?t error out when I try to import it into a IBM ?utf-8? encoded DB)? Actually, after that, I would like to learn how to grab a specific element, if present in each Collection, whenever I need it, as well - but, that can wait. I?ve tried using the JSON module on the JSONL file, but the structure is really complicated and changing with lot?s of different control and spacing characters, in addition to some odd (potentially non-unicode characters). Here?s the schema: http://json-schema.org/fraft-04/schema# I?m not a programmer, but I am learning through assimilation. Any help is greatly appreciated. Even if it?s pointing me to documentation that can help me learn what to consider and lead me to what to do. Thank you, R. Smith From python at deborahswanson.net Sun Apr 2 22:31:23 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Sun, 2 Apr 2017 19:31:23 -0700 Subject: Two variable dictionary comprehension In-Reply-To: Message-ID: <001901d2ac22$6326fa10$27b23dae@sambora> Chris Angelico wrote, on April 02, 2017 6:37 PM > > On Mon, Apr 3, 2017 at 11:26 AM, Deborah Swanson > wrote: > > It seems like this should be easy to rewrite as a dict > comprehension: > > > > records_idx = {} > > for idx, label in enumerate(records[0]): > > records_idx[label] = idx > > > > Maybe I'm having another "dumb day", or maybe I've just been > > struggling with this (larger) problem for too long, but eveything I > > try to get an equivalent dict comprehension for the 3 lines above is > > not working. > > Should be this: > > records_idx = {label: idx for idx, label in enumerate(records[0])} > > That's a direct translation of your code. > > ChrisA Well, wouldncha know it, I never tried using a colon. That's what I get for just trying to guess. Thanks Chris Deborah From python at deborahswanson.net Sun Apr 2 22:34:49 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Sun, 2 Apr 2017 19:34:49 -0700 Subject: Two variable dictionary comprehension In-Reply-To: <85r31ae0eu.fsf@benfinney.id.au> Message-ID: <001a01d2ac22$ddeda410$27b23dae@sambora> Ben Finney wrote, on April 02, 2017 6:38 PM > > "Deborah Swanson" writes: > > > It seems like this should be easy to rewrite as a dict > comprehension: > > > > records_idx = {} > > for idx, label in enumerate(records[0]): > > records_idx[label] = idx > > How about this:: > > records_idx = { > label: idx > for (idx, label) in enumerate(collection_of_labels) > } > > You may have tripped on the ambiguity of the comma in its > surrounding context. I always prefer to put parens around the > items I intend to be comma-separated, to remove that ambiguity. > > -- > \ "[It's] best to confuse only one issue at a time." > -Brian W. | > `\ Kernighan, Dennis M. Ritchie, _The C programming > language_, 1988 | > _o__) > | > Ben Finney That's a neat way to think about the problem. Me, I was guessing all the way, and pleasantly surprised when the 3-statement concoction I came up with worked. Thanks Ben! Deborah From ben+python at benfinney.id.au Sun Apr 2 22:41:18 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 03 Apr 2017 12:41:18 +1000 Subject: Two variable dictionary comprehension References: <001901d2ac22$6326fa10$27b23dae@sambora> Message-ID: <85mvbydxgx.fsf@benfinney.id.au> "Deborah Swanson" writes: > Chris Angelico wrote, on April 02, 2017 6:37 PM > > > > On Mon, Apr 3, 2017 at 11:26 AM, Deborah Swanson > > > Maybe I'm having another "dumb day" [?] > > Well, wouldncha know it, I never tried using a colon. That's what I > get for just trying to guess. Yes, guessing *is* dumb when the reference documentation is available . I was sure you'd have been reading the manual before guessing, but I'll know better in future :-) -- \ ?A computer once beat me at chess, but it was no match for me | `\ at kick boxing.? ?Emo Philips | _o__) | Ben Finney From python-oren at ben-kiki.org Mon Apr 3 00:49:50 2017 From: python-oren at ben-kiki.org (Oren Ben-Kiki) Date: Mon, 3 Apr 2017 07:49:50 +0300 Subject: Behavior of auto in Enum and Flag. Message-ID: The current behavior of `auto` is to pick a value which is one plus the previous value. It would probably be better if `auto` instead picked a value that is not used by any named member (either the minimal unused value, or the minimal higher than the previous value). That is, in this simple case: class MyEnum(Enum): FOO = 1 BAR = auto() BAZ = 2 It would be far better for BAR to get the value 3 rather than today's value 2. In the less simple case of: class MyEnum(Enum): FOO = 2 BAR = auto() BAZ = 3 Then BAR could be either 1 or 4 - IMO, 1 would be better, but 4 works as well. After all, `auto` is supposed to be used when: "If the exact value is unimportant you may use auto instances and an appropriate value will be chosen for you." Choosing a value that conflicts with BAZ in above cases doesn't seem "appropriate" for a value that is "unimportant". The docs also state "Care must be taken if you mix auto with other values." - fair enough. But: First, why require "care" if the code can take care of the issue for us? Second, the docs don't go into further detail about what exactly to avoid. In particular, the docs do not state that the automatic value will only take into account the previous values, and will ignore following values. However, this restriction is baked into the current implementation: It is not possible to just override `_generate_next_value_` to skip past named values which were not seen yet, because the implementation only passes it the list of previous values. I propose that: 1. The documentation will be more explicit about the way `auto` behaves in the presence of following values. 2. The default behavior of `auto` would avoid generating a conflict with following values. 3. Whether `auto` chooses (A) the minimal unused value higher than the previous value, or (B) the minimal overall unused value, or (C) some other strategy, would depend on the specific implementation. 3. To allow for this, the implementation will include a `_generate_auto_value_` which will take both the list of previous ("last") values (including auto values) and also a second list of the following ("next") values (excluding auto values). 4. If the class implements `_generate_next_value_`, then `_generate_auto_value_` will invoke `_generate_next_value_` with the concatenation of both lists (following values first, preceding values second), to maximize compatibility with existing code. Thanks, Oren Ben-Kiki From python at deborahswanson.net Mon Apr 3 01:06:53 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Sun, 2 Apr 2017 22:06:53 -0700 Subject: Two variable dictionary comprehension In-Reply-To: <85mvbydxgx.fsf@benfinney.id.au> Message-ID: <001d01d2ac38$1c99c030$27b23dae@sambora> Ben Finney wrote. on April 02, 2017 7:41 PM > > "Deborah Swanson" writes: > > > Chris Angelico wrote, on April 02, 2017 6:37 PM > > > > > > On Mon, Apr 3, 2017 at 11:26 AM, Deborah Swanson > > > > Maybe I'm having another "dumb day" [.] > > > > Well, wouldncha know it, I never tried using a colon. That's what I > > get for just trying to guess. > > Yes, guessing *is* dumb when the reference documentation is > available > lays-for-lists-sets-and-dictionaries>. > I was sure you'd have been reading the manual before > guessing, but I'll know better in future :-) > > -- > \ "A computer once beat me at chess, but it was no > match for me | > `\ at kick boxing." > -Emo Philips | > _o__) > | > Ben Finney > Oh, come on. That's a fairly obscure citation in the docs, one that would take a good deal of experience and time reading through them to know was there, experience and years with Python that I don't have. But you knew that ... ;) Deborah From rosuav at gmail.com Mon Apr 3 01:38:20 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Apr 2017 15:38:20 +1000 Subject: Behavior of auto in Enum and Flag. In-Reply-To: References: Message-ID: On Mon, Apr 3, 2017 at 2:49 PM, Oren Ben-Kiki wrote: > "If the exact value is unimportant you may use auto instances and an > appropriate value will be chosen for you." > > Choosing a value that conflicts with BAZ in above cases doesn't seem > "appropriate" for a value that is "unimportant". > > The docs also state "Care must be taken if you mix auto with other values." > - fair enough. But: > > First, why require "care" if the code can take care of the issue for us? > > Second, the docs don't go into further detail about what exactly to avoid. > In particular, the docs do not state that the automatic value will only > take into account the previous values, and will ignore following values. Sounds to me like the current behaviour is compliant with what the docs say, and as such, I would be disinclined to change the code. Perhaps a documentation clarification would suffice? """Care must be taken if you mix auto with other values. In particular, using auto() prior to explicitly-set values may result in conflicts.""" ChrisA From python-oren at ben-kiki.org Mon Apr 3 02:10:25 2017 From: python-oren at ben-kiki.org (Oren Ben-Kiki) Date: Mon, 3 Apr 2017 09:10:25 +0300 Subject: Behavior of auto in Enum and Flag. In-Reply-To: References: Message-ID: While "the current behaviour is compliant with what the docs say" is true, saying "as such, I would be disinclined to change the code" misses the point. The current documentation allows for multiple behaviors. The current implementation has an chosen to add an arbitrary undocumented restriction on the behavior, which has a usability issue. Even worse, for no clear reason, the current implementation forces _all_ implementations to suffer from the same usability issue. The proposed behavior is _also_ compliant with the current documentation, and does not suffer from this usability issue. The proposed implementation is compatible with existing code bases, and allows for "any" other implementation to avoid this issue. That is, I think that instead of enshrining the current implementation's undocumented and arbitrary restriction, by explicitly adding it to the documentation, we should instead remove this arbitrary restriction from the implementation, and only modify the documentation to clarify this restriction is gone. Oren. On Mon, Apr 3, 2017 at 8:38 AM, Chris Angelico wrote: > On Mon, Apr 3, 2017 at 2:49 PM, Oren Ben-Kiki > wrote: > > "If the exact value is unimportant you may use auto instances and an > > appropriate value will be chosen for you." > > > > Choosing a value that conflicts with BAZ in above cases doesn't seem > > "appropriate" for a value that is "unimportant". > > > > The docs also state "Care must be taken if you mix auto with other > values." > > - fair enough. But: > > > > First, why require "care" if the code can take care of the issue for us? > > > > Second, the docs don't go into further detail about what exactly to > avoid. > > In particular, the docs do not state that the automatic value will only > > take into account the previous values, and will ignore following values. > > Sounds to me like the current behaviour is compliant with what the > docs say, and as such, I would be disinclined to change the code. > Perhaps a documentation clarification would suffice? > > """Care must be taken if you mix auto with other values. In > particular, using auto() prior to explicitly-set values may result in > conflicts.""" > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From dieter at handshake.de Mon Apr 3 02:35:01 2017 From: dieter at handshake.de (dieter) Date: Mon, 03 Apr 2017 08:35:01 +0200 Subject: Thread within for loop References: <87y3vky3k3.fsf@handshake.de> Message-ID: <8737dqov6y.fsf@handshake.de> Iranna Mathapati writes: > How to fix it and now i got below error for same script Fixing "timeout" problems is (usually) not a Python question. A "timeout" can have various reasons: * you make something fundamentally wrong - i.e. try to connect to something which is inaccessible (e.g. by "firewall" rules) You must check whether this is the case, e.g. by trying to access the server with other means as "pexpect". * the remote operation takes an extraordinary amount of time. You may need to adjust the "timeout" configuration used by the Python access library ("pexpect" in your case). Look at the documentation, to find out whether and how this is supported. * ... > *runtimeerror threads can only be started once then* Apparently, you try to start the same thread twice. Create different "Thread" instances, instead. > On Sat, Apr 1, 2017 at 1:15 PM, dieter wrote: > >> Iranna Mathapati writes: >> > ... >> > Exception in thread Thread-5: >> > Traceback (most recent call last): >> > ... >> > File >> > "/auto/n3k-qa/CODC/ianandan/pyATS2.7/lib/python2.7/site- >> packages/pexpect/__init__.py", >> > line 1466, in expect_list >> > timeout, searchwindowsize) >> > File >> > "/auto/n3k-qa/CODC/ianandan/pyATS2.7/lib/python2.7/site- >> packages/pexpect/__init__.py", >> > line 1568, in expect_loop >> > raise TIMEOUT(str(err) + '\n' + str(self)) >> > TIMEOUT: Timeout exceeded. >> >> "Timeout" means that the "pexpect" partner did not respond sufficiently >> fast. >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> From greg.ewing at canterbury.ac.nz Mon Apr 3 02:35:18 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 03 Apr 2017 18:35:18 +1200 Subject: Two variable dictionary comprehension In-Reply-To: References: <85mvbydxgx.fsf@benfinney.id.au> <001d01d2ac38$1c99c030$27b23dae@sambora> Message-ID: Deborah Swanson wrote: > Oh, come on. That's a fairly obscure citation in the docs, one that > would take a good deal of experience and time reading through them to > know was there, You seemed to know that there was something called a "dict comprehension". Googling for "python 3 dict comprehension" gives me a link to an example of one in the docs as the second result. The first result is a page in Dive Into Python containing a section on dict comprehensions. Part of being a good programmer is knowing how to track down the information you need! Having said that, the index of the Python docs could be improved a bit in this area -- currently it only mentions "list" under "comprehension" (although the page it leads to discusses the other types as well). -- Greg From ethan at stoneleaf.us Mon Apr 3 04:03:05 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 03 Apr 2017 01:03:05 -0700 Subject: Behavior of auto in Enum and Flag. In-Reply-To: References: Message-ID: <58E201B9.2020907@stoneleaf.us> On 04/02/2017 09:49 PM, Oren Ben-Kiki wrote: > The current behavior of `auto` is to pick a value which is one plus the > previous value. Starting with 1 if no previous value exists. > It would probably be better if `auto` instead picked a value that is not > used by any named member (either the minimal unused value, or the minimal > higher than the previous value). That is, in this simple case: > > class MyEnum(Enum): > FOO = 1 > BAR = auto() > BAZ = 2 > > It would be far better for BAR to get the value 3 rather than today's value > 2. Possibly. > After all, `auto` is supposed to be used when: > > "If the exact value is unimportant you may use auto instances and an > appropriate value will be chosen for you." > > Choosing a value that conflicts with BAZ in above cases doesn't seem > "appropriate" for a value that is "unimportant". MyEnum.BAR exists, and works. It just happens to be the same as MyEnum.BAZ -- which did not exist when the value for BAR was chosen. > The docs also state "Care must be taken if you mix auto with other values." > - fair enough. But: > > First, why require "care" if the code can take care of the issue for us? > > Second, the docs don't go into further detail about what exactly to avoid. > In particular, the docs do not state that the automatic value will only > take into account the previous values, and will ignore following values. Python code is executed top-down. First FOO, then BAR, then BAZ. It is not saved up and executed later in random order. Or, put another way, the value was appropriate when it was chosen -- it is not the fault of auto() that the user chose a conflicting value (hence why care should be taken). > However, this restriction is baked into the current implementation: > It is not possible to just override `_generate_next_value_` to skip past > named values which were not seen yet, because the implementation only > passes it the list of previous values. In other words, the currently existing values, because the future values don't exist yet. > I propose that: > > 1. The documentation will be more explicit about the way `auto` behaves in > the presence of following values. I can do that. > 2. The default behavior of `auto` would avoid generating a conflict with > following values. I could do that, but I'm not convinced it's necessary, plus there would be backwards compatibility constraints at this point. > 3. Whether `auto` chooses (A) the minimal unused value higher than the > previous value, or (B) the minimal overall unused value, or (C) some other > strategy, would depend on the specific implementation. This might work for you (untested): def _generate_next_value_(name, start, count, previous_values): if not count: return start or 1 previous_values.sort() last_value = previous_values[-1] if last_value < 1000: return 1001 else: return last_value + 1 > 3. To allow for this, the implementation will include a > `_generate_auto_value_` which will take both the list of previous ("last") > values (including auto values) and also a second list of the following > ("next") values (excluding auto values). No, I'm not interested in doing that. I currently have that kind of code in aenum[1] for 2.7 compatibility, and it's a nightmare to maintain. -- ~Ethan~ [1] https://pypi.python.org/pypi/aenum Advanced Enumerations NamedConstants NamedTuple (metaclass based namedtuple -- no code eval) plus a bunch of other goodies From cl at isbd.net Mon Apr 3 04:49:32 2017 From: cl at isbd.net (Chris Green) Date: Mon, 3 Apr 2017 09:49:32 +0100 Subject: Two variable dictionary comprehension References: <85mvbydxgx.fsf@benfinney.id.au> <001d01d2ac38$1c99c030$27b23dae@sambora> Message-ID: Gregory Ewing wrote: > > Part of being a good programmer is knowing how to track > down the information you need! > A very *large* part of it! :-) > Having said that, the index of the Python docs could be > improved a bit in this area -- currently it only mentions > "list" under "comprehension" (although the page it leads > to discusses the other types as well). > It's an area I tend to have trouble with, there are rather more 'lists' in Python than I find easy to remember all about. I'm sure if I was a full-time programmer in Python (I used to earn my living writing C) I'd have it all at my finger tips. Hoever, given that I'm just a 'recreational' programmer in Python, and I'm getting old and forgetful, I need something easy to refer to. -- Chris Green ? From malte.forkel at berlin.de Mon Apr 3 04:51:49 2017 From: malte.forkel at berlin.de (Malte Forkel) Date: Mon, 3 Apr 2017 10:51:49 +0200 Subject: Best practices interfacing to device with Python's asyncio and pyserial-asyncio Message-ID: Hello, I have written a Python package to read from and write to a serial device that uses short telegrams to communicate with sensors and actuators. My classes include one to model the transceiver (it establishes the serial connection using serial.aio.create_serial_connection) and one for the telegram protocol based on asyncio.Protocol. I also have a bunch of classes for the different types of telegrams and devices. While this all works, the device model and the protocol don't look very pythonic to me. Are there any tutorials or examples demonstrating best practices of how to do something like this? Thanks, Malte From python-oren at ben-kiki.org Mon Apr 3 04:53:51 2017 From: python-oren at ben-kiki.org (Oren Ben-Kiki) Date: Mon, 3 Apr 2017 11:53:51 +0300 Subject: Behavior of auto in Enum and Flag. In-Reply-To: <58E201B9.2020907@stoneleaf.us> References: <58E201B9.2020907@stoneleaf.us> Message-ID: On Mon, Apr 3, 2017 at 11:03 AM, Ethan Furman wrote: > Python code is executed top-down. First FOO, then BAR, then BAZ. It is > not saved up and executed later in random order. Or, put another way, the > value was appropriate when it was chosen -- it is not the fault of auto() > that the user chose a conflicting value (hence why care should be taken). This is not to say that there's no possible workaround for this - the code could pretty easily defer invocation of _generate_next_macro_ until after the whole class was seen. It would still happen in order (since members are an ordered dictionary these days). So it is a matter of conflicting values - what would be more "Pythonic": treating auto as executed immediately, or avoiding conflicts between auto and explicit values. > 1. The documentation will be more explicit about the way `auto` behaves in > the presence of following value > I can do that. > Barring changing the way auto works, that would be best ("explicit is better than implicit" and all that ;-) > 2. The default behavior of `auto` would avoid generating a conflict with >> following values. >> > > I could do that, but I'm not convinced it's necessary, plus there would be > backwards compatibility constraints at this point. "Necessity" depends on the judgement call above. As for backward compatibility, the docs are pretty clear about "use auto when you don't care about the value"... and Enum is pretty new, so there's not _that_ much code that relies on "implementation specific" details. *If* backward compatibility is an issue here, then the docs might as well specify "previous value plus 1, or 1 if this is the first value" as the "standard" behavior, and be done. This has the advantage of being deterministic and explicit, so people would be justified in relying on it. It would still have to be accompanied by saying "auto() can only consider previous values, not following ones". > This might work for you (untested): > > def _generate_next_value_(name, start, count, previous_values): > if not count: > return start or 1 > previous_values.sort() > last_value = previous_values[-1] > if last_value < 1000: > return 1001 > else: > return last_value + 1 This assumes no following enum values have values > 1000 (or some predetermined constant), which doesn't work in my particular case, or in the general case. But yes, this might solve the problem for some people. > 3. To allow for this, the implementation will include a >> `_generate_auto_value_` which will take both the list of previous ("last") >> values (including auto values) and also a second list of the following >> ("next") values (excluding auto values). >> > > No, I'm not interested in doing that. I currently have that kind of code > in aenum[1] for 2.7 compatibility, and it's a nightmare to maintain. > Understood. Another alternative would be to have something like _generate_next_value_ex_ with the additional argument (similar to __reduce_ex__), which isn't ideal either. Assuming you buy into my "necessity" claim, that is... Thanks, Oren. From info at egenix.com Mon Apr 3 05:01:26 2017 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Mon, 3 Apr 2017 11:01:26 +0200 Subject: =?UTF-8?Q?ANN:_Python_Meeting_D=c3=bcsseldorf_-_05.04.2017?= Message-ID: <01117355-2c8d-c6cb-b1e6-88dba669a4a1@egenix.com> [This announcement is in German since it targets a local user group meeting in D?sseldorf, Germany] ________________________________________________________________________ ANK?NDIGUNG Python Meeting D?sseldorf http://pyddf.de/ Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosph?re. Mittwoch, 05.04.2017, 18:00 Uhr Raum 1, 2.OG im B?rgerhaus Stadtteilzentrum Bilk D?sseldorfer Arcaden, Bachstr. 145, 40217 D?sseldorf Diese Nachricht ist auch online verf?gbar: http://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2017-04-05 ________________________________________________________________________ NEUIGKEITEN * Bereits angemeldete Vortr?ge: Stefan Richthofer "pytypes" Andr? Aulich "Python-Webanwendungen als native Desktop-Apps verteilen" Charlie Clark "Frankenstein ? OO-Komposition statt Vererbung" Weitere Vortr?ge k?nnen gerne noch angemeldet werden: info at pyddf.de * Startzeit und Ort: Wir treffen uns um 18:00 Uhr im B?rgerhaus in den D?sseldorfer Arcaden. Das B?rgerhaus teilt sich den Eingang mit dem Schwimmbad und befindet sich an der Seite der Tiefgarageneinfahrt der D?sseldorfer Arcaden. ?ber dem Eingang steht ein gro?es "Schwimm' in Bilk" Logo. Hinter der T?r direkt links zu den zwei Aufz?gen, dann in den 2. Stock hochfahren. Der Eingang zum Raum 1 liegt direkt links, wenn man aus dem Aufzug kommt. Google Street View: http://bit.ly/11sCfiw ________________________________________________________________________ EINLEITUNG Das Python Meeting D?sseldorf ist eine regelm??ige Veranstaltung in D?sseldorf, die sich an Python Begeisterte aus der Region wendet: * http://pyddf.de/ Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: * http://www.youtube.com/pyddf/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: * http://www.egenix.com/ * http://www.clark-consulting.eu/ ________________________________________________________________________ PROGRAMM Das Python Meeting D?sseldorf nutzt eine Mischung aus (Lightning) Talks und offener Diskussion. Vortr?ge k?nnen vorher angemeldet werden, oder auch spontan w?hrend des Treffens eingebracht werden. Ein Beamer mit XGA Aufl?sung steht zur Verf?gung. (Lightning) Talk Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ KOSTENBETEILIGUNG Das Python Meeting D?sseldorf wird von Python Nutzern f?r Python Nutzer veranstaltet. Um die Kosten zumindest teilweise zu refinanzieren, bitten wir die Teilnehmer um einen Beitrag in H?he von EUR 10,00 inkl. 19% Mwst, Sch?ler und Studenten zahlen EUR 5,00 inkl. 19% Mwst. Wir m?chten alle Teilnehmer bitten, den Betrag in bar mitzubringen. ________________________________________________________________________ ANMELDUNG Da wir nur f?r ca. 20 Personen Sitzpl?tze haben, m?chten wir bitten, sich per EMail anzumelden. Damit wird keine Verpflichtung eingegangen. Es erleichtert uns allerdings die Planung. Meeting Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ WEITERE INFORMATIONEN Weitere Informationen finden Sie auf der Webseite des Meetings: http://pyddf.de/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Apr 03 2017) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> Python Database Interfaces ... http://products.egenix.com/ >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/ From p.f.moore at gmail.com Mon Apr 3 05:08:43 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 3 Apr 2017 02:08:43 -0700 (PDT) Subject: SocketServer and Ctrl-C on Windows Message-ID: <088d6b0f-9654-43a0-9536-b4a551209a58@googlegroups.com> I know I've seen this before, but for the life of me I can't find any reference. If I write a simple web server using wsgiref, something like from wsgiref.simple_server import make_server, demo_app with make_server('', 8000, demo_app) as httpd: print("Serving HTTP on port 8000...") # Respond to requests until process is killed httpd.serve_forever() (from the docs), then run it on Windows, the server won't respond to Ctrl-C. I know I've seen a solution that traps ctrl-C and shuts the server down gracefully, but I can't for the life of me remember how to do it. Can anyone point me to a way to do this? It's not crucial - I can use Ctrl-Break to stop the server - but I'd like an option for a clean shutdown if possible. Thanks, Paul From ammammata at tiscalinet.it Mon Apr 3 05:39:19 2017 From: ammammata at tiscalinet.it (Ammammata) Date: Mon, 3 Apr 2017 09:39:19 +0000 (UTC) Subject: Spam user References: <058a9744-44bf-4e6b-ae1d-28e1e348e60b@googlegroups.com> Message-ID: Il giorno Sat 01 Apr 2017 09:15:41p, *Mario R. Osorio* ha inviato su comp.lang.python il messaggio news:d0e9d036-2924-4c2c-99b1-0d8cb02b93df at googlegroups.com. Vediamo cosa ha scritto: > I'm not in the business of starting an argument about best/worse > newsreader, Ammammata, but could you please recommend a few? > not my intention, I just think a dedicated news *program* is better than the google *web interface* and gives you more filter tools here I'm using xnews, but I have also mesnews configured (for stats) as well as pan for windows (for other uses) at home I use pan (on linux) on the tablet I use a chinese piece of software, can't remember the name sorry, but it's in the playstore -- /-\ /\/\ /\/\ /-\ /\/\ /\/\ /-\ T /-\ -=- -=- -=- -=- -=- -=- -=- -=- - -=- >>>>> http://www.bb2002.it :) <<<<< ........... [ al lavoro ] ........... From eryksun at gmail.com Mon Apr 3 08:22:09 2017 From: eryksun at gmail.com (eryk sun) Date: Mon, 3 Apr 2017 12:22:09 +0000 Subject: SocketServer and Ctrl-C on Windows In-Reply-To: <088d6b0f-9654-43a0-9536-b4a551209a58@googlegroups.com> References: <088d6b0f-9654-43a0-9536-b4a551209a58@googlegroups.com> Message-ID: On Mon, Apr 3, 2017 at 9:08 AM, Paul Moore wrote: > I know I've seen this before, but for the life of me I can't find any reference. > > If I write a simple web server using wsgiref, something like > > from wsgiref.simple_server import make_server, demo_app > > with make_server('', 8000, demo_app) as httpd: > print("Serving HTTP on port 8000...") > > # Respond to requests until process is killed > httpd.serve_forever() > > (from the docs), then run it on Windows, the server won't respond to Ctrl-C. I > know I've seen a solution that traps ctrl-C and shuts the server down gracefully, > but I can't for the life of me remember how to do it. > > Can anyone point me to a way to do this? It's not crucial - I can use Ctrl-Break to > stop the server - but I'd like an option for a clean shutdown if possible. It works for me when run from a command prompt in Windows 10. serve_forever() uses select() with a timeout of 0.5s, so it doesn't block the main thread. From p.f.moore at gmail.com Mon Apr 3 08:34:56 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 3 Apr 2017 05:34:56 -0700 (PDT) Subject: SocketServer and Ctrl-C on Windows In-Reply-To: References: <088d6b0f-9654-43a0-9536-b4a551209a58@googlegroups.com> Message-ID: <0874481d-67ca-4b5f-986a-c92d04a88d9b@googlegroups.com> On Monday, 3 April 2017 13:23:11 UTC+1, eryk sun wrote: > It works for me when run from a command prompt in Windows 10. > serve_forever() uses select() with a timeout of 0.5s, so it doesn't > block the main thread. Odd. For me, it doesn't work (Windows 7, but I can't see why that would affect it). Having investigated a bit more, it seems like if I just start the server then hit Ctrl-C it shuts down fine. But if I start the server, then I navigate to http://localhost:8000 in my browser, and *then* hit Ctrl-C, the server just continues running. So I don't know if it's something to do with having handled a request? I have a vague recollection that it's to do with threading - maybe the exception being delivered to the wrong thread? Or a non-daemon thread being left active? Thanks for checking for me, though. Paul From lyngwyst at gmail.com Mon Apr 3 08:40:37 2017 From: lyngwyst at gmail.com (Jay Braun) Date: Mon, 3 Apr 2017 05:40:37 -0700 (PDT) Subject: "pandas" pronunciation Message-ID: I hear people say it like the plural of "panda", and others as "panduss". Is there a correct way? j From eryksun at gmail.com Mon Apr 3 08:59:18 2017 From: eryksun at gmail.com (eryk sun) Date: Mon, 3 Apr 2017 12:59:18 +0000 Subject: SocketServer and Ctrl-C on Windows In-Reply-To: <0874481d-67ca-4b5f-986a-c92d04a88d9b@googlegroups.com> References: <088d6b0f-9654-43a0-9536-b4a551209a58@googlegroups.com> <0874481d-67ca-4b5f-986a-c92d04a88d9b@googlegroups.com> Message-ID: On Mon, Apr 3, 2017 at 12:34 PM, Paul Moore wrote: > On Monday, 3 April 2017 13:23:11 UTC+1, eryk sun wrote: >> It works for me when run from a command prompt in Windows 10. >> serve_forever() uses select() with a timeout of 0.5s, so it doesn't >> block the main thread. > > Odd. For me, it doesn't work (Windows 7, but I can't see why that would affect it). > > Having investigated a bit more, it seems like if I just start the server then hit Ctrl-C > it shuts down fine. But if I start the server, then I navigate to http://localhost:8000 in > my browser, and *then* hit Ctrl-C, the server just continues running. It should service the request and return to the serve_forever() loop. Do you see a line logged for each request, like "[IP] - - [date] "GET ..."? From p.f.moore at gmail.com Mon Apr 3 09:20:25 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 3 Apr 2017 06:20:25 -0700 (PDT) Subject: SocketServer and Ctrl-C on Windows In-Reply-To: References: <088d6b0f-9654-43a0-9536-b4a551209a58@googlegroups.com> <0874481d-67ca-4b5f-986a-c92d04a88d9b@googlegroups.com> Message-ID: <14b1d06a-1ded-4e79-a0a8-525ceb4d7891@googlegroups.com> On Monday, 3 April 2017 14:00:18 UTC+1, eryk sun wrote: > It should service the request and return to the serve_forever() loop. > Do you see a line logged for each request, like "[IP] - - [date] "GET > ..."? Yes, I see that and the page is served. >py .\example.py Serving HTTP on port 8000... 127.0.0.1 - - [03/Apr/2017 13:25:34] "GET / HTTP/1.1" 200 5470 127.0.0.1 - - [03/Apr/2017 13:25:34] "GET /favicon.ico HTTP/1.1" 200 5438 But if I press Ctrl-C at this point, nothing happens. Even if I press Ctrl-C multiple times. Paul From chololennon at hotmail.com Mon Apr 3 09:28:12 2017 From: chololennon at hotmail.com (Cholo Lennon) Date: Mon, 3 Apr 2017 10:28:12 -0300 Subject: Spam user References: <058a9744-44bf-4e6b-ae1d-28e1e348e60b@googlegroups.com> Message-ID: On 01/04/17 16:15, Mario R. Osorio wrote: > I'm not in the business of starting an argument about best/worse newsreader, Ammammata, but could you please recommend a few? > Mozilla Thunderbird works very well. Spam is close to nothing using this free nntp server: news.aioe.org Regards -- Cholo Lennon Bs.As. ARG From kenneth.buckler at gmail.com Mon Apr 3 09:49:45 2017 From: kenneth.buckler at gmail.com (Kenneth Buckler) Date: Mon, 3 Apr 2017 09:49:45 -0400 Subject: Obtain Ceritificate Information from Invalid or Self-Signed Certificate in Python Message-ID: I'm working on a Python 2.7.13 (Win x64) script to verify SSL certificates, and alert for problems. Specifically, I'm looking to return the date the cert expires or did expire. However, I'm running into an issue where the script will return information only if the certificate is valid. If the certificate is invalid, I receive a CERTIFICATE_VERIFY_FAILED SSL error. Normally I would simply use a try/catch when the error is raised and just alert that the cert is invalid, but the issue here is that the I need the actual date the certificate expired, or in some cases the cert will be a self-signed cert, which will be acceptable UNLESS the cert is expired. I'm dealing with an organization that has thousands of certs, so adding every single self signed cert to the cert store locally won't be an option. Per https://docs.python.org/2/library/ssl.html I tried to use conn._https_verify_certificates(enable=False) to disable certificate validation, but get an error that the attribute _https_verify_certificates doesn't exist. Here is my code so far. I'm sure I'm missing something obvious. Surely Python can pull the SSL certificate without validating it, right? import socketimport ssl def ssl_expiry_datetime(hostname): ssl_date_fmt = r'%b %d %H:%M:%S %Y %Z' context = ssl.create_default_context() conn = context.wrap_socket( socket.socket(socket.AF_INET), server_hostname=hostname, ) # 3 second timeout because Lambda has runtime limitations conn.settimeout(3.0) #conn._https_verify_certificates(enable=False) conn.connect((hostname, 443)) ssl_info = conn.getpeercert() # parse the string from the certificate into a Python datetime object return ['notAfter'] myhost = 'www.google.com' print ssl_expiry_datetime(myhost) Thanks! Ken From mal at europython.eu Mon Apr 3 09:50:22 2017 From: mal at europython.eu (M.-A. Lemburg) Date: Mon, 3 Apr 2017 15:50:22 +0200 Subject: EuroPython 2017: Launching early-bird sales tomorrow Message-ID: <2475e252-cc09-0646-4cf3-c09c1399fb83@europython.eu> We are starting ticket sales tomorrow and, as is tradition, we have allocated a number of tickets to be sold at very low rates - in fact you can save between 40-50% on these early-bird rates, compared to the regular ticket prices. Sales at the early-bird rate will open tomorrow, April 4th, at 10:00 CEST We will have 200 tickets available at the early-bird rate and they usually sell out within a few days, so be sure to get yours quickly. Regular ticket sales will then commence shortly after the early-bird phase. Please see our registration page for full details: https://ep2017.europython.eu/en/registration/buy-tickets/ Enjoy, -- EuroPython 2017 Team http://ep2017.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/848894062715437057 Thanks. From p.f.moore at gmail.com Mon Apr 3 09:56:21 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 3 Apr 2017 06:56:21 -0700 (PDT) Subject: SocketServer and Ctrl-C on Windows In-Reply-To: <14b1d06a-1ded-4e79-a0a8-525ceb4d7891@googlegroups.com> References: <088d6b0f-9654-43a0-9536-b4a551209a58@googlegroups.com> <0874481d-67ca-4b5f-986a-c92d04a88d9b@googlegroups.com> <14b1d06a-1ded-4e79-a0a8-525ceb4d7891@googlegroups.com> Message-ID: <0ea8bd26-ecd3-4c7d-a939-00077a912912@googlegroups.com> On Monday, 3 April 2017 14:20:43 UTC+1, Paul Moore wrote: > On Monday, 3 April 2017 14:00:18 UTC+1, eryk sun wrote: > > It should service the request and return to the serve_forever() loop. > > Do you see a line logged for each request, like "[IP] - - [date] "GET > > ..."? > > Yes, I see that and the page is served. > > >py .\example.py > Serving HTTP on port 8000... > 127.0.0.1 - - [03/Apr/2017 13:25:34] "GET / HTTP/1.1" 200 5470 > 127.0.0.1 - - [03/Apr/2017 13:25:34] "GET /favicon.ico HTTP/1.1" 200 5438 > > But if I press Ctrl-C at this point, nothing happens. Even if I press Ctrl-C multiple times. Hmm, looks like sometimes it works. I wonder if the browser is holding open the page request somehow. That seems unlikely as HTTP is supposed to be stateless. I guess this isn't worth worrying about. It seems like it's only an occasional problem, and I have a workaround (Ctrl-Break) anyway. Paul From eryksun at gmail.com Mon Apr 3 09:58:31 2017 From: eryksun at gmail.com (eryk sun) Date: Mon, 3 Apr 2017 13:58:31 +0000 Subject: SocketServer and Ctrl-C on Windows In-Reply-To: <14b1d06a-1ded-4e79-a0a8-525ceb4d7891@googlegroups.com> References: <088d6b0f-9654-43a0-9536-b4a551209a58@googlegroups.com> <0874481d-67ca-4b5f-986a-c92d04a88d9b@googlegroups.com> <14b1d06a-1ded-4e79-a0a8-525ceb4d7891@googlegroups.com> Message-ID: On Mon, Apr 3, 2017 at 1:20 PM, Paul Moore wrote: > On Monday, 3 April 2017 14:00:18 UTC+1, eryk sun wrote: >> It should service the request and return to the serve_forever() loop. >> Do you see a line logged for each request, like "[IP] - - [date] "GET >> ..."? > > Yes, I see that and the page is served. > >>py .\example.py > Serving HTTP on port 8000... > 127.0.0.1 - - [03/Apr/2017 13:25:34] "GET / HTTP/1.1" 200 5470 > 127.0.0.1 - - [03/Apr/2017 13:25:34] "GET /favicon.ico HTTP/1.1" 200 5438 > > But if I press Ctrl-C at this point, nothing happens. Even if I press Ctrl-C multiple times. Try adding a low-level console control handler that shuts down the server. For example: import sys import ctypes from wsgiref.simple_server import make_server, demo_app kernel32 = ctypes.WinDLL('kernel32', use_last_error=True) CTRL_C_EVENT = 0 with make_server('', 8000, demo_app) as httpd: print("Serving HTTP on port 8000...") @ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_uint) def ctrl_handler(dwCtrlType): if dwCtrlType == CTRL_C_EVENT: print("Ctrl+C shutdown", file=sys.stderr) httpd.shutdown() return False if not kernel32.SetConsoleCtrlHandler(ctrl_handler, True): raise ctypes.WinError(ctypes.get_last_error()) # Respond to requests until process is killed httpd.serve_forever() From rosuav at gmail.com Mon Apr 3 10:09:58 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Apr 2017 00:09:58 +1000 Subject: SocketServer and Ctrl-C on Windows In-Reply-To: <0ea8bd26-ecd3-4c7d-a939-00077a912912@googlegroups.com> References: <088d6b0f-9654-43a0-9536-b4a551209a58@googlegroups.com> <0874481d-67ca-4b5f-986a-c92d04a88d9b@googlegroups.com> <14b1d06a-1ded-4e79-a0a8-525ceb4d7891@googlegroups.com> <0ea8bd26-ecd3-4c7d-a939-00077a912912@googlegroups.com> Message-ID: On Mon, Apr 3, 2017 at 11:56 PM, Paul Moore wrote: > On Monday, 3 April 2017 14:20:43 UTC+1, Paul Moore wrote: >> On Monday, 3 April 2017 14:00:18 UTC+1, eryk sun wrote: >> > It should service the request and return to the serve_forever() loop. >> > Do you see a line logged for each request, like "[IP] - - [date] "GET >> > ..."? >> >> Yes, I see that and the page is served. >> >> >py .\example.py >> Serving HTTP on port 8000... >> 127.0.0.1 - - [03/Apr/2017 13:25:34] "GET / HTTP/1.1" 200 5470 >> 127.0.0.1 - - [03/Apr/2017 13:25:34] "GET /favicon.ico HTTP/1.1" 200 5438 >> >> But if I press Ctrl-C at this point, nothing happens. Even if I press Ctrl-C multiple times. > > Hmm, looks like sometimes it works. I wonder if the browser is holding open the page request somehow. That seems unlikely as HTTP is supposed to be stateless. > You're getting HTTP/1.1 requests. Maybe you need to send a "Connection: close" header to tell the browser to leave you be? ChrisA From python at deborahswanson.net Mon Apr 3 10:30:40 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Mon, 3 Apr 2017 07:30:40 -0700 Subject: Two variable dictionary comprehension In-Reply-To: Message-ID: <007401d2ac86$dee57320$27b23dae@sambora> Gregory Ewing wrote, on April 02, 2017 11:35 PM > > Deborah Swanson wrote: > > > Oh, come on. That's a fairly obscure citation in the docs, one that > > would take a good deal of experience and time reading > through them to > > know was there, > > You seemed to know that there was something called a "dict > comprehension". Googling for "python 3 dict comprehension" > gives me a link to an example of one in the docs as the second result. > > The first result is a page in Dive Into Python containing > a section on dict comprehensions. > > Part of being a good programmer is knowing how to track > down the information you need! > > Having said that, the index of the Python docs could be > improved a bit in this area -- currently it only mentions > "list" under "comprehension" (although the page it leads to > discusses the other types as well). > > -- > Greg Despite my earlier words and protestations that I did look for two variable dict comprehensions, fairly diligently, I am taking what you said seriously. Obviously I shouldn't expect to find handy and recognizable entries in the index for everything I might want to find in the docs, and I plan to spend more time browsing around. Clearly there's more to be found in nooks, crannies and byways in the docs than you'll get to from the given pointers in the index. Maybe it would be worthwhile to scrape the whole mess and have it in searchable text form. Another thing Python would be the right tool for the job for. Regular updates as the docs are updated would be a good idea too. It's obvious that today's Google isn't up to it, although it occurs to me that I haven't tried Google's site search on python.org. I hope you won't be miffed though if I still come up empty handed and come back here to ask again. Deborah From p.f.moore at gmail.com Mon Apr 3 10:34:42 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 3 Apr 2017 07:34:42 -0700 (PDT) Subject: SocketServer and Ctrl-C on Windows In-Reply-To: References: <088d6b0f-9654-43a0-9536-b4a551209a58@googlegroups.com> <0874481d-67ca-4b5f-986a-c92d04a88d9b@googlegroups.com> <14b1d06a-1ded-4e79-a0a8-525ceb4d7891@googlegroups.com> <0ea8bd26-ecd3-4c7d-a939-00077a912912@googlegroups.com> Message-ID: <1f67125a-5c30-457a-9414-bcbabba39559@googlegroups.com> On Monday, 3 April 2017 15:10:12 UTC+1, Chris Angelico wrote: > You're getting HTTP/1.1 requests. Maybe you need to send a > "Connection: close" header to tell the browser to leave you be? That sounds possible - I don't really know enough about HTTP to even know that was a thing, so I'm not surprised if I got it wrong. My test harness is using a Bottle server, which (apparently) actively gets in the way of setting this header, so I'll have to do a bit more work to confirm this, but it certainly seems like a good lead. Paul From prathamesh.nimkar at gmail.com Mon Apr 3 12:11:49 2017 From: prathamesh.nimkar at gmail.com (Prathamesh) Date: Mon, 3 Apr 2017 09:11:49 -0700 (PDT) Subject: Improve Python + Influxdb import performance Message-ID: <104d49b4-da8c-4b23-a520-3042c9d91a3d@googlegroups.com> Hello World The following script is an extract from https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py <> import calendar, time import sys import getopt print '---------------------------------------' # Check the arguments to this script are as expected. # argv[0] is script name. argLen = len(sys.argv) if argLen -1 < 2: print "ERROR: got ", argLen -1, " args, must be at least two." print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py [] [] [] [] [targetDB influx db>' exit() outputFormat='CSV' url='t3://localhost:7001' targetHost='localhost' targetDB='obi' targetPort='8086' try: wls_user = sys.argv[1] wls_pw = sys.argv[2] url = sys.argv[3] outputFormat=sys.argv[4] targetHost=sys.argv[5] targetPort=sys.argv[6] targetDB=sys.argv[7] except: print '' print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB now_epoch = calendar.timegm(time.gmtime())*1000 if outputFormat=='InfluxDB': import httplib influx_msgs='' connect(wls_user,wls_pw,url) results = displayMetricTables('Oracle_BI*','dms_cProcessInfo') for table in results: tableName = table.get('Table') rows = table.get('Rows') rowCollection = rows.values() iter = rowCollection.iterator() while iter.hasNext(): row = iter.next() rowType = row.getCompositeType() keys = rowType.keySet() keyIter = keys.iterator() inst_name= row.get('Name').replace(' ','-') try: server= row.get('Servername').replace(' ','-').replace('/','_') except: try: server= row.get('ServerName').replace(' ','-').replace('/','_') except: server='unknown' try: host= row.get('Host').replace(' ','-') except: host='' while keyIter.hasNext(): columnName = keyIter.next() value = row.get(columnName ) if columnName.find('.value')>0: metric_name=columnName.replace('.value','') if value is not None: if value != 0: if outputFormat=='InfluxDB': influx_msg= ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % (metric_name,server,host,tableName,inst_name, value,now_epoch*1000000) influx_msgs+='\n%s' % influx_msg conn = httplib.HTTPConnection('%s:%s' % (targetHost,targetPort)) ## TODO pretty sure should be urlencoding this ... a=conn.request("POST", ("/write?db=%s" % targetDB), influx_msg) r=conn.getresponse() <> It currently takes about 3 minutes to execute completely and I was thinking of a way to make it run faster Data alignment (Influx line protocol) & data loading - done together takes up most of the time Influxdb is currently loading data at around 3 points/second Any way to align the data separately, store it and load it as a batch? I feel that would help improve performance Please let me know if you have any pointers I can send the data sheet if required Thanks P From songofacandy at gmail.com Mon Apr 3 12:22:04 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Tue, 4 Apr 2017 01:22:04 +0900 Subject: Improve Python + Influxdb import performance In-Reply-To: <104d49b4-da8c-4b23-a520-3042c9d91a3d@googlegroups.com> References: <104d49b4-da8c-4b23-a520-3042c9d91a3d@googlegroups.com> Message-ID: You can reuse connection, instead of creating for each request. (HTTP keep-alive). On Tue, Apr 4, 2017 at 1:11 AM, Prathamesh wrote: > Hello World > > The following script is an extract from > > https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py > > <> > > import calendar, time > import sys > import getopt > > print '---------------------------------------' > > # Check the arguments to this script are as expected. > # argv[0] is script name. > argLen = len(sys.argv) > if argLen -1 < 2: > print "ERROR: got ", argLen -1, " args, must be at least two." > print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py [] [] [] [] [targetDB influx db>' > exit() > > outputFormat='CSV' > url='t3://localhost:7001' > targetHost='localhost' > targetDB='obi' > targetPort='8086' > > try: > wls_user = sys.argv[1] > wls_pw = sys.argv[2] > url = sys.argv[3] > outputFormat=sys.argv[4] > targetHost=sys.argv[5] > targetPort=sys.argv[6] > targetDB=sys.argv[7] > except: > print '' > > print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB > > now_epoch = calendar.timegm(time.gmtime())*1000 > > if outputFormat=='InfluxDB': > import httplib > influx_msgs='' > > connect(wls_user,wls_pw,url) > results = displayMetricTables('Oracle_BI*','dms_cProcessInfo') > for table in results: > tableName = table.get('Table') > rows = table.get('Rows') > rowCollection = rows.values() > iter = rowCollection.iterator() > while iter.hasNext(): > row = iter.next() > rowType = row.getCompositeType() > keys = rowType.keySet() > keyIter = keys.iterator() > inst_name= row.get('Name').replace(' ','-') > try: > server= row.get('Servername').replace(' ','-').replace('/','_') > except: > try: > server= row.get('ServerName').replace(' ','-').replace('/','_') > except: > server='unknown' > try: > host= row.get('Host').replace(' ','-') > except: > host='' > while keyIter.hasNext(): > columnName = keyIter.next() > value = row.get(columnName ) > if columnName.find('.value')>0: > metric_name=columnName.replace('.value','') > if value is not None: > if value != 0: > if outputFormat=='InfluxDB': > influx_msg= ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % (metric_name,server,host,tableName,inst_name, value,now_epoch*1000000) > influx_msgs+='\n%s' % influx_msg > conn = httplib.HTTPConnection('%s:%s' % (targetHost,targetPort)) > ## TODO pretty sure should be urlencoding this ... > a=conn.request("POST", ("/write?db=%s" % targetDB), influx_msg) > r=conn.getresponse() > > <> > > It currently takes about 3 minutes to execute completely and I was thinking of a way to make it run faster > > Data alignment (Influx line protocol) & data loading - done together takes up most of the time > > Influxdb is currently loading data at around 3 points/second > > Any way to align the data separately, store it and load it as a batch? > > I feel that would help improve performance > > Please let me know if you have any pointers > I can send the data sheet if required > > Thanks P > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Mon Apr 3 12:26:30 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Apr 2017 02:26:30 +1000 Subject: SocketServer and Ctrl-C on Windows In-Reply-To: <1f67125a-5c30-457a-9414-bcbabba39559@googlegroups.com> References: <088d6b0f-9654-43a0-9536-b4a551209a58@googlegroups.com> <0874481d-67ca-4b5f-986a-c92d04a88d9b@googlegroups.com> <14b1d06a-1ded-4e79-a0a8-525ceb4d7891@googlegroups.com> <0ea8bd26-ecd3-4c7d-a939-00077a912912@googlegroups.com> <1f67125a-5c30-457a-9414-bcbabba39559@googlegroups.com> Message-ID: On Tue, Apr 4, 2017 at 12:34 AM, Paul Moore wrote: > On Monday, 3 April 2017 15:10:12 UTC+1, Chris Angelico wrote: >> You're getting HTTP/1.1 requests. Maybe you need to send a >> "Connection: close" header to tell the browser to leave you be? > > That sounds possible - I don't really know enough about HTTP to even know that was a thing, so I'm not surprised if I got it wrong. > > My test harness is using a Bottle server, which (apparently) actively gets in the way of setting this header, so I'll have to do a bit more work to confirm this, but it certainly seems like a good lead. An alternative way to diagnose this would be to see if you still have an established socket connection. I'm not sure how you do that on Windows, but it'd be a good thing to check. ChrisA From ethan at stoneleaf.us Mon Apr 3 12:29:50 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 03 Apr 2017 09:29:50 -0700 Subject: Behavior of auto in Enum and Flag. In-Reply-To: References: <58E201B9.2020907@stoneleaf.us> Message-ID: <58E2787E.7030408@stoneleaf.us> On 04/03/2017 01:53 AM, Oren Ben-Kiki wrote: > On Mon, Apr 3, 2017 at 11:03 AM, Ethan Furman wrote: > >> Python code is executed top-down. First FOO, then BAR, then BAZ. It is not saved up and executed later in random >> order. Or, put another way, the value was appropriate when it was chosen -- it is not the fault of auto() that the >> user chose a conflicting value (hence why care should be taken). > > This is not to say that there's no possible workaround for this - the code could pretty easily defer invocation of > _generate_next_macro_ until after the whole class was seen. It would still happen in order (since members are an ordered > dictionary these days). Possible, yes. Easy, no. > So it is a matter of conflicting values - what would be more "Pythonic": treating auto as executed immediately, or > avoiding conflicts between auto and explicit values. Since most things execute immediately, that is the pattern I chose. >>> 1. The documentation will be more explicit about the way `auto` behaves in the presence of following value >> >> I can do that. > > Barring changing the way auto works, that would be best ("explicit is better than implicit" and all that ;-) > As for backward compatibility, the docs are pretty clear about "use auto when you don't care about the value"... and > Enum is pretty new, so there's not _that_ much code that relies on "implementation specific" details. Fair point. > *If* backward compatibility is an issue here, then the docs might as well specify "previous value plus 1, or 1 if this > is the first value" as the "standard" behavior, and be done. Actually, (Int)Flag uses the next power of two (not already seen) -- so it isn't as easy as "last value + 1". > This has the advantage of being deterministic and explicit, so people would be justified in relying on it. It would > still have to be accompanied by saying "auto() can only consider previous values, not following ones". Something to that effect sounds good. > This might work for you (untested): > > def _generate_next_value_(name, start, count, previous_values): > if not count: > return start or 1 > previous_values.sort() > last_value = previous_values[-1] > if last_value < 1000: > return 1001 > else: > return last_value + 1 > > > This assumes no following enum values have values > 1000 (or some predetermined constant), which doesn't work in my > particular case, or in the general case. But yes, this might solve the problem for some people. General code isn't going to "do what I need" 100% of the time for 100% of the people. That's why I made the _generate_next_value_ method user over-ridable >>> 3. To allow for this, the implementation will include a >>> `_generate_auto_value_` which will take both the list of previous ("last") >>> values (including auto values) and also a second list of the following >>> ("next") values (excluding auto values). >> >> No, I'm not interested in doing that. I currently have that kind of code in aenum[1] for 2.7 compatibility, and >> it's a nightmare to maintain. > > Understood. Another alternative would be to have something like _generate_next_value_ex_ with the additional argument > (similar to __reduce_ex__), which isn't ideal either. It's a lot more work than just making another method. > Assuming you buy into my "necessity" claim, that is... It this point I do not. If you can give us an example Enum and why it's necessary to be built like that I might be swayed -- although the odds are good that the change will go into aenum instead (it's already a mess with the 2.7 compatibility code...). > Thanks, You're welcome. -- ~Ethan~ From rosuav at gmail.com Mon Apr 3 12:43:23 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Apr 2017 02:43:23 +1000 Subject: Behavior of auto in Enum and Flag. In-Reply-To: <58E2787E.7030408@stoneleaf.us> References: <58E201B9.2020907@stoneleaf.us> <58E2787E.7030408@stoneleaf.us> Message-ID: On Tue, Apr 4, 2017 at 2:29 AM, Ethan Furman wrote: > It this point I do not. If you can give us an example Enum and why it's > necessary to be built like that I might be swayed -- although the odds are > good that the change will go into aenum instead (it's already a mess with > the 2.7 compatibility code...). Here's a counter-example that supports the current behaviour: >>> from enum import IntFlag, auto >>> class Spam(IntFlag): ... FOO = auto() ... BAR = auto() ... FOOBAR = FOO | BAR ... SPAM = auto() ... HAM = auto() ... SPAMHAM = SPAM | HAM ... >>> list(Spam) [, , , , , ] It makes perfect sense to define combined flags in terms of the (previously-defined) individual flags. If auto() has to be deferred until the class is fully defined, this would be a lot harder. ChrisA From python-oren at ben-kiki.org Mon Apr 3 13:01:29 2017 From: python-oren at ben-kiki.org (Oren Ben-Kiki) Date: Mon, 3 Apr 2017 20:01:29 +0300 Subject: Behavior of auto in Enum and Flag. In-Reply-To: References: <58E201B9.2020907@stoneleaf.us> <58E2787E.7030408@stoneleaf.us> Message-ID: On Mon, Apr 3, 2017 at 7:43 PM, Chris Angelico wrote: > Here's a counter-example that supports the current behaviour: > > >>> from enum import IntFlag, auto > >>> class Spam(IntFlag): > ... FOO = auto() > ... BAR = auto() > ... FOOBAR = FOO | BAR > ... SPAM = auto() > ... HAM = auto() > ... SPAMHAM = SPAM | HAM > ... > Ugh, good point - I didn't consider that use case, I see how it would be nasty to implement. I guess just improving the documentation is called for, then... Thanks, Oren. From prathamesh.nimkar at gmail.com Mon Apr 3 13:03:47 2017 From: prathamesh.nimkar at gmail.com (Prathamesh) Date: Mon, 3 Apr 2017 10:03:47 -0700 (PDT) Subject: Improve Python + Influxdb import performance In-Reply-To: References: <104d49b4-da8c-4b23-a520-3042c9d91a3d@googlegroups.com> Message-ID: <2b086408-d176-42fd-9b15-be0aa19c584d@googlegroups.com> On Monday, April 3, 2017 at 9:52:38 PM UTC+5:30, INADA Naoki wrote: > You can reuse connection, instead of creating for each request. (HTTP > keep-alive). > > On Tue, Apr 4, 2017 at 1:11 AM, Prathamesh wrote: > > Hello World > > > > The following script is an extract from > > > > https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py > > > > <> > > > > import calendar, time > > import sys > > import getopt > > > > print '---------------------------------------' > > > > # Check the arguments to this script are as expected. > > # argv[0] is script name. > > argLen = len(sys.argv) > > if argLen -1 < 2: > > print "ERROR: got ", argLen -1, " args, must be at least two." > > print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py [] [] [] [] [targetDB influx db>' > > exit() > > > > outputFormat='CSV' > > url='t3://localhost:7001' > > targetHost='localhost' > > targetDB='obi' > > targetPort='8086' > > > > try: > > wls_user = sys.argv[1] > > wls_pw = sys.argv[2] > > url = sys.argv[3] > > outputFormat=sys.argv[4] > > targetHost=sys.argv[5] > > targetPort=sys.argv[6] > > targetDB=sys.argv[7] > > except: > > print '' > > > > print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB > > > > now_epoch = calendar.timegm(time.gmtime())*1000 > > > > if outputFormat=='InfluxDB': > > import httplib > > influx_msgs='' > > > > connect(wls_user,wls_pw,url) > > results = displayMetricTables('Oracle_BI*','dms_cProcessInfo') > > for table in results: > > tableName = table.get('Table') > > rows = table.get('Rows') > > rowCollection = rows.values() > > iter = rowCollection.iterator() > > while iter.hasNext(): > > row = iter.next() > > rowType = row.getCompositeType() > > keys = rowType.keySet() > > keyIter = keys.iterator() > > inst_name= row.get('Name').replace(' ','-') > > try: > > server= row.get('Servername').replace(' ','-').replace('/','_') > > except: > > try: > > server= row.get('ServerName').replace(' ','-').replace('/','_') > > except: > > server='unknown' > > try: > > host= row.get('Host').replace(' ','-') > > except: > > host='' > > while keyIter.hasNext(): > > columnName = keyIter.next() > > value = row.get(columnName ) > > if columnName.find('.value')>0: > > metric_name=columnName.replace('.value','') > > if value is not None: > > if value != 0: > > if outputFormat=='InfluxDB': > > influx_msg= ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % (metric_name,server,host,tableName,inst_name, value,now_epoch*1000000) > > influx_msgs+='\n%s' % influx_msg > > conn = httplib.HTTPConnection('%s:%s' % (targetHost,targetPort)) > > ## TODO pretty sure should be urlencoding this ... > > a=conn.request("POST", ("/write?db=%s" % targetDB), influx_msg) > > r=conn.getresponse() > > > > <> > > > > It currently takes about 3 minutes to execute completely and I was thinking of a way to make it run faster > > > > Data alignment (Influx line protocol) & data loading - done together takes up most of the time > > > > Influxdb is currently loading data at around 3 points/second > > > > Any way to align the data separately, store it and load it as a batch? > > > > I feel that would help improve performance > > > > Please let me know if you have any pointers > > I can send the data sheet if required > > > > Thanks P > > -- > > https://mail.python.org/mailman/listinfo/python-list How do I do that? From python at deborahswanson.net Mon Apr 3 13:27:33 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Mon, 3 Apr 2017 10:27:33 -0700 Subject: Two variable dictionary comprehension In-Reply-To: <1tt4ec5jfvpk37n57bfd8k18stsqlub4bc@4ax.com> Message-ID: <003201d2ac9f$946dff60$27b23dae@sambora> Dennis Lee Bieber wrote, on April 03, 2017 9:35 AM > > On Mon, 3 Apr 2017 07:30:40 -0700, "Deborah Swanson" > declaimed the following: > > > > >Clearly there's more to be found in nooks, crannies and > byways in the > >docs than you'll get to from the given pointers in the > index. Maybe it > >would be worthwhile to scrape the whole mess and have it in > searchable > >text form. Another thing Python would be the right tool for the job > >for. Regular updates as the docs are updated would be a good > idea too. > >It's obvious that today's Google isn't up to it, although it > occurs to > >me that I haven't tried Google's site search on python.org. > > > On Windows, the (at least, for ActiveState releases) > documentation is available in Windows Help format -- though > I'll admit the "free text search" leaves a lot to be desired... > > "dict comprehension" didn't find anything obvious; > "dictionary comprehension" brought up PEP 274 (note: I still > use 2.7 as main version). > > -=-=-=-=-=- > Semantics > The semantics of dict comprehensions can actually be demonstrated > in stock Python 2.2, by passing a list comprehension to the > builtin dictionary constructor: > > >>> dict([(i, chr(65+i)) for i in range(4)]) > > is semantically equivalent to > > >>> {i : chr(65+i) for i in range(4)} > > The dictionary constructor approach has two dictinct disadvantages > from the proposed syntax though. First, it isn't as legible as a > dict comprehension. Second, it forces the programmer to create an > in-core list object first, which could be expensive. > > -=-=-=-=-=- > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ It would be interesting to play around with different list comprehensions than the one they've shown. I'll admit that both dictionaries and comprehensions are still a little bit fuzzy to me, especially when I get away from the common usages. This could be a good exercise to clarify some of the fuzzy areas. Deborah From rgaddi at highlandtechnology.invalid Mon Apr 3 13:38:15 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Mon, 3 Apr 2017 10:38:15 -0700 Subject: Two variable dictionary comprehension In-Reply-To: References: <1tt4ec5jfvpk37n57bfd8k18stsqlub4bc@4ax.com> <003201d2ac9f$946dff60$27b23dae@sambora> Message-ID: On 04/03/2017 10:27 AM, Deborah Swanson wrote: > Dennis Lee Bieber wrote, on April 03, 2017 9:35 AM >> >> On Mon, 3 Apr 2017 07:30:40 -0700, "Deborah Swanson" >> declaimed the following: >> >>> >>> Clearly there's more to be found in nooks, crannies and >> byways in the >>> docs than you'll get to from the given pointers in the >> index. Maybe it >>> would be worthwhile to scrape the whole mess and have it in >> searchable >>> text form. Another thing Python would be the right tool for the job >>> for. Regular updates as the docs are updated would be a good >> idea too. >>> It's obvious that today's Google isn't up to it, although it >> occurs to >>> me that I haven't tried Google's site search on python.org. >>> >> On Windows, the (at least, for ActiveState releases) >> documentation is available in Windows Help format -- though >> I'll admit the "free text search" leaves a lot to be desired... >> >> "dict comprehension" didn't find anything obvious; >> "dictionary comprehension" brought up PEP 274 (note: I still >> use 2.7 as main version). >> >> -=-=-=-=-=- >> Semantics >> The semantics of dict comprehensions can actually be demonstrated >> in stock Python 2.2, by passing a list comprehension to the >> builtin dictionary constructor: >> >> >>> dict([(i, chr(65+i)) for i in range(4)]) >> >> is semantically equivalent to >> >> >>> {i : chr(65+i) for i in range(4)} >> >> The dictionary constructor approach has two dictinct disadvantages >> from the proposed syntax though. First, it isn't as legible as a >> dict comprehension. Second, it forces the programmer to create an >> in-core list object first, which could be expensive. >> >> -=-=-=-=-=- >> -- >> Wulfraed Dennis Lee Bieber AF6VN >> wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > It would be interesting to play around with different list > comprehensions than the one they've shown. > > I'll admit that both dictionaries and comprehensions are still a little > bit fuzzy to me, especially when I get away from the common usages. This > could be a good exercise to clarify some of the fuzzy areas. > > Deborah > And don't forget dict_comp : { k:v for (k,v) in kv_provider } set_comp : { item for item in item_provider } set_of_tuples_comp : { (k,v) for (k,v) in kv_provider } Just to make things more complicated. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From steve+python at pearwood.info Mon Apr 3 13:55:12 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 04 Apr 2017 03:55:12 +1000 Subject: OFF-TOPIC Bigotry on the list [was Re: Text-mode apps (Was :Who are the "spacists"?)] References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <58e12641$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58e28c83$0$1614$c3e8da3$5496439d@news.astraweb.com> On Mon, 3 Apr 2017 08:31 am, Terry Reedy wrote: [...] > I refrained because it would be off-topic and a diversion from my point: > all bigotry is inappropriate here on this list, Indeed it is not appropriate. But calling out bigotry is not itself bigotry. I hope you agree with that. If not, that leaves you with some deeply Unfortunate Implications. Suppose you are right, and merely calling out "Ranting Rick" for his bigoted attitude makes me an anti-American bigot. Then by *you* calling *me* out for bigotry, that makes you equally a bigot. And so the only way to avoid being a bigot is... to do nothing in the face of bigotry. I didn't see you calling out Rick for his prejudice against those who aren't American, his absurd belief that "most" people are satisfied with ASCII, or his claim that the rest of the world don't need file names in their native languages because the "majority" (his word) of them are illiterate. Do you think those attitudes should be left unchallenged? (In fairness, Rick doesn't say that the *entire* rest of the world is mostly illiterate. He only includes China, India, Russia, Japan, Indonesia, Arab-speakers, and Israel. So a bit less than half the world.) > including anti-Americanism. When have I demonstrated prejudice against Americans merely for being American? I stand by my comment to Rick. It is *his behaviour and attitude* which makes him an example of the stereotype, not the fact that he is an American. Of course all people are unique, and all stereotypes are incomplete. People are not their stereotype, and I'm sure that Rick is a wonderful and unique person in his own way. Perhaps he loves animals and donates his time to working in shelters for the homeless. But nevertheless people do behave in stereotypical ways, and we've seen Rick do exactly that. Insensitive to cultural differences, dismissive of those who aren't American, ignorant of everything outside of the borders of the US, and arrogantly certain that the American way is not just the best way but the only way. And *wilfully* so. This is not just an isolated incident from Rick, a mere momentary lapse. He has been expressing these sorts of attitudes for years. > (I actually think raw bigoty is inappropriate everywhere. While there > are places to discuss the relative average beauty and niceness of > various groups of people, this is not one of them. Even comparisons of > computer languages is not the main focus of this list.) I'm not discussing the "relative average beauty and niceness of various groups of people". That's absurd. I'm discussing the behaviour and attitudes demonstrated by one specific individual. [...] > Yesterday, Chris Angelico, I believe it was, asked someone to stop > including anti-Jew messages in posts here. So I asked the same of you > regarding your anti-American expression. Can you really not tell the difference between criticism of an individual American for the views he expresses, and a blanket attack on all Americans merely for being American? >> Not all Americans, perhaps not even a majority or a plurality, are Ugly >> Americans, but there are enough of them to screw it up for everyone else. > > Shall we discuss Ugly Australians, or whatever the appropriate epithet > would be? If one of them turns up and starts expressing those views, absolutely. >> It's an ugly stereotype, not because it is a stereotype, but because it > > embodies a set of ugly attitudes and behaviours. > > I am sure I have seen similar things written by various other people > justifying their prejudices. As have I. Are you judging *me* by *their* behaviour? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From python at deborahswanson.net Mon Apr 3 14:48:38 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Mon, 3 Apr 2017 11:48:38 -0700 Subject: Two variable dictionary comprehension In-Reply-To: Message-ID: <004a01d2acaa$e8727a40$27b23dae@sambora> Rob Gaddi wrote, on April 03, 2017 10:38 AM > > On 04/03/2017 10:27 AM, Deborah Swanson wrote: > > Dennis Lee Bieber wrote, on April 03, 2017 9:35 AM > >> > >> On Mon, 3 Apr 2017 07:30:40 -0700, "Deborah Swanson" > >> declaimed the following: > >> > >>> > >>> Clearly there's more to be found in nooks, crannies and byways in the > >>> docs than you'll get to from the given pointers in the index. Maybe it > >>> would be worthwhile to scrape the whole mess and have it in searchable > >>> text form. Another thing Python would be the right tool for the job > >>> for. Regular updates as the docs are updated would be a good idea too. > >>> It's obvious that today's Google isn't up to it, although it occurs to > >>> me that I haven't tried Google's site search on python.org. > >>> > >> On Windows, the (at least, for ActiveState releases) documentation > >> is available in Windows Help format -- though I'll admit the "free > >> text search" leaves a lot to be desired... > >> > >> "dict comprehension" didn't find anything obvious; "dictionary > >> comprehension" brought up PEP 274 (note: I still use 2.7 as main > >> version). > >> > >> -=-=-=-=-=- > >> Semantics > >> The semantics of dict comprehensions can actually be demonstrated > >> in stock Python 2.2, by passing a list comprehension to the > >> builtin dictionary constructor: > >> > >> >>> dict([(i, chr(65+i)) for i in range(4)]) > >> > >> is semantically equivalent to > >> > >> >>> {i : chr(65+i) for i in range(4)} > >> > >> The dictionary constructor approach has two dictinct disadvantages > >> from the proposed syntax though. First, it isn't as legible as a > >> dict comprehension. Second, it forces the programmer to create an > >> in-core list object first, which could be expensive. > >> > >> -=-=-=-=-=- > >> -- > >> Wulfraed Dennis Lee Bieber AF6VN > >> wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > > > It would be interesting to play around with different list > > comprehensions than the one they've shown. > > > > I'll admit that both dictionaries and comprehensions are still a > > little bit fuzzy to me, especially when I get away from the common > > usages. This could be a good exercise to clarify some of the fuzzy > > areas. > > > > Deborah > > > > And don't forget > dict_comp : { k:v for (k,v) in kv_provider } > set_comp : { item for item in item_provider } > set_of_tuples_comp : { (k,v) for (k,v) in kv_provider } > > Just to make things more complicated. > > -- > Rob Gaddi, Highland Technology -- www.highlandtechnology.com > Email address domain is currently out of order. See above to fix. Added to my list of comprehension types, thank you. I'm thinking it would also be good to include the PEPs in my searchable Python reference. Just making the collection and browsing through it would be highly instructive. But, if Larry Page and Sergey Brin could tinker around in their dorm rooms (or wherever they lived then) and they made the first Google (the first search engine?) to boolean search the World Wide Web, it shouldn't be so awfully hard to make a collection of Python docs that's boolean searchable. I haven't seen a search method for text that comes anywhere near boolean search's completeness in returning results (though I'm happy to take suggestions). Deborah From best_lay at yahoo.com Mon Apr 3 15:29:56 2017 From: best_lay at yahoo.com (Wildman) Date: Mon, 03 Apr 2017 14:29:56 -0500 Subject: Request Help With pkexec Message-ID: Python 3.4.2 Tkinter 8.6 GCC 4.9.1 on Linux I am working on a gui program using Tkinter. The program will have a feature to restart as root. I am testing different gui front-ends from a terminal to raise privileges and I want to be able to use as many as possible for obvious reasons. Gksu, kdesudo and su-to-root all work perfectly. However, I have a problem with pkexec. Here is the command I am using from a terminal: $ pkexec python3 /home/user/Python/linfo-tk/linfo-tk.py I get this error: Traceback (most recent call last): File "/home/user/Python/linfo-tk/linfo-tk.py", line 455, in root = tk.Tk() File "/usr/lib/python3.4/tkinter/__init__.py", line 1854, in __init__ self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) _tkinter.TclError: no display name and no $DISPLAY environment variable The display environment variable is set: $ echo $DISPLAY :0.0 And the program displays and works perfectly in every other way. I would appreciate any insight. -- GNU/Linux user #557453 May the Source be with you. From malaclypse2 at gmail.com Mon Apr 3 16:47:57 2017 From: malaclypse2 at gmail.com (Jerry Hill) Date: Mon, 3 Apr 2017 16:47:57 -0400 Subject: Two variable dictionary comprehension In-Reply-To: <007401d2ac86$dee57320$27b23dae@sambora> References: <007401d2ac86$dee57320$27b23dae@sambora> Message-ID: On Mon, Apr 3, 2017 at 10:30 AM, Deborah Swanson wrote: > Regular updates as the docs are updated would be a good idea too. It's > obvious that today's Google isn't up to it, although it occurs to me > that I haven't tried Google's site search on python.org. So, when you search google for the phrase "dict comprehension" or "dictionary comprehension", nothing useful comes up for you? When I search either of those phrases, I get lots of useful results, all of which spell out how to do what you were originally asking about. I know Google search results are skewed by past usage, but I'm surprised that you didn't find anything useful in the first couple of search results. When I do a search for 'dict comprehension' I get a boxed result linking to PEP 274 as the first hit, then two Stack Overflow questions, both of which demonstrate how to do dictionary comprehensions. Following that is another link to PEP 274, a link to the Python docs on data structures (which does talk about dict comprehensions, but it's way down on the page), and then links to a bunch of tutorials. If you had to judge based on my search results, Google does a fine job of answering python questions, at least when you already know the key phrase to look for. -- Jerry From nathan.ernst at gmail.com Mon Apr 3 16:58:35 2017 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Mon, 3 Apr 2017 15:58:35 -0500 Subject: Two variable dictionary comprehension In-Reply-To: References: <007401d2ac86$dee57320$27b23dae@sambora> Message-ID: I was a bit surprised when I looked at the language reference for 3.6.x. I expected there'd be a direct link to comprehensions, but there's not. You have to know what you're looking for: 6.2.5: List Displays 6.2.6: Set Displays 6.2.7: Dictionary Displays And, then, click on the appropriate element of the sub grammar to find the appropriate syntax. So, it took me about 30 seconds to find the appropriate grammars, when I expected it'd only take about 5 seconds, since I'm very familiar with the python docs & how the grammar documentation is laid out. I can fully understand how someone less familiar with the documentation might have a harder time finding the grammar than I did. FWIW, If one was completely new to Python, even knowing the syntax is known as a "comprehension" might be unknown. I certainly didn't know what a comprehension was when I was learning Python. A coworker showed me, some 13 years ago. Regards, Nate On Mon, Apr 3, 2017 at 3:47 PM, Jerry Hill wrote: > On Mon, Apr 3, 2017 at 10:30 AM, Deborah Swanson > wrote: > > Regular updates as the docs are updated would be a good idea too. It's > > obvious that today's Google isn't up to it, although it occurs to me > > that I haven't tried Google's site search on python.org. > > So, when you search google for the phrase "dict comprehension" or > "dictionary comprehension", nothing useful comes up for you? When I > search either of those phrases, I get lots of useful results, all of > which spell out how to do what you were originally asking about. I > know Google search results are skewed by past usage, but I'm surprised > that you didn't find anything useful in the first couple of search > results. > > When I do a search for 'dict comprehension' I get a boxed result > linking to PEP 274 as the first hit, then two Stack Overflow > questions, both of which demonstrate how to do dictionary > comprehensions. Following that is another link to PEP 274, a link to > the Python docs on data structures (which does talk about dict > comprehensions, but it's way down on the page), and then links to a > bunch of tutorials. If you had to judge based on my search results, > Google does a fine job of answering python questions, at least when > you already know the key phrase to look for. > > -- > Jerry > -- > https://mail.python.org/mailman/listinfo/python-list > From psmith36 at ewu.edu Mon Apr 3 17:02:19 2017 From: psmith36 at ewu.edu (Pauline) Date: Mon, 3 Apr 2017 14:02:19 -0700 (PDT) Subject: Which directory should requests and openpyxl modules be installed to? Message-ID: Hi, I am a newbie to Python. I am using Python 2.7.12. I want to install the modules of requests and openpyxl using pip. In the Internet, people only said pip install requests, but they do not say in which directory. I only found one that said install in the script directory within Python. Well, that didn't work. How and which directory in the command line to type pip install requests? Thanks! Pauline From nathan.ernst at gmail.com Mon Apr 3 17:27:32 2017 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Mon, 3 Apr 2017 16:27:32 -0500 Subject: Which directory should requests and openpyxl modules be installed to? In-Reply-To: References: Message-ID: Hi Pauline, It depends largely on whether you want to (and have sufficient permissions) to install for all users or just yourself. If, on *nix, you're installing site-wide (for all users), typically you'd do: "sudo pip install " (for python 2) or "sudo pip3 install " (for python 3). If you're installing it for yourself, you may need to add the --prefix= option. Typically, would be somewhere under your home directory. This can be problematic, as you may need to edit the PYTHONPATH (and possibly LD_LIBRARY_PATH) to point to appropriate directories. In this case, you're probably better of setting up a virtual environment. See: http://python-guide-pt-br.readthedocs.io/en/latest/dev/virtualenvs/. With virtualenvs, you can setup a per user/project python configuration. If you're on Windows, you should be able to "py pip install ", and that will install it for you. If you run under and adminstrator cmd prompt & python has been installed for all users, I *think* the module will be available for everyone. Hope this helps. Regards, Nate On Mon, Apr 3, 2017 at 4:02 PM, Pauline wrote: > Hi, > > I am a newbie to Python. I am using Python 2.7.12. I want to install > the modules of requests and openpyxl using pip. In the Internet, people > only said pip install requests, but they do not say in which directory. I > only found one that said install in the script directory within Python. > Well, that didn't work. > > How and which directory in the command line to type pip install requests? > > Thanks! > Pauline > -- > https://mail.python.org/mailman/listinfo/python-list > From psmith36 at ewu.edu Mon Apr 3 17:36:21 2017 From: psmith36 at ewu.edu (psmith36 at ewu.edu) Date: Mon, 3 Apr 2017 14:36:21 -0700 (PDT) Subject: Which directory should requests and openpyxl modules be installed to? In-Reply-To: References: Message-ID: <6300b9b4-57b2-4ecb-b67d-73d98f099e81@googlegroups.com> On Monday, April 3, 2017 at 2:02:30 PM UTC-7, Pauline wrote: > Hi, > > I am a newbie to Python. I am using Python 2.7.12. I want to install the modules of requests and openpyxl using pip. In the Internet, people only said pip install requests, but they do not say in which directory. I only found one that said install in the script directory within Python. Well, that didn't work. > > How and which directory in the command line to type pip install requests? > > Thanks! > Pauline Hi Nate, Thank you for your prompt reply. I am just installing it on my computer with administrative privileges. I think I can go into the command line, but then I do not know which directory to go to type: pip install requests If I have installed python 2.7.12 in the Program Files directory, and then there are many directories within the Python 2.7.12 directory, then which directory should I go to install the modules? I think my situation is indeed very simple. Pauline From python at deborahswanson.net Mon Apr 3 17:50:56 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Mon, 3 Apr 2017 14:50:56 -0700 Subject: Two variable dictionary comprehension In-Reply-To: Message-ID: <00ac01d2acc4$5ff9a750$27b23dae@sambora> Jerry Hill wrote, on April 03, 2017 1:48 PM > > On Mon, Apr 3, 2017 at 10:30 AM, Deborah Swanson > wrote: > > Regular updates as the docs are updated would be a good > idea too. It's > > obvious that today's Google isn't up to it, although it > occurs to me > > that I haven't tried Google's site search on python.org. > > So, when you search google for the phrase "dict > comprehension" or "dictionary comprehension", nothing useful > comes up for you? When I search either of those phrases, I > get lots of useful results, all of which spell out how to do > what you were originally asking about. I know Google search > results are skewed by past usage, but I'm surprised that you > didn't find anything useful in the first couple of search results. > > When I do a search for 'dict comprehension' I get a boxed > result linking to PEP 274 as the first hit, then two Stack > Overflow questions, both of which demonstrate how to do > dictionary comprehensions. Following that is another link to > PEP 274, a link to the Python docs on data structures (which > does talk about dict comprehensions, but it's way down on the > page), and then links to a bunch of tutorials. If you had to > judge based on my search results, Google does a fine job of > answering python questions, at least when you already know > the key phrase to look for. > > -- > Jerry Ah, but did you actually try to use the proposed solutions on the two stackoverflow pages? It's been several weeks now, but I did, and neither of those two examples fit my situation, which is why I ended up writing my own, and unsatisfactorily at that. I'm sorry you think the current edition of Google does such a fine job. Has it really been that many years ago that the results Google returned from a properly formatted boolean search were really useful? I'd imagine that the old Google would have returned a good 10 pages or more (probably a lot more) of urls containing the phrase "dict comprehension" or "dictionary comprehension". in which you'd find a rich variety of specific situations to glean through. (You wouldn't have needed to include "python" in the search phrase, since no other programming language that I know of, or other English usage for that matter, has dict comprehensions.) Nowadays Google just comes up with a mere handful of sorta appropriate urls, and rarely do I find exactly what I'm looking for. And usually there's nothing related to all your search terms after a page or two of results. You used to be able to keep sifting through pages of results after the bulk of urls fitting your criteria had passed, and still find useful things to look at, sometimes at page 500 or even much, much farther down the list. It really paid to comb through them all, especially if you didn't find exactly what you wanted in the early batch. But giving users the choice among tens or hundreds of similar pages (fewer if you specify 100 results per page) doesn't give Google as much grist for the advertising mill to pump out at the users, hence the present day useless mess. Deborah From nathan.ernst at gmail.com Mon Apr 3 18:04:31 2017 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Mon, 3 Apr 2017 17:04:31 -0500 Subject: Which directory should requests and openpyxl modules be installed to? In-Reply-To: <6300b9b4-57b2-4ecb-b67d-73d98f099e81@googlegroups.com> References: <6300b9b4-57b2-4ecb-b67d-73d98f099e81@googlegroups.com> Message-ID: If you've installed into Program Files, then you're on Windows, and you've installed for all users. Start a command prompt by right-clicking on the start icon, then selecting "Command Prompt (Admin)". This should work on Windows 8.x and Windows 10. Windows 7, you may need to navigate through Programs to Windows System\Command Prompt (path might be different - may be under Windows Accessories), then right-clicking on Command Prompt (Admin). >From that prompt, you should be able to run "py pip install " and install it site-wide (for all local users) On Mon, Apr 3, 2017 at 4:36 PM, wrote: > On Monday, April 3, 2017 at 2:02:30 PM UTC-7, Pauline wrote: > > Hi, > > > > I am a newbie to Python. I am using Python 2.7.12. I want to install > the modules of requests and openpyxl using pip. In the Internet, people > only said pip install requests, but they do not say in which directory. I > only found one that said install in the script directory within Python. > Well, that didn't work. > > > > How and which directory in the command line to type pip install > requests? > > > > Thanks! > > Pauline > > Hi Nate, > > Thank you for your prompt reply. I am just installing it on my computer > with administrative privileges. I think I can go into the command line, but > then I do not know which directory to go to type: pip install requests > > If I have installed python 2.7.12 in the Program Files directory, and > then there are many directories within the Python 2.7.12 directory, then > which directory should I go to install the modules? > > I think my situation is indeed very simple. > > Pauline > -- > https://mail.python.org/mailman/listinfo/python-list > From python at deborahswanson.net Mon Apr 3 18:09:44 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Mon, 3 Apr 2017 15:09:44 -0700 Subject: Two variable dictionary comprehension In-Reply-To: Message-ID: <00b801d2acc7$006d7b10$27b23dae@sambora> Nathan Ernst wrote, on April 03, 2017 1:59 PM > > I was a bit surprised when I looked at the language reference > for 3.6.x. I expected there'd be a direct link to > comprehensions, but there's not. > > You have to know what you're looking for: > > 6.2.5: List Displays > 6.2.6: Set Displays > 6.2.7: Dictionary Displays > > And, then, click on the appropriate element of the sub > grammar to find the appropriate syntax. > > So, it took me about 30 seconds to find the appropriate > grammars, when I expected it'd only take about 5 seconds, > since I'm very familiar with the python docs & how the > grammar documentation is laid out. I can fully understand > how someone less familiar with the documentation might have a > harder time finding the grammar than I did. > > FWIW, If one was completely new to Python, even knowing the > syntax is known as a "comprehension" might be unknown. I > certainly didn't know what a comprehension was when I was > learning Python. A coworker showed me, some 13 years ago. > > Regards, > Nate Thanks Nate, for your comprehension of the plight of many, if not most, newish Python coders. And it certainly doesn't help to ask the list to fill in some of the holes and be met with criticism for asking, but I digress. It is what it is. Before I started reading the list a few months ago, I'd heard of list comprehensions in an article I'd read, and hardly understood the gist of it. But look at me now Ma, I've learned not only how to use list comprehensions but also a small tribe of other kinds of comprehensions! (If there's a moral to this story, heck if I know exactly what it is. "Keep on trying" is as good as any.) Deborah > On Mon, Apr 3, 2017 at 3:47 PM, Jerry Hill > wrote: > > > On Mon, Apr 3, 2017 at 10:30 AM, Deborah Swanson > > wrote: > > > Regular updates as the docs are updated would be a good idea too. > > > It's obvious that today's Google isn't up to it, although > it occurs > > > to me that I haven't tried Google's site search on python.org. > > > > So, when you search google for the phrase "dict comprehension" or > > "dictionary comprehension", nothing useful comes up for > you? When I > > search either of those phrases, I get lots of useful > results, all of > > which spell out how to do what you were originally asking about. I > > know Google search results are skewed by past usage, but > I'm surprised > > that you didn't find anything useful in the first couple of search > > results. > > > > When I do a search for 'dict comprehension' I get a boxed result > > linking to PEP 274 as the first hit, then two Stack Overflow > > questions, both of which demonstrate how to do dictionary > > comprehensions. Following that is another link to PEP 274, > a link to > > the Python docs on data structures (which does talk about dict > > comprehensions, but it's way down on the page), and then links to a > > bunch of tutorials. If you had to judge based on my search > results, > > Google does a fine job of answering python questions, at least when > > you already know the key phrase to look for. > > > > -- > > Jerry > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list > From psmith36 at ewu.edu Mon Apr 3 18:14:12 2017 From: psmith36 at ewu.edu (psmith36 at ewu.edu) Date: Mon, 3 Apr 2017 15:14:12 -0700 (PDT) Subject: Which directory should requests and openpyxl modules be installed to? In-Reply-To: References: Message-ID: <0bf304d0-fadc-4970-be6e-e25b5225bed0@googlegroups.com> On Monday, April 3, 2017 at 2:02:30 PM UTC-7, Pauline wrote: > Hi, > > I am a newbie to Python. I am using Python 2.7.12. I want to install the modules of requests and openpyxl using pip. In the Internet, people only said pip install requests, but they do not say in which directory. I only found one that said install in the script directory within Python. Well, that didn't work. > > How and which directory in the command line to type pip install requests? > > Thanks! > Pauline Hi Nate, Well, I didn't tell you I am on Windows 7. When I went to cmd, it was C:\Users\myname. Then I navigated to where my Python was installed C:\Program Files\Python 2.7.12> Do I type pip install requests at the end of the arrow, or do I have to go somewhere else? Thanks a bunch! Pauline From rosuav at gmail.com Mon Apr 3 18:24:11 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Apr 2017 08:24:11 +1000 Subject: Which directory should requests and openpyxl modules be installed to? In-Reply-To: <0bf304d0-fadc-4970-be6e-e25b5225bed0@googlegroups.com> References: <0bf304d0-fadc-4970-be6e-e25b5225bed0@googlegroups.com> Message-ID: On Tue, Apr 4, 2017 at 8:14 AM, wrote: > Hi Nate, > > Well, I didn't tell you I am on Windows 7. When I went to cmd, it was C:\Users\myname. Then I navigated to where my Python was installed C:\Program > Files\Python 2.7.12> > > Do I type pip install requests at the end of the arrow, or do I have to go somewhere else? > > Thanks a bunch! Ah, this shouldn't matter. If you've installed Python and pip correctly, you should be able to run them from any directory at all, and they'll do their work correctly. ChrisA From nathan.ernst at gmail.com Mon Apr 3 18:25:45 2017 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Mon, 3 Apr 2017 17:25:45 -0500 Subject: Which directory should requests and openpyxl modules be installed to? In-Reply-To: <0bf304d0-fadc-4970-be6e-e25b5225bed0@googlegroups.com> References: <0bf304d0-fadc-4970-be6e-e25b5225bed0@googlegroups.com> Message-ID: Hi Pauline, I was able to infer you're on Windows, but not which version. Try right-clicking on the start menu to start a command prompt as an administrator (I'm not sure that was available in Windows 7, and I don't have access to a Win7 box currently to verify). Failing that, you should be able to find a shortcut to the command prompt somewhere under Programs\Windows, Programs\Windows Accessories, or a like named folder. Just keep looking, it's there. (the parent folder will be named Windows or Programs - look through all subfolders until you find it). Once you find it, right-click and select run as Administrator. Then, you should be able to run the pip install command just fine. If you cannot find Command Prompt for whatever reason, an alternate way is to create a short cut on your desktop. Just right-click on your desktop. Select New\Create Shortcut. When it asks you to select the location of the file, just enter "cmd.exe". Hit "next" until the dialog exits. Then, right-click on the newly created shortcut and select "run as administrator", then try your pip install command. Where you run the pip command (i.e. current directory should not matter). Regards On Mon, Apr 3, 2017 at 5:14 PM, wrote: > On Monday, April 3, 2017 at 2:02:30 PM UTC-7, Pauline wrote: > > Hi, > > > > I am a newbie to Python. I am using Python 2.7.12. I want to install > the modules of requests and openpyxl using pip. In the Internet, people > only said pip install requests, but they do not say in which directory. I > only found one that said install in the script directory within Python. > Well, that didn't work. > > > > How and which directory in the command line to type pip install > requests? > > > > Thanks! > > Pauline > > Hi Nate, > > Well, I didn't tell you I am on Windows 7. When I went to cmd, it was > C:\Users\myname. Then I navigated to where my Python was installed > C:\Program > Files\Python 2.7.12> > > Do I type pip install requests at the end of the arrow, or do I have to > go somewhere else? > > Thanks a bunch! > Pauline > -- > https://mail.python.org/mailman/listinfo/python-list > From psmith36 at ewu.edu Mon Apr 3 18:31:53 2017 From: psmith36 at ewu.edu (psmith36 at ewu.edu) Date: Mon, 3 Apr 2017 15:31:53 -0700 (PDT) Subject: Which directory should requests and openpyxl modules be installed to? In-Reply-To: References: Message-ID: <306938a9-5743-408e-aa1c-a85da2d0bc71@googlegroups.com> On Monday, April 3, 2017 at 2:02:30 PM UTC-7, Pauline wrote: > Hi, > > I am a newbie to Python. I am using Python 2.7.12. I want to install the modules of requests and openpyxl using pip. In the Internet, people only said pip install requests, but they do not say in which directory. I only found one that said install in the script directory within Python. Well, that didn't work. > > How and which directory in the command line to type pip install requests? > > Thanks! > Pauline Hi Chris, Really! :) So I can type pip install requests at the prompt: C:\Program Files\Python 2.7.12>pip install requests or at C:\>pip install requests And the modules would be installed either way? Sorry I am also a newbie at windows command line too. THANKS!!! Pauline From nathan.ernst at gmail.com Mon Apr 3 18:37:01 2017 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Mon, 3 Apr 2017 17:37:01 -0500 Subject: Two variable dictionary comprehension In-Reply-To: <00b801d2acc7$006d7b10$27b23dae@sambora> References: <00b801d2acc7$006d7b10$27b23dae@sambora> Message-ID: No worries, Deborah. Python is by most measurements a relatively easy/simple language to learn, but there are always the dusty corners. If you've not already, I recommend going through the online Python tutorial in it's entirety ( https://docs.python.org/3/tutorial/index.html). After that, learn the language syntax that wasn't covered in the tutorial by reading the Language Reference ( https://docs.python.org/3/reference/index.html). The tutorial should be fairly easy for a straight beginner to follow. The language reference assumes a little higher-level understanding of programming language grammar. The Python Language Reference uses a modified BNF syntax (BNF being Backus-Naur form. You can read about BNF at https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form). To be honest, I'm not sure what modifications Python uses to BNF, maybe someone else can shed some light (or skin) on it. After you'd done those, peruse the standard library. I don't recommend deep reading there at this point, but at least a cursory reading so you're cognizant of libraries that are built-in that may help do things may you want to do now, or in the future (i.e. make a web request, parse JSON or XML, handle datetimes). Remember: Python comes with batteries included. -Nate On Mon, Apr 3, 2017 at 5:09 PM, Deborah Swanson wrote: > Nathan Ernst wrote, on April 03, 2017 1:59 PM > > > > I was a bit surprised when I looked at the language reference > > for 3.6.x. I expected there'd be a direct link to > > comprehensions, but there's not. > > > > You have to know what you're looking for: > > > > 6.2.5: List Displays > > 6.2.6: Set Displays > > 6.2.7: Dictionary Displays > > > > And, then, click on the appropriate element of the sub > > grammar to find the appropriate syntax. > > > > So, it took me about 30 seconds to find the appropriate > > grammars, when I expected it'd only take about 5 seconds, > > since I'm very familiar with the python docs & how the > > grammar documentation is laid out. I can fully understand > > how someone less familiar with the documentation might have a > > harder time finding the grammar than I did. > > > > FWIW, If one was completely new to Python, even knowing the > > syntax is known as a "comprehension" might be unknown. I > > certainly didn't know what a comprehension was when I was > > learning Python. A coworker showed me, some 13 years ago. > > > > Regards, > > Nate > > Thanks Nate, for your comprehension of the plight of many, if not most, > newish Python coders. And it certainly doesn't help to ask the list to > fill in some of the holes and be met with criticism for asking, but I > digress. It is what it is. > > Before I started reading the list a few months ago, I'd heard of list > comprehensions in an article I'd read, and hardly understood the gist of > it. But look at me now Ma, I've learned not only how to use list > comprehensions but also a small tribe of other kinds of comprehensions! > > (If there's a moral to this story, heck if I know exactly what it is. > "Keep on trying" is as good as any.) > > Deborah > > > On Mon, Apr 3, 2017 at 3:47 PM, Jerry Hill > > wrote: > > > > > On Mon, Apr 3, 2017 at 10:30 AM, Deborah Swanson > > > wrote: > > > > Regular updates as the docs are updated would be a good idea too. > > > > It's obvious that today's Google isn't up to it, although > > it occurs > > > > to me that I haven't tried Google's site search on python.org. > > > > > > So, when you search google for the phrase "dict comprehension" or > > > "dictionary comprehension", nothing useful comes up for > > you? When I > > > search either of those phrases, I get lots of useful > > results, all of > > > which spell out how to do what you were originally asking about. I > > > know Google search results are skewed by past usage, but > > I'm surprised > > > that you didn't find anything useful in the first couple of search > > > results. > > > > > > When I do a search for 'dict comprehension' I get a boxed result > > > linking to PEP 274 as the first hit, then two Stack Overflow > > > questions, both of which demonstrate how to do dictionary > > > comprehensions. Following that is another link to PEP 274, > > a link to > > > the Python docs on data structures (which does talk about dict > > > comprehensions, but it's way down on the page), and then links to a > > > bunch of tutorials. If you had to judge based on my search > > results, > > > Google does a fine job of answering python questions, at least when > > > you already know the key phrase to look for. > > > > > > -- > > > Jerry > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > From greg.ewing at canterbury.ac.nz Mon Apr 3 19:22:32 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 04 Apr 2017 11:22:32 +1200 Subject: Two variable dictionary comprehension In-Reply-To: References: <007401d2ac86$dee57320$27b23dae@sambora> Message-ID: Deborah Swanson wrote: > All my guesses were based on the > single variable (the most common type) examples I found. I just didn't > think of putting a colon after 'label', and found nothing to suggest > that's what I should do. Hmmm, I'm not sure what the docs could do to make that any clearer. The key:value syntax is part of *every* dict comprehension (it's the only thing that distinguishes a dict comprehension from a set comprehension). > > Despite my earlier words and protestations that I did look for two > variable dict comprehensions, fairly diligently, I am taking what you > said seriously. Don't feel too bad. Sometimes it's hard to know what to google for, even for experienced people! Also it's hard for doc writers to anticipate how less experienced people will think. It wouldn't have occurred to me to use the phrase "two variable dict comprehension" when writing documentation. Another thing it's important to be able to do is see through to the principles behind things, and then use those principles to solve new problems that aren't explicitly covered in any docs or examples. The general principle behind all the forms of comprehension is that they consist of a prototypical element, followed by some clauses that generate values for that element. The syntax for the prototypical element mirrors that of the corresponding display. So, for a dict comprehension, the prototypical element has the form 'key:value', where 'key' and 'value' are arbitrary expressions. From there, it's just a matter of figuring out what to put into those expressions. In your case, another part of the puzzle is the fact that you can unpack a tuple obtained from a for-loop into variables. That's a general feature of for-loops, both inside and outside of comprehensions, so you probably won't find it mentioned explicitly under the heading of dict comprehensions. > Maybe it > would be worthwhile to scrape the whole mess and have it in searchable > text form. The HTML Python docs have a "Search" box, although I haven't really used it so I don't know how well it works. In my experience, Google with a site search often works a lot better than search functions provided by sites themselves. > I hope you won't be miffed though if I still come up empty handed and > come back here to ask again. > > Deborah > From greg.ewing at canterbury.ac.nz Mon Apr 3 19:22:40 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 04 Apr 2017 11:22:40 +1200 Subject: Two variable dictionary comprehension In-Reply-To: References: <1tt4ec5jfvpk37n57bfd8k18stsqlub4bc@4ax.com> <003201d2ac9f$946dff60$27b23dae@sambora> Message-ID: Deborah Swanson wrote: > I'll admit that both dictionaries and comprehensions are still a little > bit fuzzy to me, especially when I get away from the common usages. This > could be a good exercise to clarify some of the fuzzy areas. If you're fuzzy about dictionaries in general, it might be a good idea to concentrate on that for now and come back to comprehensions later. They're something of an advanced topic; anything you can do with a comprehension can also be done in more fundamental ways. -- Greg From greg.ewing at canterbury.ac.nz Mon Apr 3 19:22:44 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 04 Apr 2017 11:22:44 +1200 Subject: Two variable dictionary comprehension In-Reply-To: References: <004a01d2acaa$e8727a40$27b23dae@sambora> Message-ID: Deborah Swanson wrote: > But, if Larry Page and Sergey Brin could tinker around in their dorm > rooms (or wherever they lived then) and they made the first Google (the > first search engine?) It wasn't the first web search engine. But it was the first one that not only worked, but *kept* working as the web grew bigger, and bigger, and bigger. -- Greg From greg.ewing at canterbury.ac.nz Mon Apr 3 19:22:48 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 04 Apr 2017 11:22:48 +1200 Subject: Two variable dictionary comprehension In-Reply-To: References: <00ac01d2acc4$5ff9a750$27b23dae@sambora> Message-ID: Deborah Swanson wrote: > I'd > imagine that the old Google would have returned a good 10 pages or more > (probably a lot more) of urls containing the phrase "dict comprehension" > or "dictionary comprehension". It still does, as far as I can see. I just googled for "dict comprehension", and the vast majority of results in the first 10 pages relate to Python. By page 20 it's starting to wander off a bit, but you can hardly blame it for that. There *are* non-Python web pages that mention the words "dict" and "comprehension", and how is Google to know that you don't want those if you don't tell it? > You used to be able to keep sifting through pages of results > after the bulk of urls fitting your criteria had passed, and still find > useful things to look at, sometimes at page 500 Seems to me Google was doing a rather *bad* job if you had to wade through 500 pages of results to find what you wanted. I would never have the patience to do that! Anyhow, the reason Google got brought up was that you were complaining about difficulty of finding things in the Python docs. Google *does* turn up the relevant part of the docs in the very first page of results, so being able to do a direct text search on the docs wouldn't do any better. -- Greg From rantingrickjohnson at gmail.com Mon Apr 3 19:53:40 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 3 Apr 2017 16:53:40 -0700 (PDT) Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dd12d2$0$1611$c3e8da3$5496439d@news.astraweb.com> <04f771fe-1c40-48e9-85d7-3b743108c5eb@googlegroups.com> Message-ID: On Saturday, April 1, 2017 at 9:32:17 PM UTC-5, MRAB wrote: > Sometimes he mentions MUDs, sometimes he mentions Pike, but at least he > doesn't rant. I have not even _begun_ to rant. Yet... From rosuav at gmail.com Mon Apr 3 20:07:06 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Apr 2017 10:07:06 +1000 Subject: Which directory should requests and openpyxl modules be installed to? In-Reply-To: <306938a9-5743-408e-aa1c-a85da2d0bc71@googlegroups.com> References: <306938a9-5743-408e-aa1c-a85da2d0bc71@googlegroups.com> Message-ID: On Tue, Apr 4, 2017 at 8:31 AM, wrote: > Hi Chris, > > Really! :) So I can type pip install requests at the prompt: C:\Program Files\Python 2.7.12>pip install requests > or at C:\>pip install requests > > And the modules would be installed either way? > > Sorry I am also a newbie at windows command line too. > > THANKS!!! Correct! The Windows program search path means it'll find pip.exe (if it doesn't, you'll get a wordy error that used to be called SYS1041), and then pip itself looks in the registry and other places to figure out where it should install things. ChrisA From rantingrickjohnson at gmail.com Mon Apr 3 20:13:20 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 3 Apr 2017 17:13:20 -0700 (PDT) Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58e12641$0$1597$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <58e12641$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sunday, April 2, 2017 at 11:26:50 AM UTC-5, Steve D'Aprano wrote: > On Sun, 2 Apr 2017 04:41 pm, Terry Reedy wrote: > > On 4/1/2017 12:00 PM, Steve D'Aprano wrote: > > > > > example of the Ugly American. > > > > As an American I resent your promotion and perpetuation of > > an ugly ethno-centric stereotype. > > I'm glad you didn't try to describe it as a *unfair* or > *unjustified* stereotype, because (let's face it) after > November 8th 2016, that simply wouldn't fly. D'Aprano, are you still stewing because Donald J Trump spanked Hillary's jumbo sized bottom like an unruly stepchild? You poor widdle partisian hack. I almost feel sorry for you. Heck, Trump has to be the most crass and unstatesmanlike candidate to ever run for the american presidency -- well, certainly in my lifetime -- so it should have been the surest win in history for Hillary (or should i say "HER-"?), but even with the mainstream media planted firmly in her pocket; Bill Clinton's endless charms; a grotesque prosession of hollywood celebs, and Obama on the campaign trail -- she folded like lawn chair! How pathetic. Not to mention that the democratic party cheated Burnie Sanders. (i wonder if he's "feelin' the burn"?) Of course, in their hubris, the Dems put all their chips on the same old tired "game of firsts" crapola, thinking the emotional sleight of hand was enough to clinch them the white house, but fortunately (for america), somebody at the DNC forgot to tell the Dem leaders that america is getting *SICK* and *TIRED* of the emotional games. We only want two types of candidates now: (1) those who are highly qualified non-partisans, or (2) those who will burn the old orders to the ground! With Trump, we got the latter. But as bad a Trump is, he's better than the "business as usual" we get from Repuke-I-Cans and Demon-Rats. But Steven, you're not even an american are you? Nope! You're just another Brit with a stick jambed firmly up his butt waddling around lecturing Americans about how terrible we are, but have you ever stopped to consider your own nation's horrendous history? TIP OF THE DAY: "Great Britain" is the imperialist empire previously known as "England". Now sod-off to your local library so you can catch up on, say, the last umpteen centuries of English tyranny and global colonization. Oh, and, please note that people who live in glass houses would be wise not to start a stone throwing war. just FYI, old buddy. *wink* > Not all Americans, perhaps not even a majority or a > plurality, are Ugly Americans, but there are enough of them > to screw it up for everyone else. There are bad apples in every bunch; every nation; every group. Stupidity and ignorance are ubiquitous traits and are fairly evenly distributed around the globe. So enough with America bashing already. We Americans are no more guilty of hate and intolerance than any other nation or peoples on this planet. Heck, we've only existed for just over 200 years, yet many polmics and media types would have the world believe that hate and intolerance didn't exist in this universe until July 4, 1776. And when has _any_ reigning power in human history ever acted in a 100% benevolent manner? Hmm? (At least, any one that matters, that is). If we read our history books, we would come to the conclusion that tyranny is the natural order of our human society, and, more evidence of universal laws in action. Therefore, only through perpetual conflict can we keep tyranny at bay. For instance, it's not as if we could tell ol' Henry the Eighth: "You know what Henry... you can be a real horse's arse!" -- to which he would "supposedly" reply -- "Indeed. I think i am. And uh, thank you for the healthy criticism" -- NOT! It is more likely that anyone who dared critize the king would win a free all- expense-paid trip to the tower of London, a most horrific place with a most notorious reputation for cruelty. But the English had quite a knack for cruelty, eh Steven? Hmm, remind me again, ol' boy, how many wives did King Henry the VIII have executed for their "supposed" infidelity? Of course, there are rumours that one of the executions did not go as "cleanly" as planned. My observation is that the botched nature of that execution was a feature, not a bug. But depravity has been the SOP for centuries in "Merry ol' England", eh chap? > It's an ugly stereotype, not because it is a stereotype, > but because it embodies a set of ugly attitudes and > behaviours. Your feeble attempts to legitimize your American bashing are deplorable at best. For once in your life, Steven, admit that you're filled with hate and apologize for it. If you don't like America, fine, don't come here. Is that so difficult for you? *WHO* we elect and *HOW* we live our lives is none of your damned business. Personally, i don't give a monkey's toss who your prime minister is, or what your pompous Queen wishes to have dipped in gold and encrusted with diamonds. Personally i think your whole system of governance is as silly as a clown college frat party and as dreadful as a three letter sexually transmitted disease! However, unlike you, i don't feel the need to go around brow beating every Brit i come into contact with. What happens in British politics and society is not of my concern. And likewise, what happens in America politics and society is not of yours. But i'll tell you what you _should_ be concerned about, and that is the religious fundamentalist that you are gleefully importing into your cities and towns, the religious fundamentalist who's goal is the destruction of Western philosophy, society and culture. Why, just a few days ago, another brainwashed god-bot from the "religion of peace" struck at the heart of London. "Why, what a surprise?" NOT! Of course, these attacks _should_ be concerning to you, but i guess you're too busy bashing americans to notice, eh ol' boy? If you and your Euro-trash ilk are willing to stand idle while hostile invaders destroy your country, well, my friend, that is certainly your right, but i can tell you one thing with absolute certainly, and that is that we Americans didn't spend the last 200+ years defanging christianity just to let another "religion of wackos" waltz in here and turn our Democracy into theocratic hell hole. IT AIN'T GONNA HAPPEN! One of the oft-cited snobbish insults that regulars in this group love to fling at those who they do not agree with, is: Better go learn mandarin!. Well, i've got news for all you Europeans, it is not Mandarin that you will be forced to learn, oh no, it will be the regional language of whatever islamic *SECT* that happens to be ruling you "at the moment". For your sake, it would be better if the Chinese take over the world -- hey, they might be brutal dictators, but at least they don't base their society on theocratic principles originating in myths and fairy tales. Trust me, you'd much rather deal with a rational tyrant than irrational one, because there is no hope of reasoning with an irrational. And when, whatever shards of freedom you have now are snatched from you; and when your wives and daughters are treated like second and third class citizens; and when *YOU* are forced to live and die by the archaic whims of an ideology that exists for the sole purpose of subjugation and tyranny -- don't you dare, DON'T EFFING YOU *DARE*! -- to come crawling to America for your liberation, because i promise you Mr. D'Aprano, your cries will fall on deaf ears. We already saved your sorry butts once, and what did we get for that enormous sacrific, huh? We got nothing but decades of insults and endless eurotrash ingrates! So forget the library, *PAL*, and instead, sod-off to your local mosque. Time to start reading the Koran, that way you'll know who's holy sphincter you need to kiss. Godspeed ol' boy, Godspeed! PS: Don't forget the salad bowl! From nonemail at spamspamapam.net Mon Apr 3 21:01:09 2017 From: nonemail at spamspamapam.net (Mark -) Date: Tue, 4 Apr 2017 01:01:09 +0000 (UTC) Subject: Text-mode apps (Was :Who are the "spacists"?) References: Message-ID: <55246406237188d47ac3c9e04355@nntp.aioe.org> > On Sunday, April 2, 2017 at 11:26:50 AM UTC-5, Steve D'Aprano wrote: > >> On Sun, 2 Apr 2017 04:41 pm, Terry Reedy wrote: >> >>> On 4/1/2017 12:00 PM, Steve D'Aprano wrote: >>> >>>> example of the Ugly American. >>>> >>> As an American I resent your promotion and perpetuation of an ugly >>> ethno-centric stereotype. >>> >> I'm glad you didn't try to describe it as a *unfair* or *unjustified* >> stereotype, because (let's face it) after November 8th 2016, that >> simply wouldn't fly. >> > D'Aprano, are you still stewing because Donald J Trump spanked Hear hear From steve+python at pearwood.info Mon Apr 3 21:04:34 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 04 Apr 2017 11:04:34 +1000 Subject: Two variable dictionary comprehension References: <1tt4ec5jfvpk37n57bfd8k18stsqlub4bc@4ax.com> <003201d2ac9f$946dff60$27b23dae@sambora> Message-ID: <58e2f123$0$1584$c3e8da3$5496439d@news.astraweb.com> On Tue, 4 Apr 2017 03:27 am, Deborah Swanson wrote: > I'll admit that both dictionaries and comprehensions are still a little > bit fuzzy to me, especially when I get away from the common usages. This > could be a good exercise to clarify some of the fuzzy areas. As far as comprehensions go, how is your mathematics? If you remember your set builder notation from maths, list comprehensions are based on that. In maths, we say something like: {2n + 1 : 0 ? n ? 9} which might be read aloud as "the set of 2 times n, plus 1, such that n is between 0 and 9 inclusive". http://www.mathwords.com/s/set_builder_notation.htm A similar notation might be: {2n + 1 : n ? {1, 2, 3}} said as "the set of 2 times n, plus 1, such that n is an element of the set {1, 2, 3}". If you're a maths geek like me, this is second nature :-) Now, Python's list comprehension syntax is based on a similar notation, except we spell it out in words rather than symbols, using the familiar "for n in ..." syntax from for-loops instead of : "such that". {2*n + 1 for n in range(10)} {2*n + 1 for n in (1, 2, 3)} A few other differences: - list comprehensions use [ ] for the outermost brackets; - set and dict comprehensions use { }; - generator expressions use ( ) (unless the parentheses can be implied). We're not restricted to mathematical expressions, and can use any Python expression we like: [value.method(arg)[1] for (value, arg) in zip(values, arguments)] translates roughly into this for-loop: result = [] for (value, arg) in zip(values, arguments): result.append(value.method(arg)[1]) Another difference is that comprehensions allow an "if" clause: [v.method(a)[1] for (v, a) in zip(values, arguments) if v is not None] translates something like: result = [] for (v, a) in zip(values, arguments): if v is not None: result.append(v.method(a)[1]) There's more, but that covers probably 98% of comprehension usage. And of course, remember that dict comprehensions use the same key:value syntax as ordinary dict "literals" (the official name is "dict display"). result = {} for key, value in zip(keys, values): result[key] = value becomes result = {key:value for (key, value) in zip(keys, values)} although frankly that's better written as: dict(zip(keys, values)) Hope this helps! -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From larry.martell at gmail.com Mon Apr 3 21:31:39 2017 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 04 Apr 2017 01:31:39 +0000 Subject: Two variable dictionary comprehension In-Reply-To: References: <004a01d2acaa$e8727a40$27b23dae@sambora> Message-ID: On Mon, Apr 3, 2017 at 8:24 PM Dennis Lee Bieber wrote: > On Mon, 3 Apr 2017 11:48:38 -0700, "Deborah Swanson" > declaimed the following: > > >But, if Larry Page and Sergey Brin could tinker around in their dorm > >rooms (or wherever they lived then) and they made the first Google (the > >first search engine?) to boolean search the World Wide Web, it shouldn't > >be so awfully hard to make a collection of Python docs that's boolean > >searchable. > >>Alta Vista predated Google by a few years (it was later absorbed by > Yahoo). Don't forget Ask Jeeves > > From rosuav at gmail.com Mon Apr 3 22:12:11 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Apr 2017 12:12:11 +1000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> <58e12641$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 4, 2017 at 10:13 AM, Rick Johnson wrote: > D'Aprano, are you still stewing because Donald J Trump > spanked Hillary's jumbo sized bottom like an unruly > stepchild? You poor widdle partisian hack. I almost feel > sorry for you. > > [snip massively long political rant] Alright, can the politics please be taken off list? I believe the appropriate newsgroup for this drivel is comp.lang./dev/null. ChrisA From dboland9 at fastmail.fm Mon Apr 3 22:59:40 2017 From: dboland9 at fastmail.fm (Dave) Date: Mon, 3 Apr 2017 22:59:40 -0400 Subject: Appending data to a json file Message-ID: I created a python program that gets data from a user, stores the data as a dictionary in a list of dictionaries. When the program quits, it saves the data file. My desire is to append the new data to the existing data file as is done with purely text files. However, I can't find a way to do that. The advice I have seen on the web is to load the data when the program starts, append the new user input to the list, then re-write the data file. Is that the best way, or is there a better way? Thanks, Dave From rantingrickjohnson at gmail.com Mon Apr 3 23:17:00 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 3 Apr 2017 20:17:00 -0700 (PDT) Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58e12641$0$1597$c3e8da3$5496439d@news.astraweb.com> <201704021330.44532.gheskett@shentel.net> Message-ID: <59674990-b7f9-4d10-822c-4da918fc3176@googlegroups.com> On Sunday, April 2, 2017 at 3:49:43 PM UTC-5, Gene Heskett wrote: > On Sunday 02 April 2017 12:26:40 Steve D'Aprano wrote: > > On Sun, 2 Apr 2017 04:41 pm, Terry Reedy wrote: > > > On 4/1/2017 12:00 PM, Steve D'Aprano wrote: > > > > > > > > example of the Ugly American. > > > > > > As an American I resent your promotion and perpetuation > > > of an ugly ethno-centric stereotype. > > > > I'm glad you didn't try to describe it as a *unfair* or > > *unjustified* stereotype, because (let's face it) after > > November 8th 2016, that simply wouldn't fly. > > While I too detest that label, I will have to admit that I > am one of the conservatives, believing our Constitution and > Bill of Rights have been used as TP by the "establishment" > over the last 65+ years, who enabled that surprise. Saying what you just said, in _this_ group at least, can bring some nasty rebukes. And not because it is wrong, no, but because the proggie-bots will accuse you of being (1) a racist opining for the return of slavery, (2) a homophobic who would throw people from rooftops, (3) a bigot, (4) something else that is equally "bad", or (5) all of the above. Hopefully though, like me, you're undeterred by lies and slander because your skin is thicker than that of the average grape. As for me, i do not want america society to return to 1950, no, i want to american _ideals_ to return to July 4, 1776. And this time we would: "get it right". The first order of business would be to re-write the constitution in a manner that will remove the subtle semantical errors that have caused so much trouble for these last 200+ years. Starting with the Declaration of Independence. (emphasis *MINE*!) "When in the course of human events, it becomes *NECESSARY* for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth the *SEPARATE* and *EQUAL* station to which the laws of nature and of [the natural processes that] *ENTITLE* them, a decent respect to the [reputation] of [humankind] requires that they should declare the causes which impel them to the separation." "We hold these truths to be self-evident, that all [people] are created equal, that they are endowed by their [existence] with certain unalienable rights: that among these are life, liberty and the pursuit of happiness. -- that to *SECURE* these rights, governments are instituted among [people], deriving their just powers from the *CONSENT* of the governed, -- That whenever any form of government becomes destructive of these ends, it is the *RIGHT* of the people to alter or to abolish it, and to institute new government, laying its foundation on such *PRINCIPLES* and organizing its powers in such *FORM*, as to them shall seem most likely to effect their safety and happiness." "Prudence, indeed, will dictate that governments long established should *NOT* be changed for _light_ and _transient_ causes; and accordingly, all experience hath shewn, that [humankind] are more disposed to suffer while evils are "sufferable", than to right themselves by abolishing the forms to which they are "accustomed". But when a *LOOOONG* train of abuses and usurpations pursuing invariably the same [*GOALS* -- to achieve an absolute despotism --], it is their *RIGHT*, it is their *DUTY*, to throw off such government and to provide new guards for their future security. -- Such has been the patient sufferance of these [people]; and such is now the *NECESSITY* which constrains them to alter their former systems of government. The history of the present [United States Of America] is a history of repeated injuries and usurpations [-- and quite frankly, a charade of vile hypocrisy! --], all having in direct object the establishment of an absolute tyranny over these [people]. To prove this, let facts be submitted to a candid world." [List of modern grievances snipped for bandwidth] Simply removing all the misogynist references and patriarchal terms is a good start. But what is important to realize, is that, removing these mistakes does not undermine the intent of this document, no, it merely broadens and purifies that intent. The fact is, this document has caused a social transformation that has reverberated around the world. (Rhetorically i ask...) What _is_ "life, liberty, and the pursuit of happiness"? Is it merely the monotone words of a random child standing on a random grade-school stage reenacting the events of our forefathers for the sake of mere "cute spectacle"? Or is it something more? -- I believe it be. -- I believe it to be one of the most *PROFOUND* realizations of social justice that the human mind has *EVER* conceived. A culmination of many thousand years of trial and error, and the product of much pain and suffering. The American Declaration Of Independence marks an epoch in our collective human social and intellectual evolution, a specific time, when a flash of profundity *RENDERED* the blurry concepts of "self-evident truths" and "just social contracts" *CRYSTAL CLEAR* -- for *ALL* humans to see... Anyone who can read those famous lines i quoted above without having a small tear well-up in their eye -- the same kind of joyous and fearful tear that would well-up when watching the first man walk on the moon -- is not a healthy human being. Something vital is missing from this person. > Wash., DC has been turned into a polluted swamp that needed > drained and cleaned up, and the Donald was the only one > that wasn't part of the same old, same old, bull crap > establishment, and with enough money to run. The Dems and Repubs have run this country into the ground long enough. It's time for these antiquated parties, one of which whom, was the party of slavery, to step aside, and allow the next generation to take the reigns. > However, I'll be the first to admit I am less than > impressed with his efforts vis-a-vis global warming. He, I > suspect, will be a 1 term president unless he starts > listening to the technical people's warnings. Short of a massive and sudden temperature increase, I doubt he'll loose the election over global warming. With North Korea, China, Russia and radical islam, we have many more pressing existential matters which require our immediate attention. Nuclear war is far more dangerous to this planet (and its inhabitants) than global warming or climate change could ever be. And for those who think we've already lived through the darkest days of nuclear threat, well, think again, because thanks to the spread of terrorism (and roque states like NK) we are about to enter the most dangerous stage of this evolution. Mutually Assured Destruction fizzles away in the face of crackpot tyrants and brainwashed god bots. > I'd also make the prediction that the 2020 winner will > _not_ be from the establishment. Maybe not even from the > two party system. I am hoping that this will cause all > (surviving) parties to do some navel gazing, I'm hoping it will finally drive a wooden stake through both of their hearts! > and contemplating not how to enrich the constituent > businesses they own under the table, but maybe, actually > work for the common good. The American Republic will endure until the day Congress discovers that it can bribe the public with the public's money -- Alexis de Tocqueville That dire prediction became true the day FDR wiggled his obese behind into the presidents desk chair in the oval office. So, now, not only are we a welfare state, our politicians are firmly planted in the pockets of multinational corporations. Both parties! > Taking money completely out of the equation would be one > way, Many people may disagree on where exactly the line between power and absolute power is drawn, but one things for sure: the power to print money, command the economy, *AND* use coercion against citizens -- is far too much power in the hands of one entity. Alexis knew what would happen. Sadly, we ignored him. > but you could hear the gored oxen that would wound fatally > clear out to Pluto, without a radio. Human avarice being > what it is, whether I'll live long enough to see that > happen isn't up to me. At 82, it doesn't look like near as > big a chance as it did when I was 60. There will always be corruption... There will always be crime... There will always be hate... There will always be intolerance... Etc... Don't fall for the fallacy of believing that these things can edradicated from our universe. We can reduce them, but we cannot destory them. Personally, I'm convinced that every process in our universe is just as important as any other. We humans become confused because we attempt to interpret the meaning of our universe from a self-centric viewpoint. But this analysis is wrong (GIGO!). The universe does not exist for our sake. Realizing this simple truth is the first step to understanding what our universe truely _is_, and how we fit into it. All else will follow logically... > > > > Not all Americans, perhaps not even a majority or a > > plurality, are Ugly Americans, but there are enough of > > them to screw it up for everyone else. > > > Generally, I try to stay out of the Ugly camp. Then I look > in the mirror and know its hopeless. :( Hey, don't be so judgemental about yourself, that's what everyone else is for. Those are good paying Union jobs, and we don't give them up without a fight. ;-) From malaclypse2 at gmail.com Mon Apr 3 23:21:20 2017 From: malaclypse2 at gmail.com (Jerry Hill) Date: Mon, 3 Apr 2017 23:21:20 -0400 Subject: Two variable dictionary comprehension In-Reply-To: <00ac01d2acc4$5ff9a750$27b23dae@sambora> References: <00ac01d2acc4$5ff9a750$27b23dae@sambora> Message-ID: On Mon, Apr 3, 2017 at 5:50 PM, Deborah Swanson wrote: > Ah, but did you actually try to use the proposed solutions on the two > stackoverflow pages? It's been several weeks now, but I did, and neither > of those two examples fit my situation, which is why I ended up writing > my own, and unsatisfactorily at that. Well, that first Stack Overflow link has the following as the first part of the highest scored answer: In Python 2.6 and earlier, the dict constructor can receive an iterable of key/value pairs: d = dict((key, value) for (key, value) in iterable) From Python 2.7 and 3 onwards, you can just use the dict comprehension syntax directly: d = {key: value for (key, value) in iterable} Isn't that second form the exact thing you were looking for, back in your first post? > I'm sorry you think the current edition of Google does such a fine job. > Has it really been that many years ago that the results Google returned > from a properly formatted boolean search were really useful? I'd > imagine that the old Google would have returned a good 10 pages or more > (probably a lot more) of urls containing the phrase "dict comprehension" > or "dictionary comprehension". in which you'd find a rich variety of > specific situations to glean through. (You wouldn't have needed to > include "python" in the search phrase, since no other programming > language that I know of, or other English usage for that matter, has > dict comprehensions.) Is this not your experience today? I just browsed through the first 5 pages of search results for the phrase "dict comprehension" (without the quotes), and the results seem to be pretty on point. It's mostly results talking about python dict comprehensions, general python pages talking about all sorts of comprehensions (dict, list, and set), and as you get deeper into the result pages, you start to see some entries for the word "comprehension" in dictionaries too, which seems like a reasonable thing to end up mixed in with the desired results. It goes on in that vein out to page 11 or so, at which point things seem to devolve a bit. I'd be totally sympathetic with your plight if you didn't know the key phrase 'dict comprehension' to find all of that information. I'm just not seeing the poor results you seem to be getting from Google once you know the term. -- Jerry From torriem at gmail.com Mon Apr 3 23:26:41 2017 From: torriem at gmail.com (Michael Torrie) Date: Mon, 3 Apr 2017 21:26:41 -0600 Subject: Appending data to a json file In-Reply-To: References: Message-ID: <077058d6-6f91-a664-845d-17c7ef309085@gmail.com> On 04/03/2017 08:59 PM, Dave wrote: > I created a python program that gets data from a user, stores the data > as a dictionary in a list of dictionaries. When the program quits, it > saves the data file. My desire is to append the new data to the > existing data file as is done with purely text files. However, I can't > find a way to do that. The advice I have seen on the web is to load the > data when the program starts, append the new user input to the list, > then re-write the data file. Is that the best way, or is there a better > way? If you're talking about a plain text file, can't you just open the file for append mode and write away to it? f = open("file","at") with f: f.write("More text.\n") From eryksun at gmail.com Mon Apr 3 23:57:11 2017 From: eryksun at gmail.com (eryk sun) Date: Tue, 4 Apr 2017 03:57:11 +0000 Subject: Which directory should requests and openpyxl modules be installed to? In-Reply-To: References: <306938a9-5743-408e-aa1c-a85da2d0bc71@googlegroups.com> Message-ID: On Tue, Apr 4, 2017 at 1:45 AM, Dennis Lee Bieber wrote: > > C:\Users\Wulfraed>assoc .py > .py=Python.File > > C:\Users\Wulfraed>ftype python.file > python.file="C:\Python27\python.exe" "%1" %* The Windows shell stores the user file-association choice in HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py\UserChoice. The cmd shell's assoc and ftype commands only modify a subset of system associations in HKLM\Software\Classes. If keys with the same names exist in HKCU\Software\Classes (e.g. Python and the launcher were installed just for the current user), they will override the system associations. Moreover, the user may be using a totally different ProgId -- usually due to misconfiguration, which is unfortunately all too common of a problem. A couple of common misconfigurations are HKCU\Software\Classes\py_auto_file and HKCU\Software\Classes\Applications\python.exe. These get created automatically by the Windows shell, and will almost always have a broken "open" command that doesn't pass command-line arguments. By using these ProgIds you're also missing the new drop handler that Steve Dower wrote to support dropping files with non-ANSI names. It's best to switch back to using Python.File, Python.NoConFile and friends. The UserChoice key is doubly secured via its "Hash" value plus a security descriptor that prevents the current user from modifying values in the key. This is to prevent direct modification. The most you can do in code is to delete the key to have the shell reset from defaults. By design, the only way to directly change the user choice is via the GUI. Use the Control Panel's "Default Programs" app. Select "Associate a filetype or protocol...". Type ".py" to advance in the list, double-click on the entry, and select the app to use. If Python.File is configured to use the launcher, the "Python" entry in this application list should have an icon with a rocket on it. From mok-kong.shen at t-online.de Tue Apr 4 01:15:40 2017 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Tue, 4 Apr 2017 07:15:40 +0200 Subject: Version 2 of my natural language steganographical scheme released Message-ID: Version 2 of my natural language steganographical scheme WORDLISTTEXTSTEGANOGRAPHY is available on my home page http://mokkong-shen.privat.t-online.de , together with a few other cryptological and steganographical software of mine. See update notes in it for the differences to earlier versions. I regret that in the earlier versions a sentence was unfortunately missing in the explanation of how to do the examples, with the consequence that new users might have difficulties with the examples. M. K. Shen From python at deborahswanson.net Tue Apr 4 01:18:22 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Mon, 3 Apr 2017 22:18:22 -0700 Subject: Two variable dictionary comprehension In-Reply-To: Message-ID: <011401d2ad02$e1bc7590$27b23dae@sambora> Thank you Nate, for all these sources to study. Python was very easy for me to learn in 2 online courses, but it's been all uphill since then. I've learned a lot and for that I'm grateful, but there's so much farther to go. I've appreciated our discussions, but I am in fact a very sick person and my illness has come back again tonight. I can probably reply to a few more posts and then you won't see me again for awhile. But many thanks again, and I will begin reading the material you suggested. Deborah Nathan Ernst wrote, on Monday, April 03, 2017 3:37 PM No worries, Deborah. Python is by most measurements a relatively easy/simple language to learn, but there are always the dusty corners. If you've not already, I recommend going through the online Python tutorial in it's entirety (https://docs.python.org/3/tutorial/index.html). After that, learn the language syntax that wasn't covered in the tutorial by reading the Language Reference (https://docs.python.org/3/reference/index.html). The tutorial should be fairly easy for a straight beginner to follow. The language reference assumes a little higher-level understanding of programming language grammar. The Python Language Reference uses a modified BNF syntax (BNF being Backus-Naur form. You can read about BNF at https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form). To be honest, I'm not sure what modifications Python uses to BNF, maybe someone else can shed some light (or skin) on it. After you'd done those, peruse the standard library. I don't recommend deep reading there at this point, but at least a cursory reading so you're cognizant of libraries that are built-in that may help do things may you want to do now, or in the future (i.e. make a web request, parse JSON or XML, handle datetimes). Remember: Python comes with batteries included. -Nate On Mon, Apr 3, 2017 at 5:09 PM, Deborah Swanson wrote: Nathan Ernst wrote, on April 03, 2017 1:59 PM > > I was a bit surprised when I looked at the language reference > for 3.6.x. I expected there'd be a direct link to > comprehensions, but there's not. > > You have to know what you're looking for: > > 6.2.5: List Displays > 6.2.6: Set Displays > 6.2.7: Dictionary Displays > > And, then, click on the appropriate element of the sub > grammar to find the appropriate syntax. > > So, it took me about 30 seconds to find the appropriate > grammars, when I expected it'd only take about 5 seconds, > since I'm very familiar with the python docs & how the > grammar documentation is laid out. I can fully understand > how someone less familiar with the documentation might have a > harder time finding the grammar than I did. > > FWIW, If one was completely new to Python, even knowing the > syntax is known as a "comprehension" might be unknown. I > certainly didn't know what a comprehension was when I was > learning Python. A coworker showed me, some 13 years ago. > > Regards, > Nate Thanks Nate, for your comprehension of the plight of many, if not most, newish Python coders. And it certainly doesn't help to ask the list to fill in some of the holes and be met with criticism for asking, but I digress. It is what it is. Before I started reading the list a few months ago, I'd heard of list comprehensions in an article I'd read, and hardly understood the gist of it. But look at me now Ma, I've learned not only how to use list comprehensions but also a small tribe of other kinds of comprehensions! (If there's a moral to this story, heck if I know exactly what it is. "Keep on trying" is as good as any.) Deborah > On Mon, Apr 3, 2017 at 3:47 PM, Jerry Hill > wrote: > > > On Mon, Apr 3, 2017 at 10:30 AM, Deborah Swanson > > wrote: > > > Regular updates as the docs are updated would be a good idea too. > > > It's obvious that today's Google isn't up to it, although > it occurs > > > to me that I haven't tried Google's site search on python.org. > > > > So, when you search google for the phrase "dict comprehension" or > > "dictionary comprehension", nothing useful comes up for > you? When I > > search either of those phrases, I get lots of useful > results, all of > > which spell out how to do what you were originally asking about. I > > know Google search results are skewed by past usage, but > I'm surprised > > that you didn't find anything useful in the first couple of search > > results. > > > > When I do a search for 'dict comprehension' I get a boxed result > > linking to PEP 274 as the first hit, then two Stack Overflow > > questions, both of which demonstrate how to do dictionary > > comprehensions. Following that is another link to PEP 274, > a link to > > the Python docs on data structures (which does talk about dict > > comprehensions, but it's way down on the page), and then links to a > > bunch of tutorials. If you had to judge based on my search > results, > > Google does a fine job of answering python questions, at least when > > you already know the key phrase to look for. > > > > -- > > Jerry > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list > From dieter at handshake.de Tue Apr 4 01:23:33 2017 From: dieter at handshake.de (dieter) Date: Tue, 04 Apr 2017 07:23:33 +0200 Subject: Obtain Ceritificate Information from Invalid or Self-Signed Certificate in Python References: Message-ID: <87efx8lp9m.fsf@handshake.de> Kenneth Buckler writes: > I'm working on a Python 2.7.13 (Win x64) script to verify SSL certificates, > and alert for problems. Specifically, I'm looking to return the date the > cert expires or did expire. However, I'm running into an issue where the > script will return information only if the certificate is valid. You may need to tell the Python socket library that you are ready to accept any certificate - even expired ones. I see below, that you already have tried that ("conn._https_verify_certificates(enable=False)") but it failed. The reason: "_https_verify_certificates" is a function of the "ssl" module, not a method of "SSLSocket" instances. It is used to switch (globally) the behavior for verifying certificates, not locally for a specific "SSLSocket". Given the architecture of the "ssl" module (with the component classes "socket", "SSLContext" and "SSLSocket"), the most likely place to control the certificate verification is the "SSLContext". And indeed, it has an attribute "verify_mode" to control this behaviour. Likely, there is an alternative to disable certificate verification in your case: the "ssl" module has the function "get_server_certificate"; you could try to perform a normal ssl connection and if this fails due to certificate problems, you could fetch the certificate with the above function and analyse it. > ... > Per https://docs.python.org/2/library/ssl.html I tried to use > conn._https_verify_certificates(enable=False) to disable certificate > validation, but get an error that the attribute _https_verify_certificates > doesn't exist. > ... From dieter at handshake.de Tue Apr 4 01:31:30 2017 From: dieter at handshake.de (dieter) Date: Tue, 04 Apr 2017 07:31:30 +0200 Subject: Appending data to a json file References: Message-ID: <87a87wlowd.fsf@handshake.de> Dave writes: > I created a python program that gets data from a user, stores the data > as a dictionary in a list of dictionaries. When the program quits, it > saves the data file. My desire is to append the new data to the > existing data file as is done with purely text files. Usually, you cannot do that: "JSON" stands for "JavaScript Object Notation": it is a text representation for a single (!) JavaScript object. The concatenation of two JSON representations is not a valid JSON representation. Thus, you cannot expect that after such a concatenation, a single call to "load" will give you back complete information (it might be that a sequence of "load"s works). Personally, I would avoid concatenated JSON representations. Instead, I would read in (i.e. "load") the existing data, construct a Python object from the old and the new data (likely in the form of a list) and then write it out (i.e. "dump") again. From python-oren at ben-kiki.org Tue Apr 4 01:50:53 2017 From: python-oren at ben-kiki.org (Oren Ben-Kiki) Date: Tue, 4 Apr 2017 08:50:53 +0300 Subject: Appending data to a json file In-Reply-To: <87a87wlowd.fsf@handshake.de> References: <87a87wlowd.fsf@handshake.de> Message-ID: You _can_ just extend a JSON file without loading it, but it will not be "fun". Say the JSON file contains a top-level array. The final significant character in it would be a ']'. So, you can read just a reasonably-sized block from the end of the file, find the location of the final ']', overwrite it with a ',' followed by your additional array entry/entries, with a final ']'. If the JSON file contains a top-level object, the final significant character would be a '}'. Overwrite it with a ',' followed by your additional object key/value pairs, with a final '}'. Basically, if what you want to append is of the same kind as the content of the file (array appended to array, or object to object): - Locate final significant character in the file - Locate first significant character in your appended data, replace it with a ',' - Overwrite the final significant character in the file with your patched data It isn't elegant or very robust, but if you want to append to a very large JSON array (for example, some log file?), then it could be very efficient and effective. Or, you could use YAML ;-) On Tue, Apr 4, 2017 at 8:31 AM, dieter wrote: > Dave writes: > > > I created a python program that gets data from a user, stores the data > > as a dictionary in a list of dictionaries. When the program quits, it > > saves the data file. My desire is to append the new data to the > > existing data file as is done with purely text files. > > Usually, you cannot do that: > "JSON" stands for "JavaScript Object Notation": it is a text representation > for a single (!) JavaScript object. The concatenation of two > JSON representations is not a valid JSON representation. > Thus, you cannot expect that after such a concatenation, a single > call to "load" will give you back complete information (it might > be that a sequence of "load"s works). > > Personally, I would avoid concatenated JSON representations. > Instead, I would read in (i.e. "load") the existing data, > construct a Python object from the old and the new data (likely in the form > of a list) and then write it out (i.e. "dump") again. > > -- > https://mail.python.org/mailman/listinfo/python-list > From python at deborahswanson.net Tue Apr 4 01:53:15 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Mon, 3 Apr 2017 22:53:15 -0700 Subject: Two variable dictionary comprehension In-Reply-To: Message-ID: <011b01d2ad07$c1324840$27b23dae@sambora> Gregory Ewing wrote, on Monday, April 03, 2017 4:23 PM > > Deborah Swanson wrote: > > All my guesses were based on the > > single variable (the most common type) examples I found. I just didn't > > think of putting a colon after 'label', and found nothing to suggest > > that's what I should do. > > Hmmm, I'm not sure what the docs could do to make that any > clearer. The key:value syntax is part of *every* dict > comprehension (it's the only thing that distinguishes a dict > comprehension from a set comprehension). I guess I saw a lot of examples that weren't clearly using the key:value syntax, and all of it was so unfamiliar, that pattern just didn't stand out to me. But it's starting to now, and that's the direction I need to go in for dict comprehensions. > > Despite my earlier words and protestations that I did look for two > > variable dict comprehensions, fairly diligently, I am taking what you > > said seriously. > > Don't feel too bad. Sometimes it's hard to know what to > google for, even for experienced people! Also it's hard for > doc writers to anticipate how less experienced people will > think. It wouldn't have occurred to me to use the phrase "two > variable dict comprehension" when writing documentation. Yes, I was pretty sure the terminology I phrased the question with wasn't correct, but I didn't know the right words to say, or where to look them up, so I just tried to be as descriptive as I could. But I accomplished my purpose in asking the question, even if it was poorly put, and I've received quite a bit of good information, the terminology I couldn't put my finger on, and some solid pointers of directions to go in the future. > Another thing it's important to be able to do is see through > to the principles behind things, and then use those > principles to solve new problems that aren't explicitly > covered in any docs or examples. Ah, yes, there's the rub. But it's true, from cooking to car mechanics to Python coding, the key is in becoming familiar with the subject, and hands on is the best teacher. (Yes, yes, we could have a discussion about the role of education, but I'll say that it's seeing it all in motion for yourself many times that seals the teaching into something you know and don't need to be told.) > The general principle behind all the forms of comprehension > is that they consist of a prototypical element, followed by > some clauses that generate values for that element. > > The syntax for the prototypical element mirrors that of the > corresponding display. So, for a dict comprehension, the > prototypical element has the form 'key:value', where 'key' > and 'value' are arbitrary expressions. From there, it's just > a matter of figuring out what to put into those expressions. > > In your case, another part of the puzzle is the fact that > you can unpack a tuple obtained from a for-loop into > variables. That's a general feature of for-loops, both > inside and outside of comprehensions, so you probably > won't find it mentioned explicitly under the heading of > dict comprehensions. > > > Maybe it would be worthwhile to scrape the whole mess and have it in > > searchable text form. > > The HTML Python docs have a "Search" box, although I haven't > really used it so I don't know how well it works. It sucks, in a phrase. You're presented with a list of web page titles, very few of which seem to have much to do with the Python language topic you type into the search box. If you're interested in theoretical dissertations you'll be pleased, but if you're looking for barebones mechanical descriptions of the language you'll be wasting your time, in my experience. > In my > experience, Google with a site search often works a lot > better than search functions provided by sites themselves. Yes, I used to use Google's site search on a regular basis but somehow got out of the habit. It likely can't be beat if you know which website will have the answer you're looking for, but the old Google truly shown at finding places you didn't already know about. > > I hope you won't be miffed though if I still come up empty handed and > > come back here to ask again. > > > > Deborah > > > -- > https://mail.python.org/mailman/listinfo/python-list > From python at deborahswanson.net Tue Apr 4 02:22:17 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Mon, 3 Apr 2017 23:22:17 -0700 Subject: Two variable dictionary comprehension In-Reply-To: Message-ID: <011e01d2ad0b$cf6a9580$27b23dae@sambora> Gregory Ewing wrote, on Monday, April 03, 2017 4:23 PM > > Deborah Swanson wrote: > > I'd > > imagine that the old Google would have returned a good 10 pages or > > more (probably a lot more) of urls containing the phrase "dict > > comprehension" or "dictionary comprehension". > > It still does, as far as I can see. I just googled for "dict > comprehension", and the vast majority of results in the first > 10 pages relate to Python. > > By page 20 it's starting to wander off a bit, but you can > hardly blame it for that. There *are* non-Python web pages > that mention the words "dict" and "comprehension", and how is > Google to know that you don't want those if you don't tell it? Yes, I searched on "python dict comprehension" because I'd gottion the idea somewhere that the "python" was necessary in this Brave New Google world. I'll remember to omit "python" in the future when searching for phrases most frequently found in Python. Boolean rules were so much easier to learn and remember. > > You used to be able to keep sifting through pages of results after the > > bulk of urls fitting your criteria had passed, and still find useful > > things to look at, sometimes at page 500 > > Seems to me Google was doing a rather *bad* job if you had > to wade through 500 pages of results to find what you wanted. > I would never have the patience to do that! Well, it helped if you used 100 search results per page and other various and sundry tools. But patience was good too. It depended how bad you wanted the answer and how good a skim reader you are. Now I rarely find anything I want unless I'm shopping for something to buy, but even then I have to wade through all the garbage results intended to entice the impulse buyer in me, which I ditched decades ago. > Anyhow, the reason Google got brought up was that you were > complaining about difficulty of finding things in the Python > docs. Google *does* turn up the relevant part of the docs in > the very first page of results, so being able to do a direct > text search on the docs wouldn't do any better. We can duke that out some other time. My illness is overcoming me fast though, so it won't be right away. Deborah > -- > Greg From python at deborahswanson.net Tue Apr 4 02:35:46 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Mon, 3 Apr 2017 23:35:46 -0700 Subject: Two variable dictionary comprehension In-Reply-To: <58e2f123$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: <012001d2ad0d$b1628690$27b23dae@sambora> Thanks Steve for writing this, and I'll read it more carefully when my illness gives my mind back to me. I was actually a math major before I discovered computer science, and I had to progress beyond machine language and assembler before I found the subtle differences and more flexible boundaries of higher level programming languages you talk about. I'm sure much of it's the same with Python. They key I think will be in finding more of the logic in Python, and then fleshing it out with more detail and choices. The core logic wasn't taught to me in the courses I took, so I need to backfill it now. I look forward to studying what you've written here as soon as I can. Deborah Steve D'Aprano wrote, on Monday, April 03, 2017 6:05 PM > > On Tue, 4 Apr 2017 03:27 am, Deborah Swanson wrote: > > > I'll admit that both dictionaries and comprehensions are still a > > little bit fuzzy to me, especially when I get away from the common > > usages. This could be a good exercise to clarify some of the fuzzy > > areas. > > > As far as comprehensions go, how is your mathematics? > > If you remember your set builder notation from maths, list > comprehensions are based on that. > > In maths, we say something like: > > {2n + 1 : 0 ? n ? 9} > > which might be read aloud as "the set of 2 times n, plus 1, > such that n is between 0 and 9 inclusive". > > http://www.mathwords.com/s/set_builder_notation.htm > > A similar notation might be: > > {2n + 1 : n ? {1, 2, 3}} > > said as "the set of 2 times n, plus 1, such that n is an > element of the set {1, 2, 3}". > > > If you're a maths geek like me, this is second nature :-) > > > Now, Python's list comprehension syntax is based on a similar > notation, except we spell it out in words rather than > symbols, using the familiar "for n in ..." syntax from > for-loops instead of : "such that". > > {2*n + 1 for n in range(10)} > > {2*n + 1 for n in (1, 2, 3)} > > > A few other differences: > > - list comprehensions use [ ] for the outermost brackets; > - set and dict comprehensions use { }; > - generator expressions use ( ) (unless the parentheses can > be implied). > > We're not restricted to mathematical expressions, and can use > any Python expression we like: > > [value.method(arg)[1] for (value, arg) in zip(values, arguments)] > > > translates roughly into this for-loop: > > result = [] > for (value, arg) in zip(values, arguments): > result.append(value.method(arg)[1]) > > > > Another difference is that comprehensions allow an "if" clause: > > [v.method(a)[1] for (v, a) in zip(values, arguments) if v is not None] > > translates something like: > > > result = [] > for (v, a) in zip(values, arguments): > if v is not None: > result.append(v.method(a)[1]) > > > There's more, but that covers probably 98% of comprehension usage. > > And of course, remember that dict comprehensions use the same > key:value syntax as ordinary dict "literals" (the official > name is "dict display"). > > result = {} > for key, value in zip(keys, values): > result[key] = value > > > becomes > > result = {key:value for (key, value) in zip(keys, values)} > > although frankly that's better written as: > > dict(zip(keys, values)) > > > > Hope this helps! > > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered > up, and sure enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Tue Apr 4 02:41:09 2017 From: __peter__ at web.de (Peter Otten) Date: Tue, 04 Apr 2017 08:41:09 +0200 Subject: Basic Nested Dictionary in a Loop References: Message-ID: Ganesh Pal wrote: >> >> >> Whenever you feel the urge to write range(len(whatever)) -- resist that >> temptation, and you'll end up with better Python code ;) >> >> > Thanks for this suggestion but for my better understanding can explain > this further even Steve did point the same mistake. It's not directly a mistake, it's just that programming against a smaller interface makes your code more flexible and more readable. Readability: items = [...] for i in range(len(items)): ... Are list entries replaced? We cannot know without inspecting the for suite. items = [...] for item in items: ... Are list entries replaced? No. Flexibility: def give_raise(employees, amount): for i in range(len(items)): employee = employees[i] employee.payment += amount employees = [...] give_raise(employees, 10) Now let's adapt the code to raise the payment of some employees: male_employees = [ employees[i] for i in range(len(employees)) if e.sex == "male" ] give_raise(male_emplyees, 10) We need a helper list, basically because there is a len() call inside the give_raise() function. If we rewrite the function in an idiomatic way def give_raise(employees, amount): for employee in employees: employee.payment += amount it will become not just more concise, the calling code no longer needs to build the intermediate list. Instead we save the extra memory and pass a generator expression: give_raise((e for e in employees if e.sex == "female"), 10) In a similar way you can write code that iterates over data that is lazily read into memory, like lines in a file # wrong, reads the whole file into memory lines = open(...).readlines() for i in range(len(lines)): process(lines[i]) # idiomatic, read the lines as needed for line in open(...): process(line) or records from a database. From mal at europython.eu Tue Apr 4 04:45:18 2017 From: mal at europython.eu (M.-A. Lemburg) Date: Tue, 4 Apr 2017 10:45:18 +0200 Subject: EuroPython 2017: Early-bird Tickets now on sale! Message-ID: <6b81b1b4-ad03-1047-3a82-d843ad7a1a9d@europython.eu> Interested in attending EuroPython? Entry tickets are now on sale and available on our website. *** Buy your EuroPython ticket *** https://ep2017.europython.eu/en/registration/buy-tickets/ Tickets for EuroPython will be sold in three phases: First, we?ll have a short early-bird ticket phase, where we?ll sell tickets at a very low rate. Only 200 tickets will be available for this rate, so be quick. It usually takes just a few days for them to sell out. We?ll then switch to the regular rates, and closer to the conference, to the on-desk rates. You can get tickets for the whole week, if you don?t want to miss anything, or buy day passes at the on-desk rates in July to attend only one or two days. We further offer three different rates: ?students? (including PhD and postdoc researchers), ?personal? and ?business? passes (for companies). Speakers and trainers will benefit of special discounts. See Call for Proposals for further details: https://ep2017.europython.eu/en/call-for-proposals/ Take this opportunity and get your ticket now! Prices will increase the closer we get to the event. Enjoy, -- EuroPython 2017 Team http://ep2017.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/849177756873224193 Thanks. From prathamesh.nimkar at gmail.com Tue Apr 4 09:20:55 2017 From: prathamesh.nimkar at gmail.com (Prathamesh) Date: Tue, 4 Apr 2017 06:20:55 -0700 (PDT) Subject: Improve Python + Influxdb import performance In-Reply-To: References: <104d49b4-da8c-4b23-a520-3042c9d91a3d@googlegroups.com> Message-ID: <634caa93-f512-43db-9084-c4fb361e9366@googlegroups.com> Hi Inada Thank you for your response Weblogic works on Jython 2.2.1 and I think the Python requests module requires >= python 2.6 Please correct me if I'm wrong or if there is another way to get this to work Thanks P On Monday, April 3, 2017 at 9:52:38 PM UTC+5:30, INADA Naoki wrote: > You can reuse connection, instead of creating for each request. (HTTP > keep-alive). > > On Tue, Apr 4, 2017 at 1:11 AM, Prathamesh wrote: > > Hello World > > > > The following script is an extract from > > > > https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py > > > > <> > > > > import calendar, time > > import sys > > import getopt > > > > print '---------------------------------------' > > > > # Check the arguments to this script are as expected. > > # argv[0] is script name. > > argLen = len(sys.argv) > > if argLen -1 < 2: > > print "ERROR: got ", argLen -1, " args, must be at least two." > > print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py [] [] [] [] [targetDB influx db>' > > exit() > > > > outputFormat='CSV' > > url='t3://localhost:7001' > > targetHost='localhost' > > targetDB='obi' > > targetPort='8086' > > > > try: > > wls_user = sys.argv[1] > > wls_pw = sys.argv[2] > > url = sys.argv[3] > > outputFormat=sys.argv[4] > > targetHost=sys.argv[5] > > targetPort=sys.argv[6] > > targetDB=sys.argv[7] > > except: > > print '' > > > > print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB > > > > now_epoch = calendar.timegm(time.gmtime())*1000 > > > > if outputFormat=='InfluxDB': > > import httplib > > influx_msgs='' > > > > connect(wls_user,wls_pw,url) > > results = displayMetricTables('Oracle_BI*','dms_cProcessInfo') > > for table in results: > > tableName = table.get('Table') > > rows = table.get('Rows') > > rowCollection = rows.values() > > iter = rowCollection.iterator() > > while iter.hasNext(): > > row = iter.next() > > rowType = row.getCompositeType() > > keys = rowType.keySet() > > keyIter = keys.iterator() > > inst_name= row.get('Name').replace(' ','-') > > try: > > server= row.get('Servername').replace(' ','-').replace('/','_') > > except: > > try: > > server= row.get('ServerName').replace(' ','-').replace('/','_') > > except: > > server='unknown' > > try: > > host= row.get('Host').replace(' ','-') > > except: > > host='' > > while keyIter.hasNext(): > > columnName = keyIter.next() > > value = row.get(columnName ) > > if columnName.find('.value')>0: > > metric_name=columnName.replace('.value','') > > if value is not None: > > if value != 0: > > if outputFormat=='InfluxDB': > > influx_msg= ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % (metric_name,server,host,tableName,inst_name, value,now_epoch*1000000) > > influx_msgs+='\n%s' % influx_msg > > conn = httplib.HTTPConnection('%s:%s' % (targetHost,targetPort)) > > ## TODO pretty sure should be urlencoding this ... > > a=conn.request("POST", ("/write?db=%s" % targetDB), influx_msg) > > r=conn.getresponse() > > > > <> > > > > It currently takes about 3 minutes to execute completely and I was thinking of a way to make it run faster > > > > Data alignment (Influx line protocol) & data loading - done together takes up most of the time > > > > Influxdb is currently loading data at around 3 points/second > > > > Any way to align the data separately, store it and load it as a batch? > > > > I feel that would help improve performance > > > > Please let me know if you have any pointers > > I can send the data sheet if required > > > > Thanks P > > -- > > https://mail.python.org/mailman/listinfo/python-list On Monday, April 3, 2017 at 9:52:38 PM UTC+5:30, INADA Naoki wrote: > You can reuse connection, instead of creating for each request. (HTTP > keep-alive). > > On Tue, Apr 4, 2017 at 1:11 AM, Prathamesh wrote: > > Hello World > > > > The following script is an extract from > > > > https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py > > > > <> > > > > import calendar, time > > import sys > > import getopt > > > > print '---------------------------------------' > > > > # Check the arguments to this script are as expected. > > # argv[0] is script name. > > argLen = len(sys.argv) > > if argLen -1 < 2: > > print "ERROR: got ", argLen -1, " args, must be at least two." > > print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py [] [] [] [] [targetDB influx db>' > > exit() > > > > outputFormat='CSV' > > url='t3://localhost:7001' > > targetHost='localhost' > > targetDB='obi' > > targetPort='8086' > > > > try: > > wls_user = sys.argv[1] > > wls_pw = sys.argv[2] > > url = sys.argv[3] > > outputFormat=sys.argv[4] > > targetHost=sys.argv[5] > > targetPort=sys.argv[6] > > targetDB=sys.argv[7] > > except: > > print '' > > > > print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB > > > > now_epoch = calendar.timegm(time.gmtime())*1000 > > > > if outputFormat=='InfluxDB': > > import httplib > > influx_msgs='' > > > > connect(wls_user,wls_pw,url) > > results = displayMetricTables('Oracle_BI*','dms_cProcessInfo') > > for table in results: > > tableName = table.get('Table') > > rows = table.get('Rows') > > rowCollection = rows.values() > > iter = rowCollection.iterator() > > while iter.hasNext(): > > row = iter.next() > > rowType = row.getCompositeType() > > keys = rowType.keySet() > > keyIter = keys.iterator() > > inst_name= row.get('Name').replace(' ','-') > > try: > > server= row.get('Servername').replace(' ','-').replace('/','_') > > except: > > try: > > server= row.get('ServerName').replace(' ','-').replace('/','_') > > except: > > server='unknown' > > try: > > host= row.get('Host').replace(' ','-') > > except: > > host='' > > while keyIter.hasNext(): > > columnName = keyIter.next() > > value = row.get(columnName ) > > if columnName.find('.value')>0: > > metric_name=columnName.replace('.value','') > > if value is not None: > > if value != 0: > > if outputFormat=='InfluxDB': > > influx_msg= ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % (metric_name,server,host,tableName,inst_name, value,now_epoch*1000000) > > influx_msgs+='\n%s' % influx_msg > > conn = httplib.HTTPConnection('%s:%s' % (targetHost,targetPort)) > > ## TODO pretty sure should be urlencoding this ... > > a=conn.request("POST", ("/write?db=%s" % targetDB), influx_msg) > > r=conn.getresponse() > > > > <> > > > > It currently takes about 3 minutes to execute completely and I was thinking of a way to make it run faster > > > > Data alignment (Influx line protocol) & data loading - done together takes up most of the time > > > > Influxdb is currently loading data at around 3 points/second > > > > Any way to align the data separately, store it and load it as a batch? > > > > I feel that would help improve performance > > > > Please let me know if you have any pointers > > I can send the data sheet if required > > > > Thanks P > > -- > > https://mail.python.org/mailman/listinfo/python-list On Monday, April 3, 2017 at 9:52:38 PM UTC+5:30, INADA Naoki wrote: > You can reuse connection, instead of creating for each request. (HTTP > keep-alive). > > On Tue, Apr 4, 2017 at 1:11 AM, Prathamesh wrote: > > Hello World > > > > The following script is an extract from > > > > https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py > > > > <> > > > > import calendar, time > > import sys > > import getopt > > > > print '---------------------------------------' > > > > # Check the arguments to this script are as expected. > > # argv[0] is script name. > > argLen = len(sys.argv) > > if argLen -1 < 2: > > print "ERROR: got ", argLen -1, " args, must be at least two." > > print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py [] [] [] [] [targetDB influx db>' > > exit() > > > > outputFormat='CSV' > > url='t3://localhost:7001' > > targetHost='localhost' > > targetDB='obi' > > targetPort='8086' > > > > try: > > wls_user = sys.argv[1] > > wls_pw = sys.argv[2] > > url = sys.argv[3] > > outputFormat=sys.argv[4] > > targetHost=sys.argv[5] > > targetPort=sys.argv[6] > > targetDB=sys.argv[7] > > except: > > print '' > > > > print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB > > > > now_epoch = calendar.timegm(time.gmtime())*1000 > > > > if outputFormat=='InfluxDB': > > import httplib > > influx_msgs='' > > > > connect(wls_user,wls_pw,url) > > results = displayMetricTables('Oracle_BI*','dms_cProcessInfo') > > for table in results: > > tableName = table.get('Table') > > rows = table.get('Rows') > > rowCollection = rows.values() > > iter = rowCollection.iterator() > > while iter.hasNext(): > > row = iter.next() > > rowType = row.getCompositeType() > > keys = rowType.keySet() > > keyIter = keys.iterator() > > inst_name= row.get('Name').replace(' ','-') > > try: > > server= row.get('Servername').replace(' ','-').replace('/','_') > > except: > > try: > > server= row.get('ServerName').replace(' ','-').replace('/','_') > > except: > > server='unknown' > > try: > > host= row.get('Host').replace(' ','-') > > except: > > host='' > > while keyIter.hasNext(): > > columnName = keyIter.next() > > value = row.get(columnName ) > > if columnName.find('.value')>0: > > metric_name=columnName.replace('.value','') > > if value is not None: > > if value != 0: > > if outputFormat=='InfluxDB': > > influx_msg= ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % (metric_name,server,host,tableName,inst_name, value,now_epoch*1000000) > > influx_msgs+='\n%s' % influx_msg > > conn = httplib.HTTPConnection('%s:%s' % (targetHost,targetPort)) > > ## TODO pretty sure should be urlencoding this ... > > a=conn.request("POST", ("/write?db=%s" % targetDB), influx_msg) > > r=conn.getresponse() > > > > <> > > > > It currently takes about 3 minutes to execute completely and I was thinking of a way to make it run faster > > > > Data alignment (Influx line protocol) & data loading - done together takes up most of the time > > > > Influxdb is currently loading data at around 3 points/second > > > > Any way to align the data separately, store it and load it as a batch? > > > > I feel that would help improve performance > > > > Please let me know if you have any pointers > > I can send the data sheet if required > > > > Thanks P > > -- > > https://mail.python.org/mailman/listinfo/python-list On Monday, April 3, 2017 at 9:52:38 PM UTC+5:30, INADA Naoki wrote: > You can reuse connection, instead of creating for each request. (HTTP > keep-alive). > > On Tue, Apr 4, 2017 at 1:11 AM, Prathamesh wrote: > > Hello World > > > > The following script is an extract from > > > > https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py > > > > <> > > > > import calendar, time > > import sys > > import getopt > > > > print '---------------------------------------' > > > > # Check the arguments to this script are as expected. > > # argv[0] is script name. > > argLen = len(sys.argv) > > if argLen -1 < 2: > > print "ERROR: got ", argLen -1, " args, must be at least two." > > print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py [] [] [] [] [targetDB influx db>' > > exit() > > > > outputFormat='CSV' > > url='t3://localhost:7001' > > targetHost='localhost' > > targetDB='obi' > > targetPort='8086' > > > > try: > > wls_user = sys.argv[1] > > wls_pw = sys.argv[2] > > url = sys.argv[3] > > outputFormat=sys.argv[4] > > targetHost=sys.argv[5] > > targetPort=sys.argv[6] > > targetDB=sys.argv[7] > > except: > > print '' > > > > print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB > > > > now_epoch = calendar.timegm(time.gmtime())*1000 > > > > if outputFormat=='InfluxDB': > > import httplib > > influx_msgs='' > > > > connect(wls_user,wls_pw,url) > > results = displayMetricTables('Oracle_BI*','dms_cProcessInfo') > > for table in results: > > tableName = table.get('Table') > > rows = table.get('Rows') > > rowCollection = rows.values() > > iter = rowCollection.iterator() > > while iter.hasNext(): > > row = iter.next() > > rowType = row.getCompositeType() > > keys = rowType.keySet() > > keyIter = keys.iterator() > > inst_name= row.get('Name').replace(' ','-') > > try: > > server= row.get('Servername').replace(' ','-').replace('/','_') > > except: > > try: > > server= row.get('ServerName').replace(' ','-').replace('/','_') > > except: > > server='unknown' > > try: > > host= row.get('Host').replace(' ','-') > > except: > > host='' > > while keyIter.hasNext(): > > columnName = keyIter.next() > > value = row.get(columnName ) > > if columnName.find('.value')>0: > > metric_name=columnName.replace('.value','') > > if value is not None: > > if value != 0: > > if outputFormat=='InfluxDB': > > influx_msg= ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % (metric_name,server,host,tableName,inst_name, value,now_epoch*1000000) > > influx_msgs+='\n%s' % influx_msg > > conn = httplib.HTTPConnection('%s:%s' % (targetHost,targetPort)) > > ## TODO pretty sure should be urlencoding this ... > > a=conn.request("POST", ("/write?db=%s" % targetDB), influx_msg) > > r=conn.getresponse() > > > > <> > > > > It currently takes about 3 minutes to execute completely and I was thinking of a way to make it run faster > > > > Data alignment (Influx line protocol) & data loading - done together takes up most of the time > > > > Influxdb is currently loading data at around 3 points/second > > > > Any way to align the data separately, store it and load it as a batch? > > > > I feel that would help improve performance > > > > Please let me know if you have any pointers > > I can send the data sheet if required > > > > Thanks P > > -- > > https://mail.python.org/mailman/listinfo/python-list On Monday, April 3, 2017 at 9:52:38 PM UTC+5:30, INADA Naoki wrote: > You can reuse connection, instead of creating for each request. (HTTP > keep-alive). > > On Tue, Apr 4, 2017 at 1:11 AM, Prathamesh wrote: > > Hello World > > > > The following script is an extract from > > > > https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py > > > > <> > > > > import calendar, time > > import sys > > import getopt > > > > print '---------------------------------------' > > > > # Check the arguments to this script are as expected. > > # argv[0] is script name. > > argLen = len(sys.argv) > > if argLen -1 < 2: > > print "ERROR: got ", argLen -1, " args, must be at least two." > > print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py [] [] [] [] [targetDB influx db>' > > exit() > > > > outputFormat='CSV' > > url='t3://localhost:7001' > > targetHost='localhost' > > targetDB='obi' > > targetPort='8086' > > > > try: > > wls_user = sys.argv[1] > > wls_pw = sys.argv[2] > > url = sys.argv[3] > > outputFormat=sys.argv[4] > > targetHost=sys.argv[5] > > targetPort=sys.argv[6] > > targetDB=sys.argv[7] > > except: > > print '' > > > > print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB > > > > now_epoch = calendar.timegm(time.gmtime())*1000 > > > > if outputFormat=='InfluxDB': > > import httplib > > influx_msgs='' > > > > connect(wls_user,wls_pw,url) > > results = displayMetricTables('Oracle_BI*','dms_cProcessInfo') > > for table in results: > > tableName = table.get('Table') > > rows = table.get('Rows') > > rowCollection = rows.values() > > iter = rowCollection.iterator() > > while iter.hasNext(): > > row = iter.next() > > rowType = row.getCompositeType() > > keys = rowType.keySet() > > keyIter = keys.iterator() > > inst_name= row.get('Name').replace(' ','-') > > try: > > server= row.get('Servername').replace(' ','-').replace('/','_') > > except: > > try: > > server= row.get('ServerName').replace(' ','-').replace('/','_') > > except: > > server='unknown' > > try: > > host= row.get('Host').replace(' ','-') > > except: > > host='' > > while keyIter.hasNext(): > > columnName = keyIter.next() > > value = row.get(columnName ) > > if columnName.find('.value')>0: > > metric_name=columnName.replace('.value','') > > if value is not None: > > if value != 0: > > if outputFormat=='InfluxDB': > > influx_msg= ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % (metric_name,server,host,tableName,inst_name, value,now_epoch*1000000) > > influx_msgs+='\n%s' % influx_msg > > conn = httplib.HTTPConnection('%s:%s' % (targetHost,targetPort)) > > ## TODO pretty sure should be urlencoding this ... > > a=conn.request("POST", ("/write?db=%s" % targetDB), influx_msg) > > r=conn.getresponse() > > > > <> > > > > It currently takes about 3 minutes to execute completely and I was thinking of a way to make it run faster > > > > Data alignment (Influx line protocol) & data loading - done together takes up most of the time > > > > Influxdb is currently loading data at around 3 points/second > > > > Any way to align the data separately, store it and load it as a batch? > > > > I feel that would help improve performance > > > > Please let me know if you have any pointers > > I can send the data sheet if required > > > > Thanks P > > -- > > https://mail.python.org/mailman/listinfo/python-list On Monday, April 3, 2017 at 9:52:38 PM UTC+5:30, INADA Naoki wrote: > You can reuse connection, instead of creating for each request. (HTTP > keep-alive). > > On Tue, Apr 4, 2017 at 1:11 AM, Prathamesh wrote: > > Hello World > > > > The following script is an extract from > > > > https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py > > > > <> > > > > import calendar, time > > import sys > > import getopt > > > > print '---------------------------------------' > > > > # Check the arguments to this script are as expected. > > # argv[0] is script name. > > argLen = len(sys.argv) > > if argLen -1 < 2: > > print "ERROR: got ", argLen -1, " args, must be at least two." > > print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py [] [] [] [] [targetDB influx db>' > > exit() > > > > outputFormat='CSV' > > url='t3://localhost:7001' > > targetHost='localhost' > > targetDB='obi' > > targetPort='8086' > > > > try: > > wls_user = sys.argv[1] > > wls_pw = sys.argv[2] > > url = sys.argv[3] > > outputFormat=sys.argv[4] > > targetHost=sys.argv[5] > > targetPort=sys.argv[6] > > targetDB=sys.argv[7] > > except: > > print '' > > > > print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB > > > > now_epoch = calendar.timegm(time.gmtime())*1000 > > > > if outputFormat=='InfluxDB': > > import httplib > > influx_msgs='' > > > > connect(wls_user,wls_pw,url) > > results = displayMetricTables('Oracle_BI*','dms_cProcessInfo') > > for table in results: > > tableName = table.get('Table') > > rows = table.get('Rows') > > rowCollection = rows.values() > > iter = rowCollection.iterator() > > while iter.hasNext(): > > row = iter.next() > > rowType = row.getCompositeType() > > keys = rowType.keySet() > > keyIter = keys.iterator() > > inst_name= row.get('Name').replace(' ','-') > > try: > > server= row.get('Servername').replace(' ','-').replace('/','_') > > except: > > try: > > server= row.get('ServerName').replace(' ','-').replace('/','_') > > except: > > server='unknown' > > try: > > host= row.get('Host').replace(' ','-') > > except: > > host='' > > while keyIter.hasNext(): > > columnName = keyIter.next() > > value = row.get(columnName ) > > if columnName.find('.value')>0: > > metric_name=columnName.replace('.value','') > > if value is not None: > > if value != 0: > > if outputFormat=='InfluxDB': > > influx_msg= ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % (metric_name,server,host,tableName,inst_name, value,now_epoch*1000000) > > influx_msgs+='\n%s' % influx_msg > > conn = httplib.HTTPConnection('%s:%s' % (targetHost,targetPort)) > > ## TODO pretty sure should be urlencoding this ... > > a=conn.request("POST", ("/write?db=%s" % targetDB), influx_msg) > > r=conn.getresponse() > > > > <> > > > > It currently takes about 3 minutes to execute completely and I was thinking of a way to make it run faster > > > > Data alignment (Influx line protocol) & data loading - done together takes up most of the time > > > > Influxdb is currently loading data at around 3 points/second > > > > Any way to align the data separately, store it and load it as a batch? > > > > I feel that would help improve performance > > > > Please let me know if you have any pointers > > I can send the data sheet if required > > > > Thanks P > > -- > > https://mail.python.org/mailman/listinfo/python-list From cwrseckford at gmail.com Tue Apr 4 10:06:58 2017 From: cwrseckford at gmail.com (cwrseckford at gmail.com) Date: Tue, 4 Apr 2017 07:06:58 -0700 (PDT) Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dfcea3$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3b69fb8f-0c1a-467c-ac08-79afa0e0bbbe@googlegroups.com> On Saturday, 1 April 2017 17:01:03 UTC+1, Steve D'Aprano wrote: > On Sat, 1 Apr 2017 12:17 pm, Rick Johnson wrote: > > > Most people just quietly change the filename and move on > > > There are over a billion people in China, almost a billion more in India, > about 140 million people in Russia, nearly 130 million people in Japan, 250 > million in Indonesia, about 290 million native Arabic speakers, and even 9 > million speakers of Hebrew. > > If you think that all these people, and hundreds of millions more, will > just "quietly change the filename" to ASCII because you're too lazy, > self-centred and arrogant to move on from 1963, then you truly are an > example of the Ugly American. > Try to get your cliches straight. The "Ugly American" was the good guy, in contrast to the good-looking, smooth-talking State Department types who were the baddies. But hey, experience tells us that anyone ugly must automatically be wicked, not so? Will From torriem at gmail.com Tue Apr 4 10:17:57 2017 From: torriem at gmail.com (Michael Torrie) Date: Tue, 4 Apr 2017 08:17:57 -0600 Subject: Appending data to a json file In-Reply-To: <87a87wlowd.fsf@handshake.de> References: <87a87wlowd.fsf@handshake.de> Message-ID: <51ace66d-2451-da08-1c4a-4c3819400d8c@gmail.com> On 04/03/2017 11:31 PM, dieter wrote: > Dave writes: > >> I created a python program that gets data from a user, stores the data >> as a dictionary in a list of dictionaries. When the program quits, it >> saves the data file. My desire is to append the new data to the >> existing data file as is done with purely text files. > > Usually, you cannot do that: > "JSON" stands for "JavaScript Object Notation": That's assuming he's using JSON; he never specified what he's using to represent data as plain text. Though I suspect you're correct, for all we know he could just be writing data using his own text representation or writing to an ini file. And in his case it sounds like JSON is not an ideal method for saving his data since he's wanting to only append data, not read it in his program. In the future, Dave, please provide all the information pertaining to the problem so we can give accurate advice. Don't make us guess or assume we can all infer this information. From jussi.piitulainen at helsinki.fi Tue Apr 4 10:19:38 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 04 Apr 2017 17:19:38 +0300 Subject: Appending data to a json file References: <87a87wlowd.fsf@handshake.de> <51ace66d-2451-da08-1c4a-4c3819400d8c@gmail.com> Message-ID: Michael Torrie writes: > On 04/03/2017 11:31 PM, dieter wrote: >> Dave writes: >> >>> I created a python program that gets data from a user, stores the data >>> as a dictionary in a list of dictionaries. When the program quits, it >>> saves the data file. My desire is to append the new data to the >>> existing data file as is done with purely text files. >> >> Usually, you cannot do that: >> "JSON" stands for "JavaScript Object Notation": > > That's assuming he's using JSON; he never specified what he's using to > represent data as plain text. Though I suspect you're correct, for all > we know he could just be writing data using his own text representation > or writing to an ini file. And in his case it sounds like JSON is not > an ideal method for saving his data since he's wanting to only append > data, not read it in his program. > > In the future, Dave, please provide all the information pertaining to > the problem so we can give accurate advice. Don't make us guess or > assume we can all infer this information. The clue is on the subject line. From torriem at gmail.com Tue Apr 4 10:46:15 2017 From: torriem at gmail.com (Michael Torrie) Date: Tue, 4 Apr 2017 08:46:15 -0600 Subject: Appending data to a json file In-Reply-To: References: <87a87wlowd.fsf@handshake.de> <51ace66d-2451-da08-1c4a-4c3819400d8c@gmail.com> Message-ID: <7eeb2f6e-ea75-efcb-238b-fc2973d0bc9e@gmail.com> On 04/04/2017 08:19 AM, Jussi Piitulainen wrote: > The clue is on the subject line. Ahh, so it is. From venkatachalam.19 at gmail.com Tue Apr 4 10:57:59 2017 From: venkatachalam.19 at gmail.com (venkatachalam.19 at gmail.com) Date: Tue, 4 Apr 2017 07:57:59 -0700 (PDT) Subject: Data transmission from Python script to bash script Message-ID: <92a819af-f997-4140-b1dc-74ee757036cf@googlegroups.com> Hello All, I am writing a python code for processing a data obtained from a sensor. The data from sensor is obtained by executing a python script. The data obtained should be further given to another python module where the received data is used for adjusting the location of an object. For achieving this, there is a central bash script, which runs both the python modules parallel. Something like: python a.py & python b.py & I am trying to return the sensor data to the bash .sh file, therefore it can be provided to the other script. This, based on the online tutorials: sensor_data=$(python execute_sensor_process.py) & and the sensor_data is assigned by printing the required data in the corresponding python script. For example, the data is printed in a.py as follows: print >>sys.stderr,sens_data By printing the data onto sys.stderr and assigning a return variable in the bash, I am expecting the data to be assigned. But this is not happening. The sensor data is a dictionary and I like to have this data for further analysis. Can someone help me to understand why the code is not working? I tried other approaches of function call such as sensor_data=$`python execute_sensor_process.py` & #python a.py tempfile.txt & kinexon_data=`cat tempfile.txt` & But none of the approaches are working. Thank you, Venkatachalam Srinivasan From venkatachalam.19 at gmail.com Tue Apr 4 11:01:42 2017 From: venkatachalam.19 at gmail.com (venkatachalam.19 at gmail.com) Date: Tue, 4 Apr 2017 08:01:42 -0700 (PDT) Subject: Data exchange between python script and bash script Message-ID: <50298d86-e688-4162-b96f-632e5a98c141@googlegroups.com> Hello All, I am writing a python code for processing a data obtained from a sensor. The data from sensor is obtained by executing a python script. The data obtained should be further given to another python module where the received data is used for adjusting the location of an object. For achieving this, there is a central bash script, which runs both the python modules parallel. Something like: python a.py & python b.py & I am trying to return the sensor data to the bash .sh file, therefore it can be provided to the other script. This, based on the online tutorials looks like: sensor_data=$(python execute_sensor_process.py) & and the sensor_data is assigned by printing the required data in the corresponding python script. For example, the data is printed in execute_sensor_process.py as follows: print >>sys.stderr,sens_data By printing the data onto sys.stderr and assigning a return variable in the bash, I am expecting the data to be assigned. But this is not happening. The sensor data is a dictionary and I like to have this data for further analysis. I am not getting the data returned from the python script on to the bash variable. Can someone help me to understand why the code is not working? I tried other approaches of function call such as sensor_data=$`python execute_sensor_process.py` & python execute_sensor_process.py tempfile.txt & kinexon_data=`cat tempfile.txt` & But none of the approaches are working. Thank you, Venkatachalam Srinivasan From fpm at u.washington.edu Tue Apr 4 11:24:31 2017 From: fpm at u.washington.edu (Frank Miles) Date: Tue, 4 Apr 2017 15:24:31 -0000 (UTC) Subject: Data exchange between python script and bash script References: <50298d86-e688-4162-b96f-632e5a98c141@googlegroups.com> Message-ID: On Tue, 04 Apr 2017 08:01:42 -0700, venkatachalam.19 wrote: > Hello All, > > I am writing a python code for processing a data obtained from a sensor. The data from sensor is obtained by executing a python script. The data obtained should be further given to another python module where the received data is used for adjusting the location of an object. > > For achieving this, there is a central bash script, which runs both the python modules parallel. Something like: > > python a.py & > python b.py & What is going on that two python scripts are needed? Which one generates the data needed by the bash script? > I am trying to return the sensor data to the bash .sh file, therefore it can be provided to the other script. This, based on the online tutorials looks like: > > sensor_data=$(python execute_sensor_process.py) & Presumably is simply getting the exit status code from the python interpreter, not the data, right? What are you seeing? > and the sensor_data is assigned by printing the required data in the corresponding python script. For example, the data is printed in execute_sensor_process.py as follows: > > print >>sys.stderr,sens_data > > By printing the data onto sys.stderr and assigning a return variable in the bash, I am expecting the data to be assigned. Assigned to what? Some return variable in bash? What?? Why not use stdout? Either pipe the data from python directly into a (possibly modified) bash script, or into a file which gets read by the bash script. > But this is not happening. The sensor data is a dictionary and I like to have this data for further analysis. I am not getting the data returned from the python script on to the bash variable. Bash doesn't have dictionaries like python. Why is bash needed? > Can someone help me to understand why the code is not working? I tried other approaches of function call such as You haven't given us enough of the code to really answer. > sensor_data=$`python execute_sensor_process.py` & > > python execute_sensor_process.py tempfile.txt & > kinexon_data=`cat tempfile.txt` & > > But none of the approaches are working. > > Thank you, > Venkatachalam Srinivasan I wonder if you could completely eliminate the bash script - do it all in python. I've written quite a few bash scripts, but not so many since I started using python. Only exception is for low level functions on systems without a functioning python. From walters.justin01 at gmail.com Tue Apr 4 11:42:09 2017 From: walters.justin01 at gmail.com (justin walters) Date: Tue, 4 Apr 2017 08:42:09 -0700 Subject: Data exchange between python script and bash script In-Reply-To: <50298d86-e688-4162-b96f-632e5a98c141@googlegroups.com> References: <50298d86-e688-4162-b96f-632e5a98c141@googlegroups.com> Message-ID: On Tue, Apr 4, 2017 at 8:01 AM, wrote: > Hello All, > > I am writing a python code for processing a data obtained from a sensor. > The data from sensor is obtained by executing a python script. The data > obtained should be further given to another python module where the > received data is used for adjusting the location of an object. > > For achieving this, there is a central bash script, which runs both the > python modules parallel. Something like: > > python a.py & > python b.py & > > I am trying to return the sensor data to the bash .sh file, therefore it > can be provided to the other script. This, based on the online tutorials > looks like: > > sensor_data=$(python execute_sensor_process.py) & > > and the sensor_data is assigned by printing the required data in the > corresponding python script. For example, the data is printed in > execute_sensor_process.py as follows: > > print >>sys.stderr,sens_data > > By printing the data onto sys.stderr and assigning a return variable in > the bash, I am expecting the data to be assigned. > > But this is not happening. The sensor data is a dictionary and I like to > have this data for further analysis. I am not getting the data returned > from the python script on to the bash variable. > > Can someone help me to understand why the code is not working? I tried > other approaches of function call such as > > > sensor_data=$`python execute_sensor_process.py` & > > > python execute_sensor_process.py tempfile.txt & > kinexon_data=`cat tempfile.txt` & > > But none of the approaches are working. > > Thank you, > Venkatachalam Srinivasan > -- > https://mail.python.org/mailman/listinfo/python-list > I'm not sure why you need the data in a bash script. What can you do with a bash script that you can't do with Python? That said, it seems to me that you need a data persistence layer, i.e. a way to store the dictionary after it is created. My best advice would be to use the json module to write out to json files. I believe this is the best approach because json has a near 1-to-1 mapping with Python dictionaries. Json is also a good choice because almost every language has a json parser as part of it's standard library, making you data extremely portable. From ganesh1pal at gmail.com Tue Apr 4 12:07:56 2017 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Tue, 4 Apr 2017 21:37:56 +0530 Subject: Basic Nested Dictionary in a Loop In-Reply-To: References: Message-ID: Thanks Peter , Terry and others ! On Tue, Apr 4, 2017 at 12:11 PM, Peter Otten <__peter__ at web.de> wrote: > Ganesh Pal wrote: > > >> > >> > >> Whenever you feel the urge to write range(len(whatever)) -- resist that > >> temptation, and you'll end up with better Python code ;) > >> > >> > > Thanks for this suggestion but for my better understanding can explain > > this further even Steve did point the same mistake. > > It's not directly a mistake, it's just that programming against a smaller > interface makes your code more flexible and more readable. > > Readability: > > items = [...] > for i in range(len(items)): > ... > > Are list entries replaced? We cannot know without inspecting the for suite. > > items = [...] > for item in items: > ... > > Are list entries replaced? No. > > Flexibility: > > def give_raise(employees, amount): > for i in range(len(items)): > employee = employees[i] > employee.payment += amount > > employees = [...] > give_raise(employees, 10) > > Now let's adapt the code to raise the payment of some employees: > > male_employees = [ > employees[i] for i in range(len(employees)) > if e.sex == "male" > ] > give_raise(male_emplyees, 10) > > We need a helper list, basically because there is a len() call inside the > give_raise() function. If we rewrite the function in an idiomatic way > > def give_raise(employees, amount): > for employee in employees: > employee.payment += amount > > it will become not just more concise, the calling code no longer needs to > build the intermediate list. Instead we save the extra memory and pass a > generator expression: > > give_raise((e for e in employees if e.sex == "female"), 10) > > In a similar way you can write code that iterates over data that is lazily > read into memory, like lines in a file > > # wrong, reads the whole file into memory > lines = open(...).readlines() > for i in range(len(lines)): > process(lines[i]) > > # idiomatic, read the lines as needed > for line in open(...): > process(line) > > or records from a database. > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From robin.koch at t-online.de Tue Apr 4 12:20:50 2017 From: robin.koch at t-online.de (Robin Koch) Date: Tue, 4 Apr 2017 18:20:50 +0200 Subject: Appending data to a json file In-Reply-To: References: Message-ID: Am 04.04.2017 um 04:59 schrieb Dave: > I created a python program that gets data from a user, stores the data > as a dictionary in a list of dictionaries. When the program quits, it > saves the data file. My desire is to append the new data to the > existing data file as is done with purely text files. However, I can't > find a way to do that. The advice I have seen on the web is to load the > data when the program starts, append the new user input to the list, > then re-write the data file. Is that the best way, or is there a better > way? As explained by others JSON does not allow text based data appending. But maybe you take a look at YAML (if it's appropriate for your project). -- Robin Koch From ganesh1pal at gmail.com Tue Apr 4 12:56:03 2017 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Tue, 4 Apr 2017 22:26:03 +0530 Subject: Optimize this code further Message-ID: Dear friends. I am trying optimize the below sample code any suggestion on this please let me know yy-1# cat file1.py #! /usr/bin/python from __future__ import absolute_import, division, print_function import os import sys import logging logging.basicConfig(stream=sys.stderr, level=logging.INFO) logger = logging.getLogger(__name__) LOG_DIR = '/var/log/frobnitz' def createTestCases(LOG_DIR): '''create a test case data dictionary with parameters''' d = dict() d['test01'] = dict(object="inode", offset="18", size="4", optype="set") lin_02 = "something" d['test02'] = dict(object="lin", lin=lin_02, offset="18", size="5", optype="set") return addLogFilename(d, LOG_DIR) def run_tool(logfile, **kw): logger.info('%s would execute with %r', logfile, kw) def addLogFilename(d, logdir): '''put the logfile name into the test case data dictionary''' for casename, args in d.items(): args['logfile'] = os.path.join(logdir, casename + '.log') return d def main(): testcases = createTestCases(LOG_DIR) get_baddr = dict() for casename, kw in testcases.items(): # -- yank the logfile name out of the dictionary, before calling func logfile = kw.pop('logfile') get_baddr[casename] = run_tool(logfile, **kw) if __name__ == '__main__': main() # -- end of file yy-1# python file1.py INFO:__main__:/var/log/frobnitz/test02.log would execute with {'size': '5', 'lin': 'something', 'optype': 'set', 'object': 'lin', 'offset': '18'} INFO:__main__:/var/log/frobnitz/test01.log would execute with {'object': 'inode', 'optype': 'set', 'offset': '18', 'size': '4'} 1. I now need to have sub tests for every test i.e , so in the above program I will now need to store logs in the below format say for /var/log/frobnitz/Test_inode_01/ test01.log and /var/log/frobnitz/Test_inode_01/ test02.log .. etc 2. Everything else remains same and I am supposed to retain the same directory structure and logging Here is what I plan to do : 1. Use dictionary and Change testcases variable as dictionary and let its key store the subtest cases , so we have a nested dictionary testcase = {} testcase[?Test_inode_1?] = createTestCases(LOG_DIR) 2. Since I need to retain the same logging directory structure , maybe I should try to get the key first and then append it to the log file Question : 1. Any other simple tips and tricks to solve the problem , I am a Linux user using python 2.7 Regards, Ganesh From venkatachalam.19 at gmail.com Tue Apr 4 13:07:25 2017 From: venkatachalam.19 at gmail.com (Venkatachalam Srinivasan) Date: Tue, 4 Apr 2017 10:07:25 -0700 (PDT) Subject: Data exchange between python script and bash script In-Reply-To: References: <50298d86-e688-4162-b96f-632e5a98c141@googlegroups.com> Message-ID: <0e4014e2-ee4a-4177-ad8f-6c0470966a31@googlegroups.com> On Tuesday, April 4, 2017 at 5:27:42 PM UTC+2, cassiope wrote: > On Tue, 04 Apr 2017 08:01:42 -0700, venkatachalam.19 wrote: > > > Hello All, > > > > I am writing a python code for processing a data obtained from a sensor. The data from sensor is obtained by executing a python script. The data obtained should be further given to another python module where the received data is used for adjusting the location of an object. > > > > For achieving this, there is a central bash script, which runs both the python modules parallel. Something like: > > > > python a.py & > > python b.py & > > What is going on that two python scripts are needed? Which one generates the data needed by the bash script? One python script communicates with an external sensor and receives data. Another script controls a robot. That is based on ROS modules. >From the given code, a.py will be the script generating the data. Both the modules are independent of each other and so I have written both of them in different python scripts. > > > I am trying to return the sensor data to the bash .sh file, therefore it can be provided to the other script. This, based on the online tutorials looks like: > > > > sensor_data=$(python execute_sensor_process.py) & > > Presumably is simply getting the exit status code from the python interpreter, not the data, right? > What are you seeing? > I am not getting the exit status (I am not setting or printing return status in the python script). I need both the scripts running in parallel. Meaning the sensor will be continuously monitoring the location of the robot and this data will be used in another python script which controls the robot motion. For now, I am printing the output in the script and as far I understood, this can be assigned to a variable in the bash file from where this file is executed. I am not getting any output in the assigned variable in bash. > > and the sensor_data is assigned by printing the required data in the corresponding python script. For example, the data is printed in execute_sensor_process.py as follows: > > > > print >>sys.stderr,sens_data > > > > By printing the data onto sys.stderr and assigning a return variable in the bash, I am expecting the data to be assigned. > > Assigned to what? Some return variable in bash? What?? > Why not use stdout? Either pipe the data from python directly into a (possibly modified) bash script, > or into a file which gets read by the bash script. > Yes. As shown in "sensor_data=$(python execute_sensor_process.py) &", the variable sensor_data is assigned to hold the return value from the python script. I was using the stdout. But in some forums for similar problems, it is suggested to print the data to stderr (I really dont know what is the significance). I am unaware of piping the data from python. I will look into this. > > But this is not happening. The sensor data is a dictionary and I like to have this data for further analysis. I am not getting the data returned from the python script on to the bash variable. > > Bash doesn't have dictionaries like python. Why is bash needed? > Bash is needed to run the different scripts. I tried using multiprocess and thread from python, but really they are not performing parallel processing, when there are completely two different process. I understood it by executing the multiprocess/thread. Sequential operation was happening, which lead to the situation that only one python process is always executed. > > Can someone help me to understand why the code is not working? I tried other approaches of function call such as > > You haven't given us enough of the code to really answer. > > > sensor_data=$`python execute_sensor_process.py` & > > > > python execute_sensor_process.py tempfile.txt & > > kinexon_data=`cat tempfile.txt` & > > > > But none of the approaches are working. > > > > Thank you, > > Venkatachalam Srinivasan > > I wonder if you could completely eliminate the bash script - do it all in python. > I've written quite a few bash scripts, but not so many since I started using > python. Only exception is for low level functions on systems without a functioning > python. From dboland9 at fastmail.fm Tue Apr 4 13:23:52 2017 From: dboland9 at fastmail.fm (Dave) Date: Tue, 4 Apr 2017 13:23:52 -0400 Subject: Appending data to a json file References: <87a87wlowd.fsf@handshake.de> <51ace66d-2451-da08-1c4a-4c3819400d8c@gmail.com> Message-ID: On 04/04/2017 10:17 AM, Michael Torrie wrote: > On 04/03/2017 11:31 PM, dieter wrote: >> Dave writes: >> >>> I created a python program that gets data from a user, stores the data >>> as a dictionary in a list of dictionaries. When the program quits, it >>> saves the data file. My desire is to append the new data to the >>> existing data file as is done with purely text files. >> >> Usually, you cannot do that: >> "JSON" stands for "JavaScript Object Notation": > > That's assuming he's using JSON; he never specified what he's using to > represent data as plain text. Though I suspect you're correct, for all > we know he could just be writing data using his own text representation > or writing to an ini file. And in his case it sounds like JSON is not > an ideal method for saving his data since he's wanting to only append > data, not read it in his program. > > In the future, Dave, please provide all the information pertaining to > the problem so we can give accurate advice. Don't make us guess or > assume we can all infer this information. > I did. Please see the subject - it is json, not some bastardized version of it. While I didn't explicitly say that the data is read back in, it is - when the program starts. The user can enter more data, then save the data to the list (append). Then, like any other program, they can save the data to file. I don't care for the idea of replacing the data file for every save. My preference would to append to the existing data file - makes more sense. However, that is not how json works. So, I'm considering other alternatives for a data file structure. Paired data (key and value) is not really required, but my feeling is that it makes the data file more robust. A database seems a little over the top for this situation since there is no querying of data - just load and save. Dave, From ben+python at benfinney.id.au Tue Apr 4 13:37:11 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 05 Apr 2017 03:37:11 +1000 Subject: Appending data to a json file References: <87a87wlowd.fsf@handshake.de> <51ace66d-2451-da08-1c4a-4c3819400d8c@gmail.com> Message-ID: <851st8dqgo.fsf@benfinney.id.au> Dave writes: > I don't care for the idea of replacing the data file for every save. This is the simplest implementation. It works. Can you say why you don't care for it? > My preference would to append to the existing data file - makes more > sense. Can you expand on that? You haven't defined how that would satisfy the requirement, so it isn't clear to me why a more complex method ?makes more sense? than the simple way which works now. -- \ ?Holy hole in a donut, Batman!? ?Robin | `\ | _o__) | Ben Finney From venkatachalam.19 at gmail.com Tue Apr 4 13:39:08 2017 From: venkatachalam.19 at gmail.com (Venkatachalam Srinivasan) Date: Tue, 4 Apr 2017 10:39:08 -0700 (PDT) Subject: Data exchange between python script and bash script In-Reply-To: References: <50298d86-e688-4162-b96f-632e5a98c141@googlegroups.com> Message-ID: On Tuesday, April 4, 2017 at 5:42:23 PM UTC+2, justin walters wrote: > On Tue, Apr 4, 2017 at 8:01 AM, wrote: > > > Hello All, > > > > I am writing a python code for processing a data obtained from a sensor. > > The data from sensor is obtained by executing a python script. The data > > obtained should be further given to another python module where the > > received data is used for adjusting the location of an object. > > > > For achieving this, there is a central bash script, which runs both the > > python modules parallel. Something like: > > > > python a.py & > > python b.py & > > > > I am trying to return the sensor data to the bash .sh file, therefore it > > can be provided to the other script. This, based on the online tutorials > > looks like: > > > > sensor_data=$(python execute_sensor_process.py) & > > > > and the sensor_data is assigned by printing the required data in the > > corresponding python script. For example, the data is printed in > > execute_sensor_process.py as follows: > > > > print >>sys.stderr,sens_data > > > > By printing the data onto sys.stderr and assigning a return variable in > > the bash, I am expecting the data to be assigned. > > > > But this is not happening. The sensor data is a dictionary and I like to > > have this data for further analysis. I am not getting the data returned > > from the python script on to the bash variable. > > > > Can someone help me to understand why the code is not working? I tried > > other approaches of function call such as > > > > > > sensor_data=$`python execute_sensor_process.py` & > > > > > > python execute_sensor_process.py tempfile.txt & > > kinexon_data=`cat tempfile.txt` & > > > > But none of the approaches are working. > > > > Thank you, > > Venkatachalam Srinivasan > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > I'm not sure why you need the data in a bash script. What can you do with a > bash script that you > can't do with Python? > > That said, it seems to me that you need a data persistence layer, i.e. a > way to store the dictionary > after it is created. My best advice would be to use the json module to > write out to json files. I > believe this is the best approach because json has a near 1-to-1 mapping > with Python > dictionaries. > > Json is also a good choice because almost every language has a json parser > as part of it's standard > library, making you data extremely portable. Hi, Thanks for the answer. I need bash for connecting data exchange between two python scripts. To be more specific, data from one script has to be passed to the another script. You are right, I don't need the data in the bash other than to pass the obtained data to the another script which uses the data for further analysis. Regarding using the json file, I am new to this. A naive question is that if the data is too large then is json file is easy to handle? Is json file for large data is not computationally expensive? I am not using textfile for the same reason of being computationally expensive. Thanks, Venkatachalam Srinivasan From rhodri at kynesim.co.uk Tue Apr 4 13:47:02 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 4 Apr 2017 18:47:02 +0100 Subject: Data exchange between python script and bash script In-Reply-To: <0e4014e2-ee4a-4177-ad8f-6c0470966a31@googlegroups.com> References: <50298d86-e688-4162-b96f-632e5a98c141@googlegroups.com> <0e4014e2-ee4a-4177-ad8f-6c0470966a31@googlegroups.com> Message-ID: <329cf9c8-841f-6459-ad0e-2bc95c5d2d08@kynesim.co.uk> On 04/04/17 18:07, Venkatachalam Srinivasan wrote: > On Tuesday, April 4, 2017 at 5:27:42 PM UTC+2, cassiope wrote: >> On Tue, 04 Apr 2017 08:01:42 -0700, venkatachalam.19 wrote: >> >>> Hello All, >>> >>> I am writing a python code for processing a data obtained from a sensor. The data from sensor is obtained by executing a python script. The data obtained should be further given to another python module where the received data is used for adjusting the location of an object. >>> >>> For achieving this, there is a central bash script, which runs both the python modules parallel. Something like: >>> >>> python a.py & >>> python b.py & >> >> What is going on that two python scripts are needed? Which one generates the data needed by the bash script? > > One python script communicates with an external sensor and receives data. > Another script controls a robot. That is based on ROS modules. >>From the given code, a.py will be the script generating the data. Both the modules are independent [snip] Except that they clearly aren't, because the operation of one depends on the results of the other. You may need to think harder about that. It would appear that your main problem is that you don't understand bash. This isn't a Python issue at all, it's about how the shell runs programs and gets results back. We aren't a Bash programming newsgroup (or mailing list), and honestly even if we were it seems like you need to absorb a lot of basic concepts. You will be much better off finding and reading a decent shell scripting tutorial. Pay particular attention to piping, which appears to be what you are trying to reinvent. If all else fails, Read The Fine Manual; it's not the easiest of reads, but it does contain all the information you need. -- Rhodri James *-* Kynesim Ltd From rgaddi at highlandtechnology.invalid Tue Apr 4 13:50:22 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Tue, 4 Apr 2017 10:50:22 -0700 Subject: Appending data to a json file In-Reply-To: References: <87a87wlowd.fsf@handshake.de> <51ace66d-2451-da08-1c4a-4c3819400d8c@gmail.com> Message-ID: On 04/04/2017 10:23 AM, Dave wrote: > > I don't care for the idea of replacing the data file for every save. My > preference would to append to the existing data file - makes more sense. > However, that is not how json works. So, I'm considering other > alternatives for a data file structure. Paired data (key and value) is > not really required, but my feeling is that it makes the data file more > robust. A database seems a little over the top for this situation since > there is no querying of data - just load and save. > > Dave, Valid. That said, the database implementation (especially if you just use Sqlite) is written, done, and works. There are reasons that a lot of programs use it just to store things like user settings. Having a backend that's already ACID takes a lot of stress out of things like what I'm assuming you don't like about full data file replacement: what happens if you get a powerfail midway through. I'm not saying it's the right answer, but it's not nearly so much flyswatting with a sledgehammer as you may think. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From walters.justin01 at gmail.com Tue Apr 4 13:58:36 2017 From: walters.justin01 at gmail.com (justin walters) Date: Tue, 4 Apr 2017 10:58:36 -0700 Subject: Data exchange between python script and bash script In-Reply-To: References: <50298d86-e688-4162-b96f-632e5a98c141@googlegroups.com> Message-ID: On Tue, Apr 4, 2017 at 10:39 AM, Venkatachalam Srinivasan < venkatachalam.19 at gmail.com> wrote: > Hi, > > Thanks for the answer. I need bash for connecting data exchange between > two python scripts. To be more specific, data from one script has to be > passed to the another script. You are right, I don't need the data in the > bash other than to pass the obtained data to the another script which uses > the data for further analysis. > > Regarding using the json file, I am new to this. A naive question is that > if the data is too large then is json file is easy to handle? Is json file > for large data is not computationally expensive? I am not using textfile > for the same reason of being computationally expensive. > > Thanks, > Venkatachalam Srinivasan > -- > https://mail.python.org/mailman/listinfo/python-list > It could be expensive to create a dictionary from the json file depending on the amount of data. Alternatively, you could use a Unix socket to transmit the data between processes if you're on a linux or OSx machine. This is probably the best option as you can send the dictionary object itself. This would eliminate the need for the bash script entirely. The first script builds the dictionary object and sends it to the socket. The second script is listening on the socket and receives the dictionary object. Python's standard library has built in support for unix sockets. This means you can actually run two parallel Python instances and communicate between them. Assuming that the first script can build the dictionaries before the second script is done processing them, you will probably need some kind of task queue. Celery: http://www.celeryproject.org/ tends to be a good solution for this problem. In fact, Celery is probably the simplest option now that I think about it. Another alternative is using a SQLite database which Python has built in support for. Should be a bit faster and less memory-intensive. From tjreedy at udel.edu Tue Apr 4 14:03:59 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 4 Apr 2017 14:03:59 -0400 Subject: Two variable dictionary comprehension In-Reply-To: References: <85mvbydxgx.fsf@benfinney.id.au> <001d01d2ac38$1c99c030$27b23dae@sambora> Message-ID: On 4/3/2017 2:35 AM, Gregory Ewing wrote: > Deborah Swanson wrote: > >> Oh, come on. That's a fairly obscure citation in the docs, one that >> would take a good deal of experience and time reading through them to >> know was there, > Having said that, the index of the Python docs could be > improved a bit in this area -- currently it only mentions > "list" under "comprehension" (although the page it leads > to discusses the other types as well). I am sure that this is because list comprehensions were once thr only comprehensions and that the index was not updated when the syntax and code was. I opened issue 29981 "Update Index for set, dict, and generator 'comprehensions'". -- Terry Jan Reedy From dboland9 at fastmail.fm Tue Apr 4 14:05:28 2017 From: dboland9 at fastmail.fm (Dave) Date: Tue, 4 Apr 2017 14:05:28 -0400 Subject: Appending data to a json file References: <87a87wlowd.fsf@handshake.de> <51ace66d-2451-da08-1c4a-4c3819400d8c@gmail.com> Message-ID: On 04/04/2017 01:50 PM, Rob Gaddi wrote: > On 04/04/2017 10:23 AM, Dave wrote: > >> >> I don't care for the idea of replacing the data file for every save. My >> preference would to append to the existing data file - makes more sense. >> However, that is not how json works. So, I'm considering other >> alternatives for a data file structure. Paired data (key and value) is >> not really required, but my feeling is that it makes the data file more >> robust. A database seems a little over the top for this situation since >> there is no querying of data - just load and save. >> >> Dave, > > Valid. That said, the database implementation (especially if you just > use Sqlite) is written, done, and works. There are reasons that a lot > of programs use it just to store things like user settings. Having a > backend that's already ACID takes a lot of stress out of things like > what I'm assuming you don't like about full data file replacement: what > happens if you get a powerfail midway through. > > I'm not saying it's the right answer, but it's not nearly so much > flyswatting with a sledgehammer as you may think. > > I'll take a look at it. Thanks! Dave, From info at wingware.com Tue Apr 4 14:21:23 2017 From: info at wingware.com (Wingware) Date: Tue, 04 Apr 2017 14:21:23 -0400 Subject: ANN: Wing Python IDE version 6.0.4 released Message-ID: <58E3E423.4010707@wingware.com> Hi, We've just released Wing 6.0.4 which fixes remote development to systems with Python 3, addresses problems seen when switching between remote projects and when remote host configurations are missing or invalid, fixes text drag-and-drop, solves problems with analysis of some type annotations, and makes about 30 other minor improvements. For details, see http://wingware.com/pub/wingide/6.0.4/CHANGELOG.txt Wing 6 is the latest major release in Wingware's family of Python IDEs, including Wing Pro, Wing Personal, and Wing 101. Wing 6 adds many new features, introduces a new annual license option for Wing Pro, and makes Wing Personal free. New Features * Improved Multiple Selections: Quickly add selections and edit them all at once * Easy Remote Development: Work seamlessly on remote Linux, OS X, and Raspberry Pi systems * Debugging in the Python Shell: Reach breakpoints and exceptions in (and from) the Python Shell * Recursive Debugging: Debug code invoked in the context of stack frames that are already being debugged * PEP 484 and PEP 526 Type Hinting: Inform Wing's static analysis engine of types it cannot infer * Support for Python 3.6 and Stackless 3.4: Use async and other new language features * Optimized debugger: Run faster, particularly in multi-process and multi-threaded code * Support for OS X full screen mode: Zoom to a virtual screen, with auto-hiding menu bar * Added a new One Dark color palette: Enjoy the best dark display style yet * Updated French and German localizations: Thanks to Jean Sanchez, Laurent Fasnacht, and Christoph Heitkamp For a more detailed overview of new features see the release notice at http://wingware.com/news/2017-04-03 Annual Use License Option Wing 6 adds the option of purchasing a lower-cost expiring annual license for Wing Pro. An annual license includes access to all available Wing Pro versions while it is valid, and then ceases to function if it is now renewed. Pricing for annual licenses is US$ 179/user for Commercial Use and US$ 69/user for Non-Commercial Use. Perpetual licenses for Wing Pro will continue to be available at the same pricing. The cost of extending Support+Upgrades subscriptions on Non-Commercial Use perpetual licenses for Wing Pro has also been dropped from US$ 89 to US$ 39 per user. For details, see https://wingware.com/store/ Wing Personal is Free Wing Personal is now free and no longer requires a license to run. It now also includes the Source Browser, PyLint, and OS Commands tools, and supports the scripting API and Perspectives. However, Wing Personal does not include Wing Pro's advanced editing, debugging, testing and code management features, such as remote development, refactoring, find uses, version control, unit testing, interactive debug probe, multi-process and child process debugging, move program counter, conditional breakpoints, debug watch, framework-specific support (for Jupyter, Django, and others), find symbol in project, and other features. Links Release notice: http://wingware.com/news/2017-04-03 Downloads and Free Trial: http://wingware.com/downloads Buy: http://wingware.com/store/purchase Upgrade: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at support at wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE The Intelligent Development Environment for Python Programmers wingware.com From torriem at gmail.com Tue Apr 4 14:21:32 2017 From: torriem at gmail.com (Michael Torrie) Date: Tue, 4 Apr 2017 12:21:32 -0600 Subject: Appending data to a json file In-Reply-To: References: <87a87wlowd.fsf@handshake.de> <51ace66d-2451-da08-1c4a-4c3819400d8c@gmail.com> Message-ID: <9ff81c13-97ab-314e-43c7-7cd2a7182c1e@gmail.com> On 04/04/2017 11:23 AM, Dave wrote: > I did. Please see the subject - it is json, not some bastardized > version of it. My fault for not seeing that! Sorry about the noise. From grant.b.edwards at gmail.com Tue Apr 4 14:30:01 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 4 Apr 2017 18:30:01 +0000 (UTC) Subject: Appending data to a json file References: <87a87wlowd.fsf@handshake.de> <51ace66d-2451-da08-1c4a-4c3819400d8c@gmail.com> <851st8dqgo.fsf@benfinney.id.au> Message-ID: On 2017-04-04, Ben Finney wrote: > Dave writes: > >> I don't care for the idea of replacing the data file for every save. > > This is the simplest implementation. It works. Can you say why you don't > care for it? After the data is read, it requires reloading the ASR33 with a fresh spool of unpunched paper tape. >> My preference would to append to the existing data file - makes >> more sense. > > Can you expand on that? You haven't defined how that would satisfy the > requirement, so it isn't clear to me why a more complex method ?makes > more sense? than the simple way which works now. A big advantage to reading the old file and generating a complete new file is that you can read the existing file, create a new temporary file, and then 'rename(2)' the temporary file to replace the old one. At least on Unix, rename is an filesystem-atomic operation and provides a far smaller window of vulerability for r/w race conditions, crash-induced problems, etc. I assume there's a similar way to do that under Windows... -- Grant Edwards grant.b.edwards Yow! Mary Tyler Moore's at SEVENTH HUSBAND is wearing gmail.com my DACRON TANK TOP in a cheap hotel in HONOLULU! From tjreedy at udel.edu Tue Apr 4 14:58:56 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 4 Apr 2017 14:58:56 -0400 Subject: Two variable dictionary comprehension In-Reply-To: <00b801d2acc7$006d7b10$27b23dae@sambora> References: <00b801d2acc7$006d7b10$27b23dae@sambora> Message-ID: On 4/3/2017 6:09 PM, Deborah Swanson wrote: > Nathan Ernst wrote, on April 03, 2017 1:59 PM >> >> I was a bit surprised when I looked at the language reference >> for 3.6.x. I expected there'd be a direct link to >> comprehensions, but there's not. ... >> FWIW, If one was completely new to Python, even knowing the >> syntax is known as a "comprehension" might be unknown. I >> certainly didn't know what a comprehension was when I was >> learning Python. A coworker showed me, some 13 years ago. > Thanks Nate, for your comprehension of the plight of many, if not most, > newish Python coders. And it certainly doesn't help to ask the list to > fill in some of the holes and be met with criticism for asking, but I > digress. It is what it is. I have more than once looked at the Reference TOC: Expressions https://docs.python.org/3/reference/index.html and wondered 'where are comprehensions?' (and a few other things). I just opened Issue 29983: "Reference TOC: expand 'Atoms' and 'Primaries'", https://bugs.python.org/issue29983, suggesting that 6.2. Atoms 6.3. Primaries be expanded to 6.2. Atoms, including identifiers, literals, and comprehensions 6.3. Primaries: attributes, subscripts, slices, and calls The 'primaries' list is complete. The full 'atoms' list is too long so I picked what I thought might be the three most important and added 'including' to indicate that this is a selection. There might be opposition (or just +-0 indifference) from developers who are CS language theory wonks who have forgotten how obscure the terms 'atom' and 'primary' are in this context. So anyone supporting this should say so on the issue. https://bugs.python.org/issue29981, adding index entries, should be routine, but at least one +1 would be helpful. -- Terry Jan Reedy From ben+python at benfinney.id.au Tue Apr 4 15:57:08 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 05 Apr 2017 05:57:08 +1000 Subject: [ANNOUNCE] Mail Drake version 0.1.7 Message-ID: <85lgrgc5ez.fsf@benfinney.id.au> Howdy all, I am pleased to present Mail Drake (version 0.1.7), now available at PyPI . Mail Drake is a development tool for testing email traffic. Run Mail Drake?s SMTP server on a local port, send email to it, and inspect the message queue in a local web browser. Mail Drake is free software, via the Affero GPL v3 or later. Documentation in this version is very sparse. The commands installed have help (via the ?--help? option) which is the best I can point you to currently. I'd be happy to have feedback, and even happier to have contributors make merge requests. Documentation improvements would be especially worthwhile! -- \ ?Of all classes the rich are the most noticed and the least | `\ studied.? ?John Kenneth Galbraith, _The Age of Uncertainty_, | _o__) 1977 | Ben Finney From python at mrabarnett.plus.com Tue Apr 4 16:51:58 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 4 Apr 2017 21:51:58 +0100 Subject: Appending data to a json file In-Reply-To: <2hu7ech2s393iu0j4i21cfl0tbb1go24ft@4ax.com> References: <87a87wlowd.fsf@handshake.de> <51ace66d-2451-da08-1c4a-4c3819400d8c@gmail.com> <2hu7ech2s393iu0j4i21cfl0tbb1go24ft@4ax.com> Message-ID: <54efe7bb-51aa-1e88-cccd-329da7679d19@mrabarnett.plus.com> On 2017-04-04 21:00, Dennis Lee Bieber wrote: > On Tue, 4 Apr 2017 13:23:52 -0400, Dave declaimed > the following: > > >>I don't care for the idea of replacing the data file for every save. My >>preference would to append to the existing data file - makes more sense. >>However, that is not how json works. So, I'm considering other >>alternatives for a data file structure. Paired data (key and value) is >>not really required, but my feeling is that it makes the data file more >>robust. A database seems a little over the top for this situation since >>there is no querying of data - just load and save. > > Somebody must eventually have to retrieve stuff from this file for some > use; otherwise it is nothing but an ever-expanding waste of disk space. > > A database, at the very least, means you never have to read the old > contents before adding new data. However, lacking any indication of /what/ > the data contains ("dictionary of dictionaries" only indicates a nested > structure at the top level -- but does not indicate if it is possible for > an "append" pass to overwrite a pre-existing subdictionary should the outer > dictionary key be a duplicate). > > Possibly a CSV format would suffice... > Would the 'shelve' module module suffice? (OK, it's not plain text, but neither is a DB.) From python at deborahswanson.net Tue Apr 4 18:34:11 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Tue, 4 Apr 2017 15:34:11 -0700 Subject: Two variable dictionary comprehension In-Reply-To: Message-ID: <00c601d2ad93$95340da0$27b23dae@sambora> Terry Reedy wrote, on Tuesday, April 04, 2017 11:04 AM > > On 4/3/2017 2:35 AM, Gregory Ewing wrote: > > Deborah Swanson wrote: > > > >> Oh, come on. That's a fairly obscure citation in the docs, > one that > >> would take a good deal of experience and time reading > through them to > >> know was there, > > > Having said that, the index of the Python docs could be > improved a bit > > in this area -- currently it only mentions "list" under > > "comprehension" (although the page it leads to discusses the other > > types as well). > > I am sure that this is because list comprehensions were once thr only > comprehensions and that the index was not updated when the syntax and > code was. I opened issue 29981 "Update Index for set, dict, and > generator 'comprehensions'". > > -- > Terry Jan Reedy Thanks Terry. I does seem strange that there are so many types of comprehensions, yet under 'comprehensions' in the Index, you only see 'list'. And there are no entries for the other types, by their names. Deborah From rgaddi at highlandtechnology.invalid Tue Apr 4 18:56:14 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Tue, 4 Apr 2017 15:56:14 -0700 Subject: Two variable dictionary comprehension In-Reply-To: References: <00c601d2ad93$95340da0$27b23dae@sambora> Message-ID: On 04/04/2017 03:34 PM, Deborah Swanson wrote: > Terry Reedy wrote, on Tuesday, April 04, 2017 11:04 AM >> >> On 4/3/2017 2:35 AM, Gregory Ewing wrote: >>> Deborah Swanson wrote: >>> >>>> Oh, come on. That's a fairly obscure citation in the docs, >> one that >>>> would take a good deal of experience and time reading >> through them to >>>> know was there, >> >>> Having said that, the index of the Python docs could be >> improved a bit >>> in this area -- currently it only mentions "list" under >>> "comprehension" (although the page it leads to discusses the other >>> types as well). >> >> I am sure that this is because list comprehensions were once thr only >> comprehensions and that the index was not updated when the syntax and >> code was. I opened issue 29981 "Update Index for set, dict, and >> generator 'comprehensions'". >> >> -- >> Terry Jan Reedy > > Thanks Terry. I does seem strange that there are so many types of > comprehensions, yet under 'comprehensions' in the Index, you only see > 'list'. And there are no entries for the other types, by their names. > > Deborah > Does it seem... incomprehensible? -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From python at deborahswanson.net Tue Apr 4 19:10:16 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Tue, 4 Apr 2017 16:10:16 -0700 Subject: Two variable dictionary comprehension In-Reply-To: <58e2f123$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: <000701d2ad98$a03185c0$27b23dae@sambora> Sorry I bailed on you last night, but you know it's bad when you can't read anymore. I read through this today and saw several things I really need to work with more, especially dicts, sets, generators and the zip function. I've used all of them in fairly typical forms, but it's the atypical ones that throw me. And strangely enough, I've never seen dicts described as having key:value syntax, although it's certainly true and clarifies a lot in thinking about them. The one thing you mentioned that was completely new to me was the use of an if clause in a list comprehension, and I can see there being times when that's exactly what you want to do. I'll have to try the other types of comprehensions and see if this same grammar works in all of them. It should. Interesting how computer languages seem to be a hybrid of math and linguistics. I added all of these concepts and code snippets to my study list. Thanks again Steve. ;) Deborah Steve D'Aprano wrote, on Monday, April 03, 2017 6:05 PM > > On Tue, 4 Apr 2017 03:27 am, Deborah Swanson wrote: > > > I'll admit that both dictionaries and comprehensions are still a > > little bit fuzzy to me, especially when I get away from the common > > usages. This could be a good exercise to clarify some of the fuzzy > > areas. > > > As far as comprehensions go, how is your mathematics? > > If you remember your set builder notation from maths, list > comprehensions are based on that. > > In maths, we say something like: > > {2n + 1 : 0 ? n ? 9} > > which might be read aloud as "the set of 2 times n, plus 1, > such that n is between 0 and 9 inclusive". > > http://www.mathwords.com/s/set_builder_notation.htm > > A similar notation might be: > > {2n + 1 : n ? {1, 2, 3}} > > said as "the set of 2 times n, plus 1, such that n is an > element of the set {1, 2, 3}". > > > If you're a maths geek like me, this is second nature :-) > > > Now, Python's list comprehension syntax is based on a similar > notation, except we spell it out in words rather than > symbols, using the familiar "for n in ..." syntax from > for-loops instead of : "such that". > > {2*n + 1 for n in range(10)} > > {2*n + 1 for n in (1, 2, 3)} > > > A few other differences: > > - list comprehensions use [ ] for the outermost brackets; > - set and dict comprehensions use { }; > - generator expressions use ( ) (unless the parentheses can > be implied). > > We're not restricted to mathematical expressions, and can use > any Python expression we like: > > [value.method(arg)[1] for (value, arg) in zip(values, arguments)] > > > translates roughly into this for-loop: > > result = [] > for (value, arg) in zip(values, arguments): > result.append(value.method(arg)[1]) > > > > Another difference is that comprehensions allow an "if" clause: > > [v.method(a)[1] for (v, a) in zip(values, arguments) if v is not None] > > translates something like: > > > result = [] > for (v, a) in zip(values, arguments): > if v is not None: > result.append(v.method(a)[1]) > > > There's more, but that covers probably 98% of comprehension usage. > > And of course, remember that dict comprehensions use the same > key:value syntax as ordinary dict "literals" (the official > name is "dict display"). > > result = {} > for key, value in zip(keys, values): > result[key] = value > > > becomes > > result = {key:value for (key, value) in zip(keys, values)} > > although frankly that's better written as: > > dict(zip(keys, values)) > > > > Hope this helps! > > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered > up, and sure enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list > From mikhailwas at gmail.com Tue Apr 4 19:10:28 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Wed, 5 Apr 2017 01:10:28 +0200 Subject: Text-mode apps (Was :Who are the "spacists"?) Message-ID: On 3 April 2017 at 19:55, Steve D'Aprano wrote: > I didn't see you calling out Rick for his prejudice against those who aren't > American, his absurd belief that "most" people are satisfied with ASCII, Hmm... that is interesting. Everyone has some beliefs... If I make a bit more on-topic question: What is "satisfied" with ASCII, or what is "we need Unicode", where and what for? What is your "satisfaction" with Unicode? For me it is a font, where images given numbers, ok, then we need obviosly to look at it, e.g. if you make a codec. So you are just stating the fact that font files store them in this order and a txt file in Notepad will show them in correct order? hmm... I just thought you have some idea, e.g. what glyphs you adore esthetically or find especially useful in your life. Which of some 40 images that are needed for _you_ to represent speech and numbers, you find IDK, appealing or annoying, or what? In typesetting, I find annoying caps inculsion, too little space between sentences and not so good separator character design, some flaws in letter design. For development purposes I would need some glyphs for non-printable characters, ok few glyphs more. Tak zachem _nuzhen_ Unikod ? Rasskazhi chto-nibud interesnoe. From python at deborahswanson.net Tue Apr 4 19:22:51 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Tue, 4 Apr 2017 16:22:51 -0700 Subject: Two variable dictionary comprehension In-Reply-To: Message-ID: <000b01d2ad9a$61a8b1a0$27b23dae@sambora> Rob Gaddi wrote, on Tuesday, April 04, 2017 3:56 PM > > On 04/04/2017 03:34 PM, Deborah Swanson wrote: > > Terry Reedy wrote, on Tuesday, April 04, 2017 11:04 AM > >> > >> I am sure that this is because list comprehensions were once thr only > >> comprehensions and that the index was not updated when the syntax and > >> code was. I opened issue 29981 "Update Index for set, dict, and > >> generator 'comprehensions'". > >> > >> -- > >> Terry Jan Reedy > > > > Thanks Terry. I does seem strange that there are so many types of > > comprehensions, yet under 'comprehensions' in the Index, you only see > > 'list'. And there are no entries for the other types, by their names. > > > > Deborah > > > > Does it seem... incomprehensible? > > -- > Rob Gaddi, Highland Technology -- www.highlandtechnology.com > Email address domain is currently out of order. See above to fix. Ha ha! Indeed it does. Funny how 'comprehension' word forms so easily fall into puns. Deborah From fleshw at gmail.com Tue Apr 4 22:40:03 2017 From: fleshw at gmail.com (fleshw at gmail.com) Date: Tue, 4 Apr 2017 19:40:03 -0700 (PDT) Subject: Does automatic golden master unittest generation exist/or is it feasible? Message-ID: <7bcc0a39-8d39-43a0-abc3-1bdbfbaa2ac7@googlegroups.com> I have a really large and mature codebase in py2, but with no test or documentation. To resolve this I just had a simple idea to automatically generate tests and this is how: 1. Have a decorator that logs all arguments and return values 2. Put them in a test case and have it run in production. Here's a quick prototype I just wrote, just to illustrate what I'm trying to achieve: http://codepad.org/bkHRbZ4R People told me that there's a similar concept called "Golden Master Testing" where it keeps a "golden record" and runs test case on it. So it looks like I'm trying to automate golden master testing. So my question is this: 1. Is this a concept already explored? 2. Is there already a framework for doing this? From steve at pearwood.info Tue Apr 4 23:43:51 2017 From: steve at pearwood.info (Steven D'Aprano) Date: 05 Apr 2017 03:43:51 GMT Subject: Does automatic golden master unittest generation exist/or is it feasible? References: <7bcc0a39-8d39-43a0-abc3-1bdbfbaa2ac7@googlegroups.com> Message-ID: <58e467f6$0$1502$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Apr 2017 19:40:03 -0700, fleshw wrote: > People told me that there's a similar concept called "Golden Master > Testing" where it keeps a "golden record" and runs test case on it. So > it looks like I'm trying to automate golden master testing. > > So my question is this: > > 1. Is this a concept already explored? https://duckduckgo.com/?q=Golden+Master+Testing https://www.google.com.au/search?q=Golden+Master+Testing Gold master testing is not a substitute for unit tests. The purpose of gold master testing is different: not the ensure that the code is correct, but to ensure that the behaviour *doesn't change*. Or at least not without a human review to ensure the change is desired. You would use gold master testing when you have a legacy code base that needs refactoring. You don't care so much about fixing bugs (either there aren't any known bugs, or you have to keep them for backwards compatibility, or simply there's no budget for fixing them yet) but you care about keeping the behaviour unchanged as you refactor the code. If that describes your situation, then gold master testing is worth pursuing. If not, then forget about it. Just write some unit tests. I like small functions that take some arguments, do one thing, and return a result without any side-effects. They are very easy to test using doctests. Doctests make good documentation too, so you can kill two birds with one stone. Write doctests. For anything too complicated for a doctest, or for extensive and detailed functional tests that exercise all the corners of your function, write unit tests. The `unittest` module can run your doctests too, automatically turning your doctests into a test case. If your code base is well-designed, with lots of encapsulation, then writing unit tests are easy. If its not... well, you have my sympathy. > 2. Is there already a framework for doing this? This came up in googling. I make no comment about its maturity, functionality, bugginess or overall quality, as I have never used it. https://github.com/approvals/ApprovalTests.Python -- Steve From steve at pearwood.info Wed Apr 5 01:39:23 2017 From: steve at pearwood.info (Steven D'Aprano) Date: 05 Apr 2017 05:39:23 GMT Subject: using HTTPHandler cause Django server side shows http 400 and Invalid HTTP_HOST header message References: <41b72e7a-8479-4901-9397-44bae30bee9c@googlegroups.com> Message-ID: <58e4830b$0$1502$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Apr 2017 21:06:23 -0700, iMath wrote: > For those want to help, I also posted The question here > http://stackoverflow.com/questions/43185804/using-httphandler-cause- django-server-side-shows-http-400-and-invalid-http-host > > > I am using HTTPHandler to send logging messages to a Django Web server > with The following code, Are you sure you posted the code you are actually using? Because the error message suggests a difference. You have: > _TARGET = '192.168.8.100:8000' but the error message says: > Invalid HTTP_HOST header: '192.168.8.100:8000,192.168.8.100'. '192.168.8.100:8000,192.168.8.100' is not the same address you say you are using. (And it is not a valid address, just as the error message states.) I might be entirely wrong here, I'm not a Django expert, but it sure looks to me like a simple mistake in your code. It would be good if you could confirm that's not the case before people spend time trying to debug something in code they can't see. -- Steve From dieter at handshake.de Wed Apr 5 04:20:40 2017 From: dieter at handshake.de (dieter) Date: Wed, 05 Apr 2017 10:20:40 +0200 Subject: Data transmission from Python script to bash script References: <92a819af-f997-4140-b1dc-74ee757036cf@googlegroups.com> Message-ID: <87lgrf5kpz.fsf@handshake.de> venkatachalam.19 at gmail.com writes: > ... > I am writing a python code for processing a data obtained from a sensor. The data from sensor is obtained by executing a python script. The data obtained should be further given to another python module where the received data is used for adjusting the location of an object. > > For achieving this, there is a central bash script, which runs both the python modules parallel. Something like: > > python a.py & > python b.py & > > I am trying to return the sensor data to the bash .sh file, therefore it can be provided to the other script. I would recommend, do not do it this way. On an abstract level, I recommend to use a communication channel between your "a" and your "b". "a" writes to it and "b" reads from it. There are many, many options for such a communication channel. One of the easiest would be to realisize "a" and "b" as tasks in a single Python process which use a queue as communication channel. The big advantage: "a" and "b" can communicate directly via python objects. Another option would be to implement the communication channel via an external queue or file; in those cases, the Python object created by "a" would need to be serialized (to be put into the communication channel) and derialized (i.e. recreated) again by "b". From dieter at handshake.de Wed Apr 5 04:30:01 2017 From: dieter at handshake.de (dieter) Date: Wed, 05 Apr 2017 10:30:01 +0200 Subject: Does automatic golden master unittest generation exist/or is it feasible? References: <7bcc0a39-8d39-43a0-abc3-1bdbfbaa2ac7@googlegroups.com> Message-ID: <87h9235kae.fsf@handshake.de> fleshw at gmail.com writes: > I have a really large and mature codebase in py2, but with no test or documentation. > > To resolve this I just had a simple idea to automatically generate tests and this is how: > > 1. Have a decorator that logs all arguments and return values > > 2. Put them in a test case > > and have it run in production. This works only for quite simple cases -- cases without state. If you have something with state, than some function calls may change the state and thereby changing the effect of later function calls. This means: the same function call (same function, same arguments) may give different results over time. As a consequence, the initial state and the execution order becomes important. From as at sci.fi Wed Apr 5 08:37:23 2017 From: as at sci.fi (Anssi Saari) Date: Wed, 05 Apr 2017 15:37:23 +0300 Subject: Data exchange between python script and bash script References: <50298d86-e688-4162-b96f-632e5a98c141@googlegroups.com> Message-ID: venkatachalam.19 at gmail.com writes: > For example, the data is printed in > execute_sensor_process.py as follows: > > print >>sys.stderr,sens_data > > By printing the data onto sys.stderr and assigning a return variable in the bash, I am expecting the data to be assigned. > > But this is not happening. This part I can answer alhtough I'm not sure it helps with your actual problems. Bash manual explicitly states command substition (the $(...) structure) replaces the command with the standard *output* of the command. So since your Python program writes to standard error, you get nothing. From davidgshi at yahoo.co.uk Wed Apr 5 08:57:11 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Wed, 5 Apr 2017 12:57:11 +0000 (UTC) Subject: How to make use of .egg files? References: <2053193475.1923614.1491397031348.ref@mail.yahoo.com> Message-ID: <2053193475.1923614.1491397031348@mail.yahoo.com> Can anyone explain please. Regards. David From Ralf.Hildebrandt at charite.de Wed Apr 5 09:39:51 2017 From: Ralf.Hildebrandt at charite.de (Ralf Hildebrandt) Date: Wed, 5 Apr 2017 15:39:51 +0200 Subject: How to make use of .egg files? In-Reply-To: <2053193475.1923614.1491397031348@mail.yahoo.com> References: <2053193475.1923614.1491397031348.ref@mail.yahoo.com> <2053193475.1923614.1491397031348@mail.yahoo.com> Message-ID: <20170405133951.blp7h5v4hl2x5sl3@charite.de> * David Shi via Python-list : > Can anyone explain please. http://stackoverflow.com/questions/2051192/what-is-a-python-egg -- Ralf Hildebrandt Charite Universit?tsmedizin Berlin ralf.hildebrandt at charite.de Campus Benjamin Franklin https://www.charite.de Hindenburgdamm 30, 12203 Berlin Gesch?ftsbereich IT, Abt. Netzwerk fon: +49-30-450.570.155 From breamoreboy at gmail.com Wed Apr 5 10:28:36 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Wed, 5 Apr 2017 07:28:36 -0700 (PDT) Subject: How to make use of .egg files? In-Reply-To: References: <2053193475.1923614.1491397031348.ref@mail.yahoo.com> <2053193475.1923614.1491397031348@mail.yahoo.com> Message-ID: On Wednesday, April 5, 2017 at 2:00:41 PM UTC+1, David Shi wrote: > Can anyone explain please. > Regards. > David Egg files are old, wheels are the new thing http://pythonwheels.com/ Kindest regards. Mark Lawrence. From neilc at norwich.edu Wed Apr 5 10:49:21 2017 From: neilc at norwich.edu (Neil Cerutti) Date: Wed, 5 Apr 2017 14:49:21 +0000 (UTC) Subject: "pandas" pronunciation References: Message-ID: On 2017-04-03, Jay Braun wrote: > I hear people say it like the plural of "panda", and others as > "panduss". Is there a correct way? I think it is pronounced like the regular word. The second a is schwa in both the singular and plural. -- Neil Cerutti From python at example.invalid Wed Apr 5 11:09:38 2017 From: python at example.invalid (Python) Date: Wed, 5 Apr 2017 17:09:38 +0200 Subject: Quick questions about globals and database connections References: Message-ID: Le 05/04/2017 ? 16:54, DFS a ?crit : > I have identical databases in sqlite and postgres. I want to run the > same code against them, but am having a small issue. > > Current code below throws the dreaded: > > NameError: global name 'db' is not defined > > on line 12 > > How do I fix it? I want to keep dbconnect() as a separate function. > > Thanks. > > ------------------------------------------------------------- > 1 import sqlite3, psycopg2 > 2 > 3 def dbconnect(dbtype): > 4 if dbtype == "sqlite": > 5 conn = sqlite3.connect(cstr) > 6 elif dbtype == "postgres": > 7 conn = psycopg2.connect(cstr) 8 return conn.cursor() > 9 > 10 def updatedb(dbtype): 11 db = dbconnect(dbtype) > 12 db.execute("DML code") > 13 print "updated " + dbtype > 14 'close connection > > 15 def main(): > 16 updatedb('sqlite') > 17 updatedb('postgres') > 18 > 19 if __name__ == "__main__": > 20 main() > ------------------------------------------------------------- > > From joel.goldstick at gmail.com Wed Apr 5 11:17:12 2017 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 5 Apr 2017 11:17:12 -0400 Subject: Quick questions about globals and database connections In-Reply-To: References: Message-ID: On Wed, Apr 5, 2017 at 11:09 AM, Python wrote: > Le 05/04/2017 ? 16:54, DFS a ?crit : >> >> I have identical databases in sqlite and postgres. I want to run the >> same code against them, but am having a small issue. >> >> Current code below throws the dreaded: >> >> NameError: global name 'db' is not defined >> >> on line 12 >> >> How do I fix it? I want to keep dbconnect() as a separate function. >> >> Thanks. >> >> ------------------------------------------------------------- >> 1 import sqlite3, psycopg2 >> 2 >> 3 def dbconnect(dbtype): >> 4 if dbtype == "sqlite": >> 5 conn = sqlite3.connect(cstr) >> 6 elif dbtype == "postgres": >> 7 conn = psycopg2.connect(cstr) > > > 8 return conn.cursor() > >> 9 >> 10 def updatedb(dbtype): > > > 11 db = dbconnect(dbtype) > >> 12 db.execute("DML code") >> 13 print "updated " + dbtype >> 14 'close connection >> >> 15 def main(): >> 16 updatedb('sqlite') >> 17 updatedb('postgres') >> 18 >> 19 if __name__ == "__main__": >> 20 main() >> ------------------------------------------------------------- >> >> > > -- > https://mail.python.org/mailman/listinfo/python-list You may have an indentation problem that isn't apparent in your code pasted here. Are you sure that dbconnect always returns something? -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From gordon at panix.com Wed Apr 5 11:22:02 2017 From: gordon at panix.com (John Gordon) Date: Wed, 5 Apr 2017 15:22:02 +0000 (UTC) Subject: Quick questions about globals and database connections References: Message-ID: In DFS writes: > I have identical databases in sqlite and postgres. I want to run the > same code against them, but am having a small issue. > Current code below throws the dreaded: > NameError: global name 'db' is not defined > on line 12 > How do I fix it? I want to keep dbconnect() as a separate function. Instead of trying to make db global, dbconnect() can return the db object: def dbconnect(dbtype): if dbtype == "sqlite": conn = sqlite3.connect(cstr) elif dbtype == "postgres": conn = psycopg2.connect(cstr) return conn.cursor() def updatedb(dbtype): db = dbconnect(dbtype) db.execute("DML code") print "updated " + dbtype 'close connection It would probably be even better to return conn, as that would allow updatedb() to call conn.disconnect(). -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From davidgshi at yahoo.co.uk Wed Apr 5 11:30:55 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Wed, 5 Apr 2017 15:30:55 +0000 (UTC) Subject: How to capture a CSV file and read it into a Pandas Dataframe? References: <1483290626.909143.1491406255368.ref@mail.yahoo.com> Message-ID: <1483290626.909143.1491406255368@mail.yahoo.com> I tried the following codes: import urllib2response = urllib2.urlopen('http://cordis.europa.eu/search/result_en?q=uk&format=csv')myCSV = response.read() myFile = pd.read_csv(myCSV) but, it did not work well. Can any one help? Regards. David From dan at tombstonezero.net Wed Apr 5 11:31:37 2017 From: dan at tombstonezero.net (Dan Sommers) Date: Wed, 5 Apr 2017 15:31:37 -0000 (UTC) Subject: Quick questions about globals and database connections References: Message-ID: On Wed, 05 Apr 2017 10:54:29 -0400, DFS wrote: > I have identical databases in sqlite and postgres. I want to run the > same code against them, but am having a small issue. > > Current code below throws the dreaded: > > NameError: global name 'db' is not defined > > on line 12 > > How do I fix it? I want to keep dbconnect() as a separate function. > > Thanks. > > ------------------------------------------------------------- > 1 import sqlite3, psycopg2 > 2 > 3 def dbconnect(dbtype): > 4 if dbtype == "sqlite": > 5 conn = sqlite3.connect(cstr) > 6 elif dbtype == "postgres": > 7 conn = psycopg2.connect(cstr) > 8 db = conn.cursor() This line just sets db locally to dbconnect. You'll have to return it in order to use it elsewhere. Add a line like this: return db > 9 > 10 def updatedb(dbtype): > 11 dbconnect(dbtype) And then use the return value from dbconnect to create a new db locally to updatedb: db = dbconnect(dbtype) > 12 db.execute("DML code") > 13 print "updated " + dbtype > 14 'close connection > > 15 def main(): > 16 updatedb('sqlite') > 17 updatedb('postgres') > 18 > 19 if __name__ == "__main__": > 20 main() > ------------------------------------------------------------- HTH, Dan From skip.montanaro at gmail.com Wed Apr 5 12:19:00 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 5 Apr 2017 11:19:00 -0500 Subject: How to capture a CSV file and read it into a Pandas Dataframe? In-Reply-To: <1483290626.909143.1491406255368@mail.yahoo.com> References: <1483290626.909143.1491406255368.ref@mail.yahoo.com> <1483290626.909143.1491406255368@mail.yahoo.com> Message-ID: I'm not positive, but try passing response to read_csv() instead of reading the bytes yourself. Skip On Apr 5, 2017 10:38 AM, "David Shi via Python-list" wrote: > > > I tried the following codes: > import urllib2response = urllib2.urlopen('http://cordis.europa.eu/search/ > result_en?q=uk&format=csv')myCSV = response.read() > myFile = pd.read_csv(myCSV) > > but, it did not work well. > Can any one help? > Regards. > David > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Wed Apr 5 12:24:29 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 05 Apr 2017 18:24:29 +0200 Subject: How to capture a CSV file and read it into a Pandas Dataframe? References: <1483290626.909143.1491406255368.ref@mail.yahoo.com> <1483290626.909143.1491406255368@mail.yahoo.com> Message-ID: David Shi via Python-list wrote: > I tried the following codes: > import urllib2response = > urllib2.urlopen('http://cordis.europa.eu/search/result_en?q=uk&format=csv')myCSV > = response.read() myFile = pd.read_csv(myCSV) > > but, it did not work well. > Can any one help? Looks like read_csv() accepts an URL: >>> import pandas >>> url = "http://cordis.europa.eu/search/result_en?q=uk&format=csv" >>> df = pandas.read_csv(url, sep=";") >>> df.Title[0] 'Incremental Nonlinear flight Control supplemented with Envelope ProtecTION techniques' From rgacote at appropriatesolutions.com Wed Apr 5 14:14:48 2017 From: rgacote at appropriatesolutions.com (Ray Cote) Date: Wed, 5 Apr 2017 14:14:48 -0400 Subject: Python 3.6 printing crashing on OS X 10.12.4 Message-ID: Hello: Python 3.6 crashing when trying to print from the environment. $ python Python 3.6.1 (default, Mar 22 2017, 15:53:21) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> print("hello") Python(53390,0x7fffdd9e63c0) malloc: *** error for object 0x10dde4110: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Abort trap: 6 Pastebin link to OS X crash report if that?s helpful: https://pastebin.com/t1j3nz5L 1: Python installed via ports. 2: OS X 10.12.4. 3: Python 3.6.1 (though I also had this problem with 3.6.0). 4: Have successfully run python 3.5 for months. 5: Running under standard terminal program. 6: I have py36-readline installed. 7: Have tried uninstalling and re-installing Python. Any thoughts on what I could have wrong? Regards ?Ray From cjw at ncf.ca Wed Apr 5 14:46:51 2017 From: cjw at ncf.ca (Colin J. Williams) Date: Wed, 5 Apr 2017 14:46:51 -0400 Subject: Problem installing 3.6.1 AMD64 Message-ID: <6819236c-82e9-841f-23e3-85e4b413a133@ncf.ca> Successful install reported, but: Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved. C:\Users\CJW>cd\python The system cannot find the path specified. C:\Users\CJW>cd\ C:\>path PATH=C:\Program Files\Python35\Scripts\;C:\Program Files\Python35\;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system 32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologi es\ATI.ACE\Core-Static;C:\Program Files (x86)\AMD\ATI.ACE\Core-Static;C:\WINDOWS\system32\config\systemprofile\.dnx\bin; C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\TortoiseHg\; C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Skype\Phone\;C:\Users\CJW\AppData\Local\Progra ms\Python\Python35\Scripts\;C:\Users\CJW\AppData\Local\Programs\Python\Python35\;C:\Python35\Lib\site-packages\PyQt5;C:\ Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Skype\Phone\;C:\Users\CJW\AppData\Local\Programs\Git\cmd;C:\ Users\CJW\AppData\Local\Microsoft\WindowsApps; C:\> Python35 has been deleted, but it remains in the PATH. I would welcome advice. Colin W. From python at example.invalid Wed Apr 5 15:40:26 2017 From: python at example.invalid (Python) Date: Wed, 5 Apr 2017 21:40:26 +0200 Subject: Python 3.6 printing crashing on OS X 10.12.4 References: Message-ID: Le 05/04/2017 ? 20:14, Ray Cote a ?crit : > Hello: > > Python 3.6 crashing when trying to print from the environment. > > $ python > Python 3.6.1 (default, Mar 22 2017, 15:53:21) > [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> print("hello") > > Python(53390,0x7fffdd9e63c0) malloc: *** error for object 0x10dde4110: > pointer being freed was not allocated > *** set a breakpoint in malloc_error_break to debug > Abort trap: 6 > > > Pastebin link to OS X crash report if that?s helpful: > https://pastebin.com/t1j3nz5L > > > 1: Python installed via ports. > 2: OS X 10.12.4. > 3: Python 3.6.1 (though I also had this problem with 3.6.0). > 4: Have successfully run python 3.5 for months. > 5: Running under standard terminal program. > 6: I have py36-readline installed. > 7: Have tried uninstalling and re-installing Python. > > Any thoughts on what I could have wrong? > > Regards > ?Ray > Mac OS X 10.12.3, Python 3 installed by brew mac:~$ uname -r 16.4.0 mac:~$ python3 Python 3.6.0 (default, Mar 4 2017, 12:32:34) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> print("hello") hello From davidgshi at yahoo.co.uk Wed Apr 5 15:41:24 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Wed, 5 Apr 2017 19:41:24 +0000 (UTC) Subject: How to capture a CSV file and read it into a Pandas Dataframe? In-Reply-To: References: <1483290626.909143.1491406255368.ref@mail.yahoo.com> <1483290626.909143.1491406255368@mail.yahoo.com> Message-ID: <226668742.78318.1491421284738@mail.yahoo.com> Hi, Skip, This is something very different. New thinking and methods are needed. Try to click on the following link European Commission : CORDIS : Search : Results page | | | | | | | | | | | European Commission : CORDIS : Search : Results page European Commission | | | | Is there a way to capture the file? Regards. David On Wednesday, 5 April 2017, 17:19, Skip Montanaro wrote: I'm not positive, but try passing response to read_csv() instead of reading the bytes yourself. Skip On Apr 5, 2017 10:38 AM, "David Shi via Python-list" wrote: I tried the following codes: import urllib2response = urllib2.urlopen('http:// cordis.europa.eu/search/ result_en?q=uk&format=csv') myCSV = response.read() myFile = pd.read_csv(myCSV) but, it did not work well. Can any one help? Regards. David -- https://mail.python.org/ mailman/listinfo/python-list From unihno at gmail.com Wed Apr 5 15:48:54 2017 From: unihno at gmail.com (unihno at gmail.com) Date: Wed, 5 Apr 2017 12:48:54 -0700 (PDT) Subject: Using TKinter to show popular tweets from twitter API (Tweepy) Message-ID: <8fec126c-dc79-45af-9d90-b5147b7fcf34@googlegroups.com> hello I'm building a python app where it should show the popular tweets in boxex in line with each other using TKinter. The problem is that the labels of the tweets are showing at the bottom of each other and i want them to be in boxes like this: ---- ---- ---- ---- | | | | | | | | ---- ---- ---- ---- ---- ---- ---- ---- | | | | | | | | ---- ---- ---- ---- ---- ---- ---- ---- | | | | | | | | ---- ---- ---- ---- this is my code: from Tkinter import * import tweepy from local import * import Tkinter as tk auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET) auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET) api = tweepy.API(auth) sa_ID = 23424938 large_text_size = 12 text_size = 20 #create obj in the root page (main windows) root= Tk() root.title("The news Portal") root.configure(background='black') trends1 = api.trends_place(id=sa_ID) data = trends1[0] # grab the trends trends = [] trends=data['trends'] for trend in trends: if trend['name'].startswith('#'): for status in tweepy.Cursor(api.search, q=trend['name'], result_type='popular').items(1): f = tk.Frame(root, background='black', borderwidth=2, relief="groove").pack() Label(text=('@' + status.user.screen_name, "tweeted: ",status.text)).pack() root.mainloop() please help. From dan at tombstonezero.net Wed Apr 5 16:16:25 2017 From: dan at tombstonezero.net (Dan Sommers) Date: Wed, 5 Apr 2017 20:16:25 -0000 (UTC) Subject: Quick questions about globals and database connections References: Message-ID: On Wed, 05 Apr 2017 14:56:12 -0400, DFS wrote: > I split the database connection code and settings into a module, so > the connection and setting values are available to other code modules > I have. Good work. > dbset.py > ------------------------------------------------- > import sqlite3, psycopg2, cx_Oracle > > def openconnection(dbtype): > if dbtype == "sqlite": > dbName = "DB.sqlite" > conn = sqlite3.connect(dbName) > conn.text_factory = str > ps = '?' #query parameter symbol > > if dbtype == "postgres": > dbName = "DB on Postgres" > connectstring = "" \ > " host = 'localhost' " \ > " dbname = 'dbname' " \ > " user = 'USR' " \ > " password = 'PW' " > conn = psycopg2.connect(connectstring) > ps = '%s' #query parameter symbol > > if dbtype == "oracle": > 'settings Consider adding some sort of error checking. One way would be to use elif throughout and an else clause at the end to catch the errors, something like this: if dbtype == '"x": dbName = ... elif dbtype == "y": dbName = ... : : : else: raise ValueError("unknown database type: %s" % dbtype) > db = conn.cursor() > return [conn,db,dbName,ps] These values could be encapsulated into a class, but a list or a tuple works. A small step might be a named tuple (one of the batteries included with Python). Clunky is in the eye of the beholder. That appears to be clear, effective, and easily extensible if you ever add another database server. And never underestimate code that works. Ever. > In other modules, add: > ---------------------------------------------------- > import dbset > > dbconnect = dbset.openconnection(dbtype) > conn = dbconnect[0] > db = dbconnect[1] > dbName = dbconnect[2] > ps = dbconnect[3] > > or shorter version: > > c = dbset.openconnection(dbtype) > conn,db,dbName,ps = c[0],c[1],c[2],c[3] > ---------------------------------------------------- Or even shorter version: conn,db,dbName,ps = dbset.openconnection(dbtype) Python will unpack that list for you. > With that in place, I can do stuff like: > > print "updating " + dbName > db.execute("DML code") > conn.commit() > conn.close() > db.close() Yep. :-) And if you find yourself repeating that sequence of statements over and over, then wrap them into a function: def execute_database_command(dbName, conn, db, dml_statement): print "updating " + dbName db.execute(dml_statement) conn.commit() conn.execute() db.close() and then the rest of your code is just: execute_database_command(db, conn, "DML code") From best_lay at yahoo.com Wed Apr 5 17:10:37 2017 From: best_lay at yahoo.com (Wildman) Date: Wed, 05 Apr 2017 16:10:37 -0500 Subject: Request Help With pkexec References: Message-ID: On Mon, 03 Apr 2017 14:29:56 -0500, Wildman wrote: > Python 3.4.2 > Tkinter 8.6 > GCC 4.9.1 on Linux > > I am working on a gui program using Tkinter. The program will > have a feature to restart as root. I am testing different gui > front-ends from a terminal to raise privileges and I want to > be able to use as many as possible for obvious reasons. Gksu, > kdesudo and su-to-root all work perfectly. However, I have a > problem with pkexec. Here is the command I am using from a > terminal: > > $ pkexec python3 /home/user/Python/linfo-tk/linfo-tk.py > > I get this error: > > Traceback (most recent call last): > File "/home/user/Python/linfo-tk/linfo-tk.py", line 455, in > root = tk.Tk() > File "/usr/lib/python3.4/tkinter/__init__.py", line 1854, in __init__ > self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) > _tkinter.TclError: no display name and no $DISPLAY environment variable I am posting this follow-up for any Linux developer that might be working on a gui program that requires root permissions. My research revealed that programs like gksu are not going to be supported long term. Some distros have already dropped gksu in favor of pkexec. Pkexec is part of the PolicyKit package, policykit-1. By default it will not work with gui (X11) programs but that behavior can be changed by using a .policy file placed in /usr/share/polkit-1/actions/. Once I created such a file, pkexec worked perfectly with my program. So my problem was not Python related. Below is the actual .policy file I am using. It could be edited to work with any program. Lots of info on the web about pkexec and the HTML .policy file. Just search on something like "run program with pkexec". The name of the file is com.ubuntu.pkexec.linfo-tk.policy. Here is the contents: Wildman Productions Authentication is required to run Linfo-tk as root auth_admin auth_admin auth_admin /opt/linfo-tk/linfo-tk.py TRUE -- GNU/Linux user #557453 The cow died so I don't need your bull! From skip.montanaro at gmail.com Wed Apr 5 17:18:57 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 5 Apr 2017 16:18:57 -0500 Subject: How to capture a CSV file and read it into a Pandas Dataframe? In-Reply-To: <226668742.78318.1491421284738@mail.yahoo.com> References: <1483290626.909143.1491406255368.ref@mail.yahoo.com> <1483290626.909143.1491406255368@mail.yahoo.com> <226668742.78318.1491421284738@mail.yahoo.com> Message-ID: David> This is something very different. David> New thinking and methods are needed. David> Try to click on the following link David> European Commission : CORDIS : Search : Results page Hopefully not too very different. :-) Looks to me like UTF-32 or UTF-16 encoding, or one of those encodings which needs a BOM. I was able to read it using Python's csv module (this in Python 3): >>> f = open("cordis-search-results.csv") >>> rdr = csv.DictReader(f, delimiter=';') >>> for row in rdr: ... print(row["Title"]) ... Incremental Nonlinear flight Control supplemented with Envelope ProtecTION techniques AdvancEd aicRaft-noIse-AlLeviation devIceS using meTamaterials Imaging Biomarkers (IBs) for Safer Drugs: Validation of Translational Imaging Methods in Drug Safety Assessment (IB4SD-TRISTAN) Big Data for Better Outcomes, Policy Innovation and Healthcare System Transformation (DO->IT) Translational quantitative systems toxicology to improve the understanding of the safety of medicines Real world Outcomes across the AD spectrum for better care: Multi-modal data Access Platform Models Of Patient Engagement for Alzheimer?s Disease INtestinal Tissue ENgineering Solution Small vessel diseases in a mechanistic perspective: Targets for InterventionAffected pathways and mechanistic exploitation for prevention of stroke and dementia How does dopamine link QMP with reproductive repression to mediate colony harmony and productivity in the honeybee? Note that I had to specify the delimiter as a semicolon. That also works with pandas.read_csv: >>> df = pd.read_csv("cordis-search-results.csv", sep=";") >>> print(df["Title"]) 0 Incremental Nonlinear flight Control supplemen... 1 AdvancEd aicRaft-noIse-AlLeviation devIceS usi... 2 Imaging Biomarkers (IBs) for Safer Drugs: Vali... 3 Big Data for Better Outcomes, Policy Innovatio... 4 Translational quantitative systems toxicology ... 5 Real world Outcomes across the AD spectrum for... 6 Models Of Patient Engagement for Alzheimer?s D... 7 INtestinal Tissue ENgineering Solution 8 Small vessel diseases in a mechanistic perspec... 9 How does dopamine link QMP with reproductive r... Name: Title, dtype: object Skip From tjreedy at udel.edu Wed Apr 5 17:31:31 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 5 Apr 2017 17:31:31 -0400 Subject: Using TKinter to show popular tweets from twitter API (Tweepy) In-Reply-To: <8fec126c-dc79-45af-9d90-b5147b7fcf34@googlegroups.com> References: <8fec126c-dc79-45af-9d90-b5147b7fcf34@googlegroups.com> Message-ID: On 4/5/2017 3:48 PM, unihno at gmail.com wrote: > I'm building a python app where it should show the popular tweets > in boxes in line with each other using TKinter. By 'boxes' do you mean a visible border for Label widgets? If so, you have to configure one. You don't below. > The problem is that the labels of the tweets are showing at > the bottom of each other I don't understand this, and cannot run your code to see what it does. > and i want them to be in boxes like this: snip > this is my code: > > from Tkinter import * > import tweepy > from local import * > import Tkinter as tk Use just 1 of the 2 tkinter imports. > auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) > auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET) > auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) > auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET) > api = tweepy.API(auth) For initial development of the UI, and especially when asking for help, use static data included within the file. In this case, a short list of 'status' items with the required attributes. Read https://stackoverflow.com/help/mcve > for status in tweepy.Cursor(api.search, q=trend['name'], result_type='popular').items(1): for status in myshortlist: > f = tk.Frame(root, background='black', borderwidth=2, relief="groove").pack() Commen error. .pack(), etc is a status mutation method and returns None. You did not get an exception only because f is not used. > Label(text=('@' + status.user.screen_name, "tweeted: ",status.text)).pack() You omitted the master, so it defaults to the more or less undocumented default root. It this context, this should be the explicit 'root' defined previously. I recommend being explicit, always. I did not know that the 'string' passed as 'text' could be a tuple of strings. I don't know if it is documented anywhere. My simple experiment suggested that the result is ' '.join(strings), as with print calls. But I don't know it that is always true. Multiple Labels should be packed vertically, with each centered. If you want lined up to the left, you will have to say so. As I said, I don't know what you saw. > Please help Please make it easier by posting a better question, including an mcve. -- Terry Jan Reedy From greg.ewing at canterbury.ac.nz Wed Apr 5 18:55:28 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 06 Apr 2017 10:55:28 +1200 Subject: Data exchange between python script and bash script In-Reply-To: References: <50298d86-e688-4162-b96f-632e5a98c141@googlegroups.com> Message-ID: Anssi Saari wrote: > Bash manual explicitly states command substition (the $(...) structure) > replaces the command with the standard *output* of the command. Another problem is your use of '&' here: sensor_data=$(python execute_sensor_process.py) & The '&' causes the whole command, including the variable assignment, to be executed in a subshell. So the variable is only bound in the subshell process and won't be seen from the main shell process. Running the command in the background here is pointless, since if the shell script needs the variable value for subsequent processing it will have to wait for the command to finish. So just get rid of the '&'. -- Greg From greg.ewing at canterbury.ac.nz Wed Apr 5 18:59:03 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 06 Apr 2017 10:59:03 +1200 Subject: "pandas" pronunciation In-Reply-To: References: Message-ID: Neil Cerutti wrote: > On 2017-04-03, Jay Braun wrote: > >>I hear people say it like the plural of "panda", and others as >>"panduss". Is there a correct way? > > I think it is pronounced like the regular word. The second a is > schwa in both the singular and plural. I think the OP is referring to the distinction between "pandas" with an unvoiced "s", and "pandaz", as in the plural of "panda". -- Greg From eryksun at gmail.com Wed Apr 5 19:55:24 2017 From: eryksun at gmail.com (eryk sun) Date: Wed, 5 Apr 2017 23:55:24 +0000 Subject: Problem installing 3.6.1 AMD64 In-Reply-To: <6819236c-82e9-841f-23e3-85e4b413a133@ncf.ca> References: <6819236c-82e9-841f-23e3-85e4b413a133@ncf.ca> Message-ID: On Wed, Apr 5, 2017 at 6:46 PM, Colin J. Williams wrote: > Successful install reported, but: > > Microsoft Windows [Version 10.0.14393] > (c) 2016 Microsoft Corporation. All rights reserved. You're using Windows 10. > C:\Users\CJW>cd\python > The system cannot find the path specified. > > C:\Users\CJW>cd\ What is this supposed to be doing? > C:\>path > PATH=C:\Program Files\Python35\Scripts\;C:\Program > Files\Python35\;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system > 32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program > Files (x86)\ATI Technologi > es\ATI.ACE\Core-Static;C:\Program Files > (x86)\AMD\ATI.ACE\Core-Static;C:\WINDOWS\system32\config\systemprofile\.dnx\bin; > C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL > Server\130\Tools\Binn\;C:\Program Files\TortoiseHg\; > C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files > (x86)\Skype\Phone\;C:\Users\CJW\AppData\Local\Progra > ms\Python\Python35\Scripts\;C:\Users\CJW\AppData\Local\Programs\Python\Python35\;C:\Python35\Lib\site-packages\PyQt5;C:\ > Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program > Files (x86)\ > ATI Technologies\ATI.ACE\Core-Static;C:\Program Files > (x86)\Skype\Phone\;C:\Users\CJW\AppData\Local\Programs\Git\cmd;C:\ > Users\CJW\AppData\Local\Microsoft\WindowsApps; > > C:\> > > Python35 has been deleted, but it remains in the PATH. > > I would welcome advice. The environment variable editor in Windows 10 has made editing PATH about as easy as possible. Just manually remove (select and click on "Delete") whichever paths are no longer valid. Apparently one is per-machine in "C:\Program Files\Python35", which will likely be in the system PATH, and the other is per-user in "C:\Users\CJW\AppData\Local\Programs\Python\Python35", which will likely be in the user PATH. From python at mrabarnett.plus.com Wed Apr 5 20:12:01 2017 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 6 Apr 2017 01:12:01 +0100 Subject: Problem installing 3.6.1 AMD64 In-Reply-To: <6819236c-82e9-841f-23e3-85e4b413a133@ncf.ca> References: <6819236c-82e9-841f-23e3-85e4b413a133@ncf.ca> Message-ID: <9aa7a8bd-dc2d-9ab6-7484-56fab1f34018@mrabarnett.plus.com> On 2017-04-05 19:46, Colin J. Williams wrote: > Successful install reported, but: > > Microsoft Windows [Version 10.0.14393] > (c) 2016 Microsoft Corporation. All rights reserved. > > C:\Users\CJW>cd\python > The system cannot find the path specified. > > C:\Users\CJW>cd\ > > C:\>path > PATH=C:\Program Files\Python35\Scripts\;C:\Program > Files\Python35\;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system > 32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program > Files (x86)\ATI Technologi > es\ATI.ACE\Core-Static;C:\Program Files > (x86)\AMD\ATI.ACE\Core-Static;C:\WINDOWS\system32\config\systemprofile\.dnx\bin; > C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL > Server\130\Tools\Binn\;C:\Program Files\TortoiseHg\; > C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files > (x86)\Skype\Phone\;C:\Users\CJW\AppData\Local\Progra > ms\Python\Python35\Scripts\;C:\Users\CJW\AppData\Local\Programs\Python\Python35\;C:\Python35\Lib\site-packages\PyQt5;C:\ > Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program > Files (x86)\ > ATI Technologies\ATI.ACE\Core-Static;C:\Program Files > (x86)\Skype\Phone\;C:\Users\CJW\AppData\Local\Programs\Git\cmd;C:\ > Users\CJW\AppData\Local\Microsoft\WindowsApps; > > C:\> > > Python35 has been deleted, but it remains in the PATH. > > I would welcome advice. > It's easy enough to remove those references. Try to start Python 3.5 to check that it's really gone: C:\> py -3.5 It should complain if it's no longer there. Start Python 3.6: C:\> py -3.6 Have a look at the references to Python 3.5 in the PATH environment variable to double-check: >>> import os >>> [p for p in os.environ['PATH'].split(';') if 'Python35' in p] Remove those references from the PATH environment variable: >>> os.environ['PATH'] = ';'.join(p for p in os.environ['PATH'].split(';') if 'Python35' not in p) Job done! From eryksun at gmail.com Wed Apr 5 20:38:05 2017 From: eryksun at gmail.com (eryk sun) Date: Thu, 6 Apr 2017 00:38:05 +0000 Subject: Problem installing 3.6.1 AMD64 In-Reply-To: <9aa7a8bd-dc2d-9ab6-7484-56fab1f34018@mrabarnett.plus.com> References: <6819236c-82e9-841f-23e3-85e4b413a133@ncf.ca> <9aa7a8bd-dc2d-9ab6-7484-56fab1f34018@mrabarnett.plus.com> Message-ID: On Thu, Apr 6, 2017 at 12:12 AM, MRAB wrote: >>>> import os >>>> [p for p in os.environ['PATH'].split(';') if 'Python35' in p] > > Remove those references from the PATH environment variable: > >>>> os.environ['PATH'] = ';'.join(p for p in os.environ['PATH'].split(';') >>>> if 'Python35' not in p) > > Job done! Changing an environment variable in a process applies only to the process and its descendants. It doesn't change the persistent value that, on Windows, is stored in the registry. It's best to use the GUI shell's environment-variable editor for this, for multiple reasons. From dan at tombstonezero.net Wed Apr 5 22:52:14 2017 From: dan at tombstonezero.net (Dan Sommers) Date: Thu, 6 Apr 2017 02:52:14 -0000 (UTC) Subject: Quick questions about globals and database connections References: Message-ID: On Wed, 05 Apr 2017 22:00:46 -0400, DFS wrote: > I have a simple hard-coded check in place before even trying to connect: > > if dbtype not in ('sqlite postgres'): > print "db type must be sqlite or postgres" > exit() That's not doing what you think it is. Hint: What is ('sqlite postgres')? > Good comments, Lt. Dan. Thanks. No problem. From scooter800m at gmail.com Wed Apr 5 23:25:48 2017 From: scooter800m at gmail.com (scooter800m) Date: Wed, 5 Apr 2017 21:25:48 -0600 Subject: fresh install setup error Message-ID: hi i just installed python 3.6.1 32-bit on my windows 7 home premium 64-bit. and i get a file missing error. i reinstalled and used the repairing thing and still no working python 3.6.1. here is the error message that i get: From piet-l at pietvanoostrum.com Thu Apr 6 08:25:09 2017 From: piet-l at pietvanoostrum.com (Piet van Oostrum) Date: Thu, 06 Apr 2017 14:25:09 +0200 Subject: Temporary variables in list comprehensions References: <58730938$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > Suppose you have an expensive calculation that gets used two or more times in a > loop. The obvious way to avoid calculating it twice in an ordinary loop is with > a temporary variable: > > result = [] > for x in data: > tmp = expensive_calculation(x) > result.append((tmp, tmp+1)) > > > But what if you are using a list comprehension? Alas, list comps don't let you > have temporary variables, so you have to write this: > > > [(expensive_calculation(x), expensive_calculation(x) + 1) for x in data] > > > Or do you? ... no, you don't! > > > [(tmp, tmp + 1) for x in data for tmp in [expensive_calculation(x)]] > > > I can't decide whether that's an awesome trick or a horrible hack... It is a poor man's 'let'. It would be nice if python had a real 'let' construction. Or for example: [(tmp, tmp + 1) for x in data with tmp = expensive_calculation(x)] Alas! -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From aldersilva676 at gmail.com Thu Apr 6 08:43:37 2017 From: aldersilva676 at gmail.com (aldersilva676 at gmail.com) Date: Thu, 6 Apr 2017 05:43:37 -0700 (PDT) Subject: PYTHON Message-ID: <92da1b3a-0154-4d8c-8015-588e851c66dd@googlegroups.com> Hello, how can I start programming? From lists at mostrom.pp.se Thu Apr 6 08:47:56 2017 From: lists at mostrom.pp.se (Jan Erik =?utf-8?q?Mostr=C3=B6m?=) Date: Thu, 06 Apr 2017 14:47:56 +0200 Subject: PYTHON In-Reply-To: <92da1b3a-0154-4d8c-8015-588e851c66dd@googlegroups.com> References: <92da1b3a-0154-4d8c-8015-588e851c66dd@googlegroups.com> Message-ID: On 6 Apr 2017, at 14:43, aldersilva676 at gmail.com wrote: > Hello, how can I start programming? Let me google that for you => http://www.learnpython.org From vincent.vande.vyvre at telenet.be Thu Apr 6 08:56:41 2017 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Thu, 6 Apr 2017 14:56:41 +0200 Subject: Temporary variables in list comprehensions In-Reply-To: References: <58730938$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <32748803-a19e-dc76-ca4c-77f31916f05d@telenet.be> Le 06/04/17 ? 14:25, Piet van Oostrum a ?crit : > Steven D'Aprano writes: > >> Suppose you have an expensive calculation that gets used two or more times in a >> loop. The obvious way to avoid calculating it twice in an ordinary loop is with >> a temporary variable: >> >> result = [] >> for x in data: >> tmp = expensive_calculation(x) >> result.append((tmp, tmp+1)) >> >> >> But what if you are using a list comprehension? Alas, list comps don't let you >> have temporary variables, so you have to write this: >> >> >> [(expensive_calculation(x), expensive_calculation(x) + 1) for x in data] >> >> >> Or do you? ... no, you don't! >> >> >> [(tmp, tmp + 1) for x in data for tmp in [expensive_calculation(x)]] >> >> >> I can't decide whether that's an awesome trick or a horrible hack... > It is a poor man's 'let'. It would be nice if python had a real 'let' > construction. Or for example: > > [(tmp, tmp + 1) for x in data with tmp = expensive_calculation(x)] > > Alas! With two passes e = [expensive_calculation(x) for x in data] final = [(x, y+1) for x, y in zip(e, e)] Vincent From cjw at ncf.ca Thu Apr 6 10:13:00 2017 From: cjw at ncf.ca (Colin J. Williams) Date: Thu, 6 Apr 2017 10:13:00 -0400 Subject: Problem installing 3.6.1 AMD64 In-Reply-To: References: <6819236c-82e9-841f-23e3-85e4b413a133@ncf.ca> Message-ID: <03ab17a9-e35d-3107-f43b-fcf157067f47@ncf.ca> Eryk, Many thanks. I wasn't aware of the Path Editor, Colin W. On 2017-04-05 7:55 PM, eryk sun wrote: On Wed, Apr 5, 2017 at 6:46 PM, Colin J. Williams [1] wrote: Successful install reported, but: Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved. You're using Windows 10. C:\Users\CJW>cd\python The system cannot find the path specified. C:\Users\CJW>cd\ What is this supposed to be doing? C:\>path PATH=C:\Program Files\Python35\Scripts\;C:\Program Files\Python35\;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system 32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologi es\ATI.ACE\Core-Static;C:\Program Files (x86)\AMD\ATI.ACE\Core-Static;C:\WINDOWS\system32\config\systemprofile\.dnx\bin; C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\TortoiseHg\; C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Skype\Phone\;C:\Users\CJW\AppData\Local\Progra ms\Python\Python35\Scripts\;C:\Users\CJW\AppData\Local\Programs\Python\Python35\;C:\Python35\Lib\site-packages\PyQt5;C:\ Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Skype\Phone\;C:\Users\CJW\AppData\Local\Programs\Git\cmd;C:\ Users\CJW\AppData\Local\Microsoft\WindowsApps; C:\> Python35 has been deleted, but it remains in the PATH. I would welcome advice. The environment variable editor in Windows 10 has made editing PATH about as easy as possible. Just manually remove (select and click on "Delete") whichever paths are no longer valid. Apparently one is per-machine in "C:\Program Files\Python35", which will likely be in the system PATH, and the other is per-user in "C:\Users\CJW\AppData\Local\Programs\Python\Python35", which will likely be in the user PATH. References Visible links 1. mailto:cjw at ncf.ca From jussi.piitulainen at helsinki.fi Thu Apr 6 10:16:12 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Thu, 06 Apr 2017 17:16:12 +0300 Subject: Temporary variables in list comprehensions References: <58730938$0$1597$c3e8da3$5496439d@news.astraweb.com> <32748803-a19e-dc76-ca4c-77f31916f05d@telenet.be> Message-ID: Vincent Vande Vyvre writes: > Le 06/04/17 ? 14:25, Piet van Oostrum a ?crit : >> Steven D'Aprano writes: >> >>> Suppose you have an expensive calculation that gets used two or more >>> times in a loop. The obvious way to avoid calculating it twice in an >>> ordinary loop is with a temporary variable: >>> >>> result = [] >>> for x in data: >>> tmp = expensive_calculation(x) >>> result.append((tmp, tmp+1)) >>> >>> >>> But what if you are using a list comprehension? Alas, list comps >>> don't let you have temporary variables, so you have to write this: >>> >>> >>> [(expensive_calculation(x), expensive_calculation(x) + 1) for x in data] >>> >>> >>> Or do you? ... no, you don't! >>> >>> >>> [(tmp, tmp + 1) for x in data for tmp in [expensive_calculation(x)]] >>> >>> >>> I can't decide whether that's an awesome trick or a horrible hack... >> It is a poor man's 'let'. It would be nice if python had a real 'let' >> construction. Or for example: >> >> [(tmp, tmp + 1) for x in data with tmp = expensive_calculation(x)] >> >> Alas! > > With two passes > > e = [expensive_calculation(x) for x in data] > final = [(x, y+1) for x, y in zip(e, e)] > > Vincent Imagine some crazy combinatory question - how many ways can one choose two subsets of the ten decimal digits so that the size of the first is the minimum of the second and the size of the second is the maximum of the first _or_ the minima and maxima of the two are the same? Comprehensions lend themselves readily to such explorations. It happens that some expensively computed value is needed twice, like the minima and maxima of the two combinations in this exercise (because this exercise was carefully crafted to be just so, but anyway), and then it saves time to do the computations once: let the values have names. from itertools import combinations as choose print(sum(1 for m in range(1,10) for n in range(1,10) for a in choose(range(1,10), m) for b in choose(range(1,10), n) if ((len(a) == min(b) and len(b) == max(a)) or (min(a) == min(b) and max(a) == max(b))))) print(sum(1 for m in range(1,10) for n in range(1,10) for a in choose(range(1,10), m) for b in choose(range(1,10), n) for lena, mina, maxa in [[len(a), min(a), max(a)]] for lenb, minb, maxb in [[len(b), min(b), max(b)]] if ((lena == minb and lenb == maxa) or (mina == minb and maxa == maxb)))) I realized afterwards that the sizes, len(a) and len(b), already had names, m and n, and were only used once in the condition anyway, but let that illustrate the point: this kind of expression lends itself to analysis and modification, which is what one wants in explorative code. (But the "for x in [foo(u,w)]" works, so, shrug, I guess? I'd welcome a proper let construction, but then I find that I can live without.) From jussi.piitulainen at helsinki.fi Thu Apr 6 10:53:15 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Thu, 06 Apr 2017 17:53:15 +0300 Subject: Quick questions about globals and database connections References: Message-ID: DFS writes: > On 4/5/2017 10:52 PM, Dan Sommers wrote: >> On Wed, 05 Apr 2017 22:00:46 -0400, DFS wrote: >> >>> I have a simple hard-coded check in place before even trying to connect: >>> >>> if dbtype not in ('sqlite postgres'): >>> print "db type must be sqlite or postgres" >>> exit() >> >> That's not doing what you think it is. >> >> Hint: What is ('sqlite postgres')? > > ? > > dbtype is a string, and the check works perfectly. No typos make it > past the guard. "lite post" in "sqlite postgres" From python at example.invalid Thu Apr 6 10:54:21 2017 From: python at example.invalid (Python) Date: Thu, 6 Apr 2017 16:54:21 +0200 Subject: Quick questions about globals and database connections References: Message-ID: Le 06/04/2017 ? 16:46, DFS a ?crit : > On 4/5/2017 10:52 PM, Dan Sommers wrote: >> On Wed, 05 Apr 2017 22:00:46 -0400, DFS wrote: >> >>> I have a simple hard-coded check in place before even trying to connect: >>> >>> if dbtype not in ('sqlite postgres'): >>> print "db type must be sqlite or postgres" >>> exit() >> >> That's not doing what you think it is. >> >> Hint: What is ('sqlite postgres')? > > ? > > dbtype is a string, and the check works perfectly. No typos make it > past the guard. except that it would be True for dbtype = 'lite post' or dbtype = 'stgr' From mok-kong.shen at t-online.de Thu Apr 6 11:22:01 2017 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Thu, 6 Apr 2017 17:22:01 +0200 Subject: Correction of announcement of Version 2 of a steganographical software of mine Message-ID: Due to a new convention of my Internet provider, my current home page is now: http://mokkong-shen.homepage.t-online.de M. K. Shen From lele at metapensiero.it Thu Apr 6 14:07:57 2017 From: lele at metapensiero.it (Lele Gaifax) Date: Thu, 06 Apr 2017 20:07:57 +0200 Subject: Temporary variables in list comprehensions References: <58730938$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <877f2xmmte.fsf@nautilus> Piet van Oostrum writes: > It is a poor man's 'let'. It would be nice if python had a real 'let' > construction. Or for example: > > [(tmp, tmp + 1) for x in data with tmp = expensive_calculation(x)] > > Alas! It would be nice indeed! Or even [(tmp, tmp + 1) for x in data with expensive_calculation(x) as tmp if tmp is not None] that fits the usual "with" syntax. ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From python.list at tim.thechases.com Thu Apr 6 16:22:49 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 6 Apr 2017 15:22:49 -0500 Subject: Temporary variables in list comprehensions In-Reply-To: <32748803-a19e-dc76-ca4c-77f31916f05d@telenet.be> References: <58730938$0$1597$c3e8da3$5496439d@news.astraweb.com> <32748803-a19e-dc76-ca4c-77f31916f05d@telenet.be> Message-ID: <20170406152249.24cec377@bigbox.christie.dr> On 2017-04-06 14:56, Vincent Vande Vyvre wrote: > With two passes > > e = [expensive_calculation(x) for x in data] > final = [(x, y+1) for x, y in zip(e, e)] Using a generator it can be done in one pass: final = [ (value, tmp, tmp+1) for value, tmp in ( (x, expensive_calculation(x)) for x in data ) ] The above makes use of the original value as well at top level (whether you need it for "if" filtering, or in your final tuple result). If you don't care, you can discard it final = [ (tmp, tmp+1) for tmp in ( expensive_calculation(x) for x in data ) ] -tkc From jussi.piitulainen at helsinki.fi Thu Apr 6 23:54:29 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 07 Apr 2017 06:54:29 +0300 Subject: Quick questions about globals and database connections References: Message-ID: DFS writes: > On 4/6/2017 10:54 AM, Python wrote: >> Le 06/04/2017 ? 16:46, DFS a ?crit : >>> On 4/5/2017 10:52 PM, Dan Sommers wrote: >>>> On Wed, 05 Apr 2017 22:00:46 -0400, DFS wrote: >>>> >>>>> I have a simple hard-coded check in place before even trying to >>>>> connect: >>>>> >>>>> if dbtype not in ('sqlite postgres'): >>>>> print "db type must be sqlite or postgres" >>>>> exit() >>>> >>>> That's not doing what you think it is. >>>> >>>> Hint: What is ('sqlite postgres')? >>> >>> ? >>> >>> dbtype is a string, and the check works perfectly. No typos make it >>> past the guard. >> >> except that it would be True for dbtype = 'lite post' or dbtype = 'stgr' > > > Except before I even get there I have another checkpoint. > > ------------------------------------------------------------------- > if len(sys.argv) != 4: > print "Enter group name, verbose setting (-s or -v), and db type" > exit(0) > > GRP = sys.argv[1] (a few lines later I check this value against a db) > > verbose = 'x' > if sys.argv[2] == '-s': verbose = False > if sys.argv[2] == '-v': verbose = True > if verbose not in (True,False): > print "Enter -s (silent) or -v (verbose)" > exit() > > dbtype = sys.argv[3] > if dbtype not in ('sqlite postgres'): > print "db type must be sqlite or postgres" > exit() > ------------------------------------------------------------------- > > $1,000,000 virtual if you can get a bad command past those. > > These are good commands: > $python progname.py comp.lang.python -v postgres > $python progname.py comp.lang.c -s sqlite So these are meant to be bad commands: $python progname.py comp.lang.python -v post $python progname.py comp.lang.c -s sql $python progname.py comp.lang.cobol -v 'lite post' $python progname.py comp.lang.perl -s stgr What happens when you try them with the above code? From davidgshi at yahoo.co.uk Fri Apr 7 03:47:52 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Fri, 7 Apr 2017 07:47:52 +0000 (UTC) Subject: No subject References: <1939941282.1106484.1491551272538.ref@mail.yahoo.com> Message-ID: <1939941282.1106484.1491551272538@mail.yahoo.com> I was using IPython notebooks. ?All the sudden, it asks for password or token. I did not set any password or token. How do I get back to use my IPython notebooks? Looking forward to hearing from you. Regards. David From davidgshi at yahoo.co.uk Fri Apr 7 05:08:51 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Fri, 7 Apr 2017 09:08:51 +0000 (UTC) Subject: A Python solution for turning a web page into Pandas DataFrame table References: <91048751.1978472.1491556131672.ref@mail.yahoo.com> Message-ID: <91048751.1978472.1491556131672@mail.yahoo.com> Is there a Python solution for turning a web page into Pandas DataFrame table? Looking forward to hearing from you. Regards. David From Jack.Jansen at cwi.nl Fri Apr 7 05:21:38 2017 From: Jack.Jansen at cwi.nl (Jack Jansen) Date: Fri, 7 Apr 2017 11:21:38 +0200 Subject: ANN: pyftpdlib 1.5.2 released In-Reply-To: References: Message-ID: <40ADD434-240F-480F-AB64-C3ABC1096E1E@cwi.nl> It looks as though you posted this message with the ?about? paragraph from a different library? I looked at the web site, and pyftpdlib indeed seems to be an ftp daemon, as the name suggests, not a system load package?. Regards, Jack > On 06 Apr 2017, at 13:06, Giampaolo Rodola' wrote: > > Hello all, > I'm glad to announce the release of pyftpdlib 1.5.2: > https://github.com/giampaolo/pyftpdlib > > About > ===== > > pyftpdlib (process and system utilities) is a cross-platform library for > retrieving information on running processes and system utilization (CPU, > memory, disks, network) in Python. It is useful mainly for system > monitoring, profiling and limiting process resources and management of > running processes. It implements many functionalities offered by command > line tools such as: ps, top, lsof, netstat, ifconfig, who, df, kill, free, > nice, ionice, iostat, iotop, uptime, pidof, tty, taskset, pmap. It > currently supports Linux, Windows, OSX, Sun Solaris, FreeBSD, OpenBSD and > NetBSD, both 32-bit and 64-bit architectures, with Python versions from 2.6 > to 3.5 (users of Python 2.4 and 2.5 may use 2.1.3 version). PyPy is also > known to work. > > What's new > ========== > > **Enhancements** > > - #378: SSL security was improved by disabling SSLv2, SSLv3 and > SSL_COMPRESSION > features. New TLS_FTPHandler's ssl_options class attribute was added. > - #380: AbstractedFS.listdir() can now return also a generator (not only a > list). > > **Bug fixes** > > - #367: ThreadedFTPServer no longer hangs if close_all() is called. > - #394: ETIMEDOUT is not treated as an alias for "connection lost". > - #400: QUIT can raise KeyError in case the user hasn't logged in yet and > sends > QUIT command. > > Links > ===== > > - Home page: https://github.com/giampaolo/pyftpdlib > - Download: https://pypi.python.org/pypi/pyftpdlib > - Documentation: http://pythonhosted.org/pyftpdlib > - What's new: https://github.com/giampaolo/pyftpdlib/blob/master/HISTORY.rst > > -- > > Giampaolo - http://grodola.blogspot.com > -- > https://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations/ -- Jack Jansen, , http://www.cwi.nl/~jack If I can't dance I don't want to be part of your revolution -- Emma Goldman From steve+python at pearwood.info Fri Apr 7 06:19:50 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 07 Apr 2017 20:19:50 +1000 Subject: A Python solution for turning a web page into Pandas DataFrame table References: <91048751.1978472.1491556131672.ref@mail.yahoo.com> <91048751.1978472.1491556131672@mail.yahoo.com> Message-ID: <58e767c8$0$1589$c3e8da3$5496439d@news.astraweb.com> On Fri, 7 Apr 2017 07:08 pm, David Shi wrote: > > > Is there a Python solution for turning a web page into Pandas DataFrame > table? Looking forward to hearing from you. What, *any* web page? Like this? http://www.math.ubc.ca/~cass/courses/m308-03b/projects-03b/skinner/ex-dimension-sierpinski_gasket.htm What exactly would you expect to go into the dataframe? I think you need to be more specific. What web page, containing what sort of data, and what do you expect to get out of it? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From robin at reportlab.com Fri Apr 7 06:41:56 2017 From: robin at reportlab.com (Robin Becker) Date: Fri, 7 Apr 2017 11:41:56 +0100 Subject: django float round tripping Message-ID: I've been having problems with django FloatFields not round tripping properly; eg field = 0.018903438896219302 gets saved and returns as 0.0189034388962193 It turns out that this is a property of the MySQLdb python interface where in converter.py we have the definition def Float2Str(o, d): return '%.15g' % o if I change this to def Float2Str(o, d): return repr(o) I do seem able to get reproducibility. Are there any downsides to making this change? -- Robin Becker From nimbiotics at gmail.com Fri Apr 7 08:59:54 2017 From: nimbiotics at gmail.com (Mario R. Osorio) Date: Fri, 7 Apr 2017 05:59:54 -0700 (PDT) Subject: PYTHON In-Reply-To: <92da1b3a-0154-4d8c-8015-588e851c66dd@googlegroups.com> References: <92da1b3a-0154-4d8c-8015-588e851c66dd@googlegroups.com> Message-ID: <7eeaaaef-1af9-4417-8c39-4631a4de4391@googlegroups.com> On Thursday, April 6, 2017 at 8:43:48 AM UTC-4, alders... at gmail.com wrote: > Hello, how can I start programming? http://www.lmgtfy.com/?q=Hello%2C+how+can+I+start+programming%3F From brandonmace460 at gmail.com Fri Apr 7 10:57:53 2017 From: brandonmace460 at gmail.com (Brandon Mace) Date: Fri, 7 Apr 2017 15:57:53 +0100 Subject: Issues downloading python. Message-ID: I have downloaded python onto a DELL laptop, but it will not run. I have tried to install it multiple times but each time it does not work so I try again. This time it has come up with a system error and that "The program can't start because api-ms-win-crt-runtime-[1-1-0.dlll is missing" What can I do to make the program run? From hendorf at europython.eu Fri Apr 7 11:37:46 2017 From: hendorf at europython.eu (Alexander Hendorf) Date: Fri, 7 Apr 2017 17:37:46 +0200 Subject: EuroPython 2017: Tickets are now available Message-ID: <00946228-9220-4ED4-9E71-A45E5416DFC3@europython.eu> You can now buy regular tickets for Europe?s largest Python conference. After the early bird tickets sold out in just eight hours, standard rate tickets are now available: Student: EUR 130.- incl. VAT (only available for students and postdocs; please bring your student card) Personal: EUR 375.- incl. VAT (for people enjoying Python from home) Business: EUR 555.- excl. VAT / 677.10 incl. VAT (for people using Python to make a living) Tickets can be purchased via the EuroPython website. https://ep2017.europython.eu/en/registration/buy-tickets/ Please help us spreading the news by forwarding this mail or re-tweeting, thanks! https://twitter.com/europython/status/850368483061846018 Enjoy, EuroPython 2017 Team http://ep2017.europython.eu/ http://www.europython-society.org/ PS: please remember to submit your proposals for the conference. https://ep2017.europython.eu/en/call-for-proposals/ There are only a few days left for submission. The deadline is (Easter) Sunday, April 16th. From none at invalid.com Fri Apr 7 12:29:43 2017 From: none at invalid.com (mm0fmf) Date: Fri, 07 Apr 2017 17:29:43 +0100 Subject: Issues downloading python. In-Reply-To: References: Message-ID: On 07/04/2017 15:57, Brandon Mace wrote: > I have downloaded python onto a DELL laptop, but it will not run. I have > tried to install it multiple times but each time it does not work so I try > again. This time it has come up with a system error and that "The program > can't start because api-ms-win-crt-runtime-[1-1-0.dlll is missing" > What can I do to make the program run? > Install the missing file. https://support.microsoft.com/en-us/kb/2999226 From kdaatwork at gmail.com Fri Apr 7 16:15:00 2017 From: kdaatwork at gmail.com (Keith Anthony) Date: Fri, 7 Apr 2017 16:15:00 -0400 Subject: Elastic Search Message-ID: I need some insightful examples of elastic search, using REGEX ... And using REST. From toby at tobiah.org Fri Apr 7 16:24:58 2017 From: toby at tobiah.org (Tobiah) Date: Fri, 7 Apr 2017 13:24:58 -0700 Subject: Find out which module a class came from Message-ID: I was viewing the python source for a program at work and came across a class name that I knew my company had written: import mycmp1 import mycmp2 import mycmp3 import mycmp4 import mycmp5 foo = FooClass() So I knew that FooClass was defined in one of those imports, but I thought it would be tedious to track down the location of all of those modules (is module.__file___ the best way) and scan them for the class definition. Is there a better way to find the definition of FooClass()? Thanks! From rosuav at gmail.com Fri Apr 7 16:31:09 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 8 Apr 2017 06:31:09 +1000 Subject: Find out which module a class came from In-Reply-To: References: Message-ID: On Sat, Apr 8, 2017 at 6:24 AM, Tobiah wrote: > I was viewing the python source for a program at work and > came across a class name that I knew my company had written: > > import mycmp1 > import mycmp2 > import mycmp3 > import mycmp4 > import mycmp5 > > foo = FooClass() > > > So I knew that FooClass was defined in one of those imports, but > I thought it would be tedious to track down the location of all > of those modules (is module.__file___ the best way) and scan them > for the class definition. Is there a better way to find the > definition of FooClass()? If they're just "import modulename", then FooClass won't be defined unless it's been injected into the builtins or something. Are they "from mycmp1 import *"? Normally, you should be able to just look at FooClass.__module__ to see where it's been created. But if your module layout is messy, that might not be sufficient information. ChrisA From breamoreboy at gmail.com Fri Apr 7 17:02:29 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Fri, 7 Apr 2017 14:02:29 -0700 (PDT) Subject: Elastic Search In-Reply-To: References: Message-ID: <4d9561ff-708a-4bce-aa60-f0d1183b39db@googlegroups.com> On Friday, April 7, 2017 at 9:16:51 PM UTC+1, Keith Anthony wrote: > I need some insightful examples of elastic search, using REGEX ... > And using REST. What was wrong with the hits that you got from your search engine of choice? Kindest regards. Mark Lawrence. From roel at roelschroeven.net Fri Apr 7 17:29:49 2017 From: roel at roelschroeven.net (Roel Schroeven) Date: Fri, 07 Apr 2017 23:29:49 +0200 Subject: Temporary variables in list comprehensions In-Reply-To: <877f2xmmte.fsf@nautilus> References: <58730938$0$1597$c3e8da3$5496439d@news.astraweb.com> <877f2xmmte.fsf@nautilus> Message-ID: Lele Gaifax schreef op 6/04/2017 20:07: > Piet van Oostrum writes: > >> It is a poor man's 'let'. It would be nice if python had a real 'let' >> construction. Or for example: >> >> [(tmp, tmp + 1) for x in data with tmp = expensive_calculation(x)] >> >> Alas! > > It would be nice indeed! > > Or even > > [(tmp, tmp + 1) for x in data > with expensive_calculation(x) as tmp > if tmp is not None] > Perhaps this: [(tmp, tmp + 1) for tmp in (expensive_calculation(x) for x in data) if tmp is not None] A bit less elegant, but works right now. -- Roel Schroeven From steve+python at pearwood.info Fri Apr 7 20:32:52 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 08 Apr 2017 10:32:52 +1000 Subject: Elastic Search References: Message-ID: <58e82fb6$0$22140$c3e8da3$5496439d@news.astraweb.com> On Sat, 8 Apr 2017 06:15 am, Keith Anthony wrote: > I need some insightful examples of elastic search, using REGEX ... > And using REST. What's elastic search? And what does this have to do with Python? Can you be more specific rather than assume we know what you want? What have you tried, what don't you understand, what have you searched for, etc. We're all volunteers here, we aren't paid to decipher people's mysterious questions. If deciphering the question is too hard, you won't find many people willing to spend the time and effort trying to solve it. The better the question you ask, the better the answers you will probably get. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Fri Apr 7 20:48:59 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 08 Apr 2017 10:48:59 +1000 Subject: Find out which module a class came from References: Message-ID: <58e8337e$0$1622$c3e8da3$5496439d@news.astraweb.com> On Sat, 8 Apr 2017 06:24 am, Tobiah wrote: > I was viewing the python source for a program at work and > came across a class name that I knew my company had written: > > import mycmp1 > import mycmp2 > import mycmp3 > import mycmp4 > import mycmp5 > > foo = FooClass() > > > So I knew that FooClass was defined in one of those imports, No you don't. You know the opposite: FooClass must be defined *locally* in the current file, because the name isn't fully qualified. (Well, I say "must" but technically that's not *quite* true... it is possible that one of the modules mycmp1 etc. could inject FooClass into your module, but that's pretty unlikely.) If you have: from mycmp1 import FooClass from mycmp2 import FooClass # etc. foo = FooClass then the last import wins. If you have wild-card imports: from mycmp1 import * from mycmp2 import * # etc. then (1) your dev team should be stoned to death with ripe figs (so it takes longer), and (2) the same rule applies again: the last module importing a FooClass will override any previous imports of the same name. > but > I thought it would be tedious to track down the location of all > of those modules (is module.__file___ the best way) I don't know about "best". Actually having a well-structured code base is probably best. But if you are stuck with a tangled mess, then module.__file__ is probably your least-worst option. > and scan them > for the class definition. Is there a better way to find the > definition of FooClass()? Keep in mind that a sufficiently perverted and incompetent programmer can *accidentally* duplicate the trickiest obfuscation used by intentionally malicious programmers, so there is no guarantee. And if you are trying to analyse malware, or code written by somebody intentionally obfuscating the source so as to guarantee job-security, all bets are off. But for merely ordinary obfuscation caused by poor design, your best bet is probably to inspect Foo.__module__. You can also try: inspect.getsource(FooClass) inspect.getsourcefile(FooClass) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rantingrickjohnson at gmail.com Fri Apr 7 21:00:48 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 7 Apr 2017 18:00:48 -0700 (PDT) Subject: Find out which module a class came from In-Reply-To: <58e8337e$0$1622$c3e8da3$5496439d@news.astraweb.com> References: <58e8337e$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1438d258-cb94-42d8-bf6c-09833504edef@googlegroups.com> On Friday, April 7, 2017 at 7:49:11 PM UTC-5, Steve D'Aprano wrote: > But for merely ordinary obfuscation caused by poor design, > your best bet is probably to inspect Foo.__module__. > > You can also try: > > inspect.getsource(FooClass) > inspect.getsourcefile(FooClass) Hmm, I tried that code but all i got was a nameError. >>> inspect.getsource(FooClass) Traceback (most recent call last): File "", line 1, in inspect.getsource(FooClass) NameError: name 'inspect' is not defined >>> inspect.getsourcefile(FooClass) Traceback (most recent call last): File "", line 1, in inspect.getsourcefile(FooClass) NameError: name 'inspect' is not defined You must be using the Python version that has batteries _and_ imports included. From jussi.piitulainen at helsinki.fi Sat Apr 8 01:51:52 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Sat, 08 Apr 2017 08:51:52 +0300 Subject: Temporary variables in list comprehensions References: <58730938$0$1597$c3e8da3$5496439d@news.astraweb.com> <877f2xmmte.fsf@nautilus> Message-ID: Roel Schroeven writes: > Lele Gaifax schreef op 6/04/2017 20:07: >> Piet van Oostrum writes: >> >>> It is a poor man's 'let'. It would be nice if python had a real 'let' >>> construction. Or for example: >>> >>> [(tmp, tmp + 1) for x in data with tmp = expensive_calculation(x)] >>> >>> Alas! >> >> It would be nice indeed! >> >> Or even >> >> [(tmp, tmp + 1) for x in data >> with expensive_calculation(x) as tmp >> if tmp is not None] >> > > Perhaps this: > > [(tmp, tmp + 1) for tmp in > (expensive_calculation(x) for x in data) > if tmp is not None] > > A bit less elegant, but works right now. The "poor man's let" works right now. From no.email at nospam.invalid Sat Apr 8 05:01:00 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 08 Apr 2017 02:01:00 -0700 Subject: Elastic Search References: <58e82fb6$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: <878tnb9stv.fsf@nightsong.com> Steve D'Aprano writes: > What's elastic search? > And what does this have to do with Python? https://www.elastic.co/ (formerly elasticsearch.org). It's a Lucene-based distributed search engine, something like Solr if you're used to that. It has Python client libraries. That's the closest Python connection that I know of. I've never used it but I've used Solr. These things are good tools to have available if you need to index a lot of text. From jpolo at mail.usf.edu Sat Apr 8 14:32:20 2017 From: jpolo at mail.usf.edu (john polo) Date: Sat, 8 Apr 2017 13:32:20 -0500 Subject: read in a list in a file to list Message-ID: <5db12517-4c1a-f180-978f-533a632b8b36@mail.usf.edu> Hi, I am using Python 3.6 on Windows 7. I have a file called apefile.txt. apefile.txt's contents are: apes = "Home sapiens", "Pan troglodytes", "Gorilla gorilla" I have a script: apefile = open("apefile.txt") apelist = apefile.read() for ape in apelist: print("one of the apes is " + ape) apefile.close() The output from the script does not print the ape names, instead it prints each letter in the file. For example: one of the apes is a one of the apes is p one of the apes is e What should I do instead to get something like one of the apes is Home sapiens one of the apes is Pan troglodytes one of the apes is Gorilla gorilla John From breamoreboy at gmail.com Sat Apr 8 16:21:08 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sat, 8 Apr 2017 13:21:08 -0700 (PDT) Subject: read in a list in a file to list In-Reply-To: References: <5db12517-4c1a-f180-978f-533a632b8b36@mail.usf.edu> Message-ID: <43baa05f-7cdf-4e58-a62a-1e917fea8219@googlegroups.com> On Saturday, April 8, 2017 at 7:32:52 PM UTC+1, john polo wrote: > Hi, > > I am using Python 3.6 on Windows 7. > > I have a file called apefile.txt. apefile.txt's contents are: > > apes = "Home sapiens", "Pan troglodytes", "Gorilla gorilla" > > I have a script: > > apefile = open("apefile.txt") > apelist = apefile.read() > for ape in apelist: > print("one of the apes is " + ape) > apefile.close() > > The output from the script does not print the ape names, instead it > prints each letter in the file. For example: > > one of the apes is a > one of the apes is p > one of the apes is e > > What should I do instead to get something like > > one of the apes is Home sapiens > one of the apes is Pan troglodytes > one of the apes is Gorilla gorilla > > John I'll start you off. with open("apefile.txt") as apefile: for line in apefile: doSomething(line) String methods and/or the csv module might be used here in doSomething(line), but I'll leave that to you so that you can learn. If you get stuck please ask again, we don't bite :) Kindest regards. Mark Lawrence. From robertvstepp at gmail.com Sat Apr 8 17:27:39 2017 From: robertvstepp at gmail.com (boB Stepp) Date: Sat, 8 Apr 2017 16:27:39 -0500 Subject: read in a list in a file to list In-Reply-To: <43baa05f-7cdf-4e58-a62a-1e917fea8219@googlegroups.com> References: <5db12517-4c1a-f180-978f-533a632b8b36@mail.usf.edu> <43baa05f-7cdf-4e58-a62a-1e917fea8219@googlegroups.com> Message-ID: On Sat, Apr 8, 2017 at 3:21 PM, wrote: > On Saturday, April 8, 2017 at 7:32:52 PM UTC+1, john polo wrote: >> Hi, >> >> I am using Python 3.6 on Windows 7. >> >> I have a file called apefile.txt. apefile.txt's contents are: >> >> apes = "Home sapiens", "Pan troglodytes", "Gorilla gorilla" >> >> I have a script: >> >> apefile = open("apefile.txt") >> apelist = apefile.read() I think you misunderstand what the read() method is doing here. It does not return a list. Instead, it returns the entire file as a single string. >> for ape in apelist: So here despite the variable name you chose, you are acutally iterating over the entire file contents character by character. See Mark's answer/hint below on how to iterate over the file contents by line. You might want to look up the docs on how to use these file objects and their methods. >> print("one of the apes is " + ape) >> apefile.close() >> >> The output from the script does not print the ape names, instead it >> prints each letter in the file. For example: >> >> one of the apes is a >> one of the apes is p >> one of the apes is e >> >> What should I do instead to get something like >> >> one of the apes is Home sapiens >> one of the apes is Pan troglodytes >> one of the apes is Gorilla gorilla >> >> John > > I'll start you off. > > with open("apefile.txt") as apefile: > for line in apefile: > doSomething(line) > > String methods and/or the csv module might be used here in doSomething(line), but I'll leave that to you so that you can learn. If you get stuck please ask again, we don't bite :) -- boB From breamoreboy at gmail.com Sat Apr 8 20:20:24 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sat, 8 Apr 2017 17:20:24 -0700 (PDT) Subject: Python and the need for speed Message-ID: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> I've an idea that http://www.mos6581.org/python_need_for_speed is a week late for April Fool's but just in case I'm sure that some of you may wish to comment. Kindest regards. Mark Lawrence. From kbrede at gmail.com Sat Apr 8 20:55:51 2017 From: kbrede at gmail.com (Kenton Brede) Date: Sat, 8 Apr 2017 19:55:51 -0500 Subject: Need help with getting Key, Value out of dicts in lists Message-ID: This is an example of the data I'm working with. The key/value pairs may come in any order. There are some keys like the 'Resource_group_id' key and the 'Name' key which will always be present, but other lists may have unique keys. alist = [[{u'Value': 'shibboleth-prd', u'Key': 'Name'}, {u'Value': 'kvmu', u'Key': 'Billing'}, {u'Value': '20179204-181622543367489', u'Key': 'Resource_group_id'}], [{u'Value': '20172857-152037106154311', u'Key': 'Resource_group_id'}, {u'Value': 'shibboleth-tst', u'Key': 'Name'}]] What I want to do is something along the lines of: for a in alist: if a['Resource_group_id'] == '01234829-2041523815431': print the Value of 'Name' print the Value of 'Billing' I've found I can do the following, to print the value of 'Name' but that only works if the 'Resource_group_id' key is the first key in the list and the 'Name' key is in the second slot. If each list contained the same keys, I could probably sort the keys and use [num] to pull back values, but they don't. for a in alist: if a[0]['Key'] == 'Resource_group_id' and a[0]['Value'] == '20172857-152037106154311': print a[1]['Value'] There has to be a way to do this but I've been pounding away at this for hours. Any help appreciated. I'm new to Python and not a programmer, so go easy on me. :) From rantingrickjohnson at gmail.com Sat Apr 8 22:56:12 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 8 Apr 2017 19:56:12 -0700 (PDT) Subject: read in a list in a file to list In-Reply-To: References: <5db12517-4c1a-f180-978f-533a632b8b36@mail.usf.edu> Message-ID: <1312a680-b1d8-4144-a17b-a0348c89a9db@googlegroups.com> @John General debugging methodology dictates that when your output does not match your expectation, you must never assume anything. Here you made the fatal mistake of assuming that: (1) files are stored as list objects, or (2) Python automatically converts file data to list objects, or (3) that python can read your mind, and knowing that you wanted a list, gave you a list. But in any of those cases, you would be wrong. To discover the source of the problem, use Python's wonderful introspection capabilities. In this case, the built-in function named "type" is your friend. > apefile = open("apefile.txt") > apelist = apefile.read() print(type(apelist)) I would also make a slight quibble reguarding your choice of variable names. I would recommend "fileObj" and "fileData" respectively. Unless you are comparing the contents of two or more files (say: "apeData", "monkeyData" and "marmosetData") there is no need for the "ape" mnemonic. Use a generic name instead. From tomuxiong at gmx.com Sat Apr 8 23:47:45 2017 From: tomuxiong at gmx.com (Thomas Nyberg) Date: Sat, 8 Apr 2017 20:47:45 -0700 Subject: Python and the need for speed In-Reply-To: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: <82805919-6788-1542-babb-d6652d54e2ce@gmx.com> On 04/08/2017 05:20 PM, breamoreboy at gmail.com wrote: > I've an idea that http://www.mos6581.org/python_need_for_speed is a week late for April Fool's but just in case I'm sure that some of you may wish to comment. > > Kindest regards. > > Mark Lawrence. > Regarding your restricted subset of python you call turbopython, have you looked into rpython which is a restricted subset of python used by pypy to implement their jit? http://rpython.readthedocs.io/en/latest/faq.html#what-is-this-rpython-language From rosuav at gmail.com Sat Apr 8 23:57:28 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 9 Apr 2017 13:57:28 +1000 Subject: Python and the need for speed In-Reply-To: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: On Sun, Apr 9, 2017 at 10:20 AM, wrote: > I've an idea that http://www.mos6581.org/python_need_for_speed is a week late for April Fool's but just in case I'm sure that some of you may wish to comment. > >From that page: > Other candidates for banishment from TurboPython include eval and exec. Bye bye namedtuple. And compile() is going to have to go, since you could implement eval/exec by creating a new function: >>> runme = r""" print("Hello, world!") import sys sys.stdout.write("I can import modules.\n") """ >>> type(lambda: 1)(compile("def f():" + runme, "exec", "exec").co_consts[0], globals())() Hello, world! I can import modules. So if compile() goes, you also lose ast.parse, which means you lose introspection tools, plus you lose literal_eval and friends. I'm also not sure whether the import machinery would have to be rewritten, but a quick 'git grep' suggests that it would. Removing eval and exec is not as simple as removing them from the standard library. In fact, extreme dynamism is baked deep into the language. You'd have to make some fairly sweeping language changes to get any real benefits from restricting things. There are better ways to improve performance, which is why statickification isn't really pursued. These kinds of posts always come from people who haven't actually tried it. They think that, hey, it'd be easy to just make a subset of Python that's optimizable! But if you actually *do* it, you'd have to either restrict the language HUGELY, or reimplement all sorts of things in a slower way. ChrisA From Irv at furrypants.com Sun Apr 9 00:04:50 2017 From: Irv at furrypants.com (Irv Kalb) Date: Sat, 8 Apr 2017 21:04:50 -0700 Subject: Need help with getting Key, Value out of dicts in lists In-Reply-To: References: Message-ID: <151B2183-414E-4A20-AAA4-17D5143089FE@furrypants.com> > On Apr 8, 2017, at 5:55 PM, Kenton Brede wrote: > > This is an example of the data I'm working with. The key/value pairs may > come in any order. There are some keys like the 'Resource_group_id' key and > the 'Name' key which will always be present, but other lists may have > unique keys. > > alist = [[{u'Value': 'shibboleth-prd', u'Key': 'Name'}, {u'Value': 'kvmu', > u'Key': 'Billing'}, > {u'Value': '20179204-181622543367489', u'Key': > 'Resource_group_id'}], > [{u'Value': '20172857-152037106154311', u'Key': > 'Resource_group_id'}, > {u'Value': 'shibboleth-tst', u'Key': 'Name'}]] > > What I want to do is something along the lines of: > > for a in alist: > if a['Resource_group_id'] == '01234829-2041523815431': > print the Value of 'Name' > print the Value of 'Billing' > > I've found I can do the following, to print the value of 'Name' but that > only works if the 'Resource_group_id' key is the first key in the list and > the 'Name' key is in the second slot. If each list contained the same > keys, I could probably sort the keys and use [num] to pull back values, but > they don't. > > for a in alist: > if a[0]['Key'] == 'Resource_group_id' and a[0]['Value'] == > '20172857-152037106154311': > print a[1]['Value'] > > There has to be a way to do this but I've been pounding away at this for > hours. Any help appreciated. I'm new to Python and not a programmer, so > go easy on me. :) > -- > https://mail.python.org/mailman/listinfo/python-list > From Irv at furrypants.com Sun Apr 9 00:29:21 2017 From: Irv at furrypants.com (Irv Kalb) Date: Sat, 8 Apr 2017 21:29:21 -0700 Subject: Need help with getting Key, Value out of dicts in lists In-Reply-To: References: Message-ID: [ Sorry, forgot the important stuff! ] What you want to do is tricky because your data structure is difficult to deal with. My guess is that it has to do with a misconception about how a Python dictionary works. Yes, it is a series of key/value pairs, but not the way you have it. It looks like you put together dictionaries where each dictionary has a 'Value' and a 'Key'. Instead, _each_ item in a dictionary is a key value pair. The key is typically a string, and the value is obviously some value associated with that key. For example, if you have the ability to rebuild your data a different way, it looks like it would be better to deal with it something like this: aList = [ {'Name':'shibboleth-prd', 'Billing':'kmvu', 'Resource_group_id': '20179204-181622543367489'}, {'Name':'shibboleth-tst', 'Resource_group_id':'20172857-152037106154311'} ] This is a list of dictionaries. However, I'm not sure what you are trying to do with this data. I'm guessing that you want to match a resource group id, and if you find it, print the name and the billing info if they exist. If so, you may want something like this (untested): def printInfo(thisGroupID): for thisDict in aList: # loop through all dictionaries in the list if thisGroupID == aList['Resource_group_id']: if 'Name' in thisDict: # if thisDict has a key called 'Name' print ('Name is', thisDict['Dict']) if 'Billing' in thisDict: # if thisDict has a key called 'Billing' print ('Billing is', thisDict['Billing']) Hope this helps, Irv > On Apr 8, 2017, at 9:04 PM, Irv Kalb wrote: > > What you want to do is tricky because your data structure is difficult to deal with. My guess is that it has to do with a misconception about how a Python dictionary works. Yes, it is a series of key/value pairs, but not the way you have it. It looks like you put together dictionaries where each dictionary has a 'Value' and a 'Key'. > > Instead, _each_ item in a dictionary is a key value pair. The key is typically a string, and the value is obviously some value associated with that key. For example, if you have the ability to rebuild your data a different way, it looks like it would be better to deal with it something like this: > > aList = [ > {'Name':'shibboleth-prd', 'Billing':'kmvu', 'Resource_group_id': '20179204-181622543367489'}, > {'Name':'shibboleth-tst', 'Resource_group_id':'20172857-152037106154311'} > ] > > This is a list of dictionaries. However, I'm not sure what you are trying to do with this data. I'm guessing that you want to match a resource group id, and if you find it, print the name and the billing info if they exist. If so, you may want something like this (untested): > > def printInfo(thisGroupID): > for thisDict in aList: # loop through all dictionaries in the list > if thisGroupID == aList['Resource_group_id']: > if 'Name' in thisDict: # if thisDict has a key called 'Name' > print ('Name is', thisDict['Dict']) > if 'Billing' in thisDict: # if thisDict has a key called 'Billing' > print ('Billing is', thisDict['Billing']) > > Hope this helps, > > Irv > > > >> On Apr 8, 2017, at 5:55 PM, Kenton Brede wrote: >> >> This is an example of the data I'm working with. The key/value pairs may >> come in any order. There are some keys like the 'Resource_group_id' key and >> the 'Name' key which will always be present, but other lists may have >> unique keys. >> >> alist = [[{u'Value': 'shibboleth-prd', u'Key': 'Name'}, {u'Value': 'kvmu', >> u'Key': 'Billing'}, >> {u'Value': '20179204-181622543367489', u'Key': >> 'Resource_group_id'}], >> [{u'Value': '20172857-152037106154311', u'Key': >> 'Resource_group_id'}, >> {u'Value': 'shibboleth-tst', u'Key': 'Name'}]] >> >> What I want to do is something along the lines of: >> >> for a in alist: >> if a['Resource_group_id'] == '01234829-2041523815431': >> print the Value of 'Name' >> print the Value of 'Billing' >> >> I've found I can do the following, to print the value of 'Name' but that >> only works if the 'Resource_group_id' key is the first key in the list and >> the 'Name' key is in the second slot. If each list contained the same >> keys, I could probably sort the keys and use [num] to pull back values, but >> they don't. >> >> for a in alist: >> if a[0]['Key'] == 'Resource_group_id' and a[0]['Value'] == >> '20172857-152037106154311': >> print a[1]['Value'] >> >> There has to be a way to do this but I've been pounding away at this for >> hours. Any help appreciated. I'm new to Python and not a programmer, so >> go easy on me. :) >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From steve at pearwood.info Sun Apr 9 03:39:06 2017 From: steve at pearwood.info (Steven D'Aprano) Date: 09 Apr 2017 07:39:06 GMT Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> On Sun, 09 Apr 2017 13:57:28 +1000, Chris Angelico wrote: > On Sun, Apr 9, 2017 at 10:20 AM, wrote: >> I've an idea that http://www.mos6581.org/python_need_for_speed is a >> week late for April Fool's but just in case I'm sure that some of you >> may wish to comment. I'm not sure why Mark thinks that wanting Python to be faster is a joke. As the page points out, there are many projects attempting (with greater or lesser success) to speed up Python. I'm happy for Mark if his need for high performance is low, but CPython at least is definitely in the middle-tier of performance, and PyPy isn't suitable for all use-cases. I don't know anyone who has ever said "this interpreter is too fast, can you make it run slower?" >>From that page: > >> Other candidates for banishment from TurboPython include eval and exec. > > Bye bye namedtuple. All that would mean is that the implementation of namedtuple would have to change. It would probably require some sort of support from the compiler, but that's okay, the compiler can do (nearly) anything. Something as important and useful as namedtuple would not be dropped from this hypothetical TurboPython. It would just shift the implementation from pure-Python to something else. exec() is actually only needed for a *tiny* bit of namedtuple. The original implementation by Raymond Hettinger takes the easy way out by using exec on the entire class definition, but it is trivially easy to restrict that to just the class __new__ method: https://code.activestate.com/recipes/578918-yet-another-namedtuple but even that could be avoided with a minimal amount of help from the compiler. > And compile() is going to have to go, Indeed. > since you > could implement eval/exec by creating a new function: > >>>> runme = r""" > print("Hello, world!") > import sys sys.stdout.write("I can import modules.\n") > """ >>>> type(lambda: 1)(compile("def f():" + runme, "exec", >>>> "exec").co_consts[0], globals())() > Hello, world! > I can import modules. > > So if compile() goes, you also lose ast.parse, Probably. > which means you lose introspection tools, *Some* introspection tools. Python has many that don't rely on compile or ast.parse. Hell, even Java has some introspection tools, based on reflection, which lets you do Python-like things at runtime. Of course if you do this, you lose performance. > plus you lose literal_eval and friends. I don't know what "friends" you are referring to, but again, if literal_eval is important, the compiler can support it. If you can support an entire Python interpreter and compiler in the form of compile(), then you can support more restricted subset of the language. Writing a parser to evaluate strings, integers, and a few other data types is not exactly brain surgery. > I'm also > not sure whether the import machinery would have to be rewritten, but a > quick 'git grep' suggests that it would. Removing eval and exec is not > as simple as removing them from the standard library. Well of course not, but removing eval and exec is only a necessary, not sufficient, condition, for enabling a huge bunch of compiler optimizations and speeding up Python. This "TurboPython" would require a completely new implementation of the Python interpreter to be fast. It's not as if eval and exec are great heavy concrete weights chained to the leg of the compiler, and all you need do is remove the chain and the compiler suddenly becomes thirty times faster. > In fact, extreme dynamism is baked deep into the language. You'd have to > make some fairly sweeping language changes to get any real benefits from > restricting things. Well, maybe. As is pointed out many, many times, 99% of Python code avoids the sorts of extreme dynamism that keeps things slow. Lots of people would be satisfied with a language *really close* to Python that was ten or twenty times faster, even if it meant that you couldn't write code like this: answer = input("What's your name?") exec("name = %r" % answer) print(name) Even better would be if the compiler was smart enough to use the optimized, fast runtime when the dynamic features aren't used, and fall back on a slower implementation only when needed to support the more dynamic features. I wonder how Victor Stinner's FAT Python is going? http://faster-cpython.readthedocs.io/fat_python.html > There are better ways to improve performance, And yet Python lags behind Javascript and PHP for speed... -- Steve From __peter__ at web.de Sun Apr 9 04:15:51 2017 From: __peter__ at web.de (Peter Otten) Date: Sun, 09 Apr 2017 10:15:51 +0200 Subject: Need help with getting Key, Value out of dicts in lists References: Message-ID: Kenton Brede wrote: > This is an example of the data I'm working with. The key/value pairs may > come in any order. There are some keys like the 'Resource_group_id' key > and the 'Name' key which will always be present, but other lists may have > unique keys. > > alist = [[{u'Value': 'shibboleth-prd', u'Key': 'Name'}, {u'Value': 'kvmu', > u'Key': 'Billing'}, > {u'Value': '20179204-181622543367489', u'Key': > 'Resource_group_id'}], > [{u'Value': '20172857-152037106154311', u'Key': > 'Resource_group_id'}, > {u'Value': 'shibboleth-tst', u'Key': 'Name'}]] > > What I want to do is something along the lines of: > > for a in alist: > if a['Resource_group_id'] == '01234829-2041523815431': > print the Value of 'Name' > print the Value of 'Billing' > > I've found I can do the following, to print the value of 'Name' but that > only works if the 'Resource_group_id' key is the first key in the list and > the 'Name' key is in the second slot. If each list contained the same > keys, I could probably sort the keys and use [num] to pull back values, > but they don't. > > for a in alist: > if a[0]['Key'] == 'Resource_group_id' and a[0]['Value'] == > '20172857-152037106154311': > print a[1]['Value'] > > There has to be a way to do this but I've been pounding away at this for > hours. Any help appreciated. I'm new to Python and not a programmer, so > go easy on me. :) The easiest approach is to convert the inner list of dicts into one dictionary. Here's a way that ensures that duplicates are not overwritten silently: def to_dict(pairs): result = {} for pair in pairs: key = pair["Key"] value = pair["Value"] if key in result: raise ValueError("Duplicate key {!r}".format(key)) result[key] = value return result Example: >>> to_dict([{"Key": "foo", "Value": "bar"}, {"Key": "one", "Value": "two"}]) {'foo': 'bar', 'one': 'two'} Now you can convert your data: blist = [to_dict(pairs) for pairs in alist] Then the rest of the code becomes straight-forward: # linear lookup, you have to go through the whole list # to find the matching items for b in blist: if b["Resource_group_id"] == '20179204-181622543367489': print b["Name"] print b["Billing"] If you are planning to do more than a few lookups and the lookup is always by resource group ID you can use a dict as the outer data structure, too: from collections import defaultdict # map ressource-group-ID to list of matching dicts bdict = defaultdict(list) for pairs in alist: d = to_dict(pairs) bdict[d["Resource_group_id"]].append(d) # constant-time lookup of a list containing all matching items for b in bdict["20179204-181622543367489"]: print b["Name"] print b["Billing"] From rosuav at gmail.com Sun Apr 9 05:05:35 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 9 Apr 2017 19:05:35 +1000 Subject: Python and the need for speed In-Reply-To: <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 9, 2017 at 5:39 PM, Steven D'Aprano wrote: > On Sun, 09 Apr 2017 13:57:28 +1000, Chris Angelico wrote: >>>From that page: >> >>> Other candidates for banishment from TurboPython include eval and exec. >> >> Bye bye namedtuple. > > All that would mean is that the implementation of namedtuple would have > to change. It would probably require some sort of support from the > compiler, but that's okay, the compiler can do (nearly) anything. > > Something as important and useful as namedtuple would not be dropped from > this hypothetical TurboPython. It would just shift the implementation > from pure-Python to something else. > > exec() is actually only needed for a *tiny* bit of namedtuple. The > original implementation by Raymond Hettinger takes the easy way out by > using exec on the entire class definition, but it is trivially easy to > restrict that to just the class __new__ method: > > https://code.activestate.com/recipes/578918-yet-another-namedtuple > > > but even that could be avoided with a minimal amount of help from the > compiler. When people talk about making a restricted optimizable subset of Python, the implication (if not the explicit declaration) is that it's done strictly by removing, not by rewriting. A couple more quotes from the article: > It should be possible to define a subset of the Python language, > uninspiredly dubbed ?TurboPython?, that excludes those features > that stand in the way of high-performance JIT execution (or > compilation). Not using some of these features coincides with > good design practices, so it doesn?t necessarily have to be all bad. ... > Since TurboPython is a subset of Python, it will also run on Python > interpreters, albeit slower. Both of these imply that the standard library of TurboPython is *exactly* the standard library of CPython, minus the bits that aren't supported. We just cut a few of those nasty dynamic features out of the language, and voila! it becomes faster. (Or in this case, JITable.) There's nothing suggested here about reimplementing existing features in a different way, with the consequent possibility of having slightly different behaviour - a Python script is guaranteed to have the same semantics on TurboPython as on CPython. This is the kind of description used by Asm.js (http://asmjs.org), defined as a strict subset of JavaScript that can be implemented very efficiently, but with an absolute guarantee that the semantics will be identical. >> And compile() is going to have to go, > > Indeed. > > >> since you >> could implement eval/exec by creating a new function: >> >>>>> runme = r""" >> print("Hello, world!") >> import sys sys.stdout.write("I can import modules.\n") >> """ >>>>> type(lambda: 1)(compile("def f():" + runme, "exec", >>>>> "exec").co_consts[0], globals())() >> Hello, world! >> I can import modules. >> >> So if compile() goes, you also lose ast.parse, > > Probably. The only way to *not* lose ast.parse() is to completely reimplement it or compile(), which is not a good idea IMO (unless you can somehow dump a pure-Python compile() out of an existing source), and which is not at all implied to be part of the proposal. >> which means you lose introspection tools, > > *Some* introspection tools. Python has many that don't rely on compile or > ast.parse. Yes, that's what I meant - that there will be introspection tools that you lose. Sorry for the unclear language. Obviously there's a lot of introspection that's based on pre-existing features, like the attributes on functions and code objects. >> plus you lose literal_eval and friends. > > I don't know what "friends" you are referring to, but again, if > literal_eval is important, the compiler can support it. If you can > support an entire Python interpreter and compiler in the form of > compile(), then you can support more restricted subset of the language. > Writing a parser to evaluate strings, integers, and a few other data > types is not exactly brain surgery. Other tools built on top of literal_eval. Though I had the feeling there were more of them than a 'git grep' has shown up - it's actually only used in a couple of places in the stdlib. My bad. But again, you certainly COULD reimplement literal_eval, but then you have to keep your implementation accurate and up-to-date, else you risk bugs creeping in. It's a non-trivial task to rewrite these kinds of things and maintain parallel versions; by calling on compile(), the current implementation *for free* is kept up-to-date with changes in CPython's grammar. It wouldn't have needed any changes when the u"..." prefix was re-added to Python 3.3, for instance, because the AST didn't change. >> I'm also >> not sure whether the import machinery would have to be rewritten, but a >> quick 'git grep' suggests that it would. Removing eval and exec is not >> as simple as removing them from the standard library. > > Well of course not, but removing eval and exec is only a necessary, not > sufficient, condition, for enabling a huge bunch of compiler optimizations > and speeding up Python. > > This "TurboPython" would require a completely new implementation of the > Python interpreter to be fast. It's not as if eval and exec are great > heavy concrete weights chained to the leg of the compiler, and all you > need do is remove the chain and the compiler suddenly becomes thirty > times faster. Right. But my point is that it _also_ has to be a completely new implementation of large slabs of the standard library, too. At some point, it's not "Python minus the bits we can't JIT", but it's "a complete implementation of a Python-like language with a restricted stdlib". RPython has already been mentioned. >> In fact, extreme dynamism is baked deep into the language. You'd have to >> make some fairly sweeping language changes to get any real benefits from >> restricting things. > > Well, maybe. As is pointed out many, many times, 99% of Python code > avoids the sorts of extreme dynamism that keeps things slow. Lots of > people would be satisfied with a language *really close* to Python that > was ten or twenty times faster, even if it meant that you couldn't write > code like this: > > > answer = input("What's your name?") > exec("name = %r" % answer) > print(name) Sure. But would they also be happy that dunder methods for operators have different behaviour? I rather suspect that they'll be a target early on. And mandatory type hints don't help, because type hinting guarantees that something is a valid subclass, but optimization depends on the exact type. rosuav at sikorsky:~/tmp$ cat demo.py def add_two_integers(x: int, y: int): tot = x + y print("I am adding", x, "and", y, "to get", tot) return tot # Simple example add_two_integers(5, 7) # Proof that non-integers are rejected # add_two_integers(5.0, 7.0) # Uncomment to get an error from MyPy # Evil example class Int(int): def __add__(self, other): return int(self) + other - 1 add_two_integers(Int(5), 7) rosuav at sikorsky:~/tmp$ mypy demo.py rosuav at sikorsky:~/tmp$ python3 demo.py I am adding 5 and 7 to get 12 I am adding 5 and 7 to get 11 The only way to optimize this function is to somehow know that you're working with actual integers - which probably means you're doing work that can be handed off to numpy. > Even better would be if the compiler was smart enough to use the > optimized, fast runtime when the dynamic features aren't used, and fall > back on a slower implementation only when needed to support the more > dynamic features. Yes. As long as it can know when the more dynamic features are being used - and that's the hard part. Remember, as soon as you have a single class implemented in Python, it could have a method injected into it without your knowledge. Can you detect that statically, or can you use the versioning of __dict__ to notice that something's been broken? What makes you fall back to the default implementation? The problem is the same thing that gives Python a lot of its beauty: that there's very little difference between built-in types and user-defined types. In CPython, types implemented in C are immutable, but other than that, they're basically the same thing as anything you make, and you can inspect them and stuff: >>> int.__add__(5, 7) 12 In contrast, JavaScript has a fundamental difference between "stuff implemented in JavaScript" and "stuff the interpreter gives you". For example, you can create a constructor function and set its .prototype attribute to be some object, which is broadly like subclassing that object; but you can't do that with a Number (the JS floating-point type). You don't get a subclass of Number that you can then tweak the behaviour of; you get a completely different thing, one that doesn't behave like a Number at all. I'm sure a JS expert could tell me how to make an object that behaves like a Number, but it isn't as simple as Python's way: class MyInt(int): ... Pike, too, manages to outperform Python by a notable factor (usually around 3:1 or better) - and its native integer type is also distinctly different from its object types. You can't say: class MyInt { inherit int; } You can inherit from the equivalent object form Gmp.mpz, for those situations where you want an int-like object, but it's not going to perform as well as the native int does. Personally, I think that would be a far better avenue to go down. I'm not sure it would be possible to retrofit this to Python (for example, there are guarantees about object identity that apply to *all objects*), but making the core immutable types into value-only non-objects wouldn't break a lot of code, and might provide for some significant performance improvements to string manipulation and arithmetic operations. But at some point, it's not really Python any more. ChrisA From saxri89 at gmail.com Sun Apr 9 10:20:15 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Sun, 9 Apr 2017 07:20:15 -0700 (PDT) Subject: auth select chooses in forms.py Message-ID: I have read this code in this question and look nice. but if I have user auth and I want user select only your odjects how to change that code ?for ex chooses your personal upload images. from django.forms.widgets import Select class ProvinceForm(ModelForm): class Meta: CHOICES = Province.objects.all() model = Province fields = ('name',) widgets = { 'name': Select(choices=( (x.id, x.name) for x in CHOICES )), } my model : class MyModel(models.Model): user = models.ForeignKey(User, unique=True) upload = models.ImageField(upload_to='images') From karlfx4 at gmail.com Sun Apr 9 13:53:18 2017 From: karlfx4 at gmail.com (Peter Henry) Date: Sun, 9 Apr 2017 10:53:18 -0700 (PDT) Subject: Swiss Ephemeris Message-ID: <49f767bc-8059-46bb-82b3-718dc8295b53@googlegroups.com> Hi Group I have a package that has been altered to imported in to python, however I tired to get is working but without success I be missing something obvious The Swiss Ephemeris enable planetary coordinate to be imported and used in your program Files access https://pypi.python.org/pypi/pyswisseph Many thanks in advance Peter From bc at freeuk.com Sun Apr 9 14:34:31 2017 From: bc at freeuk.com (bartc) Date: Sun, 9 Apr 2017 19:34:31 +0100 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: On 09/04/2017 04:57, Chris Angelico wrote: > On Sun, Apr 9, 2017 at 10:20 AM, wrote: >> I've an idea that http://www.mos6581.org/python_need_for_speed is a week late for April Fool's but just in case I'm sure that some of you may wish to comment. > In fact, extreme dynamism is baked deep into the language. You'd have > to make some fairly sweeping language changes to get any real benefits > from restricting things. There are better ways to improve performance, > which is why statickification isn't really pursued. I have my own interpreted language which I call 'dynamic', but compared with Python, code in it might as well be set in concrete. The only thing dynamic about it is the types of variables. But, it does work extremely well. So I think the dynamism of Python is over the top. Yes, you can make a highly restricted version for which it is easier to make faster implementations, but it would be a different language that just uses Python syntax. (With considerable problems interfacing to existing dynamic Python code.) > Bye bye namedtuple. I'm not completely sure what namedtuples are but they sound like some sort of record type. Presumably there is some reason why general attributes can't be used. The latter sound inefficient and so do the former if they depend on advanced dynamism to work. Now, my language has records built-in, and they work extremely well, without using any of the dynamic features of Python other than dynamic variables as I said. So such things can be made viable with the proper language support rather than relying on layers of what I consider unnecessarily esoteric features. Get the basics working first. -- bartc From kbrede at gmail.com Sun Apr 9 17:21:47 2017 From: kbrede at gmail.com (Kenton Brede) Date: Sun, 9 Apr 2017 16:21:47 -0500 Subject: Need help with getting Key, Value out of dicts in lists In-Reply-To: References: Message-ID: Thanks for the response Irv. On one level I'm glad to know that someone more knowledgeable than myself sees this data structure as difficult. :) I was thinking it was an easy problem to solve. Unfortunately that is the structure I have to use. The data comes from pulling back tag information on AWS load balancers. So each list within the overall parent list are tags from one load balancer. Each dict pair inside the inner lists, is one tag. To simplify, below is a representation of one load balancer and two tags. The parent list contains multiple inner lists, each for a single load balancer. [ [ { "Value": "20176783-181622543367489", "Key": "Resource_group_id" }, { "Value": "shibboleth-prd-alb", "Key": "Name" } ], ] I have an ugly solution of 'for loops' and 'if statements' that works, which uses a different path to get to the information. I was just hoping to be more direct by matching the 'Value' of 'Key: Resource_group_id' and pull back the 'Value' of 'Key: Name' and other tags as needed. Thanks, Kenton Brede On Sat, Apr 8, 2017 at 11:29 PM, Irv Kalb wrote: > [ Sorry, forgot the important stuff! ] > > What you want to do is tricky because your data structure is difficult to > deal with. My guess is that it has to do with a misconception about how a > Python dictionary works. Yes, it is a series of key/value pairs, but not > the way you have it. It looks like you put together dictionaries where > each dictionary has a 'Value' and a 'Key'. > > Instead, _each_ item in a dictionary is a key value pair. The key is > typically a string, and the value is obviously some value associated with > that key. For example, if you have the ability to rebuild your data a > different way, it looks like it would be better to deal with it something > like this: > > aList = [ > {'Name':'shibboleth-prd', 'Billing':'kmvu', > 'Resource_group_id': '20179204-181622543367489'}, > {'Name':'shibboleth-tst', 'Resource_group_id':'20172857- > 152037106154311'} > ] > > This is a list of dictionaries. However, I'm not sure what you are trying > to do with this data. I'm guessing that you want to match a resource group > id, and if you find it, print the name and the billing info if they exist. > If so, you may want something like this (untested): > > def printInfo(thisGroupID): > for thisDict in aList: # loop through all dictionaries in the list > if thisGroupID == aList['Resource_group_id']: > if 'Name' in thisDict: # if thisDict has a key called 'Name' > print ('Name is', thisDict['Dict']) > if 'Billing' in thisDict: # if thisDict has a key called > 'Billing' > print ('Billing is', thisDict['Billing']) > > Hope this helps, > > Irv > > On Apr 8, 2017, at 9:04 PM, Irv Kalb wrote: > > > > What you want to do is tricky because your data structure is difficult > to deal with. My guess is that it has to do with a misconception about how > a Python dictionary works. Yes, it is a series of key/value pairs, but not > the way you have it. It looks like you put together dictionaries where > each dictionary has a 'Value' and a 'Key'. > > > > Instead, _each_ item in a dictionary is a key value pair. The key is > typically a string, and the value is obviously some value associated with > that key. For example, if you have the ability to rebuild your data a > different way, it looks like it would be better to deal with it something > like this: > > > > aList = [ > > {'Name':'shibboleth-prd', 'Billing':'kmvu', > 'Resource_group_id': '20179204-181622543367489'}, > > {'Name':'shibboleth-tst', 'Resource_group_id':'20172857- > 152037106154311'} > > ] > > > > This is a list of dictionaries. However, I'm not sure what you are > trying to do with this data. I'm guessing that you want to match a > resource group id, and if you find it, print the name and the billing info > if they exist. If so, you may want something like this (untested): > > > > def printInfo(thisGroupID): > > for thisDict in aList: # loop through all dictionaries in the list > > if thisGroupID == aList['Resource_group_id']: > > if 'Name' in thisDict: # if thisDict has a key called 'Name' > > print ('Name is', thisDict['Dict']) > > if 'Billing' in thisDict: # if thisDict has a key called > 'Billing' > > print ('Billing is', thisDict['Billing']) > > > > Hope this helps, > > > > Irv > > > > > > > >> On Apr 8, 2017, at 5:55 PM, Kenton Brede wrote: > >> > >> This is an example of the data I'm working with. The key/value pairs > may > >> come in any order. There are some keys like the 'Resource_group_id' key > and > >> the 'Name' key which will always be present, but other lists may have > >> unique keys. > >> > >> alist = [[{u'Value': 'shibboleth-prd', u'Key': 'Name'}, {u'Value': > 'kvmu', > >> u'Key': 'Billing'}, > >> {u'Value': '20179204-181622543367489', u'Key': > >> 'Resource_group_id'}], > >> [{u'Value': '20172857-152037106154311', u'Key': > >> 'Resource_group_id'}, > >> {u'Value': 'shibboleth-tst', u'Key': 'Name'}]] > >> > >> What I want to do is something along the lines of: > >> > >> for a in alist: > >> if a['Resource_group_id'] == '01234829-2041523815431': > >> print the Value of 'Name' > >> print the Value of 'Billing' > >> > >> I've found I can do the following, to print the value of 'Name' but that > >> only works if the 'Resource_group_id' key is the first key in the list > and > >> the 'Name' key is in the second slot. If each list contained the same > >> keys, I could probably sort the keys and use [num] to pull back values, > but > >> they don't. > >> > >> for a in alist: > >> if a[0]['Key'] == 'Resource_group_id' and a[0]['Value'] == > >> '20172857-152037106154311': > >> print a[1]['Value'] > >> > >> There has to be a way to do this but I've been pounding away at this for > >> hours. Any help appreciated. I'm new to Python and not a programmer, > so > >> go easy on me. :) > >> -- > >> https://mail.python.org/mailman/listinfo/python-list > >> > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From jpolo at mail.usf.edu Sun Apr 9 17:22:25 2017 From: jpolo at mail.usf.edu (john polo) Date: Sun, 9 Apr 2017 16:22:25 -0500 Subject: read in a list in a file to list In-Reply-To: <43baa05f-7cdf-4e58-a62a-1e917fea8219@googlegroups.com> References: <5db12517-4c1a-f180-978f-533a632b8b36@mail.usf.edu> <43baa05f-7cdf-4e58-a62a-1e917fea8219@googlegroups.com> Message-ID: <820a9e29-25b4-baaf-c8cb-ff40b980e6ec@mail.usf.edu> On 4/8/2017 3:21 PM, breamoreboy at gmail.com wrote: > On Saturday, April 8, 2017 at 7:32:52 PM UTC+1, john polo wrote: >> Hi, >> >> I am using Python 3.6 on Windows 7. >> >> I have a file called apefile.txt. apefile.txt's contents are: >> >> apes = "Home sapiens", "Pan troglodytes", "Gorilla gorilla" >> >> I have a script: >> >> apefile = open("apefile.txt") >> apelist = apefile.read() >> for ape in apelist: >> print("one of the apes is " + ape) >> apefile.close() >> >> The output from the script does not print the ape names, instead it >> prints each letter in the file. For example: >> >> one of the apes is a >> one of the apes is p >> one of the apes is e >> >> What should I do instead to get something like >> >> one of the apes is Home sapiens >> one of the apes is Pan troglodytes >> one of the apes is Gorilla gorilla >> >> John > I'll start you off. > > with open("apefile.txt") as apefile: > for line in apefile: > doSomething(line) > > String methods and/or the csv module might be used here in doSomething(line), but I'll leave that to you so that you can learn. If you get stuck please ask again, we don't bite :) > > Kindest regards. > > Mark Lawrence. Mark, Thanks for the reply. I looked back through the methods for strings. I also looked at the csv module, but I couldn't tell which one of those would help. The small .txt file does have commas, but with the weird form of listname = [1] , [2], [3], etc. for a .csv, I don't know how that would be read in a like a .csv. But now that I think about it, datObj2 in my script prints just the list elements, so maybe the 'listname=' part wouldn't affect it... Anyway, after reviewing string methods some more, I came up with this. If I understood your hint, the loop was supposed to somehow break up the long string that came from the apelist file, but it seemed that trying to use the split method in a loop wouldn't work, especially since one of my attempts started a list and then the interpreter said there were no split methods for list. The new attempt gives me a list, now I have to figure out how to deal with unwanted quotation marks and spaces. datFil = open("apelist.txt") datObj = datFil.read() datObj2 = datObj.replace('" ','') #added this comment while writing this email: I guess I could have used 'datObj = datFil.read().replace('" ','')'. Can you make two replacements in the same statement, for example 'datObj=datFil.read().replace('" ','').replace('"','')? datObj2 = datObj2.replace('"','') #this was here to try to get rid of " that didn't have a subsequent space. datObj2 = datObj2.split(',') print(datObj2) for i in datObj2: print("one of the apes is " + i) datFil.close() Output: ['Homo sapiens', ' Pan troglodytes', ' Gorilla gorilla'] one of the apes is Homo sapiens one of the apes is Pan troglodytes one of the apes is Gorilla gorilla Per reply of Rick Johnson, I altered variable names to something generic. Thanks for the prodding from the replies. John From rosuav at gmail.com Sun Apr 9 17:52:56 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 10 Apr 2017 07:52:56 +1000 Subject: read in a list in a file to list In-Reply-To: <820a9e29-25b4-baaf-c8cb-ff40b980e6ec@mail.usf.edu> References: <5db12517-4c1a-f180-978f-533a632b8b36@mail.usf.edu> <43baa05f-7cdf-4e58-a62a-1e917fea8219@googlegroups.com> <820a9e29-25b4-baaf-c8cb-ff40b980e6ec@mail.usf.edu> Message-ID: On Mon, Apr 10, 2017 at 7:22 AM, john polo wrote: > Thanks for the reply. I looked back through the methods for strings. I also > looked at the csv module, but I couldn't tell which one of those would help. > The small .txt file does have commas, but with the weird form of listname = > [1] , [2], [3], etc. for a .csv, I don't know how that would be read in a > like a .csv. But now that I think about it, datObj2 in my script prints just > the list elements, so maybe the 'listname=' part wouldn't affect it... > Hmm, interesting. Perhaps ast.literal_eval will help here? Parse off the bit after the first equals sign and feed it to literal_eval. You'll get back a tuple. ChrisA From greg.ewing at canterbury.ac.nz Sun Apr 9 20:21:07 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 10 Apr 2017 12:21:07 +1200 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: Chris Angelico wrote: >>From that page: > >>Other candidates for banishment from TurboPython include eval and exec. I'm not convinced that removing eval and exec has anything to do with making Python faster. There has to be a compiler somewhere in the system, and making it invokable at run time doesn't necessarily mean code that doesn't use that feature has to run slower. Heck, you can write an exec() function for C if you really want. Run the C compiler in another process, dynamically load the object file and call it. Doing that would be very inefficient, but it wouldn't slow down the rest of your C code. My take on the idea of making Python less dynamic in order to improve speed is that you'll end up with a language that, while it may superficially resemble Python, doesn't really feel like Python. Boo is an example of that. It has a Python-like syntax, but to get any speed advantage you need to add static type delarations, and then it feels more like programming in C# than Python. At that point, you wonder whether you might just be better off writing your program in C# to begin with. That's not to say this kind of approach isn't worth pursuing, but like the JIT attempts mentioned in the article, it has also been tried before, with varying levels of success. -- Greg From python at deborahswanson.net Sun Apr 9 21:52:31 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Sun, 9 Apr 2017 18:52:31 -0700 Subject: Swiss Ephemeris In-Reply-To: <49f767bc-8059-46bb-82b3-718dc8295b53@googlegroups.com> Message-ID: <009c01d2b19d$1e76ce10$27b23dae@sambora> Peter Henry wrote, on Sunday, April 09, 2017 10:53 AM > > I have a package that has been altered to imported in to > python, however I tired to get is working but without success > I be missing something obvious > > The Swiss Ephemeris enable planetary coordinate to be > imported and used in your program > > Files access https://pypi.python.org/pypi/pyswisseph > > Many thanks in advance > > Peter I've also worked on the problem of getting sweph into Python and have mostly struck out so far myself. I found one reliable means to get sweph's planetary data into Python, but it's more or less a cheat. Nonetheless, if you want to see how much good it does you, try the Swiss Ephemeris Test Page at http://www.astro.com/swisseph/swetest.htm. If you can successfully formulate a query useful to your purposes, you can download a csv of results, read it into Python, and work from there. Right now I'm working on converting some Excel spreadsheets and Excel VBA I use into Python and recoding it all, using the CSVs for jumping off points. That works pretty well, except the times from swetest are off a bit and I haven't figured out why. But I'm concentrating on getting all my VBA code ported to Python, and will go back to getting bang on data from sweph after I have my code done. The first thing I tried was to get sweph's C source code into a free IDE, but that whole project went down in flames. You can read bits and pieces of that misadventure at the tail end of the "Python application launcher (for Python code)" thread. I found sweph's C source code at some link off "Programming interface to the Swiss Ephemeris" at http://www.astro.com/swisseph/swephprg.htm (or maybe it was on http://www.astro.com/swisseph/swephinfo_e.htm - I can't easily find it now, but the download link is in one of those two pages somewhere.) Then I tried picking through sweph's C source code, attempting to manually reproduce the logic and the calculations in Python. That was a highly qualified semi-success because the times were still off, but it essentially produces the most basic planetary data. The swetest output CSVs were more complete however, and easy to read the planetary data into Python from, so I'd pretty much abandoned efforts to "translate" the C source code. And now, all my efforts to leverage the C source code. Even if successful it would be a lot more time sunk into working with a language other than Python, which I likely wouldn't have a use for after this project is completed. However, I have seen bits here and there on this list that are at least interesting. Tim Chase mentioned in passing that he encapsulated C source code in a class, which may bear looking into. Lutz Horn also gave a link for building a Python module to add a C language library to Python, which also might be worth checking out: https://docs.python.org/3/extending/index.html (I changed the 2 to a 3 from the link he gave, but you can change it back to 2 if your working in a build of Python 2.) But many thanks for your pypi link to pyswisseph, which I will check out. I can reply to this thread after I give it a shot and tell you what I think of it. But like I said earlier, that won't be until all my Excel VBA code, which jumps off from the sweph bare planetary data, is ported to Python and working. Could be awhile yet. And if pyswisseph doesn't pan out, I'll likely work on refining the two methods I have for producing the planetary data, both of which are only lacking precisely accurate time data in my local time, and both are off by only 5-30 minutes. I easily limped along for years with my Excel spread sheets using the swetest CSVs for input, even though my times then were more than a day off. Good luck! (and this venture is a goodly portion of luck...) Deborah PS. I've been using medical astrology to look ahead at my medical condition for years in advance. And being off by a day or so doesn't matter that much when you're looking at trends over the course of years and decades. I also have a little software widget to look at the planetary data in graphical chart form at any particular second, also based on sweph, which has been quite astoundingly accurate in following the rather complex kaleidoscope of my symptoms during the course of a day. (Though it doesn't do you a bit of good if you forget to look! Which is my entire motivation to get it encoded and available with a few clicks.) And it is quite useful to know in advance what will be happening when, and most importantly when it will stop. Knowledge is power! Caveat. This kind of precision and accuracy is only found in the specific forms of astrology which relate to pure physical phenomena, and most of what you see these days masquerading as astrology is pure hooey, almost entirely invented on a large scale in the Middle Ages and flowered in the Renaissance. By pure physical phenomena, which is the only phenomena that is at least debatably influenced by physical planetary forces, I mean things like the moon's tides, sunspots, plant and animal activity throughout the year, and supremely, the inner workings of the human body, the first wholly Western medicine devised by the ancient Greeks. (The ancient Greek physicians are an excellent fallback if modern medicine is failing you - if you can find enough that remains today of their art.) From rantingrickjohnson at gmail.com Sun Apr 9 22:04:07 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 9 Apr 2017 19:04:07 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> Message-ID: <27652c6d-2cb4-4f0c-9400-6aa2a3f9f855@googlegroups.com> On Sunday, April 9, 2017 at 2:39:18 AM UTC-5, Steven D'Aprano wrote: > On Sun, 09 Apr 2017 13:57:28 +1000, Chris Angelico wrote: > > I don't know anyone who has ever said "this interpreter is > too fast, can you make it run slower?" LOL! > [...] > > Well, maybe. As is pointed out many, many times, 99% of > Python code avoids the sorts of extreme dynamism that keeps > things slow. Lots of people would be satisfied with a > language *really close* to Python that was ten or twenty > times faster, even if it meant that you couldn't write code > like this: > > > answer = input("What's your name?") > exec("name = %r" % answer) > print(name) Yeah, but then we'd be discriminating against Chris. Between Python, Pike, Ook and MUDs, that pretty much defines the extent of Chris' life. > Even better would be if the compiler was smart enough to > use the optimized, fast runtime when the dynamic features > aren't used, and fall back on a slower implementation only > when needed to support the more dynamic features. Hmm, a "dynamic compiler" -- interesting! From rantingrickjohnson at gmail.com Sun Apr 9 22:23:04 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 9 Apr 2017 19:23:04 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sunday, April 9, 2017 at 4:05:57 AM UTC-5, Chris Angelico wrote: > On Sun, Apr 9, 2017 at 5:39 PM, Steven D'Aprano wrote: > > Even better would be if the compiler was smart enough to > > use the optimized, fast runtime when the dynamic features > > aren't used, and fall back on a slower implementation only > > when needed to support the more dynamic features. > > Yes. As long as it can know when the more dynamic features > are being used - and that's the hard part. Remember, as > soon as you have a single class implemented in Python, it > could have a method injected into it without your > knowledge. Can you detect that statically, or can you use > the versioning of __dict__ to notice that something's been > broken? What makes you fall back to the default > implementation? And all that sleuthing is slow as hell! The simple solution is to use a declaration (aka: "strict" in JS) instead. The programmer should be intelligent enough to know whether the code is written in an "optimized manner", or not. > The problem is the same thing that gives Python a lot of > its beauty: that there's very little difference between > built-in types and user-defined types. In CPython, types > implemented in C are immutable, but other than that, > they're basically the same thing as anything you make, and > you can inspect them and stuff: > > >>> int.__add__(5, 7) > 12 Who the hell wants to call dunder methods? Self-flagellate much? > Personally, I think that would be a far better avenue to go > down. I'm not sure it would be possible to retrofit this to > Python (for example, there are guarantees about object > identity that apply to *all objects*), but making the core > immutable types into value-only non-objects wouldn't break > a lot of code, and might provide for some significant > performance improvements to string manipulation and > arithmetic operations. But at some point, it's not really > Python any more. Well, go tell that to the type-hints shills! From rosuav at gmail.com Sun Apr 9 22:23:07 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 10 Apr 2017 12:23:07 +1000 Subject: Python and the need for speed In-Reply-To: <27652c6d-2cb4-4f0c-9400-6aa2a3f9f855@googlegroups.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <27652c6d-2cb4-4f0c-9400-6aa2a3f9f855@googlegroups.com> Message-ID: On Mon, Apr 10, 2017 at 12:04 PM, Rick Johnson wrote: >> Well, maybe. As is pointed out many, many times, 99% of >> Python code avoids the sorts of extreme dynamism that keeps >> things slow. Lots of people would be satisfied with a >> language *really close* to Python that was ten or twenty >> times faster, even if it meant that you couldn't write code >> like this: >> >> >> answer = input("What's your name?") >> exec("name = %r" % answer) >> print(name) > > Yeah, but then we'd be discriminating against Chris. Between > Python, Pike, Ook and MUDs, that pretty much defines the > extent of Chris' life. Okay, I have a pretty thick skin, but this is getting a bit obnoxious. Can you PLEASE post something that isn't just insulting me? Thanks. ChrisA From rantingrickjohnson at gmail.com Sun Apr 9 22:40:55 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 9 Apr 2017 19:40:55 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: <42aabf19-6054-4da4-8d7d-ea4802d2d3be@googlegroups.com> On Sunday, April 9, 2017 at 1:34:39 PM UTC-5, bartc wrote: > On 09/04/2017 04:57, Chris Angelico wrote: > > On Sun, Apr 9, 2017 at 10:20 AM, wrote: > > > I've an idea that > > > http://www.mos6581.org/python_need_for_speed is a week > > > late for April Fool's but just in case I'm sure that some > > > of you may wish to comment. > > > In fact, extreme dynamism is baked deep into the language. > > You'd have to make some fairly sweeping language changes > > to get any real benefits from restricting things. There > > are better ways to improve performance, which is why > > statickification isn't really pursued. > > I have my own interpreted language which I call 'dynamic', > but compared with Python, code in it might as well be set > in concrete. Is this a personal toy, or something that you can share a link to? > > Bye bye namedtuple. > > I'm not completely sure what namedtuples are but they sound > like some sort of record type. Presumably there is some > reason why general attributes can't be used. The latter > sound inefficient and so do the former if they depend on > advanced dynamism to work. Now, my language has records > built-in, and they work extremely well, without using any > of the dynamic features of Python other than dynamic > variables as I said. So such things can be made viable > with the proper language support rather than relying on > layers of what I consider unnecessarily esoteric features. > Get the basics working first. For all the hype about GvR's "supposed" time machine, we can see that Python has suffered some major design flaws. And since Python3000, feature creep has been churning into overdrive. And not that all these features are bad, but like you say, many of them seem to working around design faults rather than repairing them. I mean, fiddlesticks[1], we've already broken backwards compatibility in a *HUGE* way, so why not just go back and fix these inherent flaws once and for all, huh? And it's not like Python can wear the white dress again -- for one thing, she's put on far too many pounds since then, and for the other, well kids, you just can't un-pop a cherry! [1] I _really_ wanted to use a more powerful word there. From rantingrickjohnson at gmail.com Sun Apr 9 23:00:22 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 9 Apr 2017 20:00:22 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: <8c446c0f-6e74-4aab-8986-066724d5c731@googlegroups.com> On Sunday, April 9, 2017 at 7:21:21 PM UTC-5, Gregory Ewing wrote: > My take on the idea of making Python less dynamic in order > to improve speed is that you'll end up with a language > that, while it may superficially resemble Python, doesn't > really feel like Python. Boo is an example of that. It has > a Python-like syntax, but to get any speed advantage you > need to add static type delarations, and then it feels more > like programming in C# than Python. At that point, you > wonder whether you might just be better off writing your > program in C# to begin with. Which is exactly why i keep warning about how dangerous these type-hints are. If these dirty little type-hint syntaxes start propagating in the wild, soon, we'll all be writing code that _looks_ like C, but executes like _python_. At that point, what would be the advantage of writing Python code? I don't write Python code because i like how slow it executes, no, i write Python code because (first and foremost) i like how clean the syntax is; because i like the flexibility of interpreted languages; because i enjoy rapid development; because i like introspection; because i like batteries included. These are the fundamental attributes that make Python so special. Sure, there are a few other high level interpreted languages out there (Ruby springs to mind) but none of them are as enjoyable (to me, and many others here) as Python. Even with all it's warts, this lanague has (at least historically), been very special to me. I beginning to think that the gaining interest in creating derived python languages is a direct result of the type- hints fiasco. But the community fissure began when Py3000 was released. Too many voices in this community are being ignored. From rantingrickjohnson at gmail.com Sun Apr 9 23:19:15 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 9 Apr 2017 20:19:15 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: On Saturday, April 8, 2017 at 7:20:35 PM UTC-5, bream... at gmail.com wrote: > I've an idea that > http://www.mos6581.org/python_need_for_speed is a week late > for April Fool's but just in case I'm sure that some of you > may wish to comment. Might be a bit too late to dub this "April fools", but never too late to dub it "April fool's gold". Mark, you and everyone else here needs to confront the _real_ issue. Obviously there is a huge sub-culture within the Python community that is totally pissed about (1) the silly backwards compatable breaks of python3000, and (2) this type-hints nightmare. And while we could have overlooked python3000 (eventually), this type-hints thing is undermining the very fundamantal nature of Python. Face it Mark, by intertaining these "python forks" you (and others) are acting out in a passive agressive manner because your voices are being ignored by the Python-dev royalty. The true enemy here is not Python's slow execution speed, no, it is type- hints. Therefore, we must join together and stop this type- hints mess before it propagates in the wild and destroys this language. I can assure you, there has never been a feature more threating to the survival of this language than type-hints. Period. From Irv at furrypants.com Sun Apr 9 23:58:44 2017 From: Irv at furrypants.com (Irv Kalb) Date: Sun, 9 Apr 2017 20:58:44 -0700 Subject: Need help with getting Key, Value out of dicts in lists In-Reply-To: References: Message-ID: <889F8A73-CE3E-487F-A0A5-05CCE1E81546@furrypants.com> OK, I did't know if you were able to re-organize the data. I know nothing about AWS load balancers, but it's unfortunate that the data is laid out in a way that makes dealing with it difficult. But it sounds like you have worked it out. Best of luck. Irv > On Apr 9, 2017, at 2:21 PM, Kenton Brede wrote: > > Thanks for the response Irv. On one level I'm glad to know that someone > more knowledgeable than myself sees this data structure as difficult. :) I > was thinking it was an easy problem to solve. Unfortunately that is the > structure I have to use. > > The data comes from pulling back tag information on AWS load balancers. So > each list within the overall parent list are tags from one load balancer. > Each dict pair inside the inner lists, is one tag. To simplify, below is a > representation of one load balancer and two tags. The parent list contains > multiple inner lists, each for a single load balancer. > > [ > [ > { > "Value": "20176783-181622543367489", > "Key": "Resource_group_id" > }, > { > "Value": "shibboleth-prd-alb", > "Key": "Name" > } > ], > ] > > I have an ugly solution of 'for loops' and 'if statements' that works, > which uses a different path to get to the information. I was just hoping > to be more direct by matching the 'Value' of 'Key: Resource_group_id' and > pull back the 'Value' of 'Key: Name' and other tags as needed. > > Thanks, > > Kenton Brede > > > > > > On Sat, Apr 8, 2017 at 11:29 PM, Irv Kalb wrote: > >> [ Sorry, forgot the important stuff! ] >> >> What you want to do is tricky because your data structure is difficult to >> deal with. My guess is that it has to do with a misconception about how a >> Python dictionary works. Yes, it is a series of key/value pairs, but not >> the way you have it. It looks like you put together dictionaries where >> each dictionary has a 'Value' and a 'Key'. >> >> Instead, _each_ item in a dictionary is a key value pair. The key is >> typically a string, and the value is obviously some value associated with >> that key. For example, if you have the ability to rebuild your data a >> different way, it looks like it would be better to deal with it something >> like this: >> >> aList = [ >> {'Name':'shibboleth-prd', 'Billing':'kmvu', >> 'Resource_group_id': '20179204-181622543367489'}, >> {'Name':'shibboleth-tst', 'Resource_group_id':'20172857- >> 152037106154311'} >> ] >> >> This is a list of dictionaries. However, I'm not sure what you are trying >> to do with this data. I'm guessing that you want to match a resource group >> id, and if you find it, print the name and the billing info if they exist. >> If so, you may want something like this (untested): >> >> def printInfo(thisGroupID): >> for thisDict in aList: # loop through all dictionaries in the list >> if thisGroupID == aList['Resource_group_id']: >> if 'Name' in thisDict: # if thisDict has a key called 'Name' >> print ('Name is', thisDict['Dict']) >> if 'Billing' in thisDict: # if thisDict has a key called >> 'Billing' >> print ('Billing is', thisDict['Billing']) >> >> Hope this helps, >> >> Irv >>> On Apr 8, 2017, at 9:04 PM, Irv Kalb wrote: >>> >>> What you want to do is tricky because your data structure is difficult >> to deal with. My guess is that it has to do with a misconception about how >> a Python dictionary works. Yes, it is a series of key/value pairs, but not >> the way you have it. It looks like you put together dictionaries where >> each dictionary has a 'Value' and a 'Key'. >>> >>> Instead, _each_ item in a dictionary is a key value pair. The key is >> typically a string, and the value is obviously some value associated with >> that key. For example, if you have the ability to rebuild your data a >> different way, it looks like it would be better to deal with it something >> like this: >>> >>> aList = [ >>> {'Name':'shibboleth-prd', 'Billing':'kmvu', >> 'Resource_group_id': '20179204-181622543367489'}, >>> {'Name':'shibboleth-tst', 'Resource_group_id':'20172857- >> 152037106154311'} >>> ] >>> >>> This is a list of dictionaries. However, I'm not sure what you are >> trying to do with this data. I'm guessing that you want to match a >> resource group id, and if you find it, print the name and the billing info >> if they exist. If so, you may want something like this (untested): >>> >>> def printInfo(thisGroupID): >>> for thisDict in aList: # loop through all dictionaries in the list >>> if thisGroupID == aList['Resource_group_id']: >>> if 'Name' in thisDict: # if thisDict has a key called 'Name' >>> print ('Name is', thisDict['Dict']) >>> if 'Billing' in thisDict: # if thisDict has a key called >> 'Billing' >>> print ('Billing is', thisDict['Billing']) >>> >>> Hope this helps, >>> >>> Irv >>> >>> >>> >>>> On Apr 8, 2017, at 5:55 PM, Kenton Brede wrote: >>>> >>>> This is an example of the data I'm working with. The key/value pairs >> may >>>> come in any order. There are some keys like the 'Resource_group_id' key >> and >>>> the 'Name' key which will always be present, but other lists may have >>>> unique keys. >>>> >>>> alist = [[{u'Value': 'shibboleth-prd', u'Key': 'Name'}, {u'Value': >> 'kvmu', >>>> u'Key': 'Billing'}, >>>> {u'Value': '20179204-181622543367489', u'Key': >>>> 'Resource_group_id'}], >>>> [{u'Value': '20172857-152037106154311', u'Key': >>>> 'Resource_group_id'}, >>>> {u'Value': 'shibboleth-tst', u'Key': 'Name'}]] >>>> >>>> What I want to do is something along the lines of: >>>> >>>> for a in alist: >>>> if a['Resource_group_id'] == '01234829-2041523815431': >>>> print the Value of 'Name' >>>> print the Value of 'Billing' >>>> >>>> I've found I can do the following, to print the value of 'Name' but that >>>> only works if the 'Resource_group_id' key is the first key in the list >> and >>>> the 'Name' key is in the second slot. If each list contained the same >>>> keys, I could probably sort the keys and use [num] to pull back values, >> but >>>> they don't. >>>> >>>> for a in alist: >>>> if a[0]['Key'] == 'Resource_group_id' and a[0]['Value'] == >>>> '20172857-152037106154311': >>>> print a[1]['Value'] >>>> >>>> There has to be a way to do this but I've been pounding away at this for >>>> hours. Any help appreciated. I'm new to Python and not a programmer, >> so >>>> go easy on me. :) >>>> -- >>>> https://mail.python.org/mailman/listinfo/python-list >>>> >>> >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- > https://mail.python.org/mailman/listinfo/python-list > From rantingrickjohnson at gmail.com Mon Apr 10 00:00:11 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 9 Apr 2017 21:00:11 -0700 (PDT) Subject: Swiss Ephemeris In-Reply-To: References: <49f767bc-8059-46bb-82b3-718dc8295b53@googlegroups.com> <009c01d2b19d$1e76ce10$27b23dae@sambora> Message-ID: <1710f867-da07-4c52-9ff5-7b349dd8e485@googlegroups.com> On Sunday, April 9, 2017 at 8:52:44 PM UTC-5, Deborah Swanson wrote: > PS. I've been using medical astrology to look ahead at my > medical condition for years in advance. And being off by a > day or so doesn't matter that much when you're looking at > trends over the course of years and decades. I also have a > little software widget to look at the planetary data in > graphical chart form at any particular second, also based > on sweph, which has been quite astoundingly accurate in > following the rather complex kaleidoscope of my symptoms > during the course of a day. (Though it doesn't do you a bit > of good if you forget to look! Which is my entire > motivation to get it encoded and available with a few > clicks.) And it is quite useful to know in advance what > will be happening when, and most importantly when it will > stop. Knowledge is power! It's simply amazing what technology can do these days. And with medical diagnosis now just a few clicks away, someone really should tell those medical students to stop wasting time and money at university. > Caveat. This kind of precision and accuracy is only found > in the specific forms of astrology which relate to pure > physical phenomena, and most of what you see these days > masquerading as astrology is pure hooey, almost entirely > invented on a large scale in the Middle Ages and flowered > in the Renaissance. Whadda coinicidence, as did alchemy! > By pure physical phenomena, which is the only phenomena > that is at least debatably influenced by physical planetary > forces, I mean things like the moon's tides, sunspots, > plant and animal activity throughout the year, and > supremely, the inner workings of the human body, the first > wholly Western medicine devised by the ancient Greeks. (The > ancient Greek physicians are an excellent fallback if > modern medicine is failing you - if you can find enough > that remains today of their art.) Yeah, just uh, be sure to avoid te hemlock, mmmkay? ;-) From python at deborahswanson.net Mon Apr 10 01:29:59 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Sun, 9 Apr 2017 22:29:59 -0700 Subject: Swiss Ephemeris In-Reply-To: <1710f867-da07-4c52-9ff5-7b349dd8e485@googlegroups.com> Message-ID: <000001d2b1bb$7f8e7950$27b23dae@sambora> Fully recognizing that most of what you wrote was tongue-in-cheek, I just want to say that regardless of the wonders of modern medicine, it's a pity they learn so little about successful medicines other than their own. In other academic scientific disciplines such as physics and chemistry it's not uncommon to see history of science courses in the curriculum. But not in medicine. I learned what I know about ancient Greek science from a university physics professor, though I doubt he would ever have guessed that one of his students would someday breathe new life into that ancient science by attempting to ressurrect it. The great ancients were no less endowed with intelligence than we are, they simply directed it to different ends. Rick Johnson wrote, on Sunday, April 09, 2017 9:00 PM > > On Sunday, April 9, 2017 at 8:52:44 PM UTC-5, Deborah Swanson wrote: > > PS. I've been using medical astrology to look ahead at my medical > > condition for years in advance. And being off by a day or > so doesn't > > matter that much when you're looking at trends over the course of > > years and decades. I also have a little software widget to > look at the > > planetary data in graphical chart form at any particular > second, also > > based on sweph, which has been quite astoundingly accurate in > > following the rather complex kaleidoscope of my symptoms > > during the course of a day. (Though it doesn't do you a bit > > of good if you forget to look! Which is my entire > > motivation to get it encoded and available with a few > > clicks.) And it is quite useful to know in advance what > > will be happening when, and most importantly when it will > > stop. Knowledge is power! > > It's simply amazing what technology can do these days. And > with medical diagnosis now just a few clicks away, someone > really should tell those medical students to stop wasting > time and money at university. > > > Caveat. This kind of precision and accuracy is only found > > in the specific forms of astrology which relate to pure physical > > phenomena, and most of what you see these days masquerading as > > astrology is pure hooey, almost entirely invented on a > large scale in > > the Middle Ages and flowered in the Renaissance. > > Whadda coinicidence, as did alchemy! > > > By pure physical phenomena, which is the only phenomena > > that is at least debatably influenced by physical planetary > forces, I > > mean things like the moon's tides, sunspots, plant and > animal activity > > throughout the year, and supremely, the inner workings of the human > > body, the first wholly Western medicine devised by the > ancient Greeks. > > (The ancient Greek physicians are an excellent fallback if > > modern medicine is failing you - if you can find enough > > that remains today of their art.) > > Yeah, just uh, be sure to avoid te hemlock, mmmkay? ;-) > > -- > https://mail.python.org/mailman/listinfo/python-list > From prathamesh.nimkar at gmail.com Mon Apr 10 04:30:00 2017 From: prathamesh.nimkar at gmail.com (Prathamesh) Date: Mon, 10 Apr 2017 01:30:00 -0700 (PDT) Subject: Improve Python + Influxdb import performance In-Reply-To: <634caa93-f512-43db-9084-c4fb361e9366@googlegroups.com> References: <104d49b4-da8c-4b23-a520-3042c9d91a3d@googlegroups.com> <634caa93-f512-43db-9084-c4fb361e9366@googlegroups.com> Message-ID: <7f5716ec-710a-43ca-8049-e40bd6754540@googlegroups.com> Hi I've installed Jython 2.7 and was able to get weblogic running as a Jython 2.7 module following https://technology.amis.nl/2015/10/04/how-to-use-wlst-as-a-jython-2-7-module/ I got the requests module 2.7 installed as well But am facing an issue when invoking it related to SSL certificates and to stop those errors I think you need utillib2/utillib3 and that has dependencies one of which is cryptography - which is a real pain to install Any pointers on this or easier way to install this? I'm running Windows 2008R2 Also my pip install doesn't work I get geteid error Please let me know Thanks P On Tuesday, April 4, 2017 at 6:51:28 PM UTC+5:30, Prathamesh wrote: > Hi Inada > > Thank you for your response > Weblogic works on Jython 2.2.1 > and I think the Python requests module requires >= python 2.6 > > Please correct me if I'm wrong > or if there is another way to get this to work > > Thanks > P > > On Monday, April 3, 2017 at 9:52:38 PM UTC+5:30, INADA Naoki wrote: > > You can reuse connection, instead of creating for each request. (HTTP > > keep-alive). > > > > On Tue, Apr 4, 2017 at 1:11 AM, Prathamesh wrote: > > > Hello World > > > > > > The following script is an extract from > > > > > > https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py > > > > > > <> > > > > > > import calendar, time > > > import sys > > > import getopt > > > > > > print '---------------------------------------' > > > > > > # Check the arguments to this script are as expected. > > > # argv[0] is script name. > > > argLen = len(sys.argv) > > > if argLen -1 < 2: > > > print "ERROR: got ", argLen -1, " args, must be at least two." > > > print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py [] [] [] [] [targetDB influx db>' > > > exit() > > > > > > outputFormat='CSV' > > > url='t3://localhost:7001' > > > targetHost='localhost' > > > targetDB='obi' > > > targetPort='8086' > > > > > > try: > > > wls_user = sys.argv[1] > > > wls_pw = sys.argv[2] > > > url = sys.argv[3] > > > outputFormat=sys.argv[4] > > > targetHost=sys.argv[5] > > > targetPort=sys.argv[6] > > > targetDB=sys.argv[7] > > > except: > > > print '' > > > > > > print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB > > > > > > now_epoch = calendar.timegm(time.gmtime())*1000 > > > > > > if outputFormat=='InfluxDB': > > > import httplib > > > influx_msgs='' > > > > > > connect(wls_user,wls_pw,url) > > > results = displayMetricTables('Oracle_BI*','dms_cProcessInfo') > > > for table in results: > > > tableName = table.get('Table') > > > rows = table.get('Rows') > > > rowCollection = rows.values() > > > iter = rowCollection.iterator() > > > while iter.hasNext(): > > > row = iter.next() > > > rowType = row.getCompositeType() > > > keys = rowType.keySet() > > > keyIter = keys.iterator() > > > inst_name= row.get('Name').replace(' ','-') > > > try: > > > server= row.get('Servername').replace(' ','-').replace('/','_') > > > except: > > > try: > > > server= row.get('ServerName').replace(' ','-').replace('/','_') > > > except: > > > server='unknown' > > > try: > > > host= row.get('Host').replace(' ','-') > > > except: > > > host='' > > > while keyIter.hasNext(): > > > columnName = keyIter.next() > > > value = row.get(columnName ) > > > if columnName.find('.value')>0: > > > metric_name=columnName.replace('.value','') > > > if value is not None: > > > if value != 0: > > > if outputFormat=='InfluxDB': > > > influx_msg= ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % (metric_name,server,host,tableName,inst_name, value,now_epoch*1000000) > > > influx_msgs+='\n%s' % influx_msg > > > conn = httplib.HTTPConnection('%s:%s' % (targetHost,targetPort)) > > > ## TODO pretty sure should be urlencoding this ... > > > a=conn.request("POST", ("/write?db=%s" % targetDB), influx_msg) > > > r=conn.getresponse() > > > > > > <> > > > > > > It currently takes about 3 minutes to execute completely and I was thinking of a way to make it run faster > > > > > > Data alignment (Influx line protocol) & data loading - done together takes up most of the time > > > > > > Influxdb is currently loading data at around 3 points/second > > > > > > Any way to align the data separately, store it and load it as a batch? > > > > > > I feel that would help improve performance > > > > > > Please let me know if you have any pointers > > > I can send the data sheet if required > > > > > > Thanks P > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > On Monday, April 3, 2017 at 9:52:38 PM UTC+5:30, INADA Naoki wrote: > > You can reuse connection, instead of creating for each request. (HTTP > > keep-alive). > > > > On Tue, Apr 4, 2017 at 1:11 AM, Prathamesh wrote: > > > Hello World > > > > > > The following script is an extract from > > > > > > https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py > > > > > > <> > > > > > > import calendar, time > > > import sys > > > import getopt > > > > > > print '---------------------------------------' > > > > > > # Check the arguments to this script are as expected. > > > # argv[0] is script name. > > > argLen = len(sys.argv) > > > if argLen -1 < 2: > > > print "ERROR: got ", argLen -1, " args, must be at least two." > > > print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py [] [] [] [] [targetDB influx db>' > > > exit() > > > > > > outputFormat='CSV' > > > url='t3://localhost:7001' > > > targetHost='localhost' > > > targetDB='obi' > > > targetPort='8086' > > > > > > try: > > > wls_user = sys.argv[1] > > > wls_pw = sys.argv[2] > > > url = sys.argv[3] > > > outputFormat=sys.argv[4] > > > targetHost=sys.argv[5] > > > targetPort=sys.argv[6] > > > targetDB=sys.argv[7] > > > except: > > > print '' > > > > > > print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB > > > > > > now_epoch = calendar.timegm(time.gmtime())*1000 > > > > > > if outputFormat=='InfluxDB': > > > import httplib > > > influx_msgs='' > > > > > > connect(wls_user,wls_pw,url) > > > results = displayMetricTables('Oracle_BI*','dms_cProcessInfo') > > > for table in results: > > > tableName = table.get('Table') > > > rows = table.get('Rows') > > > rowCollection = rows.values() > > > iter = rowCollection.iterator() > > > while iter.hasNext(): > > > row = iter.next() > > > rowType = row.getCompositeType() > > > keys = rowType.keySet() > > > keyIter = keys.iterator() > > > inst_name= row.get('Name').replace(' ','-') > > > try: > > > server= row.get('Servername').replace(' ','-').replace('/','_') > > > except: > > > try: > > > server= row.get('ServerName').replace(' ','-').replace('/','_') > > > except: > > > server='unknown' > > > try: > > > host= row.get('Host').replace(' ','-') > > > except: > > > host='' > > > while keyIter.hasNext(): > > > columnName = keyIter.next() > > > value = row.get(columnName ) > > > if columnName.find('.value')>0: > > > metric_name=columnName.replace('.value','') > > > if value is not None: > > > if value != 0: > > > if outputFormat=='InfluxDB': > > > influx_msg= ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % (metric_name,server,host,tableName,inst_name, value,now_epoch*1000000) > > > influx_msgs+='\n%s' % influx_msg > > > conn = httplib.HTTPConnection('%s:%s' % (targetHost,targetPort)) > > > ## TODO pretty sure should be urlencoding this ... > > > a=conn.request("POST", ("/write?db=%s" % targetDB), influx_msg) > > > r=conn.getresponse() > > > > > > <> > > > > > > It currently takes about 3 minutes to execute completely and I was thinking of a way to make it run faster > > > > > > Data alignment (Influx line protocol) & data loading - done together takes up most of the time > > > > > > Influxdb is currently loading data at around 3 points/second > > > > > > Any way to align the data separately, store it and load it as a batch? > > > > > > I feel that would help improve performance > > > > > > Please let me know if you have any pointers > > > I can send the data sheet if required > > > > > > Thanks P > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > On Monday, April 3, 2017 at 9:52:38 PM UTC+5:30, INADA Naoki wrote: > > You can reuse connection, instead of creating for each request. (HTTP > > keep-alive). > > > > On Tue, Apr 4, 2017 at 1:11 AM, Prathamesh wrote: > > > Hello World > > > > > > The following script is an extract from > > > > > > https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py > > > > > > <> > > > > > > import calendar, time > > > import sys > > > import getopt > > > > > > print '---------------------------------------' > > > > > > # Check the arguments to this script are as expected. > > > # argv[0] is script name. > > > argLen = len(sys.argv) > > > if argLen -1 < 2: > > > print "ERROR: got ", argLen -1, " args, must be at least two." > > > print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py [] [] [] [] [targetDB influx db>' > > > exit() > > > > > > outputFormat='CSV' > > > url='t3://localhost:7001' > > > targetHost='localhost' > > > targetDB='obi' > > > targetPort='8086' > > > > > > try: > > > wls_user = sys.argv[1] > > > wls_pw = sys.argv[2] > > > url = sys.argv[3] > > > outputFormat=sys.argv[4] > > > targetHost=sys.argv[5] > > > targetPort=sys.argv[6] > > > targetDB=sys.argv[7] > > > except: > > > print '' > > > > > > print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB > > > > > > now_epoch = calendar.timegm(time.gmtime())*1000 > > > > > > if outputFormat=='InfluxDB': > > > import httplib > > > influx_msgs='' > > > > > > connect(wls_user,wls_pw,url) > > > results = displayMetricTables('Oracle_BI*','dms_cProcessInfo') > > > for table in results: > > > tableName = table.get('Table') > > > rows = table.get('Rows') > > > rowCollection = rows.values() > > > iter = rowCollection.iterator() > > > while iter.hasNext(): > > > row = iter.next() > > > rowType = row.getCompositeType() > > > keys = rowType.keySet() > > > keyIter = keys.iterator() > > > inst_name= row.get('Name').replace(' ','-') > > > try: > > > server= row.get('Servername').replace(' ','-').replace('/','_') > > > except: > > > try: > > > server= row.get('ServerName').replace(' ','-').replace('/','_') > > > except: > > > server='unknown' > > > try: > > > host= row.get('Host').replace(' ','-') > > > except: > > > host='' > > > while keyIter.hasNext(): > > > columnName = keyIter.next() > > > value = row.get(columnName ) > > > if columnName.find('.value')>0: > > > metric_name=columnName.replace('.value','') > > > if value is not None: > > > if value != 0: > > > if outputFormat=='InfluxDB': > > > influx_msg= ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % (metric_name,server,host,tableName,inst_name, value,now_epoch*1000000) > > > influx_msgs+='\n%s' % influx_msg > > > conn = httplib.HTTPConnection('%s:%s' % (targetHost,targetPort)) > > > ## TODO pretty sure should be urlencoding this ... > > > a=conn.request("POST", ("/write?db=%s" % targetDB), influx_msg) > > > r=conn.getresponse() > > > > > > <> > > > > > > It currently takes about 3 minutes to execute completely and I was thinking of a way to make it run faster > > > > > > Data alignment (Influx line protocol) & data loading - done together takes up most of the time > > > > > > Influxdb is currently loading data at around 3 points/second > > > > > > Any way to align the data separately, store it and load it as a batch? > > > > > > I feel that would help improve performance > > > > > > Please let me know if you have any pointers > > > I can send the data sheet if required > > > > > > Thanks P > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > On Monday, April 3, 2017 at 9:52:38 PM UTC+5:30, INADA Naoki wrote: > > You can reuse connection, instead of creating for each request. (HTTP > > keep-alive). > > > > On Tue, Apr 4, 2017 at 1:11 AM, Prathamesh wrote: > > > Hello World > > > > > > The following script is an extract from > > > > > > https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py > > > > > > <> > > > > > > import calendar, time > > > import sys > > > import getopt > > > > > > print '---------------------------------------' > > > > > > # Check the arguments to this script are as expected. > > > # argv[0] is script name. > > > argLen = len(sys.argv) > > > if argLen -1 < 2: > > > print "ERROR: got ", argLen -1, " args, must be at least two." > > > print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py [] [] [] [] [targetDB influx db>' > > > exit() > > > > > > outputFormat='CSV' > > > url='t3://localhost:7001' > > > targetHost='localhost' > > > targetDB='obi' > > > targetPort='8086' > > > > > > try: > > > wls_user = sys.argv[1] > > > wls_pw = sys.argv[2] > > > url = sys.argv[3] > > > outputFormat=sys.argv[4] > > > targetHost=sys.argv[5] > > > targetPort=sys.argv[6] > > > targetDB=sys.argv[7] > > > except: > > > print '' > > > > > > print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB > > > > > > now_epoch = calendar.timegm(time.gmtime())*1000 > > > > > > if outputFormat=='InfluxDB': > > > import httplib > > > influx_msgs='' > > > > > > connect(wls_user,wls_pw,url) > > > results = displayMetricTables('Oracle_BI*','dms_cProcessInfo') > > > for table in results: > > > tableName = table.get('Table') > > > rows = table.get('Rows') > > > rowCollection = rows.values() > > > iter = rowCollection.iterator() > > > while iter.hasNext(): > > > row = iter.next() > > > rowType = row.getCompositeType() > > > keys = rowType.keySet() > > > keyIter = keys.iterator() > > > inst_name= row.get('Name').replace(' ','-') > > > try: > > > server= row.get('Servername').replace(' ','-').replace('/','_') > > > except: > > > try: > > > server= row.get('ServerName').replace(' ','-').replace('/','_') > > > except: > > > server='unknown' > > > try: > > > host= row.get('Host').replace(' ','-') > > > except: > > > host='' > > > while keyIter.hasNext(): > > > columnName = keyIter.next() > > > value = row.get(columnName ) > > > if columnName.find('.value')>0: > > > metric_name=columnName.replace('.value','') > > > if value is not None: > > > if value != 0: > > > if outputFormat=='InfluxDB': > > > influx_msg= ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % (metric_name,server,host,tableName,inst_name, value,now_epoch*1000000) > > > influx_msgs+='\n%s' % influx_msg > > > conn = httplib.HTTPConnection('%s:%s' % (targetHost,targetPort)) > > > ## TODO pretty sure should be urlencoding this ... > > > a=conn.request("POST", ("/write?db=%s" % targetDB), influx_msg) > > > r=conn.getresponse() > > > > > > <> > > > > > > It currently takes about 3 minutes to execute completely and I was thinking of a way to make it run faster > > > > > > Data alignment (Influx line protocol) & data loading - done together takes up most of the time > > > > > > Influxdb is currently loading data at around 3 points/second > > > > > > Any way to align the data separately, store it and load it as a batch? > > > > > > I feel that would help improve performance > > > > > > Please let me know if you have any pointers > > > I can send the data sheet if required > > > > > > Thanks P > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > On Monday, April 3, 2017 at 9:52:38 PM UTC+5:30, INADA Naoki wrote: > > You can reuse connection, instead of creating for each request. (HTTP > > keep-alive). > > > > On Tue, Apr 4, 2017 at 1:11 AM, Prathamesh wrote: > > > Hello World > > > > > > The following script is an extract from > > > > > > https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py > > > > > > <> > > > > > > import calendar, time > > > import sys > > > import getopt > > > > > > print '---------------------------------------' > > > > > > # Check the arguments to this script are as expected. > > > # argv[0] is script name. > > > argLen = len(sys.argv) > > > if argLen -1 < 2: > > > print "ERROR: got ", argLen -1, " args, must be at least two." > > > print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py [] [] [] [] [targetDB influx db>' > > > exit() > > > > > > outputFormat='CSV' > > > url='t3://localhost:7001' > > > targetHost='localhost' > > > targetDB='obi' > > > targetPort='8086' > > > > > > try: > > > wls_user = sys.argv[1] > > > wls_pw = sys.argv[2] > > > url = sys.argv[3] > > > outputFormat=sys.argv[4] > > > targetHost=sys.argv[5] > > > targetPort=sys.argv[6] > > > targetDB=sys.argv[7] > > > except: > > > print '' > > > > > > print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB > > > > > > now_epoch = calendar.timegm(time.gmtime())*1000 > > > > > > if outputFormat=='InfluxDB': > > > import httplib > > > influx_msgs='' > > > > > > connect(wls_user,wls_pw,url) > > > results = displayMetricTables('Oracle_BI*','dms_cProcessInfo') > > > for table in results: > > > tableName = table.get('Table') > > > rows = table.get('Rows') > > > rowCollection = rows.values() > > > iter = rowCollection.iterator() > > > while iter.hasNext(): > > > row = iter.next() > > > rowType = row.getCompositeType() > > > keys = rowType.keySet() > > > keyIter = keys.iterator() > > > inst_name= row.get('Name').replace(' ','-') > > > try: > > > server= row.get('Servername').replace(' ','-').replace('/','_') > > > except: > > > try: > > > server= row.get('ServerName').replace(' ','-').replace('/','_') > > > except: > > > server='unknown' > > > try: > > > host= row.get('Host').replace(' ','-') > > > except: > > > host='' > > > while keyIter.hasNext(): > > > columnName = keyIter.next() > > > value = row.get(columnName ) > > > if columnName.find('.value')>0: > > > metric_name=columnName.replace('.value','') > > > if value is not None: > > > if value != 0: > > > if outputFormat=='InfluxDB': > > > influx_msg= ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % (metric_name,server,host,tableName,inst_name, value,now_epoch*1000000) > > > influx_msgs+='\n%s' % influx_msg > > > conn = httplib.HTTPConnection('%s:%s' % (targetHost,targetPort)) > > > ## TODO pretty sure should be urlencoding this ... > > > a=conn.request("POST", ("/write?db=%s" % targetDB), influx_msg) > > > r=conn.getresponse() > > > > > > <> > > > > > > It currently takes about 3 minutes to execute completely and I was thinking of a way to make it run faster > > > > > > Data alignment (Influx line protocol) & data loading - done together takes up most of the time > > > > > > Influxdb is currently loading data at around 3 points/second > > > > > > Any way to align the data separately, store it and load it as a batch? > > > > > > I feel that would help improve performance > > > > > > Please let me know if you have any pointers > > > I can send the data sheet if required > > > > > > Thanks P > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > On Monday, April 3, 2017 at 9:52:38 PM UTC+5:30, INADA Naoki wrote: > > You can reuse connection, instead of creating for each request. (HTTP > > keep-alive). > > > > On Tue, Apr 4, 2017 at 1:11 AM, Prathamesh wrote: > > > Hello World > > > > > > The following script is an extract from > > > > > > https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py > > > > > > <> > > > > > > import calendar, time > > > import sys > > > import getopt > > > > > > print '---------------------------------------' > > > > > > # Check the arguments to this script are as expected. > > > # argv[0] is script name. > > > argLen = len(sys.argv) > > > if argLen -1 < 2: > > > print "ERROR: got ", argLen -1, " args, must be at least two." > > > print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py [] [] [] [] [targetDB influx db>' > > > exit() > > > > > > outputFormat='CSV' > > > url='t3://localhost:7001' > > > targetHost='localhost' > > > targetDB='obi' > > > targetPort='8086' > > > > > > try: > > > wls_user = sys.argv[1] > > > wls_pw = sys.argv[2] > > > url = sys.argv[3] > > > outputFormat=sys.argv[4] > > > targetHost=sys.argv[5] > > > targetPort=sys.argv[6] > > > targetDB=sys.argv[7] > > > except: > > > print '' > > > > > > print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB > > > > > > now_epoch = calendar.timegm(time.gmtime())*1000 > > > > > > if outputFormat=='InfluxDB': > > > import httplib > > > influx_msgs='' > > > > > > connect(wls_user,wls_pw,url) > > > results = displayMetricTables('Oracle_BI*','dms_cProcessInfo') > > > for table in results: > > > tableName = table.get('Table') > > > rows = table.get('Rows') > > > rowCollection = rows.values() > > > iter = rowCollection.iterator() > > > while iter.hasNext(): > > > row = iter.next() > > > rowType = row.getCompositeType() > > > keys = rowType.keySet() > > > keyIter = keys.iterator() > > > inst_name= row.get('Name').replace(' ','-') > > > try: > > > server= row.get('Servername').replace(' ','-').replace('/','_') > > > except: > > > try: > > > server= row.get('ServerName').replace(' ','-').replace('/','_') > > > except: > > > server='unknown' > > > try: > > > host= row.get('Host').replace(' ','-') > > > except: > > > host='' > > > while keyIter.hasNext(): > > > columnName = keyIter.next() > > > value = row.get(columnName ) > > > if columnName.find('.value')>0: > > > metric_name=columnName.replace('.value','') > > > if value is not None: > > > if value != 0: > > > if outputFormat=='InfluxDB': > > > influx_msg= ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % (metric_name,server,host,tableName,inst_name, value,now_epoch*1000000) > > > influx_msgs+='\n%s' % influx_msg > > > conn = httplib.HTTPConnection('%s:%s' % (targetHost,targetPort)) > > > ## TODO pretty sure should be urlencoding this ... > > > a=conn.request("POST", ("/write?db=%s" % targetDB), influx_msg) > > > r=conn.getresponse() > > > > > > <> > > > > > > It currently takes about 3 minutes to execute completely and I was thinking of a way to make it run faster > > > > > > Data alignment (Influx line protocol) & data loading - done together takes up most of the time > > > > > > Influxdb is currently loading data at around 3 points/second > > > > > > Any way to align the data separately, store it and load it as a batch? > > > > > > I feel that would help improve performance > > > > > > Please let me know if you have any pointers > > > I can send the data sheet if required > > > > > > Thanks P > > > -- > > > https://mail.python.org/mailman/listinfo/python-list From bc at freeuk.com Mon Apr 10 05:43:42 2017 From: bc at freeuk.com (bartc) Date: Mon, 10 Apr 2017 10:43:42 +0100 Subject: Python and the need for speed In-Reply-To: <42aabf19-6054-4da4-8d7d-ea4802d2d3be@googlegroups.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <42aabf19-6054-4da4-8d7d-ea4802d2d3be@googlegroups.com> Message-ID: On 10/04/2017 03:40, Rick Johnson wrote: > On Sunday, April 9, 2017 at 1:34:39 PM UTC-5, bartc wrote: >> I have my own interpreted language which I call 'dynamic', >> but compared with Python, code in it might as well be set >> in concrete. > > Is this a personal toy, or something that you can share a > link to? It's a personal thing but not a toy. Some more info here: https://github.com/bartg/langs/tree/master/qlang Click on the 'Q Features' link, this includes a selection of built-in features that have been easily and efficiently implemented (enumerations, records etc) which Python seems to have trouble with. (And it can't have simple enumerations such that cat=1, dog=2, but needs to have every conceivable embellishment. In other words it doesn't know how to keep things simple.) (To actually run this, there still appears to be a file 'pcc.c' at the top level of that github project. This is an old C version of the interpreter (yes, just one file) and it seemed to work when I tried it just now. You need a 32-bit C compiler. I had to remove a binary version (for Windows) when someone said github doesn't allow binaries.) > For all the hype about GvR's "supposed" time machine, we can > see that Python has suffered some major design flaws. And > since Python3000, feature creep has been churning into > overdrive. Yes. I suppose when it gets to a point where there are so many features anyway, adding a few more makes little difference! -- bartc From renting at astron.nl Mon Apr 10 06:50:01 2017 From: renting at astron.nl (Adriaan Renting) Date: Mon, 10 Apr 2017 12:50:01 +0200 Subject: Swiss Ephemeris In-Reply-To: <000001d2b1bb$7f8e7950$27b23dae@sambora> References: <1710f867-da07-4c52-9ff5-7b349dd8e485@googlegroups.com> <000001d2b1bb$7f8e7950$27b23dae@sambora> Message-ID: <58EB7F790200001B00016CA3@smtp1.astron.nl> There are at least two other packages with Python bindings that allow ephimerides calculations. 1) PyEphem http://rhodesmill.org/pyephem/ 2) Pyraphttp://www.astron.nl/casacore/trunk/pyrap/docs/ (This needs a very big casacore c++ library and thus a pain to compile, but can give second level accuracy if you use updated IERS tables). As to the ancient's (Greek/Roman) nature philosophy. We still use some of it today, especially in the fields of mathematics, mechanics and observational astronomy, but their understanding of biology and especially the human body was entirely incorrect. Western/Islamic medicine largely followed Hippocrates for nearly 2000 years (although the ideas are originally from Indian Ayurveda) and some of the methods had some merit, but overall the treatments were often worse than the disease, for example George Washinton was almost certainly killed by his doctors. Only with the application of the scientific method to medicine after the enlightenment have we started to make any real progress. The most important of which is blind trials in which a treatment needs to show to be better than a placebo. One of the most important things that modern medicine has shown is that a placebo can have a real effect and cure people. Some people do get better after you give them a sugar pill or its equivalent. As humans we're also very good at seeing correlation and causation when none might exist. Matt Parker has a very entertaining talk about this here https://www.youtube.com/watch?v=sf5OrthVRPA Cheers, Adriaan Renting P.S. I had an uncle who died of cancer 2 years ago who was a firm believer in all kinds of non-mainstream cures and tried all kinds of alternative cures from accupuncture to yoga to Gc-MAF. In the end the only results I saw were that these people got many 10.000s euros from him and he died very disillusioned and poor as these were not covered by his health insurance. I learned a lot about magazines like "What doctors don't tell you" - which use the images of people in white labcoats to sell you things that doctors don't tell you about because they are known to be ineffective or even bad for you. I understand that a lot of people have a problem with authority and/or look for alternatives if mainstream medicine can't help them. And sometimes the methods seem to work and those are the stories you hear, as the other people end up like my uncle, who's not here any more to tell his story. Don't end up like my uncle. >>> > Fully recognizing that most of what you wrote was tongue-in-cheek, I > just want to say that regardless of the wonders of modern medicine, it's > a pity they learn so little about successful medicines other than their > own. In other academic scientific disciplines such as physics and > chemistry it's not uncommon to see history of science courses in the > curriculum. But not in medicine. I learned what I know about ancient > Greek science from a university physics professor, though I doubt he > would ever have guessed that one of his students would someday breathe > new life into that ancient science by attempting to ressurrect it. The > great ancients were no less endowed with intelligence than we are, they > simply directed it to different ends. > > > Rick Johnson wrote, on Sunday, April 09, 2017 9:00 PM >> >> On Sunday, April 9, 2017 at 8:52:44 PM UTC-5, Deborah Swanson wrote: >> > PS. I've been using medical astrology to look ahead at my medical >> > condition for years in advance. And being off by a day or >> so doesn't >> > matter that much when you're looking at trends over the course of >> > years and decades. I also have a little software widget to >> look at the >> > planetary data in graphical chart form at any particular >> second, also >> > based on sweph, which has been quite astoundingly accurate in >> > following the rather complex kaleidoscope of my symptoms >> > during the course of a day. (Though it doesn't do you a bit >> > of good if you forget to look! Which is my entire >> > motivation to get it encoded and available with a few >> > clicks.) And it is quite useful to know in advance what >> > will be happening when, and most importantly when it will >> > stop. Knowledge is power! >> >> It's simply amazing what technology can do these days. And >> with medical diagnosis now just a few clicks away, someone >> really should tell those medical students to stop wasting >> time and money at university. >> >> > Caveat. This kind of precision and accuracy is only found >> > in the specific forms of astrology which relate to pure physical >> > phenomena, and most of what you see these days masquerading as >> > astrology is pure hooey, almost entirely invented on a >> large scale in >> > the Middle Ages and flowered in the Renaissance. >> >> Whadda coinicidence, as did alchemy! >> >> > By pure physical phenomena, which is the only phenomena >> > that is at least debatably influenced by physical planetary >> forces, I >> > mean things like the moon's tides, sunspots, plant and >> animal activity >> > throughout the year, and supremely, the inner workings of the human >> > body, the first wholly Western medicine devised by the >> ancient Greeks. >> > (The ancient Greek physicians are an excellent fallback if >> > modern medicine is failing you - if you can find enough >> > that remains today of their art.) >> >> Yeah, just uh, be sure to avoid te hemlock, mmmkay? ;-) >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > Adriaan Renting | Email: renting at astron.nl Software Engineer Radio Observatory ASTRON | Phone: +31 521 595 100 (797 direct) P.O. Box 2 | GSM: +31 6 24 25 17 28 NL-7990 AA Dwingeloo | FAX: +31 521 595 101 The Netherlands | Web: http://www.astron.nl/~renting/ From mikhailwas at gmail.com Mon Apr 10 08:25:16 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Mon, 10 Apr 2017 14:25:16 +0200 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: On 10 April 2017 at 02:21, Gregory Ewing wrote: > > .... > > My take on the idea of making Python less dynamic in order > to improve speed is that you'll end up with a language that, > while it may superficially resemble Python, doesn't > really feel like Python. > > Boo is an example of that. It has a Python-like syntax, but > to get any speed advantage you need to add static type > delarations, and then it feels more like programming in > C# than Python. At that point, you wonder whether you might > just be better off writing your program in C# to begin with. > > That's not to say this kind of approach isn't worth pursuing, > but like the JIT attempts mentioned in the article, it has > also been tried before, with varying levels of success. Agree. python is python and I suppose that performance issues has much to do with types and OOP. When I first started with python I thought - no, it is not possible without types, if I'll write something more complicated than hello world, it will all break at some point. But hell, this works and works good. Still I miss some old school features in Python, e.g. "goto" statement would be very useful in some cases. I know it is considered bad style to use goto, but in some cases it is just most natural thing to use. What I am (and probably many people) missing is a good tool for performance middle- and low-level applications. For me it would be a coding tool, sort of minimalist IDE, with simple readable syntax which generates compilable C code. And it would not be necessarily python-like syntax, but I tend to agree that for today python's syntax is most readable. The problem that many are overlooking still is that the possibilities for syntaxes are very limited in pure text-mode presentation. From breamoreboy at gmail.com Mon Apr 10 08:44:59 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Mon, 10 Apr 2017 05:44:59 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: On Monday, April 10, 2017 at 1:25:48 PM UTC+1, Mikhail V wrote: > > Still I miss some old school features in Python, e.g. "goto" statement would > be very useful in some cases. I know it is considered bad style > to use goto, but in some cases it is just most natural thing to use. > http://entrian.com/goto/ https://pypi.python.org/pypi/goto-statement Kindest regards. Mark Lawrence. From davidgshi at yahoo.co.uk Mon Apr 10 09:17:16 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Mon, 10 Apr 2017 13:17:16 +0000 (UTC) Subject: Pound sign problem References: <679200651.679871.1491830236809.ref@mail.yahoo.com> Message-ID: <679200651.679871.1491830236809@mail.yahoo.com> In the data set, pound sign escape appears: u'price_currency': u'\xa3', u'price_formatted': u'\xa3525,000', When using table.to_csv after importing pandas as pd, an error message persists as follows: UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 0: ordinal not in range(128) Can anyone help? Regards. David From exarkun at twistedmatrix.com Mon Apr 10 09:17:36 2017 From: exarkun at twistedmatrix.com (Jean-Paul Calderone) Date: Mon, 10 Apr 2017 09:17:36 -0400 Subject: [ANN] txAWS 0.3.0 Message-ID: Hello all, I'm pleased to announce the release of txAWS 0.3.0. txAWS is a library for interacting with Amazon Web Services (AWS) using Twisted. You can download the release from PyPI (https://pypi.python.org/pypi/txAWS). txAWS development uses GitHub for issues and source control (https://github.com/twisted/txaws). Since the last release, the following enhancements have been made: - Jean-Paul Calderone added basic Route53 support. - Mark Williams add Auth v4, now used by the S3 and Route53 support. - Francisco Souza added support for VPCs to some EC2 APIs. - Drew Smathers added multi-part S3 upload support. - Several people added other S3 client features such as pagination and streaming uploads. - *txaws.testing* now provides S3 and Route53 support. Additionally, the following APIs have been deprecated: - The *client* attribute of *txaws.client.base.BaseQuery* - The *date* attribute of *txaws.s3.client.Query* Thanks to everyone who contributed and to Least Authority Enterprises () for sponsoring my work on this release. Jean-Paul Calderone From ben+python at benfinney.id.au Mon Apr 10 09:43:05 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 10 Apr 2017 23:43:05 +1000 Subject: Pound sign problem References: <679200651.679871.1491830236809.ref@mail.yahoo.com> <679200651.679871.1491830236809@mail.yahoo.com> Message-ID: <851st0cr9y.fsf@benfinney.id.au> David Shi via Python-list writes: > When using table.to_csv after importing pandas as pd I don't know much about that library. What does its documentation say for the ?table.to_csv? function? Can you write a *very short* complete example, that we can run to demonstrate the same behaviour you are seeing? > an error message persists as follows: > UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 0: ordinal not in range(128) This means the function has been told (or is assuming, in the absence of better information) that the input data is in the ?ascii? text encoding. That assumption turns out to be incorrect, for the actual data you have. So that error occurs. You will need to: * Find out exactly what text encoding was used to write the file. Don't guess, because there are many ways to be wrong. * Specify that encoding to the ?table.to_csv? function, or to whatever function opens the file. (This might be the Python built-in ?open? function, but we'd need to see your short example to know.) -- \ ?Most people, I think, don't even know what a rootkit is, so | `\ why should they care about it?? ?Thomas Hesse, Sony BMG, 2006 | _o__) | Ben Finney From __peter__ at web.de Mon Apr 10 09:51:21 2017 From: __peter__ at web.de (Peter Otten) Date: Mon, 10 Apr 2017 15:51:21 +0200 Subject: Pound sign problem References: <679200651.679871.1491830236809.ref@mail.yahoo.com> <679200651.679871.1491830236809@mail.yahoo.com> Message-ID: David Shi via Python-list wrote: > In the data set, pound sign escape appears: > u'price_currency': u'\xa3', u'price_formatted': u'\xa3525,000', > When using table.to_csv after importing pandas as pd, an error message > persists as follows: UnicodeEncodeError: 'ascii' codec can't encode > character u'\xa3' in position 0: ordinal not in range(128) The default encoding in Python 2 is ascii, and the pound sign is not part of that. > Can anyone help? Specify an alternative encoding, preferably UTF-8: >>> import pandas >>> df = pandas.DataFrame([[u"\xa3123"], [u"\xa3321"]], columns=["Price"]) >>> df Price 0 ?123 1 ?321 [2 rows x 1 columns] >>> df.to_csv("tmp.csv", encoding="utf-8") >>> $ cat tmp.csv ,Price 0,?123 1,?321 $ From jorge.conrado at cptec.inpe.br Mon Apr 10 09:53:10 2017 From: jorge.conrado at cptec.inpe.br (jorge.conrado at cptec.inpe.br) Date: Mon, 10 Apr 2017 10:53:10 -0300 Subject: Pillow ImportError: No module named Image Message-ID: <46227e6d0f8fdadcd9e1e841f6d3d2c1@cptec.inpe.br> Hi, I installed the Pillow in my computer. The I did: import Image, ImageMath ImportError: No module named Image Please, what can I do to solve this. Conrado From wrw at mac.com Mon Apr 10 09:53:47 2017 From: wrw at mac.com (William Ray Wing) Date: Mon, 10 Apr 2017 09:53:47 -0400 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: <5E03504C-6C37-4286-B1CC-B1779A8290D3@mac.com> > On Apr 10, 2017, at 8:25 AM, Mikhail V wrote: > > On 10 April 2017 at 02:21, Gregory Ewing wrote: >> >> .... >> >> My take on the idea of making Python less dynamic in order >> to improve speed is that you'll end up with a language that, >> while it may superficially resemble Python, doesn't >> really feel like Python. >> >> Boo is an example of that. It has a Python-like syntax, but >> to get any speed advantage you need to add static type >> delarations, and then it feels more like programming in >> C# than Python. At that point, you wonder whether you might >> just be better off writing your program in C# to begin with. >> >> That's not to say this kind of approach isn't worth pursuing, >> but like the JIT attempts mentioned in the article, it has >> also been tried before, with varying levels of success. > > Agree. python is python and I suppose that performance issues > has much to do with types and OOP. > When I first started with python I thought - no, it is not possible > without types, if I'll write something more complicated than > hello world, it will all break at some point. > But hell, this works and works good. > > Still I miss some old school features in Python, e.g. "goto" statement would > be very useful in some cases. I know it is considered bad style > to use goto, but in some cases it is just most natural thing to use. > > What I am (and probably many people) missing is a good tool for > performance middle- and low-level applications. > For me it would be a coding tool, sort of minimalist IDE, with simple > readable syntax which generates compilable C code. > And it would not be necessarily python-like syntax, > but I tend to agree that for today python's syntax is > most readable. Have you considered Swift, now that it is open source? Bill > > The problem that many are overlooking still is that the > possibilities for syntaxes are very limited in pure text-mode > presentation. > -- > https://mail.python.org/mailman/listinfo/python-list From rgacote at appropriatesolutions.com Mon Apr 10 09:59:14 2017 From: rgacote at appropriatesolutions.com (Ray Cote) Date: Mon, 10 Apr 2017 09:59:14 -0400 Subject: Python 3.6 printing crashing on OS X 10.12.4 In-Reply-To: References: Message-ID: On Wed, Apr 5, 2017 at 3:40 PM, Python wrote: > Le 05/04/2017 ? 20:14, Ray Cote a ?crit : > >> Hello: >> >> Python 3.6 crashing when trying to print from the environment. >> >> $ python >> Python 3.6.1 (default, Mar 22 2017, 15:53:21) >> [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>> print("hello") >>>>> >>>> >> Python(53390,0x7fffdd9e63c0) malloc: *** error for object 0x10dde4110: >> pointer being freed was not allocated >> *** set a breakpoint in malloc_error_break to debug >> Abort trap: 6 >> >> >> Pastebin link to OS X crash report if that?s helpful: >> https://pastebin.com/t1j3nz5L >> >> >> 1: Python installed via ports. >> 2: OS X 10.12.4. >> 3: Python 3.6.1 (though I also had this problem with 3.6.0). >> 4: Have successfully run python 3.5 for months. >> 5: Running under standard terminal program. >> 6: I have py36-readline installed. >> 7: Have tried uninstalling and re-installing Python. >> >> Any thoughts on what I could have wrong? >> >> Regards >> ?Ray >> >> > Mac OS X 10.12.3, Python 3 installed by brew > > mac:~$ uname -r > 16.4.0 > mac:~$ python3 > Python 3.6.0 (default, Mar 4 2017, 12:32:34) > [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> print("hello") > hello > > -- > https://mail.python.org/mailman/listinfo/python-list > Follow up: Never did find out why the macports Python was crashing. Switched over to brew and it is working fine. ?R From jon+usenet at unequivocal.eu Mon Apr 10 10:16:25 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Mon, 10 Apr 2017 14:16:25 -0000 (UTC) Subject: Pillow ImportError: No module named Image References: <46227e6d0f8fdadcd9e1e841f6d3d2c1@cptec.inpe.br> Message-ID: On 2017-04-10, jorge.conrado at cptec.inpe.br wrote: > I installed the Pillow in my computer. The I did: > > import Image, ImageMath > > ImportError: No module named Image Try: from PIL import Image, ImageMath From lew.pitcher at digitalfreehold.ca Mon Apr 10 10:50:28 2017 From: lew.pitcher at digitalfreehold.ca (Lew Pitcher) Date: Mon, 10 Apr 2017 10:50:28 -0400 Subject: Pound sign problem References: <679200651.679871.1491830236809.ref@mail.yahoo.com> <679200651.679871.1491830236809@mail.yahoo.com> Message-ID: David Shi wrote: > In the data set, pound sign escape appears: > u'price_currency': u'\xa3', u'price_formatted': u'\xa3525,000', > When using table.to_csv after importing pandas as pd, an error message > persists as follows: UnicodeEncodeError: 'ascii' codec can't encode > character u'\xa3' in position 0: ordinal not in range(128) There is no "pound sign" in ASCII[1]. Try changing your target encoding to something other than ASCII. [1]: See http://std.dkuug.dk/i18n/charmaps/ascii for a list of valid ASCII values. -- Lew Pitcher "In Skills, We Trust" PGP public key available upon request From cjw at ncf.ca Mon Apr 10 11:45:05 2017 From: cjw at ncf.ca (Colin J. Williams) Date: Mon, 10 Apr 2017 11:45:05 -0400 Subject: Installing Python 3.6.1 on a Windows 10 Message-ID: Below is the tail of my Install Log. Is this a problem that I should be able to resolve? Advice sought. C Property(S): RedirectedDllSupport = 2 Property(S): MsiRunningElevated = 1 Property(S): Privileged = 1 Property(S): USERNAME = AdminOnly Property(S): Installed = 00:00:00 Property(S): DATABASE = C:\WINDOWS\Installer\3cb4905.msi Property(S): OriginalDatabase = C:\WINDOWS\Installer\3cb4905.msi Property(S): UILevel = 2 Property(S): MsiUISourceResOnly = 1 Property(S): Preselected = 1 Property(S): ACTION = INSTALL Property(S): ROOTDRIVE = E:\ Property(S): CostingComplete = 1 Property(S): OutOfDiskSpace = 0 Property(S): OutOfNoRbDiskSpace = 0 Property(S): PrimaryVolumeSpaceAvailable = 0 Property(S): PrimaryVolumeSpaceRequired = 0 Property(S): PrimaryVolumeSpaceRemaining = 0 Property(S): INSTALLLEVEL = 1 MSI (s) (2C:60) [09:00:59:536]: Note: 1: 1724 MSI (s) (2C:60) [09:00:59:536]: Note: 1: 2205 2: 3: Error MSI (s) (2C:60) [09:00:59:536]: Note: 1: 2228 2: 3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1724 MSI (s) (2C:60) [09:00:59:536]: Note: 1: 2205 2: 3: Error MSI (s) (2C:60) [09:00:59:536]: Note: 1: 2228 2: 3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1709 MSI (s) (2C:60) [09:00:59:536]: Product: Python 3.6.1 Core Interpreter (64-bit symbols) -- Removal completed successfully. MSI (s) (2C:60) [09:00:59:536]: Windows Installer removed the product. Product Name: Python 3.6.1 Core Interpreter (64-bit symbols). Product Version: 3.6.1150.0. Product Language: 1033. Manufacturer: Python Software Foundation. Removal success or error status: 0. MSI (s) (2C:60) [09:00:59:536]: Deferring clean up of packages/files, if any exist MSI (s) (2C:60) [09:00:59:536]: MainEngineThread is returning 0 MSI (s) (2C:DC) [09:00:59:536]: RESTART MANAGER: Session closed. MSI (s) (2C:DC) [09:00:59:536]: No System Restore sequence number for this installation. === Logging stopped: 2017-04-10 9:00:59 === MSI (s) (2C:DC) [09:00:59:551]: User policy value 'DisableRollback' is 0 MSI (s) (2C:DC) [09:00:59:551]: Machine policy value 'DisableRollback' is 0 MSI (s) (2C:DC) [09:00:59:551]: Incrementing counter to disable shutdown. Counter after increment: 0 MSI (s) (2C:DC) [09:00:59:551]: Note: 1: 1402 2: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\Rollback\Scripts 3: 2 MSI (s) (2C:DC) [09:00:59:551]: Note: 1: 2265 2: 3: -2147287035 MSI (s) (2C:DC) [09:00:59:551]: Note: 1: 1402 2: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\Rollback\Scripts 3: 2 MSI (s) (2C:DC) [09:00:59:551]: Decrementing counter to disable shutdown. If counter >= 0, shutdown will be denied. Counter after decrement: -1 MSI (s) (2C:DC) [09:00:59:551]: Post-install cleanup: removing installer file 'C:\WINDOWS\Installer\3cb4905.msi' MSI (c) (C8:98) [09:00:59:551]: Decrementing counter to disable shutdown. If counter >= 0, shutdown will be denied. Counter after decrement: -1 MSI (c) (C8:98) [09:00:59:551]: MainEngineThread is returning 0 === Verbose logging stopped: 2017-04-10 9:00:59 === From redstone-cold at 163.com Mon Apr 10 12:00:17 2017 From: redstone-cold at 163.com (iMath) Date: Mon, 10 Apr 2017 09:00:17 -0700 (PDT) Subject: using HTTPHandler cause Django server side shows http 400 and Invalid HTTP_HOST header message In-Reply-To: <58e4830b$0$1502$c3e8da3$5496439d@news.astraweb.com> References: <41b72e7a-8479-4901-9397-44bae30bee9c@googlegroups.com> <58e4830b$0$1502$c3e8da3$5496439d@news.astraweb.com> Message-ID: > Are you sure you posted the code you are actually using? Because the > error message suggests a difference. > I am sure ! As I have tested: If I pass the IP address of my web server to the host parameter of HTTPHandler, the server side would show http 400 and Invalid HTTP_HOST header message , while if I pass the domain name instead, then the view function works as expected . would it be a bug within HTTPHandler? From redstone-cold at 163.com Mon Apr 10 12:08:32 2017 From: redstone-cold at 163.com (iMath) Date: Mon, 10 Apr 2017 09:08:32 -0700 (PDT) Subject: using HTTPHandler cause Django server side shows http 400 and Invalid HTTP_HOST header message In-Reply-To: References: <41b72e7a-8479-4901-9397-44bae30bee9c@googlegroups.com> <58e4830b$0$1502$c3e8da3$5496439d@news.astraweb.com> Message-ID: <41b65552-c842-4b7d-b437-4eaf29444215@googlegroups.com> On Tuesday, April 11, 2017 at 12:00:27 AM UTC+8, iMath wrote: > > Are you sure you posted the code you are actually using? Because the > > error message suggests a difference. > > > I am sure ! > > As I have tested: If I pass the IP address of my web server to the host parameter of HTTPHandler, the server side would show http 400 and Invalid HTTP_HOST header message , > Besides the http 400 and Invalid HTTP_HOST header message , there are also following exceptions Invalid HTTP_HOST header: '112.74.98.187:8001,112.74.98.187'. The domain name pr ovided is not valid according to RFC 1034/1035. [10/Apr/2017 15:38:04] "GET /VideoParser/lYYDownloaderClientLog/?funcName=%3Cmod ule%3E&lineno=26&levelname=ERROR&name=__main__&stack_info=None&args=%28%29&modul e=a&pathname=C%3A%5CUsers%5Ci%5CDocuments%5CTencent+Files%5C2281570025%5CFileRec v%5Ca.py&process=6636&thread=6972&created=1491838715.9931207&msecs=993.120670318 6035&msg=testing+remote+logging&exc_info=None&relativeCreated=64.00370597839355& filename=a.py&threadName=MainThread&processName=MainProcess&levelno=40&exc_text= None HTTP/1.1" 400 66752 Traceback (most recent call last): File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 138, in run self.finish_response() File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 180, in finish_respo nse self.write(data) File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 279, in write self._write(data) File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 453, in _write result = self.stdout.write(data) File "/usr/local/lib/python3.6/socketserver.py", line 775, in write self._sock.sendall(b) ConnectionResetError: [Errno 104] Connection reset by peer [10/Apr/2017 15:38:04] "GET /VideoParser/lYYDownloaderClientLog/?funcName=%3Cmod ule%3E&lineno=26&levelname=ERROR&name=__main__&stack_info=None&args=%28%29&modul e=a&pathname=C%3A%5CUsers%5Ci%5CDocuments%5CTencent+Files%5C2281570025%5CFileRec v%5Ca.py&process=6636&thread=6972&created=1491838715.9931207&msecs=993.120670318 6035&msg=testing+remote+logging&exc_info=None&relativeCreated=64.00370597839355& filename=a.py&threadName=MainThread&processName=MainProcess&levelno=40&exc_text= None HTTP/1.1" 500 59 ---------------------------------------- Exception happened during processing of request from ('117.136.84.223', 49862) Traceback (most recent call last): File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 138, in run self.finish_response() File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 180, in finish_respo nse self.write(data) File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 279, in write self._write(data) File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 453, in _write result = self.stdout.write(data) File "/usr/local/lib/python3.6/socketserver.py", line 775, in write self._sock.sendall(b) ConnectionResetError: [Errno 104] Connection reset by peer During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 141, in run self.handle_error() File "/usr/local/lib/python3.6/site-packages/django/core/servers/basehttp.py", line 95, in handle_error super(ServerHandler, self).handle_error() File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 368, in handle_error self.finish_response() File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 180, in finish_respo nse self.write(data) File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 274, in write self.send_headers() File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 331, in send_headers if not self.origin_server or self.client_is_modern(): File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 344, in client_is_mo dern return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9' TypeError: 'NoneType' object is not subscriptable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.6/socketserver.py", line 639, in process_request_ thread self.finish_request(request, client_address) File "/usr/local/lib/python3.6/socketserver.py", line 361, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/local/lib/python3.6/socketserver.py", line 696, in __init__ self.handle() File "/usr/local/lib/python3.6/site-packages/django/core/servers/basehttp.py", line 174, in handle handler.run(self.server.get_app()) File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 144, in run self.close() File "/usr/local/lib/python3.6/wsgiref/simple_server.py", line 35, in close self.status.split(' ',1)[0], self.bytes_sent AttributeError: 'NoneType' object has no attribute 'split' ---------------------------------------- From redstone-cold at 163.com Mon Apr 10 12:11:02 2017 From: redstone-cold at 163.com (iMath) Date: Mon, 10 Apr 2017 09:11:02 -0700 (PDT) Subject: using HTTPHandler cause Django server side shows http 400 and Invalid HTTP_HOST header message In-Reply-To: References: <41b72e7a-8479-4901-9397-44bae30bee9c@googlegroups.com> <58e4830b$0$1502$c3e8da3$5496439d@news.astraweb.com> Message-ID: <29b7b613-f40b-4bc3-a15b-56e6b61cd057@googlegroups.com> On Tuesday, April 11, 2017 at 12:00:27 AM UTC+8, iMath wrote: > > Are you sure you posted the code you are actually using? Because the > > error message suggests a difference. > > > I am sure ! > > As I have tested: If I pass the IP address of my web server to the host parameter of HTTPHandler, the server side would show http 400 and Invalid HTTP_HOST header message , Besides the http 400 and Invalid HTTP_HOST header message , there are also exceptions , pasted here https://bpaste.net/show/f2d2e64e7a7e From jtrtransport at gmail.com Mon Apr 10 13:22:23 2017 From: jtrtransport at gmail.com (John Ralph) Date: Mon, 10 Apr 2017 10:22:23 -0700 (PDT) Subject: Need help with getting Key, Value out of dicts in lists In-Reply-To: References: Message-ID: <3d916a74-9261-4bfb-968b-007c1e8c57bc@googlegroups.com> There are a number of ways to reorganise the data for the exclusive use of your script without affecting the original data. Is there a reason you can't or not allowed to do this? Regardless, here's some code that might make things a little easier. It operates on each balancer on the fly, reduces the number of for loops, and eliminates worries about where the tags are placed within the list. from operator import itemgetter alist = \ [ [ {u'Value': 'shibboleth-prd', u'Key': 'Name'}, {u'Value': 'kvmu', u'Key': 'Billing'}, {u'Value': '20179204-181622543367489', u'Key': 'Resource_group_id'} ], [ {u'Value': '20172857-152037106154311', u'Key': 'Resource_group_id'}, {u'Value': 'shibboleth-tst', u'Key': 'Name'} ] ] # Problem: # for all resource group id tags that equal '20172857-152037106154311': # print its name tag (eg, "shibboleth-prd-alb") # create a container (dict) of tags for each balancer on the fly for balancer in alist: tags = dict(map(itemgetter('Key', 'Value'), balancer)) print 'group of tags:', tags if itemgetter('Resource_group_id')(tags) == '20172857-152037106154311': print '\tfound resource, resource name:', itemgetter('Name')(tags) From eryksun at gmail.com Mon Apr 10 14:07:58 2017 From: eryksun at gmail.com (eryk sun) Date: Mon, 10 Apr 2017 18:07:58 +0000 Subject: Installing Python 3.6.1 on a Windows 10 In-Reply-To: References: Message-ID: On Mon, Apr 10, 2017 at 3:45 PM, Colin J. Williams wrote: > Below is the tail of my Install Log. > Is this a problem that I should be able to resolve? > Advice sought. Open a Windows / Installation issue on bugs.python.org. Zip up the installation logs and attach the zip to the issue. From exarkun at twistedmatrix.com Mon Apr 10 14:12:12 2017 From: exarkun at twistedmatrix.com (Jean-Paul Calderone) Date: Mon, 10 Apr 2017 14:12:12 -0400 Subject: [ANN] txkube 0.1.0 Message-ID: Hello all, I'm pleased to announce the first release of txkube, a Twisted-based library for interacting with Kubernetes using the HTTP API. This release supports several of the most commonly used basic Kubernetes objects, including Services, ConfigMaps, Deployments, ReplicaSets, and Pods. While Kubernetes has many, many more object kinds, this collection of kinds already supports a very useful set of interactions. Here is an example of txkube usage, taken from the README: from __future__ import print_function from twisted.internet.task import react from txkube import v1, network_kubernetes_from_context @react def main(reactor): k8s = network_kubernetes_from_context(reactor, u"minikube") client = k8s.client() d = client.list(v1.Namespace) d.addCallback(print) return d You can download txkube from PyPI . You can contribute to its development on GitHub . Thanks to Least Authority Enterprises for sponsoring this development. Jean-Paul Calderone http://as.ynchrono.us/ From karlfx4 at gmail.com Mon Apr 10 14:58:21 2017 From: karlfx4 at gmail.com (Peter Henry) Date: Mon, 10 Apr 2017 19:58:21 +0100 Subject: Swiss Ephemeris In-Reply-To: <009c01d2b19d$1e76ce10$27b23dae@sambora> References: <49f767bc-8059-46bb-82b3-718dc8295b53@googlegroups.com> <009c01d2b19d$1e76ce10$27b23dae@sambora> Message-ID: Hi Deborah, Thanks your reply and interest, A few years ago did create a Excel addin, that extracted planetary coordinates from the Swisseph source code and populated excel spreadsheet This Marco addin had customised planetary settings of which was useful Currently now learning to program in Python as it is flexible, popular for machine learning and data science. The idea the planetary coordinate can help with timing stock commodity and Forex markets, as both freely trading markets and planetary movement adhere to natural law Neural networks can also assist in extracting relationship information between markets and planetary positions. Whilst waiting for a solution can you advise of an efficient way of producing a a CSV file similar to the file attached, only planetary data required Many thanks Peter On 10 April 2017 at 02:52, Deborah Swanson wrote: > Peter Henry wrote, on Sunday, April 09, 2017 10:53 AM > > > > I have a package that has been altered to imported in to > > python, however I tired to get is working but without success > > I be missing something obvious > > > > The Swiss Ephemeris enable planetary coordinate to be > > imported and used in your program > > > > Files access https://pypi.python.org/pypi/pyswisseph > > > > Many thanks in advance > > > > Peter > > I've also worked on the problem of getting sweph into Python and have > mostly struck out so far myself. > > I found one reliable means to get sweph's planetary data into Python, > but it's more or less a cheat. Nonetheless, if you want to see how much > good it does you, try the Swiss Ephemeris Test Page at > http://www.astro.com/swisseph/swetest.htm. If you can successfully > formulate a query useful to your purposes, you can download a csv of > results, read it into Python, and work from there. Right now I'm working > on converting some Excel spreadsheets and Excel VBA I use into Python > and recoding it all, using the CSVs for jumping off points. That works > pretty well, except the times from swetest are off a bit and I haven't > figured out why. But I'm concentrating on getting all my VBA code ported > to Python, and will go back to getting bang on data from sweph after I > have my code done. > > The first thing I tried was to get sweph's C source code into a free > IDE, but that whole project went down in flames. You can read bits and > pieces of that misadventure at the tail end of the "Python application > launcher (for Python code)" thread. I found sweph's C source code at > some link off "Programming interface to the Swiss Ephemeris" at > http://www.astro.com/swisseph/swephprg.htm (or maybe it was on > http://www.astro.com/swisseph/swephinfo_e.htm - I can't easily find it > now, but the download link is in one of those two pages somewhere.) > > Then I tried picking through sweph's C source code, attempting to > manually reproduce the logic and the calculations in Python. That was a > highly qualified semi-success because the times were still off, but it > essentially produces the most basic planetary data. The swetest output > CSVs were more complete however, and easy to read the planetary data > into Python from, so I'd pretty much abandoned efforts to "translate" > the C source code. And now, all my efforts to leverage the C source > code. Even if successful it would be a lot more time sunk into working > with a language other than Python, which I likely wouldn't have a use > for after this project is completed. > > However, I have seen bits here and there on this list that are at least > interesting. Tim Chase mentioned in passing that he encapsulated C > source code in a class, which may bear looking into. Lutz Horn also gave > a link for building a Python module to add a C language library to > Python, which also might be worth checking out: > https://docs.python.org/3/extending/index.html (I changed the 2 to a 3 > from the link he gave, but you can change it back to 2 if your working > in a build of Python 2.) > > But many thanks for your pypi link to pyswisseph, which I will check > out. I can reply to this thread after I give it a shot and tell you what > I think of it. But like I said earlier, that won't be until all my Excel > VBA code, which jumps off from the sweph bare planetary data, is ported > to Python and working. Could be awhile yet. And if pyswisseph doesn't > pan out, I'll likely work on refining the two methods I have for > producing the planetary data, both of which are only lacking precisely > accurate time data in my local time, and both are off by only 5-30 > minutes. I easily limped along for years with my Excel spread sheets > using the swetest CSVs for input, even though my times then were more > than a day off. > > Good luck! (and this venture is a goodly portion of luck...) > > Deborah > > PS. I've been using medical astrology to look ahead at my medical > condition for years in advance. And being off by a day or so doesn't > matter that much when you're looking at trends over the course of years > and decades. I also have a little software widget to look at the > planetary data in graphical chart form at any particular second, also > based on sweph, which has been quite astoundingly accurate in following > the rather complex kaleidoscope of my symptoms during the course of a > day. (Though it doesn't do you a bit of good if you forget to look! > Which is my entire motivation to get it encoded and available with a few > clicks.) And it is quite useful to know in advance what will be > happening when, and most importantly when it will stop. Knowledge is > power! > > Caveat. This kind of precision and accuracy is only found in the > specific forms of astrology which relate to pure physical phenomena, and > most of what you see these days masquerading as astrology is pure hooey, > almost entirely invented on a large scale in the Middle Ages and > flowered in the Renaissance. By pure physical phenomena, which is the > only phenomena that is at least debatably influenced by physical > planetary forces, I mean things like the moon's tides, sunspots, plant > and animal activity throughout the year, and supremely, the inner > workings of the human body, the first wholly Western medicine devised by > the ancient Greeks. (The ancient Greek physicians are an excellent > fallback if modern medicine is failing you - if you can find enough that > remains today of their art.) > > From jobmattcon at gmail.com Mon Apr 10 16:01:08 2017 From: jobmattcon at gmail.com (Ho Yeung Lee) Date: Mon, 10 Apr 2017 13:01:08 -0700 (PDT) Subject: how to convert this container back to format build result? Message-ID: <23c47456-808b-40b1-95f8-ebdcde58a46a@googlegroups.com> http://construct.readthedocs.io/en/latest/basics.html format.build can build the hex string, but after edit attribute of the format parse result it is a container, how to convert this container back to format build result? #format.parse(format.build(dict(width=3,height=2,pixels=[7,8,9,11,12,13]))).signature format = Struct( "signature" / Const(b"a2MP"), "width" / Int8ub, "height" / Int8ub, "pixels" / Array(3 * 2, Byte), ) #protocolA = {"a1" : "a2"} #protocolA["a2"] = "a3" #protocolA["a3"] = "a1" protocolA = {"a1MP" : format.build(dict(width=3,height=2,pixels=[7,8,9,11,12,13]))} a2MP = format.parse(format.build(dict(width=3,height=2,pixels=[7,8,9,11,12,13]))) a2MP.signature = "a3MP" protocolA["a2MP"] = a2MP.build({}) a1MP = format.parse(format.build(dict(width=3,height=2,pixels=[7,8,9,11,12,13]))) a1MP.signature = "a1MP" protocolA["a3MP"] = format.build(a1MP) From python at deborahswanson.net Mon Apr 10 16:10:36 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Mon, 10 Apr 2017 13:10:36 -0700 Subject: Swiss Ephemeris In-Reply-To: Message-ID: <001e01d2b236$84eb31b0$27b23dae@sambora> Hi Peter, I would be interested in seeing your Excel addin with customized planetary settings. I'd be curious what these customizations would be, though if they look useful I'd more likely be scavenging the code to rewrite it in Python and add to what I already have, rather than using the addin in Excel. The only thing not quite right about what I have is the times, which are a smidge off. This could be due to planetary anomalies, so I definitely would like to look at it. I totally agree with all you said about Python and more. I didn't start out in Python looking to replace Excel or to migrate my planetary project to it, those things just happened along the way. But looking around to see what was new and what was better than anything I'd done before, Python was a natural choice. I'll have to say though that I don't share your enthusiasm for modeling the market with planetary relationships, indeed any mathematical modelling of the market can easily be overall wrong, and yet complex enough to engage the explorer endlessly. I've analyzed a couple of these schemes to draw that conclusion, though it's tentative at best. Obviously there are mathematical models of the market that do work, but I really don't know anything about them. In this case though, I don't see the connection between planetary configurations and a pure physical aspect of the market for them to engage with. And as you may recall from somewhere, to establish causality you must produce the causal link between the two sets of events you're attempting to correlate. No matter how stunning an array of coincidences might be, without producing the causal link you really don't have anything. This is a key error that many who do statistical analyses tend to overlook. I looked at your CSV, but I'm not sure what you would like to add to it, probably because I'm totally unfamiliar with this type of project. Best in your endeavors, Deborah Peter Henry wrote, on Monday, April 10, 2017 11:58 AM Hi Deborah, Thanks your reply and interest, A few years ago did create a Excel addin, that extracted planetary coordinates from the Swisseph source code and populated excel spreadsheet This Marco addin had customized planetary settings of which was useful Currently now learning to program in Python as it is flexible, popular for machine learning and data science. The idea the planetary coordinate can help with timing stock commodity and Forex markets, as both freely trading markets and planetary movement adhere to natural law Neural networks can also assist in extracting relationship information between markets and planetary positions. Whilst waiting for a solution can you advise of an efficient way of producing a a CSV file similar to the file attached, only planetary data required Many thanks Peter On 10 April 2017 at 02:52, Deborah Swanson wrote: Peter Henry wrote, on Sunday, April 09, 2017 10:53 AM > > I have a package that has been altered to imported in to > python, however I tired to get is working but without success > I be missing something obvious > > The Swiss Ephemeris enable planetary coordinate to be > imported and used in your program > > Files access https://pypi.python.org/pypi/pyswisseph > > Many thanks in advance > > Peter I've also worked on the problem of getting sweph into Python and have mostly struck out so far myself. I found one reliable means to get sweph's planetary data into Python, but it's more or less a cheat. Nonetheless, if you want to see how much good it does you, try the Swiss Ephemeris Test Page at http://www.astro.com/swisseph/swetest.htm. If you can successfully formulate a query useful to your purposes, you can download a csv of results, read it into Python, and work from there. Right now I'm working on converting some Excel spreadsheets and Excel VBA I use into Python and recoding it all, using the CSVs for jumping off points. That works pretty well, except the times from swetest are off a bit and I haven't figured out why. But I'm concentrating on getting all my VBA code ported to Python, and will go back to getting bang on data from sweph after I have my code done. The first thing I tried was to get sweph's C source code into a free IDE, but that whole project went down in flames. You can read bits and pieces of that misadventure at the tail end of the "Python application launcher (for Python code)" thread. I found sweph's C source code at some link off "Programming interface to the Swiss Ephemeris" at http://www.astro.com/swisseph/swephprg.htm (or maybe it was on http://www.astro.com/swisseph/swephinfo_e.htm - I can't easily find it now, but the download link is in one of those two pages somewhere.) Then I tried picking through sweph's C source code, attempting to manually reproduce the logic and the calculations in Python. That was a highly qualified semi-success because the times were still off, but it essentially produces the most basic planetary data. The swetest output CSVs were more complete however, and easy to read the planetary data into Python from, so I'd pretty much abandoned efforts to "translate" the C source code. And now, all my efforts to leverage the C source code. Even if successful it would be a lot more time sunk into working with a language other than Python, which I likely wouldn't have a use for after this project is completed. However, I have seen bits here and there on this list that are at least interesting. Tim Chase mentioned in passing that he encapsulated C source code in a class, which may bear looking into. Lutz Horn also gave a link for building a Python module to add a C language library to Python, which also might be worth checking out: https://docs.python.org/3/extending/index.html (I changed the 2 to a 3 from the link he gave, but you can change it back to 2 if your working in a build of Python 2.) But many thanks for your pypi link to pyswisseph, which I will check out. I can reply to this thread after I give it a shot and tell you what I think of it. But like I said earlier, that won't be until all my Excel VBA code, which jumps off from the sweph bare planetary data, is ported to Python and working. Could be awhile yet. And if pyswisseph doesn't pan out, I'll likely work on refining the two methods I have for producing the planetary data, both of which are only lacking precisely accurate time data in my local time, and both are off by only 5-30 minutes. I easily limped along for years with my Excel spread sheets using the swetest CSVs for input, even though my times then were more than a day off. Good luck! (and this venture is a goodly portion of luck...) Deborah PS. I've been using medical astrology to look ahead at my medical condition for years in advance. And being off by a day or so doesn't matter that much when you're looking at trends over the course of years and decades. I also have a little software widget to look at the planetary data in graphical chart form at any particular second, also based on sweph, which has been quite astoundingly accurate in following the rather complex kaleidoscope of my symptoms during the course of a day. (Though it doesn't do you a bit of good if you forget to look! Which is my entire motivation to get it encoded and available with a few clicks.) And it is quite useful to know in advance what will be happening when, and most importantly when it will stop. Knowledge is power! Caveat. This kind of precision and accuracy is only found in the specific forms of astrology which relate to pure physical phenomena, and most of what you see these days masquerading as astrology is pure hooey, almost entirely invented on a large scale in the Middle Ages and flowered in the Renaissance. By pure physical phenomena, which is the only phenomena that is at least debatably influenced by physical planetary forces, I mean things like the moon's tides, sunspots, plant and animal activity throughout the year, and supremely, the inner workings of the human body, the first wholly Western medicine devised by the ancient Greeks. (The ancient Greek physicians are an excellent fallback if modern medicine is failing you - if you can find enough that remains today of their art.) From karlfx4 at gmail.com Mon Apr 10 16:56:13 2017 From: karlfx4 at gmail.com (Peter Henry) Date: Mon, 10 Apr 2017 21:56:13 +0100 Subject: Fwd: Swiss Ephemeris In-Reply-To: References: <001e01d2b236$84eb31b0$27b23dae@sambora> Message-ID: Hi Deborah Very few people would believe there is correlation between planetary cycles and the stockmarket however this is known to select few, for many years, I can also visually see relationship on charts, however its hard to quantify statically http://astrologynewsservice.com/business/study-confirms-plan ets-impact-stock-market-averages/ I'll forward the Excel addin later it works on Windows 7 and require updating to Win10 The idea is to create a full and complete program in Python only, that would import stock data, generate planetary coordinates, pre process train then predict I'll keep you updated Peter On 10 Apr 2017 9:10 p.m., "Deborah Swanson" wrote: > Hi Peter, > > I would be interested in seeing your Excel addin with customized > planetary settings. I'd be curious what these customizations would be, > though if they look useful I'd more likely be scavenging the code to > rewrite it in Python and add to what I already have, rather than using > the addin in Excel. The only thing not quite right about what I have is > the times, which are a smidge off. This could be due to planetary > anomalies, so I definitely would like to look at it. > > I totally agree with all you said about Python and more. I didn't start > out in Python looking to replace Excel or to migrate my planetary > project to it, those things just happened along the way. But looking > around to see what was new and what was better than anything I'd done > before, Python was a natural choice. > > I'll have to say though that I don't share your enthusiasm for modeling > the market with planetary relationships, indeed any mathematical > modelling of the market can easily be overall wrong, and yet complex > enough to engage the explorer endlessly. > > I've analyzed a couple of these schemes to draw that conclusion, though > it's tentative at best. Obviously there are mathematical models of the > market that do work, but I really don't know anything about them. > > In this case though, I don't see the connection between planetary > configurations and a pure physical aspect of the market for them to > engage with. And as you may recall from somewhere, to establish > causality you must produce the causal link between the two sets of > events you're attempting to correlate. No matter how stunning an array > of coincidences might be, without producing the causal link you really > don't have anything. This is a key error that many who do statistical > analyses tend to overlook. > > I looked at your CSV, but I'm not sure what you would like to add to it, > probably because I'm totally unfamiliar with this type of project. > > Best in your endeavors, > > Deborah > > > Peter Henry wrote, on Monday, April 10, 2017 11:58 AM > > Hi Deborah, > > > Thanks your reply and interest, > > > A few years ago did create a Excel addin, that extracted planetary > coordinates from the Swisseph source code and populated excel > spreadsheet This Marco addin had customized planetary settings of which > was useful > > > Currently now learning to program in Python as it is flexible, popular > for machine learning and data science. The idea the planetary coordinate > can help with timing stock commodity and Forex markets, as both freely > trading markets and planetary movement adhere to natural law > > > Neural networks can also assist in extracting relationship information > between markets and planetary positions. > > > Whilst waiting for a solution can you advise of an efficient way of > producing a a CSV file similar to the file attached, only planetary data > required > > > > > Many thanks > > > Peter > > > On 10 April 2017 at 02:52, Deborah Swanson > wrote: > > Peter Henry wrote, on Sunday, April 09, 2017 10:53 AM > > > > I have a package that has been altered to imported in to > > python, however I tired to get is working but without success > > I be missing something obvious > > > > The Swiss Ephemeris enable planetary coordinate to be > > imported and used in your program > > > > Files access https://pypi.python.org/pypi/pyswisseph > > > > Many thanks in advance > > > > Peter > > I've also worked on the problem of getting sweph into Python and have > mostly struck out so far myself. > > I found one reliable means to get sweph's planetary data into Python, > but it's more or less a cheat. Nonetheless, if you want to see how much > good it does you, try the Swiss Ephemeris Test Page at > http://www.astro.com/swisseph/swetest.htm. If you can successfully > formulate a query useful to your purposes, you can download a csv of > results, read it into Python, and work from there. Right now I'm working > on converting some Excel spreadsheets and Excel VBA I use into Python > and recoding it all, using the CSVs for jumping off points. That works > pretty well, except the times from swetest are off a bit and I haven't > figured out why. But I'm concentrating on getting all my VBA code ported > to Python, and will go back to getting bang on data from sweph after I > have my code done. > > The first thing I tried was to get sweph's C source code into a free > IDE, but that whole project went down in flames. You can read bits and > pieces of that misadventure at the tail end of the "Python application > launcher (for Python code)" thread. I found sweph's C source code at > some link off "Programming interface to the Swiss Ephemeris" at > http://www.astro.com/swisseph/swephprg.htm (or maybe it was on > http://www.astro.com/swisseph/swephinfo_e.htm - I can't easily find it > now, but the download link is in one of those two pages somewhere.) > > Then I tried picking through sweph's C source code, attempting to > manually reproduce the logic and the calculations in Python. That was a > highly qualified semi-success because the times were still off, but it > essentially produces the most basic planetary data. The swetest output > CSVs were more complete however, and easy to read the planetary data > into Python from, so I'd pretty much abandoned efforts to "translate" > the C source code. And now, all my efforts to leverage the C source > code. Even if successful it would be a lot more time sunk into working > with a language other than Python, which I likely wouldn't have a use > for after this project is completed. > > However, I have seen bits here and there on this list that are at least > interesting. Tim Chase mentioned in passing that he encapsulated C > source code in a class, which may bear looking into. Lutz Horn also gave > a link for building a Python module to add a C language library to > Python, which also might be worth checking out: > https://docs.python.org/3/extending/index.html (I changed the 2 to a 3 > from the link he gave, but you can change it back to 2 if your working > in a build of Python 2.) > > But many thanks for your pypi link to pyswisseph, which I will check > out. I can reply to this thread after I give it a shot and tell you what > I think of it. But like I said earlier, that won't be until all my Excel > VBA code, which jumps off from the sweph bare planetary data, is ported > to Python and working. Could be awhile yet. And if pyswisseph doesn't > pan out, I'll likely work on refining the two methods I have for > producing the planetary data, both of which are only lacking precisely > accurate time data in my local time, and both are off by only 5-30 > minutes. I easily limped along for years with my Excel spread sheets > using the swetest CSVs for input, even though my times then were more > than a day off. > > Good luck! (and this venture is a goodly portion of luck...) > > Deborah > > PS. I've been using medical astrology to look ahead at my medical > condition for years in advance. And being off by a day or so doesn't > matter that much when you're looking at trends over the course of years > and decades. I also have a little software widget to look at the > planetary data in graphical chart form at any particular second, also > based on sweph, which has been quite astoundingly accurate in following > the rather complex kaleidoscope of my symptoms during the course of a > day. (Though it doesn't do you a bit of good if you forget to look! > Which is my entire motivation to get it encoded and available with a few > clicks.) And it is quite useful to know in advance what will be > happening when, and most importantly when it will stop. Knowledge is > power! > > Caveat. This kind of precision and accuracy is only found in the > specific forms of astrology which relate to pure physical phenomena, and > most of what you see these days masquerading as astrology is pure hooey, > almost entirely invented on a large scale in the Middle Ages and > flowered in the Renaissance. By pure physical phenomena, which is the > only phenomena that is at least debatably influenced by physical > planetary forces, I mean things like the moon's tides, sunspots, plant > and animal activity throughout the year, and supremely, the inner > workings of the human body, the first wholly Western medicine devised by > the ancient Greeks. (The ancient Greek physicians are an excellent > fallback if modern medicine is failing you - if you can find enough that > remains today of their art.) > > From python at deborahswanson.net Mon Apr 10 18:13:10 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Mon, 10 Apr 2017 15:13:10 -0700 Subject: Swiss Ephemeris In-Reply-To: Message-ID: <002b01d2b247$a4244bf0$27b23dae@sambora> Hi Peter I'm willing to believe there's a correlation between planetary cycles and the stockmarket, if you say you see one. The question is whether this correlation has truth value significance, or whether it's just a set of coincidences. The correlation is interesting, but I fail to see the causal link, the reason why planetary cycles necessarily have a relationship with market movements, and without that all you have is coincidence. Though one could spend a great deal of time analyzing the correlation, I have low confidence that it would be a strong and reliable correlation. This has been the fate of many other misadventures in astrology, systems of belief built around weak and unreliable correlations that are sometimes right, but more often wrong, sad to say. I don't have Windows 7 or 10. Any chance there's source code for the addin? That's what I would be looking at anyway. ;) Best, Deborah Peter Henry wrote, on Monday, April 10, 2017 1:56 PM > > Hi Deborah > > Very few people would believe there is correlation between > planetary cycles and the stockmarket however this is known > to select few, for many years, I can also visually see > relationship on charts, however its hard to quantify statically > > http://astrologynewsservice.com/business/study-confirms-plan > ets-impact-stock-market-averages/ > > I'll forward the Excel addin later it works on Windows 7 and > require updating to Win10 > > The idea is to create a full and complete program in Python > only, that would import stock data, generate planetary > coordinates, pre process train then predict > > I'll keep you updated > > Peter > > > > On 10 Apr 2017 9:10 p.m., "Deborah Swanson" > > wrote: > > > Hi Peter, > > > > I would be interested in seeing your Excel addin with customized > > planetary settings. I'd be curious what these > customizations would be, > > though if they look useful I'd more likely be scavenging > the code to > > rewrite it in Python and add to what I already have, rather > than using > > the addin in Excel. The only thing not quite right about > what I have > > is the times, which are a smidge off. This could be due to > planetary > > anomalies, so I definitely would like to look at it. > > > > I totally agree with all you said about Python and more. I didn't > > start out in Python looking to replace Excel or to migrate my > > planetary project to it, those things just happened along > the way. But > > looking around to see what was new and what was better than > anything > > I'd done before, Python was a natural choice. > > > > I'll have to say though that I don't share your enthusiasm for > > modeling the market with planetary relationships, indeed any > > mathematical modelling of the market can easily be overall > wrong, and > > yet complex enough to engage the explorer endlessly. > > > > I've analyzed a couple of these schemes to draw that conclusion, > > though it's tentative at best. Obviously there are > mathematical models > > of the market that do work, but I really don't know anything about > > them. > > > > In this case though, I don't see the connection between planetary > > configurations and a pure physical aspect of the market for them to > > engage with. And as you may recall from somewhere, to establish > > causality you must produce the causal link between the two sets of > > events you're attempting to correlate. No matter how > stunning an array > > of coincidences might be, without producing the causal link > you really > > don't have anything. This is a key error that many who do > statistical > > analyses tend to overlook. > > > > I looked at your CSV, but I'm not sure what you would like > to add to > > it, probably because I'm totally unfamiliar with this type > of project. > > > > Best in your endeavors, > > > > Deborah > > > > > > Peter Henry wrote, on Monday, April 10, 2017 11:58 AM > > > > Hi Deborah, > > > > > > Thanks your reply and interest, > > > > > > A few years ago did create a Excel addin, that extracted planetary > > coordinates from the Swisseph source code and populated excel > > spreadsheet This Marco addin had customized planetary settings of > > which was useful > > > > > > Currently now learning to program in Python as it is flexible, > > popular for machine learning and data science. The idea the > planetary > > coordinate can help with timing stock commodity and Forex > markets, as > > both freely trading markets and planetary movement adhere > to natural > > law > > > > > > Neural networks can also assist in extracting relationship > information > > between markets and planetary positions. > > > > > > Whilst waiting for a solution can you advise of an > efficient way of > > producing a a CSV file similar to the file attached, only planetary > > data required > > > > > > > > > > Many thanks > > > > > > Peter > > > > > > On 10 April 2017 at 02:52, Deborah Swanson > > > wrote: > > > > Peter Henry wrote, on Sunday, April 09, 2017 10:53 AM > > > > > > I have a package that has been altered to imported in to python, > > > however I tired to get is working but without success I > be missing > > > something obvious > > > > > > The Swiss Ephemeris enable planetary coordinate to be > imported and > > > used in your program > > > > > > Files access https://pypi.python.org/pypi/pyswisseph > > > > > > Many thanks in advance > > > > > > Peter > > > > I've also worked on the problem of getting sweph into > Python and have > > mostly struck out so far myself. > > > > I found one reliable means to get sweph's planetary data > into Python, > > but it's more or less a cheat. Nonetheless, if you want to see how > > much good it does you, try the Swiss Ephemeris Test Page at > > http://www.astro.com/swisseph/swetest.htm. If you can successfully > > formulate a query useful to your purposes, you can download > a csv of > > results, read it into Python, and work from there. Right now I'm > > working on converting some Excel spreadsheets and Excel VBA > I use into > > Python and recoding it all, using the CSVs for jumping off points. > > That works pretty well, except the times from swetest are off a bit > > and I haven't figured out why. But I'm concentrating on > getting all my > > VBA code ported to Python, and will go back to getting bang on data > > from sweph after I have my code done. > > > > The first thing I tried was to get sweph's C source code > into a free > > IDE, but that whole project went down in flames. You can > read bits and > > pieces of that misadventure at the tail end of the "Python > application > > launcher (for Python code)" thread. I found sweph's C > source code at > > some link off "Programming interface to the Swiss Ephemeris" at > > http://www.astro.com/swisseph/swephprg.htm (or maybe it was on > > http://www.astro.com/swisseph/swephinfo_e.htm - I can't > easily find it > > now, but the download link is in one of those two pages somewhere.) > > > > Then I tried picking through sweph's C source code, attempting to > > manually reproduce the logic and the calculations in > Python. That was > > a highly qualified semi-success because the times were > still off, but > > it essentially produces the most basic planetary data. The swetest > > output CSVs were more complete however, and easy to read > the planetary > > data into Python from, so I'd pretty much abandoned efforts to > > "translate" the C source code. And now, all my efforts to > leverage the > > C source code. Even if successful it would be a lot more time sunk > > into working with a language other than Python, which I likely > > wouldn't have a use for after this project is completed. > > > > However, I have seen bits here and there on this list that are at > > least interesting. Tim Chase mentioned in passing that he > encapsulated > > C source code in a class, which may bear looking into. Lutz > Horn also > > gave a link for building a Python module to add a C > language library > > to Python, which also might be worth checking out: > > https://docs.python.org/3/extending/index.html (I changed > the 2 to a 3 > > from the link he gave, but you can change it back to 2 if > your working > > in a build of Python 2.) > > > > But many thanks for your pypi link to pyswisseph, which I > will check > > out. I can reply to this thread after I give it a shot and tell you > > what I think of it. But like I said earlier, that won't be > until all > > my Excel VBA code, which jumps off from the sweph bare > planetary data, > > is ported to Python and working. Could be awhile yet. And if > > pyswisseph doesn't pan out, I'll likely work on refining the two > > methods I have for producing the planetary data, both of which are > > only lacking precisely accurate time data in my local time, > and both > > are off by only 5-30 minutes. I easily limped along for > years with my > > Excel spread sheets using the swetest CSVs for input, even > though my > > times then were more than a day off. > > > > Good luck! (and this venture is a goodly portion of luck...) > > > > Deborah > > > > PS. I've been using medical astrology to look ahead at my medical > > condition for years in advance. And being off by a day or > so doesn't > > matter that much when you're looking at trends over the course of > > years and decades. I also have a little software widget to > look at the > > planetary data in graphical chart form at any particular > second, also > > based on sweph, which has been quite astoundingly accurate in > > following the rather complex kaleidoscope of my symptoms during the > > course of a day. (Though it doesn't do you a bit of good if > you forget > > to look! Which is my entire motivation to get it encoded > and available > > with a few > > clicks.) And it is quite useful to know in advance what will be > > happening when, and most importantly when it will stop. Knowledge is > > power! > > > > Caveat. This kind of precision and accuracy is only found in the > > specific forms of astrology which relate to pure physical > phenomena, > > and most of what you see these days masquerading as > astrology is pure > > hooey, almost entirely invented on a large scale in the > Middle Ages > > and flowered in the Renaissance. By pure physical > phenomena, which is > > the only phenomena that is at least debatably influenced by > physical > > planetary forces, I mean things like the moon's tides, > sunspots, plant > > and animal activity throughout the year, and supremely, the inner > > workings of the human body, the first wholly Western > medicine devised > > by the ancient Greeks. (The ancient Greek physicians are an > excellent > > fallback if modern medicine is failing you - if you can find enough > > that remains today of their art.) > > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From python at lucidity.plus.com Mon Apr 10 18:35:40 2017 From: python at lucidity.plus.com (Erik) Date: Mon, 10 Apr 2017 23:35:40 +0100 Subject: read in a list in a file to list In-Reply-To: <820a9e29-25b4-baaf-c8cb-ff40b980e6ec@mail.usf.edu> References: <5db12517-4c1a-f180-978f-533a632b8b36@mail.usf.edu> <43baa05f-7cdf-4e58-a62a-1e917fea8219@googlegroups.com> <820a9e29-25b4-baaf-c8cb-ff40b980e6ec@mail.usf.edu> Message-ID: <2bb54f08-7fba-dd78-d1a2-4d12568b59dc@lucidity.plus.com> On 09/04/17 22:22, john polo wrote: > The new attempt gives me a list, now I have to figure out how to deal > with unwanted quotation marks and spaces. > > datFil = open("apelist.txt") > datObj = datFil.read() > > > datObj2 = datObj.replace('" ','') #added this comment while writing > this email: I guess I could have used 'datObj = datFil.read().replace('" > ','')'. Can you make two replacements in the same statement, for example > 'datObj=datFil.read().replace('" ','').replace('"','')? > > datObj2 = datObj2.replace('"','') #this was here to try to get rid of " > that didn't have a subsequent space. John, where does your "apelist.txt" file come from? Who has decided what format it should be in? If *you* get to decide that, then the best thing to do is to specify a format that is easy to read in in the first place - rather than specifying something that looks like source code and then has to be parsed. E.g., if the file had the format: Home sapiens Pan troglodytes Gorilla gorilla (i.e., each value on a separate line with no quotes or any other "noise"), then the code to read that in as you have indicated you want is something like: for i in open("apefile.txt").readlines(): print("one of the apes is " + i.rstrip()) (the .rstrip() is to remove the trailing newline character - and any other trailing whitespace - which readlines() will include in what it returns). Of course, if you don't have any control over the input file's format, then it looks like you (or something you delegate to) will have to do some sort of parsing. E. From python at lucidity.plus.com Mon Apr 10 18:45:13 2017 From: python at lucidity.plus.com (Erik) Date: Mon, 10 Apr 2017 23:45:13 +0100 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <27652c6d-2cb4-4f0c-9400-6aa2a3f9f855@googlegroups.com> Message-ID: <9bdec2c0-6050-4b55-e4a0-96fcc9af6899@lucidity.plus.com> On 10/04/17 03:23, Chris Angelico wrote: > Okay, I have a pretty thick skin, but this is getting a bit obnoxious. > Can you PLEASE post something that isn't just insulting me? Thanks. Are you suggesting he should post something that insults you *and* others? If so, I'm up for being insulted too ;) E. From rosuav at gmail.com Mon Apr 10 19:33:13 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Apr 2017 09:33:13 +1000 Subject: Python and the need for speed In-Reply-To: <9bdec2c0-6050-4b55-e4a0-96fcc9af6899@lucidity.plus.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <27652c6d-2cb4-4f0c-9400-6aa2a3f9f855@googlegroups.com> <9bdec2c0-6050-4b55-e4a0-96fcc9af6899@lucidity.plus.com> Message-ID: On Tue, Apr 11, 2017 at 8:45 AM, Erik wrote: > On 10/04/17 03:23, Chris Angelico wrote: >> >> Okay, I have a pretty thick skin, but this is getting a bit obnoxious. >> Can you PLEASE post something that isn't just insulting me? Thanks. > > > Are you suggesting he should post something that insults you *and* others? > If so, I'm up for being insulted too ;) If he does, it might be the final thing that gets him banned from the mailing list. ChrisA From steve+python at pearwood.info Mon Apr 10 21:30:04 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 11 Apr 2017 11:30:04 +1000 Subject: Pound sign problem References: <679200651.679871.1491830236809.ref@mail.yahoo.com> <679200651.679871.1491830236809@mail.yahoo.com> Message-ID: <58ec319d$0$1621$c3e8da3$5496439d@news.astraweb.com> On Tue, 11 Apr 2017 12:50 am, Lew Pitcher wrote: > David Shi wrote: > >> In the data set, pound sign escape appears: >> u'price_currency': u'\xa3', u'price_formatted': u'\xa3525,000', That looks like David is using Python 2. >> When using table.to_csv after importing pandas as pd, an error message >> persists as follows: UnicodeEncodeError: 'ascii' codec can't encode >> character u'\xa3' in position 0: ordinal not in range(128) > > There is no "pound sign" in ASCII[1]. Try changing your target encoding to > something other than ASCII. Please don't encourage the use of old legacy encodings. In 2017, unless you are reading from old legacy files created using a non-Unicode encoding, you should just use UTF-8. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From auriocus at gmx.de Tue Apr 11 02:14:41 2017 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 11 Apr 2017 08:14:41 +0200 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: Am 10.04.17 um 02:21 schrieb Gregory Ewing: > Heck, you can write an exec() function for C if you really > want. Run the C compiler in another process, dynamically > load the object file and call it. Doing that would be very > inefficient, but it wouldn't slow down the rest of your > C code. Actually, this thing exists and it is quite useful. tcc can be used as a library / JIT compiler for C. It does allow both writing to a dynamic library as well as creating callable functions in memory. https://github.com/LuaDist/tcc/blob/master/libtcc.h#L64 What you can't do with it, however, is access to local variables. i.e. writing an exec which does this: int i=0; exec("i = 5"); printf("%d", i); // prints 5 is impossible in C, and making it possible (via debug symbols, e.g.) would make the program slower, because C compilers reorder the instructions and assign variables to registers. Christian From rustompmody at gmail.com Tue Apr 11 02:49:55 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 10 Apr 2017 23:49:55 -0700 (PDT) Subject: Swiss Ephemeris In-Reply-To: References: <1710f867-da07-4c52-9ff5-7b349dd8e485@googlegroups.com> <000001d2b1bb$7f8e7950$27b23dae@sambora> Message-ID: On Monday, April 10, 2017 at 11:26:47 AM UTC+5:30, Deborah Swanson wrote: > The great ancients were no less endowed with intelligence than we are, they > simply directed it to different ends. And just when I was convinced by the all-knowers that my gpa was a monkey you've spoilt my complacence > ... medical astrology... whether that is hooey or scepticism of it is hooey, I dont know [Yeah I genuinely don't know what that term means for you] However you may be interested in http://blog.languager.org/2016/01/how-long.html which is a motley collection of the incredible persistence of humans to erroneous ways and outlooks and their damaging consequences [Frank Admission: That list started with a discussion on this list where I suggested that OOP is already debunked hooey and that FP is the way forward for programming. To which Steven asked that since FP is at least 50 years old and has not got very far, what makes one think its going anywhere... To which I wondered... Is 50 years a long time? By what standard? Hence that list ] From steve at pearwood.info Tue Apr 11 04:19:31 2017 From: steve at pearwood.info (Steven D'Aprano) Date: 11 Apr 2017 08:19:31 GMT Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> On Sun, 09 Apr 2017 19:05:35 +1000, Chris Angelico wrote: > When people talk about making a restricted optimizable subset of Python, > the implication (if not the explicit declaration) is that it's done > strictly by removing, not by rewriting. Maybe *some* people have a naive, if not foolish, idea that all you need to do to speed up CPython is to go through the C code and hit delete over any functions you don't want. But that's hardly a technique that is going to work: not only will you break features, but merely removing code doesn't magically make the rest of the code base faster. At the very least, you have to re-write the code that depends on the features you have just removed. If we're going to talk about speeding up Python, we ought to talk about *serious* approaches to the problem, not the musing of random, ignorant bloggers and other naive commentators. So let's look at what the experts have done: PyPy: a complete re-write, with a completely different approach (JIT compilation). WPython (alas, now more or less abandoned): a complete re-write of the virtual machine, using 16-bit "wordcodes" instead of 8 bit "bytecodes", nevertheless this enabled a lot of good optimizations: http://repository.root-me.org/Programmation/Python/EN%20-%20Beyond% 20python%20bytecode.pdf https://storage.googleapis.com/google-code-archive-downloads/v2/ code.google.com/wpython2/Cleanup%20and%20new%20optimizations%20in% 20WPython%201.1.pdf Unladen Swallow: among other changes, added new, specialist byte-codes to speed up common operations. http://qinsb.blogspot.com.au/2011/03/unladen-swallow-retrospective.html Nuitka: a static optimizing compiler, and a complete re-write. Nuitka implements a number of compile-time optimizations while still keeping (claimed) 100% compatibility with CPython. http://nuitka.net/doc/user-manual.html FATPython adds compile-time name lookups, specialised functions, dead- code elimination, constant folding and propagation to a CPython base. https://haypo.github.io/fat-python-status-janv12-2016.html Cython: a *superset*, not subset, of Python. I could continue, but you get the point. Some of these are experimental, like FATPython; some were production ready but abandoned because the community had little interest (wpython); some are actively maintained and used in production by many people (cython, PyPy). The Python ecosystem is actually quite healthy, if you need to speed up code there are lots of solutions, and some of them are even good solutions. Nevertheless, it is interesting to discuss whether or not any of these features will go mainstream or make it into CPython. But anyway... it's not sufficient to just delete features to speed up a language. You have to change implementation, and very likely add entirely new internal APIs for the compiler. Creating a restricted subset of Python, and giving up compatibility with ordinary Python, is certainly an opinion. That's what Facebook did with their version of PHP. But its not the only approach. > A couple more quotes from the article: > >> It should be possible to define a subset of the Python language, >> uninspiredly dubbed ?TurboPython?, that excludes those features that >> stand in the way of high-performance JIT execution (or compilation). >> Not using some of these features coincides with good design practices, >> so it doesn?t necessarily have to be all bad. > ... >> Since TurboPython is a subset of Python, it will also run on Python >> interpreters, albeit slower. > > Both of these imply that the standard library of TurboPython is > *exactly* the standard library of CPython, No. It doesn't say anything about the standard library. Maybe TurboPython has no standard library at all. The library is independent of the interpreter, and until somebody actually puts the effort in of writing it (or copying it from one repo to another), we are equally justified in saying any of: - TurboPython's std lib will have 100% functional compatibility with Python, only the implementation may change; - TurboPython has no std lib, it only has the built-in types and modules, if you want more, you can port it yourself; - TurboPython's std lib is a subset of the Python std lib, just as TurboPython itself is a subset of Python; - TurboPython's std lib is a MILLION TIMES BETTER than Python's. Since TurboPython doesn't exist, any of those statements are equally true. But in a *practical* sense, for our mythical/hypothetical TurboPython to have a chance at going mainstream, it needs a record/struct type, which in Python is namedtuple. That does not necessarily mean it needs to exec() arbitrary code. It just needs a way to create classes dynamically. Even Java can do that. http://stackoverflow.com/questions/2320404/ > minus the bits that aren't > supported. We just cut a few of those nasty dynamic features out of the > language, and voila! it becomes faster. That's exactly what I'm talking about. Anyone who says "voila! it becomes faster" and means it is too foolish to live :-) Cutting out the dynamic features is just the first step in allowing you to re-write the interpreter with more optimizations. A non-optimizing compiler doesn't magically become optimizing just because you've deleted some code from the interpreter. > (Or in this case, > JITable.) There's nothing suggested here about reimplementing existing > features in a different way, Except for common bloody sense :-P [...] > But again, you certainly COULD reimplement literal_eval, but then you > have to keep your implementation accurate and up-to-date, else you risk > bugs creeping in. It's a non-trivial task to rewrite these kinds of > things and maintain parallel versions; Sure, it's not thirty seconds work, but it's not *hard* to write a parser that accepts a small subset of Python expressions (those involving only literals and a handful of built-in displays). Are you aware that literal_eval is *not* the same code that the Python interpreter uses for evaluating literals? They are kept in sync manually, or not kept in sync as the case may be. Python 2.7 didn't support the set display syntax even though Python did: >>> from ast import literal_eval >>> {1, 2} set([1, 2]) >>> literal_eval("{1, 2}") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/ast.py", line 80, in literal_eval return _convert(node_or_string) File "/usr/lib/python2.7/ast.py", line 79, in _convert raise ValueError('malformed string') ValueError: malformed string literal_eval also had a bug that allowed it to evaluate the + and - operator, needed to support complex numbers: http://stackoverflow.com/questions/40584417/why-does-ast-literal-eval5-7 The point being, while it's not *ideal* that support for evaluating Python literals needs to be written twice (once in the real interpreter, once in literal_eval) its not unusual or uncommon or a particularly onerous requirement. > by calling on compile(), the > current implementation *for free* is kept up-to-date with changes in > CPython's grammar. That's incorrect. literal_eval() needs a whitelist of what's allowed, and a blacklist of what is allowed by the whitelist but shouldn't be. There may be other work needed as well. See the source code :-) [...] > Yes. As long as it can know when the more dynamic features are being > used - and that's the hard part. Hard, but not impossible, and not that hard. Look at Nuitka and FATPython. The thing that people forget is that not all errors are equal. There are two ways that the optimizing compiler can do the wrong thing: - fail to apply an optimization when it is safe to do so; - apply an optimization when it is unsafe to do so. Those errors are not equivalent. In the first case, all that happens is that you lose an opportunity to be a little bit faster, but the executed code is still correct. (Or at least no less correct than what you wrote.) If you even notice, which you might not, it might be tricky to work out why the compiler isn't applying the optimization, but in principle it can be done and then worked around, or the compiler made a bit smarter. For example, it might be that the compiler applies an absolutely dead- simple rule: *any* use of eval or exec disables *all* optimizations. Don't like it? Then don't use eval or exec. If that's not an option for you, patches are welcome. The second case is much worse. If you're lucky, the "optimized" code will merely crash, and you'll know it is broken. But worse, it may be subtly incorrect, and do the wrong thing. Calculate a *very slightly off* result. Or transfer funds to the wrong account, delete the wrong files, turn off the wrong life-support machine, that sort of thing. The second case must be avoided at all costs. (Or at least, unless the programmer consents to unsafe optimizations that may change behaviour, such as many unsafe floating point optermizations.) The first case merely indicates room for improvement. Patches are welcome. > Remember, as soon as you have a single > class implemented in Python, it could have a method injected into it > without your knowledge. Can you detect that statically, or can you use > the versioning of __dict__ to notice that something's been broken? What > makes you fall back to the default implementation? Ask Victor Stinner. You ask these rhetorical questions as if they're major impediments, but they actually are more-or-less solved problems. The tricky part is just applying the solutions to *Python* itself. It's one thing to have a general strategy for optimizations, its another to apply it to a real language, and especially a real implementation. But effectively, yes, I believe that dict versioning can be used to do this. Suppose you have code that says: result = myinstance.method(99) So you compile byte-code something like this pseudo-code: lookup myinstance if type(myinstance) is the expected type and neither the type nor instance __dict__ have changed: push 99 on the stack JUMP TO CODE AT 123456 # original location of method's code return else: get myinstance lookup method in myinstance.__dict__ if not found: lookup method in each of type(myisinstance).__mro__ or fail wrap the found object in MethodType build a set of positional and keyword arguments pass those positional and keyword arguments to method object which unpacks them and assigns to parameters location = look up the method's code object set up the book-keeping needed JUMP TO CODE AT location # probably 123456 as above tidy up book-keeping return The first case avoids a HUGE amount of work, at the cost of checking a couple of guards ahead of time. So the fast path becomes (say) 20% faster, and the slow path becomes 2% slower. Even if you take the slow path nine times as often as the fast path, it's still an overall win. But you don't get that just be selecting the C code for eval() and exec() in your editor and pressing Delete. -- Steve From mail at timgolden.me.uk Tue Apr 11 04:26:16 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 11 Apr 2017 09:26:16 +0100 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <27652c6d-2cb4-4f0c-9400-6aa2a3f9f855@googlegroups.com> <9bdec2c0-6050-4b55-e4a0-96fcc9af6899@lucidity.plus.com> Message-ID: On 11/04/2017 00:33, Chris Angelico wrote: > If he does, it might be the final thing that gets him banned from the > mailing list. A meta-note, since I happen to have seen this email come up. I don't know about the other list moderators, but I don't personally follow every sprawling thread and post on the look-out for offensive behaviour. Can I suggest, if anyone believes that there is a case for suspending someone from the list, that they email the List Owner whose address is at the bottom of: https://mail.python.org/mailman/listinfo/python-list and point out the behaviour they believe merits suspension or a warning or whatever. We can then confer between ourselves and decide what action to take. Thanks TJG From breamoreboy at gmail.com Tue Apr 11 05:00:05 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Tue, 11 Apr 2017 02:00:05 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <27652c6d-2cb4-4f0c-9400-6aa2a3f9f855@googlegroups.com> <9bdec2c0-6050-4b55-e4a0-96fcc9af6899@lucidity.plus.com> Message-ID: On Tuesday, April 11, 2017 at 9:26:14 AM UTC+1, Tim Golden wrote: > On 11/04/2017 00:33, Chris Angelico wrote: > > If he does, it might be the final thing that gets him banned from the > > mailing list. > > A meta-note, since I happen to have seen this email come up. > > I don't know about the other list moderators, but I don't personally > follow every sprawling thread and post on the look-out for offensive > behaviour. Can I suggest, if anyone believes that there is a case for > suspending someone from the list, that they email the List Owner whose > address is at the bottom of: > > https://mail.python.org/mailman/listinfo/python-list > > and point out the behaviour they believe merits suspension or a warning > or whatever. We can then confer between ourselves and decide what action > to take. > > Thanks > > TJG While we're at it how do we go about changing this https://www.python.org/community/lists/ which states that "comp.lang.python is a high-volume Usenet open (not moderated) newsgroup for general discussions and questions about Python."? Kindest regards. Mark Lawrence. From rosuav at gmail.com Tue Apr 11 05:00:50 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Apr 2017 19:00:50 +1000 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <27652c6d-2cb4-4f0c-9400-6aa2a3f9f855@googlegroups.com> <9bdec2c0-6050-4b55-e4a0-96fcc9af6899@lucidity.plus.com> Message-ID: On Tue, Apr 11, 2017 at 6:26 PM, Tim Golden wrote: > On 11/04/2017 00:33, Chris Angelico wrote: >> >> If he does, it might be the final thing that gets him banned from the >> mailing list. > > > A meta-note, since I happen to have seen this email come up. > > I don't know about the other list moderators, but I don't personally follow > every sprawling thread and post on the look-out for offensive behaviour. Can > I suggest, if anyone believes that there is a case for suspending someone > from the list, that they email the List Owner whose address is at the bottom > of: > > https://mail.python.org/mailman/listinfo/python-list > > and point out the behaviour they believe merits suspension or a warning or > whatever. We can then confer between ourselves and decide what action to > take. > Thanks. At this stage, I was still at the "ask the poster himself to kindly refrain from being offensive", but yes, that would be the next step. (The post you're quoting is my tongue-in-cheek response to another poster's tongue-in-cheek comment poking fun at my precise language, which is exactly how this list behaves.) ChrisA From rosuav at gmail.com Tue Apr 11 05:11:45 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Apr 2017 19:11:45 +1000 Subject: Python and the need for speed In-Reply-To: <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: (Picking up one small part of your email; for the most part, I believe we are in belligerent agreement.) On Tue, Apr 11, 2017 at 6:19 PM, Steven D'Aprano wrote: > Are you aware that literal_eval is *not* the same code that the Python > interpreter uses for evaluating literals? They are kept in sync manually, > or not kept in sync as the case may be. Yes, I am; however, literal_eval starts by compiling to AST. (At least, it does in current versions. I don't know about older CPythons.) That means that, unless it gets completely rewritten, it still gets *for free* all changes to the parsing of source to AST. For example: rosuav at sikorsky:~$ python3.5 -c "import ast; print(ast.literal_eval('1_234_567'))" Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.5/ast.py", line 46, in literal_eval node_or_string = parse(node_or_string, mode='eval') File "/usr/lib/python3.5/ast.py", line 35, in parse return compile(source, filename, mode, PyCF_ONLY_AST) File "", line 1 1_234_567 ^ SyntaxError: unexpected EOF while parsing rosuav at sikorsky:~$ python3.6 -c "import ast; print(ast.literal_eval('1_234_567'))" 1234567 Did literal_eval get changed in 3.6 to add support for this? Nope. It just hands the string of text to the compiler and says "give me an AST", and then does its whitelisted walk on that. That's a pretty huge slab of work that would have to be redone if compile() were removed from the language. Yes, brand new language features (eg f-strings) have to be considered and either accepted or rejected, and yes, literal_eval does have some definitions of "literal" that aren't atoms (eg complex numbers), necessitating some slightly more complicated rules - but they're all derived from the AST. That's why a "no-runtime-compilation-allowed" Python has to either lose or manually reimplement this. I very much doubt that CPython upstream is interested in a patch to literal_eval to make it not use compile - it makes it slower, larger, and more work to maintain, merely in order to remove a dependency on something that's a core feature. Ergo TurboPython would need to be the one maintaining this alternate literal_eval, adding significantly to the initial _and_ ongoing work of the project. And that's why I said that removing compile() would mean that ast.literal_eval() would go. ChrisA From brecht__gmane at mos6581.org Tue Apr 11 05:56:06 2017 From: brecht__gmane at mos6581.org (Brecht Machiels) Date: Tue, 11 Apr 2017 11:56:06 +0200 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2017-04-11 08:19:31 +0000, Steven D'Aprano said: > On Sun, 09 Apr 2017 19:05:35 +1000, Chris Angelico wrote: > >> When people talk about making a restricted optimizable subset of Python, >> the implication (if not the explicit declaration) is that it's done >> strictly by removing, not by rewriting. > > Maybe *some* people have a naive, if not foolish, idea that all you need > to do to speed up CPython is to go through the C code and hit delete over > any functions you don't want. But that's hardly a technique that is going > to work: not only will you break features, but merely removing code > doesn't magically make the rest of the code base faster. > > At the very least, you have to re-write the code that depends on the > features you have just removed. > > If we're going to talk about speeding up Python, we ought to talk about > *serious* approaches to the problem, not the musing of random, ignorant > bloggers and other naive commentators. Hey! This random, ignorant blogger has feelings too! :-) I don't know much about interpreter or compiler design, but I never claimed that speeding up CPython would simply be a matter of deleting some code. I merely suggested that approaches different from PyPy and other JIT compilers should be explored, since I do not feel that these projects are delivering satisfactory results. I am glad to see it got this discussion started, at the very least. > some are actively maintained and > used in production by many people (cython, PyPy). Are there any statistics on PyPy usage? I'm not convinced it is being used widely. As far as I can tell, it really is only useful for server applications because of the long JIT warm-up time. > The Python ecosystem is actually quite healthy, if you need to speed up > code there are lots of solutions, and some of them are even good > solutions. There seem to be no solutions for my use case (rinohtype). DropBox and Google seem to agree that there are no good solutions, since they are moving to Go. > Nevertheless, it is interesting to discuss whether or not any > of these features will go mainstream or make it into CPython. Indeed! I initially wanted to include the following in the article, but decided it would be too controversial. But now that I've been exposed as an ignorant and naive blogger, I might as well share these thoughts. I have the feeling that a faster Python will never materialise unless the CPython core developers make performance a high priority. I understand that high performance was never a goal in CPython development (and Python language design!), but recent events (DropBox, Google) might help to reconsider that standpoint. Here's a wild idea: consider Python 3 feature-complete. Similar to how Python 3 cleaned up the unicode and other warts of Python 2, Python 4 could clean up the performance warts, but retaining the "soul" of the language. But that last part is a diffucult one, because it would lead to endless discussions of what would still be Python. So it's better to define an official "TurboPython" subset. This would also ensure backwards compatibility, but of course complicate the implementation. But who am I (or anyone) to suggest what the CPython core developers should do? I can only supply food for thought. Best regards, Brecht From bc at freeuk.com Tue Apr 11 06:20:42 2017 From: bc at freeuk.com (bartc) Date: Tue, 11 Apr 2017 11:20:42 +0100 Subject: Python and the need for speed In-Reply-To: <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/04/2017 09:19, Steven D'Aprano wrote: > On Sun, 09 Apr 2017 19:05:35 +1000, Chris Angelico wrote: > > >> When people talk about making a restricted optimizable subset of Python, >> the implication (if not the explicit declaration) is that it's done >> strictly by removing, not by rewriting. > > > Maybe *some* people have a naive, if not foolish, idea that all you need > to do to speed up CPython is to go through the C code and hit delete over > any functions you don't want. But that's hardly a technique that is going > to work: not only will you break features, but merely removing code > doesn't magically make the rest of the code base faster. > > At the very least, you have to re-write the code that depends on the > features you have just removed. > > If we're going to talk about speeding up Python, we ought to talk about > *serious* approaches to the problem, not the musing of random, ignorant > bloggers and other naive commentators. So let's look at what the experts > have done: > > PyPy: a complete re-write, with a completely different approach (JIT > compilation). A massively complicated approach, that not many fully understand. It can give some good results, but it's no longer executing byte-code. (Yet /I/ can get good performance, that can often match pypy, and still be executing a byte-code at a time. But that's because the language is smaller and less dynamic.) > WPython (alas, now more or less abandoned): a complete re-write of the > virtual machine, using 16-bit "wordcodes" instead of 8 bit "bytecodes", > nevertheless this enabled a lot of good optimizations: > http://repository.root-me.org/Programmation/Python/EN%20-%20Beyond% > 20python%20bytecode.pdf Yes, tightening up some bytecodes. But with limited results (I think up to 2x as fast based on their results). Most of the projects you've listed work with the language as it is; they do the best they can with what's already there. Removing stuff from the language could help, but that is not an option, unless you call it Python 4 and break all compatibility. At the moment, with: def fn(): print("Yes") exec(s) fn() You can't tell if that fn call will print Yes, No, or do anything else, because the exec() could have redefined it. /Adding/ things to the language might have to the way forward, but it's already groaning under the weight of add-ons. And you don't want a feature that adds clutter that is only there for performance hints. Well, a little clutter might be OK: constant pi = 3.14159 Now 'pi' is /guaranteed/ to be the value you've specified (unlike math.pi). That sort of thing can help optimisation /and/ readability. -- bartc From jorge.conrado at cptec.inpe.br Tue Apr 11 07:57:19 2017 From: jorge.conrado at cptec.inpe.br (jorge.conrado at cptec.inpe.br) Date: Tue, 11 Apr 2017 08:57:19 -0300 Subject: Mcidas format Message-ID: Hi, I have some data from the https://ghrc.nsstc.nasa.gov/hydro/search.pl. These data are the Infrared Global Geostationary Composite and the format of this is data is Mcidas. Please anyone know how I can read this data using Python. Thanks, Conrado From tlnarayana at gmail.com Tue Apr 11 08:13:44 2017 From: tlnarayana at gmail.com (tlnarayana at gmail.com) Date: Tue, 11 Apr 2017 05:13:44 -0700 (PDT) Subject: strange behaviour when writing a large amount of data on stdout In-Reply-To: <1132842994.301406.35960@g47g2000cwa.googlegroups.com> References: <7879o1t3acnq7dq9f60pspt6rhkpkbppsv@4ax.com> <43858e09.621533618@news.oz.net> <1132831346.835691.254350@z14g2000cwz.googlegroups.com> <4385ce35.637961610@news.oz.net> <1132842994.301406.35960@g47g2000cwa.googlegroups.com> Message-ID: On Thursday, November 24, 2005 at 8:06:34 PM UTC+5:30, bon... at gmail.com wrote: > Bengt Richter wrote: > > Depends on what you run ;-) Maybe how many times buggy apps die in unusual ways. > > Or worse, buggy drivers. Your car might have bad 4-wheel drive that you never used, > > so you thought your car reliable ;-) > > > Sure, no casual toys are allowed. But this is true in general, whatever > OS it is. ================================================================ Hi , I do get the same error while executing python script (test script written robotframework - issue while capturing the screenshot ) Pleas find below error: Opening browser 'firefox' to base url 'https://onbep.agra.com/ze' [ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open | FAIL | IOError: [Errno 12] Not enough space My Infra detais : Win10 64 bit , 4GB RAM Any thing to be set in OS level ? Regards, LnT From adecchi at gmail.com Tue Apr 11 08:25:23 2017 From: adecchi at gmail.com (Alejandro Decchi) Date: Tue, 11 Apr 2017 09:25:23 -0300 Subject: ldap search and Tuple Message-ID: Dear, I am writing to ask you which is the most profitable way, to get the last uidNumber. With ldap search create a tuple with a lot of values as follows: ('dc=xxx,dc=xxx,dc=xx', {'uid': ['pepe'], 'objectClass': ['inetOrgPerson', 'mailUser', 'shadowAccount', 'amavisAccount', 'shell', 'wiki'],'uidNumber': ['5555']}] I hope you can guide me and suggest any method. Thank you From tlnarayana at gmail.com Tue Apr 11 08:30:32 2017 From: tlnarayana at gmail.com (LnT) Date: Tue, 11 Apr 2017 05:30:32 -0700 (PDT) Subject: IOError: [Errno 12] Not enough space Message-ID: <8199cb7a-fded-42b1-8a76-c9a2de4d7c78@googlegroups.com> Hi, version information python 27 java version "1.8.0_111" OS -Win 10 , 64Bit , 8GB RAM , 60GB HD executing python test script (robotframework) for a we bapplication Application url will be invoked by Firefox 38.0 Please find below log: -------------------------------------------------------------------- Opening browser 'firefox' to base url 'https://onbdev.nbpa.com/zae' [ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open | FAIL | IOError: [Errno 12] Not enough space -------------------------------------------------------------------- I have cleared %TEMP% and reran the script. But still I see this. Could you please show me some Light ? Regards, LnT From steve+python at pearwood.info Tue Apr 11 09:32:24 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 11 Apr 2017 23:32:24 +1000 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <27652c6d-2cb4-4f0c-9400-6aa2a3f9f855@googlegroups.com> <9bdec2c0-6050-4b55-e4a0-96fcc9af6899@lucidity.plus.com> Message-ID: <58ecdae8$0$1602$c3e8da3$5496439d@news.astraweb.com> On Tue, 11 Apr 2017 07:00 pm, breamoreboy at gmail.com wrote: > While we're at it how do we go about changing this > https://www.python.org/community/lists/ which states that > "comp.lang.python is a high-volume Usenet open (not moderated) newsgroup > for general discussions and questions about Python."? Change it to what, and why? As it is, it is correct. comp.lang.python is a high-volume Usenet unmoderated newsgroup for general discussions related to Python. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From piet-l at pietvanoostrum.com Tue Apr 11 09:48:38 2017 From: piet-l at pietvanoostrum.com (Piet van Oostrum) Date: Tue, 11 Apr 2017 15:48:38 +0200 Subject: Temporary variables in list comprehensions References: <58730938$0$1597$c3e8da3$5496439d@news.astraweb.com> <32748803-a19e-dc76-ca4c-77f31916f05d@telenet.be> Message-ID: Vincent Vande Vyvre writes: > final = [(x, y+1) for x, y in zip(e, e)] final = [(x, x+1) for x in e] -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From breamoreboy at gmail.com Tue Apr 11 10:20:48 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Tue, 11 Apr 2017 07:20:48 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: <58ecdae8$0$1602$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <27652c6d-2cb4-4f0c-9400-6aa2a3f9f855@googlegroups.com> <9bdec2c0-6050-4b55-e4a0-96fcc9af6899@lucidity.plus.com> <58ecdae8$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tuesday, April 11, 2017 at 2:32:34 PM UTC+1, Steve D'Aprano wrote: > On Tue, 11 Apr 2017 07:00 pm, breamoreboy wrote: > > > While we're at it how do we go about changing this > > https://www.python.org/community/lists/ which states that > > "comp.lang.python is a high-volume Usenet open (not moderated) newsgroup > > for general discussions and questions about Python."? > > Change it to what, and why? > > As it is, it is correct. comp.lang.python is a high-volume Usenet > unmoderated newsgroup for general discussions related to Python. > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. So we should be welcoming back the RUE who I see is still spewing his bile? What exactly do Tim Golden and Ethan Furman moderate on? You can be pedantic about what is a newsgroup, or mailing list, or whatever, but to me they're one and the same thing. Kindest regards. Mark Lawrence. From steve+python at pearwood.info Tue Apr 11 10:29:33 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 12 Apr 2017 00:29:33 +1000 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58ece84e$0$1618$c3e8da3$5496439d@news.astraweb.com> On Tue, 11 Apr 2017 07:11 pm, Chris Angelico wrote: > (Picking up one small part of your email; for the most part, I believe > we are in belligerent agreement.) :-) [...] > Did literal_eval get changed in 3.6 to add support for this? Nope. It > just hands the string of text to the compiler and says "give me an > AST", and then does its whitelisted walk on that. That's a pretty huge > slab of work that would have to be redone if compile() were removed > from the language. Not necessarily. You are still focused on *one specific implementation*, where literal_eval() is written in pure Python and calls the compile() built-in function. But that's not the only way to solve the problem. That's implementation, not interface. Here's another implementation: Suppose the Python compiler/interpreter included a parser that takes a string and compiles it to an AST. Pretty much every modern language has that, the days of BASIC interpreters that loop over lines of source code executing them as they go are long gone. So we need something to parse source to AST, just so the interpreter can interpret the source code. It just needs to exist. It doesn't have to be a public part of the language. So the interpreter relies on this internal "compile-to-AST". And literal_eval() can do exactly the same thing, if it is part of the interpreter. There's no reason why literal_eval() must be written in pure Python. It can be implemented any way you like, anywhere you like. Obviously this requires hooking literal_eval() into the interpreter as a built-in command. Maybe its even a single op-code in the (Turbo)Python virtual machine. We can make the op-codes as complex as we need! The existing op-codes range from the incredibly simple: POP_TOP Removes the top-of-stack (TOS) item. to quite complex: SETUP_WITH(delta) This opcode performs several operations before a with block starts. First, it loads __exit__() from the context manager and pushes it onto the stack for later use by WITH_CLEANUP. Then, __enter__() is called, and a finally block pointing to delta is pushed. Finally, the result of calling the enter method is pushed onto the stack. The next opcode will either ignore it (POP_TOP), or store it in (a) variable(s) (STORE_FAST, STORE_NAME, or UNPACK_SEQUENCE). https://docs.python.org/3/library/dis.html so there is absolutely no reason why literal_eval() cannot be a built-in function that uses the exact same parser as the interpreter, if that's important to you. Just because literal_eval() has access to the interpreter's parser, doesn't mean that there has to be a compile() builtin that can handle arbitrary source code. > That's why a "no-runtime-compilation-allowed" Python has to either > lose or manually reimplement this. I very much doubt that CPython > upstream is interested in a patch to literal_eval to make it not use > compile - it makes it slower, larger, and more work to maintain, > merely in order to remove a dependency on something that's a core > feature. Nobody is talking about CPython removing the compile() builtin. But if TurboPython wants to remove the compile() builtin, AND it becomes super-popular -- maybe Google and Facebook and Apple decide to throw away Go, PHP and Swift and move exclusively to Python *wink* -- then perhaps Python 4.5 or 5.2 will actually include a switch to disable compile(), exec() and eval() and enable a bunch of optimizations. Anything is possible, if enough people want it. *If*. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From saxri89 at gmail.com Tue Apr 11 10:36:28 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Tue, 11 Apr 2017 07:36:28 -0700 (PDT) Subject: django user images Message-ID: hello if i want to create a query in django with to take all images and preview that list in html like easy work. but if want in html page preview only the personal images where login user what changes i need in my code ? model.py class MyModel(models.Model): user = models.ForeignKey(User, unique=True) photo = models.ImageField(upload_to='images') views.py class BasicUploadView(request): photos_list = Photo.objects.all() return render(request, 'photos/basic_upload/index.html', {'photos': photos_list}) html page : {% for photo in photos %} {{ photo.file.name }} {% endfor %} From Jack at nichesoftsolutions.com Tue Apr 11 10:46:30 2017 From: Jack at nichesoftsolutions.com (Jack at nichesoftsolutions.com) Date: Tue, 11 Apr 2017 07:46:30 -0700 (PDT) Subject: Need webFOCUS Business Intelligence Developer Message-ID: <140be24f-4ec7-4420-a105-16cba9e6c366@googlegroups.com> Hi , Greetings from Niche software solutions . ?We have a new job opening for the following position, please find the job? ?description below.Please share your most recent updated resume to move forward into the process, If you are not interested please let me know if you have any friends or colleagues that who would be interested in this position Job Title: webFOCUS Business Intelligence Developer Location : Pittsburgh, PA Duration : 6 Months Interview Mode ? Phone interview is a must & Skype or face to face interview possible to follow Need ---- 3 to 5 years' experience in the design, administration, programming, and support of an enterprise reporting environment using the WebFOCUS business intelligence platform Job Description: .Bachelor's degree in Computer Science, Information Systems, or related discipline preferred; equivalent experience is acceptable .Develop and maintain reporting modules utilizing the developer and reporting tool kits within WebFOCUS .Oracle SQL coding skills with particular attention given to detail and accuracy .Experience in Java, JavaScript, jQuery, AJAX, HTML, XML, JSON, CSS and Visual Basic is preferred .Utilize the administrative tools within WebFOCUS to provide end users with ad hoc and personalized reporting while maintaining a secure and cohesive environment. .Thorough understanding of the WebFOCUS product architecture Best Regards, Jack Stutter Niche Soft Solutions INC. Direct: +1503-536-2043 Email id: jack at nichesoftsolutions.com From Jack at nichesoftsolutions.com Tue Apr 11 10:49:25 2017 From: Jack at nichesoftsolutions.com (Jack at nichesoftsolutions.com) Date: Tue, 11 Apr 2017 07:49:25 -0700 (PDT) Subject: Need webFOCUS Business Intelligence Developer Message-ID: Hi , Greetings from Niche software solutions . ?We have a new job opening for the following position, please find the job? ?description below.Please share your most recent updated resume to move forward into the process, If you are not interested please let me know if you have any friends or colleagues that who would be interested in this position Job Title: webFOCUS Business Intelligence Developer Location : Pittsburgh, PA Duration : 6 Months Interview Mode ? Phone interview is a must & Skype or face to face interview possible to follow Need ---- 3 to 5 years' experience in the design, administration, programming, and support of an enterprise reporting environment using the WebFOCUS business intelligence platform Job Description: .Bachelor's degree in Computer Science, Information Systems, or related discipline preferred; equivalent experience is acceptable .Develop and maintain reporting modules utilizing the developer and reporting tool kits within WebFOCUS .Oracle SQL coding skills with particular attention given to detail and accuracy .Experience in Java, JavaScript, jQuery, AJAX, HTML, XML, JSON, CSS and Visual Basic is preferred .Utilize the administrative tools within WebFOCUS to provide end users with ad hoc and personalized reporting while maintaining a secure and cohesive environment. .Thorough understanding of the WebFOCUS product architecture Best Regards, Jack Stutter Niche Soft Solutions INC. Direct: +1503-536-2043 Email id: jack at nichesoftsolutions.com From steve+python at pearwood.info Tue Apr 11 10:56:33 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 12 Apr 2017 00:56:33 +1000 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> On Tue, 11 Apr 2017 07:56 pm, Brecht Machiels wrote: > On 2017-04-11 08:19:31 +0000, Steven D'Aprano said: >> If we're going to talk about speeding up Python, we ought to talk about >> *serious* approaches to the problem, not the musing of random, ignorant >> bloggers and other naive commentators. > > Hey! This random, ignorant blogger has feelings too! :-) Hi, and welcome! Sorry, I wasn't *specifically* referring to you, except in the sense that you aren't a compiler expert. The truth is, all of us in this discussion -- including me -- are "random, ignorant commentators". I don't believe that any of us are experts at writing compilers. Bart is a possible exception, for some definition of "expert" -- he claims to have written a quite fast, moderately dynamic language, but nobody else (that I know of) has used it. And no offence to Bart, but from his comments and questions on the list, I think it is fair to say that whatever knowledge he has on language design was probably state of the art thirty years ago. Bart sometimes expresses surprise and confusion over concepts which are common in languages like Javascript, Python, Perl, Ruby etc. These are not young languages! Python is over 20 years old, Perl is even older. So I suspect Bart's knowledge is probably from the 70s or 80s? That doesn't mean it is irrelevant. But it does mean that there's a lot he is unfamiliar with. > I don't know much about interpreter or compiler design, but I never > claimed that speeding up CPython would simply be a matter of deleting > some code. No, that seems to be Chris' interpretation. My interpretation is that it is "common sense" that it needs more than just pressing delete on a few features to speed up an interpreter, and therefore for casual discussion (as in a blog post) it goes without saying that removing features is only the first step, not the only step. > I merely suggested that approaches different from PyPy and > other JIT compilers should be explored, since I do not feel that these > projects are delivering satisfactory results. I am glad to see it got > this discussion started, at the very least. I agree! I think that its wonderful that people and companies are willing to invest time and money exploring the options. But I also think that while making Python faster is a good goal to have, it seems that for most people, and most companies, it isn't their priority. For a company, if it costs $30,000 to build an experimental TurboPython which may or may not solve your problems, and $40,000 to migrate to Go or Javascript or something which definitely will (you hope...) solve your problem, why wouldn't you do so? Well, maybe because your development costs for using Go will be higher. Maybe. But will they be higher than your maintenance costs for TurboPython? >> some are actively maintained and >> used in production by many people (cython, PyPy). > > Are there any statistics on PyPy usage? I'm not convinced it is being > used widely. As far as I can tell, it really is only useful for server > applications because of the long JIT warm-up time. You are correct: PyPy is not designed for short scripts and other applications. The JIT warm-up is significant. >> The Python ecosystem is actually quite healthy, if you need to speed up >> code there are lots of solutions, and some of them are even good >> solutions. > > There seem to be no solutions for my use case (rinohtype). Have you tried Nuitka? > DropBox and > Google seem to agree that there are no good solutions, since they are > moving to Go. That's a good solution! Maybe we should be writing extensions in Go, instead of C. Or for maths-heavy work, using extensions written in Julia. While there are advantages to using a single language, it is silly to artificially limit yourself to a single language if you don't need to. Python started life as a "glue language" for C and Fortran, and there are projects and implementations like Jython for example that specifically exist so people can call Java libraries from Python. A hybrid code base where the heavy lifting is done in a fast but annoying language, and the glue and infrastructure is written in Python, is a good solution for many problems. >> Nevertheless, it is interesting to discuss whether or not any >> of these features will go mainstream or make it into CPython. > > Indeed! I initially wanted to include the following in the article, but > decided it would be too controversial. But now that I've been exposed > as an ignorant and naive blogger, I might as well share these thoughts. > > I have the feeling that a faster Python will never materialise unless > the CPython core developers make performance a high priority. I think you are both right and wrong. You are right in the sense that none of the companies exploring Python optimizers have wanted to carry the maintenance burden themselves. Their aim is to prove the concept, then push it back into CPython and have the core devs maintain it. But you're also wrong, in the sense that you're focused on *revolutionary* speed-ups rather than *evolutionary* optimizations. CPython is faster today than it was in version 1.5, despite doing MUCH more. Python continues to shave slow code off and improve performance. No, this isn't likely to make Python ten times faster, but its performance does incrementally increase. > I > understand that high performance was never a goal in CPython > development (and Python language design!), but recent events (DropBox, > Google) might help to reconsider that standpoint. *shrug* It isn't as if high-performance is a requirement for all code. And it isn't as if Python is in any serious risk of losing popularity. No language can expect to be popular forever. Eventually Python will be as obsolete as or niche as COBOL, Tcl or ABC. But that day is not now. > Here's a wild idea: consider Python 3 feature-complete. [...] I think that will conflict with the many, many people who want Python to have more features, and care more about them than speed. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From lew.pitcher at digitalfreehold.ca Tue Apr 11 11:24:33 2017 From: lew.pitcher at digitalfreehold.ca (Lew Pitcher) Date: Tue, 11 Apr 2017 11:24:33 -0400 Subject: Pound sign problem References: <679200651.679871.1491830236809.ref@mail.yahoo.com> <679200651.679871.1491830236809@mail.yahoo.com> <58ec319d$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > On Tue, 11 Apr 2017 12:50 am, Lew Pitcher wrote: > >> David Shi wrote: >> >>> In the data set, pound sign escape appears: >>> u'price_currency': u'\xa3', u'price_formatted': u'\xa3525,000', > > That looks like David is using Python 2. > >>> When using table.to_csv after importing pandas as pd, an error message >>> persists as follows: UnicodeEncodeError: 'ascii' codec can't encode >>> character u'\xa3' in position 0: ordinal not in range(128) >> >> There is no "pound sign" in ASCII[1]. Try changing your target encoding >> to something other than ASCII. > > Please don't encourage the use of old legacy encodings. I wonder if you actually read my reply. What in "Try changing your target encoding to something other than ASCII" is encouragement to use "old legacy encodings"? > In 2017, unless you are reading from old legacy files created using a > non-Unicode encoding, you should just use UTF-8. Thanks for your opinion. My opinion differs. -- Lew Pitcher "In Skills, We Trust" PGP public key available upon request From mail at timgolden.me.uk Tue Apr 11 11:25:43 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 11 Apr 2017 16:25:43 +0100 Subject: Moderating the list [was: Python and the need for speed] In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <27652c6d-2cb4-4f0c-9400-6aa2a3f9f855@googlegroups.com> <9bdec2c0-6050-4b55-e4a0-96fcc9af6899@lucidity.plus.com> <58ecdae8$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9fac840a-165f-789a-6631-ed913a1cdcf6@timgolden.me.uk> On 11/04/2017 15:20, breamoreboy at gmail.com wrote: > On Tuesday, April 11, 2017 at 2:32:34 PM UTC+1, Steve D'Aprano > wrote: >> On Tue, 11 Apr 2017 07:00 pm, breamoreboy wrote: >> >>> While we're at it how do we go about changing this >>> https://www.python.org/community/lists/ which states that >>> "comp.lang.python is a high-volume Usenet open (not moderated) >>> newsgroup for general discussions and questions about Python."? >> >> Change it to what, and why? >> >> As it is, it is correct. comp.lang.python is a high-volume Usenet >> unmoderated newsgroup for general discussions related to Python. >> >> -- Steve ?Cheer up,? they said, ?things could be worse.? So I >> cheered up, and sure enough, things got worse. > > What exactly do Tim Golden and Ethan Furman moderate on? We (and the other moderators) exactly moderate the mailing list. I have no authority over the newsgroup, and I don't know who does. > You > can be pedantic about what is a newsgroup, or mailing list, or > whatever, but to me they're one and the same thing. This is something which can cause contention as people from either side (mailing list <-> newsgroup) can be completely unaware that they're being copied to the other. However, it's simply a technical fact: the thing which we moderate is the mailing list. We can control which posts make it through from the newsgroup by blocking them at the gateway. But the posts will continue to appear on comp.lang.python which is, as the description says, unmoderated. TJG From jtrtransport at gmail.com Tue Apr 11 11:28:59 2017 From: jtrtransport at gmail.com (John Ralph) Date: Tue, 11 Apr 2017 08:28:59 -0700 (PDT) Subject: Mcidas format In-Reply-To: References: Message-ID: <4b609d35-0514-4d65-a072-6f4ade89af6c@googlegroups.com> Can you provide a sample of the data and its format, please? From rosuav at gmail.com Tue Apr 11 11:29:57 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Apr 2017 01:29:57 +1000 Subject: Pound sign problem In-Reply-To: References: <679200651.679871.1491830236809.ref@mail.yahoo.com> <679200651.679871.1491830236809@mail.yahoo.com> <58ec319d$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 12, 2017 at 1:24 AM, Lew Pitcher wrote: > > What in "Try changing your target encoding to something other than ASCII" is > encouragement to use "old legacy encodings"? > >> In 2017, unless you are reading from old legacy files created using a >> non-Unicode encoding, you should just use UTF-8. > > Thanks for your opinion. My opinion differs. So what encoding *do* you recommend, and why is it better than UTF-8? ChrisA From bc at freeuk.com Tue Apr 11 11:31:13 2017 From: bc at freeuk.com (bartc) Date: Tue, 11 Apr 2017 16:31:13 +0100 Subject: Python and the need for speed In-Reply-To: <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <%E6HA.723559$fZ.128741@fx41.am4> On 11/04/2017 15:56, Steve D'Aprano wrote: > The truth is, all of us in this discussion -- including me -- are "random, > ignorant commentators". I don't believe that any of us are experts at > writing compilers. > > Bart is a possible exception, for some definition of "expert" -- he claims > to have written a quite fast, moderately dynamic language, but nobody else > (that I know of) has used it. > > And no offence to Bart, but from his comments and questions on the list, I > think it is fair to say that whatever knowledge he has on language design > was probably state of the art thirty years ago. Bart sometimes expresses > surprise and confusion over concepts which are common in languages like > Javascript, Python, Perl, Ruby etc. These are not young languages! Python > is over 20 years old, Perl is even older. So I suspect Bart's knowledge is > probably from the 70s or 80s? Yes, about then. But it means I have a lot of experience getting this stuff to work briskly on limited hardware, and I can identify bloat and inefficiency. (My latest project is a C compiler, which currently generates asm source (later it will run from source like Python). But it takes 50ms to process a 30Kloc file that then takes 90 seconds, nearly 2000 times longer, to assemble into .obj. That sounds like there's something wrong to me with that assembler. So I think I can question the efficiency of other people's software. My experience may be out of date but that 50ms - half of which is generating that damned asm source - was from yesterday!) However, when the obstacle is a particular language design then the options are more limited. I think CPython does remarkably well given the language. And the official byte-code (which can do with tweaking as that Wpython project demonstrated). -- bartc From lew.pitcher at digitalfreehold.ca Tue Apr 11 12:23:54 2017 From: lew.pitcher at digitalfreehold.ca (Lew Pitcher) Date: Tue, 11 Apr 2017 12:23:54 -0400 Subject: Pound sign problem References: <679200651.679871.1491830236809.ref@mail.yahoo.com> <679200651.679871.1491830236809@mail.yahoo.com> <58ec319d$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > On Wed, Apr 12, 2017 at 1:24 AM, Lew Pitcher > wrote: >> >> What in "Try changing your target encoding to something other than ASCII" >> is encouragement to use "old legacy encodings"? >> >>> In 2017, unless you are reading from old legacy files created using a >>> non-Unicode encoding, you should just use UTF-8. >> >> Thanks for your opinion. My opinion differs. > > So what encoding *do* you recommend, and why is it better than UTF-8? I recommend whatever encoding is appropriate for the output. That's not up to you or me to decide; that's a question that only the OP can answer. (Imagine, python on an IBM Zseries running ZOS; the "native" characterset is one of the EBCDIC variants. Would UTF-8 be a better choice there? ) -- Lew Pitcher "In Skills, We Trust" PGP public key available upon request From steve+python at pearwood.info Tue Apr 11 12:29:09 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 12 Apr 2017 02:29:09 +1000 Subject: Pound sign problem References: <679200651.679871.1491830236809.ref@mail.yahoo.com> <679200651.679871.1491830236809@mail.yahoo.com> <58ec319d$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58ed0457$0$1606$c3e8da3$5496439d@news.astraweb.com> On Wed, 12 Apr 2017 01:24 am, Lew Pitcher wrote: [...] >>> There is no "pound sign" in ASCII[1]. Try changing your target encoding >>> to something other than ASCII. >> >> Please don't encourage the use of old legacy encodings. > > I wonder if you actually read my reply. Of course I did. > What in "Try changing your target encoding to something other than ASCII" > is encouragement to use "old legacy encodings"? The fact that "something other than ASCII" includes dozens of old legacy encodings, including the most obvious one for Western Europeans coming from a Windows environment: Latin-1. There are only three practical choices for text: ASCII, Unicode, and legacy encodings (or "code pages", as many people know them). TRON is effectively only available in Japan, and even there hardly anyone uses it. (And besides, Python doesn't support TRON.) You've (rightly) eliminated ASCII, as the pound sign isn't available. Python doesn't support TRON, so your instruction to the OP is logically equivalent to "use Unicode or a legacy encoding". Its the second half of that which I am objecting to. >> In 2017, unless you are reading from old legacy files created using a >> non-Unicode encoding, you should just use UTF-8. > > Thanks for your opinion. My opinion differs. What would you suggest then, if not UTF-8? My personal favourite legacy encoding is MacRoman, but I wouldn't recommend anyone use it except to interoperate with legacy Mac applications and/or data from the 80s and 90s. What's your recommendation? "Anything but ASCII"? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Tue Apr 11 12:50:12 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 12 Apr 2017 02:50:12 +1000 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <27652c6d-2cb4-4f0c-9400-6aa2a3f9f855@googlegroups.com> <9bdec2c0-6050-4b55-e4a0-96fcc9af6899@lucidity.plus.com> <58ecdae8$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58ed0946$0$1593$c3e8da3$5496439d@news.astraweb.com> On Wed, 12 Apr 2017 12:20 am, breamoreboy at gmail.com wrote: > So we should be welcoming back the RUE who I see is still spewing his > bile? The only one I see "spewing bile" is you. wxjmfauth's ignorant, stupid opinions about Python's handling of Unicode are just silly. Why are you taking it so personally? There's no need to invent a sarcastic name for him, or to falsely accuse him of "spewing bile", or to keep going on and on and on about him every time he pops his head up. > You can be pedantic about what is a newsgroup, or mailing list, or > whatever, but to me they're one and the same thing. Like wxjmfauth, we're all entitled to hold whatever ignorant and silly opinions we like, there's no law against it. (Acting on, or expressing, those opinions may be treated differently.) But the fact is that the mailing list and newsgroup are NOT one and the same thing, and never will be. This is a true fact, not a false fact. They cannot be the same thing: they use different technologies, with different organising principles, and are controlled by different people. The mailing list is controlled by the PSF; the newsgroup is not. (It's arguable whether *anyone* controls the newsgroup, except in the sense that individual system administrators on individual News servers have some power over what passes through their own server. But that's it.) http://www.ou.edu/research/electron/internet/use-faq.htm I don't know why you're so uptight over jmf, but like it or not, there's nothing you can do to keep him of Usenet. Deal with it. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From python.list at tim.thechases.com Tue Apr 11 12:55:06 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 11 Apr 2017 11:55:06 -0500 Subject: Pound sign problem In-Reply-To: <58ed0457$0$1606$c3e8da3$5496439d@news.astraweb.com> References: <679200651.679871.1491830236809.ref@mail.yahoo.com> <679200651.679871.1491830236809@mail.yahoo.com> <58ec319d$0$1621$c3e8da3$5496439d@news.astraweb.com> <58ed0457$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20170411115506.30b6847e@bigbox.christie.dr> On 2017-04-12 02:29, Steve D'Aprano wrote: > >> In 2017, unless you are reading from old legacy files created > >> using a non-Unicode encoding, you should just use UTF-8. > > > > Thanks for your opinion. My opinion differs. > > What would you suggest then, if not UTF-8? > > My personal favourite legacy encoding is MacRoman, but I wouldn't > recommend anyone use it except to interoperate with legacy Mac > applications and/or data from the 80s and 90s. > > What's your recommendation? "Anything but ASCII"? Heh, how about "Unicode as ASCII-compatible-Python-strings"? ;-) Got this from Peter Otten a while back in response to my request for functionality something like this. http://www.mail-archive.com/python-list at python.org/msg420100.html -tkc $ cat codecs_mynamereplace.py # -*- coding: utf-8 -*- import codecs import unicodedata try: codecs.namereplace_errors except AttributeError: print("using mynamereplace") def mynamereplace(exc): return u"".join( "\\N{%s}" % unicodedata.name(c) for c in exc.object[exc.start:exc.end] ), exc.end codecs.register_error("namereplace", mynamereplace) print(u"ma?ana".encode("ascii", "namereplace").decode()) $ python3.5 codecs_mynamereplace.py ma\N{LATIN SMALL LETTER N WITH TILDE}ana $ python3.4 codecs_mynamereplace.py using mynamereplace ma\N{LATIN SMALL LETTER N WITH TILDE}ana $ python2.7 codecs_mynamereplace.py using mynamereplace ma\N{LATIN SMALL LETTER N WITH TILDE}ana From irmen.NOSPAM at xs4all.nl Tue Apr 11 13:11:26 2017 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Tue, 11 Apr 2017 19:11:26 +0200 Subject: IOError: [Errno 12] Not enough space In-Reply-To: <8199cb7a-fded-42b1-8a76-c9a2de4d7c78@googlegroups.com> References: <8199cb7a-fded-42b1-8a76-c9a2de4d7c78@googlegroups.com> Message-ID: <58ed0e3c$0$829$e4fe514c@news.xs4all.nl> On 11-4-2017 14:30, LnT wrote: > Hi, > > version information > > python 27 Please be more precise, there is no Python 27. (Yeah it is clear you meant 2.7 but still) > java version "1.8.0_111" That should not be relevant > OS -Win 10 , 64Bit , 8GB RAM , 60GB HD 60 GB is not a lot of space for windows... > executing python test script (robotframework) for a we bapplication > Application url will be invoked by Firefox 38.0 > > Please find below log: > -------------------------------------------------------------------- > Opening browser 'firefox' to base url 'https://onbdev.nbpa.com/zae' > [ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open > | FAIL | > IOError: [Errno 12] Not enough space > -------------------------------------------------------------------- That's not much information. Is there really not anything else in the log? Like a traceback, that may give some clues what the application is doing when it is running out of disk space? > > I have cleared %TEMP% and reran the script. > But still I see this. > > Could you please show me some Light ? > Based on the info you provided, the only solution I can think of is: free more space. Something in your application is trying to write stuff and there's simply not enough space on the disk to do so. -i From rosuav at gmail.com Tue Apr 11 13:26:24 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Apr 2017 03:26:24 +1000 Subject: Pound sign problem In-Reply-To: References: <679200651.679871.1491830236809.ref@mail.yahoo.com> <679200651.679871.1491830236809@mail.yahoo.com> <58ec319d$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 12, 2017 at 2:23 AM, Lew Pitcher wrote: > Chris Angelico wrote: > >> On Wed, Apr 12, 2017 at 1:24 AM, Lew Pitcher >> wrote: >>> >>> What in "Try changing your target encoding to something other than ASCII" >>> is encouragement to use "old legacy encodings"? >>> >>>> In 2017, unless you are reading from old legacy files created using a >>>> non-Unicode encoding, you should just use UTF-8. >>> >>> Thanks for your opinion. My opinion differs. >> >> So what encoding *do* you recommend, and why is it better than UTF-8? > > I recommend whatever encoding is appropriate for the output. That's not up > to you or me to decide; that's a question that only the OP can answer. > > (Imagine, python on an IBM Zseries running ZOS; the "native" characterset is > one of the EBCDIC variants. Would UTF-8 be a better choice there? ) So if the OP needed to print out a number, would you take a similarly spineless approach and say that only the OP can decide what numeric base to use? Does every fledgeling programmer need to understand about archaic systems where you needed to use BCD for your numbers? EBCDIC derives from BCD, where a single decimal digit was encoded in four bits... and I'm sure you could name systems even less popular, used on important systems back in the 1960s or so. Does a modern Python programmer need to look through all of those possible ways to represent numbers? NO. Today's programmer should need to know about very few ways to represent numbers, in priority order: 1) Decimal digits represented in ASCII 2) Packed binary, network byte order 3) Packed binary, little-endian. A new programmer shouldn't need to worry about anything other than decimal digits, in fact. Of course other systems do exist, like the MIDI "variable length integer" that packs seven bits into a byte and then uses the high bit as a continuation marker; or IEEE 80-bit floating point, or a multi-limb format like GMP uses, but until you actually need to work with it, you don't need to know about it. Just use the one most obvious encoding. UTF-8 for all text. ChrisA From tjreedy at udel.edu Tue Apr 11 13:26:54 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 11 Apr 2017 13:26:54 -0400 Subject: Mcidas format In-Reply-To: References: Message-ID: <51e3082b-b256-41fd-2dfa-ded37d41aa84@udel.edu> On 4/11/2017 7:57 AM, jorge.conrado at cptec.inpe.br wrote: > I have some data from the https://ghrc.nsstc.nasa.gov/hydro/search.pl. > These data are the Infrared Global Geostationary Composite and > the format of this is data is Mcidas. Please anyone know how I can read > this data using Python. Search 'python mcidas'. Google's first few responses suggest two approaches: 1. Python interface to existing mcidas viewers. 2. Mcidas plugin for pillow (image manipulation package) that defines class McIdasImageFile(ImageFile.ImageFile) https://github.com/python-pillow/Pillow/blob/master/PIL/McIdasImagePlugin.py It reads and decodes the 256 byte header and defines attributes needed for pillow to read the data. It handles three different mcidas formats. There appears to be an mcidas user group. -- Terry Jan Reedy From no.email at nospam.invalid Tue Apr 11 13:39:51 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 11 Apr 2017 10:39:51 -0700 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87a87mn8rc.fsf@nightsong.com> Steven D'Aprano writes: > If we're going to talk about speeding up Python, we ought to talk about > *serious* approaches to the problem, not the musing of random, ignorant > bloggers and other naive commentators. So let's look at what the experts > have done: .... [list snipped] You might look at MicroPython too (micropython.org). A fairly complete Python 3 implementation with some ahead-of-time compiling, no fancy JIT. Completely breaks the Python C API though. Or you could look at the past 50 years(!) of Lisp and Scheme compilers some of which produce very good code, ask what Python features can't be straightforwardly transliterated into Lisp to use those compilers, then ask whether those features are really important to the average Python user. I don't even think eval is an obstacle. Lots of Lisp systems implement eval by handing expression off to the compiler and then running the compiled code, maybe with a bit of caching like Python and compiled regexps. I remember thinking PyPy made a mistake in trying to preserve all of Python's dynamism, and Python 3 made a mistake in trying to preserve so much compatibility with Python 2 while still breaking minor things. I thought PyPy should have been "TurboPython" that broke lots more Python 2 stuff than Python 3 did, but was as you say maybe 20x faster. Then Python 3 could have been skipped. For a while I thought something like that could become Python 4, but the readout of Python 3 seems to be that its slow uptake came from those minor breaks, so Python 4 won't have even the slightest incompatibility with Python 3 code. I still do my everyday stuff in Python and I'd like to get more conversant with stuff like numpy, but it feels like an old-fashioned language these days. From steve+python at pearwood.info Tue Apr 11 14:06:02 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 12 Apr 2017 04:06:02 +1000 Subject: Pound sign problem References: <679200651.679871.1491830236809.ref@mail.yahoo.com> <679200651.679871.1491830236809@mail.yahoo.com> <58ec319d$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58ed1b0d$0$1593$c3e8da3$5496439d@news.astraweb.com> On Wed, 12 Apr 2017 02:23 am, Lew Pitcher wrote: > I recommend whatever encoding is appropriate for the output. There are multiple encodings that are appropriate for ASCII + pound sign. How should the OP choose between them without guidance? If he understood the issue well enough to make an informed decision, he wouldn't have needed to ask for help. > That's not up > to you or me to decide; that's a question that only the OP can answer. Nobody is asking you to *decide*. But you can make a recommendation. Do you really think that the OP is capable of making an informed decision about this issue on his own? If he was, he wouldn't have needed to ask for help solving this problem in the first place. If you're going to help, actually *help*, and don't just pretend to help: "Hi, I'm a stranger in town and I'm trying to get to the post office. What's the best way for me to get there please?" "Well, that depends on whether you're flying the Space Shuttle, travelling by sailing ship, dog sled, or advanced alien hyperdrive. You should take whatever route is most appropriate for your transportation. You're welcome." I'm sorry to be so negative when you're only trying to be helpful, but I too have been on the receiving end of poor-quality "advice" that leaves me just as much in the dark as before I asked the question, so I'm quite sensitive to it. "What should I do here?" "Do whatever you see fit." (I'm not specifically referring to this community, just making a general observation.) > (Imagine, python on an IBM Zseries running ZOS; I can imagine many unlikely things that have come to pass, but that's not one of them. The OP is using Pandas, which requires Python 2.7 or better. https://pypi.python.org/pypi/pandas There is an unofficial, unmaintained(?), third-party port of Python 2.4 to Z/OS, which appears to have had no attention for more than a decade. http://www.teaser.fr/~jymengant/mvspython/mvsPythonPort.html I suppose it is just barely within the realm of possibility that the OP has hacked together his own port of Python 2.7 and Pandas to Z/OS. If so, he'd have already had to deal with some much bigger problems relating to ASCII versus EBCDIC, and if he managed to solve that, it's unlikely that he'd be puzzled by a pound sign in his data. But... even if I grant you your scenario that he's running on Big Iron, that is irrelevant! Using Unicode for his data files is still the better idea. > the "native" characterset > is one of the EBCDIC variants. Would UTF-8 be a better choice there? ) Yes it would. The OP is using Unicode strings so regardless of the OS's native character set, it is better to use Unicode rather than some 8-bit encoding. Today the OP needs a pound sign. Tomorrow he may need a Greek ?, yen sign, CJK ideograph, or Arabic character. Possibly all in the same document. Using legacy encodings, whether based on EBCDIC or ASCII, should be avoided. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From grant.b.edwards at gmail.com Tue Apr 11 14:42:03 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 11 Apr 2017 18:42:03 +0000 (UTC) Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> Message-ID: On 2017-04-11, Paul Rubin wrote: > You might look at MicroPython too (micropython.org). A fairly complete > Python 3 implementation with some ahead-of-time compiling, no fancy > JIT. Completely breaks the Python C API though. I didn't know there was such a thing as "The Python C API". Or do you just mean that the C API is different than that chosen by the developers of https://github.com/python/cpython? -- Grant Edwards grant.b.edwards Yow! I'm DESPONDENT ... I at hope there's something gmail.com DEEP-FRIED under this miniature DOMED STADIUM ... From rosuav at gmail.com Tue Apr 11 14:54:48 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Apr 2017 04:54:48 +1000 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> Message-ID: On Wed, Apr 12, 2017 at 4:42 AM, Grant Edwards wrote: > On 2017-04-11, Paul Rubin wrote: > >> You might look at MicroPython too (micropython.org). A fairly complete >> Python 3 implementation with some ahead-of-time compiling, no fancy >> JIT. Completely breaks the Python C API though. > > I didn't know there was such a thing as "The Python C API". > > Or do you just mean that the C API is different than that chosen by > the developers of https://github.com/python/cpython? Do you mean this? https://docs.python.org/3/c-api/intro.html ChrisA From grant.b.edwards at gmail.com Tue Apr 11 15:19:37 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 11 Apr 2017 19:19:37 +0000 (UTC) Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> Message-ID: On 2017-04-11, Chris Angelico wrote: > On Wed, Apr 12, 2017 at 4:42 AM, Grant Edwards > wrote: >> On 2017-04-11, Paul Rubin wrote: >> >>> You might look at MicroPython too (micropython.org). A fairly complete >>> Python 3 implementation with some ahead-of-time compiling, no fancy >>> JIT. Completely breaks the Python C API though. >> >> I didn't know there was such a thing as "The Python C API". >> >> Or do you just mean that the C API is different than that chosen by >> the developers of https://github.com/python/cpython? > > Do you mean this? > > https://docs.python.org/3/c-api/intro.html I think so. That's the C API for one particlar implementation of Python "CPython", right? There is no "Python" C API specified as part of the language definition is there? -- Grant Edwards grant.b.edwards Yow! LOOK!! Sullen at American teens wearing gmail.com MADRAS shorts and "Flock of Seagulls" HAIRCUTS! From rosuav at gmail.com Tue Apr 11 15:24:06 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Apr 2017 05:24:06 +1000 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> Message-ID: On Wed, Apr 12, 2017 at 5:19 AM, Grant Edwards wrote: > On 2017-04-11, Chris Angelico wrote: >> On Wed, Apr 12, 2017 at 4:42 AM, Grant Edwards >> wrote: >>> On 2017-04-11, Paul Rubin wrote: >>> >>>> You might look at MicroPython too (micropython.org). A fairly complete >>>> Python 3 implementation with some ahead-of-time compiling, no fancy >>>> JIT. Completely breaks the Python C API though. >>> >>> I didn't know there was such a thing as "The Python C API". >>> >>> Or do you just mean that the C API is different than that chosen by >>> the developers of https://github.com/python/cpython? >> >> Do you mean this? >> >> https://docs.python.org/3/c-api/intro.html > > I think so. That's the C API for one particlar implementation of > Python "CPython", right? > > There is no "Python" C API specified as part of the language > definition is there? Oh, I see what you mean. That is indeed correct - there is no language-level API specification - but it's linguistically redundant to say "the CPython C API", so it's often not said that way. ChrisA From grant.b.edwards at gmail.com Tue Apr 11 15:47:47 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 11 Apr 2017 19:47:47 +0000 (UTC) Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> Message-ID: On 2017-04-11, Chris Angelico wrote: >>> Do you mean this? >>> >>> https://docs.python.org/3/c-api/intro.html >> >> I think so. That's the C API for one particlar implementation of >> Python "CPython", right? >> >> There is no "Python" C API specified as part of the language >> definition is there? > > Oh, I see what you mean. > > That is indeed correct - there is no language-level API specification > - but it's linguistically redundant to say "the CPython C API", so > it's often not said that way. If there are now other Python implementations (e.g. MicroPython) with C APIs that differ from CPython, then it seems like it is no longer redundant to say "the CPython API". -- Grant Edwards grant.b.edwards Yow! I know how to do at SPECIAL EFFECTS!! gmail.com From rosuav at gmail.com Tue Apr 11 15:55:51 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Apr 2017 05:55:51 +1000 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> Message-ID: On Wed, Apr 12, 2017 at 5:47 AM, Grant Edwards wrote: > > If there are now other Python implementations (e.g. MicroPython) with > C APIs that differ from CPython, then it seems like it is no longer > redundant to say "the CPython API". I don't think there are. They either implement (some subset of) the CPython API, or they're not in C (eg Jython), or they don't offer an extension API. I don't know of anything else that offers a C API. ChrisA From abhishek.physics01 at gmail.com Tue Apr 11 16:35:28 2017 From: abhishek.physics01 at gmail.com (Abhishek Kumar) Date: Tue, 11 Apr 2017 13:35:28 -0700 (PDT) Subject: Inclusion of of python and python libraries licensed with BSD- 3 clause license in proprietary software Message-ID: Hello, I tried finding the answer but even the lawyers in my town have no idea about it and searching the web leaved me puzzled. I am planning to make a software in python which will include libraries licensed under BSD- 3 clause. Can I sell this software under proprietary license and legally inhibit redistribution by users under my own license. Also if you know anyone who holds knowledge in this field then please do let me know.. Your response will be really helpful. Regards, Abhishek Kumar ? From rosuav at gmail.com Tue Apr 11 16:53:29 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Apr 2017 06:53:29 +1000 Subject: Inclusion of of python and python libraries licensed with BSD- 3 clause license in proprietary software In-Reply-To: References: Message-ID: On Wed, Apr 12, 2017 at 6:35 AM, Abhishek Kumar wrote: > I tried finding the answer but even the lawyers in my town have no idea about it and searching the web leaved me puzzled. > I am planning to make a software in python which will include libraries licensed under BSD- 3 clause. Can I sell this software under proprietary license and legally inhibit redistribution by users under my own license. > Also if you know anyone who holds knowledge in this field then please do let me know.. > Your response will be really helpful. Firstly, if you're simply writing a Python program, the license terms of the Python interpreter don't matter. Your code is completely independent, and you can closed-source it while still running it under Python itself. Similarly, if all you're doing with those BSD-licensed libraries is importing them, there's no problem there. Things become a bit more complicated if you're *distributing* the overall package - if you're creating a single installer that installs Python, these third-party libraries, and your proprietary software. If that bothers you, the easiest way is to simply provide installation instructions that say "install Python from python.org yada yada", or check with a lawyer about exactly how you're packaging everything up. But mainly, you don't have to worry too much about the license terms of the language interpreter, because you can run your code on a different interpreter perfectly easily. ChrisA From mikhailwas at gmail.com Tue Apr 11 16:58:34 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Tue, 11 Apr 2017 22:58:34 +0200 Subject: Python and the need for speed In-Reply-To: <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11 April 2017 at 16:56, Steve D'Aprano wrote: > On Tue, 11 Apr 2017 07:56 pm, Brecht Machiels wrote: > >[...] > >> DropBox and >> Google seem to agree that there are no good solutions, since they are >> moving to Go. > > That's a good solution! Maybe we should be writing extensions in Go, instead > of C. Or for maths-heavy work, using extensions written in Julia. Just my curiosity, I've always been intersted in such question: are devs still writing extensions in C, I mean type in C code? Aren't they using some translator or IDE which at lest hides the brackets and semicolons? I personally don't have problems with understanding low-level concepts of programming, but I find it pretty hard to see through the mangroves of brackets, asterisks and Co. Mikhail From abhishek.physics01 at gmail.com Tue Apr 11 17:03:05 2017 From: abhishek.physics01 at gmail.com (Abhishek Kumar) Date: Tue, 11 Apr 2017 14:03:05 -0700 (PDT) Subject: Inclusion of of python and python libraries licensed with BSD- 3 clause license in proprietary software In-Reply-To: References: Message-ID: <0c24af77-8ef3-4d79-a680-b27bc0d0a2e0@googlegroups.com> On Wednesday, 12 April 2017 02:23:53 UTC+5:30, Chris Angelico wrote: > On Wed, Apr 12, 2017 at 6:35 AM, Abhishek Kumar > wrote: > > I tried finding the answer but even the lawyers in my town have no idea about it and searching the web leaved me puzzled. > > I am planning to make a software in python which will include libraries licensed under BSD- 3 clause. Can I sell this software under proprietary license and legally inhibit redistribution by users under my own license. > > Also if you know anyone who holds knowledge in this field then please do let me know.. > > Your response will be really helpful. > > Firstly, if you're simply writing a Python program, the license terms > of the Python interpreter don't matter. Your code is completely > independent, and you can closed-source it while still running it under > Python itself. Similarly, if all you're doing with those BSD-licensed > libraries is importing them, there's no problem there. > > Things become a bit more complicated if you're *distributing* the > overall package - if you're creating a single installer that installs > Python, these third-party libraries, and your proprietary software. If > that bothers you, the easiest way is to simply provide installation > instructions that say "install Python from python.org yada yada", or > check with a lawyer about exactly how you're packaging everything up. > > But mainly, you don't have to worry too much about the license terms > of the language interpreter, because you can run your code on a > different interpreter perfectly easily. > > ChrisA thanks for your response I am planning to distribute as a stand alone package (fro windows .exe). Should I worry about the license in this case?! Like I mentioned lawyers in my town have little or no idea about open source .. regards, Abhishek From grant.b.edwards at gmail.com Tue Apr 11 17:10:23 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 11 Apr 2017 21:10:23 +0000 (UTC) Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> Message-ID: On 2017-04-11, Chris Angelico wrote: > On Wed, Apr 12, 2017 at 5:47 AM, Grant Edwards > wrote: >> >> If there are now other Python implementations (e.g. MicroPython) with >> C APIs that differ from CPython, then it seems like it is no longer >> redundant to say "the CPython API". > > I don't think there are. They either implement (some subset of) the > CPython API, or they're not in C (eg Jython), or they don't offer an > extension API. I don't know of anything else that offers a C API. Now I'm really confused. If micropython doesn't have a C API that differs from the CPython C API, then how does it "break the C API"? -- Grant Edwards grant.b.edwards Yow! I smell like a wet at reducing clinic on Columbus gmail.com Day! From rosuav at gmail.com Tue Apr 11 17:14:01 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Apr 2017 07:14:01 +1000 Subject: Inclusion of of python and python libraries licensed with BSD- 3 clause license in proprietary software In-Reply-To: <0c24af77-8ef3-4d79-a680-b27bc0d0a2e0@googlegroups.com> References: <0c24af77-8ef3-4d79-a680-b27bc0d0a2e0@googlegroups.com> Message-ID: On Wed, Apr 12, 2017 at 7:03 AM, Abhishek Kumar wrote: > thanks for your response I am planning to distribute as a stand alone package (fro windows .exe). Should I worry about the license in this case?! > Like I mentioned lawyers in my town have little or no idea about open source .. Yes, in the sense that you should talk to a lawyer. It's going to depend on how clearly you separate your code from other people's code. You can get further advice from this list, but be aware that this is NOT binding legal advice. I am not a lawyer, nor are most of the people here, and even if one of us is, we're not _your_ lawyer and may not be in your jurisdiction. ChrisA From mikhailwas at gmail.com Tue Apr 11 17:30:05 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Tue, 11 Apr 2017 23:30:05 +0200 Subject: Pound sign problem In-Reply-To: <679200651.679871.1491830236809@mail.yahoo.com> References: <679200651.679871.1491830236809.ref@mail.yahoo.com> <679200651.679871.1491830236809@mail.yahoo.com> Message-ID: On 10 April 2017 at 15:17, David Shi via Python-list wrote: > In the data set, pound sign escape appears: > u'price_currency': u'\xa3', u'price_formatted': u'\xa3525,000', > When using table.to_csv after importing pandas as pd, an error message persists as follows: > UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 0: ordinal not in range(128) > The error indicates clearly that you have a character which is not part of the standard ASCII range, hence the message : "ordinal not in range(128)" To understand it better, try to imagine characters as numbers and that basic ASCII defines characters in this range. see http://www.ascii-code.com/ So the pound character is out this range, its ordinal is being read by your program as #a3 in hex (#163 in decimal). So *probably* your data originally is in Latin-1 encoding, First , you should find out where the data comes from: is it text file, or some input, then in which application and encoding was it created. To get rid of errors, I'd say there are 2 common strategies: ensure that all source data is saved in Unicode (save as UTF-8) Or, replace the pound sign with something which is representable in standard ASCII, e.g. replace the pound sign with "GBP" in sources. Otherwise, you must find out which encoding is used in source data and apply re-encoding accordingly to input-output format specification. From python at mrabarnett.plus.com Tue Apr 11 17:45:52 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 11 Apr 2017 22:45:52 +0100 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <891a3ea1-ac39-ba0f-97d9-899cf676f935@mrabarnett.plus.com> On 2017-04-11 21:58, Mikhail V wrote: > On 11 April 2017 at 16:56, Steve D'Aprano wrote: >> On Tue, 11 Apr 2017 07:56 pm, Brecht Machiels wrote: >> >>[...] >> >>> DropBox and >>> Google seem to agree that there are no good solutions, since they are >>> moving to Go. >> >> That's a good solution! Maybe we should be writing extensions in Go, instead >> of C. Or for maths-heavy work, using extensions written in Julia. > > Just my curiosity, I've always been intersted in such question: are devs > still writing extensions in C, I mean type in C code? Aren't they using > some translator or IDE which at lest hides the brackets and semicolons? > I personally don't have problems with understanding low-level > concepts of programming, but I find it pretty hard to see > through the mangroves of brackets, asterisks and Co. > The regex module does the matching using code written in C. From rantingrickjohnson at gmail.com Tue Apr 11 17:58:18 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 11 Apr 2017 14:58:18 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <42aabf19-6054-4da4-8d7d-ea4802d2d3be@googlegroups.com> Message-ID: <758f9589-532e-4467-9ffc-d77ce9d3a524@googlegroups.com> On Monday, April 10, 2017 at 4:43:52 AM UTC-5, bartc wrote: > On 10/04/2017 03:40, Rick Johnson wrote: > > On Sunday, April 9, 2017 at 1:34:39 PM UTC-5, bartc wrote: > > > > I have my own interpreted language which I call > > > 'dynamic', but compared with Python, code in it might as > > > well be set in concrete. > > > > Is this a personal toy, or something that you can share a > > link to? > > It's a personal thing but not a toy. Some more info here: Thanks for link bartc, i'll have a look. > Yes. I suppose when it gets to a point where there are so > many features anyway, adding a few more makes little > difference! Indeed. "A drop in the bucket" comes to mind. ;-) From rantingrickjohnson at gmail.com Tue Apr 11 18:02:48 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 11 Apr 2017 15:02:48 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: On Monday, April 10, 2017 at 7:25:48 AM UTC-5, Mikhail V wrote: > Still I miss some old school features in Python, e.g. > "goto" statement would be very useful in some cases. Are you serious? > I know it is considered bad style to use goto, but in some > cases it is just most natural thing to use. "Natural"? If you're programming from inside a spaghetti bowl, i suppose. From rantingrickjohnson at gmail.com Tue Apr 11 18:15:04 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 11 Apr 2017 15:15:04 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <27652c6d-2cb4-4f0c-9400-6aa2a3f9f855@googlegroups.com> <9bdec2c0-6050-4b55-e4a0-96fcc9af6899@lucidity.plus.com> Message-ID: <5bba9295-f5f6-47f4-ab31-9c3b062af235@googlegroups.com> On Monday, April 10, 2017 at 5:48:30 PM UTC-5, Erik wrote: > On 10/04/17 03:23, Chris Angelico wrote: > > Okay, I have a pretty thick skin, but this is getting a > > bit obnoxious. Can you PLEASE post something that isn't > > just insulting me? Thanks. > > Are you suggesting he should post something that insults > you *and* others? Oh, don't take Chris so seriously. He's not offended. He's just one of those infants who utilizes pity in hopes that mummy will come save him from the scary world of free speech. Perhaps Chris would be happier if we created a py- safe-zone for him: complete with coloring books, a petting zoo and CNN running fake news stories that Hillary actually won the election. Yep, that should pacify him for a while. > If so, I'm up for being insulted too ;) Sorry, but i don't insult people unless they deserve it. (psst: try to be less nice and less intelligent, and then _maybe_ i'll insult you.) Of course, in the end, you must decide whether you have been insulted, or not. As a third party, i have no control over other people's emotions. From rantingrickjohnson at gmail.com Tue Apr 11 18:42:47 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 11 Apr 2017 15:42:47 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tuesday, April 11, 2017 at 4:56:27 AM UTC-5, Brecht Machiels wrote: > On 2017-04-11 08:19:31 +0000, Steven D'Aprano said: > > > On Sun, 09 Apr 2017 19:05:35 +1000, Chris Angelico wrote: [...] > > The Python ecosystem is actually quite healthy, if you > > need to speed up code there are lots of solutions, and > > some of them are even good solutions. > > There seem to be no solutions for my use case (rinohtype). > DropBox and Google seem to agree that there are no good > solutions, since they are moving to Go. Yup! > > Nevertheless, it is interesting to discuss whether or not > > any of these features will go mainstream or make it into > > CPython. > > Indeed! I initially wanted to include the following in the > article, but decided it would be too controversial. But now > that I've been exposed as an ignorant and naive blogger, I > might as well share these thoughts. I love this guy! ;-) > I have the feeling that a faster Python will never > materialise unless the CPython core developers make > performance a high priority. I understand that high > performance was never a goal in CPython development (and > Python language design!), but recent events (DropBox, > Google) might help to reconsider that standpoint. The fact that both Google *AND* DropBox are ignoring Python, must be devastating to GvR, however, for us at least, this emotional devastation may help to explain why Python is evolving in such a strange direction. > Here's a wild idea: consider Python 3 feature-complete. > Similar to how Python 3 cleaned up the unicode and other > warts of Python 2, Python 4 could clean up the performance > warts, but retaining the "soul" of the language. But that > last part is a diffucult one, because it would lead to > endless discussions of what would still be Python. So it's > better to define an official "TurboPython" subset. This > would also ensure backwards compatibility, but of course > complicate the implementation. I've been hinting at that for years, to no avail. > But who am I (or anyone) to suggest what the CPython core > developers should do? Do you write Python code? If so, then you have a right to both speak and to be heard. From mikhailwas at gmail.com Tue Apr 11 19:04:27 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Wed, 12 Apr 2017 01:04:27 +0200 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: On 12 April 2017 at 00:02, Rick Johnson wrote: > On Monday, April 10, 2017 at 7:25:48 AM UTC-5, Mikhail V wrote: >> Still I miss some old school features in Python, e.g. >> "goto" statement would be very useful in some cases. > > Are you serious? Not so serious to think it is needed much. And it easy enough to imagine where it would be more readable than setting up flags and if-blocks just to jump along the script. n.d., it reminds me also about the discussion about exiting from nested loops. From mikhailwas at gmail.com Tue Apr 11 19:17:47 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Wed, 12 Apr 2017 01:17:47 +0200 Subject: Python and the need for speed In-Reply-To: <891a3ea1-ac39-ba0f-97d9-899cf676f935@mrabarnett.plus.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <891a3ea1-ac39-ba0f-97d9-899cf676f935@mrabarnett.plus.com> Message-ID: On 11 April 2017 at 23:45, MRAB wrote: > On 2017-04-11 21:58, Mikhail V wrote: >> >> On 11 April 2017 at 16:56, Steve D'Aprano >> wrote: >>> >>> On Tue, 11 Apr 2017 07:56 pm, Brecht Machiels wrote: >>> >>> [...] >>> >>>> DropBox and >>>> Google seem to agree that there are no good solutions, since they are >>>> moving to Go. >>> >>> >>> That's a good solution! Maybe we should be writing extensions in Go, >>> instead >>> of C. Or for maths-heavy work, using extensions written in Julia. >> >> >> Just my curiosity, I've always been intersted in such question: are devs >> still writing extensions in C, I mean type in C code? Aren't they using >> some translator or IDE which at lest hides the brackets and semicolons? >> I personally don't have problems with understanding low-level >> concepts of programming, but I find it pretty hard to see >> through the mangroves of brackets, asterisks and Co. >> > The regex module does the matching using code written in C. That is tough... I feel like a sissy with my humanistic readability ideas. And those monospaced, green-on-black texts... (not trolling, I just have have rich imagination) From python at deborahswanson.net Tue Apr 11 19:18:24 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Tue, 11 Apr 2017 16:18:24 -0700 Subject: Swiss Ephemeris In-Reply-To: Message-ID: <00dd01d2b319$eb9c77a0$27b23dae@sambora> Rustom Mody wrote, on Monday, April 10, 2017 11:50 PM > > On Monday, April 10, 2017 at 11:26:47 AM UTC+5:30, Deborah Swanson wrote: > > The great ancients were no less endowed with intelligence than we are, > > they simply directed it to different ends. > > And just when I was convinced by the all-knowers that my gpa > was a monkey you've spoilt my complacence Good! It's unhealthy the way modern folk strut around thinking they're the smartest humans to ever walk this earth. We've gone farther with technology than any other time or culture, but invention (and innovation) is only one aspect of intelligence. > > ... medical astrology... > > whether that is hooey or scepticism of it is hooey, I dont > know [Yeah I genuinely don't know what that term means for you] I don't know that anyone does. I use a very strict interpretation of the orginal rules that you won't by find googling "medical astrology". (I know, I've tried, in the old Google as well as the new.) There's no pretension to mystic art in my form, but mine's a lot more accurate and information rich, so far as I can see in the few writings about it. I think concentrating on the actual and valid relationships while ignoring all the mysticism yields more useful results. I know the ancient Greeks were wed to their gods and I forgive them for that. I just think they would have done better without the mythology. > However you may be interested in > http://blog.languager.org/2016/01/how-long.html > which is a > motley collection of the incredible > persistence of humans to erroneous ways and outlooks and > their damaging consequences I think you also talk about the incredible persistence of other concepts and perceptions, notably in music and mathematics (which were always linked in earlier times). I would find your other examples of erroneous thinking a bit skewed in lengths of time. Tofler was right in Future Shock. We've accelerated our intellectual development since the Middle Ages, though I don't think it's because we're any smarter. I can't remember exactly when it was that the human brain reached it's current size and mental capacity, but it was shortly before the time of the ancients. Physiologically we've changed very little since then, but the knowledge base we've built on over time was what eventually caused the acceleration. No single person in modern times is intellectually capable of buiding the concepts we now use from scratch. We stand on the shoulders of giants. > [Frank Admission: That list started with a discussion on this list where I > suggested that OOP is already debunked hooey and that FP is > the way forward for programming. To which Steven asked that > since FP is at least 50 years old and has not got > very far, what makes one think its going anywhere... > To which I wondered... Is 50 years a long time? By what standard? > Hence that list ] 50 years isn't that long, though you must consider the accelerated times we're living in. LISP is likely doomed though. It's chief claim to fame was AI, and it's unlikely to reclaim its former glory, not with languages like Python leading the charge. My only contact with LISP was from a computer science professor in 1975, who literally raved about how superior LISP was. I dunno. I was doing AI in PL1 then and had several debates with this fellow. I don't remember much of the substance of those debates, but I know he never persuaded me that LISP was superior to PL1. Deborah From rantingrickjohnson at gmail.com Tue Apr 11 19:31:16 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 11 Apr 2017 16:31:16 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <423b78ac-3e72-45d3-a7d9-88feeb47a291@googlegroups.com> On Tuesday, April 11, 2017 at 9:56:45 AM UTC-5, Steve D'Aprano wrote: > On Tue, 11 Apr 2017 07:56 pm, Brecht Machiels wrote: > > On 2017-04-11 08:19:31 +0000, Steven D'Aprano said: > > > > I understand that high performance was never a goal in > > CPython development (and Python language design!), but > > recent events (DropBox, Google) might help to reconsider > > that standpoint. > > *shrug* It isn't as if high-performance is a requirement > for all code. But given the choice, no prospective "language shopper" is going to choose the slower language over a faster language -- at least not from a pool of similar languages with similar features (no comparing Python to C, please!). So even if you don't need the speed _today_, you may need it _tomorrow_. And once you've written a few hundred thousand lines of code, well, you're committed to the language you chose yesterday. > And it isn't as if Python is in any serious risk of losing > popularity. No language can expect to be popular forever. > Eventually Python will be as obsolete as or niche as COBOL, > Tcl or ABC. But that day is not now. But considering (as you pointed out) that Python is 20 years old now, and has also recently suffered a major community fracturing with the release of Py3000, that day is getting ever closer. I don't see how Python can survive when a small core of language devs consistently ignore the wider community. > > > > Here's a wild idea: consider Python 3 feature-complete. > > I think that will conflict with the many, many people who > want Python to have more features, and care more about them > than speed. Python-ideas and Python-dev do not represent the majority of the Python community. They are out there, right now, writing code and solving problems. But when Python fails to aid in this endeavor, they will not come here to complain, no, they will search for a new language. In other words: they will vote with their feet. From rantingrickjohnson at gmail.com Tue Apr 11 19:41:41 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 11 Apr 2017 16:41:41 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: <%E6HA.723559$fZ.128741@fx41.am4> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <%E6HA.723559$fZ.128741@fx41.am4> Message-ID: <1850cf1f-734b-460a-ac8b-b9e475d8877c@googlegroups.com> On Tuesday, April 11, 2017 at 10:31:16 AM UTC-5, bartc wrote: > On 11/04/2017 15:56, Steve D'Aprano wrote: > > > The truth is, all of us in this discussion -- including me > > -- are "random, ignorant commentators". I don't believe > > that any of us are experts at writing compilers. Bart is > > a possible exception, for some definition of "expert" -- > > he claims to have written a quite fast, moderately dynamic > > language, but nobody else (that I know of) has used it. > > And no offence to Bart, but from his comments and > > questions on the list, I think it is fair to say that > > whatever knowledge he has on language design was probably > > state of the art thirty years ago. Bart sometimes > > expresses surprise and confusion over concepts which are > > common in languages like Javascript, Python, Perl, Ruby > > etc. These are not young languages! Python is over 20 > > years old, Perl is even older. So I suspect Bart's > > knowledge is probably from the 70s or 80s? > > Yes, about then. But it means I have a lot of experience > getting this stuff to work briskly on limited hardware, and > I can identify bloat and inefficiency. A _very_ good point, and kudoes to you for having a thick skin. The truth is, our modern hardware masks the inefficacy of our modern high level languages. Heck, Python could have never survived on 1970s hardware. It would have been laughable to even suggest something as inefficient as Python. From nathan.ernst at gmail.com Tue Apr 11 20:28:30 2017 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Tue, 11 Apr 2017 19:28:30 -0500 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: I used to write Python modules in C++. Well, more accurately, wrapped already-written C++ APIs to expose to Python using Boost Python. This wasn't due to performance issues, but to avoid reimplementing APIs. That said, I believe Python gets a bad wrap in regards to performance for a variety of reasons, chief among them being: Python's prime audience tends to be mathematical/scientific/statistical/financial first and are developers by happen stance (I know this is a large generalization). Point is, for these audiences, the prime driver is to get a result. Efficiency is secondary. For instance, in a separate thread in the last week, someone was asking if there was a faster way of doing something along these lines: result = [(expensive_calc(x) + 1, expensive_calc(x) for x in some_data] A valid, yet sub-optimal response was suggested: temp = [expensive_calc(x) for x in some_data] result = [(x + 1, x) for x in temp] A better result would have been: temp = (expensive_calc(x) for x in some_data) result = [(x + 1, x) for x in temp] Note: the difference is subtle, but significant. The first example creates a list with the entire temporary result, while the second uses a generator. For small sizes of "some_data", you're not likely to notice. For large sizes of "some_data", this is huge. Writing performant Python code is possible, but like writing performant code in any other language, you need to be aware of what's happening. This means paying attention to things that may cause memory allocations (which are largely hidden from you in Python). I worked on http://www.marketswiki.com/wiki/CMDX - in particular I wrote most of the Migration Utility mentioned to migrate paper CDS trades to standardized CDS contracts against CME. Most of the migration util was written in native Python 2.5 (it was written in 2008) using a single thread. Performance wasn't super critical, but desired. At the end of the project, I was processing ~100K positions per second. Memory usage of the app was constant and processing time of a portfolio was directly linear to the number of positions in the portfolio. Python wasn't the limiting factor for the app - it was the write speed to the database (and we were using the bcp interface of pysybase to write to a Sybase DB). Basically, what I'm getting at is Python *can* be performant. It's also easy to screw up and introduce non-obvious slowness. Threading in Python is bad - don't bother (until we can get rid of the GIL, I doubt the situation will improve). If you have a performance problem with Python, before you blame Python, take a step back and look at your own code (or libraries you're using) and ask yourself: "Is my code optimal?" Yes, Python is not the faster language/runtime in existence. But for probably 99% of the people out there that complain about Python's speed, there's probably plenty of suboptimal or outright wasteful code that they should fix first, before complaining. For the other 1%, Python was probably the wrong choice to begin with. **************************** I don't intend this to be seen or implied as an attack or criticism of anyone. I'm just trying to provide an insight into my experience of using Python. Regards, Nate On Tue, Apr 11, 2017 at 3:58 PM, Mikhail V wrote: > On 11 April 2017 at 16:56, Steve D'Aprano > wrote: > > On Tue, 11 Apr 2017 07:56 pm, Brecht Machiels wrote: > > > >[...] > > > >> DropBox and > >> Google seem to agree that there are no good solutions, since they are > >> moving to Go. > > > > That's a good solution! Maybe we should be writing extensions in Go, > instead > > of C. Or for maths-heavy work, using extensions written in Julia. > > Just my curiosity, I've always been intersted in such question: are devs > still writing extensions in C, I mean type in C code? Aren't they using > some translator or IDE which at lest hides the brackets and semicolons? > I personally don't have problems with understanding low-level > concepts of programming, but I find it pretty hard to see > through the mangroves of brackets, asterisks and Co. > > > Mikhail > -- > https://mail.python.org/mailman/listinfo/python-list > From no.email at nospam.invalid Tue Apr 11 20:36:24 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 11 Apr 2017 17:36:24 -0700 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> Message-ID: <87shlelawn.fsf@nightsong.com> Grant Edwards writes: > I didn't know there was such a thing as "The Python C API". It's described in this document: https://infohost.nmt.edu/tcc/help/lang/python/2_6_3/c-api.pdf You can tell that the document is about the Python/C API (ok, with a slash) because it says so at the top of the title page. From no.email at nospam.invalid Tue Apr 11 20:36:58 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 11 Apr 2017 17:36:58 -0700 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> Message-ID: <87o9w2lavp.fsf@nightsong.com> Chris Angelico writes: > Do you mean this? > https://docs.python.org/3/c-api/intro.html Correct, smart guy ;-) From rantingrickjohnson at gmail.com Tue Apr 11 20:37:14 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 11 Apr 2017 17:37:14 -0700 (PDT) Subject: Swiss Ephemeris In-Reply-To: References: <1710f867-da07-4c52-9ff5-7b349dd8e485@googlegroups.com> <000001d2b1bb$7f8e7950$27b23dae@sambora> Message-ID: <733bab9d-b4c7-48cd-959d-3a60726ea9ea@googlegroups.com> On Monday, April 10, 2017 at 12:56:47 AM UTC-5, Deborah Swanson wrote: > Fully recognizing that most of what you wrote was tongue- > in-cheek, I just want to say that regardless of the wonders > of modern medicine, it's a pity they learn so little about > successful medicines other than their own. In other > academic scientific disciplines such as physics and > chemistry it's not uncommon to see history of science > courses in the curriculum. But not in medicine. I learned > what I know about ancient Greek science from a university > physics professor, though I doubt he would ever have > guessed that one of his students would someday breathe new > life into that ancient science by attempting to ressurrect > it. The great ancients were no less endowed with > intelligence than we are, they simply directed it to > different ends. Hmm. I would say the ancients had a relatively "equal intellectual capacity" as we moderns, but with far less empirical evidence from which to theorize from. Personally. i'm highly skeptical of astrology -- but being that you're writing an application to categorize and present this raw data in an intuitive form for study -- based purely on the learing experience _alone_, i think the project has merit. Hopefully your constantly pushing your technical boundaries: learning new libraries; learning new languages; experimenting with cutting-edge algorithms, etc. I'm firmly convinced that time spent writing code is never wasted, because programming is perpetual problem solving and honing your problem solving skills can be beneficial to all aspects of life. Many times you'll find the answer to one problem while trying to solve another. Problem solving is the task that consistently bears intellectual fruit. And that's why i love writing code. It always presents me with a challenge to overcome, or a riddle to solve. From no.email at nospam.invalid Tue Apr 11 20:38:03 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 11 Apr 2017 17:38:03 -0700 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> Message-ID: <87k26qlatw.fsf@nightsong.com> Grant Edwards writes: > If there are now other Python implementations (e.g. MicroPython) with > C APIs that differ from CPython, then it seems like it is no longer > redundant to say "the CPython API". Perhaps there should be an attempt to define a unified API like the Java JNI, Lisp FFI's, etc. From no.email at nospam.invalid Tue Apr 11 20:40:29 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 11 Apr 2017 17:40:29 -0700 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87fuhelapu.fsf@nightsong.com> Mikhail V writes: > Just my curiosity, I've always been intersted in such question: are devs > still writing extensions in C, I mean type in C code? Yes. > Aren't they using some translator or IDE which at lest hides the > brackets and semicolons? I don't know of anyone who does that. I don't think anyone minds C's brackets and semicolons, and lots of other languages like Java and Perl use them too, for programmer familiarity. The actual difficulty with C is that it gives rise to a high incidence of hard-to-diagnose bugs. From nathan.ernst at gmail.com Tue Apr 11 20:44:33 2017 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Tue, 11 Apr 2017 19:44:33 -0500 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: goto is a misunderstood and much misaligned creature. It is a very useful feature, but like nearly any programming construct can be abused. Constructs like 'break', 'continue' or 'next' in languages like Python or C/C++ are goto's with implied labels. As Mikhail said, goto's can be great to break out of nested loops (only a handful of languages support named 'breaks'). So, instead of: bool found = false; for (int i = 0; i = ...; ++i) { for (int h = 0; h = ...; ++h) { if (some_condition) found = true; } if (found) break; } You can have: for (int i = 0; i = ...; ++i) { for (int h = 0; h = ...; ++h) { if (some_condition) goto found; } } // not found found: // handle found The second is better for a number of reasons: it's clearer. It has fewer variables (smaller stack), it has fewer branches (better for the CPU's branch prediction), and it has fewer instructions (better for CPU instruction cache). This is a trivial, contrived example, but I've seen more than 4x nested loops using an exit flag like this (at every level of the loops) that could have been replaced with a lot less code. People need to stop drinking "X is considered harmful." Even Dijkstra later lamented that his "Goto considered harmful" paper was misinterpreted and misrepresented as advocating that goto should never be used. Additionally, I'd recommend everyone read '"Considered Harmful" Essays Considered Harmful': http://meyerweb.com/eric/comment/chech.html Regards, Nate On Tue, Apr 11, 2017 at 6:04 PM, Mikhail V wrote: > On 12 April 2017 at 00:02, Rick Johnson > wrote: > > On Monday, April 10, 2017 at 7:25:48 AM UTC-5, Mikhail V wrote: > >> Still I miss some old school features in Python, e.g. > >> "goto" statement would be very useful in some cases. > > > > Are you serious? > > Not so serious to think it is needed much. > And it easy enough to imagine where it > would be more readable than setting up flags and if-blocks > just to jump along the script. > > n.d., it reminds me also about the discussion about > exiting from nested loops. > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Tue Apr 11 21:04:28 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Apr 2017 02:04:28 +0100 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2017-04-12 01:28, Nathan Ernst wrote: [snip] > I worked on http://www.marketswiki.com/wiki/CMDX - in particular I wrote > most of the Migration Utility mentioned to migrate paper CDS trades to > standardized CDS contracts against CME. Most of the migration util was > written in native Python 2.5 (it was written in 2008) using a single > thread. Performance wasn't super critical, but desired. At the end of the > project, I was processing ~100K positions per second. Memory usage of the > app was constant and processing time of a portfolio was directly linear to > the number of positions in the portfolio. Python wasn't the limiting factor > for the app - it was the write speed to the database (and we were using the > bcp interface of pysybase to write to a Sybase DB). > > Basically, what I'm getting at is Python *can* be performant. It's also > easy to screw up and introduce non-obvious slowness. Threading in Python is > bad - don't bother (until we can get rid of the GIL, I doubt the situation > will improve). > Threading is OK if you're waiting for I/O where the main limiting factor is the speed of the I/O, e.g. transferring stuff to/from the internet. > If you have a performance problem with Python, before you blame Python, > take a step back and look at your own code (or libraries you're using) and > ask yourself: "Is my code optimal?" > > Yes, Python is not the faster language/runtime in existence. But for > probably 99% of the people out there that complain about Python's speed, > there's probably plenty of suboptimal or outright wasteful code that they > should fix first, before complaining. For the other 1%, Python was probably > the wrong choice to begin with. > > **************************** > > I don't intend this to be seen or implied as an attack or criticism of > anyone. I'm just trying to provide an insight into my experience of using > Python. > [snip] From nathan.ernst at gmail.com Tue Apr 11 21:10:57 2017 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Tue, 11 Apr 2017 20:10:57 -0500 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: I think that's fair (and I had intended to mention it). Although, I'm curious how threading with IO compares to using async/awai (I've not experience with async/await in Python, just in C#). Regards, Nate On Tue, Apr 11, 2017 at 8:04 PM, MRAB wrote: > On 2017-04-12 01:28, Nathan Ernst wrote: > [snip] > > I worked on http://www.marketswiki.com/wiki/CMDX - in particular I wrote >> most of the Migration Utility mentioned to migrate paper CDS trades to >> standardized CDS contracts against CME. Most of the migration util was >> written in native Python 2.5 (it was written in 2008) using a single >> thread. Performance wasn't super critical, but desired. At the end of the >> project, I was processing ~100K positions per second. Memory usage of the >> app was constant and processing time of a portfolio was directly linear to >> the number of positions in the portfolio. Python wasn't the limiting >> factor >> for the app - it was the write speed to the database (and we were using >> the >> bcp interface of pysybase to write to a Sybase DB). >> >> Basically, what I'm getting at is Python *can* be performant. It's also >> easy to screw up and introduce non-obvious slowness. Threading in Python >> is >> bad - don't bother (until we can get rid of the GIL, I doubt the situation >> will improve). >> >> Threading is OK if you're waiting for I/O where the main limiting factor > is the speed of the I/O, e.g. transferring stuff to/from the internet. > > If you have a performance problem with Python, before you blame Python, >> take a step back and look at your own code (or libraries you're using) and >> ask yourself: "Is my code optimal?" >> >> Yes, Python is not the faster language/runtime in existence. But for >> probably 99% of the people out there that complain about Python's speed, >> there's probably plenty of suboptimal or outright wasteful code that they >> should fix first, before complaining. For the other 1%, Python was >> probably >> the wrong choice to begin with. >> >> **************************** >> >> I don't intend this to be seen or implied as an attack or criticism of >> anyone. I'm just trying to provide an insight into my experience of using >> Python. >> >> [snip] > -- > https://mail.python.org/mailman/listinfo/python-list > From python at deborahswanson.net Tue Apr 11 21:12:44 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Tue, 11 Apr 2017 18:12:44 -0700 Subject: Swiss Ephemeris Message-ID: <011401d2b329$e41220b0$27b23dae@sambora> > > Rustom Mody wrote, on Monday, April 10, 2017 11:50 PM > > > > On Monday, April 10, 2017 at 11:26:47 AM UTC+5:30, Deborah Swanson > > wrote: > > > The great ancients were no less endowed with intelligence than we are, > > > they simply directed it to different ends. > > > > And just when I was convinced by the all-knowers that my gpa > > was a monkey you've spoilt my complacence > > Good! It's unhealthy the way modern folk strut around > thinking they're the smartest humans to ever walk this earth. > We've gone farther with technology than any other time or > culture, but invention (and innovation) is only one aspect of > intelligence. > > > > ... medical astrology... > > > > whether that is hooey or scepticism of it is hooey, I dont > > know [Yeah I genuinely don't know what that term means for you] > > I don't know that anyone does. I use a very strict > interpretation of the orginal rules that you won't by find > googling "medical astrology". (I know, I've tried, in the old > Google as well as the new.) There's no pretension to mystic > art in my form, but mine's a lot more accurate and > information rich, so far as I can see in the few writings > about it. I think concentrating on the actual and valid > relationships while ignoring all the mysticism yields more > useful results. I know the ancient Greeks were wed to their > gods and I forgive them for that. I just think they would > have done better without the mythology. > > > However you may be interested in > > http://blog.languager.org/2016/01/how-long.html > > which is a > motley collection of the incredible > > persistence of humans to erroneous ways and outlooks and > > their damaging consequences > > I think you also talk about the incredible persistence of > other concepts and perceptions, notably in music and > mathematics (which were always linked in earlier times). > > I would find your other examples of erroneous thinking a bit > skewed in lengths of time. Tofler was right in Future Shock. > We've accelerated our intellectual development since the > Middle Ages, though I don't think it's because we're any > smarter. I can't remember exactly when it was that the human > brain reached it's current size and mental capacity, but it > was shortly before the time of the ancients. Physiologically > we've changed very little since then, but the knowledge base > we've built on over time was what eventually caused the > acceleration. No single person in modern times is > intellectually capable of buiding the concepts we now use > from scratch. We stand on the shoulders of giants. > > > [Frank Admission: That list started with a discussion on this list > > where I > > suggested that OOP is already debunked hooey and that FP is > > the way forward for programming. To which Steven asked that > > since FP is at least 50 years old and has not got > > very far, what makes one think its going anywhere... > > To which I wondered... Is 50 years a long time? By what standard? > > Hence that list ] > > 50 years isn't that long, though you must consider the > accelerated times we're living in. LISP is likely doomed > though. It's chief claim to fame was AI, and it's unlikely to > reclaim its former glory, not with languages like Python > leading the charge. My only contact with LISP was from a > computer science professor in 1975, who literally raved about > how superior LISP was. I dunno. I was doing AI in PL1 then > and had several debates with this fellow. I don't remember > much of the substance of those debates, but I know he never > persuaded me that LISP was superior to PL1. > > Deborah > From steve+python at pearwood.info Tue Apr 11 21:20:19 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 12 Apr 2017 11:20:19 +1000 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58ed80d4$0$1599$c3e8da3$5496439d@news.astraweb.com> On Wed, 12 Apr 2017 08:42 am, Rick Johnson wrote: > The fact that both Google AND DropBox are ignoring Python, > must be devastating to GvR Fact check: liar, liar, pants on fire. Neither Google nor DropBox are "ignoring Python". From two randomly selected technical job positions currently offered: "Strong coding skills in an object-oriented language (Python preferred)" https://www.dropbox.com/jobs/listing/184604 "Your knowledge of Python a plus" https://www.dropbox.com/jobs/listing/91407 Google likewise has a huge investment in Python code. *Even if* they decide to move entirely to Go for new code (unlikely), Python will still have a role to play at Google for years, possibly decades. Rick, you must be really insecure about your choice of language, given how much you obsess about other people leaving Python for other languages. You're constantly writing about (imaginary) other people leaving Python, or being unhappy with Python, or "voting with their feet". Well, people do vote with their feet, and Python is consistently in the most popular handful of languages. http://redmonk.com/sogrady/2017/03/17/language-rankings-1-17/ https://blog.newrelic.com/2016/08/18/popular-programming-languages-2016-go/ http://pypl.github.io/PYPL.html https://www.tiobe.com/tiobe-index/ I still remember your first, or at least a very early, post as Ranting Rick where you were *terrified* that unless GvR did exactly what you said, the entire Python community was going to pack up and move to Ruby. It was real Chicken Little "The Sky Is Falling" stuff. Well, GvR didn't pay the least bit of attention to your "advice", in fact he has continued to move Python in directions that you hate -- Unicode as the default string type, type annotations, Python 3 -- and far from suffering for it, the Python community is bigger and stronger than ever. How is your "Rick Python" coming along? Its been, what, ten years, fifteen years since you promised to give the "silent majority" exactly the Python language they wanted, and we're still waiting for you to publish a single line of code. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Tue Apr 11 21:30:08 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 12 Apr 2017 11:30:08 +1000 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58ed8321$0$1620$c3e8da3$5496439d@news.astraweb.com> On Wed, 12 Apr 2017 10:28 am, Nathan Ernst wrote: [...] > If you have a performance problem with Python, before you blame Python, > take a step back and look at your own code (or libraries you're using) and > ask yourself: "Is my code optimal?" > > Yes, Python is not the faster language/runtime in existence. But for > probably 99% of the people out there that complain about Python's speed, > there's probably plenty of suboptimal or outright wasteful code that they > should fix first, before complaining. For the other 1%, Python was > probably the wrong choice to begin with. Thanks for your perspective Nate, that's a really good point and I wish more people would remember that you can write slow code in any language. There's a whole *universe* of use-cases, ranging from code where speed doesn't matter one bit to absolutely performance critical code. No single language can be ideal for all tasks, that's why we have so many languages to choose from. Not just dozens, but hundreds! They all make different tradeoffs between functionality, style, performance and memory use. That's okay! Diversity in language design is a good thing. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Tue Apr 11 21:42:16 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 12 Apr 2017 11:42:16 +1000 Subject: Inclusion of of python and python libraries licensed with BSD- 3 clause license in proprietary software References: Message-ID: <58ed85f8$0$1583$c3e8da3$5496439d@news.astraweb.com> On Wed, 12 Apr 2017 06:35 am, Abhishek Kumar wrote: > Hello, > > I tried finding the answer but even the lawyers in my town have no idea Where is your town? > about it and searching the web leaved me puzzled. What have you tried? The first few links found here: https://duckduckgo.com/?q=BSD-3+licence+faqs seem pretty easy to understand. It's a very short and simple licence, precisely because it puts very few requirements on you. If you are using Library X (which is under the BSD-3 licence) then all you need do to meet the licence requirements is to include Library X's copyright notice and licence. You don't have to provide the source code to Library X, or to your own application. > I am planning to make a software in python which will include libraries > licensed under BSD- 3 clause. Can I sell this software under proprietary > license Yes. > and legally inhibit redistribution by users under my own license. Yes. > Also if you know anyone who holds knowledge in this field then please do > let me know.. Your response will be really helpful. > > Regards, > Abhishek Kumar > ? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Tue Apr 11 22:08:01 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 12 Apr 2017 12:08:01 +1000 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> Message-ID: <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> On Wed, 12 Apr 2017 03:39 am, Paul Rubin wrote: > I still do my everyday stuff in Python and I'd like to get more > conversant with stuff like numpy, but it feels like an old-fashioned > language these days. "Old fashioned"? With await/async just added to the language, and type annotations? And comprehensions and iterators? Admittedly type annotations are mostly of interest to large projects with many developers and a huge code base. But the rest? Comprehensions may have been around for a decade or two in Haskell, but most older languages don't have them. I'm pretty sure Java doesn't. Does Javascript? Comprehensions feel like a fancy new language feature to me. The whole asynchronous programming features are extremely new and "hip". What sort of things do you consider "new-fashioned" if Python is old-fashioned? I'm reminded of this quote from the timbot: In many ways, it's a dull language, borrowing solid old concepts from many other languages & styles: boring syntax, unsurprising semantics, few automatic coercions, etc etc. But that's one of the things I like about it. -- Tim Peters, 16 Sep 1993 -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Tue Apr 11 22:20:07 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 11 Apr 2017 19:20:07 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: <5bbd9499-4a49-40a6-ad18-56bb3f61ad22@googlegroups.com> On Wednesday, April 12, 2017 at 3:32:57 AM UTC+5:30, Rick Johnson wrote: > On Monday, April 10, 2017 at 7:25:48 AM UTC-5, Mikhail V wrote: > > Still I miss some old school features in Python, e.g. > > "goto" statement would be very useful in some cases. > > Are you serious? > > > I know it is considered bad style to use goto, but in some > > cases it is just most natural thing to use. > > "Natural"? If you're programming from inside a spaghetti > bowl, i suppose. Try coding up an automaton (synonyms DFA, FSM) by hand With state = goto-label [And the stuff 'under' it] transition = goto-statement is a mapping that is hard to beat From rustompmody at gmail.com Tue Apr 11 22:29:03 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 11 Apr 2017 19:29:03 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: <069ed317-abab-4980-a06c-6eafdc029653@googlegroups.com> On Wednesday, April 12, 2017 at 7:38:12 AM UTC+5:30, Steve D'Aprano wrote: > On Wed, 12 Apr 2017 03:39 am, Paul Rubin wrote: > > > I still do my everyday stuff in Python and I'd like to get more > > conversant with stuff like numpy, but it feels like an old-fashioned > > language these days. > > "Old fashioned"? With await/async just added to the language, and type > annotations? I wonder if you notice Steven, that people use these examples to make the opposite case? When you see "python is sweet... almost as sweet as javascript" you know you are in trouble and need to start running (at least I do) http://stackabuse.com/python-async-await-tutorial/ [last para] From rantingrickjohnson at gmail.com Tue Apr 11 22:33:15 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 11 Apr 2017 19:33:15 -0700 (PDT) Subject: read in a list in a file to list In-Reply-To: References: <5db12517-4c1a-f180-978f-533a632b8b36@mail.usf.edu> <43baa05f-7cdf-4e58-a62a-1e917fea8219@googlegroups.com> <820a9e29-25b4-baaf-c8cb-ff40b980e6ec@mail.usf.edu> Message-ID: <6d9e54ca-a2be-420f-91b5-30b53124d122@googlegroups.com> On Sunday, April 9, 2017 at 4:22:59 PM UTC-5, john polo wrote: > On 4/8/2017 3:21 PM, breamoreboy at gmail.com wrote: > > On Saturday, April 8, 2017 at 7:32:52 PM UTC+1, john polo wrote: > > I'll start you off. > > > > with open("apefile.txt") as apefile: > > for line in apefile: > > doSomething(line) > > > > String methods and/or the csv module might be used here in > > doSomething(line), but I'll leave that to you so that you > > can learn. If you get stuck please ask again, we don't > > bite :) > Mark, Thanks for the reply. I looked back through the > methods for strings. I also looked at the csv module, but I > couldn't tell which one of those would help. Well, if you plan to write much code in Python you'd be wise to memorize every string method ASAP. And if you cannot, or are not willing to do that, then your programming adventures are going to be very painful. My advice would be to forget about the csv module for now, and do some major studying of all the string methods. And please, use the interactive interpreter to play around with each one of these methods. Here is a sample of me playing... ## START INTERACTIVE SESSION (Python2.x) ## >>> myStr = 'Rick is awesome!' >>> type(myStr) >>> len(myStr) 16 >>> dir(myStr) ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] >>> help(myStr.split) Help on built-in function split: split(...) S.split([sep [,maxsplit]]) -> list of strings Return a list of the words in the string S, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done. If sep is not specified or is None, any whitespace string is a separator and empty strings are removed from the result. ## END INTERACTIVE SESSION (Python2.x) ## > The small .txt file does have commas, but with the weird > form of listname = [1] , [2], [3], etc. for a .csv, I don't > know how that would be read in a like a .csv. But now that > I think about it, datObj2 in my script prints just the list > elements, so maybe the 'listname=' part wouldn't affect > it... Again, forget about the csv module for now, it will only confuse you. Focus on learning Python String methods first. I can assure you, you might could get by without knowing jack about the csv module, but you won't get anywhere until you become intimately familiar with Python String methods. > Anyway, after reviewing string methods some more, I came up > with this. If I understood your hint, the loop was supposed > to somehow break up the long string that came from the > apelist file, Mark's code sample iterates over the lines of a file and passes each line to a function named "doSomething". His hope was that you would replace the call to doSomething with code that actually, well, does something. > but it seemed that trying to use the split method in a loop > wouldn't work, Where's your code proving it "would not work"? I can assure you, a string can be split inside a loop. > especially since one of my attempts started a list and then > the interpreter said there were no split methods for list. Of course, because there is no split method for a list. Don't believe me? Okay, let's conduct an experiment... ## START INTERACTIVE SESSION (Python2.x) ## >>> aList = [1,2,3] >>> 'split' in dir(aList) False ## END INTERACTIVE SESSION (Python2.x) ## > The new attempt gives me a list, now I have to figure out > how to deal with unwanted quotation marks and spaces. Then stop trying to solve 10 problems at once and open your interactive Python interpreter and do some testing until your confident that you can remove unwanted chars from a string. > Can you make two replacements in the same statement, for > example 'datObj=datFil.read().replace('"','').replace('"','')? i dunno, did you try testing the code yourself in an interactive session like i asked? Here, once more... ## START INTERACTIVE SESSION (Python2.x) ## >>> myStr 'Rick is awesome!' >>> myStr.replace('Rick', "Rick's patience").replace('awesome', 'wearing thin') "Rick's patience is wearing thin!" >>> myStr 'Rick is awesome!' ## END INTERACTIVE SESSION (Python2.x) ## > Per reply of Rick Johnson, I altered variable names to > something generic. Indeed you did, and it seems you took my advice to the extreme, and now your code is a real pain to read. And after observing that the multiple exchanges here are not producing the desired result, i am getting the feeling that you are unwilling to invest the effort required to solve this problem. Feel free to prove me wrong. Many people have offered good advice, but you are not following the advice as closely as you should. So one last time, i will try to help you by compiling all the tips: (1) The first step to solving any programming problem is to devise a "general plan of attack". One of the most common techniques is called "Divide And Conquer". Using this technique, you will divide a large problem into many small problems, solve each of the small problems _individually_, and then combine them to produce a solution. This type of "general approach" is what Mark's code example was hinting at, but i would go further. Follows is a general outline of how to solve this problem using the necessary amount of division. def handle_result(result): # # Currently this only prints the parsed line, but once you # get everything else working correctly, you can have it # do something more interesting. # print result def parse_line(line): # # Parse out the relevant bits here and return them as a string # or list or whatever you want. Currently all this function # does is send the `line` back unchanged. # parsedBits = line return parsedBits def parse_file(filePath): with open(filePath) as fileObj: for line in fileObj: result = parse_line(line) handle_result(result) parse_file('ape.txt') (2) Use the interactive nature of Python to test code snippits as you write the code. (3) If you are designer of this "ape file format", then for Guido's sake man, redesign it! It's not a wise way to store data. Unless you're storing source code. But being that you're not familiar with strings methods, i have a hard time believing that this code is part of a mini language. (4) And while you could "technically" use ast.literal_eval to solve this problem, i wouldn't suggest it. i think Chris was just using esoteric comedy on you. And don't worry if you don't understand why that's funny, it's a joke that is meant for _us_. You'll understand at some point in the future. From eryksun at gmail.com Tue Apr 11 22:47:11 2017 From: eryksun at gmail.com (eryk sun) Date: Wed, 12 Apr 2017 02:47:11 +0000 Subject: IOError: [Errno 12] Not enough space In-Reply-To: <8199cb7a-fded-42b1-8a76-c9a2de4d7c78@googlegroups.com> References: <8199cb7a-fded-42b1-8a76-c9a2de4d7c78@googlegroups.com> Message-ID: On Tue, Apr 11, 2017 at 12:30 PM, LnT wrote: > Opening browser 'firefox' to base url 'https://onbdev.nbpa.com/zae' > [ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: > No browser is open > | FAIL | > IOError: [Errno 12] Not enough space > -------------------------------------------------------------------- > > I have cleared %TEMP% and reran the script. Errno 12 is ENOMEM. It's a memory error and has nothing to do with disk space. The fact that you're getting this error while doing I/O seems odd if you're really using Windows 10. In Windows 7 this error is not uncommon with console I/O, since a small 64K heap of shared memory is used for IPC between the client and the console host (conhost.exe). Buffers for reading from and writing to the console can be no larger than the largest contiguous block in this shared heap. Otherwise the request fails with ERROR_NOT_ENOUGH_MEMORY, which the CRT translates to the errno value ENOMEM. Windows 8+ uses a kernel device (ConDrv) for IPC between the client and console host, so it doesn't have this limitation. From rosuav at gmail.com Tue Apr 11 22:55:12 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Apr 2017 12:55:12 +1000 Subject: Python and the need for speed In-Reply-To: <069ed317-abab-4980-a06c-6eafdc029653@googlegroups.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> <069ed317-abab-4980-a06c-6eafdc029653@googlegroups.com> Message-ID: On Wed, Apr 12, 2017 at 12:29 PM, Rustom Mody wrote: > > I wonder if you notice Steven, that people use these examples to make > the opposite case? > > When you see "python is sweet... almost as sweet as javascript" > > you know you are in trouble and need to start running (at least I do) > > http://stackabuse.com/python-async-await-tutorial/ > [last para] Ah, yes, because JS's generators are so smooth compared to Python's. The fact that yielded values get packaged up into {value: ..., done: false} makes so much more sense, plus it's hugely advantageous that you need to transpile your code to be able to actually use async functions in anything other than the latest Chrome/Safari/Firefox. There are two areas where JS has a really significant advantage over Python: 1) Invoking a JS async function is as simple as calling it, because you already are running everything through an event loop. I don't think Python should do the same, but maybe a more obvious way to do this than ensure_future would help. 2) If you have existing code that is built on JS's promises (of which there's a lot, but by no means all), async functions cleanly interface with them. You can await any promise, and an async function automatically returns a promise. So they're better integrated with the rest of the ecosystem - or at least, that portion of the ecosystem that jumped on the promise bandwagon. Got something that only uses callbacks? Sorry, mate, you're out of luck. Both of them come from the fact that JS has always been intended as an asynchronous language - right back in the 90s, before it was all standardized as ECMAScript, you had a setTimeout() function rather than a sleep(). Python, meanwhile, has made it easy to write blocking I/O in a single-threaded program, and then adds async'ness to it. So with JS, you're adding smoothness to functionality that already exists, but with Python, you're adding functionality to a smooth and clean language. ChrisA From rantingrickjohnson at gmail.com Tue Apr 11 23:00:01 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 11 Apr 2017 20:00:01 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: <0e10d5d3-ed5a-4ddb-af50-f82eb5db3b53@googlegroups.com> On Tuesday, April 11, 2017 at 7:10:00 PM UTC-5, Mikhail V wrote: > On 12 April 2017 at 00:02, Rick Johnson wrote: > > On Monday, April 10, 2017 at 7:25:48 AM UTC-5, Mikhail V wrote: > > > Still I miss some old school features in Python, e.g. > > > "goto" statement would be very useful in some cases. > > > > Are you serious? > > Not so serious to think it is needed much. And it easy > enough to imagine where it would be more readable than > setting up flags and if-blocks just to jump along the > script. Oh, you mean a goto that is confined to the realms of conditional logic? I see... Hmm... perhaps i'm more supportive of the idea after all. Do you have any Python- centric code (or pseudo code) examples you can provide that showcase the power of this proposed feature over the legacy features? > n.d., it reminds me also about the discussion about exiting > from nested loops. Do you have a link? From cjw at ncf.ca Tue Apr 11 23:07:58 2017 From: cjw at ncf.ca (Colin J. Williams) Date: Tue, 11 Apr 2017 23:07:58 -0400 Subject: Python-list Digest, Vol 163, Issue 14 In-Reply-To: References: Message-ID: <8b2b14e5-0f59-4edf-e2de-da44bd630b55@ncf.ca> Thanks Eryk, I have today successfully installed python 3.6.1. Next I have to tackle installing the whl versions of Numpy and Matplotlib. Colin W. On 2017-04-11 11:25 AM, python-list-request at python.org wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > > Today's Topics: > > 1. Re: using HTTPHandler cause Django server side shows http 400 > and Invalid HTTP_HOST header message (iMath) > 2. Re: using HTTPHandler cause Django server side shows http 400 > and Invalid HTTP_HOST header message (iMath) > 3. Re: using HTTPHandler cause Django server side shows http 400 > and Invalid HTTP_HOST header message (iMath) > 4. Re: Need help with getting Key, Value out of dicts in lists > (John Ralph) > 5. Re: Installing Python 3.6.1 on a Windows 10 (eryk sun) > 6. [ANN] txkube 0.1.0 (Jean-Paul Calderone) > 7. Re: Swiss Ephemeris (Peter Henry) > 8. how to convert this container back to format build result? > (Ho Yeung Lee) > 9. RE: Swiss Ephemeris (Deborah Swanson) > 10. Fwd: Swiss Ephemeris (Peter Henry) > 11. RE: Swiss Ephemeris (Deborah Swanson) > 12. Re: read in a list in a file to list (Erik) > 13. Re: Python and the need for speed (Erik) > 14. Re: Python and the need for speed (Chris Angelico) > 15. Re: Pound sign problem (Steve D'Aprano) > 16. Re: Python and the need for speed (Christian Gollwitzer) > 17. Re: Swiss Ephemeris (Rustom Mody) > 18. Re: Python and the need for speed (Steven D'Aprano) > 19. Re: Python and the need for speed (Tim Golden) > 20. Re: Python and the need for speed (Chris Angelico) > 21. Re: Python and the need for speed (breamoreboy at gmail.com) > 22. Re: Python and the need for speed (Chris Angelico) > 23. Re: Python and the need for speed (Brecht Machiels) > 24. Re: Python and the need for speed (bartc) > 25. Re: strange behaviour when writing a large amount of data on > stdout (tlnarayana at gmail.com) > 26. IOError: [Errno 12] Not enough space (LnT) > 27. Re: Python and the need for speed (Steve D'Aprano) > 28. Re: Temporary variables in list comprehensions (Piet van Oostrum) > 29. Re: Python and the need for speed (Steve D'Aprano) > 30. django user images (Xristos Xristoou) > 31. Need webFOCUS Business Intelligence Developer > (Jack at nichesoftsolutions.com) > 32. Need webFOCUS Business Intelligence Developer > (Jack at nichesoftsolutions.com) > 33. Re: Python and the need for speed (Steve D'Aprano) > 34. Re: Python and the need for speed (breamoreboy at gmail.com) > 35. ldap search and Tuple (Alejandro Decchi) > 36. Mcidas format (jorge.conrado at cptec.inpe.br) > 37. Re: Pound sign problem (Lew Pitcher) > > From rantingrickjohnson at gmail.com Wed Apr 12 00:10:56 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 11 Apr 2017 21:10:56 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> On Tuesday, April 11, 2017 at 7:28:46 PM UTC-5, Nathan Ernst wrote: > > [...] > > Writing performant Python code is possible, but like > writing performant code in any other language, you need to > be aware of what's happening. This means paying attention > to things that may cause memory allocations (which are > largely hidden from you in Python). But what you're asking people to do is not unlike reinventing wheels. Some are not aware of every subtle case that will cause a bottleneck. For this reason, it would be wise to create a database where these bottlenecks can be logged, with the intention of creating a python optimizing tool at some time in the future. Like you said, since a large subset of python coders are not CS majors, we cannot expect them to understand Python at such a fundamental level as someone such as GvR. That is the price of creating a language that abstracts away all the dirty details so that laymen can wield it. But just as Python should _never_ seg- fault (but it does!), high level languages like Python should make it difficult, if not impossible, to write sub- optimal code (at least in the blatantly obvious cases). The whole fundamental nature of Python is to relieve the programmer of all the onerous tedium and drudgery (memory management, cryptic syntaxes, etc...), so that the programmer's mental energy can be devoted solely to the creative demands of logic and interfaces. > I worked on http://www.marketswiki.com/wiki/CMDX - in > particular I wrote most of the Migration Utility mentioned > to migrate paper CDS trades to standardized CDS contracts > against CME. Most of the migration util was written in > native Python 2.5 (it was written in 2008) using a single > thread. Performance wasn't super critical, but desired. At > the end of the project, I was processing ~100K positions > per second. Yeah, but what kind of hardware were you running it on? It seems in this case, that you wrote up a utility and ran it on a machine of your choosing, but not all developers have the advantage of choosing which machine their code executes on. Most code is written and released for mass consumption on client machines which come in all shapes and sizes. Sure, you can write sloppy code on a top-of-the-line hardware and not notice, but try the same code on a windoze 95 box and see what happens... > Threading in Python is bad - don't bother (until we can get > rid of the GIL, I doubt the situation will improve). If you search the archives (and internet) for "remove GIL", you'll find more hits than you could parse in a lifetime. Basically, the community has been begging for the GIL to be removed since the early 90s, but the Python royalty have no interest to do so. And the reasons for this could be many. I have my personal suspicions... > If you have a performance problem with Python, before you > blame Python, take a step back and look at your own code > (or libraries you're using) and ask yourself: "Is my code > optimal?" > > Yes, Python is not the faster language/runtime in > existence. But for probably 99% I don't think it's fair to make broad-brushed assertions as to the technical prowess of everyday Python programmers. Perhaps the incidents of non-optimal code are high, but 99% is difficult to swallow and sounds an awful lot like hyperbole. And although i'm sure some folks here will lap-up such gross exaggerations with prideful glee, sorry, but i'm not one of them. From no.email at nospam.invalid Wed Apr 12 00:32:06 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 11 Apr 2017 21:32:06 -0700 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> <069ed317-abab-4980-a06c-6eafdc029653@googlegroups.com> Message-ID: <87r30yjlfd.fsf@nightsong.com> Chris Angelico writes: > Python, meanwhile, has made it easy to write blocking > I/O in a single-threaded program, and then adds async'ness to it. I'd be interested to know how to open a disk file asynchronously in a single-threaded Python program under Linux. As far as I can tell there is no way to do it. From rantingrickjohnson at gmail.com Wed Apr 12 00:41:28 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 11 Apr 2017 21:41:28 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: <047a3e70-c627-413a-9d9a-35e2b345f61d@googlegroups.com> On Tuesday, April 11, 2017 at 7:44:49 PM UTC-5, Nathan Ernst wrote: > goto is a misunderstood and much misaligned creature. It is > a very useful feature, but like nearly any programming > construct can be abused. Constructs like 'break', > 'continue' or 'next' in languages like Python or C/C++ are > goto's with implied labels. As Mikhail said, goto's can be > great to break out of nested loops (only a handful of > languages support named 'breaks'). So, instead of: > > bool found = false; > for (int i = 0; i = ...; ++i) > { > for (int h = 0; h = ...; ++h) > { > if (some_condition) > found = true; > } > if (found) break; > } > > You can have: > > for (int i = 0; i = ...; ++i) > { > for (int h = 0; h = ...; ++h) > { > if (some_condition) > goto found; > } > } > // not found > > found: > // handle found > I'll admit, that in a few cases of deeply nested loops, i have purposely stripped out the nested code and wrapped it in a function so i could take advantage of return, because indeed, flags are distracting. However, i don't think this one example is enough to warrent a goto. Unless you can provide more than one legitimate use for goto, i'd rather support a new keyword like "breakall". In fact, the more i think about it, the more i realize that it should have been "breaklocal" and "breakglobal" all along! Hmm, how would goto handle a logic that required both a local and a global break within the same nested loop structure? > The second is better for a number of reasons: it's clearer. > It has fewer variables (smaller stack), it has fewer > branches (better for the CPU's branch prediction), and it > has fewer instructions (better for CPU instruction cache). > This is a trivial, contrived example, but I've seen more > than 4x nested loops using an exit flag like this (at every > level of the loops) that could have been replaced with a > lot less code. But it also requires a named target. (Although i'll admit, goto does offer more _flexibility_ over a single "breakglobal" keyword) From rosuav at gmail.com Wed Apr 12 01:01:20 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Apr 2017 15:01:20 +1000 Subject: Python and the need for speed In-Reply-To: <87r30yjlfd.fsf@nightsong.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> <069ed317-abab-4980-a06c-6eafdc029653@googlegroups.com> <87r30yjlfd.fsf@nightsong.com> Message-ID: On Wed, Apr 12, 2017 at 2:32 PM, Paul Rubin wrote: > Chris Angelico writes: >> Python, meanwhile, has made it easy to write blocking >> I/O in a single-threaded program, and then adds async'ness to it. > > I'd be interested to know how to open a disk file asynchronously in a > single-threaded Python program under Linux. As far as I can tell there > is no way to do it. I'm not sure how Node does it. But most of JavaScript/ECMAScript has historically been aimed at web browsers, where you're not allowed to open files as such, but you _can_ make HTTP requests. It's also entirely possible to have a single "application thread" and then a "file opening thread" that does nothing but open files; your app is still single threaded (thus you don't have concurrency concerns), but file opening becomes truly asynchronous. Oh, and Python also has to cope with a bit more complexity because it's possible to start multiple application threads in Python. It's not in JS. ChrisA From no.email at nospam.invalid Wed Apr 12 01:26:49 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 11 Apr 2017 22:26:49 -0700 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> <069ed317-abab-4980-a06c-6eafdc029653@googlegroups.com> <87r30yjlfd.fsf@nightsong.com> Message-ID: <87inmajiw6.fsf@nightsong.com> Chris Angelico writes: > It's also entirely possible to have a single "application thread" and > then a "file opening thread" that does nothing but open files; Thanks. I think GHC and Erlang BEAM both do that. I hoped there was a better way. Note you potentially need multiple file opening threads. > your app is still single threaded (thus you don't have concurrency > concerns), but file opening becomes truly asynchronous. Of course you still have concurrency concerns, plus you have to be very very careful that nothing ever blocks. I've generally preferred in Python to use threads communicating by message passing through queues. This is pretty safe if you remember to not having any mutable objects shared between threads. Of course I like the way Erlang does it even more, with isolated lightweight processes. > Oh, and Python also has to cope with a bit more complexity because > it's possible to start multiple application threads in Python. It's > not in JS. Yeah I'm not sure of the JS situation. C++11 has futures and promises and I've been wanting to try to use them, but it's still on my infinitely deep stack of stuff to do. This looks amazing though: http://www.seastar-project.org/ From tlnarayana at gmail.com Wed Apr 12 01:42:59 2017 From: tlnarayana at gmail.com (LnT) Date: Tue, 11 Apr 2017 22:42:59 -0700 (PDT) Subject: IOError: [Errno 12] Not enough space In-Reply-To: References: <8199cb7a-fded-42b1-8a76-c9a2de4d7c78@googlegroups.com> Message-ID: Hello eryk sun, Thanks so much for your input. could you please advice. 1) Any workaround for this issue ? 2) is it good to report issue in Windows OS help desk ? Regards, LnT On Wednesday, April 12, 2017 at 8:18:11 AM UTC+5:30, eryk sun wrote: > On Tue, Apr 11, 2017 at 12:30 PM, LnT wrote: > > Opening browser 'firefox' to base url 'https://onbdev.nbpa.com/zae' > > [ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: > > No browser is open > > | FAIL | > > IOError: [Errno 12] Not enough space > > -------------------------------------------------------------------- > > > > I have cleared %TEMP% and reran the script. > > Errno 12 is ENOMEM. It's a memory error and has nothing to do with > disk space. The fact that you're getting this error while doing I/O > seems odd if you're really using Windows 10. In Windows 7 this error > is not uncommon with console I/O, since a small 64K heap of shared > memory is used for IPC between the client and the console host > (conhost.exe). Buffers for reading from and writing to the console can > be no larger than the largest contiguous block in this shared heap. > Otherwise the request fails with ERROR_NOT_ENOUGH_MEMORY, which the > CRT translates to the errno value ENOMEM. Windows 8+ uses a kernel > device (ConDrv) for IPC between the client and console host, so it > doesn't have this limitation. From tlnarayana at gmail.com Wed Apr 12 01:48:33 2017 From: tlnarayana at gmail.com (LnT) Date: Tue, 11 Apr 2017 22:48:33 -0700 (PDT) Subject: IOError: [Errno 12] Not enough space In-Reply-To: <58ed0e3c$0$829$e4fe514c@news.xs4all.nl> References: <8199cb7a-fded-42b1-8a76-c9a2de4d7c78@googlegroups.com> <58ed0e3c$0$829$e4fe514c@news.xs4all.nl> Message-ID: <1c25e713-65dc-4dcf-97eb-a6a7149d608b@googlegroups.com> Hi Irmen, 1) yes. its Python 2.7 2) Since windows 10 machine is a VM ,Only drive is available C and is provided 60GB for both OS and other softwares like java and python. And still 20GB free space is available. This python script does - open web application and capture the screenshot of the webpage incase any functionality Fail? Hope this information is suffice. Let me know , if you need more specific logs to be captured ? Regards, LnT On Tuesday, April 11, 2017 at 10:41:36 PM UTC+5:30, Irmen de Jong wrote: > On 11-4-2017 14:30, LnT wrote: > > Hi, > > > > version information > > > > python 27 > > Please be more precise, there is no Python 27. (Yeah it is clear you meant 2.7 but still) > > > java version "1.8.0_111" > That should not be relevant > > > OS -Win 10 , 64Bit , 8GB RAM , 60GB HD > > 60 GB is not a lot of space for windows... > > > > executing python test script (robotframework) for a we bapplication > > Application url will be invoked by Firefox 38.0 > > > > Please find below log: > > -------------------------------------------------------------------- > > Opening browser 'firefox' to base url 'https://onbdev.nbpa.com/zae' > > [ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open > > | FAIL | > > IOError: [Errno 12] Not enough space > > -------------------------------------------------------------------- > > That's not much information. Is there really not anything else in the log? Like a > traceback, that may give some clues what the application is doing when it is running out > of disk space? > > > > > > I have cleared %TEMP% and reran the script. > > But still I see this. > > > > Could you please show me some Light ? > > > > Based on the info you provided, the only solution I can think of is: free more space. > Something in your application is trying to write stuff and there's simply not enough > space on the disk to do so. > > > -i From tlnarayana at gmail.com Wed Apr 12 01:54:43 2017 From: tlnarayana at gmail.com (LnT) Date: Tue, 11 Apr 2017 22:54:43 -0700 (PDT) Subject: IOError: [Errno 12] Not enough space In-Reply-To: <58ed0e3c$0$829$e4fe514c@news.xs4all.nl> References: <8199cb7a-fded-42b1-8a76-c9a2de4d7c78@googlegroups.com> <58ed0e3c$0$829$e4fe514c@news.xs4all.nl> Message-ID: Hi Irmen, you may please find full log @ https://pastebin.mozilla.org/9018753 Regards, LnT On Tuesday, April 11, 2017 at 10:41:36 PM UTC+5:30, Irmen de Jong wrote: > On 11-4-2017 14:30, LnT wrote: > > Hi, > > > > version information > > > > python 27 > > Please be more precise, there is no Python 27. (Yeah it is clear you meant 2.7 but still) > > > java version "1.8.0_111" > That should not be relevant > > > OS -Win 10 , 64Bit , 8GB RAM , 60GB HD > > 60 GB is not a lot of space for windows... > > > > executing python test script (robotframework) for a we bapplication > > Application url will be invoked by Firefox 38.0 > > > > Please find below log: > > -------------------------------------------------------------------- > > Opening browser 'firefox' to base url 'https://onbdev.nbpa.com/zae' > > [ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open > > | FAIL | > > IOError: [Errno 12] Not enough space > > -------------------------------------------------------------------- > > That's not much information. Is there really not anything else in the log? Like a > traceback, that may give some clues what the application is doing when it is running out > of disk space? > > > > > > I have cleared %TEMP% and reran the script. > > But still I see this. > > > > Could you please show me some Light ? > > > > Based on the info you provided, the only solution I can think of is: free more space. > Something in your application is trying to write stuff and there's simply not enough > space on the disk to do so. > > > -i From grownbetterwe at gmail.com Wed Apr 12 01:55:41 2017 From: grownbetterwe at gmail.com (grownbetterwe at gmail.com) Date: Tue, 11 Apr 2017 22:55:41 -0700 (PDT) Subject: download redtube video - Free In-Reply-To: References: Message-ID: <0dd464cd-447f-4239-a302-a0c3e15c2ea6@googlegroups.com> ? 2008?9?22???? UTC+8??6:39:10?uomioc... at gmail.com??? > download redtube video > . > . > . > *******CLICK HERE******** > http://vids365.cn/download-redtube-video > ***************************** > . > . > . > . > . > . > . > . > . > . > . > . > download redtube video You may also try Allavsoft to download from Redtube, Pornhub, Youporn, etc Here is the easy guide http://www.allavsoft.com/how-to/redtube-downloader.html? From greg.ewing at canterbury.ac.nz Wed Apr 12 02:17:50 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 12 Apr 2017 18:17:50 +1200 Subject: Python and the need for speed In-Reply-To: <87a87mn8rc.fsf@nightsong.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> Message-ID: Paul Rubin wrote: > Or you could look at the past 50 years(!) of Lisp and Scheme compilers > some of which produce very good code, ask what Python features can't be > straightforwardly transliterated into Lisp to use those compilers, Lisp and Scheme are much less dynamic than Python. The problem of translating Python code into efficient Lisp or Scheme isn't really much different from translating it into efficient machine code, or Java bytecode, or whatever. Type information is needed, either explicitly written in, or inferred, or JITted. -- Greg From tjreedy at udel.edu Wed Apr 12 02:24:29 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 12 Apr 2017 02:24:29 -0400 Subject: Python and the need for speed In-Reply-To: <87fuhelapu.fsf@nightsong.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <87fuhelapu.fsf@nightsong.com> Message-ID: On 4/11/2017 8:40 PM, Paul Rubin wrote: > Mikhail V writes: >> Just my curiosity, I've always been intersted in such question: are devs >> still writing extensions in C, I mean type in C code? > > Yes. > >> Aren't they using some translator or IDE which at lest hides the >> brackets and semicolons? > > I don't know of anyone who does that. I don't think anyone minds C's > brackets and semicolons, and lots of other languages like Java and Perl People who do, like me, may avoid using C. I am really grateful that there are people willing to maintain the C code for CPython ;-). > use them too, for programmer familiarity. The actual difficulty with C > is that it gives rise to a high incidence of hard-to-diagnose bugs. -- Terry Jan Reedy From steve at pearwood.info Wed Apr 12 02:48:50 2017 From: steve at pearwood.info (Steven D'Aprano) Date: 12 Apr 2017 06:48:50 GMT Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> Message-ID: <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> On Tue, 11 Apr 2017 21:10:56 -0700, Rick Johnson wrote: > high level languages like Python should make it difficult, if not > impossible, to write sub- > optimal code (at least in the blatantly obvious cases). You mean that Python should make it impossible to write: near_limit = [] near_limit.append(1) near_limit = len(near_limit) instead of: near_limit = 1 ? I look forward to seeing your version of RickPython that can enforce that rule. Oh, in case you think I'm making this up, this example came from some real-life code: https://mail.python.org/pipermail//python-list/2016-August/712673.html Here's another example: answer = 0 for i in range(10): answer += 1 instead of answer = 10 So... how exactly does the compiler prohibit stupid code? -- Steve From ian.g.kelly at gmail.com Wed Apr 12 02:55:18 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 12 Apr 2017 00:55:18 -0600 Subject: Python and the need for speed In-Reply-To: <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 11, 2017 at 8:08 PM, Steve D'Aprano wrote: > Comprehensions may have been around for a decade or two in Haskell, but most > older languages don't have them. I'm pretty sure Java doesn't. Java does not have comprehensions per se, but the Streams API introduced in Java 8 is similar in concept and also much more powerful -- for example, streams can be executed either serially or in parallel, which is not a feature of any list comprehension I've ever seen. https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html > Does > Javascript? Comprehensions feel like a fancy new language feature to me. ES6 was going to include array comprehensions and generator comprehensions but these didn't make it into the final version. My understanding is that they were deferred because the committee hoped to come up with something more LINQ-like, which I think is also greatly motivated by parallelism concerns. From vincent.vande.vyvre at telenet.be Wed Apr 12 02:57:07 2017 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Wed, 12 Apr 2017 08:57:07 +0200 Subject: CPython Class variable exposed to Python is altered. Message-ID: <5824dded-cd31-90d0-6044-edc132daf071@telenet.be> Hi, Learning CPython, I've made this simple exercice, a module test which contains an object Test. The object Test has an attribute name, fixed at instanciation. So, I try my code with a script: ------------------------------------------- from test import Test for n in ("The name", "Foo", "Spam"): t = Test(n) print("%s --> %s" %(n, t.name)) ------------------------------------------- And the return: Uhe name --> Uhe name Goo --> Goo Tpam --> Tpam As we can see, the first letter is changed with the next letter in alphabetical order, but not only for the attribute name, also for the reference n. Same into a console: (py352_venv) vincent at djoliba:~/CPython/py352_venv/pydcraw$ python Python 3.5.2 (default, Dec 19 2016, 11:46:33) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from test import Test >>> for n in ("The name", "Foo", "Spam"): ... t = Test(n) ... print("%s --> %s" %(n, t.name)) ... Uhe name --> Uhe name Goo --> Goo Tpam --> Tpam I'm working in a venv. The testmodule.c is attached. The setup.py ------------------------------------------------ from distutils.core import setup, Extension setup(name="test", version="1.0", ext_modules=[ Extension("test", ["testmodule.c"], libraries=[]) ]) ------------------------------------------------ Best, Vincent From vincent.vande.vyvre at telenet.be Wed Apr 12 03:23:17 2017 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Wed, 12 Apr 2017 09:23:17 +0200 Subject: CPython Class variable exposed to Python is altered. In-Reply-To: <5824dded-cd31-90d0-6044-edc132daf071@telenet.be> References: <5824dded-cd31-90d0-6044-edc132daf071@telenet.be> Message-ID: <816bdd8e-e22a-7237-75a8-01783d468bcc@telenet.be> Le 12/04/17 ? 08:57, Vincent Vande Vyvre a ?crit : > Hi, > > Learning CPython, I've made this simple exercice, a module test which > contains an object Test. > > The object Test has an attribute name, fixed at instanciation. > > So, I try my code with a script: > > ------------------------------------------- > from test import Test > > for n in ("The name", "Foo", "Spam"): > t = Test(n) > print("%s --> %s" %(n, t.name)) > ------------------------------------------- > > And the return: > > Uhe name --> Uhe name > Goo --> Goo > Tpam --> Tpam > > As we can see, the first letter is changed with the next letter in > alphabetical order, but not only for the attribute name, also for the > reference n. > > Same into a console: > > (py352_venv) vincent at djoliba:~/CPython/py352_venv/pydcraw$ python > Python 3.5.2 (default, Dec 19 2016, 11:46:33) > [GCC 4.8.4] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> from test import Test > >>> for n in ("The name", "Foo", "Spam"): > ... t = Test(n) > ... print("%s --> %s" %(n, t.name)) > ... > Uhe name --> Uhe name > Goo --> Goo > Tpam --> Tpam > > > I'm working in a venv. > > The testmodule.c is attached. > > > The setup.py > ------------------------------------------------ > from distutils.core import setup, Extension > setup(name="test", version="1.0", > ext_modules=[ > Extension("test", ["testmodule.c"], > libraries=[]) > ]) > ------------------------------------------------ > > > Best, > > > Vincent > I see the attachement is rejected. This is the testmodule.c ----------------------------------------------------------- #include #include "structmember.h" typedef struct { PyObject_HEAD PyObject *name; } Test; static void Test_dealloc(Test* self) { Py_XDECREF(self->name); } static PyObject * Test_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { Test *self; self = (Test *)type->tp_alloc(type, 0); if (self != NULL){ self->name = PyUnicode_FromString(""); if (self->name == NULL){ Py_DECREF(self); return NULL; } } return (PyObject *)self; } static int Test_init(Test *self, PyObject *args, PyObject *kwds) { PyObject *name, *tmp; static char *kwlist[] = {"name", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|", kwlist, &name)) return -1; if (name) { tmp = self->name; Py_INCREF(name); self->name = name; Py_XDECREF(tmp); } return 0; } static PyMemberDef Test_members[] = { {"name", T_STRING, offsetof(Test, name), 0, "The object name"}, {NULL} /* Sentinel */ }; static PyMethodDef Test_methods[] = { {NULL} /* sentinel */ }; static PyTypeObject TestType = { PyVarObject_HEAD_INIT(NULL, 0) "test.Test", /* tp_name */ sizeof(Test), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)Test_dealloc, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_reserved */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ "Test object", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ Test_methods, /* tp_methods */ Test_members, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ (initproc)Test_init, /* tp_init */ 0, /* tp_alloc */ Test_new, /* tp_new */ }; static PyModuleDef testmodule = { PyModuleDef_HEAD_INIT, "test", "Example module.", -1, NULL, NULL, NULL, NULL, NULL }; PyMODINIT_FUNC PyInit_test(void) { PyObject* m; if (PyType_Ready(&TestType) < 0) return NULL; m = PyModule_Create(&testmodule); if (m == NULL) return NULL; Py_INCREF(&TestType); PyModule_AddObject(m, "Test", (PyObject *)&TestType); return m; } ----------------------------------------------------------------------------------- From abhishek.physics01 at gmail.com Wed Apr 12 03:55:13 2017 From: abhishek.physics01 at gmail.com (Abhishek Kumar) Date: Wed, 12 Apr 2017 00:55:13 -0700 (PDT) Subject: Inclusion of of python and python libraries licensed with BSD- 3 clause license in proprietary software In-Reply-To: <58ed85f8$0$1583$c3e8da3$5496439d@news.astraweb.com> References: <58ed85f8$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wednesday, 12 April 2017 07:12:27 UTC+5:30, Steve D'Aprano wrote: > On Wed, 12 Apr 2017 06:35 am, Abhishek Kumar wrote: > > > Hello, > > > > I tried finding the answer but even the lawyers in my town have no idea > > Where is your town? > > > > about it and searching the web leaved me puzzled. > > What have you tried? > > The first few links found here: > > https://duckduckgo.com/?q=BSD-3+licence+faqs > > > seem pretty easy to understand. It's a very short and simple licence, > precisely because it puts very few requirements on you. If you are using > Library X (which is under the BSD-3 licence) then all you need do to meet > the licence requirements is to include Library X's copyright notice and > licence. You don't have to provide the source code to Library X, or to your > own application. > > > > I am planning to make a software in python which will include libraries > > licensed under BSD- 3 clause. Can I sell this software under proprietary > > license > > Yes. > > > > and legally inhibit redistribution by users under my own license. > > Yes. > > > > Also if you know anyone who holds knowledge in this field then please do > > let me know.. Your response will be really helpful. > > > > Regards, > > Abhishek Kumar > > ? > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. Hello, I'm living in Pune(India) the lawyers keep on giving different answers some yes you can distribute the software under proprietary license and restrict users from ditributing it in any form while other negate it.. A tried googling and like the lawyers got different answers.. So I posted in stack exchange here is the the link : http://opensource.stackexchange.com/questions/5361/use-of-bsd-3-clause-license-and-python-software-license-for-proprietary-use? I hope you have an experience(legal) in software license Also if you know some one who holds a knowledge in software licenses then please do let me know.. Regards, Abhishek From jfong at ms4.hinet.net Wed Apr 12 04:08:07 2017 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Wed, 12 Apr 2017 01:08:07 -0700 (PDT) Subject: What is the difference between x[:]=y and x=y[:]? Message-ID: I have a list of list and like to expand each "list element" by appending a 1 and a 0 to it. For example, from "lr = [[1], [0]]" expand to "lr = [[1,1], [0,1], [1,0], [0,0]]". The following won't work: 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. >>> lr = [[1], [0]] >>> lx = [] >>> for i in range(len(lr)): ... lx[:] = lr[i] ... lx.append(0) ... lr[i].append(1) ... lr.append(lx) ... >>> lr [[1, 1], [0, 1], [0, 0], [0, 0]] >>> But the following does: >>> lr = [[1], [0]] >>> lx = [] >>> for i in range(len(lr)): ... lx = lr[i][:] ... lx.append(0) ... lr[i].append(1) ... lr.append(lx) ... >>> lr [[1, 1], [0, 1], [1, 0], [0, 0]] >>> After stepping through the first one manually: >>> lr = [[1], [0]] >>> lx[:] = lr[0] >>> lx.append(0) >>> lx [1, 0] >>> lr[0].append(1) >>> lr [[1, 1], [0]] >>> lr.append(lx) >>> lr [[1, 1], [0], [1, 0]] >>> So far so good... >>> lx[:] = lr[1] >>> lx.append(0) >>> lx [0, 0] >>> lr[1].append(1) >>> lr [[1, 1], [0, 1], [0, 0]] >>> Woops! What's wrong? --Jach Fong From alister.ware at ntlworld.com Wed Apr 12 04:33:13 2017 From: alister.ware at ntlworld.com (alister) Date: Wed, 12 Apr 2017 08:33:13 GMT Subject: What is the difference between x[:]=y and x=y[:]? References: Message-ID: On Wed, 12 Apr 2017 01:08:07 -0700, jfong wrote: > I have a list of list and like to expand each "list element" by > appending a 1 and a 0 to it. For example, from "lr = [[1], [0]]" expand > to "lr = [[1,1], [0,1], [1,0], [0,0]]". > > The following won't work: > > 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. >>>> lr = [[1], [0]] >>>> lx = [] >>>> for i in range(len(lr)): > ... lx[:] = lr[i] > ... lx.append(0) > ... lr[i].append(1) > ... lr.append(lx) > ... >>>> lr > [[1, 1], [0, 1], [0, 0], [0, 0]] >>>> >>>> > But the following does: > >>>> lr = [[1], [0]] >>>> lx = [] >>>> for i in range(len(lr)): > ... lx = lr[i][:] > ... lx.append(0) > ... lr[i].append(1) > ... lr.append(lx) > ... >>>> lr > [[1, 1], [0, 1], [1, 0], [0, 0]] >>>> >>>> > After stepping through the first one manually: > >>>> lr = [[1], [0]] >>>> lx[:] = lr[0] lx.append(0) >>>> lx > [1, 0] >>>> lr[0].append(1) >>>> lr > [[1, 1], [0]] >>>> lr.append(lx) >>>> lr > [[1, 1], [0], [1, 0]] >>>> >>>> > So far so good... > >>>> lx[:] = lr[1] lx.append(0) >>>> lx > [0, 0] >>>> lr[1].append(1) >>>> lr > [[1, 1], [0, 1], [0, 0]] >>>> >>>> > Woops! What's wrong? > > --Jach Fong 1st never* use range to step through items in a list if you need the index as well as the item use Enumerate a=[[1],[2]] for i,x in enumerate(a): a[i].append(0) print a * like all rules an experienced programmer may find a usage case where it may be broken -- While money doesn't buy love, it puts you in a great bargaining position. From __peter__ at web.de Wed Apr 12 04:41:04 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 12 Apr 2017 10:41:04 +0200 Subject: What is the difference between x[:]=y and x=y[:]? References: Message-ID: jfong at ms4.hinet.net wrote: Assuming both x and y are lists x[:] = y replaces the items in x with the items in y while x = y[:] makes a copy of y and binds that to the name x. In both cases x and y remain different lists, but in only in the second case x is rebound. This becomes relevant when initially there are other names bound to x. Compare: >>> z = x = [1, 2] >>> y = [10, 20, 30] >>> x[:] = y # replace the values, z affected >>> z [10, 20, 30] >>> z = x = [1, 2] >>> y = [10, 20, 30] >>> x = y[:] # rebind. x and z are now different lists >>> z [1, 2] From __peter__ at web.de Wed Apr 12 04:51:35 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 12 Apr 2017 10:51:35 +0200 Subject: CPython Class variable exposed to Python is altered. References: <5824dded-cd31-90d0-6044-edc132daf071@telenet.be> <816bdd8e-e22a-7237-75a8-01783d468bcc@telenet.be> Message-ID: Vincent Vande Vyvre wrote: > Le 12/04/17 ? 08:57, Vincent Vande Vyvre a ?crit : >> Hi, >> >> Learning CPython, I've made this simple exercice, a module test which >> contains an object Test. >> >> The object Test has an attribute name, fixed at instanciation. >> >> So, I try my code with a script: >> >> ------------------------------------------- >> from test import Test >> >> for n in ("The name", "Foo", "Spam"): >> t = Test(n) >> print("%s --> %s" %(n, t.name)) >> ------------------------------------------- >> >> And the return: >> >> Uhe name --> Uhe name >> Goo --> Goo >> Tpam --> Tpam >> >> As we can see, the first letter is changed with the next letter in >> alphabetical order, but not only for the attribute name, also for the >> reference n. > if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|", kwlist, &name)) > return -1; > > if (name) { > tmp = self->name; > Py_INCREF(name); While I don't know how to do this properly you seem to be applying Py_INCREF() to a C string rather than a Python string object. C being C you can cast anything to anything else... Aren't there any warnings at compile time? From vincent.vande.vyvre at telenet.be Wed Apr 12 05:19:51 2017 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Wed, 12 Apr 2017 11:19:51 +0200 Subject: CPython Class variable exposed to Python is altered. In-Reply-To: References: <5824dded-cd31-90d0-6044-edc132daf071@telenet.be> <816bdd8e-e22a-7237-75a8-01783d468bcc@telenet.be> Message-ID: Le 12/04/17 ? 10:51, Peter Otten a ?crit : > Vincent Vande Vyvre wrote: > >> Le 12/04/17 ? 08:57, Vincent Vande Vyvre a ?crit : >>> Hi, >>> >>> Learning CPython, I've made this simple exercice, a module test which >>> contains an object Test. >>> >>> The object Test has an attribute name, fixed at instanciation. >>> >>> So, I try my code with a script: >>> >>> ------------------------------------------- >>> from test import Test >>> >>> for n in ("The name", "Foo", "Spam"): >>> t = Test(n) >>> print("%s --> %s" %(n, t.name)) >>> ------------------------------------------- >>> >>> And the return: >>> >>> Uhe name --> Uhe name >>> Goo --> Goo >>> Tpam --> Tpam >>> >>> As we can see, the first letter is changed with the next letter in >>> alphabetical order, but not only for the attribute name, also for the >>> reference n. >> if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|", kwlist, &name)) >> return -1; >> >> if (name) { >> tmp = self->name; >> Py_INCREF(name); > While I don't know how to do this properly you seem to be applying > Py_INCREF() to a C string rather than a Python string object. C being C you > can cast anything to anything else... > > Aren't there any warnings at compile time? > No, no warning. For the truth, this code is copy-pasted from the doc. https://docs.python.org/3.5//extending/newtypes.html#adding-data-and-methods-to-the-basic-example Vincent From alister.ware at ntlworld.com Wed Apr 12 05:30:05 2017 From: alister.ware at ntlworld.com (alister) Date: Wed, 12 Apr 2017 09:30:05 GMT Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <423b78ac-3e72-45d3-a7d9-88feeb47a291@googlegroups.com> Message-ID: On Tue, 11 Apr 2017 16:31:16 -0700, Rick Johnson wrote: > On Tuesday, April 11, 2017 at 9:56:45 AM UTC-5, Steve D'Aprano wrote: >> On Tue, 11 Apr 2017 07:56 pm, Brecht Machiels wrote: >> > On 2017-04-11 08:19:31 +0000, Steven D'Aprano said: >> > >> > I understand that high performance was never a goal in CPython >> > development (and Python language design!), but recent events >> > (DropBox, Google) might help to reconsider that standpoint. >> >> *shrug* It isn't as if high-performance is a requirement for all code. > > But given the choice, no prospective "language shopper" is going to > choose the slower language over a faster language -- at least not from a > pool of similar languages with similar features (no comparing Python to > C, please!). So even if you don't need the speed _today_, you may need > it _tomorrow_. And once you've written a few hundred thousand lines of > code, well, you're committed to the language you chose yesterday. but cost is also a factor , not just cost of the tools but cost in time writing & debugging he software the write. if they can produce a finished product in half the time with a "slower" language the speed may not be important (especially when the application is IO bound & spends 90% of its time idling anyway). if this were not the case then we would all be writing Assembler > >> And it isn't as if Python is in any serious risk of losing popularity. >> No language can expect to be popular forever. Eventually Python will be >> as obsolete as or niche as COBOL, >> Tcl or ABC. But that day is not now. > > But considering (as you pointed out) that Python is 20 years old now, > and has also recently suffered a major community fracturing with the > release of Py3000, that day is getting ever closer. I don't see how > Python can survive when a small core of language devs consistently > ignore the wider community. > > >> > Here's a wild idea: consider Python 3 feature-complete. >> >> I think that will conflict with the many, many people who want Python >> to have more features, and care more about them than speed. > > Python-ideas and Python-dev do not represent the majority of the Python > community. They are out there, right now, writing code and solving > problems. But when Python fails to aid in this endeavor, they will not > come here to complain, no, they will search for a new language. In other > words: they will vote with their feet. -- I realize that command does have its fascination, even under circumstances such as these, but I neither enjoy the idea of command nor am I frightened of it. It simply exists, and I will do whatever logically needs to be done. -- Spock, "The Galileo Seven", stardate 2812.7 From brecht__gmane at mos6581.org Wed Apr 12 05:33:49 2017 From: brecht__gmane at mos6581.org (Brecht Machiels) Date: Wed, 12 Apr 2017 11:33:49 +0200 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2017-04-11 14:56:33 +0000, Steve D'Aprano said: > On Tue, 11 Apr 2017 07:56 pm, Brecht Machiels wrote: >> >> Hey! This random, ignorant blogger has feelings too! :-) > > Hi, and welcome! > > Sorry, I wasn't *specifically* referring to you, except in the sense that > you aren't a compiler expert. That's ok. No offense taken. > But I also think that while making Python faster is a good goal to have, it > seems that for most people, and most companies, it isn't their priority. That may very well be correct. I have used Python/NumPy extensively for data processing/analysis, and I haven't been disappointed by its performance in that area (so far, at least). However, rinohtype is located in a very different niche and it would greatly benefit a lot from a speed boost. Rendering the Sphinx documentation (311 pages) takes almost 10 minutes on my i7, which is simply too long given the available processing power. And yes, I have spent a lot time profiling and optimizing the code. You're always welcome to demonstrate my incompetence by means of a pull request, of course ;-) I have toyed with the idea of porting rinohtype to JavaScript, for the increased performance (though that is not certain) and the advantage of being able to run in the browser. While it may not be an extreme amount of work to port rinohtype itself using something like RapydScript, the docutils and Sphinx dependencies are not easily replaced. As for moving to a compiled language (Nim or Rust would be interesting choices, IMO), it doesn't make much sense. rinohtype should be easily extendable with new document templates for example. An interpreted language like Python is ideal for that (not to mention it's lovely syntax). >>> The Python ecosystem is actually quite healthy, if you need to speed up >>> code there are lots of solutions, and some of them are even good >>> solutions. >> >> There seem to be no solutions for my use case (rinohtype). > > Have you tried Nuitka? I have, a long time ago, so it's a bit vague. But if it performed marginally better than CPython, I would have remembered. Definitely not enough to warrant having to distribute binaries. >>> Nevertheless, it is interesting to discuss whether or not any >>> of these features will go mainstream or make it into CPython. >> >> Indeed! I initially wanted to include the following in the article, but >> decided it would be too controversial. But now that I've been exposed >> as an ignorant and naive blogger, I might as well share these thoughts. >> >> I have the feeling that a faster Python will never materialise unless >> the CPython core developers make performance a high priority. > > I think you are both right and wrong. > > You are right in the sense that none of the companies exploring Python > optimizers have wanted to carry the maintenance burden themselves. Their > aim is to prove the concept, then push it back into CPython and have the > core devs maintain it. > > But you're also wrong, in the sense that you're focused on *revolutionary* > speed-ups rather than *evolutionary* optimizations. CPython is faster today > than it was in version 1.5, despite doing MUCH more. Python continues to > shave slow code off and improve performance. No, this isn't likely to make > Python ten times faster, but its performance does incrementally increase. I do appreciate the evolutionary speedups of CPython. However, I love Python and it's just a bit frustrating that it's not all that it could be. Python *could* be faster, it's just not moving in that direction. But, it may indeed be I'm just one of the few that think that Python is not fast enough. If that is the case, it of course makes no sense to focus more on performance. However, we don't really know how Python's performance is affecting its popularity. It would be good to have some kind of information about user's motivations for choosing Python or moving away from it. Have any polls been organized in the past to try to find out? I realize that work on CPython (and thus the language itself) is done by unpaid volunteers. But I assume that they also want the language to thrive, and therefore want to cater to the wishes of the userbase at some level. So perhaps the conclusion to this discussion is that we should first try to find out whether performance is an issue for a large part of the community (or possible newcomers). Best regards, Brecht From __peter__ at web.de Wed Apr 12 05:47:40 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 12 Apr 2017 11:47:40 +0200 Subject: CPython Class variable exposed to Python is altered. References: <5824dded-cd31-90d0-6044-edc132daf071@telenet.be> <816bdd8e-e22a-7237-75a8-01783d468bcc@telenet.be> Message-ID: Vincent Vande Vyvre wrote: > Le 12/04/17 ? 10:51, Peter Otten a ?crit : >> Vincent Vande Vyvre wrote: >> >>> Le 12/04/17 ? 08:57, Vincent Vande Vyvre a ?crit : >>>> Hi, >>>> >>>> Learning CPython, I've made this simple exercice, a module test which >>>> contains an object Test. >>>> >>>> The object Test has an attribute name, fixed at instanciation. >>>> >>>> So, I try my code with a script: >>>> >>>> ------------------------------------------- >>>> from test import Test >>>> >>>> for n in ("The name", "Foo", "Spam"): >>>> t = Test(n) >>>> print("%s --> %s" %(n, t.name)) >>>> ------------------------------------------- >>>> >>>> And the return: >>>> >>>> Uhe name --> Uhe name >>>> Goo --> Goo >>>> Tpam --> Tpam >>>> >>>> As we can see, the first letter is changed with the next letter in >>>> alphabetical order, but not only for the attribute name, also for the >>>> reference n. >>> if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|", kwlist, &name)) >>> return -1; >>> >>> if (name) { >>> tmp = self->name; >>> Py_INCREF(name); >> While I don't know how to do this properly you seem to be applying >> Py_INCREF() to a C string rather than a Python string object. C being C >> you can cast anything to anything else... >> >> Aren't there any warnings at compile time? >> > > No, no warning. > > > For the truth, this code is copy-pasted from the doc. > > https://docs.python.org/3.5//extending/newtypes.html#adding-data-and-methods-to-the-basic-example But the example expects objects (the big O), not strings. Following the example you need if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|", kwlist, &name)) return -1; and also static PyMemberDef Test_members[] = { {"name", T_OBJECT_EX, offsetof(Test, name), 0, "The object name"}, {NULL} /* Sentinel */ }; If you want a string instead of an object you must not apply Py_INCREF(), you probably have to manage its lifetime yourself. From bart4858 at gmail.com Wed Apr 12 05:56:58 2017 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Wed, 12 Apr 2017 02:56:58 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wednesday, 12 April 2017 07:48:57 UTC+1, Steven D'Aprano wrote: > On Tue, 11 Apr 2017 21:10:56 -0700, Rick Johnson wrote: > > > high level languages like Python should make it difficult, if not > > impossible, to write sub- > > optimal code (at least in the blatantly obvious cases). > > Here's another example: > > answer = 0 > for i in range(10): > answer += 1 > > instead of > > answer = 10 > > So... how exactly does the compiler prohibit stupid code? Actually, an optimising C compiler (not one of mine!) probably could reduce that to answer=10. And eliminate even that if 'answer' was never used. But that's not really the issue here. Assume that such a loop /is/ doing something more useful. The problems with Python (last time I looked anyway) were these: (1) If answer was a global variable, then it needs a symbol table lookup to find out what it is. That would not happen in a static language, or a less dynamic one, as you already have the address. And this lookup happens for every loop iteration. (2) There is also 'range', which could have been redefined to mean something else, so /that/ needs a lookup. The byte-code compiler can't just assume this loop is to be executed 10 times. (3) This was fixed long ago but at one time, even when 'range' had been established to be a range, it involved constructing a list of items (10 here, but it could be a million), and then iterating over the list. This might seem crazy, but it might have been exceptable for a script language at one time. Not for a general purpose one however. (4) Python's integer types being immutable, the += operation means evaluating the result, then creating a new integer object and binding 'a' to that new value. (Correct me if I'm wrong.) These are all things the language could point a finger at before blaming the user for writing inefficient code. The problem is also the language encouraging people to use high-level but inefficient methods, as the emphasis is on productivity and readability** rather than performance. In fact most users probably have no idea on what is efficient and what isn't. If I wanted to work with the code for character 'A' (ie. the integer 65), in another language it might represent it as 'A' which is mapped to 65. In Python, 'A' is a string. To get the integer code, I have to use ord('A'). To do that, it has to look up 'ord', than execute a function call... In the meantime the more static language has long since finished whatever it was going to do with that code. (** Although I find code full of class definitions, one-liners, decorators and all the other esoterics, incomprehensive. I'm sure I'm not the only one, so perhaps readability isn't too much of a priority either.) -- bartc From marko at pacujo.net Wed Apr 12 06:05:21 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 12 Apr 2017 13:05:21 +0300 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> <069ed317-abab-4980-a06c-6eafdc029653@googlegroups.com> <87r30yjlfd.fsf@nightsong.com> Message-ID: <878tn6djq6.fsf@elektro.pacujo.net> Paul Rubin : > I'd be interested to know how to open a disk file asynchronously in a > single-threaded Python program under Linux. As far as I can tell there > is no way to do it. Traditionally, disk access in Linux has been considered nonblocking. There is AIO, but that hasn't been used much. I have seen quite a bit of activity on the Linux FS mailing list recently on AIO so maybe that will change in the future. I believe the lack of asynchronous disk I/O is related to the grand Solaris idea which Linux adopted: all memory is on a disk and RAM is merely a cache. You can turn disk access into memory access with mmap() and you can turn memory access into disk access with /proc/mem. If you access a file and the relevant bytes are already cached in RAM you get them instantaneously; otherwise you'll have to wait for a "page fault" to be processed. If you need to execute a CPU instruction and the relevant address is already cached in RAM, the CPU can proceed without delay; otherwise the CPU will have to wait for a page fault to be processed. As swapping is no longer considered normal on modern computers, the memory-disk duality doesn't seem all that practical anymore. Rather, you'd like to treat the disk analogously to network access and keep RAM access separate. Marko From vincent.vande.vyvre at telenet.be Wed Apr 12 06:05:25 2017 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Wed, 12 Apr 2017 12:05:25 +0200 Subject: CPython Class variable exposed to Python is altered. In-Reply-To: References: <5824dded-cd31-90d0-6044-edc132daf071@telenet.be> <816bdd8e-e22a-7237-75a8-01783d468bcc@telenet.be> Message-ID: <2b79c163-815d-2357-a6c8-420aac25a977@telenet.be> Le 12/04/17 ? 11:47, Peter Otten a ?crit : > Vincent Vande Vyvre wrote: > > >> No, no warning. >> >> >> For the truth, this code is copy-pasted from the doc. >> >> https://docs.python.org/3.5//extending/newtypes.html#adding-data-and-methods-to-the-basic-example > But the example expects objects (the big O), not strings. Following the > example you need > > if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|", kwlist, &name)) > return -1; > > and also > > static PyMemberDef Test_members[] = { > {"name", T_OBJECT_EX, offsetof(Test, name), 0, > "The object name"}, > {NULL} /* Sentinel */ > }; > > If you want a string instead of an object you must not apply Py_INCREF(), > you probably have to manage its lifetime yourself. > I've just installed a new venv with the 3.6.1 and tested your changes. And now, that's all right. I see the devil is into the details ... Many thanks Peter Vincent From marko at pacujo.net Wed Apr 12 06:11:00 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 12 Apr 2017 13:11:00 +0300 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zifmc4wb.fsf@elektro.pacujo.net> bart4858 at gmail.com: > On Wednesday, 12 April 2017 07:48:57 UTC+1, Steven D'Aprano wrote: >> Here's another example: >> >> answer = 0 >> for i in range(10): >> answer += 1 >> >> instead of >> >> answer = 10 >> >> So... how exactly does the compiler prohibit stupid code? > > Actually, an optimising C compiler (not one of mine!) probably could > reduce that to answer=10. One of the reasons C compilers need to address "stupid" code like that is that it may arise from macros or from generated code. Maybe the statement "answer += 1" is "answer = answer * 1.01 + 0.0001" in some other (compile-time) circumstances. A similar situation can hit Python as well through a (virtual) method call, a dynamic function call or a conditional import, for example. Marko From jfong at ms4.hinet.net Wed Apr 12 06:51:42 2017 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Wed, 12 Apr 2017 03:51:42 -0700 (PDT) Subject: What is the difference between x[:]=y and x=y[:]? In-Reply-To: References: Message-ID: <045c9994-c4c4-41ee-9f63-9e834e80d574@googlegroups.com> Peter Otten at 2017/4/12 UTC+8 PM 4:41:36 wrote: > jfong at ms4.hinet.net wrote: > > Assuming both x and y are lists > > x[:] = y > > replaces the items in x with the items in y while > > > x = y[:] > > makes a copy of y and binds that to the name x. In both cases x and y remain > different lists, but in only in the second case x is rebound. This becomes > relevant when initially there are other names bound to x. Compare: > > > >>> z = x = [1, 2] > >>> y = [10, 20, 30] > >>> x[:] = y # replace the values, z affected > >>> z > [10, 20, 30] > > > >>> z = x = [1, 2] > >>> y = [10, 20, 30] > >>> x = y[:] # rebind. x and z are now different lists > >>> z > [1, 2] Thank you Peter, I think I know the problem now. The append(lx) method actually append a link to the name lx, not append a copy of lx. When use lx[:]=lr[i]. the lx's content changes and it also reflected to the lr. When use lx=lr[i][:], a new lx was created and it will not affect the old one linked in the lr. Anyway it seems as better to use append(lx[:]) for this sake:-) --Jach From fabiofz at gmail.com Wed Apr 12 07:14:55 2017 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Wed, 12 Apr 2017 08:14:55 -0300 Subject: PyDev 5.7.0 Released Message-ID: PyDev 5.7.0 Release Highlights ------------------------------- * **Important** PyDev now requires Java 8 and Eclipse 4.6 (Neon) onwards. * PyDev 5.2.0 is the last release supporting Eclipse 4.5 (Mars). * **PyLint** * The PyLint integration is much improved. * Working along with the PyDev code-analysis. * If there's an equivalent code analysis error in PyLint and PyDev, the PyLint one is hidden. * **Ctrl+1** on PyLint error line shows option to silent error in that line. * See: http://pydev.org/manual_adv_pylint.html for details. * **Debugger** * Fixed issue when sorting which could lead to error comparing a value with None. * Fixed issue which prevented debugger from working with Jython due to the lack of sys._current_frames. * Testing Jython on CI. * **Code Completion** * Properly unpacking assigns from a parameter to an instance with type documented in docstring. **#PyDev-778** * **Others** * When assigning parameters to attributes (**Ctrl+1** on function **def**), skip adding duplicate assignments. * When adding parameters to docstrings (**Ctrl+1** on function **def**), it will now properly update an existing docstring, not only create one from scratch. * In Windows, when searching executables, priority is given to a python executable found in the PATH (as in Mac/Linux). * Fixed issue were space was wrongly removed in code formatter. **#PyDev-784** What is PyDev? --------------------------- PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com What is LiClipse? --------------------------- LiClipse is a PyDev standalone with goodies such as support for Multiple cursors, theming, TextMate bundles and a number of other languages such as Django Templates, Jinja2, Kivy Language, Mako Templates, Html, Javascript, etc. It's also a commercial counterpart which helps supporting the development of PyDev. Details on LiClipse: http://www.liclipse.com/ Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer LiClipse http://www.liclipse.com PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com PyVmMonitor - Python Profiler http://www.pyvmmonitor.com/ From mafshari44 at gmail.com Wed Apr 12 07:18:45 2017 From: mafshari44 at gmail.com (Masoud Afshari) Date: Wed, 12 Apr 2017 04:18:45 -0700 (PDT) Subject: closing image automatically in for loop , python Message-ID: <8e5d24d1-1453-4526-88d5-790702c00f1c@googlegroups.com> Dear all I have several *.sfd files which created by a simulation code. I wrote a program containing a for Loop which reads each time one .sfd file and plot the requested Parameters. I have two request: 1- my Problem is that for Showing successive Images in for Loop I have to Close the Image MANAULLY each time to read next sdf file. can anyone please tell me which command do I have to use so the code Close the Images automatically. 2- more over, can anyone please tell me how can I create a movie with this code. in the following you can see my code ##################### # in this program, PYTHON reads the reduced files and plot the variables . ? ? import sys import sdf import numpy as np import matplotlib.pyplot as plt from matplotlib.font_manager import FontProperties fp = FontProperties('Symbola') ? ##################### information from EPOCH input.deck nx,ny= 1200, 1600 ? xmin=-100e-6 xmax = 50e-6 ymin = -100e-6 ymax = 100e-6 ? X =np.linspace(xmin,xmax,nx) #Generate linearly spaced vector. The spacing between the points is (x2-x1)/(n-1). Y =np.linspace(ymin,ymax,ny) ? ################# for n in range(0,27): nstr = str(n)#.zfill(4) #print nstr ? ###### fig = plt.figure() #plot several figures simultaneously ########..... reading Ex ? filename ="Ex_resample" +'_sdf_'+ str(n)+'.dat' with open(filename, 'rb') as f: #read binary file data = np.fromfile(f, dtype='float64', count=nx*ny) #float64 for Double precision float numbers Ex = np.reshape(data, [ny, nx], order='F') #print Ex.max() ? #Display image with scaled colors: plt.subplot(222) fig1=plt.imshow(Ex, extent=[X.min()*1e6, X.max()*1e6, Y.min()*1e6, Y.max()*1e6], vmin=0, vmax=2e12, cmap='brg', aspect='auto') #cmap='jet', 'nipy_spectral','hot','gist_ncar' #plt.suptitle('Ex') plt.title('sdf '+ str(n)+ '; Time= ' +str(n*50)+ 'ps',color='green', fontsize=15) plt.xlabel('x($\mu$m)') plt.ylabel('y($\mu$m)') plt.text(40,80,'Ex',color='red', fontsize=15) plt.colorbar() plt.show() #fig.savefig('test.jpg') sys.exit() From bart4858 at gmail.com Wed Apr 12 07:48:05 2017 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Wed, 12 Apr 2017 04:48:05 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> On Wednesday, 12 April 2017 10:57:10 UTC+1, bart... at gmail.com wrote: > On Wednesday, 12 April 2017 07:48:57 UTC+1, Steven D'Aprano wrote: > > for i in range(10): > > answer += 1 > > So... how exactly does the compiler prohibit stupid code? > And this lookup happens for every loop iteration. I've just looked at byte-code for that loop (using an on-line Python as I don't have it on this machine). I counted 7 byte-codes that need to be executed per iteration, plus five to set up the loop, one of which needs to call a function. My language does the same loop with only 4 byte-codes. Loop setup needs 2 (to store '10' into the loop counter). It also has the option of using a loop with no control variable (as it's not used here). Still four byte-codes, but the looping byte-code is a bit faster. Plus there is the option of using ++answer instead of answer += 1. Now there are only two byte-codes! (NB don't try ++ in Python.) These are straightforward language enhancements. -- bartc From jeanmichel at sequans.com Wed Apr 12 07:55:45 2017 From: jeanmichel at sequans.com (jmp) Date: Wed, 12 Apr 2017 13:55:45 +0200 Subject: Swiss Ephemeris In-Reply-To: <000001d2b1bb$7f8e7950$27b23dae@sambora> References: <1710f867-da07-4c52-9ff5-7b349dd8e485@googlegroups.com> <000001d2b1bb$7f8e7950$27b23dae@sambora> Message-ID: On 04/10/2017 07:29 AM, Deborah Swanson wrote: > Fully recognizing that most of what you wrote was tongue-in-cheek, I > just want to say that regardless of the wonders of modern medicine, it's > a pity they learn so little about successful medicines other than their > own. In other academic scientific disciplines such as physics and > chemistry it's not uncommon to see history of science courses in the > curriculum. But not in medicine. I learned what I know about ancient > Greek science from a university physics professor, though I doubt he > would ever have guessed that one of his students would someday breathe > new life into that ancient science by attempting to ressurrect it. The > great ancients were no less endowed with intelligence than we are, they > simply directed it to different ends. 1/ success of medicine astrology is yet to be demonstrated 2/ history of science is about history, not actual science 3/ Ancients were probably as intelligent as we are, they just lacked a proper education and were filled with many false information I can understand why people would study ancient medicines, I don't when they decide to consider it actual applicable science. It could be harmful in some cases. But since it's done in Python, I guess we can let it slide :o) jm From jussi.piitulainen at helsinki.fi Wed Apr 12 07:56:22 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 12 Apr 2017 14:56:22 +0300 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> Message-ID: bart4858 at gmail.com writes: > On Wednesday, 12 April 2017 10:57:10 UTC+1, bart... at gmail.com wrote: >> On Wednesday, 12 April 2017 07:48:57 UTC+1, Steven D'Aprano wrote: > >> > for i in range(10): >> > answer += 1 > >> > So... how exactly does the compiler prohibit stupid code? > >> And this lookup happens for every loop iteration. > > I've just looked at byte-code for that loop (using an on-line Python > as I don't have it on this machine). I counted 7 byte-codes that need > to be executed per iteration, plus five to set up the loop, one of > which needs to call a function. > > My language does the same loop with only 4 byte-codes. Loop setup > needs 2 (to store '10' into the loop counter). > > It also has the option of using a loop with no control variable (as > it's not used here). Still four byte-codes, but the looping byte-code > is a bit faster. > > Plus there is the option of using ++answer instead of answer += 1. Now > there are only two byte-codes! (NB don't try ++ in Python.) > > These are straightforward language enhancements. FYI, the question is not how to optimize the code but how to prevent the programmer from writing stupid code in the first place. Someone suggested that a language should do that. But you appear to be talking about the original topic of the thread, as seen on the subject line, so ok :) From __peter__ at web.de Wed Apr 12 08:13:09 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 12 Apr 2017 14:13:09 +0200 Subject: What is the difference between x[:]=y and x=y[:]? References: <045c9994-c4c4-41ee-9f63-9e834e80d574@googlegroups.com> Message-ID: jfong at ms4.hinet.net wrote: > Peter Otten at 2017/4/12 UTC+8 PM 4:41:36 wrote: >> jfong at ms4.hinet.net wrote: >> >> Assuming both x and y are lists >> >> x[:] = y >> >> replaces the items in x with the items in y while >> >> >> x = y[:] >> >> makes a copy of y and binds that to the name x. In both cases x and y >> remain different lists, but in only in the second case x is rebound. This >> becomes relevant when initially there are other names bound to x. >> Compare: >> >> >> >>> z = x = [1, 2] >> >>> y = [10, 20, 30] >> >>> x[:] = y # replace the values, z affected >> >>> z >> [10, 20, 30] >> >> >> >>> z = x = [1, 2] >> >>> y = [10, 20, 30] >> >>> x = y[:] # rebind. x and z are now different lists >> >>> z >> [1, 2] > > Thank you Peter, I think I know the problem now. The append(lx) method > actually append a link to the name lx, not append a copy of lx. When use > lx[:]=lr[i]. the lx's content changes and it also reflected to the lr. > When use lx=lr[i][:], a new lx was created and it will not affect the old > one linked in the lr. > > Anyway it seems as better to use append(lx[:]) for this sake:-) I should add that you can write >>>> lr = [[1], [0]] >>>> lx = [] >>>> for i in range(len(lr)): > ... lx = lr[i][:] > ... lx.append(0) > ... lr[i].append(1) > ... lr.append(lx) > ... >>>> lr >[[1, 1], [0, 1], [1, 0], [0, 0]] > idiomatially as >>> lr = [[1], [0]] >>> [inner + tail for tail in [[1], [0]] for inner in lr] [[1, 1], [0, 1], [1, 0], [0, 0]] Note that there is a difference -- the resulting list does not share any lists with the original `lr` as concatenating two lists produces a new one: >>> a = [1] >>> b = [2] >>> c = a + b >>> a is c False >>> b is c False From tlnarayana at gmail.com Wed Apr 12 08:21:30 2017 From: tlnarayana at gmail.com (LnT) Date: Wed, 12 Apr 2017 05:21:30 -0700 (PDT) Subject: IOError: [Errno 12] Not enough space In-Reply-To: References: <8199cb7a-fded-42b1-8a76-c9a2de4d7c78@googlegroups.com> Message-ID: On Wednesday, April 12, 2017 at 11:13:22 AM UTC+5:30, LnT wrote: > Hello eryk sun, > Thanks so much for your input. > > could you please advice. > 1) Any workaround for this issue ? > 2) is it good to report issue in Windows OS help desk ? > > Regards, > LnT > > > > On Wednesday, April 12, 2017 at 8:18:11 AM UTC+5:30, eryk sun wrote: > > On Tue, Apr 11, 2017 at 12:30 PM, LnT wrote: > > > Opening browser 'firefox' to base url 'https://onbdev.nbpa.com/zae' > > > [ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: > > > No browser is open > > > | FAIL | > > > IOError: [Errno 12] Not enough space > > > -------------------------------------------------------------------- > > > > > > I have cleared %TEMP% and reran the script. > > > > Errno 12 is ENOMEM. It's a memory error and has nothing to do with > > disk space. The fact that you're getting this error while doing I/O > > seems odd if you're really using Windows 10. In Windows 7 this error > > is not uncommon with console I/O, since a small 64K heap of shared > > memory is used for IPC between the client and the console host > > (conhost.exe). Buffers for reading from and writing to the console can > > be no larger than the largest contiguous block in this shared heap. > > Otherwise the request fails with ERROR_NOT_ENOUGH_MEMORY, which the > > CRT translates to the errno value ENOMEM. Windows 8+ uses a kernel > > device (ConDrv) for IPC between the client and console host, so it > > doesn't have this limitation. Hi , you may please close this thread. Resolved the issue. Root cause - Post restart the Windows VM , Firefox browser was blocked @ Firewall. Regards, LnT From ben.usenet at bsb.me.uk Wed Apr 12 09:38:52 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Wed, 12 Apr 2017 14:38:52 +0100 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: <878tn5zqxf.fsf@bsb.me.uk> Steve D'Aprano writes: > On Wed, 12 Apr 2017 03:39 am, Paul Rubin wrote: > >> I still do my everyday stuff in Python and I'd like to get more >> conversant with stuff like numpy, but it feels like an old-fashioned >> language these days. > > "Old fashioned"? With await/async just added to the language, and type > annotations? And comprehensions and iterators? > > Admittedly type annotations are mostly of interest to large projects with > many developers and a huge code base. But the rest? > > Comprehensions may have been around for a decade or two in Haskell, but most > older languages don't have them. I'm pretty sure Java doesn't. Does > Javascript? Comprehensions feel like a fancy new language feature to > me. They've been in in Haskell for nearly three decades, but they were around before that. Miranda had them, as did Miranda's immediate predecessor, KRC. KRC dates from about 1980, so if you've been using that lineage of languages, list comprehensions have been a standard feature for 37 years. I've been using them almost my entire programming life. It seems odd that ECMAScript (the JavaScript standard) does not have them, but then JS seems to hide its function nature under an imperative bushel. Just another perspective... -- Ben. From bart4858 at gmail.com Wed Apr 12 09:44:19 2017 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Wed, 12 Apr 2017 06:44:19 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> Message-ID: <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> On Wednesday, 12 April 2017 12:56:32 UTC+1, Jussi Piitulainen wrote: > bartc writes: > > > These are straightforward language enhancements. > > FYI, the question is not how to optimize the code but how to prevent the > programmer from writing stupid code in the first place. Someone > suggested that a language should do that. The 'stupid code' thing is a red herring. I assume the code people write is there for a reason. But the language can also play a part in not allowing certain things to be expressed naturally. So the for-loop in the example has to have a control-variable even if it's not referenced. There is no 'case' or 'switch' statement to test one expression against multiple possibilities; usually the suggestion is to use a Dict, more of a heavyweight feature of unknown efficiency. You can't take a numeric constant and give it a name, without turning it into a global variable which now needs a lookup and which can't be folded with other constants. It seems Python completely disregards the question of efficiency, leaving that minor detail to implementations. But they can only work with what the language provides. -- bartc From rustompmody at gmail.com Wed Apr 12 09:48:51 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 12 Apr 2017 06:48:51 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: <878tn5zqxf.fsf@bsb.me.uk> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> <878tn5zqxf.fsf@bsb.me.uk> Message-ID: <8daf1dfa-9deb-48c0-826b-07e0b350fa27@googlegroups.com> On Wednesday, April 12, 2017 at 7:09:04 PM UTC+5:30, Ben Bacarisse wrote: > Steve D'Aprano writes: > > > On Wed, 12 Apr 2017 03:39 am, Paul Rubin wrote: > > > >> I still do my everyday stuff in Python and I'd like to get more > >> conversant with stuff like numpy, but it feels like an old-fashioned > >> language these days. > > > > "Old fashioned"? With await/async just added to the language, and type > > annotations? And comprehensions and iterators? > > > > Admittedly type annotations are mostly of interest to large projects with > > many developers and a huge code base. But the rest? > > > > Comprehensions may have been around for a decade or two in Haskell, but most > > older languages don't have them. I'm pretty sure Java doesn't. Does > > Javascript? Comprehensions feel like a fancy new language feature to > > me. > > They've been in in Haskell for nearly three decades, but they were > around before that. Miranda had them, as did Miranda's immediate > predecessor, KRC. KRC dates from about 1980, so if you've been using > that lineage of languages, list comprehensions have been a standard > feature for 37 years. I've been using them almost my entire programming > life. > > It seems odd that ECMAScript (the JavaScript standard) does not have > them, but then JS seems to hide its function nature under an imperative > bushel. Comes from set comprehensions in SETL (I think) ie about 50 years old https://en.wikipedia.org/wiki/SETL Which itself goes back another 50 years to Zermelo-Fraenkel set theory [Miranda actually used to call list comprehensions as ZF-expressions] From larry.martell at gmail.com Wed Apr 12 09:51:12 2017 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 12 Apr 2017 09:51:12 -0400 Subject: external process not terminating Message-ID: I have an app (using 2.7) that processes requests. When a request of type "A" is received I need to start an external process. When a request of type "B" is received I need to check and see if that external process has completed or not and then do some stuff depending on if it has or not. The issue I am running into is that when the external process is done is does not exit, it goes into a zombie state, e.g.: 1 Z root 13703 13644 0 80 0 - 0 exit 09:37 ? 00:00:00 [python] Initially I was starting the process with Popen like this: DEVNULL = open(os.devnull, "wb") subprocess.Popen(cmd+args, stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL, close_fds=True) I tried using os.spawn: os.spawnv(os.P_NOWAIT, 'python', cmd+args) But still the process did not exit. Anyone know how I can get the external process to terminate when done? TIA! From torriem at gmail.com Wed Apr 12 10:40:56 2017 From: torriem at gmail.com (Michael Torrie) Date: Wed, 12 Apr 2017 08:40:56 -0600 Subject: Python and the need for speed In-Reply-To: <87k26qlatw.fsf@nightsong.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <87k26qlatw.fsf@nightsong.com> Message-ID: <0c09c8c2-e68c-ed58-5603-0efa2aebbe70@gmail.com> On 04/11/2017 06:38 PM, Paul Rubin wrote: > Grant Edwards writes: >> If there are now other Python implementations (e.g. MicroPython) with >> C APIs that differ from CPython, then it seems like it is no longer >> redundant to say "the CPython API". > > Perhaps there should be an attempt to define a unified API like the Java > JNI, Lisp FFI's, etc. This is not at all what the CPython API is all about. The CPython API is of course for extending Python with or embedding Python in C. Equivalent to the JNI and Lisp FFI is the CFFI [1]. The JNI, the FFI, and the CFFI, are all for calling native code from within their respective languages, if I understand correctly. They don't define a standard way for native code to call into these languages. [1] https://cffi.readthedocs.io/en/latest/ From torriem at gmail.com Wed Apr 12 10:46:45 2017 From: torriem at gmail.com (Michael Torrie) Date: Wed, 12 Apr 2017 08:46:45 -0600 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/12/2017 03:33 AM, Brecht Machiels wrote: > However, rinohtype is located in a very different niche and it would > greatly benefit a lot from a speed boost. Rendering the Sphinx > documentation (311 pages) takes almost 10 minutes on my i7, which is > simply too long given the available processing power. And yes, I have > spent a lot time profiling and optimizing the code. You're always > welcome to demonstrate my incompetence by means of a pull request, of > course ;-) You talked about PyPy before. Did you try rinohtype on pypy3? I tried to download pypy3 just now but the x86_64 binary package isn't compatible with my old distro (Centos 7) and I don't quite have time to build it from source. But if I can get that running I would like to try your rinoh demos with it and see how it performs. I've seen some pretty good speedups on slow, CPU-intensive python code before with pypy. From davidgshi at yahoo.co.uk Wed Apr 12 10:54:32 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Wed, 12 Apr 2017 14:54:32 +0000 (UTC) Subject: XML tree to a pandas dataframe References: <1040609956.845534.1492008872146.ref@mail.yahoo.com> Message-ID: <1040609956.845534.1492008872146@mail.yahoo.com> What is the best way to convert XML document into a pandas dataframe? Regards. David From brecht__gmane at mos6581.org Wed Apr 12 11:04:23 2017 From: brecht__gmane at mos6581.org (Brecht Machiels) Date: Wed, 12 Apr 2017 17:04:23 +0200 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2017-04-12 14:46:45 +0000, Michael Torrie said: > On 04/12/2017 03:33 AM, Brecht Machiels wrote: >> However, rinohtype is located in a very different niche and it would >> greatly benefit a lot from a speed boost. Rendering the Sphinx >> documentation (311 pages) takes almost 10 minutes on my i7, which is >> simply too long given the available processing power. And yes, I have >> spent a lot time profiling and optimizing the code. You're always >> welcome to demonstrate my incompetence by means of a pull request, of >> course ;-) > > You talked about PyPy before. Did you try rinohtype on pypy3? I did. See https://bitbucket.org/pypy/pypy/issues/2365/rinohtype-much-slower-on-pypy3 A long time ago, I also backported rinohtype to Python2 to test with PyPy2. See https://mail.python.org/pipermail/pypy-dev/2015-August/013767.html I haven't been able to try the latest PyPy3 release because there is no binary for macOS, and building it using pyenv fails (https://github.com/pyenv/pyenv/issues/890). > I tried to download pypy3 just now but the x86_64 binary package isn't > compatible with my old distro (Centos 7) and I don't quite have time to > build it from source. But if I can get that running I would like to try > your rinoh demos with it and see how it performs. I've seen some pretty > good speedups on slow, CPU-intensive python code before with pypy. It would be great if you could run the benchmark I mention in my first link and share the results. Highly appreciated! Best regards, Brecht From fpm at u.washington.edu Wed Apr 12 11:28:13 2017 From: fpm at u.washington.edu (Frank Miles) Date: Wed, 12 Apr 2017 15:28:13 -0000 (UTC) Subject: closing image automatically in for loop , python References: <8e5d24d1-1453-4526-88d5-790702c00f1c@googlegroups.com> Message-ID: On Wed, 12 Apr 2017 04:18:45 -0700, Masoud Afshari wrote: > filename ="Ex_resample" +'_sdf_'+ str(n)+'.dat' > with open(filename, 'rb') as f: #read binary file data = np.fromfile(f, > dtype='float64', count=nx*ny) #float64 for Double precision float numbers > Ex = np.reshape(data, [ny, nx], order='F') > #print Ex.max() Your use of the 'with open(...) as f :' should automatically close access to filename once beyond that section. In your posting, the commented-out sections and garbled spacing would prevent anything useful from happening. Does that accurately reflect the code you're trying to run? -F From davidgshi at yahoo.co.uk Wed Apr 12 11:33:07 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Wed, 12 Apr 2017 15:33:07 +0000 (UTC) Subject: How to pd.read_csv into a DataFrame with multiple seperators? References: <485144351.858803.1492011187414.ref@mail.yahoo.com> Message-ID: <485144351.858803.1492011187414@mail.yahoo.com> Have a look at this example. http://www.ebi.ac.uk/ena/data/warehouse/search?query=%22geo_circ(-0.587,-90.5713,170)%22&result=sequence_release&display=text How to pd.read_csv into a DataFrame with multiple seperators? Regards. David From jussi.piitulainen at helsinki.fi Wed Apr 12 11:49:51 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 12 Apr 2017 18:49:51 +0300 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> Message-ID: bart4858 at gmail.com writes: > On Wednesday, 12 April 2017 12:56:32 UTC+1, Jussi Piitulainen wrote: >> bartc writes: >> > >> > These are straightforward language enhancements. >> >> FYI, the question is not how to optimize the code but how to prevent >> the programmer from writing stupid code in the first place. Someone >> suggested that a language should do that. > > The 'stupid code' thing is a red herring. I assume the code people > write is there for a reason. So you walked in to a conversation about something that does not interest you and simply started talking about your own thing. Because of course you did. I get confused when you do that. From irmen.NOSPAM at xs4all.nl Wed Apr 12 12:57:18 2017 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Wed, 12 Apr 2017 18:57:18 +0200 Subject: IOError: [Errno 12] Not enough space In-Reply-To: References: <8199cb7a-fded-42b1-8a76-c9a2de4d7c78@googlegroups.com> <58ed0e3c$0$829$e4fe514c@news.xs4all.nl> Message-ID: <58ee5c6c$0$726$e4fe514c@news.xs4all.nl> On 12-4-2017 7:54, LnT wrote: > > Hi Irmen, > > you may please find full log @ https://pastebin.mozilla.org/9018753 I have no idea what I'm looking at. But my initial response was wrong, see the reply by eryk sun; your error has nothing to do with disk space but rather, a lack of system memory. Irmen From Jack at nichesoftsolutions.com Wed Apr 12 13:50:39 2017 From: Jack at nichesoftsolutions.com (Jack at nichesoftsolutions.com) Date: Wed, 12 Apr 2017 10:50:39 -0700 (PDT) Subject: HOT LIST Message-ID: Hi Hope you doing great! Greeting from Niche Soft Solutions. I would like to present our topnotch consultants currently available. Please have a look at the below hot list of Niche Soft Solutions and mail your Direct Client requirements to jack at nichesoftsolutions.com Please add my Email ID to your mailing list and send the requirements on daily basis You can reach me at 503-536-2043 Name Technology Experience Visa status Current Location Relocation Tapasya .Net & Data Analyst 10+ H1B CO OPEN Malika Java 9+ H1B CA OPEN Vinoth Data Stage Developer 7+ H1B MI OPEN Sumathi QA Tester 8+ H1B CT OPEN Rahul People Soft 8+ H1B CA OPEN Laxman Java 10+ H1B VA VA Pooja Gosh WebMethod Developer 7+ H1B CA OPEN Rashi Guidewire Developer 8+ H1B TX OPEN Shabeer WebMethod Developer 7+ H1B NC OPEN From bart4858 at gmail.com Wed Apr 12 14:27:04 2017 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Wed, 12 Apr 2017 11:27:04 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> Message-ID: <9506d7a6-cdd8-4285-8c2d-4c71b48be5da@googlegroups.com> On Wednesday, 12 April 2017 16:50:01 UTC+1, Jussi Piitulainen wrote: > bart4858 at gmail.com writes: > > > On Wednesday, 12 April 2017 12:56:32 UTC+1, Jussi Piitulainen wrote: > >> bartc writes: > >> > > > >> > These are straightforward language enhancements. > >> > >> FYI, the question is not how to optimize the code but how to prevent > >> the programmer from writing stupid code in the first place. Someone > >> suggested that a language should do that. > > > > The 'stupid code' thing is a red herring. I assume the code people > > write is there for a reason. > > So you walked in to a conversation about something that does not > interest you and simply started talking about your own thing. > > Because of course you did. > > I get confused when you do that. Huh? The subject is making Python faster. It's generally agreed that being very dynamic makes that harder, everything else being equal. I don't agree that stopping people writing silly code is that helpful. It might be in the itself silly example of 'for i in range(10): x+=1', but usually there will be a good reason for such a loop. If you want to argue that bad choices of algorithm and bad code are a factor in performance, then there's that too. But that applies equally to every language. You can choose the best algorithm and perfectly correct code, and Python will still most likely execute it more slowely than a less dynamic language. If by some chance Python is faster, then it will probably be because it's offloading the real work to some library, not written in Python. From rosuav at gmail.com Wed Apr 12 14:38:47 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Apr 2017 04:38:47 +1000 Subject: XML tree to a pandas dataframe In-Reply-To: <1040609956.845534.1492008872146@mail.yahoo.com> References: <1040609956.845534.1492008872146.ref@mail.yahoo.com> <1040609956.845534.1492008872146@mail.yahoo.com> Message-ID: On Thu, Apr 13, 2017 at 12:54 AM, David Shi via Python-list wrote: > What is the best way to convert XML document into a pandas dataframe? > Regards. > David I don't know. What's the least painful way to gouge out my eyes with a rusty fork? You're going to need to know the layout of the XML document. Since XML is not, by nature, a tabular data structure, it's not going to directly translate into a dataframe (in the way that, say, a CSV file can). You'll need to figure out what represents a row and what represents the fields within that row. This will probably involve a large amount of work parsing the XML file; you can do the low level heavy lifting with lxml or equivalent, but compiling the parsed data into rows and columns is all up to you. In all sincerity I say to you: Good luck. ChrisA From bart4858 at gmail.com Wed Apr 12 14:45:16 2017 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Wed, 12 Apr 2017 11:45:16 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3d3ce9b0-5388-42fe-9472-a511e0e10d8d@googlegroups.com> On Wednesday, 12 April 2017 16:04:53 UTC+1, Brecht Machiels wrote: > On 2017-04-12 14:46:45 +0000, Michael Torrie said: > It would be great if you could run the benchmark I mention in my first > link and share the results. Highly appreciated! Were you ever able to isolate what it was that's taking up most of the time? Either in general or in the bit that pypy has trouble with. Or is execution time spread too widely? (I looked at your project but it's too large, and didn't get much further with the github benchmark, which requires me to subscribe, but the .sh file extensions don't seem too promising to someone on Windows.) Your program seems to be to do with typesetting. Is it possible to at least least quantity the work that is being done in terms of total bytes (and total files) of input, and bytes of output? That might enable comparisons with other systems executing similar tasks, to see if the Python version is taking unreasonably long. -- bartc From python at deborahswanson.net Wed Apr 12 15:57:08 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Wed, 12 Apr 2017 12:57:08 -0700 Subject: Namedtuples: some unexpected inconveniences Message-ID: <008101d2b3c6$f8261eb0$27b23dae@sambora> I won't say the following points are categorically true, but I became convinced enough they were true in this instance that I abandoned the advised strategy. Which was to use defaultdict to group the list of namedtuples by one of the fields for the purpose of determining whether certain other fields in each group were either missing values or contained contradictory values. Are these bugs, or was there something I could have done to avoid these problems? Or are they just things you need to know working with namedtuples? The list of namedtuples was created with: infile = open("E:\\Coding projects\\Pycharm\\Moving\\Moving 2017 in - test.csv") rows = csv.reader(infile)fieldnames = next(rows) Record = namedtuple("Record", fieldnames) records = [Record._make(fieldnames)] records.extend(Record._make(row) for row in rows) . . . (many lines of field processing code) . . . then the attempt to group the records by title: import operator records[1:] = sorted(records[1:], key=operator.attrgetter("title", "Date")) groups = defaultdict() for r in records[1:]: # if the key doesn't exist, make a new group if r.title not in groups.keys(): groups[r.title] = [r] # if key (group) exists, append this record else: groups[r.title].append(r) (Please note that this default dict will not automatically make new keys when they are encountered, possibly because the keys of the defaultdict are made from namedtuples and the values are namedtuples. So you have to include the step to make a new key when a key is not found.) If you succeed in modifying records in a group, the dismaying thing is that the underlying records are not updated, making the entire exercise totally pointless, which was a severe and unexpected inconvenience. It looks like the values and the structure were only copied from the original list of namedtuples to the defaultdict. The rows of the grouped-by dict still behave like namedtuples, but they are no longer the same namedtuples as the original list of namedtuples. (I'm sure I didn't say that quite right, please correct me if you have better words for it.) It might be possible to complete the operation and then write out the groups of rows of namedtuples in the dict to a simple list of namedtuples, discarding the original, but at the time I noticed that modifying rows in a group didn't change the values in the original list of namedtuples, I still had further to go with the dict of groups, and it was looking easier by the minute to solve the missing values problem directly from the original list of namedtuples, so that's what I did. If requested I can reproduce how I saw that the original list of namedtuples was not changed when I modified field values in group rows of the dict, but it's lengthy and messy. It might be worthwhile though if someone might see a mistake I made, though I found the same behavior several different ways. Which was when I called it barking up the wrong tree and quit trying to solve the problem that way. Another inconvenience is that there appears to be no way to access field values of a named tuple by variable, although I've had limited success accessing by variable indices. However, direct attempts to do so, like: values = {row[label] for row in group} (where 'label' is a variable for the field names of a namedtuple) gets "object has no attribute 'label' or, where 'record' is a row in a list of namedtuples and 'label' is a variable for the fieldnames of a namedtuple: value = getattr(record, label) setattr(record, label, value) also don't work. You get the error 'object has no attribute 'label' every time. From python at mrabarnett.plus.com Wed Apr 12 16:42:12 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Apr 2017 21:42:12 +0100 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: <008101d2b3c6$f8261eb0$27b23dae@sambora> References: <008101d2b3c6$f8261eb0$27b23dae@sambora> Message-ID: <64bc7c73-8f33-ef87-8b21-bd0a6ef526e9@mrabarnett.plus.com> On 2017-04-12 20:57, Deborah Swanson wrote: > I won't say the following points are categorically true, but I became > convinced enough they were true in this instance that I abandoned the > advised strategy. Which was to use defaultdict to group the list of > namedtuples by one of the fields for the purpose of determining whether > certain other fields in each group were either missing values or > contained contradictory values. > > Are these bugs, or was there something I could have done to avoid these > problems? Or are they just things you need to know working with > namedtuples? > > The list of namedtuples was created with: > > infile = open("E:\\Coding projects\\Pycharm\\Moving\\Moving 2017 in - > test.csv") > rows = csv.reader(infile)fieldnames = next(rows) > Record = namedtuple("Record", fieldnames) > records = [Record._make(fieldnames)] > records.extend(Record._make(row) for row in rows) > . . . > (many lines of field processing code) > . . . > > then the attempt to group the records by title: > > import operator > records[1:] = sorted(records[1:], key=operator.attrgetter("title", > "Date")) groups = defaultdict() for r in records[1:]: > # if the key doesn't exist, make a new group > if r.title not in groups.keys(): > groups[r.title] = [r] > # if key (group) exists, append this record > else: > groups[r.title].append(r) > > (Please note that this default dict will not automatically make new keys > when they are encountered, possibly because the keys of the defaultdict > are made from namedtuples and the values are namedtuples. So you have to > include the step to make a new key when a key is not found.) > The defaultdict _will_ work when you use it properly. :-) The line should be: groups = defaultdict(list) so that it'll make a new list every time a new key is automatically added. Another point: namedtuples, as with normal tuples, are immutable; once created, you can't change an attribute. A dict might be a better bet. > If you succeed in modifying records in a group, the dismaying thing is > that the underlying records are not updated, making the entire exercise > totally pointless, which was a severe and unexpected inconvenience. > > It looks like the values and the structure were only copied from the > original list of namedtuples to the defaultdict. The rows of the > grouped-by dict still behave like namedtuples, but they are no longer > the same namedtuples as the original list of namedtuples. (I'm sure I > didn't say that quite right, please correct me if you have better words > for it.) > > It might be possible to complete the operation and then write out the > groups of rows of namedtuples in the dict to a simple list of > namedtuples, discarding the original, but at the time I noticed that > modifying rows in a group didn't change the values in the original list > of namedtuples, I still had further to go with the dict of groups, and > it was looking easier by the minute to solve the missing values problem > directly from the original list of namedtuples, so that's what I did. > > If requested I can reproduce how I saw that the original list of > namedtuples was not changed when I modified field values in group rows > of the dict, but it's lengthy and messy. It might be worthwhile though > if someone might see a mistake I made, though I found the same behavior > several different ways. Which was when I called it barking up the wrong > tree and quit trying to solve the problem that way. > > Another inconvenience is that there appears to be no way to access field > values of a named tuple by variable, although I've had limited success > accessing by variable indices. However, direct attempts to do so, like: > > values = {row[label] for row in group} > (where 'label' is a variable for the field names of a namedtuple) > > gets "object has no attribute 'label' > > or, where 'record' is a row in a list of namedtuples and 'label' is a > variable for the fieldnames of a namedtuple: > > value = getattr(record, label) > setattr(record, label, value) also don't work. > > You get the error 'object has no attribute 'label' every time. > From andrew.holway at otternetworks.de Wed Apr 12 16:42:22 2017 From: andrew.holway at otternetworks.de (andrew.holway at otternetworks.de) Date: Wed, 12 Apr 2017 13:42:22 -0700 (PDT) Subject: Passing parameters thru decorators Message-ID: Hi, I'm trying to work out how to pass parameters through decorators: class Meow(): def __init__(self, arg1, arg2): print("INIT ClassBasedDecoratorWithParams") print(arg1) print(arg2) def makebold(self, fn): def wrapped(): return "" + fn() + "" return wrapped banana = Meow("foo", "bar") @banana.makebold("foobar") def hello(): return "hello world" print(hello()) Returns error: INIT ClassBasedDecoratorWithParams Traceback (most recent call last): foo File "/Users/andrew/PycharmProjects/untitled3/meow5.py", line 15, in bar @banana.makebold("foobar") TypeError: wrapped() takes 0 positional arguments but 1 was given so I add a var to wrapped: def makebold(self, fn): def wrapped(flibble): print(flibble) return "" + fn() + "" return wrapped Returns error: INIT ClassBasedDecoratorWithParams Traceback (most recent call last): foo bar File "/Users/andrew/PycharmProjects/untitled3/meow5.py", line 16, in @banana.makebold("foobar") File "/Users/andrew/PycharmProjects/untitled3/meow5.py", line 11, in wrapped return "" + fn() + "" TypeError: 'str' object is not callable This is confusing me. How do I get hold of the "foobar" string so I can use it in the decorator? Cheers, Andrew From __peter__ at web.de Wed Apr 12 16:44:46 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 12 Apr 2017 22:44:46 +0200 Subject: Namedtuples: some unexpected inconveniences References: <008101d2b3c6$f8261eb0$27b23dae@sambora> Message-ID: Deborah Swanson wrote: > I won't say the following points are categorically true, but I became > convinced enough they were true in this instance that I abandoned the > advised strategy. Which was to use defaultdict to group the list of > namedtuples by one of the fields for the purpose of determining whether > certain other fields in each group were either missing values or > contained contradictory values. > > Are these bugs, or was there something I could have done to avoid these > problems? Or are they just things you need to know working with > namedtuples? > > The list of namedtuples was created with: > > infile = open("E:\\Coding projects\\Pycharm\\Moving\\Moving 2017 in - > test.csv") > rows = csv.reader(infile)fieldnames = next(rows) > Record = namedtuple("Record", fieldnames) > records = [Record._make(fieldnames)] > records.extend(Record._make(row) for row in rows) > . . . > (many lines of field processing code) > . . . > > then the attempt to group the records by title: > > import operator > records[1:] = sorted(records[1:], key=operator.attrgetter("title", > "Date")) Personally I would immediately discard the header row once and for all, not again and again on every operation. > groups = defaultdict() for r in records[1:]: > # if the key doesn't exist, make a new group > if r.title not in groups.keys(): > groups[r.title] = [r] > # if key (group) exists, append this record > else: > groups[r.title].append(r) You are not using the defaultdict the way it is intended; the groups can be built with groups = defaultdict(list) for r in records[1:]: groups[r.title].append(r) > (Please note that this default dict will not automatically make new keys > when they are encountered, possibly because the keys of the defaultdict > are made from namedtuples and the values are namedtuples. So you have to > include the step to make a new key when a key is not found.) > > If you succeed in modifying records in a group, the dismaying thing is > that the underlying records are not updated, making the entire exercise > totally pointless, which was a severe and unexpected inconvenience. > > It looks like the values and the structure were only copied from the > original list of namedtuples to the defaultdict. The rows of the > grouped-by dict still behave like namedtuples, but they are no longer > the same namedtuples as the original list of namedtuples. (I'm sure I > didn't say that quite right, please correct me if you have better words > for it.) They should be the same namedtuple. Something is wrong with your actual code or your diagnosis or both. > > It might be possible to complete the operation and then write out the > groups of rows of namedtuples in the dict to a simple list of > namedtuples, discarding the original, but at the time I noticed that > modifying rows in a group didn't change the values in the original list > of namedtuples, I still had further to go with the dict of groups, and > it was looking easier by the minute to solve the missing values problem > directly from the original list of namedtuples, so that's what I did. > > If requested I can reproduce how I saw that the original list of > namedtuples was not changed when I modified field values in group rows > of the dict, but it's lengthy and messy. It might be worthwhile though > if someone might see a mistake I made, though I found the same behavior > several different ways. Which was when I called it barking up the wrong > tree and quit trying to solve the problem that way. > > Another inconvenience is that there appears to be no way to access field > values of a named tuple by variable, although I've had limited success > accessing by variable indices. However, direct attempts to do so, like: > > values = {row[label] for row in group} > (where 'label' is a variable for the field names of a namedtuple) > > gets "object has no attribute 'label' > > or, where 'record' is a row in a list of namedtuples and 'label' is a > variable for the fieldnames of a namedtuple: > > value = getattr(record, label) That should work. > setattr(record, label, value) also don't work. > > You get the error 'object has no attribute 'label' every time. Indeed you cannot change the namedtuple's attributes. Like the "normal" tuple it is designed to be immutable. If you want changes in one list (the group) to appear in another (the original records) you need a mutable data type. From python at mrabarnett.plus.com Wed Apr 12 17:04:45 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Apr 2017 22:04:45 +0100 Subject: Passing parameters thru decorators In-Reply-To: References: Message-ID: On 2017-04-12 21:42, andrew.holway at otternetworks.de wrote: > Hi, > > I'm trying to work out how to pass parameters through decorators: > > class Meow(): > > def __init__(self, arg1, arg2): > print("INIT ClassBasedDecoratorWithParams") > print(arg1) > print(arg2) > > def makebold(self, fn): > def wrapped(): > return "" + fn() + "" > return wrapped > > banana = Meow("foo", "bar") > @banana.makebold("foobar") > > def hello(): > return "hello world" > > print(hello()) > > > Returns error: > INIT ClassBasedDecoratorWithParams > Traceback (most recent call last): > foo > File "/Users/andrew/PycharmProjects/untitled3/meow5.py", line 15, in > bar > @banana.makebold("foobar") > TypeError: wrapped() takes 0 positional arguments but 1 was given > > > so I add a var to wrapped: > > def makebold(self, fn): > def wrapped(flibble): > print(flibble) > return "" + fn() + "" > return wrapped > > Returns error: > INIT ClassBasedDecoratorWithParams > Traceback (most recent call last): > foo > bar > File "/Users/andrew/PycharmProjects/untitled3/meow5.py", line 16, in > > @banana.makebold("foobar") > File "/Users/andrew/PycharmProjects/untitled3/meow5.py", line 11, in wrapped > return "" + fn() + "" > TypeError: 'str' object is not callable > > This is confusing me. How do I get hold of the "foobar" string so I can use it in the decorator? > You're passing "foobar" into 'makebold' in the parameter 'fn' and then trying to call 'fn' in the return statement. You can't call a string. From python at deborahswanson.net Wed Apr 12 17:17:12 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Wed, 12 Apr 2017 14:17:12 -0700 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: <64bc7c73-8f33-ef87-8b21-bd0a6ef526e9@mrabarnett.plus.com> Message-ID: <009601d2b3d2$2799ca60$27b23dae@sambora> > -----Original Message----- > From: Python-list > [mailto:python-list-bounces+python=deborahswanson.net at python.o > rg] On Behalf Of MRAB > Sent: Wednesday, April 12, 2017 1:42 PM > To: python-list at python.org > Subject: Re: Namedtuples: some unexpected inconveniences > > > On 2017-04-12 20:57, Deborah Swanson wrote: > > Are these bugs, or was there something I could have done to avoid > > these problems? Or are they just things you need to know > working with namedtuples? > > > > The list of namedtuples was created with: > > > > infile = open("E:\\Coding projects\\Pycharm\\Moving\\Moving > 2017 in - > > test.csv") > > rows = csv.reader(infile)fieldnames = next(rows) > > Record = namedtuple("Record", fieldnames) > > records = [Record._make(fieldnames)] > > records.extend(Record._make(row) for row in rows) > > . . . > > (many lines of field processing code) > > . . . > > > > then the attempt to group the records by title: > > > > import operator > > records[1:] = sorted(records[1:], key=operator.attrgetter("title", > > "Date")) groups = defaultdict() for r in records[1:]: > > # if the key doesn't exist, make a new group > > if r.title not in groups.keys(): > > groups[r.title] = [r] > > # if key (group) exists, append this record > > else: > > groups[r.title].append(r) > > > > (Please note that this default dict will not automatically make new > > keys when they are encountered, possibly because the keys of the > > defaultdict are made from namedtuples and the values are > namedtuples. > > So you have to include the step to make a new key when a key is not > > found.) MRAB said: > The defaultdict _will_ work when you use it properly. :-) > > The line should be: > > groups = defaultdict(list) > > so that it'll make a new list every time a new key is > automatically added. Arg. Now I remember the thought crossing my mind early on, and noticing that the characterizing property of a defaultdict was what you set the default to be. Too bad I forgot that useful thought once I was entangled with all those other problems. Thanks for jogging that memory stuck in a hidey hole. > Another point: namedtuples, as with normal tuples, are immutable; once > created, you can't change an attribute. A dict might be a better bet. Yes, namedtuples still being tuples was a point mentioned in passing by someone, I think Steve D'Aprano, but I didn't immediately see that as being the roadblock to accessing field values by variable. It does make sense now though, although others on the list also didn't see it, so I'm not feeling as bad about it as I could. Namedtuples absolutely was the right data structure for two thirds of this program. I only ran into trouble with it trying to do the defaultdict group by thing. And it all turned out ok just by going back to the original list. Now, if I could understand why the namedtuples grouped by the defaultdict were only copied instead of remaining the same namedtuples as the list they were copied from, that should wrap this set of problems up. Many thanks again! Deborah From __peter__ at web.de Wed Apr 12 17:22:33 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 12 Apr 2017 23:22:33 +0200 Subject: Passing parameters thru decorators References: Message-ID: andrew.holway at otternetworks.de wrote: > Hi, > > I'm trying to work out how to pass parameters through decorators: > > class Meow(): > > def __init__(self, arg1, arg2): > print("INIT ClassBasedDecoratorWithParams") > print(arg1) > print(arg2) > > def makebold(self, fn): > def wrapped(): > return "" + fn() + "" > return wrapped > > banana = Meow("foo", "bar") > @banana.makebold("foobar") > > def hello(): > return "hello world" > > print(hello()) > > > Returns error: > INIT ClassBasedDecoratorWithParams > Traceback (most recent call last): > foo > File "/Users/andrew/PycharmProjects/untitled3/meow5.py", line 15, in > > bar > @banana.makebold("foobar") > TypeError: wrapped() takes 0 positional arguments but 1 was given > > > so I add a var to wrapped: > > def makebold(self, fn): > def wrapped(flibble): > print(flibble) > return "" + fn() + "" > return wrapped > > Returns error: > INIT ClassBasedDecoratorWithParams > Traceback (most recent call last): > foo > bar > File "/Users/andrew/PycharmProjects/untitled3/meow5.py", line 16, in > > > @banana.makebold("foobar") > File "/Users/andrew/PycharmProjects/untitled3/meow5.py", line 11, in > wrapped > return "" + fn() + "" > TypeError: 'str' object is not callable > > This is confusing me. How do I get hold of the "foobar" string so I can > use it in the decorator? You need one more level of indirection: class Meow(): def __init__(self, arg1, arg2): print("INIT ClassBasedDecoratorWithParams") print(arg1) print(arg2) def makebold(self, flibble): def decorator(fn): def wrapped(): print("flibble =", flibble) return "" + fn() + "" return wrapped return decorator banana = Meow("foo", "bar") @banana.makebold("foobar") def hello(): return "hello world" print(hello()) From larry.martell at gmail.com Wed Apr 12 17:46:32 2017 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 12 Apr 2017 17:46:32 -0400 Subject: external process not terminating In-Reply-To: <6kfsec56g7aikjqm2dedt9i2g2ohrnf6bh@4ax.com> References: <6kfsec56g7aikjqm2dedt9i2g2ohrnf6bh@4ax.com> Message-ID: On Wed, Apr 12, 2017 at 10:51 AM, Dennis Lee Bieber wrote: > On Wed, 12 Apr 2017 09:51:12 -0400, Larry Martell > declaimed the following: > > >> >>Anyone know how I can get the external process to terminate when done? >> > > It has... You just haven't cleaned up after it... > > https://en.wikipedia.org/wiki/Zombie_process > > """ > This occurs for child processes, where the entry is still needed to allow > the parent process to read its child's exit status: once the exit status is > read via the wait system call, the zombie's entry is removed from the > process table and it is said to be "reaped". > """ Thanks. I knew that but I had lost the forest for the trees. I added a call to os.waitpid() and now all is well. From python at deborahswanson.net Wed Apr 12 18:00:06 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Wed, 12 Apr 2017 15:00:06 -0700 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: Message-ID: <00a901d2b3d8$25d09460$27b23dae@sambora> Peter Otten wrote, on Wednesday, April 12, 2017 1:45 PM > > Deborah Swanson wrote: > > > I won't say the following points are categorically true, but I became > > convinced enough they were true in this instance that I abandoned the > > advised strategy. Which was to use defaultdict to group the list of > > namedtuples by one of the fields for the purpose of determining > > whether certain other fields in each group were either missing values > > or contained contradictory values. > > > > Are these bugs, or was there something I could have done to avoid > > these problems? Or are they just things you need to know working with > > namedtuples? > > > > The list of namedtuples was created with: > > > > infile = open("E:\\Coding projects\\Pycharm\\Moving\\Moving 2017 in - > > test.csv") > > rows = csv.reader(infile)fieldnames = next(rows) > > Record = namedtuple("Record", fieldnames) > > records = [Record._make(fieldnames)] > > records.extend(Record._make(row) for row in rows) > > . . . > > (many lines of field processing code) > > . . . > > > > then the attempt to group the records by title: > > > > import operator > > records[1:] = sorted(records[1:], key=operator.attrgetter("title", > > "Date")) > > Personally I would immediately discard the header row once and for all, not > again and again on every operation. Well, perhaps, but I need the header row to stay in place to write the list to a csv when I'm done (which is why it's there in the first place). There might be a tiny performance edge in discarding the header row for the sort, but there would also be a hit to recreate it at output time. > > groups = defaultdict() for r in records[1:]: > > # if the key doesn't exist, make a new group > > if r.title not in groups.keys(): > > groups[r.title] = [r] > > # if key (group) exists, append this record > > else: > > groups[r.title].append(r) > > You are not using the defaultdict the way it is intended; the > groups can be built with > > groups = defaultdict(list) > for r in records[1:]: > groups[r.title].append(r) Yes, going back to your original post I see now that's what you gave, and it's probably why I noticed defaultdict's being characterized by what you make the default to be. Too bad I lost track of that. > > (Please note that this default dict will not automatically make new > > keys when they are encountered, possibly because the keys of the > > defaultdict are made from namedtuples and the values are namedtuples. > > So you have to include the step to make a new key when a key is not > > found.) > > > > If you succeed in modifying records in a group, the dismaying thing is > > that the underlying records are not updated, making the entire > > exercise totally pointless, which was a severe and unexpected > > inconvenience. > > > > It looks like the values and the structure were only copied from the > > original list of namedtuples to the defaultdict. The rows of the > > grouped-by dict still behave like namedtuples, but they are no longer > > the same namedtuples as the original list of namedtuples. (I'm sure I > > didn't say that quite right, please correct me if you have better > > words for it.) > > They should be the same namedtuple. Something is wrong with > your actual code or your diagnosis or both. Well, I didn't see them behaving as the same namedtuples, and I looked hard at it, many different ways. If someone could point out the mistake I might have made to get only copies of them or why they necessarily would be the same namedtuples, I'd certainly look into it. Or better yet some code that does the same thing and they remain the same ones. (But I think you got it right in your last sentence below. defaultdict copied them because they were immutable, leaving the original list unchanged.) > > It might be possible to complete the operation and then write out the > > groups of rows of namedtuples in the dict to a simple list of > > namedtuples, discarding the original, but at the time I noticed that > > modifying rows in a group didn't change the values in the original > > list of namedtuples, I still had further to go with the dict of > > groups, and it was looking easier by the minute to solve the missing > > values problem directly from the original list of namedtuples, so > > that's what I did. > > > > If requested I can reproduce how I saw that the original list of > > namedtuples was not changed when I modified field values in group rows > > of the dict, but it's lengthy and messy. It might be worthwhile though > > if someone might see a mistake I made, though I found the same > > behavior several different ways. Which was when I called it barking up > > the wrong tree and quit trying to solve the problem that way. > > > > Another inconvenience is that there appears to be no way to access > > field values of a named tuple by variable, although I've had limited > > success accessing by variable indices. However, direct attempts to do > > so, like: > > > > values = {row[label] for row in group} > > (where 'label' is a variable for the field names of a namedtuple) > > > > gets "object has no attribute 'label' > > > > or, where 'record' is a row in a list of namedtuples and 'label' is a > > variable for the fieldnames of a namedtuple: > > > > value = getattr(record, label) > > That should work. We may agree that it *should* work, by an intuitive grasp of how it should work, but it doesn't. You get "object has no attribute 'label'. It wants to see one of the specific names of a defined field and it rejects the variable as an invalid attribute. I think MRAB nailed it by pointing out that as fundamentally a tuple itself, a namedtuple is immutable, and its elements can't be referenced by variable. > > setattr(record, label, value) also don't work. > > > > You get the error 'object has no attribute 'label' every time. > > Indeed you cannot change the namedtuple's attributes. Like the "normal" > tuple it is designed to be immutable. If you want changes in one list (the > group) to appear in another (the original records) you need a mutable data > type. Sadly, that does seem to be the correct conclusion here. From __peter__ at web.de Wed Apr 12 18:15:18 2017 From: __peter__ at web.de (Peter Otten) Date: Thu, 13 Apr 2017 00:15:18 +0200 Subject: Namedtuples: some unexpected inconveniences References: <00a901d2b3d8$25d09460$27b23dae@sambora> Message-ID: Deborah Swanson wrote: >> >value = getattr(record, label) >> >> That should work. > > We may agree that it *should* work, by an intuitive grasp of how it > should work, but it doesn't. You get "object has no attribute 'label'. Only if the namedtuple (1) does not have a label attribute and (2) the value of the name label is the string "label" In that case both label = "label" getattr(record, label) and record.label will fail with the same AttributeError. The problem is *not* the dynamic access through getattr(). >> Indeed you cannot change the namedtuple's attributes. Like the "normal" >> tuple it is designed to be immutable. If you want changes in one list >> (the group) to appear in another (the original records) you need a >> mutable data type. > > Sadly, that does seem to be the correct conclusion here. Think hard if you really need the original list. From python at lucidity.plus.com Wed Apr 12 18:15:45 2017 From: python at lucidity.plus.com (Erik) Date: Wed, 12 Apr 2017 23:15:45 +0100 Subject: Merging multiple sorted sequences. Message-ID: Hi. I need to be able to lazily merge a variable number of already-sorted(*) variable-length sequences into a single sorted sequence. The merge should continue until the longest sequence has been exhausted. (*) They may in practice be a lazy source of data known to only ever be generated in an order that's "sorted" from the POV of this function. I have the following - can anyone think of any improvements (other than indentation style on the try/excepts ;) )? This seems like the sort of thing for which there might be a built-in or recipe that I've missed. ----------------------------------------- def merge(*sources): items = [] for source in (iter(s) for s in sources): try: items.append([next(source), source]) except StopIteration: pass while len(items) > 1: items.sort(key=lambda item: item[0]) lowest = items[0] yield lowest[0] try: lowest[0] = next(lowest[1]) except StopIteration: del items[0] if len(items) != 0: yield items[0][0] yield from items[0][1] ----------------------------------------- Test code: ----------------------------------------- a = range(10) b = range(4, 50, 3) c = range(20, 100, 5) # Greedy version to verify result: greedy = list(a) + list(b) + list(c) greedy.sort() # Test multiple sequences: assert list(merge(a, b, c)) == greedy # Test a single sequence: assert list(merge(greedy)) == list(merge(a, b, c)) # Test no sequences: assert list(merge()) == [] assert list(merge([], (), range(0))) == [] ----------------------------------------- Thanks, E. From __peter__ at web.de Wed Apr 12 18:42:41 2017 From: __peter__ at web.de (Peter Otten) Date: Thu, 13 Apr 2017 00:42:41 +0200 Subject: Merging multiple sorted sequences. References: Message-ID: Erik wrote: > I need to be able to lazily merge a variable number of already-sorted(*) > variable-length sequences into a single sorted sequence. https://docs.python.org/dev/library/heapq.html#heapq.merge From ian.g.kelly at gmail.com Wed Apr 12 18:44:07 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 12 Apr 2017 16:44:07 -0600 Subject: Merging multiple sorted sequences. In-Reply-To: References: Message-ID: On Wed, Apr 12, 2017 at 4:15 PM, Erik wrote: > Hi. > > I need to be able to lazily merge a variable number of already-sorted(*) > variable-length sequences into a single sorted sequence. The merge should > continue until the longest sequence has been exhausted. > > (*) They may in practice be a lazy source of data known to only ever be > generated in an order that's "sorted" from the POV of this function. > > I have the following - can anyone think of any improvements (other than > indentation style on the try/excepts ;) )? This seems like the sort of thing > for which there might be a built-in or recipe that I've missed. There probably should be. I know I've implemented something similar in the past. > ----------------------------------------- > def merge(*sources): > items = [] > for source in (iter(s) for s in sources): > try: items.append([next(source), source]) > except StopIteration: pass > > while len(items) > 1: > items.sort(key=lambda item: item[0]) This might be okay since Timsort on an already-sorted list should be O(n). But there's not really any need to keep them sorted and I would just use "lowest = min(items, key=itemgetter(0))". > lowest = items[0] > yield lowest[0] > > try: lowest[0] = next(lowest[1]) > except StopIteration: del items[0] > > if len(items) != 0: "if items:" > yield items[0][0] > yield from items[0][1] > ----------------------------------------- From ian.g.kelly at gmail.com Wed Apr 12 18:45:57 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 12 Apr 2017 16:45:57 -0600 Subject: Merging multiple sorted sequences. In-Reply-To: References: Message-ID: On Wed, Apr 12, 2017 at 4:44 PM, Ian Kelly wrote: > On Wed, Apr 12, 2017 at 4:15 PM, Erik wrote: >> while len(items) > 1: >> items.sort(key=lambda item: item[0]) > > This might be okay since Timsort on an already-sorted list should be > O(n). But there's not really any need to keep them sorted and I would > just use "lowest = min(items, key=itemgetter(0))". Actually, you should consider using a heap. From cs at zip.com.au Wed Apr 12 18:52:13 2017 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 13 Apr 2017 08:52:13 +1000 Subject: Merging multiple sorted sequences. In-Reply-To: References: Message-ID: <20170412225213.GA20243@cskk.homeip.net> On 12Apr2017 23:15, Erik wrote: >I need to be able to lazily merge a variable number of already-sorted(*) >variable-length sequences into a single sorted sequence. The merge should >continue until the longest sequence has been exhausted. > >(*) They may in practice be a lazy source of data known to only ever >be generated in an order that's "sorted" from the POV of this >function. > >I have the following - can anyone think of any improvements (other >than indentation style on the try/excepts ;) )? This seems like the >sort of thing for which there might be a built-in or recipe that I've >missed. It can be improved. The big cost in yours is notionally the sort, which you do on every yield. For comparison, here's mine: https://bitbucket.org/cameron_simpson/css/src/tip/lib/python/cs/seq.py?fileviewer=file-view-default#seq.py-131 It keeps a heap (see the "heapq" standard module) containing tuples of the latest item from each source and the source iterable i.e. (item, iterable). That way the lowest item is always first on the heap, so you pop it off, which gets you (item, iterable). Yield the item. Fetch the next item from iterable. If that gets StopIteration, that is exhausted. Otherwise insert the new item and the iterable back into the heap. Repeat until the heap is empty. In this way you discard exhausted iterables and never need to re-examine them, and the sorting overhead is just heap insertion which is O(log n) for the heap size. Your method is O(n log n) for each item (sorting the collection of head items). The heap is faster because it makes a much weaker ordering guarentee, and for us the feature is that the front of the heap is the lowest item; the rest of the heap is partially ordered, not fully ordered. Insert and pop preserve that criterion. Cheers, Cameron Simpson From greg.ewing at canterbury.ac.nz Wed Apr 12 19:09:17 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 13 Apr 2017 11:09:17 +1200 Subject: Python and the need for speed In-Reply-To: <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> Message-ID: bart4858 at gmail.com wrote: > But the language can also play a part in not allowing certain things to be > expressed naturally. So the for-loop in the example has to have a > control-variable even if it's not referenced. If the compiler can recognise when code is "stupid", it's probably capable of doing something more intelligent than just rejecting it outright. E.g. it could notice that a loop variable wasn't used anywhere in the function and optimise it out. And it could recognise x += 1 and emit an ADD_ONE bytecode for it. Etc. -- Greg From python at lucidity.plus.com Wed Apr 12 19:09:42 2017 From: python at lucidity.plus.com (Erik) Date: Thu, 13 Apr 2017 00:09:42 +0100 Subject: Merging multiple sorted sequences. In-Reply-To: References: Message-ID: On 12/04/17 23:44, Ian Kelly wrote: > This might be okay since Timsort on an already-sorted list should be > O(n). But there's not really any need to keep them sorted and I would > just use "lowest = min(items, key=itemgetter(0))". Sure (and this was my main worry). I had it in my head for some reason that min() would return the smallest key, not the object (and hence I wouldn't be able to know which sequence object to get the next value from - sorting means it's always at index 0). But of course, min() returns the outer object containing the key so I don't need to sort them to know how to address the correct sequence object. operator.itemgetter() probably helps a bit, too ;) I've done all that and it works. Thanks, E. From python at lucidity.plus.com Wed Apr 12 19:15:47 2017 From: python at lucidity.plus.com (Erik) Date: Thu, 13 Apr 2017 00:15:47 +0100 Subject: Merging multiple sorted sequences. In-Reply-To: References: Message-ID: <1815e8aa-473d-db5d-019a-d4440f61a8f8@lucidity.plus.com> Hi Peter, On 12/04/17 23:42, Peter Otten wrote: > Erik wrote: > >> I need to be able to lazily merge a variable number of already-sorted(*) >> variable-length sequences into a single sorted sequence. > > https://docs.python.org/dev/library/heapq.html#heapq.merge AFAICT (looking at the Python 3.5 heapq implementation, albeit very briefly), it seems like that is a greedy algorithm. Am I missing something? Thanks, E. From python at deborahswanson.net Wed Apr 12 19:29:15 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Wed, 12 Apr 2017 16:29:15 -0700 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: Message-ID: <00bf01d2b3e4$99b6b8d0$27b23dae@sambora> Peter Otten wrote, on Wednesday, April 12, 2017 3:15 PM > > Deborah Swanson wrote: > > >> >value = getattr(record, label) > >> > >> That should work. > > > > We may agree that it *should* work, by an intuitive grasp of how it > > should work, but it doesn't. You get "object has no attribute 'label'. > > Only if the namedtuple > > (1) does not have a label attribute and > (2) the value of the name label is the string "label" > > In that case both > > label = "label" > getattr(record, label) > > and > > record.label > > will fail with the same AttributeError. The problem is *not* the dynamic > access through getattr(). Agreed, it's not getattr's fault. It's a small point, but I suspect getattr(record, label) would still fail, even if label's value is 'label' and only 'label', but what's the point of having a variable if it will only ever have just one value? The question would be whether the compiler (interpreter?) would look at getattr(record, label), evaluate label and see that there is a field named 'label', but I suspect it wouldn't take that many steps. It wants to see recordset.fieldname, and a bare "label" does not reference the object. I don't exactly understand your point (2). If the namedtuple does not have a label attribute, then getattr(record, label) will get the error whether the name label holds the string 'label' or not. And it wants to see recordset.fieldname, not just fieldname. But maybe I misunderstood what you were saying. This stuff is quite loopy to think about, at least for me it is. > >> Indeed you cannot change the namedtuple's attributes. Like the > >> "normal" tuple it is designed to be immutable. If you want changes in > >> one list (the group) to appear in another (the original records) you > >> need a mutable data type. > > > > Sadly, that does seem to be the correct conclusion here. > > Think hard if you really need the original list. It's possible you might transform the namedtuple into a mutable type, and I didn't try that. But it seems like the group-by defaultdict strategy would have to have a significant performance edge to be worth it and you wouldn't have any of the namedtuple properties to work with after the transformation. I also ran into some trouble with your algorithm that follows making the defaultdict, and I'm not sure what value there would be in hashing through that. Though I'm certainly willing to if you are. It worked to simply stay with the original list of namedtuples to begin with. I remain grateful for your introduction to the collections module. What a neat little package of tools! From bart4858 at gmail.com Wed Apr 12 19:30:38 2017 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Wed, 12 Apr 2017 16:30:38 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> Message-ID: <2759e6e0-ad95-466c-81f6-556133620999@googlegroups.com> On Thursday, 13 April 2017 00:09:35 UTC+1, Gregory Ewing wrote: > bart4858 at gmail.com wrote: > > > But the language can also play a part in not allowing certain things to be > > expressed naturally. So the for-loop in the example has to have a > > control-variable even if it's not referenced. > > If the compiler can recognise when code is "stupid", it's > probably capable of doing something more intelligent than > just rejecting it outright. > > E.g. it could notice that a loop variable wasn't used > anywhere in the function and optimise it out. And it could > recognise x += 1 and emit an ADD_ONE bytecode for it. > Etc. Maybe. (Although I think Python would have difficulty in turning x+=1 into a single opcode, if using normal object references and a shared object model.) But I wouldn't be happy about a language deciding my code is 'stupid'. I might for example have an N-times loop containing x+=1 because I want to know how long it takes to execute x+=1 N times. (This is a common problem with benchmarking code actually, as you can end up measuring how long it takes /not/ to do something instead of doing it!) Anyway that loop example (I think it was Steve's) was a simple illustration. It will usually be harder to figure out if a bit of code is rational. Even with x+=1, isn't it possible to override the + or += operation with user code? Code which change the handling method at each iteration. This is dynamism making a rod for its own back. 99.99...% of the time that won't happen, but... -- bartc From mikhailwas at gmail.com Wed Apr 12 19:42:01 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Thu, 13 Apr 2017 01:42:01 +0200 Subject: "Goto" statement in Python Message-ID: On 12 April 2017 at 02:44, Nathan Ernst wrote: > goto is a misunderstood and much misaligned creature. It is a very useful > feature, but like nearly any programming construct can be abused. > > Constructs like 'break', 'continue' or 'next' in languages like Python or > C/C++ are goto's with implied labels. > > As Mikhail said, goto's can be great to break out of nested loops (only a > handful of languages support named 'breaks'). > > So, instead of: > bool found = false; > for (int i = 0; i = ...; ++i) > { > for (int h = 0; h = ...; ++h) > { > if (some_condition) > found = true; > } > if (found) break; > } > > You can have: > > for (int i = 0; i = ...; ++i) > { > for (int h = 0; h = ...; ++h) > { > if (some_condition) > goto found; > } > } > // not found > > found: > // handle found > > The second is better for a number of reasons: it's clearer. It has fewer > variables (smaller stack), it has fewer branches (better for the CPU's > branch prediction), and it has fewer instructions (better for CPU > instruction cache). This is a trivial, contrived example, but I've seen > more than 4x nested loops using an exit flag like this (at every level of > the loops) that could have been replaced with a lot less code. > > People need to stop drinking "X is considered harmful." Even Dijkstra later > lamented that his "Goto considered harmful" paper was misinterpreted and > misrepresented as advocating that goto should never be used. > > Additionally, I'd recommend everyone read '"Considered Harmful" Essays > Considered Harmful': http://meyerweb.com/eric/comment/chech.html > > Regards, > Nate > Here are recent related discussions about exiting from nested loops (at least seems to be so): https://mail.python.org/pipermail/python-ideas/2017-March/044932.html https://mail.python.org/pipermail/python-ideas/2017-March/045049.html I personally have difficulties to fully understand some of the examples given in those proposals, namely that proposals were thought for other(?) purposes also, not only breaking nested loops. At a first glance it seems to me that "goto" would solve the nested breaking problem and in a nice flexible way. (correct me if I am wrong, probably I'm missing something) So besides nested loops, in my practice I had occasions when I would want to use "goto". It would be fair to say that those occasions are not so common, but I'll try to give an example. Say, there is some pure procedural processing for some simple task and I don't want to make the script heavy and just care for the clarity: =========== Log = "" S = "lorem ipsum" for s in S: if s == "i" : message = "found on stage 1" goto .output S = S + " hello world" for s in S: if s == "d" : message = "found on stage 2" goto .output print "not found" print "S = ", S goto .exit .output print message Log = Log + message .exit: print "exiting" ============= For me it looks clear and I'd say easy to comprehend, Main critic would be obviously that it is not a good, *scalable application*, but quite often I don't even have this in mind, and just want to express a step-by-step direct instructions. In this case sticking any "def():.." inside the script does not make any sense for me. Simplicity here reflects the fact that this code represents exactly what I want the computer to do. And a working variant of this would be like: =========== Log = "" found = False Error = False S = "lorem ipsum" if not found: for s in S: if s == "i" : message = "found on stage 1" found = True if not found: S = S + " hello world" for s in S: if s == "d" : message = "found on stage 2" found = True if not found: Error = True print "Error : not found" print "S = ", S if not Error: print message Log = Log + message print "exiting" ============== This is working code, but I would say there is a lot extra indentation, and if I don't care about application scalability, those are just adding noise and I it needs some boolean flags. I am not sure what examples to add here ... it seems to me that e.g. if I would use Python for modelling "pipeline" algorithms this could be helpful also. Now if I count in the nested loops breaking problematic, seems that there is at least a prerequisite for existence of "goto". Am I right? Mikhail From python at deborahswanson.net Wed Apr 12 20:04:30 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Wed, 12 Apr 2017 17:04:30 -0700 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: <00bf01d2b3e4$99b6b8d0$27b23dae@sambora> Message-ID: <00cf01d2b3e9$8638b1a0$27b23dae@sambora> Deborah Swanson wrote, on Wednesday, April 12, 2017 4:29 PM > > Peter Otten wrote, on Wednesday, April 12, 2017 3:15 PM > > > > >> Indeed you cannot change the namedtuple's attributes. Like the > > >> "normal" tuple it is designed to be immutable. If you want changes in > > >> one list (the group) to appear in another (the original records) you > > >> need a mutable data type. > > > > > > Sadly, that does seem to be the correct conclusion here. > > > > Think hard if you really need the original list. > > It's possible you might transform the namedtuple into a > mutable type, and I didn't try that. But it seems like the > group-by defaultdict strategy would have to have a > significant performance edge to be worth it and you wouldn't > have any of the namedtuple properties to work with after the > transformation. I also ran into some trouble with your > algorithm that follows making the defaultdict, and I'm not > sure what value there would be in hashing through that. > Though I'm certainly willing to if you are. > > It worked to simply stay with the original list of > namedtuples to begin with. > > I remain grateful for your introduction to the collections > module. What a neat little package of tools! I know it's quick for this double-take, but it occurs to me that transforming to a mutable type isn't a performance evaluation at all. Filling in missing values is the last step before outputting the processed list, so it might not be necessary to work with namedtuples at that point. The algorithm to fill in the missing values for each group (which would no longer be namedtuples) in the defaultdict is something I'm back at the drawing board for. But it shouldn't be too hard. Haha, we'll see! From rgaddi at highlandtechnology.invalid Wed Apr 12 20:17:37 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Wed, 12 Apr 2017 17:17:37 -0700 Subject: "Goto" statement in Python In-Reply-To: References: Message-ID: On 04/12/2017 04:42 PM, Mikhail V wrote: > On 12 April 2017 at 02:44, Nathan Ernst wrote: >> goto is a misunderstood and much misaligned creature. It is a very useful >> feature, but like nearly any programming construct can be abused. >> >> Constructs like 'break', 'continue' or 'next' in languages like Python or >> C/C++ are goto's with implied labels. >> >> As Mikhail said, goto's can be great to break out of nested loops (only a >> handful of languages support named 'breaks'). >> >> So, instead of: >> bool found = false; >> for (int i = 0; i = ...; ++i) >> { >> for (int h = 0; h = ...; ++h) >> { >> if (some_condition) >> found = true; >> } >> if (found) break; >> } >> >> You can have: >> >> for (int i = 0; i = ...; ++i) >> { >> for (int h = 0; h = ...; ++h) >> { >> if (some_condition) >> goto found; >> } >> } >> // not found >> >> found: >> // handle found >> >> The second is better for a number of reasons: it's clearer. It has fewer >> variables (smaller stack), it has fewer branches (better for the CPU's >> branch prediction), and it has fewer instructions (better for CPU >> instruction cache). This is a trivial, contrived example, but I've seen >> more than 4x nested loops using an exit flag like this (at every level of >> the loops) that could have been replaced with a lot less code. >> >> People need to stop drinking "X is considered harmful." Even Dijkstra later >> lamented that his "Goto considered harmful" paper was misinterpreted and >> misrepresented as advocating that goto should never be used. >> >> Additionally, I'd recommend everyone read '"Considered Harmful" Essays >> Considered Harmful': http://meyerweb.com/eric/comment/chech.html >> >> Regards, >> Nate >> > > > > Here are recent related discussions about exiting from > nested loops (at least seems to be so): > https://mail.python.org/pipermail/python-ideas/2017-March/044932.html > https://mail.python.org/pipermail/python-ideas/2017-March/045049.html > > I personally have difficulties to fully understand some > of the examples given in those proposals, namely > that proposals were thought for other(?) purposes also, > not only breaking nested loops. > > At a first glance it seems to me that "goto" would solve > the nested breaking problem and in a nice flexible way. > (correct me if I am wrong, probably I'm missing something) > > So besides nested loops, in my practice I had occasions > when I would want to use "goto". > It would be fair to say that those occasions are not so common, > but I'll try to give an example. Say, there is some > pure procedural processing for some simple task > and I don't want to make the script heavy and just > care for the clarity: > > =========== > Log = "" > S = "lorem ipsum" > > for s in S: > if s == "i" : > message = "found on stage 1" > goto .output > > S = S + " hello world" > for s in S: > if s == "d" : > message = "found on stage 2" > goto .output > > print "not found" > print "S = ", S > goto .exit > > .output > print message > Log = Log + message > > .exit: > print "exiting" > ============= > > For me it looks clear and I'd say easy to comprehend, > Main critic would be obviously that it is not > a good, *scalable application*, but quite often I don't > even have this in mind, and just want to express a > step-by-step direct instructions. > In this case sticking any "def():.." inside the script > does not make any sense for me. Simplicity here > reflects the fact that this code represents > exactly what I want the computer to do. > > And a working variant of this would be like: > > =========== > Log = "" > found = False > Error = False > S = "lorem ipsum" > > if not found: > for s in S: > if s == "i" : > message = "found on stage 1" > found = True > > if not found: > S = S + " hello world" > for s in S: > if s == "d" : > message = "found on stage 2" > found = True > > if not found: > Error = True > print "Error : not found" > print "S = ", S > > > if not Error: > print message > Log = Log + message > > print "exiting" > ============== > > This is working code, but I would say there is > a lot extra indentation, and if I don't care about > application scalability, those are just adding noise > and I it needs some boolean flags. > > I am not sure what examples to add here ... > it seems to me that e.g. if I would use Python > for modelling "pipeline" algorithms > this could be helpful also. > > Now if I count in the nested loops breaking problematic, > seems that there is at least a prerequisite for existence of "goto". > Am I right? > > > Mikhail > def finder: for s in S: if s == 'i': return 'found on stage 1' S = S + ' hello world' for s in S: if s == 'd': return 'found on stage 2' raise ValueError('not found; S=' + S) try: message = finder() print(message) log += message except ValueError as e: print(e) -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From python at lucidity.plus.com Wed Apr 12 20:39:19 2017 From: python at lucidity.plus.com (Erik) Date: Thu, 13 Apr 2017 01:39:19 +0100 Subject: Merging multiple sorted sequences. In-Reply-To: References: Message-ID: <7e609d76-86ae-50c4-aac8-70683d94f93e@lucidity.plus.com> Hi Ian, On 13/04/17 00:09, Erik wrote: > On 12/04/17 23:44, Ian Kelly wrote: >> I would >> just use "lowest = min(items, key=itemgetter(0))". > > I had it in my head for some reason > that min() would return the smallest key, not the object (and hence I > wouldn't be able to know which sequence object to get the next value > from - sorting means it's always at index 0). Actually, no, that wasn't my issue. It was that I don't know the index of the source to 'del'ete from the list when it has exhausted. The code always deletes item 0 and my test sequences are such that they happen to exhaust in first to last order, so that works by accident. If you swap the definitions of the 'a', 'b', and 'c' test data, then it all goes horribly wrong with the "min()" change. However, I can use the 'remove' method on the items list to delete that element instead. It's going to do a linear search of the list to find the correct element, but I expect the number of sources to be trivially small compared to the amount of data in each, so for my specific case that should be OK. Thanks, E. From jfong at ms4.hinet.net Wed Apr 12 21:01:01 2017 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Wed, 12 Apr 2017 18:01:01 -0700 (PDT) Subject: What is the difference between x[:]=y and x=y[:]? In-Reply-To: References: <045c9994-c4c4-41ee-9f63-9e834e80d574@googlegroups.com> Message-ID: <12eb47a3-30d4-4ea9-9049-62a555471f34@googlegroups.com> Peter Otten at 2017/4/12 UTC+8 PM 8:13:53 wrote: > I should add that you can write > > >>>> lr = [[1], [0]] > >>>> lx = [] > >>>> for i in range(len(lr)): > > ... lx = lr[i][:] > > ... lx.append(0) > > ... lr[i].append(1) > > ... lr.append(lx) > > ... > >>>> lr > >[[1, 1], [0, 1], [1, 0], [0, 0]] > > > > idiomatially as > > >>> lr = [[1], [0]] > >>> [inner + tail for tail in [[1], [0]] for inner in lr] > [[1, 1], [0, 1], [1, 0], [0, 0]] > > Note that there is a difference -- the resulting list does not share any > lists with the original `lr` as concatenating two lists produces a new one: > > >>> a = [1] > >>> b = [2] > >>> c = a + b > >>> a is c > False > >>> b is c > False I was a little embarrassed when looking at my codes. It may take me a long time to get used to thinking in the "Pythonic" way:-( But definitely I have learned much from this forum:-) From ian.stegner at gmail.com Wed Apr 12 21:59:00 2017 From: ian.stegner at gmail.com (ian.stegner at gmail.com) Date: Wed, 12 Apr 2017 18:59:00 -0700 (PDT) Subject: Python Command Line Arguments Message-ID: I have this code which I got from https://www.tutorialspoint.com/python/python_command_line_arguments.htm The example works fine but when I modify it to what I need, it only half works. The problem is the try/except. If you don't specify an input/output, they are blank at the end but it shouldn't be. import getopt import sys def main(argv): inputfile = '' outputfile = '' try: opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="]) except getopt.GetoptError: inputfile = 'Input' outputfile = 'Output' if inputfile == '': for opt, arg in opts: if opt == '-h': print ('Usage: Encrypt.py -i -o ') sys.exit() elif opt in ("-i", "--ifile"): inputfile = arg elif opt in ("-o", "--ofile"): outputfile = arg else: '' print 'In: ' + inputfile print 'Out: ' + outputfile if __name__ == "__main__": main(sys.argv[1:]) From lauren.sophia1998 at gmail.com Wed Apr 12 22:13:19 2017 From: lauren.sophia1998 at gmail.com (Lauren Fugate) Date: Wed, 12 Apr 2017 19:13:19 -0700 (PDT) Subject: homework confusion Message-ID: <160ad06f-3ae8-4587-9a9a-dd92e5c8a141@googlegroups.com> Hello! So I have a homework assignment that I can't seem to understand. The problems are talking about classes and subclasses. My issue is that the examples use objects as arguments and I don't know how to make that happen without getting a name error. The question is: Create a subclass of Openable called Lockable for representing physical objects that can be unlocked and opened. Remember to make sure that Lockable is a subclass of Openable. In addition to the methods and attributes it automatically inherits from Openable and Thing, it should have: A public boolean attribute called is_locked that represents whether or not the object is locked. A public attribute called key which is a Thing object that represents the item that can be used as akey to unlock the Lockable object. An overridden constructor that takes two strings (the name and the location), a Thing (the key), and two optional boolean values (first, whether the object starts off open and second, whether it starts out locked). If neither of the optional boolean values are given, then the object should default to being closed but not locked. If only the first of the optional arguments (the starting "openness" state) is given, then the object should start out unlocked. Your version of .__init__() for Lockable must use the version of .__init__() from the superclass Openable to handle the name, location, and "openness" state. Setting the is_locked and key attributes are the only ones you need to handle separately. So you should be able to create Lockable objects with commands* like Lockable("front door", "in the foyer", house_key, False, True) (returning an object that starts out closed and locked), or Lockable("diary", "under Sam's bed", tiny_key, True) (returning an object that starts out open and unlocked), or Lockable("ancient treasure chest", "at the bottom of the sea", rusty_key) (returning an object that starts out closed and unlocked). *Assuming that the variables house_key, tiny_key, and rusty_key already exist and refer to instances of Things. My code is: class Thing: """represents physical objects in a game attributes: name(str), location(str)""" def __init__(self, name, location): """creates a Thing with a name and location str, str""" self.name = name self.location = location def __repr__(self): """returns the Thing as a string that could be used to create a Thing None-> str""" return "Thing(" + self.name + ", " + self.location + ")" def description(self): """returnd the Thing along with its name and location in a string None -> str""" return "The " + repr(self.name) + " is " + repr(self.location) + "." class Openable(Thing): """representing the Things that can be opened attributes: name(str), location(str), is_open(str)""" def __init__(self, name, location, is_open = False): """creates a Thing with a name and location str, str""" Thing.__init__(self, name, location) self.is_open = is_open def __repr__(self): """returns the Thing as a string that could be used to create an Openable None-> str""" return "Openable('" + self.name + "', '" + self.location + "', '" + str(self.is_open) + "')" def description(self): """returnd the Thing along with its name and location and whether it is open in a string None -> str""" if self.is_open == True: opened = "is open" else: opened = "is closed" return "The " + self.name + self.location + " is " + opened + "." def try_open(self): """tries to open the Openable and returns the result None -> bool""" if self.is_open == True: return False if self.is_open == False: self.is_open = True return True class Lockable(Openable): """respresents the Openable Things that are Lockable attributes: name(str), location(str), is_open(str), is_locked(str), key(str)""" def __init__(self, name, location, key, is_open = False, is_locked = False): """creates a Thing with a name and location str, str""" Openable.__init__(self, name, location, is_open = False) self.is_locked = is_locked def __repr__(self): """returns the Thing as a string that could be used to create an Lockable None-> str""" return "Lockable('" + self.name + "', '" + self.location + "', '" + str(self.is_open) + "', '" + str(self.is_locked) + "')" def description(self): """returnd the Thing along with its name and location and whether it is open in a string and whether it is locked None -> str""" if self.is_open == True: opened = "is open" return "The " + self.name + self.location + " is " + opened + "." elif self.is_open == Flase: opened = "is closed" if self.is_locked == True: locked = "is locked" return "The " + self.name + self.location + " is " + locked + "." else: locked = "is unlocked" return "The " + self.name + self.location + " is " + opened + " but " + locked + "." The example command is: Lockable("diary", "under Sam's bed", tiny_key, True) And I keep getting a NameError: tiny_key is not defined. What do I do? From jsf80238 at gmail.com Wed Apr 12 22:33:04 2017 From: jsf80238 at gmail.com (Jason Friedman) Date: Wed, 12 Apr 2017 20:33:04 -0600 Subject: Python Command Line Arguments In-Reply-To: References: Message-ID: > > I have this code which I got from https://www.tutorialspoint. > com/python/python_command_line_arguments.htm The example works fine but > when I modify it to what I need, it only half works. The problem is the > try/except. If you don't specify an input/output, they are blank at the end > but it shouldn't be. > > import getopt > import sys > Hello Ian, I am guessing you are wanting to parse command-line arguments rather than particularly wanting to use the getopt module. If I am correct you might want to spend your time instead learning the argparse module: https://docs.python.org/3/library/argparse.html https://docs.python.org/3/howto/argparse.html From tjreedy at udel.edu Wed Apr 12 22:34:35 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 12 Apr 2017 22:34:35 -0400 Subject: Merging multiple sorted sequences. In-Reply-To: <1815e8aa-473d-db5d-019a-d4440f61a8f8@lucidity.plus.com> References: <1815e8aa-473d-db5d-019a-d4440f61a8f8@lucidity.plus.com> Message-ID: On 4/12/2017 7:15 PM, Erik wrote: > Hi Peter, > > On 12/04/17 23:42, Peter Otten wrote: >> Erik wrote: >> >>> I need to be able to lazily merge a variable number of already-sorted(*) >>> variable-length sequences into a single sorted sequence. >> >> https://docs.python.org/dev/library/heapq.html#heapq.merge > > AFAICT (looking at the Python 3.5 heapq implementation, albeit very > briefly), it seems like that is a greedy algorithm. Am I missing something? Yes. Read the source to see what it does and why one or more inputs could be infinite iterators. Hint: it does *not* heapify everything at once. -- Terry Jan Reedy From python at mrabarnett.plus.com Wed Apr 12 22:38:24 2017 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 13 Apr 2017 03:38:24 +0100 Subject: Python Command Line Arguments In-Reply-To: References: Message-ID: <30b37030-7b5d-ba6a-f926-c748077a4f86@mrabarnett.plus.com> On 2017-04-13 02:59, ian.stegner at gmail.com wrote: > I have this code which I got from https://www.tutorialspoint.com/python/python_command_line_arguments.htm The example works fine but when I modify it to what I need, it only half works. The problem is the try/except. If you don't specify an input/output, they are blank at the end but it shouldn't be. > > > import getopt > import sys > > def main(argv): > inputfile = '' > outputfile = '' > try: > opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="]) > except getopt.GetoptError: > inputfile = 'Input' > outputfile = 'Output' > if inputfile == '': > for opt, arg in opts: > if opt == '-h': > print ('Usage: Encrypt.py -i -o ') > sys.exit() > elif opt in ("-i", "--ifile"): > inputfile = arg > elif opt in ("-o", "--ofile"): > outputfile = arg > else: > '' > > print 'In: ' + inputfile > print 'Out: ' + outputfile > > if __name__ == "__main__": > main(sys.argv[1:]) > You'll get the GetoptError exception if an option that requires an argument doesn't have one. That's not the same as omitting the option entirely. For example: # No -i option. foo # Option -i present but without its required argument. foo -i From jsf80238 at gmail.com Wed Apr 12 22:39:49 2017 From: jsf80238 at gmail.com (Jason Friedman) Date: Wed, 12 Apr 2017 20:39:49 -0600 Subject: Moderating the list [was: Python and the need for speed] In-Reply-To: <9fac840a-165f-789a-6631-ed913a1cdcf6@timgolden.me.uk> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <27652c6d-2cb4-4f0c-9400-6aa2a3f9f855@googlegroups.com> <9bdec2c0-6050-4b55-e4a0-96fcc9af6899@lucidity.plus.com> <58ecdae8$0$1602$c3e8da3$5496439d@news.astraweb.com> <9fac840a-165f-789a-6631-ed913a1cdcf6@timgolden.me.uk> Message-ID: > > However, it's simply a technical fact: the thing which we moderate is the >> mailing list. We can control which posts make it through from the newsgroup >> by blocking them at the gateway. But the posts will continue to appear on >> comp.lang.python which is, as the description says, unmoderated. >> > > TJG Thank you, Tim and Ethan and the other moderators, for performing that function. It makes the reading experience more pleasant for me. From jsf80238 at gmail.com Wed Apr 12 22:47:12 2017 From: jsf80238 at gmail.com (Jason Friedman) Date: Wed, 12 Apr 2017 20:47:12 -0600 Subject: homework confusion In-Reply-To: <160ad06f-3ae8-4587-9a9a-dd92e5c8a141@googlegroups.com> References: <160ad06f-3ae8-4587-9a9a-dd92e5c8a141@googlegroups.com> Message-ID: > > The example command is: Lockable("diary", "under Sam's bed", tiny_key, > True) > > And I keep getting a NameError: tiny_key is not defined. > > What do I do? > Without knowing what your professor intends this is a guess: define tiny_key. For example tiny_key = "some string" thing = Lockable("diary", "under Sam's bed", tiny_key, True) or tiny_key = 1234 thing = Lockable("diary", "under Sam's bed", tiny_key, True) Maybe in the next assignment the professor will ask you to collect by key the Lockables that you construct. From python at mrabarnett.plus.com Wed Apr 12 22:47:12 2017 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 13 Apr 2017 03:47:12 +0100 Subject: homework confusion In-Reply-To: <160ad06f-3ae8-4587-9a9a-dd92e5c8a141@googlegroups.com> References: <160ad06f-3ae8-4587-9a9a-dd92e5c8a141@googlegroups.com> Message-ID: On 2017-04-13 03:13, Lauren Fugate wrote: [snip] Read the last 2 paragraphs again: ""So you should be able to create Lockable objects with commands* like Lockable("front door", "in the foyer", house_key, False, True) (returning an object that starts out closed and locked), or Lockable("diary", "under Sam's bed", tiny_key, True) (returning an object that starts out open and unlocked), or Lockable("ancient treasure chest", "at the bottom of the sea", rusty_key) (returning an object that starts out closed and unlocked). *Assuming that the variables house_key, tiny_key, and rusty_key already exist and refer to instances of Things. """ It gives """Lockable("diary", "under Sam's bed", tiny_key, True)""" as an _example_ of how it would be used. The final sentence is also important. Try defining 'tiny_key' before testing the example. From ian.stegner at gmail.com Wed Apr 12 23:00:34 2017 From: ian.stegner at gmail.com (ian.stegner at gmail.com) Date: Wed, 12 Apr 2017 20:00:34 -0700 (PDT) Subject: Python Command Line Arguments In-Reply-To: References: <30b37030-7b5d-ba6a-f926-c748077a4f86@mrabarnett.plus.com> Message-ID: On Thursday, April 13, 2017 at 12:38:48 PM UTC+10, MRAB wrote: > On 2017-04-13 02:59, ian.stegner at gmail.com wrote: > > I have this code which I got from https://www.tutorialspoint.com/python/python_command_line_arguments.htm The example works fine but when I modify it to what I need, it only half works. The problem is the try/except. If you don't specify an input/output, they are blank at the end but it shouldn't be. > > > > > > import getopt > > import sys > > > > def main(argv): > > inputfile = '' > > outputfile = '' > > try: > > opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="]) > > except getopt.GetoptError: > > inputfile = 'Input' > > outputfile = 'Output' > > if inputfile == '': > > for opt, arg in opts: > > if opt == '-h': > > print ('Usage: Encrypt.py -i -o ') > > sys.exit() > > elif opt in ("-i", "--ifile"): > > inputfile = arg > > elif opt in ("-o", "--ofile"): > > outputfile = arg > > else: > > '' > > > > print 'In: ' + inputfile > > print 'Out: ' + outputfile > > > > if __name__ == "__main__": > > main(sys.argv[1:]) > > > You'll get the GetoptError exception if an option that requires an > argument doesn't have one. That's not the same as omitting the option > entirely. > > For example: > > # No -i option. > foo > > # Option -i present but without its required argument. > foo -i WOW. Thanks for that. From wrw at mac.com Thu Apr 13 00:04:59 2017 From: wrw at mac.com (William Ray Wing) Date: Thu, 13 Apr 2017 00:04:59 -0400 Subject: closing image automatically in for loop , python In-Reply-To: <8e5d24d1-1453-4526-88d5-790702c00f1c@googlegroups.com> References: <8e5d24d1-1453-4526-88d5-790702c00f1c@googlegroups.com> Message-ID: > On Apr 12, 2017, at 7:18 AM, Masoud Afshari wrote: > > Dear all > > I have several *.sfd files which created by a simulation code. I wrote a program containing a for Loop which reads each time one .sfd file and plot the requested Parameters. I have two request: > > 1- my Problem is that for Showing successive Images in for Loop I have to Close the Image MANAULLY each time to read next sdf file. can anyone please tell me which command do I have to use so the code Close the Images automatically. > I normally run matplolib in interactive mode, so this may not be quite correct, BUT I think you only need to add a call to: close() After your call to plt.show() Bill > 2- more over, can anyone please tell me how can I create a movie with this code. > > in the following you can see my code > > > ##################### > # in this program, PYTHON reads the reduced files and plot the variables . > ? > ? > import sys > import sdf > import numpy as np > import matplotlib.pyplot as plt > from matplotlib.font_manager import FontProperties > fp = FontProperties('Symbola') > ? > ##################### information from EPOCH input.deck > nx,ny= 1200, 1600 > ? > xmin=-100e-6 > xmax = 50e-6 > ymin = -100e-6 > ymax = 100e-6 > ? > X =np.linspace(xmin,xmax,nx) #Generate linearly spaced vector. The spacing between the points is (x2-x1)/(n-1). > Y =np.linspace(ymin,ymax,ny) > ? > ################# > for n in range(0,27): > nstr = str(n)#.zfill(4) > #print nstr > ? > ###### > fig = plt.figure() #plot several figures simultaneously > > ########..... reading Ex > ? > filename ="Ex_resample" +'_sdf_'+ str(n)+'.dat' > with open(filename, 'rb') as f: #read binary file > data = np.fromfile(f, dtype='float64', count=nx*ny) #float64 for Double precision float numbers > Ex = np.reshape(data, [ny, nx], order='F') > #print Ex.max() > ? > #Display image with scaled colors: > plt.subplot(222) > fig1=plt.imshow(Ex, extent=[X.min()*1e6, X.max()*1e6, Y.min()*1e6, Y.max()*1e6], vmin=0, vmax=2e12, cmap='brg', aspect='auto') #cmap='jet', 'nipy_spectral','hot','gist_ncar' > #plt.suptitle('Ex') > plt.title('sdf '+ str(n)+ '; Time= ' +str(n*50)+ 'ps',color='green', fontsize=15) > plt.xlabel('x($\mu$m)') > plt.ylabel('y($\mu$m)') > plt.text(40,80,'Ex',color='red', fontsize=15) > plt.colorbar() > plt.show() > #fig.savefig('test.jpg') > sys.exit() > -- > https://mail.python.org/mailman/listinfo/python-list From no.email at nospam.invalid Thu Apr 13 00:28:48 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 12 Apr 2017 21:28:48 -0700 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mvblhqwv.fsf@nightsong.com> Brecht Machiels writes: > However, rinohtype is located in a very different niche and it would > greatly benefit a lot from a speed boost. Rendering the Sphinx > documentation (311 pages) takes almost 10 minutes on my i7 Yikes... > As for moving to a compiled language (Nim or Rust would be interesting > choices, IMO), it doesn't make much sense. Have you tried PyPy? Thought about Lisp? Lisp is easily extensible and goes well with the DSL idea. Or if most of the time is used in some hot loop, maybe a small C extension is the simplest fix. From no.email at nospam.invalid Thu Apr 13 00:31:40 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 12 Apr 2017 21:31:40 -0700 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> <069ed317-abab-4980-a06c-6eafdc029653@googlegroups.com> <87r30yjlfd.fsf@nightsong.com> <878tn6djq6.fsf@elektro.pacujo.net> Message-ID: <87inm9hqs3.fsf@nightsong.com> Marko Rauhamaa writes: > Traditionally, disk access in Linux has been considered nonblocking. > There is AIO, but that hasn't been used much. AIO is asynchronous but it's for dealing with already-opened files. There doesn't seem to be a way to asynchronously OPEN a file. > I believe the lack of asynchronous disk I/O is related to the grand > Solaris idea which Linux adopted: all memory is on a disk and RAM is > merely a cache. And I thought Solaris's heritage involved NFS, with its notorious infinite hard hangs if something happened on the server end. > As swapping is no longer considered normal on modern computers, the > memory-disk duality doesn't seem all that practical anymore. Rather, > you'd like to treat the disk analogously to network access and keep RAM > access separate. Yep. But opening disk files that way seems to require threads or extra processes. From no.email at nospam.invalid Thu Apr 13 00:37:52 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 12 Apr 2017 21:37:52 -0700 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <87k26qlatw.fsf@nightsong.com> <0c09c8c2-e68c-ed58-5603-0efa2aebbe70@gmail.com> Message-ID: <87bms0j527.fsf@nightsong.com> Michael Torrie writes: > Equivalent to the JNI and Lisp FFI is the CFFI [1]. The JNI, the FFI, > and the CFFI, are all for calling native code from within their > respective languages, if I understand correctly. They don't define a > standard way for native code to call into these languages. They often do, and at least the JNI does. Some general issues are discussed here: http://autocad.xarch.at/lisp/ffis.html From no.email at nospam.invalid Thu Apr 13 00:38:51 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 12 Apr 2017 21:38:51 -0700 Subject: Merging multiple sorted sequences. References: Message-ID: <877f2oj50k.fsf@nightsong.com> Erik writes: > I need to be able to lazily merge a variable number of > already-sorted(*) variable-length sequences If the number of sequences is large, the traditional way is with the heapq module. From bostananwar at gmail.com Thu Apr 13 00:48:54 2017 From: bostananwar at gmail.com (Nicole) Date: Wed, 12 Apr 2017 21:48:54 -0700 (PDT) Subject: Visit All URLs with selenium python Message-ID: <43f70312-83ba-457e-a83f-7b46e5d2a08f@googlegroups.com> browser.get('https://www.google.co.uk/search?q=Rashmi&oq=Rashmi&aqs=chrome..69i57j69i60l3.6857j0j1&sourceid=chrome&ie=UTF-8#q=Rashmi+Custom+Tailors') time.sleep(5) try: p_links = browser.find_elements_by_css_selector('div > h3 > a') url_list = [] for urls in p_links: if "Rashmi Custom Tailors" in urls.text: url = urls.get_attribute("href") url_list.append(url) for url in url_list: browser.get(url) time.sleep(4) it just visit first url not all .. Can anybody help how to fix that.. From jussi.piitulainen at helsinki.fi Thu Apr 13 01:19:53 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Thu, 13 Apr 2017 08:19:53 +0300 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> <9506d7a6-cdd8-4285-8c2d-4c71b48be5da@googlegroups.com> Message-ID: bart4858 at gmail.com writes: > On Wednesday, 12 April 2017 16:50:01 UTC+1, Jussi Piitulainen wrote: >> bart4858 at gmail.com writes: >> >> > On Wednesday, 12 April 2017 12:56:32 UTC+1, Jussi Piitulainen wrote: >> >> bartc writes: >> >> >> > >> >> > These are straightforward language enhancements. >> >> >> >> FYI, the question is not how to optimize the code but how to prevent >> >> the programmer from writing stupid code in the first place. Someone >> >> suggested that a language should do that. >> > >> > The 'stupid code' thing is a red herring. I assume the code people >> > write is there for a reason. >> >> So you walked in to a conversation about something that does not >> interest you and simply started talking about your own thing. >> >> Because of course you did. >> >> I get confused when you do that. > > Huh? The subject is making Python faster. It's generally agreed that > being very dynamic makes that harder, everything else being equal. Amazingly, the references in this part of the thread work all the way back to the point were you joined in. Let me quote extensively from the message to which you originally followed up. I lay it out so that I can add some commentary where I point out that the topic of the discussion at that point is whether a programming language should prevent people from writing bad code. [Rick Johnson, quoted by Steven D'Aprano] | high level languages like Python should make it difficult, if not | impossible, to write sub-optimal code (at least in the blatantly | obvious cases). That's the topic of the discussion at that point: whether it should be difficult to *write* bad code in the language. I don't know what else Rick may have said in his message, but Steven chose that topic for that message. Not whether a language should be such that the compiler could produce efficient code, or whether the compiler should be such that it could produce efficient code even if the language makes it a challenge, but whether it should be difficult to write blatantly sub-optimal code. [Steven D'Aprano, in response] | You mean that Python should make it impossible to write: | | near_limit = [] | near_limit.append(1) | near_limit = len(near_limit) | | instead of: | | near_limit = 1 | | ? I look forward to seeing your version of RickPython that can | enforce that rule. You snipped that. Steven asks whether Rick really thinks that Python should prevent that code from being written. Steven also pointed out that this example came from some actual code :) [*I* snipped that.] It's not a question how to produce efficient code for that, or how Python prevents the compiler from producing optimal code. It's a question of the compiler rejecting the code. Traceback (most recent call last): File "/dev/fd/63", line 37, in SanityClauseException: code is blatantly sub-optimal As far as I know, no language does that. Because reasons? [Steven D'Aprano, in response] | Here's another example: | | answer = 0 | for i in range(10): | answer += 1 | | instead of | | answer = 10 | | So... how exactly does the compiler prohibit stupid code? That was Steven's second example, which Steven again used to ask Rick whether or how he really thinks the compiler should prohibit such code. (I have no idea whether that discussion has continued in other branches of the thread, or whether Rick really thinks that, but he seemed to be saying something like that.) You chose to comment on that example, but I think you chose to ignore the question of prohibition altogether, even though that was the question in this particular exchange between Rick and Steven. You went on to address the actual compilation challenges instead. It's a valid topic but it's a different topic. It fits under the subject line, but not in response to that particular message. Those example snippets were intended as a *different kind of challenge*. That's why your original response had me confused, briefly, and then irritated, slightly. That's all. From python at deborahswanson.net Thu Apr 13 01:29:00 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Wed, 12 Apr 2017 22:29:00 -0700 Subject: Visit All URLs with selenium python In-Reply-To: <43f70312-83ba-457e-a83f-7b46e5d2a08f@googlegroups.com> Message-ID: <000301d2b416$db88c6e0$27b23dae@sambora> Nicole wrote, on Wednesday, April 12, 2017 9:49 PM > > browser.get('https://www.google.co.uk/search?q=Rashmi&oq=Rashm > i&aqs=chrome..69i57j69i60l3.6857j0j1&sourceid=chrome&ie=UTF-8# q=Rashmi+Custom+Tailors') > time.sleep(5) > > try: > p_links = > browser.find_elements_by_css_selector('div > h3 > a') > url_list = [] > for urls in p_links: > if "Rashmi Custom Tailors" in urls.text: > > url = urls.get_attribute("href") > url_list.append(url) > for url in url_list: > browser.get(url) > time.sleep(4) > > > it just visit first url not all .. Can anybody help how to fix that.. You don't say what module you're using and it would help to see the "import ..." statement. But there are a couple things I can think of that could be causing the problem: There's only one result with the exact phrase "Rashmi Custom Tailors" on the page. or The css_selector('div > h3 > a') only occurs for the first result and selectors for subsequent results are different. I've seen that before. If the div extends all the way down the list until after the last result, the results after the first one might have css_selector('h3 > a'), but I'm just guessing about how they might be different. Deborah From steve at pearwood.info Thu Apr 13 01:29:55 2017 From: steve at pearwood.info (Steven D'Aprano) Date: 13 Apr 2017 05:29:55 GMT Subject: Calling dunder methods manually Message-ID: <58ef0cd3$0$1501$c3e8da3$5496439d@news.astraweb.com> Should you call dunder methods (Double leading and trailing UNDERscores) manually? For example: my_number.__add__(another_number) The short answer is: NO! In general, you shouldn't do it. Guido recently commented: I agree that one shouldn't call __init__ manually (and in fact Python always reserves the right to have "undefined" behavior when you define or use dunder names other than documented). so unless documented as safe to use manually, you should assume that it is not. https://github.com/python/typing/issues/241#issuecomment-292694838 This-Public-Service-Announcement-Brought-To-You-By-MyPy-ly y'rs, -- Steve From bostananwar at gmail.com Thu Apr 13 02:02:58 2017 From: bostananwar at gmail.com (Nicole) Date: Wed, 12 Apr 2017 23:02:58 -0700 (PDT) Subject: Visit All URLs with selenium python In-Reply-To: <43f70312-83ba-457e-a83f-7b46e5d2a08f@googlegroups.com> References: <43f70312-83ba-457e-a83f-7b46e5d2a08f@googlegroups.com> Message-ID: <662aca9a-4671-48f5-88b3-3f5cf3effe49@googlegroups.com> from selenium.webdriver.firefox.firefox_profile import FirefoxProfile import random from selenium import webdriver from selenium.webdriver.common.keys import Keys From bostananwar at gmail.com Thu Apr 13 02:04:37 2017 From: bostananwar at gmail.com (Nicole) Date: Wed, 12 Apr 2017 23:04:37 -0700 (PDT) Subject: Visit All URLs with selenium python In-Reply-To: <43f70312-83ba-457e-a83f-7b46e5d2a08f@googlegroups.com> References: <43f70312-83ba-457e-a83f-7b46e5d2a08f@googlegroups.com> Message-ID: <96dabd69-deff-4293-8e7c-46aa90875728@googlegroups.com> Hi Deborah, I checked again selecting css there found 11 URLS and I printed it is printing all urls but it visits the first url not all.. From rustompmody at gmail.com Thu Apr 13 02:18:47 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 12 Apr 2017 23:18:47 -0700 (PDT) Subject: Calling dunder methods manually In-Reply-To: <58ef0cd3$0$1501$c3e8da3$5496439d@news.astraweb.com> References: <58ef0cd3$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: <523039d1-5f43-4d73-932a-4b2bd130754e@googlegroups.com> On Thursday, April 13, 2017 at 11:00:03 AM UTC+5:30, Steven D'Aprano wrote: > Should you call dunder methods (Double leading and trailing UNDERscores) > manually? For example: > > > my_number.__add__(another_number) > > > The short answer is: > > NO! In general, you shouldn't do it. > > > Guido recently commented: > > I agree that one shouldn't call __init__ manually (and in fact Python > always reserves the right to have "undefined" behavior when you > define or use dunder names other than documented). > > > so unless documented as safe to use manually, you should assume that it > is not. > > > https://github.com/python/typing/issues/241#issuecomment-292694838 > > > > This-Public-Service-Announcement-Brought-To-You-By-MyPy-ly y'rs, > > > > > -- > Steve I believe it was ChrisA who gave a pithy summary of the situation: Dont CALL dunders But its fine to DEFINE them From greg.ewing at canterbury.ac.nz Thu Apr 13 02:19:24 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 13 Apr 2017 18:19:24 +1200 Subject: Python and the need for speed In-Reply-To: <2759e6e0-ad95-466c-81f6-556133620999@googlegroups.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> <2759e6e0-ad95-466c-81f6-556133620999@googlegroups.com> Message-ID: bart4858 at gmail.com wrote: > (Although I think Python would have difficulty in turning x+=1 into a > single opcode, if using normal object references and a shared object model.) The ADD_ONE opcode would have to be defined to have the same effect as the sequence emitted for x+=1, including all the dynamic lookups, so the only speed advantage would be eliminating a few trips around the bytecode fetch-decode-execute loop. Which could still be worthwhile, if experience with the wordcode interpreter is anything to go by. There was also a project that attempted to find frequently used sequences of opcodes and create specialised opcodes for them, which reportedly had some success as well. The logic behind these approaches is that unpredictable branches, such as the opcode switch in the ceval loop, are expensive on modern architectures, so eliminating as many of them as possible can be a win. -- Greg From bostananwar at gmail.com Thu Apr 13 02:29:54 2017 From: bostananwar at gmail.com (Nicole) Date: Wed, 12 Apr 2017 23:29:54 -0700 (PDT) Subject: Visit All URLs with selenium python In-Reply-To: <43f70312-83ba-457e-a83f-7b46e5d2a08f@googlegroups.com> References: <43f70312-83ba-457e-a83f-7b46e5d2a08f@googlegroups.com> Message-ID: <210cfded-1b40-49b9-b59e-2f54aad5f3d7@googlegroups.com> Here you can see now from selenium.webdriver.firefox.firefox_profile import FirefoxProfile import random from selenium import webdriver from selenium.webdriver.common.keys import Keys browser.get('https://www.google.co.uk/search?q=Rashmi&oq=Rashmi&aqs=chrome..69i57j69i60l3.6857j0j1&sourceid=chrome&ie=UTF-8#q=Mobiles+in+london') time.sleep(5) try: p_links = browser.find_elements_by_css_selector(' div > h3 > a') url_list = [] for urls in p_links: if "London" in urls.text: urls.get_attribute("href") url_list.append(urls) for links in url_list: browser.get(links) time.sleep(4) except: browser.close() From __peter__ at web.de Thu Apr 13 02:30:03 2017 From: __peter__ at web.de (Peter Otten) Date: Thu, 13 Apr 2017 08:30:03 +0200 Subject: Merging multiple sorted sequences. References: <1815e8aa-473d-db5d-019a-d4440f61a8f8@lucidity.plus.com> Message-ID: Erik wrote: > Hi Peter, > > On 12/04/17 23:42, Peter Otten wrote: >> Erik wrote: >> >>> I need to be able to lazily merge a variable number of already-sorted(*) >>> variable-length sequences into a single sorted sequence. >> >> https://docs.python.org/dev/library/heapq.html#heapq.merge > > AFAICT (looking at the Python 3.5 heapq implementation, albeit very > briefly), it seems like that is a greedy algorithm. Am I missing > something? > > Thanks, E. Watching it at work: >>> import heapq >>> def noisy(items, source): ... for item in items: ... print("fetching", item, "from", source) ... yield item ... >>> a = noisy(range(0, 10, 2), "a") >>> b = noisy(range(1, 10, 2), "b") >>> c = noisy([3.5, 3.6, 5.5], "c") >>> abc = heapq.merge(a, b, c) >>> next(abc) fetching 0 from a fetching 1 from b fetching 3.5 from c 0 >>> next(abc) fetching 2 from a 1 >>> next(abc) fetching 3 from b 2 >>> next(abc) fetching 4 from a 3 >>> next(abc) fetching 5 from b 3.5 >>> next(abc) fetching 3.6 from c 3.6 Verdict: not greedy ;) From greg.ewing at canterbury.ac.nz Thu Apr 13 02:32:17 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 13 Apr 2017 18:32:17 +1200 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> <9506d7a6-cdd8-4285-8c2d-4c71b48be5da@googlegroups.com> Message-ID: Jussi Piitulainen wrote: > Traceback (most recent call last): > File "/dev/fd/63", line 37, in > SanityClauseException: code is blatantly sub-optimal > > As far as I know, no language does that. Because reasons? Because the problem of making a compiler do that is probably AI-complete! -- Greg From steve at pearwood.info Thu Apr 13 02:32:22 2017 From: steve at pearwood.info (Steven D'Aprano) Date: 13 Apr 2017 06:32:22 GMT Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> <878tn5zqxf.fsf@bsb.me.uk> Message-ID: <58ef1b75$0$1501$c3e8da3$5496439d@news.astraweb.com> On Wed, 12 Apr 2017 14:38:52 +0100, Ben Bacarisse wrote: > Steve D'Aprano writes: > >> On Wed, 12 Apr 2017 03:39 am, Paul Rubin wrote: >> >>> I still do my everyday stuff in Python and I'd like to get more >>> conversant with stuff like numpy, but it feels like an old-fashioned >>> language these days. >> >> "Old fashioned"? With await/async just added to the language, and type >> annotations? And comprehensions and iterators? >> >> Admittedly type annotations are mostly of interest to large projects >> with many developers and a huge code base. But the rest? >> >> Comprehensions may have been around for a decade or two in Haskell, but >> most older languages don't have them. I'm pretty sure Java doesn't. >> Does Javascript? Comprehensions feel like a fancy new language feature >> to me. > > They've been in in Haskell for nearly three decades, but they were > around before that. Miranda had them, as did Miranda's immediate > predecessor, KRC. KRC dates from about 1980, so if you've been using > that lineage of languages, list comprehensions have been a standard > feature for 37 years. I've been using them almost my entire programming > life. Indeed, and this is a very common phenomenon: features which "ordinary" programmers imagine are "trendy" and new end up having their roots in some functional language dating back to the 1980s, or 70s, or in extreme cases the 1950s and Lisp. That's what I meant: even though Haskell has had comprehensions for decades, they haven't hit "mainstream" procedural languages (Java, Javascript, C) at all or until recently. Python's had them for a decade or more (how time flies...) but they still to this day get reactions from many Python programmers like "I don't get these fancy new list comprehensions, what's wrong with an old-fashioned for-loop?" (not quoting anyone in particular, although Bart did specifically mention he didn't grok comprehensions). > It seems odd that ECMAScript (the JavaScript standard) does not have > them, but then JS seems to hide its function nature under an imperative > bushel. > > Just another perspective... Thanks. I knew comprehensions have been around for a while, I didn't realise they went back to Miranda and even older. -- Steve From __peter__ at web.de Thu Apr 13 02:34:55 2017 From: __peter__ at web.de (Peter Otten) Date: Thu, 13 Apr 2017 08:34:55 +0200 Subject: Namedtuples: some unexpected inconveniences References: <00bf01d2b3e4$99b6b8d0$27b23dae@sambora> Message-ID: Deborah Swanson wrote: > It's a small point, but I suspect getattr(record, label) would still > fail, even if label's value is 'label' and only 'label', but what's the > point of having a variable if it will only ever have just one value? You are misunderstanding. Your getattr() call fails because you have label = "label" burried somewhere in your code. As soon as you change that to label = the error will go away. From python at deborahswanson.net Thu Apr 13 02:38:46 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Wed, 12 Apr 2017 23:38:46 -0700 Subject: Visit All URLs with selenium python In-Reply-To: <662aca9a-4671-48f5-88b3-3f5cf3effe49@googlegroups.com> Message-ID: <000f01d2b420$9ac30170$27b23dae@sambora> Nicole wrote, on Wednesday, April 12, 2017 11:03 PM > > from selenium.webdriver.firefox.firefox_profile import > FirefoxProfile import random from selenium import webdriver > from selenium.webdriver.common.keys import Keys Ok, that gives us a clue what you're working with, which will probably help with something. Since your code works, I'm guessing your use of selenium is probably ok. I'd be looking for structural issues in the HTML for reasons why you're not getting what you want to get. From python at deborahswanson.net Thu Apr 13 02:45:53 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Wed, 12 Apr 2017 23:45:53 -0700 Subject: Visit All URLs with selenium python In-Reply-To: <96dabd69-deff-4293-8e7c-46aa90875728@googlegroups.com> Message-ID: <001001d2b421$996502a0$27b23dae@sambora> Nicole wrote, on Wednesday, April 12, 2017 11:05 PM > > Hi Deborah, > I checked again selecting css there found 11 URLS and I > printed it is printing all urls but it visits the first url not all.. I'm just guessing again, but time.sleep(4) could be too long a time to sleep, especially if you're on a fast network and you don't have many browser windows open before you run your code. It might be opening the first url and printing all the others and exiting the for loop before time.sleep(4) expires. From python at deborahswanson.net Thu Apr 13 02:50:46 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Wed, 12 Apr 2017 23:50:46 -0700 Subject: Visit All URLs with selenium python In-Reply-To: <96dabd69-deff-4293-8e7c-46aa90875728@googlegroups.com> Message-ID: <001101d2b422$47b83cf0$27b23dae@sambora> Nicole wrote, on Wednesday, April 12, 2017 11:05 PM > > Hi Deborah, > I checked again selecting css there found 11 URLS and I > printed it is printing all urls but it visits the first url not all.. Hmm. Sounds like you've changed your code in some way. Either changing the web page you're pointing to, changing the css selector or something I can't guess, because in your last msg yo said you were seeing just the opposite. From bostananwar at gmail.com Thu Apr 13 02:56:09 2017 From: bostananwar at gmail.com (Nicole) Date: Wed, 12 Apr 2017 23:56:09 -0700 (PDT) Subject: Visit All URLs with selenium python In-Reply-To: References: <96dabd69-deff-4293-8e7c-46aa90875728@googlegroups.com> <001101d2b422$47b83cf0$27b23dae@sambora> Message-ID: Not actually that's not.. You said there could be a Problem in HTML that's why I tested it on a new URL but it just viting the first URL not all.. Please help.. From python at deborahswanson.net Thu Apr 13 02:56:15 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Wed, 12 Apr 2017 23:56:15 -0700 Subject: Visit All URLs with selenium python In-Reply-To: <210cfded-1b40-49b9-b59e-2f54aad5f3d7@googlegroups.com> Message-ID: <001401d2b423$0b914310$27b23dae@sambora> Nicole wrote, on Wednesday, April 12, 2017 11:30 PM > > Here you can see now > > from selenium.webdriver.firefox.firefox_profile import FirefoxProfile > import random > from selenium import webdriver > from selenium.webdriver.common.keys import Keys > > browser.get('https://www.google.co.uk/search?q=Rashmi&oq=Rashm > i&aqs=chrome..69i57j69i60l3.6857j0j1&sourceid=chrome&ie=UTF-8# > q=Mobiles+in+london') > time.sleep(5) > > try: > p_links = browser.find_elements_by_css_selector(' div > > h3 > a') > url_list = [] > for urls in p_links: > if "London" in urls.text: > > urls.get_attribute("href") > url_list.append(urls) > for links in url_list: > browser.get(links) > time.sleep(4) > except: > browser.close() Ok, I'm sure you changed the search terms, don't know if you changed the google url, but the code looks the same. I'm headed away from the computer for the night, but try using a shorter sleep time, like time.sleep(1) From bostananwar at gmail.com Thu Apr 13 02:57:36 2017 From: bostananwar at gmail.com (Nicole) Date: Wed, 12 Apr 2017 23:57:36 -0700 (PDT) Subject: Visit All URLs with selenium python In-Reply-To: References: <96dabd69-deff-4293-8e7c-46aa90875728@googlegroups.com> <001101d2b422$47b83cf0$27b23dae@sambora> Message-ID: browser.get('https://www.google.co.uk/search?q=Rashmi&oq=Rashmi&aqs=chrome..69i57j69i60l3.6857j0j1&sourceid=chrome&ie=UTF-8#q=Rashmi+Custom+Tailors') time.sleep(5) try: p_links = browser.find_elements_by_css_selector(' div > h3 > a') url_list = [] for urls in p_links: if "Rashmi Custom Tailors" in urls.text: url = urls.get_attribute("href") url_list.append(url) for links in url_list: browser.get(links) time.sleep(4) except: pass From bostananwar at gmail.com Thu Apr 13 02:59:29 2017 From: bostananwar at gmail.com (Nicole) Date: Wed, 12 Apr 2017 23:59:29 -0700 (PDT) Subject: Visit All URLs with selenium python In-Reply-To: References: <96dabd69-deff-4293-8e7c-46aa90875728@googlegroups.com> <001101d2b422$47b83cf0$27b23dae@sambora> Message-ID: I have used 0 to 10 sec time sleep but it is not working.. please help me otherwise my assignment would get mark 0 From storchaka at gmail.com Thu Apr 13 03:01:16 2017 From: storchaka at gmail.com (Serhiy Storchaka) Date: Thu, 13 Apr 2017 10:01:16 +0300 Subject: Calling dunder methods manually In-Reply-To: <58ef0cd3$0$1501$c3e8da3$5496439d@news.astraweb.com> References: <58ef0cd3$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 13.04.17 08:29, Steven D'Aprano wrote: > Should you call dunder methods (Double leading and trailing UNDERscores) > manually? For example: > > > my_number.__add__(another_number) > > > The short answer is: > > NO! In general, you shouldn't do it. > > > Guido recently commented: > > I agree that one shouldn't call __init__ manually (and in fact Python > always reserves the right to have "undefined" behavior when you > define or use dunder names other than documented). > > > so unless documented as safe to use manually, you should assume that it > is not. > > > https://github.com/python/typing/issues/241#issuecomment-292694838 __init__ is perhaps the most called dunder method. It is often called from the __init__ method of subclasses. __add__ also can be called from other __add__, __iadd__ or __radd__. From python at deborahswanson.net Thu Apr 13 03:03:36 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Thu, 13 Apr 2017 00:03:36 -0700 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: Message-ID: <001701d2b424$12a34d00$27b23dae@sambora> Peter Otten wrote, on Wednesday, April 12, 2017 11:35 PM > > Deborah Swanson wrote: > > > It's a small point, but I suspect getattr(record, label) > would still > > fail, even if label's value is 'label' and only 'label', but what's > > the point of having a variable if it will only ever have just one > > value? > > You are misunderstanding. Your getattr() call fails because you have > > label = "label" > > burried somewhere in your code. As soon as you change that to > > label = > > the error will go away. Yes, the error goes away, but now getattr(record, label) is useless for processing field names, unless you want to write a line of code for each one. (I have 17 field names, and forget about passing label to a function.) From greg.ewing at canterbury.ac.nz Thu Apr 13 03:16:37 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 13 Apr 2017 19:16:37 +1200 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: References: <00a901d2b3d8$25d09460$27b23dae@sambora> Message-ID: Deborah Swanson wrote: > But I think you got it right in your last sentence below. defaultdict > copied them because they were immutable, No, definitely not. A defaultdict will never take it upon itself to copy an object you give it, either as a key or a value. The copying, if any, must have occurred somewhere else, in code that you didn't show us. Can you show us the actual code you used to attempt to update the namedtuples? -- Greg From __peter__ at web.de Thu Apr 13 03:17:28 2017 From: __peter__ at web.de (Peter Otten) Date: Thu, 13 Apr 2017 09:17:28 +0200 Subject: Namedtuples: some unexpected inconveniences References: <001701d2b424$12a34d00$27b23dae@sambora> Message-ID: Deborah Swanson wrote: > Peter Otten wrote, on Wednesday, April 12, 2017 11:35 PM >> >> Deborah Swanson wrote: >> >> > It's a small point, but I suspect getattr(record, label) >> would still >> > fail, even if label's value is 'label' and only 'label', but what's >> > the point of having a variable if it will only ever have just one >> > value? >> >> You are misunderstanding. Your getattr() call fails because you have >> >> label = "label" >> >> burried somewhere in your code. As soon as you change that to >> >> label = >> >> the error will go away. > > > Yes, the error goes away, but now getattr(record, label) is useless for > processing field names, unless you want to write a line of code for each > one. (I have 17 field names, and forget about passing label to a > function.) No, it's not useless: >>> from collections import namedtuple >>> T = namedtuple("T", "foo bar baz") >>> t = T(1, 2, 3) >>> for name in t._fields: ... print(name, "=", getattr(t, name)) ... foo = 1 bar = 2 baz = 3 And as a special service here's a mutable datatype with sufficient namedtuple compatibility to replicate the above snippet: $ cat namedtuple_replacement.py def struct(name, wanted_columns): class Struct: _fields = __slots__ = wanted_columns.split() def __init__(self, *args): names = self.__slots__ if len(args) != len(names): raise ValueError for name, value in zip(names, args): setattr(self, name, value) @classmethod def _make(cls, args): return cls(*args) def __repr__(self): names = self.__slots__ return "{}({})".format( self.__class__.__name__, ", ".join("{}={!r}".format(n, getattr(self, n)) for n in names) ) Struct.__name__ = name return Struct T = struct("T", "foo bar baz") t = T(1, 2, 3) print(t) for name in t._fields: print(name, "=", getattr(t, name)) t.bar = 42 print(t) $ python3 namedtuple_replacement.py T(foo=1, bar=2, baz=3) foo = 1 bar = 2 baz = 3 T(foo=1, bar=42, baz=3) From eryksun at gmail.com Thu Apr 13 03:18:10 2017 From: eryksun at gmail.com (eryk sun) Date: Thu, 13 Apr 2017 07:18:10 +0000 Subject: Calling dunder methods manually In-Reply-To: <58ef0cd3$0$1501$c3e8da3$5496439d@news.astraweb.com> References: <58ef0cd3$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Apr 13, 2017 at 5:29 AM, Steven D'Aprano wrote: > Should you call dunder methods (Double leading and trailing UNDERscores) > manually? For example: > > > my_number.__add__(another_number) > > > The short answer is: > > NO! In general, you shouldn't do it. > > > Guido recently commented: > > I agree that one shouldn't call __init__ manually (and in fact Python > always reserves the right to have "undefined" behavior when you > define or use dunder names other than documented). > > > so unless documented as safe to use manually, you should assume that it > is not. > > > https://github.com/python/typing/issues/241#issuecomment-292694838 I manually call dunder methods all the time when overriding a special method in a subclass. It's happening all over the place -- thousands and even millions of times in a program. You generally shouldn't call them outside of a class definition -- not because it's inherently bad (though calling __init__ on an already initialized object is weird and probably bad), but because it's bad style and does an end-run around the high-level behavior of the interpreter. From greg.ewing at canterbury.ac.nz Thu Apr 13 03:34:27 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 13 Apr 2017 19:34:27 +1200 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: References: <00a901d2b3d8$25d09460$27b23dae@sambora> Message-ID: Deborah Swanson wrote: > Peter Otten wrote, on Wednesday, April 12, 2017 1:45 PM > >> Personally I would immediately discard the header row once and for >> all, not again and again on every operation. > > Well, perhaps, but I need the header row to stay in place to write the > list to a csv when I'm done That's no problem, just write the header row separately. Do this at the beginning: header = [Record._make(fieldnames)] records = [Record._make(row) for row in rows] and then to write out the file: writer = csv.writer(outputfile) writer.writerow(header) writer.writerows(records) > There might be a tiny performance edge in discarding the header > row for the sort, but there would also be a hit to recreate it at output > time. It's not about performance, it's about keeping the code as clean and simple as you can, thus making it easier to understand and maintain. The general idea to take away from this is that it's almost always best to arrange things so that a given collection contains just one kind of data, so you can treat every element of it in exactly the same way. -- Greg From greg.ewing at canterbury.ac.nz Thu Apr 13 03:36:24 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 13 Apr 2017 19:36:24 +1200 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: References: <00a901d2b3d8$25d09460$27b23dae@sambora> Message-ID: If you want to be able to update your rows, you may find this useful: https://pypi.python.org/pypi/recordclass It's very similar to a namedtuple, but mutable. Looks like it should be a drop-in replacement. -- Greg From eryksun at gmail.com Thu Apr 13 03:43:08 2017 From: eryksun at gmail.com (eryk sun) Date: Thu, 13 Apr 2017 07:43:08 +0000 Subject: Calling dunder methods manually In-Reply-To: <58ef0cd3$0$1501$c3e8da3$5496439d@news.astraweb.com> References: <58ef0cd3$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Apr 13, 2017 at 5:29 AM, Steven D'Aprano wrote: > > my_number.__add__(another_number) > > The short answer is: > > NO! In general, you shouldn't do it. For example: class C: def __add__(self, other): return NotImplemented class D: def __radd__(self, other): return 42 >>> C().__add__(D()) NotImplemented >>> C() + D() 42 The functions in the operator module implement abstract behavior (e.g. PyNumber_Add in CPython): >>> operator.__add__(C(), D()) 42 From steve at pearwood.info Thu Apr 13 04:08:14 2017 From: steve at pearwood.info (Steven D'Aprano) Date: 13 Apr 2017 08:08:14 GMT Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> <2759e6e0-ad95-466c-81f6-556133620999@googlegroups.com> Message-ID: <58ef31ee$0$1501$c3e8da3$5496439d@news.astraweb.com> On Wed, 12 Apr 2017 16:30:38 -0700, bart4858 wrote: > (Although I think Python would have difficulty in turning x+=1 into a > single opcode, if using normal object references and a shared object > model.) You know, since Python actually exists and isn't just a hypothetical language, we can find out what it actually does, not just guess :-) >>> import dis >>> code = compile("x += 1", "", "single") >>> dis.dis(code) 1 0 LOAD_NAME 0 (x) 3 LOAD_CONST 0 (1) 6 INPLACE_ADD 7 STORE_NAME 0 (x) 10 LOAD_CONST 1 (None) 13 RETURN_VALUE There's an op-code for looking up the name 'x', another to push the constant 1 on the stack, an op-code for "INPLACE_ADD", followed by an op- code for STORE_NAME again. In principle, we could replace the LOAD_CONST and INPLACE_ADD with a single op-code that combines the two. Whether that would speed anything up is another question. Is it possible to skip the STORE_NAME op-code? If you knew *for sure* that the target (x) was a mutable object which implemented += using an in- place mutation, then you could, but the only built-in where that applies is list so even if you could guarantee x was a list, it hardly seems worth the bother. -- Steve From davidgshi at yahoo.co.uk Thu Apr 13 04:12:33 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Thu, 13 Apr 2017 08:12:33 +0000 (UTC) Subject: Read a text file into a Pandas DataFrame Table References: <1040730225.1594206.1492071153498.ref@mail.yahoo.com> Message-ID: <1040730225.1594206.1492071153498@mail.yahoo.com> Dear All, Can anyone help to read a text file into a Pandas DataFrame Table? Please see the link below. http://www.ebi.ac.uk/ena/data/warehouse/search?query=%22geo_circ(-0.587,-90.5713,170)%22&result=sequence_release&display=text Regards. David From greg.ewing at canterbury.ac.nz Thu Apr 13 04:14:19 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 13 Apr 2017 20:14:19 +1200 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: References: <00bf01d2b3e4$99b6b8d0$27b23dae@sambora> Message-ID: Deborah Swanson wrote: > I don't exactly understand your point (2). If the namedtuple does not > have a label attribute, then getattr(record, label) will get the error > whether the name label holds the string 'label' or not. You sound rather confused. Maybe the following interactive session transcript will help. >>> from collections import namedtuple >>> record = namedtuple('record', 'alpha,beta') >>> r = record(1, 2) >>> r record(alpha=1, beta=2) >>> label = 'alpha' >>> getattr(r, label) 1 >>> label = 'beta' >>> getattr(r, label) 2 >>> label = 'gamma' >>> getattr(r, label) Traceback (most recent call last): File "", line 1, in AttributeError: 'record' object has no attribute 'gamma' Can you see what's happening here? The expression label is being evaluated, and whatever string it evaluates to is being used as the attribute name to look up. Now, I'm not sure exactly what you were doing to get the message "'record' object has no attribute 'label'". Here are a few possible ways to get that effect: >>> r.label Traceback (most recent call last): File "", line 1, in AttributeError: 'record' object has no attribute 'label' >>> getattr(r, 'label') Traceback (most recent call last): File "", line 1, in AttributeError: 'record' object has no attribute 'label' >>> label = 'label' >>> getattr(r, label) Traceback (most recent call last): File "", line 1, in AttributeError: 'record' object has no attribute 'label' Or maybe you did something else again. We would need to see your code in order to tell. -- Greg From kwpolska at gmail.com Thu Apr 13 04:24:24 2017 From: kwpolska at gmail.com (Chris Warrick) Date: Thu, 13 Apr 2017 10:24:24 +0200 Subject: Calling dunder methods manually In-Reply-To: References: <58ef0cd3$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 13 April 2017 at 09:43, eryk sun wrote: > The functions in the operator module implement abstract behavior (e.g. > PyNumber_Add in CPython): > > >>> operator.__add__(C(), D()) > 42 Those functions also do not need underscores ? operator.add is a prettier way to achieve the same result. -- Chris Warrick PGP: 5EAAEA16 From greg.ewing at canterbury.ac.nz Thu Apr 13 04:25:35 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 13 Apr 2017 20:25:35 +1200 Subject: Python and the need for speed In-Reply-To: <878tn6djq6.fsf@elektro.pacujo.net> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> <069ed317-abab-4980-a06c-6eafdc029653@googlegroups.com> <87r30yjlfd.fsf@nightsong.com> <878tn6djq6.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > As swapping is no longer considered normal on modern computers, It isn't? When did that happen? -- Greg From breamoreboy at gmail.com Thu Apr 13 04:32:55 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Thu, 13 Apr 2017 01:32:55 -0700 (PDT) Subject: Read a text file into a Pandas DataFrame Table In-Reply-To: References: <1040730225.1594206.1492071153498.ref@mail.yahoo.com> <1040730225.1594206.1492071153498@mail.yahoo.com> Message-ID: On Thursday, April 13, 2017 at 9:15:18 AM UTC+1, David Shi wrote: > Dear All, > Can anyone help to read a text file into a Pandas DataFrame Table? > Please see the link below. > http://www.ebi.ac.uk/ena/data/warehouse/search?query=%22geo_circ(-0.587,-90.5713,170)%22&result=sequence_release&display=text > > Regards. > David http://pandas.pydata.org/pandas-docs/stable/io.html#io-read-csv-table From marko at pacujo.net Thu Apr 13 04:57:33 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 13 Apr 2017 11:57:33 +0300 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> <069ed317-abab-4980-a06c-6eafdc029653@googlegroups.com> <87r30yjlfd.fsf@nightsong.com> <878tn6djq6.fsf@elektro.pacujo.net> <87inm9hqs3.fsf@nightsong.com> Message-ID: <87shlcd6rm.fsf@elektro.pacujo.net> Paul Rubin : > Marko Rauhamaa writes: >> As swapping is no longer considered normal on modern computers, the >> memory-disk duality doesn't seem all that practical anymore. Rather, >> you'd like to treat the disk analogously to network access and keep >> RAM access separate. > > Yep. But opening disk files that way seems to require threads or extra > processes. At the moment, yes. But in the ideal world, everything would be (optionally) nonblocking. So open(O_NONBLOCK) would return a file descriptor before the system knows if the requested pathname refers to a valid file. Or maybe we should introduce a new "socket" family: AF_FILE. You would do: f = socket.socket(socket.AF_FILE, socket.SOCK_STREAM, "rwb") f.setblocking(False) try: f.connect(pathname) except socket.error as e: if e.errno != errno.EINPROGRESS: raise ... ... Marko From rosuav at gmail.com Thu Apr 13 04:58:48 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Apr 2017 18:58:48 +1000 Subject: Calling dunder methods manually In-Reply-To: <523039d1-5f43-4d73-932a-4b2bd130754e@googlegroups.com> References: <58ef0cd3$0$1501$c3e8da3$5496439d@news.astraweb.com> <523039d1-5f43-4d73-932a-4b2bd130754e@googlegroups.com> Message-ID: On Thu, Apr 13, 2017 at 4:18 PM, Rustom Mody wrote: > I believe it was ChrisA who gave a pithy summary of the situation: > Dont CALL dunders > But its fine to DEFINE them As others have mentioned, you call dunders during the definitions of dunders, mainly during subclassing. But from outside the class, you generally shouldn't. ChrisA From marko at pacujo.net Thu Apr 13 05:00:07 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 13 Apr 2017 12:00:07 +0300 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> <069ed317-abab-4980-a06c-6eafdc029653@googlegroups.com> <87r30yjlfd.fsf@nightsong.com> <878tn6djq6.fsf@elektro.pacujo.net> Message-ID: <87o9w0d6nc.fsf@elektro.pacujo.net> Gregory Ewing : > Marko Rauhamaa wrote: >> As swapping is no longer considered normal on modern computers, > > It isn't? When did that happen? Thing is, the moment you start thrashing, the game is over. Doubly so for Python, whose garbage collector will grind your machine to a halt as it is traversing the process's heap (which is on the disk). Marko From python at lucidity.plus.com Thu Apr 13 05:30:14 2017 From: python at lucidity.plus.com (Erik) Date: Thu, 13 Apr 2017 10:30:14 +0100 Subject: Merging multiple sorted sequences. In-Reply-To: References: <1815e8aa-473d-db5d-019a-d4440f61a8f8@lucidity.plus.com> Message-ID: <36c05b52-309d-454c-63d5-53d076f631ea@lucidity.plus.com> On 13/04/17 07:30, Peter Otten wrote: > Verdict: not greedy ;) Great (as I mentioned I did look at the code VERY quickly whilst VERY tired and at first glance missed that it's doing almost exactly what my code is doing except using the heapq to manage tracking the smallest value rather than sorting or scanning a flat list all the time). Thanks for the clear demonstration - it looks like that's exactly what I need then (as others have also pointed out, too). E. From mail at timgolden.me.uk Thu Apr 13 05:31:34 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 13 Apr 2017 10:31:34 +0100 Subject: Moderating the list [was: Python and the need for speed] In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <27652c6d-2cb4-4f0c-9400-6aa2a3f9f855@googlegroups.com> <9bdec2c0-6050-4b55-e4a0-96fcc9af6899@lucidity.plus.com> <58ecdae8$0$1602$c3e8da3$5496439d@news.astraweb.com> <9fac840a-165f-789a-6631-ed913a1cdcf6@timgolden.me.uk> Message-ID: <0b06e80e-eb1f-889e-c4f2-5f0d5f158c09@timgolden.me.uk> On 13/04/2017 03:39, Jason Friedman wrote: >> >> However, it's simply a technical fact: the thing which we moderate is the >>> mailing list. We can control which posts make it through from the newsgroup >>> by blocking them at the gateway. But the posts will continue to appear on >>> comp.lang.python which is, as the description says, unmoderated. >>> >> >> TJG > > > Thank you, Tim and Ethan and the other moderators, for performing that > function. > It makes the reading experience more pleasant for me. > I looked, for the first time in a long while, at the GG mirror of the newsgroup. Hadn't realised how much of that really nasty all-caps spam we were blocking. (We set up some gateway rules when that started to become a problem so we just don't see it on the mailing list). Most of the time we're just binning run-of-the-mill spam. Doesn't take too much effort if you keep on top of it, but it piles up quickly enough if you leave it for a bit! TJG From brecht__gmane at mos6581.org Thu Apr 13 05:52:04 2017 From: brecht__gmane at mos6581.org (Brecht Machiels) Date: Thu, 13 Apr 2017 11:52:04 +0200 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <3d3ce9b0-5388-42fe-9472-a511e0e10d8d@googlegroups.com> Message-ID: Bah. My newsreader lost my reply when the WiFi connection dropped out... attempt #2. On 2017-04-12 18:45:16 +0000, bart4858 at gmail.com said: > On Wednesday, 12 April 2017 16:04:53 UTC+1, Brecht Machiels wrote: >> On 2017-04-12 14:46:45 +0000, Michael Torrie said: > >> It would be great if you could run the benchmark I mention in my first> >> link and share the results. Highly appreciated! > > Were you ever able to isolate what it was that's taking up most of the > time? Either in general or in the bit that pypy has trouble with. Or is > execution time spread too widely? It's been a while since I last focused on performance, but the profile is still pretty flat. It's easy enough to verify (see also the URL referenced below): python -m cProfile -o demo.prof `which rinoh` -f restructuredtext demo.rst python -m pstats demo.prof demo.prof% strip demo.prof% sort tottime demo.prof% stats 15 Thu Apr 13 10:59:19 2017 demo.prof 35193174 function calls (27868271 primitive calls) in 22.461 seconds Ordered by: internal time List reduced from 5499 to 15 due to restriction <15> ncalls tottime percall cumtime percall filename:lineno(function) 6020041/321084 2.812 0.000 2.884 0.000 layout.py:152(document_part) 287201 1.211 0.000 6.156 0.000 style.py:645(match) 98788 0.901 0.000 1.965 0.000 version.py:198(__init__) 419928/232734 0.751 0.000 17.332 0.000 util.py:109(function_wrapper) 344783 0.588 0.000 1.198 0.000 style.py:319(match) 1302467 0.534 0.000 0.840 0.000 style.py:438(__hash__) 128992/83504 0.459 0.000 15.477 0.000 style.py:556(get_style_recursive) 1472251/1472250 0.399 0.000 0.469 0.000 {built-in method builtins.isinstance} 701320 0.395 0.000 0.679 0.000 parse.py:18(reader) 306381/10913 0.389 0.000 6.546 0.000 style.py:757(find_matches) 89622/86768 0.368 0.000 2.126 0.000 style.py:369(match) 176 0.311 0.002 0.840 0.005 parse.py:157(check_sum) 339968/10360 0.308 0.000 0.417 0.000 dimension.py:239(__float__) 95312 0.301 0.000 0.347 0.000 version.py:343(_cmpkey) 2642 0.288 0.000 3.380 0.001 __init__.py:792(resolve) > (I looked at your project but it's too large, and didn't get much > further with the github benchmark, which requires me to subscribe, but > the .sh file extensions don't seem too promising to someone on Windows.) GitHub benchmark? .sh file extensions? You can easily run some benchmarks following the instructions here (pip install): https://bitbucket.org/pypy/pypy/issues/2365/rinohtype-much-slower-on-pypy3 As I commented on that issue, I have been able to run the benchmarks using PyPy3 5.7.1 beta, which is now significantly faster than CPython. That's very promising! > Your program seems to be to do with typesetting. Is it possible to at > least least quantity the work that is being done in terms of total > bytes (and total files) of input, and bytes of output? That might > enable comparisons with other systems executing similar tasks, to see > if the Python version is taking unreasonably long. The Sphinx benchmark's source reStructuredText files add up to 584 KB. The output PDF file is almost 3 MB (includes fonts and images). Note that the input document is parsed into a document tree where each paragraph is represented by an object of the Paragraph class, containing StyledText objects and so on. The total memory used is about 1 GB! LaTeX is orders of magnitude faster, but requires multiple passes. It's memory usage is probably much less since it works stream-based. Best regards, Brecht From davidgshi at yahoo.co.uk Thu Apr 13 06:06:26 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Thu, 13 Apr 2017 10:06:26 +0000 (UTC) Subject: Reading structured text file (non-CSV) into Pandas Dataframe References: <1072392017.1753695.1492077986904.ref@mail.yahoo.com> Message-ID: <1072392017.1753695.1492077986904@mail.yahoo.com> http://www.ebi.ac.uk/ena/data/warehouse/search?query=%22geo_circ(-0.587,-90.5713,170)%22&result=sequence_release&display=text The above is a web link to a structured text file. ?It is not a CSV. How can this text file be read into a Pandas Dataframe, so that further processing can be made? Looking forward to hearing from you. Regards. David From breamoreboy at gmail.com Thu Apr 13 06:34:34 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Thu, 13 Apr 2017 03:34:34 -0700 (PDT) Subject: Reading structured text file (non-CSV) into Pandas Dataframe In-Reply-To: References: <1072392017.1753695.1492077986904.ref@mail.yahoo.com> <1072392017.1753695.1492077986904@mail.yahoo.com> Message-ID: <3c59aa6d-8ec2-4588-93e8-f8b9b602f73c@googlegroups.com> On Thursday, April 13, 2017 at 11:09:23 AM UTC+1, David Shi wrote: > http://www.ebi.ac.uk/ena/data/warehouse/search?query=%22geo_circ(-0.587,-90.5713,170)%22&result=sequence_release&display=text > The above is a web link to a structured text file. ?It is not a CSV. > How can this text file be read into a Pandas Dataframe, so that further processing can be made? > Looking forward to hearing from you. > Regards. > David http://pandas.pydata.org/pandas-docs/stable/io.html From davidgshi at yahoo.co.uk Thu Apr 13 07:27:54 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Thu, 13 Apr 2017 11:27:54 +0000 (UTC) Subject: No subject References: <1687361172.1861440.1492082874952.ref@mail.yahoo.com> Message-ID: <1687361172.1861440.1492082874952@mail.yahoo.com> 13.1. csv ? CSV File Reading and Writing ? Python 2.7.13 documentation | | | 13.1. csv ? CSV File Reading and Writing ? Python 2.7.13 documentation | | | I am trying to parse this text file into a table. How to use consecutive 3 spaces to work as delimiter with csv.reader? Looking forward to hearing from you. Regards. David From jsmcmahon3 at gmail.com Thu Apr 13 07:31:02 2017 From: jsmcmahon3 at gmail.com (James McMahon) Date: Thu, 13 Apr 2017 07:31:02 -0400 Subject: Check multiple file parms in single os.access? Message-ID: Hello. Am a Python newbie. I have researched and found examples how we can check existence, readability, and write-ability on a given fully-qualified filename for the current python script user. Evidently os.access is the way to go, wrapped in some additional try and catch logic that helps insulate us from changes in file state after our os.access checks. I understand that os.stat() calls can be relatively expensive. I assume likewise for os.access(). Since I'm going to apply my Python permission check script within a NiFi ExecuteScript processor handling many flowfiles, I seek any and all performance optimizations I possibly can. Is there a way to mask the F_OK, R_OK, and W_OK in a single os.access call? I'm guessing there must be, rather than doing this if ( os.access(fqfname,os.F_OK) and os.access(fqfname,os.R_OK) and os.access(fqfname,os.W_OK)) : Thanks in advance for your insights. -Jim From alister.ware at ntlworld.com Thu Apr 13 07:31:40 2017 From: alister.ware at ntlworld.com (alister) Date: Thu, 13 Apr 2017 11:31:40 GMT Subject: "Goto" statement in Python Message-ID: On Thu, 13 Apr 2017 01:42:01 +0200, Mikhail V wrote: > On 12 April 2017 at 02:44, Nathan Ernst wrote: >> goto is a misunderstood and much misaligned creature. It is a very >> useful feature, but like nearly any programming construct can be >> abused. >> >> Constructs like 'break', 'continue' or 'next' in languages like Python >> or C/C++ are goto's with implied labels. >> >> As Mikhail said, goto's can be great to break out of nested loops (only >> a handful of languages support named 'breaks'). >> >> So, instead of: >> bool found = false; >> for (int i = 0; i = ...; ++i) >> { >> for (int h = 0; h = ...; ++h) >> { >> if (some_condition) >> found = true; >> } >> if (found) break; >> } >> >> You can have: >> >> for (int i = 0; i = ...; ++i) >> { >> for (int h = 0; h = ...; ++h) >> { >> if (some_condition) >> goto found; >> } >> } >> // not found >> >> found: >> // handle found >> >> The second is better for a number of reasons: it's clearer. It has >> fewer variables (smaller stack), it has fewer branches (better for the >> CPU's branch prediction), and it has fewer instructions (better for CPU >> instruction cache). This is a trivial, contrived example, but I've >> seen more than 4x nested loops using an exit flag like this (at every >> level of the loops) that could have been replaced with a lot less code. >> >> People need to stop drinking "X is considered harmful." Even Dijkstra >> later lamented that his "Goto considered harmful" paper was >> misinterpreted and misrepresented as advocating that goto should never >> be used. >> >> Additionally, I'd recommend everyone read '"Considered Harmful" Essays >> Considered Harmful': http://meyerweb.com/eric/comment/chech.html >> >> Regards, >> Nate >> >> > > > Here are recent related discussions about exiting from nested loops (at > least seems to be so): > https://mail.python.org/pipermail/python-ideas/2017-March/044932.html > https://mail.python.org/pipermail/python-ideas/2017-March/045049.html > > I personally have difficulties to fully understand some of the examples > given in those proposals, namely that proposals were thought for > other(?) purposes also, > not only breaking nested loops. > > At a first glance it seems to me that "goto" would solve the nested > breaking problem and in a nice flexible way. > (correct me if I am wrong, probably I'm missing something) > > So besides nested loops, in my practice I had occasions when I would > want to use "goto". > It would be fair to say that those occasions are not so common, > but I'll try to give an example. Say, there is some pure procedural > processing for some simple task and I don't want to make the script > heavy and just care for the clarity: > > =========== > Log = "" > S = "lorem ipsum" > > for s in S: > if s == "i" : > message = "found on stage 1" > goto .output > > S = S + " hello world" > for s in S: > if s == "d" : > message = "found on stage 2" > goto .output > > print "not found" > print "S = ", S goto .exit > > .output print message Log = Log + message > > .exit: > print "exiting" > ============= > > For me it looks clear and I'd say easy to comprehend, > Main critic would be obviously that it is not a good, *scalable > application*, but quite often I don't even have this in mind, and just > want to express a step-by-step direct instructions. > In this case sticking any "def():.." inside the script does not make any > sense for me. Simplicity here reflects the fact that this code > represents exactly what I want the computer to do. > > And a working variant of this would be like: > > =========== > Log = "" > found = False Error = False S = "lorem ipsum" > > if not found: > for s in S: > if s == "i" : > message = "found on stage 1" > found = True > > if not found: > S = S + " hello world" for s in S: > if s == "d" : > message = "found on stage 2" > found = True > > if not found: > Error = True print "Error : not found" > print "S = ", S > > > if not Error: > print message Log = Log + message > > print "exiting" > ============== > > This is working code, but I would say there is a lot extra indentation, > and if I don't care about application scalability, those are just adding > noise and I it needs some boolean flags. > > I am not sure what examples to add here ... > it seems to me that e.g. if I would use Python for modelling "pipeline" > algorithms this could be helpful also. > > Now if I count in the nested loops breaking problematic, > seems that there is at least a prerequisite for existence of "goto". Am > I right? > > > Mikhail I expect you could simulate most of these with a custom exception for example break from nested loop: class GoTo(Exception): pass try: for i in range(100): print i for j in range (50): print j if i*j>60: raise GoTo except GoTo: print "Exit Early" print "end of loop" -- /* * Buddy system. Hairy. You really aren't expected to understand this * */ -- From /usr/src/linux/mm/page_alloc.cA From bc at freeuk.com Thu Apr 13 07:55:57 2017 From: bc at freeuk.com (bartc) Date: Thu, 13 Apr 2017 12:55:57 +0100 Subject: Python and the need for speed In-Reply-To: <58ef31ee$0$1501$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> <2759e6e0-ad95-466c-81f6-556133620999@googlegroups.com> <58ef31ee$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5HJHA.649047$0k4.415939@fx37.am4> On 13/04/2017 09:08, Steven D'Aprano wrote: > On Wed, 12 Apr 2017 16:30:38 -0700, bart4858 wrote: > >> (Although I think Python would have difficulty in turning x+=1 into a >> single opcode, if using normal object references and a shared object >> model.) > > You know, since Python actually exists and isn't just a hypothetical > language, we can find out what it actually does, not just guess :-) > > >>>> import dis >>>> code = compile("x += 1", "", "single") >>>> dis.dis(code) > 1 0 LOAD_NAME 0 (x) > 3 LOAD_CONST 0 (1) > 6 INPLACE_ADD > 7 STORE_NAME 0 (x) > 10 LOAD_CONST 1 (None) > 13 RETURN_VALUE > > > There's an op-code for looking up the name 'x', another to push the > constant 1 on the stack, an op-code for "INPLACE_ADD", followed by an op- > code for STORE_NAME again. > > In principle, we could replace the LOAD_CONST and INPLACE_ADD with a > single op-code that combines the two. Whether that would speed anything > up is another question. > > Is it possible to skip the STORE_NAME op-code? If the starting-point is the existing byte-code of a program, then what can be done is more limited. If the optimiser can generate new byte-codes, then it might be possible to add an extra indirection, so that: LOAD_NAME (x) instead becomes (for example): LOAD_NAME_REF (x) INPLACE_ADD_REF The latter doing all the work (indirectly access x, work out x+1 and create a new object for that if necessary, then rebind the original x to that new value, because now we have a reference to the name). This means the byte-code set and the work some of them have to do is more complex, but it has been suggested that reducing the number of byte-code dispatches can be beneficial. > If you knew *for sure* > that the target (x) was a mutable object which implemented += using an in- > place mutation, then you could, but the only built-in where that applies > is list so even if you could guarantee x was a list, it hardly seems > worth the bother. I think x+=y is most usefully optimised when x and y are numbers. But numbers can't be modified in-place, not in general. -- bartc From bc at freeuk.com Thu Apr 13 08:23:09 2017 From: bc at freeuk.com (bartc) Date: Thu, 13 Apr 2017 13:23:09 +0100 Subject: Python and the need for speed In-Reply-To: <5HJHA.649047$0k4.415939@fx37.am4> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> <2759e6e0-ad95-466c-81f6-556133620999@googlegroups.com> <58ef31ee$0$1501$c3e8da3$5496439d@news.astraweb.com> <5HJHA.649047$0k4.415939@fx37.am4> Message-ID: On 13/04/2017 12:55, bartc wrote: > On 13/04/2017 09:08, Steven D'Aprano wrote: >> Is it possible to skip the STORE_NAME op-code? > > If the starting-point is the existing byte-code of a program, then what > can be done is more limited. > > If the optimiser can generate new byte-codes, then it might be possible > to add an extra indirection, so that: > > LOAD_NAME (x) > > instead becomes (for example): > > LOAD_NAME_REF (x) > INPLACE_ADD_REF I meant INPLACE_INCR_REF From rustompmody at gmail.com Thu Apr 13 08:39:08 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 13 Apr 2017 05:39:08 -0700 (PDT) Subject: Swiss Ephemeris In-Reply-To: References: <00dd01d2b319$eb9c77a0$27b23dae@sambora> Message-ID: On Thursday, April 13, 2017 at 2:10:16 PM UTC+5:30, Deborah Swanson wrote: > Rustom Mody wrote, on Monday, April 10, 2017 11:50 PM > > > > On Monday, April 10, 2017 at 11:26:47 AM UTC+5:30, Deborah Swanson > wrote: > > > The great ancients were no less endowed with intelligence than we > are, > > > they simply directed it to different ends. > > > > And just when I was convinced by the all-knowers that my gpa > > was a monkey you've spoilt my complacence > > Good! It's unhealthy the way modern folk strut around thinking they're > the smartest humans to ever walk this earth. We've gone farther with > technology than any other time or culture, but invention (and > innovation) is only one aspect of intelligence. Quote from Peter Landin, one of the precursors of modern functional programming: Most papers in computer science describe how their author learned what someone else already knew [And this dates from 60s/70s] Applies beyond just CS? From steve+python at pearwood.info Thu Apr 13 08:50:47 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 13 Apr 2017 22:50:47 +1000 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> <069ed317-abab-4980-a06c-6eafdc029653@googlegroups.com> <87r30yjlfd.fsf@nightsong.com> <878tn6djq6.fsf@elektro.pacujo.net> <87o9w0d6nc.fsf@elektro.pacujo.net> Message-ID: <58ef7429$0$1596$c3e8da3$5496439d@news.astraweb.com> On Thu, 13 Apr 2017 07:00 pm, Marko Rauhamaa wrote: > Gregory Ewing : > >> Marko Rauhamaa wrote: >>> As swapping is no longer considered normal on modern computers, >> >> It isn't? When did that happen? > > Thing is, the moment you start thrashing, the game is over. Indeed. But swapping != thrashing. For what it's worth, three of the five sys admins I work with prefer not to use swap space on the Linux desktops they build. I'm not sure what their opinion is about servers. I *think* they would be okay with it if the server was using SSD rather than spinning metal. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From marko at pacujo.net Thu Apr 13 09:20:44 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 13 Apr 2017 16:20:44 +0300 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> <069ed317-abab-4980-a06c-6eafdc029653@googlegroups.com> <87r30yjlfd.fsf@nightsong.com> <878tn6djq6.fsf@elektro.pacujo.net> <87o9w0d6nc.fsf@elektro.pacujo.net> <58ef7429$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87a87kzbo3.fsf@elektro.pacujo.net> Steve D'Aprano : > On Thu, 13 Apr 2017 07:00 pm, Marko Rauhamaa wrote: >> Thing is, the moment you start thrashing, the game is over. > > Indeed. But swapping != thrashing. > > For what it's worth, three of the five sys admins I work with prefer > not to use swap space on the Linux desktops they build. I'm not sure > what their opinion is about servers. I *think* they would be okay with > it if the server was using SSD rather than spinning metal. Not sure if this is still valid: Still today Flash RAM cells built in SSDs have a limited lifespan. Every write (not read) cycle or better every erasure wears a memory cell and at some time it will stop working. I really don't see much point with swap space nowadays, anyway. Especially as it comes to production servers, you should reserve enough RAM for worst-case needs. And make sure you really need that much RAM; you probably don't. Marko From ben.usenet at bsb.me.uk Thu Apr 13 09:46:15 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Thu, 13 Apr 2017 14:46:15 +0100 Subject: Check multiple file parms in single os.access? References: Message-ID: <87o9w0xvx4.fsf@bsb.me.uk> James McMahon writes: > Hello. Am a Python newbie. I have researched and found examples how we can > check existence, readability, and write-ability on a given fully-qualified > filename for the current python script user. Evidently os.access is the way > to go, wrapped in some additional try and catch logic that helps insulate > us from changes in file state after our os.access checks. I'm not sure what you are saying here but I think it relates to a point I was going to make... In general, I'd say that testing for access is not the way to go. It is almost always better simply to try the operations you need to do and deal with the failures as they occur. The bottom line is that you can't be sure the operation will work even if os.access said it should a few moments ago. > I understand that os.stat() calls can be relatively expensive. I > assume likewise for os.access(). Since I'm going to apply my Python > permission check script within a NiFi ExecuteScript processor handling > many flowfiles, I seek any and all performance optimizations I > possibly can. > > Is there a way to mask the F_OK, R_OK, and W_OK in a single os.access > call? I'm guessing there must be, rather than doing this > > if ( os.access(fqfname,os.F_OK) and os.access(fqfname,os.R_OK) and > os.access(fqfname,os.W_OK)) : You can "or" together os.R_OK | os.W_OK into one call but you can can't do that with F_OK. Mind you, I'm not sure that matters since I can't think of a case where you want to fail because os.F_OK fails but os.R_OK and os.W_OK succeeds. In other words, why not just test for os.R_OK | os.W_OK? Note that despite using the "or" operation to construct the parameter, the test is an implied "and": os.access(fqfname, os.R_OK | os.W_OK) is true only if both read and write access are permitted. -- Ben. From Jack at nichesoftsolutions.com Thu Apr 13 10:12:41 2017 From: Jack at nichesoftsolutions.com (Jack at nichesoftsolutions.com) Date: Thu, 13 Apr 2017 07:12:41 -0700 (PDT) Subject: HOT LIST Message-ID: <6a5fdb9c-41f0-4e69-8972-8a5c51a7c46e@googlegroups.com> Hi Hope you doing great! Greeting from Niche Soft Solutions. I would like to present our topnotch consultants currently available. Please have a look at the below hot list of Niche Soft Solutions and mail your Direct Client requirements to jack at nichesoftsolutions.com Please add my Email ID to your mailing list and send the requirements on daily basis You can reach me at 503-536-2043 Name Technology Experience Visa status Current Location Relocation Tapasya .Net & Data Analyst 10+ H1B CO OPEN Malika Java 9+ H1B CA OPEN Vinoth Data Stage Developer 7+ H1B MI OPEN Sumathi QA Tester 8+ H1B CT OPEN Rahul People Soft 8+ H1B CA OPEN Laxman Java 10+ H1B VA VA Pooja Gosh WebMethod Developer 7+ H1B CA OPEN Rashi Guidewire Developer 8+ H1B TX OPEN Shabeer WebMethod Developer 7+ H1B NC OPEN With Regards Jack From gbs.deadeye at gmail.com Thu Apr 13 10:31:51 2017 From: gbs.deadeye at gmail.com (=?UTF-8?Q?Andre_M=C3=BCller?=) Date: Thu, 13 Apr 2017 14:31:51 +0000 Subject: Merging multiple sorted sequences. In-Reply-To: <36c05b52-309d-454c-63d5-53d076f631ea@lucidity.plus.com> References: <1815e8aa-473d-db5d-019a-d4440f61a8f8@lucidity.plus.com> <36c05b52-309d-454c-63d5-53d076f631ea@lucidity.plus.com> Message-ID: Hi, when you have lists with different lengths and want to zip them, you should look at itertools.zip_longest Greetings Andre From rosuav at gmail.com Thu Apr 13 10:35:20 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Apr 2017 00:35:20 +1000 Subject: "Goto" statement in Python In-Reply-To: References: Message-ID: On Thu, Apr 13, 2017 at 9:31 PM, alister wrote: > I expect you could simulate most of these with a custom exception > for example break from nested loop: > > class GoTo(Exception): > pass > > try: > for i in range(100): > print i > for j in range (50): > print j > if i*j>60: > raise GoTo > except GoTo: > print "Exit Early" > print "end of loop" Or you could turn it into a function and "return". Or if you feel like it, you could turn the nested loops into a generator, then iterate over it and break when you need to. There are many things you CAN do, but to the true goto-aficionado, none of them is as clean. Personally, I can't remember the last time I yearned for "goto" in Python, and the only times I've ever wished for it or used it in other languages have been multi-loop breaks or "for...else" blocks. And neither is very frequent. ChrisA From bc at freeuk.com Thu Apr 13 10:52:24 2017 From: bc at freeuk.com (bartc) Date: Thu, 13 Apr 2017 15:52:24 +0100 Subject: "Goto" statement in Python In-Reply-To: References: Message-ID: On 13/04/2017 15:35, Chris Angelico wrote: > On Thu, Apr 13, 2017 at 9:31 PM, alister wrote: >> I expect you could simulate most of these with a custom exception >> for example break from nested loop: >> >> class GoTo(Exception): >> pass >> >> try: >> for i in range(100): >> print i >> for j in range (50): >> print j >> if i*j>60: >> raise GoTo >> except GoTo: >> print "Exit Early" >> print "end of loop" > > Or you could turn it into a function and "return". Or if you feel like > it, you could turn the nested loops into a generator, then iterate > over it and break when you need to. I know this isn't the Python need-for-speed thread, but this is a classic example where the lack of one simple feature leads to using slower, more cumbersome ones. 'goto' would be one easy-to-execute byte-code; no variables, objects or types to worry about. If implemented properly (with the byte-code compiler using a dedicated name-space for labels) there would be no name lookups. Function calls, returns and generators are rather more heavyweight in comparison. There are many things you CAN do, > but to the true goto-aficionado, none of them is as clean. > > Personally, I can't remember the last time I yearned for "goto" in > Python, and the only times I've ever wished for it or used it in other > languages have been multi-loop breaks or "for...else" blocks. And > neither is very frequent. It might be a better idea to have a multi-level loop break then. This would also be an absolute jump byte-code. -- bartc From ian.g.kelly at gmail.com Thu Apr 13 11:03:20 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 13 Apr 2017 09:03:20 -0600 Subject: "Goto" statement in Python In-Reply-To: References: Message-ID: On Thu, Apr 13, 2017 at 8:52 AM, bartc wrote: > On 13/04/2017 15:35, Chris Angelico wrote: >> Personally, I can't remember the last time I yearned for "goto" in >> Python, and the only times I've ever wished for it or used it in other >> languages have been multi-loop breaks or "for...else" blocks. And >> neither is very frequent. > > > It might be a better idea to have a multi-level loop break then. This would > also be an absolute jump byte-code. This has previously been proposed and rejected: https://www.python.org/dev/peps/pep-3136/ Rejection notice: https://mail.python.org/pipermail/python-3000/2007-July/008663.html From davidgshi at yahoo.co.uk Thu Apr 13 11:04:12 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Thu, 13 Apr 2017 15:04:12 +0000 (UTC) Subject: No subject References: <274646852.2132748.1492095852078.ref@mail.yahoo.com> Message-ID: <274646852.2132748.1492095852078@mail.yahoo.com> Which VCF reader has been well tested and proven to be robust? Looking forward to hearing from you. Regards. David From eryksun at gmail.com Thu Apr 13 11:11:25 2017 From: eryksun at gmail.com (eryk sun) Date: Thu, 13 Apr 2017 15:11:25 +0000 Subject: Calling dunder methods manually In-Reply-To: References: <58ef0cd3$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Apr 13, 2017 at 8:24 AM, Chris Warrick wrote: > On 13 April 2017 at 09:43, eryk sun wrote: >> The functions in the operator module implement abstract behavior (e.g. >> PyNumber_Add in CPython): >> >> >>> operator.__add__(C(), D()) >> 42 > > Those functions also do not need underscores ? operator.add is a > prettier way to achieve the same result. I debated myself about which one to use in the example. The dunder aliases were added for completeness, to clarify the relationship to the corresponding special method, and I suppose to make it simpler to dynamically call them. I opted to use the explicit name, even though it's an alias because it seemed to make the example more consistent. Normally I would call operator.add. From marko at pacujo.net Thu Apr 13 11:26:38 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 13 Apr 2017 18:26:38 +0300 Subject: "Goto" statement in Python References: Message-ID: <8760i8z5u9.fsf@elektro.pacujo.net> Chris Angelico : > Personally, I can't remember the last time I yearned for "goto" in > Python, and the only times I've ever wished for it or used it in other > languages have been multi-loop breaks or "for...else" blocks. And > neither is very frequent. I have occasionally felt the urge to try "goto" in my C code, but having written it, I have taken it out. It just doesn't make the code look more elegant or robust. Unlike "break" or "return," "goto" makes me uneasy about variable scope and lifetime. Maybe it would work in some state machine implementation. Some 30 years ago I wrote a compiler. The parser came out nicer with methodical use of "goto," but even then, I used a parsing-specific macro to wrap it. Marko From pcmanticore at gmail.com Thu Apr 13 11:34:09 2017 From: pcmanticore at gmail.com (Claudiu Popa) Date: Thu, 13 Apr 2017 18:34:09 +0300 Subject: Pylint 1.7.0 was released Message-ID: Hey folks, We just released a new version of Pylint, 1.7.0, after a long period of time since the last release. You can find more details about what's new in this release over here: https://pylint.readthedocs.io/en/latest/whatsnew/1.7.html Thanks and enjoy, Claudiu From gordon at panix.com Thu Apr 13 12:07:24 2017 From: gordon at panix.com (John Gordon) Date: Thu, 13 Apr 2017 16:07:24 +0000 (UTC) Subject: Visit All URLs with selenium python References: <43f70312-83ba-457e-a83f-7b46e5d2a08f@googlegroups.com> Message-ID: In <43f70312-83ba-457e-a83f-7b46e5d2a08f at googlegroups.com> Nicole writes: > it just visit first url not all .. Can anybody help how to fix that.. Have you tried some basic debugging, for example printing p_links to verify that it contains what you expected, and then printing each url in the loop? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From mikhailwas at gmail.com Thu Apr 13 12:23:57 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Thu, 13 Apr 2017 18:23:57 +0200 Subject: "Goto" statement in Python In-Reply-To: References: Message-ID: On 13 April 2017 at 02:17, Rob Gaddi wrote: > > def finder: > for s in S: > if s == 'i': > return 'found on stage 1' > > S = S + ' hello world' > for s in S: > if s == 'd': > return 'found on stage 2' > > raise ValueError('not found; S=' + S) > > try: > message = finder() > print(message) > log += message > except ValueError as e: > print(e) > Mother of God... This is like placing some abstract art into a gallery of monumentalism art. I am upset and need some healing therapy now. I'll stay here for a while: https://www.pinterest.com/soren19/arqbrt/ On 13 April 2017 at 13:31, alister wrote: > > I expect you could simulate most of these with a custom exception > for example break from nested loop: > > class GoTo(Exception): > pass > > try: > for i in range(100): > print i > for j in range (50): > print j > if i*j>60: > raise GoTo > except GoTo: > print "Exit Early" > print "end of loop" > Now I wonder, have we already collected *all* bells and whistles of Python in these two examples, or is there something else for expressing trivial thing. Mikhail From ian.g.kelly at gmail.com Thu Apr 13 12:48:38 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 13 Apr 2017 10:48:38 -0600 Subject: "Goto" statement in Python In-Reply-To: References: Message-ID: On Thu, Apr 13, 2017 at 10:23 AM, Mikhail V wrote: > Now I wonder, have we already collected *all* bells and whistles of Python > in these two examples, or is there something else for expressing trivial thing. Functions and exceptions are considered "bells and whistles"? From rustompmody at gmail.com Thu Apr 13 13:13:12 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 13 Apr 2017 10:13:12 -0700 (PDT) Subject: "Goto" statement in Python In-Reply-To: References: Message-ID: <44db5cea-8831-4951-baa0-a50d99a79b1c@googlegroups.com> On Thursday, April 13, 2017 at 10:19:33 PM UTC+5:30, Ian wrote: > On Thu, Apr 13, 2017 at 10:23 AM, Mikhail V wrote: > > Now I wonder, have we already collected *all* bells and whistles of Python > > in these two examples, or is there something else for expressing trivial thing. > > Functions and exceptions are considered "bells and whistles"? People's tastes differ? violently on - food - music - opposite sex What to do?? Ask Trump? [I guess we now need a Godwin 2.0 with :s/Hitler/Trump ] I wonder if you noticed that you classed functions together with exceptions... presumably as basic elements. And that the bedrock of much contemporary computer technology ? linux-kernel, even (C)Python itself, viz C ? does not support one of these From bc at freeuk.com Thu Apr 13 13:17:24 2017 From: bc at freeuk.com (bartc) Date: Thu, 13 Apr 2017 18:17:24 +0100 Subject: "Goto" statement in Python In-Reply-To: References: Message-ID: On 13/04/2017 16:03, Ian Kelly wrote: > On Thu, Apr 13, 2017 at 8:52 AM, bartc wrote: >> On 13/04/2017 15:35, Chris Angelico wrote: >>> Personally, I can't remember the last time I yearned for "goto" in >>> Python, and the only times I've ever wished for it or used it in other >>> languages have been multi-loop breaks or "for...else" blocks. And >>> neither is very frequent. >> >> >> It might be a better idea to have a multi-level loop break then. This would >> also be an absolute jump byte-code. > > This has previously been proposed and rejected: > https://www.python.org/dev/peps/pep-3136/ Poorly presented I think with, what, five possible ways of adding it? > Rejection notice: > https://mail.python.org/pipermail/python-3000/2007-July/008663.html Rejected because it would only occur in complex code? That's just where it would help! I think it should be in for completeness, and to avoid this bug in the language; start with: for i in range(n): break; break inside a loop; that's currently allowed. Now for reasons of logic, that break is put inside an 'if' branch: for i in range(n): if cond: break; The break still works. But if, for any reason at all, that break ended up inside a nested loop instead of a nested if: for i in range(n): while cond: break; Now it no longer works as expected. The break has been 'captured' by the new loop. (IME most breaks from loops are either from the innermost loop, or from the outermost one. For these two cases, you don't need naming, labelling or numbering of loops. Just 'break [inner]' or 'break outer'.) -- bartc From mikhailwas at gmail.com Thu Apr 13 13:25:51 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Thu, 13 Apr 2017 19:25:51 +0200 Subject: "Goto" statement in Python In-Reply-To: References: Message-ID: On 13 April 2017 at 18:48, Ian Kelly wrote: > On Thu, Apr 13, 2017 at 10:23 AM, Mikhail V wrote: >> Now I wonder, have we already collected *all* bells and whistles of Python >> in these two examples, or is there something else for expressing trivial thing. > > Functions and exceptions are considered "bells and whistles"? You mean probably classes and exceptions? For me, indeed they are, but it depends. And breaking the code into def() chunks that are not functions but just chunks... I don't know, looks bad. From rgaddi at highlandtechnology.invalid Thu Apr 13 13:26:42 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Thu, 13 Apr 2017 10:26:42 -0700 Subject: "Goto" statement in Python In-Reply-To: <44db5cea-8831-4951-baa0-a50d99a79b1c@googlegroups.com> References: <44db5cea-8831-4951-baa0-a50d99a79b1c@googlegroups.com> Message-ID: On 04/13/2017 10:13 AM, Rustom Mody wrote: > On Thursday, April 13, 2017 at 10:19:33 PM UTC+5:30, Ian wrote: >> On Thu, Apr 13, 2017 at 10:23 AM, Mikhail V wrote: >>> Now I wonder, have we already collected *all* bells and whistles of Python >>> in these two examples, or is there something else for expressing trivial thing. >> >> Functions and exceptions are considered "bells and whistles"? > > People's tastes differ? violently on > - food > - music > - opposite sex > > What to do?? > Ask Trump? > [I guess we now need a Godwin 2.0 with :s/Hitler/Trump ] > > I wonder if you noticed that you classed functions together with exceptions... > presumably as basic elements. > And that the bedrock of much contemporary computer technology ? linux-kernel, > even (C)Python itself, viz C ? does not support one of these > No, C doesn't support exception handling. As a result, handling error conditions in C is a huge pain for which (forward-only) goto is often, while not the only remedy, the least painful one. Or if you've really developed a need for self-harm, setjmp/longjmp. Or, as is more frequently the case in code in the wild, error conditions simply don't get checked for and come as a surprise and/or segfault later on. Python is a radically higher level language than C. Python supports different structures than C, largely and specifically so that you don't have to do things in some of the error-prone ways you would do them in C. Therefore, a given task should be solved differently in Python than in C. I try very hard to write Python when I write Python, and to write C when I write C. And to write through the tears when I write C++. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From tomuxiong at gmx.com Thu Apr 13 13:31:18 2017 From: tomuxiong at gmx.com (Thomas Nyberg) Date: Thu, 13 Apr 2017 10:31:18 -0700 Subject: "Goto" statement in Python In-Reply-To: References: Message-ID: On 04/12/2017 04:42 PM, Mikhail V wrote: > For me it looks clear and I'd say easy to comprehend, > Main critic would be obviously that it is not > a good, *scalable application*, but quite often I don't > even have this in mind, and just want to express a > step-by-step direct instructions. I think that scalability is the only objectively reasonable (at least as far as this kind of argument could be objective) argument against gotos. They're not fundamentally a bad idea (the people who put them into certain languages weren't stupid after all), but they do seem to create a maintenance and complexity burden as the codebase grows. But if you're talking one off single scripts as your example, I think you can safely use many habits considered bad by most. That's simply not the scenario where gotos create a problem. There are of course many different ways you can get around using them, but there are certainly cases where that's exactly what you want and a substitute will always be a substitute and it may feel lacking. It's just a matter of taste really. Cheers, Thomas From ian.g.kelly at gmail.com Thu Apr 13 13:33:48 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 13 Apr 2017 11:33:48 -0600 Subject: "Goto" statement in Python In-Reply-To: <44db5cea-8831-4951-baa0-a50d99a79b1c@googlegroups.com> References: <44db5cea-8831-4951-baa0-a50d99a79b1c@googlegroups.com> Message-ID: On Thu, Apr 13, 2017 at 11:13 AM, Rustom Mody wrote: > What to do?? > Ask Trump? > [I guess we now need a Godwin 2.0 with :s/Hitler/Trump ] Not even close. Whatever one's opinion may be of Trump, he hasn't murdered millions of people. From rgaddi at highlandtechnology.invalid Thu Apr 13 13:35:53 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Thu, 13 Apr 2017 10:35:53 -0700 Subject: "Goto" statement in Python In-Reply-To: <8760i8z5u9.fsf@elektro.pacujo.net> References: <8760i8z5u9.fsf@elektro.pacujo.net> Message-ID: On 04/13/2017 08:26 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> Personally, I can't remember the last time I yearned for "goto" in >> Python, and the only times I've ever wished for it or used it in other >> languages have been multi-loop breaks or "for...else" blocks. And >> neither is very frequent. > > I have occasionally felt the urge to try "goto" in my C code, but having > written it, I have taken it out. It just doesn't make the code look more > elegant or robust. Unlike "break" or "return," "goto" makes me uneasy > about variable scope and lifetime. > > Maybe it would work in some state machine implementation. Some 30 years > ago I wrote a compiler. The parser came out nicer with methodical use of > "goto," but even then, I used a parsing-specific macro to wrap it. > > > Marko > You see it all the time in kernel code or when doing I/O. A pretty common pattern is: int return_val = 1; if (init_thing(x)) goto bk1; if (init_thing(y)) goto bk2; if (init_thing(z)) goto bk3; do_things_with(x, y, z); return_val = 0; bk3: cleanup_thing(z); bk2: cleanup_thing(y); bk1: cleanup_thing(x); return return_val; But the point is, in Python we have context managers and exceptions and classes, all of which serve to allow you to not have to explicitly lay out how to wind yourself step-by-step back out of the situation you've gotten yourself into. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From ian.g.kelly at gmail.com Thu Apr 13 13:38:13 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 13 Apr 2017 11:38:13 -0600 Subject: "Goto" statement in Python In-Reply-To: References: Message-ID: On Thu, Apr 13, 2017 at 11:25 AM, Mikhail V wrote: > On 13 April 2017 at 18:48, Ian Kelly wrote: >> On Thu, Apr 13, 2017 at 10:23 AM, Mikhail V wrote: >>> Now I wonder, have we already collected *all* bells and whistles of Python >>> in these two examples, or is there something else for expressing trivial thing. >> >> Functions and exceptions are considered "bells and whistles"? > > You mean probably classes and exceptions? For me, indeed they are, > but it depends. No, I meant functions (the first example) and exceptions (the second example). > And breaking the code into def() chunks that are not > functions but just chunks... I don't know, looks bad. I don't know what you mean by this. There is no such thing as a "def() chunk" that is not a function. From rustompmody at gmail.com Thu Apr 13 13:39:24 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 13 Apr 2017 10:39:24 -0700 (PDT) Subject: "Goto" statement in Python In-Reply-To: References: <44db5cea-8831-4951-baa0-a50d99a79b1c@googlegroups.com> Message-ID: <633df0f9-10c9-4cff-ba86-4a1270b4b19c@googlegroups.com> On Thursday, April 13, 2017 at 10:56:53 PM UTC+5:30, Rob Gaddi wrote: > On 04/13/2017 10:13 AM, Rustom Mody wrote: > > On Thursday, April 13, 2017 at 10:19:33 PM UTC+5:30, Ian wrote: > >> On Thu, Apr 13, 2017 at 10:23 AM, Mikhail V wrote: > >>> Now I wonder, have we already collected *all* bells and whistles of Python > >>> in these two examples, or is there something else for expressing trivial thing. > >> > >> Functions and exceptions are considered "bells and whistles"? > > > > People's tastes differ? violently on > > - food > > - music > > - opposite sex > > > > What to do?? > > Ask Trump? > > [I guess we now need a Godwin 2.0 with :s/Hitler/Trump ] > > > > I wonder if you noticed that you classed functions together with exceptions... > > presumably as basic elements. > > And that the bedrock of much contemporary computer technology ? linux-kernel, > > even (C)Python itself, viz C ? does not support one of these > > > > No, C doesn't support exception handling. As a result, handling error > conditions in C is a huge pain for which (forward-only) goto is often, > while not the only remedy, the least painful one. Or if you've really > developed a need for self-harm, setjmp/longjmp. Or, as is more > frequently the case in code in the wild, error conditions simply don't > get checked for and come as a surprise and/or segfault later on. > > Python is a radically higher level language than C. Python supports > different structures than C, largely and specifically so that you don't > have to do things in some of the error-prone ways you would do them in > C. Therefore, a given task should be solved differently in Python than > in C. You are answering to a different issue than I was: Sure C and python are done differently [your point] I was saying that if Mikhail finds exceptions (and as he later explained classes) as a heavy-duty solution to a control-flow issue, he has a point > > I try very hard to write Python when I write Python, and to write C when > I write C. And to write through the tears when I write C++. C++ has exceptions but no gc Haskell has gc (like python) but no exceptions So that suggests that while desirable, both are not in the bare-minimum set My broader point (vive la Trump) was that if we learn to actively tolerate people with views wildly far from ours, the world would be a better place. So what would I say to (people like) Mikhail? "Here's the sources mate! Fork it! And cheers!" From steve+python at pearwood.info Thu Apr 13 13:43:55 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 14 Apr 2017 03:43:55 +1000 Subject: Goto Considered Harmful [was Re: Python and the need for speed] References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> Message-ID: <58efb8de$0$1618$c3e8da3$5496439d@news.astraweb.com> On Wed, 12 Apr 2017 10:44 am, Nathan Ernst wrote: > goto is a misunderstood and much misaligned creature. It is a very useful > feature, but like nearly any programming construct can be abused. Indeed. The problem is that it is abused far more often than it is used correctly -- or at least it was, back in the days when people routinely used GOTO. People don't abuse GOTO much these days only because most languages don't encourage, or even allow, GOTO. > Constructs like 'break', 'continue' or 'next' in languages like Python or > C/C++ are goto's with implied labels. They are *restricted* and *structured* jumps, which is not the same thing as an *unrestricted and unstructured* GOTO. In much the same way that hiring a private security guard is not quite the same thing as declaring martial law and telling the soldiers they have carte blanche to shoot to kill for any reason at all. > As Mikhail said, goto's can be great to break out of nested loops (only a > handful of languages support named 'breaks'). I have to ask... if named breaks are so great, why don't more languages support them? > People need to stop drinking "X is considered harmful." That's one opinion. > Even Dijkstra > later lamented that his "Goto considered harmful" paper was misinterpreted > and misrepresented as advocating that goto should never be used. Citation required. 1987 was pretty much the last gasp of the unstructured programming paradigm, the last time that anyone made a serious case for it. Frank Rubin responded to Dijkstra's famous letter with a response "GOTO Considered Harmful Considered Harmful" Unfortunately, his response was not so much a refutation of Dijkstra, but the last desperate and failed defence of an all-but-dead programming style. Dijkstra responded to Rubin in an especially cranky (and rather pedantic and arrogant manner). You can read his response here: https://www.cs.utexas.edu/~EWD/transcriptions/EWD10xx/EWD1009.html Bottom line: Rubin's code was buggy, and the problem he posed could be solved without GOTO. More on the history of Dijkstra's letter here: https://blog.codinghorror.com/id-consider-that-harmful-too/ and a connection to Python: http://joshuah.scripts.mit.edu/blog/?p=195 > Additionally, I'd recommend everyone read '"Considered Harmful" Essays > Considered Harmful': http://meyerweb.com/eric/comment/chech.html The author makes a number of dogmatic claims without offering a shred of evidence for any of them. He expects us to simply believe on his say-so alone that "Considered Harmful" essays are counter-productive to their own cause, a clear and obvious case of "concern trolling" if I've ever seen one. His essay is full of weasel words and unsupported opinions masquerading as facts: * Considered Harmful essays "often" inflame the debate (how often? 1% of the time or 99% of the time? how do you know?) * supporters of the opposing view are "more likely" to dig in and defend their position (how much more like? how do you know?) * Considered Harmful essays have "a strong tendency to alienate neutral parties" (how strong? how do you know?) and he contradicts himself: Considered Harmful essays are "boring cliches" that nobody bothers to read or pay any attention to. Strangely enough, despite Considered Harmful being a boring, counter- productive cliche that harms your own cause, the author Eric Meyer chose to write one himself. Recognising this contradiction, he tries to pass it off as a joke. And what is his cause? To argue against a strawman, that Considered Harmful essays cannot and do not "engage in reasoned debate". They don't? Says who? Why can't a paper that draws a firm and opinionated conclusion (as Meyer himself does) also be reasoned? Meyer himself doesn't sit on the fence. He argues against Considered Harmful essays. Not very convincingly, but he does take a position against them. Why doesn't he follow his own advice, and describe the strengths and weaknesses of Considered Harmful essays? So there's one rule for Meyer, and everyone else should write wishy-washy fence-sitting essays that draw no firm conclusions. Meyer states that a "benefits and weaknesses" essay will allow people to "more readily find a compromise solution" without questioning whether or not a compromise solution is either possible or desirable. For example: - A language cannot compromise on the question of whether to allow COMEFROM: it either supports that *deliberately awful* language misfeature, or it doesn't. - Even if a compromise position is *possible*, that doesn't mean that one is desirable. Should array indexing start at 0 or 1, or shall we compromise with 0.5? Meyer implicitly assumes that technical questions are won by "reasoned debate", which goes against the history of science and technology and in fact all of human history. Very few questions can be resolved by mere facts. Rather, they are resolved by *persuasion*, and despite Meyer's concern-trolling, it does appear that in at least two cases "Considered Harmful" essays have persuaded people to turn against the dominant programming paradigm: - Unstructured GOTOs - Global variables. In both cases, the dominant paradigm has turned around almost 180?, and now the prevailing wisdom is that both GOTO and global variables should be used as little as possible, if at all. TL;DR: Meyer's "Considered Harmful Essays Considered Harmful" essay is hypocritical junk, and should be considered harmful. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ian.g.kelly at gmail.com Thu Apr 13 13:48:37 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 13 Apr 2017 11:48:37 -0600 Subject: "Goto" statement in Python In-Reply-To: <633df0f9-10c9-4cff-ba86-4a1270b4b19c@googlegroups.com> References: <44db5cea-8831-4951-baa0-a50d99a79b1c@googlegroups.com> <633df0f9-10c9-4cff-ba86-4a1270b4b19c@googlegroups.com> Message-ID: On Thu, Apr 13, 2017 at 11:39 AM, Rustom Mody wrote: > My broader point (vive la Trump) was that if we learn to actively tolerate > people with views wildly far from ours, the world would be a better place. I fail to see how my comment "Functions and exceptions are considered 'bells and whistles'?" suggests intolerance on my part. From python at mrabarnett.plus.com Thu Apr 13 13:50:12 2017 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 13 Apr 2017 18:50:12 +0100 Subject: Python and the need for speed In-Reply-To: <58ef31ee$0$1501$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> <2759e6e0-ad95-466c-81f6-556133620999@googlegroups.com> <58ef31ee$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6f8fc379-51f1-897d-f099-ebcee2be68fa@mrabarnett.plus.com> On 2017-04-13 09:08, Steven D'Aprano wrote: > On Wed, 12 Apr 2017 16:30:38 -0700, bart4858 wrote: > >> (Although I think Python would have difficulty in turning x+=1 into a >> single opcode, if using normal object references and a shared object >> model.) > > You know, since Python actually exists and isn't just a hypothetical > language, we can find out what it actually does, not just guess :-) > > >>>> import dis >>>> code = compile("x += 1", "", "single") >>>> dis.dis(code) > 1 0 LOAD_NAME 0 (x) > 3 LOAD_CONST 0 (1) > 6 INPLACE_ADD > 7 STORE_NAME 0 (x) > 10 LOAD_CONST 1 (None) > 13 RETURN_VALUE > > > There's an op-code for looking up the name 'x', another to push the > constant 1 on the stack, an op-code for "INPLACE_ADD", followed by an op- > code for STORE_NAME again. > > In principle, we could replace the LOAD_CONST and INPLACE_ADD with a > single op-code that combines the two. Whether that would speed anything > up is another question. > > Is it possible to skip the STORE_NAME op-code? If you knew *for sure* > that the target (x) was a mutable object which implemented += using an in- > place mutation, then you could, but the only built-in where that applies > is list so even if you could guarantee x was a list, it hardly seems > worth the bother. > If the reference to be stored by STORE_NAME is the same as the reference returned by LOAD_NAME, then STORE_NAME could be omitted. That would just mean remembering that address. I'm still trying to think whether it's ever possible to lose all references to the object when INPLACE_ADD is called, leading to the object having been garbage-collected by the time it returns. From rustompmody at gmail.com Thu Apr 13 14:01:57 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 13 Apr 2017 11:01:57 -0700 (PDT) Subject: "Goto" statement in Python In-Reply-To: References: <44db5cea-8831-4951-baa0-a50d99a79b1c@googlegroups.com> <633df0f9-10c9-4cff-ba86-4a1270b4b19c@googlegroups.com> Message-ID: On Thursday, April 13, 2017 at 11:19:38 PM UTC+5:30, Ian wrote: > On Thu, Apr 13, 2017 at 11:39 AM, Rustom Mody wrote: > > My broader point (vive la Trump) was that if we learn to actively tolerate > > people with views wildly far from ours, the world would be a better place. > > I fail to see how my comment "Functions and exceptions are considered > 'bells and whistles'?" suggests intolerance on my part. It was not directed specifically at you but at the overall quality of responses that Mikhail is receiving for his (to me admittedly) outlandish views From mikhailwas at gmail.com Thu Apr 13 14:08:24 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Thu, 13 Apr 2017 20:08:24 +0200 Subject: "Goto" statement in Python In-Reply-To: References: Message-ID: On 13 April 2017 at 19:38, Ian Kelly wrote: > On Thu, Apr 13, 2017 at 11:25 AM, Mikhail V wrote: >> On 13 April 2017 at 18:48, Ian Kelly wrote: >>> On Thu, Apr 13, 2017 at 10:23 AM, Mikhail V wrote: >>>> Now I wonder, have we already collected *all* bells and whistles of Python >>>> in these two examples, or is there something else for expressing trivial thing. >>> >>> Functions and exceptions are considered "bells and whistles"? >> >> You mean probably classes and exceptions? For me, indeed they are, >> but it depends. > > No, I meant functions (the first example) and exceptions (the second example). > >> And breaking the code into def() chunks that are not >> functions but just chunks... I don't know, looks bad. > > I don't know what you mean by this. There is no such thing as a "def() > chunk" that is not a function. I mean that in my example I have consequent code and Rob takes a part of the code and puts it in a function. And this is just a part of code, I don't need here anything to wrap or return and don't want to scroll up and down and collect it all in my brain back into original sequence. Therefore I've called it abstract art. From rustompmody at gmail.com Thu Apr 13 14:09:53 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 13 Apr 2017 11:09:53 -0700 (PDT) Subject: Goto Considered Harmful [was Re: Python and the need for speed] In-Reply-To: <58efb8de$0$1618$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58efb8de$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3fbbdbde-107c-4ebb-b608-fd370c0ce72f@googlegroups.com> On Thursday, April 13, 2017 at 11:14:15 PM UTC+5:30, Steve D'Aprano wrote: > Meyer's "Considered Harmful Essays Considered Harmful" essay is hypocritical > junk, and should be considered harmful. Your view. Here's an alternative. [Sorry its a vague memory of something I read more than a decade ago that I cant trace again] Some unknown Cobol programmer talking about Dijkstra: Dijkstra used his enormous prestige to destroy Cobol. We lost a great deal What did he gain? Ok so Cobol's control constructs are below par But do any of its modern successors have its data-describing properties? [the PIC clause] Or consider(!) Alan Kay's statement: "Arrogance in computer science is measured in nanodijktras" Maybe that's a response to similar violent, unnecessary barbs from Dijkstra? From larry.martell at gmail.com Thu Apr 13 14:16:12 2017 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 13 Apr 2017 14:16:12 -0400 Subject: Goto Considered Harmful [was Re: Python and the need for speed] In-Reply-To: <3fbbdbde-107c-4ebb-b608-fd370c0ce72f@googlegroups.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58efb8de$0$1618$c3e8da3$5496439d@news.astraweb.com> <3fbbdbde-107c-4ebb-b608-fd370c0ce72f@googlegroups.com> Message-ID: On Thu, Apr 13, 2017 at 2:09 PM, Rustom Mody wrote: > Or consider(!) Alan Kay's statement: "Arrogance in computer science is measured > in nanodijktras" Completely unrelated but it reminded me about this bon mot about Niklaus Wirth: Europeans tend to pronounce his name properly, as Nih-klaus Virt, while Americans usually mangle it into something like Nickles Worth. That has led to the programmer joke saying Europeans call him by name while Americans call him by value. From grant.b.edwards at gmail.com Thu Apr 13 14:24:53 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 13 Apr 2017 18:24:53 +0000 (UTC) Subject: "Goto" statement in Python References: <44db5cea-8831-4951-baa0-a50d99a79b1c@googlegroups.com> Message-ID: On 2017-04-13, Rob Gaddi wrote: > No, C doesn't support exception handling. As a result, handling error > conditions in C is a huge pain for which (forward-only) goto is often, > while not the only remedy, the least painful one. Indeed. That is almost the only place I use 'goto' in C, and the almost the only place I see others use it. Very occasionally, you see a the error handling goto refactored into a backwards "goto retry": this code foo() { while (1) { if () goto error: return; error: } } becomes foo() { retry: if () { goto retry: } } I happen to find the latter easier to read. Fortunately, Python doesn't need goto to deal with things like that. > Or if you've really developed a need for self-harm, setjmp/longjmp. I've tried to use setjmp/longjmp for error handling a few times. It never went well... -- Grant Edwards grant.b.edwards Yow! Catsup and Mustard all at over the place! It's the gmail.com Human Hamburger! From eryksun at gmail.com Thu Apr 13 14:36:11 2017 From: eryksun at gmail.com (eryk sun) Date: Thu, 13 Apr 2017 18:36:11 +0000 Subject: Check multiple file parms in single os.access? In-Reply-To: <87o9w0xvx4.fsf@bsb.me.uk> References: <87o9w0xvx4.fsf@bsb.me.uk> Message-ID: On Thu, Apr 13, 2017 at 1:46 PM, Ben Bacarisse wrote: > James McMahon writes: > >> Is there a way to mask the F_OK, R_OK, and W_OK in a single os.access >> call? I'm guessing there must be, rather than doing this >> >> if ( os.access(fqfname,os.F_OK) and os.access(fqfname,os.R_OK) and >> os.access(fqfname,os.W_OK)) : > > You can "or" together os.R_OK | os.W_OK into one call but you can can't bitwise OR. > do that with F_OK. Mind you, I'm not sure that matters since I can't > think of a case where you want to fail because os.F_OK fails but os.R_OK > and os.W_OK succeeds. In other words, why not just test for os.R_OK | > os.W_OK? > > Note that despite using the "or" operation to construct the parameter, > the test is an implied "and": > > os.access(fqfname, os.R_OK | os.W_OK) > > is true only if both read and write access are permitted. Note that os.access doesn't check file security on Windows. W_OK just checks the read-only flag. Thus using try/except is really the only possibility if you're on Windows and aren't using the Windows security API. From nathan.ernst at gmail.com Thu Apr 13 14:51:42 2017 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Thu, 13 Apr 2017 13:51:42 -0500 Subject: Goto Considered Harmful [was Re: Python and the need for speed] In-Reply-To: <3fbbdbde-107c-4ebb-b608-fd370c0ce72f@googlegroups.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58efb8de$0$1618$c3e8da3$5496439d@news.astraweb.com> <3fbbdbde-107c-4ebb-b608-fd370c0ce72f@googlegroups.com> Message-ID: Thank you for that Alan Kay quote. Brightened up my day. Since you also mentioned COBOL, and this is a thread about "goto", reminded me of the single most abhorrent thing I ever saw in COBOL (I had to convert a single COBOL batch process to ASP.Net as an intern back in 2003-4). "MOVE NEXT SENTENCE". What is this statement? An unlabelled goto. It literally jumps to the next period: "." in the source. Now, I'm fine with judicious use of goto with good labels. (and, I've only used goto maybe 3 or 4 times in a 15 year career), but a blocky construct like "MOVE NEXT SENTENCE" in a language that also has lots of (all-caps required) block statements to jump to a tiny on the screen period...that is just evil. On Thu, Apr 13, 2017 at 1:09 PM, Rustom Mody wrote: > On Thursday, April 13, 2017 at 11:14:15 PM UTC+5:30, Steve D'Aprano wrote: > > Meyer's "Considered Harmful Essays Considered Harmful" essay is > hypocritical > > junk, and should be considered harmful. > > Your view. > Here's an alternative. > [Sorry its a vague memory of something I read more than a decade ago that > I cant > trace again] > Some unknown Cobol programmer talking about Dijkstra: > > Dijkstra used his enormous prestige to destroy Cobol. > We lost a great deal > What did he gain? > Ok so Cobol's control constructs are below par > But do any of its modern successors have its data-describing properties? > [the PIC clause] > > Or consider(!) Alan Kay's statement: "Arrogance in computer science is > measured > in nanodijktras" > Maybe that's a response to similar violent, unnecessary barbs from > Dijkstra? > -- > https://mail.python.org/mailman/listinfo/python-list > From marko at pacujo.net Thu Apr 13 15:05:56 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 13 Apr 2017 22:05:56 +0300 Subject: "Goto" statement in Python References: <8760i8z5u9.fsf@elektro.pacujo.net> Message-ID: <87vaq886wb.fsf@elektro.pacujo.net> Rob Gaddi : > On 04/13/2017 08:26 AM, Marko Rauhamaa wrote: >> I have occasionally felt the urge to try "goto" in my C code, but having >> written it, I have taken it out. It just doesn't make the code look more >> elegant or robust. Unlike "break" or "return," "goto" makes me uneasy >> about variable scope and lifetime. > [...] > You see it all the time in kernel code or when doing I/O. A pretty > common pattern is: > > int return_val = 1; > if (init_thing(x)) goto bk1; > if (init_thing(y)) goto bk2; > if (init_thing(z)) goto bk3; > > do_things_with(x, y, z); > return_val = 0; > > bk3: cleanup_thing(z); > bk2: cleanup_thing(y); > bk1: cleanup_thing(x); > return return_val; I know, but I still don't like it. Marko From breamoreboy at gmail.com Thu Apr 13 17:47:03 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Thu, 13 Apr 2017 14:47:03 -0700 (PDT) Subject: Moderating the list [was: Python and the need for speed] In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <27652c6d-2cb4-4f0c-9400-6aa2a3f9f855@googlegroups.com> <9bdec2c0-6050-4b55-e4a0-96fcc9af6899@lucidity.plus.com> <58ecdae8$0$1602$c3e8da3$5496439d@news.astraweb.com> <9fac840a-165f-789a-6631-ed913a1cdcf6@timgolden.me.uk> <0b06e80e-eb1f-889e-c4f2-5f0d5f158c09@timgolden.me.uk> Message-ID: <1a4a03e4-3c20-4426-9f51-c14860f2ea3a@googlegroups.com> On Thursday, April 13, 2017 at 10:31:22 AM UTC+1, Tim Golden wrote: > On 13/04/2017 03:39, Jason Friedman wrote: > >> > >> However, it's simply a technical fact: the thing which we moderate is the > >>> mailing list. We can control which posts make it through from the newsgroup > >>> by blocking them at the gateway. But the posts will continue to appear on > >>> comp.lang.python which is, as the description says, unmoderated. > >>> > >> > >> TJG > > > > > > Thank you, Tim and Ethan and the other moderators, for performing that > > function. > > It makes the reading experience more pleasant for me. > > > > I looked, for the first time in a long while, at the GG mirror of the > newsgroup. Hadn't realised how much of that really nasty all-caps spam > we were blocking. (We set up some gateway rules when that started to > become a problem so we just don't see it on the mailing list). > > Most of the time we're just binning run-of-the-mill spam. Doesn't take > too much effort if you keep on top of it, but it piles up quickly enough > if you leave it for a bit! > > TJG I routinely set all of the upper-case crap to "violent content" on GG just as a matter of principle. There's even been a couple of English versions lately but the filters have stopped them, well done :-) Kindest regards. Mark Lawrence. From ian.g.kelly at gmail.com Thu Apr 13 17:58:57 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 13 Apr 2017 15:58:57 -0600 Subject: "Goto" statement in Python In-Reply-To: <42rvech210hf4il6c4h7q5eoli5toiv8mk@4ax.com> References: <42rvech210hf4il6c4h7q5eoli5toiv8mk@4ax.com> Message-ID: On Thu, Apr 13, 2017 at 3:27 PM, Dennis Lee Bieber wrote: > On Thu, 13 Apr 2017 15:52:24 +0100, bartc declaimed the > following: > >>'goto' would be one easy-to-execute byte-code; no variables, objects or >>types to worry about. If implemented properly (with the byte-code >>compiler using a dedicated name-space for labels) there would be no name >>lookups. >> > > Only if GOTO is not allowed to break out of namespaces... > > NO GOTO from inside a function to some global catch-all handler... No > GOTO from a global scope into a non-global scope. > > Once you permit uncontrolled/unlimited GOTO you have to be concerned > with stack-frames and object life-times. Even within a function you would still have to be concerned about a goto from inside a try or with block to outside of that block, as the finally block or the context manager's __exit__ still need to be executed on the way out. Not to mention the time-honored tradition of using goto to jump INTO a block, such as Duff's Device. From bc at freeuk.com Thu Apr 13 18:59:25 2017 From: bc at freeuk.com (bartc) Date: Thu, 13 Apr 2017 23:59:25 +0100 Subject: "Goto" statement in Python In-Reply-To: References: <42rvech210hf4il6c4h7q5eoli5toiv8mk@4ax.com> Message-ID: <4pTHA.695356$nT1.588759@fx44.am4> On 13/04/2017 22:58, Ian Kelly wrote: > On Thu, Apr 13, 2017 at 3:27 PM, Dennis Lee Bieber > wrote: >> On Thu, 13 Apr 2017 15:52:24 +0100, bartc declaimed the >> following: >> >>> 'goto' would be one easy-to-execute byte-code; no variables, objects or >>> types to worry about. If implemented properly (with the byte-code >>> compiler using a dedicated name-space for labels) there would be no name >>> lookups. >>> >> >> Only if GOTO is not allowed to break out of namespaces... >> >> NO GOTO from inside a function to some global catch-all handler... (That doesn't happen. No sane language would allow it, not on the user-side anyway.) >> Once you permit uncontrolled/unlimited GOTO you have to be concerned >> with stack-frames and object life-times. > > Even within a function you would still have to be concerned about a > goto from inside a try or with block to outside of that block, as the > finally block or the context manager's __exit__ still need to be > executed on the way out. So how does 'break' manage it? I assume break works from inside a try- or with-block. Jumping /into/ such a block might be more tricky, but it is simple enough to not allow it. -- Bartc From roel at roelschroeven.net Thu Apr 13 20:25:46 2017 From: roel at roelschroeven.net (Roel Schroeven) Date: Fri, 14 Apr 2017 02:25:46 +0200 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: References: <00a901d2b3d8$25d09460$27b23dae@sambora> Message-ID: Gregory Ewing schreef op 13/04/2017 9:34: > Deborah Swanson wrote: >> Peter Otten wrote, on Wednesday, April 12, 2017 1:45 PM >> >>> Personally I would immediately discard the header row once and for >>> all, not again and again on every operation. >> Well, perhaps, but I need the header row to stay in place to write the >> list to a csv when I'm done > > That's no problem, just write the header row separately. > > Do this at the beginning: > > header = [Record._make(fieldnames)] > records = [Record._make(row) for row in rows] > > and then to write out the file: > > writer = csv.writer(outputfile) > writer.writerow(header) > writer.writerows(records) I don't even think there's any need to store the field names anywhere else than in fieldnames. So unless I'm missing something, just do this at the beginning: fieldnames = next(rows) Record = namedtuple("Record", fieldnames) records = [Record._make(row) for row in rows] and this at the end: writer = csv.writer(outputfile) writer.writerow(fieldnames) # or writer.writerow(Record._fields) writer.writerows(records) -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From ian.g.kelly at gmail.com Thu Apr 13 20:36:57 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 13 Apr 2017 18:36:57 -0600 Subject: "Goto" statement in Python In-Reply-To: <4pTHA.695356$nT1.588759@fx44.am4> References: <42rvech210hf4il6c4h7q5eoli5toiv8mk@4ax.com> <4pTHA.695356$nT1.588759@fx44.am4> Message-ID: On Thu, Apr 13, 2017 at 4:59 PM, bartc wrote: > On 13/04/2017 22:58, Ian Kelly wrote: >> >> On Thu, Apr 13, 2017 at 3:27 PM, Dennis Lee Bieber >> wrote: >>> >>> On Thu, 13 Apr 2017 15:52:24 +0100, bartc declaimed the >>> following: >>> >>>> 'goto' would be one easy-to-execute byte-code; no variables, objects or >>>> types to worry about. If implemented properly (with the byte-code >>>> compiler using a dedicated name-space for labels) there would be no name >>>> lookups. >>>> >>> >>> Only if GOTO is not allowed to break out of namespaces... >>> >>> NO GOTO from inside a function to some global catch-all >>> handler... > > > (That doesn't happen. No sane language would allow it, not on the user-side > anyway.) Well, you can do it in Assembly. And BASIC, if you count the primitive GOSUB-type subroutines, though modern BASICs have real subroutines that don't allow it. >>> Once you permit uncontrolled/unlimited GOTO you have to be >>> concerned >>> with stack-frames and object life-times. >> >> >> Even within a function you would still have to be concerned about a >> goto from inside a try or with block to outside of that block, as the >> finally block or the context manager's __exit__ still need to be >> executed on the way out. > > > So how does 'break' manage it? I assume break works from inside a try- or > with-block. Yes, it would have to work similarly to break, continue and return. I didn't mean to imply that it was impossible, only that it's not quite as simple as just modifying a program counter. For reference, here's what break inside a try block compiles to: >>> dis.dis(""" ... while True: ... try: ... break ... finally: ... print("Bye") ... """) 2 0 SETUP_LOOP 22 (to 24) 3 >> 2 SETUP_FINALLY 6 (to 10) 4 4 BREAK_LOOP 6 POP_BLOCK 8 LOAD_CONST 0 (None) 6 >> 10 LOAD_NAME 0 (print) 12 LOAD_CONST 1 ('Bye') 14 CALL_FUNCTION 1 16 POP_TOP 18 END_FINALLY 20 JUMP_ABSOLUTE 2 22 POP_BLOCK >> 24 LOAD_CONST 0 (None) 26 RETURN_VALUE From python at deborahswanson.net Thu Apr 13 20:41:12 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Thu, 13 Apr 2017 17:41:12 -0700 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: Message-ID: <009a01d2b4b7$d1962aa0$27b23dae@sambora> Peter Otten wrote, on Thursday, April 13, 2017 12:17 AM > > Deborah Swanson wrote: > > > Peter Otten wrote, on Wednesday, April 12, 2017 11:35 PM > >> > >> Deborah Swanson wrote: > >> > >> > It's a small point, but I suspect getattr(record, label) > >> would still > >> > fail, even if label's value is 'label' and only 'label', > but what's > >> > the point of having a variable if it will only ever have > just one > >> > value? > >> > >> You are misunderstanding. Your getattr() call fails because you have > >> > >> label = "label" > >> > >> burried somewhere in your code. As soon as you change that to > >> > >> label = > >> > >> the error will go away. > > > > > > Yes, the error goes away, but now getattr(record, label) is useless > > for processing field names, unless you want to write a line of code > > for each one. (I have 17 field names, and forget about passing label > > to a function.) Uh-oh, I boobooed and misread what you wrote here. > No, it's not useless: > > >>> from collections import namedtuple > >>> T = namedtuple("T", "foo bar baz") > >>> t = T(1, 2, 3) > >>> for name in t._fields: > ... print(name, "=", getattr(t, name)) > ... > foo = 1 > bar = 2 > baz = 3 Wow. Ok, I can see that the specific circumstance I got the "object has no attribute 'label' error was quite likely not due to using getattr() with a variable for a namedtuple field name, and probably some other factor was at work. Unfortunately, when I shifted gears on the overall problem and abandoned the strategy of making the group-by defaultdict, I renamed the project file and started over, going back to the original list of namedtuples. As a result, all the back versions of my code producing this error were lost. I've spent the better part of today rewriting the lost code, and I'm nowhere near finished, and now my illness is ganging up on me again. So anything further will have to wait til tomorrow. I remain quite sure that at no point did I have the line label = "label" in my code, and I wouldn't even have thought of writing it because it's so absurd in so many ways. Hopefully I can show you what I wrote soon, and you can see for yourself. > And as a special service here's a mutable datatype with sufficient > namedtuple compatibility to replicate the above snippet: > > $ cat namedtuple_replacement.py > def struct(name, wanted_columns): > class Struct: > _fields = __slots__ = wanted_columns.split() > > def __init__(self, *args): > names = self.__slots__ > if len(args) != len(names): > raise ValueError > for name, value in zip(names, args): > setattr(self, name, value) > > @classmethod > def _make(cls, args): > return cls(*args) > > def __repr__(self): > names = self.__slots__ > return "{}({})".format( > self.__class__.__name__, > ", ".join("{}={!r}".format(n, getattr(self, > n)) for n in > names) > ) > > Struct.__name__ = name > return Struct > > T = struct("T", "foo bar baz") > t = T(1, 2, 3) > print(t) > for name in t._fields: > print(name, "=", getattr(t, name)) > t.bar = 42 > print(t) > $ python3 namedtuple_replacement.py > T(foo=1, bar=2, baz=3) > foo = 1 > bar = 2 > baz = 3 > T(foo=1, bar=42, baz=3) Thank you for this datatype definition. I won't take a serious look at it until I rewrite the code I lost and get to the bottom of why getattr() got the attribute error, but once that issue is resolved I will return to your mutable datatype with namedtuple compatibility (to some extent, I gather). I apologize for the delay, but your simple getattr() example above demands that I find out why it wasn't working for me before moving on with the rest of this. And that will take some time. Probably not the 3 weeks it took me to get to the point where I was consistently seeing the error, but it will be awhile. I'll come back to address these issues and your datatype when I've got code to show what I did. (For my own sanity, if no other reason.) From python at deborahswanson.net Thu Apr 13 20:47:34 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Thu, 13 Apr 2017 17:47:34 -0700 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: Message-ID: <00a001d2b4b8$b4e9d090$27b23dae@sambora> Gregory Ewing wrote, on Thursday, April 13, 2017 12:17 AM > > Deborah Swanson wrote: > > But I think you got it right in your last sentence below. > defaultdict > > copied them because they were immutable, > > No, definitely not. A defaultdict will never take it upon > itself to copy an object you give it, either as a key or a value. > > The copying, if any, must have occurred somewhere else, in > code that you didn't show us. > > Can you show us the actual code you used to attempt to > update the namedtuples? > > -- > Greg As I just told Peter, I just discovered earlier today that all of that code is lost, and it will take awhile to rewrite. And now I have several reasons to do so. I don't know how long it will take, but I will come back and produce the code that gave me this behavior. From ian.g.kelly at gmail.com Thu Apr 13 20:48:19 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 13 Apr 2017 18:48:19 -0600 Subject: Goto Considered Harmful [was Re: Python and the need for speed] In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58efb8de$0$1618$c3e8da3$5496439d@news.astraweb.com> <3fbbdbde-107c-4ebb-b608-fd370c0ce72f@googlegroups.com> Message-ID: On Thu, Apr 13, 2017 at 12:51 PM, Nathan Ernst wrote: > Thank you for that Alan Kay quote. Brightened up my day. Since you also > mentioned COBOL, and this is a thread about "goto", reminded me of the > single most abhorrent thing I ever saw in COBOL (I had to convert a single > COBOL batch process to ASP.Net as an intern back in 2003-4). "MOVE NEXT > SENTENCE". What is this statement? An unlabelled goto. It literally jumps > to the next period: "." in the source. > > Now, I'm fine with judicious use of goto with good labels. (and, I've only > used goto maybe 3 or 4 times in a 15 year career), but a blocky construct > like "MOVE NEXT SENTENCE" in a language that also has lots of (all-caps > required) block statements to jump to a tiny on the screen period...that is > just evil. Yikes. I never took the time to learn COBOL, but that almost sounds like something that you'd find in an esoteric language like INTERCAL. From python at deborahswanson.net Thu Apr 13 20:52:15 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Thu, 13 Apr 2017 17:52:15 -0700 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: Message-ID: <00a101d2b4b9$5c886dc0$27b23dae@sambora> Gregory Ewing wrote, on Thursday, April 13, 2017 12:34 AM > > Deborah Swanson wrote: > > Peter Otten wrote, on Wednesday, April 12, 2017 1:45 PM > > > >> Personally I would immediately discard the header row once and for > >> all, not again and again on every operation. > > > > Well, perhaps, but I need the header row to stay in place > to write the > > list to a csv when I'm done > > That's no problem, just write the header row separately. > > Do this at the beginning: > > header = [Record._make(fieldnames)] > records = [Record._make(row) for row in rows] > > and then to write out the file: > > writer = csv.writer(outputfile) > writer.writerow(header) > writer.writerows(records) > > > There might be a tiny performance edge in discarding the header row > > for the sort, but there would also be a hit to recreate it > at output > > time. > > It's not about performance, it's about keeping the code as > clean and simple as you can, thus making it easier to > understand and maintain. > > The general idea to take away from this is that it's almost > always best to arrange things so that a given collection > contains just one kind of data, so you can treat every > element of it in exactly the same way. > > -- > Greg That's good advice and I'll rewrite it that way, after I have the code I started with to answer the other questions. I certainly know I have a lot to learn about writing good code, and I can see that what you're suggesting is much cleaner than what I had. Thanks, Deborah From python at deborahswanson.net Thu Apr 13 20:55:57 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Thu, 13 Apr 2017 17:55:57 -0700 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: Message-ID: <00a201d2b4b9$e1142930$27b23dae@sambora> Gregory Ewing wrote, on Thursday, April 13, 2017 12:36 AM > > If you want to be able to update your rows, you may find > this useful: > https://pypi.python.org/pypi/recordclass It's very similar to a namedtuple, but mutable. Looks like it should be a drop-in replacement. -- Greg Thanks Greg, I'll definitely take a look at it From python at deborahswanson.net Thu Apr 13 21:01:49 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Thu, 13 Apr 2017 18:01:49 -0700 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: Message-ID: <00a301d2b4ba$b2cd9560$27b23dae@sambora> Gregory Ewing wrote, on Thursday, April 13, 2017 1:14 AM > > Deborah Swanson wrote: > > I don't exactly understand your point (2). If the > namedtuple does not > > have a label attribute, then getattr(record, label) will > get the error > > whether the name label holds the string 'label' or not. > > You sound rather confused. Maybe the following interactive > session transcript will help. > > >>> from collections import namedtuple > >>> record = namedtuple('record', 'alpha,beta') > >>> r = record(1, 2) > >>> r > record(alpha=1, beta=2) > >>> label = 'alpha' > >>> getattr(r, label) > 1 > >>> label = 'beta' > >>> getattr(r, label) > 2 > >>> label = 'gamma' > >>> getattr(r, label) > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'record' object has no attribute 'gamma' > > Can you see what's happening here? The expression > > label > > is being evaluated, and whatever string it evaluates to is > being used as the attribute name to look up. > > Now, I'm not sure exactly what you were doing to get the > message "'record' object has no attribute 'label'". Here are > a few possible ways to get that effect: > > >>> r.label > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'record' object has no attribute 'label' > > >>> getattr(r, 'label') > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'record' object has no attribute 'label' > > >>> label = 'label' > >>> getattr(r, label) > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'record' object has no attribute 'label' > > Or maybe you did something else again. We would need to > see your code in order to tell. > > -- > Greg And it's reproducing the code that's the roadblock to all of these issues. Rest assured I will get to the bottom of this, or at least come back with the code to ask more questions about it and let you see what I had. I want to see what's going on here too. Might be a day or two though. Deborah From python at deborahswanson.net Thu Apr 13 21:08:53 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Thu, 13 Apr 2017 18:08:53 -0700 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: Message-ID: <00a401d2b4bb$af5011f0$27b23dae@sambora> Roel Schroeven wrote, on Thursday, April 13, 2017 5:26 PM > > Gregory Ewing schreef op 13/04/2017 9:34: > > Deborah Swanson wrote: > >> Peter Otten wrote, on Wednesday, April 12, 2017 1:45 PM > >> > >>> Personally I would immediately discard the header row > once and for > >>> all, not again and again on every operation. > >> Well, perhaps, but I need the header row to stay in place to write > >> the list to a csv when I'm done > > > > That's no problem, just write the header row separately. > > > > Do this at the beginning: > > > > header = [Record._make(fieldnames)] > > records = [Record._make(row) for row in rows] > > > > and then to write out the file: > > > > writer = csv.writer(outputfile) > > writer.writerow(header) > > writer.writerows(records) > > I don't even think there's any need to store the field names anywhere > else than in fieldnames. So unless I'm missing something, > just do this > at the beginning: > > fieldnames = next(rows) > Record = namedtuple("Record", fieldnames) > records = [Record._make(row) for row in rows] > > and this at the end: > > writer = csv.writer(outputfile) > writer.writerow(fieldnames) # or writer.writerow(Record._fields) > writer.writerows(records) > > > -- > The saddest aspect of life right now is that science gathers > knowledge faster than society gathers wisdom. > -- Isaac Asimov > > Roel Schroeven Thanks Roel. I'll try your version when I get the code reconstructed, and that might take a few to several days. I'll try to get back to you though on how it goes. Read the previous messages if you want the sad story of what happened to the original code. Deborah From steve+python at pearwood.info Thu Apr 13 21:33:12 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 14 Apr 2017 11:33:12 +1000 Subject: Goto Considered Harmful [was Re: Python and the need for speed] References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58efb8de$0$1618$c3e8da3$5496439d@news.astraweb.com> <3fbbdbde-107c-4ebb-b608-fd370c0ce72f@googlegroups.com> Message-ID: <58f026d9$0$1612$c3e8da3$5496439d@news.astraweb.com> On Fri, 14 Apr 2017 04:09 am, Rustom Mody wrote: > On Thursday, April 13, 2017 at 11:14:15 PM UTC+5:30, Steve D'Aprano wrote: >> Meyer's "Considered Harmful Essays Considered Harmful" essay is >> hypocritical junk, and should be considered harmful. > > Your view. Well duh :-) > Here's an alternative. > [Sorry its a vague memory of something I read more than a decade ago that > [I cant > trace again] > Some unknown Cobol programmer talking about Dijkstra: > > Dijkstra used his enormous prestige to destroy Cobol. "Imminent Death Of Cobol Predicted. Again." When the sun finally expands into a supergiant in five billion years, destroying the earth, the last survivors to die will be COBOL-programming cockroaches and Keith Richards. > We lost a great deal > What did he gain? > Ok so Cobol's control constructs are below par > But do any of its modern successors have its data-describing properties? > [the PIC clause] If PIC is so great, why do no other languages have it? That's a serious question, not a rhetorical question. > Or consider(!) Alan Kay's statement: "Arrogance in computer science is > measured in nanodijktras" Indeed. What's your point? Because that sounds awfully like an ad hominem fallacy. Dijkstra was arrogant, therefore he must be wrong. > Maybe that's a response to similar violent, unnecessary barbs from > Dijkstra? "Violent"? Are you one of those people who think that calling a person an idiot is morally indistinguishable from beating them into a coma? "Sticks and stones will break my bones, but that's nothing to the harm caused by a few mean words." -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Thu Apr 13 21:44:59 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 14 Apr 2017 11:44:59 +1000 Subject: "Goto" statement in Python References: Message-ID: <58f0299c$0$1620$c3e8da3$5496439d@news.astraweb.com> On Fri, 14 Apr 2017 12:52 am, bartc wrote: > I know this isn't the Python need-for-speed thread, but this is a > classic example where the lack of one simple feature leads to using > slower, more cumbersome ones. Dear gods, have I fallen back in time to 1975 again? The Goto Wars are over, and the structured programming camp won the war decisively. Are functions/procedures *technically* slower than GOTOs? Yes. So what? You're nano-optimizing the wrong thing: you're saving a microsecond of runtime at the cost of a megasecond of development and maintenance time. At the point that you say "Function calls ... are rather more heavyweight" the whole argument becomes farcical. Function calls are so prevalent in modern structured programming (whether you write in procedural, functional or object-oriented style, or a combination of all three) that saving one or two function calls isn't even a micro-optimization, especially not in a high-level language. To save any meaningful time, you would need to return to the bad-old-days of unmaintainable unstructured spaghetti code. This debate about the usefulness of GOTO in modern languages reminds me of the sort of people who will drive around the city for an hour looking to save 0.1 cent on the cost of petrol (gasoline for Americans). > 'goto' would be one easy-to-execute byte-code; no variables, objects or > types to worry about. If implemented properly (with the byte-code > compiler using a dedicated name-space for labels) there would be no name > lookups. I don't care much about the implementation of GOTO. I care a lot about the code written that includes GOTOs. Are there reasonable uses for GOTO? Perhaps. There are semi-structured restricted versions of GOTO, like exceptions, break and return, but an unrestricted GOTO where you can jump anywhere in the program is a terrible feature for anything but the smallest, most trivial programs. To be even *close* to safe, you have to restrict GOTO considerably. At the very minimum, you need two restrictions: - cannot jump into the middle of a procedure or function; - cannot jump immediately out of a procedure or function without cleaning up the stack and other handling. Even that's not enough for some. Donald Knuth, who supports the use of GOTO under some circumstances, maintains that any program using GOTOs should have the invariant that its flow chart can be drawn with all forward branches on the left, all backward branches on the right, and no branches crossing each other. Features should not be judged solely on their usefulness to the best 1% of programmers using the feature in the best possible way. You also need to consider the lesser mortals, the below-average 50% of programmers who will use the feature in sub-optimal if not outright terrible ways. GOTOs are far to easy to abuse. The harm that they do is outweighed a thousand times by the rare positive use. Most languages do well to avoid GOTO, even if that means that there are one or two rare uses that have to be written slightly sub-optimally for the lack. > Function calls, returns and generators are rather more heavyweight in > comparison. And enormously better. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Thu Apr 13 22:13:03 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 14 Apr 2017 12:13:03 +1000 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58f03030$0$1598$c3e8da3$5496439d@news.astraweb.com> On Wed, 12 Apr 2017 07:56 pm, bart4858 at gmail.com wrote: > The problem is also the language encouraging people to use high-level but > inefficient methods, as the emphasis is on productivity and readability** > rather than performance. I'm sorry, but that is in no way "the problem". Emphasising productivity and readability is not a problem. It is a feature. There are a bazillion ugly, unreadable, unproductive but slow languages if you want them: C, C++, C#, Objective C, Lisp, Scheme, Fortran, Java, Rust, D, Ada ... (although of course aficionados of each language will disagree about it being unproductive; whatever rocks your boat). That's fine. If you want fast code, you can get it. Python's emphasis on readability and productivity is not a cross to bear, it is not a bug, or a design mistake, or a problem. It is an intentional trade-off. While it is certainly true that faster Python is welcome, and that there may be ways of getting it without giving up on the essential Pythonness of the language, if speed is your number one concern, maybe Python was the wrong choice of language for you. Just like if you care most about program correctness, type-safety and correctness proofs, choosing C is probably the wrong decision. [...] > (** Although I find code full of class definitions, one-liners, decorators > and all the other esoterics, incomprehensive. I'm sure I'm not the only > one, so perhaps readability isn't too much of a priority either.) Classes and decorators are not esoteric. You sound like an old man who complains about this new-fangled "telephone", and how things were so much better when we had messenger boys to deliver messages anywhere in the city. I'm not sure what you consider incomprehensible about "one liners", surely it depends on what the one liner does. These are pretty clear to me: # The archetypal "Hello World!" program is a one-liner. print("Hello World!") # One liner to calculate the sum of the first 50 cubes. total = sum(i**3 for i in range(50)) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Thu Apr 13 22:52:25 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 13 Apr 2017 19:52:25 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: <58f03030$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <58f03030$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0042cab4-f998-4118-b83c-331a7d97c533@googlegroups.com> On Friday, April 14, 2017 at 7:43:22 AM UTC+5:30, Steve D'Aprano wrote: > On Wed, 12 Apr 2017 07:56 pm, bart wrote: > > > The problem is also the language encouraging people to use high-level but > > inefficient methods, as the emphasis is on productivity and readability** > > rather than performance. > > I'm sorry, but that is in no way "the problem". > > Emphasising productivity and readability is not a problem. It is a feature. > > There are a bazillion ugly, unreadable, unproductive but slow languages if > you want them: > > C, C++, C#, Objective C, Lisp, Scheme, Fortran, Java, Rust, D, Ada ... C and Fortran in the slow-set?? I'd say you are typing too fast :D From rustompmody at gmail.com Thu Apr 13 23:06:31 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 13 Apr 2017 20:06:31 -0700 (PDT) Subject: Goto Considered Harmful [was Re: Python and the need for speed] In-Reply-To: <58f026d9$0$1612$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58efb8de$0$1618$c3e8da3$5496439d@news.astraweb.com> <3fbbdbde-107c-4ebb-b608-fd370c0ce72f@googlegroups.com> <58f026d9$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, April 14, 2017 at 7:03:24 AM UTC+5:30, Steve D'Aprano wrote: > On Fri, 14 Apr 2017 04:09 am, Rustom Mody wrote: > > [Sorry its a vague memory of something I read more than a decade ago that > > [I cant > > trace again] > > Some unknown Cobol programmer talking about Dijkstra: > > > > Dijkstra used his enormous prestige to destroy Cobol. > > We lost a great deal > > What did he gain? > > Ok so Cobol's control constructs are below par > > But do any of its modern successors have its data-describing properties? > > [the PIC clause] > > If PIC is so great, why do no other languages have it? > > That's a serious question, not a rhetorical question. Dunno enough about Cobol and that ecosystem to make a useful comment However your question is really two: 1. Whats good about Cobol's PIC? 2. Why dont other languages have it/that benefit? 1st as I said I dont feel qualified to answer 2nd is ridiculous. Because of collective stupidity: - Species go extinct - Garbage fills the oceans - Fukushima fallout reaches Canada - And in general good, valuable things die out > > "Imminent Death Of Cobol Predicted. Again." > > When the sun finally expands into a supergiant in five billion years, > destroying the earth, the last survivors to die will be COBOL-programming > cockroaches and Keith Richards. > > Maybe that's a response to similar violent, unnecessary barbs from > > Dijkstra? > > "Violent"? > > Are you one of those people who think that calling a person an idiot is > morally indistinguishable from beating them into a coma? > > "Sticks and stones will break my bones, but that's nothing to the harm > caused by a few mean words." You are treating violence as literal physical violence. Thats backwards. Ultimately all violence is moral Else an orthopaedic sawing off a knee to replace or a dentist yanking out a molar would be felons From rustompmody at gmail.com Thu Apr 13 23:20:44 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 13 Apr 2017 20:20:44 -0700 (PDT) Subject: "Goto" statement in Python In-Reply-To: <58f0299c$0$1620$c3e8da3$5496439d@news.astraweb.com> References: <58f0299c$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, April 14, 2017 at 7:15:11 AM UTC+5:30, Steve D'Aprano wrote: > On Fri, 14 Apr 2017 12:52 am, bartc wrote: > > > I know this isn't the Python need-for-speed thread, but this is a > > classic example where the lack of one simple feature leads to using > > slower, more cumbersome ones. > > Dear gods, have I fallen back in time to 1975 again? Good that you start with the suggestion that we are not in 1975 > Features should not be judged solely on their usefulness to the best 1% of > programmers using the feature in the best possible way. You also need to > consider the lesser mortals, the below-average 50% of programmers who will > use the feature in sub-optimal if not outright terrible ways. > > GOTOs are far to easy to abuse. The harm that they do is outweighed a > thousand times by the rare positive use. Most languages do well to avoid > GOTO, even if that means that there are one or two rare uses that have to > be written slightly sub-optimally for the lack. That sounds very 1970s to me. With the languages that I (and presumably you) grew up with using gotos was too easy; not using was hard or impossible. The most structured was Pascal which set out to be ornery by making one declare labels. With everything else ? Fortran-IV, Basic, assembler ? it was next to impossible. Cut to 2017 and take a random 20 year old brought up on python/java/ruby/javascript/haskell Where/how would he have learnt to use gotos? In short: In 1968 "Goto statement considered harmful" was a necessary viewpoint. Today its a quasi-religious bias without basis. Personal Note: Much of the direction that my programming/teaching has taken in the last 30 years can be traced to a statement made by a teacher when I was graduating: ?What the goto does to control-structure, the assignment does to data-structure? From steve+python at pearwood.info Fri Apr 14 00:25:27 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 14 Apr 2017 14:25:27 +1000 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <58f03030$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58f04f38$0$1611$c3e8da3$5496439d@news.astraweb.com> On Fri, 14 Apr 2017 12:13 pm, Steve D'Aprano wrote: > There are a bazillion ugly, unreadable, unproductive but slow languages if > you want them: Er, I mean *fast*. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From auriocus at gmx.de Fri Apr 14 02:29:22 2017 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 14 Apr 2017 08:29:22 +0200 Subject: Python and the need for speed In-Reply-To: <87a87kzbo3.fsf@elektro.pacujo.net> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> <069ed317-abab-4980-a06c-6eafdc029653@googlegroups.com> <87r30yjlfd.fsf@nightsong.com> <878tn6djq6.fsf@elektro.pacujo.net> <87o9w0d6nc.fsf@elektro.pacujo.net> <58ef7429$0$1596$c3e8da3$5496439d@news.astraweb.com> <87a87kzbo3.fsf@elektro.pacujo.net> Message-ID: Am 13.04.17 um 15:20 schrieb Marko Rauhamaa: > > Not sure if this is still valid: > > Still today Flash RAM cells built in SSDs have a limited lifespan. > Every write (not read) cycle or better every erasure wears a memory > cell and at some time it will stop working. > > s-on-ssd-drives> > It is true, in general, but the lifetime has gotten MUCH better due to overprovisioning and intelligent wear leveling. The German computer magazine c't has tested a few current SSDs by filling them over and over again with random numbers 24/7 until they failed [1]. For these drives with a capacity of 256GB, the manufacturers guaranteed ~70 TB written to them, for Samsung 850 Pro and SanDisk Extreme 150TB were guaranteed. Most drives withstood much more data, the best one being the Samsung 850 Pro, which did not fail until they ended the test after writing 4600 TB in half a year. The others failed at ~1000 TB. So, unless you really plan to fully use them as a cache for number crunching TB sized data blocks, they will practically not fail. The failure mode, however, was very abrupt - unlike from a hard drive, where you can sometimes recover portions of the data, the full drive is completely dead from one point on. Christian [1] https://www.heise.de/newsticker/meldung/SSDs-im-Stresstest-mit-ueberraschenden-Ergebnissen-3580824.html From greg.ewing at canterbury.ac.nz Fri Apr 14 03:06:14 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 14 Apr 2017 19:06:14 +1200 Subject: Goto Considered Harmful [was Re: Python and the need for speed] In-Reply-To: <58f026d9$0$1612$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58efb8de$0$1618$c3e8da3$5496439d@news.astraweb.com> <3fbbdbde-107c-4ebb-b608-fd370c0ce72f@googlegroups.com> <58f026d9$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > If PIC is so great, why do no other languages have it? Something akin to it has turned up in other places, although usually in the guise of an output formatting facility rather than a way of describing how data is stored internally. For example, the PRINT USING found in some BASIC dialects. -- Greg From greg.ewing at canterbury.ac.nz Fri Apr 14 03:17:04 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 14 Apr 2017 19:17:04 +1200 Subject: Goto Considered Harmful [was Re: Python and the need for speed] In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58efb8de$0$1618$c3e8da3$5496439d@news.astraweb.com> <3fbbdbde-107c-4ebb-b608-fd370c0ce72f@googlegroups.com> Message-ID: Ian Kelly wrote: > Yikes. I never took the time to learn COBOL, but that almost sounds > like something that you'd find in an esoteric language like INTERCAL. COBOL has other fun stuff like that, too. For example, the destination of a GOTO statement can be changed from elsewhere in the program: https://www.ibm.com/support/knowledgecenter/SSAE4W_7.1.0/com.ibm.etools.iseries.langref.doc/c0925395347.htm Not quite COMEFROM, but it's getting close! -- Greg From marko at pacujo.net Fri Apr 14 03:52:14 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 14 Apr 2017 10:52:14 +0300 Subject: Goto Considered Harmful [was Re: Python and the need for speed] References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58efb8de$0$1618$c3e8da3$5496439d@news.astraweb.com> <3fbbdbde-107c-4ebb-b608-fd370c0ce72f@googlegroups.com> <58f026d9$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r30vctox.fsf@elektro.pacujo.net> Gregory Ewing : > Steve D'Aprano wrote: > >> If PIC is so great, why do no other languages have it? > > Something akin to it has turned up in other places, although usually > in the guise of an output formatting facility rather than a way of > describing how data is stored internally. For example, the PRINT USING > found in some BASIC dialects. You have the storage thing in SQL: CHAR(4) VARCHAR(256) YEAR(2) DECIMAL(5,2) Marko From marko at pacujo.net Fri Apr 14 04:13:00 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 14 Apr 2017 11:13:00 +0300 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> <069ed317-abab-4980-a06c-6eafdc029653@googlegroups.com> <87r30yjlfd.fsf@nightsong.com> <878tn6djq6.fsf@elektro.pacujo.net> <87o9w0d6nc.fsf@elektro.pacujo.net> <58ef7429$0$1596$c3e8da3$5496439d@news.astraweb.com> <87a87kzbo3.fsf@elektro.pacujo.net> Message-ID: <87mvbjcsqb.fsf@elektro.pacujo.net> Christian Gollwitzer : > Am 13.04.17 um 15:20 schrieb Marko Rauhamaa: >> >> Not sure if this is still valid: >> >> Still today Flash RAM cells built in SSDs have a limited lifespan. >> Every write (not read) cycle or better every erasure wears a memory >> cell and at some time it will stop working. >> >> > s-on-ssd-drives> >> > > It is true, in general, but the lifetime has gotten MUCH better due to > overprovisioning and intelligent wear leveling. [...] > > For these drives with a capacity of 256GB, the manufacturers > guaranteed ~70 TB written to them, for Samsung 850 Pro and SanDisk > Extreme 150TB were guaranteed. Most drives withstood much more data, > the best one being the Samsung 850 Pro, which did not fail until they > ended the test after writing 4600 TB in half a year. The others failed > at ~1000 TB. None of those numbers sound all that high to me. It's a catch-22: if you rarely use swap, you don't have a problem, but you probably don't need swap space to begin with. However, if you want to lean on swap space heavily and create a Python program that operates on 100 GB of memory, garbage collections are going to create quite a rewrite load on the disk. Marko From bc at freeuk.com Fri Apr 14 06:05:18 2017 From: bc at freeuk.com (bartc) Date: Fri, 14 Apr 2017 11:05:18 +0100 Subject: "Goto" statement in Python In-Reply-To: <58f0299c$0$1620$c3e8da3$5496439d@news.astraweb.com> References: <58f0299c$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 14/04/2017 02:44, Steve D'Aprano wrote: > On Fri, 14 Apr 2017 12:52 am, bartc wrote: > >> I know this isn't the Python need-for-speed thread, but this is a >> classic example where the lack of one simple feature leads to using >> slower, more cumbersome ones. > > Dear gods, have I fallen back in time to 1975 again? > > The Goto Wars are over, and the structured programming camp won the war > decisively. > > Are functions/procedures *technically* slower than GOTOs? Yes. So what? > You're nano-optimizing the wrong thing: you're saving a microsecond of > runtime at the cost of a megasecond of development and maintenance time. Usually, yes. (And when you run CPython, whatever speed you do get, is partly thanks to compiler writers choosing jumps, or in-lining, over function calls. All those nanoseconds add up.) However my comment wasn't specifically about goto. It's about using a slower feature to get around the lack of another feature that could have been implemented efficiently. >> Function calls, returns and generators are rather more heavyweight in >> comparison. > > And enormously better. It depends if your application is speed-sensitive. Much scripting code isn't, or if it is, most of the work is done outside the language. But sometimes you want your dynamic code to do some actual work of its own that involves executing byte-code, rather than calling some compiled code. And performance can matter. -- bartc From bc at freeuk.com Fri Apr 14 06:42:39 2017 From: bc at freeuk.com (bartc) Date: Fri, 14 Apr 2017 11:42:39 +0100 Subject: Python and the need for speed In-Reply-To: <58f03030$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <58f03030$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 14/04/2017 03:13, Steve D'Aprano wrote: > On Wed, 12 Apr 2017 07:56 pm, bart4858 at gmail.com wrote: > if you care most about program correctness, type-safety and > correctness proofs, choosing C is probably the wrong decision. CPython is written in C; bad choice? >> (** Although I find code full of class definitions, one-liners, decorators >> and all the other esoterics, [incomprehensible]... I'm not the only >> one, so perhaps readability isn't too much of a priority either.) > > Classes and decorators are not esoteric. You sound like an old man who > complains about this new-fangled "telephone", and how things were so much > better when we had messenger boys to deliver messages anywhere in the city. These days I like code to be as simple and obvious as possible. I guess no one's going to complain when it is! > I'm not sure what you consider incomprehensible about "one liners", surely > it depends on what the one liner does. These are pretty clear to me: > > # The archetypal "Hello World!" program is a one-liner. > print("Hello World!") > > # One liner to calculate the sum of the first 50 cubes. > total = sum(i**3 for i in range(50)) Those are fine. I means when lots of things are arranged on one line, where the output of one method feeds into the next. Vertical space is free after all. However, you might argue that having discrete, intermediate steps would be a little slower than one-lining.. -- bartc From rosuav at gmail.com Fri Apr 14 06:56:05 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Apr 2017 20:56:05 +1000 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <58f03030$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 14, 2017 at 8:42 PM, bartc wrote: >> Classes and decorators are not esoteric. You sound like an old man who >> complains about this new-fangled "telephone", and how things were so much >> better when we had messenger boys to deliver messages anywhere in the >> city. > > > These days I like code to be as simple and obvious as possible. I guess no > one's going to complain when it is! Everyone says that, but there's a stark division between two groups of people: 1) Those who think the code should have an obvious concrete meaning - that you should be able to see exactly what bits get flipped in memory 2) Those who think the code should have an obvious abstract meaning - that you should be able to see exactly what the programmer intended. Declarative notations like decorators can beautifully provide the second, even though they might obscure the first. For example: @app.route("/hello/") def greet(name): return f"A very warm hello to you too, {name}!" Nice, clean code that might be found in a Flask application. In concrete terms, there's a lot going on, but in abstract terms it's simple: when this kind of URL is requested, return this formatted string. I'm of the opinion that the concrete meaning is insignificant, and your code should clearly portray its abstract meaning. So classes, decorators, etc, etc, etc are all excellent tools for *improving* readability. Of course, if you feel the other way, you're most welcome to write everything in C. ChrisA From bc at freeuk.com Fri Apr 14 08:04:31 2017 From: bc at freeuk.com (bartc) Date: Fri, 14 Apr 2017 13:04:31 +0100 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <58f03030$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4V2IA.973357$qK5.728302@fx45.am4> On 14/04/2017 11:56, Chris Angelico wrote: > On Fri, Apr 14, 2017 at 8:42 PM, bartc wrote: >>> Classes and decorators are not esoteric. You sound like an old man who >>> complains about this new-fangled "telephone", and how things were so much >>> better when we had messenger boys to deliver messages anywhere in the >>> city. >> >> >> These days I like code to be as simple and obvious as possible. I guess no >> one's going to complain when it is! > > Everyone says that, but there's a stark division between two groups of people: > > 1) Those who think the code should have an obvious concrete meaning - > that you should be able to see exactly what bits get flipped in memory > 2) Those who think the code should have an obvious abstract meaning - > that you should be able to see exactly what the programmer intended. > > Declarative notations like decorators can beautifully provide the > second, even though they might obscure the first. For example: > > @app.route("/hello/") > def greet(name): > return f"A very warm hello to you too, {name}!" > > Nice, clean code that might be found in a Flask application. In > concrete terms, there's a lot going on, but in abstract terms it's > simple: when this kind of URL is requested, return this formatted > string. > > I'm of the opinion that the concrete meaning is insignificant, and > your code should clearly portray its abstract meaning. So classes, > decorators, etc, etc, etc are all excellent tools for *improving* > readability. C++ has classes, templates and so on, all of which can be argued can improve readability (when you eventually find that code that actually does something). But somehow it doesn't really work. Because such features are overused? I don't know. I do know that if I want to port some program (be it in Python or C++), or simply try and understand it, if I see it's full of class definitions or whatever, then I won't bother. > Of course, if you feel the other way, you're most welcome to write > everything in C. 'pseudo-code' is often the language used to describe an algorithm in terms that are independent of any particular language. It doesn't usually contain classes or decorators. -- bartc From rosuav at gmail.com Fri Apr 14 09:04:46 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Apr 2017 23:04:46 +1000 Subject: Python and the need for speed In-Reply-To: <4V2IA.973357$qK5.728302@fx45.am4> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <58f03030$0$1598$c3e8da3$5496439d@news.astraweb.com> <4V2IA.973357$qK5.728302@fx45.am4> Message-ID: On Fri, Apr 14, 2017 at 10:04 PM, bartc wrote: > >> Of course, if you feel the other way, you're most welcome to write >> everything in C. > > > 'pseudo-code' is often the language used to describe an algorithm in terms > that are independent of any particular language. It doesn't usually contain > classes or decorators. Decorators no, classes sometimes. And then you try to transform that pseudocode into executable code as closely as possible, and you need some sort of feature that makes these things functional. For instance, the pseudocode for the example I gave might be: /hello/[name]: return "A very warm hello to you too, [name]!" ChrisA From Bernd.Nawothnig at t-online.de Fri Apr 14 09:22:12 2017 From: Bernd.Nawothnig at t-online.de (Bernd Nawothnig) Date: Fri, 14 Apr 2017 15:22:12 +0200 Subject: Python Command Line Arguments References: Message-ID: <41v6sd-6ve.ln1@bernd.nawothnig.dialin.t-online.de> On 2017-04-13, Jason Friedman wrote: >> I have this code which I got from https://www.tutorialspoint. >> com/python/python_command_line_arguments.htm The example works fine but >> when I modify it to what I need, it only half works. The problem is the >> try/except. If you don't specify an input/output, they are blank at the end >> but it shouldn't be. >> >> import getopt >> import sys > > I am guessing you are wanting to parse command-line arguments rather than > particularly wanting to use the getopt module. > If I am correct you might want to spend your time instead learning the > argparse module: > https://docs.python.org/3/library/argparse.html > https://docs.python.org/3/howto/argparse.html He should switch to argparse in any case because getopt is no longer supported and does only receive bugfixes. Bernd -- Die Antisemiten vergeben es den Juden nicht, dass die Juden ?Geist? haben ? und Geld. Die Antisemiten ? ein Name der ?Schlechtweggekommenenen? [Friedrich Nietzsche] From Bernd.Nawothnig at t-online.de Fri Apr 14 09:30:39 2017 From: Bernd.Nawothnig at t-online.de (Bernd Nawothnig) Date: Fri, 14 Apr 2017 15:30:39 +0200 Subject: "Goto" statement in Python References: Message-ID: On 2017-04-13, Mikhail V wrote: > On 13 April 2017 at 18:48, Ian Kelly wrote: >> On Thu, Apr 13, 2017 at 10:23 AM, Mikhail V wrote: >>> Now I wonder, have we already collected *all* bells and whistles of Python >>> in these two examples, or is there something else for expressing trivial thing. >> >> Functions and exceptions are considered "bells and whistles"? > > You mean probably classes and exceptions? For me, indeed they are, > but it depends. > > And breaking the code into def() chunks that are not > functions but just chunks... I don't know, looks bad. Organising code in a bunch of small functions is by far better coding style and better readable than put it all together in one chunk. And that holds for all programming languages, not only for Python. Bernd -- Die Antisemiten vergeben es den Juden nicht, dass die Juden ?Geist? haben ? und Geld. Die Antisemiten ? ein Name der ?Schlechtweggekommenenen? [Friedrich Nietzsche] From Bernd.Nawothnig at t-online.de Fri Apr 14 09:43:54 2017 From: Bernd.Nawothnig at t-online.de (Bernd Nawothnig) Date: Fri, 14 Apr 2017 15:43:54 +0200 Subject: "Goto" statement in Python References: <44db5cea-8831-4951-baa0-a50d99a79b1c@googlegroups.com> Message-ID: On 2017-04-13, Grant Edwards wrote: > On 2017-04-13, Rob Gaddi wrote: > >> No, C doesn't support exception handling. As a result, handling error >> conditions in C is a huge pain for which (forward-only) goto is often, >> while not the only remedy, the least painful one. > > Indeed. That is almost the only place I use 'goto' in C, and the > almost the only place I see others use it. Very occasionally, you see > a the error handling goto refactored into a backwards "goto retry": > > this code > > foo() > { > while (1) > { > > if () > goto error: > > return; > > error: > > } > } foo() { int done = 0; while (! done) { if () { } else { done = 1; } } Bernd -- Die Antisemiten vergeben es den Juden nicht, dass die Juden ?Geist? haben ? und Geld. Die Antisemiten ? ein Name der ?Schlechtweggekommenenen? [Friedrich Nietzsche] From cl at isbd.net Fri Apr 14 10:00:09 2017 From: cl at isbd.net (Chris Green) Date: Fri, 14 Apr 2017 15:00:09 +0100 Subject: "Goto" statement in Python References: Message-ID: <9817sd-k4m.ln1@esprimo.zbmc.eu> Bernd Nawothnig wrote: > On 2017-04-13, Mikhail V wrote: > > On 13 April 2017 at 18:48, Ian Kelly wrote: > >> On Thu, Apr 13, 2017 at 10:23 AM, Mikhail V wrote: > >>> Now I wonder, have we already collected *all* bells and whistles of Python > >>> in these two examples, or is there something else for expressing trivial thing. > >> > >> Functions and exceptions are considered "bells and whistles"? > > > > You mean probably classes and exceptions? For me, indeed they are, > > but it depends. > > > > And breaking the code into def() chunks that are not > > functions but just chunks... I don't know, looks bad. > > Organising code in a bunch of small functions is by far better coding > style and better readable than put it all together in one chunk. And > that holds for all programming languages, not only for Python. > The functions need *some* reason for being an entity though. -- Chris Green ? From rosuav at gmail.com Fri Apr 14 10:17:18 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 15 Apr 2017 00:17:18 +1000 Subject: "Goto" statement in Python In-Reply-To: References: <42rvech210hf4il6c4h7q5eoli5toiv8mk@4ax.com> <4pTHA.695356$nT1.588759@fx44.am4> Message-ID: On Sat, Apr 15, 2017 at 12:13 AM, Dennis Lee Bieber wrote: > On Thu, 13 Apr 2017 18:36:57 -0600, Ian Kelly > declaimed the following: > >> >>Well, you can do it in Assembly. And BASIC, if you count the primitive >>GOSUB-type subroutines, though modern BASICs have real subroutines >>that don't allow it. >> > REXX probably allows it too... (No GOTO, but the SIGNAL statement can > do unconditional jumps to named labels)... Hmmm, if I read the manual > correctly, any use of SIGNAL will terminate loops, even if the SIGNAL and > target are both within the same loop. This is correct. Annoyingly, it also wipes out indentation in the TRACE output, so you really want to use it *only* for error handling (which is its stated purpose). ChrisA From kasperseidem.gamer at gmail.com Fri Apr 14 10:27:08 2017 From: kasperseidem.gamer at gmail.com (Kasper) Date: Fri, 14 Apr 2017 07:27:08 -0700 (PDT) Subject: Hi! i need some help with a program in python on Raspberry pi3. Message-ID: every time i run the program i get this messeage: Traceback (most recent call last): File "smartmirror.py", line 159, in get_weather temprature2 = "%S%S" % (str(int(weather_obj['currently']['temperature'])), degree_sign) KeyError: 'currently' Error: 'currently'. Cannot get weather. How do i fix that? Here is the program: # smartmirror.py # requirements # requests, feedparser, traceback, Pillow from Tkinter import * import locale import threading import time import requests import json import traceback import feedparser from PIL import Image, ImageTk from contextlib import contextmanager LOCALE_LOCK = threading.Lock() ui_locale = '' # e.g. 'fr_FR' fro French, '' as default time_format = 24 # 12 or 24 date_format = "%b %d, %Y" # check python doc for strftime() for options news_country_code = 'nb' weather_api_token = '16dc67b56f94f8083b1afed7e69c5dc1' # create account at https://darksky.net/dev/ weather_lang = 'nb' # see https://darksky.net/dev/docs/forecast for full list of language parameters values weather_unit = 'nb' # see https://darksky.net/dev/docs/forecast for full list of unit parameters values latitude = (59.1311800) # Set this if IP location lookup does not work for you (must be a string) longitude = (10.2166500) # Set this if IP location lookup does not work for you (must be a string) xlarge_text_size = 94 large_text_size = 48 medium_text_size = 28 small_text_size = 18 @contextmanager def setlocale(name): #thread proof function to work with locale with LOCALE_LOCK: saved = locale.setlocale(locale.LC_ALL) try: yield locale.setlocale(locale.LC_ALL, name) finally: locale.setlocale(locale.LC_ALL, saved) # maps open weather icons to # icon reading is not impacted by the 'lang' parameter icon_lookup = { 'clear-day': "assets/Sun.png", # clear sky day 'wind': "assets/Wind.png", #wind 'cloudy': "assets/Cloud.png", # cloudy day 'partly-cloudy-day': "assets/PartlySunny.png", # partly cloudy day 'rain': "assets/Rain.png", # rain day 'snow': "assets/Snow.png", # snow day 'snow-thin': "assets/Snow.png", # sleet day 'fog': "assets/Haze.png", # fog day 'clear-night': "assets/Moon.png", # clear sky night 'partly-cloudy-night': "assets/PartlyMoon.png", # scattered clouds night 'thunderstorm': "assets/Storm.png", # thunderstorm 'tornado': "assests/Tornado.png", # tornado 'hail': "assests/Hail.png" # hail } class Clock(Frame): def __init__(self, parent, *args, **kwargs): Frame.__init__(self, parent, bg='black') # initialize time label self.time1 = '' self.timeLbl = Label(self, font=('Helvetica', large_text_size), fg="white", bg="black") self.timeLbl.pack(side=TOP, anchor=E) # initialize day of week self.day_of_week1 = '' self.dayOWLbl = Label(self, text=self.day_of_week1, font=('Helvetica', small_text_size), fg="white", bg="black") self.dayOWLbl.pack(side=TOP, anchor=E) # initialize date label self.date1 = '' self.dateLbl = Label(self, text=self.date1, font=('Helvetica', small_text_size), fg="white", bg="black") self.dateLbl.pack(side=TOP, anchor=E) self.tick() def tick(self): with setlocale(ui_locale): if time_format == 12: time2 = time.strftime('%I:%M %p') #hour in 12h format else: time2 = time.strftime('%H:%M') #hour in 24h format day_of_week2 = time.strftime('%A') date2 = time.strftime(date_format) # if time string has changed, update it if time2 != self.time1: self.time1 = time2 self.timeLbl.config(text=time2) if day_of_week2 != self.day_of_week1: self.day_of_week1 = day_of_week2 self.dayOWLbl.config(text=day_of_week2) if date2 != self.date1: self.date1 = date2 self.dateLbl.config(text=date2) # calls itself every 200 milliseconds # to update the time display as needed # could use >200 ms, but display gets jerky self.timeLbl.after(200, self.tick) class Weather(Frame): def __init__(self, parent, *args, **kwargs): Frame.__init__(self, parent, bg='black') self.temperature = '' self.forecast = '' self.location = '' self.currently = '' self.icon = '' self.degreeFrm = Frame(self, bg="black") self.degreeFrm.pack(side=TOP, anchor=W) self.temperatureLbl = Label(self.degreeFrm, font=('Helvetica', xlarge_text_size), fg="white", bg="black") self.temperatureLbl.pack(side=LEFT, anchor=N) self.iconLbl = Label(self.degreeFrm, bg="black") self.iconLbl.pack(side=LEFT, anchor=N, padx=20) self.currentlyLbl = Label(self, font=('Helvetica', medium_text_size), fg="white", bg="black") self.currentlyLbl.pack(side=TOP, anchor=W) self.forecastLbl = Label(self, font=('Helvetica', small_text_size), fg="white", bg="black") self.forecastLbl.pack(side=TOP, anchor=W) self.locationLbl = Label(self, font=('Helvetica', small_text_size), fg="white", bg="black") self.locationLbl.pack(side=TOP, anchor=W) self.get_weather() def get_ip(self): try: ip_url = "http://jsonip.com/" req = requests.get(ip_url) ip_json = json.loads(req.text) return ip_json['ip'] except Exception as e: traceback.print_exc() return "Error: %s. Cannot get ip." % e def get_weather(self): try: if latitude is None and longitude is None: # get location location_req_url = "http://freegeoip.net/json/%s" % self.get_ip() r = requests.get(location_req_url) location_obj = json.loads(r.text) lat = location_obj['latitude'] lon = location_obj['longitude'] location2 = "%s, %s" % (location_obj['city'], location_obj['region_code']) # get weather weather_req_url = "https://api.darksky.net/forecast/%s/%s,%s?lang=%s&units=%s" % (weather_api_token, lat,lon,weather_lang,weather_unit) else: location2 = "" # get weather weather_req_url = "https://api.darksky.net/forecast/%s/%s,%s?lang=%s&units=%s" % (weather_api_token, latitude, longitude, weather_lang, weather_unit) r = requests.get(weather_req_url) weather_obj = json.loads(r.text) degree_sign= u'\N{DEGREE SIGN}' temperature2 = "%s%s" % (str(int(weather_obj['currently']['temperature'])), degree_sign) currently2 = weather_obj['currently']['summary'] forecast2 = weather_obj["hourly"]["summary"] icon_id = weather_obj['currently']['icon'] icon2 = None if icon_id in icon_lookup: icon2 = icon_lookup[icon_id] if icon2 is not None: if self.icon != icon2: self.icon = icon2 image = Image.open(icon2) image = image.resize((100, 100), Image.ANTIALIAS) image = image.convert('RGB') photo = ImageTk.PhotoImage(image) self.iconLbl.config(image=photo) self.iconLbl.image = photo else: # remove image self.iconLbl.config(image='') if self.currently != currently2: self.currently = currently2 self.currentlyLbl.config(text=currently2) if self.forecast != forecast2: self.forecast = forecast2 self.forecastLbl.config(text=forecast2) if self.temperature != temperature2: self.temperature = temperature2 self.temperatureLbl.config(text=temperature2) if self.location != location2: if location2 == ", ": self.location = "Cannot Pinpoint Location" self.locationLbl.config(text="Cannot Pinpoint Location") else: self.location = location2 self.locationLbl.config(text=location2) except Exception as e: traceback.print_exc() print ("Error: %s. Cannot get weather.") % e self.after(600000, self.get_weather) @staticmethod def convert_kelvin_to_fahrenheit(kelvin_temp): return 1.8 * (kelvin_temp - 273) + 32 class News(Frame): def __init__(self, parent, *args, **kwargs): Frame.__init__(self, parent, *args, **kwargs) self.config(bg='black') self.title = 'News' # 'News' is more internationally generic self.newsLbl = Label(self, text=self.title, font=('Helvetica', medium_text_size), fg="white", bg="black") self.newsLbl.pack(side=TOP, anchor=W) self.headlinesContainer = Frame(self, bg="black") self.headlinesContainer.pack(side=TOP) self.get_headlines() def get_headlines(self): try: # remove all children for widget in self.headlinesContainer.winfo_children(): widget.destroy() if news_country_code == None: headlines_url = "https://news.google.com/news?ned=us&output=rss" else: headlines_url = "https://news.google.com/news?ned=%s&output=rss" % news_country_code feed = feedparser.parse(headlines_url) for post in feed.entries[0:5]: headline = NewsHeadline(self.headlinesContainer, post.title) headline.pack(side=TOP, anchor=W) except Exception as e: traceback.print_exc() print ("Error: %s. Cannot get news.") % e self.after(600000, self.get_headlines) class NewsHeadline(Frame): def __init__(self, parent, event_name=""): Frame.__init__(self, parent, bg='black') image = Image.open("assets/Newspaper.png") image = image.resize((25, 25), Image.ANTIALIAS) image = image.convert('RGB') photo = ImageTk.PhotoImage(image) self.iconLbl = Label(self, bg='black', image=photo) self.iconLbl.image = photo self.iconLbl.pack(side=LEFT, anchor=N) self.eventName = event_name self.eventNameLbl = Label(self, text=self.eventName, font=('Helvetica', small_text_size), fg="white", bg="black") self.eventNameLbl.pack(side=LEFT, anchor=N) class Calendar(Frame): def __init__(self, parent, *args, **kwargs): Frame.__init__(self, parent, bg='black') self.title = 'Calendar Events' self.calendarLbl = Label(self, text=self.title, font=('Helvetica', medium_text_size), fg="white", bg="black") self.calendarLbl.pack(side=TOP, anchor=E) self.calendarEventContainer = Frame(self, bg='black') self.calendarEventContainer.pack(side=TOP, anchor=E) self.get_events() def get_events(self): #TODO: implement this method # reference https://developers.google.com/google-apps/calendar/quickstart/python # remove all children for widget in self.calendarEventContainer.winfo_children(): widget.destroy() calendar_event = CalendarEvent(self.calendarEventContainer) calendar_event.pack(side=TOP, anchor=E) pass class CalendarEvent(Frame): def __init__(self, parent, event_name="Event 1"): Frame.__init__(self, parent, bg='black') self.eventName = event_name self.eventNameLbl = Label(self, text=self.eventName, font=('Helvetica', small_text_size), fg="white", bg="black") self.eventNameLbl.pack(side=TOP, anchor=E) class FullscreenWindow: def __init__(self): self.tk = Tk() self.tk.configure(background='black') self.topFrame = Frame(self.tk, background = 'black') self.bottomFrame = Frame(self.tk, background = 'black') self.topFrame.pack(side = TOP, fill=BOTH, expand = YES) self.bottomFrame.pack(side = BOTTOM, fill=BOTH, expand = YES) self.state = False self.tk.bind("", self.toggle_fullscreen) self.tk.bind("", self.end_fullscreen) # clock self.clock = Clock(self.topFrame) self.clock.pack(side=RIGHT, anchor=N, padx=100, pady=60) # weather self.weather = Weather(self.topFrame) self.weather.pack(side=LEFT, anchor=N, padx=100, pady=60) # news self.news = News(self.bottomFrame) self.news.pack(side=LEFT, anchor=S, padx=100, pady=60) # calender - removing for now # self.calender = Calendar(self.bottomFrame) # self.calender.pack(side = RIGHT, anchor=S, padx=100, pady=60) def toggle_fullscreen(self, event=None): self.state = not self.state # Just toggling the boolean self.tk.attributes("-fullscreen", self.state) return "break" def end_fullscreen(self, event=None): self.state = False self.tk.attributes("-fullscreen", False) return "break" if __name__ == '__main__': w = FullscreenWindow() w.tk.mainloop() From steve+python at pearwood.info Fri Apr 14 10:38:22 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 15 Apr 2017 00:38:22 +1000 Subject: Hi! i need some help with a program in python on Raspberry pi3. References: Message-ID: <58f0dedf$0$1620$c3e8da3$5496439d@news.astraweb.com> On Sat, 15 Apr 2017 12:27 am, Kasper wrote: > every time i run the program i get this messeage: > > Traceback (most recent call last): > File "smartmirror.py", line 159, in get_weather > temprature2 = "%S%S" % > (str(int(weather_obj['currently']['temperature'])), > degree_sign) > KeyError: 'currently' > Error: 'currently'. Cannot get weather. > > How do i fix that? We're unpaid volunteers, we're not being paid to debug your code. Don't dump over 300 lines of code in our lap and expect us to debug it. If you can't spend the time simplifying the problem and removing all the irrelevant details, how can you expect us to do it for you? If you want help, make it easy for people to help you. Cut your code down to the simplest, shortest amount of code that demonstrates the problem. If your code has nothing to do with the GUI, cut out all the GUI code. More advice here: http://sscce.org/ -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From breamoreboy at gmail.com Fri Apr 14 10:57:00 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Fri, 14 Apr 2017 07:57:00 -0700 (PDT) Subject: Hi! i need some help with a program in python on Raspberry pi3. In-Reply-To: References: Message-ID: On Friday, April 14, 2017 at 3:27:29 PM UTC+1, Kasper wrote: > every time i run the program i get this messeage: > > Traceback (most recent call last): > File "smartmirror.py", line 159, in get_weather > temprature2 = "%S%S" % (str(int(weather_obj['currently']['temperature'])), > degree_sign) > KeyError: 'currently' > Error: 'currently'. Cannot get weather. > > How do i fix that? > > Here is the program: > > r = requests.get(weather_req_url) > weather_obj = json.loads(r.text) > > degree_sign= u'\N{DEGREE SIGN}' > temperature2 = "%s%s" % (str(int(weather_obj['currently']['temperature'])), degree_sign) Find the correct name for the key by printing out `weather_obj`. At least I think so, as the line above does not match the line that you've given. Kindest regards. Mark Lawrence. From breamoreboy at gmail.com Fri Apr 14 11:03:55 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Fri, 14 Apr 2017 08:03:55 -0700 (PDT) Subject: Python Command Line Arguments In-Reply-To: <41v6sd-6ve.ln1@bernd.nawothnig.dialin.t-online.de> References: <41v6sd-6ve.ln1@bernd.nawothnig.dialin.t-online.de> Message-ID: <0fe093c6-fa0a-45d2-961f-ecebea5ebbf6@googlegroups.com> On Friday, April 14, 2017 at 2:44:09 PM UTC+1, Bernd Nawothnig wrote: > On 2017-04-13, Jason Friedman wrote: > >> I have this code which I got from https://www.tutorialspoint. > >> com/python/python_command_line_arguments.htm The example works fine but > >> when I modify it to what I need, it only half works. The problem is the > >> try/except. If you don't specify an input/output, they are blank at the end > >> but it shouldn't be. > >> > >> import getopt > >> import sys > > > > I am guessing you are wanting to parse command-line arguments rather than > > particularly wanting to use the getopt module. > > If I am correct you might want to spend your time instead learning the > > argparse module: > > https://docs.python.org/3/library/argparse.html > > https://docs.python.org/3/howto/argparse.html > > He should switch to argparse in any case because getopt is no longer > supported and does only receive bugfixes. > > Bernd > > -- > Die Antisemiten vergeben es den Juden nicht, dass die Juden ?Geist? > haben ? und Geld. Die Antisemiten ? ein Name der > ?Schlechtweggekommenenen? [Friedrich Nietzsche] optparse is deprecated, not getopt. Kindest regards. Mark Lawrence. From malik.a.rumi at gmail.com Fri Apr 14 11:12:00 2017 From: malik.a.rumi at gmail.com (Malik Rumi) Date: Fri, 14 Apr 2017 08:12:00 -0700 (PDT) Subject: Regular Expressions, Speed, Python, and NFA Message-ID: <0e334222-676b-4a7b-91c2-1345592cced5@googlegroups.com> I am running some tests using the site regex101 to figure out the correct regexs to use for a project. I was surprised at how slow it was, constantly needing to increase the timeouts. I went Googling for a reason, and solution, and found Russ Cox?s article from 2007: https://swtch.com/~rsc/regexp/regexp1.html . I couldn?t understand why, if this was even remotely correct, we don?t use NFA in Python, which led me here: https://groups.google.com/forum/#!msg/comp.lang.python/L1ZFI_R2hAo/C12Nf3patWIJ;context-place=forum/comp.lang.python where all of these issues were addressed. Unfortunately, this is also from 2007. BTW, John Machin in one of his replies cites Navarro?s paper, but that link is broken. Navarro?s work can now be found at http://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.21.3112&rep=rep1&type=pdf But be forewarned, it is 68 pages of dense reading. I am not a computer science major. I am not new to Python, but I don?t think I?m qualified to take on the idea of creating a new NFA module for Python. >Getting back to the "It would be nice ..." bit: yes, it would be nice >to have even more smarts in re, but who's going to do it? It's not a >"rainy Sunday afternoon" job :-) >Cheers, >John - >Well, just as an idea, there is a portable C library for this at? >http://laurikari.net/tre/?released under LGPL. ?If one is willing to? >give up PCRE extensions for speed, it might be worth the work to? >wrap this library using SWIG. >Kirk Sluder (BTW, this link is also old. TRE is now at https://github.com/laurikari/tre/ ) I am not a computer science major. I am not new to Python, but I don?t think I?m qualified to take on the idea of creating a new NFA module for Python. Nor am I entirely sure I want to try something new (to me) like TRE. Most threads related to this topic are older than 2007. I did find this https://groups.google.com/forum/#!searchin/comp.lang.python/regex$20speed%7Csort:relevance/comp.lang.python/O7rUwVoD2t0/NYAQM0mUX7sJ from 2011 but I did not do an exhaustive search. The bottom line is I wanted to know if anything has changed since 2007, and if there is a) any hope for improving regex speeds in Python, or b) some 3rd party module/library that is already out there and solves this problem? Or should I just take this advice? >The cheap way in terms of programmer time is to pipe out to grep or >awk on this one. >Kirk Sluder Thanks. From steve+python at pearwood.info Fri Apr 14 12:17:35 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 15 Apr 2017 02:17:35 +1000 Subject: Regular Expressions, Speed, Python, and NFA References: <0e334222-676b-4a7b-91c2-1345592cced5@googlegroups.com> Message-ID: <58f0f621$0$1620$c3e8da3$5496439d@news.astraweb.com> On Sat, 15 Apr 2017 01:12 am, Malik Rumi wrote: > I couldn?t understand why, if this was even remotely correct, > we don?t use NFA in Python [...] > I don?t think I?m qualified to take on the idea of creating > a new NFA module for Python. If not you, then who should do it? Python is open source and written by volunteers. If you want something done, there are only four possibilities: - you do it yourself; - you wait as long as it takes for somebody else to do it; - you pay somebody to do it; - or it doesn't get done. If you're not willing or able to do the work yourself, does that help you understand why we don't use NFA? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jcasale at activenetwerx.com Fri Apr 14 12:21:45 2017 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Fri, 14 Apr 2017 16:21:45 +0000 Subject: Regular Expressions, Speed, Python, and NFA In-Reply-To: <0e334222-676b-4a7b-91c2-1345592cced5@googlegroups.com> References: <0e334222-676b-4a7b-91c2-1345592cced5@googlegroups.com> Message-ID: <5171a0c5133244ada3d6847d2da1322b@activenetwerx.com> -----Original Message----- From: Python-list [mailto:python-list- bounces+jcasale=activenetwerx.com at python.org] On Behalf Of Malik Rumi Sent: Friday, April 14, 2017 9:12 AM To: python-list at python.org Subject: Regular Expressions, Speed, Python, and NFA > I am running some tests using the site regex101 to figure out the correct > regexs to use for a project. I was surprised at how slow it was, constantly > needing to increase the timeouts. I went Googling for a reason, and solution, > and found Russ Cox?s article from 2007: > https://swtch.com/~rsc/regexp/regexp1.html . I couldn?t understand why, if > this was even remotely correct, we don?t use NFA in Python, which led me > here: Do you have any sample data you can share? From __peter__ at web.de Fri Apr 14 12:22:44 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 14 Apr 2017 18:22:44 +0200 Subject: Hi! i need some help with a program in python on Raspberry pi3. References: Message-ID: Kasper wrote: > every time i run the program i get this messeage: > > Traceback (most recent call last): > File "smartmirror.py", line 159, in get_weather > temprature2 = "%S%S" % (str(int(weather_obj['currently'] ['temperature'])), > degree_sign) > KeyError: 'currently' > Error: 'currently'. Cannot get weather. > > How do i fix that? > > Here is the program: > > weather_api_token = '16dc67b56f94f8083b1afed7e69c5dc1' # create account at > https://darksky.net/dev/ Oops, is that your personal token? You are probably not supposed to publish it and now run the risk of having it revoked. > values weather_unit = 'nb' # see https://darksky.net/dev/docs/forecast for > full list of unit parameters values You have to replace nb with one of the allowed values listed on the site. > weather_lang = 'nb' # see > https://darksky.net/dev/docs/forecast for full list of language parameters Again, you have to pick one of the values listed -- unless you want Norsk bokm?l that is. From __peter__ at web.de Fri Apr 14 12:39:25 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 14 Apr 2017 18:39:25 +0200 Subject: Regular Expressions, Speed, Python, and NFA References: <0e334222-676b-4a7b-91c2-1345592cced5@googlegroups.com> Message-ID: Malik Rumi wrote: > I am running some tests using the site regex101 to figure out the correct > regexs to use for a project. I was surprised at how slow it was, > constantly needing to increase the timeouts. I went Googling for a reason, > and solution, and found Russ Cox?s article from 2007: > https://swtch.com/~rsc/regexp/regexp1.html . I couldn?t understand why, if > this was even remotely correct, we don?t use NFA in Python, which led me > here: You might try https://en.wikipedia.org/wiki/RE2_(software) for which Python wrappers are available. However, "RE2 does not support back-references, which cannot be implemented efficiently." From rgaddi at highlandtechnology.invalid Fri Apr 14 13:07:41 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 14 Apr 2017 10:07:41 -0700 Subject: "Goto" statement in Python In-Reply-To: References: <58f0299c$0$1620$c3e8da3$5496439d@news.astraweb.com> <6cm1fc1k3i9bk9isv1i541t2i7f5euvsf7@4ax.com> Message-ID: On 04/14/2017 07:19 AM, Dennis Lee Bieber wrote: > On Fri, 14 Apr 2017 11:44:59 +1000, Steve D'Aprano > declaimed the following: > >> >> Even that's not enough for some. Donald Knuth, who supports the use of GOTO >> under some circumstances, maintains that any program using GOTOs should >> have the invariant that its flow chart can be drawn with all forward >> branches on the left, all backward branches on the right, and no branches >> crossing each other. >> > > Good thing I never had him for an instructor... My practice, when last > flow-charting, favored back-branches on the left. > > After all, I read left-to-right/top-to-bottom, so forward branches > going right and down seem natural. Encountering a branch going left sort of > implies "re-reading" part of the chart; going upwards... > Yeah, but I love the naked concept there. It pretty much encapsulates what I find to be the only useful use of GOTO in any reasonable language in a simple, easy to visualize way. If your GOTOs are crossing you've done something wrong. If more people had good mechanisms for visualizing their code I'd use far less profanity literally every day of my life. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From rgaddi at highlandtechnology.invalid Fri Apr 14 13:21:33 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 14 Apr 2017 10:21:33 -0700 Subject: Regular Expressions, Speed, Python, and NFA In-Reply-To: <0e334222-676b-4a7b-91c2-1345592cced5@googlegroups.com> References: <0e334222-676b-4a7b-91c2-1345592cced5@googlegroups.com> Message-ID: On 04/14/2017 08:12 AM, Malik Rumi wrote: > I am running some tests using the site regex101 to figure out the correct regexs to use for a project. I was surprised at how slow it was, constantly needing to increase the timeouts. I went Googling for a reason, and solution, and found Russ Cox?s article from 2007: https://swtch.com/~rsc/regexp/regexp1.html . I couldn?t understand why, if this was even remotely correct, we don?t use NFA in Python, which led me here: > > https://groups.google.com/forum/#!msg/comp.lang.python/L1ZFI_R2hAo/C12Nf3patWIJ;context-place=forum/comp.lang.python where all of these issues were addressed. Unfortunately, this is also from 2007. > > BTW, John Machin in one of his replies cites Navarro?s paper, but that link is broken. Navarro?s work can now be found at http://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.21.3112&rep=rep1&type=pdf But be forewarned, it is 68 pages of dense reading. I am not a computer science major. I am not new to Python, but I don?t think I?m qualified to take on the idea of creating a new NFA module for Python. > >> Getting back to the "It would be nice ..." bit: yes, it would be nice >> to have even more smarts in re, but who's going to do it? It's not a >> "rainy Sunday afternoon" job :-) >> Cheers, >> John > - >> Well, just as an idea, there is a portable C library for this at >> http://laurikari.net/tre/ released under LGPL. If one is willing to >> give up PCRE extensions for speed, it might be worth the work to >> wrap this library using SWIG. >> Kirk Sluder > > (BTW, this link is also old. TRE is now at https://github.com/laurikari/tre/ ) > > I am not a computer science major. I am not new to Python, but I don?t think I?m qualified to take on the idea of creating a new NFA module for Python. Nor am I entirely sure I want to try something new (to me) like TRE. > > Most threads related to this topic are older than 2007. I did find this https://groups.google.com/forum/#!searchin/comp.lang.python/regex$20speed%7Csort:relevance/comp.lang.python/O7rUwVoD2t0/NYAQM0mUX7sJ from 2011 but I did not do an exhaustive search. > > The bottom line is I wanted to know if anything has changed since 2007, and if there is a) any hope for improving regex speeds in Python, or b) some 3rd party module/library that is already out there and solves this problem? Or should I just take this advice? > >> The cheap way in terms of programmer time is to pipe out to grep or >> awk on this one. >> Kirk Sluder > > Thanks. > I'll also throw in the obligatory quote from Jamie Zawinsky, "Some people, when confronted with a problem, think 'I know, I'll use regular expressions.' Now they have two problems." It's not that regexes are the wrong tool for any job; I personally use them all the time. But they're, tautologically, the wrong tool for any job that can be done better with a different one. In Python, you've got "in", .startswith, .endswith, and .split to handle simple parsing tasks. On the other end, you've got lxml and the like to handle complex tasks that provably cannot be done with regexes at all, let alone efficiently. This leaves them in a fairly bounded middle ground, where is my task so complex that it warrants something as difficult to read as a regex, but still simple enough to be solved by one. And that ground is definitely occupied. But not vast. So is it worth the time to try to write a more efficient regex parser for Python? Yours if you want it to be, but not mine. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From rurpy at yahoo.com Fri Apr 14 14:21:50 2017 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 14 Apr 2017 11:21:50 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: <58f03030$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <58f03030$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7117f7a7-0ee7-4e05-84b4-5dc3d9688348@googlegroups.com> On 04/13/2017 08:13 PM, Steve D'Aprano wrote: > On Wed, 12 Apr 2017 07:56 pm, bart4858 at gmail.com wrote: > [...] >> (** Although I find code full of class definitions, one-liners, decorators >> and all the other esoterics, incomprehensive. I'm sure I'm not the only >> one, so perhaps readability isn't too much of a priority either.) > > [...] You sound like an old man who > complains about this new-fangled "telephone", and how things were so much > better when we had messenger boys to deliver messages anywhere in the city. This is the second time in two weeks that I have seen an offensive stereotype presented in this list. Last time it was "ugly americans". For those (who've been living under a rock) that are unaware, the stereotype of the "old person" who can't understand or adapt to new technology is a very vile one that many believe is in large part responsible for the high unemployment rate of over-50's in the US, along with their positions near the tops of lay-off lists. This form of bigotry is called "ageism". There are plenty of ways to use the english language to make your point (that people often prefer that which they're familiar with) without employing hateful stereotypes directed at a specific groups of people. Given that this is the second time in two weeks, I publicly ask the list moderators to invoke whatever procedures they use to deal with bigotry on this list. From tjreedy at udel.edu Fri Apr 14 14:45:29 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 14 Apr 2017 14:45:29 -0400 Subject: Hi! i need some help with a program in python on Raspberry pi3. In-Reply-To: References: Message-ID: On 4/14/2017 10:27 AM, Kasper wrote: > every time i run the program i get this messeage: > > Traceback (most recent call last): > File "smartmirror.py", line 159, in get_weather > temprature2 = "%S%S" % (str(int(weather_obj['currently']['temperature'])), > degree_sign) > KeyError: 'currently' > Error: 'currently'. Cannot get weather. > > How do i fix that? Use a valid key for weather_obj. Check doc or add print(list(weather_obj.keys())) before the failing subscription. > Here is the program: I second Steve's comment. -- Terry Jan Reedy From barry at barrys-emacs.org Fri Apr 14 15:33:59 2017 From: barry at barrys-emacs.org (Barry Scott) Date: Fri, 14 Apr 2017 20:33:59 +0100 Subject: Python3 C extension how to support dir() Message-ID: <2199850.VDM6Ou3jKE@varric.chelsea.private> I have an python3 C++ extension that works. But dir(obj) does not return the list of member variables. How should I support dir() from the C API? I cannot use tp_members, not appropiate to the code I'm writing. If I provide __dir__ I then hit the problem I need the C API version all_attr = super( mytype, obj ).__dir__(); all_attr.extend( mytype_variable_names ); I'm not getting inspiration from the python 3.6 sources for this problem. I did find the object_dir function in typeobject.c, but that has not helped get me forward. What am I missing? Barry From python at deborahswanson.net Fri Apr 14 15:34:52 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Fri, 14 Apr 2017 12:34:52 -0700 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: Message-ID: <004601d2b556$308b82f0$27b23dae@sambora> Peter, Retracing my steps to rewrite the getattr(row, label) code, this is what sent me down the rabbit hole in the first place. (I changed your 'rows' to 'records' just to use the same name everywhere, but all else is the same as you gave me.) I'd like you to look at it and see if you still think complete(group, label) should work. Perhaps seeing why it fails will clarify some of the difficulties I'm having. I ran into problems with values and has_empty. values has a problem because row[label] gets a TypeError. has_empty has a problem because a list of field values will be shorter with missing values than a full list, but a namedtuple with missing values will be the same length as a full namedtuple since missing values have '' placeholders. Two more unexpected inconveniences. A short test csv is at the end, for you to read in and attempt to execute the following code, and I'm still working on reconstructing the lost getattr(row, label) code. import csv from collections import namedtuple, defaultdict def get_title(row): return row.title def complete(group, label): values = {row[label] for row in group} # get "TypeError: tuple indices must be integers, not str" has_empty = not min(values, key=len) if len(values) - has_empty != 1: # no value or multiple values; manual intervention needed return False elif has_empty: for row in group: row[label] = max(values, key=len) return True infile = open("E:\\Coding projects\\Pycharm\\Moving\\Moving 2017 in - test.csv") rows = csv.reader(infile) fieldnames = next(rows) Record = namedtuple("Record", fieldnames) records = [Record._make(fieldnames)] records.extend(Record._make(row) for row in rows) # group rows by title groups = defaultdict(list) for row in records: groups[get_title(row)].append(row) LABELS = ['Location', 'Kind', 'Notes'] # add missing values for group in groups.values(): for label in LABELS: complete(group, label) Moving 2017 in - test.csv: (If this doesn't come through the mail system correctly, I've also uploaded the file to http://deborahswanson.net/python/Moving%202017%20in%20-%20test.csv. Permissions should be set correctly, but let me know if you run into problems downloading the file.) CLDesc,url,title,Description,Location,ST,co,miles,Kind,Rent,Date,first,b r,Notes,yesno,mark,arc Jan 3 1 bedroom/1 bath mobile $700 1br - (Mount Vernon),http://skagit.craigslist.org/apa/5943737902.html,1 bedroom/1 bath mobile $700 1br - (Mount Vernon) - (Mount Vernon),1 bedroom/1 bath mobile $700 1br,Mount Vernon,WA,sk,,trailer,700,1/3/2017,1/3/2017,1,no smoking,,,deleted by its author Jan 6 1 bedroom/1 bath mobile $700 1br - (Mount Vernon),http://skagit.craigslist.org/apa/5943737902.html,1 bedroom/1 bath mobile $700 1br - (Mount Vernon) - (Mount Vernon),1 bedroom/1 bath mobile $700 1br,,WA,,,trailer,700,1/6/2017,1/3/2017,1,no smoking,,, Jan 10 1 bedroom/1 bath mobile $700 1br - (Mount Vernon),http://skagit.craigslist.org/apa/5943737902.html,1 bedroom/1 bath mobile $700 1br - (Mount Vernon) - (Mount Vernon),1 bedroom/1 bath mobile $700 1br,,,,,,700,1/10/2017,1/3/2017,1,,,, Jan 17 1 bedroom/1 bath mobile $700 1br - (Mount Vernon),http://skagit.craigslist.org/apa/5943737902.html,1 bedroom/1 bath mobile $700 1br - (Mount Vernon) - (Mount Vernon),1 bedroom/1 bath mobile $700 1br,Mount Vernon,WA,,,trailer,700,1/17/2017,1/3/2017,1,no smoking,,, Jan 19 1 bedroom/1 bath mobile $700 1br - (Mount Vernon),http://skagit.craigslist.org/apa/5943737902.html,1 bedroom/1 bath mobile $700 1br - (Mount Vernon) - (Mount Vernon),1 bedroom/1 bath mobile $700 1br,Mount Vernon,WA,,,trailer,700,1/19/2017,1/3/2017,1,no smoking,,, Jan 26 1240 8th Avenue $725 2br - 676ft2 - (Longview),http://portland.craigslist.org/clk/apa/5976442500.html,1240 8th Avenue $725 2br - 676ft2 - (Longview),1240 8th Avenue $725 2br - 676ft2,,,,,,725,1/26/2017,1/16/2017,2,,,, Jan 16 1240 8th Avenue $725 2br - 676ft2 - (Longview),http://portland.craigslist.org/clk/apa/5961794305.html,1240 8th Avenue $725 2br - 676ft2 - (Longview) - (Longview),1240 8th Avenue $725 2br - 676ft2,Longview,WA,,,house,725,1/16/2017,1/16/2017,2,"detached garage, w/d hookups",,, Jan 6 1424 California Avenue $750 2br - 1113ft2 - (Klamath Falls),http://klamath.craigslist.org/apa/5947977083.html,1424 California Avenue $750 2br - 1113ft2 - (Klamath Falls) - (Klamath Falls),1424 California Avenue $750 2br - 1113ft2,Klamath Falls,OR,kl,,house,750,1/6/2017,1/6/2017,2,no smoking,,, Jan 11 1424 California Avenue $750 2br - 1113ft2 - (Klamath Falls),http://klamath.craigslist.org/apa/5947977083.html,1424 California Avenue $750 2br - 1113ft2 - (Klamath Falls) - (Klamath Falls),1424 California Avenue $750 2br - 1113ft2,,OR,kl,,house,750,1/11/2017,1/6/2017,2,no smoking,,, "Jan 3 1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2 - (1838 Alma Drive Kelso, WA)",http://portland.craigslist.org/clk/apa/5937961608.html,"1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2","1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2",Kelso,WA,ck,,house,550,1/3/2017,12/29/2016,1,no smoking,,, "Jan 5 1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2 - (1838 Alma Drive Kelso, WA",http://portland.craigslist.org/clk/apa/5937961608.html,"1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2","1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2",,,,,,550,1/5/2017,12/29/2016,1,,,, "Jan 9 1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2 - (1838 Alma Drive Kelso, WA)",http://portland.craigslist.org/clk/apa/5937961608.html,"1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2","1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2",,,,house,550,1/9/2017,12/29/2016,1,no smoking,,,, "Jan 12 1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2 - (1838 Alma Drive Kelso, WA)",http://portland.craigslist.org/clk/apa/5937961608.html,"1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2","1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2",Kelso,WA,,,house,550,1/12/2017,12/29/2016,1,no smoking,,, "Jan 17 1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2 - (1838 Alma Drive Kelso, WA) pic map",http://portland.craigslist.org/clk/apa/5937961608.html,"1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2","1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2",Kelso,WA,,,house,550,1/17/2017,12/29/2016,1,no smoking,,, "Jan 19 1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2 - (1838 Alma Drive Kelso, WA) pic map",http://portland.craigslist.org/clk/apa/5937961608.html,"1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2","1838 Alma Drive Kelso, WA 98626 $550 1br - 600ft2",,,,house,550,1/19/2017,12/29/2016,1,no smoking,,,, Jan 9 1907 Olympic Hwy N #22 - Shelton Home for Rent $750 2br - (Shelton),http://seattle.craigslist.org/oly/apa/5916473104.html,1907 Olymwy N #22 - Shelton Home for Rent $750 2br,1907 Olymwy N #22 - Shelton Home for Rent $750 2br,,,,mfgd,750,1/9/2017,12/5/2016,2,carport and storage shed,,,, Jan 16 1907 Olympic Hwy N #22 - Shelton Home for Rent $750 2br - (Shelton) pic map ,http://seattle.craigslist.org/oly/apa/5961587289.html,1907 Olymwy N #22 - Shelton Home for Rent $750 2br,1907 Olymwy N #22 - Shelton Home for Rent $750 2br,Shelton,WA,ma,,mfgd,750,1/16/2017,12/5/2016,2,carport and storage shed,,, From marko at pacujo.net Fri Apr 14 16:10:52 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 14 Apr 2017 23:10:52 +0300 Subject: Goto Considered Harmful [was Re: Python and the need for speed] References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58efb8de$0$1618$c3e8da3$5496439d@news.astraweb.com> <3fbbdbde-107c-4ebb-b608-fd370c0ce72f@googlegroups.com> <58f026d9$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: <877f2myckz.fsf@elektro.pacujo.net> ram at zedat.fu-berlin.de (Stefan Ram): > struct example > { PIC<5,X<15>> last_name; > PIC<88,VALUE<1,3,5,7,9>> odd_numbers; } > > . The above assumes appropriate definitions for ?VALUE? (as a > variadic template) ?PIC?, and ?X?. Only a C++ expert would be able > to provide these definitions, but then they could be used by average > C++ programmers. I don't like your expert/average dichotomy. Similar dichotomies plague other frameworks: Eclipse, Jenkins, Maven, Xt, MS Word etc. If templates are considered a good thing, creating them should be considered routine for *all* C++ programmers. > . C++ has a very expressive user-definable type system including > user-definable literals. I don't like said system. Analogously, I'm not too keen on formal schemata. Even more generally, I'm not big on *rule languages*, which are ad-hoc and incomplete. Instead, I prefer *programming languages*, which are compact and expressive, or even plain English. > It should then also be possible to generate compile-time errors for > assignments such as > > example_instance.odd_numbers = 4; Every programming language has its big selling points. C++'s gospel is its utmost compile-time checking. I'm a long time user of C++, but I'm not a convert to that ideology. > . I know too little about Python to tell whether something like this > would be possible with Python, too. Unfortunately, Python is taking baby steps in that direction. Marko From __peter__ at web.de Fri Apr 14 17:16:10 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 14 Apr 2017 23:16:10 +0200 Subject: Namedtuples: some unexpected inconveniences References: <004601d2b556$308b82f0$27b23dae@sambora> Message-ID: Deborah Swanson wrote: > Peter, > > Retracing my steps to rewrite the getattr(row, label) code, this is what > sent me down the rabbit hole in the first place. (I changed your 'rows' > to 'records' just to use the same name everywhere, but all else is the > same as you gave me.) I'd like you to look at it and see if you still > think complete(group, label) should work. Perhaps seeing why it fails > will clarify some of the difficulties I'm having. > > I ran into problems with values and has_empty. values has a problem > because > row[label] gets a TypeError. has_empty has a problem because a list of > field values will be shorter with missing values than a full list, but a > namedtuple with missing values will be the same length as a full > namedtuple since missing values have '' placeholders. Two more > unexpected inconveniences. > > A short test csv is at the end, for you to read in and attempt to > execute the following code, and I'm still working on reconstructing the > lost getattr(row, label) code. > > import csv > from collections import namedtuple, defaultdict > > def get_title(row): > return row.title > > def complete(group, label): > values = {row[label] for row in group} > # get "TypeError: tuple indices must be integers, not str" Yes, the function expects row to be dict-like. However when you change row[label] to getattr(row, label) this part of the code will work... > has_empty = not min(values, key=len) > if len(values) - has_empty != 1: > # no value or multiple values; manual intervention needed > return False > elif has_empty: > for row in group: > row[label] = max(values, key=len) but here you'll get an error. I made the experiment to change everything necessary to make it work with namedtuples, but you'll probably find the result a bit hard to follow: import csv from collections import namedtuple, defaultdict INFILE = "E:\\Coding projects\\Pycharm\\Moving\\Moving 2017 in - test.csv" OUTFILE = "tmp.csv" def get_title(row): return row.title def complete(group, label): values = {getattr(row, label) for row in group} has_empty = not min(values, key=len) if len(values) - has_empty != 1: # no value or multiple values; manual intervention needed return False elif has_empty: # replace namedtuples in the group. Yes, it's ugly fix = {label: max(values, key=len)} group[:] = [record._replace(**fix) for record in group] return True with open(INFILE) as infile: rows = csv.reader(infile) fieldnames = next(rows) Record = namedtuple("Record", fieldnames) groups = defaultdict(list) for row in rows: record = Record._make(row) groups[get_title(record)].append(record) LABELS = ['Location', 'Kind', 'Notes'] # add missing values for group in groups.values(): for label in LABELS: complete(group, label) # dump data (as a demo that you do not need the list of all records) with open(OUTFILE, "w") as outfile: writer = csv.writer(outfile) writer.writerow(fieldnames) writer.writerows( record for group in groups.values() for record in group ) One alternative is to keep the original and try to replace the namedtuple with the class suggested by Gregory Ewing. Then it should suffice to also change > elif has_empty: > for row in group: > row[label] = max(values, key=len) to > elif has_empty: > for row in group: setattr(row, label, max(values, key=len)) PS: Personally I would probably take the opposite direction and use dicts throughout... From python at mrabarnett.plus.com Fri Apr 14 17:18:30 2017 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 14 Apr 2017 22:18:30 +0100 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: <004601d2b556$308b82f0$27b23dae@sambora> References: <004601d2b556$308b82f0$27b23dae@sambora> Message-ID: On 2017-04-14 20:34, Deborah Swanson wrote: > Peter, > > Retracing my steps to rewrite the getattr(row, label) code, this is what > sent me down the rabbit hole in the first place. (I changed your 'rows' > to 'records' just to use the same name everywhere, but all else is the > same as you gave me.) I'd like you to look at it and see if you still > think complete(group, label) should work. Perhaps seeing why it fails > will clarify some of the difficulties I'm having. > > I ran into problems with values and has_empty. values has a problem > because > row[label] gets a TypeError. has_empty has a problem because a list of > field values will be shorter with missing values than a full list, but a > namedtuple with missing values will be the same length as a full > namedtuple since missing values have '' placeholders. Two more > unexpected inconveniences. > In the line: values = {row[label] for row in group} 'group' is a list of records; row is a record (namedtuple). You can get the members of a namedtuple (also 'normal' tuple) by numeric index, e.g. row[0], but the point of a namedtuple is that you can get them by name, as an attribute, e.g. row.Location. As the name of the attribute isn't fixed, but passed by name, use getattr(row, label) instead: values = {getattr(row, label) for row in group} As for the values: # Remove the missing value, if present. values.discard('') # There's only 1 value left, so fill in the empty places. if len(values) == 1: ... The next point is that namedtuples, like normal tuples, are immutable. You can't change the value of an attribute. > A short test csv is at the end, for you to read in and attempt to > execute the following code, and I'm still working on reconstructing the > lost getattr(row, label) code. > > import csv > from collections import namedtuple, defaultdict > > def get_title(row): > return row.title > > def complete(group, label): > values = {row[label] for row in group} > # get "TypeError: tuple indices must be integers, not str" > has_empty = not min(values, key=len) > if len(values) - has_empty != 1: > # no value or multiple values; manual intervention needed > return False > elif has_empty: > for row in group: > row[label] = max(values, key=len) > return True > > infile = open("E:\\Coding projects\\Pycharm\\Moving\\Moving 2017 in - > test.csv") > rows = csv.reader(infile) > fieldnames = next(rows) > Record = namedtuple("Record", fieldnames) > records = [Record._make(fieldnames)] > records.extend(Record._make(row) for row in rows) > > # group rows by title > groups = defaultdict(list) > for row in records: > groups[get_title(row)].append(row) > > LABELS = ['Location', 'Kind', 'Notes'] > > # add missing values > for group in groups.values(): > for label in LABELS: > complete(group, label) > > Moving 2017 in - test.csv: > (If this doesn't come through the mail system correctly, I've also > uploaded the file to > http://deborahswanson.net/python/Moving%202017%20in%20-%20test.csv. > Permissions should be set correctly, but let me know if you run into > problems downloading the file.) > [snip] From no.email at nospam.invalid Fri Apr 14 18:05:04 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 14 Apr 2017 15:05:04 -0700 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <58f03030$0$1598$c3e8da3$5496439d@news.astraweb.com> <4V2IA.973357$qK5.728302@fx45.am4> Message-ID: <8760i6hchb.fsf@nightsong.com> bartc writes: > I do know that if I want to port some program (be it in Python or > C++), or simply try and understand it, if I see it's full of class > definitions or whatever, then I won't bother. There was a time in the evolution of OOP when inheritance was thought of as a cool and enabling thing for code re-use, and lots of architecture astronautics involved designing deeply nested and complex inheritance hierarchies in programs. These days I think there's more accepted that inheritance is confusing and obscures the control flow in programs, that it was often mis-used, and that while there are still legitimate uses cases for it, it should be used sparingly. That helps quite a lot. C++ templates let you write generics that are often cleaner than using subclasses, though the design of templates can lead to awful code and notoriously bloated and useless error messages. The long-awaited Concepts extension should help some with that. Again though, like anything else, templates work best when used tastefully rather than willy-nilly. From rantingrickjohnson at gmail.com Fri Apr 14 19:40:35 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 14 Apr 2017 16:40:35 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: <95345397-bb7f-46e9-ba4d-c398a2aeae88@googlegroups.com> On Wednesday, April 12, 2017 at 1:48:57 AM UTC-5, Steven D'Aprano wrote: > On Tue, 11 Apr 2017 21:10:56 -0700, Rick Johnson wrote: > > > high level languages like Python should make it difficult, > > if not impossible, to write sub- optimal code (at least in > > the blatantly obvious cases). > > You mean that Python should make it impossible to write: > > near_limit = [] > near_limit.append(1) > near_limit = len(near_limit) > > instead of: > > near_limit = 1 Yes. > ? I look forward to seeing your version of RickPython that > can enforce that rule. Oh, in case you think I'm making > this up, this example came from some real-life code: > [snip: link] My guess about that obviously superfluous code is that it is an artifact of an early algorithm, but since the code executes without error, the programmer forgot about it. That's my two cents anyways... > Here's another example: > > answer = 0 > for i in range(10): > answer += 1 > > instead of > > answer = 10 > > So... how exactly does the compiler prohibit stupid code? Easy. The same way _any_ optimizer optimizes code, by analysing the code! In this example, the integer named 'answer` is simply being incremented in a superfluous loop. Nothing here is "dynamic". For example: * `range(10)` will always produce a list of the _same_ 10 integers. * `for i in range(10)` will aways iterate over the _same_ 10 integers * `answer += 1` will always increment the "current integer value" by 1 Therefore, since `answer` will always be `10`, the code should be optimized to `answer = 10`. What's so difficult to understand here? Hell, if we have to live with the syntactic burden of type- hints, we should at least be rewarded with an optimizer. From rantingrickjohnson at gmail.com Fri Apr 14 19:59:50 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 14 Apr 2017 16:59:50 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <423b78ac-3e72-45d3-a7d9-88feeb47a291@googlegroups.com> Message-ID: On Wednesday, April 12, 2017 at 4:30:16 AM UTC-5, alister wrote: > On Tue, 11 Apr 2017 16:31:16 -0700, Rick Johnson wrote: > > On Tuesday, April 11, 2017 at 9:56:45 AM UTC-5, Steve D'Aprano wrote: > >> On Tue, 11 Apr 2017 07:56 pm, Brecht Machiels wrote: > >> > On 2017-04-11 08:19:31 +0000, Steven D'Aprano said: > > > > I understand that high performance was never a goal in > > > > CPython development (and Python language design!), but > > > > recent events (DropBox, Google) might help to reconsider > > > > that standpoint. > > > *shrug* It isn't as if high-performance is a > > > requirement for all code. > > But given the choice, no prospective "language shopper" > > is going to choose the slower language over a faster > > language -- at least not from a pool of similar languages > > with similar features (no comparing Python to C, please!). > > So even if you don't need the speed _today_, you may need > > it _tomorrow_. And once you've written a few hundred > > thousand lines of code, well, you're committed to the > > language you chose yesterday. > > but cost is also a factor , not just cost of the tools but > cost in time writing & debugging he software the write. if > they can produce a finished product in half the time with a > "slower" language the speed may not be important > (especially when the application is IO bound & spends 90% > of its time idling anyway). Yes, and that is why many people have, at least historically, picked Python for their project. An interpreted language with a clean syntax and an avoidance of TIM-TOWTDI results not only in a Rapid Development, but also less headaches during the maintenance lifetime of the software. But we cannot _always_ know what the final destination of our software may be. Many times a simple project can grow into an enormous beast, and by the time we realize that Python is too slow, we're faced with only bad choices and worse choices. > if this were not the case then we would all be writing > Assembler Only a few, poor, masochistic souls choose to write assembly, the rest of us try to avoid pain as much as we can. ;-) From python at deborahswanson.net Fri Apr 14 20:03:04 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Fri, 14 Apr 2017 17:03:04 -0700 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: Message-ID: <00b001d2b57b$a8ffffc0$27b23dae@sambora> fix = {label: max(values, key=len)} group[:] = [record._replace(**fix) for record in group] Peter Otten wrote, on Friday, April 14, 2017 2:16 PM > > def complete(group, label): > > values = {row[label] for row in group} > > # get "TypeError: tuple indices must be integers, not str" > > Yes, the function expects row to be dict-like. However when > you change > > row[label] > > to > > getattr(row, label) > > this part of the code will work... > > > has_empty = not min(values, key=len) > > if len(values) - has_empty != 1: > > # no value or multiple values; manual intervention needed > > return False > > elif has_empty: > > for row in group: > > row[label] = max(values, key=len) > > but here you'll get an error. I made the experiment to change > everything > necessary to make it work with namedtuples, but you'll > probably find the > result a bit hard to follow: > > import csv > from collections import namedtuple, defaultdict > > INFILE = "E:\\Coding projects\\Pycharm\\Moving\\Moving 2017 > in - test.csv" OUTFILE = "tmp.csv" > > def get_title(row): > return row.title > > def complete(group, label): > values = {getattr(row, label) for row in group} > has_empty = not min(values, key=len) > if len(values) - has_empty != 1: > # no value or multiple values; manual intervention needed > return False > elif has_empty: > # replace namedtuples in the group. Yes, it's ugly > fix = {label: max(values, key=len)} > group[:] = [record._replace(**fix) for record in group] > return True > > with open(INFILE) as infile: > rows = csv.reader(infile) > fieldnames = next(rows) > Record = namedtuple("Record", fieldnames) > groups = defaultdict(list) > for row in rows: > record = Record._make(row) > groups[get_title(record)].append(record) > > LABELS = ['Location', 'Kind', 'Notes'] > > # add missing values > for group in groups.values(): > for label in LABELS: > complete(group, label) > > # dump data (as a demo that you do not need the list of all > records) with open(OUTFILE, "w") as outfile: > writer = csv.writer(outfile) > writer.writerow(fieldnames) > writer.writerows( > record for group in groups.values() for record in group > ) > > One alternative is to keep the original and try to replace > the namedtuple > with the class suggested by Gregory Ewing. Then it should > suffice to also > change > > > elif has_empty: > > for row in group: > > row[label] = max(values, key=len) > > to > > > elif has_empty: > > for row in group: > setattr(row, label, max(values, key=len)) > > PS: Personally I would probably take the opposite direction > and use dicts > throughout... Ok, thank you. I haven't run it on a real input file yet, but this seems to work with the test file. Because the earlier incarnation defined 'values' as values = {row[label] for row in group} I'd incorrectly guessed what was going on in has_empty = not min(values, key=len). Now that values = {getattr(row, label) for row in group} works properly as you intended it to, I see you get the set of unique values for that label in that group, which makes the rest of it make sense. I know it's your "ugly" answer, but can I ask what the '**' in fix = {label: max(values, key=len)} group[:] = [record._replace(**fix) for record in group] means? I haven't seen it before, and I imagine it's one of the possible 'kwargs' in 'somenamedtuple._replace(kwargs)', but I have no idea where to look up the possible 'kwargs'. (probably short for keyword args) Also, I don't see how you get a set for values with the notation you used. Looks like if anything you've got a comprehension that should give you a dict. (But I haven't worked a lot with sets either.) Thanks From rantingrickjohnson at gmail.com Fri Apr 14 20:14:22 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 14 Apr 2017 17:14:22 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wednesday, April 12, 2017 at 4:34:00 AM UTC-5, Brecht Machiels wrote: > On 2017-04-11 14:56:33 +0000, Steve D'Aprano said: > > On Tue, 11 Apr 2017 07:56 pm, Brecht Machiels wrote: > [...] > However, we don't really know how Python's performance is > affecting its popularity. It would be good to have some > kind of information about user's motivations for choosing > Python or moving away from it. Have any polls been > organized in the past to try to find out? Not to my knowledge. But a very good idea. Because when Python fails to meet the demands of most users, those users will not bother to complain, they will simply move quietly to another langauge that _does_ meet their needs. So, it would behoove us to anticipate the tends before they become _the tend_. Judging Python's popularity by gawking at Python's position in an internet popularity list is like judging if you have black paint on the bottom side of your shoe by walking across white carpet and looking behind you for footprints -- by the time you realize you're leaving tracks, it's too late! > I realize that work on CPython (and thus the language > itself) is done by unpaid volunteers. But I assume that > they also want the language to thrive, and therefore want > to cater to the wishes of the userbase at some level. I would hope so, for, without the large userbase, what would be the point? > So perhaps the conclusion to this discussion is that we > should first try to find out whether performance is an > issue for a large part of the community (or possible > newcomers). +1 From python at deborahswanson.net Fri Apr 14 20:14:45 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Fri, 14 Apr 2017 17:14:45 -0700 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: Message-ID: <00b601d2b57d$49cdcfd0$27b23dae@sambora> MRAB wrote, on Friday, April 14, 2017 2:19 PM > > In the line: > > values = {row[label] for row in group} > > 'group' is a list of records; row is a record (namedtuple). > > You can get the members of a namedtuple (also 'normal' tuple) by numeric > index, e.g. row[0], but the point of a namedtuple is that you can get > them by name, as an attribute, e.g. row.Location. > > As the name of the attribute isn't fixed, but passed by name, use > getattr(row, label) instead: > > values = {getattr(row, label) for row in group} > > As for the values: > > # Remove the missing value, if present. > values.discard('') > > # There's only 1 value left, so fill in the empty places. > if len(values) == 1: > ... Thanks for this, but honestly, I'm namedtupled-out at the moment and I have several other projects I'd like to be working on. But I saved your suggestion with ones that others have made, so I'll revisit yours again when I come back for another look at namedtuples. > The next point is that namedtuples, like normal tuples, are immutable. > You can't change the value of an attribute. No you can't, but you can use somenamedtuple._replace(kwargs) to replace the value. Works just as well. From bc at freeuk.com Fri Apr 14 20:23:39 2017 From: bc at freeuk.com (bartc) Date: Sat, 15 Apr 2017 01:23:39 +0100 Subject: Python and the need for speed In-Reply-To: <95345397-bb7f-46e9-ba4d-c398a2aeae88@googlegroups.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <95345397-bb7f-46e9-ba4d-c398a2aeae88@googlegroups.com> Message-ID: On 15/04/2017 00:40, Rick Johnson wrote: > On Wednesday, April 12, 2017 at 1:48:57 AM UTC-5, Steven D'Aprano wrote: >> answer = 0 >> for i in range(10): >> answer += 1 >> >> instead of >> >> answer = 10 >> >> So... how exactly does the compiler prohibit stupid code? > > Easy. The same way _any_ optimizer optimizes code, by > analysing the code! In Python, the optimising would need to be done every time you run from source. You can't spend too long at it. (I don't know how much it relies on caching pre-compiled byte-code.) In this example, the integer named > 'answer` is simply being incremented in a superfluous loop. > Nothing here is "dynamic". In Python, nearly everything is. For example: > > * `range(10)` will always produce a list of the _same_ 10 > integers. You don't know if 'range' is still a range. If this has been executed first, then the answer will be 20: oldrange=range def double(x): return oldrange(x*2) range=double > * `for i in range(10)` will aways iterate over the _same_ > 10 integers And range could be set to something else each time the loop is executed. > * `answer += 1` will always increment the "current integer > value" by 1 I don't know if it's possible to override __iadd__ for integers so that +=1 does something different here. But if there is any code between answer=0 and the start of the loop, then there is the possibility that answer could be something different. -- bartc From python at deborahswanson.net Fri Apr 14 20:24:58 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Fri, 14 Apr 2017 17:24:58 -0700 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: Message-ID: <00b701d2b57e$b75df2e0$27b23dae@sambora> Gregory Ewing wrote, on Thursday, April 13, 2017 12:17 AM > > Deborah Swanson wrote: > > But I think you got it right in your last sentence below. defaultdict > > copied them because they were immutable, > > No, definitely not. A defaultdict will never take it upon > itself to copy an object you give it, either as a key or a value. > > The copying, if any, must have occurred somewhere else, in > code that you didn't show us. > > Can you show us the actual code you used to attempt to > update the namedtuples? > > -- > Greg I think you've heard my sob story of how the actual code was lost (PyCharm ate it). I've made some attempts to recover that code, but honestly, at this point Peter Otten has showed my enough examples of getattr() that work with namedtuples with variable names, that I'd rather just accept that probably some tranformation of the structure I did caused the copying of values only. I remember looking at it in the debugger, but that code was convoluted and I don't think it's worth teasing out exactly what went wrong. (or figuring out how I did it in the first place) Deborah From greg.ewing at canterbury.ac.nz Fri Apr 14 21:02:21 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 15 Apr 2017 13:02:21 +1200 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: References: <004601d2b556$308b82f0$27b23dae@sambora> Message-ID: Peter Otten wrote: > PS: Personally I would probably take the opposite direction and use dicts > throughout... Yes, my suggestion to used namedtuples in the first place was based on the assumption that you would mostly be referring to fields using fixed names. If that's not true, then using namedtuples (or a mutable equivalent) might just be making things harder. If the names are sometimes fixed and sometimes not, then you have a tradeoff to make. In the code you posted most recently, the only fixed field reference seems to be row.title, and that only appears once. So as long as that's all you want to do with the rows, storing them as dicts would appear to be a clear winner. -- Greg From python at deborahswanson.net Fri Apr 14 21:37:13 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Fri, 14 Apr 2017 18:37:13 -0700 Subject: Namedtuples: some unexpected inconveniences In-Reply-To: Message-ID: <00ba01d2b588$cee48c30$27b23dae@sambora> Roel Schroeven wrote, on Thursday, April 13, 2017 5:26 PM > > Gregory Ewing schreef op 13/04/2017 9:34: > > Deborah Swanson wrote: > >> Peter Otten wrote, on Wednesday, April 12, 2017 1:45 PM > >> > >>> Personally I would immediately discard the header row > once and for > >>> all, not again and again on every operation. > >> Well, perhaps, but I need the header row to stay in place to write > >> the list to a csv when I'm done > > > > That's no problem, just write the header row separately. > > > > Do this at the beginning: > > > > header = [Record._make(fieldnames)] > > records = [Record._make(row) for row in rows] > > > > and then to write out the file: > > > > writer = csv.writer(outputfile) > > writer.writerow(header) > > writer.writerows(records) > > I don't even think there's any need to store the field names anywhere > else than in fieldnames. So unless I'm missing something, > just do this > at the beginning: > > fieldnames = next(rows) > Record = namedtuple("Record", fieldnames) > records = [Record._make(row) for row in rows] > > and this at the end: > > writer = csv.writer(outputfile) > writer.writerow(fieldnames) # or writer.writerow(Record._fields) > writer.writerows(records) > > > -- > The saddest aspect of life right now is that science gathers > knowledge faster than society gathers wisdom. > -- Isaac Asimov > > Roel Schroeven This is essentially what Peter Otten most recently recommended. I know you got there first, but it is better to only get the header row to name the fields as you and Greg Ewing suggested, and then use just the records in processing the field data, using the field names only for the output. Thanks, Deborah From greg.ewing at canterbury.ac.nz Fri Apr 14 21:39:05 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 15 Apr 2017 13:39:05 +1200 Subject: Goto Considered Harmful [was Re: Python and the need for speed] In-Reply-To: References: <58efb8de$0$1618$c3e8da3$5496439d@news.astraweb.com> <3fbbdbde-107c-4ebb-b608-fd370c0ce72f@googlegroups.com> <58f026d9$0$1612$c3e8da3$5496439d@news.astraweb.com> <37o1fch1fueo74r021feurp11b0jpvmt1e@4ax.com> Message-ID: Dennis Lee Bieber wrote: > And since the original COBOL standard numeric format was BCD, PIC not > only defined output layout, but also internal storage needed by numerics > and string data types. Unless you said USAGE IS COMPUTATIONAL, which left the compiler free to pick a more efficient storage format internally. BTW, one thing I think COBOL did right was not limiting you to some arbitrary compiler or language defined maximum size for numbers. You could declare something as PIC 9(100) and do arithmetic on 100-digit numbers if you wanted. (At least potentially -- not sure if all compilers would really support something that big.) -- Greg From rantingrickjohnson at gmail.com Fri Apr 14 21:55:47 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 14 Apr 2017 18:55:47 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wednesday, April 12, 2017 at 4:57:10 AM UTC-5, bart... at gmail.com wrote: > On Wednesday, 12 April 2017 07:48:57 UTC+1, Steven D'Aprano wrote: > > On Tue, 11 Apr 2017 21:10:56 -0700, Rick Johnson wrote: > > > > > > high level languages like Python should make it > > > difficult, if not impossible, to write sub- optimal code > > > (at least in the blatantly obvious cases). > > > > Here's another example: > > > > answer = 0 > > for i in range(10): > > answer += 1 > > > > instead of > > > > answer = 10 > > > > So... how exactly does the compiler prohibit stupid code? > > Actually, an optimising C compiler (not one of mine!) > probably could reduce that to answer=10. And eliminate even > that if 'answer' was never used. > > But that's not really the issue here. Assume that such a > loop /is/ doing something more useful. The problems with > Python (last time I looked anyway) were these: > > (1) If answer was a global variable, then it needs a symbol > table lookup to find out what it is. That would not happen > in a static language, or a less dynamic one, as you already > have the address. Indeed. I have argued for syntax that will resolve variable scope many times. but apparently, the py-devs believe we only deserve type declarations that do _nothing_ to speed up code execution (aka: type-hints), instead of type declarations that could actually speed up the code. Go figure! I'm not a fan of forced static typing, but i am a fan of optional static typing. The global keyword is one idiosyncrasy of Python that causes a lot of confusion , especially to noobs, but also from a standpoint of "general intuitiviness" for old hats. This keyword does not define "true globals" (aka: a symbol that can be accessed or reassigned from anywhere), no, but rather, a symbol that is global only with respect to the "current module scope" (aka: module level variable). You can only get "true globals" in Python by going rogue and injecting symbols into sys.modules like some mad scientist -- which is not officially supported. Go figure! ;-) > And this [global] lookup happens for every loop iteration. I sure hope not. I have not taken the time to inspect the inner workings of Python, but if the lookup happens every time, that would be an awfully inefficient design. > (2) There is also 'range', which could have been redefined > to mean something else, so /that/ needs a lookup. The byte- > code compiler can't just assume this loop is to be executed > 10 times. Yep, and more evidence that Python has taken dynamics to such a fundamentalist extreme, that even ISIS is jealous! # START INTERACTIVE SESSION (Py2.x) ## >>> def range(*args): ... return "Death to static infidels!" >>> for i in range(10): ... print i D e a t h t o s t a t i c i n f i d e l s ! ## END INTERACTIVE SESSION ## > (3) This was fixed long ago but at one time, even when > 'range' had been established to be a range, it involved > constructing a list of items (10 here, but it could be a > million), and then iterating over the list. First, it was "range", then "xrange", and now, "range" again. Third time's a charm i suppose. The last iteration of the range function design removed the underlying inefficiency, however, it created a semantical nightmare (more on this below). > This might seem crazy, but it might have been exceptable > for a script language at one time. Not for a general > purpose one however. Yeah, this is one of those screw-ups that even GvR's famous time machine could not fix. Must have been in the shop for a tune-up... > (4) Python's integer types being immutable, the += > operation means evaluating the result, then creating a new > integer object and binding 'a' to that new value. (Correct > me if I'm wrong.) > > These are all things the language could point a finger at > before blaming the user for writing inefficient code. > > The problem is also the language encouraging people to use > high-level but inefficient methods, as the emphasis is on > productivity and readability** rather than performance. In > fact most users probably have no idea on what is efficient > and what isn't. And that's the point i was trying to make earlier. Most Python programmers are not CS majors, they are just "technical folk" who need to write a logic program to do this or that task. We shouldn't expect them to know about things like memory management, neither should we expect/burden them to know that calling range(1000000), just to do one million iterations, is inefficient. Instead, we should provide them with the proper "efficient tools" to get the job done. So instead of: for x in range(1000000): # Legacy python was slow here! doSomething(x) It should have _always_ been... 1000000.times: doSomething() or, if you need a counter: 1000000.times as x: doSomething(x) Or something similar. The exact syntax is irrelevant. However, preventing the Python programmer from writing inefficient code is the key. But, equally important, is making a clear distinction between "building a list of integers" and "looping N times". The current implementation of range() is creating a semantical nightmare. "EXPLICIT IS BETTER THAN IMPLICIT!" -- i know i heard that somewhere... > If I wanted to work with the code for character 'A' (ie. > the integer 65), in another language it might represent it > as 'A' which is mapped to 65. In Python, 'A' is a string. > To get the integer code, I have to use ord('A'). To do > that, it has to look up 'ord', than execute a function > call... In the meantime the more static language has long > since finished whatever it was going to do with that code. I don't see a problem here. Those other languages that return ASCII values of string chars really piss me off. Ruby comes to mind: ## START INTERACTIVE SESSION (Ruby 1.8.6) ## >>> sl = "Hello from Ruby" >>> sl[0] 72 ## END INTERACTIVE SESSION (Ruby 1.8.6) ## When indexing a string, 99% of the time, a string is what i want in return, not an integer. But maybe i'm the exception??? > (** Although I find code full of class definitions, one- > liners, decorators and all the other esoterics, > incomprehensive. I'm sure I'm not the only one, so perhaps > readability isn't too much of a priority either.) Agreed on the decorators, and, in Python at least, i much prefer a named function over the less readable comprehension -- unless the comprehension is limited to one level. For example: Good: [i+1 for i in range(10)] Bad: [(i+1, j) for i in range(10) for j in range(10) if j < 2] Because "READABILITY COUNTS!". And long, syntactically complex lines are just not readable. As for classes, being that i have a solid background in Java, classes don't bother me one bit. Actually, I find their "syntactical scoping" to be quite natural and pleasing to my eye. Which shouldn't be surprising when you consider one of my pet peeves is namespace pollution. Especially module- level namespace pollution. From rantingrickjohnson at gmail.com Fri Apr 14 22:35:30 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 14 Apr 2017 19:35:30 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> Message-ID: <616ebaec-f140-491c-897e-f2c4b8368d28@googlegroups.com> On Wednesday, April 12, 2017 at 8:44:30 AM UTC-5, bart... at gmail.com wrote: > On Wednesday, 12 April 2017 12:56:32 UTC+1, Jussi Piitulainen wrote: > > bartc writes: > > > > > > These are straightforward language enhancements. > > > > FYI, the question is not how to optimize the code but how > > to prevent the programmer from writing stupid code in the > > first place. Someone suggested that a language should do > > that. > The 'stupid code' thing is a red herring. I assume the > code people write is there for a reason. Yeah, but you have to admit, sometimes there is no obvious good reason -- as Steven's example code has proven. ;-) Although, i'm convinved that any one of us could find examples like that in our own repos. And if you cannot find code that makes you feel embarassed, then you're not evolving anymore. > But the language can also play a part in not allowing > certain things to be expressed naturally. Exactly! > So the for-loop in the example has to have a control- > variable even if it's not referenced. Yes, one of the design flaws of Python's "for loop" is that the control variable is injected whether you need it or not (Nightmarish images of petulant children being force-fed castor oil comes to mind...). In fact, in Python, there are only two loop forms avialable -- the "for" and the "while". -- however, many other languages have relized that these two forms are insufficent to cover the various types of loops that are needed. At a minimum, every language should offer the following four loop-forms (using Python semantics): while CONDITION: doSomething() for VALUE in COLLECTION: doSomething(value) loop(N): doSomething() loop(N) as i: doSomething(i) From rantingrickjohnson at gmail.com Fri Apr 14 22:55:40 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 14 Apr 2017 19:55:40 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: <58ef1b75$0$1501$c3e8da3$5496439d@news.astraweb.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <87a87mn8rc.fsf@nightsong.com> <58ed8c02$0$1620$c3e8da3$5496439d@news.astraweb.com> <878tn5zqxf.fsf@bsb.me.uk> <58ef1b75$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: <72107d81-48bc-47e9-a1f7-358967edce37@googlegroups.com> On Thursday, April 13, 2017 at 1:32:28 AM UTC-5, Steven D'Aprano wrote: > On Wed, 12 Apr 2017 14:38:52 +0100, Ben Bacarisse wrote: > > Steve D'Aprano writes: > >> On Wed, 12 Apr 2017 03:39 am, Paul Rubin wrote: > > [...] Indeed, and this is a very common phenomenon: > features which "ordinary" programmers imagine are "trendy" > and new end up having their roots in some functional > language dating back to the 1980s, or 70s, or in extreme > cases the 1950s and Lisp. Be advised that functional programmers are a fanatical bunch, and saying something like that could be akin to blowing a "functional purist dogwhistle". If this thread becomes overrun with functional trolls, i'm blaming you. ;-) From rantingrickjohnson at gmail.com Fri Apr 14 22:57:48 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 14 Apr 2017 19:57:48 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> <9506d7a6-cdd8-4285-8c2d-4c71b48be5da@googlegroups.com> Message-ID: <1ca35d13-9223-4174-a14f-4050ebef6f32@googlegroups.com> On Thursday, April 13, 2017 at 1:32:29 AM UTC-5, Gregory Ewing wrote: > Jussi Piitulainen wrote: > > Traceback (most recent call last): > > File "/dev/fd/63", line 37, in > > SanityClauseException: code is blatantly sub-optimal > > > > As far as I know, no language does that. Because reasons? > > Because the problem of making a compiler do that is > probably AI-complete! What? GvR's time machine only goes backwards? From rantingrickjohnson at gmail.com Sat Apr 15 00:56:56 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 14 Apr 2017 21:56:56 -0700 (PDT) Subject: Swiss Ephemeris In-Reply-To: References: <00dd01d2b319$eb9c77a0$27b23dae@sambora> Message-ID: On Thursday, April 13, 2017 at 7:39:38 AM UTC-5, Rustom Mody wrote: > Quote from Peter Landin, one of the precursors of modern > functional programming: Most papers in computer science > describe how their author learned what someone else already > knew [And this dates from 60s/70s] Applies beyond just > CS? There are very few truely orignal ideas. Most of what we say, do and know are derivative works. For example; the kernel of Python was formed in the mind of Guido from his observations of another language called "ABC" -- he saw many good ideas in ABC, but also, many design flaws (kinda coming full circle now, eh?). The key to success in evolution is to propagate the good traits whilst discarding the bad ones. And like most other languages, Python is simply an evolution of many likable traits with a few new features sprinkled on top to "sweeten the pot". Much is the same in any field of study. There are countless examples of theorists and experimentors who knew the answers long before the "named discoverer" was given credit for the supposed discovery. In the reams of the historical record, many times, good communication skills and friends in academic/political circles can be the difference between a Nobel laureate and a nobody. From jobmattcon at gmail.com Sat Apr 15 03:03:06 2017 From: jobmattcon at gmail.com (Ho Yeung Lee) Date: Sat, 15 Apr 2017 00:03:06 -0700 (PDT) Subject: 'module' object has no attribute 'wrap_socket' when use ssl Message-ID: Python 2.7.6 (default, Jun 22 2015, 18:00:18) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import ssl Traceback (most recent call last): File "", line 1, in File "/home/martin/Documents/ssl.py", line 13, in SSLError -- exception raised for I/O errors AttributeError: 'module' object has no attribute 'wrap_socket' From __peter__ at web.de Sat Apr 15 03:18:32 2017 From: __peter__ at web.de (Peter Otten) Date: Sat, 15 Apr 2017 09:18:32 +0200 Subject: 'module' object has no attribute 'wrap_socket' when use ssl References: Message-ID: Ho Yeung Lee wrote: > Python 2.7.6 (default, Jun 22 2015, 18:00:18) > [GCC 4.8.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import ssl > Traceback (most recent call last): > File "", line 1, in > File "/home/martin/Documents/ssl.py", line 13, in > SSLError -- exception raised for I/O errors > AttributeError: 'module' object has no attribute 'wrap_socket' Look at the traceback again -- the ssl.py you are importing is not the one from the standard library, it's an arbitrary module, perhaps written by "martin". Once you rename Martin's ssl.py to something else and also remove the corresponding ssl.pyc you will be able to work with the desired ssl.py from the stdlib. From __peter__ at web.de Sat Apr 15 03:43:49 2017 From: __peter__ at web.de (Peter Otten) Date: Sat, 15 Apr 2017 09:43:49 +0200 Subject: Namedtuples: some unexpected inconveniences References: <00b001d2b57b$a8ffffc0$27b23dae@sambora> Message-ID: Deborah Swanson wrote: > I know it's your "ugly" answer, but can I ask what the '**' in > > fix = {label: max(values, key=len)} > group[:] = [record._replace(**fix) for record in group] > > means? d = {"a": 1, "b": 2} f(**d) is equivalent to f(a=1, b=2) so ** is a means to call a function with keyword arguments when you want to decide about the *names* at runtime. Example: >>> def f(a=1, b=2): ... print("a =", a) ... print("b =", b) ... print() ... >>> for d in [{"a": 10}, {"b": 42}, {"a": 100, "b": 200}]: ... f(**d) ... a = 10 b = 2 a = 1 b = 42 a = 100 b = 200 Starting from a namedtuple `record` record._replace(Location="elswhere") creates a new namedtuple with the Location attribute changed to "elsewhere", and the slice [:] on the left causes all items in the `groups` list to be replaced with new namedtuples, group[:] = [record._replace(Location="elsewhere") for record in group] is basically the same as tmp = group.copy() group.clear() for record in tmp: group.append(record_replace(Location="elsewhere")) To support not just Location, but also Kind and Notes we need the double asterisk. From jobmattcon at gmail.com Sat Apr 15 04:41:53 2017 From: jobmattcon at gmail.com (Ho Yeung Lee) Date: Sat, 15 Apr 2017 01:41:53 -0700 (PDT) Subject: 'module' object has no attribute 'wrap_socket' when use ssl In-Reply-To: References: Message-ID: On Saturday, April 15, 2017 at 3:18:58 PM UTC+8, Peter Otten wrote: > Ho Yeung Lee wrote: > > > Python 2.7.6 (default, Jun 22 2015, 18:00:18) > > [GCC 4.8.2] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> import ssl > > Traceback (most recent call last): > > File "", line 1, in > > File "/home/martin/Documents/ssl.py", line 13, in > > SSLError -- exception raised for I/O errors > > AttributeError: 'module' object has no attribute 'wrap_socket' > > Look at the traceback again -- the ssl.py you are importing is not the one > from the standard library, it's an arbitrary module, perhaps written by > "martin". Once you rename Martin's ssl.py to something else and also remove > the corresponding ssl.pyc you will be able to work with the desired ssl.py > from the stdlib. thanks , it can run now, but how to create a SSL server for testing it? when I use google as server, it failed handshake python crackssl.py Traceback (most recent call last): File "crackssl.py", line 16, in wrappedSocket.connect((HOST, PORT)) File "/usr/lib/python2.7/ssl.py", line 433, in connect self._real_connect(addr, False) File "/usr/lib/python2.7/ssl.py", line 420, in _real_connect socket.connect(self, addr) File "/usr/lib/python2.7/socket.py", line 224, in meth return getattr(self._sock,name)(*args) socket.error: [Errno 111] Connection refused martin at ubuntu:~/Documents$ python crackssl.py Traceback (most recent call last): File "crackssl.py", line 16, in wrappedSocket.connect((HOST, PORT)) File "/usr/lib/python2.7/ssl.py", line 433, in connect self._real_connect(addr, False) File "/usr/lib/python2.7/ssl.py", line 423, in _real_connect self.do_handshake() File "/usr/lib/python2.7/ssl.py", line 405, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [Errno 1] _ssl.c:510: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure import socket import ssl # SET VARIABLES packet, reply = "SOME_DATA", "" HOST, PORT = 'www.google.com.hk', 443 # CREATE SOCKET sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(10) # WRAP SOCKET wrappedSocket = ssl.wrap_socket(sock, ssl_version=ssl.PROTOCOL_TLSv1, ciphers="ADH-AES256-SHA") # CONNECT AND PRINT REPLY wrappedSocket.connect((HOST, PORT)) wrappedSocket.send(packet) print wrappedSocket.recv(1280) # CLOSE SOCKET CONNECTION wrappedSocket.close() From tflchkl at gmail.com Sat Apr 15 07:31:27 2017 From: tflchkl at gmail.com (tflchkl at gmail.com) Date: Sat, 15 Apr 2017 04:31:27 -0700 (PDT) Subject: TIC TAE TOE's problem(i am beginner) Message-ID: <1f99a232-568a-4228-9661-7241e408d468@googlegroups.com> A=['1', ' ', '1'] B=['1', ' ', '2'] C=['1', ' ', '3'] D=['2', ' ', '1'] E=['2', ' ', '2'] F=['2', ' ', '3'] G=['3', ' ', '1'] H=['3', ' ', '2'] I=['3', ' ', '3'] N=int(9) def my_func1(): X=list(input()) global N N=N-1 if X==['1', ' ', '1']: A="X" my_func3() my_func2() if X==['1', ' ', '2']: B="X" my_func3() my_func2() if X==['1', ' ', '3']: C="X" my_func3() my_func2() if X==['2', ' ', '1']: D='X' my_func3() my_func2() if X==['2', ' ', '2']: E="X" my_func3() my_func2() if X==['2', ' ', '3']: F='X' my_func3() my_func2() if X==['3', ' ', '1']: G='X' my_func3() my_func2() if X==['3', ' ', '2']: H='X' my_func3() my_func2() if X==['3', ' ', '3']: I='X' my_func3() my_func2() def my_func2(): Y=list(input()) global N N=N-1 if Y==['1', ' ', '1']: A="O" my_func3() my_func1() if Y==['1', ' ', '2']: B="O" my_func3() my_func1() if Y==['1', ' ', '3']: C="O" my_func3() my_func1() if Y==['2', ' ', '1']: D="O" my_func3() my_func1() if Y==['2', ' ', '2']: E="O" my_func3() my_func1() if Y==['2', ' ', '3']: F="O" my_func3() my_func1() if Y==['3', ' ', '1']: G="O" my_func3() my_func1() if Y==['3', ' ', '2']: H="O" my_func3() my_func1() if Y==['3', ' ', '3']: I="O" my_func3() my_func1() def my_func3(): if A and B and C=="X": print("X win") elif D=="X" and E=="X" and F=="X": print("X win") elif G=="X" and H=="X" and I=="X": print("X win") elif A=="X" and D=="X" and G=="X": print("X win") elif B=="X" and E=="X" and H=="X": print("X win") elif C=="X" and F=="X" and I=="X": print("X win") elif A=="X" and E=="X" and I=="X": print("X win") elif A=="O" and B=="O" and C=="O": print("O win") elif D=="O" and E=="O" and F=="O": print("O win") elif G=="O" and H=="O" and I=="O": print("O win") elif A=="O" and D=="O" and G=="O": print("O win") elif B=="O" and E=="O" and H=="O": print("O win") elif C=="O" and F=="O" and I=="O": print("O win") elif A=="O" and E=="O" and I=="O": print("O win") elif N==0: print("DRAW") print(A,B) P=input("X/O:") if P=="X": my_func1() else: my_func2() why cant function to print X or O win... From nsssayom at gmail.com Sat Apr 15 08:16:03 2017 From: nsssayom at gmail.com (Sayom Shakib) Date: Sat, 15 Apr 2017 05:16:03 -0700 (PDT) Subject: Python Environment Setup in Windows 10 Message-ID: <1a5f7408-bc14-4bc4-af5a-78f36822f54c@googlegroups.com> I am a beginner .NET developer. But I need to use python now for a project. I need to use Scikit-Learn, Numpy, Scipy, matplotlib.pyplot, Pandas, Keras, TensorFlow etc libraries (Mostly for Machine Learning). To be more specific, I want to implement this example- http://machinelearningmastery.com/time-series-prediction-with-deep-learning-in-python-with-keras/ I want to use PyCharm as my IDE. But I am tired trying to install python, anaconda, CUDA etc etc, nothing helps me run those codes. I am sure that the problem is with environment setup. I need a complete walkthrough about the installation and other setup procedures (Including path variable changes and other details). (I will uninstall all the python related things are currently installed in my system.) I use Windows 10 (64 Bit) And I have a NVIDIA 1050 Ti GPU. (Want to use GPU installation for TensorFlow). I have Visual Studio 2015 installed in my system. From bc at freeuk.com Sat Apr 15 08:17:45 2017 From: bc at freeuk.com (bartc) Date: Sat, 15 Apr 2017 13:17:45 +0100 Subject: Python and the need for speed In-Reply-To: <616ebaec-f140-491c-897e-f2c4b8368d28@googlegroups.com> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> <616ebaec-f140-491c-897e-f2c4b8368d28@googlegroups.com> Message-ID: On 15/04/2017 03:35, Rick Johnson wrote: > On Wednesday, April 12, 2017 at 8:44:30 AM UTC-5, bart... at gmail.com wrote: > At a minimum, every language should offer > the following four loop-forms (using Python semantics): > > while CONDITION: > doSomething() > > for VALUE in COLLECTION: > doSomething(value) > > loop(N): > doSomething() > > loop(N) as i: > doSomething(i) > Yes, I'm constantly surprised at this, as such syntax has a very low cost (in my last compiler, supporting 'while' for example only added 30 lines to the project). Of course, it's possible to overdo it; if you look at Lisp, you'll lose yourself in the myriad looping options. But very common requirements are endless loops, and repeat N times without needing an explicit counter. The former /can/ be easily written as: while 1: body but it's more psychological; I don't want to use an idiom to denote an endless loop, I want to be able to express it directly! Python's byte-code does at least optimise out the check that '1' is true, but that's not what the reader sees, which is 'loop while 1 is true'. And one day it will be: while l: body that can be mistaken for that common idiom. -- bartc From steve+python at pearwood.info Sat Apr 15 08:47:39 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 15 Apr 2017 22:47:39 +1000 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <95345397-bb7f-46e9-ba4d-c398a2aeae88@googlegroups.com> Message-ID: <58f2166e$0$1603$c3e8da3$5496439d@news.astraweb.com> On Sat, 15 Apr 2017 10:23 am, bartc wrote: > On 15/04/2017 00:40, Rick Johnson wrote: >> * `range(10)` will always produce a list of the _same_ 10 >> integers. > > You don't know if 'range' is still a range. If this has been executed > first, then the answer will be 20: > > oldrange=range > def double(x): return oldrange(x*2) > range=double Correct. It is true that *at the moment* CPython doesn't know if range has been shadowed or redefined, but Victor Stinner is working on a project, FATPython, which will. Or at least, FATPython can tell: - there's no chance that range() has been redefined, so it is safe to optimize the call to it; - or there is a chance, in which case it is not safe to optimize. >> * `for i in range(10)` will aways iterate over the _same_ >> 10 integers > > And range could be set to something else each time the loop is executed. It could, but that won't effect the loop. py> old_range = range py> for i in range(5): ... range = i*100 ... print(i) ... 0 1 2 3 4 py> range 400 >> * `answer += 1` will always increment the "current integer >> value" by 1 > > I don't know if it's possible to override __iadd__ for integers so that > +=1 does something different here. No, Python doesn't allow the built-in types to be monkey-patched. However, that's not the problem. The problem is that CPython doesn't know whether answer is a built-in int or not until runtime. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rantingrickjohnson at gmail.com Sat Apr 15 08:50:12 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 15 Apr 2017 05:50:12 -0700 (PDT) Subject: Calling dunder methods manually In-Reply-To: References: <58ef0cd3$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5190e78b-972a-4678-8ee0-5d76d7452ab0@googlegroups.com> On Thursday, April 13, 2017 at 2:01:41 AM UTC-5, Serhiy Storchaka wrote: > > __init__ is perhaps the most called dunder method. It is > often called from the __init__ method of subclasses. Yes, that would be one of the exceptions to the rule, but not because the rule is unsound, but because Python's super really sucks. Even to this day, i avoid super because the semantics are confusing, eaisier to just write the path in long-form. In many other languages though, super is intelligent enough to know what scope it is in. But in any event, i cannot think one one good reason to call dunder methods from outside a class definition (maybe someone can think of a few???). > __add__ also can be called from other __add__, __iadd__ or > __radd__. Some people have mentioned using the methods of the operator module to avoid calling dunders, but from the POV of consistency, i think such a policy would be a bad idea and just more evidence that Python's super is woefully inadequate. Which begs the question: "What's the point of having super if the majority are unwilling to use it?" Hmm. I suppose "for consistency's sake" would be the only legitimate answer. From kondaiah505 at gmail.com Sat Apr 15 09:13:54 2017 From: kondaiah505 at gmail.com (kondaiah sinha) Date: Sat, 15 Apr 2017 06:13:54 -0700 (PDT) Subject: what type of application implemented with python? Message-ID: <957c77db-c61d-4b70-9cc6-5add541b8043@googlegroups.com> what type of application implemented with python?...like by using java we can implement web,Standard alone app's,mobile based. Can anyone tell me is it possible to implement Standard alone applications with, if possible give any example From marko at pacujo.net Sat Apr 15 09:27:55 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 15 Apr 2017 16:27:55 +0300 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> <616ebaec-f140-491c-897e-f2c4b8368d28@googlegroups.com> Message-ID: <87zifhx0kk.fsf@elektro.pacujo.net> bartc : > Of course, it's possible to overdo it; if you look at Lisp, you'll lose > yourself in the myriad looping options. Funny, in Scheme, the only looping construct I use is named-let. > The former /can/ be easily written as: > > while 1: > body Why not say it like it is: while True: body > but it's more psychological; I don't want to use an idiom to denote an > endless loop, I want to be able to express it directly! C's: for (;;) statement I would call an idiom. Python's while True: body is about as straightforward as it gets. > Python's byte-code does at least optimise I don't understand why there's so much talk about CPython's bytecode on this list. That should only be of interest to active CPython developers. Marko From rantingrickjohnson at gmail.com Sat Apr 15 09:28:40 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 15 Apr 2017 06:28:40 -0700 (PDT) Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> <616ebaec-f140-491c-897e-f2c4b8368d28@googlegroups.com> Message-ID: <45b1d7a2-568e-4e42-8897-26bd007c96e0@googlegroups.com> On Saturday, April 15, 2017 at 7:17:55 AM UTC-5, bartc wrote: > On 15/04/2017 03:35, Rick Johnson wrote: > > On Wednesday, April 12, 2017 at 8:44:30 AM UTC-5, bart... at gmail.com wrote: > > > At a minimum, every language should offer > > the following four loop-forms (using Python semantics): > > > > while CONDITION: > > doSomething() > > > > for VALUE in COLLECTION: > > doSomething(value) > > > > loop(N): > > doSomething() > > > > loop(N) as i: > > doSomething(i) > > > > Yes, I'm constantly surprised at this, as such syntax has a > very low cost (in my last compiler, supporting 'while' for > example only added 30 lines to the project). Of course, > it's possible to overdo it; if you look at Lisp, you'll > lose yourself in the myriad looping options. But very > common requirements are endless loops, and repeat N times > without needing an explicit counter. The former /can/ be > easily written as: > > while 1: > body > > but it's more psychological; I don't want to use an idiom > to denote an endless loop, I want to be able to express it > directly! A good point. I don't like the idiom of using "always True conditions" to denote an endless loop either. So it's just a matter of recognizing that loop() without an "explicit confining parameter", would be endless. loop: # This loop never ends. Of course, recognizing that at some point that the loop will need to end, or that something surprizing will cause it to end, how then would you end it in a clean manner? Which would cause the semantics to be: loop: # This loop never ends. Well "never" unless an # exception occurs; or the hardware malfunctions; or # melts; or unless nuclear war breaks out; or unless the # sun expands and envelopes the earth -- except for # those cases (and possibly a long list of others...), # it never ends. ;-) > Python's byte-code does at least optimise out the check > that '1' is true, but that's not what the reader sees, > which is 'loop while 1 is true'. And one day it will be: > > while l: > body > > that can be mistaken for that common idiom. Another good point. However that's more a consequence of using 1 as a truth value than anything else. Python has offered booleans for a loooong time, so i don't understand why some of us feel the need to use 0 and 1 in place of the more intuitive (and less bug prone) False and True. The obvious solution is: while True: # This loop never ends. # (Note: see exceptions above) Integers should only be utilized for their numeric value, and nothing else. Python should never allow an integer to be used as a truth value, only booleans or expressions that evaluate to a truth value. Of course, these can perverted also. if 1 == 1: # superfluous! 1 will always equal 1 if None: # superfluous! None will always be False if True == False: # superfluous! True and False will never be equal. etc... (of course, i _hope_ those examples are rock solid. Sometimes, i forget how utterly and stubbornly dynamic this damned language can be!) From bc at freeuk.com Sat Apr 15 10:37:41 2017 From: bc at freeuk.com (bartc) Date: Sat, 15 Apr 2017 15:37:41 +0100 Subject: Python and the need for speed In-Reply-To: <87zifhx0kk.fsf@elektro.pacujo.net> References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> <616ebaec-f140-491c-897e-f2c4b8368d28@googlegroups.com> <87zifhx0kk.fsf@elektro.pacujo.net> Message-ID: On 15/04/2017 14:27, Marko Rauhamaa wrote: > bartc : >> while 1: >> body > > Why not say it like it is: > > while True: > body > >> but it's more psychological; I don't want to use an idiom to denote an >> endless loop, I want to be able to express it directly! > > C's: > > for (;;) > statement > > I would call an idiom. I don't like that either! > Python's > > while True: > body > > is about as straightforward as it gets. In the syntax I normally use (based on Algol 68), the endless loop is: do body end (well, actually I use do body od, but that may have raised some eyebrows). 'do', in the original Algol 68 syntax, was part of its 'for' statement, where you could leave out the parts you don't need. The full syntax is something like: for var := a to b by c while d do body od If you leave out the first part you get a while loop. Leave out all except 'to b do', you get a repeat-n-times loop. And so on. Elegant. (I don't do it that way, I have discrete loop types, plus my own variations. Devising syntax is so easy, the hard bit is knowing when to stop...) > >> Python's byte-code does at least optimise > > I don't understand why there's so much talk about CPython's bytecode on > this list. That should only be of interest to active CPython developers. What proportion of Python implementations depend on executing byte-code? -- Bartc From breamoreboy at gmail.com Sat Apr 15 10:54:55 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sat, 15 Apr 2017 07:54:55 -0700 (PDT) Subject: Regular Expressions, Speed, Python, and NFA In-Reply-To: <0e334222-676b-4a7b-91c2-1345592cced5@googlegroups.com> References: <0e334222-676b-4a7b-91c2-1345592cced5@googlegroups.com> Message-ID: <52ab7956-a489-4a9b-b49d-791982633e64@googlegroups.com> On Friday, April 14, 2017 at 4:12:27 PM UTC+1, Malik Rumi wrote: > I am running some tests using the site regex101 to figure out the correct regexs to use for a project. I was surprised at how slow it was, constantly needing to increase the timeouts. I went Googling for a reason, and solution, and found Russ Cox?s article from 2007: https://swtch.com/~rsc/regexp/regexp1.html . I couldn?t understand why, if this was even remotely correct, we don?t use NFA in Python, which led me here: > > https://groups.google.com/forum/#!msg/comp.lang.python/L1ZFI_R2hAo/C12Nf3patWIJ;context-place=forum/comp.lang.python where all of these issues were addressed. Unfortunately, this is also from 2007. > > BTW, John Machin in one of his replies cites Navarro?s paper, but that link is broken. Navarro?s work can now be found at http://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.21.3112&rep=rep1&type=pdf But be forewarned, it is 68 pages of dense reading. I am not a computer science major. I am not new to Python, but I don?t think I?m qualified to take on the idea of creating a new NFA module for Python. > > I am not a computer science major. I am not new to Python, but I don?t think I?m qualified to take on the idea of creating a new NFA module for Python. Nor am I entirely sure I want to try something new (to me) like TRE. > > Most threads related to this topic are older than 2007. I did find this https://groups.google.com/forum/#!searchin/comp.lang.python/regex$20speed%7Csort:relevance/comp.lang.python/O7rUwVoD2t0/NYAQM0mUX7sJ from 2011 but I did not do an exhaustive search. > > The bottom line is I wanted to know if anything has changed since 2007, and if there is a) any hope for improving regex speeds in Python, or b) some 3rd party module/library that is already out there and solves this problem? Or should I just take this advice? > > > Thanks. Check out https://pypi.python.org/pypi/regex and for a little light background reading please see http://bugs.python.org/issue2636 Kindest regards. Mark Lawrence. From karlfx4 at gmail.com Sat Apr 15 11:18:31 2017 From: karlfx4 at gmail.com (Peter Henry) Date: Sat, 15 Apr 2017 16:18:31 +0100 Subject: Swiss Ephemeris Message-ID: Hi I hired a programmer to help to extract data for windows 10 64 Bit system You will be able generate data and use for your models, the idea is to eventually get Swiss Ephemeris working as phython file Create folder and use and drop Swedll64.dll and Swetest64.exe into same folder as spreadsheet Happy Easter Peter On 10 April 2017 at 02:52, Deborah Swanson wrote: > Peter Henry wrote, on Sunday, April 09, 2017 10:53 AM > > > > I have a package that has been altered to imported in to > > python, however I tired to get is working but without success > > I be missing something obvious > > > > The Swiss Ephemeris enable planetary coordinate to be > > imported and used in your program > > > > Files access https://pypi.python.org/pypi/pyswisseph > > > > Many thanks in advance > > > > Peter > > I've also worked on the problem of getting sweph into Python and have > mostly struck out so far myself. > > I found one reliable means to get sweph's planetary data into Python, > but it's more or less a cheat. Nonetheless, if you want to see how much > good it does you, try the Swiss Ephemeris Test Page at > http://www.astro.com/swisseph/swetest.htm. If you can successfully > formulate a query useful to your purposes, you can download a csv of > results, read it into Python, and work from there. Right now I'm working > on converting some Excel spreadsheets and Excel VBA I use into Python > and recoding it all, using the CSVs for jumping off points. That works > pretty well, except the times from swetest are off a bit and I haven't > figured out why. But I'm concentrating on getting all my VBA code ported > to Python, and will go back to getting bang on data from sweph after I > have my code done. > > The first thing I tried was to get sweph's C source code into a free > IDE, but that whole project went down in flames. You can read bits and > pieces of that misadventure at the tail end of the "Python application > launcher (for Python code)" thread. I found sweph's C source code at > some link off "Programming interface to the Swiss Ephemeris" at > http://www.astro.com/swisseph/swephprg.htm (or maybe it was on > http://www.astro.com/swisseph/swephinfo_e.htm - I can't easily find it > now, but the download link is in one of those two pages somewhere.) > > Then I tried picking through sweph's C source code, attempting to > manually reproduce the logic and the calculations in Python. That was a > highly qualified semi-success because the times were still off, but it > essentially produces the most basic planetary data. The swetest output > CSVs were more complete however, and easy to read the planetary data > into Python from, so I'd pretty much abandoned efforts to "translate" > the C source code. And now, all my efforts to leverage the C source > code. Even if successful it would be a lot more time sunk into working > with a language other than Python, which I likely wouldn't have a use > for after this project is completed. > > However, I have seen bits here and there on this list that are at least > interesting. Tim Chase mentioned in passing that he encapsulated C > source code in a class, which may bear looking into. Lutz Horn also gave > a link for building a Python module to add a C language library to > Python, which also might be worth checking out: > https://docs.python.org/3/extending/index.html (I changed the 2 to a 3 > from the link he gave, but you can change it back to 2 if your working > in a build of Python 2.) > > But many thanks for your pypi link to pyswisseph, which I will check > out. I can reply to this thread after I give it a shot and tell you what > I think of it. But like I said earlier, that won't be until all my Excel > VBA code, which jumps off from the sweph bare planetary data, is ported > to Python and working. Could be awhile yet. And if pyswisseph doesn't > pan out, I'll likely work on refining the two methods I have for > producing the planetary data, both of which are only lacking precisely > accurate time data in my local time, and both are off by only 5-30 > minutes. I easily limped along for years with my Excel spread sheets > using the swetest CSVs for input, even though my times then were more > than a day off. > > Good luck! (and this venture is a goodly portion of luck...) > > Deborah > > PS. I've been using medical astrology to look ahead at my medical > condition for years in advance. And being off by a day or so doesn't > matter that much when you're looking at trends over the course of years > and decades. I also have a little software widget to look at the > planetary data in graphical chart form at any particular second, also > based on sweph, which has been quite astoundingly accurate in following > the rather complex kaleidoscope of my symptoms during the course of a > day. (Though it doesn't do you a bit of good if you forget to look! > Which is my entire motivation to get it encoded and available with a few > clicks.) And it is quite useful to know in advance what will be > happening when, and most importantly when it will stop. Knowledge is > power! > > Caveat. This kind of precision and accuracy is only found in the > specific forms of astrology which relate to pure physical phenomena, and > most of what you see these days masquerading as astrology is pure hooey, > almost entirely invented on a large scale in the Middle Ages and > flowered in the Renaissance. By pure physical phenomena, which is the > only phenomena that is at least debatably influenced by physical > planetary forces, I mean things like the moon's tides, sunspots, plant > and animal activity throughout the year, and supremely, the inner > workings of the human body, the first wholly Western medicine devised by > the ancient Greeks. (The ancient Greek physicians are an excellent > fallback if modern medicine is failing you - if you can find enough that > remains today of their art.) > > From jsf80238 at gmail.com Sat Apr 15 11:54:40 2017 From: jsf80238 at gmail.com (Jason Friedman) Date: Sat, 15 Apr 2017 09:54:40 -0600 Subject: TIC TAE TOE's problem(i am beginner) In-Reply-To: <1f99a232-568a-4228-9661-7241e408d468@googlegroups.com> References: <1f99a232-568a-4228-9661-7241e408d468@googlegroups.com> Message-ID: > > P=input("X/O:") > if P=="X": > my_func1() > else: > my_func2() > > > > why cant function to print X or O win... > As a beginner I'd try to code using Python idioms rather than writing Python using BASIC idioms. Try to understand how this code works: https://codereview.stackexchange.com/questions/108738/python-tic-tac-toe-game Note that one of the answers on that page has improved the original poster's code. From ben.usenet at bsb.me.uk Sat Apr 15 12:31:00 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Sat, 15 Apr 2017 17:31:00 +0100 Subject: Python and the need for speed References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> <616ebaec-f140-491c-897e-f2c4b8368d28@googlegroups.com> <87zifhx0kk.fsf@elektro.pacujo.net> Message-ID: <87h91ppr97.fsf@bsb.me.uk> bartc writes: > 'do', in the original Algol 68 syntax, was part of its 'for' > statement, where you could leave out the parts you don't need. The > full syntax is something like: > > for var := a to b by c while d do body od FOR name FROM e1 BY e2 TO e3 WHILE cond DO body OD The significant part is the the name is bound to a value and can't be assigned in the body. (You don't say it can be but "var := a" makes var look like a plain Algol68 variable.) -- Ben. From torriem at gmail.com Sat Apr 15 13:35:24 2017 From: torriem at gmail.com (Michael Torrie) Date: Sat, 15 Apr 2017 11:35:24 -0600 Subject: Python and the need for speed In-Reply-To: References: <768f9a44-5d90-4756-8a99-821253a491f8@googlegroups.com> <58e9e519$0$1528$c3e8da3$5496439d@news.astraweb.com> <58ec9192$0$1602$c3e8da3$5496439d@news.astraweb.com> <58eceea2$0$1615$c3e8da3$5496439d@news.astraweb.com> <4277c149-e136-4d33-91d5-d011df9149f1@googlegroups.com> <58edcdd2$0$1501$c3e8da3$5496439d@news.astraweb.com> <54f1685d-1d2d-44b5-869e-a510569ba9d1@googlegroups.com> <1d352948-9029-4b86-b2f1-2b52608109ea@googlegroups.com> <616ebaec-f140-491c-897e-f2c4b8368d28@googlegroups.com> <87zifhx0kk.fsf@elektro.pacujo.net> Message-ID: <4a4d79bc-3d7f-c8f8-06ee-cc5c4c4f32ca@gmail.com> On 04/15/2017 08:37 AM, bartc wrote: > What proportion of Python implementations depend on executing byte-code? Presumably Nuitka does not depend on any byte code at all. Jython uses JVM byte codes. Iron Python uses .net VM bytecodes. While CPython's byte codes do take their form in part because of Python and its syntax. But that doesn't mean that Python itself as a language is necessarily dependent on the specifics of the CPython byte code interpreter and architecture, though I concede that for some aspects of Python, the behavior of the language is defined by the CPython implementation. The two aspects are definitely linked, but not as solidly as you seem to think. From grant.b.edwards at gmail.com Sat Apr 15 13:45:23 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 15 Apr 2017 17:45:23 +0000 (UTC) Subject: Python Command Line Arguments References: <41v6sd-6ve.ln1@bernd.nawothnig.dialin.t-online.de> Message-ID: On 2017-04-14, Bernd Nawothnig wrote: > He should switch to argparse in any case because getopt is no longer > supported and does only receive bugfixes. In my book, "receiving bug fixes" means it's still supported. -- Grant From breamoreboy at gmail.com Sat Apr 15 14:47:06 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sat, 15 Apr 2017 11:47:06 -0700 (PDT) Subject: Python Command Line Arguments In-Reply-To: References: <41v6sd-6ve.ln1@bernd.nawothnig.dialin.t-online.de> Message-ID: <01938fc6-55e3-41f8-b52b-9f62e5aafdba@googlegroups.com> On Saturday, April 15, 2017 at 6:45:51 PM UTC+1, Grant Edwards wrote: > On 2017-04-14, Bernd Nawothnig wrote: > > > He should switch to argparse in any case because getopt is no longer > > supported and does only receive bugfixes. > > In my book, "receiving bug fixes" means it's still supported. > > -- > Grant Just to reinforce what I said before, optparse is deprecated, not getopt. Kindest regards. Mark Lawrence. From ozovozovozo202 at gmail.com Sat Apr 15 15:34:45 2017 From: ozovozovozo202 at gmail.com (Debiller 777) Date: Sat, 15 Apr 2017 12:34:45 -0700 (PDT) Subject: New implementation(patterns) Message-ID: <622a1dab-a87b-4ff9-9e2a-a16cbe72bf1f@googlegroups.com> So.....Basically recently I just faced with some problem. I wanted to create my own data type. I created new class put something in it. But I really wanted to set items in it like so: ======== >>>datatype[0][0][1]=1 ======== As you could see I used 3 keys.... But magic method __setitem__ alows me only to do something like this: ======= >>>datatype[0,0,1]=1 ======= And that's a little bit uncomortable. Also...I know that probably everyone sometime wanted to 'hide' class name when you create object and not to write this: ======= >>>var=MyClass('David') ======= ...And instead to write this: ======= >>>var= >>>var <__main__.MyClass object at 0x0000006242B13748> ======= I think that would be much easier and glamourus. So here I present you special type of object: pattern Example: ======= >>>&mypattern='<'str'>' ====== Here I created variable that stored pattern This pattern allows me to write '<>' with string in this For example from that momemnt if I type '' Nothing will happen. Also patterns can have commands in them: ====== >>>&mynewpattern='#'list'#' >>> def &mynewpattern: ... return MyClass(list) ====== Here I gave pattern 'mynewpattern' functionality. Now it RETURNS CLASS!!! This way we could make shorter and more beautiful.In the example list is type of data like string or integer. And now I made that when I type lists with '#'s program returns class MyClass. That's concludes explanation of patterns P.S. Ask me in comments if you didnt understand something. From saxri89 at gmail.com Sat Apr 15 15:36:51 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Sat, 15 Apr 2017 12:36:51 -0700 (PDT) Subject: how to get image url from django form Message-ID: <51e7e2ff-c221-4f62-bdb0-963b016eff2f@googlegroups.com> i have create a simple django form where the authentication user can select one of personal images where have upload before and i want do something with that request in my views.py. but i dont know how to take the image url from that request in my view because first i using request.user in the form to take only self user images and i dont know how to continue and finaly i take that images url. the form work great show me only the self user images any idea ? here the code views.py @login_required(login_url="login/") def carlist(request): Myform = MyModelForm(user=request.user) return render(request,'about.html',{'Myform':Myform}) select django form : class MyModelForm(ModelForm): def __init__(self, *args, **kwargs): # extract "user" from kwrags (passed upon form init) if 'user' in kwargs: self.user = kwargs.pop('user') super(MyModelForm, self).__init__(*args, **kwargs) # generate the choices as (display, value). Display is the one that'll be shown to user, value is the one that'll be sent upon submitting (the "value" attribute of