From nospam at dfs.com Fri Apr 1 00:07:45 2016 From: nospam at dfs.com (DFS) Date: Fri, 1 Apr 2016 00:07:45 -0400 Subject: Use pyodbc to count and list tables, columns, indexes, etc In-Reply-To: References: Message-ID: On 3/31/2016 11:44 PM, DFS wrote: > ================================================================ > import pyodbc > > dbName = "D:\test_data.mdb" > conn = pyodbc.connect('DRIVER={Microsoft Access Driver > (*.mdb)};DBQ='+dbName) > cursor = conn.cursor() > > #COUNT TABLES, LIST COLUMNS > tblCount = 0 > for rows in cursor.tables(): > if rows.table_type == "TABLE": #LOCAL TABLES ONLY > tblCount += 1 > print rows.table_name > for fld in cursor.columns(rows.table_name): > print(fld.table_name, fld.column_name) > > print tblCount,"tables" > ================================================================ > > Problem is, the 'for rows' loop executes only once if the 'for fld' loop > is in place. So even if I have 50 tables, the output is like: > > DATA_TYPES > (u'DATA_TYPES', u'FLD_TEXT', -9, u'VARCHAR') > (u'DATA_TYPES', u'FLD_MEMO', -10, u'LONGCHAR') > (u'DATA_TYPES', u'FLD_NBR_BYTE', -6, u'BYTE') > 1 tables > > And no errors are thrown. > > If I comment out the 2 'for fld' lines, it counts and lists all 50 > tables correctly. > > Any ideas? > > Thanks! Never mind! I discovered I just needed a 2nd cursor object for the columns. ----------------------------------------------------------- cursor1 = conn.cursor() cursor2 = conn.cursor() tblCount = 0 for rows in cursor1.tables(): if rows.table_type == "TABLE": tblCount += 1 print rows.table_name for fld in cursor2.columns(rows.table_name): print(fld.table_name, fld.column_name) ----------------------------------------------------------- Works splendiferously. From mark at msapiro.net Fri Apr 1 00:17:16 2016 From: mark at msapiro.net (Mark Sapiro) Date: Thu, 31 Mar 2016 21:17:16 -0700 Subject: Threading is foobared? In-Reply-To: <1459401951.1771032.564341266.6995438B@webmail.messagingengine.com> References: <1459401951.1771032.564341266.6995438B@webmail.messagingengine.com> Message-ID: <56FDF64C.2020101@msapiro.net> Random832 wrote: > Any chance that it could fix reference headers to match? > > Actually, merely prepending the original Message-ID itself to the > references header might be enough to change the reply's situation from > "nephew" ("reply to [missing] sibling") to "grandchild" ("reply to > [missing] reply"), which might be good enough to make threading work > right on most clients, and would be *easy* (whereas maintaining an > ongoing reversible mapping may not be). > > And if it's not too much additional work, maybe throw in an > X-Mailman-Original-Message-ID (and -References if anything is done with > that) field, so that the original state can be recovered. I think these are good ideas. I'm going to try to do something along these lines. > Rather than exclusively rewriting for usenet, maybe the rewritten > headers could also be included in outgoing emails and the archive? > > Putting it in outgoing emails would solve the problem entirely, though > it would mean people get duplicates if they're subscribed to multiple > lists to which something is posted or get CC'd. The archive wouldn't > have this issue. This is more difficult since archiving, gatewaying to Usenet and delivery to list members are asynchronous processes that have no way to communicate with each other. It could be accomplished by doing a Usenet check in the incoming pipeline and putting the Mailman Message-ID in the message metadata or doing the mods at that point, but I don't think I want to expand the scope of something that is non RFC compliant in the first place. I need to think about these things some more. -- Mark Sapiro The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan From mark at msapiro.net Fri Apr 1 00:17:23 2016 From: mark at msapiro.net (Mark Sapiro) Date: Thu, 31 Mar 2016 21:17:23 -0700 Subject: Threading is foobared? In-Reply-To: <1459402204.1771438.564347074.6B36AF7F@webmail.messagingengine.com> References: <1459402204.1771438.564347074.6B36AF7F@webmail.messagingengine.com> Message-ID: <56FDF653.6030206@msapiro.net> Random832 wrote: > One additional thing that would be nice and would solve most of the > duplicate problem with hypothetically including the rewritten > Message-IDs in outgoing emails, would be to detect crossposts to > multiple lists in the same Mailman instance, and to send them to Usenet > (and to subscribers) as a single message, with appropriate headers for a > crosspost. This is difficult to do for various reasons. The main issue is gating to news is asynchronously done by a separate process. Even if the process could reliably determine that another gatewayed list in the installation was a recipient of this post which it could only do by examining explicit addressees and the other list might be a Bcc:, we'd still have to arbitrate somehow which post gets gatewayed to the multiple news groups and which ones get dropped. Although I suppose we could send each one for all the news groups and let the news server figure it out. Anyway, I don't plan to try this. -- Mark Sapiro The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan From gandalf at shopzeus.com Fri Apr 1 01:24:53 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Fri, 1 Apr 2016 07:24:53 +0200 Subject: Set type for datetime intervals Message-ID: <56FE0625.5030901@shopzeus.com> Hello, I need to compare sets of datetime intervals, and make set operations on them: intersect, union, difference etc. One element of a set would be an interval like this: element ::= (start_point_in_time, end_point_in_time) intervalset ::= { element1, element2, .... } Operations on elements: element1.intersect(element2) element1.union(element2) element1.minus(element2) Operations on sets: intervalset1.intersect(intervalset2) intervalset1.union(intervalset2) intervalset1.minus(intervalset2) Does anyone know a library that already implements these functions? Thanks, Laszlo From stefan at dilettant.eu Fri Apr 1 01:34:54 2016 From: stefan at dilettant.eu (Stefan Hagen) Date: Fri, 1 Apr 2016 07:34:54 +0200 Subject: Ammended proposal: Python 832? Re: The next major Python version will be Python 8 In-Reply-To: References: Message-ID: <56FE087E.8030209@dilettant.eu> Sorry for the blunt terseness, but wasn't the plan to target Python 832 i.e. 8.3.2 as a single, frozen thus *eternal* version tag to firstly integrate all beauty (PEP8), good (3.x), bad (2.x) and secondly **never** have to embrace those thrilling, dirty changes again, was it? $ python832 -m stefan Before you write, think, after you read. Am 01.04.16 um 00:26 schrieb Victor Stinner: > Hi, > > Python 3 becomes more and more popular and is close to a dangerous point > where it can become popular that Python 2. The PSF decided that it's > time to elaborate a new secret plan to ensure that Python users suffer > again with a new major release breaking all their legacy code. > > The PSF is happy to announce that the new Python release will be > Python 8! > > Why the version 8? It's just to be greater than Perl 6 and PHP 7, but > it's also a mnemonic for PEP 8. By the way, each minor release will now > multiply the version by 2. With Python 8 released in 2016 and one > release every two years, we will beat Firefox 44 in 2022 (Python 64) and > Windows 2003 in 2032 (Python 2048). > > A major release requires a major change to justify a version bump: the > new killer feature is that it's no longer possible to import a module > which does not respect the PEP 8. It ensures that all your code is pure. > Example: > > $ python8 -c 'import keyword' > Lib/keyword.py:16:1: E122 continuation line missing indentation or outdented > Lib/keyword.py:16:1: E265 block comment should start with '# ' > Lib/keyword.py:50:1: E122 continuation line missing indentation or outdented > (...) > ImportError: no pep8, no glory > > Good news: since *no* module of the current standard library of Python 3 > respect the PEP 8, the standard library will be simplified to one > unique module, which is new in Python 8: pep8. The standard library will > move to the Python Cheeseshop (PyPI), to reply to an old and popular > request. > > > DON'T PANIC! You are still able to import your legacy code into > Python 8, you just have to rename all your modules to add a "_noqa" suffix > to the filename. For example, rename utils.py to utils_noqa.py. A side > effect is that you have to update all imports. For example, replace > "import django" with "import django_noqa". After a study of the PSF, > it's a best option to split again the Python community and make sure > that all users are angry. > > > The plan is that in 10 years, at least 50% of the 77,000 packages on the > Python cheeseshop will be updated to get the "_noqa" tag. After 2020, > the PSF will start to sponsor trolls to harass users of the legacy > Python 3 to force them to migrate to Python 8. > > > Python 8 is a work-in-progress (it's still an alpha version), the > standard library was not removed yet. Hopefully, trying to import any > module of the standard library fails. > > Don't hesitate to propose more ideas to make Python 8 more incompatible > with Python 3! > > Note: The change is already effective in the default branch of Python: > https://hg.python.org/cpython/rev/9aedec2dbc01 > > Have fun, > Victor > -- Stefan Hagen read://stefan-hagen.website talk://0049 151 70 89 64 00 From steve at pearwood.info Fri Apr 1 01:41:14 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 01 Apr 2016 16:41:14 +1100 Subject: Issue with opening a python file References: Message-ID: <56fe09fc$0$1591$c3e8da3$5496439d@news.astraweb.com> On Fri, 1 Apr 2016 02:56 pm, Daniel Ding wrote: > Hello, I'm relatively new to python. > Recently I have been receiving errors every time I attempt to open python > files. When try open them, it sends me directly to the 'Modify Setup' > window. Clicking on repair or modify does not fix the problem, it simply > goes through the repair or modify process and then closes, whilst the > problem still persists. Is there any possible fix for this? Depends. What has changed? Have you upgrade the OS? (Windows 8 apparently tends to auto-update to Windows 10 without warning.) Installed a new version of Python which doesn't work? What happens if you try to launch the Python application directly, without a file? Open a shell (command.exe or cmd.com or whatever Windows calls it) and try entering "python" or "python3". What happens? If you get an error message, try to copy and paste the complete error message into your reply. Otherwise try to type out the actual error message. Don't bother taking a screen-shot unless the message is extremely large: firstly, this mailing list and newsgroup will delete attachments, so you would have to post it to imgur or similar, and secondly, a screen-shot is of no use to anyone using a screen reader. -- Steven From muhkader at gmail.com Fri Apr 1 03:34:20 2016 From: muhkader at gmail.com (A. ElKader) Date: Fri, 1 Apr 2016 10:34:20 +0300 Subject: Help is needed! Message-ID: Hi, I am trying to do the following : I am trying to show the changes in the command line in real time in my Tkinter GUI, I managed to create the GUI and integrate the terminal into it, but I cant bind the buttons with the terminal, my code is : import Tkinterfrom Tkinter import *import subprocessimport osfrom os import system as cmd WINDOW_SIZE = "600x400" top = Tkinter.Tk() top.geometry(WINDOW_SIZE) def helloCallBack(): print "Below is the output from the shell script in terminal" subprocess.call('perl /projects/tfs/users/$USER/scripts_coverage.pl', shell=True)def BasicCovTests(): print "Below is the output from the shell script in terminal" subprocess.call('perl /projects/tfs/users/$USER/basic_coverage_tests.pl', shell=True)def FullCovTests(): print "Below is the output from the shell script in terminal" subprocess.call('perl /projects/tfs/users/$USER/basic_coverage_tests.pl', shell=True) Scripts_coverage = Tkinter.Button(top, text ="Scripts Coverage", command = helloCallBack)Scripts_coverage.pack() Basic_coverage_tests = Tkinter.Button(top, text ="Basic Coverage Tests", command = BasicCovTests)Basic_coverage_tests.pack() Full_coverage_tests = Tkinter.Button(top, text ="Full Coverage Tests", command = FullCovTests)Full_coverage_tests.pack() termf = Frame(top, height=100, width=500) termf.pack(fill=BOTH, expand=YES) wid = termf.winfo_id() os.system('xterm -into %d -geometry 100x20 -sb &' % wid) def send_entry_to_terminal(*args): """*args needed since callback may be called from no arg (button) or one arg (entry) """ cmd("%s" % (BasicCovTests)) top.mainloop() I want win I click the button to see it printing the command in the terminal[image: enter image description here] How do I do that ??? Please advice From antoon.pardon at rece.vub.ac.be Fri Apr 1 03:59:23 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 1 Apr 2016 09:59:23 +0200 Subject: Suggestion: make sequence and map interfaces more similar In-Reply-To: References: <56fb677f$0$11121$c3e8da3@news.astraweb.com> <56fba7d3$0$1616$c3e8da3$5496439d@news.astraweb.com> <56fbc518$0$1593$c3e8da3$5496439d@news.astraweb.com> <56fbf73d$0$1591$c3e8da3$5496439d@news.astraweb.com> <56fc8e09$0$1600$c3e8da3$5496439d@news.astraweb.com> <56fcfdc6$0$1612$c3e8da3$5496439d@news.astraweb.com> <56FD086F.2090301@rece.vub.ac.be> <56FD2158.2050406@rece.vub.ac.be> <1459430873.2282305.564680498.6FEA3042@webmail.messagingengine.com> Message-ID: <56FE2A5B.8000804@rece.vub.ac.be> Op 31-03-16 om 16:12 schreef Mark Lawrence via Python-list: > On 31/03/2016 14:27, Random832 wrote: >> So can we discuss how a unified method to get a set of all valid >> subscripts (and/or subscript-value pairs) on an object would be a useful >> thing to have without getting bogged down in theoretical claptrap about >> the meaning of the mapping contract? >> > > We can discuss anything here until the cows come home, but it's a > complete waste of time if the powers that be over on python-ideas > and/or python-dev don't agree. This was suggested a day or two back > but seems to have gone completely over people's heads. Just because you are not interested, doesn't mean it's a complete waste of time. Discussions like this often enough produce suggestions on how one could handle these things within python without the need for the powers that be to agree on anything. If you are not interested just don't contribute. Others can make up their own mind on whether this is a waste of their time or not. -- Antoon. From michael.selik at gmail.com Fri Apr 1 04:19:56 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 1 Apr 2016 04:19:56 -0400 Subject: Suggestion: make sequence and map interfaces more similar In-Reply-To: <87lh4ylp8p.fsf@elektro.pacujo.net> References: <56fb677f$0$11121$c3e8da3@news.astraweb.com> <56fba7d3$0$1616$c3e8da3$5496439d@news.astraweb.com> <56fbc518$0$1593$c3e8da3$5496439d@news.astraweb.com> <56fbf73d$0$1591$c3e8da3$5496439d@news.astraweb.com> <56fc8e09$0$1600$c3e8da3$5496439d@news.astraweb.com> <56fcfdc6$0$1612$c3e8da3$5496439d@news.astraweb.com> <56FD086F.2090301@rece.vub.ac.be> <87poualt87.fsf@elektro.pacujo.net> <87lh4ylp8p.fsf@elektro.pacujo.net> Message-ID: > On Mar 31, 2016, at 10:02 AM, Marko Rauhamaa wrote: > > However, weirdly, dicts have get but lists don't. Read PEP 463 for discussion on this topic. https://www.python.org/dev/peps/pep-0463/ From mail at timgolden.me.uk Fri Apr 1 04:27:25 2016 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 1 Apr 2016 09:27:25 +0100 Subject: Suggestion: make sequence and map interfaces more similar In-Reply-To: <56FE2A5B.8000804@rece.vub.ac.be> References: <56fb677f$0$11121$c3e8da3@news.astraweb.com> <56fba7d3$0$1616$c3e8da3$5496439d@news.astraweb.com> <56fbc518$0$1593$c3e8da3$5496439d@news.astraweb.com> <56fbf73d$0$1591$c3e8da3$5496439d@news.astraweb.com> <56fc8e09$0$1600$c3e8da3$5496439d@news.astraweb.com> <56fcfdc6$0$1612$c3e8da3$5496439d@news.astraweb.com> <56FD086F.2090301@rece.vub.ac.be> <56FD2158.2050406@rece.vub.ac.be> <1459430873.2282305.564680498.6FEA3042@webmail.messagingengine.com> <56FE2A5B.8000804@rece.vub.ac.be> Message-ID: <56FE30ED.90406@timgolden.me.uk> On 01/04/2016 08:59, Antoon Pardon wrote: > Op 31-03-16 om 16:12 schreef Mark Lawrence via Python-list: >> On 31/03/2016 14:27, Random832 wrote: >>> So can we discuss how a unified method to get a set of all valid >>> subscripts (and/or subscript-value pairs) on an object would be a useful >>> thing to have without getting bogged down in theoretical claptrap about >>> the meaning of the mapping contract? >>> >> >> We can discuss anything here until the cows come home, but it's a >> complete waste of time if the powers that be over on python-ideas >> and/or python-dev don't agree. This was suggested a day or two back >> but seems to have gone completely over people's heads. > > Just because you are not interested, doesn't mean it's a complete waste of time. > Discussions like this often enough produce suggestions on how one could handle > these things within python without the need for the powers that be to agree on > anything. > > If you are not interested just don't contribute. Others can make up their own > mind on whether this is a waste of their time or not. FWIW I'm broadly with Antoon here: wider-ranging discussions can be interesting and useful. (And informative, especially where people speak knowledgeably about an area outside my own competence). There *are* technical forums where anything outside their strict subject matter is frowned upon or curtailed. I don't think we need to be that rigid here. However I think there are a couple of lines which can be crossed. In one case a a poster (perhaps abruptly) says: I think Python should do this; why doesn't it? The other is where the discussion goes so far into cloud-cuckoo land that it alienates all but a few devoted adherents to the thread. Especially where it goes round in circles. For the latter, I take the view that I know where the delete key is (or the "ignore thread" button or whatever) and I just skip the thread when it shows up. Perhaps missing some interesting points in the process if it comes back down to earth but that's the way it goes. For the former, I think it's fine if someone is asking in a genuine spirit of enquiry, ie to learn about the history of a particular decision or the ramifications of an alternative which might not be obvious at first glance. (Why do we have both lists and tuples? Why does Python index from 0? etc). People who know something about it can explain if they wish. If it becomes clear that the poster is in fact pushing for a change (either intelligently thought-out or naively ill-considered) then I would push them towards Python-ideas sooner than later, because that's exactly the purpose of *that* mailing list. People on python-ideas want to go to and fro over the relative merits of proposals. Specifically, I believe that's the only mailing list which GvR follows apart from python-dev. Any discussion here would likely have to be repeated over there anyway, so why not go there earlier on? Courtesy & respect on this and any list are important, so as long as someone's not being genuinely rude or abusive, your best plan is to make your point clearly and politely and then step back. I've been impressed again and again on Python lists where people maintain a courteous front in the course of a perhaps quite heated discussion. And more impressed when people who have lost their cool come back and apologise (without necessarily backing down from their point, of course). Feel free to contact the list owner [python-list-owner at python.org] if you think there's a real contravention of the list etiquette but I'm personally not inclined to jump too heavily on rambling discussions or wild-eyed ideas as such. TJG From michael.selik at gmail.com Fri Apr 1 04:30:06 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 01 Apr 2016 08:30:06 +0000 Subject: The next major Python version will be Python 8 In-Reply-To: <56fdf000$0$1607$c3e8da3$5496439d@news.astraweb.com> References: <56FDBC3B.80202@stoneleaf.us> <56fdf000$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: It suddenly occurred to me that if Microsoft announced it's Ubuntu-in-Windows feature today, no one would believe it. On Thu, Mar 31, 2016 at 11:55 PM Steven D'Aprano wrote: > On Fri, 1 Apr 2016 11:13 am, Chris Angelico wrote: > > > Now's the time to get in with the ideas. My proposal is that Python 8, > > in keeping with its new opinionated style, will require everyone to > > follow a single timezone: Europe/Amsterdam. > > Swatch Internet time: > > https://en.wikipedia.org/wiki/Swatch_Internet_Time > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list > From breamoreboy at yahoo.co.uk Fri Apr 1 05:04:04 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 1 Apr 2016 10:04:04 +0100 Subject: Suggestion: make sequence and map interfaces more similar In-Reply-To: <56FE2A5B.8000804@rece.vub.ac.be> References: <56fb677f$0$11121$c3e8da3@news.astraweb.com> <56fba7d3$0$1616$c3e8da3$5496439d@news.astraweb.com> <56fbc518$0$1593$c3e8da3$5496439d@news.astraweb.com> <56fbf73d$0$1591$c3e8da3$5496439d@news.astraweb.com> <56fc8e09$0$1600$c3e8da3$5496439d@news.astraweb.com> <56fcfdc6$0$1612$c3e8da3$5496439d@news.astraweb.com> <56FD086F.2090301@rece.vub.ac.be> <56FD2158.2050406@rece.vub.ac.be> <1459430873.2282305.564680498.6FEA3042@webmail.messagingengine.com> <56FE2A5B.8000804@rece.vub.ac.be> Message-ID: On 01/04/2016 08:59, Antoon Pardon wrote: > Op 31-03-16 om 16:12 schreef Mark Lawrence via Python-list: >> On 31/03/2016 14:27, Random832 wrote: >>> So can we discuss how a unified method to get a set of all valid >>> subscripts (and/or subscript-value pairs) on an object would be a useful >>> thing to have without getting bogged down in theoretical claptrap about >>> the meaning of the mapping contract? >>> >> >> We can discuss anything here until the cows come home, but it's a >> complete waste of time if the powers that be over on python-ideas >> and/or python-dev don't agree. This was suggested a day or two back >> but seems to have gone completely over people's heads. > > Just because you are not interested, doesn't mean it's a complete waste of time. > Discussions like this often enough produce suggestions on how one could handle > these things within python without the need for the powers that be to agree on > anything. > > If you are not interested just don't contribute. Others can make up their own > mind on whether this is a waste of their time or not. > Who said I'm not interested? It is a simple fact of life in Python world that anything that gets discussed has to go through python-dev, and possibly python-ideas first. You can spend years discussing anything you like here and get 100% agreement, but if the devlopers say no it does not happen. I believe that this proposal is like trying to change the design of the Morris Minor and a McClaren Mercedes because they're both cars, so you can make them similar. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From alister.ware at ntlworld.com Fri Apr 1 05:44:42 2016 From: alister.ware at ntlworld.com (alister) Date: Fri, 01 Apr 2016 09:44:42 GMT Subject: The next major Python version will be Python 8 Message-ID: On Fri, 01 Apr 2016 11:13:43 +1100, Chris Angelico wrote: > On Fri, Apr 1, 2016 at 11:09 AM, Ethan Furman > wrote: >> On 03/31/2016 05:02 PM, Roel Schroeven wrote: >>> >>> Victor Stinner schreef op 2016-03-31 23:40: >> >> >>>> Python 3 becomes more and more popular and is close to a dangerous >>>> point where it can become popular that Python 2. The PSF decided that >>>> it's time to elaborate a new secret plan to ensure that Python users >>>> suffer again with a new major release breaking all their legacy code. >>> >>> >>> "2016-03-31 23:40" >>> You're 20 minutes early :) >> >> >> No, that's a naive datetime. You need to travel to Victor's location >> to figure out what that is there. >> >> I sure hope Python 8 doesn't have that problem! > > Now's the time to get in with the ideas. My proposal is that Python 8, > in keeping with its new opinionated style, will require everyone to > follow a single timezone: Europe/Amsterdam. > > ChrisA Not bad but it would have to be Zulu (GMT) -- Nobody's gonna believe that computers are intelligent until they start coming in late and lying about it. From rosuav at gmail.com Fri Apr 1 05:57:45 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Apr 2016 20:57:45 +1100 Subject: The next major Python version will be Python 8 In-Reply-To: References: Message-ID: On Fri, Apr 1, 2016 at 8:44 PM, alister wrote: > On Fri, 01 Apr 2016 11:13:43 +1100, Chris Angelico wrote: > >> Now's the time to get in with the ideas. My proposal is that Python 8, >> in keeping with its new opinionated style, will require everyone to >> follow a single timezone: Europe/Amsterdam. >> >> ChrisA > > Not bad but it would have to be Zulu (GMT) Why? Nothing in Python's documentation ever says you have to be a Zuul to understand its design choices! ChrisA From steve at pearwood.info Fri Apr 1 06:38:50 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 01 Apr 2016 21:38:50 +1100 Subject: Suggestion: make sequence and map interfaces more similar References: <56fb677f$0$11121$c3e8da3@news.astraweb.com> <56fba7d3$0$1616$c3e8da3$5496439d@news.astraweb.com> <56fbc518$0$1593$c3e8da3$5496439d@news.astraweb.com> <56fbf73d$0$1591$c3e8da3$5496439d@news.astraweb.com> <56fc8e09$0$1600$c3e8da3$5496439d@news.astraweb.com> <56fcfdc6$0$1612$c3e8da3$5496439d@news.astraweb.com> <56FD086F.2090301@rece.vub.ac.be> <56FD2158.2050406@rece.vub.ac.be> <1459430873.2282305.564680498.6FEA3042@webmail.messagingengine.com> <56FE2A5B.8000804@rece.vub.ac.be> Message-ID: <56fe4fbc$0$22142$c3e8da3$5496439d@news.astraweb.com> On Fri, 1 Apr 2016 07:27 pm, Tim Golden wrote: > FWIW I'm broadly with Antoon here: wider-ranging discussions can be > interesting and useful. Sure. But sometimes conversations are going nowhere: http://www.youtube.com/watch?v=kQFKtI6gn9Y http://www.montypython.net/scripts/argument.php [...] > If it becomes clear that the poster is in fact pushing for a change > (either intelligently thought-out or naively ill-considered) then I > would push them towards Python-ideas sooner than later, because that's > exactly the purpose of *that* mailing list. People on python-ideas want > to go to and fro over the relative merits of proposals. Specifically, I > believe that's the only mailing list which GvR follows apart from > python-dev. Any discussion here would likely have to be repeated over > there anyway, so why not go there earlier on? Informally, ideas are supposed to have an initial "sanity check" here to avoid the really silly ideas: Q: "Suggestion: I'm sick of writing for key, value in other_dict.items(): mydict[key] = value I think that dicts should have a method to copy all the keys and values from another dict." A: "You mean dict.update?" Or perhaps: Q: "I think that object oriented programming is too inefficient. I think that Python should get rid of all the objects and just be a lightweight, easy-to-read wrapper around C, with the same semantics and limitations as the 1988 C standard." A: "Surely you aren't serious?" But most people don't bother passing ideas through here first, they just go straight to Python-Ideas. -- Steven From marko at pacujo.net Fri Apr 1 06:50:18 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 01 Apr 2016 13:50:18 +0300 Subject: Suggestion: make sequence and map interfaces more similar References: <56fba7d3$0$1616$c3e8da3$5496439d@news.astraweb.com> <56fbc518$0$1593$c3e8da3$5496439d@news.astraweb.com> <56fbf73d$0$1591$c3e8da3$5496439d@news.astraweb.com> <56fc8e09$0$1600$c3e8da3$5496439d@news.astraweb.com> <56fcfdc6$0$1612$c3e8da3$5496439d@news.astraweb.com> <56FD086F.2090301@rece.vub.ac.be> <56FD2158.2050406@rece.vub.ac.be> <1459430873.2282305.564680498.6FEA3042@webmail.messagingengine.com> <56FE2A5B.8000804@rece.vub.ac.be> <56fe4fbc$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8737r5li1h.fsf@elektro.pacujo.net> Steven D'Aprano : > On Fri, 1 Apr 2016 07:27 pm, Tim Golden wrote: > >> FWIW I'm broadly with Antoon here: wider-ranging discussions can be >> interesting and useful. > > Sure. But sometimes conversations are going nowhere: That's why GNUS has the "k" command to wipe out a whole thread. I know, it depends on threading working... Marko From saxri89 at gmail.com Fri Apr 1 06:56:39 2016 From: saxri89 at gmail.com (saxri89 at gmail.com) Date: Fri, 1 Apr 2016 03:56:39 -0700 (PDT) Subject: install open cv on windows 10 and python 3.5 Message-ID: <8b4a2755-388a-43fa-8ab3-ae416ff87950@googlegroups.com> hello, i have windows 10 and python 3.5 and i want to use open cv but i think so opencv work only on python 2.7 ? and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv but not work again From gvanem at yahoo.no Fri Apr 1 09:06:20 2016 From: gvanem at yahoo.no (Gisle Vanem) Date: Fri, 1 Apr 2016 15:06:20 +0200 Subject: The next major Python version will be Python 8 In-Reply-To: References: <56FDBC3B.80202@stoneleaf.us> <56fdf000$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: <56FE724C.3010108@yahoo.no> Michael Selik wrote: > It suddenly occurred to me that if Microsoft announced it's > Ubuntu-in-Windows feature today, no one would believe it. My feeling too, but this was announced 30 March. In the video in this link: http://www.cnx-software.com/2016/03/31/microsoft-brings-bash-on-ubuntu-on-windows-10/ they say Python inside Ubuntu-in-Windows works! Ref. time 03:03. -- --gv From marko at pacujo.net Fri Apr 1 09:15:41 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 01 Apr 2016 16:15:41 +0300 Subject: Strange range Message-ID: <87y48xjwqq.fsf@elektro.pacujo.net> This seems sane: >>> it = iter(range(10)) >>> for i in it: ... if i >= 3: ... break ... >>> list(it) [4, 5, 6, 7, 8, 9] As does this: >>> it = iter(list(range(10))) >>> for i in it: ... if i >= 3: ... break ... >>> list(it) [4, 5, 6, 7, 8, 9] This not so much: >>> it = range(10) >>> for i in it: ... if i >= 3: ... break ... >>> list(it) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Note to self: range(10) is an iterator factory, not an iterator. Marko From rosuav at gmail.com Fri Apr 1 09:24:49 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Apr 2016 00:24:49 +1100 Subject: Strange range In-Reply-To: <87y48xjwqq.fsf@elektro.pacujo.net> References: <87y48xjwqq.fsf@elektro.pacujo.net> Message-ID: On Sat, Apr 2, 2016 at 12:15 AM, Marko Rauhamaa wrote: > Note to self: range(10) is an iterator factory, not an iterator. It is an iterable. It is not a factory, as that implies that you call it. It is an object which, when you ask it for an iterator, gives you an iterator. That's called an iterable. ChrisA From steve at pearwood.info Fri Apr 1 09:26:09 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 02 Apr 2016 00:26:09 +1100 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> Message-ID: <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> On Sat, 2 Apr 2016 12:15 am, Marko Rauhamaa wrote: > > This seems sane: [...] > This not so much: > > >>> it = range(10) > >>> for i in it: > ... if i >= 3: > ... break > ... > >>> list(it) > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > > Note to self: range(10) is an iterator factory, not an iterator. Incorrect. range is a lazy sequence. The only difference between [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] and range(10) is that the list [0, ..., 9] is calculated eagerly, ahead of time, while range(10) only generates the values on demand. You can think of range as equivalent to something close to this: class Range(object): def __init__(self, start, end, step=1): self.start = start self.end = end self.step = step def __getitem__(self, index): value = self.start + (index-1)*self.step if value < self.end: return value raise IndexError def __iter__(self): try: index = 0 while True: yield self[index] index += 1 except IndexError: return except with more error checking, better bounds checking, support for the `in` operator, etc. -- Steven From marko at pacujo.net Fri Apr 1 10:12:49 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 01 Apr 2016 17:12:49 +0300 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87twjlju3i.fsf@elektro.pacujo.net> Steven D'Aprano : > On Sat, 2 Apr 2016 12:15 am, Marko Rauhamaa wrote: >> Note to self: range(10) is an iterator factory, not an iterator. > > Incorrect. range is a lazy sequence. Incorrect. You and I agree. > You can think of range as equivalent to something close to this: > > class Range(object): > def __init__(self, start, end, step=1): > self.start = start > self.end = end > self.step = step > > def __getitem__(self, index): > value = self.start + (index-1)*self.step > if value < self.end: > return value > raise IndexError > > def __iter__(self): > try: > index = 0 > while True: > yield self[index] > index += 1 > except IndexError: > return Yes, I realize it now. I had thought it was: def range(start, end=None, step=1): if end is None: start, end = 0, start i = start while step * (end - i) > 0: yield i i += step Marko From fabien.maussion at gmail.com Fri Apr 1 10:16:30 2016 From: fabien.maussion at gmail.com (Fabien) Date: Fri, 1 Apr 2016 16:16:30 +0200 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/01/2016 03:26 PM, Steven D'Aprano wrote: > Incorrect. range is a lazy sequence. But how does range "know" that it has to start from scratch again? As in this example: it = range(10) for i in it: if i >= 3: break for i in it: # why does it start from zero again? print(i) From jussi.piitulainen at helsinki.fi Fri Apr 1 10:28:40 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 01 Apr 2016 17:28:40 +0300 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> Message-ID: Fabien writes: > On 04/01/2016 03:26 PM, Steven D'Aprano wrote: >> Incorrect. range is a lazy sequence. > > But how does range "know" that it has to start from scratch again? As > in this example: > > it = range(10) > for i in it: > if i >= 3: > break > for i in it: > # why does it start from zero again? > print(i) The loops are effectively iterating over iter(it) each time. Since "it" is not already an iterator, iter constructs a new one based on "it". Try it = iter(range(10)) to see it not start over. From rosuav at gmail.com Fri Apr 1 10:31:20 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Apr 2016 01:31:20 +1100 Subject: Strange range In-Reply-To: References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 2, 2016 at 1:16 AM, Fabien wrote: > On 04/01/2016 03:26 PM, Steven D'Aprano wrote: >> >> Incorrect. range is a lazy sequence. > > > But how does range "know" that it has to start from scratch again? As in > this example: > > it = range(10) > for i in it: > if i >= 3: > break > for i in it: > # why does it start from zero again? > print(i) It's not an iterator. It's an iterable. So every time you call iter() on it - which is done implicitly by the starting of the 'for' loop - you get a completely new iterator which will step through the whole range object. *A range object is not an iterator.* ChrisA From invalid at invalid.invalid Fri Apr 1 10:31:59 2016 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 1 Apr 2016 14:31:59 +0000 (UTC) Subject: The next major Python version will be Python 8 References: Message-ID: On 2016-04-01, alister wrote: > On Fri, 01 Apr 2016 11:13:43 +1100, Chris Angelico wrote: > >> On Fri, Apr 1, 2016 at 11:09 AM, Ethan Furman >> wrote: >>> On 03/31/2016 05:02 PM, Roel Schroeven wrote: >>>> >>>> Victor Stinner schreef op 2016-03-31 23:40: >>> >>> >>>>> Python 3 becomes more and more popular and is close to a dangerous >>>>> point where it can become popular that Python 2. The PSF decided that >>>>> it's time to elaborate a new secret plan to ensure that Python users >>>>> suffer again with a new major release breaking all their legacy code. >>>> >>>> >>>> "2016-03-31 23:40" >>>> You're 20 minutes early :) >>> >>> >>> No, that's a naive datetime. You need to travel to Victor's location >>> to figure out what that is there. >>> >>> I sure hope Python 8 doesn't have that problem! >> >> Now's the time to get in with the ideas. My proposal is that Python 8, >> in keeping with its new opinionated style, will require everyone to >> follow a single timezone: Europe/Amsterdam. > > Not bad but it would have to be Zulu (GMT) Nope, my vote is for TAI. It's even more opinionated. That whole making the time agree with the changing rotation of the Earth thing is just too wishy-washy. -- Grant Edwards grant.b.edwards Yow! ... I don't like FRANK at SINATRA or his CHILDREN. gmail.com From marko at pacujo.net Fri Apr 1 10:32:35 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 01 Apr 2016 17:32:35 +0300 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87pou9jt6k.fsf@elektro.pacujo.net> Fabien : > On 04/01/2016 03:26 PM, Steven D'Aprano wrote: >> Incorrect. range is a lazy sequence. > > But how does range "know" that it has to start from scratch again? The "for .. in" statement invokes the __iter__() method of the iterable object to get an iterator (maybe via the builtin iter() function). Iterators have an __iter__() method as well which returns the iterator itself. Thus, >>> it = iter(range(10)) >>> it is iter(it) True Marko From marko at pacujo.net Fri Apr 1 10:34:36 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 01 Apr 2016 17:34:36 +0300 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87lh4xjt37.fsf@elektro.pacujo.net> Chris Angelico : > *A range object is not an iterator.* We now have learned as much. However, doesn't that extra level of indirection seem like an odd choice? Marko From random832 at fastmail.com Fri Apr 1 10:39:45 2016 From: random832 at fastmail.com (Random832) Date: Fri, 01 Apr 2016 10:39:45 -0400 Subject: Strange range In-Reply-To: <87twjlju3i.fsf@elektro.pacujo.net> References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87twjlju3i.fsf@elektro.pacujo.net> Message-ID: <1459521585.2603170.565810994.3096ECD3@webmail.messagingengine.com> On Fri, Apr 1, 2016, at 10:12, Marko Rauhamaa wrote: > Yes, I realize it now. I had thought it was: > > def range(start, end=None, step=1): > if end is None: > start, end = 0, start > i = start > while step * (end - i) > 0: > yield i > i += step You know the other funny thing? Even people who understand this about Python 3 ranges, many assume that python 2 xrange was more similar to your latter example (possibly caused by the fact that python 2 had other things such as dict.iteritems which _were_ mere iterators) From rustompmody at gmail.com Fri Apr 1 10:41:12 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 1 Apr 2016 07:41:12 -0700 (PDT) Subject: Suggestion: make sequence and map interfaces more similar In-Reply-To: References: <56fb677f$0$11121$c3e8da3@news.astraweb.com> <56fba7d3$0$1616$c3e8da3$5496439d@news.astraweb.com> <56fbc518$0$1593$c3e8da3$5496439d@news.astraweb.com> <56fbf73d$0$1591$c3e8da3$5496439d@news.astraweb.com> <56fc8e09$0$1600$c3e8da3$5496439d@news.astraweb.com> <56fcfdc6$0$1612$c3e8da3$5496439d@news.astraweb.com> <56FD086F.2090301@rece.vub.ac.be> <56FD2158.2050406@rece.vub.ac.be> <1459430873.2282305.564680498.6FEA3042@webmail.messagingengine.com> <56FE2A5B.8000804@rece.vub.ac.be> Message-ID: On Friday, April 1, 2016 at 1:58:29 PM UTC+5:30, Tim Golden wrote: > > For the latter, I take the view that I know where the delete key is (or > the "ignore thread" button or whatever) and I just skip the thread when > it shows up. > Feel free to contact the list owner [python list-owner] if > you think there's a real contravention of the list etiquette but I'm > personally not inclined to jump too heavily on rambling discussions or > wild-eyed ideas as such. I thought sanity was frowned upon out here From random832 at fastmail.com Fri Apr 1 10:42:09 2016 From: random832 at fastmail.com (Random832) Date: Fri, 01 Apr 2016 10:42:09 -0400 Subject: Strange range In-Reply-To: References: <87y48xjwqq.fsf@elektro.pacujo.net> Message-ID: <1459521729.2604028.565815842.7D7557F9@webmail.messagingengine.com> On Fri, Apr 1, 2016, at 09:24, Chris Angelico wrote: > It is an iterable. It is not a factory, as that implies that you call > it. I do have an objection to this statement. It's perfectly reasonable to describe the factory pattern as applying to objects on which you call a method to return the new object you are interested in. In this sense, all collections are iterator factories. From jussi.piitulainen at helsinki.fi Fri Apr 1 10:44:42 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 01 Apr 2016 17:44:42 +0300 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa writes: > Chris Angelico wrote: > >> *A range object is not an iterator.* > > We now have learned as much. > > However, doesn't that extra level of indirection seem like an odd > choice? I think it's brilliant. The range object behaves like a tuple containing the numbers in the range, one can index it, slice it, zip it, for it, like it, without it taking up the space or getting consumed in the process. From rosuav at gmail.com Fri Apr 1 10:45:00 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Apr 2016 01:45:00 +1100 Subject: Strange range In-Reply-To: <87lh4xjt37.fsf@elektro.pacujo.net> References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> Message-ID: On Sat, Apr 2, 2016 at 1:34 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> *A range object is not an iterator.* > > We now have learned as much. > > However, doesn't that extra level of indirection seem like an odd > choice? No; a range object is an entity in itself. You can test if something's within the range: >>> 5 in range(2,10) True >>> 5 in range(2,10,2) False You can ask how many numbers are in the range: >>> len(range(2,10,2)) 4 You can even ask what position a number would be in, if you index through the range: >>> range(3,100,3).index(57) 18 Iterators can't do any of this, except the 'in' check, which is destructive and O(N). ChrisA From rosuav at gmail.com Fri Apr 1 10:50:06 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Apr 2016 01:50:06 +1100 Subject: Strange range In-Reply-To: <1459521729.2604028.565815842.7D7557F9@webmail.messagingengine.com> References: <87y48xjwqq.fsf@elektro.pacujo.net> <1459521729.2604028.565815842.7D7557F9@webmail.messagingengine.com> Message-ID: On Sat, Apr 2, 2016 at 1:42 AM, Random832 wrote: > On Fri, Apr 1, 2016, at 09:24, Chris Angelico wrote: >> It is an iterable. It is not a factory, as that implies that you call >> it. > > I do have an objection to this statement. It's perfectly reasonable to > describe the factory pattern as applying to objects on which you call a > method to return the new object you are interested in. In this sense, > all collections are iterator factories. Hmm. I suppose that would be reasonable, if you expect to call range_object.__iter__() - but you shouldn't. You should call iter(range_object), which, to my mind, means that *iter* is an iterator factory. Anyway, the word "iterable" accurately sums up the state: it's a thing you can iterate over. ChrisA From ian.g.kelly at gmail.com Fri Apr 1 10:52:27 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 1 Apr 2016 08:52:27 -0600 Subject: Strange range In-Reply-To: <1459521729.2604028.565815842.7D7557F9@webmail.messagingengine.com> References: <87y48xjwqq.fsf@elektro.pacujo.net> <1459521729.2604028.565815842.7D7557F9@webmail.messagingengine.com> Message-ID: On Fri, Apr 1, 2016 at 8:42 AM, Random832 wrote: > On Fri, Apr 1, 2016, at 09:24, Chris Angelico wrote: >> It is an iterable. It is not a factory, as that implies that you call >> it. > > I do have an objection to this statement. It's perfectly reasonable to > describe the factory pattern as applying to objects on which you call a > method to return the new object you are interested in. In this sense, > all collections are iterator factories. I think the problem with that is that it implies something about the purpose of the object. Usually when we talk about the factory pattern, we're talking about an object that creates instances of something and does nothing else. So in that sense it's misleading to refer to dict or list or even range objects as "iterator factories", because they also do a lot of other things that are equally if not more important. From random832 at fastmail.com Fri Apr 1 11:09:54 2016 From: random832 at fastmail.com (Random832) Date: Fri, 01 Apr 2016 11:09:54 -0400 Subject: Set type for datetime intervals In-Reply-To: <56FE0625.5030901@shopzeus.com> References: <56FE0625.5030901@shopzeus.com> Message-ID: <1459523394.2611014.565840994.593DD99A@webmail.messagingengine.com> On Fri, Apr 1, 2016, at 01:24, Nagy L?szl? Zsolt wrote: > > Hello, > > I need to compare sets of datetime intervals, and make set operations on > them: intersect, union, difference etc. One element of a set would be an > interval like this: Two thoughts on this: Such an object is not precisely a set* of datetimes, rather it is a set of nonintersecting intervals. It could also be useful to have one for numbers (the datetime version could even maybe be implemented in terms of it) *in the python sense. in the mathematical sense, it is a set with infinite* cardinality **well, datetimes have a fixed resolution, so it's not _really_ infinite. Numbers don't, though. > element ::= (start_point_in_time, end_point_in_time) > intervalset ::= { element1, element2, .... } Are these open intervals or closed intervals? Also, how are you going to handle daylight savings? From gheskett at wdtv.com Fri Apr 1 11:36:43 2016 From: gheskett at wdtv.com (Gene Heskett) Date: Fri, 1 Apr 2016 11:36:43 -0400 Subject: The next major Python version will be Python 8 In-Reply-To: <56FE724C.3010108@yahoo.no> References: <56FE724C.3010108@yahoo.no> Message-ID: <201604011136.43851.gheskett@wdtv.com> On Friday 01 April 2016 09:06:20 Gisle Vanem via Python-list wrote: > Michael Selik wrote: > > It suddenly occurred to me that if Microsoft announced it's > > Ubuntu-in-Windows feature today, no one would believe it. > > My feeling too, but this was announced 30 March. > In the video in this link: > > http://www.cnx-software.com/2016/03/31/microsoft-brings-bash-on-ubuntu >-on-windows-10/ > > they say Python inside Ubuntu-in-Windows works! Ref. time 03:03. > > -- > --gv I am inclined to think that because microsoft just "has to be first" even when they are last, they chose to do it a full 2 days early. Me? I'm from Missouri. And I don't know of anyone in my neck of the woods who is running winderz-10 so I could go ask them. Shrug. 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 marko at pacujo.net Fri Apr 1 11:43:01 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 01 Apr 2016 18:43:01 +0300 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> Message-ID: <87a8lds5bu.fsf@elektro.pacujo.net> Chris Angelico : > On Sat, Apr 2, 2016 at 1:34 AM, Marko Rauhamaa wrote: >> However, doesn't that extra level of indirection seem like an odd >> choice? > > No; a range object is an entity in itself. You can test if something's > within the range: > >>>> 5 in range(2,10) > True >>>> 5 in range(2,10,2) > False > > You can ask how many numbers are in the range: > >>>> len(range(2,10,2)) > 4 > > You can even ask what position a number would be in, if you index > through the range: > >>>> range(3,100,3).index(57) > 18 > > Iterators can't do any of this, except the 'in' check, which is > destructive and O(N). I can't think of a situation where I would have needed those things. I'm hard-pressed to find an example of noniterator usage of range in the standard library, for example. Here the only counterexample that caught my eye among the first couple of hundred of occurrences: reversed(range(len(self))) Marko From wxjmfauth at gmail.com Fri Apr 1 11:44:16 2016 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 1 Apr 2016 08:44:16 -0700 (PDT) Subject: The next major Python version will be Python 8 In-Reply-To: References: Message-ID: Le vendredi 1 avril 2016 00:04:44 UTC+2, Victor Stinner a ?crit?: > Hi, > > Python 3 becomes more and more popular and is close to a dangerous point > where it can become popular that Python 2. The PSF decided that it's > time to elaborate a new secret plan to ensure that Python users suffer > again with a new major release breaking all their legacy code. > > The PSF is happy to announce that the new Python release will be > Python 8! > > Why the version 8? It's just to be greater than Perl 6 and PHP 7, but > it's also a mnemonic for PEP 8. By the way, each minor release will now > multiply the version by 2. With Python 8 released in 2016 and one > release every two years, we will beat Firefox 44 in 2022 (Python 64) and > Windows 2003 in 2032 (Python 2048). > > A major release requires a major change to justify a version bump: the > new killer feature is that it's no longer possible to import a module > which does not respect the PEP 8. It ensures that all your code is pure. > Example: > > $ python8 -c 'import keyword' > Lib/keyword.py:16:1: E122 continuation line missing indentation or outdented > Lib/keyword.py:16:1: E265 block comment should start with '# ' > Lib/keyword.py:50:1: E122 continuation line missing indentation or outdented > (...) > ImportError: no pep8, no glory > > Good news: since *no* module of the current standard library of Python 3 > respect the PEP 8, the standard library will be simplified to one > unique module, which is new in Python 8: pep8. The standard library will > move to the Python Cheeseshop (PyPI), to reply to an old and popular > request. > > > DON'T PANIC! You are still able to import your legacy code into > Python 8, you just have to rename all your modules to add a "_noqa" suffix > to the filename. For example, rename utils.py to utils_noqa.py. A side > effect is that you have to update all imports. For example, replace > "import django" with "import django_noqa". After a study of the PSF, > it's a best option to split again the Python community and make sure > that all users are angry. > > > The plan is that in 10 years, at least 50% of the 77,000 packages on the > Python cheeseshop will be updated to get the "_noqa" tag. After 2020, > the PSF will start to sponsor trolls to harass users of the legacy > Python 3 to force them to migrate to Python 8. > > > Python 8 is a work-in-progress (it's still an alpha version), the > standard library was not removed yet. Hopefully, trying to import any > module of the standard library fails. > > Don't hesitate to propose more ideas to make Python 8 more incompatible > with Python 3! > > Note: The change is already effective in the default branch of Python: > https://hg.python.org/cpython/rev/9aedec2dbc01 > > Have fun, > Victor Tr?s bonne id?e. Et d'ailleurs, Python 8 arr?tera de se planter d?s que l'on utilisera un e accent aigu, (U+00E9) ou un ? (U+00FC) comme dans "ETH Z?rich". Salutations. From random832 at fastmail.com Fri Apr 1 11:45:37 2016 From: random832 at fastmail.com (Random832) Date: Fri, 01 Apr 2016 11:45:37 -0400 Subject: Set type for datetime intervals In-Reply-To: <56FE0625.5030901@shopzeus.com> References: <56FE0625.5030901@shopzeus.com> Message-ID: <1459525537.2619077.565849418.5270FACE@webmail.messagingengine.com> More thoughts... sorry. On Fri, Apr 1, 2016, at 01:24, Nagy L?szl? Zsolt wrote: > > Hello, > > I need to compare sets of datetime intervals, and make set operations on > them: intersect, union, difference etc. One element of a set would be an > interval like this: > > element ::= (start_point_in_time, end_point_in_time) > intervalset ::= { element1, element2, .... } > > Operations on elements: Eh... I think these should be realized as operations on an intervalset with a single element, and that elements should simply have properties like the start, end, and if it's open or closed on each side. In particular, any one of these could return something that is not an element. > element1.intersect(element2) May return the empty set, if they do not intersect. > element1.union(element2) May return {element1, element 2} > element1.minus(element2) May return { (start1, start2), (end2, end1) }... and the open/closeness of the element2 endpoints is reversed. > Operations on sets: > > intervalset1.intersect(intervalset2) > intervalset1.union(intervalset2) > intervalset1.minus(intervalset2) These should be operators. s1 & s2, s1 | s2, s1 - s2. There's also a s1 ^ s2 operation for python sets, the symmetric difference. Wouldn't it be useful to have some operations on datetimes? intervalset1.ltall(dt) .... all(dt < x.start or dt == x.start and x.startopen for x in dt) intervalset1.gtall(dt) .... all(dt > x.end or dt == x.end and x.endopen for x in dt) intervalset1.leall(dt) .... all(dt <= x.start for x in intervalset1) # I _think_ this is all you need for this intervalset1.geall(dt) .... all(dt >= x.end for x in intervalset1) dt in intervalset1 ... any(dt in elem for x in intervalset1) dt in elem ... dt > elem.start and dt < elem.end or dt == elem.start and not elem.startopen or dt == elem.end and not elem.endopen min and max ... seems trivial, but what to return if the first/last element is open? I'm truly shocked you didn't even mention the "in" operation. Also, as long as we're setting up an infinite (not really but anyway) set, why not also have the ability to have open-ended intervals that extend to infinity. Then you could invert the set too, for free given the minus operation: ~x == {(-inf, inf)} - x. It occurs to me that while I mentioned numbers, in principle you could use _any_ total-ordered type*. strings, tuples... *nitpicker's corner: here, "type" is used to mean any set/class/category of objects, possibly of multiple python types and possibly not comprising the entirety of a single type, which are total-ordered with respect to each other, including the codomain of any key projection function suitable for sorting. From george.trojan at noaa.gov Fri Apr 1 11:59:09 2016 From: george.trojan at noaa.gov (George Trojan - NOAA Federal) Date: Fri, 1 Apr 2016 15:59:09 +0000 Subject: A tool to add diagrams to sphinx docs Message-ID: What graphics editor would you recommend to create diagrams that can be included in sphinx made documentation? In the past I used xfig, but was not happy with font quality. My understanding is the diagrams would be saved in a .png file and I should use an image directive in the relevant .rst file. George From irmen.NOSPAM at xs4all.nl Fri Apr 1 12:26:48 2016 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Fri, 1 Apr 2016 18:26:48 +0200 Subject: A tool to add diagrams to sphinx docs In-Reply-To: References: Message-ID: <56fea147$0$5832$e4fe514c@news.xs4all.nl> On 1-4-2016 17:59, George Trojan - NOAA Federal wrote: > What graphics editor would you recommend to create diagrams that can be > included in sphinx made documentation? In the past I used xfig, but was not > happy with font quality. My understanding is the diagrams would be saved in > a .png file and I should use an image directive in the relevant .rst file. > > George > I've used .png successfully for a few images in my sphinx docs. However if you're concerned with font quality, a better option is perhaps to use a vector format like SVG instead. You can create them using a tool like Inkskape or Illustrator. I haven't tried to use .svg in sphinx myself yet but I guess it simply embeds/links it into the resulting html so a recent web browser should display them just fine. Irmen From ian.g.kelly at gmail.com Fri Apr 1 13:25:42 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 1 Apr 2016 11:25:42 -0600 Subject: [Python-ideas] Decorators for variables In-Reply-To: References: Message-ID: On Fri, Apr 1, 2016 at 11:14 AM, Matthias welp wrote: >> An example of the transformation would help here > > An example, that detects cycles in a graph, and doesn't do an update if > the graph has cycles. Thanks. > class A(object): > def __init__(self, parent): > @prevent_cycles > self.parent = parent I think you'll find that this doesn't work. Properties are members of the class, not of instances of the class. > This would prevent cycles from being created in this object A, and would > make > some highly reusable code. The same can be done for @not_none, etc, to > prevent > some states which may be unwanted. But you could accomplish the same thing with "self.parent = prevent_cycles(parent)". So I'm still not seeing how the use of the decorator syntax eliminates repetition. From tjreedy at udel.edu Fri Apr 1 14:31:42 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 1 Apr 2016 14:31:42 -0400 Subject: install open cv on windows 10 and python 3.5 In-Reply-To: <8b4a2755-388a-43fa-8ab3-ae416ff87950@googlegroups.com> References: <8b4a2755-388a-43fa-8ab3-ae416ff87950@googlegroups.com> Message-ID: On 4/1/2016 6:56 AM, saxri89 at gmail.com wrote: > hello, > > i have windows 10 and python 3.5 and i want to use > open cv but i think so opencv work only on python 2.7 ? The following link has binaries for 3.4 and 3.5 as well. I believe Gohlke tests his binaries, so I expect them to work. > and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv > but not work again I don't know what 'not work again' means here. -- Terry Jan Reedy From saxri89 at gmail.com Fri Apr 1 15:11:11 2016 From: saxri89 at gmail.com (saxri89 at gmail.com) Date: Fri, 1 Apr 2016 12:11:11 -0700 (PDT) Subject: install open cv on windows 10 and python 3.5 In-Reply-To: <8b4a2755-388a-43fa-8ab3-ae416ff87950@googlegroups.com> References: <8b4a2755-388a-43fa-8ab3-ae416ff87950@googlegroups.com> Message-ID: <044d7b5a-99b4-44d9-abdb-b7651c0d87b3@googlegroups.com> ?? ?????????, 1 ???????? 2016 - 1:56:52 ?.?. UTC+3, ? ??????? sax... at gmail.com ??????: > hello, > > i have windows 10 and python 3.5 and i want to use > open cv but i think so opencv work only on python 2.7 ? > and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv > but not work again i install opencv_python-3.1.0-cp35-none-win32.whl but if i import cv2 or import opencv then show me no module with that name From sjeik_appie at hotmail.com Fri Apr 1 15:14:32 2016 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Fri, 1 Apr 2016 19:14:32 +0000 Subject: A tool to add diagrams to sphinx docs In-Reply-To: <56fea147$0$5832$e4fe514c@news.xs4all.nl> References: , <56fea147$0$5832$e4fe514c@news.xs4all.nl> Message-ID: > Subject: Re: A tool to add diagrams to sphinx docs > From: irmen.NOSPAM at xs4all.nl > Date: Fri, 1 Apr 2016 18:26:48 +0200 > To: python-list at python.org > > On 1-4-2016 17:59, George Trojan - NOAA Federal wrote: > > What graphics editor would you recommend to create diagrams that can be > > included in sphinx made documentation? In the past I used xfig, but was not > > happy with font quality. My understanding is the diagrams would be saved in > > a .png file and I should use an image directive in the relevant .rst file. > > > > George > > > > I've used .png successfully for a few images in my sphinx docs. > However if you're concerned with font quality, a better option is perhaps to use a > vector format like SVG instead. You can create them using a tool like Inkskape or > Illustrator. I haven't tried to use .svg in sphinx myself yet but I guess it simply > embeds/links it into the resulting html so a recent web browser should display them just > fine. I used .svg for dependency graphs made with snakefood. Looked good in html, though they essily get too detailed. The .rst: .. figure:: images/my_image.svg :width: 100% From fanjianling at gmail.com Fri Apr 1 15:22:12 2016 From: fanjianling at gmail.com (Jianling Fan) Date: Fri, 1 Apr 2016 13:22:12 -0600 Subject: extract rar Message-ID: Hello everyone, I am wondering is there any way to extract rar files by python without WinRAR software? I tried Archive() and patool, but seems they required the WinRAR software. Thanks, Regards, Jianling From random832 at fastmail.com Fri Apr 1 15:29:54 2016 From: random832 at fastmail.com (Random832) Date: Fri, 01 Apr 2016 15:29:54 -0400 Subject: extract rar In-Reply-To: References: Message-ID: <1459538994.2669387.566083386.060473AE@webmail.messagingengine.com> On Fri, Apr 1, 2016, at 15:22, Jianling Fan wrote: > Hello everyone, > > I am wondering is there any way to extract rar files by python without > WinRAR software? > > I tried Archive() and patool, but seems they required the WinRAR > software. Rar is a proprietary format. They do distribute a free "unrar" program for multiple platforms. From sjeik_appie at hotmail.com Fri Apr 1 15:37:17 2016 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Fri, 1 Apr 2016 19:37:17 +0000 Subject: extract rar In-Reply-To: References: Message-ID: > Date: Fri, 1 Apr 2016 13:22:12 -0600 > Subject: extract rar > From: fanjianling at gmail.com > To: python-list at python.org > > Hello everyone, > > I am wondering is there any way to extract rar files by python without > WinRAR software? > > I tried Archive() and patool, but seems they required the WinRAR software. Perhaps 7-zip in a Python subprocess:http://superuser.com/questions/458643/unzip-rar-from-command-line-with-7-zip/464128 From python at lucidity.plus.com Fri Apr 1 15:58:33 2016 From: python at lucidity.plus.com (Erik) Date: Fri, 1 Apr 2016 20:58:33 +0100 Subject: Strange range In-Reply-To: <87lh4xjt37.fsf@elektro.pacujo.net> References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> Message-ID: <56FED2E9.2080100@lucidity.plus.com> On 01/04/16 15:34, Marko Rauhamaa wrote: > Chris Angelico : > >> *A range object is not an iterator.* > > We now have learned as much. > > However, doesn't that extra level of indirection seem like an odd > choice? If you write your own class which has an __iter__ method, would you expect: >>> o = MyClass() >>> i1 = iter(o) >>> i2 = iter(o) >>> list(i1) ['foo', 'bar', 'baz'] >>> list(i2) [] ? Or, would you expect both iterators to be independent and both return the 'foo', 'bar', 'baz' sequence (where that is the hypothetical result of iterating over your object)? If you now replace MyClass() with range(10), why would you expect the two iterators to be related? E. From marko at pacujo.net Fri Apr 1 16:14:42 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 01 Apr 2016 23:14:42 +0300 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> Message-ID: <874mblrsr1.fsf@elektro.pacujo.net> Erik : > On 01/04/16 15:34, Marko Rauhamaa wrote: >> Chris Angelico : >> >>> *A range object is not an iterator.* >> >> We now have learned as much. >> >> However, doesn't that extra level of indirection seem like an odd >> choice? > > [...] > > If you write your own class which has an __iter__ method, would you > [...] expect both iterators to be independent and both return the > 'foo', 'bar', 'baz' sequence (where that is the hypothetical result of > iterating over your object)? > > If you now replace MyClass() with range(10), why would you expect the > two iterators to be related? I simply had thought of range() returning an iterator. I would expect an iterator to behave like one. There's a bit of a cognitive dissonance between iterables and iterators. On the one hand, they behave identically in many contexts. On the other hand, the distinction is crucial in some special cases. (Somehow, the difference between iterables and iterators is analogous with the difference between C's arrays and pointers.) Marko From rgaddi at highlandtechnology.invalid Fri Apr 1 16:21:12 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 1 Apr 2016 20:21:12 -0000 (UTC) Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <874mblrsr1.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > Erik : > >> On 01/04/16 15:34, Marko Rauhamaa wrote: >>> Chris Angelico : >>> >>>> *A range object is not an iterator.* >>> >>> We now have learned as much. >>> >>> However, doesn't that extra level of indirection seem like an odd >>> choice? >> >> [...] >> >> If you write your own class which has an __iter__ method, would you >> [...] expect both iterators to be independent and both return the >> 'foo', 'bar', 'baz' sequence (where that is the hypothetical result of >> iterating over your object)? >> >> If you now replace MyClass() with range(10), why would you expect the >> two iterators to be related? > > I simply had thought of range() returning an iterator. I would expect an > iterator to behave like one. > > There's a bit of a cognitive dissonance between iterables and iterators. > On the one hand, they behave identically in many contexts. On the other > hand, the distinction is crucial in some special cases. You're missing a key point. All (well-behaved) iterators are iterables, with their __iter__ method returning themselves. for x in y: ... implies: try: _it = iter(y) while True: x = next(_it) ... except StopIteration: pass That's true for any iterable y, including a y which is itself an iterator. You still call iter() on it, and get _it, the iterator over y, which if y is an iterator is the same thing as y. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From fillmore_remove at hotmail.com Fri Apr 1 16:27:13 2016 From: fillmore_remove at hotmail.com (Fillmore) Date: Fri, 1 Apr 2016 16:27:13 -0400 Subject: Drowning in a teacup? Message-ID: notorious pass by reference vs pass by value biting me in the backside here. Proceeding in order. I need to scan a list of strings. If one of the elements matches the beginning of a search keyword, that element needs to snap to the front of the list. I achieved that this way: for i in range(len(mylist)): if(mylist[i].startswith(key)): mylist = [mylist[i]] + mylist[:i] + mylist[i+1:] Since I need this code in multiple places, I placed it inside a function def bringOrderStringToFront(mylist, key): for i in range(len(mylist)): if(mylist[i].startswith(key)): mylist = [mylist[i]] + mylist[:i] + mylist[i+1:] and called it this way: if orderstring: bringOrderStringToFront(Tokens, orderstring) right? Nope, wrong! contrary to what I thought I had understood about how parameters are passed in Python, the function is acting on a copy(!) and my original list is unchanged. I fixed it this way: def bringOrderStringToFront(mylist, key): for i in range(len(mylist)): if(mylist[i].startswith(key)): mylist = [mylist[i]] + mylist[:i] + mylist[i+1:] return(mylist) and: if orderstring: Tokens = bringOrderStringToFront(Tokens, orderstring) but I'm left with a sour taste of not understanding what I was doing wrong. Can anyone elaborate? what's the pythonista way to do it right? Thanks From michael.selik at gmail.com Fri Apr 1 16:31:32 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 01 Apr 2016 20:31:32 +0000 Subject: Set type for datetime intervals In-Reply-To: <56FE0625.5030901@shopzeus.com> References: <56FE0625.5030901@shopzeus.com> Message-ID: On Fri, Apr 1, 2016 at 1:32 AM Nagy L?szl? Zsolt wrote: > Does anyone know a library that already implements these functions? > What do you not like about the ones on PyPI? https://pypi.python.org/pypi?%3Aaction=search&term=interval&submit=search Depending on the resolution you want, you might be able to use builtin sets for everything. def interval(start, stop, precision=60): a = round(start.timestamp(), precision) b = round(stop.timestamp(), precision) return set(range(a, b, precision)) From michael.selik at gmail.com Fri Apr 1 16:32:43 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 01 Apr 2016 20:32:43 +0000 Subject: Set type for datetime intervals In-Reply-To: References: <56FE0625.5030901@shopzeus.com> Message-ID: Whoops, I mixed up tasks. Here's what I meant: def interval(start, stop, precision=60): a, b = start.timestamp(), stop.timestamp() return set(range(a, b, precision)) On Fri, Apr 1, 2016 at 4:31 PM Michael Selik wrote: > On Fri, Apr 1, 2016 at 1:32 AM Nagy L?szl? Zsolt > wrote: > >> Does anyone know a library that already implements these functions? >> > > What do you not like about the ones on PyPI? > https://pypi.python.org/pypi?%3Aaction=search&term=interval&submit=search > > Depending on the resolution you want, you might be able to use builtin > sets for everything. > > def interval(start, stop, precision=60): > a = round(start.timestamp(), precision) > b = round(stop.timestamp(), precision) > return set(range(a, b, precision)) > From python at mrabarnett.plus.com Fri Apr 1 16:33:02 2016 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 1 Apr 2016 21:33:02 +0100 Subject: install open cv on windows 10 and python 3.5 In-Reply-To: <044d7b5a-99b4-44d9-abdb-b7651c0d87b3@googlegroups.com> References: <8b4a2755-388a-43fa-8ab3-ae416ff87950@googlegroups.com> <044d7b5a-99b4-44d9-abdb-b7651c0d87b3@googlegroups.com> Message-ID: <56FEDAFE.4010207@mrabarnett.plus.com> On 2016-04-01 20:11, saxri89 at gmail.com wrote: > ?? ?????????, 1 ???????? 2016 - 1:56:52 ?.?. UTC+3, ? ??????? sax... at gmail.com ??????: >> hello, >> >> i have windows 10 and python 3.5 and i want to use >> open cv but i think so opencv work only on python 2.7 ? >> and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv >> but not work again > > i install opencv_python-3.1.0-cp35-none-win32.whl > but if i import cv2 or import opencv > then show me no module with that name > "OpenCV" is the name of the project, not the name of a module. The name of the module "cv2". From saxri89 at gmail.com Fri Apr 1 16:38:51 2016 From: saxri89 at gmail.com (saxri89 at gmail.com) Date: Fri, 1 Apr 2016 13:38:51 -0700 (PDT) Subject: install open cv on windows 10 and python 3.5 In-Reply-To: <8b4a2755-388a-43fa-8ab3-ae416ff87950@googlegroups.com> References: <8b4a2755-388a-43fa-8ab3-ae416ff87950@googlegroups.com> Message-ID: ?? ?????????, 1 ???????? 2016 - 1:56:52 ?.?. UTC+3, ? ??????? sax... at gmail.com ??????: > hello, > > i have windows 10 and python 3.5 and i want to use > open cv but i think so opencv work only on python 2.7 ? > and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv > but not work again show me no module name cv2 From rgaddi at highlandtechnology.invalid Fri Apr 1 16:39:59 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 1 Apr 2016 20:39:59 -0000 (UTC) Subject: Drowning in a teacup? References: Message-ID: Fillmore wrote: > > notorious pass by reference vs pass by value biting me in the backside > here. Proceeding in order. > > I need to scan a list of strings. If one of the elements matches the > beginning of a search keyword, that element needs to snap to the front > of the list. > I achieved that this way: > > > for i in range(len(mylist)): > if(mylist[i].startswith(key)): > mylist = [mylist[i]] + mylist[:i] + mylist[i+1:] > > Since I need this code in multiple places, I placed it inside a function > > def bringOrderStringToFront(mylist, key): > > for i in range(len(mylist)): > if(mylist[i].startswith(key)): > mylist = [mylist[i]] + mylist[:i] + mylist[i+1:] > > and called it this way: > > if orderstring: > bringOrderStringToFront(Tokens, orderstring) > > right? > Nope, wrong! contrary to what I thought I had understood about how > parameters are passed in Python, the function is acting on a copy(!) and > my original list is unchanged. > Nope, that's not your problem. Your problem is the line: > mylist = [mylist[i]] + mylist[:i] + mylist[i+1:] Which should be read as: "Take mylist[i], all of mylist before i, and all of mylist after i and create a new list from it. Store that new list in a variable called mylist, overwriting the previous value." If instead you were using the .insert and .remove methods, you'd be manipulating the existing list instead. But you don't want to do that, because those methods are O(N) on the list length; manipulating the middle of lists is slow. That said, you've got some logic problems too; which come from the fact that your iteration is shooting at a moving target. How about: newlist = ( [x for x in mylist if x.startswith(key)] + [x for x in mylist if not x.startswith(key)] ) return newlist Or if you really insist on mutating the original list (which seems less clean to me, but you do you), then: newlist = blahblahblah mylist[:] = newlist -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From marko at pacujo.net Fri Apr 1 16:44:57 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 01 Apr 2016 23:44:57 +0300 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <874mblrsr1.fsf@elektro.pacujo.net> Message-ID: <87zitdqcs6.fsf@elektro.pacujo.net> Rob Gaddi : > Marko Rauhamaa wrote: >> There's a bit of a cognitive dissonance between iterables and iterators. >> On the one hand, they behave identically in many contexts. On the other >> hand, the distinction is crucial in some special cases. > > You're missing a key point. All (well-behaved) iterators are iterables, > with their __iter__ method returning themselves. I don't know what I'm missing. Marko From python at mrabarnett.plus.com Fri Apr 1 16:45:02 2016 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 1 Apr 2016 21:45:02 +0100 Subject: Drowning in a teacup? In-Reply-To: References: Message-ID: <56FEDDCE.5040505@mrabarnett.plus.com> On 2016-04-01 21:27, Fillmore wrote: > > notorious pass by reference vs pass by value biting me in the backside > here. Proceeding in order. > > I need to scan a list of strings. If one of the elements matches the > beginning of a search keyword, that element needs to snap to the front > of the list. > I achieved that this way: > > > for i in range(len(mylist)): > if(mylist[i].startswith(key)): > mylist = [mylist[i]] + mylist[:i] + mylist[i+1:] > > Since I need this code in multiple places, I placed it inside a function > > def bringOrderStringToFront(mylist, key): > > for i in range(len(mylist)): > if(mylist[i].startswith(key)): > mylist = [mylist[i]] + mylist[:i] + mylist[i+1:] > > and called it this way: > > if orderstring: > bringOrderStringToFront(Tokens, orderstring) > > right? > Nope, wrong! contrary to what I thought I had understood about how > parameters are passed in Python, the function is acting on a copy(!) and > my original list is unchanged. > > I fixed it this way: > > def bringOrderStringToFront(mylist, key): > > for i in range(len(mylist)): > if(mylist[i].startswith(key)): > mylist = [mylist[i]] + mylist[:i] + mylist[i+1:] > return(mylist) > > and: > > if orderstring: > Tokens = bringOrderStringToFront(Tokens, orderstring) > > but I'm left with a sour taste of not understanding what I was doing > wrong. Can anyone elaborate? what's the pythonista way to do it right? > Python always passes a reference to the object, so the name "mylist" in the function is a local name that refers to the list that you passed. When you say "mylist = something", you're just binding that local name to another object (i.e., it'll now refer to that object instead). What you want to do it mutate the list itself. You can do that by replacing its elements with the new list you've created: mylist[:] = [mylist[i]] + mylist[:i] + mylist[i+1:] From michael.selik at gmail.com Fri Apr 1 16:46:19 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 01 Apr 2016 20:46:19 +0000 Subject: Drowning in a teacup? In-Reply-To: References: Message-ID: Give this a shot def snap(keyword, words): matches = [i for i, s in enumerate(words) if s.startswith(keyword)] for i in matches: lst.insert(0, lst.pop(i)) Your current implementation is reassigning the local variable ``mylist`` to a new list inside the function. On Fri, Apr 1, 2016 at 4:30 PM Fillmore wrote: > > notorious pass by reference vs pass by value biting me in the backside > here. Proceeding in order. > > I need to scan a list of strings. If one of the elements matches the > beginning of a search keyword, that element needs to snap to the front > of the list. > I achieved that this way: > > > for i in range(len(mylist)): > if(mylist[i].startswith(key)): > mylist = [mylist[i]] + mylist[:i] + mylist[i+1:] > > Since I need this code in multiple places, I placed it inside a function > > def bringOrderStringToFront(mylist, key): > > for i in range(len(mylist)): > if(mylist[i].startswith(key)): > mylist = [mylist[i]] + mylist[:i] + mylist[i+1:] > > and called it this way: > > if orderstring: > bringOrderStringToFront(Tokens, orderstring) > > right? > Nope, wrong! contrary to what I thought I had understood about how > parameters are passed in Python, the function is acting on a copy(!) and > my original list is unchanged. > > I fixed it this way: > > def bringOrderStringToFront(mylist, key): > > for i in range(len(mylist)): > if(mylist[i].startswith(key)): > mylist = [mylist[i]] + mylist[:i] + mylist[i+1:] > return(mylist) > > and: > > if orderstring: > Tokens = bringOrderStringToFront(Tokens, orderstring) > > but I'm left with a sour taste of not understanding what I was doing > wrong. Can anyone elaborate? what's the pythonista way to do it right? > > Thanks > > -- > https://mail.python.org/mailman/listinfo/python-list > From ian.g.kelly at gmail.com Fri Apr 1 16:52:10 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 1 Apr 2016 14:52:10 -0600 Subject: Drowning in a teacup? In-Reply-To: References: Message-ID: On Fri, Apr 1, 2016 at 2:39 PM, Rob Gaddi wrote: > Fillmore wrote: >> Nope, wrong! contrary to what I thought I had understood about how >> parameters are passed in Python, the function is acting on a copy(!) and >> my original list is unchanged. >> > > Nope, that's not your problem. Your problem is the line: > >> mylist = [mylist[i]] + mylist[:i] + mylist[i+1:] > > Which should be read as: "Take mylist[i], all of mylist before i, > and all of mylist after i and create a new list from it. Store that > new list in a variable called mylist, overwriting the previous value." > > If instead you were using the .insert and .remove methods, you'd be > manipulating the existing list instead. But you don't want to do that, > because those methods are O(N) on the list length; manipulating the > middle of lists is slow. Or use slice assignment. This should work in place of the above: mylist[:] = [mylist[i]] + mylist[:i] + mylist[i+1:] Still O(n), but so will be any implementation that removes something from an arbitrary list position and inserts it at the front. From tjreedy at udel.edu Fri Apr 1 16:59:52 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 1 Apr 2016 16:59:52 -0400 Subject: install open cv on windows 10 and python 3.5 In-Reply-To: References: <8b4a2755-388a-43fa-8ab3-ae416ff87950@googlegroups.com> Message-ID: On 4/1/2016 4:38 PM, saxri89 at gmail.com wrote: > ?? ?????????, 1 ???????? 2016 - 1:56:52 ?.?. UTC+3, ? ??????? sax... at gmail.com ??????: >> hello, >> >> i have windows 10 and python 3.5 and i want to use >> open cv but i think so opencv work only on python 2.7 ? >> and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv >> but not work again > > show me no module name cv2 Do you have other versions of python installed. How did you install opencv/cv2? If pip, what did it say? What you you see in python35/Lib/site-packages? -- Terry Jan Reedy From fanjianling at gmail.com Fri Apr 1 17:01:23 2016 From: fanjianling at gmail.com (Jianling Fan) Date: Fri, 1 Apr 2016 15:01:23 -0600 Subject: extract rar In-Reply-To: References: Message-ID: Thanks, but the problem is that I am not allowed to install any software in my office PC, even free software. Normally, I use zip files but this time I need to extract a rar file. I don't like to go to IT guys because it takes time. That's why I am looking for an alternative way without installing other software. Thanks, On 1 April 2016 at 13:37, Albert-Jan Roskam wrote: > > > >> Date: Fri, 1 Apr 2016 13:22:12 -0600 >> Subject: extract rar >> From: fanjianling at gmail.com >> To: python-list at python.org >> >> Hello everyone, >> >> I am wondering is there any way to extract rar files by python without >> WinRAR software? >> >> I tried Archive() and patool, but seems they required the WinRAR software. > > Perhaps 7-zip in a Python subprocess: > http://superuser.com/questions/458643/unzip-rar-from-command-line-with-7-zip/464128 > -- Jianling Fan ??? From muhkader at gmail.com Fri Apr 1 17:02:16 2016 From: muhkader at gmail.com (A. ElKader) Date: Sat, 2 Apr 2016 00:02:16 +0300 Subject: writing to command line thru python gui Message-ID: I posted this question, no reply : Any advice : http://unix.stackexchange.com/questions/273573/write-to-terminal-in-tkinter-gui From ckaynor at zindagigames.com Fri Apr 1 17:10:02 2016 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 1 Apr 2016 14:10:02 -0700 Subject: Drowning in a teacup? In-Reply-To: References: Message-ID: On Fri, Apr 1, 2016 at 1:52 PM, Ian Kelly wrote: > On Fri, Apr 1, 2016 at 2:39 PM, Rob Gaddi > wrote: > > Fillmore wrote: > >> Nope, wrong! contrary to what I thought I had understood about how > >> parameters are passed in Python, the function is acting on a copy(!) and > >> my original list is unchanged. > >> > > > > Nope, that's not your problem. Your problem is the line: > > > >> mylist = [mylist[i]] + mylist[:i] + mylist[i+1:] > > > > Which should be read as: "Take mylist[i], all of mylist before i, > > and all of mylist after i and create a new list from it. Store that > > new list in a variable called mylist, overwriting the previous value." > > > > If instead you were using the .insert and .remove methods, you'd be > > manipulating the existing list instead. But you don't want to do that, > > because those methods are O(N) on the list length; manipulating the > > middle of lists is slow. > > Or use slice assignment. This should work in place of the above: > > mylist[:] = [mylist[i]] + mylist[:i] + mylist[i+1:] > > Still O(n), but so will be any implementation that removes something > from an arbitrary list position and inserts it at the front. > The overall algorithm is O(n^2), as its doing a O(n) operation in a O(n) loop: def bringOrderStringToFront(mylist, key): for i in range(len(mylist)): # O(n) if(mylist[i].startswith(key)): mylist[:] = [mylist[i]] + mylist[:i] + mylist[i+1:] # O(n) You should get an overall O(n) with (untested): def bringOrderStringToFront(mylist, key): starts = [] other = [] for item in mylist: # O(n) if item.startswith(key): starts.append(item) # amortized O(1) else: other.append(item) # amortized O(1) mylist[:] = starts[::-1] + other # O(n); slice assignment mutates input list From ethan at stoneleaf.us Fri Apr 1 17:15:49 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 01 Apr 2016 14:15:49 -0700 Subject: Drowning in a teacup? In-Reply-To: References: Message-ID: <56FEE505.6000603@stoneleaf.us> On 04/01/2016 01:27 PM, Fillmore wrote: > notorious pass by reference vs pass by value biting me in the backside > here. Proceeding in order. It's only notorious for folks that don't understand that Python uses neither. It also doesn't help when folks don't understand how name-binding works. if orderstring: bringOrderStringToFront(Tokens, orderstring) Tokens has now been passed in to bringOrderStringToFront, and it has been assigned the name of `mylist`. def bringOrderStringToFront(mylist, key): At this point `mylist` and `Tokens` are the same object. for i in range(len(mylist)): if(mylist[i].startswith(key)): mylist = [mylist[i]] + mylist[:i] + mylist[i+1:] And now they are not, as you just assigned the name `mylist` to something else. -- ~Ethan~ From ian.g.kelly at gmail.com Fri Apr 1 17:16:50 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 1 Apr 2016 15:16:50 -0600 Subject: Drowning in a teacup? In-Reply-To: References: Message-ID: On Fri, Apr 1, 2016 at 3:10 PM, Chris Kaynor wrote: > The overall algorithm is O(n^2), as its doing a O(n) operation in a O(n) > loop: Depends on whether the OP expects to find only one match or potentially multiple matches in the list. E did say "if one of the elements matches". If there are only ever a constant number of matches, then it's O(n) overall. From accessnewbie at gmail.com Fri Apr 1 17:20:14 2016 From: accessnewbie at gmail.com (accessnewbie at gmail.com) Date: Fri, 1 Apr 2016 14:20:14 -0700 (PDT) Subject: Grab metadata from images and save to file, batch mode Message-ID: <75200b1c-eb54-4e03-a859-6c9631b9073a@googlegroups.com> I have a directory (and sub-directories) full of images that I want to cycle through and grab certain metadata values and save those values to a single row in a cvs file. I would like to tack on the full path name to the row as a separate value. Folder C:\Images\Family Brother.jpg Sister.jpg Mom.jpg Keys/Values Original Date/Time User Name File Name Thus, data might look like this in a Family.csv file 2014:11:10 13:52:12; BillyBob111; Brother.jpg; C:\Images\Family\Brother.jpg 2015:10:54 11:45:34; BillyBob111; Sister.jpg; C:\Images\Family\Sister.jpg 2010:10:31 19:22:11; SallySue232; Mom.jpg; C:\Images\Family\Mom.jpg Big time noob. Much of what I have read cites command line examples dealing with single files and no info as to how to extract specific keys and their values. What module would some of you users recommend I use (I want it to be python as that is what I am trying to learn) Can you give me some coding suggestions to get me goings? I haven't found any substantive scripts to use as guides. Many thanks in advance From tjreedy at udel.edu Fri Apr 1 17:22:22 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 1 Apr 2016 17:22:22 -0400 Subject: Strange range In-Reply-To: <874mblrsr1.fsf@elektro.pacujo.net> References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <874mblrsr1.fsf@elektro.pacujo.net> Message-ID: On 4/1/2016 4:14 PM, Marko Rauhamaa wrote: > There's a bit of a cognitive dissonance between iterables and iterators. > On the one hand, they behave identically in many contexts. Because iterators *are* (a proper subset of) iterables This goes back to pre-iterator days when for-loops worked on sequences and sequence-like objects. When iterators (and generators and generator functions) were added and the iteration protocol added to the sequence protocol, 'sequence' was generalized to 'iterable'. Replacing 'sequence' with 'iterator' (and having an iterator not be an iterable) would have broken most code and made for loops less convenient to use. > On the other hand, the distinction between iterators and non-iterator iterables > is crucial in some special cases. I often call non-iterator iterables 're-iterables' (which is usually correct) but there is no agree-on term. It is sort of like having 'people' and 'men' but no word for non-men people. > (Somehow, the difference between iterables and iterators is analogous > with the difference between C's arrays and pointers.) (Yes, C uses pointers to iterates through arrays, in either direction.) -- Terry Jan Reedy From saxri89 at gmail.com Fri Apr 1 17:37:22 2016 From: saxri89 at gmail.com (Xristos Xristoou) Date: Fri, 1 Apr 2016 14:37:22 -0700 (PDT) Subject: install open cv on windows 10 and python 3.5 In-Reply-To: <8b4a2755-388a-43fa-8ab3-ae416ff87950@googlegroups.com> References: <8b4a2755-388a-43fa-8ab3-ae416ff87950@googlegroups.com> Message-ID: ?? ?????????, 1 ???????? 2016 - 1:56:52 ?.?. UTC+3, ? ??????? Xristos Xristoou ??????: > hello, > > i have windows 10 and python 3.5 and i want to use > open cv but i think so opencv work only on python 2.7 ? > and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv > but not work again in my site-packages i have : opencv_python-3.1.0.dist-info cv2.cp35-win32.pyd cv2.pyd cv and more opencv.dlls yes i have and python2.7 for other version in pip install succefully From okuntsov.mikhail at yandex.ru Fri Apr 1 17:48:27 2016 From: okuntsov.mikhail at yandex.ru (Michael Okuntsov) Date: Sat, 2 Apr 2016 03:48:27 +0600 Subject: [beginner] What's wrong? Message-ID: Hello, I have a Pascal code for some hash function. I've tried to rewrite it on Python but it doesn't give the right value (which is 32202). Please tell me where is the error. Thanks. ********************** Pascal program ********************** Program K_S; Var ST: String; function KSUM(var S: String): String; var i, l: Integer; KS: Word; SS: String; begin KS:=65535; for i:=2 to Length(S) do begin KS := KS xor Ord(S[i]); writeln(S[i]); for l:=1 to 8 do if (KS div 2)*2<>KS then KS := (KS div 2) xor 40961 else KS := (KS div 2); end; Str(KS, SS); KSUM := SS; end; Begin ST := ':1;1;2;'; Writeln(KSUM(ST)); End. ********************** Python program ********************** def myhash(s): KS=65535 for i in range(1,len(s)): KS=KS ^ ord(s[i]) for j in range(1,8): if (KS // 2)*2 != KS: KS=(KS // 2) ^ 40961 else: KS=KS // 2 return(str(KS)) if __name__ == "__main__": st=myhash(":1;1;2;") print (st) From okuntsov.mikhail at yandex.ru Fri Apr 1 18:10:38 2016 From: okuntsov.mikhail at yandex.ru (Michael Okuntsov) Date: Sat, 2 Apr 2016 04:10:38 +0600 Subject: [beginner] What's wrong? In-Reply-To: References: Message-ID: Nevermind. for j in range(1,8) should be for j in range(8). From breamoreboy at yahoo.co.uk Fri Apr 1 18:24:55 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 1 Apr 2016 23:24:55 +0100 Subject: Drowning in a teacup? In-Reply-To: References: Message-ID: On 01/04/2016 21:27, Fillmore wrote: > > notorious pass by reference vs pass by value biting me in the backside > here. Proceeding in order. It is pass by object. By definition your following analysis is wrong. To my knowledge this has been discussed at least twice a year for the past 15 years. I would suggest that you search the archives, but that would upset teacher, so I won't. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Fri Apr 1 18:32:33 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 1 Apr 2016 23:32:33 +0100 Subject: Strange range In-Reply-To: <87zitdqcs6.fsf@elektro.pacujo.net> References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <874mblrsr1.fsf@elektro.pacujo.net> <87zitdqcs6.fsf@elektro.pacujo.net> Message-ID: On 01/04/2016 21:44, Marko Rauhamaa wrote: > Rob Gaddi : > >> Marko Rauhamaa wrote: >>> There's a bit of a cognitive dissonance between iterables and iterators. >>> On the one hand, they behave identically in many contexts. On the other >>> hand, the distinction is crucial in some special cases. >> >> You're missing a key point. All (well-behaved) iterators are iterables, >> with their __iter__ method returning themselves. > > I don't know what I'm missing. > > Marko > Neither do we, which is why so many threads here belong, eventually, on comp.lang.theoretical.claptrap. I remember when we used to have Bots here commenting on the Python language. Obviously they've all given up as so much drivel is spouted, and/or they've gone to join the Norwegian Blue. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Fri Apr 1 18:34:35 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 1 Apr 2016 23:34:35 +0100 Subject: [beginner] What's wrong? In-Reply-To: References: Message-ID: On 01/04/2016 23:10, Michael Okuntsov wrote: > Nevermind. for j in range(1,8) should be for j in range(8). Thank you for your correction, we in Python land greatly appreciate such things :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From sohcahtoa82 at gmail.com Fri Apr 1 18:44:26 2016 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Fri, 1 Apr 2016 15:44:26 -0700 (PDT) Subject: [beginner] What's wrong? In-Reply-To: References: Message-ID: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> On Friday, April 1, 2016 at 3:10:51 PM UTC-7, Michael Okuntsov wrote: > Nevermind. for j in range(1,8) should be for j in range(8). I can't tell you how many times I've gotten bit in the ass with that off-by-one mistake whenever I use a range that doesn't start at zero. I know that if I want to loop 10 times and I either want to start at zero or just don't care about the actual number, I use `for i in range(10)`. But if I want to loop from 10 to 20, my first instinct is to write `for i in range(10, 20)`, and then I'm left figuring out why my loop isn't executing the last step. From steve at pearwood.info Fri Apr 1 18:46:10 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 02 Apr 2016 09:46:10 +1100 Subject: Drowning in a teacup? References: Message-ID: <56fefa34$0$1622$c3e8da3$5496439d@news.astraweb.com> On Sat, 2 Apr 2016 07:27 am, Fillmore wrote: > > notorious pass by reference vs pass by value biting me in the backside > here. Proceeding in order. Python is NEITHER pass by reference nor pass by value. Please read this: http://import-that.dreamwidth.org/1130.html before asking any additional questions. > def bringOrderStringToFront(mylist, key): > > for i in range(len(mylist)): > if(mylist[i].startswith(key)): > mylist = [mylist[i]] + mylist[:i] + mylist[i+1:] [mylist[i]] + mylist[:i] + mylist[i+1:] creates a new list. It doesn't modify the existing list. mylist = ... performs an assignment to the LOCAL VARIABLE mylist, setting it to the new list just created. The original list is unchanged. Trick: you can use slicing to write to the original list: mylist[:] = [mylist[i]] + mylist[:i] + mylist[i+1:] Or you can modify the list directly in place: for i in range(len(mylist)): if mylist[i].startswith(key): x = mylist[i] del mylist[i] mylist.insert(0, x) which is better written as: for i, x in enumerate(mylist): if x.startswith(key): del mylist[i] mylist.insert(0, x) or if you prefer: for i, x in enumerate(mylist): if x.startswith(key): mylist[:] = [x] + mylist[:i] + mylist[i+1:] -- Steven From python at mrabarnett.plus.com Fri Apr 1 18:54:56 2016 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 1 Apr 2016 23:54:56 +0100 Subject: install open cv on windows 10 and python 3.5 In-Reply-To: References: <8b4a2755-388a-43fa-8ab3-ae416ff87950@googlegroups.com> Message-ID: <56FEFC40.8040105@mrabarnett.plus.com> On 2016-04-01 22:37, Xristos Xristoou wrote: > ?? ?????????, 1 ???????? 2016 - 1:56:52 ?.?. UTC+3, ? ??????? Xristos Xristoou ??????: >> hello, >> >> i have windows 10 and python 3.5 and i want to use >> open cv but i think so opencv work only on python 2.7 ? >> and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv >> but not work again > > in my site-packages i have : > opencv_python-3.1.0.dist-info > cv2.cp35-win32.pyd > cv2.pyd > cv > and more opencv.dlls > yes i have and python2.7 for other version > in pip install succefully > If a module has been written in Python, it will have the extension ".py", but if it has been written in C, it will have the extension ".pyd" (on Windows) or ".so" (on Linux). The real test is if you can import it: >>> import cv2 From breamoreboy at yahoo.co.uk Fri Apr 1 18:57:05 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 1 Apr 2016 23:57:05 +0100 Subject: [beginner] What's wrong? In-Reply-To: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> Message-ID: On 01/04/2016 23:44, sohcahtoa82 at gmail.com wrote: > On Friday, April 1, 2016 at 3:10:51 PM UTC-7, Michael Okuntsov wrote: >> Nevermind. for j in range(1,8) should be for j in range(8). > > I can't tell you how many times I've gotten bit in the ass with that off-by-one mistake whenever I use a range that doesn't start at zero. > > I know that if I want to loop 10 times and I either want to start at zero or just don't care about the actual number, I use `for i in range(10)`. But if I want to loop from 10 to 20, my first instinct is to write `for i in range(10, 20)`, and then I'm left figuring out why my loop isn't executing the last step. > "First instinct"? "I expected"? The Python docs might not be perfect, but they were certainly adequate enough to get me going 15 years ago, and since then they've improved. So where is the problem, other than failure to RTFM? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From vaulhausen at gmail.com Fri Apr 1 19:08:07 2016 From: vaulhausen at gmail.com (vaulhausen at gmail.com) Date: Fri, 1 Apr 2016 16:08:07 -0700 (PDT) Subject: pow() & modulo QUESTION Message-ID: Having trouble performing the pow() function with real numbers. I want to also take a modulo value.... Weirdly, this works fine ; pow(2,6000,400) = 176 However, this returns an error ; pow(1.4142, 6000, 400) I have tried also the math.pow() function but it doesnt work either..... can any one give me a hand with this? From michael.selik at gmail.com Fri Apr 1 19:29:15 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 01 Apr 2016 23:29:15 +0000 Subject: [beginner] What's wrong? In-Reply-To: References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> Message-ID: Humans have always had trouble with this, in many contexts. I remember being annoyed at folks saying the year 2000 was the first year of the new millennium, rather than 2001. They'd forgotten the Gregorian calendar starts from AD 1. On Fri, Apr 1, 2016, 6:58 PM Mark Lawrence via Python-list < python-list at python.org> wrote: > On 01/04/2016 23:44, sohcahtoa82 at gmail.com wrote: > > On Friday, April 1, 2016 at 3:10:51 PM UTC-7, Michael Okuntsov wrote: > >> Nevermind. for j in range(1,8) should be for j in range(8). > > > > I can't tell you how many times I've gotten bit in the ass with that > off-by-one mistake whenever I use a range that doesn't start at zero. > > > > I know that if I want to loop 10 times and I either want to start at > zero or just don't care about the actual number, I use `for i in > range(10)`. But if I want to loop from 10 to 20, my first instinct is to > write `for i in range(10, 20)`, and then I'm left figuring out why my loop > isn't executing the last step. > > > > "First instinct"? "I expected"? The Python docs might not be perfect, > but they were certainly adequate enough to get me going 15 years ago, > and since then they've improved. So where is the problem, other than > failure to RTFM? > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence > > -- > https://mail.python.org/mailman/listinfo/python-list > From dmarv at dop.com Fri Apr 1 19:33:12 2016 From: dmarv at dop.com (Dale Marvin) Date: Fri, 1 Apr 2016 16:33:12 -0700 Subject: Grab metadata from images and save to file, batch mode In-Reply-To: <75200b1c-eb54-4e03-a859-6c9631b9073a@googlegroups.com> References: <75200b1c-eb54-4e03-a859-6c9631b9073a@googlegroups.com> Message-ID: <56FF0538.8020901@dop.com> On 4/1/16 2:20 PM, accessnewbie at gmail.com wrote: > I have a directory (and sub-directories) full of images that I want to cycle through and grab certain metadata values and save those values to a single row in a cvs file. I would like to tack on the full path name to the row as a separate value. > > Folder > C:\Images\Family > Brother.jpg > Sister.jpg > Mom.jpg > > Keys/Values > Original Date/Time > User Name > File Name > > Thus, data might look like this in a Family.csv file > 2014:11:10 13:52:12; BillyBob111; Brother.jpg; C:\Images\Family\Brother.jpg > 2015:10:54 11:45:34; BillyBob111; Sister.jpg; C:\Images\Family\Sister.jpg > 2010:10:31 19:22:11; SallySue232; Mom.jpg; C:\Images\Family\Mom.jpg > > Big time noob. Much of what I have read cites command line examples dealing with single files and no info as to how to extract specific keys and their values. > What module would some of you users recommend I use (I want it to be python as that is what I am trying to learn) > > Can you give me some coding suggestions to get me goings? I haven't found any substantive scripts to use as guides. > > Many thanks in advance > Hi accessnewbie, I do a fair amount of media processing and automation with python. Look at exiftool There are python bindings as well . Dale From dmarv at dop.com Fri Apr 1 19:52:33 2016 From: dmarv at dop.com (Dale Marvin) Date: Fri, 1 Apr 2016 16:52:33 -0700 Subject: Introduction In-Reply-To: <75200b1c-eb54-4e03-a859-6c9631b9073a@googlegroups.com> References: <75200b1c-eb54-4e03-a859-6c9631b9073a@googlegroups.com> Message-ID: <56FF09C1.9030605@dop.com> I just sent my first post, been using python for about 12 years to automate media production tasks. Lately I've been adding testing (Thanks Ned Batchelder: ), and documentation with Sphinx/rst. Thanks Dale Marvin digital OutPost From python at mrabarnett.plus.com Fri Apr 1 21:04:22 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 2 Apr 2016 02:04:22 +0100 Subject: pow() & modulo QUESTION In-Reply-To: References: Message-ID: <56FF1A96.5010504@mrabarnett.plus.com> On 2016-04-02 00:08, vaulhausen at gmail.com wrote: > Having trouble performing the pow() function with > real numbers. > > I want to also take a modulo value.... > > Weirdly, this works fine ; > > pow(2,6000,400) = 176 > > However, this returns an error ; > > pow(1.4142, 6000, 400) > > I have tried also the math.pow() function but it doesnt > work either..... can any one give me a hand with this? > The 2-argument form pow(x, y) is equivalent to x ** y. When working with integers, there's a more efficient way of calculating x ** y % z, so pow provides that with the 3-argument form pow(x, y, z). Of course, you could argue that pow should allow the 3-argument for even with floats, but it wouldn't be any faster than x ** y % z. From walters.justin01 at gmail.com Fri Apr 1 22:53:52 2016 From: walters.justin01 at gmail.com (justin walters) Date: Fri, 1 Apr 2016 19:53:52 -0700 Subject: Django Channels examples Message-ID: To all of my Web developer bros and broettes, You all should check out this github repo: https://github.com/andrewgodwin/channels-examples This is not my repo or my work. Channels is a package for Django that allows Django to work more easily with websockets through an asgi interface. The Django devs intend to add Channels into the core packages with the next major release. The linked repo contains 2 examples. One is a live blogging application, and one is a live chat application. I just typed out all of the code to build the chat application myself and it works well. It was a fun exercise. If you are interested in websocket applications with Python, I highly recommend checking it out. Let me know if this kind of thing does not belong on this list. I'm just really excited about this. From fillmore_remove at hotmail.com Sat Apr 2 00:03:41 2016 From: fillmore_remove at hotmail.com (Fillmore) Date: Sat, 02 Apr 2016 00:03:41 -0400 Subject: Drowning in a teacup? References: Message-ID: On 04/01/2016 04:27 PM, Fillmore wrote: > > notorious pass by reference vs pass by value biting me in the backside here. Proceeding in order. Many thanks to all of those who replied! From random832 at fastmail.com Sat Apr 2 00:27:50 2016 From: random832 at fastmail.com (Random832) Date: Sat, 02 Apr 2016 00:27:50 -0400 Subject: [beginner] What's wrong? In-Reply-To: References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> Message-ID: <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> On Fri, Apr 1, 2016, at 19:29, Michael Selik wrote: > Humans have always had trouble with this, in many contexts. I remember > being annoyed at folks saying the year 2000 was the first year of the new > millennium, rather than 2001. They'd forgotten the Gregorian calendar > starts from AD 1. Naturally, this means the first millennium was only 999 years long, and all subsequent millennia were 1000 years long. (Whereas "millennium" is defined as the set of all years of a given era for a given integer k where y // 1000 == k. How else would you define it?) And if you want to get technical, the gregorian calendar starts from some year no earlier than 1582, depending on the country. The year numbering system has little to do with the calendar type - your assertion in fact regards the BC/AD year numbering system, which was invented by Bede. The astronomical year-numbering system, which does contain a year zero (and uses negative numbers rather than a reverse-numbered "BC" era), and is incidentally used by ISO 8601, was invented by Jacques Cassini in the 17th century. Rule #1 of being pedantic: There's always someone more pedantic than you, whose pedantry supports the opposite conclusion. From wrw at mac.com Sat Apr 2 00:54:21 2016 From: wrw at mac.com (William Ray Wing) Date: Sat, 02 Apr 2016 00:54:21 -0400 Subject: [beginner] What's wrong? In-Reply-To: References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> Message-ID: > On Apr 1, 2016, at 6:57 PM, Mark Lawrence via Python-list wrote: > >> On 01/04/2016 23:44, sohcahtoa82 at gmail.com wrote: >>> On Friday, April 1, 2016 at 3:10:51 PM UTC-7, Michael Okuntsov wrote: >>> Nevermind. for j in range(1,8) should be for j in range(8). >> >> I can't tell you how many times I've gotten bit in the ass with that off-by-one mistake whenever I use a range that doesn't start at zero. >> >> I know that if I want to loop 10 times and I either want to start at zero or just don't care about the actual number, I use `for i in range(10)`. But if I want to loop from 10 to 20, my first instinct is to write `for i in range(10, 20)`, and then I'm left figuring out why my loop isn't executing the last step. > > "First instinct"? "I expected"? The Python docs might not be perfect, but they were certainly adequate enough to get me going 15 years ago, and since then they've improved. So where is the problem, other than failure to RTFM? > I've always found it vaguely amusing that the server(s) for just about all the technical info at MIT reside behind http://rtfm.mit.edu Bill > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence > > -- > https://mail.python.org/mailman/listinfo/python-list From michael.selik at gmail.com Sat Apr 2 01:36:13 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sat, 02 Apr 2016 05:36:13 +0000 Subject: [beginner] What's wrong? In-Reply-To: <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> Message-ID: On Sat, Apr 2, 2016, 12:28 AM Random832 wrote: > On Fri, Apr 1, 2016, at 19:29, Michael Selik wrote: > > Humans have always had trouble with this, in many contexts. I remember > > being annoyed at folks saying the year 2000 was the first year of the new > > millennium, rather than 2001. They'd forgotten the Gregorian calendar > > starts from AD 1. > > Naturally, this means the first millennium was only 999 years long, and > all subsequent millennia were 1000 years long. (Whereas "millennium" is > defined as the set of all years of a given era for a given integer k > where y // 1000 == k. How else would you define it?) > > And if you want to get technical, the gregorian calendar starts from > some year no earlier than 1582, depending on the country. The year > numbering system has little to do with the calendar type - your > assertion in fact regards the BC/AD year numbering system, which was > invented by Bede. > > The astronomical year-numbering system, which does contain a year zero > (and uses negative numbers rather than a reverse-numbered "BC" era), and > is incidentally used by ISO 8601, was invented by Jacques Cassini in the > 17th century. > > > > Rule #1 of being pedantic: There's always someone more pedantic than > you, whose pedantry supports the opposite conclusion. > I'll have to remember that one. And thanks for the facts. > From vito.detullio at gmail.com Sat Apr 2 01:45:31 2016 From: vito.detullio at gmail.com (Vito De Tullio) Date: Sat, 02 Apr 2016 07:45:31 +0200 Subject: Drowning in a teacup? References: Message-ID: Fillmore wrote: > I need to scan a list of strings. If one of the elements matches the > beginning of a search keyword, that element needs to snap to the front > of the list. I know this post regards the function passing, but, on you specific problem, can't you just ... sort the list with a custom key? something like (new list) >>> sorted(['no_a', 'yes_c', 'no_b', 'yes_z', 'no_y', 'yes_x'], ... key=lambda e: not e.startswith('yes')) ['yes_c', 'yes_z', 'yes_x', 'no_a', 'no_b', 'no_y'] or (in place) >>> l = ['no_a', 'yes_c', 'no_b', 'yes_z', 'no_y', 'yes_x'] >>> l.sort(key=lambda e: not e.startswith('yes')) >>> l ['yes_c', 'yes_z', 'yes_x', 'no_a', 'no_b', 'no_y'] -- By ZeD From michael.selik at gmail.com Sat Apr 2 01:51:46 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sat, 02 Apr 2016 05:51:46 +0000 Subject: Drowning in a teacup? In-Reply-To: References: Message-ID: On Sat, Apr 2, 2016, 1:46 AM Vito De Tullio wrote: > Fillmore wrote: > > > I need to scan a list of strings. If one of the elements matches the > > beginning of a search keyword, that element needs to snap to the front > > of the list. > > I know this post regards the function passing, but, on you specific > problem, > can't you just ... sort the list with a custom key? > > something like (new list) > > >>> sorted(['no_a', 'yes_c', 'no_b', 'yes_z', 'no_y', 'yes_x'], > ... key=lambda e: not e.startswith('yes')) > ['yes_c', 'yes_z', 'yes_x', 'no_a', 'no_b', 'no_y'] > > or (in place) > > >>> l = ['no_a', 'yes_c', 'no_b', 'yes_z', 'no_y', 'yes_x'] > >>> l.sort(key=lambda e: not e.startswith('yes')) > >>> l > ['yes_c', 'yes_z', 'yes_x', 'no_a', 'no_b', 'no_y'] > If the number of matches is small relative to the size of the list, I'd expect the sort would be slower than most of the other suggestions. > From vito.detullio at gmail.com Sat Apr 2 02:26:35 2016 From: vito.detullio at gmail.com (Vito De Tullio) Date: Sat, 02 Apr 2016 08:26:35 +0200 Subject: Drowning in a teacup? References: Message-ID: Michael Selik wrote: >> > I need to scan a list of strings. If one of the elements matches the >> > beginning of a search keyword, that element needs to snap to the front >> > of the list. >> >> I know this post regards the function passing, but, on you specific >> problem, >> can't you just ... sort the list with a custom key? > > If the number of matches is small relative to the size of the list, I'd > expect the sort would be slower than most of the other suggestions. umm... I take the liberty to set up a little test $ cat test_sort_prefix.py #!/usr/bin/env python3 from sys import argv from timeit import timeit def sort_in_place(l): def key(e): return not e.startswith('yes') l.sort(key=key) def original_solution(mylist): for i in range(len(mylist)): if(mylist[i].startswith('yes')): mylist[:] = [mylist[i]] + mylist[:i] + mylist[i+1:] def main(): if argv[1] == 'sort_in_place': f = sort_in_place elif argv[1] == 'original_solution': f = original_solution else: raise Exception() nomatches = int(argv[2]) matches = int(argv[3]) l = ["no_" for _ in range(nomatches)] + ["yes_" for _ in range(matches)] print(timeit("f(l)", number=100, globals={"f": f, "l": l})) if __name__ == '__main__': main() $ ./test_sort_prefix.py sort_in_place 1000000 3 33.260575089996564 $ ./test_sort_prefix.py original_solution 1000000 3 35.93009542999789 $ in my tests there is no sensible difference between the two solutions... and the number of matches is risible :) -- By ZeD From saxri89 at gmail.com Sat Apr 2 03:03:04 2016 From: saxri89 at gmail.com (Xristos Xristoou) Date: Sat, 2 Apr 2016 00:03:04 -0700 (PDT) Subject: install open cv on windows 10 and python 3.5 In-Reply-To: <8b4a2755-388a-43fa-8ab3-ae416ff87950@googlegroups.com> References: <8b4a2755-388a-43fa-8ab3-ae416ff87950@googlegroups.com> Message-ID: ?? ?????????, 1 ???????? 2016 - 1:56:52 ?.?. UTC+3, ? ??????? Xristos Xristoou ??????: > hello, > > i have windows 10 and python 3.5 and i want to use > open cv but i think so opencv work only on python 2.7 ? > and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv > but not work again yes i cant import cv2 on my idle that is my problem From nospam at dfs.com Sat Apr 2 03:56:12 2016 From: nospam at dfs.com (DFS) Date: Sat, 2 Apr 2016 03:56:12 -0400 Subject: extract rar In-Reply-To: References: Message-ID: On 4/1/2016 5:01 PM, Jianling Fan wrote: > Thanks, but the problem is that I am not allowed to install any > software in my office PC, even free software. > Normally, I use zip files but this time I need to extract a rar file. > I don't like to go to IT guys because it takes time. > That's why I am looking for an alternative way without installing > other software. > > Thanks, > > On 1 April 2016 at 13:37, Albert-Jan Roskam wrote: >> >> >> >>> Date: Fri, 1 Apr 2016 13:22:12 -0600 >>> Subject: extract rar >>> From: fanjianling at gmail.com >>> To: python-list at python.org >>> >>> Hello everyone, >>> >>> I am wondering is there any way to extract rar files by python without >>> WinRAR software? >>> >>> I tried Archive() and patool, but seems they required the WinRAR software. >> >> Perhaps 7-zip in a Python subprocess: >> http://superuser.com/questions/458643/unzip-rar-from-command-line-with-7-zip/464128 I'm not experienced with Python, but I found this: "pip install patool import patoolib patoolib.extract_archive("foo_bar.rar", outdir=".") Works on Windows and linux without any other libraries needed." http://stackoverflow.com/questions/17614467/how-can-unrar-a-file-with-python From rosuav at gmail.com Sat Apr 2 04:15:36 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Apr 2016 19:15:36 +1100 Subject: [beginner] What's wrong? In-Reply-To: <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> Message-ID: On Sat, Apr 2, 2016 at 3:27 PM, Random832 wrote: > On Fri, Apr 1, 2016, at 19:29, Michael Selik wrote: >> Humans have always had trouble with this, in many contexts. I remember >> being annoyed at folks saying the year 2000 was the first year of the new >> millennium, rather than 2001. They'd forgotten the Gregorian calendar >> starts from AD 1. > > Naturally, this means the first millennium was only 999 years long, and > all subsequent millennia were 1000 years long. (Whereas "millennium" is > defined as the set of all years of a given era for a given integer k > where y // 1000 == k. How else would you define it?) > > And if you want to get technical, the gregorian calendar starts from > some year no earlier than 1582, depending on the country. The year > numbering system has little to do with the calendar type - your > assertion in fact regards the BC/AD year numbering system, which was > invented by Bede. > > The astronomical year-numbering system, which does contain a year zero > (and uses negative numbers rather than a reverse-numbered "BC" era), and > is incidentally used by ISO 8601, was invented by Jacques Cassini in the > 17th century. > Are you sure? Because I'm pretty sure these folks were already talking about BC. http://xenohistorian.faithweb.com/holybook/quotes/YK.html ChrisA From vincent.vande.vyvre at telenet.be Sat Apr 2 05:14:41 2016 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Sat, 2 Apr 2016 11:14:41 +0200 Subject: Grab metadata from images and save to file, batch mode In-Reply-To: <75200b1c-eb54-4e03-a859-6c9631b9073a@googlegroups.com> References: <75200b1c-eb54-4e03-a859-6c9631b9073a@googlegroups.com> Message-ID: <56FF8D81.1060501@telenet.be> Le 01/04/2016 23:20, accessnewbie at gmail.com a ?crit : > I have a directory (and sub-directories) full of images that I want to cycle through and grab certain metadata values and save those values to a single row in a cvs file. I would like to tack on the full path name to the row as a separate value. > > Folder > C:\Images\Family > Brother.jpg > Sister.jpg > Mom.jpg > > Keys/Values > Original Date/Time > User Name > File Name > > Thus, data might look like this in a Family.csv file > 2014:11:10 13:52:12; BillyBob111; Brother.jpg; C:\Images\Family\Brother.jpg > 2015:10:54 11:45:34; BillyBob111; Sister.jpg; C:\Images\Family\Sister.jpg > 2010:10:31 19:22:11; SallySue232; Mom.jpg; C:\Images\Family\Mom.jpg > > Big time noob. Much of what I have read cites command line examples dealing with single files and no info as to how to extract specific keys and their values. > What module would some of you users recommend I use (I want it to be python as that is what I am trying to learn) > > Can you give me some coding suggestions to get me goings? I haven't found any substantive scripts to use as guides. > > Many thanks in advance Have a look at py3exiv2: http://python3-exiv2.readthedocs.org/en/latest/ Vincent From steve at pearwood.info Sat Apr 2 06:09:53 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 02 Apr 2016 21:09:53 +1100 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <874mblrsr1.fsf@elektro.pacujo.net> Message-ID: <56ff9a73$0$1599$c3e8da3$5496439d@news.astraweb.com> On Sat, 2 Apr 2016 07:14 am, Marko Rauhamaa wrote: > There's a bit of a cognitive dissonance between iterables and iterators. > On the one hand, they behave identically in many contexts. On the other > hand, the distinction is crucial in some special cases. Iterable just means "something which can be iterated over". Anything which you can feed directly into a for-loop: for x in obj: ... is by definition an iterable. The particular mechanism by which iteration is performed is unspecified. In Python today, there are two specific mechanisms, although in practice only one commonly is used. The older of the two is the "Sequence Protocol", which says that iteration is performed by repeatedly fetching an item from the object with an incrementing index until IndexError is raised: x = obj[0] x = obj[1] x = obj[2] ... The newer, and more common, mechanism is to call iter(obj) to get an iterator, then repeatedly call next(iterator) until it raises StopIteration. it = iter(obj) x = next(it) x = next(it) x = next(it) ... So what's an iterator? Any object which obeys the "Iterator Protocol". The rules for the protocol are: - the object must provide two methods, __iter__ and __next__; - __iter__ must return self; - __next__ must return the next value in the sequence, or raise StopIteration. range objects themselves do not obey the iterator protocol, which makes them not iterators: py> o = range(23) py> iter(o) is o False py> hasattr(o, '__next__') False But they are *iterable* since you can call iter on a range object and get an iterator: py> it = iter(o) py> iter(it) is it True py> hasattr(it, '__next__') True > (Somehow, the difference between iterables and iterators is analogous > with the difference between C's arrays and pointers.) I don't understand this analogy. Can you explain please? -- Steven From __peter__ at web.de Sat Apr 2 06:31:30 2016 From: __peter__ at web.de (Peter Otten) Date: Sat, 02 Apr 2016 12:31:30 +0200 Subject: Drowning in a teacup? References: Message-ID: Vito De Tullio wrote: > Michael Selik wrote: > >>> > I need to scan a list of strings. If one of the elements matches the >>> > beginning of a search keyword, that element needs to snap to the front >>> > of the list. >>> >>> I know this post regards the function passing, but, on you specific >>> problem, >>> can't you just ... sort the list with a custom key? >> >> If the number of matches is small relative to the size of the list, I'd >> expect the sort would be slower than most of the other suggestions. > > umm... I take the liberty to set up a little test > > $ cat test_sort_prefix.py > #!/usr/bin/env python3 > > from sys import argv > from timeit import timeit > > > def sort_in_place(l): > def key(e): > return not e.startswith('yes') > l.sort(key=key) > > > def original_solution(mylist): > for i in range(len(mylist)): > if(mylist[i].startswith('yes')): > mylist[:] = [mylist[i]] + mylist[:i] + mylist[i+1:] original_solution() reverses the order of the matches while sort_in_place() doesn't. If the order is not relevant I'd try something like def exchange(items): pos = 0 for index, item in enumerate(items): if item.startswith("yes"): items[pos], items[index] = item, items[pos] pos += 1 > def main(): > if argv[1] == 'sort_in_place': > f = sort_in_place > elif argv[1] == 'original_solution': > f = original_solution > else: > raise Exception() > > nomatches = int(argv[2]) > matches = int(argv[3]) > > l = ["no_" for _ in range(nomatches)] + ["yes_" for _ in > range(matches)] Python's timsort knows how to deal with (partially) sorted lists. I suggest that you add random.seed(42) # same list for all script invocations random.shuffle(l) here to spread the matches somewhat over the list. > print(timeit("f(l)", number=100, globals={"f": f, "l": l})) Remember that f(l) modifies l, so all but the first invocation will see a list where all matches are at the beginning. In other words: in 99 out of 100 runs the list is already sorted. While adding the overhead of copying the list I would expect the results of timeit("f(l[:])", ...) to be more realistic. > if __name__ == '__main__': > main() > $ ./test_sort_prefix.py sort_in_place 1000000 3 > 33.260575089996564 > $ ./test_sort_prefix.py original_solution 1000000 3 > 35.93009542999789 > $ > > > in my tests there is no sensible difference between the two solutions... > and the number of matches is risible :) Indeed, as the number of matches rises your sort() approach will likely fare better. Your conclusions may be correct, but the benchmark to support them is flawed. From marko at pacujo.net Sat Apr 2 06:48:20 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 02 Apr 2016 13:48:20 +0300 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <874mblrsr1.fsf@elektro.pacujo.net> <56ff9a73$0$1599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87oa9sqoaz.fsf@elektro.pacujo.net> Steven D'Aprano : > On Sat, 2 Apr 2016 07:14 am, Marko Rauhamaa wrote: >> (Somehow, the difference between iterables and iterators is analogous >> with the difference between C's arrays and pointers.) > > I don't understand this analogy. Can you explain please? In numerous contexts, T a[N] and T *a are interchangeable. In fact, C has no rvalue notation for an array. For any other type, this works: T a, b; a = b; However, if T is an array type, the compiler complains: error: assignment to expression with array type This C innovation of blurring the lines between arrays and pointers is very different of the type system of Pascal, whose arrays behave like any other type. C could have treated arrays like other types without any loss of generality. Then you'd have to write: T a[N], *b; b = &a[0]; for: T a[N], *b; b = a; Semantically, as well, C arrays are iterables, and pointers are used to iterate over the elements of an array. Similarly, Python could have kept iterables and iterators in their separate corners by specifying: * iter(iterable) returns an iterator * iter(iterator) typically raises an Exception * the for statement requires an iterator Then, you'd have to write: for i in iter([1, 2, 3]): ... Not recommending anything one way or another. Marko From breamoreboy at yahoo.co.uk Sat Apr 2 07:53:49 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 2 Apr 2016 12:53:49 +0100 Subject: Drowning in a teacup? In-Reply-To: References: Message-ID: On 02/04/2016 06:51, Michael Selik wrote: > On Sat, Apr 2, 2016, 1:46 AM Vito De Tullio wrote: > >> Fillmore wrote: >> >>> I need to scan a list of strings. If one of the elements matches the >>> beginning of a search keyword, that element needs to snap to the front >>> of the list. >> >> I know this post regards the function passing, but, on you specific >> problem, >> can't you just ... sort the list with a custom key? >> >> something like (new list) >> >> >>> sorted(['no_a', 'yes_c', 'no_b', 'yes_z', 'no_y', 'yes_x'], >> ... key=lambda e: not e.startswith('yes')) >> ['yes_c', 'yes_z', 'yes_x', 'no_a', 'no_b', 'no_y'] >> >> or (in place) >> >> >>> l = ['no_a', 'yes_c', 'no_b', 'yes_z', 'no_y', 'yes_x'] >> >>> l.sort(key=lambda e: not e.startswith('yes')) >> >>> l >> ['yes_c', 'yes_z', 'yes_x', 'no_a', 'no_b', 'no_y'] >> > > If the number of matches is small relative to the size of the list, I'd > expect the sort would be slower than most of the other suggestions. > My gut feeling about how fast something is in Python has never once been right in 15 years. There is only way way to find out, measure it with things like https://docs.python.org/3/library/profile.html and https://docs.python.org/3/library/timeit.html. IIRC Steven D'Aprano has a wrapper for the latter called Stopwatch. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From michael.selik at gmail.com Sat Apr 2 10:36:45 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sat, 02 Apr 2016 14:36:45 +0000 Subject: Drowning in a teacup? In-Reply-To: References: Message-ID: On Sat, Apr 2, 2016 at 6:32 AM Peter Otten <__peter__ at web.de> wrote: > Vito De Tullio wrote: > > > Michael Selik wrote: > > > >>> > I need to scan a list of strings. If one of the elements matches the > >>> > beginning of a search keyword, that element needs to snap to the > front > >>> > of the list. > >>> > >>> I know this post regards the function passing, but, on you specific > >>> problem, > >>> can't you just ... sort the list with a custom key? > >> > >> If the number of matches is small relative to the size of the list, I'd > >> expect the sort would be slower than most of the other suggestions. > > > > umm... I take the liberty to set up a little test > > > > $ cat test_sort_prefix.py > > #!/usr/bin/env python3 > > > > from sys import argv > > from timeit import timeit > > > > > > def sort_in_place(l): > > def key(e): > > return not e.startswith('yes') > > l.sort(key=key) > > > > > > def original_solution(mylist): > > for i in range(len(mylist)): > > if(mylist[i].startswith('yes')): > > mylist[:] = [mylist[i]] + mylist[:i] + mylist[i+1:] > > original_solution() reverses the order of the matches while sort_in_place() > doesn't. If the order is not relevant I'd try something like > > def exchange(items): > pos = 0 > for index, item in enumerate(items): > if item.startswith("yes"): > items[pos], items[index] = item, items[pos] > pos += 1 > > > def main(): > > if argv[1] == 'sort_in_place': > > f = sort_in_place > > elif argv[1] == 'original_solution': > > f = original_solution > > else: > > raise Exception() > > > > nomatches = int(argv[2]) > > matches = int(argv[3]) > > > > l = ["no_" for _ in range(nomatches)] + ["yes_" for _ in > > range(matches)] > > Python's timsort knows how to deal with (partially) sorted lists. I suggest > that you add > > random.seed(42) # same list for all script invocations > random.shuffle(l) > > here to spread the matches somewhat over the list. > > > print(timeit("f(l)", number=100, globals={"f": f, "l": l})) > > Remember that f(l) modifies l, so all but the first invocation will see a > list where all matches are at the beginning. In other words: in 99 out of > 100 runs the list is already sorted. > > While adding the overhead of copying the list I would expect the results of > > timeit("f(l[:])", ...) > > to be more realistic. > > > if __name__ == '__main__': > > main() > > $ ./test_sort_prefix.py sort_in_place 1000000 3 > > 33.260575089996564 > > $ ./test_sort_prefix.py original_solution 1000000 3 > > 35.93009542999789 > > $ > > > > > > in my tests there is no sensible difference between the two solutions... > > and the number of matches is risible :) > > Indeed, as the number of matches rises your sort() approach will likely > fare > better. > > Your conclusions may be correct, but the benchmark to support them is > flawed. > > Option 1: scan and match, pop, insert Scan and match is O(n) pop is O(n) ... gotta shift everything over one after deleting insert is O(n) on a list, better use deque.appendleft for O(1) Option 2: map keyfunc, sort Mapping the keyfunction is O(n) (tim)Sorting is O(n log n) worst case, O(n) best case. Option 1 using a deque will be O(n). Option 2 will be O(n log n) worst case and O(n) best case. On small datasets the constant factors matter, but then it's small, so who cares about speed? (partially joking) From michael.selik at gmail.com Sat Apr 2 10:48:05 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sat, 02 Apr 2016 14:48:05 +0000 Subject: [beginner] What's wrong? In-Reply-To: References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> Message-ID: On Sat, Apr 2, 2016 at 4:16 AM Chris Angelico wrote: > On Sat, Apr 2, 2016 at 3:27 PM, Random832 wrote: > > On Fri, Apr 1, 2016, at 19:29, Michael Selik wrote: > >> Humans have always had trouble with this, in many contexts. I remember > >> being annoyed at folks saying the year 2000 was the first year of the > new > >> millennium, rather than 2001. They'd forgotten the Gregorian calendar > >> starts from AD 1. > > > > Naturally, this means the first millennium was only 999 years long, and > > all subsequent millennia were 1000 years long. (Whereas "millennium" is > > defined as the set of all years of a given era for a given integer k > > where y // 1000 == k. How else would you define it?) > > > > And if you want to get technical, the gregorian calendar starts from > > some year no earlier than 1582, depending on the country. The year > > numbering system has little to do with the calendar type - your > > assertion in fact regards the BC/AD year numbering system, which was > > invented by Bede. > > > > The astronomical year-numbering system, which does contain a year zero > > (and uses negative numbers rather than a reverse-numbered "BC" era), and > > is incidentally used by ISO 8601, was invented by Jacques Cassini in the > > 17th century. > > > > Are you sure? Because I'm pretty sure these folks were already talking > about BC. > > http://xenohistorian.faithweb.com/holybook/quotes/YK.html > > If they'd only used Unicode, they could have said "?ou" in prayer and "?ousand" for the year. BTW, I finally know why there are all those "Ye Olde ...". https://en.wikipedia.org/wiki/Thorn_(letter) From rosuav at gmail.com Sat Apr 2 10:55:25 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Apr 2016 01:55:25 +1100 Subject: [beginner] What's wrong? In-Reply-To: References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> Message-ID: On Sun, Apr 3, 2016 at 1:48 AM, Michael Selik wrote: > If they'd only used Unicode, they could have said "?ou" in prayer and > "?ousand" for the year. > > BTW, I finally know why there are all those "Ye Olde ...". > https://en.wikipedia.org/wiki/Thorn_(letter) Yep! And the letters (thorn and eth) survive in a very few languages (Icelandic, notably). Fortunately, Python 3 lets you use it in identifiers. ChrisA From marko at pacujo.net Sat Apr 2 11:07:55 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 02 Apr 2016 18:07:55 +0300 Subject: [beginner] What's wrong? References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> Message-ID: <87bn5sqcac.fsf@elektro.pacujo.net> Chris Angelico : > Yep! And the letters (thorn and eth) survive in a very few languages > (Icelandic, notably). Fortunately, Python 3 lets you use it in > identifiers. While it is fine for Python to support Unicode to its fullest, I don't think it's a good idea for a programmer to use non-English identifiers. The (few) keywords are in English anyway. Imagine reading code like this: for oppilas in luokka: if oppilas.hyl?tty(): oppilas.ilmoita(oppilas.koetulokset) which looks nauseating whether you are an English-speaker or Finnish-speaker. Marko From breamoreboy at yahoo.co.uk Sat Apr 2 11:11:19 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 2 Apr 2016 16:11:19 +0100 Subject: tkinter Entry validation modes Message-ID: A typical call to create an Entry field would be:- e = Entry(master, validate='all', ...) Once this call has been made is it possible to change the validation mode at runtime? Background, I'm knocking up an app so I can play with the various modes so that I can see how they work, as I'm just venturing into the tkinter world. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Sat Apr 2 11:36:48 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Apr 2016 02:36:48 +1100 Subject: [beginner] What's wrong? In-Reply-To: <87bn5sqcac.fsf@elektro.pacujo.net> References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> Message-ID: On Sun, Apr 3, 2016 at 2:07 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> Yep! And the letters (thorn and eth) survive in a very few languages >> (Icelandic, notably). Fortunately, Python 3 lets you use it in >> identifiers. > > While it is fine for Python to support Unicode to its fullest, I don't > think it's a good idea for a programmer to use non-English identifiers. > > The (few) keywords are in English anyway. Imagine reading code like > this: > > for oppilas in luokka: > if oppilas.hyl?tty(): > oppilas.ilmoita(oppilas.koetulokset) > > which looks nauseating whether you are an English-speaker or > Finnish-speaker. I disagree. I've spoken with people who've used that kind of bilingual hybrid in regular conversation. There's a channel I hang out on that mainly speaks Turkish, but some sentences are a Turkish-English hybrid; usually they use Turkish grammar (subject-object-verb), as that's the native language of most of the people there. A lot of Python's keywords are derived from English, yes, but once they've been abbreviated some, and have slid in meaning from their original words, they become jargon that can plausibly be imported into other languages. Words like "lambda" aren't English, so other Roman alphabet languages are at no disadvantage there; words like "def" might easily acquire back-formation justifications/mnemonics in other languages. It's only the words that truly are English terms ("while") that are problematic, and there's only a handful of those to learn. Of course, there's the whole standard library, which is written in English. You could translate that without breaking everything, but it'd be a big job. The main reason for permitting non-English identifiers is to let people synchronize on external naming conventions. Suppose you create a form (web or GUI or something) and ask a human to key in half a dozen pieces of information, and then do some arithmetic on them. In English, we can do this kind of thing: name = input("Object name: ") length = int(input("Length: ")) width = int(input("Width: ")) height = int(input("Height: ")) volume = length * width * height print("Volume of %s is: %d" % (name, volume)) Note how every piece of input or output is directly associated with a keyword, which is used as the identifier in the code. This is important; when you come to debug code like this (let's assume there's a lot more of it than this), you can glance at the form, glance at the code, and not have to maintain a mental translation table. This is why we use identifiers in the first place - to identify things! Okay. So far, so good. Let's translate all that into Russian. (I don't speak Russian, so the actual translation has been done with Google Translate. Apologies in advance if the Russian text here says something horribly wrong.) ???????? = input("???????? ???????: ") ????? = int(input("?????: ")) ?????? = int(input("??????: ")) ?????? = int(input("??????: ")) ????? = ????? * ?????? * ?????? print("????? %s ????? %d" % (????????, ?????)) Its a hybrid of English function names and Russian text strings and identifiers. But if you force everyone to write their identifiers in English, all you get is a hybrid of English function names and identifiers and Russian text strings - no improvement at all! Or, more likely, you'll get this: nazvanie = input("???????? ???????: ") dlina = int(input("?????: ")) shirina = int(input("??????: ")) vysota = int(input("??????: ")) obyem = dlina * shirina * vysota print("????? %s ????? %d" % (nazvanie, obyem)) Is that an improvement? I don't think so. Far better to let people write their names in any way that makes sense for their code. ChrisA From steve at pearwood.info Sat Apr 2 12:06:08 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 03 Apr 2016 02:06:08 +1000 Subject: [beginner] What's wrong? References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> Message-ID: <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> On Sun, 3 Apr 2016 02:07 am, Marko Rauhamaa wrote: > I don't think it's a good idea for a programmer to use non-English > identifiers. So you're saying that learning to be a fluent speaker of English is a pre-requisite of being a programmer? I'd rather read: for oppilas in luokka: if oppilas.hyl?tty(): oppilas.ilmoita(oppilas.koetulokset) than either of these: for cornea in excellence: if cornea.marooned(): cornea.amuse(cornea.eventualities) for pupel in clas: if pupel.abandened(): pupel.plaese(pupel.resolts) Google translate suggests Marko's code means: for pupil in class: if pupil.abandoned(): pupil.please(pupil.results) -- Steven From marko at pacujo.net Sat Apr 2 12:44:22 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 02 Apr 2016 19:44:22 +0300 Subject: [beginner] What's wrong? References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87h9fkq7tl.fsf@elektro.pacujo.net> Steven D'Aprano : > I'd rather read: > > for oppilas in luokka: > if oppilas.hyl?tty(): > oppilas.ilmoita(oppilas.koetulokset) > > [...] > > Google translate suggests Marko's code means: > > for pupil in class: > if pupil.abandoned(): > pupil.please(pupil.results) "Hyl?tty" in this context means "rejected." "Ilmoita" means "inform, announce, let know." > So you're saying that learning to be a fluent speaker of English is a > pre-requisite of being a programmer? No more than learning Latin is a prerequisite of being a doctor. Nowadays software companies and communities are international. You never know who needs to maintain your code. At work, I need to maintain code that was created in Japan, with coworkers from all over the world. The Japanese author had had a hard time with English, and made some awkward naming choices, but had the common sense to use English-only names in his code. I also think log file timestamps should be expressed in UTC. Marko From PointedEars at web.de Sat Apr 2 13:12:13 2016 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sat, 02 Apr 2016 19:12:13 +0200 Subject: [beginner] What's wrong? References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> Message-ID: <3524319.g0I1c1cpMS@PointedEars.de> Marko Rauhamaa wrote: > Steven D'Aprano : >> So you're saying that learning to be a fluent speaker of English is a >> pre-requisite of being a programmer? > > No more than learning Latin is a prerequisite of being a doctor. Full ACK. Probably starting with the Industrial Revolution enabled by the improvements of the steam machine in England, English has become the /lingua franca/ of technology (even though the French often still disagree, preferring words like ? ordinateur ? and ? octet ? over ?computer? and ?byte?, respectively?). (With the Internet at the latest, then, it has also become the /lingua franca/ of science, although Latin terms are common in medicine.) > Nowadays software companies and communities are international. You never > know who needs to maintain your code. At work, I need to maintain code > that was created in Japan, with coworkers from all over the world. The > Japanese author had had a hard time with English, and made some > awkward naming choices, but had the common sense to use English-only > names in his code. One will have a hard time finding a company or community, international or not, that does not have at least a basic knowledge of English included in what they require of a software developer. ____________ ? Years ago, I was helping a French colleague with her computer, and was surprised to read ?Mo? instead of ?MB? in the status bar of Windows Explorer. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From PointedEars at web.de Sat Apr 2 13:20:38 2016 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sat, 02 Apr 2016 19:20:38 +0200 Subject: writing to command line thru python gui References: Message-ID: <47108471.0biVFO8ft1@PointedEars.de> A. ElKader wrote: > I posted this question, no reply : > > Any advice : > > http://unix.stackexchange.com/questions/273573/write-to-terminal-in-tkinter-gui I do not think that this newsgroup/mailing list is meant as an advertisement board to get your questions answered on Q&A forums on the Web, or to get your questions answered *here* that you ask *there*. So if you have a question, you should ask it *here*. If you do so, you would be well-advised to post it using your real name. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From rustompmody at gmail.com Sat Apr 2 13:28:17 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 2 Apr 2016 10:28:17 -0700 (PDT) Subject: [beginner] What's wrong? In-Reply-To: <3524319.g0I1c1cpMS@PointedEars.de> References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> Message-ID: On Saturday, April 2, 2016 at 10:42:27 PM UTC+5:30, Thomas 'PointedEars' Lahn wrote: > Marko Rauhamaa wrote: > > > Steven D'Aprano : > >> So you're saying that learning to be a fluent speaker of English is a > >> pre-requisite of being a programmer? > > > > No more than learning Latin is a prerequisite of being a doctor. > > Full ACK. Probably starting with the Industrial Revolution enabled by the > improvements of the steam machine in England, English has become the /lingua > franca/ of technology (even though the French often still disagree, > preferring words like ? ordinateur ? and ? octet ? over ?computer? and > ?byte?, respectively?). (With the Internet at the latest, then, it has also > become the /lingua franca/ of science, although Latin terms are common in > medicine.) IMHO the cavalier usage of random alphabet-soup for identifiers can lead to worse than just aesthetic unpleasantness: https://en.wikipedia.org/wiki/IDN_homograph_attack When python went to full unicode identifers it should have also added pragmas for which blocks the programmer intended to use -- something like a charset declaration of html. This way if the programmer says "I want latin and greek" and then A and ? get mixed up well he asked for it. If he didn't ask then springing it on him seems unnecessary and uncalled for From best_lay at yahoo.com Sat Apr 2 13:47:53 2016 From: best_lay at yahoo.com (Wildman) Date: Sat, 02 Apr 2016 12:47:53 -0500 Subject: tkinter Entry validation modes References: Message-ID: On Sat, 02 Apr 2016 16:11:19 +0100, Mark Lawrence wrote: > A typical call to create an Entry field would be:- > > e = Entry(master, validate='all', ...) > > Once this call has been made is it possible to change the validation > mode at runtime? Background, I'm knocking up an app so I can play with > the various modes so that I can see how they work, as I'm just venturing > into the tkinter world. This is off the top of my head and I have not tested it. Since validate is a config option this might do it: e.config(validate='focus') -- GNU/Linux user #557453 The cow died so I don't need your bull! From marko at pacujo.net Sat Apr 2 14:43:26 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 02 Apr 2016 21:43:26 +0300 Subject: [beginner] What's wrong? References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> Message-ID: <87d1q7rgvl.fsf@elektro.pacujo.net> Rustom Mody : > When python went to full unicode identifers it should have also added > pragmas for which blocks the programmer intended to use -- something > like a charset declaration of html. You are being silly. Marko From tjreedy at udel.edu Sat Apr 2 14:45:33 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 2 Apr 2016 14:45:33 -0400 Subject: tkinter Entry validation modes In-Reply-To: References: Message-ID: On 4/2/2016 11:11 AM, Mark Lawrence via Python-list wrote: > A typical call to create an Entry field would be:- > > e = Entry(master, validate='all', ...) > > Once this call has been made is it possible to change the validation > mode at runtime? AFAIK, every keyword-only configuration option can be changed. e['validate'] = xyz e.config(validate=xyz) -- Terry Jan Reedy From tjreedy at udel.edu Sat Apr 2 14:59:40 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 2 Apr 2016 14:59:40 -0400 Subject: [beginner] What's wrong? In-Reply-To: <87bn5sqcac.fsf@elektro.pacujo.net> References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> Message-ID: On 4/2/2016 11:07 AM, Marko Rauhamaa wrote: > While it is fine for Python to support Unicode to its fullest, I don't > think it's a good idea for a programmer to use non-English identifiers. Non-English identifiers can written, at least in romanized versions, in ascii. > The (few) keywords are in English anyway. Imagine reading code like > this: > > for oppilas in luokka: > if oppilas.hyl?tty(): > oppilas.ilmoita(oppilas.koetulokset) > > which looks nauseating whether you are an English-speaker or > Finnish-speaker. Your sense of nausea is different from others, so speak for yourself (as you did in the first sentence -- "I don't ..."). People were happily and routinely writing thing like the above (minus the accented char) in 2.x. I guess they must have kept your code out of your sight. -- Terry Jan Reedy From tjreedy at udel.edu Sat Apr 2 15:07:29 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 2 Apr 2016 15:07:29 -0400 Subject: [beginner] What's wrong? In-Reply-To: <87h9fkq7tl.fsf@elektro.pacujo.net> References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> Message-ID: On 4/2/2016 12:44 PM, Marko Rauhamaa wrote: > Nowadays software companies and communities are international. Grade school classrooms, especially pre-high school, are not. > You never know who needs to maintain your code. For one-off school assignments, nobody other than the author. > At work, I need to maintain code > that was created in Japan, with coworkers from all over the world. The > Japanese author had had a hard time with English, and made some > awkward naming choices, but had the common sense to use English-only > names in his code. Could not have been worse than semi-random ascii like x3tu9. > I also think log file timestamps should be expressed in UTC. I agree. Any translation to local time should be in the viewer. I presume this is already true for email and news message timestamps. -- Terry Jan Reedy From toddbyrne1046 at yahoo.com Sat Apr 2 15:14:32 2016 From: toddbyrne1046 at yahoo.com (Pythonnoob) Date: Sat, 2 Apr 2016 12:14:32 -0700 (PDT) Subject: Python program Message-ID: Hello, I am new to Python and programming in general. However, I have gained some skills in Python. I have been working with it in order to gain some real world problem solving skills for my job. I have written a program in Python track the number of visits customers make to our business based upon their account numbers. Right now we are doing this via paper. We have 7 computers. Each with a different user. We do have a network and server. I know this program will run on my computer and I can enter the information and update it from my computer. I want all of our associates to have the program on their computer and be able to update it in real time. So at the end of the day, week, month, etc..... the visits can be calculated. I know that I can install Python on each of the computers, but I know this would be local to their computer. I also know I could have our IT guy install the program on the server as well. But in order for the stats to be updated by all associates in real time , would I have to build a database and then get that installed on the server ? If so , how would some of you get this done? Besides writing the Python program, step by step what would you do and what other resources would you use to accomplish this? I am a complete noob at this. Forgive me for not knowing all of the proper terminology. I know that there are some real world solutions that Python can ultimately offer me and our company. Thank you for your time and knowledge ! From ned at nedbatchelder.com Sat Apr 2 15:26:44 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 2 Apr 2016 12:26:44 -0700 (PDT) Subject: writing to command line thru python gui In-Reply-To: <47108471.0biVFO8ft1@PointedEars.de> References: <47108471.0biVFO8ft1@PointedEars.de> Message-ID: <80696a23-aec7-4ce0-a7fe-8d2a0140b7eb@googlegroups.com> On Saturday, April 2, 2016 at 1:20:52 PM UTC-4, Thomas 'PointedEars' Lahn wrote: > A. ElKader wrote: > > > I posted this question, no reply : > > > > Any advice : > > > > http://unix.stackexchange.com/questions/273573/write-to-terminal-in-tkinter-gui > > I do not think that this newsgroup/mailing list is meant as an advertisement > board to get your questions answered on Q&A forums on the Web, or to get > your questions answered *here* that you ask *there*. Definitely ask your questions here. We prefer to have a complete conversation here rather than links off to other sites. > So if you have a question, you should ask it *here*. If you do so, you > would be well-advised to post it using your real name. Don't worry about this "real name" idea, it's just one of Thomas' quirks. --Ned. From ned at nedbatchelder.com Sat Apr 2 15:28:53 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 2 Apr 2016 12:28:53 -0700 (PDT) Subject: Drowning in a teacup? In-Reply-To: References: Message-ID: On Friday, April 1, 2016 at 4:27:30 PM UTC-4, Fillmore wrote: > notorious pass by reference vs pass by value biting me in the backside > here. Proceeding in order. As others have pointed out, this is false dichotomy. There are other possibilities than pass by reference and pass by value. Python (and many other languages) use something called pass by object or pass by sharing. This talk has details of how Python's names and values work: http://nedbatchelder.com/text/names1.html --Ned. From marko at pacujo.net Sat Apr 2 15:36:03 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 02 Apr 2016 22:36:03 +0300 Subject: [beginner] What's wrong? References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> Message-ID: <877fgfrefw.fsf@elektro.pacujo.net> Terry Reedy : > On 4/2/2016 12:44 PM, Marko Rauhamaa wrote: > >> Nowadays software companies and communities are international. > > Grade school classrooms, especially pre-high school, are not. Parenthetically, English teachers in Finland have been happy with how teenage boys' English grades have gone up with the advent of online gaming. High school boys get more top scores in English than girls. According to a recent master's thesis, the most important causal factor for the boys' success is spending a lot of time playing computer games. An English language professor wants to raise awareness about the role of games for language skills. Marko From ned at nedbatchelder.com Sat Apr 2 15:47:01 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 2 Apr 2016 12:47:01 -0700 (PDT) Subject: Strange range In-Reply-To: <87lh4xjt37.fsf@elektro.pacujo.net> References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> Message-ID: <1671ea2b-09ff-4745-a6e7-d2c57864cba3@googlegroups.com> On Friday, April 1, 2016 at 10:34:50 AM UTC-4, Marko Rauhamaa wrote: > Chris Angelico : > > > *A range object is not an iterator.* > > We now have learned as much. > > However, doesn't that extra level of indirection seem like an odd > choice? I agree that it is surprising (and confusing) at first. It took me some getting used to. Now I think of it like this: An iterable is a thing that could be iterated, that is, it has a sequence of things. An iterator holds the current status of a thing that is being iterated. For example, the pages of a book are an iterable (we could iterate over them), and a bookmark is an iterator for the pages of a book: it knows where we are in the iteration. This analogy illuminates an important point: a single iterable can have a number of active iterators working over it at once, just as a book can have a number of bookmarks in it at once. nums = [1, 2, 3] for i in nums: for j in nums: print i, j This prints all the pairs of numbers, because the iterator in the first loop is independent of the iterator(s) in the second loop, even though they are iterating over the same iterator (the nums list). Without the extra indirection of iterators over iterables, this code would get tangled up. --Ned. From random832 at fastmail.com Sat Apr 2 15:54:28 2016 From: random832 at fastmail.com (Random832) Date: Sat, 02 Apr 2016 15:54:28 -0400 Subject: Drowning in a teacup? In-Reply-To: References: Message-ID: <1459626868.1382635.566734322.250BAE2A@webmail.messagingengine.com> On Sat, Apr 2, 2016, at 15:28, Ned Batchelder wrote: > On Friday, April 1, 2016 at 4:27:30 PM UTC-4, Fillmore wrote: > > notorious pass by reference vs pass by value biting me in the backside > > here. Proceeding in order. > > As others have pointed out, this is false dichotomy. There are other > possibilities than pass by reference and pass by value. Python (and > many other languages) use something called pass by object or pass by > sharing. I think that this arises from a confusion as to what a "value" is in "pass by value". The point of it being pass by value is that there is no statement you can execute in the function that has the effect of an assignment of the expression that was passed in from the caller. This holds no matter what kind of object is passed in or what mutable properties it has or does not have. From marko at pacujo.net Sat Apr 2 16:44:16 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 02 Apr 2016 23:44:16 +0300 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <1671ea2b-09ff-4745-a6e7-d2c57864cba3@googlegroups.com> Message-ID: <87zitbpwpr.fsf@elektro.pacujo.net> Ned Batchelder : > This analogy illuminates an important point: a single iterable can have > a number of active iterators working over it at once, just as a book can > have a number of bookmarks in it at once. > > nums = [1, 2, 3] > for i in nums: > for j in nums: > print i, j > > This prints all the pairs of numbers, because the iterator in the first > loop is independent of the iterator(s) in the second loop, even though > they are iterating over the same iterator (the nums list). Without the > extra indirection of iterators over iterables, this code would get > tangled up. I don't have a problem with a list being a "reiterable." I only was surprised about range(), which I had thought to be a plain, down-to-earth iterator. There's barely any other practical use for a range, I believe. Marko From rosuav at gmail.com Sat Apr 2 17:03:13 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Apr 2016 07:03:13 +1000 Subject: Python program In-Reply-To: References: Message-ID: On Sun, Apr 3, 2016 at 5:14 AM, Pythonnoob via Python-list wrote: > I have written a program in Python track the number of visits customers make to our business based upon their account numbers. Right now we are doing this via paper. We have 7 computers. Each with a different user. We do have a network and server. I know this program will run on my computer and I can enter the information and update it from my computer. I want all of our associates to have the program on their computer and be able to update it in real time. So at the end of the day, week, month, etc..... the visits can be calculated. I know that I can install Python on each of the computers, but I know this would be local to their computer. I also know I could have our IT guy install the program on the server as well. But in order for the stats to be updated by all associates in real time , would I have to build a database and then get that installed on the server ? > Hi! Welcome to the list. (I'd like to be able to greet you by name, but I don't think "Noob" is a name. Are you Todd? Or perhaps I can call you Christine, after CookingForNoobs?) It might not be *necessary* to do it that way, but I would certainly recommend it. These days, the easiest way to arrange these sorts of things would be a web server that manages everything, and have your associates point their web browsers to it. It's a little bit of work to set up, but everyone knows how to use a web browser these days, and they don't need to install Python. Have you any experience with building web sites in Python? If not, there are lots of tutorials around. Start with Python 3 and Flask, and put together an HTML form to accept information from one of your associates, with another function to process the responses. Use a PostgreSQL database to store the information, and either psycopg2 or SQLAlchemy to access that from Python. There are other ways to do things, but this is how I'd recommend it. That's a very VERY basic roadmap; it's meant to be enough for you to recognize which parts you don't know yet. From there, you can hopefully dig into the project a bit, and add some stats and stuff like that. Should be fun! ChrisA From rosuav at gmail.com Sat Apr 2 17:05:29 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Apr 2016 07:05:29 +1000 Subject: Strange range In-Reply-To: <87zitbpwpr.fsf@elektro.pacujo.net> References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <1671ea2b-09ff-4745-a6e7-d2c57864cba3@googlegroups.com> <87zitbpwpr.fsf@elektro.pacujo.net> Message-ID: On Sun, Apr 3, 2016 at 6:44 AM, Marko Rauhamaa wrote: > I don't have a problem with a list being a "reiterable." I only was > surprised about range(), which I had thought to be a plain, > down-to-earth iterator. There's barely any other practical use for a > range, I believe. That's Blub's Paradox right there. There are lots of other uses for range(), but you just haven't used them. ChrisA From marko at pacujo.net Sat Apr 2 17:40:22 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 03 Apr 2016 00:40:22 +0300 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <1671ea2b-09ff-4745-a6e7-d2c57864cba3@googlegroups.com> <87zitbpwpr.fsf@elektro.pacujo.net> Message-ID: <87vb3zpu49.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Apr 3, 2016 at 6:44 AM, Marko Rauhamaa wrote: >> I don't have a problem with a list being a "reiterable." I only was >> surprised about range(), which I had thought to be a plain, >> down-to-earth iterator. There's barely any other practical use for a >> range, I believe. > > That's Blub's Paradox right there. There are lots of other uses for > range(), but you just haven't used them. That's why I was looking for counterexamples in the standard library sources but couldn't really spot any (apart from a single reversed(range())). Maybe I wasn't looking carefully enough. As far as I can tell, range() is simply Python's way of implementing classical integral "for" loops. Marko From michael.selik at gmail.com Sat Apr 2 17:42:49 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sat, 02 Apr 2016 21:42:49 +0000 Subject: [beginner] What's wrong? In-Reply-To: <877fgfrefw.fsf@elektro.pacujo.net> References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <877fgfrefw.fsf@elektro.pacujo.net> Message-ID: On Sat, Apr 2, 2016, 3:40 PM Marko Rauhamaa wrote: > Terry Reedy : > > > On 4/2/2016 12:44 PM, Marko Rauhamaa wrote: > > > >> Nowadays software companies and communities are international. > > > > Grade school classrooms, especially pre-high school, are not. > > Parenthetically, English teachers in Finland have been happy with how > teenage boys' English grades have gone up with the advent of online > gaming. > > High school boys get more top scores in English than girls. According > to a recent master's thesis, the most important causal factor for the > boys' success is spending a lot of time playing computer games. An > English language professor wants to raise awareness about the role of > games for language skills. > Gaming also helps your reaction time. Normally 0.3 ms, but 0.1 ms for top gamers. And fighter pilots. > From ned at nedbatchelder.com Sat Apr 2 17:50:23 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 2 Apr 2016 14:50:23 -0700 (PDT) Subject: Strange range In-Reply-To: <87vb3zpu49.fsf@elektro.pacujo.net> References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <1671ea2b-09ff-4745-a6e7-d2c57864cba3@googlegroups.com> <87zitbpwpr.fsf@elektro.pacujo.net> <87vb3zpu49.fsf@elektro.pacujo.net> Message-ID: On Saturday, April 2, 2016 at 5:40:35 PM UTC-4, Marko Rauhamaa wrote: > Chris Angelico : > > > On Sun, Apr 3, 2016 at 6:44 AM, Marko Rauhamaa wrote: > >> I don't have a problem with a list being a "reiterable." I only was > >> surprised about range(), which I had thought to be a plain, > >> down-to-earth iterator. There's barely any other practical use for a > >> range, I believe. > > > > That's Blub's Paradox right there. There are lots of other uses for > > range(), but you just haven't used them. > > That's why I was looking for counterexamples in the standard library > sources but couldn't really spot any (apart from a single > reversed(range())). Maybe I wasn't looking carefully enough. > > As far as I can tell, range() is simply Python's way of implementing > classical integral "for" loops. You can easily use range in my double-loop example, or a variant: def pairs(n): nums = range(n) for i in nums: for j in nums: yield i, j More importantly, range can be useful as an argument to a function that doesn't realize it's receiving a range, as in the better way to implement pairs: from itertools import product def pairs(n): return product(range(n), repeat=2) By making range an iterable like lots of other things, it's more useful in these kinds of compositional situations. --Ned. From squatsquadonline at gmail.com Sat Apr 2 17:55:19 2016 From: squatsquadonline at gmail.com (Loop.IO) Date: Sat, 2 Apr 2016 14:55:19 -0700 (PDT) Subject: [Beginner] Hanging in the code until I press return, can't figure it out Message-ID: Hey So I built a keylogger using python as a test, got the code from the tutorial online, I want to improve on it to make it more automated, but the issue I'm having is it won't create the file until I press return, any clues where I'm going wrong? If I press return it makes the batch file, otherwise it just hangs. CODE: import os from os.path import join lookfor = "iexplore.exe" for root, dirs, files in os.walk('C:\\Program Files\\Internet Explorer'): print "searching", root if lookfor in files: print "found: %s" % join(root, lookfor) import sys def create(): print("creating new file") name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat' try: file=open(name,'w') file.close() except: print("error occured") sys.exit(0) create() From thisisink01 at gmail.com Sat Apr 2 17:59:10 2016 From: thisisink01 at gmail.com (Loop.IO) Date: Sat, 2 Apr 2016 14:59:10 -0700 (PDT) Subject: [Beginner] - Hanging in the code, can't figure out what's wrong Message-ID: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> Hey So I built a keylogger using python as a test, got the code from the tutorial online, I want to improve on it to make it more automated, but the issue I'm having is it won't create the file until I press return, any clues where I'm going wrong? If I press return it makes the batch file, otherwise it just hangs. CODE: import os from os.path import join lookfor = "iexplore.exe" for root, dirs, files in os.walk('C:\\Program Files\\Internet Explorer'): print "searching", root if lookfor in files: print "found: %s" % join(root, lookfor) import sys def create(): print("creating new file") name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat' try: file=open(name,'w') file.close() except: print("error occured") sys.exit(0) create() From rosuav at gmail.com Sat Apr 2 18:04:53 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Apr 2016 08:04:53 +1000 Subject: [Beginner] Hanging in the code until I press return, can't figure it out In-Reply-To: References: Message-ID: On Sun, Apr 3, 2016 at 7:55 AM, Loop.IO wrote: > So I built a keylogger using python as a test, got the code from the tutorial online, I want to improve on it to make it more automated, but the issue I'm having is it won't create the file until I press return, any clues where I'm going wrong? > > If I press return it makes the batch file, otherwise it just hangs. > > CODE: > > name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat' > What's this line supposed to be doing? ChrisA From bc at freeuk.com Sat Apr 2 18:08:56 2016 From: bc at freeuk.com (BartC) Date: Sat, 2 Apr 2016 23:08:56 +0100 Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> Message-ID: On 02/04/2016 22:59, Loop.IO wrote: > Hey > > So I built a keylogger using python as a test, got the code from the tutorial online, I want to improve on it to make it more automated, but the issue I'm having is it won't create the file until I press return, any clues where I'm going wrong? > > If I press return it makes the batch file, otherwise it just hangs. > name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat' You're asking for a file name to be entered. So that if ABC is pressed, followed by Enter, it will use: C:\Documents\PythonCoding\ABClaunch2.bat Assuming that's the intention, then Enter is needed so that it knows when the user has completed typing the name. If not, then just use: name='C:\\Documents\\PythonCoding\\launch2.bat' (If you want a single character name, without pressing Enter, that's harder to do. Someone else will have to help.) -- Bartc From ned at nedbatchelder.com Sat Apr 2 18:16:42 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 2 Apr 2016 15:16:42 -0700 (PDT) Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> Message-ID: On Saturday, April 2, 2016 at 6:09:13 PM UTC-4, BartC wrote: > On 02/04/2016 22:59, Loop.IO wrote: > > Hey > > > > So I built a keylogger using python as a test, got the code from the tutorial online, I want to improve on it to make it more automated, but the issue I'm having is it won't create the file until I press return, any clues where I'm going wrong? > > > > If I press return it makes the batch file, otherwise it just hangs. > > > name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat' > > You're asking for a file name to be entered. So that if ABC is pressed, > followed by Enter, it will use: > > C:\Documents\PythonCoding\ABClaunch2.bat That line of code will prompt the user: C:\Documents\PythonCoding\ then the user enters ABC: C:\Documents\PythonCoding\ABC and raw_input returns "ABC", so name becomes "ABClaunch2.bat". Presumably the intention here was to use the prompt as a suggestion for a value to enter, but I can't be sure. --Ned. From thisisink01 at gmail.com Sat Apr 2 18:23:03 2016 From: thisisink01 at gmail.com (Loop.IO) Date: Sat, 2 Apr 2016 15:23:03 -0700 (PDT) Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> Message-ID: <18604420-d8ee-485a-96ef-bbda9a590201@googlegroups.com> On Saturday, April 2, 2016 at 11:09:13 PM UTC+1, BartC wrote: > On 02/04/2016 22:59, Loop.IO wrote: > > Hey > > > > So I built a keylogger using python as a test, got the code from the tutorial online, I want to improve on it to make it more automated, but the issue I'm having is it won't create the file until I press return, any clues where I'm going wrong? > > > > If I press return it makes the batch file, otherwise it just hangs. > > > name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat' > > You're asking for a file name to be entered. So that if ABC is pressed, > followed by Enter, it will use: > > C:\Documents\PythonCoding\ABClaunch2.bat > > Assuming that's the intention, then Enter is needed so that it knows > when the user has completed typing the name. If not, then just use: > > name='C:\\Documents\\PythonCoding\\launch2.bat' > > (If you want a single character name, without pressing Enter, that's > harder to do. Someone else will have to help.) > > -- > Bartc Hey Bartc I don't quite understand what you mean? The file is just supposed to be created, I don't want to have to press "Enter" or "Return" for it to complete the file creation the info i followed to create the file advised I had to add the file name and extension on after like in the code From bc at freeuk.com Sat Apr 2 18:27:33 2016 From: bc at freeuk.com (BartC) Date: Sat, 2 Apr 2016 23:27:33 +0100 Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> Message-ID: On 02/04/2016 23:16, Ned Batchelder wrote: > On Saturday, April 2, 2016 at 6:09:13 PM UTC-4, BartC wrote: >> On 02/04/2016 22:59, Loop.IO wrote: >>> Hey >>> >>> So I built a keylogger using python as a test, got the code from the tutorial online, I want to improve on it to make it more automated, but the issue I'm having is it won't create the file until I press return, any clues where I'm going wrong? >>> >>> If I press return it makes the batch file, otherwise it just hangs. >> >>> name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat' >> >> You're asking for a file name to be entered. So that if ABC is pressed, >> followed by Enter, it will use: >> >> C:\Documents\PythonCoding\ABClaunch2.bat > > That line of code will prompt the user: > > C:\Documents\PythonCoding\ > > then the user enters ABC: > > C:\Documents\PythonCoding\ABC > > and raw_input returns "ABC", so name becomes "ABClaunch2.bat". Yes, of course. I ran the code and picked up the wrong line even though I printed out 'name'! But, it does look as though that path is supposed to form part of the resulting filename. -- Bartc From thisisink01 at gmail.com Sat Apr 2 18:31:01 2016 From: thisisink01 at gmail.com (Loop.IO) Date: Sat, 2 Apr 2016 15:31:01 -0700 (PDT) Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> Message-ID: <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> On Saturday, April 2, 2016 at 11:27:49 PM UTC+1, BartC wrote: > On 02/04/2016 23:16, Ned Batchelder wrote: > > On Saturday, April 2, 2016 at 6:09:13 PM UTC-4, BartC wrote: > >> On 02/04/2016 22:59, Loop.IO wrote: > >>> Hey > >>> > >>> So I built a keylogger using python as a test, got the code from the tutorial online, I want to improve on it to make it more automated, but the issue I'm having is it won't create the file until I press return, any clues where I'm going wrong? > >>> > >>> If I press return it makes the batch file, otherwise it just hangs. > >> > >>> name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat' > >> > >> You're asking for a file name to be entered. So that if ABC is pressed, > >> followed by Enter, it will use: > >> > >> C:\Documents\PythonCoding\ABClaunch2.bat > > > > That line of code will prompt the user: > > > > C:\Documents\PythonCoding\ > > > > then the user enters ABC: > > > > C:\Documents\PythonCoding\ABC > > > > and raw_input returns "ABC", so name becomes "ABClaunch2.bat". > > Yes, of course. I ran the code and picked up the wrong line even though > I printed out 'name'! > > But, it does look as though that path is supposed to form part of the > resulting filename. > > -- > Bartc Oh i see, so the code prompts for a name.. so i'm more lost than i thought, what do I need to change to make it just create the file with the chosen name Launch2.bat without the prompt? From michael.selik at gmail.com Sat Apr 2 18:37:32 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sat, 02 Apr 2016 22:37:32 +0000 Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> Message-ID: I might be overlooking something, but raw_input (Python 2) and input (Python 3) won't return the input from sys.stdin until you type ENTER. Or did I misunderstand the question? On Sat, Apr 2, 2016 at 6:30 PM BartC wrote: > On 02/04/2016 23:16, Ned Batchelder wrote: > > On Saturday, April 2, 2016 at 6:09:13 PM UTC-4, BartC wrote: > >> On 02/04/2016 22:59, Loop.IO wrote: > >>> Hey > >>> > >>> So I built a keylogger using python as a test, got the code from the > tutorial online, I want to improve on it to make it more automated, but the > issue I'm having is it won't create the file until I press return, any > clues where I'm going wrong? > >>> > >>> If I press return it makes the batch file, otherwise it just hangs. > >> > >>> name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat' > >> > >> You're asking for a file name to be entered. So that if ABC is pressed, > >> followed by Enter, it will use: > >> > >> C:\Documents\PythonCoding\ABClaunch2.bat > > > > That line of code will prompt the user: > > > > C:\Documents\PythonCoding\ > > > > then the user enters ABC: > > > > C:\Documents\PythonCoding\ABC > > > > and raw_input returns "ABC", so name becomes "ABClaunch2.bat". > > Yes, of course. I ran the code and picked up the wrong line even though > I printed out 'name'! > > But, it does look as though that path is supposed to form part of the > resulting filename. > > -- > Bartc > -- > https://mail.python.org/mailman/listinfo/python-list > From torriem at gmail.com Sat Apr 2 18:49:06 2016 From: torriem at gmail.com (Michael Torrie) Date: Sat, 2 Apr 2016 16:49:06 -0600 Subject: [beginner] What's wrong? In-Reply-To: References: Message-ID: <57004C62.8060304@gmail.com> Mark, your messages are showing up to the list as being from "python," at least on my email. Any reason for this? From ethan at stoneleaf.us Sat Apr 2 19:15:53 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 02 Apr 2016 16:15:53 -0700 Subject: Drowning in a teacup? In-Reply-To: <1459626868.1382635.566734322.250BAE2A@webmail.messagingengine.com> References: <1459626868.1382635.566734322.250BAE2A@webmail.messagingengine.com> Message-ID: <570052A9.8040608@stoneleaf.us> On 04/02/2016 12:54 PM, Random832 wrote: > On Sat, Apr 2, 2016, at 15:28, Ned Batchelder wrote: >> On Friday, April 1, 2016 at 4:27:30 PM UTC-4, Fillmore wrote: >>> notorious pass by reference vs pass by value biting me in the backside >>> here. Proceeding in order. >> >> As others have pointed out, this is false dichotomy. There are other >> possibilities than pass by reference and pass by value. Python (and >> many other languages) use something called pass by object or pass by >> sharing. > > I think that this arises from a confusion as to what a "value" is in > "pass by value". > > The point of it being pass by value is that there is no statement you > can execute in the function that has the effect of an assignment of the > expression that was passed in from the caller. This holds no matter what > kind of object is passed in or what mutable properties it has or does > not have. Also, if "pass-by-value" is being used, even mutation of the passed object will not show up in the caller. -- ~Ethan~ From random832 at fastmail.com Sat Apr 2 19:19:22 2016 From: random832 at fastmail.com (Random832) Date: Sat, 02 Apr 2016 19:19:22 -0400 Subject: Drowning in a teacup? In-Reply-To: <570052A9.8040608@stoneleaf.us> References: <1459626868.1382635.566734322.250BAE2A@webmail.messagingengine.com> <570052A9.8040608@stoneleaf.us> Message-ID: <1459639162.1426200.566951194.6898462A@webmail.messagingengine.com> On Sat, Apr 2, 2016, at 19:15, Ethan Furman wrote: > Also, if "pass-by-value" is being used, even mutation of the passed > object will not show up in the caller. I disagree. I don't think the definition of pass-by-value implies this. From steve at pearwood.info Sat Apr 2 19:49:16 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 03 Apr 2016 09:49:16 +1000 Subject: [beginner] What's wrong? References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> Message-ID: <57005a7e$0$1589$c3e8da3$5496439d@news.astraweb.com> On Sun, 3 Apr 2016 03:12 am, Thomas 'PointedEars' Lahn wrote: > Marko Rauhamaa wrote: > >> Steven D'Aprano : >>> So you're saying that learning to be a fluent speaker of English is a >>> pre-requisite of being a programmer? >> >> No more than learning Latin is a prerequisite of being a doctor. > > Full ACK. Probably starting with the Industrial Revolution enabled by the > improvements of the steam machine in England, English has become the > /lingua franca/ of technology (even though the French often still > disagree, preferring words like ? ordinateur ? and ? octet ? over > ?computer? and ?byte?, respectively?). (With the Internet at the latest, > then, it has also become the /lingua franca/ of science, although Latin > terms are common in medicine.) And this is a BAD THING. Monoculture is harmful, and science and technology is becoming a monoculture: Anglo-American language expressing Anglo-American ideas, regardless of the nationality of the scientist or engineer. During the heyday of the scientific revolution, the sciences and mathematics were much diverse. Depending on your field, the professional scientist needed at least a working knowledge of German, French, English and Latin, possibly some Greek and Russian. Likewise for engineering. I don't think that it is a coincidence that the great scientific theories like relativity (both of them), quantum mechanics, evolution by natural selection and continental drift had time to mature in smaller, national communities before diffusing out to broader international communities. Fortunately at least some people are aware of the problem and doing something about it: https://blog.stackoverflow.com/2014/02/cant-we-all-be-reasonable-and-speak-english/ Unlike the rest of us, Stackoverflow have actually run the numbers: 10% of the world's programmers are in China 1.4% of their visits come from China so either Chinese developers are so brilliant and knowledgeable that they have no need of Stackoverflow, or they're unable to make use of it because they cannot participate in English-only forums. >> Nowadays software companies and communities are international. You never >> know who needs to maintain your code. At work, I need to maintain code >> that was created in Japan, with coworkers from all over the world. The >> Japanese author had had a hard time with English, and made some >> awkward naming choices, but had the common sense to use English-only >> names in his code. > > One will have a hard time finding a company or community, international or > not, that does not have at least a basic knowledge of English included in > what they require of a software developer. Particularly if one keeps a Euro-centric perspective and doesn't look to Asia or Brazil. -- Steven From breamoreboy at yahoo.co.uk Sat Apr 2 19:58:58 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 3 Apr 2016 00:58:58 +0100 Subject: [beginner] What's wrong? In-Reply-To: References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> Message-ID: On 02/04/2016 17:31, Dennis Lee Bieber wrote: > On Sat, 2 Apr 2016 19:15:36 +1100, Chris Angelico > declaimed the following: > >> On Sat, Apr 2, 2016 at 3:27 PM, Random832 wrote: >>> On Fri, Apr 1, 2016, at 19:29, Michael Selik wrote: >>>> Humans have always had trouble with this, in many contexts. I remember >>>> being annoyed at folks saying the year 2000 was the first year of the new >>>> millennium, rather than 2001. They'd forgotten the Gregorian calendar >>>> starts from AD 1. >>> >>> Naturally, this means the first millennium was only 999 years long, and >>> all subsequent millennia were 1000 years long. (Whereas "millennium" is >>> defined as the set of all years of a given era for a given integer k >>> where y // 1000 == k. How else would you define it?) >>> >>> And if you want to get technical, the gregorian calendar starts from >>> some year no earlier than 1582, depending on the country. The year >>> numbering system has little to do with the calendar type - your >>> assertion in fact regards the BC/AD year numbering system, which was >>> invented by Bede. >>> >>> The astronomical year-numbering system, which does contain a year zero >>> (and uses negative numbers rather than a reverse-numbered "BC" era), and >>> is incidentally used by ISO 8601, was invented by Jacques Cassini in the >>> 17th century. >>> >> >> Are you sure? Because I'm pretty sure these folks were already talking about BC. > > Bede's BC/AD goes back to circa 700AD. It is the use of negative years > for astronomical counting that is circa 1650AD >> >> http://xenohistorian.faithweb.com/holybook/quotes/YK.html > > And that I'll take as something suited for the first of April... It's > almost on par with an old story (in Asimov's I think) on why the pyramids > were behind schedule -- among other things, the pile of government mandated > documentation, on clay tablets of course, was becoming larger than the > pyramid being built; the older records (on the bottom of the stack) were > decomposing from the pressure, etc. If I recall, they discover cuneiform as > more condense than hieroglyphics, and then learn of papyrus/ink (but then > have to support an entire industry of workers to transcribe the old clay > tablets...) > > Here we go again, yet another completely useless thread that is irrelevant to the Python programming language. Hardly surprising that the bots don't bother any more. Are any of the bots still alive? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From dmw at yubasolutions.com Sat Apr 2 20:05:26 2016 From: dmw at yubasolutions.com (Daniel Wilcox) Date: Sat, 2 Apr 2016 17:05:26 -0700 Subject: crash while using PyCharm / Python3 In-Reply-To: References: Message-ID: Hi Adam, from my mail client sent to python-list directly -- actually attempting to reply to the OP in the past has generated some weirdness and bounced messages (probably Gmail attempting to stop me from replying-all with the OP in the TO line rather than the list. But the behavior you mentioned is quite odd. Here are some message headers I was just looking at, and pasting here to debug. 1 - Adam (OP) Message-ID: no references list vars included 2 - from me Message-ID: no references no list vars included 3 - OP Message-ID: References: list vars included 4 - Dirk Message-ID: <56f03080$0$5924$e4fe514c at news.xs4all.nl> no references list vars included 5 - OP Message-ID: References: list vars included 6 - OP Message-ID: References: <56f03080$0$5924$e4fe514c at news.xs4all.nl> 7 - OP Message-ID: References: <56f03080$0$5924$e4fe514c at news.xs4all.nl> 8 - Jonathan Message-ID: References: <56f03080$0$5924$e4fe514c at news.xs4all.nl> 9 - OP Message-ID: References: <56f03080$0$5924$e4fe514c at news.xs4all.nl> 10 - OP Message-ID: References: <56f03080$0$5924$e4fe514c at news.xs4all.nl> ... my next reply In-Reply-To: References: <56f03080$0$5924$e4fe514c at news.xs4all.nl> and Big Bad Bob by far had the funniest headers (right after my last msg) References: <56f03080$0$5924$e4fe514c at news.xs4all.nl> In-Reply-To: X-Why-Are-You-Looking-Here: Jedi Business, move along X-Testing: of course! Message-ID: and the message I'm currently replying to ... Message-ID: References: So I see a few patterns here -- mostly my Message-IDs never appear in any References so I'd imagine something building a thread of the messages wouldn't include mine. But that makes me worry about delivery or at least properly threading in other clients as well. I'm not sure why that is it could be using Gmail for my domain or the Gmail client itself leaving off the List headers that all the other messages appear to have. I might need to try my Mutt config on this account to see if I get different behavior. Of course it could be that I'm not seeing all the headers I should on my own messages, or referring to my messages, because in that case perhaps Gmail is joining messages in my Sent folder with the thread in another manner. I should really get this fixed, it's probably not a good thing to have the messages vanishing from archives and the like. If you have a few minutes and can check Message-IDs and references and other headers from my emails that'd be awesome and might help me track down what is going on. Thanks for mentioning this! Cheers, =D On Wed, Mar 23, 2016 at 9:18 PM, Adam wrote: > > "Adam" wrote in message > news:ncikss$tks$1 at news.albasani.net... > > > > Host OS: Ubuntu Desktop 14.04 LTS / Unity > > > > System crashed while using PyCharm / Python3. > > Booting takes forever and stuck at the purple screen with > > the Ubuntu logo and the five dots cycling. > > How to fix? > > > > Searching for this thread in a browser lead to > the code.activestate.com website where > I see posts from Daniel Wilcox. > But, in my newsreader, I do not see his posts, > which is why his posts are not getting any response. > Daniel, how/where are you responding to this thread? > > > -- > https://mail.python.org/mailman/listinfo/python-list > From breamoreboy at yahoo.co.uk Sat Apr 2 20:08:32 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 3 Apr 2016 01:08:32 +0100 Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: <18604420-d8ee-485a-96ef-bbda9a590201@googlegroups.com> References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <18604420-d8ee-485a-96ef-bbda9a590201@googlegroups.com> Message-ID: On 02/04/2016 23:23, Loop.IO wrote: > On Saturday, April 2, 2016 at 11:09:13 PM UTC+1, BartC wrote: >> On 02/04/2016 22:59, Loop.IO wrote: >>> Hey >>> >>> So I built a keylogger using python as a test, got the code from the tutorial online, I want to improve on it to make it more automated, but the issue I'm having is it won't create the file until I press return, any clues where I'm going wrong? >>> >>> If I press return it makes the batch file, otherwise it just hangs. >> >>> name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat' >> >> You're asking for a file name to be entered. So that if ABC is pressed, >> followed by Enter, it will use: >> >> C:\Documents\PythonCoding\ABClaunch2.bat >> >> Assuming that's the intention, then Enter is needed so that it knows >> when the user has completed typing the name. If not, then just use: >> >> name='C:\\Documents\\PythonCoding\\launch2.bat' >> >> (If you want a single character name, without pressing Enter, that's >> harder to do. Someone else will have to help.) >> >> -- >> Bartc > > Hey Bartc > > I don't quite understand what you mean? > > The file is just supposed to be created, I don't want to have to press "Enter" or "Return" for it to complete the file creation > > the info i followed to create the file advised I had to add the file name and extension on after like in the code > There is no point asking BartC about Python as he has repeatedly stated that he knows nothing about Python. OTOH there are loads of people here who do know Python, backwards, sideways and inside out. If you state precisely what you are trying to achieve then you will get the correct answer. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Sat Apr 2 20:11:55 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 3 Apr 2016 01:11:55 +0100 Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> Message-ID: On 02/04/2016 23:37, Michael Selik wrote: > I might be overlooking something, but raw_input (Python 2) and input > (Python 3) won't return the input from sys.stdin until you type ENTER. Or > did I misunderstand the question? > > On Sat, Apr 2, 2016 at 6:30 PM BartC wrote: > >> On 02/04/2016 23:16, Ned Batchelder wrote: >>> On Saturday, April 2, 2016 at 6:09:13 PM UTC-4, BartC wrote: >>>> On 02/04/2016 22:59, Loop.IO wrote: >>>>> Hey >>>>> >>>>> So I built a keylogger using python as a test, got the code from the >> tutorial online, I want to improve on it to make it more automated, but the >> issue I'm having is it won't create the file until I press return, any >> clues where I'm going wrong? >>>>> >>>>> If I press return it makes the batch file, otherwise it just hangs. >>>> >>>>> name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat' >>>> >>>> You're asking for a file name to be entered. So that if ABC is pressed, >>>> followed by Enter, it will use: >>>> >>>> C:\Documents\PythonCoding\ABClaunch2.bat >>> >>> That line of code will prompt the user: >>> >>> C:\Documents\PythonCoding\ >>> >>> then the user enters ABC: >>> >>> C:\Documents\PythonCoding\ABC >>> >>> and raw_input returns "ABC", so name becomes "ABClaunch2.bat". >> >> Yes, of course. I ran the code and picked up the wrong line even though >> I printed out 'name'! >> >> But, it does look as though that path is supposed to form part of the >> resulting filename. >> >> -- >> Bartc >> -- >> https://mail.python.org/mailman/listinfo/python-list >> BartC is renowned for knowing nothing about Python by his own admittance, and would you please not top post on the list. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From bc at freeuk.com Sat Apr 2 20:12:09 2016 From: bc at freeuk.com (BartC) Date: Sun, 3 Apr 2016 01:12:09 +0100 Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> Message-ID: On 02/04/2016 23:31, Loop.IO wrote: > Oh i see, so the code prompts for a name.. so i'm more lost than i thought, what do I need to change to make it just create the file with the chosen name Launch2.bat without the prompt? If you don't want the user to enter anything, then I explained how before, just use: name='C:\\Documents\\PythonCoding\\launch2.bat' if that's the file name you need. -- Bartc From breamoreboy at yahoo.co.uk Sat Apr 2 20:26:21 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 3 Apr 2016 01:26:21 +0100 Subject: [beginner] What's wrong? In-Reply-To: <57005a7e$0$1589$c3e8da3$5496439d@news.astraweb.com> References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <57005a7e$0$1589$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/04/2016 00:49, Steven D'Aprano wrote: > On Sun, 3 Apr 2016 03:12 am, Thomas 'PointedEars' Lahn wrote: > >> Marko Rauhamaa wrote: >> >>> Steven D'Aprano : >>>> So you're saying that learning to be a fluent speaker of English is a >>>> pre-requisite of being a programmer? >>> >>> No more than learning Latin is a prerequisite of being a doctor. >> >> Full ACK. Probably starting with the Industrial Revolution enabled by the >> improvements of the steam machine in England, English has become the >> /lingua franca/ of technology (even though the French often still >> disagree, preferring words like ? ordinateur ? and ? octet ? over >> ?computer? and ?byte?, respectively?). (With the Internet at the latest, >> then, it has also become the /lingua franca/ of science, although Latin >> terms are common in medicine.) > > And this is a BAD THING. Monoculture is harmful, and science and technology > is becoming a monoculture: Anglo-American language expressing > Anglo-American ideas, regardless of the nationality of the scientist or > engineer. > > During the heyday of the scientific revolution, the sciences and mathematics > were much diverse. Depending on your field, the professional scientist > needed at least a working knowledge of German, French, English and Latin, > possibly some Greek and Russian. Likewise for engineering. > > I don't think that it is a coincidence that the great scientific theories > like relativity (both of them), quantum mechanics, evolution by natural > selection and continental drift had time to mature in smaller, national > communities before diffusing out to broader international communities. > > Fortunately at least some people are aware of the problem and doing > something about it: > > https://blog.stackoverflow.com/2014/02/cant-we-all-be-reasonable-and-speak-english/ > > Unlike the rest of us, Stackoverflow have actually run the numbers: > > 10% of the world's programmers are in China > 1.4% of their visits come from China > > so either Chinese developers are so brilliant and knowledgeable that they > have no need of Stackoverflow, or they're unable to make use of it because > they cannot participate in English-only forums. > > >>> Nowadays software companies and communities are international. You never >>> know who needs to maintain your code. At work, I need to maintain code >>> that was created in Japan, with coworkers from all over the world. The >>> Japanese author had had a hard time with English, and made some >>> awkward naming choices, but had the common sense to use English-only >>> names in his code. >> >> One will have a hard time finding a company or community, international or >> not, that does not have at least a basic knowledge of English included in >> what they require of a software developer. > > Particularly if one keeps a Euro-centric perspective and doesn't look to > Asia or Brazil. > My mum was from Tredegar. She was very upset because English newspaper correspondents were biased against her "boys", and because the selectors never even put her into the squad, let alone the starting lineup. Of course this is completely irrelevant on the Python programming main mailing list, but it appears that any old crap is acceptable in the year 2016. A Bot, a Bot, any kingdom for a Bot. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Sat Apr 2 20:38:21 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 3 Apr 2016 01:38:21 +0100 Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> Message-ID: On 03/04/2016 01:12, BartC wrote: > On 02/04/2016 23:31, Loop.IO wrote: > >> Oh i see, so the code prompts for a name.. so i'm more lost than i >> thought, what do I need to change to make it just create the file with >> the chosen name Launch2.bat without the prompt? > > If you don't want the user to enter anything, then I explained how > before, just use: > > name='C:\\Documents\\PythonCoding\\launch2.bat' > > if that's the file name you need. > name = r'C:\Documents\PythonCoding\launch2.bat' Alternatively you could just use a forward slash. I'm not sure which is the most efficient, I'll leave that to others to test. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve at pearwood.info Sat Apr 2 20:48:19 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 03 Apr 2016 10:48:19 +1000 Subject: [beginner] What's wrong? References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <877fgfrefw.fsf@elektro.pacujo.net> Message-ID: <57006856$0$1614$c3e8da3$5496439d@news.astraweb.com> On Sun, 3 Apr 2016 07:42 am, Michael Selik wrote: > Gaming also helps your reaction time. Normally 0.3 ms, but 0.1 ms for top > gamers. And fighter pilots. Does gaming help reaction time, or do only people with fast reaction times become top gamers? Personally, in my experience gaming hurts reaction time. I ask people a question, and they don't reply for a week or at all, because they're too busy playing games all day. -- Steven From breamoreboy at yahoo.co.uk Sat Apr 2 21:04:05 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 3 Apr 2016 02:04:05 +0100 Subject: [beginner] What's wrong? In-Reply-To: <57006856$0$1614$c3e8da3$5496439d@news.astraweb.com> References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <877fgfrefw.fsf@elektro.pacujo.net> <57006856$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/04/2016 01:48, Steven D'Aprano wrote: > On Sun, 3 Apr 2016 07:42 am, Michael Selik wrote: > >> Gaming also helps your reaction time. Normally 0.3 ms, but 0.1 ms for top >> gamers. And fighter pilots. > > Does gaming help reaction time, or do only people with fast reaction times > become top gamers? > > Personally, in my experience gaming hurts reaction time. I ask people a > question, and they don't reply for a week or at all, because they're too > busy playing games all day. > I must agree. When you're trying to get the ball away, and 23 stone of bone and muscle smashes into you, that slows your reaction time. I am of course referring to the sport of rugby, not that silly "World Series", which takes part in only one country, where for some reason unknown to me they wear huge quantities of armour and need oxygen masks after they've run a few yards. What would happen to the poor little darlings if they had to spend the entire match on the pitch? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve at pearwood.info Sat Apr 2 22:33:50 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 03 Apr 2016 12:33:50 +1000 Subject: Drowning in a teacup? References: Message-ID: <5700810f$0$1612$c3e8da3$5496439d@news.astraweb.com> On Sun, 3 Apr 2016 05:54 am, Random832 wrote: > On Sat, Apr 2, 2016, at 15:28, Ned Batchelder wrote: >> On Friday, April 1, 2016 at 4:27:30 PM UTC-4, Fillmore wrote: >> > notorious pass by reference vs pass by value biting me in the backside >> > here. Proceeding in order. >> >> As others have pointed out, this is false dichotomy. There are other >> possibilities than pass by reference and pass by value. Python (and >> many other languages) use something called pass by object or pass by >> sharing. > > I think that this arises from a confusion as to what a "value" is in > "pass by value". I don't understand what you mean by this. Are you defending the idea that Python is pass-by-value, or saying that Fillmore is confused by what pass-by-value means, or something else? What precisely are you trying to say here? > The point of it being pass by value is that there is no statement you > can execute in the function that has the effect of an assignment of the > expression that was passed in from the caller. No, that alone is insufficient. There are other calling conventions that have the same effect. Pass-by-value also requires that the value being passed is copied. Unfortunately we've been plagued by a bunch of comp sci graduates who suffer from the "little bit of learning" problem. Having learned that there are only two calling conventions, pass by value and pass by reference, and correctly recognising that their language of choice is not pass by reference, they then jump through some remarkable intellectual contortions to prove that it is therefore pass by value. To do this, they normally redefine "value" to mean something other than what everyone else thinks of as the value being passed to a function. The Java community is especially prone to this: http://javadude.com/articles/passbyvalue.htm Note the author's definition of pass-by-value: [quote] Pass-by-value The actual parameter (or argument expression) is fully evaluated and the resulting value is copied into a location being used to hold the formal parameter's value during method/function execution. [end quote] That the value is *copied* is fundamental to pass by value semantics. The author, Scott Stanchfield, then claims that Java is pass by value. (Note: for this entire discussion, I'm referring to boxed values, or objects, not primitives. There's no dispute that Java is pass by value for primitives.) But to make this work, he has to use a bit of slight of hand: what gets copied in Java function calls is not the value of the argument, but some abstract reference to that value. There's this invisible abstract reference is the value of the variable. He doesn't come right out and say this, but if you read his description of what Java does, it should be obvious that he thinks of Java variables as being bound to abstract pointers or references rather than being bound to objects themselves. Consequently, if you bind a value to a variable name: String str = "Hello"; then to Stanchfield, the value of the string variable str is presumably not "Hello", but some unknown and unknowable abstract reference like 0x832fe50. This is the only way to make sense of his argument. Objects are not copied when you pass them to a function in Java, but the invisible reference to the object may be. Fredrik Lundh (the Effbot) quite rightly holds this view in scorn: [quote] I guess you can, in theory, value an artificial number assigned to an object as much as the object itself. "Joe, I think our son might be lost in the woods" "Don't worry, I have his social security number" [end quote] http://effbot.org/zone/call-by-object.htm Stanchfield's view of invisible references to objects being passed by value is, I have no doubt, right from the perspective of the Java implementation. Some would argue that he is "technically correct". But he is answering the wrong question. Calling Java (or Python) "pass by value" gives us no insight into how the language works. It is reductionism gone mad. Nobody, except maybe compiler designers, cares how the Java virtual machine implements argument passing. What Java developers care about is the behaviour of the Java language. Java's so-called "pass by value (where the value is some invisible reference to the value you actually care about)" behaves quite differently from pass by value in C, Pascal and others. Java doesn't copy objects when you pass them to functions. Nor does it pass references in pass by reference sense. Java objects are passed using the exact same semantics as Python objects, and neither pass by reference nor pass by value match that actual behaviour. Both languages provide an abstraction layer between the internal implementation details of the interpreter or virtual machine, and the high-level behaviour of the language. Stanchfield makes the same mistake with his claim that "Java has pointers", since of course it does not. The Java language gives you no way of creating such pointers to arbitrary chunks of memory (or to primitives), no way to dereference such a pointer if you had one (which you don't), and especially no way of advancing such (non-existent) pointers to the next record in memory. To put it another way, not only are pointers not first-class values in Java, they aren't values at all. There's no way to declare a variable of type "Pointer to Foo", or equivalent. So Stanchfield's claim that "Java has pointers" is, again, based on his conflating of values in the Java language compared to implementation details of the Java virtual machine. The JVM manages objects via indirect references to the object, and for that indirection, it may use some form of "thing which points to another thing": - C pointers (memory addresses); - some form of managed reference to a memory location; - classic Mac OS "handles" (managed pointers-to-pointers); - or even integer indexes into a giant array, like early versions of Fortran. But that hardly means that pointers are a feature of the Java language. > This holds no matter what > kind of object is passed in or what mutable properties it has or does > not have. I'm still not getting your point. -- Steven From hongyi.zhao at gmail.com Sat Apr 2 23:28:23 2016 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Sun, 3 Apr 2016 03:28:23 +0000 (UTC) Subject: Failed to update the os.environ with subprocess.Popen. Message-ID: Hi all, I use the following code to update the os.environ with subprocess.Popen: ------------- from subprocess import Popen output = Popen(""" /bin/bash < os.environ.update(line.partition('=')[::2] for line in output.split ('\0')) AttributeError: 'Popen' object has no attribute 'split' ------------------- How to solve this issue? -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From hongyi.zhao at gmail.com Sat Apr 2 23:28:54 2016 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Sun, 3 Apr 2016 03:28:54 +0000 (UTC) Subject: Failed to update the os.environ with subprocess.Popen. Message-ID: Hi all, I use the following code to update the os.environ with subprocess.Popen: ------------- from subprocess import Popen output = Popen(""" /bin/bash < os.environ.update(line.partition('=')[::2] for line in output.split ('\0')) AttributeError: 'Popen' object has no attribute 'split' ------------------- How to solve this issue? -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From hongyi.zhao at gmail.com Sat Apr 2 23:29:24 2016 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Sun, 3 Apr 2016 03:29:24 +0000 (UTC) Subject: Failed to update the os.environ with subprocess.Popen. Message-ID: Hi all, I use the following code to update the os.environ with subprocess.Popen: ------------- from subprocess import Popen output = Popen(""" /bin/bash < os.environ.update(line.partition('=')[::2] for line in output.split ('\0')) AttributeError: 'Popen' object has no attribute 'split' ------------------- How to solve this issue? -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From ben+python at benfinney.id.au Sat Apr 2 23:37:24 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 03 Apr 2016 13:37:24 +1000 Subject: Get the output from a Popen instance (was: Failed to update the os.environ with subprocess.Popen.) References: Message-ID: <85bn5r8irv.fsf@benfinney.id.au> Hongyi Zhao writes: > I use the following code to update the os.environ with > subprocess.Popen Again, it is quite misleading to describe what you are doing as ?update the os.environ with subprocess.Popen?. The ?subprocess.Popen? call *cannot* upsdate the Python process's ?os.environ?. What you're doing is two quite separate steps: * Obtain a collection of items (key ? value pairs). * Update a dictionary. Please be clear that's what you're doing because ?update ?os.environ? with ?subprocess.Popen? is *not* that. > But, I meet the following errors: > > ------------ > Traceback (most recent call last): > File "/home/werner/software/hpc/dft-to-study/jasp/jasp.git/jasp/bin/ > runjasp.py", line 125, in > os.environ.update(line.partition('=')[::2] for line in output.split > ('\0')) > AttributeError: 'Popen' object has no attribute 'split' > ------------------- So your problem is nothing to do with ?update ?os.environ??. I have updated the Subject field accordingly. The problem you're encountering is only to do with ?subprocess.Popen?. That should make it much easier to search for the documentation to understand the problem. -- \ ?When people believe that they have absolute knowledge, with no | `\ test in reality, this [the Auschwitz crematorium] is how they | _o__) behave.? ?Jacob Bronowski, _The Ascent of Man_, 1973 | Ben Finney From hongyi.zhao at gmail.com Sun Apr 3 00:00:54 2016 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Sun, 3 Apr 2016 04:00:54 +0000 (UTC) Subject: Get the output from a Popen instance (was: Failed to update the os.environ with subprocess.Popen.) References: Message-ID: On Sun, 03 Apr 2016 13:37:24 +1000, Ben Finney wrote: >> But, I meet the following errors: >> >> ------------ >> Traceback (most recent call last): >> File "/home/werner/software/hpc/dft-to-study/jasp/jasp.git/jasp/bin/ >> runjasp.py", line 125, in >> os.environ.update(line.partition('=')[::2] for line in output.split >> ('\0')) >> AttributeError: 'Popen' object has no attribute 'split' >> ------------------- > > So your problem is nothing to do with ?update ?os.environ??. I have > updated the Subject field accordingly. > > The problem you're encountering is only to do with ?subprocess.Popen?. > That should make it much easier to search for the documentation to > understand the problem. > > Thanks a lot, got it. Should be used as follows: output = Popen(""" /bin/bash < Message-ID: <57009af2$0$1607$c3e8da3$5496439d@news.astraweb.com> On Sun, 3 Apr 2016 01:29 pm, Hongyi Zhao wrote: > Hi all, > > I use the following code to update the os.environ with subprocess.Popen: I don't understand what you are trying to do here. But regardless of your intention, the problem you have is nothing to do with updating os.environ. Proof: change the last line from this complicated expression: os.environ.update(line.partition('=')[::2] for line in output.split('\0')) to this simple expression: output.split('\0') and you will get the same error. os.environ is irrelevant. Your problem is only with Popen. What makes you think that Popen objects have a split() method? They are not documented as having this method: https://docs.python.org/2/library/subprocess.html https://docs.python.org/3/library/subprocess.html https://pymotw.com/2/subprocess/ -- Steven From greg.ewing at canterbury.ac.nz Sun Apr 3 00:43:47 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 03 Apr 2016 16:43:47 +1200 Subject: [beginner] What's wrong? In-Reply-To: References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> Message-ID: Chris Angelico wrote: > Yep! And the letters (thorn and eth) survive in a very few languages > (Icelandic, notably). Fortunately, Python 3 lets you use it in > identifiers. This suggests an elegant solution to the problem of whether "python" should refer to Python 2 or Python 3. The Python 3 link should be "py?on"! -- Greg From steve at pearwood.info Sun Apr 3 00:43:59 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 03 Apr 2016 14:43:59 +1000 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <1671ea2b-09ff-4745-a6e7-d2c57864cba3@googlegroups.com> <87zitbpwpr.fsf@elektro.pacujo.net> Message-ID: <57009f91$0$1612$c3e8da3$5496439d@news.astraweb.com> On Sun, 3 Apr 2016 06:44 am, Marko Rauhamaa wrote: > I don't have a problem with a list being a "reiterable." I only was > surprised about range(), which I had thought to be a plain, > down-to-earth iterator. There's barely any other practical use for a > range, I believe. I can understand that you were mistaken. It's an easy mistake to make. But I don't understand why you seem to be insisting that its somehow a flaw that (x)range is implemented as a "lazy list" instead of an iterator. If you want an iterator, it's only a single function call away: iter(r). In the meantime, range objects provide the full sequence API. They're not quite full lists, as they don't allow arbitrary orderings or arbitrary items, so any list method which implies that arbitrary items can be inserted or deleted are not included. It also acts as a proof of concept that Python supports intelligent, lazy objects that can produce values on demand. If you personally don't see any advantage in this, so be it, but you might not be aware of the history of (x)range: Guido in 2001: "Nobody uses this extra functionality, and its buggy, let's get rid of it." https://www.python.org/dev/peps/pep-0260/ Feature request in 2004: "Membership testing in xrange objects is horribly slow. Let's add a __contains__ method." http://bugs.python.org/issue1002085 (Request rejected, because the __contains__ method was removed in 2002.) Discussion and feature request in 2007: "We really ought to fix that slow performance of (x)range membership testing..." http://bugs.python.org/issue1766304 So it's one of those things on the border of useful or not. Those who use it, miss it when its gone. Those who don't, don't understand why anyone wants it. -- Steven From greg.ewing at canterbury.ac.nz Sun Apr 3 00:57:16 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 03 Apr 2016 16:57:16 +1200 Subject: [beginner] What's wrong? In-Reply-To: <3524319.g0I1c1cpMS@PointedEars.de> References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> Message-ID: Thomas 'PointedEars' Lahn wrote: > even though the French often still disagree, > preferring words like ? ordinateur ? and ? octet ? over ?computer? and > ?byte?, respectively To be fair, "octet" is a slightly more precise term than "byte", meaning exactly 8 bits (whereas "byte" could theoretically mean something else depending on the context). There's no excuse for "ordinateur", though. :-) -- Greg From random832 at fastmail.com Sun Apr 3 01:20:52 2016 From: random832 at fastmail.com (Random832) Date: Sun, 03 Apr 2016 01:20:52 -0400 Subject: Strange range In-Reply-To: <57009f91$0$1612$c3e8da3$5496439d@news.astraweb.com> References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <1671ea2b-09ff-4745-a6e7-d2c57864cba3@googlegroups.com> <87zitbpwpr.fsf@elektro.pacujo.net> <57009f91$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1459660852.1498819.567133042.73910FE5@webmail.messagingengine.com> On Sun, Apr 3, 2016, at 00:43, Steven D'Aprano wrote: > If you personally don't see any advantage in this, so be it, but you > might > not be aware of the history of (x)range: > > Guido in 2001: "Nobody uses this extra functionality, and its buggy, > let's > get rid of it." > > https://www.python.org/dev/peps/pep-0260/ Several of those features apparently never did come back. The repeat count never did (you can't multiply ranges now), and it occurs to me that slicing a range that has a repeat count is intractable: (range(3)*2)[1:5] should yield 1, 2, 0, 1, which can't be represented as a range object. It also doesn't support comparison operations. From steve at pearwood.info Sun Apr 3 01:28:49 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 03 Apr 2016 15:28:49 +1000 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <1671ea2b-09ff-4745-a6e7-d2c57864cba3@googlegroups.com> <87zitbpwpr.fsf@elektro.pacujo.net> <57009f91$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5700aa13$0$1606$c3e8da3$5496439d@news.astraweb.com> On Sun, 3 Apr 2016 02:43 pm, Steven D'Aprano wrote: > If you personally don't see any advantage in this, so be it, but you might > not be aware of the history of (x)range: > > Guido in 2001: "..." Correction: these are not direct quotes, but paraphrases. My apologies for any confusion. -- Steven From steve at pearwood.info Sun Apr 3 01:34:27 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 03 Apr 2016 15:34:27 +1000 Subject: [beginner] What's wrong? References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> Message-ID: <5700ab65$0$1584$c3e8da3$5496439d@news.astraweb.com> On Sun, 3 Apr 2016 02:57 pm, Gregory Ewing wrote: > Thomas 'PointedEars' Lahn wrote: >> even though the French often still disagree, >> preferring words like ? ordinateur ? and ? octet ? over ?computer? and >> ?byte?, respectively > > To be fair, "octet" is a slightly more precise term than > "byte", meaning exactly 8 bits (whereas "byte" could > theoretically mean something else depending on the > context). "Theoretically"? http://stackoverflow.com/questions/2098149/what-platforms-have-something-other-than-8-bit-char -- Steven From me+python at ixokai.io Sun Apr 3 02:43:12 2016 From: me+python at ixokai.io (Stephen Hansen) Date: Sat, 02 Apr 2016 23:43:12 -0700 Subject: Strange range In-Reply-To: <87vb3zpu49.fsf@elektro.pacujo.net> References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <1671ea2b-09ff-4745-a6e7-d2c57864cba3@googlegroups.com> <87zitbpwpr.fsf@elektro.pacujo.net> <87vb3zpu49.fsf@elektro.pacujo.net> Message-ID: <1459665792.195389.567158250.1843796D@webmail.messagingengine.com> On Sat, Apr 2, 2016, at 02:40 PM, Marko Rauhamaa wrote: > That's why I was looking for counterexamples in the standard library This entire bent of an argument seems flawed to me. The standard library has never been a beacon for best practices or idiomatic uses of Python. That a use exists in the standard library, or that one does not, doesn't really tell you anything meaningful about Python itself or good practices with the language. The standard library is under uniquely conservative constraints that enshrine compatibility and reliability from one point release to another over any kind of innovation. That code exists in the standard library is, itself, an incredibly strong reason why it should stay as IS: changes for style, idiom, best practices, modern techniques, those are all valid but *weak* arguments to change the standard library. The stdlib works and its continuing to work tomorrow is its most important burden. Just look at how much of the stdlib is not PEP8 compliant. Changing it to be PEP8 compliant is seen as a worse thing to do then the possibility of introducing bugs by doing such a sweeping change in the interest of good practices and style. The stdlib exists as a bastion of stability above all else. Its standards aren't a reason to make a change (or, not to make a change, either). That doesn't mean its not useful to look at the standard library, but you should not enshrine it as the example of good or idiomatic code to measure decisions against. Most code exists outside the stdlib. --- Stephen Hansen m e @ i x o k a i . i o From marko at pacujo.net Sun Apr 3 02:58:26 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 03 Apr 2016 09:58:26 +0300 Subject: Strange range References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <1671ea2b-09ff-4745-a6e7-d2c57864cba3@googlegroups.com> <87zitbpwpr.fsf@elektro.pacujo.net> <87vb3zpu49.fsf@elektro.pacujo.net> Message-ID: <87shz3p4a5.fsf@elektro.pacujo.net> Stephen Hansen : > On Sat, Apr 2, 2016, at 02:40 PM, Marko Rauhamaa wrote: >> That's why I was looking for counterexamples in the standard library > > This entire bent of an argument seems flawed to me. > > The standard library has never been a beacon for best practices or > idiomatic uses of Python. It's an obvious corpus of Python code not written by me that's readily available on my computer. An argument was made that range() has varied uses. I was trying to find those varied uses. > That a use exists in the standard library, or that one does not, > doesn't really tell you anything meaningful about Python itself or > good practices with the language. The standard library is under > uniquely conservative constraints that enshrine compatibility and > reliability from one point release to another over any kind of > innovation. What you seem to be saying is that range() used to be an iterator but has since ascended to the status of an iterable. > Most code exists outside the stdlib. Which should then make it easy for you to point out the kinds of counterexamples I was looking for. Marko From rosuav at gmail.com Sun Apr 3 03:08:21 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Apr 2016 17:08:21 +1000 Subject: Strange range In-Reply-To: <1459665792.195389.567158250.1843796D@webmail.messagingengine.com> References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <1671ea2b-09ff-4745-a6e7-d2c57864cba3@googlegroups.com> <87zitbpwpr.fsf@elektro.pacujo.net> <87vb3zpu49.fsf@elektro.pacujo.net> <1459665792.195389.567158250.1843796D@webmail.messagingengine.com> Message-ID: On Sun, Apr 3, 2016 at 4:43 PM, Stephen Hansen wrote: > The stdlib exists as a bastion of stability above all else. Its > standards aren't a reason to make a change (or, not to make a change, > either). That doesn't mean its not useful to look at the standard > library, but you should not enshrine it as the example of good or > idiomatic code to measure decisions against. Most code exists outside > the stdlib. Expanding on this: There have been times when the stdlib has been cited in proposals, such as the introduction of a new keyword. Out of five plausible words, two have significant use in the stdlib, another has a couple of uses, and two more have no references at all. Specific example from PEP 359 [1]; the same line of analysis has also been used elsewhere. Also, a proposed new syntax can attempt to justify its benefit by taking examples from the stdlib, not because they will necessarily be changed, but simply because it's a good-sized codebase that all Python devs and tinkerers will have easy access to. PEP 463 [2] demonstrates this. Similarly, but in reverse: The stdlib can provide examples showing how a proposal will _break_ existing code, and how it should be fixed; PEP 479 [3] has a few examples, some from the stdlib, some hypothetical. In each case, the stdlib is being treated as simply "a body of Python code", and one which has a measure of neutrality (we're not favouring web app developers by looking at the Django source code, or numeric computational work by looking at Pandas, or anything like that), and if anything, it's indicative of older codebases rather than newer ones, which is usually good for proposals that need to be conservative. So in the case of range() usage, I would say that stdlib usage showing "x in range(...)" would be highly significant, but *absence* of such usage is not. ChrisA [1] https://www.python.org/dev/peps/pep-0359/#keyword [2] https://www.python.org/dev/peps/pep-0463/#example-usage [3] https://www.python.org/dev/peps/pep-0479/#examples-of-breakage From rosuav at gmail.com Sun Apr 3 03:10:42 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Apr 2016 17:10:42 +1000 Subject: Strange range In-Reply-To: <87shz3p4a5.fsf@elektro.pacujo.net> References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <1671ea2b-09ff-4745-a6e7-d2c57864cba3@googlegroups.com> <87zitbpwpr.fsf@elektro.pacujo.net> <87vb3zpu49.fsf@elektro.pacujo.net> <87shz3p4a5.fsf@elektro.pacujo.net> Message-ID: On Sun, Apr 3, 2016 at 4:58 PM, Marko Rauhamaa wrote: >> That a use exists in the standard library, or that one does not, >> doesn't really tell you anything meaningful about Python itself or >> good practices with the language. The standard library is under >> uniquely conservative constraints that enshrine compatibility and >> reliability from one point release to another over any kind of >> innovation. > > What you seem to be saying is that range() used to be an iterator but > has since ascended to the status of an iterable. No, range() has never returned an iterator. In Python 2, it returned a list, which is iterable. In Python 3, it returns a range object, which is iterable. And in Python 2, xrange returns an xrange object, which is also iterable (but less functional than the Py3 range object). None of these is an iterator. ChrisA From PointedEars at web.de Sun Apr 3 04:12:35 2016 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sun, 03 Apr 2016 10:12:35 +0200 Subject: [beginner] What's wrong? References: Message-ID: <5902127.ulEZ6DodmD@PointedEars.de> Michael Torrie wrote: > Mark, your messages are showing up to the list as being from "python," > at least on my email. Any reason for this? Depends on which Mark you are addressing and how you are reading e-mail. The messages of Mark Lawrence, for example, appear to me as technically correct as can be expected from a botched Mail-to-News interface; in particular, their ?From? header fields are correct. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From cs at zip.com.au Sun Apr 3 04:20:31 2016 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 3 Apr 2016 18:20:31 +1000 Subject: Failed to update the os.environ with subprocess.Popen. In-Reply-To: <57009af2$0$1607$c3e8da3$5496439d@news.astraweb.com> References: <57009af2$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20160403082031.GA42241@cskk.homeip.net> On 03Apr2016 14:24, Steven D'Aprano wrote: >On Sun, 3 Apr 2016 01:29 pm, Hongyi Zhao wrote: >> I use the following code to update the os.environ with subprocess.Popen: > >I don't understand what you are trying to do here. But regardless of your >intention, the problem you have is nothing to do with updating os.environ. >Proof: change the last line from this complicated expression: > >os.environ.update(line.partition('=')[::2] for line in output.split('\0')) >to this simple expression: >output.split('\0') > >and you will get the same error. os.environ is irrelevant. Your problem is >only with Popen. > >What makes you think that Popen objects have a split() method? They are not >documented as having this method: > >https://docs.python.org/2/library/subprocess.html >https://docs.python.org/3/library/subprocess.html >https://pymotw.com/2/subprocess/ In particular, you want the subprocess' output. As written, your code sets "output" to the Popen object. You actually want to set it to the .stdout attribute of that object, which is the output from the subcommand. Cheers, Cameron Simpson From hongyi.zhao at gmail.com Sun Apr 3 07:24:42 2016 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Sun, 3 Apr 2016 11:24:42 +0000 (UTC) Subject: Failed to update the os.environ with subprocess.Popen. References: <57009af2$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 03 Apr 2016 18:20:31 +1000, Cameron Simpson wrote: > In particular, you want the subprocess' output. As written, your code > sets "output" to the Popen object. You actually want to set it to the > .stdout attribute of that object, which is the output from the > subcommand. Based on your above hints, I try to use the following codes: output = Popen(""" /bin/bash < os.environ.update(line.partition('=')[::2] for line in output.split ('\0')) AttributeError: 'NoneType' object has no attribute 'split' While the following code will work smoothly: output = Popen(""" /bin/bash < <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> Message-ID: <2796705.edb3E9ArW3@PointedEars.de> Rustom Mody wrote: > On Saturday, April 2, 2016 at 10:42:27 PM UTC+5:30, Thomas 'PointedEars' > Lahn wrote: >> Marko Rauhamaa wrote: >> > Steven D'Aprano : >> >> So you're saying that learning to be a fluent speaker of English is a >> >> pre-requisite of being a programmer? >> > >> > No more than learning Latin is a prerequisite of being a doctor. >> >> Full ACK. Probably starting with the Industrial Revolution enabled by >> the improvements of the steam machine in England, English has become the >> /lingua franca/ of technology (even though the French often still >> disagree, preferring words like ? ordinateur ? and ? octet ? over >> ?computer? and >> ?byte?, respectively?). (With the Internet at the latest, then, it has >> also become the /lingua franca/ of science, although Latin terms are >> common in medicine.) > > IMHO the cavalier usage of random alphabet-soup for identifiers Straw man. Nobody has suggested that. Suggested were words in natural languages other than English as (parts of) names in Python programs. The suggestion was rejected by some (including me) on the grounds that source code is not written only for the person writing it, but also for other developers to read, and that English is the /lingua franca/ of software development at least. So it is reasonable to expect a software developer to understand English, and more software developers are going to understand the source code if it is written in English. Another argument that was made in favor of English-language names (albeit on the grounds of ?nausea? instead of the logical reason of practicality) is that the (Python) programming language?s keywords (e.g., False, None, True, and, as, assert [1]) and built-in identifiers (e.g., NotImplemented, Ellipsis, abs, all, int, float, complex, iterator [2]) are (abbreviations or concatenations of) *English* words; therefore, mixing keywords with names in a natural language other than English causes source code to be more difficult to read than an all-English source code (string values notwithstanding). This is particularly true with Python because a lot of (well-written) Python code can easily be read as if it were pseudocode. (I would not be surprised at all to learn that this was Guido van Rossum?s intention.) As for the ?Chinese? argument, I did some research recently, indicating that it is a statistical fallacy: >From personal experience, I can say that I had no great difficulty communicating in English with my Chinese flatmates and classmates at a German technical university when all of us were studying computer science there 16 years ago. It was natural. At least the boys even preferred self- chosen English first names for themselves (e.g., in instant messaging) since, as they explained to me, their original names were difficult to pronounce correctly for Europeans (or Europeans might mistakenly call them by their family name since it would come first), and to type on European keyboards (although I observed them to be proficient in using IMEs when chatting with their folks back home). ____________ [1] [2] > can lead to worse than just aesthetic unpleasantness: > https://en.wikipedia.org/wiki/IDN_homograph_attack Relevance? > When python went to full unicode identifers it should have also added > pragmas for which blocks the programmer intended to use -- something like > a charset declaration of html. > > This way if the programmer says "I want latin and greek" > and then A and ? get mixed up well he asked for it. > If he didn't ask then springing it on him seems unnecessary and uncalled > for Nonsense. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From alister.ware at ntlworld.com Sun Apr 3 08:37:44 2016 From: alister.ware at ntlworld.com (alister) Date: Sun, 03 Apr 2016 12:37:44 GMT Subject: [beginner] What's wrong? References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <877fgfrefw.fsf@elektro.pacujo.net> <57006856$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 03 Apr 2016 02:04:05 +0100, Mark Lawrence wrote: > On 03/04/2016 01:48, Steven D'Aprano wrote: >> On Sun, 3 Apr 2016 07:42 am, Michael Selik wrote: >> >>> Gaming also helps your reaction time. Normally 0.3 ms, but 0.1 ms for >>> top gamers. And fighter pilots. >> >> Does gaming help reaction time, or do only people with fast reaction >> times become top gamers? >> >> Personally, in my experience gaming hurts reaction time. I ask people a >> question, and they don't reply for a week or at all, because they're >> too busy playing games all day. >> >> > I must agree. When you're trying to get the ball away, and 23 stone of > bone and muscle smashes into you, that slows your reaction time. I am > of course referring to the sport of rugby, not that silly "World > Series", which takes part in only one country, where for some reason > unknown to me they wear huge quantities of armour and need oxygen masks > after they've run a few yards. What would happen to the poor little > darlings if they had to spend the entire match on the pitch? while i agree with your sentiments you have a few minor inacuracies the "World Series" has nothing to do with Poofs In Pads, it is actually Rounders. -- Real programmers don't write in BASIC. Actually, no programmers write in BASIC after reaching puberty. From rustompmody at gmail.com Sun Apr 3 10:30:47 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 3 Apr 2016 07:30:47 -0700 (PDT) Subject: [beginner] What's wrong? In-Reply-To: <2796705.edb3E9ArW3@PointedEars.de> References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <2796705.edb3E9ArW3@PointedEars.de> Message-ID: On Sunday, April 3, 2016 at 5:17:36 PM UTC+5:30, Thomas 'PointedEars' Lahn wrote: > Rustom Mody wrote: > > > On Saturday, April 2, 2016 at 10:42:27 PM UTC+5:30, Thomas 'PointedEars' > > Lahn wrote: > >> Marko Rauhamaa wrote: > >> > Steven D'Aprano : > >> >> So you're saying that learning to be a fluent speaker of English is a > >> >> pre-requisite of being a programmer? > >> > > >> > No more than learning Latin is a prerequisite of being a doctor. > >> > >> Full ACK. Probably starting with the Industrial Revolution enabled by > >> the improvements of the steam machine in England, English has become the > >> /lingua franca/ of technology (even though the French often still > >> disagree, preferring words like ? ordinateur ? and ? octet ? over > >> ?computer? and > >> ?byte?, respectively?). (With the Internet at the latest, then, it has > >> also become the /lingua franca/ of science, although Latin terms are > >> common in medicine.) > > > > IMHO the cavalier usage of random alphabet-soup for identifiers > > Straw man. Nobody has suggested that. Suggested were words in natural > languages other than English as (parts of) names in Python programs. > > The suggestion was rejected by some (including me) on the grounds that > source code is not written only for the person writing it, but also for > other developers to read, and that English is the /lingua franca/ of > software development at least. So it is reasonable to expect a software > developer to understand English, and more software developers are going to > understand the source code if it is written in English. > > Another argument that was made in favor of English-language names (albeit on > the grounds of ?nausea? instead of the logical reason of practicality) is > that the (Python) programming language?s keywords (e.g., False, None, True, > and, as, assert [1]) and built-in identifiers (e.g., NotImplemented, > Ellipsis, abs, all, int, float, complex, iterator [2]) are (abbreviations or > concatenations of) *English* words; therefore, mixing keywords with names > in a natural language other than English causes source code to be more > difficult to read than an all-English source code (string values > notwithstanding). This is particularly true with Python because a lot of > (well-written) Python code can easily be read as if it were pseudocode. (I > would not be surprised at all to learn that this was Guido van Rossum?s > intention.) > > As for the ?Chinese? argument, I did some research recently, indicating that > it is a statistical fallacy: > > > > > From personal experience, I can say that I had no great difficulty > communicating in English with my Chinese flatmates and classmates at a > German technical university when all of us were studying computer science > there 16 years ago. It was natural. At least the boys even preferred self- > chosen English first names for themselves (e.g., in instant messaging) > since, as they explained to me, their original names were difficult to > pronounce correctly for Europeans (or Europeans might mistakenly call them > by their family name since it would come first), and to type on European > keyboards (although I observed them to be proficient in using IMEs when > chatting with their folks back home). > > ____________ > [1] > [2] > > > can lead to worse than just aesthetic unpleasantness: > > https://en.wikipedia.org/wiki/IDN_homograph_attack > > Relevance? > > > When python went to full unicode identifers it should have also added > > pragmas for which blocks the programmer intended to use -- something like > > a charset declaration of html. > > > > This way if the programmer says "I want latin and greek" > > and then A and ? get mixed up well he asked for it. > > If he didn't ask then springing it on him seems unnecessary and uncalled > > for > > Nonsense. Some misunderstanding of what I said it looks [Guessing also from Marko's "...silly..."] So here are some examples to illustrate what I am saying: Example 1 -- Ligatures: Python3 gets it right >>> ?ag = 1 >>> flag 1 Whereas haskell gets it wrong: Prelude> let ?ag = 1 Prelude> flag :3:1: Not in scope: ?flag? Prelude> ?ag 1 Prelude> Example 2 Case Sensitivity Scheme? gets it right > (define a 1) > A 1 > a 1 Python gets it wrong >>> a=1 >>> A Traceback (most recent call last): File "", line 1, in NameError: name 'A' is not defined >>> a [Likewise filenames windows gets right; Unix wrong] Unicode Identifiers in the spirit of IDN homograph attack. Every language that 'supports' unicode gets it wrong Python3 >>> A=1 >>> ? Traceback (most recent call last): File "", line 1, in NameError: name '?' is not defined >>> A 1 Can you make out why A both is and is not defined? When the language does not support it eg python2 the behavior is better >>> A=1 >>> ? File "", line 1 ? ^ SyntaxError: invalid syntax >>> A 1 >>> So whats the point? The notion of 'variable' in programming language is inherently based on that of 'identifier'. With ASCII the problems are minor: Case-distinct identifiers are distinct -- they dont IDENTIFY. This contradicts standard English usage and practice buts its not such a big deal With Unicode there are zillions of look-alike that eg A and ? and ? that are identical until you ferret out the details. A language that allows this without some red flag is storing future grief for unsuspecting programmers. ? Ironically upto R5RS version of scheme this was true Thereafter Unix nerds have won over good old standard English practice From thisisink01 at gmail.com Sun Apr 3 10:41:43 2016 From: thisisink01 at gmail.com (Loop.IO) Date: Sun, 3 Apr 2016 07:41:43 -0700 (PDT) Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> Message-ID: <32c7ba6b-b61d-45fb-89a8-dd62aa09fe78@googlegroups.com> On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote: > On 02/04/2016 23:31, Loop.IO wrote: > > > Oh i see, so the code prompts for a name.. so i'm more lost than i thought, what do I need to change to make it just create the file with the chosen name Launch2.bat without the prompt? > > If you don't want the user to enter anything, then I explained how > before, just use: > > name='C:\\Documents\\PythonCoding\\launch2.bat' > > if that's the file name you need. > > -- > Bartc Hi Bartc, i tried that, didn't work From thisisink01 at gmail.com Sun Apr 3 10:45:02 2016 From: thisisink01 at gmail.com (Loop.IO) Date: Sun, 3 Apr 2016 07:45:02 -0700 (PDT) Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <18604420-d8ee-485a-96ef-bbda9a590201@googlegroups.com> Message-ID: On Sunday, April 3, 2016 at 1:08:59 AM UTC+1, Mark Lawrence wrote: > On 02/04/2016 23:23, Loop.IO wrote: > > On Saturday, April 2, 2016 at 11:09:13 PM UTC+1, BartC wrote: > >> On 02/04/2016 22:59, Loop.IO wrote: > >>> Hey > >>> > >>> So I built a keylogger using python as a test, got the code from the tutorial online, I want to improve on it to make it more automated, but the issue I'm having is it won't create the file until I press return, any clues where I'm going wrong? > >>> > >>> If I press return it makes the batch file, otherwise it just hangs. > >> > >>> name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat' > >> > >> You're asking for a file name to be entered. So that if ABC is pressed, > >> followed by Enter, it will use: > >> > >> C:\Documents\PythonCoding\ABClaunch2.bat > >> > >> Assuming that's the intention, then Enter is needed so that it knows > >> when the user has completed typing the name. If not, then just use: > >> > >> name='C:\\Documents\\PythonCoding\\launch2.bat' > >> > >> (If you want a single character name, without pressing Enter, that's > >> harder to do. Someone else will have to help.) > >> > >> -- > >> Bartc > > > > Hey Bartc > > > > I don't quite understand what you mean? > > > > The file is just supposed to be created, I don't want to have to press "Enter" or "Return" for it to complete the file creation > > > > the info i followed to create the file advised I had to add the file name and extension on after like in the code > > > > There is no point asking BartC about Python as he has repeatedly stated > that he knows nothing about Python. OTOH there are loads of people here > who do know Python, backwards, sideways and inside out. If you state > precisely what you are trying to achieve then you will get the correct > answer. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence Hi Mark Basically I want the program to do the search, which it does fine, then create the batch file then close. What I will be doing once thats fixed is then adding a write to the batch file some lines of code, which im already testing and seems to work fine, its just the having to press enter to create the file and then close the program From rustompmody at gmail.com Sun Apr 3 10:52:29 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 3 Apr 2016 07:52:29 -0700 (PDT) Subject: [beginner] What's wrong? In-Reply-To: <57005a7e$0$1589$c3e8da3$5496439d@news.astraweb.com> References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <57005a7e$0$1589$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4c5e7000-de47-49c2-bc3b-d7b23ed98625@googlegroups.com> On Sunday, April 3, 2016 at 5:19:33 AM UTC+5:30, Steven D'Aprano wrote: > On Sun, 3 Apr 2016 03:12 am, Thomas 'PointedEars' Lahn wrote: > > > Marko Rauhamaa wrote: > > > >> Steven D'Aprano : > >>> So you're saying that learning to be a fluent speaker of English is a > >>> pre-requisite of being a programmer? > >> > >> No more than learning Latin is a prerequisite of being a doctor. > > > > Full ACK. Probably starting with the Industrial Revolution enabled by the > > improvements of the steam machine in England, English has become the > > /lingua franca/ of technology (even though the French often still > > disagree, preferring words like << ordinateur >> and << octet >> over > > "computer" and "byte", respectively?). (With the Internet at the latest, > > then, it has also become the /lingua franca/ of science, although Latin > > terms are common in medicine.) > > And this is a BAD THING. Monoculture is harmful, and science and technology > is becoming a monoculture: Anglo-American language expressing > Anglo-American ideas, regardless of the nationality of the scientist or > engineer. I think you are ending making the opposite point of what you seem to want to make Yeah... ok monoculture is a bad thing. Is python(3) helping towards a 'polyculture'? To see this consider some app like Word or Gimp that has significant functionality and has a history over 20 years. So let us say some 10 years ago it was internationalized. This consists of 1. Rewriting the 'strings' into gettext (or whatever) form along with other program reorgs 2. Translators actually translating the 'strings' Or take a modern OS like Windows or Ubuntu -- from the first install screen we can pick a language and then it will be localized to that To really localize python one would have to 1. Localize the keywords 2. Localize all module names 3. Localize all the help strings 4. Localize the entire stuff up at https://docs.python.org/3/ 5. ... That is probably one or two orders of magnitude more work than localizing gimp or Word So if this is the full goal how far does "You can now spell (or misspell) your python identifiers in any language of your choice" go towards that goal? From anthony.uwaifo55 at gmail.com Sun Apr 3 11:06:58 2016 From: anthony.uwaifo55 at gmail.com (anthony uwaifo) Date: Sun, 3 Apr 2016 16:06:58 +0100 Subject: i cant seem to figure out the error Message-ID: hi everyone, please i need help with this assignment. I have written a code and i still get an error. please help me debug my code. instructions: - Create a constructor that takes in an integer and assigns this to a `balance` property. - Create a method called `deposit` that takes in cash deposit amount and updates the balance accordingly. - Create a method called `withdraw` that takes in cash withdrawal amount and updates the balance accordingly. if amount is greater than balance return `"invalid transaction"` - Create a subclass MinimumBalanceAccount of the BankAccount class My code: class BankAccount(object): def __init__(self, balance): self.balance = balance def deposit(self, amount): self.amount=amount self.balance += amount return self.balance def withdraw(self, amount): self.amount=amount if(amount > self.balance): return ("Amount greater than available balance.") else: self.balance -= amount return self.balance class MinimumBalanceAccount(BankAccount): def __init__(self, minimum_balance): BankAccount.__init__(self) self.minimum_balance = minimum_balance act = BankAccount(5) act.deposit(400) act.withdraw(200) print act.balance error message: THERE IS AN ERROR/BUG IN YOUR CODE*Results: * {"finished": true, "success": [{"fullName": "test_balance", "passedSpecNumber": 1}, {"fullName": "test_deposit", "passedSpecNumber": 2}, {"fullName": "test_sub_class", "passedSpecNumber": 3}, {"fullName": "test_withdraw", "passedSpecNumber": 4}], "passed": false, "started": true, "failures": [{"failedSpecNumber": 1, "fullName": "test_invalid_operation", "failedExpectations": [{"message": "Failure in line 23, in test_invalid_operation\n self.assertEqual(self.my_account.withdraw(1000), \"invalid transaction\", msg='Invalid transaction')\nAssertionError: Invalid transaction\n"}]}], "specs": {"count": 5, "pendingCount": 0, "time": "0.000079"}} 205 From bc at freeuk.com Sun Apr 3 11:11:36 2016 From: bc at freeuk.com (BartC) Date: Sun, 3 Apr 2016 16:11:36 +0100 Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: <32c7ba6b-b61d-45fb-89a8-dd62aa09fe78@googlegroups.com> References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> <32c7ba6b-b61d-45fb-89a8-dd62aa09fe78@googlegroups.com> Message-ID: On 03/04/2016 15:41, Loop.IO wrote: > On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote: >> On 02/04/2016 23:31, Loop.IO wrote: >> >>> Oh i see, so the code prompts for a name.. so i'm more lost than i thought, what do I need to change to make it just create the file with the chosen name Launch2.bat without the prompt? >> >> If you don't want the user to enter anything, then I explained how >> before, just use: >> >> name='C:\\Documents\\PythonCoding\\launch2.bat' >> >> if that's the file name you need. >> >> -- >> Bartc > > Hi Bartc, i tried that, didn't work You mean it gave an error when you tried to create that file? Does that path already exist on your machine? If not then trying to create a file in a non-existent path won't work. You can create the path manually outside of Python. Or look up the docs to find out how to do that. A quick google suggested using os.makedirs (to create multiple nested paths at the same time). The following code worked on my machine: import sys import os def create(): print("creating new file") path="c:/Documents/PythonCoding/" name=path+"launch2.bat" try: os.stat(path) except: os.makedirs(path) print (name) try: file=open(name,'w') file.close() except: print("error occured") sys.exit(0) create() -- Bartc From rustompmody at gmail.com Sun Apr 3 11:25:11 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 3 Apr 2016 08:25:11 -0700 (PDT) Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> <32c7ba6b-b61d-45fb-89a8-dd62aa09fe78@googlegroups.com> Message-ID: <3596709a-c16d-401f-8ab3-70d0ab9dd9be@googlegroups.com> On Sunday, April 3, 2016 at 8:41:49 PM UTC+5:30, BartC wrote: > On 03/04/2016 15:41, Loop.IO wrote: > > On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote: > >> On 02/04/2016 23:31, Loop.IO wrote: > >> > >>> Oh i see, so the code prompts for a name.. so i'm more lost than i thought, what do I need to change to make it just create the file with the chosen name Launch2.bat without the prompt? > >> > >> If you don't want the user to enter anything, then I explained how > >> before, just use: > >> > >> name='C:\\Documents\\PythonCoding\\launch2.bat' > >> > >> if that's the file name you need. > >> > >> -- > >> Bartc > > > > Hi Bartc, i tried that, didn't work > > You mean it gave an error when you tried to create that file? > > Does that path already exist on your machine? If not then trying to > create a file in a non-existent path won't work. > > You can create the path manually outside of Python. Or look up the docs > to find out how to do that. A quick google suggested using os.makedirs > (to create multiple nested paths at the same time). > > The following code worked on my machine: > > import sys > import os > > def create(): > print("creating new file") > > path="c:/Documents/PythonCoding/" > name=path+"launch2.bat" > > try: > os.stat(path) > except: > os.makedirs(path) > > print (name) > > try: > file=open(name,'w') > file.close() > except: If you dont want the vigilantes out in their squadrons please dont do it that way. More seriously you can do what you like but dont teach beginners to use bare excepts. Do except IOError # I think... else whatever is the error you want to trap From dan at tombstonezero.net Sun Apr 3 11:25:29 2016 From: dan at tombstonezero.net (Dan Sommers) Date: Sun, 3 Apr 2016 15:25:29 -0000 (UTC) Subject: [beginner] What's wrong? References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <2796705.edb3E9ArW3@PointedEars.de> Message-ID: On Sun, 03 Apr 2016 07:30:47 -0700, Rustom Mody wrote: > So here are some examples to illustrate what I am saying: [A vs a, A vs A, ?ag vs flag, etc.] Are identifiers text or bytes? or something else entirely that takes natural language rules and the appearance of the glyphs into account? I, for one, am very happy that identifiers are more like bytes than like they are like text. The rules for equality for sequences of bytes are well-defined and unambiguous. The rules for equality for text are not. Do I have to know the details of every human (and some non-human) language, not to mention their typographical conventions (e.g., ligatures) just to determine whether two identifiers are the same? Yes, it's marginally annoying, and a security hole waiting to happen, than A and A often look very much alike. It's also troubling that I, a native English speaker with some knowledge of a random selection of other languages, should know whether e and ? are the same, or whether ij and ? are the same, and that it might depend on the fonts that happen to have been used to render them. And where does it end? If ?ag and flag are the same, then are Omega and ? the same? In English (and many other languages), it is wrong to spell my first name with an initial lower case letter. Therefore, Dan and dan are not, and should not be, the same identifier. ObPython: if my identifiers are case-insensitive, then what about the language's keywords? Can I spell class and for as Class and For? I understand that in some use cases, ?ag and flag represent the same English word, but please don't extend that to identifiers in my software. Dan From rustompmody at gmail.com Sun Apr 3 11:39:02 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 3 Apr 2016 08:39:02 -0700 (PDT) Subject: [beginner] What's wrong? In-Reply-To: References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <2796705.edb3E9ArW3@PointedEars.de> Message-ID: <33b043f4-b68e-4346-8e47-029815ab1204@googlegroups.com> On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote: > On Sun, 03 Apr 2016 07:30:47 -0700, Rustom Mody wrote: > > > So here are some examples to illustrate what I am saying: > > [A vs a, A vs A, ?ag vs flag, etc.] > I understand that in some use cases, ?ag and flag represent the same > English word, but please don't extend that to identifiers in my > software. I wonder once again if you are getting my point opposite to the one I am making. With ASCII there were problems like O vs 0 -- niggling but small. With Unicode its a gigantic pandora box. Python by allowing unicode identifiers without restraint has made grief for unsuspecting programmers. That is why my original suggestion that there should have been alongside this 'brave new world', a pragma wherein a programmer can EXPLICITLY declare #language Greek Then he is knowingly opting into possible clashes between A and ? But not between A and ?. [And if you think the above is a philosophical disquisition on Aristotle's law of identity: "A is A" you just proved my point that unconstrained Unicode identifiers is a mess] From rustompmody at gmail.com Sun Apr 3 11:46:59 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 3 Apr 2016 08:46:59 -0700 (PDT) Subject: [beginner] What's wrong? In-Reply-To: References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <2796705.edb3E9ArW3@PointedEars.de> Message-ID: On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote: > Yes, it's marginally annoying, and a security hole waiting to happen, > that A and A often look very much alike. "A security hole waiting to happen" = "Marginally annoying" Frankly I find this juxtaposition alarming Personal note: I once was idiot enough to have root with password root123 and transferring some files to a friend ... over ssh... Lost my entire installation in a matter of minutes From rosuav at gmail.com Sun Apr 3 11:53:41 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Apr 2016 01:53:41 +1000 Subject: [beginner] What's wrong? In-Reply-To: References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <2796705.edb3E9ArW3@PointedEars.de> Message-ID: On Mon, Apr 4, 2016 at 1:46 AM, Rustom Mody wrote: > On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote: >> Yes, it's marginally annoying, and a security hole waiting to happen, >> that A and A often look very much alike. > > > "A security hole waiting to happen" = "Marginally annoying" > > Frankly I find this juxtaposition alarming > > Personal note: I once was idiot enough to have root with password root123 > and transferring some files to a friend ... over ssh... > Lost my entire installation in a matter of minutes Exactly why did you have root ssh access with a password? ChrisA From larry.martell at gmail.com Sun Apr 3 11:55:41 2016 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 3 Apr 2016 11:55:41 -0400 Subject: [beginner] What's wrong? In-Reply-To: References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <2796705.edb3E9ArW3@PointedEars.de> Message-ID: On Sun, Apr 3, 2016 at 11:46 AM, Rustom Mody wrote: > Personal note: I once was idiot enough to have root with password root123 I changed my password to "incorrect," so whenever I forget it the computer will say, "Your password is incorrect." From bc at freeuk.com Sun Apr 3 12:04:24 2016 From: bc at freeuk.com (BartC) Date: Sun, 3 Apr 2016 17:04:24 +0100 Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: <3596709a-c16d-401f-8ab3-70d0ab9dd9be@googlegroups.com> References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> <32c7ba6b-b61d-45fb-89a8-dd62aa09fe78@googlegroups.com> <3596709a-c16d-401f-8ab3-70d0ab9dd9be@googlegroups.com> Message-ID: On 03/04/2016 16:25, Rustom Mody wrote: > On Sunday, April 3, 2016 at 8:41:49 PM UTC+5:30, BartC wrote: >> You can create the path manually outside of Python. Or look up the docs >> to find out how to do that. A quick google suggested using os.makedirs >> (to create multiple nested paths at the same time). >> try: >> os.stat(path) >> except: >> os.makedirs(path) >> >> print (name) >> >> try: >> file=open(name,'w') >> file.close() >> except: > > If you dont want the vigilantes out in their squadrons please dont do it that way. > > More seriously you can do what you like but dont teach beginners to use bare excepts. They're not mine (the first is from the first google hit, the second is the OP's); if it was my choice I wouldn't use exceptions at all. But the primary issue here is that file not being created. Once the code works, it can be tweaked later and, if the path still needs creating from the code, there are doubtless better ways of doing it, with or without exceptions. At the minute we don't even know if this was the problem. -- Bartc From dan at tombstonezero.net Sun Apr 3 12:07:42 2016 From: dan at tombstonezero.net (Dan Sommers) Date: Sun, 3 Apr 2016 16:07:42 -0000 (UTC) Subject: [beginner] What's wrong? References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <2796705.edb3E9ArW3@PointedEars.de> Message-ID: On Sun, 03 Apr 2016 08:46:59 -0700, Rustom Mody wrote: > On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote: >> Yes, it's marginally annoying, and a security hole waiting to happen, >> that A and A often look very much alike. > > "A security hole waiting to happen" = "Marginally annoying" > > Frankly I find this juxtaposition alarming Sorry about that. I didn't mean to equate the two. I meant to point out that the fact that A and A look alike can be one, or both, of those things. Perhaps I should have used "or" instead of "and." From dan at tombstonezero.net Sun Apr 3 12:22:55 2016 From: dan at tombstonezero.net (Dan Sommers) Date: Sun, 3 Apr 2016 16:22:55 -0000 (UTC) Subject: [beginner] What's wrong? References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <2796705.edb3E9ArW3@PointedEars.de> <33b043f4-b68e-4346-8e47-029815ab1204@googlegroups.com> Message-ID: On Sun, 03 Apr 2016 08:39:02 -0700, Rustom Mody wrote: > On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote: >> On Sun, 03 Apr 2016 07:30:47 -0700, Rustom Mody wrote: >> >> > So here are some examples to illustrate what I am saying: >> >> [A vs a, A vs A, ?ag vs flag, etc.] > >> I understand that in some use cases, ?ag and flag represent the same >> English word, but please don't extend that to identifiers in my >> software. > I wonder once again if you are getting my point opposite to the one I > am making. With ASCII there were problems like O vs 0 -- niggling but > small. > > With Unicode its a gigantic pandora box. Python by allowing unicode > identifiers without restraint has made grief for unsuspecting > programmers. What about the A vs a case, which comes up even with ASCII-only characters? If those are the same, then I, as a reader of Python code, have to understand all the rules about ? (which I think have changed over time), and potentially ? and others. > That is why my original suggestion that there should have been alongside this > 'brave new world', a pragma wherein a programmer can EXPLICITLY declare > #language Greek > Then he is knowingly opting into possible clashes between A and ? > But not between A and ?. If I declared #language Greek, then I'd expect an identifier like A to be rejected by the compiler. That said, I don't know if that sort of distinction is as clear cut in every language supported by Unicode. And just to cause trouble (because that's the way I feel today), can I declare #?????? ???????? ;-) > [And if you think the above is a philosophical disquisition on > Aristotle's law of identity: "A is A" you just proved my point that > unconstrained Unicode identifiers is a mess] Can we take a "we're all adults here" approach? For the same reason that adults don't use identifiers like xl0, x10, xlO, and xl0 anywhere near each other, shouldn't we also not use A and A anywhere near each other? I certainly don't want the language itself to [try to] reject x10 and xIO because they look too much alike in many fonts. From okuntsov.mikhail at yandex.ru Sun Apr 3 12:24:41 2016 From: okuntsov.mikhail at yandex.ru (Michael Okuntsov) Date: Sun, 3 Apr 2016 22:24:41 +0600 Subject: [beginner] What's wrong? In-Reply-To: <4c5e7000-de47-49c2-bc3b-d7b23ed98625@googlegroups.com> References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <57005a7e$0$1589$c3e8da3$5496439d@news.astraweb.com> <4c5e7000-de47-49c2-bc3b-d7b23ed98625@googlegroups.com> Message-ID: 03.04.2016 20:52, Rustom Mody ?????: > To really localize python one would have to > 1. Localize the keywords > 2. Localize all module names > 3. Localize all the help strings > 4. Localize the entire stuff up at https://docs.python.org/3/ > 5. ... > > That is probably one or two orders of magnitude more work than > localizing gimp or Word > > So if this is the full goal how far does > "You can now spell (or misspell) your python identifiers in any language of your choice" > go towards that goal? > As an OP, can I participate in the discussion? Here in Russia we have a monstrous bookkeeping system called 1C-Predpriyatiye that is used by almost all firms and organizations, from kiosks to huge factories. This system has a Basic-like language with keywords, module names etc. localized in Russian language, but it has also English, German, and Ukrainian localizations. I don't want to say that common programming languages should be like this, but here we have an example that it can be done. From ethan at stoneleaf.us Sun Apr 3 12:28:19 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 03 Apr 2016 09:28:19 -0700 Subject: Strange range In-Reply-To: <87shz3p4a5.fsf@elektro.pacujo.net> References: <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <87lh4xjt37.fsf@elektro.pacujo.net> <1671ea2b-09ff-4745-a6e7-d2c57864cba3@googlegroups.com> <87zitbpwpr.fsf@elektro.pacujo.net> <87vb3zpu49.fsf@elektro.pacujo.net> <87shz3p4a5.fsf@elektro.pacujo.net> Message-ID: <570144A3.2040701@stoneleaf.us> On 04/02/2016 11:58 PM, Marko Rauhamaa wrote: > Stephen Hansen : > >> On Sat, Apr 2, 2016, at 02:40 PM, Marko Rauhamaa wrote: >>> That's why I was looking for counterexamples in the standard library >> >> This entire bent of an argument seems flawed to me. >> >> The standard library has never been a beacon for best practices or >> idiomatic uses of Python. > > It's an obvious corpus of Python code not written by me that's readily > available on my computer. An argument was made that range() has varied > uses. I was trying to find those varied uses. Which is fine, but failing to find them is insignificant. >> Most code exists outside the stdlib. > > Which should then make it easy for you to point out the kinds of > counterexamples I was looking for. I'm pretty sure that 99+% of the non-stdlib code out there is also completely inaccessible (or at least inconveniently accessible) to Stephen as well. Besides which, the amount of extra effort someone else is willing to go to to prove something is directly related to the interestingness of the topic -- and the various uses of range() isn't that interesting (it would be more interesting if a PEP was on the line...) . -- ~Ethan~ From rosuav at gmail.com Sun Apr 3 12:28:20 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Apr 2016 02:28:20 +1000 Subject: [beginner] What's wrong? In-Reply-To: References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <57005a7e$0$1589$c3e8da3$5496439d@news.astraweb.com> <4c5e7000-de47-49c2-bc3b-d7b23ed98625@googlegroups.com> Message-ID: On Mon, Apr 4, 2016 at 2:24 AM, Michael Okuntsov wrote: > As an OP, can I participate in the discussion? Here in Russia we have a > monstrous bookkeeping system called 1C-Predpriyatiye that is used by almost > all firms and organizations, from kiosks to huge factories. This system has > a Basic-like language with keywords, module names etc. localized in Russian > language, but it has also English, German, and Ukrainian localizations. I > don't want to say that common programming languages should be like this, but > here we have an example that it can be done. Absolutely you can participate! And thank you. That's exactly the sort of thing I'm talking about; you should be able to script that in Russian if your business is primarily Russian. ChrisA From rosuav at gmail.com Sun Apr 3 12:44:16 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Apr 2016 02:44:16 +1000 Subject: [beginner] What's wrong? In-Reply-To: References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <2796705.edb3E9ArW3@PointedEars.de> <33b043f4-b68e-4346-8e47-029815ab1204@googlegroups.com> Message-ID: On Mon, Apr 4, 2016 at 2:22 AM, Dan Sommers wrote: > What about the A vs a case, which comes up even with ASCII-only > characters? If those are the same, then I, as a reader of Python code, > have to understand all the rules about ? (which I think have changed > over time), and potentially ? and others. And I??i, and ???, and (if you want completeness) ? too. And various other case conversion rules. It's not possible to case-fold perfectly without knowing what language something is. This, coupled with the extremely useful case distinction between "Classes" and "instances", means I'm very much glad Python is case sensitive. "base = Base()" is perfectly legal and meaningful, no matter what language you translate those words into (well, as long as it's bicameral - otherwise you need to adorn one of them somehow, but you'd have to anyway). ChrisA From rustompmody at gmail.com Sun Apr 3 12:49:03 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 3 Apr 2016 09:49:03 -0700 (PDT) Subject: [beginner] What's wrong? In-Reply-To: References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <2796705.edb3E9ArW3@PointedEars.de> Message-ID: On Sunday, April 3, 2016 at 9:30:40 PM UTC+5:30, Chris Angelico wrote: > Exactly why did you have root ssh access with a password? Umm... Dont exactly remember. Probably it was not strictly necessary. Combination of carelessness, stupidity, hurry.... Brings me to... On Sunday, April 3, 2016 at 9:41:11 PM UTC+5:30, Dan Sommers wrote: > On Sun, 03 Apr 2016 08:46:59 -0700, Rustom Mody wrote: > > > On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote: > >> Yes, it's marginally annoying, and a security hole waiting to happen, > >> that A and A often look very much alike. > > > > "A security hole waiting to happen" = "Marginally annoying" > > > > Frankly I find this juxtaposition alarming > > Sorry about that. > > I didn't mean to equate the two. I meant to point out that the fact > that A and A look alike can be one, or both, of those things. Perhaps I > should have used "or" instead of "and." Chill! No offence. Just that when you have the above ingredients (carelessness, stupidity, hurry....) multiplied by a GHz clock, it makes for spicy security incidents(!). I just meant to say that "Just a lil security incident" is not a helpful attitude to foster From rustompmody at gmail.com Sun Apr 3 13:18:45 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 3 Apr 2016 10:18:45 -0700 (PDT) Subject: [beginner] What's wrong? In-Reply-To: References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <2796705.edb3E9ArW3@PointedEars.de> <33b043f4-b68e-4346-8e47-029815ab1204@googlegroups.com> Message-ID: <257887ea-df88-4229-b045-57d50b7e60b1@googlegroups.com> On Sunday, April 3, 2016 at 9:56:24 PM UTC+5:30, Dan Sommers wrote: > On Sun, 03 Apr 2016 08:39:02 -0700, Rustom Mody wrote: > > > On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote: > >> On Sun, 03 Apr 2016 07:30:47 -0700, Rustom Mody wrote: > >> > >> > So here are some examples to illustrate what I am saying: > >> > >> [A vs a, A vs A, ?ag vs flag, etc.] > > > >> I understand that in some use cases, ?ag and flag represent the same > >> English word, but please don't extend that to identifiers in my > >> software. > > > I wonder once again if you are getting my point opposite to the one I > > am making. With ASCII there were problems like O vs 0 -- niggling but > > small. > > > > With Unicode its a gigantic pandora box. Python by allowing unicode > > identifiers without restraint has made grief for unsuspecting > > programmers. > > What about the A vs a case, which comes up even with ASCII-only > characters? If those are the same, then I, as a reader of Python code, > have to understand all the rules about ? (which I think have changed > over time), and potentially ? and others. Dont get your point. If you know German then these rules should be clear enough to you If not youve probably got bigger problems reading that code anyway As illustration, here is Marko's code few posts back: for oppilas in luokka: if oppilas.hyl?tty(): oppilas.ilmoita(oppilas.koetulokset) Does it make sense to you? > > > That is why my original suggestion that there should have been alongside this > > 'brave new world', a pragma wherein a programmer can EXPLICITLY declare > > #language Greek > > Then he is knowingly opting into possible clashes between A and ? > > But not between A and ?. > > If I declared #language Greek, then I'd expect an identifier like A to > be rejected by the compiler. That said, I don't know if that sort of > distinction is as clear cut in every language supported by Unicode. > > And just to cause trouble (because that's the way I feel today), can I > declare > > #?????? ???????? > > ;-) > > > [And if you think the above is a philosophical disquisition on > > Aristotle's law of identity: "A is A" you just proved my point that > > unconstrained Unicode identifiers is a mess] > > Can we take a "we're all adults here" approach? Who's the 'we' we are talking about? > For the same reason > that adults don't use identifiers like xl0, x10, xlO, and xl0 anywhere > near each other, shouldn't we also not use A and A anywhere near each > other? I certainly don't want the language itself to [try to] reject > x10 and xIO because they look too much alike in many fonts. When Kernighan and Ritchie wrote C there was no problem with gets. Then suddenly, decades later the problem exploded. What happened? Here's an analysis: Security means two almost completely unrelated concepts - protection against shooting oneself in the foot (remember the 'protected' keyword of C++ ?) - protection against intelligent, capable, motivated criminals Lets call them security-s (against stupidity) and security-c (against criminals) Security-c didnt figure because computers were anyway physically secured and there was no much internet to speak of. gets was provided exactly on your principle of 'consenting-adults' -- if you use it you know what you are using. Then suddenly computers became net-facing and their servers could be written by 'consenting' (to whom?) adults using gets. Voila -- Security has just become a lucrative profession! I believe python's situation of laissez-faire unicode is similarly trouble-inviting. While I personally dont know enough about security to be able to demonstrate a full sequence of events, here's a little fun I had with Chris: https://mail.python.org/pipermail/python-list/2014-May/672413.html Do you not think this could be tailored into something more sinister and dangerous? From jsf80238 at gmail.com Sun Apr 3 13:34:52 2016 From: jsf80238 at gmail.com (Jason Friedman) Date: Sun, 3 Apr 2016 11:34:52 -0600 Subject: i cant seem to figure out the error In-Reply-To: References: Message-ID: > > - Create a method called `withdraw` that takes in cash withdrawal amount > and updates the balance accordingly. if amount is greater than balance > return `"invalid transaction"` > > def withdraw(self, amount): > self.amount=amount > if(amount > self.balance): > return ("Amount greater than available balance.") > else: > self.balance -= amount > return self.balance > The instructions say to "return 'invalid transaction'" but I expect they really want that error printed to STDERR (typically your screen) rather than literally returned. Try this: def withdraw(self, amount): self.amount=amount if(amount > self.balance): print "Amount greater than available balance, no funds withdrawn." else: self.balance -= amount return self.balance From rosuav at gmail.com Sun Apr 3 13:35:57 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Apr 2016 03:35:57 +1000 Subject: [beginner] What's wrong? In-Reply-To: <257887ea-df88-4229-b045-57d50b7e60b1@googlegroups.com> References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <2796705.edb3E9ArW3@PointedEars.de> <33b043f4-b68e-4346-8e47-029815ab1204@googlegroups.com> <257887ea-df88-4229-b045-57d50b7e60b1@googlegroups.com> Message-ID: On Mon, Apr 4, 2016 at 3:18 AM, Rustom Mody wrote: > While I personally dont know enough about security to be able to demonstrate a > full sequence of events, here's a little fun I had with Chris: > > https://mail.python.org/pipermail/python-list/2014-May/672413.html > > Do you not think this could be tailored into something more sinister and > dangerous? I honestly don't know what you're proving there. You didn't import a file called "1.py"; you just created a file with a non-ASCII name and used a non-ASCII identifier to import it. In other words, you did exactly what Unicode should allow: names in any language. ChrisA From python at mrabarnett.plus.com Sun Apr 3 13:36:43 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 3 Apr 2016 18:36:43 +0100 Subject: i cant seem to figure out the error In-Reply-To: References: Message-ID: <570154AB.4090009@mrabarnett.plus.com> On 2016-04-03 16:06, anthony uwaifo wrote: > hi everyone, > > please i need help with this assignment. I have written a code and i still > get an error. please help me debug my code. > > instructions: > > - Create a constructor that takes in an integer and assigns this to a > `balance` property. > - Create a method called `deposit` that takes in cash deposit amount and > updates the balance accordingly. > - Create a method called `withdraw` that takes in cash withdrawal amount > and updates the balance accordingly. if amount is greater than balance > return `"invalid transaction"` > - Create a subclass MinimumBalanceAccount of the BankAccount class > > > My code: > > class BankAccount(object): > def __init__(self, balance): > self.balance = balance > > > def deposit(self, amount): > self.amount=amount > self.balance += amount > return self.balance > > > def withdraw(self, amount): > self.amount=amount > if(amount > self.balance): > return ("Amount greater than available balance.") > else: > self.balance -= amount > return self.balance > > > > class MinimumBalanceAccount(BankAccount): > def __init__(self, minimum_balance): > BankAccount.__init__(self) > self.minimum_balance = minimum_balance > > act = BankAccount(5) > act.deposit(400) > act.withdraw(200) > print act.balance > > > error message: > > THERE IS AN ERROR/BUG IN YOUR CODE*Results: * > {"finished": true, "success": [{"fullName": "test_balance", > "passedSpecNumber": 1}, {"fullName": "test_deposit", > "passedSpecNumber": 2}, {"fullName": "test_sub_class", > "passedSpecNumber": 3}, {"fullName": "test_withdraw", > "passedSpecNumber": 4}], "passed": false, "started": true, "failures": > [{"failedSpecNumber": 1, "fullName": "test_invalid_operation", > "failedExpectations": [{"message": "Failure in line 23, in > test_invalid_operation\n > self.assertEqual(self.my_account.withdraw(1000), \"invalid > transaction\", msg='Invalid transaction')\nAssertionError: Invalid > transaction\n"}]}], "specs": {"count": 5, "pendingCount": 0, "time": > "0.000079"}} > 205 > What do the instructions say that `withdraw` should return if the amount is greater than the balance? What would your code return in such a case? From jsf80238 at gmail.com Sun Apr 3 13:37:09 2016 From: jsf80238 at gmail.com (Jason Friedman) Date: Sun, 3 Apr 2016 11:37:09 -0600 Subject: i cant seem to figure out the error In-Reply-To: References: Message-ID: > def deposit(self, amount): > self.amount=amount > self.balance += amount > return self.balance > > > def withdraw(self, amount): > self.amount=amount > if(amount > self.balance): > return ("Amount greater than available balance.") > else: > self.balance -= amount > return self.balance Also, this line is not needed in the deposit and withdraw methods: self.amount=amount From pkpearson at nowhere.invalid Sun Apr 3 14:18:10 2016 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 3 Apr 2016 18:18:10 GMT Subject: i cant seem to figure out the error References: Message-ID: On Sun, 3 Apr 2016 16:06:58 +0100, anthony uwaifo wrote: [snip] > > class BankAccount(object): > def __init__(self, balance): > self.balance = balance > > > def deposit(self, amount): > self.amount=amount > self.balance += amount > return self.balance > > > def withdraw(self, amount): > self.amount=amount > if(amount > self.balance): > return ("Amount greater than available balance.") > else: > self.balance -= amount > return self.balance > > > > class MinimumBalanceAccount(BankAccount): > def __init__(self, minimum_balance): > BankAccount.__init__(self) > self.minimum_balance = minimum_balance > > act = BankAccount(5) > act.deposit(400) > act.withdraw(200) > print act.balance There is an indentation error following the "else:" line. After I fixed that, the program runs and prints "205" (under Python 2.7.3). -- To email me, substitute nowhere->runbox, invalid->com. From python at mrabarnett.plus.com Sun Apr 3 14:21:45 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 3 Apr 2016 19:21:45 +0100 Subject: i cant seem to figure out the error In-Reply-To: References: Message-ID: <57015F39.1090305@mrabarnett.plus.com> On 2016-04-03 18:34, Jason Friedman wrote: >> >> - Create a method called `withdraw` that takes in cash withdrawal amount >> and updates the balance accordingly. if amount is greater than balance >> return `"invalid transaction"` >> >> def withdraw(self, amount): >> self.amount=amount >> if(amount > self.balance): >> return ("Amount greater than available balance.") >> else: >> self.balance -= amount >> return self.balance >> > > The instructions say to "return 'invalid transaction'" but I expect they > really want that error printed to STDERR (typically your screen) rather > than literally returned. Try this: > > def withdraw(self, amount): > self.amount=amount > if(amount > self.balance): > print "Amount greater than available balance, no funds withdrawn." > else: > self.balance -= amount > return self.balance > The instructions say "return", not "print" and the report contains: self.assertEqual(self.my_account.withdraw(1000), "invalid transaction", msg='Invalid transaction') so it _is_ checking the returned result of 'withdraw'. Not Pythonic (neither is printing to stderr! :-)), but that's something that can be worked on later. From dan at tombstonezero.net Sun Apr 3 14:26:48 2016 From: dan at tombstonezero.net (Dan Sommers) Date: Sun, 3 Apr 2016 18:26:48 -0000 (UTC) Subject: [beginner] What's wrong? References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <2796705.edb3E9ArW3@PointedEars.de> <33b043f4-b68e-4346-8e47-029815ab1204@googlegroups.com> <257887ea-df88-4229-b045-57d50b7e60b1@googlegroups.com> Message-ID: On Sun, 03 Apr 2016 10:18:45 -0700, Rustom Mody wrote: > On Sunday, April 3, 2016 at 9:56:24 PM UTC+5:30, Dan Sommers wrote: >> On Sun, 03 Apr 2016 08:39:02 -0700, Rustom Mody wrote: >> >> > On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote: >> >> On Sun, 03 Apr 2016 07:30:47 -0700, Rustom Mody wrote: >> >> >> >> > So here are some examples to illustrate what I am saying: >> >> >> >> [A vs a, A vs A, ?ag vs flag, etc.] >> > >> >> I understand that in some use cases, ?ag and flag represent the same >> >> English word, but please don't extend that to identifiers in my >> >> software. >> >> > I wonder once again if you are getting my point opposite to the one I >> > am making. With ASCII there were problems like O vs 0 -- niggling but >> > small. >> > >> > With Unicode its a gigantic pandora box. Python by allowing unicode >> > identifiers without restraint has made grief for unsuspecting >> > programmers. >> >> What about the A vs a case, which comes up even with ASCII-only >> characters? If those are the same, then I, as a reader of Python code, >> have to understand all the rules about ? (which I think have changed >> over time), and potentially ? and others. > > Dont get your point. > If you know German then these rules should be clear enough to you > If not youve probably got bigger problems reading that code anyway My point is that case sensitivity is good. I was disagreeing with your point about scheme getting A vs a "right" and Python and C and Unix getting it "wrong." My larger point, and my experience, is that case sensitivity is easier for to handle than case insensitivity. Most of the time, the same letter's capital and small renditions look different from each other (A vs a, Q vs q, and even ? and ? is no worse than O and o), and there are no context sensitive conversion rules to worry about. > As illustration, here is Marko's code few posts back: > > for oppilas in luokka: > if oppilas.hyl?tty(): > oppilas.ilmoita(oppilas.koetulokset) > > Does it make sense to you? It makes enough sense to recognize the idiom: for each item in a collection that satisfies a predicate, call a method on the item. My point here is that while the identifiers themselves can be enormously helpful to someone seeing a block of code for the first time or maintaining it five years later, it's just as important to recognize quickly that one identifier is not the same as another one, or that a particular identifier only appears once or only in certain syntactical constructs. If the above code were written a little differently, we'd be having a completely different discussion: for list in object: if list.clear(): list.pop(list.append) >> Can we take a "we're all adults here" approach? > > Who's the 'we' we are talking about? The community, who has accepted Python as a case-sensitive language and knows better than to use identifiers that look too much alike or are otherwise deliberatly mis-leading. >> For the same reason >> that adults don't use identifiers like xl0, x10, xlO, and xl0 anywhere >> near each other, shouldn't we also not use A and A anywhere near each >> other? I certainly don't want the language itself to [try to] reject >> x10 and xIO because they look too much alike in many fonts. > > When Kernighan and Ritchie wrote C there was no problem with gets. > Then suddenly, decades later the problem exploded. When Kernighan and Ritchie wrote C there *was* a problem with gets. > What happened? The problem was no longer isolated to taking down one Unix process or a single machine, or discovering passwords on that one machine. > Here's an analysis: > Security means two almost completely unrelated concepts > - protection against shooting oneself in the foot (remember the 'protected' > keyword of C++ ?) > - protection against intelligent, capable, motivated criminals > Lets call them security-s (against stupidity) and security-c (against criminals) > > Security-c didnt figure because computers were anyway physically secured and > there was no much internet to speak of. > gets was provided exactly on your principle of 'consenting-adults' -- if you > use it you know what you are using. > > Then suddenly computers became net-facing and their servers could be > written by 'consenting' (to whom?) adults using gets. > > Voila -- Security has just become a lucrative profession! I can't prevent insecure web servers, or unknowing users. Allowing or disallowing A and A and ? to coexist in the source code doesn't matter. > I believe python's situation of laissez-faire unicode is similarly > trouble-inviting. I'm not sure I agree, but I didn't timing attacks on cryptographic algorithms or devices reading passwords from air-gapped computers coming, either. I do know that complexity is also a source of bugs and security risks. Allowing or disallowing certain unicode code points in identifiers, and declaring that identifiers consisting of the same sequence of code points are the same, is way less complex than getting something else (even something as "simple" as case-insensitivity) right for all cases. > While I personally dont know enough about security to be able to demonstrate a > full sequence of events, here's a little fun I had with Chris: > > https://mail.python.org/pipermail/python-list/2014-May/672413.html > > Do you not think this could be tailored into something more sinister and > dangerous? From nospam at dfs.com Sun Apr 3 14:30:00 2016 From: nospam at dfs.com (DFS) Date: Sun, 3 Apr 2016 14:30:00 -0400 Subject: Sorting a list Message-ID: cntText = 60 cntBool = 20 cntNbrs = 30 cntDate = 20 cntBins = 20 strText = " text: " strBool = " boolean: " strNbrs = " numeric: " strDate = " date-time:" strBins = " binary: " colCounts = [(cntText,strText) , (cntBool,strBool), (cntNbrs,strNbrs) , (cntDate,strDate) , (cntBins,strBins)] # sort by alpha, then by column type count descending colCounts.sort(key=lambda x: x[1]) colCounts.sort(key=lambda x: x[0], reverse=True) for key in colCounts: print key[1], key[0]] ------------------------------------------------- Output (which is exactly what I want): text: 60 numeric: 30 binary: 20 boolean: 20 date-time: 20 ------------------------------------------------- But, is there a 1-line way to sort and print? Thanks! From dan at tombstonezero.net Sun Apr 3 14:32:26 2016 From: dan at tombstonezero.net (Dan Sommers) Date: Sun, 3 Apr 2016 18:32:26 -0000 (UTC) Subject: [beginner] What's wrong? References: <99234e90-fcd4-4a05-b97f-b47228dde20c@googlegroups.com> <1459571270.714249.566352882.6ADCD0CC@webmail.messagingengine.com> <87bn5sqcac.fsf@elektro.pacujo.net> <56ffedf1$0$1611$c3e8da3$5496439d@news.astraweb.com> <87h9fkq7tl.fsf@elektro.pacujo.net> <3524319.g0I1c1cpMS@PointedEars.de> <2796705.edb3E9ArW3@PointedEars.de> Message-ID: On Sun, 03 Apr 2016 09:49:03 -0700, Rustom Mody wrote: > On Sunday, April 3, 2016 at 9:41:11 PM UTC+5:30, Dan Sommers wrote: >> On Sun, 03 Apr 2016 08:46:59 -0700, Rustom Mody wrote: >> >> > On Sunday, April 3, 2016 at 8:58:59 PM UTC+5:30, Dan Sommers wrote: >> >> Yes, it's marginally annoying, and a security hole waiting to happen, >> >> that A and A often look very much alike. >> > >> > "A security hole waiting to happen" = "Marginally annoying" >> > >> > Frankly I find this juxtaposition alarming >> >> Sorry about that. >> >> I didn't mean to equate the two. I meant to point out that the fact >> that A and A look alike can be one, or both, of those things. Perhaps I >> should have used "or" instead of "and." > > Chill! No offence. I'm chilled. :-) No offense taken. I am arguably overly sensitive to putting forth an argument that isn't clear and concise (because I've also been known to derail the proceedings until I can get my head around someone else's argument). > Just that when you have the above ingredients (carelessness, > stupidity, hurry....) multiplied by a GHz clock, it makes for spicy > security incidents(!). I just meant to say that "Just a lil security > incident" is not a helpful attitude to foster On this we agree. :-) From nospam at dfs.com Sun Apr 3 14:34:44 2016 From: nospam at dfs.com (DFS) Date: Sun, 3 Apr 2016 14:34:44 -0400 Subject: Sorting a list In-Reply-To: References: Message-ID: On 4/3/2016 2:30 PM, DFS wrote: > cntText = 60 > cntBool = 20 > cntNbrs = 30 > cntDate = 20 > cntBins = 20 > > strText = " text: " > strBool = " boolean: " > strNbrs = " numeric: " > strDate = " date-time:" > strBins = " binary: " > > colCounts = [(cntText,strText) , (cntBool,strBool), (cntNbrs,strNbrs) , > (cntDate,strDate) , (cntBins,strBins)] > > # sort by alpha, then by column type count descending > colCounts.sort(key=lambda x: x[1]) > colCounts.sort(key=lambda x: x[0], reverse=True) > for key in colCounts: print key[1], key[0]] > > ------------------------------------------------- > > Output (which is exactly what I want): > > text: 60 > numeric: 30 > binary: 20 > boolean: 20 > date-time: 20 > > ------------------------------------------------- > > > But, is there a 1-line way to sort and print? Meant to include this example: print {i:os.strerror(i) for i in sorted(errno.errorcode)} > Thanks! > > > From muhammadaliaskari at gmail.com Sun Apr 3 14:57:05 2016 From: muhammadaliaskari at gmail.com (Muhammad Ali) Date: Sun, 3 Apr 2016 11:57:05 -0700 (PDT) Subject: PyQt4 Message-ID: Hi, How can we confirm that either PyQt4 is already installed on LInux machine or not? Please suggest commands to confirm the already existence of PyQt4 in the machine. Thank you. From muhammadaliaskari at gmail.com Sun Apr 3 15:01:48 2016 From: muhammadaliaskari at gmail.com (Muhammad Ali) Date: Sun, 3 Apr 2016 12:01:48 -0700 (PDT) Subject: Plot/Graph Message-ID: <768f1e2e-baab-4ce3-ae4e-aab2d8ac5bf8@googlegroups.com> Hi, Could anybody tell me that how can I plot graphs by matplotlib and get expertise in a short time? I have to plot 2D plots just like origin software. Secondly, how could we draw some horizontal reference line at zero when the vertical scale is from -3 to 3? Looking for your posts, please. Thank you. p.s: Is there any short and to the point text book/manual/pdf to learn 2D plotting with matplotlib? From torriem at gmail.com Sun Apr 3 15:14:45 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 3 Apr 2016 13:14:45 -0600 Subject: PyQt4 In-Reply-To: References: Message-ID: <57016BA5.2030602@gmail.com> On 04/03/2016 12:57 PM, Muhammad Ali wrote: > > Hi, > > How can we confirm that either PyQt4 is already installed on LInux machine or not? > > Please suggest commands to confirm the already existence of PyQt4 in the machine. Ideally you make a distribution-specific package of the binary in a .deb on Debian or an RPM on other distros, and specify that it depends on the package that provides PyQt4. That way when it's installed, modern package managers will automatically install the dependencies. Alternatively you can use try and except in your python code to attempt to import something from PyQt4 and see if it fails or not. This technique is also used to make your code work either PyQt4 or PySide, depending on which the user has installed. try: from PySide import QtGui except ImportError: from PyQt4 import QtGui If neither are installed, this little example will end with an ImportError. From __peter__ at web.de Sun Apr 3 15:31:05 2016 From: __peter__ at web.de (Peter Otten) Date: Sun, 03 Apr 2016 21:31:05 +0200 Subject: Sorting a list References: Message-ID: DFS wrote: > cntText = 60 > cntBool = 20 > cntNbrs = 30 > cntDate = 20 > cntBins = 20 > > strText = " text: " > strBool = " boolean: " > strNbrs = " numeric: " > strDate = " date-time:" > strBins = " binary: " > > colCounts = [(cntText,strText) , (cntBool,strBool), (cntNbrs,strNbrs) , > (cntDate,strDate) , (cntBins,strBins)] > > # sort by alpha, then by column type count descending > colCounts.sort(key=lambda x: x[1]) > colCounts.sort(key=lambda x: x[0], reverse=True) > for key in colCounts: print key[1], key[0]] > > ------------------------------------------------- > > Output (which is exactly what I want): > > text: 60 > numeric: 30 > binary: 20 > boolean: 20 > date-time: 20 > > ------------------------------------------------- > > > But, is there a 1-line way to sort and print? Yes, but I would not recommend it. You can replace the sort() method invocations with nested calls of sorted() and instead of for item in items: print convert_to_str(item) use print "\n".join(convert_to_str(item) for item in items) Putting it together: >>> from operator import itemgetter as get >>> print "\n".join("{1} {0}".format(*p) for p in sorted( ... sorted(colCounts, key=get(1)), key=get(0), reverse=True)) text: 60 numeric: 30 binary: 20 boolean: 20 date-time: 20 You could also cheat and use lambda v: (-v[0], v[1]) and a single sorted(). From thisisink01 at gmail.com Sun Apr 3 15:31:50 2016 From: thisisink01 at gmail.com (Loop.IO) Date: Sun, 3 Apr 2016 12:31:50 -0700 (PDT) Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> <32c7ba6b-b61d-45fb-89a8-dd62aa09fe78@googlegroups.com> Message-ID: <860f0703-08a1-4721-86c9-67ddc129cdc6@googlegroups.com> On Sunday, April 3, 2016 at 4:11:49 PM UTC+1, BartC wrote: > On 03/04/2016 15:41, Loop.IO wrote: > > On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote: > >> On 02/04/2016 23:31, Loop.IO wrote: > >> > >>> Oh i see, so the code prompts for a name.. so i'm more lost than i thought, what do I need to change to make it just create the file with the chosen name Launch2.bat without the prompt? > >> > >> If you don't want the user to enter anything, then I explained how > >> before, just use: > >> > >> name='C:\\Documents\\PythonCoding\\launch2.bat' > >> > >> if that's the file name you need. > >> > >> -- > >> Bartc > > > > Hi Bartc, i tried that, didn't work > > You mean it gave an error when you tried to create that file? > > Does that path already exist on your machine? If not then trying to > create a file in a non-existent path won't work. > > You can create the path manually outside of Python. Or look up the docs > to find out how to do that. A quick google suggested using os.makedirs > (to create multiple nested paths at the same time). > > The following code worked on my machine: > > import sys > import os > > def create(): > print("creating new file") > > path="c:/Documents/PythonCoding/" > name=path+"launch2.bat" > > try: > os.stat(path) > except: > os.makedirs(path) > > print (name) > > try: > file=open(name,'w') > file.close() > except: > print("error occured") > sys.exit(0) > > create() > > -- > Bartc The issue is that it hangs, there is no error. its like it pauses until i press enter, ill try what you've posted one moment From muhammadaliaskari at gmail.com Sun Apr 3 15:36:25 2016 From: muhammadaliaskari at gmail.com (Muhammad Ali) Date: Sun, 3 Apr 2016 12:36:25 -0700 (PDT) Subject: PyQt4 In-Reply-To: References: Message-ID: On Sunday, April 3, 2016 at 12:15:06 PM UTC-7, Michael Torrie wrote: > On 04/03/2016 12:57 PM, Muhammad Ali wrote: > > > > Hi, > > > > How can we confirm that either PyQt4 is already installed on LInux machine or not? > > > > Please suggest commands to confirm the already existence of PyQt4 in the machine. > > Ideally you make a distribution-specific package of the binary in a .deb > on Debian or an RPM on other distros, and specify that it depends on the > package that provides PyQt4. That way when it's installed, modern > package managers will automatically install the dependencies. > > Alternatively you can use try and except in your python code to attempt > to import something from PyQt4 and see if it fails or not. This > technique is also used to make your code work either PyQt4 or PySide, > depending on which the user has installed. > > try: > from PySide import QtGui > except ImportError: > from PyQt4 import QtGui > > If neither are installed, this little example will end with an ImportError. Thank you for your suggestions. I tried both but it shows the following error: IndentationError: expected an indented block Actually, I have to plot some graphs by using matplotlib and PyQt4 at supercomputer. Any other suggestion??? From thisisink01 at gmail.com Sun Apr 3 15:36:34 2016 From: thisisink01 at gmail.com (Loop.IO) Date: Sun, 3 Apr 2016 12:36:34 -0700 (PDT) Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: <860f0703-08a1-4721-86c9-67ddc129cdc6@googlegroups.com> References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> <32c7ba6b-b61d-45fb-89a8-dd62aa09fe78@googlegroups.com> <860f0703-08a1-4721-86c9-67ddc129cdc6@googlegroups.com> Message-ID: <99671ed7-7a89-4116-917d-3c9151847237@googlegroups.com> On Sunday, April 3, 2016 at 8:32:06 PM UTC+1, Loop.IO wrote: > On Sunday, April 3, 2016 at 4:11:49 PM UTC+1, BartC wrote: > > On 03/04/2016 15:41, Loop.IO wrote: > > > On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote: > > >> On 02/04/2016 23:31, Loop.IO wrote: > > >> > > >>> Oh i see, so the code prompts for a name.. so i'm more lost than i thought, what do I need to change to make it just create the file with the chosen name Launch2.bat without the prompt? > > >> > > >> If you don't want the user to enter anything, then I explained how > > >> before, just use: > > >> > > >> name='C:\\Documents\\PythonCoding\\launch2.bat' > > >> > > >> if that's the file name you need. > > >> > > >> -- > > >> Bartc > > > > > > Hi Bartc, i tried that, didn't work > > > > You mean it gave an error when you tried to create that file? > > > > Does that path already exist on your machine? If not then trying to > > create a file in a non-existent path won't work. > > > > You can create the path manually outside of Python. Or look up the docs > > to find out how to do that. A quick google suggested using os.makedirs > > (to create multiple nested paths at the same time). > > > > The following code worked on my machine: > > > > import sys > > import os > > > > def create(): > > print("creating new file") > > > > path="c:/Documents/PythonCoding/" > > name=path+"launch2.bat" > > > > try: > > os.stat(path) > > except: > > os.makedirs(path) > > > > print (name) > > > > try: > > file=open(name,'w') > > file.close() > > except: > > print("error occured") > > sys.exit(0) > > > > create() > > > > -- > > Bartc > > The issue is that it hangs, there is no error. its like it pauses until i press enter, ill try what you've posted one moment Ok the Bartc code gives me an error. What is it that makes the code hang with what I have, you said it was that it's prompting for a name for the file, so how do I bypass that and force it to create the file with the name I've provided? From python at lucidity.plus.com Sun Apr 3 15:46:01 2016 From: python at lucidity.plus.com (Erik) Date: Sun, 3 Apr 2016 20:46:01 +0100 Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: <32c7ba6b-b61d-45fb-89a8-dd62aa09fe78@googlegroups.com> References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> <32c7ba6b-b61d-45fb-89a8-dd62aa09fe78@googlegroups.com> Message-ID: <570172F9.8020904@lucidity.plus.com> Hi Loop.IO, On 03/04/16 15:41, Loop.IO wrote: >> If you don't want the user to enter anything, then I explained how >> before, just use: >> >> name='C:\\Documents\\PythonCoding\\launch2.bat' >> >> if that's the file name you need. >> >> -- >> Bartc > > Hi Bartc, i tried that, didn't work FYI, for the future. Telling someone what _didn't_ happen is generally not very useful to them if you expect them to try to help further. If you tell them what _did_ happen (be that an error message or a weird file created or a pain in your leg or whatever), then that is much more likely to be productive ;) If you would like someone to diagnose your illness, you must explain your symptoms ... E. From michael.selik at gmail.com Sun Apr 3 15:46:49 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sun, 03 Apr 2016 19:46:49 +0000 Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: <99671ed7-7a89-4116-917d-3c9151847237@googlegroups.com> References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> <32c7ba6b-b61d-45fb-89a8-dd62aa09fe78@googlegroups.com> <860f0703-08a1-4721-86c9-67ddc129cdc6@googlegroups.com> <99671ed7-7a89-4116-917d-3c9151847237@googlegroups.com> Message-ID: How do you know when you're done typing the name of the file? It's hard to get tone right on the internet, so I'll clarify: this is not a rhetorical question and I mean you, LoopIO, not a generic person. On Sun, Apr 3, 2016, 8:40 PM Loop.IO wrote: > On Sunday, April 3, 2016 at 8:32:06 PM UTC+1, Loop.IO wrote: > > On Sunday, April 3, 2016 at 4:11:49 PM UTC+1, BartC wrote: > > > On 03/04/2016 15:41, Loop.IO wrote: > > > > On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote: > > > >> On 02/04/2016 23:31, Loop.IO wrote: > > > >> > > > >>> Oh i see, so the code prompts for a name.. so i'm more lost than i > thought, what do I need to change to make it just create the file with the > chosen name Launch2.bat without the prompt? > > > >> > > > >> If you don't want the user to enter anything, then I explained how > > > >> before, just use: > > > >> > > > >> name='C:\\Documents\\PythonCoding\\launch2.bat' > > > >> > > > >> if that's the file name you need. > > > >> > > > >> -- > > > >> Bartc > > > > > > > > Hi Bartc, i tried that, didn't work > > > > > > You mean it gave an error when you tried to create that file? > > > > > > Does that path already exist on your machine? If not then trying to > > > create a file in a non-existent path won't work. > > > > > > You can create the path manually outside of Python. Or look up the docs > > > to find out how to do that. A quick google suggested using os.makedirs > > > (to create multiple nested paths at the same time). > > > > > > The following code worked on my machine: > > > > > > import sys > > > import os > > > > > > def create(): > > > print("creating new file") > > > > > > path="c:/Documents/PythonCoding/" > > > name=path+"launch2.bat" > > > > > > try: > > > os.stat(path) > > > except: > > > os.makedirs(path) > > > > > > print (name) > > > > > > try: > > > file=open(name,'w') > > > file.close() > > > except: > > > print("error occured") > > > sys.exit(0) > > > > > > create() > > > > > > -- > > > Bartc > > > > The issue is that it hangs, there is no error. its like it pauses until > i press enter, ill try what you've posted one moment > > Ok the Bartc code gives me an error. > > What is it that makes the code hang with what I have, you said it was that > it's prompting for a name for the file, so how do I bypass that and force > it to create the file with the name I've provided? > -- > https://mail.python.org/mailman/listinfo/python-list > From thisisink01 at gmail.com Sun Apr 3 15:52:38 2016 From: thisisink01 at gmail.com (Loop.IO) Date: Sun, 3 Apr 2016 12:52:38 -0700 (PDT) Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> Message-ID: On Sunday, April 3, 2016 at 1:38:48 AM UTC+1, Mark Lawrence wrote: > On 03/04/2016 01:12, BartC wrote: > > On 02/04/2016 23:31, Loop.IO wrote: > > > >> Oh i see, so the code prompts for a name.. so i'm more lost than i > >> thought, what do I need to change to make it just create the file with > >> the chosen name Launch2.bat without the prompt? > > > > If you don't want the user to enter anything, then I explained how > > before, just use: > > > > name='C:\\Documents\\PythonCoding\\launch2.bat' > > > > if that's the file name you need. > > > > name = r'C:\Documents\PythonCoding\launch2.bat' > > Alternatively you could just use a forward slash. > > I'm not sure which is the most efficient, I'll leave that to others to test. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence Hey Mark, Sorry i totally missed your input, and guess what, it solved it !!! Thanks man, it created the file and finished, what is different with r and raw_input From thisisink01 at gmail.com Sun Apr 3 15:54:16 2016 From: thisisink01 at gmail.com (Loop.IO) Date: Sun, 3 Apr 2016 12:54:16 -0700 (PDT) Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> <32c7ba6b-b61d-45fb-89a8-dd62aa09fe78@googlegroups.com> Message-ID: <686d7aab-4020-4840-a1b7-fce8e89c6633@googlegroups.com> On Sunday, April 3, 2016 at 8:49:28 PM UTC+1, Erik wrote: > Hi Loop.IO, > > On 03/04/16 15:41, Loop.IO wrote: > >> If you don't want the user to enter anything, then I explained how > >> before, just use: > >> > >> name='C:\\Documents\\PythonCoding\\launch2.bat' > >> > >> if that's the file name you need. > >> > >> -- > >> Bartc > > > > Hi Bartc, i tried that, didn't work > > FYI, for the future. > > Telling someone what _didn't_ happen is generally not very useful to > them if you expect them to try to help further. > > If you tell them what _did_ happen (be that an error message or a weird > file created or a pain in your leg or whatever), then that is much more > likely to be productive ;) > > If you would like someone to diagnose your illness, you must explain > your symptoms ... > > E. The original post said what did happen, the code runs and hangs on the create file, and once i press Enter it then finishes and creates the file, not sure how you missed that but thanks From nospam at dfs.com Sun Apr 3 16:08:42 2016 From: nospam at dfs.com (DFS) Date: Sun, 3 Apr 2016 16:08:42 -0400 Subject: Sorting a list In-Reply-To: References: Message-ID: On 4/3/2016 3:31 PM, Peter Otten wrote: > DFS wrote: > >> cntText = 60 >> cntBool = 20 >> cntNbrs = 30 >> cntDate = 20 >> cntBins = 20 >> >> strText = " text: " >> strBool = " boolean: " >> strNbrs = " numeric: " >> strDate = " date-time:" >> strBins = " binary: " >> >> colCounts = [(cntText,strText) , (cntBool,strBool), (cntNbrs,strNbrs) , >> (cntDate,strDate) , (cntBins,strBins)] >> >> # sort by alpha, then by column type count descending >> colCounts.sort(key=lambda x: x[1]) >> colCounts.sort(key=lambda x: x[0], reverse=True) >> for key in colCounts: print key[1], key[0]] >> >> ------------------------------------------------- >> >> Output (which is exactly what I want): >> >> text: 60 >> numeric: 30 >> binary: 20 >> boolean: 20 >> date-time: 20 >> >> ------------------------------------------------- >> >> >> But, is there a 1-line way to sort and print? > > Yes, but I would not recommend it. You can replace the sort() method > invocations with nested calls of sorted() and instead of > > for item in items: > print convert_to_str(item) > > use > > print "\n".join(convert_to_str(item) for item in items) > > Putting it together: > >>>> from operator import itemgetter as get >>>> print "\n".join("{1} {0}".format(*p) for p in sorted( > ... sorted(colCounts, key=get(1)), key=get(0), reverse=True)) Kind of clunky looking. Is that why don't you recommend it? > text: 60 > numeric: 30 > binary: 20 > boolean: 20 > date-time: 20 > > You could also cheat and use > > lambda v: (-v[0], v[1]) > > and a single sorted(). That works well. Why is it 'cheating'? Thanks for the reply. From python at lucidity.plus.com Sun Apr 3 16:10:51 2016 From: python at lucidity.plus.com (Erik) Date: Sun, 3 Apr 2016 21:10:51 +0100 Subject: i cant seem to figure out the error In-Reply-To: References: Message-ID: <570178CB.8060402@lucidity.plus.com> Hi Anthony, On 03/04/16 16:06, anthony uwaifo wrote: > please i need help with this assignment. I have written a code and i still > get an error. please help me debug my code. We see this assignment come up a lot. The "tutor" list is a better place to go, but well done for at least attempting it and coming up with quite a good result. > - Create a method called `withdraw` that takes in cash withdrawal amount > and updates the balance accordingly. if amount is greater than balance > return `"invalid transaction"` Read this carefully. Read it _literally_. What does your 'withdraw' method return? E. From python at lucidity.plus.com Sun Apr 3 16:15:00 2016 From: python at lucidity.plus.com (Erik) Date: Sun, 3 Apr 2016 21:15:00 +0100 Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: <686d7aab-4020-4840-a1b7-fce8e89c6633@googlegroups.com> References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> <32c7ba6b-b61d-45fb-89a8-dd62aa09fe78@googlegroups.com> <686d7aab-4020-4840-a1b7-fce8e89c6633@googlegroups.com> Message-ID: <570179C4.4000706@lucidity.plus.com> On 03/04/16 20:54, Loop.IO wrote: > The original post said what did happen, the code runs and hangs on > the create file, and once i press Enter it then finishes and creates > the file, not sure how you missed that but thanks Yes, I read your original post. That was days ago. The comment I was replying to was you telling BartC that what he had suggested "didn't work" (with no further information). Please pay attention to the context of the email you are responding to. E. From bc at freeuk.com Sun Apr 3 16:21:30 2016 From: bc at freeuk.com (BartC) Date: Sun, 3 Apr 2016 21:21:30 +0100 Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: <99671ed7-7a89-4116-917d-3c9151847237@googlegroups.com> References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> <32c7ba6b-b61d-45fb-89a8-dd62aa09fe78@googlegroups.com> <860f0703-08a1-4721-86c9-67ddc129cdc6@googlegroups.com> <99671ed7-7a89-4116-917d-3c9151847237@googlegroups.com> Message-ID: On 03/04/2016 20:36, Loop.IO wrote: > On Sunday, April 3, 2016 at 8:32:06 PM UTC+1, Loop.IO wrote: >> The issue is that it hangs, there is no error. its like it pauses until i press enter, ill try what you've posted one momen > Ok the Bartc code gives me an error. This is confusing! I know you said you fixed the problem now, but if it was waiting for the user to press enter, then you still had a raw_input or input() call in your code. You need to get rid of that raw_input(). That was explained early on in the thread but perhaps you didn't grasp that you had to use: name = '....' in place of: name = raw_input(....) and not as well as! (And the 'r' in name = r'....' isn't a different version of raw_input(), it's just a way of entering strings without having to type \\ when you need \.) -- Bartc From thisisink01 at gmail.com Sun Apr 3 16:25:04 2016 From: thisisink01 at gmail.com (Loop.IO) Date: Sun, 3 Apr 2016 13:25:04 -0700 (PDT) Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> <32c7ba6b-b61d-45fb-89a8-dd62aa09fe78@googlegroups.com> <686d7aab-4020-4840-a1b7-fce8e89c6633@googlegroups.com> Message-ID: <6d022206-5f4d-4ac9-be50-76ce74ef48c0@googlegroups.com> On Sunday, April 3, 2016 at 9:15:22 PM UTC+1, Erik wrote: > On 03/04/16 20:54, Loop.IO wrote: > > The original post said what did happen, the code runs and hangs on > > the create file, and once i press Enter it then finishes and creates > > the file, not sure how you missed that but thanks > > Yes, I read your original post. That was days ago. > > The comment I was replying to was you telling BartC that what he had > suggested "didn't work" (with no further information). > > Please pay attention to the context of the email you are responding to. > > E. Erik It was a syntax error. But sure, thanks. The problem has been rectified, I used the r as suggested by Mark. I've now been able to get the file created and write the code in the file, thanks for everyones replies. From vincent.vande.vyvre at telenet.be Sun Apr 3 16:32:15 2016 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Sun, 3 Apr 2016 22:32:15 +0200 Subject: PyQt4 In-Reply-To: References: Message-ID: <57017DCF.2080507@telenet.be> Le 03/04/2016 21:36, Muhammad Ali a ?crit : > On Sunday, April 3, 2016 at 12:15:06 PM UTC-7, Michael Torrie wrote: >> On 04/03/2016 12:57 PM, Muhammad Ali wrote: >>> Hi, >>> >>> How can we confirm that either PyQt4 is already installed on LInux machine or not? >>> >>> Please suggest commands to confirm the already existence of PyQt4 in the machine. >> Ideally you make a distribution-specific package of the binary in a .deb >> on Debian or an RPM on other distros, and specify that it depends on the >> package that provides PyQt4. That way when it's installed, modern >> package managers will automatically install the dependencies. >> >> Alternatively you can use try and except in your python code to attempt >> to import something from PyQt4 and see if it fails or not. This >> technique is also used to make your code work either PyQt4 or PySide, >> depending on which the user has installed. >> >> try: >> from PySide import QtGui >> except ImportError: >> from PyQt4 import QtGui >> >> If neither are installed, this little example will end with an ImportError. > Thank you for your suggestions. I tried both but it shows the following error: > IndentationError: expected an indented block > > Actually, I have to plot some graphs by using matplotlib and PyQt4 at supercomputer. > > Any other suggestion??? There's no IndentationError in the exemple provided by Michael. Copy the code AS IT in a file and retry. Vincent From michael.selik at gmail.com Sun Apr 3 17:04:20 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sun, 03 Apr 2016 21:04:20 +0000 Subject: Plot/Graph In-Reply-To: <768f1e2e-baab-4ce3-ae4e-aab2d8ac5bf8@googlegroups.com> References: <768f1e2e-baab-4ce3-ae4e-aab2d8ac5bf8@googlegroups.com> Message-ID: Indeed there is. Every example in the gallery shows the code to produce it. http://matplotlib.org/gallery.html On Sun, Apr 3, 2016, 8:05 PM Muhammad Ali wrote: > > Hi, > > Could anybody tell me that how can I plot graphs by matplotlib and get > expertise in a short time? I have to plot 2D plots just like origin > software. > > Secondly, how could we draw some horizontal reference line at zero when > the vertical scale is from -3 to 3? > > Looking for your posts, please. > > Thank you. > > p.s: Is there any short and to the point text book/manual/pdf to learn 2D > plotting with matplotlib? > -- > https://mail.python.org/mailman/listinfo/python-list > From thisisink01 at gmail.com Sun Apr 3 17:07:34 2016 From: thisisink01 at gmail.com (Loop.IO) Date: Sun, 3 Apr 2016 14:07:34 -0700 (PDT) Subject: [Beginner] - Hanging in the code, can't figure out what's wrong In-Reply-To: References: <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> <32c7ba6b-b61d-45fb-89a8-dd62aa09fe78@googlegroups.com> <860f0703-08a1-4721-86c9-67ddc129cdc6@googlegroups.com> <99671ed7-7a89-4116-917d-3c9151847237@googlegroups.com> Message-ID: On Sunday, April 3, 2016 at 9:21:44 PM UTC+1, BartC wrote: > On 03/04/2016 20:36, Loop.IO wrote: > > On Sunday, April 3, 2016 at 8:32:06 PM UTC+1, Loop.IO wrote: > > >> The issue is that it hangs, there is no error. its like it pauses until i press enter, ill try what you've posted one momen > > > > Ok the Bartc code gives me an error. > > This is confusing! I know you said you fixed the problem now, but if it > was waiting for the user to press enter, then you still had a raw_input > or input() call in your code. > > You need to get rid of that raw_input(). That was explained early on in > the thread but perhaps you didn't grasp that you had to use: > > name = '....' > > in place of: > > name = raw_input(....) > > and not as well as! > > (And the 'r' in name = r'....' isn't a different version of raw_input(), > it's just a way of entering strings without having to type \\ when you > need \.) > > -- > Bartc Hey Bartc I'm sorry about getting you confused, I did try that, but it didn't work, maybe it was me, but now I've tried it again it does work. I've now managed to get the file to be created and write to the file so its all working fine. The only question left is when I've conducted a search through all the drives for a browser .exe file, how do I take the search results and put them in to a text file, but I guess that's for another thread. From jon+usenet at unequivocal.co.uk Sun Apr 3 17:12:05 2016 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Sun, 3 Apr 2016 21:12:05 -0000 (UTC) Subject: Untrusted code execution Message-ID: I'd just like to say up front that this is more of a thought experiment than anything else, I don't have any plans to use this idea on any genuinely untrusted code. Apart from anything else, there's the denial-of-service issue. That said, is there any way that the following Python 3.4 code could result in a arbitrary code execution security hole? tree = compile(untrusted_code, "
but i am afraid the problem lies in urls.py (i do not know what to do) http://127.0.0.1:8000/static/css/file_name (in the firebug network) but i can not open it directly via server. urls.py urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^hello/','category.views.hello'), ] Any kind of help would be convenient to me? Kind Regards Kostas Asimakopoulos From srirajarajeswaridevikrupa at gmail.com Fri Apr 15 08:13:03 2016 From: srirajarajeswaridevikrupa at gmail.com (durgadevi1) Date: Fri, 15 Apr 2016 05:13:03 -0700 (PDT) Subject: How to print a part of a string? Message-ID: Hello all, I have another homework problem. I have a textfile. It contains lines of string. I am required to only print out a certain part of the string. For example the textfile contain: ABC XXXXX NNNNN BCD QQQQQ EEEEE ABC WWWWW AAAAA I need to print all the parts that come after only ABC. That means I need to print only XXXXX from the first line and WWWWW from the second line. I'm not sure of what code to use to achieve that. From joel.goldstick at gmail.com Fri Apr 15 08:28:38 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 15 Apr 2016 08:28:38 -0400 Subject: How to print a part of a string? In-Reply-To: References: Message-ID: On Fri, Apr 15, 2016 at 8:13 AM, durgadevi1 wrote: > Hello all, > > I have another homework problem. > > I have a textfile. It contains lines of string. > > I am required to only print out a certain part of the string. > > For example the textfile contain: > > ABC XXXXX NNNNN > BCD QQQQQ EEEEE > ABC WWWWW AAAAA > > > I need to print all the parts that come after only ABC. > > That means I need to print only XXXXX from the first line and WWWWW from the second line. > > I'm not sure of what code to use to achieve that. > -- > https://mail.python.org/mailman/listinfo/python-list do you know how to open the file and do a for loop to get each line in the string? If you do, do you know about this: >>> s = "ABC XXXXX NNNNN" >>> s_split = s.split() >>> s_split ['ABC', 'XXXXX', 'NNNNN'] >>> s_split[0] 'ABC' >>> -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From Joaquin.Alzola at lebara.com Fri Apr 15 08:40:06 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Fri, 15 Apr 2016 12:40:06 +0000 Subject: How to print a part of a string? In-Reply-To: References: Message-ID: list_append = [] with open('filename') as f: for line in f: t_line = line.split(' ') if (t_line[0] == 'ABC'): print(t_line[1]) list_append.append(t_line[1]) -----Original Message----- From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com at python.org] On Behalf Of durgadevi1 Sent: 15 April 2016 13:13 To: python-list at python.org Subject: How to print a part of a string? Hello all, I have another homework problem. I have a textfile. It contains lines of string. I am required to only print out a certain part of the string. For example the textfile contain: ABC XXXXX NNNNN BCD QQQQQ EEEEE ABC WWWWW AAAAA I need to print all the parts that come after only ABC. That means I need to print only XXXXX from the first line and WWWWW from the second line. I'm not sure of what code to use to achieve that. -- https://mail.python.org/mailman/listinfo/python-list This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. From antoon.pardon at rece.vub.ac.be Fri Apr 15 08:48:11 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 15 Apr 2016 14:48:11 +0200 Subject: How to parameterize unittests In-Reply-To: <5710D3DA.6030005@rece.vub.ac.be> References: <570FA466.20003@rece.vub.ac.be> <570fb1a3$0$1609$c3e8da3$5496439d@news.astraweb.com> <57108FAC.3020105@rece.vub.ac.be> <5710A442.8000906@rece.vub.ac.be> <5710affd$0$22140$c3e8da3$5496439d@news.astraweb.com> <5710D3DA.6030005@rece.vub.ac.be> Message-ID: <5710E30B.6050304@rece.vub.ac.be> Op 15-04-16 om 13:43 schreef Antoon Pardon: > Op 15-04-16 om 11:10 schreef Steven D'Aprano: >> If you have code which is not parameterized, and you want to parameterize >> it, you have to refactor. Unit tests are no different from anything else. > I don't agree with that. If I have a piece of code that I want to parameterize, > Often enough all I need to do is shift the code to the right. Prepend a def > line and use a parameter with the same name as the more global variable I > was using before. I don't need to change access to the variable in the code. Some prelimary tests seems to suggest this idea might work here too. Starting from this: class Test_AVLTree(unittest.TestCase): def test_empty_tree_is_false(self): instance = avltree() self.assertFalse(instance) Changing it into this: def MakeAVLTest(avltree): class Test_AVLTree(unittest.TestCase): def test_empty_tree_is_false(self): instance = avltree() self.assertFalse(instance) return Test_AVLTree AVLTest = MakeAVLTest(avltree) MyTreeTest = MakeAVLTest(mytree) Seems to work From oscar.j.benjamin at gmail.com Fri Apr 15 09:02:30 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 15 Apr 2016 14:02:30 +0100 Subject: Python garbage collection: not releasing memory to OS! In-Reply-To: <215cf2a4-c2fa-41d0-8c49-23b9494234d4@googlegroups.com> References: <215cf2a4-c2fa-41d0-8c49-23b9494234d4@googlegroups.com> Message-ID: On 15 April 2016 at 11:25, wrote: > The input was a 4MB file. Even after returning from the 'fileopen' function the 4MB memory was not released. I checked htop output while the loop was running, the resident memory stays at 14MB. So unless the process is stopped the memory stays with it. When exactly memory gets freed to the OS is unclear but it's possible that your process can reuse the same bits of memory. The real question is whether continuously allocating and deallocating leads to steadily growing memory usage. If you change it so that your code calls fun inside the loop you will see that repeatedly calling fun does not lead to growing memory usage. > So if the celery worker is not killed after its task is finished it is going to keep the memory for itself. I know I can use **max_tasks_per_child** config value to kill the process and spawn a new one. **Is there any other way to return the memory to OS from a python process?.** I don't really understand what you're asking here. You're running celery in a subprocess right? Is the problem about the memory used by subprocesses that aren't killed or is it the memory usage of the Python process? -- Oscar From oscar.j.benjamin at gmail.com Fri Apr 15 09:49:19 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 15 Apr 2016 14:49:19 +0100 Subject: sum accuracy In-Reply-To: <87d1prw5b7.fsf@bsb.me.uk> References: <570E78F9.8050409@chamonix.reportlab.co.uk> <1460567110.3933817.577783969.165F6097@webmail.messagingengine.com> <5710B365.5040903@chamonix.reportlab.co.uk> <87d1prw5b7.fsf@bsb.me.uk> Message-ID: On 15 April 2016 at 11:10, Ben Bacarisse wrote: > Oscar Benjamin writes: > >> On 15 April 2016 at 10:24, Robin Becker wrote: > >>> yes indeed summation is hard :( >> >> Not with Fraction it isn't: >> >> from fractions import Fraction >> >> def exact_sum(nums): >> return sum(map(Fraction, nums)) >> >> This will give you the exact result with precisely zero rounding >> error. You can convert it to float at the end. > > Just a word of warning for people new to numerical work: there's no > rounding error, but unless you start with Fraction objects you still > have input or conversion errors. There are no conversion errors in the Fraction constructor. This will exactly sum any combination of int/float/Fraction/Decimal without errors. (It will raise ValueError on nan/inf but I consider that a good thing). > The uninitiated might expect > > exact_sum([0.3, 0.7]) > > to be 1. That's true but I wanted to correct the impression (from above) that *converting* to Fraction is a source of rounding error. It is your responsibility to give exact_sum the exact numbers that you want to add. You can even use strings if you want to write numbers in decimal: exact_sum(['0.3', '0.7']) -- Oscar From torriem at gmail.com Fri Apr 15 09:59:47 2016 From: torriem at gmail.com (Michael Torrie) Date: Fri, 15 Apr 2016 07:59:47 -0600 Subject: Python garbage collection: not releasing memory to OS! In-Reply-To: <215cf2a4-c2fa-41d0-8c49-23b9494234d4@googlegroups.com> References: <215cf2a4-c2fa-41d0-8c49-23b9494234d4@googlegroups.com> Message-ID: <5710F3D3.7010603@gmail.com> On 04/15/2016 04:25 AM, cshintov at gmail.com wrote: > The input was a 4MB file. Even after returning from the 'fileopen' > function the 4MB memory was not released. I checked htop output while > the loop was running, the resident memory stays at 14MB. So unless > the process is stopped the memory stays with it. I guess the question is, why is this a problem? If there are no leaks, then I confess I don't understand what your concern is. And indeed you say it's not leaking as it never rises above 14 MB. Also there are ways of reading a file without allocating huge amounts of memory. Why not read it in in chunks, or in lines. Take advantage of Python's generator facilities to process your data. > So if the celery worker is not killed after its task is finished it > is going to keep the memory for itself. I know I can use > **max_tasks_per_child** config value to kill the process and spawn a > new one. **Is there any other way to return the memory to OS from a > python process?.** Have you tried using the subprocess module of python? If I understand it correctly, this would allow you to run python code as a subprocess (completely separate process), which would be completely reaped by the OS when it's finished. From D.Strohl at F5.com Fri Apr 15 10:27:38 2016 From: D.Strohl at F5.com (Dan Strohl) Date: Fri, 15 Apr 2016 14:27:38 +0000 Subject: How to print a part of a string? In-Reply-To: References: Message-ID: As with lots of things in python, there are lots of ways of approaching this, here are some hints for you to think about (in no particular order): - REGEX - replace() - string[:y] - split() And of course, you could consider creating a table with every possible string that could start with "ABC", and it's matching non-"ABC" string, then lookup the string in the table and get your match, it's a bit brute forcey, but it would work (eventually) Good luck in your homework! Dan > -----Original Message----- > From: Python-list [mailto:python-list-bounces+d.strohl=f5.com at python.org] > On Behalf Of durgadevi1 > Sent: Friday, April 15, 2016 5:13 AM > To: python-list at python.org > Subject: How to print a part of a string? > > Hello all, > > I have another homework problem. > > I have a textfile. It contains lines of string. > > I am required to only print out a certain part of the string. > > For example the textfile contain: > > ABC XXXXX NNNNN > BCD QQQQQ EEEEE > ABC WWWWW AAAAA > > > I need to print all the parts that come after only ABC. > > That means I need to print only XXXXX from the first line and WWWWW from > the second line. > > I'm not sure of what code to use to achieve that. > -- > https://mail.python.org/mailman/listinfo/python-list From python at net153.net Fri Apr 15 10:27:44 2016 From: python at net153.net (Sam) Date: Fri, 15 Apr 2016 09:27:44 -0500 Subject: Python garbage collection: not releasing memory to OS! In-Reply-To: <215cf2a4-c2fa-41d0-8c49-23b9494234d4@googlegroups.com> References: <215cf2a4-c2fa-41d0-8c49-23b9494234d4@googlegroups.com> Message-ID: <5710FA60.4070704@net153.net> On 04/15/2016 05:25 AM, cshintov at gmail.com wrote: > I have written an application with flask and uses celery for a long running task. While load testing I noticed that the celery tasks are not releasing memory even after completing the task. So I googled and found this group discussion.. > > https://groups.google.com/forum/#!topic/celery-users/jVc3I3kPtlw > > In that discussion it says, thats how python works. > > Also the article at https://hbfs.wordpress.com/2013/01/08/python-memory-management-part-ii/ says > > "But from the OS's perspective, your program's size is the total (maximum) memory allocated to Python. Since Python returns memory to the OS on the heap (that allocates other objects than small objects) only on Windows, if you run on Linux, you can only see the total memory used by your program increase." > > And I use Linux. So I wrote the below script to verify it. > > import gc > def memory_usage_psutil(): > # return the memory usage in MB > import resource > print 'Memory usage: %s (MB)' % (resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1000.0) > > def fileopen(fname): > memory_usage_psutil()# 10 MB > f = open(fname) > memory_usage_psutil()# 10 MB > content = f.read() > memory_usage_psutil()# 14 MB > > def fun(fname): > memory_usage_psutil() # 10 MB > fileopen(fname) > gc.collect() > memory_usage_psutil() # 14 MB > > import sys > from time import sleep > if __name__ == '__main__': > fun(sys.argv[1]) > for _ in range(60): > gc.collect() > memory_usage_psutil()#14 MB ... > sleep(1) > > The input was a 4MB file. Even after returning from the 'fileopen' function the 4MB memory was not released. I checked htop output while the loop was running, the resident memory stays at 14MB. So unless the process is stopped the memory stays with it. > > So if the celery worker is not killed after its task is finished it is going to keep the memory for itself. I know I can use **max_tasks_per_child** config value to kill the process and spawn a new one. **Is there any other way to return the memory to OS from a python process?.** > With situations like this, I normally just fork and do the mem intensive work in the child and then kill it off when done. Might be able to use a thread instead of a fork. But not sure how well all that would work with celery. --Sam From wrh8609 at gmail.com Fri Apr 15 10:37:55 2016 From: wrh8609 at gmail.com (wrh8609 at gmail.com) Date: Fri, 15 Apr 2016 07:37:55 -0700 (PDT) Subject: help install numpy and scipy in window 7 and 3.5.0 shell Message-ID: Hi all, I have downloaded the numpy-1.11.01 and scipy-0.17.0 but after running setup files over IDLE in numpy and scipy, it still can not get through. Can someone give me a hand? or you can provide the installation instruction for both. Thanks, Wen-Ruey From bgailer at gmail.com Fri Apr 15 10:56:05 2016 From: bgailer at gmail.com (Bob Gailer) Date: Fri, 15 Apr 2016 10:56:05 -0400 Subject: help install numpy and scipy in window 7 and 3.5.0 shell In-Reply-To: References: Message-ID: On Apr 15, 2016 10:40 AM, wrote: > > Hi all, > > I have downloaded the numpy-1.11.01 and scipy-0.17.0 but after running setup files over IDLE in numpy and scipy, it still can not get through. Can someone give me a hand? or you can provide the installation instruction for both. Can you be more specific? "Can not get through" is not very informative. What opeting system are you using? What version of python? What messages or symptoms do you get? The more you help us the easier it is for us to help you. We do welcome your questions thank you From walters.justin01 at gmail.com Fri Apr 15 11:24:29 2016 From: walters.justin01 at gmail.com (justin walters) Date: Fri, 15 Apr 2016 08:24:29 -0700 Subject: Static files load problem Django 1.9 In-Reply-To: References: Message-ID: On Fri, Apr 15, 2016 at 5:13 AM, asimkon . wrote: > I have got a problem with static files regarding Django 1.9. These files > are (js,css) in the standard folder static, inside project folder > directory. I got an error Http 404 that can not be loaded. > > Project folder / static / css / several files *.css > /static / js / several files *.js > several_apps > > i have executed the python manage.py collectstatic > > settings.py > > STATIC_URL = '/static/' > > STATIC_ROOT = os.path.join(BASE_DIR, "static") > > STATICFILES_DIRS = ( > > os.path.join(BASE_DIR, 'static'), > ) > > and of course as INSTALLED_APPS > > 'django.contrib.staticfiles', > > Sorry for my template (at the beginning of my work): > > {% load staticfiles %} > > > > > > > > > > > > >
>
> > > > > but i am afraid the problem lies in urls.py (i do not know what to do) > > http://127.0.0.1:8000/static/css/file_name (in the firebug network) but > i > can not open it directly via server. > > urls.py > > urlpatterns = [ > url(r'^admin/', admin.site.urls), > url(r'^hello/','category.views.hello'), > ] > > > Any kind of help would be convenient to me? > > Kind Regards > Kostas Asimakopoulos > -- > https://mail.python.org/mailman/listinfo/python-list > You shouldn't need a special pattern in your urls for static files. I think your issue lies with your STATIC_ROOT setting. It is the same as your STATICFILES_DIRS setting. Try changing the STATIC_ROOT setting to: STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static') This will put the static root outside of your project folder. This may solve your problem, and will make it easier to host static files somewhere else on your server or in a CDN if need be. From wrh8609 at gmail.com Fri Apr 15 12:29:24 2016 From: wrh8609 at gmail.com (wrh8609 at gmail.com) Date: Fri, 15 Apr 2016 09:29:24 -0700 (PDT) Subject: help install numpy and scipy in window 7 and 3.5.0 shell In-Reply-To: References: Message-ID: <7daec141-40c0-4a7c-953e-7e0628d74654@googlegroups.com> On Friday, April 15, 2016 at 10:56:28 AM UTC-4, Bob Gailer wrote: > On Apr 15, 2016 10:40 AM, wrote: > > > > Hi all, > > > > I have downloaded the numpy-1.11.01 and scipy-0.17.0 but after running > setup files over IDLE in numpy and scipy, it still can not get through. Can > someone give me a hand? or you can provide the installation instruction for > both. > > Can you be more specific? "Can not get through" is not very informative. > What opeting system are you using? What version of python? What messages or > symptoms do you get? The more you help us the easier it is for us to help > you. We do welcome your questions thank you Hi Bob, First I would like to have your input of installation instruction for numpy and scipy. I don't know what I did to run the setup.py is correct. The operating system is on window 7 and the version of python is 3.5.0. By the way, after I ran the setup.py of numpy over IDLE, it shows "Running from numpy source directory." and I can import numpy. But after I ran setup.py of scipy over IDLE, it shows =============== RESTART: C:\PythonFiles\scipy-0.17.0\setup.py =============== Traceback (most recent call last): File "C:\PythonFiles\scipy-0.17.0\setup.py", line 265, in setup_package() File "C:\PythonFiles\scipy-0.17.0\setup.py", line 253, in setup_package from numpy.distutils.core import setup ImportError: No module named 'numpy' If you have further suggestion, please let me know. Thanks, Wen-Ruey From steve at pearwood.info Fri Apr 15 12:47:05 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 16 Apr 2016 02:47:05 +1000 Subject: How to parameterize unittests References: <570FA466.20003@rece.vub.ac.be> <570fb1a3$0$1609$c3e8da3$5496439d@news.astraweb.com> <57108FAC.3020105@rece.vub.ac.be> <5710A442.8000906@rece.vub.ac.be> <5710affd$0$22140$c3e8da3$5496439d@news.astraweb.com> <5710D3DA.6030005@rece.vub.ac.be> <5710E30B.6050304@rece.vub.ac.be> Message-ID: <57111b0b$0$1606$c3e8da3$5496439d@news.astraweb.com> On Fri, 15 Apr 2016 10:48 pm, Antoon Pardon wrote: > Starting from this: > > class Test_AVLTree(unittest.TestCase): > > def test_empty_tree_is_false(self): > instance = avltree() > self.assertFalse(instance) > > Changing it into this: > > def MakeAVLTest(avltree): > class Test_AVLTree(unittest.TestCase): > > def test_empty_tree_is_false(self): > instance = avltree() > self.assertFalse(instance) > > return Test_AVLTree > > AVLTest = MakeAVLTest(avltree) > MyTreeTest = MakeAVLTest(mytree) > > Seems to work Right up to the moment that you realise that you need different tests for a subclass, and now you can't using subclassing because they aren't subclasses, they're completely independent classes that happen to duplicate the same methods. If the tests for your AVL tree and it's subclasses are *identical*, then what's the point of the subclasses? -- Steven From ben.usenet at bsb.me.uk Fri Apr 15 12:54:44 2016 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Fri, 15 Apr 2016 17:54:44 +0100 Subject: sum accuracy References: <570E78F9.8050409@chamonix.reportlab.co.uk> <1460567110.3933817.577783969.165F6097@webmail.messagingengine.com> <5710B365.5040903@chamonix.reportlab.co.uk> <87d1prw5b7.fsf@bsb.me.uk> Message-ID: <87vb3iu817.fsf@bsb.me.uk> Oscar Benjamin writes: > On 15 April 2016 at 11:10, Ben Bacarisse wrote: >> Oscar Benjamin writes: >> >>> On 15 April 2016 at 10:24, Robin Becker wrote: >> >>>> yes indeed summation is hard :( >>> >>> Not with Fraction it isn't: >>> >>> from fractions import Fraction >>> >>> def exact_sum(nums): >>> return sum(map(Fraction, nums)) >>> >>> This will give you the exact result with precisely zero rounding >>> error. You can convert it to float at the end. >> >> Just a word of warning for people new to numerical work: there's no >> rounding error, but unless you start with Fraction objects you still >> have input or conversion errors. > > There are no conversion errors in the Fraction constructor. This will > exactly sum any combination of int/float/Fraction/Decimal without > errors. (It will raise ValueError on nan/inf but I consider that a > good thing). Yes, that's a good point. Starting with Fraction objects is just one way to know exactly what you are exactly summing. >> The uninitiated might expect >> >> exact_sum([0.3, 0.7]) >> >> to be 1. > > That's true but I wanted to correct the impression (from above) that > *converting* to Fraction is a source of rounding error. It is your > responsibility to give exact_sum the exact numbers that you want to > add. The bad phrase "input or conversion errors" was intended to refer to the conversion Python does when you write 0.3 in the source or when you read your data and convert it to floating-point. It can certainly be read as if I was talking about the constructor but, as you say, *that* conversion is exact. -- Ben. From m at funkyhat.org Fri Apr 15 13:04:14 2016 From: m at funkyhat.org (Matt Wheeler) Date: Fri, 15 Apr 2016 18:04:14 +0100 Subject: sum accuracy In-Reply-To: <87d1prw5b7.fsf@bsb.me.uk> References: <570E78F9.8050409@chamonix.reportlab.co.uk> <1460567110.3933817.577783969.165F6097@webmail.messagingengine.com> <5710B365.5040903@chamonix.reportlab.co.uk> <87d1prw5b7.fsf@bsb.me.uk> Message-ID: So we could build on this On 15 April 2016 at 11:10, Ben Bacarisse wrote: >> from fractions import Fraction >> >> def exact_sum(nums): >> return sum(map(Fraction, nums)) >> >> This will give you the exact result with precisely zero rounding >> error. You can convert it to float at the end. > > Just a word of warning for people new to numerical work: there's no > rounding error, but unless you start with Fraction objects you still > have input or conversion errors. The uninitiated might expect > > exact_sum([0.3, 0.7]) > > to be 1. and make def not_exact_but_probably_the_sum_you_wanted(nums): return sum(map(lambda x:Fraction(x).limit_denominator(), nums)) -- Matt Wheeler http://funkyh.at From rosuav at gmail.com Fri Apr 15 13:51:17 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Apr 2016 03:51:17 +1000 Subject: How to parameterize unittests In-Reply-To: <57111b0b$0$1606$c3e8da3$5496439d@news.astraweb.com> References: <570FA466.20003@rece.vub.ac.be> <570fb1a3$0$1609$c3e8da3$5496439d@news.astraweb.com> <57108FAC.3020105@rece.vub.ac.be> <5710A442.8000906@rece.vub.ac.be> <5710affd$0$22140$c3e8da3$5496439d@news.astraweb.com> <5710D3DA.6030005@rece.vub.ac.be> <5710E30B.6050304@rece.vub.ac.be> <57111b0b$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 16, 2016 at 2:47 AM, Steven D'Aprano wrote: > If the tests for your AVL tree and it's subclasses are *identical*, then > what's the point of the subclasses? If the tree classes all have the same API but different performance trade-offs, it would make sense to use all the same tests to make sure their behaviours are correct. But if your module's purpose is to offer a variety of tree classes, its tests should be designed around parameterization. Refactoring the code would be the correct behaviour. ChrisA From sohcahtoa82 at gmail.com Fri Apr 15 13:52:20 2016 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Fri, 15 Apr 2016 10:52:20 -0700 (PDT) Subject: Looking for feedback on weighted voting algorithm In-Reply-To: References: Message-ID: <3567e3a1-6a55-4471-ad70-dc23e9ad05f4@googlegroups.com> On Thursday, April 14, 2016 at 1:48:40 PM UTC-7, Michael Selik wrote: > On Thu, Apr 14, 2016, 7:37 PM justin walters > wrote: > > > On Apr 14, 2016 9:41 AM, "Martin A. Brown" wrote: > > > > > > > > > Greetings Justin, > > > > > > > score = sum_of_votes/num_of_votes > > > > > > >votes = [(72, 4), (96, 3), (48, 2), (53, 1), (26, 4), (31, 3), (68, 2), > > (91, 1)] > > > > > > >Specifically, I'm wondering if this is a good algorithm for > > > >weighted voting. Essentially a vote is weighted by the number of > > > >votes it counts as. I realize that this is an extremely simple > > > >algorithm, but I was wondering if anyone had suggestions on how to > > > >improve it. > > > > > > I snipped most of your code. I don't see anything wrong with your > > > overall approach. I will make one suggestion: watch out for > > > DivisionByZero. > > > > > > try: > > > score = sum_of_votes / num_of_votes > > > except ZeroDivisionError: > > > score = float('nan') > > > > > > In your example data, all of the weights were integers, which means > > > that a simple mean function would work, as well, if you expanded the > > > votes to an alternate representation: > > > > > > votes = [72, 72, 72, 72, 96, 96, 96, 48, 48, 53, 26, 26, 26, 26, > > > 31, 31, 31, 68, 68, 91] > > > > > > But, don't bother! > > > > > > Your function can handle votes that have a float weight: > > > > > > >>> weight([(4, 1.3), (1, 1),]) > > > 2.695652173913044 > > > > > > Have fun! > > > > > > -Martin > > > > > > -- > > > Martin A. Brown > > > http://linux-ip.net/ > > > > Thanks Martin! > > > > I'll add the check for division by zero. Didn't think about that. I think > > I'm going to sanitize input anyways, but always better to be safe than > > sorry. > > > > I suggest not worrying about sanitizing inputs. If someone provides bad > data, Python will do the right thing: stop the program and print an > explanation of what went wrong, often a more helpful message than one you'd > write. Use error handling mostly for when you want to do something *other* > than stop the program. > > I'm not sure I'd use NaN instead of raise division by zero error. NaNs can > be troublesome for downstream code that might not notice until it gets > confusing. A div-by-zero error is clear and easier to track down because of > the traceback. > > What do you think of using list comprehensions? > > weighted_sum = sum(rating * weight for rating, weight in votes) > total_weights = sum(weight for rating, weight in votes) > score = weighted_sum / total_weights > > It's two loops as I wrote it, which is instinctively slower, but it might > actually execute faster because of the built-in sum vs a regular for loop. > Not sure. > > > I disagree with your notion of not sanitizing inputs. If I'm the only person that will be using my program, then sure, I won't sanitize inputs. It was my mistake and I should read the traceback and know what I did wrong. But if ANY third party is going to be using it, especially as part of a web service of some kind, I'd much rather sanitize the inputs and tell the user they did something bad than to have the script crash and give a 500 Internal Server Error to the user. Even worse, I definitely wouldn't want to give any hints of the source code organization by letting the user see the traceback. I'll log it privately so I can view it myself, of course. From sergio.am.spina at gmail.com Fri Apr 15 13:56:44 2016 From: sergio.am.spina at gmail.com (Sergio Spina) Date: Fri, 15 Apr 2016 10:56:44 -0700 (PDT) Subject: python3 - No module named 'html5lib' In-Reply-To: References: Message-ID: <223d0e55-08cc-4502-8c54-19532c9e72ee@googlegroups.com> Il giorno gioved? 14 aprile 2016 17:54:00 UTC+2, Wildman ha scritto: > On Thu, 14 Apr 2016 02:31:59 -0700, Sergio Spina wrote: > > > I'm running a python3 program that requires html5lib but I receive the error No module named 'html5lib'. > > > > Here are two session of terminal: > > > > sam at pc ~ $ python > > Python 2.7.9 (default, Mar 1 2015, 12:57:24) > > [GCC 4.9.2] on linux2 > > >>> import html5lib > > >>> html5lib.__file__ > > '/usr/local/lib/python2.7/dist-packages/html5lib/__init__.pyc' > > >>> quit() > > > > sam at pc ~ $ python3 > > Python 3.4.2 (default, Oct 8 2014, 10:45:20) > > [GCC 4.9.1] on linux > > >>> import html5lib > > Traceback (most recent call last): > > File "", line 1, in > > ImportError: No module named 'html5lib' > > > > Where can be the problem? > > apt-get install python3-html5lib > > -- > GNU/Linux user #557453 > The cow died so I don't need your bull! It works, many thanks. From pierre.quentel at gmail.com Fri Apr 15 15:03:46 2016 From: pierre.quentel at gmail.com (Pierre Quentel) Date: Fri, 15 Apr 2016 12:03:46 -0700 (PDT) Subject: how to setup for localhost:8000 In-Reply-To: <2e597a56-00ab-4370-b337-667f34eac56a@googlegroups.com> References: <5ea1e31b-09ba-4b6a-be8b-58886c5c5f81@googlegroups.com> <2e597a56-00ab-4370-b337-667f34eac56a@googlegroups.com> Message-ID: Le jeudi 14 avril 2016 22:50:33 UTC+2, wrh... at gmail.com a ?crit?: > On Thursday, April 14, 2016 at 2:23:36 PM UTC-4, Andrew Farrell wrote: > > What happens when you type > > > > http://localhost:8000 > > > > Into the address bar of your browser as this is running? > > > > On Thu, Apr 14, 2016 at 12:46 PM, wrote: > > > > > Hi, > > > > > > I am working on window 7 and Python 3.5 to setup a localhost:8000 but it > > > did not get through as shown below: > > > > python -m http.server > > > Serving HTTP on 0.0.0.0 port 8000 ... > > > > > > But it did not show the results. > > > > > > Can someone help me how to setup the localhost? > > > > > > Thanks, > > > Wen-Ruey > > > > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > > hi Andrew, > > Yes. after I type http:\\localhost:8000, the browser did not show anything except a empty page without any errors. > > Thanks, > Wen-Ruey Hi, When you type http://localhost:8000, do you see something in the console after the line "Serving HTTP on 0.0.0.0 port 8000 ..." ? If the server actually serves requests on port 8000 you should see a log message such as 127.0.0.1 - - [15/Apr/2016 20:57:32] "GET / HTTP/1.1" 200 - From martin.schoon at gmail.com Fri Apr 15 16:41:35 2016 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 15 Apr 2016 20:41:35 GMT Subject: help install numpy and scipy in window 7 and 3.5.0 shell References: <7daec141-40c0-4a7c-953e-7e0628d74654@googlegroups.com> Message-ID: Den 2016-04-15 skrev wrh8609 at gmail.com : > On Windows (at work) I use Python(x,y) http://python-xy.github.io/ It has yet to fail me. /Martin From oscar.j.benjamin at gmail.com Fri Apr 15 17:23:23 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 15 Apr 2016 22:23:23 +0100 Subject: help install numpy and scipy in window 7 and 3.5.0 shell In-Reply-To: <7daec141-40c0-4a7c-953e-7e0628d74654@googlegroups.com> References: <7daec141-40c0-4a7c-953e-7e0628d74654@googlegroups.com> Message-ID: On 15 April 2016 at 17:29, wrote: >> On Apr 15, 2016 10:40 AM, wrote: >> > >> > I have downloaded the numpy-1.11.01 and scipy-0.17.0 but after running >> setup files over IDLE in numpy and scipy, it still can not get through. Can >> someone give me a hand? or you can provide the installation instruction for >> > > First I would like to have your input of installation instruction for numpy and scipy. I don't know what I did to run the setup.py is correct. The operating system is on window 7 and the version of python is 3.5.0. By the way, after I ran the setup.py of numpy over IDLE, it shows "Running from numpy source directory." I think what you mean is that you ran the setup.py to build e.g "python setup.py biuld" and then you ran Python and did "import numpy" and then numpy complained about you importing from within the source directory. Numpy complains about this because you should *install* numpy, change to a different directory and then import it e.g.: $ python setup.py install $ cd /some/where/else $ python >>> import numpy > and I can import numpy. But after I ran setup.py of scipy over IDLE, it shows > =============== RESTART: C:\PythonFiles\scipy-0.17.0\setup.py =============== > Traceback (most recent call last): > File "C:\PythonFiles\scipy-0.17.0\setup.py", line 265, in > setup_package() > File "C:\PythonFiles\scipy-0.17.0\setup.py", line 253, in setup_package > from numpy.distutils.core import setup > ImportError: No module named 'numpy' You didn't install numpy so it's not importable when you're not in the numpy source directory. In order to build scipy you have used cd to change to a different directory and now "import numpy" (which is what scipy's setup.py does) fails. I'm not sure what toolchain you can actually use to build numpy and scipy for Python 3.5 on Windows because: 1) In the past (Pre 3.5) MinGW gcc was used to be able to compile the fortran parts of scipy. 2) python.org's Python 3.5 Windows build is updated to use MSVC2015 which uses the new UCRT. 3) MinGW gcc cannot make binaries compatible with the UCRT so... 4) MSVC2015 is needed for extension modules for Python 3.5 on Windows but... 5) MSVC2015 cannot compile Fortran so it can't compile scipy There is work on a project called mingwpy which will hopefully add ucrt support to MinGW-W64 but I'm not sure of its status. All of the above is just background on the difficulties of building numpy/scipy yourself for Python 3.5 on Windows however... Numpy now has binary (pre-complied) wheels for Windows, OSX and Linux on PyPI so you should be able to just install it with: $ pip install numpy This is much easier than what you're currently attempting. I don't know if the same works for scipy now or not. Here on Linux I can install both numpy and scipy as precompiled wheels from PyPI simply by running $ pip install numpy scipy and it takes about 5 seconds. Give it a try and let and us know. -- Oscar From a3a95797 at telus.net Fri Apr 15 18:48:23 2016 From: a3a95797 at telus.net (a3a95797) Date: Fri, 15 Apr 2016 16:48:23 -0600 (MDT) Subject: Python 2.7 In-Reply-To: <1852181004.1116878.1460760280543.JavaMail.zimbra@mailid.telus.net> Message-ID: <2092809416.1121798.1460760503869.JavaMail.zimbra@mailid.telus.net> Sirs(s) I wish to have python 2.7 on a computer. I have not been able to get a working copy to work on my machine. I am prepared to follow instructions or to pay someone to install Python on my computer. Either the Debian or the Windows operating system is satisfactory. I am prepared to pay a company or person to reach my goal of programming with Python. From michael.selik at gmail.com Fri Apr 15 20:35:02 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sat, 16 Apr 2016 00:35:02 +0000 Subject: Looking for feedback on weighted voting algorithm In-Reply-To: <3567e3a1-6a55-4471-ad70-dc23e9ad05f4@googlegroups.com> References: <3567e3a1-6a55-4471-ad70-dc23e9ad05f4@googlegroups.com> Message-ID: On Fri, Apr 15, 2016, 7:56 PM wrote: > On Thursday, April 14, 2016 at 1:48:40 PM UTC-7, Michael Selik wrote: > > I suggest not worrying about sanitizing inputs. If someone provides bad > > data, Python will do the right thing: stop the program and print an > > explanation of what went wrong, often a more helpful message than one > you'd > > write. Use error handling mostly for when you want to do something > *other* > > than stop the program. > > > > I'm not sure I'd use NaN instead of raise division by zero error. NaNs > can > > be troublesome for downstream code that might not notice until it gets > > confusing. A div-by-zero error is clear and easier to track down because > of > > the traceback. > > I'd much rather sanitize the inputs and tell the user they did something > bad than to have the script crash and give a 500 Internal Server Error to > the user. > Right, my advice was only good if the user can read the original error and traceback. And can restart the program, etc. Even worse, I definitely wouldn't want to give any hints of the source code > organization by letting the user see the traceback. > Depends on the kind of user you have. > From cs at zip.com.au Fri Apr 15 23:48:33 2016 From: cs at zip.com.au (cs at zip.com.au) Date: Sat, 16 Apr 2016 13:48:33 +1000 Subject: sys.exit(1) vs raise SystemExit vs raise In-Reply-To: References: Message-ID: <20160416034833.GA24653@cskk.homeip.net> On 12Apr2016 18:20, Ganesh Pal wrote: >I m on python 2.7 and Linux , I have a simple code need suggestion if I > I could replace sys.exit(1) with raise SystemExit . > >==Actual code== > >def main(): > try: > create_logdir() > create_dataset() > unittest.main() > except Exception as e: > logging.exception(e) > sys.exit(EXIT_STATUS_ERROR) > >if __name__ == '__main__': > main() > >==Changed Code== > > >def main(): > try: > create_logdir() > create_dataset() > unittest.main() > except Exception as e: > logging.exception(e) > raise SystemExit > >if __name__ == '__main__': > main() I am against both of these personally. My preferred pattern is like this: def main(argv): try: ... except Exception as e: logging.exception(e) return 1 if __name__ == '__main__': sys.exit(main(sys.argv)) Notice that main() is back to being a normal function with normal returns. Also, most of us would avoid the "except Exception" and just let a top level except bubble out: that way you get a stack backtrace for debugging. I agree it prevents logging the exception and makes for uglier console output, but I think it is a win. And if you _do_ want to log the exception there is always this: try: ... except Exception as e: logging.exception(e) raise to recite the exception into the log and still let it bubble out normally. The problem with the "except Exception" pattern is that it catches and _hides_ _every_ exception, not merely the narrow set of specific exceptions that you understand. Finally, it is frowned upon to raise a bare Exception class. In python 3 I believe it is actually forbidden, so it is nonportable anyway. But even In Python to it is best to supply an Exception instance, not the class: raise SystemExit(1) >2. All the functions in try block have exception bubbled out using raise > > Example for create_logdir() here is the function definition > >def create_logdir(): > > try: > os.makedirs(LOG_DIR) > except OSError as e: > sys.stderr.write("Failed to create log directory...Exiting !!!") > raise > print "log file: " + corrupt_log > return True > >def main(): > try: > create_logdir() > except Exception as e: > logging.exception(e) > raise SystemExit > >(a) In case if create_logdir() fails we will get the below error ,is >this fine or do I need to improve this code. > >Failed to create log directory...Exiting !!!ERROR:root:[Errno 17] File >exists: '/var/log/dummy' > >Traceback (most recent call last): > File "corrupt_test.py", line 245, in main > create_logdir() > File "corrupt_test.py", line 53, in create_logdir > os.makedirs(LOG_DIR) > File "/usr/local/lib/python2.7/os.py", line 157, in makedirs >OSError: [Errno 17] File exists: '/var/log/dummy' I prefer the bubble out approach, perhap with a log or warning messages as you have done, eg: logging.exception("create_logdir failed: makedirs(%r): %s" % (LOG_DIR, e)) raise (Also not that that log message records more context: context is very useful when debugging problems.) For very small scripts sys.stderr.write is ok, but in general any of your functions that turned out to be generally useful might migrate into a library in order to be reused; consider that stderr is not always the place for messages; instead reading for the logging module with error() or wanr() or exception() as appropriate. There is more scope for configuring where the output goes that way without wiring it into your inner functions. >3. Can I have just raise , instead of SystemExit or sys.exit(1) . This >looks wrong to me > > def main(): > > try: > create_logdir() > except Exception as e > logging.exception(e) > raise This is what I would do, myself. Think: has the exception been "handled", meaning has the situation been dealt with because it was expected? If not, let the exception bubble out so that the user knows that something _not_ understood by the program has occurred. Finally, it is generally bad to SystemExit or sys.exit() from inside anything other than the outermost main() function. And I resist it even there; the main function, if written well, may often be called from somewhere else usefully, and that makes it effectively a library function (it has been reused). Such a function should not unilaterally abort the program. How rude! Instead, let the exception bubble out: perhaps the _caller_ of main() expects it and can handle it. By aborting and not "raise"ing, you have deprived the caller of the chance to do something appropriate, even though you yourself (i.e. "main") do not know enough context to handle the exception. So I am for "raise" myself. And then only because you want to log the error. If you didn't want to log the exception you could avoid the try/except _entirely_ and have simpler code: let the caller worry about unhandled exceptions! Cheers, Cameron Simpson From termim at gmail.com Fri Apr 15 23:59:44 2016 From: termim at gmail.com (Mike) Date: Fri, 15 Apr 2016 20:59:44 -0700 (PDT) Subject: good way to avoid recomputations? In-Reply-To: <8725470c-9554-4281-9427-43bd37f42f87@googlegroups.com> References: <8725470c-9554-4281-9427-43bd37f42f87@googlegroups.com> Message-ID: On Tuesday, April 5, 2016 at 4:54:50 PM UTC-4, Maurice wrote: > Hi. I working on a project where I have 5 scripts loading the same file at the very beginning so I would like to know the best way I can get this file without having to compute it 5 times. > > I also perform, in all the scripts, a list comprehension using this file that takes 30s to run. Would be cool to always have access to it as well. > > Cheers You can load the file and then fork ... From ben+python at benfinney.id.au Sat Apr 16 00:13:43 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 16 Apr 2016 14:13:43 +1000 Subject: sys.exit(1) vs raise SystemExit vs raise References: <20160416034833.GA24653@cskk.homeip.net> Message-ID: <858u0ew5qg.fsf@benfinney.id.au> cs at zip.com.au writes: > My preferred pattern is like this: > > def main(argv): > try: > ... > except Exception as e: > logging.exception(e) > return 1 > > if __name__ == '__main__': > sys.exit(main(sys.argv)) > > Notice that main() is back to being a normal function with normal > returns. That's good. A couple of points: * If you allow ?main? to be called with no arguments, and default to the actual command-line, then ?main? becomes a function you can use as a Setuptools entry point. * If the ?main? function encounters no exception, it will return ?None? instead of the correct exit status of 0. * You can use named constants from ?os? for the purpose of specifying exit status numbers. So:: def main(argv=None): """ Mainline procedure for this program. :param argv: Sequence of command-line arguments. Default: `sys.argv`. :return: Exit status (integer) for this program. """ exit_status = os.EX_OK if argv is None: argv = sys.argv try: ... except Exception as exc: logging.exception(exc) exit_status = os.EX_SOFTWARE return exit_status if __name__ == '__main__': sys.exit(main(sys.argv)) -- \ ?He that would make his own liberty secure must guard even his | `\ enemy from oppression.? ?Thomas Paine | _o__) | Ben Finney From steve at pearwood.info Sat Apr 16 00:38:09 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 16 Apr 2016 14:38:09 +1000 Subject: Guido sees the light: PEP 8 updated Message-ID: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> Until now, PEP 8 has recommended that multi-line expressions should break *after* infix operators: result = (this_value * some_value + another_value - excess_value or default_value ) After a mercifully short discussion on the Python-Ideas mailing list, Guido has been persuaded to change PEP 8 to recommend that the break should occur *before* the infix operator: result = (this_value * some_value + another_value - excess_value or default_value ) This makes me happy :-) Guido's announcement, including links to relevant discussion: https://mail.python.org/pipermail/python-dev/2016-April/144205.html -- Steven From me at ixokai.io Sat Apr 16 01:34:32 2016 From: me at ixokai.io (Stephen Hansen) Date: Fri, 15 Apr 2016 22:34:32 -0700 Subject: sys.exit(1) vs raise SystemExit vs raise In-Reply-To: <858u0ew5qg.fsf@benfinney.id.au> References: <20160416034833.GA24653@cskk.homeip.net> <858u0ew5qg.fsf@benfinney.id.au> Message-ID: <1460784872.1843058.580428001.63445E11@webmail.messagingengine.com> > * You can use named constants from ?os? for the purpose of specifying > exit status numbers. Only on *nix. Even then it varies from platform to platform which constants you can use. I'd prefer to document the return status and use numbers/my own constants directly, that way supporting any platform (even windows, where its %ERRORLEVEL% --S From rosuav at gmail.com Sat Apr 16 02:05:29 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Apr 2016 16:05:29 +1000 Subject: Python 2.7 In-Reply-To: <2092809416.1121798.1460760503869.JavaMail.zimbra@mailid.telus.net> References: <1852181004.1116878.1460760280543.JavaMail.zimbra@mailid.telus.net> <2092809416.1121798.1460760503869.JavaMail.zimbra@mailid.telus.net> Message-ID: On Sat, Apr 16, 2016 at 8:48 AM, a3a95797 wrote: > > Sirs(s) > > I wish to have python 2.7 on a computer. I have not been able to get a working copy to work on my machine. I am prepared to follow instructions or to pay someone to install Python on my computer. Either the Debian or the Windows operating system is satisfactory. I am prepared to pay a company or person to reach my goal of programming with Python. > Debian will usually come with Python already installed. Try opening a terminal and typing "python" - it'll probably be there. ChrisA From me at ixokai.io Sat Apr 16 02:21:12 2016 From: me at ixokai.io (Stephen Hansen) Date: Fri, 15 Apr 2016 23:21:12 -0700 Subject: Python 2.7 In-Reply-To: <2092809416.1121798.1460760503869.JavaMail.zimbra@mailid.telus.net> References: <2092809416.1121798.1460760503869.JavaMail.zimbra@mailid.telus.net> Message-ID: <1460787672.1851497.580441513.277C5981@webmail.messagingengine.com> On Fri, Apr 15, 2016, at 03:48 PM, a3a95797 wrote: > > Sirs(s) > > I wish to have python 2.7 on a computer. I have not been able to get a > working copy to work on my machine. I am prepared to follow instructions > or to pay someone to install Python on my computer. Either the Debian or > the Windows operating system is satisfactory. I am prepared to pay a > company or person to reach my goal of programming with Python. Define "not been ablke to get a working copy on my machine". For windows, just go to python.org and download it. For debian, it should come pre-installed. --- Stephen Hansen m e @ i x o k a i . i o From ben+python at benfinney.id.au Sat Apr 16 02:53:19 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 16 Apr 2016 16:53:19 +1000 Subject: Python 2.7 References: <1852181004.1116878.1460760280543.JavaMail.zimbra@mailid.telus.net> <2092809416.1121798.1460760503869.JavaMail.zimbra@mailid.telus.net> Message-ID: <854mb2vycg.fsf@benfinney.id.au> a3a95797 writes: > I wish to have python 2.7 on a computer. I have not been able to get a > working copy to work on my machine. Welcome! Thank you for learning Python. Please be aware that Python 2.7 is a dead end today. It will never get any new features, and only bug fixes will ever be made. Even that will stop in a few years. If you do not have a highly compelling reason to use that old version, you should not be writing any new code in Python 2. Instead, get the latest Python 3 for your computer and learn Python that way. > I am prepared to follow instructions or to pay someone to install > Python on my computer. Either the Debian or the Windows operating > system is satisfactory. The Debian package manager will install Python 3 for you, just install the ?python3? package. > I am prepared to pay a company or person to reach my goal of > programming with Python. Good hunting, and feel free to ask questions as you learn. You will probably want to join the ?tutor? forum for collaborative tutoring . -- \ ?Contentment is a pearl of great price, and whosoever procures | `\ it at the expense of ten thousand desires makes a wise and | _o__) happy purchase.? ?J. Balguy | Ben Finney From ben+python at benfinney.id.au Sat Apr 16 02:56:10 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 16 Apr 2016 16:56:10 +1000 Subject: sys.exit(1) vs raise SystemExit vs raise References: <20160416034833.GA24653@cskk.homeip.net> <858u0ew5qg.fsf@benfinney.id.au> <1460784872.1843058.580428001.63445E11@webmail.messagingengine.com> Message-ID: <85zisuujn9.fsf@benfinney.id.au> Stephen Hansen writes: > > * You can use named constants from ?os? for the purpose of specifying > > exit status numbers. > > Only on *nix. Hmm, I didn't see that. It seems strange that even the constant for ?no error? exit status should be defined only for Unix :-/ -- \ ?Geeks like to think that they can ignore politics. You can | `\ leave politics alone, but politics won't leave you alone.? | _o__) ?Richard M. Stallman, 2002-07-26 | Ben Finney From bob.martin at excite.com Sat Apr 16 08:05:34 2016 From: bob.martin at excite.com (Bob Martin) Date: Sat, 16 Apr 2016 08:05:34 BST Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: in 758117 20160416 053809 Steven D'Aprano wrote: >Until now, PEP 8 has recommended that multi-line expressions should break >*after* infix operators: > > >result = (this_value * >some_value + >another_value - >excess_value or >default_value >) > > >After a mercifully short discussion on the Python-Ideas mailing list, Guido >has been persuaded to change PEP 8 to recommend that the break should occur >*before* the infix operator: > > >result = (this_value >* some_value >+ another_value >- excess_value >or default_value >) > > >This makes me happy :-) That's how I've always done it. > > >Guido's announcement, including links to relevant discussion: > >https://mail.python.org/pipermail/python-dev/2016-April/144205.html From rosuav at gmail.com Sat Apr 16 03:08:43 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Apr 2016 17:08:43 +1000 Subject: sys.exit(1) vs raise SystemExit vs raise In-Reply-To: <85zisuujn9.fsf@benfinney.id.au> References: <20160416034833.GA24653@cskk.homeip.net> <858u0ew5qg.fsf@benfinney.id.au> <1460784872.1843058.580428001.63445E11@webmail.messagingengine.com> <85zisuujn9.fsf@benfinney.id.au> Message-ID: On Sat, Apr 16, 2016 at 4:56 PM, Ben Finney wrote: > Stephen Hansen writes: > >> > * You can use named constants from ?os? for the purpose of specifying >> > exit status numbers. >> >> Only on *nix. > > Hmm, I didn't see that. It seems strange that even the constant for ?no > error? exit status should be defined only for Unix :-/ Maybe it's an error to use anything non-Unix?? ChrisA From srirajarajeswaridevikrupa at gmail.com Sat Apr 16 03:25:39 2016 From: srirajarajeswaridevikrupa at gmail.com (durgadevi1) Date: Sat, 16 Apr 2016 00:25:39 -0700 (PDT) Subject: How to print a part of a string? In-Reply-To: References: Message-ID: On Friday, April 15, 2016 at 8:13:17 PM UTC+8, durgadevi1 wrote: > Hello all, > > I have another homework problem. > > I have a textfile. It contains lines of string. > > I am required to only print out a certain part of the string. > > For example the textfile contain: > > ABC XXXXX NNNNN > BCD QQQQQ EEEEE > ABC WWWWW AAAAA > > > I need to print all the parts that come after only ABC. > > That means I need to print only XXXXX from the first line and WWWWW from the second line. > > I'm not sure of what code to use to achieve that. Yay! I'm able to complete my homework now. :) Thanks for your replies guys :) From srirajarajeswaridevikrupa at gmail.com Sat Apr 16 03:35:37 2016 From: srirajarajeswaridevikrupa at gmail.com (durgadevi1) Date: Sat, 16 Apr 2016 00:35:37 -0700 (PDT) Subject: Dynamic inputs Message-ID: <901a5b60-25b3-4e1c-9178-755bf668a5c5@googlegroups.com> Hi guys, what does dynamic inputs mean and how is it implemented in python programming? From marko at pacujo.net Sat Apr 16 04:06:59 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 16 Apr 2016 11:06:59 +0300 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87shym6kpo.fsf@elektro.pacujo.net> Bob Martin : > in 758117 20160416 053809 Steven D'Aprano wrote: >>Until now, PEP 8 has recommended that multi-line expressions should >>break *after* infix operators: >> >> >>result = (this_value * >>some_value + >>another_value - >>excess_value or >>default_value >>) >> >> >>After a mercifully short discussion on the Python-Ideas mailing list, >>Guido has been persuaded to change PEP 8 to recommend that the break >>should occur *before* the infix operator: >> >> >>result = (this_value >>* some_value >>+ another_value >>- excess_value >>or default_value >>) >> >> >>This makes me happy :-) > > That's how I've always done it. It doesn't really matter one way or another. The true WTF is that it's been changed. Marko From rosuav at gmail.com Sat Apr 16 04:32:32 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Apr 2016 18:32:32 +1000 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <87shym6kpo.fsf@elektro.pacujo.net> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> Message-ID: On Sat, Apr 16, 2016 at 6:06 PM, Marko Rauhamaa wrote: > It doesn't really matter one way or another. The true WTF is that it's > been changed. Why? Was PEP 8 inscribed on stone tablets carried down from a mountain? ChrisA From marko at pacujo.net Sat Apr 16 04:51:01 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 16 Apr 2016 11:51:01 +0300 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> Message-ID: <87h9f26ioa.fsf@elektro.pacujo.net> Chris Angelico : > On Sat, Apr 16, 2016 at 6:06 PM, Marko Rauhamaa wrote: >> It doesn't really matter one way or another. The true WTF is that it's >> been changed. > > Why? Was PEP 8 inscribed on stone tablets carried down from a mountain? In a way, yes. I don't follow PEP 8 to the tee; probably nobody does. However, I don't see the point of turning truckloads of exemplary Python code into truckloads of substandard Python code. Marko From rosuav at gmail.com Sat Apr 16 05:30:21 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Apr 2016 19:30:21 +1000 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <87h9f26ioa.fsf@elektro.pacujo.net> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> Message-ID: On Sat, Apr 16, 2016 at 6:51 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sat, Apr 16, 2016 at 6:06 PM, Marko Rauhamaa wrote: >>> It doesn't really matter one way or another. The true WTF is that it's >>> been changed. >> >> Why? Was PEP 8 inscribed on stone tablets carried down from a mountain? > > In a way, yes. > > I don't follow PEP 8 to the tee; probably nobody does. However, I don't > see the point of turning truckloads of exemplary Python code into > truckloads of substandard Python code. Let me quote to you from the most important section of PEP 8. """ A style guide is about consistency. Consistency with this style guide is important. Consistency within a project is more important. Consistency within one module or function is the most important. However, know when to be inconsistent -- sometimes style guide recommendations just aren't applicable. When in doubt, use your best judgment. Look at other examples and decide what looks best. And don't hesitate to ask! """ (from the section "A Foolish Consistency is the Hobgoblin of Little Minds") Maybe we need a blog post "Falsehoods Programmers Believe About PEP 8", along the lines of the ones about time and names. Remember, every one of these is false. * All Python code should follow PEP 8. * If you use a tool named pep8, your code will be PEP 8 compliant. * If your code is PEP 8 compliant, a tool named pep8 will accept it. * The Python Standard Library is PEP 8 compliant. * Okay, at least the new parts of the standard library are PEP 8 compliant. * PEP 8 compliant code is inherently better than non-compliant code. * PEP8-ing existing code will improve it. * Once code is PEP 8 compliant, it can easily be kept that way through subsequent edits. * PEP 8 never changes. * Well, it never materially changes. * I mean, new advice, sure, but it'll never actually go back on a rule. Contributions welcomed. ChrisA From michael.selik at gmail.com Sat Apr 16 05:31:09 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sat, 16 Apr 2016 09:31:09 +0000 Subject: Dynamic inputs In-Reply-To: <901a5b60-25b3-4e1c-9178-755bf668a5c5@googlegroups.com> References: <901a5b60-25b3-4e1c-9178-755bf668a5c5@googlegroups.com> Message-ID: On Sat, Apr 16, 2016, 9:41 AM durgadevi1 < srirajarajeswaridevikrupa at gmail.com> wrote: > what does dynamic inputs mean and how is it implemented in python > programming? > In what context did you hear or read the phrase "dynamic inputs"? > From michael.selik at gmail.com Sat Apr 16 05:34:29 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sat, 16 Apr 2016 09:34:29 +0000 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <87h9f26ioa.fsf@elektro.pacujo.net> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> Message-ID: On Sat, Apr 16, 2016, 10:56 AM Marko Rauhamaa wrote: > Chris Angelico : > > > On Sat, Apr 16, 2016 at 6:06 PM, Marko Rauhamaa > wrote: > >> It doesn't really matter one way or another. The true WTF is that it's > >> been changed. > > > > Why? Was PEP 8 inscribed on stone tablets carried down from a mountain? > > In a way, yes. > > I don't follow PEP 8 to the tee; probably nobody does. However, I don't > see the point of turning truckloads of exemplary Python code into > truckloads of substandard Python code. > A change to PEP 8 does not change the quality of any code. Many teams follow their own, different styles. > From steve at pearwood.info Sat Apr 16 08:03:19 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 16 Apr 2016 22:03:19 +1000 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> Message-ID: <57122a08$0$1584$c3e8da3$5496439d@news.astraweb.com> On Sat, 16 Apr 2016 06:51 pm, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sat, Apr 16, 2016 at 6:06 PM, Marko Rauhamaa wrote: >>> It doesn't really matter one way or another. The true WTF is that it's >>> been changed. >> >> Why? Was PEP 8 inscribed on stone tablets carried down from a mountain? > > In a way, yes. > > I don't follow PEP 8 to the tee; probably nobody does. However, I don't > see the point of turning truckloads of exemplary Python code into > truckloads of substandard Python code. In Guido's own words: The update is already serving its real purpose: showing that style is debatable and cannot always easily be reduced to fixed rules. https://mail.python.org/pipermail/python-dev/2016-April/144211.html GvR is not a fan of the automatic and compulsory application of PEP 8 conventions without thought, so I don't think he would agree with you that a change in the preferred style automatically and necessarily converts "exemplary Python code" into "substandard Python code". -- Steven From me+python at ixokai.io Sat Apr 16 08:32:02 2016 From: me+python at ixokai.io (Stephen Hansen) Date: Sat, 16 Apr 2016 05:32:02 -0700 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <87h9f26ioa.fsf@elektro.pacujo.net> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> Message-ID: <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> On Sat, Apr 16, 2016, at 01:51 AM, Marko Rauhamaa wrote: > Chris Angelico : > > > On Sat, Apr 16, 2016 at 6:06 PM, Marko Rauhamaa wrote: > >> It doesn't really matter one way or another. The true WTF is that it's > >> been changed. > > > > Why? Was PEP 8 inscribed on stone tablets carried down from a mountain? > > In a way, yes. > > I don't follow PEP 8 to the tee; probably nobody does. However, I don't > see the point of turning truckloads of exemplary Python code into > truckloads of substandard Python code. This attitude is part of the problem: not following PEP8 does not make code "substandard". PEP8 was never meant to be an authoritative metric of 'good'. Its a set of guidelines that are subject to change over time (this isn't even KINDA the first change!) and represent the core devs taste and particular needs, and it goes out of its way to say that it is only a suggestion and other concerns (especially local consistency) override its advice. --- Stephen Hansen m e @ i x o k a i . i o From larry.martell at gmail.com Sat Apr 16 10:53:33 2016 From: larry.martell at gmail.com (Larry Martell) Date: Sat, 16 Apr 2016 10:53:33 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> Message-ID: On Sat, Apr 16, 2016 at 8:32 AM, Stephen Hansen wrote: > On Sat, Apr 16, 2016, at 01:51 AM, Marko Rauhamaa wrote: >> Chris Angelico : >> >> > On Sat, Apr 16, 2016 at 6:06 PM, Marko Rauhamaa wrote: >> >> It doesn't really matter one way or another. The true WTF is that it's >> >> been changed. >> > >> > Why? Was PEP 8 inscribed on stone tablets carried down from a mountain? >> >> In a way, yes. >> >> I don't follow PEP 8 to the tee; probably nobody does. However, I don't >> see the point of turning truckloads of exemplary Python code into >> truckloads of substandard Python code. > > This attitude is part of the problem: not following PEP8 does not make > code "substandard". PEP8 was never meant to be an authoritative metric > of 'good'. Its a set of guidelines that are subject to change over time > (this isn't even KINDA the first change!) and represent the core devs > taste and particular needs, and it goes out of its way to say that it is > only a suggestion and other concerns (especially local consistency) > override its advice. I have worked for many companies where you are required to get a clean run of pep8 on your code before your pull request will even be considered for approval. I don't agree with this at all, as I think it makes the code very ugly, especially enforcing the max line length. I have referred people to this, but it fell on blind eyes: https://www.python.org/dev/peps/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds From mal at europython.eu Sat Apr 16 10:56:34 2016 From: mal at europython.eu (M.-A. Lemburg) Date: Sat, 16 Apr 2016 16:56:34 +0200 Subject: EuroPython 2016: Schedule online Message-ID: <571252A2.2020201@europython.eu> We are happy to announce the schedule for EuroPython 2016 in Bilbao. The program WG has been working hard trying to fit all the sessions in the last few weeks. With over 180 sessions, over 150 speakers, one day for workshops, 5 days of talks, training, keynotes, lightning talks and open spaces, followed by 2 days of sprints, EuroPython will be one of the most exciting and vibrant Python events this year: *** EuroPython 2016 Schedule *** https://ep2016.europython.eu/p3/schedule/ep2016/ The schedule is available in table and list format. Please note that we are still applying changes to the slots and will also add some more interesting special sessions to it in the coming days. Early in June we will have a short second Call for Proposals, limited to hot topics and most recent developments in software and technology. We will announce details soon. Many thanks to everyone who submitted proposals. EuroPython wouldn?t be possible without our speakers. If you want to join the fun, be sure to get your tickets as soon as possible, since ticket sales usually start picking up quite a bit after we announce the schedule. https://ep2016.europython.eu/en/registration/ With gravitational regards, -- EuroPython 2016 Team http://ep2016.europython.eu/ http://www.europython-society.org/ From steve at pearwood.info Sat Apr 16 12:04:31 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 17 Apr 2016 02:04:31 +1000 Subject: Does get-pip work under sudo? Message-ID: <57126291$0$1615$c3e8da3$5496439d@news.astraweb.com> I tried to install pip following the instructions here: https://pip.pypa.io/en/stable/installing/ but whenever I tried to run the installer, I got an error. If I ran as a regular user: python2.7 get-pip.py I'd get a permission denied error (as expected) trying to write to the site-packages directory: OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/site-packages/pip-8.1.1.dist-info' This does not surprise me, and I'm not concerned by that. But if I ran using sudo, I'd get a surprising error. I tried using both 2.7 and 3.3, and got similar errors each time: sudo python2.7 get-pip.py IOError: [Errno 21] Is a directory: '/tmp' sudo python3.3 get-pip.py IsADirectoryError: [Errno 21] Is a directory: '/tmp' This surprises me. Is this a bug in pip? Here are the full tracebacks: # Python 2.7 traceback Exception: Traceback (most recent call last): File "/tmp/tmpCYNTpT/pip.zip/pip/basecommand.py", line 209, in main status = self.run(options, args) File "/tmp/tmpCYNTpT/pip.zip/pip/commands/install.py", line 249, in run with self._build_session(options) as session: File "/tmp/tmpCYNTpT/pip.zip/pip/basecommand.py", line 72, in _build_session insecure_hosts=options.trusted_hosts, File "/tmp/tmpCYNTpT/pip.zip/pip/download.py", line 321, in __init__ self.headers["User-Agent"] = user_agent() File "/tmp/tmpCYNTpT/pip.zip/pip/download.py", line 97, in user_agent zip(["lib", "version"], platform.libc_ver()), File "/usr/local/lib/python2.7/platform.py", line 163, in libc_ver f = open(executable,'rb') IOError: [Errno 21] Is a directory: '/tmp' Traceback (most recent call last): File "get-pip.py", line 19154, in main() File "get-pip.py", line 194, in main bootstrap(tmpdir=tmpdir) File "get-pip.py", line 172, in bootstrap sys.exit(pip.main(["install", "--upgrade"] + args)) File "/tmp/tmpCYNTpT/pip.zip/pip/__init__.py", line 213, in main File "/tmp/tmpCYNTpT/pip.zip/pip/basecommand.py", line 245, in main File "/tmp/tmpCYNTpT/pip.zip/pip/basecommand.py", line 72, in _build_session File "/tmp/tmpCYNTpT/pip.zip/pip/download.py", line 321, in __init__ File "/tmp/tmpCYNTpT/pip.zip/pip/download.py", line 97, in user_agent File "/usr/local/lib/python2.7/platform.py", line 163, in libc_ver f = open(executable,'rb') IOError: [Errno 21] Is a directory: '/tmp' # Python 3.3 traceback Exception: Traceback (most recent call last): File "/tmp/tmp75x40t/pip.zip/pip/basecommand.py", line 209, in main status = self.run(options, args) File "/tmp/tmp75x40t/pip.zip/pip/commands/install.py", line 249, in run with self._build_session(options) as session: File "/tmp/tmp75x40t/pip.zip/pip/basecommand.py", line 72, in _build_session insecure_hosts=options.trusted_hosts, File "/tmp/tmp75x40t/pip.zip/pip/download.py", line 321, in __init__ self.headers["User-Agent"] = user_agent() File "/tmp/tmp75x40t/pip.zip/pip/download.py", line 97, in user_agent zip(["lib", "version"], platform.libc_ver()), File "/usr/local/lib/python3.3/platform.py", line 162, in libc_ver f = open(executable,'rb') IsADirectoryError: [Errno 21] Is a directory: '/tmp' Traceback (most recent call last): File "get-pip.py", line 19154, in main() File "get-pip.py", line 194, in main bootstrap(tmpdir=tmpdir) File "get-pip.py", line 172, in bootstrap sys.exit(pip.main(["install", "--upgrade"] + args)) File "/tmp/tmp75x40t/pip.zip/pip/__init__.py", line 213, in main File "/tmp/tmp75x40t/pip.zip/pip/basecommand.py", line 245, in main File "/tmp/tmp75x40t/pip.zip/pip/basecommand.py", line 72, in _build_session File "/tmp/tmp75x40t/pip.zip/pip/download.py", line 321, in __init__ File "/tmp/tmp75x40t/pip.zip/pip/download.py", line 97, in user_agent File "/usr/local/lib/python3.3/platform.py", line 162, in libc_ver f = open(executable,'rb') IsADirectoryError: [Errno 21] Is a directory: '/tmp' -- Steven From marko at pacujo.net Sat Apr 16 12:51:58 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 16 Apr 2016 19:51:58 +0300 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> Message-ID: <878u0d7az5.fsf@elektro.pacujo.net> Larry Martell : > I have worked for many companies where you are required to get a clean > run of pep8 on your code before your pull request will even be > considered for approval. I don't agree with this at all, as I think it > makes the code very ugly, especially enforcing the max line length. Agh, I was with you until your last remark. A max line length of 79 characters is among the *only* rigorous principles I judge coding style on. It comes with the maxim that one function must be visible at once on the screen. Marko From larry.martell at gmail.com Sat Apr 16 12:58:54 2016 From: larry.martell at gmail.com (Larry Martell) Date: Sat, 16 Apr 2016 12:58:54 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <878u0d7az5.fsf@elektro.pacujo.net> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: On Sat, Apr 16, 2016 at 12:51 PM, Marko Rauhamaa wrote: > Larry Martell : > >> I have worked for many companies where you are required to get a clean >> run of pep8 on your code before your pull request will even be >> considered for approval. I don't agree with this at all, as I think it >> makes the code very ugly, especially enforcing the max line length. > > Agh, I was with you until your last remark. > > A max line length of 79 characters is among the *only* rigorous > principles I judge coding style on. > > It comes with the maxim that one function must be visible at once on the > screen. if we still had 1970's 80 character TTYs that would matter but on my 29" 1920x1080 screen it doesn't. From mdrosis at yahoo.com Sat Apr 16 13:12:48 2016 From: mdrosis at yahoo.com (Mel Drosis) Date: Sat, 16 Apr 2016 13:12:48 -0400 Subject: Fraud Message-ID: <444136AD-6A91-4BCE-B80F-6D1B5A8F4B65@yahoo.com> My phone my accounts my home network have all been affected because of someone using coding from Python and Linux and GitHub and json. I don't even know what this stuff is but how do I get rid of it all. It's ruined my life. Sent from my iPhone From tjreedy at udel.edu Sat Apr 16 13:19:08 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 16 Apr 2016 13:19:08 -0400 Subject: Dynamic inputs In-Reply-To: <901a5b60-25b3-4e1c-9178-755bf668a5c5@googlegroups.com> References: <901a5b60-25b3-4e1c-9178-755bf668a5c5@googlegroups.com> Message-ID: On 4/16/2016 3:35 AM, durgadevi1 wrote: > what does dynamic inputs mean and how is it implemented in python programming? 'dynamic input' is new to me. I would take it to mean input that is not available until the program is running. Inputs from people and sensors would qualify. But maybe whoever you read it from meant 'strong, energizing' as opposed to 'weak, inervating'. -- Terry Jan Reedy From tjreedy at udel.edu Sat Apr 16 13:25:37 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 16 Apr 2016 13:25:37 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: On 4/16/2016 12:58 PM, Larry Martell wrote: > On Sat, Apr 16, 2016 at 12:51 PM, Marko Rauhamaa wrote: >> Larry Martell : >> >>> I have worked for many companies where you are required to get a clean >>> run of pep8 on your code before your pull request will even be >>> considered for approval. I don't agree with this at all, as I think it >>> makes the code very ugly, especially enforcing the max line length. >> >> Agh, I was with you until your last remark. >> >> A max line length of 79 characters is among the *only* rigorous >> principles I judge coding style on. >> >> It comes with the maxim that one function must be visible at once on the >> screen. > > if we still had 1970's 80 character TTYs that would matter but on my > 29" 1920x1080 screen it doesn't. It depends on whether one prefers to use the extra width to have long lines or side-by-side windows. I prefer the latter. -- Terry Jan Reedy From bc at freeuk.com Sat Apr 16 14:18:17 2016 From: bc at freeuk.com (BartC) Date: Sat, 16 Apr 2016 19:18:17 +0100 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: On 16/04/2016 17:58, Larry Martell wrote: > On Sat, Apr 16, 2016 at 12:51 PM, Marko Rauhamaa wrote: >> Larry Martell : >> >>> I have worked for many companies where you are required to get a clean >>> run of pep8 on your code before your pull request will even be >>> considered for approval. I don't agree with this at all, as I think it >>> makes the code very ugly, especially enforcing the max line length. >> >> Agh, I was with you until your last remark. >> >> A max line length of 79 characters is among the *only* rigorous >> principles I judge coding style on. >> >> It comes with the maxim that one function must be visible at once on the >> screen. > > if we still had 1970's 80 character TTYs that would matter but on my > 29" 1920x1080 screen it doesn't. There are reasons why 'broadsheet' newspapers don't have a single wide column spanning the entire width of the page, but are divided into multiple columns. (But I think 80 columns is a bit limited. Maybe 100 or 132.) -- Bartc From marko at pacujo.net Sat Apr 16 14:33:33 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 16 Apr 2016 21:33:33 +0300 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: <87wpnx5rpe.fsf@elektro.pacujo.net> Terry Reedy : > On 4/16/2016 12:58 PM, Larry Martell wrote: >> if we still had 1970's 80 character TTYs that would matter but on my >> 29" 1920x1080 screen it doesn't. > > It depends on whether one prefers to use the extra width to have long > lines or side-by-side windows. I prefer the latter. Precisely. I have better uses for my screen than seeing a mostly white, ragged right margin. Marko From larry.martell at gmail.com Sat Apr 16 14:53:34 2016 From: larry.martell at gmail.com (Larry Martell) Date: Sat, 16 Apr 2016 14:53:34 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: On Sat, Apr 16, 2016 at 2:18 PM, BartC wrote: > On 16/04/2016 17:58, Larry Martell wrote: >> >> On Sat, Apr 16, 2016 at 12:51 PM, Marko Rauhamaa wrote: >>> >>> Larry Martell : >>> >>>> I have worked for many companies where you are required to get a clean >>>> run of pep8 on your code before your pull request will even be >>>> considered for approval. I don't agree with this at all, as I think it >>>> makes the code very ugly, especially enforcing the max line length. >>> >>> >>> Agh, I was with you until your last remark. >>> >>> A max line length of 79 characters is among the *only* rigorous >>> principles I judge coding style on. >>> >>> It comes with the maxim that one function must be visible at once on the >>> screen. >> >> >> if we still had 1970's 80 character TTYs that would matter but on my >> 29" 1920x1080 screen it doesn't. > > > There are reasons why 'broadsheet' newspapers don't have a single wide > column spanning the entire width of the page, but are divided into multiple > columns. Nor do they have a \ at the end of each line with the following line indented. From ethan at stoneleaf.us Sat Apr 16 15:07:09 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 16 Apr 2016 12:07:09 -0700 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: <57128D5D.8050401@stoneleaf.us> On 04/16/2016 10:25 AM, Terry Reedy wrote: > On 4/16/2016 12:58 PM, Larry Martell wrote: >> On Sat, Apr 16, 2016 at 12:51 PM, Marko Rauhamaa wrote: >>> Larry Martell wrote: >>>> I have worked for many companies where you are required to get a clean >>>> run of pep8 on your code before your pull request will even be >>>> considered for approval. I don't agree with this at all, as I think it >>>> makes the code very ugly, especially enforcing the max line length. >>> >>> Agh, I was with you until your last remark. >>> >>> A max line length of 79 characters is among the *only* rigorous >>> principles I judge coding style on. >>> >>> It comes with the maxim that one function must be visible at once on the >>> screen. >> >> if we still had 1970's 80 character TTYs that would matter but on my >> 29" 1920x1080 screen it doesn't. > > It depends on whether one prefers to use the extra width to have long > lines or side-by-side windows. I prefer the latter. Python code windows go in my portrait mode 27" screens (120 chars), while xml windows go in landscape mode (220 chars). Yes, there are many reasons why I don't like xml. :( -- ~Ethan~ From jdsukdeo at gmail.com Sat Apr 16 15:16:05 2016 From: jdsukdeo at gmail.com (Jurell) Date: Sat, 16 Apr 2016 21:16:05 +0200 Subject: Installation problem Message-ID: <000001d19814$707c3090$517491b0$@com> Dear Sir/Madam I installed the Python program version 3.5.1 32 bit and the IDE I am going to use is Wing IDE 101. The problem when I tried installing the python program was as follows: "The program can`t start because api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer. Try reinstalling the program to fix this problem". What I did was uninstall Python and reinstall it installed ,I proceed on to install the IDE then this message appeared again. N.B: My computer has Windows 7 64bit operating system I hope that helps .Please help your time and effort will be greatly appreciated J .Just in case you can`t reach me you can send a message to TSSukdeo at gmail.com . Thank you for reading my message ,I hope we can resolve this issue together J. Yours sincerely Tiara --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From wrightalexw at gmail.com Sat Apr 16 15:21:59 2016 From: wrightalexw at gmail.com (alex wright) Date: Sat, 16 Apr 2016 15:21:59 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: We employ a pretty hard limit of 100. This way I can reliably have 1 module split vertically with a test or configuration file open or 3 separate modules, etc. I find 80 to be a bit strict, although in the past I've been in unfortunate environments where it was helpful. The rest of PEP8 is largely adhered to wherever possible and it's been wonderful. When I first came to the project it had no real standard and was mostly formatted at the whims of the one dev working on it. It was a mess. The team has grown significantly internationally and a codified standard not rooted in any of our habits is great. (I've never replied to this list so I hope I don't goof up.) On Sat, Apr 16, 2016 at 2:18 PM, BartC wrote: > On 16/04/2016 17:58, Larry Martell wrote: > >> On Sat, Apr 16, 2016 at 12:51 PM, Marko Rauhamaa >> wrote: >> >>> Larry Martell : >>> >>> I have worked for many companies where you are required to get a clean >>>> run of pep8 on your code before your pull request will even be >>>> considered for approval. I don't agree with this at all, as I think it >>>> makes the code very ugly, especially enforcing the max line length. >>>> >>> >>> Agh, I was with you until your last remark. >>> >>> A max line length of 79 characters is among the *only* rigorous >>> principles I judge coding style on. >>> >>> It comes with the maxim that one function must be visible at once on the >>> screen. >>> >> >> if we still had 1970's 80 character TTYs that would matter but on my >> 29" 1920x1080 screen it doesn't. >> > > There are reasons why 'broadsheet' newspapers don't have a single wide > column spanning the entire width of the page, but are divided into multiple > columns. > > (But I think 80 columns is a bit limited. Maybe 100 or 132.) > > -- > Bartc > -- > https://mail.python.org/mailman/listinfo/python-list > -- "On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question." -Charles Babbage, 19th century English mathematician, philosopher, inventor and mechanical engineer who originated the concept of a programmable computer. From ben+python at benfinney.id.au Sat Apr 16 16:08:12 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 17 Apr 2016 06:08:12 +1000 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: <85vb3huxjn.fsf@benfinney.id.au> Larry Martell writes: > if we still had 1970's 80 character TTYs that would matter but on my > 29" 1920x1080 screen it doesn't. Larry, you've been around long enough to know that's not an argument against a limited line length for code. It is not about the technology of your terminal. It's about the technology of the brain reading the text. -- \ ?Fascism is capitalism plus murder.? ?Upton Sinclair | `\ | _o__) | Ben Finney From ben+python at benfinney.id.au Sat Apr 16 16:21:54 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 17 Apr 2016 06:21:54 +1000 Subject: Falsehoods People Believe about PEP 8 (was: Guido sees the light: PEP 8 updated) References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> Message-ID: <85potpuwwt.fsf_-_@benfinney.id.au> Chris Angelico writes: > Maybe we need a blog post "Falsehoods Programmers Believe About PEP > 8", along the lines of the ones about time and names. Great suggestion. (Do you have a blog on which you could post an article like this?) > Remember, every one of these is false. > > * All Python code should follow PEP 8. > > * If you use a tool named pep8, your code will be PEP 8 compliant. > > * If your code is PEP 8 compliant, a tool named pep8 will accept it. > > * The Python Standard Library is PEP 8 compliant. > > * Okay, at least the new parts of the standard library are PEP 8 > compliant. > > * PEP 8 compliant code is inherently better than non-compliant code. > > * PEP8-ing existing code will improve it. > > * Once code is PEP 8 compliant, it can easily be kept that way through > subsequent edits. > > * PEP 8 never changes. > > * Well, it never materially changes. > > * I mean, new advice, sure, but it'll never actually go back on a > rule. * The line length limit is obsolete in an age of high-resolution displays. * Okay, but if you disregard side-by-side windows, lines of code can be arbitrarily long without hurting readability. * Well, maybe not several hundred characters, but surely 120 characters of code on a line is easy enough to read. * The only valid white space is line breaks and U+0020 SPACE. * Okay, U+0009 TAB when lining up columns, but no other white space. * Oh, come on, no-one would use U+000C FORM FEED in source code. -- \ ?The apparent lesson of the Inquisition is that insistence on | `\ uniformity of belief is fatal to intellectual, moral, and | _o__) spiritual health.? ?_The Uses Of The Past_, Herbert J. Muller | Ben Finney From ben+python at benfinney.id.au Sat Apr 16 16:24:14 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 17 Apr 2016 06:24:14 +1000 Subject: sys.exit(1) vs raise SystemExit vs raise References: <20160416034833.GA24653@cskk.homeip.net> <858u0ew5qg.fsf@benfinney.id.au> <1460784872.1843058.580428001.63445E11@webmail.messagingengine.com> <85zisuujn9.fsf@benfinney.id.au> Message-ID: <85lh4duwsx.fsf@benfinney.id.au> Dennis Lee Bieber writes: > On Sat, 16 Apr 2016 16:56:10 +1000, Ben Finney > declaimed the following: > > >It seems strange that even the constant for ?no error? exit status > >should be defined only for Unix :-/ > > VMS had a whole slew of "no error" status values That's fine; those values can be defined per operating system, and maybe they should be. My concern is that (according to the documentation) the ?no error? exit status *isn't even defined* on non-Unix operating systems, as though no other OS uses it. -- \ ?Do unto others twenty-five percent better than you expect them | `\ to do unto you. (The twenty-five percent is [to correct] for | _o__) error.)? ?Linus Pauling's Golden Rule | Ben Finney From rosuav at gmail.com Sat Apr 16 16:31:53 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Apr 2016 06:31:53 +1000 Subject: Falsehoods People Believe about PEP 8 (was: Guido sees the light: PEP 8 updated) In-Reply-To: <85potpuwwt.fsf_-_@benfinney.id.au> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <85potpuwwt.fsf_-_@benfinney.id.au> Message-ID: On Sun, Apr 17, 2016 at 6:21 AM, Ben Finney wrote: > Great suggestion. (Do you have a blog on which you could post an article > like this?) I do. I'll let people contribute for a while, and then I'll post it on rosuav.blogspot.com. Thanks for the additions! ChrisA From antoon.pardon at rece.vub.ac.be Sat Apr 16 16:37:52 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Sat, 16 Apr 2016 22:37:52 +0200 Subject: How to parameterize unittests In-Reply-To: <57111b0b$0$1606$c3e8da3$5496439d@news.astraweb.com> References: <570FA466.20003@rece.vub.ac.be> <570fb1a3$0$1609$c3e8da3$5496439d@news.astraweb.com> <57108FAC.3020105@rece.vub.ac.be> <5710A442.8000906@rece.vub.ac.be> <5710affd$0$22140$c3e8da3$5496439d@news.astraweb.com> <5710D3DA.6030005@rece.vub.ac.be> <5710E30B.6050304@rece.vub.ac.be> <57111b0b$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5712A2A0.7080606@rece.vub.ac.be> Op 15-04-16 om 18:47 schreef Steven D'Aprano: > On Fri, 15 Apr 2016 10:48 pm, Antoon Pardon wrote: > >> Starting from this: >> >> class Test_AVLTree(unittest.TestCase): >> >> def test_empty_tree_is_false(self): >> instance = avltree() >> self.assertFalse(instance) >> >> Changing it into this: >> >> def MakeAVLTest(avltree): >> class Test_AVLTree(unittest.TestCase): >> >> def test_empty_tree_is_false(self): >> instance = avltree() >> self.assertFalse(instance) >> >> return Test_AVLTree >> >> AVLTest = MakeAVLTest(avltree) >> MyTreeTest = MakeAVLTest(mytree) >> >> Seems to work > > Right up to the moment that you realise that you need different tests for a > subclass, and now you can't using subclassing because they aren't > subclasses, they're completely independent classes that happen to duplicate > the same methods. > > If the tests for your AVL tree and it's subclasses are *identical*, then > what's the point of the subclasses? The subclass has a key-function as a static method similar to the key argument for sort. This way I can have a tree with strings as keys, but with the keys sorted according to the locale with the locale.strxfrm function. This means the only tests that need changing are the tests that test for iterators to deliver the items in sorted order. But that can be done by letting the test check for the presence of the keyfunction and in that case, use if to check if things are in order. -- Antoon From random832 at fastmail.com Sat Apr 16 16:44:30 2016 From: random832 at fastmail.com (Random832) Date: Sat, 16 Apr 2016 16:44:30 -0400 Subject: Falsehoods People Believe about PEP 8 (was: Guido sees the light: PEP 8 updated) In-Reply-To: <85potpuwwt.fsf_-_@benfinney.id.au> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <85potpuwwt.fsf_-_@benfinney.id.au> Message-ID: <1460839470.2322496.580822385.2D74AE6C@webmail.messagingengine.com> On Sat, Apr 16, 2016, at 16:21, Ben Finney wrote: > * Oh, come on, no-one would use U+000C FORM FEED in source code. Some text editors have shortcuts to navigate to the previous/next line that begins with a form feed. From dan at tombstonezero.net Sat Apr 16 17:22:48 2016 From: dan at tombstonezero.net (Dan Sommers) Date: Sat, 16 Apr 2016 21:22:48 -0000 (UTC) Subject: Falsehoods People Believe about PEP 8 (was: Guido sees the light: PEP 8 updated) References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <85potpuwwt.fsf_-_@benfinney.id.au> <1460839470.2322496.580822385.2D74AE6C@webmail.messagingengine.com> Message-ID: On Sat, 16 Apr 2016 16:44:30 -0400, Random832 wrote: > On Sat, Apr 16, 2016, at 16:21, Ben Finney wrote: >> * Oh, come on, no-one would use U+000C FORM FEED in source code. > > Some text editors have shortcuts to navigate to the previous/next line > that begins with a form feed. Add these to the list of myths: * All producers use the same tools to produce code. * All consumers use the same tools to consume code. * All entities that produce and consume code use the same tools. * All entities use the same tools to consume code that they do to produce it. From rosuav at gmail.com Sat Apr 16 17:23:25 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Apr 2016 07:23:25 +1000 Subject: Fraud In-Reply-To: <444136AD-6A91-4BCE-B80F-6D1B5A8F4B65@yahoo.com> References: <444136AD-6A91-4BCE-B80F-6D1B5A8F4B65@yahoo.com> Message-ID: On Sun, Apr 17, 2016 at 3:12 AM, Mel Drosis via Python-list wrote: > > My phone my accounts my home network have all been affected because of someone using coding from Python and Linux and GitHub and json. I don't even know what this stuff is but how do I get rid of it all. It's ruined my life. > You don't need Python help after an attack like this any more than you need an automotive mechanic after you've been run over by a car. What you need is someone who can help you repair your systems and fix your security; I suggest looking locally in your area for a computer expert. ChrisA From rosuav at gmail.com Sat Apr 16 17:34:20 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Apr 2016 07:34:20 +1000 Subject: Falsehoods People Believe about PEP 8 (was: Guido sees the light: PEP 8 updated) In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <85potpuwwt.fsf_-_@benfinney.id.au> <1460839470.2322496.580822385.2D74AE6C@webmail.messagingengine.com> Message-ID: On Sun, Apr 17, 2016 at 7:22 AM, Dan Sommers wrote: > On Sat, 16 Apr 2016 16:44:30 -0400, Random832 wrote: > >> On Sat, Apr 16, 2016, at 16:21, Ben Finney wrote: >>> * Oh, come on, no-one would use U+000C FORM FEED in source code. >> >> Some text editors have shortcuts to navigate to the previous/next line >> that begins with a form feed. > > Add these to the list of myths: > > * All producers use the same tools to produce code. > * All consumers use the same tools to consume code. > * All entities that produce and consume code use the same tools. > * All entities use the same tools to consume code that they do to produce it. Those are definitely myths, but are they sufficiently connected to PEP 8? ChrisA From python.list at tim.thechases.com Sat Apr 16 17:50:27 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 16 Apr 2016 16:50:27 -0500 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <85vb3huxjn.fsf@benfinney.id.au> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <85vb3huxjn.fsf@benfinney.id.au> Message-ID: <20160416165027.0fe70e5f@bigbox.christie.dr> On 2016-04-17 06:08, Ben Finney wrote: > Larry Martell writes: > > if we still had 1970's 80 character TTYs that would matter but on > > my 29" 1920x1080 screen it doesn't. > > Larry, you've been around long enough to know that's not an argument > against a limited line length for code. It is not about the > technology of your terminal. It's about the technology of the brain > reading the text. But just in case you do want to consider hardware limits, I do some of my coding on my phone & tablet, both of which are ~80 characters wide at best (or less if I use the phone in portrait mode). I also do some editing/diffing within a cmd.exe window on Windows which is limited to 80 characters unless you do some hijinks in the settings to expand it. -tkc From ykt2271707491 at gmail.com Sat Apr 16 17:53:48 2016 From: ykt2271707491 at gmail.com (ykt2271707491 at gmail.com) Date: Sat, 16 Apr 2016 14:53:48 -0700 (PDT) Subject: Python2.7 win64 --- cannot install the package of scipy Message-ID: <66c616a4-a36f-437e-9ce0-e7694d28af7a@googlegroups.com> I failed to install the package of scipy on Python2.7(win64). 1. I tried the direct way that use cmd--pip install scripy. The result shows that it failed with error code 1 in c:\tyk\appdata\local\temp\pip-build-an9fye\scipy\. 2. I tried to install in another way. I download the scipy-0.17.0-cp27-none-win_amd64.whl from Unofficial Windows Binaries for Python Extension Packages. And use cmd to install that in the Scripts direction, but still failed.(I have installed the package wheel already). The result shows that scipy-0.17.0-cp27-none-win_amd64.whl is not a supported wheel on this platform. Would someone provide a pointer? Much appreciated! From joel.goldstick at gmail.com Sat Apr 16 18:02:50 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 16 Apr 2016 18:02:50 -0400 Subject: Fraud In-Reply-To: References: <444136AD-6A91-4BCE-B80F-6D1B5A8F4B65@yahoo.com> Message-ID: On Sat, Apr 16, 2016 at 5:23 PM, Chris Angelico wrote: > On Sun, Apr 17, 2016 at 3:12 AM, Mel Drosis via Python-list > wrote: >> >> My phone my accounts my home network have all been affected because of someone using coding from Python and Linux and GitHub and json. I don't even know what this stuff is but how do I get rid of it all. It's ruined my life. >> > > You don't need Python help after an attack like this any more than you > need an automotive mechanic after you've been run over by a car. What > you need is someone who can help you repair your systems and fix your > security; I suggest looking locally in your area for a computer > expert. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list Help, I've fallen down and I can't reach my beer! Sorry :( I'm curious as to what makes you think all this trouble was caused by python, etc. Did they leave a note? -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From timothy.c.delaney at gmail.com Sat Apr 16 18:15:55 2016 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Sun, 17 Apr 2016 08:15:55 +1000 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <20160416165027.0fe70e5f@bigbox.christie.dr> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <85vb3huxjn.fsf@benfinney.id.au> <20160416165027.0fe70e5f@bigbox.christie.dr> Message-ID: On 17 April 2016 at 07:50, Tim Chase wrote: > On 2016-04-17 06:08, Ben Finney wrote: > > Larry Martell writes: > > > if we still had 1970's 80 character TTYs that would matter but on > > > my 29" 1920x1080 screen it doesn't. > > > > Larry, you've been around long enough to know that's not an argument > > against a limited line length for code. It is not about the > > technology of your terminal. It's about the technology of the brain > > reading the text. > > But just in case you do want to consider hardware limits, I do some > of my coding on my phone & tablet, both of which are ~80 characters > wide at best (or less if I use the phone in portrait mode). I also do > some editing/diffing within a cmd.exe window on Windows which is > limited to 80 characters unless you do some hijinks in the settings > to expand it. > Personally, I've given up on 80 characters (or even 120 in rare cases) for Java code (esp method declarations), where just specifying the generics can often take almost that much. But for Python code it's generally fairly easy to break a line in a natural place. Tim Delaney From python at lucidity.plus.com Sat Apr 16 18:21:53 2016 From: python at lucidity.plus.com (Erik) Date: Sat, 16 Apr 2016 23:21:53 +0100 Subject: Fraud In-Reply-To: References: <444136AD-6A91-4BCE-B80F-6D1B5A8F4B65@yahoo.com> Message-ID: <5712BB01.4010001@lucidity.plus.com> On 16/04/16 23:02, Joel Goldstick wrote: >> On Sun, Apr 17, 2016 at 3:12 AM, Mel Drosis via Python-list >> wrote: >>> >>> My phone my accounts my home network have all been affected because of someone using coding from Python and Linux and GitHub and json. I don't even know what this stuff is but how do I get rid of it all. It's ruined my life. > I'm curious as to what makes you think all this trouble was caused by > python, etc. Did they leave a note? If this is genuine, then I don't want to be dismissive of the plea. However, given that Chris's response is quite enough for a genuine request to find a solution, I'll say that I smell a feint hint of troll ... :) E From marko at pacujo.net Sat Apr 16 18:30:07 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 17 Apr 2016 01:30:07 +0300 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <85vb3huxjn.fsf@benfinney.id.au> <20160416165027.0fe70e5f@bigbox.christie.dr> Message-ID: <87potp5gr4.fsf@elektro.pacujo.net> Tim Delaney : > Personally, I've given up on 80 characters (or even 120 in rare cases) > for Java code (esp method declarations), where just specifying the > generics can often take almost that much. Java generics ruined a perfectly good language. I mean: Map> customersOfAccountManager = new HashMap>(); where classic Java would have: Map customersOfAccountManager = new HashMap(); and Python simply: customers_of_account_manager = {} However, even during my Java years, I didn't give up on the 79-character religion (see above). Marko From torriem at gmail.com Sat Apr 16 18:31:32 2016 From: torriem at gmail.com (Michael Torrie) Date: Sat, 16 Apr 2016 16:31:32 -0600 Subject: Fraud In-Reply-To: <5712BB01.4010001@lucidity.plus.com> References: <444136AD-6A91-4BCE-B80F-6D1B5A8F4B65@yahoo.com> <5712BB01.4010001@lucidity.plus.com> Message-ID: <5712BD44.5030009@gmail.com> On 04/16/2016 04:21 PM, Erik wrote: > On 16/04/16 23:02, Joel Goldstick wrote: >>> On Sun, Apr 17, 2016 at 3:12 AM, Mel Drosis via Python-list >>> wrote: >>>> >>>> My phone my accounts my home network have all been affected because of someone using coding from Python and Linux and GitHub and json. I don't even know what this stuff is but how do I get rid of it all. It's ruined my life. > >> I'm curious as to what makes you think all this trouble was caused by >> python, etc. Did they leave a note? > > If this is genuine, then I don't want to be dismissive of the plea. > However, given that Chris's response is quite enough for a genuine > request to find a solution, I'll say that I smell a feint hint of troll > ... :) Reminds me of this classic story from 10 years ago: http://www.theregister.co.uk/2006/03/24/tuttle_centos/ From rosuav at gmail.com Sat Apr 16 18:33:23 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Apr 2016 08:33:23 +1000 Subject: Fraud In-Reply-To: <5712BB01.4010001@lucidity.plus.com> References: <444136AD-6A91-4BCE-B80F-6D1B5A8F4B65@yahoo.com> <5712BB01.4010001@lucidity.plus.com> Message-ID: On Sun, Apr 17, 2016 at 8:21 AM, Erik wrote: > On 16/04/16 23:02, Joel Goldstick wrote: >>> >>> On Sun, Apr 17, 2016 at 3:12 AM, Mel Drosis via Python-list >>> wrote: >>>> >>>> >>>> My phone my accounts my home network have all been affected because of >>>> someone using coding from Python and Linux and GitHub and json. I don't even >>>> know what this stuff is but how do I get rid of it all. It's ruined my life. > > >> I'm curious as to what makes you think all this trouble was caused by >> python, etc. Did they leave a note? > > > If this is genuine, then I don't want to be dismissive of the plea. However, > given that Chris's response is quite enough for a genuine request to find a > solution, I'll say that I smell a feint hint of troll ... :) It sounds fairly plausible. "Help, I just got 'got'! Now what?" *researches* "Hmm, I'm seeing a lot of stuff about Python and Linux and stuff. Where can I get help about Python?" The request is misdirected (we can't help), but not unreasonable IMO. ChrisA From wrh8609 at gmail.com Sat Apr 16 18:35:55 2016 From: wrh8609 at gmail.com (wrh8609 at gmail.com) Date: Sat, 16 Apr 2016 15:35:55 -0700 (PDT) Subject: how to setup for localhost:8000 In-Reply-To: References: <5ea1e31b-09ba-4b6a-be8b-58886c5c5f81@googlegroups.com> <2e597a56-00ab-4370-b337-667f34eac56a@googlegroups.com> Message-ID: <67abca1d-8ac5-4a9a-825d-3aa76d9ccf3f@googlegroups.com> On Friday, April 15, 2016 at 3:04:09 PM UTC-4, Pierre Quentel wrote: > Le jeudi 14 avril 2016 22:50:33 UTC+2, wrh... at gmail.com a ?crit?: > > On Thursday, April 14, 2016 at 2:23:36 PM UTC-4, Andrew Farrell wrote: > > > What happens when you type > > > > > > http://localhost:8000 > > > > > > Into the address bar of your browser as this is running? > > > > > > On Thu, Apr 14, 2016 at 12:46 PM, wrote: > > > > > > > Hi, > > > > > > > > I am working on window 7 and Python 3.5 to setup a localhost:8000 but it > > > > did not get through as shown below: > > > > > python -m http.server > > > > Serving HTTP on 0.0.0.0 port 8000 ... > > > > > > > > But it did not show the results. > > > > > > > > Can someone help me how to setup the localhost? > > > > > > > > Thanks, > > > > Wen-Ruey > > > > > > > > -- > > > > https://mail.python.org/mailman/listinfo/python-list > > > > > > > > hi Andrew, > > > > Yes. after I type http:\\localhost:8000, the browser did not show anything except a empty page without any errors. > > > > Thanks, > > Wen-Ruey > > Hi, > > When you type http://localhost:8000, do you see something in the console after the line "Serving HTTP on 0.0.0.0 port 8000 ..." ? > > If the server actually serves requests on port 8000 you should see a log message such as > > 127.0.0.1 - - [15/Apr/2016 20:57:32] "GET / HTTP/1.1" 200 - Hi Pierre, When I type http://localhost:8000, I did not see anything in the console after the line "Serving HTTP on 0.0.0.0 port 8000 ... I believe the way I ran was not correct as shown below: > python -m http.server Serving HTTP on 0.0.0.0 port 8000 ... Also if I use internet Explorer, it shows HTTP 404 errors. Do you think the way I am doing of the localhost:8000 setting was not correct? Thanks, Wen-Ruey From rosuav at gmail.com Sat Apr 16 19:11:14 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Apr 2016 09:11:14 +1000 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: On Sun, Apr 17, 2016 at 9:02 AM, Dennis Lee Bieber wrote: > I still miss the Amiga -- in which one could /push/ a window to the > back of the stack while still retaining input focus! Made it nice for > transcribing stuff from a visible window to a text input region while it > was obscured. OS/2 could do the same thing. I've tried to mess with it in various Linux desktops, but haven't really found what I want. ChrisA From grant.b.edwards at gmail.com Sat Apr 16 19:19:22 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 16 Apr 2016 23:19:22 +0000 (UTC) Subject: Guido sees the light: PEP 8 updated References: <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: On 2016-04-16, Dennis Lee Bieber wrote: > I still miss the Amiga -- in which one could /push/ a window to the > back of the stack while still retaining input focus! Made it nice for > transcribing stuff from a visible window to a text input region while it > was obscured. I do that all the time on Linux. What sort of brain-dead window manager doesn't allow that? -- Grant From ben.usenet at bsb.me.uk Sat Apr 16 19:25:00 2016 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Sun, 17 Apr 2016 00:25:00 +0100 Subject: Guido sees the light: PEP 8 updated References: <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: <87zistp25v.fsf@bsb.me.uk> Dennis Lee Bieber writes: > I still miss the Amiga -- in which one could /push/ a window to the > back of the stack while still retaining input focus! Made it nice for > transcribing stuff from a visible window to a text input region while it > was obscured. That was commonly available on Unix window managers and is still around. I use it on even an up-to-date Linux/Gnome3 system (you set focus follows mouse rather than focus on click). -- Ben. From rosuav at gmail.com Sat Apr 16 19:33:40 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Apr 2016 09:33:40 +1000 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <87zistp25v.fsf@bsb.me.uk> References: <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <87zistp25v.fsf@bsb.me.uk> Message-ID: On Sun, Apr 17, 2016 at 9:25 AM, Ben Bacarisse wrote: > Dennis Lee Bieber writes: > >> I still miss the Amiga -- in which one could /push/ a window to the >> back of the stack while still retaining input focus! Made it nice for >> transcribing stuff from a visible window to a text input region while it >> was obscured. > > That was commonly available on Unix window managers and is still around. > I use it on even an up-to-date Linux/Gnome3 system (you set focus > follows mouse rather than focus on click). Focus follows mouse is annoying for other reasons though. ChrisA From dan at tombstonezero.net Sat Apr 16 19:35:06 2016 From: dan at tombstonezero.net (Dan Sommers) Date: Sat, 16 Apr 2016 23:35:06 -0000 (UTC) Subject: Falsehoods People Believe about PEP 8 (was: Guido sees the light: PEP 8 updated) References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <85potpuwwt.fsf_-_@benfinney.id.au> <1460839470.2322496.580822385.2D74AE6C@webmail.messagingengine.com> Message-ID: On Sun, 17 Apr 2016 07:34:20 +1000, Chris Angelico wrote: > On Sun, Apr 17, 2016 at 7:22 AM, Dan Sommers wrote: >> On Sat, 16 Apr 2016 16:44:30 -0400, Random832 wrote: >> >>> On Sat, Apr 16, 2016, at 16:21, Ben Finney wrote: >>>> * Oh, come on, no-one would use U+000C FORM FEED in source code. >>> >>> Some text editors have shortcuts to navigate to the previous/next line >>> that begins with a form feed. >> >> Add these to the list of myths: >> >> * All producers use the same tools to produce code. >> * All consumers use the same tools to consume code. >> * All entities that produce and consume code use the same tools. >> * All entities use the same tools to consume code that they do to produce it. > > Those are definitely myths, but are they sufficiently connected to PEP 8? > > ChrisA PEP8 is all about readability, and we all read source code through one tool and/or another. Anecdotally, a lot of readability arguments (including that one about some text editors treating U+000C as a special case) end up being as much about the tools we use as they are about the source code itself. We (this mailing list, or maybe it was the python-ideas mailing list) just had a thread about non-ASCII characters in identifiers. One of the main argument against is the confusables (A vs ? vs ?). Sufficient tooling, however, could render (pun intended) that argument moot. Not too long ago, one of the main arguments against was that not everyone's tools could even render ? or ?. From wrightalexw at gmail.com Sat Apr 16 19:43:40 2016 From: wrightalexw at gmail.com (alex wright) Date: Sat, 16 Apr 2016 19:43:40 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <87zistp25v.fsf@bsb.me.uk> Message-ID: The 80 column limit probably helps protect us from the singularity. Once the robots take over we will have code with a digestible amount of logic per line and can fix what we have caused. In other words, Java is only armoring the robots against us for the inevitable battle. On Sat, Apr 16, 2016 at 7:33 PM, Chris Angelico wrote: > On Sun, Apr 17, 2016 at 9:25 AM, Ben Bacarisse > wrote: > > Dennis Lee Bieber writes: > > > >> I still miss the Amiga -- in which one could /push/ a window to > the > >> back of the stack while still retaining input focus! Made it nice for > >> transcribing stuff from a visible window to a text input region while it > >> was obscured. > > > > That was commonly available on Unix window managers and is still around. > > I use it on even an up-to-date Linux/Gnome3 system (you set focus > > follows mouse rather than focus on click). > > Focus follows mouse is annoying for other reasons though. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- "On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question." -Charles Babbage, 19th century English mathematician, philosopher, inventor and mechanical engineer who originated the concept of a programmable computer. From gheskett at wdtv.com Sat Apr 16 19:49:08 2016 From: gheskett at wdtv.com (Gene Heskett) Date: Sat, 16 Apr 2016 19:49:08 -0400 Subject: Fraud In-Reply-To: References: <444136AD-6A91-4BCE-B80F-6D1B5A8F4B65@yahoo.com> Message-ID: <201604161949.08423.gheskett@wdtv.com> On Saturday 16 April 2016 18:02:50 Joel Goldstick wrote: > On Sat, Apr 16, 2016 at 5:23 PM, Chris Angelico wrote: > > On Sun, Apr 17, 2016 at 3:12 AM, Mel Drosis via Python-list > > > > wrote: > >> My phone my accounts my home network have all been affected because > >> of someone using coding from Python and Linux and GitHub and json. > >> I don't even know what this stuff is but how do I get rid of it > >> all. It's ruined my life. > > > > You don't need Python help after an attack like this any more than > > you need an automotive mechanic after you've been run over by a car. > > What you need is someone who can help you repair your systems and > > fix your security; I suggest looking locally in your area for a > > computer expert. > > > > ChrisA > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Help, I've fallen down and I can't reach my beer! > > Sorry :( > I haven't fallen, and I can reach my beer, but in this factless post, beer doesn't help. :) > I'm curious as to what makes you think all this trouble was caused by > python, etc. Did they leave a note? > > -- > Joel Goldstick > http://joelgoldstick.com/blog > http://cc-baseballstats.info/stats/birthdays 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 python.list at tim.thechases.com Sat Apr 16 20:12:54 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 16 Apr 2016 19:12:54 -0500 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: <20160416191254.38be21e8@bigbox.christie.dr> On 2016-04-16 19:02, Dennis Lee Bieber wrote: > I still miss the Amiga -- in which one could /push/ a > window to the back of the stack while still retaining input focus! > Made it nice for transcribing stuff from a visible window to a text > input region while it was obscured. What OS (or if X-based, which window-manager) do you use? I have Mod4 Next :LowerLayer Mod4 Prior :RaiseLayer in my ~/.fluxbox/keys configuration which lets me use the logo key with pageup/pagedown to raise/lower the focus of the current window. I find that most of the time I want to raise one particular window above all other windows (most of the time I end up closing it when done, but sometimes I want to lower it back down to the main application layer). -tkc From joel.goldstick at gmail.com Sat Apr 16 20:20:13 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 16 Apr 2016 20:20:13 -0400 Subject: Fraud In-Reply-To: <201604161949.08423.gheskett@wdtv.com> References: <444136AD-6A91-4BCE-B80F-6D1B5A8F4B65@yahoo.com> <201604161949.08423.gheskett@wdtv.com> Message-ID: On Sat, Apr 16, 2016 at 7:49 PM, Gene Heskett wrote: > On Saturday 16 April 2016 18:02:50 Joel Goldstick wrote: > >> On Sat, Apr 16, 2016 at 5:23 PM, Chris Angelico > wrote: >> > On Sun, Apr 17, 2016 at 3:12 AM, Mel Drosis via Python-list >> > >> > wrote: >> >> My phone my accounts my home network have all been affected because >> >> of someone using coding from Python and Linux and GitHub and json. >> >> I don't even know what this stuff is but how do I get rid of it >> >> all. It's ruined my life. >> > >> > You don't need Python help after an attack like this any more than >> > you need an automotive mechanic after you've been run over by a car. >> > What you need is someone who can help you repair your systems and >> > fix your security; I suggest looking locally in your area for a >> > computer expert. >> > >> > ChrisA >> > -- >> > https://mail.python.org/mailman/listinfo/python-list >> >> Help, I've fallen down and I can't reach my beer! >> >> Sorry :( >> > I haven't fallen, and I can reach my beer, but in this factless post, > beer doesn't help. :) > >> I'm curious as to what makes you think all this trouble was caused by >> python, etc. Did they leave a note? >> >> -- >> Joel Goldstick >> http://joelgoldstick.com/blog >> http://cc-baseballstats.info/stats/birthdays > > > 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 > -- > https://mail.python.org/mailman/listinfo/python-list Sorry Gene, but I'm a long time reader and sometimes contributor to this list, and there are some things that are just a bit nutty. I imagine that this post is from someone who really is upset, but his response to the list is really a bit silly in my opinion. It isn't about python, so I thought I'd be light hearted. As it turns out, the OP hasn't engaged in any further back and forth, which to me enforces my original post. -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From python at mrabarnett.plus.com Sat Apr 16 20:24:19 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 17 Apr 2016 01:24:19 +0100 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: <5712D7B3.5090404@mrabarnett.plus.com> On 2016-04-17 00:11, Chris Angelico wrote: > On Sun, Apr 17, 2016 at 9:02 AM, Dennis Lee Bieber > wrote: >> I still miss the Amiga -- in which one could /push/ a window to the >> back of the stack while still retaining input focus! Made it nice for >> transcribing stuff from a visible window to a text input region while it >> was obscured. > > OS/2 could do the same thing. I've tried to mess with it in various > Linux desktops, but haven't really found what I want. > You could also do that on Acorn's RISC OS. From ben.usenet at bsb.me.uk Sat Apr 16 20:29:49 2016 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Sun, 17 Apr 2016 01:29:49 +0100 Subject: Guido sees the light: PEP 8 updated References: <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <87zistp25v.fsf@bsb.me.uk> Message-ID: <87oa99oz5u.fsf@bsb.me.uk> Chris Angelico writes: > On Sun, Apr 17, 2016 at 9:25 AM, Ben Bacarisse wrote: >> Dennis Lee Bieber writes: >> >>> I still miss the Amiga -- in which one could /push/ a window to the >>> back of the stack while still retaining input focus! Made it nice for >>> transcribing stuff from a visible window to a text input region while it >>> was obscured. >> >> That was commonly available on Unix window managers and is still around. >> I use it on even an up-to-date Linux/Gnome3 system (you set focus >> follows mouse rather than focus on click). > > Focus follows mouse is annoying for other reasons though. Sure. But if you want it only sometimes you can bind a key to turn it on or off so you can have it only momentarily. The other way is to bind a key (if not already bound) to the "lower winder" action. That won't (or shouldn't) alter the focus and will push the window under the one you want to see. -- Ben. From random832 at fastmail.com Sat Apr 16 20:54:00 2016 From: random832 at fastmail.com (Random832) Date: Sat, 16 Apr 2016 20:54:00 -0400 Subject: Fraud In-Reply-To: References: <444136AD-6A91-4BCE-B80F-6D1B5A8F4B65@yahoo.com> <201604161949.08423.gheskett@wdtv.com> Message-ID: <1460854440.2366362.580922841.07DFDE6F@webmail.messagingengine.com> On Sat, Apr 16, 2016, at 20:20, Joel Goldstick wrote: > As it turns out, the OP hasn't engaged in any further back and forth, > which to me enforces my original post. It's entirely possible he's not subscribed to the mailing list. From steve at pearwood.info Sat Apr 16 21:17:01 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 17 Apr 2016 11:17:01 +1000 Subject: sys.exit(1) vs raise SystemExit vs raise References: <20160416034833.GA24653@cskk.homeip.net> <858u0ew5qg.fsf@benfinney.id.au> <1460784872.1843058.580428001.63445E11@webmail.messagingengine.com> <85zisuujn9.fsf@benfinney.id.au> Message-ID: <5712e40e$0$1593$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Apr 2016 02:09 am, Dennis Lee Bieber wrote: > VMS had a whole slew of "no error" status values (essentially all > positive odd integers were "success", but different values carried > additional information. 1 = success 3 = success against all odds 5 = success but at great cost 7 = success, and it was as easy as falling off a log 9 = success, and it was so easy you ought to be ashamed for asking the computer to do it instead of doing it yourself 11 = I told you I already did it yesterday 13 = done, but it wasn't worth doing 15 = well that was easier than I expected 17 = that was harder than I expected 19 = I did it, but I'm not going to do it again > Even integers were errors [I forget if positive or > negative were "warnings" vs "error"]) > > True, the simplest was "1", which just carried "success -- no > additional details" and "0" was "unspecified failure". -- Steven From steve at pearwood.info Sat Apr 16 21:27:33 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 17 Apr 2016 11:27:33 +1000 Subject: Fraud References: <444136AD-6A91-4BCE-B80F-6D1B5A8F4B65@yahoo.com> Message-ID: <5712e685$0$1597$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Apr 2016 03:12 am, Mel Drosis wrote: > > My phone my accounts my home network have all been affected because of > someone using coding from Python and Linux and GitHub and json. I don't > even know what this stuff is but how do I get rid of it all. It's ruined > my life. Sent from my iPhone Go to Russia. Find a corrupt Russian general. Purchase the biggest nuclear warhead you can afford, at least 20 megatons. Launch it into space and detonate it in near-Earth orbit. When the radiation hits the atmosphere, it will generate the mother of all electromagnetic pulses. Which will permanently fry all computer chips and most electronics all over the world, sending the entire planet back to pre-Industrial Revolution technology. (You may need to do it twice, once for each hemisphere.) Which is the only way to get rid of the scourge of "Python and Linux and GitHub and json" once and for all. -- Steven From python.list at tim.thechases.com Sat Apr 16 21:30:52 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 16 Apr 2016 20:30:52 -0500 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <85vb3huxjn.fsf@benfinney.id.au> <20160416165027.0fe70e5f@bigbox.christie.dr> Message-ID: <20160416203052.2598ad15@bigbox.christie.dr> On 2016-04-16 19:39, eryk sun wrote: > On Sat, Apr 16, 2016 at 4:50 PM, Tim Chase wrote: > > I also do some editing/diffing within a cmd.exe window on Windows > > which is limited to 80 characters unless you do some hijinks in > > the settings to expand it. > > Try `mode con cols=120 lines=30`. Yeah, that will do it, as will going into the settings and changing it. But basically every other program on Windows, and every console on Linux/BSD/Mac will let me resize a terminal running while another program is running. For a cmd.exe window, I have to quit, issue the `mode` command, restart my application, and return to where I was. -tkc From blueridiculous at gmail.com Sat Apr 16 21:31:19 2016 From: blueridiculous at gmail.com (blueridiculous at gmail.com) Date: Sat, 16 Apr 2016 18:31:19 -0700 (PDT) Subject: error with tkinter, help Message-ID: <47977d70-6208-4e68-aca3-e1f63aacfac7@googlegroups.com> So I was reading https://wiki.python.org/moin/TkInter for help. I got to step 3 under "Checking your Tkinter support." Nothing happens when I do steps 1 or 2, and when I do step 3, I get this error: " Traceback (most recent call last): File "", line 301, in runcode File "", line 1, in File "C:\Python34\lib\tkinter\__init__.py", line 3882, in _test root = Tk() File "C:\Python34\lib\tkinter\__init__.py", line 1856, in __init__ self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) _tkinter.TclError: Can't find a usable init.tcl in the following directories: C:/Python34/lib/tcl8.6 C:/lib/tcl8.6 C:/lib/tcl8.6 C:/library C:/library C:/tcl8.6.1/library C:/tcl8.6.1/library This probably means that Tcl wasn't installed properly. " What should I do to get Tkinter working? Sorry if the answer should be obvious to me; I am not very experienced with Python. From steve at pearwood.info Sat Apr 16 21:38:10 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 17 Apr 2016 11:38:10 +1000 Subject: Falsehoods People Believe about PEP 8 (was: Guido sees the light: PEP 8 updated) References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <85potpuwwt.fsf_-_@benfinney.id.au> <1460839470.2322496.580822385.2D74AE6C@webmail.messagingengine.com> Message-ID: <5712e903$0$1597$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Apr 2016 06:44 am, Random832 wrote: > On Sat, Apr 16, 2016, at 16:21, Ben Finney wrote: >> * Oh, come on, no-one would use U+000C FORM FEED in source code. > > Some text editors have shortcuts to navigate to the previous/next line > that begins with a form feed. Are you saying that's a falsehood? -- Steven From steve at pearwood.info Sat Apr 16 21:48:11 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 17 Apr 2016 11:48:11 +1000 Subject: Falsehoods People Believe about PEP 8 (was: Guido sees the light: PEP 8 updated) References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <85potpuwwt.fsf_-_@benfinney.id.au> <1460839470.2322496.580822385.2D74AE6C@webmail.messagingengine.com> Message-ID: <5712eb5c$0$1604$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Apr 2016 09:35 am, Dan Sommers wrote: > We (this mailing list, or maybe it was the python-ideas mailing list) > just had a thread about non-ASCII characters in identifiers. One of the > main argument against is the confusables (A vs ? vs ?). Sufficient > tooling, however, could render (pun intended) that argument moot. Not > too long ago, one of the main arguments against was that not everyone's > tools could even render ? or ?. Technically speaking, they still might not. My editor can render both Cyrillic and Greek characters, but does a terrible job at Chinese and Korean because I don't have the font support. So all I see is a series of "missing character" boxes. There may be folks who don't have installed fonts that support Cyrillic or Greek. -- Steven From random832 at fastmail.com Sat Apr 16 21:59:01 2016 From: random832 at fastmail.com (Random832) Date: Sat, 16 Apr 2016 21:59:01 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <20160416203052.2598ad15@bigbox.christie.dr> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <85vb3huxjn.fsf@benfinney.id.au> <20160416165027.0fe70e5f@bigbox.christie.dr> <20160416203052.2598ad15@bigbox.christie.dr> Message-ID: <1460858341.2377173.580944673.0F0ECA86@webmail.messagingengine.com> On Sat, Apr 16, 2016, at 21:30, Tim Chase wrote: > On 2016-04-16 19:39, eryk sun wrote: > > On Sat, Apr 16, 2016 at 4:50 PM, Tim Chase wrote: > > > I also do some editing/diffing within a cmd.exe window on Windows > > > which is limited to 80 characters unless you do some hijinks in > > > the settings to expand it. > > > > Try `mode con cols=120 lines=30`. > > Yeah, that will do it, as will going into the settings and changing > it. But basically every other program on Windows, and every console > on Linux/BSD/Mac will let me resize a terminal running while another > program is running. For a cmd.exe window, I have to quit, issue the > `mode` command, restart my application, and return to where I was. Well, if your interactive application allows you to run commands within it, you don't have to quit. Plus you can always go into the settings window, I don't know what's "hijinks" about that. I heard Windows 10 is going to finally fix this, anyway. From steve at pearwood.info Sat Apr 16 22:36:12 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 17 Apr 2016 12:36:12 +1000 Subject: Introducing the secrets module Message-ID: <5712f69d$0$1585$c3e8da3$5496439d@news.astraweb.com> I'm pleased to announce a new standard library module for Python 3.6 and better, to aid in generating secure tokens for authentication and other secrets. Last year, the founder of OpenBSD Theo de Raadt contacted Guido van Rossum with concerns that the Python standard library made it too easy for people to generate insecure tokens, session keys and related data. The problem is that developers may use the random module for generating tokens which need to be hard to guess. However the random module uses the Mersenne Twister by default, which is designed for simulation and modelling and is not suitable for cryptographic purposes. Consequently such tokens may be insecure. After much discussion, it was decided to leave the random module as-is, but introduce a new module which would can be used to generate hard-to-guess (cryptographically strong) tokens and random numbers: the secrets module. See the PEP for more details: https://www.python.org/dev/peps/pep-0506/ And the documentation: https://docs.python.org/3.6/library/secrets.html Comments requested. -- Steven From rustompmody at gmail.com Sat Apr 16 23:44:06 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 16 Apr 2016 20:44:06 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: <878u0d7az5.fsf@elektro.pacujo.net> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> On Saturday, April 16, 2016 at 10:22:10 PM UTC+5:30, Marko Rauhamaa wrote: > Larry Martell : > > > I have worked for many companies where you are required to get a clean > > run of pep8 on your code before your pull request will even be > > considered for approval. I don't agree with this at all, as I think it > > makes the code very ugly, especially enforcing the max line length. > > Agh, I was with you until your last remark. Count me in the "80-chars is ante-deluvian gunk" camp > > A max line length of 79 characters is among the *only* rigorous > principles I judge coding style on. > > It comes with the maxim that one function must be visible at once on the > screen. Thats a strange self-contradiction. I wrote this: http://blog.languager.org/2012/10/layout-imperative-in-functional.html to make the case against PEP8 style line length strictures. Which has the SAME code formatted in two styles: -- < 80 cols, 48 lines -- 115 cols 37 lines Clearly the 115 cols is MORE fittable in a page than the 80 cols [Though my argument for that is based on other structural/semantic principles] Should mention an irony here though: When I first wrote it, the examples were inline and blogger was breaking the lines randomly completely invalidating my point. IIRC blogger was breaking at 68 cols -- invalidating the 80 cols from the other side. Clearly 80 cols is more portable than longer. However if we literally implement the view that different people use different technologies -- AND WE SHOULD SUPPORT THEM ALL -- then notepad becomes the ineluctable gold standard. From rosuav at gmail.com Sat Apr 16 23:49:17 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Apr 2016 13:49:17 +1000 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> Message-ID: On Sun, Apr 17, 2016 at 1:44 PM, Rustom Mody wrote: > Thats a strange self-contradiction. I wrote this: > http://blog.languager.org/2012/10/layout-imperative-in-functional.html > to make the case against PEP8 style line length strictures. > Which has the SAME code formatted in two styles: > > -- < 80 cols, 48 lines > -- 115 cols 37 lines > > Clearly the 115 cols is MORE fittable in a page than the 80 cols > [Though my argument for that is based on other structural/semantic principles] There are certain specific situations where 80 (79) is the correct width to aim for, but even if you aren't going for that, there's still the general principle that longer lines are harder to read. So maybe you declare that your codebase is allowed to go to 100, or 120, but you don't want to let it run to 2048. No matter WHAT screen you're on, that's too wide! ChrisA From dan at tombstonezero.net Sat Apr 16 23:52:34 2016 From: dan at tombstonezero.net (Dan Sommers) Date: Sun, 17 Apr 2016 03:52:34 -0000 (UTC) Subject: Falsehoods People Believe about PEP 8 (was: Guido sees the light: PEP 8 updated) References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <85potpuwwt.fsf_-_@benfinney.id.au> <1460839470.2322496.580822385.2D74AE6C@webmail.messagingengine.com> <5712eb5c$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 17 Apr 2016 11:48:11 +1000, Steven D'Aprano wrote: > On Sun, 17 Apr 2016 09:35 am, Dan Sommers wrote: > >> We (this mailing list, or maybe it was the python-ideas mailing list) >> just had a thread about non-ASCII characters in identifiers. One of >> the main argument against is the confusables (A vs ? vs ?). >> Sufficient tooling, however, could render (pun intended) that >> argument moot. Not too long ago, one of the main arguments against >> was that not everyone's tools could even render ? or ?. > > Technically speaking, they still might not. My editor can render both > Cyrillic and Greek characters, but does a terrible job at Chinese and > Korean because I don't have the font support. So all I see is a series > of "missing character" boxes. There may be folks who don't have > installed fonts that support Cyrillic or Greek. I think we're agreeing. Not everyone's tools render the same source code the same way, which means that at least some part of readability depends on the tools people use. People who use screen readers rather than visual displays probably wonder why the rest of us can't tell our "l"s from our "1"s and our "O"s from our "0"s. If PEP8 is about readability, then it should dispell the myth that everyone perceives source code the same way through the same tools. From nimbiotics at gmail.com Sun Apr 17 00:11:28 2016 From: nimbiotics at gmail.com (Mario R. Osorio) Date: Sat, 16 Apr 2016 21:11:28 -0700 (PDT) Subject: Fraud In-Reply-To: References: <444136AD-6A91-4BCE-B80F-6D1B5A8F4B65@yahoo.com> Message-ID: <00b95c52-d4e6-40a3-a431-0510d5c4dbad@googlegroups.com> Mel: Portuguese for honey Drosis: from Greek hidr?s; to sweat From tjreedy at udel.edu Sun Apr 17 00:29:18 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 17 Apr 2016 00:29:18 -0400 Subject: error with tkinter, help In-Reply-To: <47977d70-6208-4e68-aca3-e1f63aacfac7@googlegroups.com> References: <47977d70-6208-4e68-aca3-e1f63aacfac7@googlegroups.com> Message-ID: On 4/16/2016 9:31 PM, blueridiculous at gmail.com wrote: > So I was reading https://wiki.python.org/moin/TkInter for help. > I got to step 3 under "Checking your Tkinter support." > Nothing happens when I do steps 1 or 2, and when I do step 3, > I get this error: > > Traceback (most recent call last): > File "", line 301, in runcode > File "", line 1, in > File "C:\Python34\lib\tkinter\__init__.py", line 3882, in _test > root = Tk() > File "C:\Python34\lib\tkinter\__init__.py", line 1856, in __init__ > self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) > _tkinter.TclError: Can't find a usable init.tcl in the following directories: > C:/Python34/lib/tcl8.6 C:/lib/tcl8.6 C:/lib/tcl8.6 C:/library C:/library C:/tcl8.6.1/library C:/tcl8.6.1/library > > This probably means that Tcl wasn't installed properly. > " The directory list is obsolete. You should have C:/Python34/tcl How did you install Python? The Windows PSF installer from python.org will create this directory unless you uncheck the box to include tcl/tk. -- Terry Jan Reedy From robertvstepp at gmail.com Sun Apr 17 00:43:22 2016 From: robertvstepp at gmail.com (boB Stepp) Date: Sat, 16 Apr 2016 23:43:22 -0500 Subject: Installation problem In-Reply-To: <000001d19814$707c3090$517491b0$@com> References: <000001d19814$707c3090$517491b0$@com> Message-ID: On Sat, Apr 16, 2016 at 2:16 PM, Jurell wrote: > I installed the Python program version 3.5.1 32 bit and the IDE I am going > to use is Wing IDE 101. The problem when I tried installing the python > program was as follows: "The program can`t start because > api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer. Try > reinstalling the program to fix this problem". What I did was uninstall > Python and reinstall it installed ,I proceed on to install the IDE then this > message appeared again. These sorts of questions get asked by many people. When I have an error message that I cannot figure out I do an Internet search for that error message. But since this is a Python-related question, I might first search the Python list archives at https://www.mail-archive.com/python-list at python.org/ or the Python Tutor list archives at https://www.mail-archive.com/tutor at python.org/ Doing the former (Searching just for "api-ms-win-crt-runtime-l1-1-0.dll") led me to this: https://www.mail-archive.com/python-list%40python.org/msg402592.html I have not looked at this in depth, but the second item mentioned (Since you state you have Win 7 64 bit.) seems appropriate. Usually I can solve my own problems much quicker this way than waiting on someone to respond on this (or other) mailing lists! BTW, if you are a beginner learning Python you might want to subscribe to the Python Tutor list as it is designed for those of us who are learning... boB From eryksun at gmail.com Sun Apr 17 01:01:30 2016 From: eryksun at gmail.com (eryk sun) Date: Sun, 17 Apr 2016 00:01:30 -0500 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <20160416203052.2598ad15@bigbox.christie.dr> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <85vb3huxjn.fsf@benfinney.id.au> <20160416165027.0fe70e5f@bigbox.christie.dr> <20160416203052.2598ad15@bigbox.christie.dr> Message-ID: On Sat, Apr 16, 2016 at 8:30 PM, Tim Chase wrote: > On 2016-04-16 19:39, eryk sun wrote: >> On Sat, Apr 16, 2016 at 4:50 PM, Tim Chase wrote: >> > I also do some editing/diffing within a cmd.exe window on Windows >> > which is limited to 80 characters unless you do some hijinks in >> > the settings to expand it. >> >> Try `mode con cols=120 lines=30`. > > Yeah, that will do it, as will going into the settings and changing > it. But basically every other program on Windows, and every console > on Linux/BSD/Mac will let me resize a terminal running while another > program is running. For a cmd.exe window, I have to quit, issue the > `mode` command, restart my application, and return to where I was. cmd.exe doesn't own a window. You probably meant the console host/server, conhost.exe. cmd has handles for StandardInput, StandardOutput, and StandardError -- which may be handles for console I/O, but not necessarily. I agree that the classic console window has a bad UI. It can only be resized up to the size of the screen buffer, which is not terribly useful. There's no way to change the screen buffer size when manually sizing the window. You have to either use the properties dialog or the API. In Python you can run mode.com via subprocess.call('mode.com con cols=120'). Or you can use ctypes to call GetConsoleScreenBufferInfoEx and SetConsoleScreenBufferInfoEx. The Windows 10 console is a significant step in the right direction. It automatically resizes the screen buffer with text wrapping, selects a text stream instead of a rectangle, and uses regular keyboard shortcuts such as Ctrl+C and Ctrl+V for copy and paste. It still has room for improvement, however. It doesn't support fonts that mix half-width and full-width glyphs. It can't display characters that use multiple WCHAR values, such as astral characters (UTF-16 surrogate pairs) and decomposed characters. It doesn't support ANSI/VT100 terminal emulation (but maybe this is in the works for the new Linux subsystem). From random832 at fastmail.com Sun Apr 17 01:10:40 2016 From: random832 at fastmail.com (Random832) Date: Sun, 17 Apr 2016 01:10:40 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <85vb3huxjn.fsf@benfinney.id.au> <20160416165027.0fe70e5f@bigbox.christie.dr> <20160416203052.2598ad15@bigbox.christie.dr> Message-ID: <1460869840.2418229.581008993.127F25A8@webmail.messagingengine.com> On Sun, Apr 17, 2016, at 01:01, eryk sun wrote: > It doesn't support fonts that mix half-width and full-width glyphs. This is the most baffling bit to me. I mean, it _has_ to, for Chinese, Japanese, and Korean users. This support obviously exists in the code. Why not extend it to everyone, instead of maintaining two versions of whatever it's doing? From srirajarajeswaridevikrupa at gmail.com Sun Apr 17 02:59:45 2016 From: srirajarajeswaridevikrupa at gmail.com (durgadevi1) Date: Sat, 16 Apr 2016 23:59:45 -0700 (PDT) Subject: Dynamic inputs In-Reply-To: References: <901a5b60-25b3-4e1c-9178-755bf668a5c5@googlegroups.com> Message-ID: On Saturday, April 16, 2016 at 5:31:39 PM UTC+8, Michael Selik wrote: > On Sat, Apr 16, 2016, 9:41 AM durgadevi1 < > srirajarajeswaridevikrupa at gmail.com> wrote: > > > what does dynamic inputs mean and how is it implemented in python > > programming? > > > > In what context did you hear or read the phrase "dynamic inputs"? > > > Oh I read it in my assignment manual. The sentence is "Use dynamic inputs to XOR the binary file. " Thanks for your replies :) From becon12 at hotmail.com Sun Apr 17 03:27:14 2016 From: becon12 at hotmail.com (B N) Date: Sun, 17 Apr 2016 08:27:14 +0100 Subject: No subject Message-ID: Foor ages, I have been trying to summon up courage learn how to program. I chose o start with Python. I found that when the ?black? screen comes on, I am unable to read/see any characters even if I turn up the brightness of the screen. So, I give up. I tried version 3.5.1. I shall be grateful for any help. Also I have not ben ale to save it on C/programmes/files Thank you Ben Sent from Mail for Windows 10 From eryksun at gmail.com Sun Apr 17 04:14:55 2016 From: eryksun at gmail.com (eryk sun) Date: Sun, 17 Apr 2016 03:14:55 -0500 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <1460869840.2418229.581008993.127F25A8@webmail.messagingengine.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <85vb3huxjn.fsf@benfinney.id.au> <20160416165027.0fe70e5f@bigbox.christie.dr> <20160416203052.2598ad15@bigbox.christie.dr> <1460869840.2418229.581008993.127F25A8@webmail.messagingengine.com> Message-ID: On Sun, Apr 17, 2016 at 12:10 AM, Random832 wrote: > > On Sun, Apr 17, 2016, at 01:01, eryk sun wrote: >> It doesn't support fonts that mix half-width and full-width glyphs. > > This is the most baffling bit to me. I mean, it _has_ to, for Chinese, > Japanese, and Korean users. This support obviously exists in the code. > Why not extend it to everyone, instead of maintaining two versions of > whatever it's doing? Right, the console implements this for CJK locales, in which case it uses 2 columns for a full-width character. But based on the public symbols, I'd guess that the implementation is tied to using a DBCS codepage: 0:004> x /1 /n conhostv2!*dbcs* ConhostV2!DBCS_SCREEN_BUFFER::CreateInstance ConhostV2!DBCS_SCREEN_BUFFER::`scalar deleting destructor' ConhostV2!DBCS_SCREEN_BUFFER::~DBCS_SCREEN_BUFFER ConhostV2!InitializeDbcsMisc ConhostV2!IsDBCSLeadByteConsole ConhostV2!ReCreateDbcsScreenBuffer ConhostV2!ReCreateDbcsScreenBufferWorker ConhostV2!RemoveDbcsMark ConhostV2!RemoveDbcsMarkAll ConhostV2!RemoveDbcsMarkCell ConhostV2!g_fIsDBCSACP Implementing this in a Western locale would need an implementation based on Unicode character properties. From sergio.am.spina at gmail.com Sun Apr 17 06:04:11 2016 From: sergio.am.spina at gmail.com (Sergio Spina) Date: Sun, 17 Apr 2016 03:04:11 -0700 (PDT) Subject: ReST: link bookmark Message-ID: I would know what is the way to implement in ReST a link bookmark like in this example: > > > >

This text stand for an example of text containing > a bookmarked target bookmark.

> >

So let's go all together to visit the bookmarked target > clicking on this link.

> > > The string that is the name of the anchor is produced by an algorithm and 1) cannot be left away and 2) cannot be seen in the printed document. Thanks. From bc at freeuk.com Sun Apr 17 06:04:40 2016 From: bc at freeuk.com (BartC) Date: Sun, 17 Apr 2016 11:04:40 +0100 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> Message-ID: On 17/04/2016 04:44, Rustom Mody wrote: > On Saturday, April 16, 2016 at 10:22:10 PM UTC+5:30, Marko Rauhamaa wrote: >> It comes with the maxim that one function must be visible at once on the >> screen. > > Thats a strange self-contradiction. I wrote this: > http://blog.languager.org/2012/10/layout-imperative-in-functional.html > to make the case against PEP8 style line length strictures. > Which has the SAME code formatted in two styles: > > -- < 80 cols, 48 lines > -- 115 cols 37 lines > > Clearly the 115 cols is MORE fittable in a page than the 80 cols > [Though my argument for that is based on other structural/semantic principles] Um, that's a different language, or does PEP8 apply to Haskell too? Haskell has a style that likes to be written horizontally (rather than have statements one after another - /on separate lines/ - as in imperative code). I also have trouble regarding that code as a single function, as it implements (AFAICS) an entire lexer. It resembles data more than anything else, and data presumably is allowed to be scrolled. Otherwise things would be very restrictive! -- Bartc From sergio.am.spina at gmail.com Sun Apr 17 06:14:41 2016 From: sergio.am.spina at gmail.com (Sergio Spina) Date: Sun, 17 Apr 2016 03:14:41 -0700 (PDT) Subject: ReST: link bookmark In-Reply-To: References: Message-ID: Il giorno domenica 17 aprile 2016 12:04:38 UTC+2, Sergio Spina ha scritto: > I would know what is the way to implement in ReST a link bookmark like in this example: > > > > > > > > >

This text stand for an example of text containing > > a bookmarked target bookmark.

> > > >

So let's go all together to visit the bookmarked target > > clicking on this link.

> > > > > > > > The string that is the name of the anchor is produced by an algorithm and 1) cannot be left away and 2) cannot be seen in the printed document. > > Thanks. The correct example is: > > > >

This text stand for an example of text containig > a target bookmark.

> >

So let's go all together to visit the target clicking > on this link.

> > > Sorry for the mispelling. From marko at pacujo.net Sun Apr 17 07:01:15 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 17 Apr 2016 14:01:15 +0300 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> Message-ID: <877ffw5wjo.fsf@elektro.pacujo.net> Rustom Mody : > On Saturday, April 16, 2016 at 10:22:10 PM UTC+5:30, Marko Rauhamaa wrote: >> A max line length of 79 characters is among the *only* rigorous >> principles I judge coding style on. >> >> It comes with the maxim that one function must be visible at once on the >> screen. > > Thats a strange self-contradiction. Why? You are allowed to break a function into subfunctions, you know. In fact, if you find yourself introducing coding "paragraphs" with comments: def f(...): # I'll start by doing this ... # segueing into the middle portion ... # and finish it off as follows ... you had better break those paragraphs off into separate functions. Just turn your comments into function names. Marko From rosuav at gmail.com Sun Apr 17 07:14:42 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Apr 2016 21:14:42 +1000 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <877ffw5wjo.fsf@elektro.pacujo.net> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> <877ffw5wjo.fsf@elektro.pacujo.net> Message-ID: On Sun, Apr 17, 2016 at 9:01 PM, Marko Rauhamaa wrote: > In fact, if you find yourself introducing coding "paragraphs" with > comments: > > def f(...): > # I'll start by doing this > ... > # segueing into the middle portion > ... > # and finish it off as follows > ... > > you had better break those paragraphs off into separate functions. Just > turn your comments into function names. It's really easy to do this in toy examples, isn't it? But the real world is not so wonderful, as Alice's nanny said. What more often happens is that, once the function exceeds the stipulated maximum, it gets split somewhat arbitrarily into a "master" function and several "part" functions, with each part having exactly one call site in the driver and exactly none elsewhere. Even if the partial functions have reasonable names (which they don't always), they're still tightly bound to the master, and end up still functioning as a single unit. Unless you can genuinely make that subfunction useful in some other context, there's not a lot of use splitting it into a function. You don't generally see those perfect "paragraphs" in real-world code. ChrisA From bc at freeuk.com Sun Apr 17 08:04:05 2016 From: bc at freeuk.com (BartC) Date: Sun, 17 Apr 2016 13:04:05 +0100 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> <877ffw5wjo.fsf@elektro.pacujo.net> Message-ID: On 17/04/2016 12:14, Chris Angelico wrote: > On Sun, Apr 17, 2016 at 9:01 PM, Marko Rauhamaa wrote: >> In fact, if you find yourself introducing coding "paragraphs" with >> comments: >> >> def f(...): >> # I'll start by doing this >> ... >> # segueing into the middle portion >> ... >> # and finish it off as follows >> ... >> >> you had better break those paragraphs off into separate functions. Just >> turn your comments into function names. > > It's really easy to do this in toy examples, isn't it? But the real > world is not so wonderful, as Alice's nanny said. What more often > happens is that, once the function exceeds the stipulated maximum, it > gets split somewhat arbitrarily into a "master" function and several > "part" functions, with each part having exactly one call site in the > driver and exactly none elsewhere. Even if the partial functions have > reasonable names (which they don't always), they're still tightly > bound to the master, and end up still functioning as a single unit. > > Unless you can genuinely make that subfunction useful in some other > context, there's not a lot of use splitting it into a function. You > don't generally see those perfect "paragraphs" in real-world code. With the additional problems that the sub-functions need a way of accessing the local and declared names of the 'master' function. That means creating an interface (possibly a custom one for each sub-function) so that the master's local variables can be shared. Except that a sub-function can't directly write to the local variables that would be simply shared in the original monolithic function. Besides, for a set of sub-functions that are only used by a master function F, they really belong as local functions in F. That makes it even bigger and more complex, although access to F's locals is simplified. -- bartc From marko at pacujo.net Sun Apr 17 08:10:17 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 17 Apr 2016 15:10:17 +0300 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> <877ffw5wjo.fsf@elektro.pacujo.net> Message-ID: <8737qk5tcm.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Apr 17, 2016 at 9:01 PM, Marko Rauhamaa wrote: >> In fact, if you find yourself introducing coding "paragraphs" with >> comments: >> >> def f(...): >> # I'll start by doing this >> ... >> # segueing into the middle portion >> ... >> # and finish it off as follows >> ... >> >> you had better break those paragraphs off into separate functions. Just >> turn your comments into function names. > > It's really easy to do this in toy examples, isn't it? But the real > world is not so wonderful, as Alice's nanny said. I do this in the real world, professionally. Been doing it for decades, and it hasn't failed me so far. Exceptions exist, but they are that: rare exceptions. > What more often happens is that, once the function exceeds the > stipulated maximum, it gets split somewhat arbitrarily into a "master" > function and several "part" functions, with each part having exactly > one call site in the driver and exactly none elsewhere. Even if the > partial functions have reasonable names (which they don't always), > they're still tightly bound to the master, and end up still > functioning as a single unit. And? That's a feature, not a bug. It makes you analyze your approach a bit more. It makes you give names to things. It makes it more likely that your solution really works. And the main thing: whoever needs to come and maintain your code will have an easier time understanding what your code is trying to accomplish. > Unless you can genuinely make that subfunction useful in some other > context, there's not a lot of use splitting it into a function. You > don't generally see those perfect "paragraphs" in real-world code. No, that's Software Engineering 101: you split your solution into subroutines regardless of whether those subroutines are needed in multiple places. (The main practical problem with the divide-and-conquer approach is the fact that you need to drag the context around. Sometimes you have to keep piling on function arguments, which spoil the visual advantages you are trying to gain by partitioning your solution. One obvious solution to the argument clutter is to carry the context in *the* object or *a* special-purpose context object.) The compactness requirement for the code discourages empty lines and commenting. If find that, too, a feature rather than a bug. The code should in general speak for itself. Well-chosen names and a compact, elegant structure communicate the intent of the code better than plain-English comments that will not stay current with the code anyway. Marko From irmen.NOSPAM at xs4all.nl Sun Apr 17 08:40:00 2016 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 17 Apr 2016 14:40:00 +0200 Subject: Introducing the secrets module In-Reply-To: <5712f69d$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <5712f69d$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5713841c$0$5916$e4fe514c@news.xs4all.nl> On 17-4-2016 4:36, Steven D'Aprano wrote: > And the documentation: > > https://docs.python.org/3.6/library/secrets.html > > > Comments requested. I've read about the "How many bytes should tokens use?" consideration. It suggests that to be secure, tokens need to have sufficient randomness. The default token length is subject to change at any time to remain secure against brute-force. However the API allows you to supply any token length, even one that is (a lot) shorter than the default. In view of the rationale for this new module ("Python's standard library makes it too easy for developers to inadvertently make serious security errors") should it perhaps not be allowed to use a value that is less than the default? Hm, perhaps it should not; enforcing this could break code suddenly in the future when the default is raised... Irmen From kliateni at gmail.com Sun Apr 17 09:12:05 2016 From: kliateni at gmail.com (Karim) Date: Sun, 17 Apr 2016 15:12:05 +0200 Subject: Fraud In-Reply-To: <5712e685$0$1597$c3e8da3$5496439d@news.astraweb.com> References: <444136AD-6A91-4BCE-B80F-6D1B5A8F4B65@yahoo.com> <5712e685$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57138BA5.8010301@gmail.com> On 17/04/2016 03:27, Steven D'Aprano wrote: > On Sun, 17 Apr 2016 03:12 am, Mel Drosis wrote: > >> My phone my accounts my home network have all been affected because of >> someone using coding from Python and Linux and GitHub and json. I don't >> even know what this stuff is but how do I get rid of it all. It's ruined >> my life. Sent from my iPhone > Go to Russia. > > Find a corrupt Russian general. > > Purchase the biggest nuclear warhead you can afford, at least 20 megatons. > > Launch it into space and detonate it in near-Earth orbit. > > When the radiation hits the atmosphere, it will generate the mother of all > electromagnetic pulses. > > Which will permanently fry all computer chips and most electronics all over > the world, sending the entire planet back to pre-Industrial Revolution > technology. > > (You may need to do it twice, once for each hemisphere.) > > Which is the only way to get rid of the scourge of "Python and Linux and > GitHub and json" once and for all. > > > Steven you make me laugh very loud. hahaha. From gheskett at wdtv.com Sun Apr 17 09:28:35 2016 From: gheskett at wdtv.com (Gene Heskett) Date: Sun, 17 Apr 2016 09:28:35 -0400 Subject: Fraud In-Reply-To: <57138BA5.8010301@gmail.com> References: <444136AD-6A91-4BCE-B80F-6D1B5A8F4B65@yahoo.com> <5712e685$0$1597$c3e8da3$5496439d@news.astraweb.com> <57138BA5.8010301@gmail.com> Message-ID: <201604170928.35713.gheskett@wdtv.com> On Sunday 17 April 2016 09:12:05 Karim wrote: > On 17/04/2016 03:27, Steven D'Aprano wrote: > > On Sun, 17 Apr 2016 03:12 am, Mel Drosis wrote: > >> My phone my accounts my home network have all been affected because > >> of someone using coding from Python and Linux and GitHub and json. > >> I don't even know what this stuff is but how do I get rid of it > >> all. It's ruined my life. Sent from my iPhone > > > > Go to Russia. > > > > Find a corrupt Russian general. > > > > Purchase the biggest nuclear warhead you can afford, at least 20 > > megatons. > > > > Launch it into space and detonate it in near-Earth orbit. > > > > When the radiation hits the atmosphere, it will generate the mother > > of all electromagnetic pulses. > > > > Which will permanently fry all computer chips and most electronics > > all over the world, sending the entire planet back to pre-Industrial > > Revolution technology. > > > > (You may need to do it twice, once for each hemisphere.) > > > > Which is the only way to get rid of the scourge of "Python and Linux > > and GitHub and json" once and for all. > > Steven you make me laugh very loud. > > hahaha. I stick around this list, lurking I think its called, to see what happens next, even to learn something when you folks are serious, and I do so appreciate a sense of humor with teeth. ;-) Good post, generated a BWG here. 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 ian.g.kelly at gmail.com Sun Apr 17 09:38:08 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 17 Apr 2016 07:38:08 -0600 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <87potp5gr4.fsf@elektro.pacujo.net> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <85vb3huxjn.fsf@benfinney.id.au> <20160416165027.0fe70e5f@bigbox.christie.dr> <87potp5gr4.fsf@elektro.pacujo.net> Message-ID: On Sat, Apr 16, 2016 at 4:30 PM, Marko Rauhamaa wrote: > > Java generics ruined a perfectly good language. I mean: > > Map> customersOfAccountManager = > new HashMap>(); > > where classic Java would have: > > Map customersOfAccountManager = new HashMap(); The diamond operator in JDK 7 makes this a lot more tolerable, IMO: Map> customersOfAccountManager = new HashMap<>(); From chforth at hccnet.nl Sun Apr 17 10:35:44 2016 From: chforth at hccnet.nl (Coos Haak) Date: Sun, 17 Apr 2016 16:35:44 +0200 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <85vb3huxjn.fsf@benfinney.id.au> <20160416165027.0fe70e5f@bigbox.christie.dr> <20160416203052.2598ad15@bigbox.christie.dr> Message-ID: <4winspmqbztx$.3syiofssbnnl.dlg@40tude.net> Op Sat, 16 Apr 2016 20:30:52 -0500 schreef Tim Chase: > On 2016-04-16 19:39, eryk sun wrote: >> On Sat, Apr 16, 2016 at 4:50 PM, Tim Chase wrote: >>> I also do some editing/diffing within a cmd.exe window on Windows >>> which is limited to 80 characters unless you do some hijinks in >>> the settings to expand it. >> >> Try `mode con cols=120 lines=30`. > > Yeah, that will do it, as will going into the settings and changing > it. But basically every other program on Windows, and every console > on Linux/BSD/Mac will let me resize a terminal running while another > program is running. For a cmd.exe window, I have to quit, issue the > `mode` command, restart my application, and return to where I was. > > -tkc No need to close. Right-click on statusbar and set properties. groet Coos From Radek1 at holych.org Sun Apr 17 10:56:57 2016 From: Radek1 at holych.org (=?UTF-8?Q?Radek_Hol=C3=BD?=) Date: Sun, 17 Apr 2016 16:56:57 +0200 Subject: HTTPServer and SSL Message-ID: Hello, some people recommend following implementation of a simple HTTP server that supports SSL: Handler = http.server.BaseHTTPRequestHandlerhttpd = http.server.HTTPServer(("", 4443), Handler) httpd.socket = ssl.wrap_socket(httpd.socket, server_side=True) httpd.serve_forever() I wonder whether this usage is *supported* or not. The documentation is not explicit about whether the httpd.socket attribute can be safely reassigned. Also there were some questions regarding a simple HTTPS server on this list already and none of the answerers mentioned this approach. Also there used to be a HTTPSServer in the test suite of Python 2.7 in 2014 that did a similar thing but in the "get_request" method but it isn't there anymore. So, is there a *supported* way of combining http.server.HTTPServer and ssl? Best regards -- Radek From memilanuk at gmail.com Sun Apr 17 12:27:38 2016 From: memilanuk at gmail.com (Monte Milanuk) Date: Sun, 17 Apr 2016 09:27:38 -0700 Subject: how to setup for localhost:8000 In-Reply-To: <67abca1d-8ac5-4a9a-825d-3aa76d9ccf3f@googlegroups.com> References: <5ea1e31b-09ba-4b6a-be8b-58886c5c5f81@googlegroups.com> <2e597a56-00ab-4370-b337-667f34eac56a@googlegroups.com> <67abca1d-8ac5-4a9a-825d-3aa76d9ccf3f@googlegroups.com> Message-ID: On 2016-04-16 15:35, wrh8609 at gmail.com wrote: >> When you type http://localhost:8000, do you see something in the >> console after the line "Serving HTTP on 0.0.0.0 port 8000 ..." ? >> >> If the server actually serves requests on port 8000 you should see >> a log message such as >> >> 127.0.0.1 - - [15/Apr/2016 20:57:32] "GET / HTTP/1.1" 200 - > Hi Pierre, > > When I type http://localhost:8000, I did not see anything in the > console after the line "Serving HTTP on 0.0.0.0 port 8000 ... I > believe the way I ran was not correct as shown below: >> python -m http.server > Serving HTTP on 0.0.0.0 port 8000 ... > > Also if I use internet Explorer, it shows HTTP 404 errors. Do you > think the way I am doing of the localhost:8000 setting was not > correct? > Do you have any anti-virus programs running? Its possible they may be interfering with letting your python installation open a server on the local host at all, or with letting your browser access it, if it is running. What I get in the console looks like this: Windows PowerShell Copyright (C) 2015 Microsoft Corporation. All rights reserved. PS C:\Users\Monte Milanuk> python -m http.server Serving HTTP on 0.0.0.0 port 8000 ... ...and then once I open a browser window to 'localhost:8000', I get the following in the console: 127.0.0.1 - - [17/Apr/2016 09:21:49] "GET / HTTP/1.1" 200 - Which is the python http.server telling you that it responded to a request from 127.0.0.1, completion code (200), etc. If you're not seeing that, and you're instead getting 404 codes in the browswer window, something on your machine is blocking it from seeing the server. You might try '127.0.0.1:8000' instead of 'localhost:8000' in the browser window, or you might try specifying different interface or port numbers for the server when you start it. It *should* 'just work' as is, with the basic 'python -m http.server' command, but obviously it isn't, for whatever reason. From ranran at NOSPAM.it Sun Apr 17 12:46:25 2016 From: ranran at NOSPAM.it (ranran) Date: Sun, 17 Apr 2016 18:46:25 +0200 Subject: read datas from sensors and plotting Message-ID: I'm reading in python some values from some sensors and I write them in a csv file. My problem now is to use this datas to plot a realtime graph for a example in a web server. Is it possible to read in the same time the values, writing in the file and plot them in a webpage with python? From mail at timgolden.me.uk Sun Apr 17 12:57:51 2016 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 17 Apr 2016 17:57:51 +0100 Subject: Moderation and slight change of (de facto) policy Message-ID: <5713C08F.3010207@timgolden.me.uk> There's been a bit of chatter lately about the moderation on the Python List (and, indirectly, comp.lang.python). The list moderators have suspended a couple of posters for a while and we've been discussing a little our policy towards non-subscribed posts. First, a quick summary of the current settings of the list: * Any post from someone who's not subscribed to the list is held for moderation * Subscribers are also held for moderation until a moderator clears that flag (which we usually do on the first post, unless there's some doubt). This is basically to prevent canny spammers from signing up and then posting garbage. * There are a few other rules which will cause posts to be held for moderation: unduly large posts, certain odd headers, large-scale cross-posting, etc. * All attachments are stripped Exactly how held posts are handled is down to each moderator: generally, though, it's quite obvious as most spam is very blatant. Occasionally, of course, we have a post which borders on (or is clearly) objectionable, and we have to decide whether to reject it at source or to let it through and let the community deal. Our approach to non-subscribed posts has been to let them through if they're clearly genuine, ie non-spam. However, as has been pointed out recently, this can quite easily result in useful advice falling on deaf ears. The OP isn't subscribed to the list, may not be reading it via gmane/ggroups etc. and may simply expect people to cc them directly. The list subscribers have no way of knowing whether someone's subscribed or not, so they reply to the List. And, of course, some people object to cc-ing individuals as well as the List. Our new approach (from as soon as we set it up) will be to reject unsubscribed posts with a friendly message indicating how to subscribe. The only exception we expect to make is if we spot a regular subscriber who's come in on a different address for some reason (eg posting from a phone). The main effect, we hope, will be that people asking questions actually see the answers. Of course, as we've seen in the past, some people will be confounded by the way in which a mailing list works (ie that they see all the chatter going through not just the answers to their question). But I don't see there's very much we can do about that except to help them to understand how it works. In general, please feel free to feed back to the list owners. Like everyone around here, we're all volunteers so we can't guarantee to respond in any particular timeframe, but we'll try. TJG From larry.martell at gmail.com Sun Apr 17 13:00:06 2016 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 17 Apr 2016 13:00:06 -0400 Subject: read datas from sensors and plotting In-Reply-To: References: Message-ID: On Sunday, April 17, 2016, ranran wrote: > I'm reading in python some values from some sensors and I write them in a > csv file. > My problem now is to use this datas to plot a realtime graph for a example > in a web server. > Is it possible to read in the same time the values, writing in the file > and plot them in a webpage with python? > Check out plotly https://plot.ly/python/ From joel.goldstick at gmail.com Sun Apr 17 13:04:42 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 17 Apr 2016 13:04:42 -0400 Subject: read datas from sensors and plotting In-Reply-To: References: Message-ID: On Sun, Apr 17, 2016 at 1:00 PM, Larry Martell wrote: > On Sunday, April 17, 2016, ranran wrote: > >> I'm reading in python some values from some sensors and I write them in a >> csv file. >> My problem now is to use this datas to plot a realtime graph for a example >> in a web server. >> Is it possible to read in the same time the values, writing in the file >> and plot them in a webpage with python? >> > > Check out plotly > > https://plot.ly/python/ > -- > https://mail.python.org/mailman/listinfo/python-list Matplotlib and pygals are two others. -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From pierre.quentel at gmail.com Sun Apr 17 13:11:24 2016 From: pierre.quentel at gmail.com (Pierre Quentel) Date: Sun, 17 Apr 2016 10:11:24 -0700 (PDT) Subject: how to setup for localhost:8000 In-Reply-To: <67abca1d-8ac5-4a9a-825d-3aa76d9ccf3f@googlegroups.com> References: <5ea1e31b-09ba-4b6a-be8b-58886c5c5f81@googlegroups.com> <2e597a56-00ab-4370-b337-667f34eac56a@googlegroups.com> <67abca1d-8ac5-4a9a-825d-3aa76d9ccf3f@googlegroups.com> Message-ID: <60e461a5-95ff-49c0-9beb-7bc595c057e1@googlegroups.com> > > 127.0.0.1 - - [15/Apr/2016 20:57:32] "GET / HTTP/1.1" 200 - > Hi Pierre, > > When I type http://localhost:8000, I did not see anything in the console after the line "Serving HTTP on 0.0.0.0 port 8000 ... I believe the way I ran was not correct as shown below: > > python -m http.server > Serving HTTP on 0.0.0.0 port 8000 ... > > Also if I use internet Explorer, it shows HTTP 404 errors. > Do you think the way I am doing of the localhost:8000 setting was not correct? > > Thanks, > Wen-Ruey If you're not seeing anything there, it is sure that the Python server doesn't serve requests on port 8000. But if you're seeing a blank screen or a 404 error instead of a message saying that a connection couldn't be set up, it is likely that another HTTP server is running on your machine on port 8000. Could you try to start the server on another port, eg "python -m http.server 8085" and see what happens in the browser with "http://127.0.0.1:8085" ? From blueridiculous at gmail.com Sun Apr 17 13:17:56 2016 From: blueridiculous at gmail.com (BlueRidiculous) Date: Sun, 17 Apr 2016 10:17:56 -0700 (PDT) Subject: error with tkinter, help In-Reply-To: References: <47977d70-6208-4e68-aca3-e1f63aacfac7@googlegroups.com> Message-ID: On Saturday, April 16, 2016 at 9:30:39 PM UTC-7, Terry Reedy wrote: > On 4/16/2016 9:31 PM, blueridiculous at gmail.com wrote: > > So I was reading https://wiki.python.org/moin/TkInter for help. > > I got to step 3 under "Checking your Tkinter support." > > Nothing happens when I do steps 1 or 2, and when I do step 3, > > I get this error: > > > > Traceback (most recent call last): > > File "", line 301, in runcode > > File "", line 1, in > > File "C:\Python34\lib\tkinter\__init__.py", line 3882, in _test > > root = Tk() > > File "C:\Python34\lib\tkinter\__init__.py", line 1856, in __init__ > > self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) > > _tkinter.TclError: Can't find a usable init.tcl in the following directories: > > C:/Python34/lib/tcl8.6 C:/lib/tcl8.6 C:/lib/tcl8.6 C:/library C:/library C:/tcl8.6.1/library C:/tcl8.6.1/library > > > > This probably means that Tcl wasn't installed properly. > > " > > The directory list is obsolete. You should have C:/Python34/tcl > How did you install Python? The Windows PSF installer from python.org > will create this directory unless you uncheck the box to include tcl/tk. > > -- > Terry Jan Reedy What is a PSF installer? Anyway, I installed the "Windows x86 MSI installer" from https://www.python.org/downloads/release/python-344/ Is that correct? From best_lay at yahoo.com Sun Apr 17 13:21:20 2016 From: best_lay at yahoo.com (Wildman) Date: Sun, 17 Apr 2016 12:21:20 -0500 Subject: Moderation and slight change of (de facto) policy References: <5713C08F.3010207@timgolden.me.uk> Message-ID: On Sun, 17 Apr 2016 17:57:51 +0100, Tim Golden wrote: > There's been a bit of chatter lately about the moderation on the Python > List (and, indirectly, comp.lang.python). The list moderators have > suspended a couple of posters for a while and we've been discussing a > little our policy towards non-subscribed posts. > > First, a quick summary of the current settings of the list: > > * Any post from someone who's not subscribed to the list is held for > moderation > > * Subscribers are also held for moderation until a moderator clears that > flag (which we usually do on the first post, unless there's some doubt). > This is basically to prevent canny spammers from signing up and then > posting garbage. > > * There are a few other rules which will cause posts to be held for > moderation: unduly large posts, certain odd headers, large-scale > cross-posting, etc. > > * All attachments are stripped > > Exactly how held posts are handled is down to each moderator: generally, > though, it's quite obvious as most spam is very blatant. Occasionally, > of course, we have a post which borders on (or is clearly) > objectionable, and we have to decide whether to reject it at source or > to let it through and let the community deal. > > Our approach to non-subscribed posts has been to let them through if > they're clearly genuine, ie non-spam. However, as has been pointed out > recently, this can quite easily result in useful advice falling on deaf > ears. The OP isn't subscribed to the list, may not be reading it via > gmane/ggroups etc. and may simply expect people to cc them directly. The > list subscribers have no way of knowing whether someone's subscribed or > not, so they reply to the List. And, of course, some people object to > cc-ing individuals as well as the List. > > Our new approach (from as soon as we set it up) will be to reject > unsubscribed posts with a friendly message indicating how to subscribe. > The only exception we expect to make is if we spot a regular subscriber > who's come in on a different address for some reason (eg posting from a > phone). > > The main effect, we hope, will be that people asking questions actually > see the answers. Of course, as we've seen in the past, some people will > be confounded by the way in which a mailing list works (ie that they see > all the chatter going through not just the answers to their question). > But I don't see there's very much we can do about that except to help > them to understand how it works. > > In general, please feel free to feed back to the list owners. Like > everyone around here, we're all volunteers so we can't guarantee to > respond in any particular timeframe, but we'll try. > > TJG How will this change affect posts to comp.lang.python? -- GNU/Linux user #557453 From blueridiculous at gmail.com Sun Apr 17 13:24:17 2016 From: blueridiculous at gmail.com (BlueRidiculous) Date: Sun, 17 Apr 2016 10:24:17 -0700 (PDT) Subject: error with tkinter, help In-Reply-To: References: <47977d70-6208-4e68-aca3-e1f63aacfac7@googlegroups.com> Message-ID: <9cd33690-bb18-446b-9151-aedfd32693ca@googlegroups.com> On Sunday, April 17, 2016 at 10:18:09 AM UTC-7, BlueRidiculous wrote: > On Saturday, April 16, 2016 at 9:30:39 PM UTC-7, Terry Reedy wrote: > > On 4/16/2016 9:31 PM, blueridiculous at gmail.com wrote: > > > So I was reading https://wiki.python.org/moin/TkInter for help. > > > I got to step 3 under "Checking your Tkinter support." > > > Nothing happens when I do steps 1 or 2, and when I do step 3, > > > I get this error: > > > > > > Traceback (most recent call last): > > > File "", line 301, in runcode > > > File "", line 1, in > > > File "C:\Python34\lib\tkinter\__init__.py", line 3882, in _test > > > root = Tk() > > > File "C:\Python34\lib\tkinter\__init__.py", line 1856, in __init__ > > > self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) > > > _tkinter.TclError: Can't find a usable init.tcl in the following directories: > > > C:/Python34/lib/tcl8.6 C:/lib/tcl8.6 C:/lib/tcl8.6 C:/library C:/library C:/tcl8.6.1/library C:/tcl8.6.1/library > > > > > > This probably means that Tcl wasn't installed properly. > > > " > > > > The directory list is obsolete. You should have C:/Python34/tcl > > How did you install Python? The Windows PSF installer from python.org > > will create this directory unless you uncheck the box to include tcl/tk. > > > > -- > > Terry Jan Reedy > > What is a PSF installer? Anyway, I installed the "Windows x86 MSI installer" from https://www.python.org/downloads/release/python-344/ Is that correct? Actually nevermind, I uninstalled and reinstalled Python and it works now. I remember I uninstalled and reinstalled before, and it worked, then stopped working, so I'm not sure how permanent this fix will be. Stay tuned for updates. Thanks again. From sjeik_appie at hotmail.com Sun Apr 17 13:35:45 2016 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Sun, 17 Apr 2016 17:35:45 +0000 Subject: read datas from sensors and plotting In-Reply-To: References: Message-ID: > From: ranran at NOSPAM.it > Subject: read datas from sensors and plotting > Date: Sun, 17 Apr 2016 18:46:25 +0200 > To: python-list at python.org > > I'm reading in python some values from some sensors and I write them in > a csv file. > My problem now is to use this datas to plot a realtime graph for a > example in a web server. > Is it possible to read in the same time the values, writing in the file > and plot them in a webpage with python? tail -F data.log | python myprogram.py http://stackoverflow.com/questions/1712276/tail-read-a-growing-dynamic-file-and-extract-two-columns-and-then-print-a-graphhttp://code.activestate.com/recipes/577968-log-watcher-tail-f-log/ From python.list at tim.thechases.com Sun Apr 17 14:11:56 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 17 Apr 2016 13:11:56 -0500 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <4winspmqbztx$.3syiofssbnnl.dlg@40tude.net> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <85vb3huxjn.fsf@benfinney.id.au> <20160416165027.0fe70e5f@bigbox.christie.dr> <20160416203052.2598ad15@bigbox.christie.dr> <4winspmqbztx$.3syiofssbnnl.dlg@40tude.net> Message-ID: <20160417131156.6907840c@bigbox.christie.dr> On 2016-04-17 16:35, Coos Haak wrote: > Op Sat, 16 Apr 2016 20:30:52 -0500 schreef Tim Chase: > >> Try `mode con cols=120 lines=30`. > > > > Yeah, that will do it, as will going into the settings and > > changing it. But basically every other program on Windows, and > > every console on Linux/BSD/Mac will let me resize a terminal > > running while another program is running. For a cmd.exe window, > > I have to quit, issue the `mode` command, restart my application, > > and return to where I was. > > No need to close. Right-click on statusbar and set properties. By "close", I meant "close the application running within the cmd.exe window" rather than "close the cmd.exe window". In most *nix programs, they understand the SIGWINCH (window-size changed) signal and respond accordingly. In the Win32 world, it was pretty fixed in size, so most terminal programs don't readily accommodate changed size while they're running. So as Eryk Sun mentions, the program has to jump through hoops to run "mode" in a subprocess to change the terminal size, or use GetConsoleScreenBufferInfoEx/SetConsoleScreenBufferInfoEx or other such mechanisms. It's not that it *can't* be done, it's just done in an *inconvenient* way (if done at all). -tkc From rosuav at gmail.com Sun Apr 17 15:08:39 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Apr 2016 05:08:39 +1000 Subject: error with tkinter, help In-Reply-To: References: <47977d70-6208-4e68-aca3-e1f63aacfac7@googlegroups.com> Message-ID: On Mon, Apr 18, 2016 at 3:17 AM, BlueRidiculous wrote: >> How did you install Python? The Windows PSF installer from python.org >> will create this directory unless you uncheck the box to include tcl/tk. >> >> -- >> Terry Jan Reedy > > What is a PSF installer? Anyway, I installed the "Windows x86 MSI installer" from https://www.python.org/downloads/release/python-344/ Is that correct? Yep, that answers the question! Thanks. For the TLDR version, skip to the next email now. If you're curious, this is what Terry meant by "PSF installer". Python is available from a number of places. The most simple and straight-forward installers come direct from the Python Software Foundation, and are downloaded from python.org, which is what you've done. You can also get prepackaged distributions from Enthought, ActiveState, Anaconda, and other redistributors. They may charge money for what they give you (this is legal, even with free software like the Python interpreter), and they can promise things that the PSF doesn't, such as support for old/obscure operating systems, guaranteed response times on support requests, or pre-included (and compatibility-guaranteed) third-party libraries. What's significant here is that your problem is with the *installer*, not with the language itself. When an organization repackages Python in some way, they may replace the installer with something that puts things in different places, or has different default options. It's not very helpful for us to say "Rerun the installer, go to this point, and tick this box" if you're actually using (say) Anaconda's installer and it all looks different! So Terry was basically clarifying that he was talking about the vanilla installer that you can get off python.org, as opposed to any of the others. Hope that helps! ChrisA From christopher_reimer at icloud.com Sun Apr 17 15:34:05 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sun, 17 Apr 2016 12:34:05 -0700 Subject: How much sanity checking is required for function inputs? Message-ID: <5713E52D.3060407@icloud.com> Greetings, I'm currently building a chess engine to learn the finer details of Python. When I learned all flavors of Java in community college a decade ago, we had to sanity check the hell out of the input values for every function and wrote a lot of redundant code in addition to the getters/setters code. Here's the input sanity checking I got for a generator function to return a set of chess pieces for a specified color and position. def generate_set(color, positions): if color not in [VARS['COLOR_BLACK'], VARS['COLOR_WHITE']]: raise Exception("Require \'{}\' or \'{}\' for input value, got \'{}\' instead.".format(VARS['COLOR_BLACK'], VARS['COLOR_WHITE'], color)) if len(positions) != 16: raise Exception("Require 16 positions for input value, got {} instead.".format(len(positions))) The two sanity checks are fairly straight forward. Color input has to match the color constant strings. Positions input has to have 16 items. I *could* sanity check the positions input to determine if it had a list of 16 valid coordinates. The reason I don't is because the code that calls this function builds the coordinates from constants with valid coordinates. However, if I was doing this in my Java classes, one of my instructors rap me on the knuckles for not sanity checking to nth degree. How much sanity checking is too much in Python? Thank you, Chris R From rosuav at gmail.com Sun Apr 17 15:45:01 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Apr 2016 05:45:01 +1000 Subject: Falsehoods People Believe about PEP 8 (was: Guido sees the light: PEP 8 updated) In-Reply-To: <85potpuwwt.fsf_-_@benfinney.id.au> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <85potpuwwt.fsf_-_@benfinney.id.au> Message-ID: On Sun, Apr 17, 2016 at 6:21 AM, Ben Finney wrote: > Chris Angelico writes: > >> Maybe we need a blog post "Falsehoods Programmers Believe About PEP >> 8", along the lines of the ones about time and names. > > Great suggestion. (Do you have a blog on which you could post an article > like this?) An initial list has been posted here: http://rosuav.blogspot.com/2016/04/falsehoods-programmers-believe-about.html Additional contributions are still welcome. ChrisA From mail at timgolden.me.uk Sun Apr 17 15:50:02 2016 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 17 Apr 2016 20:50:02 +0100 Subject: Moderation and slight change of (de facto) policy In-Reply-To: References: <5713C08F.3010207@timgolden.me.uk> Message-ID: <5713E8EA.1080801@timgolden.me.uk> On 17/04/2016 18:21, Wildman via Python-list wrote: > On Sun, 17 Apr 2016 17:57:51 +0100, Tim Golden wrote: [... snip my explanation of new moderation for non-subscribers ...] > How will this change affect posts to comp.lang.python? > Not at all, in the sense that the moderation doesn't apply to comp.lang.python, except insofar as posts which are sent to the list and which we reject obviously won't make it to comp.lang.python either. TJG From eryksun at gmail.com Sun Apr 17 15:52:16 2016 From: eryksun at gmail.com (eryk sun) Date: Sun, 17 Apr 2016 14:52:16 -0500 Subject: No subject In-Reply-To: References: Message-ID: On Sun, Apr 17, 2016 at 2:27 AM, B N wrote: > I found that when the ?black? screen comes on, I am unable to read/see > any characters even if I turn up the brightness of the screen. Do you mean the console, i.e. the window used by the command prompt (cmd.exe)? For a novice, you'll probably be better off using Python IDLE. It should be in the start menu under "Python 3.5". Or just type "idle" to search for it. If you want to continue using the console, you can modify the default text and background colors for the current application. Click on the system menu in the upper left-hand corner of the window and choose "Properties". On the "Colors" tab change the color of the screen text and background. On the "Font" tab I recommend selecting a TrueType font such as Consolas. To change the default settings, select "Defaults" instead of "Properties". You can also modify per-shortcut settings by right-clicking a shortcut and selecting "Properties". The console applies saved settings starting with the defaults, then the application settings, and then the shortcut settings. cmd also has a built-in "color" command to modify the text and background colors in a command prompt. Enter "color /?" to get a list of the 16 supported colors, which are numbered 0-F. For example, "color 0F" uses bright white (F) text on a black (0) background. > Also I have not ben ale to save it on C/programmes/files You shouldn't be saving files to system directories. Save your scripts in your personal folder. From ranran at NOSPAM.it Sun Apr 17 16:21:38 2016 From: ranran at NOSPAM.it (ranran) Date: Sun, 17 Apr 2016 22:21:38 +0200 Subject: read datas from sensors and plotting References: Message-ID: > Check out plotly > > https://plot.ly/python/ > nice! but it's no completely free...for example I should plot 4 chart of temperatures in the same time. I think I can plot only 1 chart. Anyway I need to be connected to internet instead sometimes I want to show it only in my webserver. From eryksun at gmail.com Sun Apr 17 16:24:00 2016 From: eryksun at gmail.com (eryk sun) Date: Sun, 17 Apr 2016 15:24:00 -0500 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <7fd7hbh28cmcusb4aqr8oicm04u146j9a9@4ax.com> References: <878u0d7az5.fsf@elektro.pacujo.net> <85vb3huxjn.fsf@benfinney.id.au> <20160416165027.0fe70e5f@bigbox.christie.dr> <20160416203052.2598ad15@bigbox.christie.dr> <1460858341.2377173.580944673.0F0ECA86@webmail.messagingengine.com> <7fd7hbh28cmcusb4aqr8oicm04u146j9a9@4ax.com> Message-ID: On Sun, Apr 17, 2016 at 11:13 AM, Dennis Lee Bieber wrote: > On Sat, 16 Apr 2016 21:59:01 -0400, Random832 > declaimed the following: >> >>I heard Windows 10 is going to finally fix this, anyway. > > Probably by removing the old CLI window completely and making everyone > learn PowerShell ISE PowerShell ISE doesn't support interactive console applications. It runs console apps with a hidden console (conhost.exe) and sets the StandardOutput and StandardError to pipes. It leaves StandardInput set to the console input handle. If you run python.exe in this environment, you can use ctypes to show the console. Then enter commands in the console, and get the output in ISE. Or rebind sys.stdout and sys.stderr to \\.\CONOUT$ handles and forget about ISE, which is really only meant for developing PowerShell scripts. Microsoft won't abandon existing console programs, such as python.exe. The console system was fairly stagnant between NT 4 and Vista. In Windows 7, they changed how it interacts with a Windows session, by moving the server out of csrss.exe to multiple conhost.exe instances. In Windows 8, they reimplemented the API to use a kernel device driver, condrv.sys. For Windows 10, they've focused on improving the user interface: https://blogs.windows.com/buildingapps/2014/10/07/ console-improvements-in-the-windows-10-technical-preview There's a new blog dedicated to Windows command-line tools, which should be the place to look for announcements about the console subsystem and the new Linux command-line environment that depends on the console: https://blogs.msdn.microsoft.com/commandline From torriem at gmail.com Sun Apr 17 16:41:28 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 17 Apr 2016 14:41:28 -0600 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <7fd7hbh28cmcusb4aqr8oicm04u146j9a9@4ax.com> References: <878u0d7az5.fsf@elektro.pacujo.net> <85vb3huxjn.fsf@benfinney.id.au> <20160416165027.0fe70e5f@bigbox.christie.dr> <20160416203052.2598ad15@bigbox.christie.dr> <1460858341.2377173.580944673.0F0ECA86@webmail.messagingengine.com> <7fd7hbh28cmcusb4aqr8oicm04u146j9a9@4ax.com> Message-ID: <5713F4F8.2080307@gmail.com> On 04/17/2016 10:13 AM, Dennis Lee Bieber wrote: > On Sat, 16 Apr 2016 21:59:01 -0400, Random832 > declaimed the following: > >> >> I heard Windows 10 is going to finally fix this, anyway. > > Probably by removing the old CLI window completely and making everyone > learn PowerShell ISE Or a Linux ELF bash binary running on the new Linux subsystem for Windows. :) From michael.selik at gmail.com Sun Apr 17 17:46:14 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sun, 17 Apr 2016 21:46:14 +0000 Subject: Dynamic inputs In-Reply-To: References: <901a5b60-25b3-4e1c-9178-755bf668a5c5@googlegroups.com> Message-ID: On Sun, Apr 17, 2016, 7:01 AM durgadevi1 < srirajarajeswaridevikrupa at gmail.com> wrote: > On Saturday, April 16, 2016 at 5:31:39 PM UTC+8, Michael Selik wrote: > > On Sat, Apr 16, 2016, 9:41 AM durgadevi1 < > > srirajarajeswaridevikrupa at gmail.com> wrote: > > > > > what does dynamic inputs mean and how is it implemented in python > > > programming? > > > > > > > In what context did you hear or read the phrase "dynamic inputs"? > > > > > > > Oh I read it in my assignment manual. The sentence is "Use dynamic inputs > to XOR the binary file. " Thanks for your replies :) > It seems the assignment wants you to ask a user for input. What input source would you like to use? > From timothy.c.delaney at gmail.com Sun Apr 17 18:02:45 2016 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Mon, 18 Apr 2016 08:02:45 +1000 Subject: [OT] Java generics (was: Guido sees the light: PEP 8 updated) Message-ID: On 17 April 2016 at 23:38, Ian Kelly wrote: > > Java generics ruined a perfectly good language. I mean: > > The diamond operator in JDK 7 makes this a lot more tolerable, IMO: > > Map> customersOfAccountManager = > new HashMap<>(); > To some extent - you can't use the diamond operator when creating an anonymous subclass, and you often need to explicitly specify the types for generic methods. The inference engine is fairly limited. I wouldn't say generics ruined Java - they made it better in some ways (for a primarily statically-typed language) but worse in others (esp. that they're implemented by erasure). I also wouldn't describe Java as a "perfectly good language" - it is at best a compromise language that just happened to be heavily promoted and accepted at the right time. Python is *much* closer to my idea of a perfectly good language. Tim Delaney From matt.ruffalo at gmail.com Sun Apr 17 18:08:07 2016 From: matt.ruffalo at gmail.com (Matt Ruffalo) Date: Sun, 17 Apr 2016 18:08:07 -0400 Subject: Moderation and slight change of (de facto) policy In-Reply-To: <5713C08F.3010207@timgolden.me.uk> References: <5713C08F.3010207@timgolden.me.uk> Message-ID: <57140947.3050902@gmail.com> Hi- That seems like a reasonable approach, though I think there *really* needs to be an option along the lines of "subscribed to the list for the purposes of moderation, but not receiving list messages via email". I think I did this with the Git mailing list in the past, and it was quite useful. I prefer to read the mailing list over NNTP through Thunderbird -- if I have to decide between receiving every mailing list message via email, or not sending messages to the list, I'll probably decide to not send anything to the list at all. This is one of the reasons I'm not very active on this mailing list; it's hard to effectively participate in a conversation when I know it might be several hours or half a day before my message appears, and a discussion will likely have changed enough in that time that a late message may not be very useful. MMR... On 2016-04-17 12:57, Tim Golden wrote: > There's been a bit of chatter lately about the moderation on the > Python List (and, indirectly, comp.lang.python). The list moderators > have suspended a couple of posters for a while and we've been > discussing a little our policy towards non-subscribed posts. > > First, a quick summary of the current settings of the list: > > * Any post from someone who's not subscribed to the list is held for > moderation > > * Subscribers are also held for moderation until a moderator clears > that flag (which we usually do on the first post, unless there's some > doubt). This is basically to prevent canny spammers from signing up > and then posting garbage. > > * There are a few other rules which will cause posts to be held for > moderation: unduly large posts, certain odd headers, large-scale > cross-posting, etc. > > * All attachments are stripped > > Exactly how held posts are handled is down to each moderator: > generally, though, it's quite obvious as most spam is very blatant. > Occasionally, of course, we have a post which borders on (or is > clearly) objectionable, and we have to decide whether to reject it at > source or to let it through and let the community deal. > > Our approach to non-subscribed posts has been to let them through if > they're clearly genuine, ie non-spam. However, as has been pointed out > recently, this can quite easily result in useful advice falling on > deaf ears. The OP isn't subscribed to the list, may not be reading it > via gmane/ggroups etc. and may simply expect people to cc them > directly. The list subscribers have no way of knowing whether > someone's subscribed or not, so they reply to the List. And, of > course, some people object to cc-ing individuals as well as the List. > > Our new approach (from as soon as we set it up) will be to reject > unsubscribed posts with a friendly message indicating how to > subscribe. The only exception we expect to make is if we spot a > regular subscriber who's come in on a different address for some > reason (eg posting from a phone). > > The main effect, we hope, will be that people asking questions > actually see the answers. Of course, as we've seen in the past, some > people will be confounded by the way in which a mailing list works (ie > that they see all the chatter going through not just the answers to > their question). But I don't see there's very much we can do about > that except to help them to understand how it works. > > In general, please feel free to feed back to the list owners. Like > everyone around here, we're all volunteers so we can't guarantee to > respond in any particular timeframe, but we'll try. > > TJG From ben+python at benfinney.id.au Sun Apr 17 18:13:58 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 18 Apr 2016 08:13:58 +1000 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> <877ffw5wjo.fsf@elektro.pacujo.net> <8737qk5tcm.fsf@elektro.pacujo.net> Message-ID: <85zisrubmh.fsf@benfinney.id.au> Marko Rauhamaa writes: > Chris Angelico : > > > What more often happens is that, once the function exceeds the > > stipulated maximum, it gets split somewhat arbitrarily into a > > "master" function and several "part" functions, with each part > > having exactly one call site in the driver and exactly none > > elsewhere. Even if the partial functions have reasonable names > > (which they don't always), they're still tightly bound to the > > master, and end up still functioning as a single unit. > > And? That's a feature, not a bug. It makes you analyze your approach a > bit more. It makes you give names to things. It makes it more likely > that your solution really works. Yes. It also counters the tendency to let distant areas of code in a function become too tightly dependent. By identifying large functions with inherent ?do this then do that then do the other then ?? structure as a problem in itself, the writer must split it into small functions and think *explicitly* about how those parts interact. The interface between those parts is already part of the code design, and if they're tightly coupled in a way difficult to describe simply, it is a *bad* design already. A large function just obscures that, it doesn't make it better. Encouraging the split of large functions into small ones makes that design explicit, and exposes places wehre the coupling is too complex or too tight. The code writer is then explicitly and routinely thinking about how best to narrow the coupling between the parts. > > Unless you can genuinely make that subfunction useful in some other > > context, there's not a lot of use splitting it into a function. You > > don't generally see those perfect "paragraphs" in real-world code. The point of splitting functions is not re-use (though that is a useful side effect when it happens). The point is, in the face of trends that are all toward code becoming difficult to understand and tangled, to make the design as clear and simple and obviously correct as feasible. -- \ ?Welchen Teil von ?Gestalt? verstehen Sie nicht? [What part of | `\ ?gestalt? don't you understand?]? ?Karsten M. Self | _o__) | Ben Finney From michael.selik at gmail.com Sun Apr 17 18:18:47 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sun, 17 Apr 2016 22:18:47 +0000 Subject: How much sanity checking is required for function inputs? In-Reply-To: <5713E52D.3060407@icloud.com> References: <5713E52D.3060407@icloud.com> Message-ID: On Sun, Apr 17, 2016, 4:35 PM Christopher Reimer < christopher_reimer at icloud.com> wrote: > Greetings, > > I'm currently building a chess engine to learn the finer details of > Python. When I learned all flavors of Java in community college a decade > ago, we had to sanity check the hell out of the input values for every > function and wrote a lot of redundant code in addition to the > getters/setters code. > > Here's the input sanity checking I got for a generator function to > return a set of chess pieces for a specified color and position. > > > def generate_set(color, positions): > > if color not in [VARS['COLOR_BLACK'], VARS['COLOR_WHITE']]: > raise Exception("Require \'{}\' or \'{}\' for input value, got > \'{}\' instead.".format(VARS['COLOR_BLACK'], VARS['COLOR_WHITE'], color)) > > if len(positions) != 16: > raise Exception("Require 16 positions for input value, got {} > instead.".format(len(positions))) > > > The two sanity checks are fairly straight forward. Color input has to > match the color constant strings. Positions input has to have 16 items. > > I *could* sanity check the positions input to determine if it had a list > of 16 valid coordinates. The reason I don't is because the code that > calls this function builds the coordinates from constants with valid > coordinates. However, if I was doing this in my Java classes, one of my > instructors rap me on the knuckles for not sanity checking to nth degree. > > How much sanity checking is too much in Python? > I'd rather turn the question around: how much sanity checking is necessary or useful? You'll find the answer is "surprisingly little" compared to your experience in Java. For example, you don't need to explicitly check whether the color is present in your dictionary, because it'll give you a KeyError if you look up a bad key. Why does the len of positions need to be 16? > From ethan at stoneleaf.us Sun Apr 17 19:29:04 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 17 Apr 2016 16:29:04 -0700 Subject: Moderation and slight change of (de facto) policy In-Reply-To: <57140947.3050902@gmail.com> References: <5713C08F.3010207@timgolden.me.uk> <57140947.3050902@gmail.com> Message-ID: <57141C40.8060007@stoneleaf.us> On 04/17/2016 03:08 PM, Matt Ruffalo wrote: > That seems like a reasonable approach, though I think there *really* > needs to be an option along the lines of "subscribed to the list for the > purposes of moderation, but not receiving list messages via email". I don't understand what you are saying. If you are not receiving emails, how are you reading the list? A news reader? If you are subscribed for moderation, how does that help with the lag time when you do post? -- ~Ethan~ From rosuav at gmail.com Sun Apr 17 19:30:56 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Apr 2016 09:30:56 +1000 Subject: [OT] Java generics (was: Guido sees the light: PEP 8 updated) In-Reply-To: References: Message-ID: On Mon, Apr 18, 2016 at 8:02 AM, Tim Delaney wrote: > I also wouldn't describe Java as a > "perfectly good language" - it is at best a compromise language that just > happened to be heavily promoted and accepted at the right time. > > Python is *much* closer to my idea of a perfectly good language. "Java" was originally four related, but separate, concepts: a source language, a bytecode, a sandboxing system, and one other that I can't now remember. The published bytecode was way ahead of its day, and coupled with the sandbox, it made Java into the one obvious language for web browser applets (until the rise of Flash, and then the increase in power of JavaScript etc). If the source language and bytecode+sandbox had been more disconnected, and the latter more standardized, Java might have been a hugely popular language because of one important role (web browser applets) that can also be used elsewhere. Instead, it made a promise of "write once, run everywhere" that didn't really hold up (the Australian Taxation Office let you file corporate taxes either on paper or using their Java application - and it didn't run on OS/2 Java) and lost a ton of potential marketshare. Imagine how the world would be today, if languages like NetRexx had had a chance to shine - completely different source code language, compiling to the same Java bytecode. Jython might have been the one most popular language for applet development... ChrisA From rosuav at gmail.com Sun Apr 17 19:35:40 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Apr 2016 09:35:40 +1000 Subject: Moderation and slight change of (de facto) policy In-Reply-To: <57140947.3050902@gmail.com> References: <5713C08F.3010207@timgolden.me.uk> <57140947.3050902@gmail.com> Message-ID: On Mon, Apr 18, 2016 at 8:08 AM, Matt Ruffalo wrote: > Hi- > > That seems like a reasonable approach, though I think there *really* > needs to be an option along the lines of "subscribed to the list for the > purposes of moderation, but not receiving list messages via email". I > think I did this with the Git mailing list in the past, and it was quite > useful. I prefer to read the mailing list over NNTP through Thunderbird > -- if I have to decide between receiving every mailing list message via > email, or not sending messages to the list, I'll probably decide to not > send anything to the list at all. That shouldn't be difficult. You should be able to subscribe, and then go to the Mailman page and change your delivery options. https://mail.python.org/mailman/listinfo/python-list """ Mail delivery Set this option to Enabled to receive messages posted to this mailing list. Set it to Disabled if you want to stay subscribed, but don't want mail delivered to you for a while (e.g. you're going on vacation). If you disable mail delivery, don't forget to re-enable it when you come back; it will not be automatically re-enabled. """ It talks about temporarily disabling delivery, but it works fine for permanent blocking, too. I run a Mailman list for the committee of a non-profit organization, and several of the members are subscribed under multiple addresses, with all but one of them in nomail mode; it lets them post from any of their accounts, without moderation delay, but not get spammed with all the copies. ChrisA From greg.ewing at canterbury.ac.nz Sun Apr 17 19:56:26 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 18 Apr 2016 11:56:26 +1200 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <878u0d7az5.fsf@elektro.pacujo.net> <85vb3huxjn.fsf@benfinney.id.au> <20160416165027.0fe70e5f@bigbox.christie.dr> <20160416203052.2598ad15@bigbox.christie.dr> <1460858341.2377173.580944673.0F0ECA86@webmail.messagingengine.com> <7fd7hbh28cmcusb4aqr8oicm04u146j9a9@4ax.com> <5713F4F8.2080307@gmail.com> Message-ID: Michael Torrie wrote: > On 04/17/2016 10:13 AM, Dennis Lee Bieber wrote: > >>On Sat, 16 Apr 2016 21:59:01 -0400, Random832 >>declaimed the following: >> >> >>>I heard Windows 10 is going to finally fix this, anyway. >> >> Probably by removing the old CLI window completely and making everyone >>learn PowerShell ISE > > > Or a Linux ELF bash binary running on the new Linux subsystem for > Windows. :) And then legacy command-line exes will be supported by running cmd.exe under WINE in the Linux subsystem. -- Greg From random832 at fastmail.com Sun Apr 17 20:27:40 2016 From: random832 at fastmail.com (Random832) Date: Sun, 17 Apr 2016 20:27:40 -0400 Subject: Moderation and slight change of (de facto) policy In-Reply-To: <57140947.3050902@gmail.com> References: <5713C08F.3010207@timgolden.me.uk> <57140947.3050902@gmail.com> Message-ID: <1460939260.3483225.581520729.146827C9@webmail.messagingengine.com> On Sun, Apr 17, 2016, at 18:08, Matt Ruffalo wrote: > Hi- > > That seems like a reasonable approach, though I think there *really* > needs to be an option along the lines of "subscribed to the list for the > purposes of moderation, but not receiving list messages via email". There is. I'm on several other (non-python, but still using mailman) mailing lists like that because they require you to be a subscriber to post via gmane. > On 2016-04-17 12:57, Tim Golden wrote: > > First, a quick summary of the current settings of the list: > > > > * Any post from someone who's not subscribed to the list is held for > > moderation As an alternative, when you send them through can you put a note on the bottom saying they're not subscribed, to remind people to CC them in responses? I think that's why we never get any followup on "newbie problem" questions (especially the crt dll thing and the modify remove repair thing). A couple other lists I'm on do this and it works well. I think most of the people who have objections to CC-ing are annoyed when they *receive* messages CC'd *to them*, rather than objecting on principle to doing it in reply to other people who aren't subscribed. From random832 at fastmail.com Sun Apr 17 20:29:24 2016 From: random832 at fastmail.com (Random832) Date: Sun, 17 Apr 2016 20:29:24 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <878u0d7az5.fsf@elektro.pacujo.net> <85vb3huxjn.fsf@benfinney.id.au> <20160416165027.0fe70e5f@bigbox.christie.dr> <20160416203052.2598ad15@bigbox.christie.dr> <1460858341.2377173.580944673.0F0ECA86@webmail.messagingengine.com> <7fd7hbh28cmcusb4aqr8oicm04u146j9a9@4ax.com> <5713F4F8.2080307@gmail.com> Message-ID: <1460939364.3483512.581523489.7993F05E@webmail.messagingengine.com> On Sun, Apr 17, 2016, at 19:56, Gregory Ewing wrote: > And then legacy command-line exes will be supported by running > cmd.exe under WINE in the Linux subsystem. Running the command directly under WINE, more like. Because cmd.exe is pretty terrible as a scripting language and command interpreter (MS knows this, this is why they created PowerShell), and isn't required to run console programs. From rosuav at gmail.com Sun Apr 17 20:32:08 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Apr 2016 10:32:08 +1000 Subject: Moderation and slight change of (de facto) policy In-Reply-To: <1460939260.3483225.581520729.146827C9@webmail.messagingengine.com> References: <5713C08F.3010207@timgolden.me.uk> <57140947.3050902@gmail.com> <1460939260.3483225.581520729.146827C9@webmail.messagingengine.com> Message-ID: On Mon, Apr 18, 2016 at 10:27 AM, Random832 wrote: > As an alternative, when you send them through can you put a note on the > bottom saying they're not subscribed, to remind people to CC them in > responses? I think that's why we never get any followup on "newbie > problem" questions (especially the crt dll thing and the modify remove > repair thing). A couple other lists I'm on do this and it works well. I > think most of the people who have objections to CC-ing are annoyed when > they *receive* messages CC'd *to them*, rather than objecting on > principle to doing it in reply to other people who aren't subscribed. I'd rather insist that people actually join the community. It's too hard to know when to keep cc'ing someone in. ChrisA From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Sun Apr 17 20:46:25 2016 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Mon, 18 Apr 2016 01:46:25 +0100 Subject: Creating a hot vector (numpy) Message-ID: Hi all. I have seen this "trick" to create a hot vector. In [45]: x Out[45]: array([0, 1]) In [46]: y Out[46]: array([1, 1, 1, 0, 0, 1, 0, 0], dtype=uint8) In [47]: y[:,None] Out[47]: array([[1], [1], [1], [0], [0], [1], [0], [0]], dtype=uint8) In [48]: x==y[:,None] Out[48]: array([[False, True], [False, True], [False, True], [ True, False], [ True, False], [False, True], [ True, False], [ True, False]], dtype=bool) In [49]: (x==y[:,None]).astype(np.float32) Out[49]: array([[ 0., 1.], [ 0., 1.], [ 0., 1.], [ 1., 0.], [ 1., 0.], [ 0., 1.], [ 1., 0.], [ 1., 0.]], dtype=float32) How does this (step 48) work? Thanks From steve at pearwood.info Sun Apr 17 20:46:55 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 18 Apr 2016 10:46:55 +1000 Subject: Introducing the secrets module References: <5712f69d$0$1585$c3e8da3$5496439d@news.astraweb.com> <5713841c$0$5916$e4fe514c@news.xs4all.nl> Message-ID: <57142e82$0$1602$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Apr 2016 10:40 pm, Irmen de Jong wrote: > On 17-4-2016 4:36, Steven D'Aprano wrote: > >> And the documentation: >> >> https://docs.python.org/3.6/library/secrets.html >> >> >> Comments requested. > > I've read about the "How many bytes should tokens use?" consideration. It > suggests that to be secure, tokens need to have sufficient randomness. The > default token length is subject to change at any time to remain secure > against brute-force. However the API allows you to supply any token > length, even one that is (a lot) shorter than the default. > In view of the rationale for this new module ("Python's standard library > makes it too easy for developers to inadvertently make serious security > errors") should it perhaps not be allowed to use a value that is less than > the default? > > Hm, perhaps it should not; enforcing this could break code suddenly in the > future when the default is raised... Correct. Also, consider that random tokens are not necessarily for high-security purposes. Consider Youtube URLs that are intended to be hard to guess and unpredictable, but permanent: http://www.youtube.com/watch?v=kQFKtI6gn9Y There are no security implications from revealing or guessing this URL. On the other hand: https://freedom-to-tinker.com/blog/vitaly/gone-in-six-characters-short-urls-considered-harmful-for-cloud-services/ -- Steven From ben+python at benfinney.id.au Sun Apr 17 20:49:07 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 18 Apr 2016 10:49:07 +1000 Subject: Moderation and slight change of (de facto) policy References: <5713C08F.3010207@timgolden.me.uk> <57140947.3050902@gmail.com> <57141C40.8060007@stoneleaf.us> Message-ID: <8537qju4fw.fsf@benfinney.id.au> Ethan Furman writes: > On 04/17/2016 03:08 PM, Matt Ruffalo wrote: > > > That seems like a reasonable approach, though I think there *really* > > needs to be an option along the lines of "subscribed to the list for > > the purposes of moderation, but not receiving list messages via > > email". > > I don't understand what you are saying. > > If you are not receiving emails, how are you reading the list? A news > reader? Another way is to receive messages to one email address, but to post using a different email address that should not receive those messages. E.g. the same person may wish to post as , but not receive messages to that address because they receive the same messages already at . > If you are subscribed for moderation, how does that help with the lag > time when you do post? I think that (using the above example) the wish is for *both* those addresses to be considered ?subscribed for the purpose of moderation?, without that also entailing delivery of messages. -- \ ?What is needed is not the will to believe but the will to find | `\ out, which is the exact opposite.? ?Bertrand Russell, _Free | _o__) Thought and Official Propaganda_, 1928 | Ben Finney From ben+python at benfinney.id.au Sun Apr 17 20:51:44 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 18 Apr 2016 10:51:44 +1000 Subject: Moderation and slight change of (de facto) policy References: <5713C08F.3010207@timgolden.me.uk> <57140947.3050902@gmail.com> <1460939260.3483225.581520729.146827C9@webmail.messagingengine.com> Message-ID: <85y48bspr3.fsf@benfinney.id.au> Random832 writes: > As an alternative, when you send them through can you put a note on > the bottom saying they're not subscribed, to remind people to CC them > in responses? That still relies on every participant manually changing from the correct behaviour (reply to the mailing list only, by default). > I think that's why we never get any followup on "newbie problem" > questions I think encouraging new posters to have a subscription in order to participate is the right way forward. -- \ ?Facts do not cease to exist because they are ignored.? ?Aldous | `\ Huxley | _o__) | Ben Finney From steve at pearwood.info Sun Apr 17 21:03:46 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 18 Apr 2016 11:03:46 +1000 Subject: [OT] Java generics (was: Guido sees the light: PEP 8 updated) References: Message-ID: <57143273$0$1610$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Apr 2016 09:30 am, Chris Angelico wrote: > "Java" was originally four related, but separate, concepts: a source > language, a bytecode, a sandboxing system, and one other that I can't > now remember. The virtual machine? Or is that what you mean by bytecode? The Java Virtual Machine is probably the most successful part of Java, as it has spawned a whole lot of new languages that are built on the JVM, including Clojure, Groovy and Scala, as well as JVM implementations of Python, Ruby, Javascript, Perl6, TCL, Fortran, Oberon, Pascal and more. https://en.wikipedia.org/wiki/List_of_JVM_languages One of the more interesting approaches is of Fantom, a new language designed from the beginning to run on top of any of the JVM, the .Net CLR, or a Javascript VM. -- Steven From rosuav at gmail.com Sun Apr 17 21:17:25 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Apr 2016 11:17:25 +1000 Subject: [OT] Java generics (was: Guido sees the light: PEP 8 updated) In-Reply-To: <57143273$0$1610$c3e8da3$5496439d@news.astraweb.com> References: <57143273$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Apr 18, 2016 at 11:03 AM, Steven D'Aprano wrote: > On Mon, 18 Apr 2016 09:30 am, Chris Angelico wrote: > >> "Java" was originally four related, but separate, concepts: a source >> language, a bytecode, a sandboxing system, and one other that I can't >> now remember. > > The virtual machine? Or is that what you mean by bytecode? Could be. I can't remember where it was that I read about the four-part name overloading on "Java", but it doesn't much matter. The VM and bytecode go together, and the sandboxing is the thing that makes that better than just compiling to machine code. > The Java Virtual Machine is probably the most successful part of Java, as it > has spawned a whole lot of new languages that are built on the JVM, > including Clojure, Groovy and Scala, as well as JVM implementations of > Python, Ruby, Javascript, Perl6, TCL, Fortran, Oberon, Pascal and more. > > https://en.wikipedia.org/wiki/List_of_JVM_languages Yes, but how long did it take before they came along? I didn't click on all the links, but the five that Wikipedia lists as "High Profile" are all post-2000. By that time, Flash had already established a strong footing. NetRexx, in contrast, dates back to 1996, when the battle was on. It could have been Java's game entirely if there'd been enough interest in the early days. > One of the more interesting approaches is of Fantom, a new language designed > from the beginning to run on top of any of the JVM, the .Net CLR, or a > Javascript VM. I hadn't heard of that one specifically, but there have been some extremely interesting forays into language layering. (PyPyJS, I'm looking at you.) Code is code, compilers are compilers, you can implement anything in anything. Although sometimes it's just for the sake of showing off ("hey look, I just compiled Firefox to asm.js and ran it inside Firefox!")... but that's fun too :) ChrisA From steve at pearwood.info Sun Apr 17 21:39:11 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 18 Apr 2016 11:39:11 +1000 Subject: QWERTY was not designed to intentionally slow typists down (was: Unicode normalisation [was Re: [beginner] What's wrong?]) References: <2796705.edb3E9ArW3@PointedEars.de> <1584744.4h7ToaqLat@PointedEars.de> <5705b9ef$0$1611$c3e8da3$5496439d@news.astraweb.com> <570748ec$0$1620$c3e8da3$5496439d@news.astraweb.com> <874mbcgfmd.fsf@elektro.pacujo.net> <753cdb8b-9f94-48d6-bc0d-589efba86afc@googlegroups.com> <8560vr627l.fsf_-_@benfinney.id.au> <570876f1$0$1619$c3e8da3$5496439d@news.astraweb.com> <1460217233.3804713.573755729.61D3FCF2@webmail.messagingengine.com> Message-ID: <57143ac0$0$1609$c3e8da3$5496439d@news.astraweb.com> Oh no, it's the thread that wouldn't die! *wink* On Sun, 10 Apr 2016 01:53 am, Random832 wrote: > On Fri, Apr 8, 2016, at 23:28, Steven D'Aprano wrote: >> This is the power of the "slowing typists down is a myth" meme: same >> Wikipedia contributor takes an article which *clearly and obviously* >> repeats the conventional narrative that QWERTY was designed to >> decrease the number of key presses per second, and uses that to defend >> the counter-myth that QWERTY wasn't designed to decrease the number of >> key presses per second! > > Er, the footnote is clearly and obviously being used to cite the claim > that that is popularly believed, not the claim that it's incorrect. That's not clear nor obvious to me. But I won't quibble, I'll accept that as a plausible interpretation. >> These are the historical facts: > >> - Sholes spend significant time developing a layout which reduced the >> number of jams by intentionally moving frequently typed characters >> far apart, which has the effect of slowing down the rate at which >> the typist can hit keys; > > "Moving characters far apart has the effect of slowing down the rate at > which the typist can hit keys" is neither a fact nor historical. Actually, yes it is. At least, according to this website: http://www.mit.edu/~jcb/Dvorak/history.html [quote] Because typists at that time used the "hunt-and-peck" method, Sholes's arrangement increased the time it took for the typists to hit the keys for common two-letter combinations enough to ensure that each type bar had time to fall back sufficiently far to be out of the way before the next one came up. [end quote] The QWERTY layout was first sold in 1873 while the first known use of ten-fingered typing was in 1878, and touch-typing wasn't invented for another decade, in 1888. So I think it is pretty clear that *at the time QWERTY was invented* it slowed down the rate at which keys were pressed, thus allowing an overall greater typing speed thanks to the reduced jamming. Short of a signed memo from Shole himself, commenting one way or another, I don't think we're going to find anything more definitive. Even though QWERTY wasn't designed with touch-typing in mind, it's interesting to look at some of the weaknesses of the system. It is almost as if it had been designed to make touch-typing as inefficient as possible :-) Just consider the home keys. The home keys require the least amount of finger or hand movement, and are therefore the fastest to reach. With QWERTY, the eight home keys only cover a fraction over a quarter of all key presses: ASDF JKL; have frequencies of 8.12% 6.28% 4.32% 2.30% 0.10% 0.69% 3.98% and effectively 0% making a total of 25.79%. If you also include G and H as "virtual home-keys", that rises to 33.74%. But that's far less than the obvious tactic of using the most common letters ETAOIN as the home keys, which would cover 51.18% just from those eight keys alone. The 19th century Blickensderfer typewriter used a similar layout, with the ten home keys DHIATENSOR as the home keys. This would allow the typist to make just under 74% of all alphabetical key presses without moving the hands. https://en.wikipedia.org/wiki/Blickensderfer_typewriter Letter frequencies taken from here: http://www.math.cornell.edu/~mec/2003-2004/cryptography/subs/frequencies.html > Keys > that are further apart *can be hit faster without jamming* due to the > specifics of the type-basket mechanism, and there's no reason to think > that they can't be hit with at least equal speed by the typist. You may be correct about that specific issue when it comes to touch typing, but touch typing was 15 years in the future when Sholes invented QWERTY. And unlike Guido, he didn't have a time-machine :-) -- Steven From rustompmody at gmail.com Sun Apr 17 21:39:36 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 17 Apr 2016 18:39:36 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> Message-ID: <04721fe6-5feb-49c8-b5b2-beb12f6ff495@googlegroups.com> On Sunday, April 17, 2016 at 9:19:48 AM UTC+5:30, Chris Angelico wrote: > On Sun, Apr 17, 2016 at 1:44 PM, Rustom Mody wrote: > > Thats a strange self-contradiction. I wrote this: > > http://blog.languager.org/2012/10/layout-imperative-in-functional.html > > to make the case against PEP8 style line length strictures. > > Which has the SAME code formatted in two styles: > > > > -- < 80 cols, 48 lines > > -- 115 cols 37 lines > > > > Clearly the 115 cols is MORE fittable in a page than the 80 cols > > [Though my argument for that is based on other structural/semantic principles] > > There are certain specific situations where 80 (79) is the correct > width to aim for, but even if you aren't going for that, there's still > the general principle that longer lines are harder to read. So maybe > you declare that your codebase is allowed to go to 100, or 120, but > you don't want to let it run to 2048. No matter WHAT screen you're on, > that's too wide! yes we can agree on this -- arbitrary line lengths are almost certainly unreadable. The problem then becomes so what is optimal? Interesting question... and one that certainly has no bearing on the characteristics. of 30 year old technology. Remember that the most important characteristics of code are almost always un-legislatable eg choose 'nice' names. From steve at pearwood.info Sun Apr 17 21:57:01 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 18 Apr 2016 11:57:01 +1000 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> <877ffw5wjo.fsf@elektro.pacujo.net> Message-ID: <57143eee$0$1612$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Apr 2016 09:01 pm, Marko Rauhamaa wrote: > In fact, if you find yourself introducing coding "paragraphs" with > comments: > > def f(...): > # I'll start by doing this > ... > # segueing into the middle portion > ... > # and finish it off as follows > ... > > you had better break those paragraphs off into separate functions. Just > turn your comments into function names. I'm reminded of the book "Refactoring - Ruby Edition" by Jay Fields, Shane Harvie and Martin Fowler (which I strongly recommend, for what it's worth). It is full of sections like: Change Value to Reference Change Reference to Value Decompose Conditional Recompose Conditional and most relevant to this discussion: Extract Method Inline Method (For "Method", substitute "Function".) The intro to Extract Method says: "You have a code fragment that can be grouped together." and then the author explains that he looks for methods which are too long, or code that needs a comment to explain what it does, and turns that fragment of code into its own method. But then the same author goes on to introduce Inline Method: "A method's body is just as clear as its name." and explains "sometimes you do come across a method in which the body is as clear as the name. ... When this happens, you should then get rid of the method. Indirection can be helpful, but needless indirection is irritating." Indeed. Once your code is the most straight-forward and simple implementation of the needed algorithm, it is hard to reduce complexity any further. All you can do is move the complexity around. You can hide the complexity inside the function, where it exposes itself only to those who need to dig into the body of the function to understand what it does. Or you can extract the code into functions of their own, which decreases the internal complexity of the function, but increases the complexity of the application or module. Extract Method hides complexity of the function by moving it into the module: def Do_The_Thing(): ... def internal_subpart_start(): ... def internal_subpart_middle(): ... def internal_subpart_end(): ... Inline Method reduces module complexity by moving it into the function: def Do_The_Thing(): ... # internal subpart start ... # internal subpart middle ... # internal subpart end But the total complexity remains the same. One technique which is common in Pascal, but less so in Python, is to get the best of both worlds by using nested functions. In Python syntax: def Do_The_Thing(): def internal_subpart_start(): ... def internal_subpart_middle(): ... def internal_subpart_end(): ... ... This hides complexity of the function by moving it into the nested functions, where they can be ignored, but without increasing the complexity of the module. (Of course, the *total* complexity of module, function and nested functions is the same.) -- Steven From steve at pearwood.info Sun Apr 17 21:59:39 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 18 Apr 2016 11:59:39 +1000 Subject: Moderation and slight change of (de facto) policy References: <5713C08F.3010207@timgolden.me.uk> <57140947.3050902@gmail.com> <1460939260.3483225.581520729.146827C9@webmail.messagingengine.com> Message-ID: <57143f8b$0$1612$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Apr 2016 10:27 am, Random832 wrote: > As an alternative, when you send them through can you put a note on the > bottom saying they're not subscribed, to remind people to CC them in > responses? That doesn't work so well from Usenet. I can reply via news (which definitely works), or I can reply via email (which may or may not work), but it is a pain to reply via *both*. -- Steven From random832 at fastmail.com Sun Apr 17 22:01:49 2016 From: random832 at fastmail.com (Random832) Date: Sun, 17 Apr 2016 22:01:49 -0400 Subject: QWERTY was not designed to intentionally slow typists down (was: Unicode normalisation [was Re: [beginner] What's wrong?]) In-Reply-To: <57143ac0$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <2796705.edb3E9ArW3@PointedEars.de> <1584744.4h7ToaqLat@PointedEars.de> <5705b9ef$0$1611$c3e8da3$5496439d@news.astraweb.com> <570748ec$0$1620$c3e8da3$5496439d@news.astraweb.com> <874mbcgfmd.fsf@elektro.pacujo.net> <753cdb8b-9f94-48d6-bc0d-589efba86afc@googlegroups.com> <8560vr627l.fsf_-_@benfinney.id.au> <570876f1$0$1619$c3e8da3$5496439d@news.astraweb.com> <1460217233.3804713.573755729.61D3FCF2@webmail.messagingengine.com> <57143ac0$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1460944909.3502334.581571497.197404E2@webmail.messagingengine.com> On Sun, Apr 17, 2016, at 21:39, Steven D'Aprano wrote: > Oh no, it's the thread that wouldn't die! *wink* > > Actually, yes it is. At least, according to this website: > > http://www.mit.edu/~jcb/Dvorak/history.html I'd really rather see an instance of the claim not associated with Dvorak marketing. It only holds up as an obvious inference from the nature of how typing works if we assume *one*-finger hunt-and-peck rather than two-finger. Your website describes two-finger as the method that was being replaced by the 1878 introduction of ten-finger typing. > The QWERTY layout was first sold in 1873 while the first known use of > ten-fingered typing was in 1878, and touch-typing wasn't invented for > another decade, in 1888. Two-finger hunt-and-peck is sufficient for placing keys on opposite hands to speed typing up rather than slow it down. From flebber.crue at gmail.com Sun Apr 17 22:05:24 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sun, 17 Apr 2016 19:05:24 -0700 (PDT) Subject: What iterable method should I use for Lists of Lists Message-ID: <67c4c88b-62e9-4275-a761-25e5d7114025@googlegroups.com> Hi I have an XML and using pyquery to obtain the elements within it and then write it to csv. What is the best most reliable way to take dictionaries of each element, and print them(csv write later) based on each position so get item 0 of each list and then it 1 and so on. Any other code I post is open to criticism. Because there are many attributes I will want to collect my thought is to create a list of lists, again seems a bit clunky so could be wrong. from pyquery import PyQuery as pq d = pq(filename='20160319RHIL0_edit.xml') res = d('nomination') # myAt = pq.each(res.attr('bbid')) # print(repr(res)) # myAt = [res.eq(i).attr('horse') for i in range(len(res))] # print(myAt) nomID = [res.eq(i).attr('horse') for i in range(len(res))] horseName = [res.eq(i).attr('horse') for i in range(len(res))] group = [nomID, horseName] for items in group: print(items) This is my source. Of $150000 and trophies of $1000. First $90000 and trophies of $1000 to owner, second $30000, third $15000, fourth $7500, fifth $3000, sixth $1500, seventh $1500, eighth $1500 No class restriction, Set Weights plus Penalties, For Three-Years-Old and Upwards, Fillies and Mares, (Group 3) No Allowances for apprentices. Field Limit: 14 + 4 EM If I do this nomID = [res.eq(i).attr('horse') for i in range(len(res))] horseName = [res.eq(i).attr('horse') for i in range(len(res))] print(nomID, horseName) comes out correctly In [7]: 171115 Vergara Since I will be taking another 10 attributes out of nominmation category an efficient way that ensures data integrity would be valued. Thanks Sayth From rosuav at gmail.com Sun Apr 17 22:09:57 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Apr 2016 12:09:57 +1000 Subject: QWERTY was not designed to intentionally slow typists down (was: Unicode normalisation [was Re: [beginner] What's wrong?]) In-Reply-To: <57143ac0$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <2796705.edb3E9ArW3@PointedEars.de> <1584744.4h7ToaqLat@PointedEars.de> <5705b9ef$0$1611$c3e8da3$5496439d@news.astraweb.com> <570748ec$0$1620$c3e8da3$5496439d@news.astraweb.com> <874mbcgfmd.fsf@elektro.pacujo.net> <753cdb8b-9f94-48d6-bc0d-589efba86afc@googlegroups.com> <8560vr627l.fsf_-_@benfinney.id.au> <570876f1$0$1619$c3e8da3$5496439d@news.astraweb.com> <1460217233.3804713.573755729.61D3FCF2@webmail.messagingengine.com> <57143ac0$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Apr 18, 2016 at 11:39 AM, Steven D'Aprano wrote: > With QWERTY, the eight home keys only cover a fraction over a quarter of > all key presses: ASDF JKL; have frequencies of > > 8.12% 6.28% 4.32% 2.30% 0.10% 0.69% 3.98% and effectively 0% > > making a total of 25.79%. If you also include G and H as "virtual > home-keys", that rises to 33.74%. Hey, that's a little unfair. Remember, lots of people still have to write C code, so the semicolon is an important character! :) In fact, skimming the CPython source code (grouped by file extension) shows that C code has more semicolons than j's or k's: a 3.19% s 3.26% d 1.90% f 1.76% g 0.95% h 0.89% j 0.36% k 0.35% l 2.62% ; 1.40% for a total of 16.69% of characters coming from the home row. ChrisA From flebber.crue at gmail.com Sun Apr 17 22:12:45 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sun, 17 Apr 2016 19:12:45 -0700 (PDT) Subject: What iterable method should I use for Lists of Lists In-Reply-To: <67c4c88b-62e9-4275-a761-25e5d7114025@googlegroups.com> References: <67c4c88b-62e9-4275-a761-25e5d7114025@googlegroups.com> Message-ID: On Monday, 18 April 2016 12:05:39 UTC+10, Sayth Renshaw wrote: > Hi > > I have an XML and using pyquery to obtain the elements within it and then write it to csv. > > What is the best most reliable way to take dictionaries of each element, and print them(csv write later) based on each position so get item 0 of each list and then it 1 and so on. > > Any other code I post is open to criticism. Because there are many attributes I will want to collect my thought is to create a list of lists, again seems a bit clunky so could be wrong. > > from pyquery import PyQuery as pq > > > d = pq(filename='20160319RHIL0_edit.xml') > res = d('nomination') > # myAt = pq.each(res.attr('bbid')) > # print(repr(res)) > # myAt = [res.eq(i).attr('horse') for i in range(len(res))] > # print(myAt) > > nomID = [res.eq(i).attr('horse') for i in range(len(res))] > horseName = [res.eq(i).attr('horse') for i in range(len(res))] > group = [nomID, horseName] > > for items in group: > print(items) > > > This is my source. > > > > > > Of $150000 and trophies of $1000. First $90000 and trophies of $1000 to owner, second $30000, third $15000, fourth $7500, fifth $3000, sixth $1500, seventh $1500, eighth $1500 > No class restriction, Set Weights plus Penalties, For Three-Years-Old and Upwards, Fillies and Mares, (Group 3) > No Allowances for apprentices. Field Limit: 14 + 4 EM > > > > > > > > > > > > > > > If I do this > > > nomID = [res.eq(i).attr('horse') for i in range(len(res))] > horseName = [res.eq(i).attr('horse') for i in range(len(res))] > print(nomID, horseName) > > comes out correctly > > In [7]: 171115 Vergara > > Since I will be taking another 10 attributes out of nominmation category an efficient way that ensures data integrity would be valued. > > Thanks > > Sayth Also if I create it as an iterable only the first list in the list is printed. group = [nomID, horseName] iterthis = iter(group) for items in iterthis: print(items) In [10]: ['Vergara', 'Heavens Above', 'Sweet Fire', 'Alegria', 'Piamimi', 'Blendwell', 'Adorabeel (NZ)', 'Mary Lou', 'Skyline Blush', 'All Cerise', 'Gust of Wind (NZ)'] ['Vergara', 'Heavens Above', 'Sweet Fire', 'Alegria', 'Piamimi', 'Blendwell', 'Adorabeel (NZ)', 'Mary Lou', 'Skyline Blush', 'All Cerise', 'Gust of Wind (NZ)'] Sayth From flebber.crue at gmail.com Sun Apr 17 23:13:08 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sun, 17 Apr 2016 20:13:08 -0700 (PDT) Subject: What iterable method should I use for Lists of Lists In-Reply-To: References: <67c4c88b-62e9-4275-a761-25e5d7114025@googlegroups.com> Message-ID: <0a8c3fd1-ca01-4a62-b2fb-10fd841cde74@googlegroups.com> On Monday, 18 April 2016 12:12:59 UTC+10, Sayth Renshaw wrote: > On Monday, 18 April 2016 12:05:39 UTC+10, Sayth Renshaw wrote: > > Hi > > > > I have an XML and using pyquery to obtain the elements within it and then write it to csv. > > > > What is the best most reliable way to take dictionaries of each element, and print them(csv write later) based on each position so get item 0 of each list and then it 1 and so on. > > > > Any other code I post is open to criticism. Because there are many attributes I will want to collect my thought is to create a list of lists, again seems a bit clunky so could be wrong. > > > > from pyquery import PyQuery as pq > > > > > > d = pq(filename='20160319RHIL0_edit.xml') > > res = d('nomination') > > # myAt = pq.each(res.attr('bbid')) > > # print(repr(res)) > > # myAt = [res.eq(i).attr('horse') for i in range(len(res))] > > # print(myAt) > > > > nomID = [res.eq(i).attr('horse') for i in range(len(res))] > > horseName = [res.eq(i).attr('horse') for i in range(len(res))] > > group = [nomID, horseName] > > > > for items in group: > > print(items) > > > > > > This is my source. > > > > > > > > > > > > Of $150000 and trophies of $1000. First $90000 and trophies of $1000 to owner, second $30000, third $15000, fourth $7500, fifth $3000, sixth $1500, seventh $1500, eighth $1500 > > No class restriction, Set Weights plus Penalties, For Three-Years-Old and Upwards, Fillies and Mares, (Group 3) > > No Allowances for apprentices. Field Limit: 14 + 4 EM > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > If I do this > > > > > > nomID = [res.eq(i).attr('horse') for i in range(len(res))] > > horseName = [res.eq(i).attr('horse') for i in range(len(res))] > > print(nomID, horseName) > > > > comes out correctly > > > > In [7]: 171115 Vergara > > > > Since I will be taking another 10 attributes out of nominmation category an efficient way that ensures data integrity would be valued. > > > > Thanks > > > > Sayth > > Also if I create it as an iterable only the first list in the list is printed. > > group = [nomID, horseName] > > iterthis = iter(group) > > for items in iterthis: > print(items) > > In [10]: ['Vergara', 'Heavens Above', 'Sweet Fire', 'Alegria', 'Piamimi', 'Blendwell', 'Adorabeel (NZ)', 'Mary Lou', 'Skyline Blush', 'All Cerise', 'Gust of Wind (NZ)'] > ['Vergara', 'Heavens Above', 'Sweet Fire', 'Alegria', 'Piamimi', 'Blendwell', 'Adorabeel (NZ)', 'Mary Lou', 'Skyline Blush', 'All Cerise', 'Gust of Wind (NZ)'] > > Sayth Think I have a solution of sorts, although my numpy array failed, zip worked. from pyquery import PyQuery as pq import numpy as np d = pq(filename='20160319RHIL0_edit.xml') res = d('nomination') # myAt = pq.each(res.attr('bbid')) # print(repr(res)) # myAt = [res.eq(i).attr('horse') for i in range(len(res))] # print(myAt) nomID = [res.eq(i).attr('id') for i in range(len(res))] horseName = [res.eq(i).attr('horse') for i in range(len(res))] zipped = zip(nomID, horseName) # yes = np.array(zipped) for items in zipped: print(items) In [8]: ('171115', 'Vergara') ('187674', 'Heavens Above') ('184732', 'Sweet Fire') ('181928', 'Alegria') ('158914', 'Piamimi') ('171408', 'Blendwell') ('166836', 'Adorabeel (NZ)') ('172933', 'Mary Lou') ('182533', 'Skyline Blush') ('171801', 'All Cerise') ('181079', 'Gust of Wind (NZ)') Still interested if there is a better to do this. Sayth From steve at pearwood.info Sun Apr 17 23:19:08 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 18 Apr 2016 13:19:08 +1000 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> <04721fe6-5feb-49c8-b5b2-beb12f6ff495@googlegroups.com> Message-ID: <5714522d$0$1622$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Apr 2016 11:39 am, Rustom Mody wrote: > yes we can agree on this -- arbitrary line lengths are almost certainly > unreadable. > The problem then becomes so what is optimal? I really don't think it is a problem. We have about 400 years of experience with printed text, and that experience tells us that the optimal width for reading prose in Western languages is about 60 characters, give or take. This width is optimal for eye movement, and minimizes the number of errors and reduces eye-strain. There's only so far that our eyes can follow a line to the right without increasing stress or reading errors, and likewise when returning back to the left margin. The longer the line, the higher the chance of losing track, and the physical effort it takes to read. (You have to move the eyes further, and for extremely long lines, you may have to move your entire head.) Long lines are simply harder to read because you have to move your eyes more, and the longer the lines, the greater the tendency to wander across the lines. Especially if the lines are close together and the height of the lines is small. (It boggles my mind how many programmers I've met who routinely view their code in tiny physical heights, even when reading it in fine detail.) The optimal width for eye-tracking (that is, the maximum width for which the rate of such errors can be disregarded) is somewhere about sixty characters per line. The same eye-tracking considerations apply to code, but: when it comes to code, we don't always have to track all the way back to the left-hand margin. If we start (say) up to twenty columns in, then we can afford to write up to twenty columns further to the right too. (Also, code tends to have VERY ragged right-hand margins. Not all lines end up even close to sixty characters wide.) There are other considerations though. Unlike prose, with code, shorter lines *may* sometimes force an increase in complexity. For instance, temporary variables need to be created, or new functions created, just to avoid otherwise excessively long lines. So one might be willing to accept a little more eye-movement for a little less code complexity. So allowing a total width of 80 (give or take) is already a compromise from the optimal sixty characters. This compromise allows for indented code, and allows up to 20 characters extra to avoid creating more complexity elsewhere. But there's another factor: long lines of code are themselves a code-smell. Perhaps: - you have indented too deeply, suggesting that your function is doing too much or has too much internal complexity: def func(): if a: for b in seq: while c: with d: try: try: for e in it: block # only 48 columns available here (But note also that even with this extreme example, eight indentation levels deep, you can still fit almost characters per line without breaking the 80-char limit. You can do a lot in 50 characters.) - you have too many expressions on one line, suggesting that the over-all complexity of the line is excessive; - your variable or function names are needlessly verbose or are doing too much or are too specific ("calculate_number_of_pages_and_number_of_semicolons_in_chapter_one"); - or you are violating the rule of Demeter: get(customer.trousers.pocket.wallet).open().money.pay(1) In other words, long lines of code are themselves an indication of poorly-designed code. Even though there are exceptions, we should resist strongly the urge to extend beyond the 60-80 (or perhaps 90 in extreme cases) limit. Whenever I hear people saying that they regularly need to use 100 or even 120 columns for their code, what I hear is "my code is badly written". -- Steven From rustompmody at gmail.com Sun Apr 17 23:48:58 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 17 Apr 2016 20:48:58 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: <5714522d$0$1622$c3e8da3$5496439d@news.astraweb.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> <04721fe6-5feb-49c8-b5b2-beb12f6ff495@googlegroups.com> <5714522d$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, April 18, 2016 at 8:49:33 AM UTC+5:30, Steven D'Aprano wrote: > On Mon, 18 Apr 2016 11:39 am, Rustom Mody wrote: > > > yes we can agree on this -- arbitrary line lengths are almost certainly > > unreadable. > > The problem then becomes so what is optimal? > > I really don't think it is a problem. We have about 400 years > of experience with printed text, and that experience tells us > that the optimal width for reading prose in Western languages > is about 60 characters, give or take. This width is optimal > for eye movement, and minimizes the number of errors and > reduces eye-strain. No disagreement so far > > There's only so far that our eyes can follow a line to the > right without increasing stress or reading errors, and > likewise when returning back to the left margin. The longer > the line, the higher the chance of losing track, and the > physical effort it takes to read. (You have to move the eyes > further, and for extremely long lines, you may have to move > your entire head.) > > Long lines are simply harder to read because you have to > move your eyes more, and the longer the lines, the greater > the tendency to wander across the lines. Especially if the > lines are close together and the height of the lines is > small. (It boggles my mind how many programmers I've met who > routinely view their code in tiny physical heights, even > when reading it in fine detail.) > > The optimal width for eye-tracking (that is, the maximum > width for which the rate of such errors can be disregarded) > is somewhere about sixty characters per line. Maybe even this is ok > > The same eye-tracking considerations apply to code This is nonsense. The last attempt of making code text-ish was Cobol -- by most accounts an unhappy experience. What is more code needs to be read very intensively for comprehension "x... what is x where is it defined? (scan backwards) ah there? Uh no further back... No global..." My own estimate of increased back-n-forth scanning of code vs plain text is probably an order of magnitude ie close to 10 times Even if I grant that you are twice as good a programmer as I am it will become 5 times. You would have to be 10 times better than me to equalize to (my) plaintext rate But if you are that kind of genius you probably speed-read plain text as well. tl;dr 1. Different languages -- natural and computer -- have different optimal line lengths. 2. There is very scant data on that. 3. PEP8 style strictures only delay discovery and collection of such data From torriem at gmail.com Sun Apr 17 23:50:58 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 17 Apr 2016 21:50:58 -0600 Subject: QWERTY was not designed to intentionally slow typists down In-Reply-To: <57143ac0$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <2796705.edb3E9ArW3@PointedEars.de> <1584744.4h7ToaqLat@PointedEars.de> <5705b9ef$0$1611$c3e8da3$5496439d@news.astraweb.com> <570748ec$0$1620$c3e8da3$5496439d@news.astraweb.com> <874mbcgfmd.fsf@elektro.pacujo.net> <753cdb8b-9f94-48d6-bc0d-589efba86afc@googlegroups.com> <8560vr627l.fsf_-_@benfinney.id.au> <570876f1$0$1619$c3e8da3$5496439d@news.astraweb.com> <1460217233.3804713.573755729.61D3FCF2@webmail.messagingengine.com> <57143ac0$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: <571459A2.6050700@gmail.com> On 04/17/2016 07:39 PM, Steven D'Aprano wrote: > Even though QWERTY wasn't designed with touch-typing in mind, it's > interesting to look at some of the weaknesses of the system. It is almost > as if it had been designed to make touch-typing as inefficient as > possible :-) Just consider the home keys. The home keys require the least > amount of finger or hand movement, and are therefore the fastest to reach. > With QWERTY, the eight home keys only cover a fraction over a quarter of > all key presses: ASDF JKL; have frequencies of > > 8.12% 6.28% 4.32% 2.30% 0.10% 0.69% 3.98% and effectively 0% > > making a total of 25.79%. If you also include G and H as "virtual > home-keys", that rises to 33.74%. > > But that's far less than the obvious tactic of using the most common > letters ETAOIN as the home keys, which would cover 51.18% just from those > eight keys alone. The 19th century Blickensderfer typewriter used a similar > layout, with the ten home keys DHIATENSOR as the home keys. This would > allow the typist to make just under 74% of all alphabetical key presses > without moving the hands. While they Dvorak layout also puts more coverage in the home row, and also lets the touch typist alternate more equally between the fingers, I had to quit using it because it just wasn't as comfortable to use with vi, especially for things like cursor navigation, and I didn't really want to remap all the keys. vi is very flexible and I bet there are key mappings for vi that work better with Dvorak. Maybe if I try it again I'll have another look. From saxri89 at gmail.com Sun Apr 17 23:53:13 2016 From: saxri89 at gmail.com (Xristos Xristoou) Date: Sun, 17 Apr 2016 20:53:13 -0700 (PDT) Subject: scipy install error,need help its important Message-ID: <6931c7f5-ffa0-4a8c-86bc-d257f0582c09@googlegroups.com> guys i have big proplem i want to install scipy but all time show me error i have python 2.7 and windows 10 i try to use pip install scipy and i take that error raise NotFoundError('no lapack/blas resources found') numpy.distutils.system_info.NotFoundError: no lapack/blas resources found Command "C:\Python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\name\\appdata\\local\\temp\\pip-build-a3fjaf\\scipy\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\name\appdata\local\temp\pip-pgtkuz-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\name\appdata\local\temp\pip-build-a3fjaf\scipy\ From christopher_reimer at icloud.com Mon Apr 18 00:04:04 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sun, 17 Apr 2016 21:04:04 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: References: <5713E52D.3060407@icloud.com> Message-ID: <57145CB4.5040100@icloud.com> On 4/17/2016 3:18 PM, Michael Selik wrote: > I'd rather turn the question around: how much sanity checking is > necessary or useful? You'll find the answer is "surprisingly little" > compared to your experience in Java. I'm looking for a pythonic approach to sanity checking. From what I read elsewhere, sanity checking belongs in the unit tests and/or library classes designed for other people to use. I haven't seen many examples of sanity checks that is common in Java. > For example, you don't need to > explicitly check whether the color is present in your dictionary, > because it'll give you a KeyError if you look up a bad key. Without the sanity check against the constant dictionary, the color variable could be anything (it should be a string value). Looking at the code again, I should relocate the sanity checks in the Piece base class. > Why does the len of positions need to be 16? The positions variable is list of coordinates for 16 chess pieces (eight pawns, two rooks, two knights, two bishops, a king and a queen) for each color, locating the pieces on either the bottom quarter (i.e., [(1,1), ..., (2,8)]) or the top quarter (i.e., [(7,1), ..., (8,8)]) of the board. Thanks, Chris R. From brunnre8 at gmail.com Mon Apr 18 00:05:19 2016 From: brunnre8 at gmail.com (Reto Brunner) Date: Mon, 18 Apr 2016 04:05:19 +0000 Subject: Creating a hot vector (numpy) In-Reply-To: References: Message-ID: Hi, It is called broadcasting an array, have a look here: http://docs.scipy.org/doc/numpy-1.10.1/user/basics.broadcasting.html Greetings, Reto On Mon, Apr 18, 2016, 02:54 Paulo da Silva wrote: > Hi all. > > I have seen this "trick" to create a hot vector. > > In [45]: x > Out[45]: array([0, 1]) > > In [46]: y > Out[46]: array([1, 1, 1, 0, 0, 1, 0, 0], dtype=uint8) > > In [47]: y[:,None] > Out[47]: > array([[1], > [1], > [1], > [0], > [0], > [1], > [0], > [0]], dtype=uint8) > > In [48]: x==y[:,None] > Out[48]: > array([[False, True], > [False, True], > [False, True], > [ True, False], > [ True, False], > [False, True], > [ True, False], > [ True, False]], dtype=bool) > > In [49]: (x==y[:,None]).astype(np.float32) > Out[49]: > array([[ 0., 1.], > [ 0., 1.], > [ 0., 1.], > [ 1., 0.], > [ 1., 0.], > [ 0., 1.], > [ 1., 0.], > [ 1., 0.]], dtype=float32) > > How does this (step 48) work? > > Thanks > -- > https://mail.python.org/mailman/listinfo/python-list > From rustompmody at gmail.com Mon Apr 18 00:06:35 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 17 Apr 2016 21:06:35 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> Message-ID: <91134e90-1cce-471b-9f5a-616276886e84@googlegroups.com> On Sunday, April 17, 2016 at 3:34:56 PM UTC+5:30, BartC wrote: > On 17/04/2016 04:44, Rustom Mody wrote: > > On Saturday, April 16, 2016 at 10:22:10 PM UTC+5:30, Marko Rauhamaa wrote: > > >> It comes with the maxim that one function must be visible at once on the > >> screen. > > > > Thats a strange self-contradiction. I wrote this: > > http://blog.languager.org/2012/10/layout-imperative-in-functional.html > > to make the case against PEP8 style line length strictures. > > Which has the SAME code formatted in two styles: > > > > -- < 80 cols, 48 lines > > -- 115 cols 37 lines > > > > Clearly the 115 cols is MORE fittable in a page than the 80 cols > > [Though my argument for that is based on other structural/semantic principles] > > Um, that's a different language, or does PEP8 apply to Haskell too? > > Haskell has a style that likes to be written horizontally (rather than > have statements one after another - /on separate lines/ - as in > imperative code). > > I also have trouble regarding that code as a single function, as it > implements (AFAICS) an entire lexer. It resembles data more than > anything else, and data presumably is allowed to be scrolled. Thats a nice point ... and often neglected by even the aficionados of functional programming. See Data Orientation http://blog.languager.org/2012/10/functional-programming-lost-booty.html [yeah funny that I am tell you this given your recent famous thread on lexing!] Come to think of it take an SQL DBMS browser. Should we say: Horizontal scrolls are BAD; just reformat the table after reaching 80 columns? In fact much of the point of http://blog.languager.org/2012/10/layout-imperative-in-functional.html is just this: that as code becomes more and more data-ish, a more-lines-less-columns regime becomes correspondingly irksome. > Otherwise things would be very restrictive! Dont understand that comment From flebber.crue at gmail.com Mon Apr 18 00:09:30 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sun, 17 Apr 2016 21:09:30 -0700 (PDT) Subject: What iterable method should I use for Lists of Lists In-Reply-To: <0a8c3fd1-ca01-4a62-b2fb-10fd841cde74@googlegroups.com> References: <67c4c88b-62e9-4275-a761-25e5d7114025@googlegroups.com> <0a8c3fd1-ca01-4a62-b2fb-10fd841cde74@googlegroups.com> Message-ID: <6e0e6e06-269d-44ab-badc-6f27071d3649@googlegroups.com> On Monday, 18 April 2016 13:13:21 UTC+10, Sayth Renshaw wrote: > On Monday, 18 April 2016 12:12:59 UTC+10, Sayth Renshaw wrote: > > On Monday, 18 April 2016 12:05:39 UTC+10, Sayth Renshaw wrote: > > > Hi > > > > > > I have an XML and using pyquery to obtain the elements within it and then write it to csv. > > > > > > What is the best most reliable way to take dictionaries of each element, and print them(csv write later) based on each position so get item 0 of each list and then it 1 and so on. > > > > > > Any other code I post is open to criticism. Because there are many attributes I will want to collect my thought is to create a list of lists, again seems a bit clunky so could be wrong. > > > > > > from pyquery import PyQuery as pq > > > > > > > > > d = pq(filename='20160319RHIL0_edit.xml') > > > res = d('nomination') > > > # myAt = pq.each(res.attr('bbid')) > > > # print(repr(res)) > > > # myAt = [res.eq(i).attr('horse') for i in range(len(res))] > > > # print(myAt) > > > > > > nomID = [res.eq(i).attr('horse') for i in range(len(res))] > > > horseName = [res.eq(i).attr('horse') for i in range(len(res))] > > > group = [nomID, horseName] > > > > > > for items in group: > > > print(items) > > > > > > > > > This is my source. > > > > > > > > > > > > > > > > > > Of $150000 and trophies of $1000. First $90000 and trophies of $1000 to owner, second $30000, third $15000, fourth $7500, fifth $3000, sixth $1500, seventh $1500, eighth $1500 > > > No class restriction, Set Weights plus Penalties, For Three-Years-Old and Upwards, Fillies and Mares, (Group 3) > > > No Allowances for apprentices. Field Limit: 14 + 4 EM > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > If I do this > > > > > > > > > nomID = [res.eq(i).attr('horse') for i in range(len(res))] > > > horseName = [res.eq(i).attr('horse') for i in range(len(res))] > > > print(nomID, horseName) > > > > > > comes out correctly > > > > > > In [7]: 171115 Vergara > > > > > > Since I will be taking another 10 attributes out of nominmation category an efficient way that ensures data integrity would be valued. > > > > > > Thanks > > > > > > Sayth > > > > Also if I create it as an iterable only the first list in the list is printed. > > > > group = [nomID, horseName] > > > > iterthis = iter(group) > > > > for items in iterthis: > > print(items) > > > > In [10]: ['Vergara', 'Heavens Above', 'Sweet Fire', 'Alegria', 'Piamimi', 'Blendwell', 'Adorabeel (NZ)', 'Mary Lou', 'Skyline Blush', 'All Cerise', 'Gust of Wind (NZ)'] > > ['Vergara', 'Heavens Above', 'Sweet Fire', 'Alegria', 'Piamimi', 'Blendwell', 'Adorabeel (NZ)', 'Mary Lou', 'Skyline Blush', 'All Cerise', 'Gust of Wind (NZ)'] > > > > Sayth > > Think I have a solution of sorts, although my numpy array failed, zip worked. > > from pyquery import PyQuery as pq > import numpy as np > > d = pq(filename='20160319RHIL0_edit.xml') > res = d('nomination') > # myAt = pq.each(res.attr('bbid')) > # print(repr(res)) > # myAt = [res.eq(i).attr('horse') for i in range(len(res))] > # print(myAt) > > nomID = [res.eq(i).attr('id') for i in range(len(res))] > horseName = [res.eq(i).attr('horse') for i in range(len(res))] > zipped = zip(nomID, horseName) > > # yes = np.array(zipped) > for items in zipped: > print(items) > > In [8]: ('171115', 'Vergara') > ('187674', 'Heavens Above') > ('184732', 'Sweet Fire') > ('181928', 'Alegria') > ('158914', 'Piamimi') > ('171408', 'Blendwell') > ('166836', 'Adorabeel (NZ)') > ('172933', 'Mary Lou') > ('182533', 'Skyline Blush') > ('171801', 'All Cerise') > ('181079', 'Gust of Wind (NZ)') > > Still interested if there is a better to do this. > > Sayth Using zip and Pandas I can get it into a good format easily, yay python. from pyquery import PyQuery as pq import pandas as pd d = pq(filename='20160319RHIL0_edit.xml') res = d('nomination') nomID = [res.eq(i).attr('id') for i in range(len(res))] horseName = [res.eq(i).attr('horse') for i in range(len(res))] zipped = list(zip(nomID, horseName)) frames = pd.DataFrame(zipped) print(frames) 0 1 0 171115 Vergara 1 187674 Heavens Above 2 184732 Sweet Fire 3 181928 Alegria 4 158914 Piamimi 5 171408 Blendwell 6 166836 Adorabeel (NZ) 7 172933 Mary Lou 8 182533 Skyline Blush 9 171801 All Cerise 10 181079 Gust of Wind (NZ) Sayth From flebber.crue at gmail.com Mon Apr 18 00:11:52 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sun, 17 Apr 2016 21:11:52 -0700 (PDT) Subject: scipy install error,need help its important In-Reply-To: <6931c7f5-ffa0-4a8c-86bc-d257f0582c09@googlegroups.com> References: <6931c7f5-ffa0-4a8c-86bc-d257f0582c09@googlegroups.com> Message-ID: <7f1b2ebb-a5aa-446a-83ad-436cc986d747@googlegroups.com> On Monday, 18 April 2016 13:53:30 UTC+10, Xristos Xristoou wrote: > guys i have big proplem i want to install scipy > but all time show me error > i have python 2.7 and windows 10 > i try to use pip install scipy and i take that error > > raise NotFoundError('no lapack/blas resources found') > numpy.distutils.system_info.NotFoundError: no lapack/blas resources found > > > Command "C:\Python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\name\\appdata\\local\\temp\\pip-build-a3fjaf\\scipy\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\name\appdata\local\temp\pip-pgtkuz-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\name\appdata\local\temp\pip-build-a3fjaf\scipy\ Either install and use anaconda https://www.continuum.io/downloads or use these builds to install. http://www.lfd.uci.edu/~gohlke/pythonlibs/ Cheers Sayth From flebber.crue at gmail.com Mon Apr 18 00:13:06 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sun, 17 Apr 2016 21:13:06 -0700 (PDT) Subject: scipy install error,need help its important In-Reply-To: <6931c7f5-ffa0-4a8c-86bc-d257f0582c09@googlegroups.com> References: <6931c7f5-ffa0-4a8c-86bc-d257f0582c09@googlegroups.com> Message-ID: <12eb1f0c-4e28-472d-926d-2497ebb747d3@googlegroups.com> On Monday, 18 April 2016 13:53:30 UTC+10, Xristos Xristoou wrote: > guys i have big proplem i want to install scipy > but all time show me error > i have python 2.7 and windows 10 > i try to use pip install scipy and i take that error > > raise NotFoundError('no lapack/blas resources found') > numpy.distutils.system_info.NotFoundError: no lapack/blas resources found > > > Command "C:\Python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\name\\appdata\\local\\temp\\pip-build-a3fjaf\\scipy\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\name\appdata\local\temp\pip-pgtkuz-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\name\appdata\local\temp\pip-build-a3fjaf\scipy\ Oh and I would choose the anaconda route. Then you can use conda to easy manage libraries that could otherwise be dificult on windows. Sayth From saxri89 at gmail.com Mon Apr 18 00:21:31 2016 From: saxri89 at gmail.com (Xristos Xristoou) Date: Sun, 17 Apr 2016 21:21:31 -0700 (PDT) Subject: scipy install error,need help its important In-Reply-To: <6931c7f5-ffa0-4a8c-86bc-d257f0582c09@googlegroups.com> References: <6931c7f5-ffa0-4a8c-86bc-d257f0582c09@googlegroups.com> Message-ID: ?? ???????, 18 ???????? 2016 - 6:53:30 ?.?. UTC+3, ? ??????? Xristos Xristoou ??????: after google search to many post propose install lapack and atla bt=ut i dont know > guys i have big proplem i want to install scipy > but all time show me error > i have python 2.7 and windows 10 > i try to use pip install scipy and i take that error > > raise NotFoundError('no lapack/blas resources found') > numpy.distutils.system_info.NotFoundError: no lapack/blas resources found > > > Command "C:\Python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\name\\appdata\\local\\temp\\pip-build-a3fjaf\\scipy\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\name\appdata\local\temp\pip-pgtkuz-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\name\appdata\local\temp\pip-build-a3fjaf\scipy\ From saxri89 at gmail.com Mon Apr 18 00:38:00 2016 From: saxri89 at gmail.com (Xristos Xristoou) Date: Sun, 17 Apr 2016 21:38:00 -0700 (PDT) Subject: scipy install error,need help its important In-Reply-To: <6931c7f5-ffa0-4a8c-86bc-d257f0582c09@googlegroups.com> References: <6931c7f5-ffa0-4a8c-86bc-d257f0582c09@googlegroups.com> Message-ID: <18152623-df1a-4da3-8b93-30672a7281f3@googlegroups.com> ?? ???????, 18 ???????? 2016 - 6:53:30 ?.?. UTC+3, ? ??????? Xristos Xristoou ??????: > guys i have big proplem i want to install scipy > but all time show me error > i have python 2.7 and windows 10 > i try to use pip install scipy and i take that error > > raise NotFoundError('no lapack/blas resources found') > numpy.distutils.system_info.NotFoundError: no lapack/blas resources found > > > Command "C:\Python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\name\\appdata\\local\\temp\\pip-build-a3fjaf\\scipy\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\name\appdata\local\temp\pip-pgtkuz-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\name\appdata\local\temp\pip-build-a3fjaf\scipy\ i fllow you with anaconda route and i install scipy without error but in the idle i write import scipy and show me erroe msg no module name scipy,why ? From rosuav at gmail.com Mon Apr 18 00:40:43 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Apr 2016 14:40:43 +1000 Subject: What iterable method should I use for Lists of Lists In-Reply-To: <6e0e6e06-269d-44ab-badc-6f27071d3649@googlegroups.com> References: <67c4c88b-62e9-4275-a761-25e5d7114025@googlegroups.com> <0a8c3fd1-ca01-4a62-b2fb-10fd841cde74@googlegroups.com> <6e0e6e06-269d-44ab-badc-6f27071d3649@googlegroups.com> Message-ID: On Mon, Apr 18, 2016 at 2:09 PM, Sayth Renshaw wrote: >> > > ="0" sectional1200="0" bonusindicator="" /> You're getting very chatty with yourself, which is fine... but do you need to quote your entire previous message every time? We really don't need another copy of your XML file in every post. Thanks! ChrisA From ethan at stoneleaf.us Mon Apr 18 01:26:21 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 17 Apr 2016 22:26:21 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <5713E52D.3060407@icloud.com> References: <5713E52D.3060407@icloud.com> Message-ID: <57146FFD.4090204@stoneleaf.us> On 04/17/2016 12:34 PM, Christopher Reimer wrote: > How much sanity checking is too much in Python? What happens if your extensive sanity checks turn up a bug? In Python the usual answer is you raise an error: raise ValueError('blahblah not a valid color') What happens if you don't sanity check anything and the wrong color is passed in? Python will raise an error for you: Traceback ... KeyError: 'blahblah' not found --- I sanity check for three reasons: 1) raise a nicer error message 2) keep the point of failure close to the error 3) the consequences of bad data are Bad Bad Things (tm) If none of those apply, I don't bother sanity checking. -- ~Ethan~ From marko at pacujo.net Mon Apr 18 01:32:07 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Apr 2016 08:32:07 +0300 Subject: Moderation and slight change of (de facto) policy References: <5713C08F.3010207@timgolden.me.uk> <57140947.3050902@gmail.com> <1460939260.3483225.581520729.146827C9@webmail.messagingengine.com> <57143f8b$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r3e34h48.fsf@elektro.pacujo.net> Steven D'Aprano : > On Mon, 18 Apr 2016 10:27 am, Random832 wrote: > >> As an alternative, when you send them through can you put a note on >> the bottom saying they're not subscribed, to remind people to CC them >> in responses? > > That doesn't work so well from Usenet. I can reply via news (which > definitely works), or I can reply via email (which may or may not > work), but it is a pain to reply via *both*. I don't like the Usenet+CC approach, but let's try it. Did you get the CC, Steven. Marko From tjreedy at udel.edu Mon Apr 18 01:39:19 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 18 Apr 2016 01:39:19 -0400 Subject: HTTPServer and SSL In-Reply-To: References: Message-ID: On 4/17/2016 10:56 AM, Radek Hol? wrote: > Hello, > > some people recommend following implementation of a simple HTTP server > that supports SSL: > > asdfghjkki > Handler = http.server.BaseHTTPRequestHandlerhttpd = > http.server.HTTPServer(("", 4443), Handler) > httpd.socket = ssl.wrap_socket(httpd.socket, server_side=True) > httpd.serve_forever() > > I wonder whether this usage is *supported* or not. The documentation > is not explicit about whether the httpd.socket attribute can be safely > reassigned. Also there were some questions regarding a simple HTTPS > server on this list already and none of the answerers mentioned this > approach. > > Also there used to be a HTTPSServer in the test suite of Python 2.7 in > 2014 that did a similar thing but in the "get_request" method but it > isn't there anymore. > > So, is there a *supported* way of combining http.server.HTTPServer and ssl? > > Best regards > -- Terry Jan Reedy From tjreedy at udel.edu Mon Apr 18 01:51:55 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 18 Apr 2016 01:51:55 -0400 Subject: HTTPServer and SSL In-Reply-To: References: Message-ID: On 4/18/2016 1:39 AM, Terry Reedy wrote: My apologies for the tired, twitchy finger junk post that I noticed 1/2 second after clicking the wrong button and I wish I oould delete. -- Terry Jan Reedy From kushal at locationd.net Mon Apr 18 01:57:53 2016 From: kushal at locationd.net (Kushal Kumaran) Date: Mon, 18 Apr 2016 11:27:53 +0530 Subject: [OT] Java generics In-Reply-To: (Chris Angelico's message of "Mon, 18 Apr 2016 09:30:56 +1000") References: Message-ID: <87potntq5a.fsf@carbon.locationd.net.> Chris Angelico writes: > On Mon, Apr 18, 2016 at 8:02 AM, Tim Delaney > wrote: >> I also wouldn't describe Java as a >> "perfectly good language" - it is at best a compromise language that just >> happened to be heavily promoted and accepted at the right time. >> >> Python is *much* closer to my idea of a perfectly good language. > > "Java" was originally four related, but separate, concepts: a source > language, a bytecode, a sandboxing system, and one other that I can't > now remember. > > The included standard library. I read Jamie Zawinski making this distinction in his rant at https://www.jwz.org/doc/java.html -- regards, kushal From auriocus at gmx.de Mon Apr 18 02:39:56 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 18 Apr 2016 08:39:56 +0200 Subject: scipy install error,need help its important In-Reply-To: <18152623-df1a-4da3-8b93-30672a7281f3@googlegroups.com> References: <6931c7f5-ffa0-4a8c-86bc-d257f0582c09@googlegroups.com> <18152623-df1a-4da3-8b93-30672a7281f3@googlegroups.com> Message-ID: Am 18.04.16 um 06:38 schrieb Xristos Xristoou: > > i fllow you with anaconda route and i install scipy without error > but in the idle i write import scipy and show me erroe msg no module name scipy,why ? > Maybe you run IDLE with the python that you had installed before? Try looking for IDLE within anaconda. Also read this thread: https://groups.google.com/a/continuum.io/forum/#!topic/anaconda/Dr8xFdKbA20 Christian From harirammanohar at gmail.com Mon Apr 18 03:07:44 2016 From: harirammanohar at gmail.com (harirammanohar at gmail.com) Date: Mon, 18 Apr 2016 00:07:44 -0700 (PDT) Subject: delete from pattern to pattern if it contains match Message-ID: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> HI All, can you help me out in doing below. file: guava fruit mango fruit orange fruit need to delete from start to end if it contains mango in a file... output should be: guava fruit orange fruit Thank you From flebber.crue at gmail.com Mon Apr 18 03:13:32 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Mon, 18 Apr 2016 00:13:32 -0700 (PDT) Subject: What iterable method should I use for Lists of Lists In-Reply-To: References: <67c4c88b-62e9-4275-a761-25e5d7114025@googlegroups.com> <0a8c3fd1-ca01-4a62-b2fb-10fd841cde74@googlegroups.com> <6e0e6e06-269d-44ab-badc-6f27071d3649@googlegroups.com> Message-ID: <3ad1c98f-a442-4744-8580-f48338282a13@googlegroups.com> > > You're getting very chatty with yourself, which is fine... but do you > need to quote your entire previous message every time? We really don't > need another copy of your XML file in every post. > > Thanks! > > ChrisA Oops sorry, everytime I posted I then thought of another resource and kept reading. I have a working messy solution hopefully I can resolve it to something nicer. Sayth From kasddoa at gmail.com Mon Apr 18 03:17:51 2016 From: kasddoa at gmail.com (pssdo aood) Date: Mon, 18 Apr 2016 00:17:51 -0700 (PDT) Subject: buy ambien online overnight shipping cheapest ambien with quick delivery Message-ID: <0dbba064-f603-465f-8be1-dbaca0830754@googlegroups.com> Click here to buy ambien ! 100 % Highest Quality! Save Your Time and Money! http://ow.ly/101LRw Looking for ambien ? No problem! Click here to buy ambien online order ambien without prescription | overnight ambien without a prescription | buy cheap ambien no Prescription BIEN online purchase | cheap ambien no prescription next day delivery | cod delivery ambien ambien without perscription |buy ambien without prescription pay cod | ambien shipped with no prescription how to get ambien prescription | pharmacy ambien no prescrption | buy ambien without perscription no prescription ambien fedex delivery | buy cheapGET OVERNIGHT ambien | ambien OVERNIGHT | ambien CHEAP FEDEX DELIVERY |BUY ambien cheap cod | ambien without presciption | doctor shopping for ambien script ______________________________________________ Click here to buy ambien ! 100 % Highest Quality! Save Your Time and Money! http://ow.ly/101LRw ambien overnight fedex ambien overnight shipping order ambien overnight ambien fast shipping-usa ambien for sale how to get ambien online buy zolpidem online buy ambien online next day delivery buy ambien online overnight shipping cheapest ambien with quick delivery ambien overnight fedex __________________________________________________ From steve+comp.lang.python at pearwood.info Mon Apr 18 03:21:58 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 18 Apr 2016 17:21:58 +1000 Subject: QWERTY was not designed to intentionally slow typists down (was: Unicode normalisation [was Re: [beginner] What's wrong?]) References: <2796705.edb3E9ArW3@PointedEars.de> <1584744.4h7ToaqLat@PointedEars.de> <5705b9ef$0$1611$c3e8da3$5496439d@news.astraweb.com> <570748ec$0$1620$c3e8da3$5496439d@news.astraweb.com> <874mbcgfmd.fsf@elektro.pacujo.net> <753cdb8b-9f94-48d6-bc0d-589efba86afc@googlegroups.com> <8560vr627l.fsf_-_@benfinney.id.au> <570876f1$0$1619$c3e8da3$5496439d@news.astraweb.com> <1460217233.3804713.573755729.61D3FCF2@webmail.messagingengine.com> <57143ac0$0$1609$c3e8da3$5496439d@news.astraweb.com> <1460944909.3502334.581571497.197404E2@webmail.messagingengine.com> Message-ID: <57148b18$0$11112$c3e8da3@news.astraweb.com> On Monday 18 April 2016 12:01, Random832 wrote: > On Sun, Apr 17, 2016, at 21:39, Steven D'Aprano wrote: >> Oh no, it's the thread that wouldn't die! *wink* >> >> Actually, yes it is. At least, according to this website: >> >> http://www.mit.edu/~jcb/Dvorak/history.html > > I'd really rather see an instance of the claim not associated with > Dvorak marketing. So would I, but this is hardly a Dvorak *marketing*. The author even points out that the famous case-study done by the US Navy was "biased, and at worst, fabricated". http://www.mit.edu/~jcb/Dvorak/ And he too repeats the canard that "Contrary to popular opinion" QWERTY wasn't designed to slow typists down. (Even though he later goes on to support the popular opinion.) You can also read the article in Reason magazine: http://reason.com/archives/1996/06/01/typing-errors You can skip the entire first page -- it is almost entirely a screed against government regulation and a defence of the all-mighty free-market. But the article goes through some fairly compelling evidence that Dvorak keyboards are barely more efficient that QWERTY, and that there was plenty of competition in type-writers in the late 1800s. I don't agree with the Reason article that they have disproven the conventional wisdom that QWERTY won the typewriter wars due to luck and path-dependence. The authors are (in my opinion) overly keen to dismiss path-dependence, for instance taking it as self-evidently true that the use of QWERTY in the US would have no influence over other countries' choice in key layout. But it does support the contention that, at the time, QWERTY was faster than the alternatives. Unfortunately, what it doesn't talk about is whether or not the alternate layouts had fewer jams. Wikipedia's article on QWERTY shows the various designs used by Sholes and Remington, leading to the modern layout https://en.wikipedia.org/wiki/QWERTY One serious problem for discussion is that the QWERTY keyboard we use now is *not* the same as that designed by Sholes. For instance, one anomaly is that two very common digraphs, ER and RE, are right next to each other. But that's not how Sholes laid out the keys. On his keyboard, the top row was initially AEI.?Y then changed to QWE.TY. Failure to recognise this leads to errors like this blogger's claim that it is "wrong" that QWERTY was designed to break apart common digraphs: http://yasuoka.blogspot.com.au/2006/08/sholes-discovered-that-many- english.html Even on a modern keyboard, out of the ten most common digraphs: th he in er an re nd at on nt only er/re use consecutive keys, and five out of the ten use alternate hands. Move the R back to its original position, and there are none with consecutive keys and seven with alternate hands. > It only holds up as an obvious inference from the > nature of how typing works if we assume *one*-finger hunt-and-peck > rather than two-finger. I don't agree, but neither can I prove it conclusively. > Your website describes two-finger as the method > that was being replaced by the 1878 introduction of ten-finger typing. > >> The QWERTY layout was first sold in 1873 while the first known use of >> ten-fingered typing was in 1878, and touch-typing wasn't invented for >> another decade, in 1888. > > Two-finger hunt-and-peck is sufficient for placing keys on opposite > hands to speed typing up rather than slow it down. Correct, once you take into account jamming. That's the whole point of separating the keys. But consider common letter combinations that can be typed by the one hand: QWERTY has a significant number of quite long words that can be typed with one hand, the *left* hand. That's actually quite harmful for both typing speed and accuracy. Anyway, you seem to have ignored (or perhaps you just have nothing to say) my comments about the home keys. It seems clear to me that even with two- finger typing, a layout that puts ETAOIN on the home keys, such as the Blickensderfer typewriter, would minimize the distance travelled by the fingers and improve typing speed -- but only so long as the problem of jamming was solved. Interestingly, Wikipedia makes it clear that in the 19th century, the problem of jamming arms was already solved by doing away with the arms and using a wheel or a ball. -- Steve From saxri89 at gmail.com Mon Apr 18 03:38:12 2016 From: saxri89 at gmail.com (Xristos Xristoou) Date: Mon, 18 Apr 2016 00:38:12 -0700 (PDT) Subject: scipy install error,need help its important In-Reply-To: <6931c7f5-ffa0-4a8c-86bc-d257f0582c09@googlegroups.com> References: <6931c7f5-ffa0-4a8c-86bc-d257f0582c09@googlegroups.com> Message-ID: <69ea7171-f143-44cb-b415-3a3c17f3c88c@googlegroups.com> ?? ???????, 18 ???????? 2016 - 6:53:30 ?.?. UTC+3, ? ??????? Xristos Xristoou ??????: > guys i have big proplem i want to install scipy > but all time show me error > i have python 2.7 and windows 10 > i try to use pip install scipy and i take that error > > raise NotFoundError('no lapack/blas resources found') > numpy.distutils.system_info.NotFoundError: no lapack/blas resources found > > > Command "C:\Python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\name\\appdata\\local\\temp\\pip-build-a3fjaf\\scipy\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\name\appdata\local\temp\pip-pgtkuz-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\name\appdata\local\temp\pip-build-a3fjaf\scipy\ yes i have idle python 2.7 before,must delete first before install anaconda ?how can anaconda packages to run with old idle ?because i have to many packages in old python. From Joaquin.Alzola at lebara.com Mon Apr 18 03:49:18 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Mon, 18 Apr 2016 07:49:18 +0000 Subject: delete from pattern to pattern if it contains match In-Reply-To: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> Message-ID: Hi, Try to use the xml module. import xml.etree.ElementTree as ET That might help. BR Joaquin -----Original Message----- From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com at python.org] On Behalf Of harirammanohar at gmail.com Sent: 18 April 2016 08:08 To: python-list at python.org Subject: delete from pattern to pattern if it contains match HI All, can you help me out in doing below. file: guava fruit mango fruit orange fruit need to delete from start to end if it contains mango in a file... output should be: guava fruit orange fruit Thank you -- https://mail.python.org/mailman/listinfo/python-list This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. From hasandiwan+usenet at gmail.com Mon Apr 18 03:51:01 2016 From: hasandiwan+usenet at gmail.com (Hasan Diwan) Date: Mon, 18 Apr 2016 07:51:01 +0000 (UTC) Subject: Python2.7 win64 --- cannot install the package of scipy References: <66c616a4-a36f-437e-9ce0-e7694d28af7a@googlegroups.com> Message-ID: On 2016-04-16, ykt2271707491 at gmail.com wrote: > I failed to install the package of scipy on Python2.7(win64). Have you tried anaconda python -- https://3230d63b5fc54e62148e-c95ac804525aac4b6dba79b00b39d1d3.ssl.cf1.rackcdn.com/Anaconda2-4.0.0-Windows-x86_64.exe From marko at pacujo.net Mon Apr 18 04:02:40 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Apr 2016 11:02:40 +0300 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> <877ffw5wjo.fsf@elektro.pacujo.net> <57143eee$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ega3s5sv.fsf@elektro.pacujo.net> Steven D'Aprano : > One technique which is common in Pascal, but less so in Python, is to get > the best of both worlds by using nested functions. In Python syntax: > > def Do_The_Thing(): > def internal_subpart_start(): ... > def internal_subpart_middle(): ... > def internal_subpart_end(): ... > ... That really should be done more. C weaned us from the routine Pascal mechanism, but there's no reason not to exploit it again in Python. It also solves the problem of lugging the local context between internal functions, especially now that Python possesses the "nonlocal" keyword. Marko From greg.ewing at canterbury.ac.nz Mon Apr 18 04:32:38 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 18 Apr 2016 20:32:38 +1200 Subject: [OT] Java generics In-Reply-To: References: Message-ID: > On 17 April 2016 at 23:38, Ian Kelly wrote: > >>The diamond operator in JDK 7 makes this a lot more tolerable, IMO: The diamond notation helps slightly, but not very much. What would help a lot more would be something like C's typedef for giving aliases to type expressions. It's understandable that Java didn't originally have a typedef, because all types had short enough names anyway. But generics changed that in a big way, and it baffles me that some form of typedef wasn't added soon afterwards. -- Greg From greg.ewing at canterbury.ac.nz Mon Apr 18 04:43:37 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 18 Apr 2016 20:43:37 +1200 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <87ega3s5sv.fsf@elektro.pacujo.net> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> <877ffw5wjo.fsf@elektro.pacujo.net> <57143eee$0$1612$c3e8da3$5496439d@news.astraweb.com> <87ega3s5sv.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > Steven D'Aprano : > >>def Do_The_Thing(): >> def internal_subpart_start(): ... >> def internal_subpart_middle(): ... >> def internal_subpart_end(): ... >> ... > > That really should be done more. C weaned us from the routine Pascal > mechanism, but there's no reason not to exploit it again in Python. Two things Python has that Pascal didn't are modules and classes. They take care of a lot of the grouping that you had to rely on nested functions for in Pascal. I do find myself nesting functions like that in Python, but only very occasionally. -- Greg From harirammanohar at gmail.com Mon Apr 18 04:52:19 2016 From: harirammanohar at gmail.com (harirammanohar at gmail.com) Date: Mon, 18 Apr 2016 01:52:19 -0700 (PDT) Subject: delete from pattern to pattern if it contains match In-Reply-To: References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> Message-ID: <1020e7f0-68ac-48a3-88f0-056f25f49b6c@googlegroups.com> On Monday, April 18, 2016 at 1:19:43 PM UTC+5:30, Joaquin Alzola wrote: > Hi, > > Try to use the xml module. > > import xml.etree.ElementTree as ET > > That might help. > > BR > > Joaquin > > -----Original Message----- > > > HI All, > > can you help me out in doing below. > > file: > > guava > fruit > > > mango > fruit > > > orange > fruit > > > need to delete from start to end if it contains mango in a file... > > output should be: > > > guava > fruit > > > orange > fruit > > > Thank you > -- > https://mail.python.org/mailman/listinfo/python-list > This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. Hi Alzola, Still any easier way ?? From greg.ewing at canterbury.ac.nz Mon Apr 18 05:03:56 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 18 Apr 2016 21:03:56 +1200 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <91134e90-1cce-471b-9f5a-616276886e84@googlegroups.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> <91134e90-1cce-471b-9f5a-616276886e84@googlegroups.com> Message-ID: Rustom Mody wrote: > Come to think of it take an SQL DBMS browser. > Should we say: Horizontal scrolls are BAD; just reformat the table after reaching 80 columns? I would say, yes, horizontal scrolling *is* bad in a table -- probably even worse than it is for text or code. The reason is that tables are usually laid out so that data items in a row are related to each other. You can't make sense of a piece of data in the table without seeing the other items in the same row. That's hard to do if you can't see the whole row at once. > In fact much of the point of > http://blog.languager.org/2012/10/layout-imperative-in-functional.html > is just this: that as code becomes more and more data-ish, > a more-lines-less-columns regime becomes correspondingly irksome. I draw the opposite conclusion. The more your code is laid out like a table, the more important it is to be able to see the whole width of it at once. Your Haskell lexer example looks all very nice in a good wide browser window. But reduce it so you can only see half of it at a time and then tell me how readable it is. -- Greg From marko at pacujo.net Mon Apr 18 05:11:36 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Apr 2016 12:11:36 +0300 Subject: [OT] Java generics References: Message-ID: <878u0bs2lz.fsf@elektro.pacujo.net> Gregory Ewing : > It's understandable that Java didn't originally have a typedef, > because all types had short enough names anyway. But generics changed > that in a big way, and it baffles me that some form of typedef wasn't > added soon afterwards. Java's opposition to typedef seems to be something fundamental and philosophical, although I don't exactly understand what. What people do then is they define classes and interfaces as typedefs, which is even worse. Marko From marko at pacujo.net Mon Apr 18 05:17:25 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Apr 2016 12:17:25 +0300 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> <877ffw5wjo.fsf@elektro.pacujo.net> <57143eee$0$1612$c3e8da3$5496439d@news.astraweb.com> <87ega3s5sv.fsf@elektro.pacujo.net> Message-ID: <874mazs2ca.fsf@elektro.pacujo.net> Gregory Ewing : > Marko Rauhamaa wrote: >> Steven D'Aprano : >> >>>def Do_The_Thing(): >>> def internal_subpart_start(): ... >>> def internal_subpart_middle(): ... >>> def internal_subpart_end(): ... >>> ... >> >> That really should be done more. C weaned us from the routine Pascal >> mechanism, but there's no reason not to exploit it again in Python. > > Two things Python has that Pascal didn't are modules and classes. They > take care of a lot of the grouping that you had to rely on nested > functions for in Pascal. I don't think Pascal did it for grouping or readability but for conceptual correctness. When I moved from Pascal to C, I felt the absence of local functions; it was a slight unease about abstraction leakage. > I do find myself nesting functions like that in Python, but only very > occasionally. Same for me. Essentially, I use local functions to register callbacks. Decades of C has done that to us. Marko From greg.ewing at canterbury.ac.nz Mon Apr 18 05:17:54 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 18 Apr 2016 21:17:54 +1200 Subject: QWERTY was not designed to intentionally slow typists down In-Reply-To: <57148b18$0$11112$c3e8da3@news.astraweb.com> References: <2796705.edb3E9ArW3@PointedEars.de> <1584744.4h7ToaqLat@PointedEars.de> <5705b9ef$0$1611$c3e8da3$5496439d@news.astraweb.com> <570748ec$0$1620$c3e8da3$5496439d@news.astraweb.com> <874mbcgfmd.fsf@elektro.pacujo.net> <753cdb8b-9f94-48d6-bc0d-589efba86afc@googlegroups.com> <8560vr627l.fsf_-_@benfinney.id.au> <570876f1$0$1619$c3e8da3$5496439d@news.astraweb.com> <1460217233.3804713.573755729.61D3FCF2@webmail.messagingengine.com> <57143ac0$0$1609$c3e8da3$5496439d@news.astraweb.com> <1460944909.3502334.581571497.197404E2@webmail.messagingengine.com> <57148b18$0$11112$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Even on a modern keyboard, out of the ten most common digraphs: > > th he in er an re nd at on nt > > only er/re use consecutive keys, Also keep in mind that E and R being adjacent on the keyboard does *not* mean they're adjacent in the type basket -- they're actually separated by two other characters (D and C). That's only one less than I and N (separated by U, J nd M). -- Greg From oscar.j.benjamin at gmail.com Mon Apr 18 05:19:41 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 18 Apr 2016 10:19:41 +0100 Subject: scipy install error,need help its important In-Reply-To: <69ea7171-f143-44cb-b415-3a3c17f3c88c@googlegroups.com> References: <6931c7f5-ffa0-4a8c-86bc-d257f0582c09@googlegroups.com> <69ea7171-f143-44cb-b415-3a3c17f3c88c@googlegroups.com> Message-ID: On 18 April 2016 at 08:38, Xristos Xristoou wrote: > ?? ???????, 18 ???????? 2016 - 6:53:30 ?.?. UTC+3, ? ??????? Xristos Xristoou ??????: >> guys i have big proplem i want to install scipy >> but all time show me error >> i have python 2.7 and windows 10 >> i try to use pip install scipy and i take that error >> >> raise NotFoundError('no lapack/blas resources found') >> numpy.distutils.system_info.NotFoundError: no lapack/blas resources found >> > > yes i have idle python 2.7 before,must delete first before install anaconda ?how can anaconda packages to run with old idle ?because i have to many packages in old python. Just install numpy and scipy from here (as already mentioned earlier in the thread): http://www.lfd.uci.edu/~gohlke/pythonlibs/ -- Oscar From oscar.j.benjamin at gmail.com Mon Apr 18 05:26:17 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 18 Apr 2016 10:26:17 +0100 Subject: Python2.7 win64 --- cannot install the package of scipy In-Reply-To: <66c616a4-a36f-437e-9ce0-e7694d28af7a@googlegroups.com> References: <66c616a4-a36f-437e-9ce0-e7694d28af7a@googlegroups.com> Message-ID: On 16 April 2016 at 22:53, wrote: > I failed to install the package of scipy on Python2.7(win64). > > 1. I tried the direct way that use cmd--pip install scripy. The result shows that it failed with error code 1 in c:\tyk\appdata\local\temp\pip-build-an9fye\scipy\. > > 2. I tried to install in another way. I download the scipy-0.17.0-cp27-none-win_amd64.whl from Unofficial Windows Binaries for Python Extension Packages. And use cmd to install that in the Scripts direction, but still failed.(I have installed the package wheel already). The result shows that scipy-0.17.0-cp27-none-win_amd64.whl is not a supported wheel on this platform. That should be the right wheel if you have 64-bit Python 2.7 on Windows. Note that it's possible you have 32 bit Python even if the computer and Windows is 64-bit. It's also possible that you need to update pip. -- Oscar From __peter__ at web.de Mon Apr 18 06:23:05 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 18 Apr 2016 12:23:05 +0200 Subject: What iterable method should I use for Lists of Lists References: <67c4c88b-62e9-4275-a761-25e5d7114025@googlegroups.com> <0a8c3fd1-ca01-4a62-b2fb-10fd841cde74@googlegroups.com> Message-ID: Sayth Renshaw wrote: > Think I have a solution of sorts, although my numpy array failed, zip > worked. > > from pyquery import PyQuery as pq > import numpy as np > > d = pq(filename='20160319RHIL0_edit.xml') > res = d('nomination') > # myAt = pq.each(res.attr('bbid')) > # print(repr(res)) > # myAt = [res.eq(i).attr('horse') for i in range(len(res))] > # print(myAt) > > nomID = [res.eq(i).attr('id') for i in range(len(res))] > horseName = [res.eq(i).attr('horse') for i in range(len(res))] > zipped = zip(nomID, horseName) > > # yes = np.array(zipped) > for items in zipped: > print(items) > > In [8]: ('171115', 'Vergara') > ('187674', 'Heavens Above') > ('184732', 'Sweet Fire') > ('181928', 'Alegria') > ('158914', 'Piamimi') > ('171408', 'Blendwell') > ('166836', 'Adorabeel (NZ)') > ('172933', 'Mary Lou') > ('182533', 'Skyline Blush') > ('171801', 'All Cerise') > ('181079', 'Gust of Wind (NZ)') > > Still interested if there is a better to do this. I don't know pyquery, so there may still be better ways. This is how far I got with dir() and the common Python wisdom "Never use range(len(...))": >>> import pyquery >>> d = pyquery.PyQuery(filename="horse.xml") >>> pairs = [(n.attrib["horse"], n.attrib["id"]) for n in d("nomination")] >>> import pprint >>> pprint.pprint(pairs) [('Vergara', '171115'), ('Heavens Above', '187674'), ('Sweet Fire', '184732'), ('Alegria', '181928'), ('Piamimi', '158914'), ('Blendwell', '171408'), ('Adorabeel (NZ)', '166836'), ('Mary Lou', '172933'), ('Skyline Blush', '182533'), ('All Cerise', '171801'), ('Gust of Wind (NZ)', '181079')] pprint is not really necessary, it just gives more readable output than >>> pairs [('Vergara', '171115'), ('Heavens Above', '187674'), ('Sweet Fire', '184732'), ('Alegria', '181928'), ('Piamimi', '158914'), ('Blendwell', '171408'), ('Adorabeel (NZ)', '166836'), ('Mary Lou', '172933'), ('Skyline Blush', '182533'), ('All Cerise', '171801'), ('Gust of Wind (NZ)', '181079')] To extract more than one attribute operator.itemgetter comes in handy: >>> from operator import itemgetter >>> get = itemgetter("horse", "id", "saddlecloth") >>> pprint.pprint([get(n.attrib) for n in d("nomination")]) [('Vergara', '171115', '4'), ('Heavens Above', '187674', '2'), ('Sweet Fire', '184732', '6'), ('Alegria', '181928', '7'), ('Piamimi', '158914', '11'), ('Blendwell', '171408', '10'), ('Adorabeel (NZ)', '166836', '3'), ('Mary Lou', '172933', '8'), ('Skyline Blush', '182533', '9'), ('All Cerise', '171801', '5'), ('Gust of Wind (NZ)', '181079', '1')] If you need to do some post-processing use a helper function: >>> def extract(n): ... attrib = n.attrib ... id = int(attrib["id"]) ... name = attrib["horse"].upper() ... return id, name ... >>> pprint.pprint([extract(n) for n in d("nomination")]) [(171115, 'VERGARA'), (187674, 'HEAVENS ABOVE'), (184732, 'SWEET FIRE'), (181928, 'ALEGRIA'), (158914, 'PIAMIMI'), (171408, 'BLENDWELL'), (166836, 'ADORABEEL (NZ)'), (172933, 'MARY LOU'), (182533, 'SKYLINE BLUSH'), (171801, 'ALL CERISE'), (181079, 'GUST OF WIND (NZ)')] From flebber.crue at gmail.com Mon Apr 18 07:02:45 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Mon, 18 Apr 2016 04:02:45 -0700 (PDT) Subject: How to track files processed Message-ID: <59023020-9464-4fb3-8d9d-c42db593f7ea@googlegroups.com> Hi If you are parsing files in a directory what is the best way to record which files were actioned? So that if i re-parse the directory i only parse the new files in the directory? Thanks Sayth From rustompmody at gmail.com Mon Apr 18 07:07:28 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 18 Apr 2016 04:07:28 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> <91134e90-1cce-471b-9f5a-616276886e84@googlegroups.com> Message-ID: <3ca5df02-dfd5-4e1f-8e2f-e7a6d1231987@googlegroups.com> On Monday, April 18, 2016 at 2:34:10 PM UTC+5:30, Gregory Ewing wrote: > Rustom Mody wrote: > > Come to think of it take an SQL DBMS browser. > > Should we say: Horizontal scrolls are BAD; just reformat the table after reaching 80 columns? > > I would say, yes, horizontal scrolling *is* bad in a table -- > probably even worse than it is for text or code. > > The reason is that tables are usually laid out so that > data items in a row are related to each other. You can't > make sense of a piece of data in the table without seeing > the other items in the same row. That's hard to do if > you can't see the whole row at once. "horizontal scrolling: BAD" + "Need to see whole row at once" How to reconcile these two? (Think of a 50 column table/spreadsheet) The only answer I know in DBMS lingo is "normalize" (refactor in programming lingo) which one way or other amounts to "Store some of those columns in your head" Obviously I am not against normalization when it actually cleans up I am against normalization just to reduce no of columns > > > In fact much of the point of > > http://blog.languager.org/2012/10/layout-imperative-in-functional.html > > is just this: that as code becomes more and more data-ish, > > a more-lines-less-columns regime becomes correspondingly irksome. > > I draw the opposite conclusion. The more your code is > laid out like a table, the more important it is to be > able to see the whole width of it at once. > > Your Haskell lexer example looks all very nice in a > good wide browser window. But reduce it so you can only > see half of it at a time and then tell me how readable > it is. Horrible. So what are we (if at all) disagreeing on? From timothy.c.delaney at gmail.com Mon Apr 18 07:33:30 2016 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Mon, 18 Apr 2016 21:33:30 +1000 Subject: [OT] Java generics (was: Guido sees the light: PEP 8 updated) In-Reply-To: References: Message-ID: On 18 April 2016 at 09:30, Chris Angelico wrote: > On Mon, Apr 18, 2016 at 8:02 AM, Tim Delaney > wrote: > > I also wouldn't describe Java as a > > "perfectly good language" - it is at best a compromise language that just > > happened to be heavily promoted and accepted at the right time. > > > > Python is *much* closer to my idea of a perfectly good language. > > "Java" was originally four related, but separate, concepts: a source > language, a bytecode, a sandboxing system, and one other that I can't > now remember. I was very specifically referring to Java the language. The JVM is fairly nice, especially with the recent changes specifically aimed at more easily supporting dynamic languages. Speaking of JVM changes - I had to take over support of a chat applet developed by a contractor built on Java 1.0. We just could not get it to work reliably (this was for the original Foxtel web site - I remember trying to keep it up and running while Richard Fidler was doing a promoted chat session ...). Then Java 1.1 was released and what a huge improvement that was. Tim Delaney From dpalao.python at gmail.com Mon Apr 18 07:35:42 2016 From: dpalao.python at gmail.com (David Palao) Date: Mon, 18 Apr 2016 13:35:42 +0200 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <5714522d$0$1622$c3e8da3$5496439d@news.astraweb.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> <04721fe6-5feb-49c8-b5b2-beb12f6ff495@googlegroups.com> <5714522d$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: 2016-04-18 5:19 GMT+02:00 Steven D'Aprano : > On Mon, 18 Apr 2016 11:39 am, Rustom Mody wrote: > >> yes we can agree on this -- arbitrary line lengths are almost certainly >> unreadable. >> The problem then becomes so what is optimal? > > I really don't think it is a problem. We have about 400 years > of experience with printed text, and that experience tells us > that the optimal width for reading prose in Western languages > is about 60 characters, give or take. This width is optimal > for eye movement, and minimizes the number of errors and > reduces eye-strain. > > There's only so far that our eyes can follow a line to the > right without increasing stress or reading errors, and > likewise when returning back to the left margin. The longer > the line, the higher the chance of losing track, and the > physical effort it takes to read. (You have to move the eyes > further, and for extremely long lines, you may have to move > your entire head.) > > Long lines are simply harder to read because you have to > move your eyes more, and the longer the lines, the greater > the tendency to wander across the lines. Especially if the > lines are close together and the height of the lines is > small. (It boggles my mind how many programmers I've met who > routinely view their code in tiny physical heights, even > when reading it in fine detail.) > > The optimal width for eye-tracking (that is, the maximum > width for which the rate of such errors can be disregarded) > is somewhere about sixty characters per line. > > The same eye-tracking considerations apply to code, but: > > when it comes to code, we don't always have to track all the > way back to the left-hand margin. If we start (say) up to > twenty columns in, then we can afford to write up to twenty > columns further to the right too. > > > (Also, code tends to have VERY ragged right-hand margins. > Not all lines end up even close to sixty characters wide.) > > There are other considerations though. Unlike prose, with > code, shorter lines *may* sometimes force an increase in > complexity. For instance, temporary variables need to be > created, or new functions created, just to avoid otherwise > excessively long lines. So one might be willing to accept a > little more eye-movement for a little less code complexity. > > So allowing a total width of 80 (give or take) is already a > compromise from the optimal sixty characters. This compromise > allows for indented code, and allows up to 20 characters > extra to avoid creating more complexity elsewhere. > > > But there's another factor: long lines of code are themselves > a code-smell. Perhaps: > > - you have indented too deeply, suggesting that your function > is doing too much or has too much internal complexity: > > def func(): > if a: > for b in seq: > while c: > with d: > try: > try: > for e in it: > block # only 48 columns available here > > (But note also that even with this extreme example, eight > indentation levels deep, you can still fit almost > characters per line without breaking the 80-char limit. > You can do a lot in 50 characters.) > > > - you have too many expressions on one line, suggesting that > the over-all complexity of the line is excessive; > > - your variable or function names are needlessly verbose or > are doing too much or are too specific > ("calculate_number_of_pages_and_number_of_semicolons_in_chapter_one"); > > - or you are violating the rule of Demeter: > get(customer.trousers.pocket.wallet).open().money.pay(1) > > > In other words, long lines of code are themselves an > indication of poorly-designed code. Even though there are > exceptions, we should resist strongly the urge to extend > beyond the 60-80 (or perhaps 90 in extreme cases) limit. > Whenever I hear people saying that they regularly need to > use 100 or even 120 columns for their code, what I hear is > "my code is badly written". > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list Excellent! Thank you for this contribution. From __peter__ at web.de Mon Apr 18 08:30:42 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 18 Apr 2016 14:30:42 +0200 Subject: How to track files processed References: <59023020-9464-4fb3-8d9d-c42db593f7ea@googlegroups.com> Message-ID: Sayth Renshaw wrote: > If you are parsing files in a directory what is the best way to record > which files were actioned? What do you do with the result of the parsing process? If you write it to another file you can just look if that file already exists. If you write it to a database there may be a specific record to look for. > So that if i re-parse the directory i only parse the new files in the > directory? Can you give some context? What are you trying to do? Is your application running all the time or would you like to invoke it, process new files and then terminate? From info at wingware.com Mon Apr 18 09:27:17 2016 From: info at wingware.com (Wingware) Date: Mon, 18 Apr 2016 09:27:17 -0400 Subject: ANN: Wing IDE 5.1.11 released Message-ID: <5714E0B5.3000402@wingware.com> Hi, Wingware has released version 5.1.11 of Wing IDE, our cross-platform integrated development environment for the Python programming language. Wing IDE features a professional code editor with vi, emacs, visual studio, and other key bindings, auto-completion, call tips, context-sensitive auto-editing, goto-definition, find uses, refactoring, a powerful debugger, version control, unit testing, search, project management, and many other features. This release includes the following minor improvements: Fix Django template debugging for Django version 1.9 (requires 1.9.3+) Fix Debian package dependency for newer Linux distributions Fix git status when --use-porcelain is disabled with recent git versions Correctly find points of use of class attributes Added block commenting option for PEP8 style column 0 comment Fix analysis of extension modules when using Python 3.5 on Windows Sort alphabetically within type in Source Browser when using Sort by Type Fix problems with extra argument passing to unit test runners Several auto-editing fixes About 20 other bug fixes For details see http://wingware.com/news/2016-04-15 and http://wingware.com/pub/wingide/5.1.11/CHANGELOG.txt What's New in Wing 5.1: Wing IDE 5.1 adds multi-process and child process debugging, syntax highlighting in the shells, support for pytest, Find Symbol in Project, persistent time-stamped unit test results, auto-conversion of indents on paste, an XCode keyboard personality, support for Flask, Django 1.7, 1.8, and 1.9, Python 3.5 and recent Google App Engine versions, improved auto-completion for PyQt, recursive snippet invocation, and many other minor features and improvements. Free trial: http://wingware.com/wingide/trial Downloads: http://wingware.com/downloads Feature list: http://wingware.com/wingide/features Sales: http://wingware.com/store/purchase Upgrades: 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 sivan at vitakka.co Mon Apr 18 09:35:25 2016 From: sivan at vitakka.co (Sivan Greenberg) Date: Mon, 18 Apr 2016 16:35:25 +0300 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: On Sat, Apr 16, 2016 at 8:25 PM, Terry Reedy wrote: > On 4/16/2016 12:58 PM, Larry Martell wrote: > >> On Sat, Apr 16, 2016 at 12:51 PM, Marko Rauhamaa >> wrote: >> >>> Larry Martell : >>> >>> I have worked for many companies where you are required to get a clean >>>> run of pep8 on your code before your pull request will even be >>>> considered for approval. I don't agree with this at all, as I think it >>>> makes the code very ugly, especially enforcing the max line length. >>>> >>> >>> Agh, I was with you until your last remark. >>> >>> A max line length of 79 characters is among the *only* rigorous >>> principles I judge coding style on. >>> >>> It comes with the maxim that one function must be visible at once on the >>> screen. >>> >> >> if we still had 1970's 80 character TTYs that would matter but on my >> 29" 1920x1080 screen it doesn't. >> > > It depends on whether one prefers to use the extra width to have long > lines or side-by-side windows. I prefer the latter. That's my use case as well, and why I admire the forethought in the width length. Side by side windows rock when doing TTD. -Sivan From barry at python.org Mon Apr 18 10:05:18 2016 From: barry at python.org (Barry Warsaw) Date: Mon, 18 Apr 2016 10:05:18 -0400 Subject: Moderation and slight change of (de facto) policy In-Reply-To: <57140947.3050902@gmail.com> References: <5713C08F.3010207@timgolden.me.uk> <57140947.3050902@gmail.com> Message-ID: <20160418100518.4f357807@subdivisions.wooz.org> On Apr 17, 2016, at 06:08 PM, Matt Ruffalo wrote: >That seems like a reasonable approach, though I think there *really* >needs to be an option along the lines of "subscribed to the list for the >purposes of moderation, but not receiving list messages via email". We can do this effectively in Mailman 2.1 by adding the non-member to accept_these_nonmembers, and that's fairly easy to do from the admin page. Mailman 3 will make this more explicit by actually assigning a role of "nonmember" to the person, so as to be able to more granularly control their posting privileges. While we're starting to roll out some Mailman 3 lists, it will probably be a while before python-list is converted. Alternatively, individuals can subscribe to a mailing list and then disable delivery to their address. This essentially accomplishes the same thing, although for some lists, posts start out moderated until the person builds some positive reputation. Then the admin can turn off their moderation bit and their posts will go straight through. Cheers, -Barry From grant.b.edwards at gmail.com Mon Apr 18 10:38:00 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 18 Apr 2016 14:38:00 +0000 (UTC) Subject: Moderation and slight change of (de facto) policy References: <5713C08F.3010207@timgolden.me.uk> <57140947.3050902@gmail.com> <20160418100518.4f357807@subdivisions.wooz.org> Message-ID: On 2016-04-18, Barry Warsaw wrote: > On Apr 17, 2016, at 06:08 PM, Matt Ruffalo wrote: > >>That seems like a reasonable approach, though I think there *really* >>needs to be an option along the lines of "subscribed to the list for the >>purposes of moderation, but not receiving list messages via email". > Alternatively, individuals can subscribe to a mailing list and then disable > delivery to their address. AFAIR, all the mailing lists I've ever joined offer this setting, and I generally use it (I read all my mailing lists by pointing a NNTP client at news.gmane.org). If a mailing list doesn't allow to to disable delivery, then it's usually pretty trivial to set up a filter to toss all messages received from that list into /dev/null. -- Grant Edwards grant.b.edwards Yow! ... I want to perform at cranial activities with gmail.com Tuesday Weld!! From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Mon Apr 18 11:38:13 2016 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Mon, 18 Apr 2016 16:38:13 +0100 Subject: Creating a hot vector (numpy) References: Message-ID: ?s 05:05 de 18-04-2016, Reto Brunner escreveu: > Hi, > It is called broadcasting an array, have a look here: > http://docs.scipy.org/doc/numpy-1.10.1/user/basics.broadcasting.html > So, there are two broadcasts here. OK. Thanks. From martin at linux-ip.net Mon Apr 18 13:56:12 2016 From: martin at linux-ip.net (Martin A. Brown) Date: Mon, 18 Apr 2016 10:56:12 -0700 Subject: How to track files processed In-Reply-To: <59023020-9464-4fb3-8d9d-c42db593f7ea@googlegroups.com> References: <59023020-9464-4fb3-8d9d-c42db593f7ea@googlegroups.com> Message-ID: Greetings, >If you are parsing files in a directory what is the best way to >record which files were actioned? > >So that if i re-parse the directory i only parse the new files in >the directory? How will you know that the files are new? If a file has exactly the same content as another file, but a different name, is it new? Often this depends on the characteristics of the system in which your (planned) software is operating. Peter Otten has also asked for some more context, which would help us give you some tips that are more targetted to the problem you are trying to solve. But, I'll just forge ahead and make some assumptions: * You are watching a directory for new/changed files. * New files are appearing regularly. * Contents of old files get updated and you want to know. Have you ever seen an MD5SUMS file? Do you know what a content hash is? You could find a place to store the content hash (a.k.a. digest) of each file that you process. Below is a program that should work in Python2 and Python3. You could use this sort of approach as part of your solution. In order to make sure you have handled a file before, you should store and compare two things. 1. The filename. 2. The content hash. Note: If you are sure the content is not going to change, then just use the filename to track whether you have handled something or not. How would you use this tracking info ? * Create a dictionary (or a set), e.g.: handled = dict() handled[('410c35da37b9a25d9b5d701753b011e5','setup.py')] = time.time() Lasts only as long as the program runs. But, you will know that you have handled any file by the tuple of its content hash and filename. * Store the filename (and/or digest) in a database. So many options: sqlite, pickle, anydbm, text file of your own crafting, SQLAlchemy ... * Create a file, hardlink or symlink in the filesystem (in the same directory or another directory), e.g.: trackingfile = os.path.join('another-directory', 'setup.py') with open(trackingfile, 'w') as f: f.write('410c35da37b9a25d9b5d701753b011e5') OR os.symlink('setup.py', '410c35da37b9a25d9b5d701753b011e5-setup.py') Now, you can also examine your little cache of handled files to compare for when the content hash changes. If the system is an automated system, then this can be perfectly fine. If humans create the files, I would suggest not doing this. Humans tend to be easily confused by such things (and then want to delete the files or just be intimidated by them; scary hashes!). There are lots of options, but without some more context, we can only make generic suggestions. So, I'll stop with my generic suggestions now. Have fun and good luck! -Martin #! /usr/bin/python from __future__ import print_function import os import sys import logging import hashlib logformat = '%(levelname)-9s %(name)s %(filename)s#%(lineno)s ' \ + '%(funcName)s %(message)s' logging.basicConfig(stream=sys.stderr, format=logformat, level=logging.ERROR) logger = logging.getLogger(__name__) def hashthatfile(fname): contenthash = hashlib.md5() try: with open(fname, 'rb') as f: contenthash.update(f.read()) return contenthash.hexdigest() except IOError as e: logger.warning("See exception below; skipping file %s", fname) logger.exception(e) return None def main(dirname): for fname in os.listdir(dirname): if not os.path.isfile(fname): logger.debug("Skipping non-file %s", fname) continue logger.info("Found file %s", fname) digest = hashthatfile(fname) logger.info("Computed MD5 hash digest %s", digest) print('%s %s' % (digest, fname,)) return os.EX_OK if __name__ == '__main__': if len(sys.argv) == 1: sys.exit(main(os.getcwd())) else: sys.exit(main(sys.argv[1])) # -- end of file -- Martin A. Brown http://linux-ip.net/ From ben+python at benfinney.id.au Mon Apr 18 15:11:42 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 19 Apr 2016 05:11:42 +1000 Subject: Convert input to upper case on screen as it is typed References: <85oa9cyiqt.fsf@benfinney.id.au> <85bn5cy6bz.fsf@benfinney.id.au> <8537qoy49y.fsf@benfinney.id.au> Message-ID: <85zisqratt.fsf@benfinney.id.au> Ben Finney writes: > Ben Finney writes: > > > Okay, ?termios.tcgetattr? will let me preserve the attributes, and > > with Dan Sommers's suggestion of which attribute to use, I may have > > a shot at setting the terminal attributes. > > This works! Except, it doesn't. As designed and documented in the Single Unix Specification , the behaviour of the OLCUC feature is: OLCUC Map lower case to upper on output. (LEGACY) That ominous ?LEGACY? annotation is applied, notably, to all the case-conversion features of ?termios?. The mapping is ignorant of Unicode, ignorant of ANSI escape sequences; it blindly converts bytes via a mapping that assumes all bytes are ASCII text, regardless of whether those bytes actually represent text. It breaks the ?visual bell? feature, among others. I end up with garbage on the screen, that would otherwise have been Unicode text or useful control sequences. > I had been hoping that I could simply wrap some stream in a simple > ?convert what they actually type so it's upper case? text codec, > without fiddling at such a low operating-system specific level. This > is rather more esoteric than I had hoped. And, it turns out, doesn't address the requirements without causing more problems. I am still looking for a solution (a Python-specific one would be fine). -- \ ?Anything that we scientists can do to weaken the hold of | `\ religion should be done and may in the end be our greatest | _o__) contribution to civilization.? ?Steven Weinberg | Ben Finney From ian.g.kelly at gmail.com Mon Apr 18 16:41:44 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 18 Apr 2016 14:41:44 -0600 Subject: [Python-ideas] Changing the meaning of bool.__invert__ In-Reply-To: References: <570679AF.7020502@stoneleaf.us> <57068A10.3020904@stoneleaf.us> <57069645.8040509@stoneleaf.us> <20160408014030.GL12526@ando.pearwood.info> <22279.18221.103226.654215@turnbull.sk.tsukuba.ac.jp> <20160409154305.GU12526@ando.pearwood.info> Message-ID: On Sun, Apr 17, 2016 at 12:24 PM, Pavol Lisy wrote: > 2016-04-09 17:43 GMT+02:00, Steven D'Aprano : >> flag ^ flag is useful since we don't have a boolean-xor operator and >> bitwise-xor does the right thing for bools. And I suppose some people >> might prefer & and | over boolean-and and boolean-or because they're >> shorter and require less typing. I don't think that's a particularly >> good reason for using them, and as you say, you do have to guard >> against non-bools slipping, but Consenting Adults applies. > > They are also useful if you need to avoid short-circuit evaluation. One can easily write functions to do that. def long_or(a, b): """Equivalent to a or b but always evaluates both expressions.""" return a or b long_or(a, b) may not be as pretty as a | b, but I'll argue that it's more readable since it's up-front about its intent, whereas a | b looks like it could just be a mistake. From petef4+usenet at gmail.com Mon Apr 18 17:14:02 2016 From: petef4+usenet at gmail.com (Pete Forman) Date: Mon, 18 Apr 2016 22:14:02 +0100 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: Why is it that Python continues to use a fixed width font and therefore specifies the maximum line width as a character count? An essential part of the language is indentation which ought to continue to mandate that lines start with a multiple of 4 em worth of space (or some other size or encode with hard tabs, that is not germane to my question). The content of the line need not be bound by the rules needed to position its start. -- Pete Forman From ian.g.kelly at gmail.com Mon Apr 18 17:29:49 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 18 Apr 2016 15:29:49 -0600 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: On Mon, Apr 18, 2016 at 3:14 PM, Pete Forman wrote: > Why is it that Python continues to use a fixed width font and therefore > specifies the maximum line width as a character count? > > An essential part of the language is indentation which ought to continue > to mandate that lines start with a multiple of 4 em worth of space (or > some other size or encode with hard tabs, that is not germane to my > question). The content of the line need not be bound by the rules needed > to position its start. How many spaces is "4 em worth"? How would you incorporate that into the Python compiler or a linter without needing to know what particular font the programmer is using? What happens when another programmer reviews the code using a different font and finds that there is only 3.5em worth of space? Do we descend into Calibri / Verdana line-length edit wars? From fillmore_remove at hotmail.com Mon Apr 18 17:32:29 2016 From: fillmore_remove at hotmail.com (Fillmore) Date: Mon, 18 Apr 2016 17:32:29 -0400 Subject: I have been dealing with Python for a few weeks... References: Message-ID: On 04/14/2016 10:12 PM, justin walters wrote: > On Thu, Apr 14, 2016 at 1:50 PM, Fillmore > wrote: > >> >> ...and I'm loving it. >> >> Sooo much more elegant than Perl...and so much less going back to the >> manual to lookup the syntax of simple data structures and operations... >> >> REPL is so useful >> >> and you guys rock too >> >> cheers >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > Good to hear you're enjoying it. Out of curiosity, what were you using Perl > for? > I am a programmer by education but have not programmed in years. Sometimes I need to get my point across to people in my team that something can be done. The fact that I could prototype in Perl (now Python) certainly makes it harder for others to argue that this or that cannot be done in (java/PHP) or that it would take a disproportionate amount of time to carry out... Thanks From flebber.crue at gmail.com Mon Apr 18 17:39:11 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Mon, 18 Apr 2016 14:39:11 -0700 (PDT) Subject: How to track files processed In-Reply-To: References: <59023020-9464-4fb3-8d9d-c42db593f7ea@googlegroups.com> Message-ID: <7fd5639c-b438-4651-8d0e-74d248b782a6@googlegroups.com> Thank you Martin and Peter To clarify Peter at the moment only writing to csv but am wanting to set up an item pipeline to SQL db next. I will have a go at your examples Martin and see how i go. Thank you both for taking time to help. Sayth From petef4+usenet at gmail.com Mon Apr 18 18:20:09 2016 From: petef4+usenet at gmail.com (Pete Forman) Date: Mon, 18 Apr 2016 23:20:09 +0100 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: Ian Kelly writes: > On Mon, Apr 18, 2016 at 3:14 PM, Pete Forman wrote: >> Why is it that Python continues to use a fixed width font and >> therefore specifies the maximum line width as a character count? >> >> An essential part of the language is indentation which ought to >> continue to mandate that lines start with a multiple of 4 em worth of >> space (or some other size or encode with hard tabs, that is not >> germane to my question). The content of the line need not be bound by >> the rules needed to position its start. > > How many spaces is "4 em worth"? How would you incorporate that into > the Python compiler or a linter without needing to know what > particular font the programmer is using? What happens when another > programmer reviews the code using a different font and finds that > there is only 3.5em worth of space? Do we descend into Calibri / > Verdana line-length edit wars? 4 em is what PEP 8 implies, with the implicit use of a monospaced font. I was trying to convey that the mechanics of indentation was not relevant to my question about why Python and indeed other programming languages are rarely edited or viewed with proportional fonts. The programmer, other humans reading the source and the interpreter need to be able to discern structure by the indentation. It is what follows the indentation that interests me. The current Python interpreter will happily digest a combination of spaces and hard tabs as long as consistency rules are obeyed. My question was intended to concentrate on the presentation after the leading whitespace. -- Pete Forman From ben+python at benfinney.id.au Mon Apr 18 18:58:44 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 19 Apr 2016 08:58:44 +1000 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: <85vb3er0bf.fsf@benfinney.id.au> Pete Forman writes: > Why is it that Python continues to use a fixed width font I think you know this isn't true. > and therefore specifies the maximum line width as a character count? and that this ?therefore? is not justified by that. You've seen elsewhere the justification for *having* a maximum line width (primarily because of limits on human cognition of lines of text). As for what the limit *is*, it's much better to have an easy-to-apply and easy-to-measure rule, because consistent application is important for such a guide. Counting characters is objectively easy and easily comparable. -- \ ?I think Western civilization is more enlightened precisely | `\ because we have learned how to ignore our religious leaders.? | _o__) ?Bill Maher, 2003 | Ben Finney From flebber.crue at gmail.com Mon Apr 18 19:44:09 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Mon, 18 Apr 2016 16:44:09 -0700 (PDT) Subject: Why are my files in in my list - os module used with sys argv Message-ID: <0bce26b1-ad3d-42c4-8f99-08e82d1bce88@googlegroups.com> Hi Why would it be that my files are not being found in this script? from pyquery import PyQuery as pq import pandas as pd import os import sys if len(sys.argv) == 2: print("no params") sys.exit(1) dir = sys.argv[1] mask = sys.argv[2] files = os.listdir(dir) fileResult = filter(lambda x: x.endswith(mask), files) # d = pq(filename='20160319RHIL0_edit.xml') data = [] for file in fileResult: print(file) for items in fileResult: d = pq(filename=items) res = d('nomination') attrs = ('id', 'horse') data = [[res.eq(i).attr(x) for x in attrs] for i in range(len(res))] # from nominations # res = d('nomination') # nomID = [res.eq(i).attr('id') for i in range(len(res))] # horseName = [res.eq(i).attr('horse') for i in range(len(res))] # attrs = ('id', 'horse') frames = pd.DataFrame(data) print(frames) I am running this from the bash prompt as (pyquery)sayth at sayth-E6410:~/Projects/pyquery$ python jqxml.py samples *.xml my directory structure (pyquery)sayth at sayth-E6410:~/Projects/pyquery$ ls -a . .. environment.yml .git .gitignore #jqxml.py# jqxml.py samples and samples contains (pyquery)sayth at sayth-E6410:~/Projects/pyquery/samples$ ls -a . 20160319RHIL0_edit.xml 20160409RAND0.xml .. 20160402RAND0.xml 20160416RAND0.xml yet I get no files out of the print statement. Ideas? Sayth From steve at pearwood.info Mon Apr 18 20:19:20 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 19 Apr 2016 10:19:20 +1000 Subject: Why are my files in in my list - os module used with sys argv References: <0bce26b1-ad3d-42c4-8f99-08e82d1bce88@googlegroups.com> Message-ID: <5715798b$0$1612$c3e8da3$5496439d@news.astraweb.com> On Tue, 19 Apr 2016 09:44 am, Sayth Renshaw wrote: > Hi > > Why would it be that my files are not being found in this script? You are calling the script with: python jqxml.py samples *.xml This does not do what you think it does: under Linux shells, the glob *.xml will be expanded by the shell. Fortunately, in your case, you have no files in the current directory matching the glob *.xml, so it is not expanded and the arguments your script receives are: "python jqxml.py" # not used "samples" # dir "*.xml" # mask You then call: fileResult = filter(lambda x: x.endswith(mask), files) which looks for file names which end with a literal string (asterisk, dot, x, m, l) in that order. You have no files that match that string. At the shell prompt, enter this: touch samples/junk\*.xml and run the script again, and you should see that it now matches one file. Instead, what you should do is: (1) Use the glob module: https://docs.python.org/2/library/glob.html https://docs.python.org/3/library/glob.html https://pymotw.com/2/glob/ https://pymotw.com/3/glob/ (2) When calling the script, avoid the shell expanding wildcards by escaping them or quoting them: python jqxml.py samples "*.xml" -- Steven From python at mrabarnett.plus.com Mon Apr 18 21:17:15 2016 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 19 Apr 2016 02:17:15 +0100 Subject: Why are my files in in my list - os module used with sys argv In-Reply-To: <0bce26b1-ad3d-42c4-8f99-08e82d1bce88@googlegroups.com> References: <0bce26b1-ad3d-42c4-8f99-08e82d1bce88@googlegroups.com> Message-ID: <5715871B.5000003@mrabarnett.plus.com> On 2016-04-19 00:44, Sayth Renshaw wrote: > Hi > > Why would it be that my files are not being found in this script? > > from pyquery import PyQuery as pq > import pandas as pd > import os > import sys > > if len(sys.argv) == 2: > print("no params") > sys.exit(1) > > dir = sys.argv[1] > mask = sys.argv[2] > > files = os.listdir(dir) > > fileResult = filter(lambda x: x.endswith(mask), files) > > # d = pq(filename='20160319RHIL0_edit.xml') > data = [] > > for file in fileResult: > print(file) > > for items in fileResult: > d = pq(filename=items) > res = d('nomination') > attrs = ('id', 'horse') > data = [[res.eq(i).attr(x) for x in attrs] for i in range(len(res))] > > # from nominations > # res = d('nomination') > # nomID = [res.eq(i).attr('id') for i in range(len(res))] > # horseName = [res.eq(i).attr('horse') for i in range(len(res))] > > # attrs = ('id', 'horse') > > frames = pd.DataFrame(data) > print(frames) > > > I am running this from the bash prompt as > > (pyquery)sayth at sayth-E6410:~/Projects/pyquery$ python jqxml.py samples *.xml > > my directory structure > > (pyquery)sayth at sayth-E6410:~/Projects/pyquery$ ls -a > . .. environment.yml .git .gitignore #jqxml.py# jqxml.py samples > > and samples contains > > (pyquery)sayth at sayth-E6410:~/Projects/pyquery/samples$ ls -a > . 20160319RHIL0_edit.xml 20160409RAND0.xml > .. 20160402RAND0.xml 20160416RAND0.xml > > yet I get no files out of the print statement. > > Ideas? > I don't use Linux, but I think it might be a problem with what you have on the command line. I believe that Linux expands wildcarded names, so what you might be getting is "samples" followed by all the names in the current directory that match "*.xml". Even if that isn't the case, and mask is "*.xml", the filtering that you're doing is asking for those names that end with "*.xml"; you might find a name that ends with ".xml", but I doubt you'll ever find one that ends with "*.xml"! From sohcahtoa82 at gmail.com Mon Apr 18 21:19:18 2016 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Mon, 18 Apr 2016 18:19:18 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: On Monday, April 18, 2016 at 2:14:17 PM UTC-7, Pete Forman wrote: > Why is it that Python continues to use a fixed width font and therefore > specifies the maximum line width as a character count? > > An essential part of the language is indentation which ought to continue > to mandate that lines start with a multiple of 4 em worth of space (or > some other size or encode with hard tabs, that is not germane to my > question). The content of the line need not be bound by the rules needed > to position its start. > > -- > Pete Forman "Why is it that Python continues to use a fixed width font " This guy is trolling, right? From rustompmody at gmail.com Mon Apr 18 23:04:06 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 18 Apr 2016 20:04:06 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> On Tuesday, April 19, 2016 at 6:49:34 AM UTC+5:30, sohcatoa wrote: > On Monday, April 18, 2016 at 2:14:17 PM UTC-7, Pete Forman wrote: > > Why is it that Python continues to use a fixed width font and therefore > > specifies the maximum line width as a character count? > > > > An essential part of the language is indentation which ought to continue > > to mandate that lines start with a multiple of 4 em worth of space (or > > some other size or encode with hard tabs, that is not germane to my > > question). The content of the line need not be bound by the rules needed > > to position its start. > > > > -- > > Pete Forman > > "Why is it that Python continues to use a fixed width font " > > This guy is trolling, right? See elastic tabstops: http://nickgravgaard.com/elastic-tabstops/ And more generally that programmers sticking to text when rest of world has moved on is rather backward: http://blog.languager.org/2012/10/html-is-why-mess-in-programming-syntax.html From random832 at fastmail.com Mon Apr 18 23:29:49 2016 From: random832 at fastmail.com (Random832) Date: Mon, 18 Apr 2016 23:29:49 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> Message-ID: <1461036589.1221872.582808913.08A50F70@webmail.messagingengine.com> On Mon, Apr 18, 2016, at 23:04, Rustom Mody wrote: > See elastic tabstops: http://nickgravgaard.com/elastic-tabstops/ >From there: >A column block is a run of uninterrupted vertically adjacent cells. How's that going to handle this case: if foo: # comment that is aligned do some stuff # across multiple indent levels As far as I can tell, the model being proposed would align the indented code either with the first line's comment, or somewhere after the colon. I think it's excessively "clever" to think you can or should use the same model to solve indentation as other forms of alignment. From rustompmody at gmail.com Mon Apr 18 23:54:40 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 18 Apr 2016 20:54:40 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <1461036589.1221872.582808913.08A50F70@webmail.messagingengine.com> Message-ID: <8b3aa2c6-4314-446a-a894-fe61451a373a@googlegroups.com> On Tuesday, April 19, 2016 at 9:00:12 AM UTC+5:30, Random832 wrote: > On Mon, Apr 18, 2016, at 23:04, Rustom Mody wrote: > > See elastic tabstops: http://nickgravgaard.com/elastic-tabstops/ > > >From there: > >A column block is a run of uninterrupted vertically adjacent cells. > > How's that going to handle this case: > > if foo: # comment that is aligned > do some stuff # across multiple indent levels Just tried it with the jar file? he supplies and it seems to work Start no tabs: if foo# comment that is aligned do some stuff# across multiple indent levels Add tabs as leading indents with second line indented 1 tab more (showing tabs as |) |if foo# comment that is aligned ||do some stuff# across multiple indent levels Indent the first comment with 2 tabs At this point the first comment is/shows lefter than the second Indent the second with 1 tab -- the two #es now line up The invariant of course is clear -- if the total no of tabs in the line prior to the char are equal then all such lines line up ? yeah thats not very secure! And does not work with open java, works with Sun/Oracle java From harirammanohar at gmail.com Tue Apr 19 00:01:09 2016 From: harirammanohar at gmail.com (harirammanohar at gmail.com) Date: Mon, 18 Apr 2016 21:01:09 -0700 (PDT) Subject: delete from pattern to pattern if it contains match In-Reply-To: References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> Message-ID: <670498a7-7033-45e7-b6ac-015d4a40c34e@googlegroups.com> On Monday, April 18, 2016 at 1:19:43 PM UTC+5:30, Joaquin Alzola wrote: > Hi, > > Try to use the xml module. > > import xml.etree.ElementTree as ET > > That might help. > > BR > > Joaquin > > -----Original Message----- > From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com at python.org] On Behalf Of harirammanohar at gmail.com > Sent: 18 April 2016 08:08 > To: python-list at python.org > Subject: delete from pattern to pattern if it contains match > > > HI All, > > can you help me out in doing below. > > file: > > guava > fruit > > > mango > fruit > > > orange > fruit > > > need to delete from start to end if it contains mango in a file... > > output should be: > > > guava > fruit > > > orange > fruit > > > Thank you > -- > https://mail.python.org/mailman/listinfo/python-list > This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. hi Alzola, xml parsing solution works fine only in the below case if input file is in below format. guava fruit mango fruit orange fruit its not working if the input file as below, just a change in the starting header... guava fruit mango fruit orange fruit inthis case its not working.... pls suggest what i have to do to make it work.. From random832 at fastmail.com Tue Apr 19 00:11:03 2016 From: random832 at fastmail.com (Random832) Date: Tue, 19 Apr 2016 00:11:03 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <8b3aa2c6-4314-446a-a894-fe61451a373a@googlegroups.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <1461036589.1221872.582808913.08A50F70@webmail.messagingengine.com> <8b3aa2c6-4314-446a-a894-fe61451a373a@googlegroups.com> Message-ID: <1461039063.1234620.582832393.7B6F72B6@webmail.messagingengine.com> On Mon, Apr 18, 2016, at 23:54, Rustom Mody wrote: > Start no tabs: > if foo# comment that is aligned > do some stuff# across multiple indent levels > > Add tabs as leading indents with second line indented 1 tab more > (showing tabs as |) > |if foo# comment that is aligned > ||do some stuff# across multiple indent levels > > Indent the first comment with 2 tabs > At this point the first comment is/shows lefter than the second > > Indent the second with 1 tab -- the two #es now line up Yeah but now the second line of code is to the right of the whole first line of code. "if foo" must have been too short to illustrate it (it's long enough if a tab is four spaces, but I guess it's longer in the sample), but I assumed you would get the concept of what I was saying and try putting something longer there or try extending the comments in the C code the sample preloads. Like, it ends up looking like this: if foo("what if it's a much longer condition"): # comment do something # comment2 There's no way to get this: if foo("what if it's a much longer condition"): # comment do something # comment2 From blueridiculous at gmail.com Tue Apr 19 00:26:49 2016 From: blueridiculous at gmail.com (BlueRidiculous) Date: Mon, 18 Apr 2016 21:26:49 -0700 (PDT) Subject: error with tkinter, help In-Reply-To: <9cd33690-bb18-446b-9151-aedfd32693ca@googlegroups.com> References: <47977d70-6208-4e68-aca3-e1f63aacfac7@googlegroups.com> <9cd33690-bb18-446b-9151-aedfd32693ca@googlegroups.com> Message-ID: On Sunday, April 17, 2016 at 10:24:32 AM UTC-7, BlueRidiculous wrote: > On Sunday, April 17, 2016 at 10:18:09 AM UTC-7, BlueRidiculous wrote: > > On Saturday, April 16, 2016 at 9:30:39 PM UTC-7, Terry Reedy wrote: > > > On 4/16/2016 9:31 PM, blueridiculous at gmail.com wrote: > > > > So I was reading https://wiki.python.org/moin/TkInter for help. > > > > I got to step 3 under "Checking your Tkinter support." > > > > Nothing happens when I do steps 1 or 2, and when I do step 3, > > > > I get this error: > > > > > > > > Traceback (most recent call last): > > > > File "", line 301, in runcode > > > > File "", line 1, in > > > > File "C:\Python34\lib\tkinter\__init__.py", line 3882, in _test > > > > root = Tk() > > > > File "C:\Python34\lib\tkinter\__init__.py", line 1856, in __init__ > > > > self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) > > > > _tkinter.TclError: Can't find a usable init.tcl in the following directories: > > > > C:/Python34/lib/tcl8.6 C:/lib/tcl8.6 C:/lib/tcl8.6 C:/library C:/library C:/tcl8.6.1/library C:/tcl8.6.1/library > > > > > > > > This probably means that Tcl wasn't installed properly. > > > > " > > > > > > The directory list is obsolete. You should have C:/Python34/tcl > > > How did you install Python? The Windows PSF installer from python.org > > > will create this directory unless you uncheck the box to include tcl/tk. > > > > > > -- > > > Terry Jan Reedy > > > > What is a PSF installer? Anyway, I installed the "Windows x86 MSI installer" from https://www.python.org/downloads/release/python-344/ Is that correct? > > Actually nevermind, I uninstalled and reinstalled Python and it works now. I remember I uninstalled and reinstalled before, and it worked, then stopped working, so I'm not sure how permanent this fix will be. Stay tuned for updates. Thanks again. So no need to "stay tuned for updates" anymore, it has been working for a day and I think that it is good now. If ever it breaks again, I'll just start a new thread. You guys can ignore this now. Thanks again to you guys for the help. From greg.ewing at canterbury.ac.nz Tue Apr 19 01:39:06 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 19 Apr 2016 17:39:06 +1200 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: Ian Kelly wrote: > What happens when another > programmer reviews the code using a different font and finds that > there is only 3.5em worth of space? Do we descend into Calibri / > Verdana line-length edit wars? That's easy, we just decree that all Python source code is to be displayed in this font: http://fontstruct.com/fontstructions/show/89341/flying_circus -- Greg From greg.ewing at canterbury.ac.nz Tue Apr 19 01:46:31 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 19 Apr 2016 17:46:31 +1200 Subject: Convert input to upper case on screen as it is typed In-Reply-To: References: <85oa9cyiqt.fsf@benfinney.id.au> <85bn5cy6bz.fsf@benfinney.id.au> <8537qoy49y.fsf@benfinney.id.au> <85zisqratt.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > > I am still looking for a solution (a Python-specific one would be fine). > The only other way I can think of is to put the tty into raw mode and do your own line editing and echoing. You could wrap it all up in a file-like object for the rest of the code to use. -- Greg From saxri89 at gmail.com Tue Apr 19 02:19:20 2016 From: saxri89 at gmail.com (Xristos Xristoou) Date: Mon, 18 Apr 2016 23:19:20 -0700 (PDT) Subject: Python packages for hydrology and DEM Message-ID: <06a6bfe3-49c2-48a9-9e95-69359cffdebf@googlegroups.com> I want to ask for hydrology python packages with complete function to calculate hydrology tasks like fill,flow direction,flow accumulator and more?or how can i find genetic algorithms for to do this tasks to finaly create a complete hydro model with python. can someone tell me some documentation to do that with python ? i want to find like this TopoToolbox from matlab in python using also i want to ask and for python psckage for digital elevation models calcultor like idw krigging spline and more...or some documentation for this or some genetic algorithm for this ty. From ben+python at benfinney.id.au Tue Apr 19 03:07:18 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 19 Apr 2016 17:07:18 +1000 Subject: Python packages for hydrology and DEM References: <06a6bfe3-49c2-48a9-9e95-69359cffdebf@googlegroups.com> Message-ID: <85d1pmqdp5.fsf@benfinney.id.au> Xristos Xristoou writes: > I want to ask for hydrology python packages with complete function to > calculate hydrology tasks like fill,flow direction,flow accumulator > and more?or how can i find genetic algorithms for to do this tasks to > finaly create a complete hydro model with python. I know nothing useful about that problem domain. What I can say is that the first place to look for Python packages is the Python Package Index. What is your assessment of the search results for searching ?hydrology? or ?genetic algorithm? at the Python Package Index? -- \ ?It is clear that thought is not free if the profession of | `\ certain opinions makes it impossible to earn a living.? | _o__) ?Bertrand Russell, _Free Thought and Official Propaganda_, 1928 | Ben Finney From petef4+usenet at gmail.com Tue Apr 19 03:34:27 2016 From: petef4+usenet at gmail.com (Pete Forman) Date: Tue, 19 Apr 2016 08:34:27 +0100 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> Message-ID: Rustom Mody writes: > On Tuesday, April 19, 2016 at 6:49:34 AM UTC+5:30, sohcatoa wrote: >> On Monday, April 18, 2016 at 2:14:17 PM UTC-7, Pete Forman wrote: >> > Why is it that Python continues to use a fixed width font and therefore >> > specifies the maximum line width as a character count? >> > >> > An essential part of the language is indentation which ought to continue >> > to mandate that lines start with a multiple of 4 em worth of space (or >> > some other size or encode with hard tabs, that is not germane to my >> > question). The content of the line need not be bound by the rules needed >> > to position its start. >> > >> > -- >> > Pete Forman >> >> "Why is it that Python continues to use a fixed width font " >> >> This guy is trolling, right? No, it is a genuine question. It applies to computer langauges in general but this thread is about PEP 8 so I framed it for Python. I was not proposing a change to the langauge. > See elastic tabstops: http://nickgravgaard.com/elastic-tabstops/ I like that Nick separates out the concept of alignment with implicit semantics from the n spaces v tabs arguments. My question asks why monospace is used for the text. > And more generally that programmers sticking to text when rest of > world has moved on is rather backward: > http://blog.languager.org/2012/10/html-is-why-mess-in-programming-syntax.html -- Pete Forman From michael.selik at gmail.com Tue Apr 19 04:02:03 2016 From: michael.selik at gmail.com (Michael Selik) Date: Tue, 19 Apr 2016 08:02:03 +0000 Subject: How much sanity checking is required for function inputs? In-Reply-To: <57145CB4.5040100@icloud.com> References: <5713E52D.3060407@icloud.com> <57145CB4.5040100@icloud.com> Message-ID: On Mon, Apr 18, 2016 at 1:05 AM Christopher Reimer < christopher_reimer at icloud.com> wrote: > On 4/17/2016 3:18 PM, Michael Selik wrote: > > > I'd rather turn the question around: how much sanity checking is > > necessary or useful? You'll find the answer is "surprisingly little" > > compared to your experience in Java. > > I'm looking for a pythonic approach to sanity checking. From what I read > elsewhere, sanity checking belongs in the unit tests and/or library > classes designed for other people to use. I haven't seen many examples > of sanity checks that is common in Java. > > > For example, you don't need to > > explicitly check whether the color is present in your dictionary, > > because it'll give you a KeyError if you look up a bad key. > > Without the sanity check against the constant dictionary, the color > variable could be anything (it should be a string value). Looking at the > code again, I should relocate the sanity checks in the Piece base class. > Why relocate rather than remove? What message would you provide that's better than ``KeyError: 42`` with a traceback that shows exactly which dictionary is being used and how? > Why does the len of positions need to be 16? > > The positions variable is list of coordinates for 16 chess pieces (eight > pawns, two rooks, two knights, two bishops, a king and a queen) for each > color, locating the pieces on either the bottom quarter (i.e., [(1,1), > ..., (2,8)]) or the top quarter (i.e., [(7,1), ..., (8,8)]) of the board. > I meant, what goes wrong if the number of positions input is other than 16? Without these "sanity" checks, your functions might be reusable in, say, a checkers game. From ben+python at benfinney.id.au Tue Apr 19 04:04:06 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 19 Apr 2016 18:04:06 +1000 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> Message-ID: <858u0aqb2h.fsf@benfinney.id.au> Pete Forman writes: > My question asks why monospace is used for the text. Used by whom? Python the programming language (and that includes PEP 8) has nothing to say about what font you use in your text editor. -- \ ?Why should I care about posterity? What's posterity ever done | `\ for me?? ?Groucho Marx | _o__) | Ben Finney From marko at pacujo.net Tue Apr 19 04:09:47 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 19 Apr 2016 11:09:47 +0300 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> Message-ID: <87wpnuqat0.fsf@elektro.pacujo.net> Pete Forman : > I like that Nick separates out the concept of alignment with implicit > semantics from the n spaces v tabs arguments. My question asks why > monospace is used for the text. Because the so-called "plain text" is the age-old lowest common denominator for formal syntax. Python is especially picky about alignment, but the same de-facto assumption is critical pretty much in any programming language from Pascal to Go. Old computer science textbooks presenting algorithms in Algol, Pascal or, say, process algebra, did use varying-width fonts but they were typeset manually. You *could* liberate programming languages from the monospace stranglehold but then you couldn't effectively use "cat", "vi" or "firefox" to display Python programs. You probably would need to wrap the source code in some richer markup like XML and support it specially in the editors. Such enrichment would offer advantages. For example, the visual layout wouldn't necessarily have to be rigid. No more line-length wars (no lines would ever need to be "continued"). No more TAB wars. Comments could be displayed as floating bubbles, or maybe you would have to scratch the screen to see the comment text. Why, you could even decide on local language variations. How about braces to delineate blocks in Python? How about translating the keywords into Japanese? How about setting the Python code right-to-left with Hebrew keywords? Now, descending back on earth, I don't believe the advantages of rich source code will outweigh those of plain text in the foreseeable future. Marko From __peter__ at web.de Tue Apr 19 04:16:28 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 19 Apr 2016 10:16:28 +0200 Subject: Why are my files in in my list - os module used with sys argv References: <0bce26b1-ad3d-42c4-8f99-08e82d1bce88@googlegroups.com> <5715798b$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Tue, 19 Apr 2016 09:44 am, Sayth Renshaw wrote: > >> Hi >> >> Why would it be that my files are not being found in this script? > > You are calling the script with: > > python jqxml.py samples *.xml > > This does not do what you think it does: under Linux shells, the glob > *.xml will be expanded by the shell. Fortunately, in your case, you have > no files in the current directory matching the glob *.xml, so it is not > expanded and the arguments your script receives are: > > > "python jqxml.py" # not used > > "samples" # dir > > "*.xml" # mask > > > You then call: > > fileResult = filter(lambda x: x.endswith(mask), files) > > which looks for file names which end with a literal string (asterisk, dot, > x, m, l) in that order. You have no files that match that string. > > At the shell prompt, enter this: > > touch samples/junk\*.xml > > and run the script again, and you should see that it now matches one file. > > Instead, what you should do is: > > > (1) Use the glob module: > > https://docs.python.org/2/library/glob.html > https://docs.python.org/3/library/glob.html > > https://pymotw.com/2/glob/ > https://pymotw.com/3/glob/ > > > (2) When calling the script, avoid the shell expanding wildcards by > escaping them or quoting them: > > python jqxml.py samples "*.xml" (3) *Use* the expansion mechanism provided by the shell instead of fighting it: $ python jqxml.py samples/*.xml This requires that you change your script from pyquery import PyQuery as pq import pandas as pd import sys fileResult = sys.argv[1:] if not fileResult: print("no files specified") sys.exit(1) for file in fileResult: print(file) for items in fileResult: try: d = pq(filename=items) except FileNotFoundError as e: print(e) continue res = d('nomination') # you could move the attrs definition before the loop attrs = ('id', 'horse') # probably a bug: you are overwriting data on every iteration data = [[res.eq(i).attr(x) for x in attrs] for i in range(len(res))] I think this is the most natural approach if you are willing to accept the quirk that the script tries to process the file 'samples/*.xml' if the samples directory doesn't contain any files with the .xml suffix. Common shell tools work that way: $ ls samples/*.xml samples/1.xml samples/2.xml samples/3.xml $ ls samples/*.XML ls: cannot access samples/*.XML: No such file or directory Unrelated: instead of working with sys.argv directly you could use argparse which is part of the standard library. The code to get at least one file is import argparse parser = argparse.ArgumentParser() parser.add_argument("files", nargs="+") args = parser.parse_args() print(args.files) Note that this doesn't fix the shell expansion oddity. From RasikaSrinivasan at gmail.com Tue Apr 19 04:16:39 2016 From: RasikaSrinivasan at gmail.com (RasikaSrinivasan at gmail.com) Date: Tue, 19 Apr 2016 01:16:39 -0700 (PDT) Subject: building python for qnx 6.5 Message-ID: <3a44eab1-387d-42ea-acb3-4c278806b603@googlegroups.com> friends I am interested in python3 for QNX 6.5. Since i have not found a prebuilt distribution, I would like to build it. I wanted to find out how I could use Momentics IDE to build python for different targets. I want to build only for x86 right now but may want to build for the ARM target as well. The IDE is hosted on a windows platform. Momentics is based on eclipse I believe. any pointers would be deeply appreciated. thanks, srini From rosuav at gmail.com Tue Apr 19 04:17:33 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Apr 2016 18:17:33 +1000 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <87wpnuqat0.fsf@elektro.pacujo.net> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <87wpnuqat0.fsf@elektro.pacujo.net> Message-ID: On Tue, Apr 19, 2016 at 6:09 PM, Marko Rauhamaa wrote: > Now, descending back on earth, I don't believe the advantages of rich > source code will outweigh those of plain text in the foreseeable future. No, they will not, because they'll make your code proprietary. Suddenly *nothing* else will viably work with your code. (And before you say "but diff tools are fine with XML/JSON/YAML/whatever", it's not that simple; as soon as the underlying structure is capable of representing information that doesn't matter to your source code, you open yourself up to diff noise. I've had this exact problem with git-managing my OBS configs, which are JSON files; there's one particular array that's effectively a set, and the file keeps reordering itself. I had to write a pre-commit script that sorts them into a consistent order, else I'd have had useless diffs.) Of course, there's no such thing as "plain text". Encodings will always bite you. But if you can depend on all files being (a) binary, (b) UTF-8, or (c) tagged with a coding cookie, it's not too hard to work with other people's files. ChrisA From asimkostas at gmail.com Tue Apr 19 04:39:05 2016 From: asimkostas at gmail.com (asimkon .) Date: Tue, 19 Apr 2016 11:39:05 +0300 Subject: Django - tastypie - jqgrid Wrapper (installation - manual) Message-ID: I would like to use the following wrapper in one of my Django models, but unfortunately i do not know how to do it due to the lack of sufficient information. I run on my machine Djnago 1.9, tastypi via easy_install, Apache via mod_wsgi and MySQL. After installing all these i do not know how to proceed step 1, step 2 etc in order to use the demo code mentioned in the above page and finally work successfully. Further details about the type of fields and how could be used in grids.py (additional information) would help me a lot. I found the author's github page but unfortunately there is contact information to get in touch with him. If anyone knows so much about it, i would be delighted! Regards Kostas Asimakopoulos From saxri89 at gmail.com Tue Apr 19 04:45:46 2016 From: saxri89 at gmail.com (Xristos Xristoou) Date: Tue, 19 Apr 2016 01:45:46 -0700 (PDT) Subject: Python packages for hydrology and DEM In-Reply-To: <06a6bfe3-49c2-48a9-9e95-69359cffdebf@googlegroups.com> References: <06a6bfe3-49c2-48a9-9e95-69359cffdebf@googlegroups.com> Message-ID: <7ec44c3a-51ff-4c76-b8e4-63f9a36a9f00@googlegroups.com> ?? ?????, 19 ???????? 2016 - 9:19:33 ?.?. UTC+3, ? ??????? Xristos Xristoou ??????: > I want to ask for hydrology python packages with complete function to calculate hydrology tasks like fill,flow direction,flow accumulator and more?or how can i find genetic algorithms for to do this tasks to finaly create a complete hydro model with python. > > can someone tell me some documentation to do that with python ? i want to find like this TopoToolbox from matlab in python using > > also i want to ask and for python psckage for digital elevation models calcultor like idw krigging spline and more...or some documentation for this > or some genetic algorithm for this > > ty. all this packages is old and without or low support-documentecion From sergio.am.spina at gmail.com Tue Apr 19 04:58:09 2016 From: sergio.am.spina at gmail.com (Sergio Spina) Date: Tue, 19 Apr 2016 01:58:09 -0700 (PDT) Subject: ReST: link bookmark In-Reply-To: References: Message-ID: <9d2fb272-ac5d-4c83-908c-86080ea93cb5@googlegroups.com> Il giorno domenica 17 aprile 2016 12:14:57 UTC+2, Sergio Spina ha scritto: > Il giorno domenica 17 aprile 2016 12:04:38 UTC+2, Sergio Spina ha scritto: > > I would know what is the way to implement in ReST a link bookmark like in this example: > > > > > > > > > > > > > >

This text stand for an example of text containing > > > a bookmarked target bookmark.

> > > > > >

So let's go all together to visit the bookmarked target > > > clicking on this link.

> > > > > > > > > > > > > The string that is the name of the anchor is produced by an algorithm and 1) cannot be left away and 2) cannot be seen in the printed document. > > > > Thanks. > > The correct example is: > > > > > > > > >

This text stand for an example of text containig > > a target bookmark.

> > > >

So let's go all together to visit the target clicking > > on this link.

> > > > > > > > Sorry for the mispelling. I've tried some experiments looking for a hint: # file: test.htm

This text stand for an example of text containing a bookmarked target bookmark.

So let's go all together to visit the bookmarked target clicking on this link.

First try: # test.htm converted at http://www.siafoo.net/html.xml This text stand for an example of text containig a `target <>`_ bookmark. So let's go all together to visit the target clicking on `this link <#B3Pa9-5ZRIx-1>`_ . that is not what I'm looking for; # pandoc -f html test.htm -s -o test.rst This text stand for an example of text containig a target bookmark. So let's go all together to visit the target clicking on `this link <#B3Pa9-5ZRIx-1>`__. that is not what I'm looking for; # html2rst.py taken from http://docutils.sourceforge.net/sandbox/cliechti/html2rst/html2rst.py # python html2rst.py test.htm > test.rst This text stand for an example of text containig a target bookmark. So let's go all together to visit the target clicking on `this link`_. .. _this link: #B3Pa9-5ZRIx-1 Not a good try. Is there a better way ? From jon+usenet at unequivocal.co.uk Tue Apr 19 05:03:54 2016 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Tue, 19 Apr 2016 09:03:54 -0000 (UTC) Subject: Moderation and slight change of (de facto) policy References: <5713C08F.3010207@timgolden.me.uk> <5713E8EA.1080801@timgolden.me.uk> Message-ID: On 2016-04-17, Tim Golden wrote: > On 17/04/2016 18:21, Wildman via Python-list wrote: >> On Sun, 17 Apr 2016 17:57:51 +0100, Tim Golden wrote: > > [... snip my explanation of new moderation for non-subscribers ...] > >> How will this change affect posts to comp.lang.python? > > Not at all, in the sense that the moderation doesn't apply to > comp.lang.python, except insofar as posts which are sent to the list and > which we reject obviously won't make it to comp.lang.python either. But from what you described, it sounds like all Usenet posts will now be prevented from reaching the list. If so you should probably consider rmgrouping comp.lang.python or at least abandoning the idea of it being linked to the mailing list. (I've no idea of course if you will even see this message!) From mail at timgolden.me.uk Tue Apr 19 05:16:53 2016 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 19 Apr 2016 10:16:53 +0100 Subject: Moderation and slight change of (de facto) policy In-Reply-To: References: <5713C08F.3010207@timgolden.me.uk> <5713E8EA.1080801@timgolden.me.uk> Message-ID: <5715F785.4010005@timgolden.me.uk> On 19/04/2016 10:03, Jon Ribbens wrote: > On 2016-04-17, Tim Golden wrote: >> On 17/04/2016 18:21, Wildman via Python-list wrote: >>> On Sun, 17 Apr 2016 17:57:51 +0100, Tim Golden wrote: >> >> [... snip my explanation of new moderation for non-subscribers ...] >> >>> How will this change affect posts to comp.lang.python? >> >> Not at all, in the sense that the moderation doesn't apply to >> comp.lang.python, except insofar as posts which are sent to the list and >> which we reject obviously won't make it to comp.lang.python either. > > But from what you described, it sounds like all Usenet posts will > now be prevented from reaching the list. If so you should probably > consider rmgrouping comp.lang.python or at least abandoning the > idea of it being linked to the mailing list. > > (I've no idea of course if you will even see this message!) > Well something in my explanation obviously wasn't clear, because that's certainly not the case. I'm not even sure which bit gave you that impression (please feel free to quote it back at me!). The Usenet gateway operates distinctly from the Mailman moderation -- in fact we have to jump through a hoop or two if we *do* want to moderate someone who usually posts via Usenet. TJG From jon+usenet at unequivocal.co.uk Tue Apr 19 06:43:26 2016 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Tue, 19 Apr 2016 10:43:26 -0000 (UTC) Subject: Moderation and slight change of (de facto) policy References: <5713C08F.3010207@timgolden.me.uk> <5713E8EA.1080801@timgolden.me.uk> <5715F785.4010005@timgolden.me.uk> Message-ID: On 2016-04-19, Tim Golden wrote: > On 19/04/2016 10:03, Jon Ribbens wrote: >> But from what you described, it sounds like all Usenet posts will >> now be prevented from reaching the list. If so you should probably >> consider rmgrouping comp.lang.python or at least abandoning the >> idea of it being linked to the mailing list. >> >> (I've no idea of course if you will even see this message!) > > Well something in my explanation obviously wasn't clear, because that's > certainly not the case. I'm not even sure which bit gave you that > impression (please feel free to quote it back at me!). You said "Our new approach ... will be to reject unsubscribed posts". Usenet posters are not subscribed to the mailing list, hence their posts will be be rejected from the list, according to what you said. > The Usenet gateway operates distinctly from the Mailman moderation -- in > fact we have to jump through a hoop or two if we *do* want to moderate > someone who usually posts via Usenet. Are you saying that Usenet posts skip the moderation entirely? This whole thing seems a bit of a mess. What you really need to be doing is changing the Usenet group to be moderated, otherwise you're going to end up with two different views supposedly of the same thing which in fact may be completely different. From paul.nospam at rudin.co.uk Tue Apr 19 06:49:14 2016 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Tue, 19 Apr 2016 11:49:14 +0100 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> Message-ID: <86twix3mc5.fsf@rudin.co.uk> Pete Forman writes: > Why is it that Python continues to use a fixed width font and therefore > specifies the maximum line width as a character count? Python doesn't require the use of any particular font for editing your code. However programmers tend to use fixed width fonts when editing code because then the visual representation of indentation works consistently. But that's not a python specific thing. From rustompmody at gmail.com Tue Apr 19 07:37:25 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 19 Apr 2016 04:37:25 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <87wpnuqat0.fsf@elektro.pacujo.net> Message-ID: <39d27a77-fa74-4d63-b1b6-d612c3905bd4@googlegroups.com> On Tuesday, April 19, 2016 at 1:47:48 PM UTC+5:30, Chris Angelico wrote: > On Tue, Apr 19, 2016 at 6:09 PM, Marko Rauhamaa wrote: > > Now, descending back on earth, I don't believe the advantages of rich > > source code will outweigh those of plain text in the foreseeable future. > > No, they will not, because they'll make your code proprietary. Pragmatically yes; theoretically no because its like saying "If one dont want to get locked down to MSWord proprietary tools and formats one should use latex" Refuted by the fact that libreoffice and odf etc are free/open > Suddenly *nothing* else will viably work with your code. (And before > you say "but diff tools are fine with XML/JSON/YAML/whatever", it's > not that simple; as soon as the underlying structure is capable of > representing information that doesn't matter to your source code, you > open yourself up to diff noise. You just nicely described how diff is ?-assed. In more detail here is foo.txt foo1.txt and foo2.txt containing ------- Now is the time for all good men to come to the aid of their country ------- vi, emacs, shell (cat) show them right and having the same contents However diff (and therefore unfortunately git) have no clue that one has DOS line-endings and one is UTF-16 > I've had this exact problem with > git-managing my OBS configs, which are JSON files; there's one > particular array that's effectively a set, and the file keeps > reordering itself. I had to write a pre-commit script that sorts them > into a consistent order, else I'd have had useless diffs.) If you are ok with json morphing to yaml you may find ruamel useful http://stackoverflow.com/questions/5121931/in-python-how-can-you-load-yaml-mappings-as-ordereddicts https://pypi.python.org/pypi/ruamel.yaml From marko at pacujo.net Tue Apr 19 07:47:50 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 19 Apr 2016 14:47:50 +0300 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <86twix3mc5.fsf@rudin.co.uk> Message-ID: <87potlrfa1.fsf@elektro.pacujo.net> Paul Rudin : > Pete Forman writes: >> Why is it that Python continues to use a fixed width font and >> therefore specifies the maximum line width as a character count? > > Python doesn't require the use of any particular font for editing your > code. > > However programmers tend to use fixed width fonts when editing code > because then the visual representation of indentation works > consistently. But that's not a python specific thing. Prehistoric programming languages considered uppercase/lowercase differences insignificant variations. Most modern languages preserve the distinction and in fact invite us to make a difference between: BLACK Black black Why stop there? We need a PEP to distinguish also between: - typefaces (Times New Roman vs Garamond) - weights (bold vs thin) - serifs (with or without) - sizes (8pt vs 11pt) - colors (goldenrod vs maroon) Think of all the lesser programming languages that would seem so 20th-century when Python takes this step -- which virtually every self-respecting web site has already taken in their style sheets! Marko From rustompmody at gmail.com Tue Apr 19 08:06:18 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 19 Apr 2016 05:06:18 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: <87potlrfa1.fsf@elektro.pacujo.net> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <86twix3mc5.fsf@rudin.co.uk> <87potlrfa1.fsf@elektro.pacujo.net> Message-ID: <899a2469-3627-468f-8591-9cf95f17e1e8@googlegroups.com> On Tuesday, April 19, 2016 at 5:18:07 PM UTC+5:30, Marko Rauhamaa wrote: > Paul Rudin : > > > Pete Forman writes: > >> Why is it that Python continues to use a fixed width font and > >> therefore specifies the maximum line width as a character count? > > > > Python doesn't require the use of any particular font for editing your > > code. > > > > However programmers tend to use fixed width fonts when editing code > > because then the visual representation of indentation works > > consistently. But that's not a python specific thing. > > Prehistoric programming languages considered uppercase/lowercase > differences insignificant variations. Most modern languages preserve the > distinction and in fact invite us to make a difference between: > > BLACK > Black > black > > Why stop there? > > We need a PEP to distinguish also between: > > - typefaces (Times New Roman vs Garamond) > > - weights (bold vs thin) > > - serifs (with or without) > > - sizes (8pt vs 11pt) > > - colors (goldenrod vs maroon) > > > Think of all the lesser programming languages that would seem so > 20th-century when Python takes this step -- which virtually every > self-respecting web site has already taken in their style sheets! You are of course being facetious but Forth already beat you to it in Color Forth: https://blogs.msdn.microsoft.com/ashleyf/2013/11/02/the-beautiful-simplicity-of-colorforth/ More seriously the problem is that when we go from 100 of ASCII to 1 million of Unicode its like a digital to analogue jump. In http://blog.languager.org/2014/04/unicoded-python.html Ive described that it would be nice if for instance we could write x ? y in place of the clunky x <= y Likewise x ? y would obviate all useless arguments between x <>y or x != y etc But then there are a slew of lookalikes like x ? y x ? y If someone seriously starts embracing unicode in program source, these kinds of questions/issues need corresponding serious consideration. In the same way and like colorforth, it would be better to distinguish identifier from identifier rather than the current status of distinguishing identifier from Identifier But then we have a slippery slope: Should be same/distinct from ? From marko at pacujo.net Tue Apr 19 08:14:18 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 19 Apr 2016 15:14:18 +0300 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <86twix3mc5.fsf@rudin.co.uk> <87potlrfa1.fsf@elektro.pacujo.net> <899a2469-3627-468f-8591-9cf95f17e1e8@googlegroups.com> Message-ID: <87lh49re1x.fsf@elektro.pacujo.net> Rustom Mody : > In the same way and like colorforth, it would be better to distinguish > identifier from > identifier rather than the current status of > distinguishing identifier from Identifier But then we have a slippery > slope: Should be same/distinct from ? In a past life of mine, a development team proudly presented their new reporting tool that produced beautiful graphs with dozens of crisscrossing, jagged lines. I proposed they needed to make each line a different color and add a legend for each color. The developers thought that was a great idea. Marko From rustompmody at gmail.com Tue Apr 19 08:55:53 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 19 Apr 2016 05:55:53 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <1461036589.1221872.582808913.08A50F70@webmail.messagingengine.com> <8b3aa2c6-4314-446a-a894-fe61451a373a@googlegroups.com> <1461039063.1234620.582832393.7B6F72B6@webmail.messagingengine.com> Message-ID: <0536e5a3-793f-44b3-87cc-5743bcf2a6a9@googlegroups.com> On Tuesday, April 19, 2016 at 9:41:24 AM UTC+5:30, Random832 wrote: > On Mon, Apr 18, 2016, at 23:54, Rustom Mody wrote: > > Start no tabs: > > if foo# comment that is aligned > > do some stuff# across multiple indent levels > > > > Add tabs as leading indents with second line indented 1 tab more > > (showing tabs as |) > > |if foo# comment that is aligned > > ||do some stuff# across multiple indent levels > > > > Indent the first comment with 2 tabs > > At this point the first comment is/shows lefter than the second > > > > Indent the second with 1 tab -- the two #es now line up > > Yeah but now the second line of code is to the right of the whole first > line of code. "if foo" must have been too short to illustrate it (it's > long enough if a tab is four spaces, but I guess it's longer in the > sample), but I assumed you would get the concept of what I was saying > and try putting something longer there or try extending the comments in > the C code the sample preloads. > > Like, it ends up looking like this: > > if foo("what if it's a much longer condition"): # comment > do something # > comment2 > > There's no way to get this: > > if foo("what if it's a much longer condition"): # comment > do something # comment2 I get it looking quite nice if I put a tab between "foo" and "(" Is that an acceptable solution?? Dunno... html tables need all sorts of 'un-table-ifying' options eg column/row groups, tables within tables and what not. At which point we cross the point of diminishing returns is not clear when we are still armchair discussing. For something a bit more practical here is emacs (orgtbl mode) doing html tables: https://www.youtube.com/watch?v=EQAd41VAXWo From antoon.pardon at rece.vub.ac.be Tue Apr 19 09:07:50 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 19 Apr 2016 15:07:50 +0200 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <87potlrfa1.fsf@elektro.pacujo.net> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <86twix3mc5.fsf@rudin.co.uk> <87potlrfa1.fsf@elektro.pacujo.net> Message-ID: <57162DA6.7000509@rece.vub.ac.be> Op 19-04-16 om 13:47 schreef Marko Rauhamaa: > Prehistoric programming languages considered uppercase/lowercase > differences insignificant variations. Most modern languages preserve the > distinction and in fact invite us to make a difference between: > > BLACK > Black > black > > Why stop there? > > We need a PEP to distinguish also between: > > - typefaces (Times New Roman vs Garamond) > > - weights (bold vs thin) > > - serifs (with or without) > > - sizes (8pt vs 11pt) > > - colors (goldenrod vs maroon) Well personnaly I would like the introduction of weights. So that reserved keywords are in bold and identifiers are thin. With unicode we could use the mathematical bold letters for reserved words. -- Antoon Pardon From python.list at tim.thechases.com Tue Apr 19 09:17:08 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 19 Apr 2016 08:17:08 -0500 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <39d27a77-fa74-4d63-b1b6-d612c3905bd4@googlegroups.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <87wpnuqat0.fsf@elektro.pacujo.net> <39d27a77-fa74-4d63-b1b6-d612c3905bd4@googlegroups.com> Message-ID: <20160419081708.56aeed8d@bigbox.christie.dr> On 2016-04-19 04:37, Rustom Mody wrote: > > No, they will not, because they'll make your code proprietary. > > Pragmatically yes; theoretically no because its like saying > "If one dont want to get locked down to MSWord proprietary tools > and formats one should use latex" > Refuted by the fact that libreoffice and odf etc are free/open Except that I still regularly have trouble with consistent formatting being portable between LO/OO.o/MSWord (heck, I still have trouble with MS Word not being consistent between versions). -tkc From flebber.crue at gmail.com Tue Apr 19 09:21:22 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Tue, 19 Apr 2016 06:21:22 -0700 (PDT) Subject: Why are my files in in my list - os module used with sys argv In-Reply-To: References: <0bce26b1-ad3d-42c4-8f99-08e82d1bce88@googlegroups.com> <5715798b$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: <719abd0a-d3b4-483d-ab77-1989b06f062e@googlegroups.com> On Tuesday, 19 April 2016 18:17:02 UTC+10, Peter Otten wrote: > Steven D'Aprano wrote: > > > On Tue, 19 Apr 2016 09:44 am, Sayth Renshaw wrote: > > > >> Hi > >> > >> Why would it be that my files are not being found in this script? > > > > You are calling the script with: > > > > python jqxml.py samples *.xml > > > > This does not do what you think it does: under Linux shells, the glob > > *.xml will be expanded by the shell. Fortunately, in your case, you have > > no files in the current directory matching the glob *.xml, so it is not > > expanded and the arguments your script receives are: > > > > > > "python jqxml.py" # not used > > > > "samples" # dir > > > > "*.xml" # mask > > > > > > You then call: > > > > fileResult = filter(lambda x: x.endswith(mask), files) > > > > which looks for file names which end with a literal string (asterisk, dot, > > x, m, l) in that order. You have no files that match that string. > > > > At the shell prompt, enter this: > > > > touch samples/junk\*.xml > > > > and run the script again, and you should see that it now matches one file. > > > > Instead, what you should do is: > > > > > > (1) Use the glob module: > > > > https://docs.python.org/2/library/glob.html > > https://docs.python.org/3/library/glob.html > > > > https://pymotw.com/2/glob/ > > https://pymotw.com/3/glob/ > > > > > > (2) When calling the script, avoid the shell expanding wildcards by > > escaping them or quoting them: > > > > python jqxml.py samples "*.xml" > > (3) *Use* the expansion mechanism provided by the shell instead of fighting > it: > > $ python jqxml.py samples/*.xml > > This requires that you change your script > > from pyquery import PyQuery as pq > import pandas as pd > import sys > > fileResult = sys.argv[1:] > > if not fileResult: > print("no files specified") > sys.exit(1) > > for file in fileResult: > print(file) > > for items in fileResult: > try: > d = pq(filename=items) > except FileNotFoundError as e: > print(e) > continue > res = d('nomination') > # you could move the attrs definition before the loop > attrs = ('id', 'horse') > # probably a bug: you are overwriting data on every iteration > data = [[res.eq(i).attr(x) for x in attrs] for i in range(len(res))] > > I think this is the most natural approach if you are willing to accept the > quirk that the script tries to process the file 'samples/*.xml' if the > samples directory doesn't contain any files with the .xml suffix. Common > shell tools work that way: > > $ ls samples/*.xml > samples/1.xml samples/2.xml samples/3.xml > $ ls samples/*.XML > ls: cannot access samples/*.XML: No such file or directory > > Unrelated: instead of working with sys.argv directly you could use argparse > which is part of the standard library. The code to get at least one file is > > import argparse > > parser = argparse.ArgumentParser() > parser.add_argument("files", nargs="+") > args = parser.parse_args() > > print(args.files) > > Note that this doesn't fix the shell expansion oddity. Hi Thanks for the insight, after doing a little reading I found this post which uses both argparse and glob and attempts to cover the windows and bash expansion of wildcards, http://breathmintsforpenguins.blogspot.com.au/2013/09/python-crossplatform-handling-of.html import argparse from glob import glob def main(file_names): print file_names if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("file_names", nargs='*') #nargs='*' tells it to combine all positional arguments into a single list args = parser.parse_args() file_names = list() #go through all of the arguments and replace ones with wildcards with the expansion #if a string does not contain a wildcard, glob will return it as is. for arg in args.file_names: file_names += glob(arg) main(file_names) And way beyond my needs for such a tiny script but I think tis is the flask developers python cli creation package Click http://click.pocoo.org/5/why/#why-not-argparse based of optparse. > # probably a bug: you are overwriting data on every iteration > data = [[res.eq(i).attr(x) for x in attrs] for i in range(len(res))] Thanks for picking this up will have to append to it on each iteration for each attribute. Thank You Sayth From michael.selik at gmail.com Tue Apr 19 09:28:48 2016 From: michael.selik at gmail.com (Michael Selik) Date: Tue, 19 Apr 2016 13:28:48 +0000 Subject: Python packages for hydrology and DEM In-Reply-To: <06a6bfe3-49c2-48a9-9e95-69359cffdebf@googlegroups.com> References: <06a6bfe3-49c2-48a9-9e95-69359cffdebf@googlegroups.com> Message-ID: On Tue, Apr 19, 2016 at 2:21 AM Xristos Xristoou wrote: > I want to ask for hydrology python packages with complete function to > calculate hydrology tasks like fill,flow direction,flow accumulator and > more?or how can i find genetic algorithms for to do this tasks to finaly > create a complete hydro model with python. > > can someone tell me some documentation to do that with python ? i want to > find like this TopoToolbox from matlab in python using > > also i want to ask and for python psckage for digital elevation models > calcultor like idw krigging spline and more...or some documentation for this > or some genetic algorithm for this > > Sklearn is a good machine learning package (http://scikit-learn.org/). I suggest simulated annealing rather than genetic algorithms. From python.list at tim.thechases.com Tue Apr 19 09:31:01 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 19 Apr 2016 08:31:01 -0500 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <87potlrfa1.fsf@elektro.pacujo.net> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <86twix3mc5.fsf@rudin.co.uk> <87potlrfa1.fsf@elektro.pacujo.net> Message-ID: <20160419083101.5cdfe184@bigbox.christie.dr> On 2016-04-19 14:47, Marko Rauhamaa wrote: > We need a PEP to distinguish also between: > - typefaces (Times New Roman vs Garamond) > - weights (bold vs thin) > - serifs (with or without) > - sizes (8pt vs 11pt) > - colors (goldenrod vs maroon) Like HTML & CSS, the goal should be to separate the code (HTML) from its presentation (how it appears in your editor). It's why I've taken to using formulaic indenting (one or two indents depending on whether the continued line starts an indented block) rather than trying to align with something in a prior line. It drives me nuts when I globally change the spelling of something (and thus the length of some variable name) and then feel obligated to re-indent my continuations to get them to line back up with some arbitrary paren. Compare def do_something(param1, param2, param3, ): implementation() with just using def do_something(param1, param2, param3, ): implementation() (or, if you want your params to line up def do_something( param1, param2, param3, ): implementation() which is usually how I end up splitting them) When "do_something" changes to "frobify", I don't feel the need to go play with indentation with my scheme. Likewise, I detest aligning comments and almost always prefer to put them in a neighboring line if there's continuation: foo = bar * 3 + 2 # we have 3 bars # plus one for margin on either side changing the length of the code portion (say, s/bar/inner_width/) will require re-indenting (and possibly re-flowing) the comments. It's even worse if the comment flows to an unrelated line foo = bar * 3 + 2 # we have 3 bars result = apply(bar) # plus one for margin on either side Now, if either line of *code* changes, it requires rejiggering the comment indentation. If the comment gets moved above, it's no longer an issue: # we have 3 bars plus one for margin on either side foo = bar * 3 + 2 result = apply(bar) I strongly advocate from keeping the content (the code and its AST) separate from its presentation. -tkc From flebber.crue at gmail.com Tue Apr 19 09:31:50 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Tue, 19 Apr 2016 06:31:50 -0700 (PDT) Subject: Why are my files in in my list - os module used with sys argv In-Reply-To: <719abd0a-d3b4-483d-ab77-1989b06f062e@googlegroups.com> References: <0bce26b1-ad3d-42c4-8f99-08e82d1bce88@googlegroups.com> <5715798b$0$1612$c3e8da3$5496439d@news.astraweb.com> <719abd0a-d3b4-483d-ab77-1989b06f062e@googlegroups.com> Message-ID: <19e288ee-fc9d-4ed3-bf7a-e6d76c379b60@googlegroups.com> On Tuesday, 19 April 2016 23:21:42 UTC+10, Sayth Renshaw wrote: > On Tuesday, 19 April 2016 18:17:02 UTC+10, Peter Otten wrote: > > Steven D'Aprano wrote: > > > > > On Tue, 19 Apr 2016 09:44 am, Sayth Renshaw wrote: > > > > > >> Hi > > >> > > >> Why would it be that my files are not being found in this script? > > > > > > You are calling the script with: > > > > > > python jqxml.py samples *.xml > > > > > > This does not do what you think it does: under Linux shells, the glob > > > *.xml will be expanded by the shell. Fortunately, in your case, you have > > > no files in the current directory matching the glob *.xml, so it is not > > > expanded and the arguments your script receives are: > > > > > > > > > "python jqxml.py" # not used > > > > > > "samples" # dir > > > > > > "*.xml" # mask > > > > > > > > > You then call: > > > > > > fileResult = filter(lambda x: x.endswith(mask), files) > > > > > > which looks for file names which end with a literal string (asterisk, dot, > > > x, m, l) in that order. You have no files that match that string. > > > > > > At the shell prompt, enter this: > > > > > > touch samples/junk\*.xml > > > > > > and run the script again, and you should see that it now matches one file. > > > > > > Instead, what you should do is: > > > > > > > > > (1) Use the glob module: > > > > > > https://docs.python.org/2/library/glob.html > > > https://docs.python.org/3/library/glob.html > > > > > > https://pymotw.com/2/glob/ > > > https://pymotw.com/3/glob/ > > > > > > > > > (2) When calling the script, avoid the shell expanding wildcards by > > > escaping them or quoting them: > > > > > > python jqxml.py samples "*.xml" > > > > (3) *Use* the expansion mechanism provided by the shell instead of fighting > > it: > > > > $ python jqxml.py samples/*.xml > > > > This requires that you change your script > > > > from pyquery import PyQuery as pq > > import pandas as pd > > import sys > > > > fileResult = sys.argv[1:] > > > > if not fileResult: > > print("no files specified") > > sys.exit(1) > > > > for file in fileResult: > > print(file) > > > > for items in fileResult: > > try: > > d = pq(filename=items) > > except FileNotFoundError as e: > > print(e) > > continue > > res = d('nomination') > > # you could move the attrs definition before the loop > > attrs = ('id', 'horse') > > # probably a bug: you are overwriting data on every iteration > > data = [[res.eq(i).attr(x) for x in attrs] for i in range(len(res))] > > > > I think this is the most natural approach if you are willing to accept the > > quirk that the script tries to process the file 'samples/*.xml' if the > > samples directory doesn't contain any files with the .xml suffix. Common > > shell tools work that way: > > > > $ ls samples/*.xml > > samples/1.xml samples/2.xml samples/3.xml > > $ ls samples/*.XML > > ls: cannot access samples/*.XML: No such file or directory > > > > Unrelated: instead of working with sys.argv directly you could use argparse > > which is part of the standard library. The code to get at least one file is > > > > import argparse > > > > parser = argparse.ArgumentParser() > > parser.add_argument("files", nargs="+") > > args = parser.parse_args() > > > > print(args.files) > > > > Note that this doesn't fix the shell expansion oddity. > > Hi > > Thanks for the insight, after doing a little reading I found this post which uses both argparse and glob and attempts to cover the windows and bash expansion of wildcards, http://breathmintsforpenguins.blogspot.com.au/2013/09/python-crossplatform-handling-of.html > > import argparse > from glob import glob > > def main(file_names): > print file_names > > if __name__ == "__main__": > parser = argparse.ArgumentParser() > parser.add_argument("file_names", nargs='*') > #nargs='*' tells it to combine all positional arguments into a single list > args = parser.parse_args() > file_names = list() > > #go through all of the arguments and replace ones with wildcards with the expansion > #if a string does not contain a wildcard, glob will return it as is. > for arg in args.file_names: > file_names += glob(arg) > > main(file_names) > > And way beyond my needs for such a tiny script but I think tis is the flask developers python cli creation package Click http://click.pocoo.org/5/why/#why-not-argparse based of optparse. > > > > # probably a bug: you are overwriting data on every iteration > > data = [[res.eq(i).attr(x) for x in attrs] for i in range(len(res))] > > Thanks for picking this up will have to append to it on each iteration for each attribute. > > Thank You > > Sayth Scratch that bit about the code for http://breathmintsforpenguins.blogspot.com.au/2013/09/python-crossplatform-handling-of.html can't get it to work, good general direction though Sayth From rosuav at gmail.com Tue Apr 19 09:41:06 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Apr 2016 23:41:06 +1000 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <20160419083101.5cdfe184@bigbox.christie.dr> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <86twix3mc5.fsf@rudin.co.uk> <87potlrfa1.fsf@elektro.pacujo.net> <20160419083101.5cdfe184@bigbox.christie.dr> Message-ID: On Tue, Apr 19, 2016 at 11:31 PM, Tim Chase wrote: > Likewise, I detest aligning comments and almost always prefer to put > them in a neighboring line if there's continuation: > > foo = bar * 3 + 2 # we have 3 bars > # plus one for margin on either side > > changing the length of the code portion (say, s/bar/inner_width/) will > require re-indenting (and possibly re-flowing) the comments. > > It's even worse if the comment flows to an unrelated line > > foo = bar * 3 + 2 # we have 3 bars > result = apply(bar) # plus one for margin on either side > > Now, if either line of *code* changes, it requires rejiggering the > comment indentation. > > If the comment gets moved above, it's no longer an issue: > > # we have 3 bars plus one for margin on either side > foo = bar * 3 + 2 > result = apply(bar) Oh, absolutely! If the right-hand comment can't fit in the right-hand-side, it needs to move above the code. The only time I'll "wrap" that kind of comment is when it actually applies to both lines of code: width = bar * 3 + 2 # we have 3x2 bars, plus one... height = bar * 2 + 2 # ... pixel of margin on all sides ChrisA From __peter__ at web.de Tue Apr 19 09:45:24 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 19 Apr 2016 15:45:24 +0200 Subject: Why are my files in in my list - os module used with sys argv References: <0bce26b1-ad3d-42c4-8f99-08e82d1bce88@googlegroups.com> <5715798b$0$1612$c3e8da3$5496439d@news.astraweb.com> <719abd0a-d3b4-483d-ab77-1989b06f062e@googlegroups.com> Message-ID: Sayth Renshaw wrote: > Thanks for the insight, after doing a little reading I found this post > which uses both argparse and glob and attempts to cover the windows and > bash expansion of wildcards, > http://breathmintsforpenguins.blogspot.com.au/2013/09/python-crossplatform-handling-of.html I hope you read the comment section of that page carefully. On Linux your script's behaviour will be surprising. From python.list at tim.thechases.com Tue Apr 19 09:50:28 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 19 Apr 2016 08:50:28 -0500 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <86twix3mc5.fsf@rudin.co.uk> <87potlrfa1.fsf@elektro.pacujo.net> <20160419083101.5cdfe184@bigbox.christie.dr> Message-ID: <20160419085028.50aabd63@bigbox.christie.dr> On 2016-04-19 23:41, Chris Angelico wrote: > The only time I'll "wrap" that kind of comment is when it actually > applies to both lines of code: > > width = bar * 3 + 2 # we have 3x2 bars, plus one... > height = bar * 2 + 2 # ... pixel of margin on all sides And even then in that exceptional case, I see that you do the same thing I do: just append , hash, space, comment. No fancy aligning. -tkc From liran.maymoni at gmail.com Tue Apr 19 09:58:58 2016 From: liran.maymoni at gmail.com (liran.maymoni at gmail.com) Date: Tue, 19 Apr 2016 06:58:58 -0700 (PDT) Subject: Problem with textblob lib Message-ID: Hey, Using windows 10 I've install textblob using "py -m pip install textblob". I can import textblob, or from textblob import blob,word But i cant: from textblobl import Textblob. The error i get is: Traceback (most recent call last): File "", line 1, in from textblob import Textblob ImportError: cannot import name 'Textblob' Thanks. From random832 at fastmail.com Tue Apr 19 10:05:48 2016 From: random832 at fastmail.com (Random832) Date: Tue, 19 Apr 2016 10:05:48 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <0536e5a3-793f-44b3-87cc-5743bcf2a6a9@googlegroups.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <1461036589.1221872.582808913.08A50F70@webmail.messagingengine.com> <8b3aa2c6-4314-446a-a894-fe61451a373a@googlegroups.com> <1461039063.1234620.582832393.7B6F72B6@webmail.messagingengine.com> <0536e5a3-793f-44b3-87cc-5743bcf2a6a9@googlegroups.com> Message-ID: <1461074748.2551319.583266185.15F4C348@webmail.messagingengine.com> On Tue, Apr 19, 2016, at 08:55, Rustom Mody wrote: > > Like, it ends up looking like this: > > > > if foo("what if it's a much longer condition"): # comment > > do something # > > comment2 > > > > There's no way to get this: > > > > if foo("what if it's a much longer condition"): # comment > > do something # comment2 > > I get it looking quite nice if I put a tab between "foo" and "(" > Is that an acceptable solution?? Dunno... No, because what if "foo" is much longer? You could put a tab after "if", but that means while-blocks are indented further than if-blocks. And that just delays the problem to the third indent block, you've got to find something to line that up to. if foo("blah blah blah"): # comment if bar("etc etc etc etc"): # comment do stuff # comment becomes if foo ("blah blah blah"): # comment if bar ("etc etc etc etc"): # comment do stuff # comment Maybe what we really need is a way to _display_ a multiline comment at the right margin (and hanging down for as many lines as it needs), without having it baked into the source code that way. Source file contains: ### Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ### ut mattis leo. In sed arcu gravida, consequat tellus placerat, ### ullamcorper metus. if foo: if bar: do stuff ### some other stuff (the last ### is just an empty comment to push stuff after it down past the first comment - if another comment is there instead, it will be displayed starting from the "some other stuff" line) Displays as: if foo: # Lorem ipsum dolor sit amet, consectetur if bar: # adipiscing elit. Etiam ut mattis leo. In sed do stuff # arcu gravida, consequat tellus # placerat, ullamcorper metus. some other stuff From __peter__ at web.de Tue Apr 19 10:08:21 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 19 Apr 2016 16:08:21 +0200 Subject: Problem with textblob lib References: Message-ID: liran.maymoni at gmail.com wrote: > Hey, > Using windows 10 > I've install textblob using "py -m pip install textblob". > I can import textblob, or from textblob import blob,word > But i cant: from textblobl import Textblob. > The error i get is: > Traceback (most recent call last): > File "", line 1, in > from textblob import Textblob > ImportError: cannot import name 'Textblob' > > Thanks. Try from textblob import TextBlob Python is case-sensitive. From rustompmody at gmail.com Tue Apr 19 10:10:08 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 19 Apr 2016 07:10:08 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <87wpnuqat0.fsf@elektro.pacujo.net> <39d27a77-fa74-4d63-b1b6-d612c3905bd4@googlegroups.com> <20160419081708.56aeed8d@bigbox.christie.dr> Message-ID: <9165ef47-2201-4520-bcd4-881165c839bf@googlegroups.com> On Tuesday, April 19, 2016 at 7:30:18 PM UTC+5:30, Tim Chase wrote: > On 2016-04-19 04:37, Rustom Mody wrote: > > > No, they will not, because they'll make your code proprietary. > > > > Pragmatically yes; theoretically no because its like saying > > "If one dont want to get locked down to MSWord proprietary tools > > and formats one should use latex" > > Refuted by the fact that libreoffice and odf etc are free/open > > Except that I still regularly have trouble with consistent formatting > being portable between LO/OO.o/MSWord (heck, I still have trouble > with MS Word not being consistent between versions). 1. That libre is in sux category compared to MS 2. That MS does legal and illegal things to lock people in 3. And other charms of civilized existence naturally conduce us to the most rational choice - luddeiteism Fortunately or unfortunately we dont always make rational choices :-) text files are a luddite choice They work in the same way that pen-n-paper keep working when the power fails and computer is down From rosuav at gmail.com Tue Apr 19 10:13:00 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Apr 2016 00:13:00 +1000 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <1461074748.2551319.583266185.15F4C348@webmail.messagingengine.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <1461036589.1221872.582808913.08A50F70@webmail.messagingengine.com> <8b3aa2c6-4314-446a-a894-fe61451a373a@googlegroups.com> <1461039063.1234620.582832393.7B6F72B6@webmail.messagingengine.com> <0536e5a3-793f-44b3-87cc-5743bcf2a6a9@googlegroups.com> <1461074748.2551319.583266185.15F4C348@webmail.messagingengine.com> Message-ID: On Wed, Apr 20, 2016 at 12:05 AM, Random832 wrote: > Source file contains: > ### Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam > ### ut mattis leo. In sed arcu gravida, consequat tellus placerat, > ### ullamcorper metus. > if foo: > if bar: > do stuff > ### > some other stuff > > (the last ### is just an empty comment to push stuff after it down past > the first comment - if another comment is there instead, it will be > displayed starting from the "some other stuff" line) > > Displays as: > > if foo: # Lorem ipsum dolor sit amet, consectetur > if bar: # adipiscing elit. Etiam ut mattis leo. In sed > do stuff # arcu gravida, consequat tellus > # placerat, ullamcorper metus. > > some other stuff Why does it need to be displayed to the right, though? Do we gain anything by not having the comment above the code? ChrisA From grant.b.edwards at gmail.com Tue Apr 19 10:15:52 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 19 Apr 2016 14:15:52 +0000 (UTC) Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> Message-ID: On 2016-04-19, Pete Forman wrote: > My question asks why monospace is used for the text. Well, I always use a monospaced font for code because I find it helps readability for things like tables of data, block comments, and lines of code that have some sort of parallel structure that I want to be obvious to the reader. > And more generally that programmers sticking to text when rest of > world has moved on is rather backward: > http://blog.languager.org/2012/10/html-is-why-mess-in-programming-syntax.html The same reason humans use written and spoken language rather than just drawing pictures, pointing, and grunting? -- Grant Edwards grant.b.edwards Yow! What a COINCIDENCE! at I'm an authorized "SNOOTS gmail.com OF THE STARS" dealer!! From flebber.crue at gmail.com Tue Apr 19 10:18:11 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Tue, 19 Apr 2016 07:18:11 -0700 (PDT) Subject: Why are my files in in my list - os module used with sys argv In-Reply-To: References: <0bce26b1-ad3d-42c4-8f99-08e82d1bce88@googlegroups.com> <5715798b$0$1612$c3e8da3$5496439d@news.astraweb.com> <719abd0a-d3b4-483d-ab77-1989b06f062e@googlegroups.com> Message-ID: <96dfb79a-697c-47cb-b9d9-690f4f937062@googlegroups.com> On Tuesday, 19 April 2016 23:46:01 UTC+10, Peter Otten wrote: > Sayth Renshaw wrote: > > > Thanks for the insight, after doing a little reading I found this post > > which uses both argparse and glob and attempts to cover the windows and > > bash expansion of wildcards, > > http://breathmintsforpenguins.blogspot.com.au/2013/09/python-crossplatform-handling-of.html > > I hope you read the comment section of that page carefully. > On Linux your script's behaviour will be surprising. Yes I have gone your way now and am parsing the files, where my data is going will have to wait till after I sleep. Thanks for the advice. from pyquery import PyQuery as pq import pandas as pd import argparse # from glob import glob parser = argparse.ArgumentParser(description=None) def GetArgs(parser): """Parser function using argparse""" # parser.add_argument('directory', help='directory use', # action='store', nargs='*') parser.add_argument("files", nargs="+") return parser.parse_args() fileList = GetArgs(parser) print(fileList.files) # d = pq(filename='20160319RHIL0_edit.xml') data = [] attrs = ('id', 'horse') for items in fileList.files: d = pq(filename=items) res = d('nomination') dataSets = [[res.eq(i).attr(x) for x in attrs] for i in range(len(res))] resultList = data.append(dataSets) frames = pd.DataFrame(resultList) print(frames) -------------------------------------------------------------------------- (pyquery)sayth at sayth-E6410:~/Projects/pyquery$ python jqxml.py samples/*.xml ['samples/20160319RHIL0_edit.xml', 'samples/20160402RAND0.xml', 'samples/20160409RAND0.xml', 'samples/20160416RAND0.xml'] Empty DataFrame Columns: [] Index: [] (pyquery)sayth at sayth-E6410:~/Projects/pyquery$ Thanks Sayth From rosuav at gmail.com Tue Apr 19 10:24:30 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Apr 2016 00:24:30 +1000 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> Message-ID: On Wed, Apr 20, 2016 at 12:15 AM, Grant Edwards wrote: >> And more generally that programmers sticking to text when rest of >> world has moved on is rather backward: >> http://blog.languager.org/2012/10/html-is-why-mess-in-programming-syntax.html > > The same reason humans use written and spoken language rather than > just drawing pictures, pointing, and grunting? http://catb.org/esr/writings/unix-koans/gui-programmer.html ChrisA From liran.maymoni at gmail.com Tue Apr 19 10:31:04 2016 From: liran.maymoni at gmail.com (liran.maymoni at gmail.com) Date: Tue, 19 Apr 2016 07:31:04 -0700 (PDT) Subject: Problem with textblob lib In-Reply-To: References: Message-ID: <57f1a079-2549-44c1-91c5-5865c99338cc@googlegroups.com> On Tuesday, April 19, 2016 at 5:08:58 PM UTC+3, Peter Otten wrote: > liran.maymoni at gmail.com wrote: > > > Hey, > > Using windows 10 > > I've install textblob using "py -m pip install textblob". > > I can import textblob, or from textblob import blob,word > > But i cant: from textblobl import Textblob. > > The error i get is: > > Traceback (most recent call last): > > File "", line 1, in > > from textblob import Textblob > > ImportError: cannot import name 'Textblob' > > > > Thanks. > > Try > > from textblob import TextBlob > > Python is case-sensitive. OMG!!!! thank you From alice at gothcandy.com Tue Apr 19 10:45:10 2016 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Tue, 19 Apr 2016 10:45:10 -0400 Subject: Guido sees the light: PEP 8 updated References: Message-ID: On 2016-04-18 21:14:02 +0000, Pete Forman said: > Why is it that Python continues to use a fixed width font and therefore > specifies the maximum line width as a character count? > > An essential part of the language is indentation which ought to continue > to mandate that lines start with a multiple of 4 em worth of space (or > some other size or encode with hard tabs, that is not germane to my > question). The content of the line need not be bound by the rules needed > to position its start. I wrote a semi-serious, somewhat tongue-in-cheek article entitled "Your code style guide is crap, but still better than nothing." a number of years ago, and reposted it towards the end of last year. It would seem to apply here, as the fundamental disconnect isn't just "use of N space characters", but "use of space characters at all". >From the article: > Do you use spaces in a word processor to line up bullet points? If you > do you?ll be first against the wall when the revolution comes! http://s.webcore.io/2K0W0m2T2e2f It also touches on points raised by others, such as Elastic Tabstops. ? Alice. From rustompmody at gmail.com Tue Apr 19 10:54:17 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 19 Apr 2016 07:54:17 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> Message-ID: On Tuesday, April 19, 2016 at 7:46:21 PM UTC+5:30, Grant Edwards wrote: > On 2016-04-19, Pete Forman wrote: > > > My question asks why monospace is used for the text. > > Well, I always use a monospaced font for code because I find it helps > readability for things like tables of data, block comments, and lines > of code that have some sort of parallel structure that I want to be > obvious to the reader. > > > And more generally that programmers sticking to text when rest of > > world has moved on is rather backward: > > http://blog.languager.org/2012/10/html-is-why-mess-in-programming-syntax.html > > The same reason humans use written and spoken language rather than > just drawing pictures, pointing, and grunting? I wonder who the joke is on: | A study comparing Canadian and Chinese students found that the latter were | better at complex maths | Native English speakers rely more on additional brain regions involved in the | meaning of words, whereas native Chinese speakers rely more on additional | brain regions involved in the visual appearance and physical manipulation of | numbers, from : https://www.newscientist.com/article/dn9422-mother-tongue-may-determine-maths-skills/ From steve at pearwood.info Tue Apr 19 11:50:00 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 20 Apr 2016 01:50:00 +1000 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> Message-ID: <571653aa$0$1606$c3e8da3$5496439d@news.astraweb.com> On Wed, 20 Apr 2016 12:54 am, Rustom Mody wrote: > I wonder who the joke is on: > > | A study comparing Canadian and Chinese students found that the latter > | were better at complex maths Most published studies are wrong. http://www.ncbi.nlm.nih.gov/pmc/articles/PMC1182327/ - Has that study been replicated by others? Have people tried to replicate it? Were negative findings published, or do they languish in some researcher's bottom drawer? (Publication bias is a big problem in research.) - Was the study well-designed, and the given conclusions supported by the study? How well did it survive the critical attention of experts in that field? Did the study account for differences in mathematics education? - Did the study have sufficient statistical power to support the claimed results? Most published studies are invalid since they simply lack the power to justify their conclusion. - Is the effect due to chance? Remember, with a p-value of 0.05 (the so-called 95% significance level), one in twenty experiments will give a positive result just by chance. A p-value of 0.05 does not mean "these results are proven", it just means "if every single thing about this experiment is perfect, then the chances that these results are due by chance alone is 1 in 20". Anyone who has played (say) Dungeons and Dragons, or other role-playing games, will know that events with a probability of 1 in 20 occur very frequently. To be precise, they occur one time in twenty. Even if the claimed results are correct, how strong is the effect? (a) On average, Canadian students get 49.0% on a standard exam that Chinese students get 89.0% for. (b) On average, Canadian students get 49.0% on a standard exam that Chinese students get 49.1% for. The level of statistical significance is not related to the strength of the effect: we can be very confident of small effects, and weakly confident of large effects. -- Steven From liran.maymoni at gmail.com Tue Apr 19 11:51:56 2016 From: liran.maymoni at gmail.com (liran.maymoni at gmail.com) Date: Tue, 19 Apr 2016 08:51:56 -0700 (PDT) Subject: Failed install scipy lib Message-ID: <08215756-d9f5-4dba-b710-ab8626ebfe27@googlegroups.com> Hello, i'm trying to use: "py -m pip install scipy" and after couple of lines a get an error saying: Command "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Liran\\AppData\\Local\\Temp\\pip-build-er8bfsou\\scipy\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Liran\AppData\Local\Temp\pip-4505t4eq-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Liran\AppData\Local\Temp\pip-build-er8bfsou\scipy What is the problem? From liran.maymoni at gmail.com Tue Apr 19 11:55:30 2016 From: liran.maymoni at gmail.com (liran.maymoni at gmail.com) Date: Tue, 19 Apr 2016 08:55:30 -0700 (PDT) Subject: Failed install scipy lib In-Reply-To: <08215756-d9f5-4dba-b710-ab8626ebfe27@googlegroups.com> References: <08215756-d9f5-4dba-b710-ab8626ebfe27@googlegroups.com> Message-ID: <5e7723b3-8685-444f-874c-14d7783cf9cc@googlegroups.com> This is the full Log: C:\Users\Liran>py -m pip install scipy Collecting scipy Using cached scipy-0.17.0.tar.gz Installing collected packages: scipy Running setup.py install for scipy ... error Complete output from command C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Liran\\AppData\\Local\\Temp\\pip-build-47xsb0ek\\scipy\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Liran\AppData\Local\Temp\pip-ybdtaj2y-record\install-record.txt --single-version-externally-managed --compile: lapack_opt_info: openblas_lapack_info: libraries openblas not found in ['C:\\Users\\Liran\\AppData\\Local\\Programs\\Python\\Python35-32\\lib', 'C:\\', 'C:\\Users\\Liran\\AppData\\Local\\Programs\\Python\\Python35-32\\libs'] NOT AVAILABLE lapack_mkl_info: mkl_info: libraries mkl,vml,guide not found in ['C:\\Users\\Liran\\AppData\\Local\\Programs\\Python\\Python35-32\\lib', 'C:\\', 'C:\\Users\\Liran\\AppData\\Local\\Programs\\Python\\Python35-32\\libs'] NOT AVAILABLE NOT AVAILABLE atlas_3_10_threads_info: Setting PTATLAS=ATLAS C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\distutils\system_info.py:633: UserWarning: Specified path C:\projects\windows-wheel-builder\atlas-builds\atlas-3.10.1-sse2-32\lib is invalid. warnings.warn('Specified path %s is invalid.' % d) NOT AVAILABLE atlas_3_10_info: NOT AVAILABLE atlas_threads_info: Setting PTATLAS=ATLAS NOT AVAILABLE atlas_info: NOT AVAILABLE C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\distutils\system_info.py:1542: UserWarning: Atlas (http://math-atlas.sourceforge.net/) libraries not found. Directories to search for the libraries can be specified in the numpy/distutils/site.cfg file (section [atlas]) or by setting the ATLAS environment variable. warnings.warn(AtlasNotFoundError.__doc__) lapack_info: libraries lapack not found in ['C:\\Users\\Liran\\AppData\\Local\\Programs\\Python\\Python35-32\\lib', 'C:\\', 'C:\\Users\\Liran\\AppData\\Local\\Programs\\Python\\Python35-32\\libs'] NOT AVAILABLE C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\distutils\system_info.py:1553: UserWarning: Lapack (http://www.netlib.org/lapack/) libraries not found. Directories to search for the libraries can be specified in the numpy/distutils/site.cfg file (section [lapack]) or by setting the LAPACK environment variable. warnings.warn(LapackNotFoundError.__doc__) lapack_src_info: NOT AVAILABLE C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\distutils\system_info.py:1556: UserWarning: Lapack (http://www.netlib.org/lapack/) sources not found. Directories to search for the sources can be specified in the numpy/distutils/site.cfg file (section [lapack_src]) or by setting the LAPACK_SRC environment variable. warnings.warn(LapackSrcNotFoundError.__doc__) NOT AVAILABLE Running from scipy source directory. Traceback (most recent call last): File "", line 1, in File "C:\Users\Liran\AppData\Local\Temp\pip-build-47xsb0ek\scipy\setup.py", line 265, in setup_package() File "C:\Users\Liran\AppData\Local\Temp\pip-build-47xsb0ek\scipy\setup.py", line 262, in setup_package setup(**metadata) File "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\distutils\core.py", line 135, in setup config = configuration() File "C:\Users\Liran\AppData\Local\Temp\pip-build-47xsb0ek\scipy\setup.py", line 182, in configuration config.add_subpackage('scipy') File "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\distutils\misc_util.py", line 1003, in add_subpackage caller_level = 2) File "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\distutils\misc_util.py", line 972, in get_subpackage caller_level = caller_level + 1) File "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\distutils\misc_util.py", line 909, in _get_configuration_from_setup_py config = setup_module.configuration(*args) File "scipy\setup.py", line 15, in configuration config.add_subpackage('linalg') File "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\distutils\misc_util.py", line 1003, in add_subpackage caller_level = 2) File "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\distutils\misc_util.py", line 972, in get_subpackage caller_level = caller_level + 1) File "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\numpy\distutils\misc_util.py", line 909, in _get_configuration_from_setup_py config = setup_module.configuration(*args) File "scipy\linalg\setup.py", line 20, in configuration raise NotFoundError('no lapack/blas resources found') numpy.distutils.system_info.NotFoundError: no lapack/blas resources found ---------------------------------------- Command "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Liran\\AppData\\Local\\Temp\\pip-build-47xsb0ek\\scipy\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Liran\AppData\Local\Temp\pip-ybdtaj2y-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Liran\AppData\Local\Temp\pip-build-47xsb0ek\scipy\ From steve at pearwood.info Tue Apr 19 11:58:42 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 20 Apr 2016 01:58:42 +1000 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <571653aa$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <571655b4$0$1599$c3e8da3$5496439d@news.astraweb.com> On Wed, 20 Apr 2016 01:50 am, Steven D'Aprano wrote: > - Is the effect due to chance? Remember, with a p-value of 0.05 (the > so-called 95% significance level), one in twenty experiments will > give a positive result just by chance. A p-value of 0.05 does not > mean "these results are proven", it just means "if every single > thing about this experiment is perfect, then the chances that these > results are due by chance alone is 1 in 20". Arggh! The above is, of course, *wrong*. This is why statistical significance is so hard. I know the correct interpretation[1] of p-values and I still got it wrong. p-values give the probability of a positive result by chance if the null hypothesis is true, that is, the chances of getting a false positive result. "We detected a difference that actually isn't there." It *doesn't* tell you anything about a false negative result: "We failed to detect a difference which actually is there." And it certainly doesn't tell you the chances that the result are true. More here: https://www.sciencenews.org/article/odds-are-its-wrong [1] At least, I'm confident I understand p-values with a 95% significance level. -- Steven From steve at pearwood.info Tue Apr 19 12:05:54 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 20 Apr 2016 02:05:54 +1000 Subject: Moderation and slight change of (de facto) policy References: <5713C08F.3010207@timgolden.me.uk> <5713E8EA.1080801@timgolden.me.uk> <5715F785.4010005@timgolden.me.uk> Message-ID: <57165764$0$1605$c3e8da3$5496439d@news.astraweb.com> On Tue, 19 Apr 2016 08:43 pm, Jon Ribbens wrote: > Are you saying that Usenet posts skip the moderation entirely? > > This whole thing seems a bit of a mess. What you really need to be > doing is changing the Usenet group to be moderated, otherwise you're > going to end up with two different views supposedly of the same thing > which in fact may be completely different. It's worse than that. There are many other places that mirror this group, such as gmane, Activestate, bytes.com, gossamer-threads.com, and of course Google Groups. They all have their own moderation and filtering policies, which may differ from those of the others. Some of them may do only mirroring, while others (including GG and gmane) may allow posting. And yet, we manage to muddle on. If the plethora of mirrors with inconsistent views is the worst that happens to us, I for one will be amazingly happy. -- Steven From steve at pearwood.info Tue Apr 19 12:14:18 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 20 Apr 2016 02:14:18 +1000 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> Message-ID: <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> On Tue, 19 Apr 2016 01:04 pm, Rustom Mody wrote: > And more generally that programmers sticking to text when rest of world > has moved on is rather backward: I'm pretty sure that the rest of the world has not moved on from text. Text still makes up by far the bulk of human communication. It's compact (one second of a Youtube video requires about the same bandwidth as about 7000 words), it can be easily searched, edited, translated, the presentation can be changed to suit the reader, and more. When precision of meaning is important, text is still the winner except in a few specialist areas, such as technical drawings, and even they still make extensive use of text. -- Steven From info at egenix.com Tue Apr 19 12:15:03 2016 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 19 Apr 2016 18:15:03 +0200 Subject: =?UTF-8?Q?ANN:_Python_Meeting_D=c3=bcsseldorf_-_27.04.2016?= Message-ID: <57165987.4000903@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. Dienstag, 27.04.2016, 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-2016-04-27 ________________________________________________________________________ NEUIGKEITEN * Bereits angemeldete Vortr?ge: Matthias Endler "Protector - a Circuit Breaker for Time-Series Databases" Dr. Klaus Bremer "django-autotask" Jens Diemer "PyHardLinkBackup" Tom Engemann "Eine kurze Einf?hrung in Kivy" Johannes Spielmann "Symmetrische Verschl?sselung f?r alle!" 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 Open Space und Lightning Talks, wobei die Gewitter bei uns auch schon mal 20 Minuten dauern k?nnen ;-). Lightning Talks 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 19 2016) >>> 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 steve at pearwood.info Tue Apr 19 12:15:52 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 20 Apr 2016 02:15:52 +1000 Subject: Moderation and slight change of (de facto) policy References: <5713C08F.3010207@timgolden.me.uk> <57140947.3050902@gmail.com> <1460939260.3483225.581520729.146827C9@webmail.messagingengine.com> <57143f8b$0$1612$c3e8da3$5496439d@news.astraweb.com> <87r3e34h48.fsf@elektro.pacujo.net> Message-ID: <571659b9$0$1585$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Apr 2016 03:32 pm, Marko Rauhamaa wrote: > Steven D'Aprano : > >> On Mon, 18 Apr 2016 10:27 am, Random832 wrote: >> >>> As an alternative, when you send them through can you put a note on >>> the bottom saying they're not subscribed, to remind people to CC them >>> in responses? >> >> That doesn't work so well from Usenet. I can reply via news (which >> definitely works), or I can reply via email (which may or may not >> work), but it is a pain to reply via *both*. > > I don't like the Usenet+CC approach, but let's try it. > > Did you get the CC, Steven. Yes I did. I frequently have people CCing me. But that's not the problem for me -- as I said above, it's a pain for me to SEND (not receive) via both email and news. -- Steven From rustompmody at gmail.com Tue Apr 19 12:46:09 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 19 Apr 2016 09:46:09 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> On Tuesday, April 19, 2016 at 9:44:39 PM UTC+5:30, Steven D'Aprano wrote: > On Tue, 19 Apr 2016 01:04 pm, Rustom Mody wrote: > > > And more generally that programmers sticking to text when rest of world > > has moved on is rather backward: > > I'm pretty sure that the rest of the world has not moved on from text. Run your popular search engine on "popular linux apps" or some such and you will get for example: inkscape gimp blender libreoffice writer/calc/prese wireshark skype firefox audacity musescore totem vlc dia Do these look like text-based apps to you? > Text > still makes up by far the bulk of human communication. It's compact (one > second of a Youtube video requires about the same bandwidth as about 7000 > words), it can be easily searched, edited, translated, the presentation can > be changed to suit the reader, and more. Yes so you just showed that in the realm of multimedia we are somewhere nearabouts... tickertape? Hollerith cards? Doesn't change the basic structure of the human being viz that 5 senses working in harmony make us more productive than one overworking rest languishing > When precision of meaning is > important, text is still the winner except in a few specialist areas, such > as technical drawings, and even they still make extensive use of text. Yes in the short to medium run our text capability remains better than others. Those who want to keep it so forever are keeping the rest of us back.... fortunately futilely! From oscar.j.benjamin at gmail.com Tue Apr 19 13:05:48 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 19 Apr 2016 18:05:48 +0100 Subject: Failed install scipy lib In-Reply-To: <08215756-d9f5-4dba-b710-ab8626ebfe27@googlegroups.com> References: <08215756-d9f5-4dba-b710-ab8626ebfe27@googlegroups.com> Message-ID: On 19 Apr 2016 17:01, wrote: > > Hello, > i'm trying to use: > "py -m pip install scipy" > and after couple of lines a get an error saying: I thought that binary wheels for scipy would be available on pypi for each OS now. Try updating pip and then using it to install scipy. I'm not on Windows to check myself though I'm afraid. -- Oscar From larry.martell at gmail.com Tue Apr 19 13:06:29 2016 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 19 Apr 2016 13:06:29 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <571653aa$0$1606$c3e8da3$5496439d@news.astraweb.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <571653aa$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 19, 2016 at 11:50 AM, Steven D'Aprano wrote: > On Wed, 20 Apr 2016 12:54 am, Rustom Mody wrote: > > >> I wonder who the joke is on: >> >> | A study comparing Canadian and Chinese students found that the latter >> | were better at complex maths > > Most published studies are wrong. > > http://www.ncbi.nlm.nih.gov/pmc/articles/PMC1182327/ > > - Has that study been replicated by others? Have people tried to > replicate it? Were negative findings published, or do they > languish in some researcher's bottom drawer? (Publication bias > is a big problem in research.) > > - Was the study well-designed, and the given conclusions supported > by the study? How well did it survive the critical attention of > experts in that field? Did the study account for differences in > mathematics education? > > - Did the study have sufficient statistical power to support the > claimed results? Most published studies are invalid since they > simply lack the power to justify their conclusion. > > - Is the effect due to chance? Remember, with a p-value of 0.05 (the > so-called 95% significance level), one in twenty experiments will > give a positive result just by chance. A p-value of 0.05 does not > mean "these results are proven", it just means "if every single > thing about this experiment is perfect, then the chances that these > results are due by chance alone is 1 in 20". > > Anyone who has played (say) Dungeons and Dragons, or other role-playing > games, will know that events with a probability of 1 in 20 occur very > frequently. To be precise, they occur one time in twenty. > > Even if the claimed results are correct, how strong is the effect? > > (a) On average, Canadian students get 49.0% on a standard exam that Chinese > students get 89.0% for. > > (b) On average, Canadian students get 49.0% on a standard exam that Chinese > students get 49.1% for. > > The level of statistical significance is not related to the strength of the > effect: we can be very confident of small effects, and weakly confident of > large effects. 85% of all statistics are made up. From alister.ware at ntlworld.com Tue Apr 19 13:13:20 2016 From: alister.ware at ntlworld.com (alister) Date: Tue, 19 Apr 2016 17:13:20 GMT Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <571653aa$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 20 Apr 2016 01:50:00 +1000, Steven D'Aprano wrote: > Anyone who has played (say) Dungeons and Dragons, or other role-playing > games, will know that events with a probability of 1 in 20 occur very > frequently. To be precise, they occur one time in twenty. > Million to 1 chances happen 9 time out of Ten (T prachett - Varius Discworld books :-) ) > Even if the claimed results are correct, how strong is the effect? > > (a) On average, Canadian students get 49.0% on a standard exam that > Chinese students get 89.0% for. > > (b) On average, Canadian students get 49.0% on a standard exam that > Chinese students get 49.1% for. > > The level of statistical significance is not related to the strength of > the effect: we can be very confident of small effects, and weakly > confident of large effects. -- If anyone has seen my dog, please contact me at x2883 as soon as possible. We're offering a substantial reward. He's a sable collie, with three legs, blind in his left eye, is missing part of his right ear and the tip of his tail. He's been recently fixed. Answers to "Lucky". From random832 at fastmail.com Tue Apr 19 13:30:56 2016 From: random832 at fastmail.com (Random832) Date: Tue, 19 Apr 2016 13:30:56 -0400 Subject: Moderation and slight change of (de facto) policy In-Reply-To: <57165764$0$1605$c3e8da3$5496439d@news.astraweb.com> References: <5713C08F.3010207@timgolden.me.uk> <5713E8EA.1080801@timgolden.me.uk> <5715F785.4010005@timgolden.me.uk> <57165764$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1461087056.2618107.583507065.17E27E1D@webmail.messagingengine.com> On Tue, Apr 19, 2016, at 12:05, Steven D'Aprano wrote: > It's worse than that. There are many other places that mirror this group, > such as gmane, Activestate, bytes.com, gossamer-threads.com, and of > course > Google Groups. Google groups goes through Usenet, and would be affected equally by any solution to the usenet issue. Gmane passes posts through normal email submission. It'd be mildly irritating to have to be subscribed to be able to post through gmane, but it wouldn't be the first group to have that requirement. Gossamer threads and Activestate both appear to use the mailing list archives and not allow posting. Bytes.com appears to mirror *stack overflow*, not this list, unless I'm missing something. From python.list at tim.thechases.com Tue Apr 19 13:43:21 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 19 Apr 2016 12:43:21 -0500 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> Message-ID: <20160419124321.361751dc@bigbox.christie.dr> On 2016-04-19 09:46, Rustom Mody wrote: > inkscape > gimp > blender > libreoffice writer/calc/prese > wireshark > skype > firefox > audacity > musescore > totem > vlc > dia > > Do these look like text-based apps to you? Well, let's take a look at their native file formats: Inkscape: SVG Libreoffice: compressed XML Firefox: HTML+CSS+JS Musescore: compressed text Dia: compressed XML While I haven't used Musescore, I have used the others and hand-edited the files in each case. Using vi/vim, or even ed(1). Because I can, and sometimes because I have to in order to do some convoluted process that would be a pain to do in a GUI. For Gimp, Blender, Audacity, Totem, and VLC, those all deal with binary streams of their content-type. Skype being proprietary, it doesn't interoperate with bupkis. So wireshark is the only outlier in my mind, though since it captures binary packets, I suspect the native format is optimized for streaming stuff from the NIC to the disk as fast as possible (though given CPU and disk speeds, I would have figured that a gzipped stream of text markup would be almost as good). -tkc From jon+usenet at unequivocal.co.uk Tue Apr 19 13:55:33 2016 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Tue, 19 Apr 2016 17:55:33 -0000 (UTC) Subject: Moderation and slight change of (de facto) policy References: <5713C08F.3010207@timgolden.me.uk> <5713E8EA.1080801@timgolden.me.uk> <5715F785.4010005@timgolden.me.uk> <57165764$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-04-19, Steven D'Aprano wrote: > On Tue, 19 Apr 2016 08:43 pm, Jon Ribbens wrote: >> Are you saying that Usenet posts skip the moderation entirely? >> >> This whole thing seems a bit of a mess. What you really need to be >> doing is changing the Usenet group to be moderated, otherwise you're >> going to end up with two different views supposedly of the same thing >> which in fact may be completely different. > > It's worse than that. There are many other places that mirror this group, > such as gmane, Activestate, bytes.com, gossamer-threads.com, and of course > Google Groups. They all have their own moderation and filtering policies, > which may differ from those of the others. Some of them may do only > mirroring, while others (including GG and gmane) may allow posting. > > And yet, we manage to muddle on. We've muddled on so far, but apparently we're just about to have a significant change in moderation policy which sounds like it may very well add to the confusion. > If the plethora of mirrors with inconsistent views is the worst that > happens to us, I for one will be amazingly happy. Well indeed, the main reason I posted at all was because it sounded like the new policy hadn't thought about Usenet at all and was about to block Usenet posts completely. If that's not true then I'm more or less happy ;-) From marko at pacujo.net Tue Apr 19 14:00:27 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 19 Apr 2016 21:00:27 +0300 Subject: Moderation and slight change of (de facto) policy References: <5713C08F.3010207@timgolden.me.uk> <57140947.3050902@gmail.com> <1460939260.3483225.581520729.146827C9@webmail.messagingengine.com> <57143f8b$0$1612$c3e8da3$5496439d@news.astraweb.com> <87r3e34h48.fsf@elektro.pacujo.net> <571659b9$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: <877fft4gxw.fsf@elektro.pacujo.net> Steven D'Aprano : > On Mon, 18 Apr 2016 03:32 pm, Marko Rauhamaa wrote: >> Did you get the CC, Steven. > > Yes I did. I frequently have people CCing me. But that's not the > problem for me -- as I said above, it's a pain for me to SEND (not > receive) via both email and news. GNUS does both at once (if requested). Marko From rustompmody at gmail.com Tue Apr 19 14:05:39 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 19 Apr 2016 11:05:39 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <20160419124321.361751dc@bigbox.christie.dr> Message-ID: <0a63660e-e1b7-4478-92db-6a3d7cea5b07@googlegroups.com> On Tuesday, April 19, 2016 at 11:17:23 PM UTC+5:30, Tim Chase wrote: > On 2016-04-19 09:46, Rustom Mody wrote: > > inkscape > > gimp > > blender > > libreoffice writer/calc/prese > > wireshark > > skype > > firefox > > audacity > > musescore > > totem > > vlc > > dia > > > > Do these look like text-based apps to you? > > Well, let's take a look at their native file formats: > > Inkscape: SVG > > Libreoffice: compressed XML > > Firefox: HTML+CSS+JS > > Musescore: compressed text > > Dia: compressed XML > > While I haven't used Musescore, I have used the others and > hand-edited the files in each case. Using vi/vim, or even ed(1). > Because I can, and sometimes because I have to in order to do some > convoluted process that would be a pain to do in a GUI. If you think xml/html is ok as replacement for text then we have no significant disagreement. That is after all the main point of http://blog.languager.org/2012/10/html-is-why-mess-in-programming-syntax.html viz that program texts would be better off replacing text with hypertext. [that html = Hyper Text Markup Language adds to the snark; but does not change the message] The key difference between all the above and state of art in programming languages is that lexing, parsing is in principle and possibly in practice 'outsourced' to generic XML tools. With programming languages these are in silos in the innards of the language implementation. And so people typically studying compilers etc come to think of lexing and parsing as important/key activities.... except for a few outliers like Marvin Minsky: http://web.media.mit.edu/~minsky/papers/TuringLecture/TuringLecture.html From liran.maymoni at gmail.com Tue Apr 19 14:18:23 2016 From: liran.maymoni at gmail.com (liran.maymoni at gmail.com) Date: Tue, 19 Apr 2016 11:18:23 -0700 (PDT) Subject: Failed install scipy lib In-Reply-To: References: <08215756-d9f5-4dba-b710-ab8626ebfe27@googlegroups.com> Message-ID: <188eba37-bf96-4d58-923f-96717d51325b@googlegroups.com> On Tuesday, April 19, 2016 at 8:06:06 PM UTC+3, Oscar Benjamin wrote: > On 19 Apr 2016 17:01, wrote: > > > > Hello, > > i'm trying to use: > > "py -m pip install scipy" > > and after couple of lines a get an error saying: > > I thought that binary wheels for scipy would be available on pypi for each > OS now. Try updating pip and then using it to install scipy. > > I'm not on Windows to check myself though I'm afraid. > > -- > Oscar I tried. updated pip but still having the same problem From eryksun at gmail.com Tue Apr 19 14:20:31 2016 From: eryksun at gmail.com (eryk sun) Date: Tue, 19 Apr 2016 13:20:31 -0500 Subject: Failed install scipy lib In-Reply-To: References: <08215756-d9f5-4dba-b710-ab8626ebfe27@googlegroups.com> Message-ID: On Tue, Apr 19, 2016 at 12:05 PM, Oscar Benjamin wrote: > On 19 Apr 2016 17:01, wrote: >> >> i'm trying to use: >> "py -m pip install scipy" >> and after couple of lines a get an error saying: > > I thought that binary wheels for scipy would be available on pypi for each > OS now. Try updating pip and then using it to install scipy. PyPI only has Windows wheels for NumPy, not SciPy. You can use Christoph Gohlke's unofficial packages: http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy From random832 at fastmail.com Tue Apr 19 14:54:50 2016 From: random832 at fastmail.com (Random832) Date: Tue, 19 Apr 2016 14:54:50 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <20160419124321.361751dc@bigbox.christie.dr> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <20160419124321.361751dc@bigbox.christie.dr> Message-ID: <1461092090.2638611.583593041.7C981FAD@webmail.messagingengine.com> On Tue, Apr 19, 2016, at 13:43, Tim Chase wrote: > Well, let's take a look at their native file formats: > > Inkscape: SVG > > Libreoffice: compressed XML > > Firefox: HTML+CSS+JS > > Musescore: compressed text > > Dia: compressed XML None of those are "text" in the sense being discussed here, which is "preferred method of viewing and editing is a text editor". You could, for example, design a programming language that uses XML markup to associate comments with specific positions in the code and the editor displays them in little callout boxes when you hover over them with the mouse. That's not done because of the notion that code has to be plain text. The fact that the resulting format would still be a text format that could theoretically be edited with a text editor isn't relevant to this discussion. From random832 at fastmail.com Tue Apr 19 14:58:06 2016 From: random832 at fastmail.com (Random832) Date: Tue, 19 Apr 2016 14:58:06 -0400 Subject: Moderation and slight change of (de facto) policy In-Reply-To: References: <5713C08F.3010207@timgolden.me.uk> <5713E8EA.1080801@timgolden.me.uk> <5715F785.4010005@timgolden.me.uk> <57165764$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1461092286.2639434.583597513.7C7B98F4@webmail.messagingengine.com> On Tue, Apr 19, 2016, at 13:55, Jon Ribbens wrote: > On 2016-04-19, Steven D'Aprano wrote: > > It's worse than that. There are many other places that mirror this group, > > such as gmane, Activestate, bytes.com, gossamer-threads.com, and of course > > Google Groups. They all have their own moderation and filtering policies, > > which may differ from those of the others. Some of them may do only > > mirroring, while others (including GG and gmane) may allow posting. > > > > And yet, we manage to muddle on. > > We've muddled on so far, but apparently we're just about to have > a significant change in moderation policy which sounds like it may > very well add to the confusion. It does look like some attention may need to be given to gmane (either to allow posts to continue to be submitted, or to notify gmane that the list should be put in "Non-public (posting through Gmane allowed for list members)" mode. From ethan at stoneleaf.us Tue Apr 19 15:01:35 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 19 Apr 2016 12:01:35 -0700 Subject: Moderation and slight change of (de facto) policy In-Reply-To: References: <5713C08F.3010207@timgolden.me.uk> <5713E8EA.1080801@timgolden.me.uk> <5715F785.4010005@timgolden.me.uk> <57165764$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5716808F.8080801@stoneleaf.us> On 04/19/2016 10:55 AM, Jon Ribbens wrote: > On 2016-04-19, Steven D'Aprano wrote: >> And yet, we manage to muddle on. > > We've muddled on so far, but apparently we're just about to have > a significant change in moderation policy which sounds like it may > very well add to the confusion. The only thing changing is what happens if someone posts /directly/ to the mailing list (not through gmane, etc). And the change is: Instead of passing the message through, with the risk that the poster will never see the responses), we are instead rejecting the post with a short explanation of how to either sign-up to the list, or use a mirror, etc, to interact with the list/newsgroup/mirror/whatever. > If that's not true then I'm more or less happy ;-) Excellent. -- ~Ethan~ From random832 at fastmail.com Tue Apr 19 15:05:18 2016 From: random832 at fastmail.com (Random832) Date: Tue, 19 Apr 2016 15:05:18 -0400 Subject: Moderation and slight change of (de facto) policy In-Reply-To: <5716808F.8080801@stoneleaf.us> References: <5713C08F.3010207@timgolden.me.uk> <5713E8EA.1080801@timgolden.me.uk> <5715F785.4010005@timgolden.me.uk> <57165764$0$1605$c3e8da3$5496439d@news.astraweb.com> <5716808F.8080801@stoneleaf.us> Message-ID: <1461092718.2640693.583607497.6B3E1B28@webmail.messagingengine.com> On Tue, Apr 19, 2016, at 15:01, Ethan Furman wrote: > The only thing changing is what happens if someone posts /directly/ to > the mailing list (not through gmane, etc). Is the mailing list software able to make that distinction? I thought that was on gmane's end. From amfarrell at mit.edu Tue Apr 19 15:10:52 2016 From: amfarrell at mit.edu (Andrew Farrell) Date: Tue, 19 Apr 2016 14:10:52 -0500 Subject: Failed install scipy lib In-Reply-To: <188eba37-bf96-4d58-923f-96717d51325b@googlegroups.com> References: <08215756-d9f5-4dba-b710-ab8626ebfe27@googlegroups.com> <188eba37-bf96-4d58-923f-96717d51325b@googlegroups.com> Message-ID: Hi Liran, If your goal is simply to install SciPy on windows and not have to worry about python packaging, your best bet is to go ahead and install Anaconda , which comes with SciPy and a bunch of other libraries for scientific computing. If you don't want all the other libraries and only want scipy, you can also install miniconda and then run conda install scipy You can also create an isolated environment with conda create --name scipy35 python=3.5 scipy activate scipy35 All the best, Andrew On Tue, Apr 19, 2016 at 1:18 PM, wrote: > On Tuesday, April 19, 2016 at 8:06:06 PM UTC+3, Oscar Benjamin wrote: > > On 19 Apr 2016 17:01, wrote: > > > > > > Hello, > > > i'm trying to use: > > > "py -m pip install scipy" > > > and after couple of lines a get an error saying: > > > > I thought that binary wheels for scipy would be available on pypi for > each > > OS now. Try updating pip and then using it to install scipy. > > > > I'm not on Windows to check myself though I'm afraid. > > > > -- > > Oscar > > I tried. > updated pip but still having the same problem > -- > https://mail.python.org/mailman/listinfo/python-list > From mail at timgolden.me.uk Tue Apr 19 15:17:21 2016 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 19 Apr 2016 20:17:21 +0100 Subject: Moderation and slight change of (de facto) policy In-Reply-To: <1461087056.2618107.583507065.17E27E1D@webmail.messagingengine.com> References: <5713C08F.3010207@timgolden.me.uk> <5713E8EA.1080801@timgolden.me.uk> <5715F785.4010005@timgolden.me.uk> <57165764$0$1605$c3e8da3$5496439d@news.astraweb.com> <1461087056.2618107.583507065.17E27E1D@webmail.messagingengine.com> Message-ID: <57168441.2030709@timgolden.me.uk> On 19/04/2016 18:30, Random832 wrote: > > > On Tue, Apr 19, 2016, at 12:05, Steven D'Aprano wrote: >> It's worse than that. There are many other places that mirror this group, >> such as gmane, Activestate, bytes.com, gossamer-threads.com, and of >> course >> Google Groups. > > Google groups goes through Usenet, and would be affected equally by any > solution to the usenet issue. > > Gmane passes posts through normal email submission. It'd be mildly > irritating to have to be subscribed to be able to post through gmane, > but it wouldn't be the first group to have that requirement. > > Gossamer threads and Activestate both appear to use the mailing list > archives and not allow posting. > > Bytes.com appears to mirror *stack overflow*, not this list, unless I'm > missing something. Just to be clear: GMane does some kind of header-munging to post on its users' behalf; GGroups comes in through usenet. Very little is actually going to change. Really. (I'm almost sorry now I gave the explanation...). We're not disconnecting from Usenet, or GMane or anything else. TJG From ethan at stoneleaf.us Tue Apr 19 15:21:42 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 19 Apr 2016 12:21:42 -0700 Subject: Moderation and slight change of (de facto) policy In-Reply-To: <1461092718.2640693.583607497.6B3E1B28@webmail.messagingengine.com> References: <5713C08F.3010207@timgolden.me.uk> <5713E8EA.1080801@timgolden.me.uk> <5715F785.4010005@timgolden.me.uk> <57165764$0$1605$c3e8da3$5496439d@news.astraweb.com> <5716808F.8080801@stoneleaf.us> <1461092718.2640693.583607497.6B3E1B28@webmail.messagingengine.com> Message-ID: <57168546.8000809@stoneleaf.us> On 04/19/2016 12:05 PM, Random832 wrote: > On Tue, Apr 19, 2016, at 15:01, Ethan Furman wrote: >> The only thing changing is what happens if someone posts /directly/ to >> the mailing list (not through gmane, etc). > > Is the mailing list software able to make that distinction? I thought > that was on gmane's end. As far as I understand it, mirrors/usenet are either simply allowed through (with spam checks), or the service has it's own user account. -- ~Ethan~ From ben+python at benfinney.id.au Tue Apr 19 16:50:51 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 20 Apr 2016 06:50:51 +1000 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> Message-ID: <854maxqq50.fsf@benfinney.id.au> Rustom Mody writes: > On Tuesday, April 19, 2016 at 9:44:39 PM UTC+5:30, Steven D'Aprano wrote: > > On Tue, 19 Apr 2016 01:04 pm, Rustom Mody wrote: > > > > > And more generally that programmers sticking to text when rest of world > > > has moved on is rather backward: > > > > I'm pretty sure that the rest of the world has not moved on from text. > > Run your popular search engine on "popular linux apps" or some such and > you will get for example: That supports a claim of ?there are many programs available that primarily manipulate something other than text?. You didn't make that claim, so providing support for that is irrelevant. Your actual claim is that ?the rest of the world has moved on from text?. You haven't supported that claim at all, and I see endless text everyday in ?the rest of the world?. So your claim is false. -- \ ?I do not believe in immortality of the individual, and I | `\ consider ethics to be an exclusively human concern with no | _o__) superhuman authority behind it.? ?Albert Einstein, letter, 1953 | Ben Finney From rosuav at gmail.com Tue Apr 19 16:59:30 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Apr 2016 06:59:30 +1000 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <854maxqq50.fsf@benfinney.id.au> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <854maxqq50.fsf@benfinney.id.au> Message-ID: On Wed, Apr 20, 2016 at 6:50 AM, Ben Finney wrote: >> > On Tue, 19 Apr 2016 01:04 pm, Rustom Mody wrote: >> > > And more generally that programmers sticking to text when rest of world >> > > has moved on is rather backward: > > You haven't supported that claim at all, and I see endless text everyday > in ?the rest of the world?. So your claim is false. In this part of the world, I'm seeing a lot of emails/news posts that consist of text. How does the rest of the world discuss important topics? Is everything done with infographics and meme pics? ChrisA not that this is exactly an important topic, really... From marko at pacujo.net Tue Apr 19 17:35:05 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 20 Apr 2016 00:35:05 +0300 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <854maxqq50.fsf@benfinney.id.au> Message-ID: <87potl2sfq.fsf@elektro.pacujo.net> Chris Angelico : > On Wed, Apr 20, 2016 at 6:50 AM, Ben Finney > wrote: >>> > On Tue, 19 Apr 2016 01:04 pm, Rustom Mody wrote: >>> > > And more generally that programmers sticking to text when rest >>> > > of world has moved on is rather backward: >> >> You haven't supported that claim at all, and I see endless text everyday >> in ?the rest of the world?. So your claim is false. > > In this part of the world, I'm seeing a lot of emails/news posts that > consist of text. How does the rest of the world discuss important > topics? Is everything done with infographics and meme pics? The "plain text" content type is used less and less. Really it is reserved mostly to programmers. Even texters routinely field animated emojies nowadays. Text, in general, might have started to decline. I'm foreseeing a not-too-distant future where only a smallish group of trained scribes masters reading and writing. The remainder of the population will consume and interact with animated pictures, videos, music, games etc. Back to ancient Egypt. Just look at the US presidential primaries, where the political discourse seems to be centered on grunts, melees and simple slogans: ?We won the evangelicals,? Trump said. ?We won with young. We won with old. We won with highly educated. We won with poorly educated. I love the poorly educated.? My point is not political; I'm only talking about the communication media. The medieval populace regarded the Latin-spewing theologians with awe. Maybe one day, the same superstitious respect will be afforded to trained Python masters who can bend the machines to their will. Marko From sohcahtoa82 at gmail.com Tue Apr 19 17:43:01 2016 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Tue, 19 Apr 2016 14:43:01 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <854maxqq50.fsf@benfinney.id.au> Message-ID: <4a917863-6e92-4e30-912f-f4e4d3d31c20@googlegroups.com> On Tuesday, April 19, 2016 at 1:59:48 PM UTC-7, Chris Angelico wrote: > On Wed, Apr 20, 2016 at 6:50 AM, Ben Finney wrote: > >> > On Tue, 19 Apr 2016 01:04 pm, Rustom Mody wrote: > >> > > And more generally that programmers sticking to text when rest of world > >> > > has moved on is rather backward: > > > > You haven't supported that claim at all, and I see endless text everyday > > in "the rest of the world". So your claim is false. > > In this part of the world, I'm seeing a lot of emails/news posts that > consist of text. How does the rest of the world discuss important > topics? Is everything done with infographics and meme pics? > > ChrisA > not that this is exactly an important topic, really... Personally, I prefer smoke signals. Range is decent, but the bandwidth is atrocious. From Seymore4Head at Hotmail.invalid Tue Apr 19 18:29:38 2016 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 19 Apr 2016 18:29:38 -0400 Subject: Python path and append Message-ID: This doesn't work. Does Python recognize hidden directories? handle = open("\\Winmx\New$\q.txt") for line in handle: line=line.strip() print line Traceback (most recent call last): File "\\Winmx\New$\add viewed.py", line 2, in handle = open("\\Winmx\New$\q.txt") IOError: [Errno 2] No such file or directory: '\\Winmx\\New$\\q.txt' What I would like to do is read a plain text file from a hidden network drive and append a space and the * character to the end of each line. Would someone be so kind as to fill in the blanks to accomplish this please? From rosuav at gmail.com Tue Apr 19 18:38:50 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Apr 2016 08:38:50 +1000 Subject: Python path and append In-Reply-To: References: Message-ID: On Wed, Apr 20, 2016 at 8:29 AM, Seymore4Head wrote: > > handle = open("\\Winmx\New$\q.txt") > for line in handle: > line=line.strip() > print line > > > Traceback (most recent call last): > File "\\Winmx\New$\add viewed.py", line 2, in > handle = open("\\Winmx\New$\q.txt") > IOError: [Errno 2] No such file or directory: '\\Winmx\\New$\\q.txt' > > What I would like to do is read a plain text file from a hidden > network drive and append a space and the * character to the end of > each line. Start with this: print("\\Winmx\New$\q.txt") If that doesn't do what you expect, it's possibly because you want to use a raw string literal to prevent the backslashes from being parsed. handle = open(r"\\Winmx\New$\q.txt") That might help you. (One clue that this is happening is that some of your backslashes got doubled in the error message.) ChrisA From grant.b.edwards at gmail.com Tue Apr 19 19:21:24 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 19 Apr 2016 23:21:24 +0000 (UTC) Subject: Moderation and slight change of (de facto) policy References: <5713C08F.3010207@timgolden.me.uk> <5713E8EA.1080801@timgolden.me.uk> <5715F785.4010005@timgolden.me.uk> <57165764$0$1605$c3e8da3$5496439d@news.astraweb.com> <1461092286.2639434.583597513.7C7B98F4@webmail.messagingengine.com> Message-ID: On 2016-04-19, Random832 wrote: > It does look like some attention may need to be given to gmane > (either to allow posts to continue to be submitted, or to notify > gmane that the list should be put in "Non-public (posting through > Gmane allowed for list members)" mode. While there is such a mode, many lists that don't accepts posts from non-memebers never inform gmane of it. In my experience they usually just discard non-member posts and send an email to the poster saying that they only accept posts from membersk. When that happens, you join the list, turn off delivery, and then go back to gmane and post again. -- Grant From grant.b.edwards at gmail.com Tue Apr 19 19:22:44 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 19 Apr 2016 23:22:44 +0000 (UTC) Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <854maxqq50.fsf@benfinney.id.au> Message-ID: On 2016-04-19, Chris Angelico wrote: > On Wed, Apr 20, 2016 at 6:50 AM, Ben Finney wrote: >>> > On Tue, 19 Apr 2016 01:04 pm, Rustom Mody wrote: >>> > > And more generally that programmers sticking to text when rest of world >>> > > has moved on is rather backward: >> >> You haven't supported that claim at all, and I see endless text everyday >> in ???the rest of the world???. So your claim is false. > > In this part of the world, I'm seeing a lot of emails/news posts that > consist of text. How does the rest of the world discuss important > topics? Is everything done with infographics and meme pics? Emojis, one would assume. -- Grant From rosuav at gmail.com Tue Apr 19 19:33:54 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Apr 2016 09:33:54 +1000 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <854maxqq50.fsf@benfinney.id.au> Message-ID: On Wed, Apr 20, 2016 at 9:22 AM, Grant Edwards wrote: > On 2016-04-19, Chris Angelico wrote: >> On Wed, Apr 20, 2016 at 6:50 AM, Ben Finney wrote: >>>> > On Tue, 19 Apr 2016 01:04 pm, Rustom Mody wrote: >>>> > > And more generally that programmers sticking to text when rest of world >>>> > > has moved on is rather backward: >>> >>> You haven't supported that claim at all, and I see endless text everyday >>> in ???the rest of the world???. So your claim is false. >> >> In this part of the world, I'm seeing a lot of emails/news posts that >> consist of text. How does the rest of the world discuss important >> topics? Is everything done with infographics and meme pics? > > Emojis, one would assume. > What, like characters in the U+1F300-U+1F64F codepoint range? ChrisA From mrabarnett at mrabarnett.plus.com Tue Apr 19 19:36:52 2016 From: mrabarnett at mrabarnett.plus.com (Matthew Barnett) Date: Wed, 20 Apr 2016 00:36:52 +0100 Subject: Python path and append In-Reply-To: References: Message-ID: <5716C114.6000703@mrabarnett.plus.com> On 2016-04-19 23:38, Chris Angelico wrote: > On Wed, Apr 20, 2016 at 8:29 AM, Seymore4Head > wrote: >> >> handle = open("\\Winmx\New$\q.txt") >> for line in handle: >> line=line.strip() >> print line >> >> >> Traceback (most recent call last): >> File "\\Winmx\New$\add viewed.py", line 2, in >> handle = open("\\Winmx\New$\q.txt") >> IOError: [Errno 2] No such file or directory: '\\Winmx\\New$\\q.txt' >> >> What I would like to do is read a plain text file from a hidden >> network drive and append a space and the * character to the end of >> each line. > > Start with this: > > print("\\Winmx\New$\q.txt") > > If that doesn't do what you expect, it's possibly because you want to > use a raw string literal to prevent the backslashes from being parsed. > > handle = open(r"\\Winmx\New$\q.txt") > > That might help you. > > (One clue that this is happening is that some of your backslashes got > doubled in the error message.) > when printed out: >>> print "\\Winmx\New$\q.txt" \Winmx\New$\q.txt That's a file 2 directories down on the current drive. From python.list at tim.thechases.com Tue Apr 19 20:02:30 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 19 Apr 2016 19:02:30 -0500 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <1461092090.2638611.583593041.7C981FAD@webmail.messagingengine.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <20160419124321.361751dc@bigbox.christie.dr> <1461092090.2638611.583593041.7C981FAD@webmail.messagingengine.com> Message-ID: <20160419190230.4da81b2e@bigbox.christie.dr> On 2016-04-19 14:54, Random832 wrote: > On Tue, Apr 19, 2016, at 13:43, Tim Chase wrote: > > Well, let's take a look at their native file formats: > > Inkscape: SVG > > Libreoffice: compressed XML > > Firefox: HTML+CSS+JS > > Musescore: compressed text > > Dia: compressed XML > > None of those are "text" in the sense being discussed here, which is > "preferred method of viewing and editing is a text editor". Well, my preferred method of "viewing" python code is /usr/bin/python Authoring, editing, and consuming are all distinct actions. Yes, a lot of tools can use libpcap to interface with wireshark dumps, but if your tool doesn't talk pcap, you can dump to plain-text (as Dennis mentions doing...well, XML) which is the lingua franca of tool development. > You could, for example, design a programming language that uses XML > markup [shudders at remembering using a DSL "programming language" that was XML] -tkc From steve at pearwood.info Tue Apr 19 20:32:25 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 20 Apr 2016 10:32:25 +1000 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> Message-ID: <5716ce1b$0$1618$c3e8da3$5496439d@news.astraweb.com> On Wed, 20 Apr 2016 02:46 am, Rustom Mody wrote: > On Tuesday, April 19, 2016 at 9:44:39 PM UTC+5:30, Steven D'Aprano wrote: >> On Tue, 19 Apr 2016 01:04 pm, Rustom Mody wrote: >> >> > And more generally that programmers sticking to text when rest of world >> > has moved on is rather backward: >> >> I'm pretty sure that the rest of the world has not moved on from text. > > Run your popular search engine on "popular linux apps" or some such When you did that, did you do so by pointing and clicking on a menu of symbolic icons, or by typing the text "popular linux apps"? When the search engine provides the search results for you, does it fetch up a bunch of little pictures, or a list of text URLs with an extract of the text from the site? When I try it: https://duckduckgo.com/html/?q=popular%20linux%20apps I get text: What Are The Best 10 Linux Desktop Apps? This weekend, I'm going to be spending some time at the Southeast Linux Expo (SCALE) and presenting at the Linux Beginner Training. I'm doing the Desktops and ... linux.com/learn/what-are-best-10-linux-desktop-apps Lifehacker Pack for Linux: Our List of the Best Linux Apps NOTE: This post is outdated. Check out the most recent Lifehacker Pack for a more up-to-date list of essential Linux apps. Note that, unlike Windows and OS X, Linux ... lifehacker.com/5924951/lifehacker-pack-for-linux-our-lis... 20 Popular Ubuntu Linux Apps to Try Now | PCWorld As Ubuntu Linux continues to grow in popularity, most discussions of it tend to focus on the basics of the operating system itself, including especially ... pcworld.com/article/249663/20_popular_ubuntu_linux_ap... and so forth. The death of text as a communication medium is greatly exaggerated. > and > you will get for example: > > inkscape [...] How ironic that you are using a text-based medium to claim that people have "moved on" from text. Why didn't you draw us a picture to make your argument? > Do these look like text-based apps to you? Depends on what you mean by text-based. I don't doubt that some popular applications are used for manipulating media other than text, e.g. Gimp. But others are all about text: the two most popular parts of the LibreOffice application suite are used for word processing and spreadsheets, both text-based media. Perhaps the most common use of photo editing software like Photoshop and Gimp is to add text to images. Even for applications that are used to generate non-text media, their UIs are filled with text: menus and buttons display words, help screens filled with text, status bars that display the current coordinates of the mouse as text, dialog boxes filled with text boxes that you type into. When the UI has controls which can be controlled by the mouse (e.g. sliders), the control's value is usually displayed as text. Even colour wheels invariably display their results as text, as RGB triples or HTML codes. You list Firefox (but neglect Thunderbird) but browsing the web is still primarily a text-based medium. Not only is the fundamental file format of the web (HTML) text, but the information displayed is more often than not text. Even when the site displays non-text media, the pages usually include a way for people to comment, which they do by clicking from a menu of pre-defined emotions and messages displayed as icons. Nah, just kidding. They comment by writing text. I think that your assertion that the "rest of world has moved on" from text to be nonsense on stilts, but *even if you were right* that doesn't imply that programmers should do the same. Programmers operate under particular constraints which the average podcaster or film-maker does not have to deal with. Just because some people communicate through the medium of interpretative dance doesn't mean that programmers can or should. -- Steven From steve at pearwood.info Tue Apr 19 20:34:49 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 20 Apr 2016 10:34:49 +1000 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <20160419124321.361751dc@bigbox.christie.dr> <1461092090.2638611.583593041.7C981FAD@webmail.messagingengine.com> Message-ID: <5716ceab$0$1618$c3e8da3$5496439d@news.astraweb.com> On Wed, 20 Apr 2016 04:54 am, Random832 wrote: > None of those are "text" in the sense being discussed here, which is > "preferred method of viewing and editing is a text editor". That's not the sense of being discussed here. How absurd. Why should a letter containing nothing but text be classified as "not text" because it was written in Microsoft World or LibreOffice rather than vi or emacs? -- Steven From steve at pearwood.info Tue Apr 19 21:03:19 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 20 Apr 2016 11:03:19 +1000 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <854maxqq50.fsf@benfinney.id.au> <87potl2sfq.fsf@elektro.pacujo.net> Message-ID: <5716d558$0$1587$c3e8da3$5496439d@news.astraweb.com> On Wed, 20 Apr 2016 07:35 am, Marko Rauhamaa wrote: > The "plain text" content type is used less and less. Really it is > reserved mostly to programmers. Even texters routinely field animated > emojies nowadays. Who cares about "plain text" content type? That is not the beginning or end of what counts as text. By that ridiculously limited definition, Python progammers have already "moved on from text", because the MIME type of .py source code is application/x-python. > Text, in general, might have started to decline. o_O People today, especially the young, probably send more text today than in any previous time in history. You might have heard of something called "SMSes"? Kids today spend half their day SMSing, twitting, posting comments on Facebook, etc. And the other half taking selfies. *wink* Anyone who thinks that we're heading back to hieroglyphics simply isn't paying attention. -- Steven From steve at pearwood.info Tue Apr 19 21:38:42 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 20 Apr 2016 11:38:42 +1000 Subject: Guido sees the light: PEP 8 updated References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <20160419124321.361751dc@bigbox.christie.dr> <1461092090.2638611.583593041.7C981FAD@webmail.messagingengine.com> Message-ID: <5716dda3$0$1621$c3e8da3$5496439d@news.astraweb.com> On Wed, 20 Apr 2016 04:54 am, Random832 wrote: > You could, for example, design a programming language that uses XML > markup to associate comments with specific positions in the code and the > editor displays them in little callout boxes when you hover over them > with the mouse. That's not done because of the notion that code has to > be plain text. No, it's not done because the user interface of such a language would be absolute bollocks. The reason programmers use text for communicating with (1) other programmers and (2) the computer is that text is still, and probably always will be, so much better than any other media *for the purpose of programming* as to make it no contest. I'm sure that interpretive dance has its uses, but can you imagine the computer infrastructure needed to make that practical for programming? More seriously, there have been attempts to come up with "point and click" interfaces for programming. The idea makes a sort of sense, if you think of programming as a flow-chart (does anyone still use them?), but outside of a handful of specialist areas, they have been a total, utter dead-end. So-called "visual programming environments" (think: Visual Basic) are well-suited to laying out the interface of GUI applications. They might even be useful for extremely limited mini-languages like regexes. I'm told that there are still people who think that UML diagrams are a good idea. They're probably good for dataflow programming. But ultimately, to be productive with one, you still need text. As for "visual programming languages" (languages with an inherent visual form which lacks any simple or obvious text equivalent), they've been a dead-end. Even languages like Scratch cannot do without text. Look at the "Hello World" program here: https://en.wikipedia.org/wiki/File:Scratch_Hello_World.png The graphical elements are pure presentation, to make it more palatable to children and beginners. Don't think that I'm opposed to such visual presentations. Look at the sample code shown at the top of the page here: https://scratch.mit.edu/ It kinda looks like Hypertalk syntax, which some of you may remember I'm exceedingly fond of. There's no reason why a GUI editor couldn't display Python code using such "building block" structure. E.g. indented blocks could use colour and shape cues to reinforce the structure of the code, just as Scratch does. And if you want to see another reason why text rocks as the core for programming languages? "Oh no! We're having trouble displaying this Scratch project. If you are on a mobile phone or tablet, try visiting this project on a computer. If you're on a computer, your Flash player might be disabled, missing, or out of date." Yeah, thanks guys. Really helpful. -- Steven From random832 at fastmail.com Tue Apr 19 21:57:05 2016 From: random832 at fastmail.com (Random832) Date: Tue, 19 Apr 2016 21:57:05 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <20160419190230.4da81b2e@bigbox.christie.dr> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <20160419124321.361751dc@bigbox.christie.dr> <1461092090.2638611.583593041.7C981FAD@webmail.messagingengine.com> <20160419190230.4da81b2e@bigbox.christie.dr> Message-ID: <1461117425.2451657.583922609.0982EAB8@webmail.messagingengine.com> On Tue, Apr 19, 2016, at 20:02, Tim Chase wrote: > Well, my preferred method of "viewing" python code is /usr/bin/python > > Authoring, editing, and consuming are all distinct actions. Viewing and executing are also distinct. > > You could, for example, design a programming language that uses XML > > markup > > [shudders at remembering using a DSL "programming language" that was > XML] But I'm not proposing directly programming in XML markup. You'd use a GUI. From random832 at fastmail.com Tue Apr 19 22:02:49 2016 From: random832 at fastmail.com (Random832) Date: Tue, 19 Apr 2016 22:02:49 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <5716ceab$0$1618$c3e8da3$5496439d@news.astraweb.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <20160419124321.361751dc@bigbox.christie.dr> <1461092090.2638611.583593041.7C981FAD@webmail.messagingengine.com> <5716ceab$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1461117769.2452693.583923689.23F7301B@webmail.messagingengine.com> On Tue, Apr 19, 2016, at 20:34, Steven D'Aprano wrote: > That's not the sense of being discussed here. Yes it is - this started as a discussion of whether indentation and alignment should be based on fixed spaces (as text editors support) or dynamic tab stops (as any word processing format supports). > How absurd. Why should a > letter containing nothing but text be classified as "not text" because it > was written in Microsoft World or LibreOffice rather than vi or emacs? Because it's not _a text file_. It's not obligated to be devoid of formatting markup or other metadata, or to have a perfectly flat structure, or to be edited in programs whose design has not been updated since the early 1970s, which are _exactly_ the complaints leveled against python source code at the start of this discussion.. ______ : Python :: MS Word : Plain Text From christopher_reimer at icloud.com Tue Apr 19 22:20:43 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Tue, 19 Apr 2016 19:20:43 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: References: <5713E52D.3060407@icloud.com> <57145CB4.5040100@icloud.com> Message-ID: <5716E77B.6030306@icloud.com> On 4/19/2016 1:02 AM, Michael Selik wrote: > Why relocate rather than remove? What message would you provide that's > better than ``KeyError: 42`` with a traceback that shows exactly which > dictionary is being used and how? I think you misread my code. No dictionary exception occurs in the sanity checks. Below is the full function with the revised sanity check for positions that compares the input list with the two valid lists of board positions. def generate_set(color, positions): if positions not in [VARS['COORDINATES'][VARS['BOARD_BOTTOM']], VARS['COORDINATES'][VARS['BOARD_TOP']]]: raise Exception("List for positions contains no valid coordinates, " "got {} instead.".format(positions)) # generate objects according to color and position for position in positions: rank, file = position if rank in VARS['RANK_NOBILITY']: if file in VARS['FILE_ROOK']: yield Rook(color, position) elif file in VARS['FILE_BISHOP']: yield Bishop(color, position) elif file in VARS['FILE_KNIGHT']: yield Knight(color, position) elif file is VARS['FILE_QUEEN']: yield Queen(color, position) elif file is VARS['FILE_KING']: yield King(color, position) else: yield Pawn(color, position) > I meant, what goes wrong if the number of positions input is other than > 16? Without these "sanity" checks, your functions might be reusable in, > say, a checkers game. Chess has 16 pieces (six types) on each side that are set up on the board in a particular order. Checkers has 12 pieces (one type) on each side that are set up on alternating squares in no particular order. Since I'm writing a chess engine because it has endless supply of programming changes, I have no desire to write reusable code for two similar but different games at the same time. Thanks, Chris R. From rosuav at gmail.com Tue Apr 19 22:21:50 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Apr 2016 12:21:50 +1000 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <5716dda3$0$1621$c3e8da3$5496439d@news.astraweb.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <20160419124321.361751dc@bigbox.christie.dr> <1461092090.2638611.583593041.7C981FAD@webmail.messagingengine.com> <5716dda3$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 20, 2016 at 11:38 AM, Steven D'Aprano wrote: > As for "visual programming languages" (languages with an inherent visual > form which lacks any simple or obvious text equivalent), they've been a > dead-end. Even languages like Scratch cannot do without text. Look at > the "Hello World" program here: > > https://en.wikipedia.org/wiki/File:Scratch_Hello_World.png > > The graphical elements are pure presentation, to make it more palatable to > children and beginners. > > Don't think that I'm opposed to such visual presentations. Scratch itself is aimed at children, but there's a very similar language (or maybe it's actually a Scratch derivative) used by the Unreal Engine to animate sprites - the "blueprint" system. I've seen it used by someone who doesn't consider herself a programmer in any way, yet she has a sufficiently logical mind to do the same kind of work as programming requires. Effectively, flow control has been turned into a two-dimensional graph, with nodes pointing to other nodes, but each node is still described primarily with text (using colour to add instant recognition). I think there's a lot of value in depicting flow control graphically. For anyone who's accustomed to working visually, seeing nice little tagged blocks of "stuff", linked by little lines to show how you get from one to another, is way easier to handle than a page of "while" and "if" and "else" statements. But even there, each piece of flow control is *defined* in text - there's a short message saying what the condition is, and then two or more pieces of text defining the potential results of the condition, from which you can link to destinations. https://www.twitch.tv/ellalune/v/59455498 - starts at about the 41 minute mark. Notably, around the 00:42:30 point, I say that this is code, and she says that, well, it sort of is code, but it doesn't *feel* like code. Probably the least text-y form of coding that I've ever seen is turtle graphics, where you depict something using (usually) two dimensional movement and rotation. But even there, it's normal to use text to define all the actual actions. Take this, for example: https://studio.code.org/s/frozen/reset A nice tutorial, a theme that'll appeal to a lot of people (including young children), and primarily point-and-click (or drag) to move components around - but you can *read* the meaning of each component, in *text*. Once again, it uses a visual representation of flow control to bury some of the complexity, but the basic actions (move, turn, etc) are text - and if you want to "capture" a series of actions to reuse, the way to do that is to give it a name, because names and words are how people think. ChrisA From tjreedy at udel.edu Tue Apr 19 23:23:32 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 19 Apr 2016 23:23:32 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <5716dda3$0$1621$c3e8da3$5496439d@news.astraweb.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <20160419124321.361751dc@bigbox.christie.dr> <1461092090.2638611.583593041.7C981FAD@webmail.messagingengine.com> <5716dda3$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/19/2016 9:38 PM, Steven D'Aprano wrote: > So-called "visual programming environments" (think: Visual Basic) are > well-suited to laying out the interface of GUI applications. They might > even be useful for extremely limited mini-languages like regexes. I'm told > that there are still people who think that UML diagrams are a good idea. > They're probably good for dataflow programming. But ultimately, to be > productive with one, you still need text. > > As for "visual programming languages" (languages with an inherent visual > form which lacks any simple or obvious text equivalent), they've been a > dead-end. Even languages like Scratch cannot do without text. Look at > the "Hello World" program here: > > https://en.wikipedia.org/wiki/File:Scratch_Hello_World.png > > The graphical elements are pure presentation, to make it more palatable to > children and beginners. I think it is at least as important that the output is pictorial or even aural, then having the input text (and you are right, it is text) colored. By comparison, factorial functions (and most calculation examples) are rather boring. > Don't think that I'm opposed to such visual presentations. Look at the > sample code shown at the top of the page here: > > https://scratch.mit.edu/ > > It kinda looks like Hypertalk syntax, which some of you may remember I'm > exceedingly fond of. There's no reason why a GUI editor couldn't display > Python code using such "building block" structure. E.g. indented blocks > could use colour and shape cues to reinforce the structure of the code, > just as Scratch does. That is an interesting idea. Perhaps I have been stuck in either/or thinking -- either graphical or textual. With tk Text (IDLE), it would be possible to tag each (4-space) indent with a color for the compound statememt keywork causing the indent. > And if you want to see another reason why text rocks as the core for > programming languages? > > > "Oh no! We're having trouble displaying this Scratch project. > > If you are on a mobile phone or tablet, try visiting this project on a > computer. > > If you're on a computer, your Flash player might be disabled, missing, or > out of date." I had to enable Flash for this site. What are they going to do when Flash is dead rather than just dying? (Get with html5, perhaps?) > Yeah, thanks guys. Really helpful. -- Terry Jan Reedy From rosuav at gmail.com Tue Apr 19 23:41:59 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Apr 2016 13:41:59 +1000 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <20160419124321.361751dc@bigbox.christie.dr> <1461092090.2638611.583593041.7C981FAD@webmail.messagingengine.com> <5716dda3$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 20, 2016 at 1:23 PM, Terry Reedy wrote: >> It kinda looks like Hypertalk syntax, which some of you may remember I'm >> exceedingly fond of. There's no reason why a GUI editor couldn't display >> Python code using such "building block" structure. E.g. indented blocks >> could use colour and shape cues to reinforce the structure of the code, >> just as Scratch does. > > > That is an interesting idea. Perhaps I have been stuck in either/or > thinking -- either graphical or textual. With tk Text (IDLE), it would be > possible to tag each (4-space) indent with a color for the compound > statememt keywork causing the indent. > Interesting indeed! Tell me if I've understood you correctly. You'd display this code: def func(x): for n in range(1, x): while n < x: if n % 2: n = (n + 1) * 3 / 2 else: n = n * 2 + 3 with stripes of colour, with the entire first column of spaces all tied to the "def", and then the next block of four tied to the "for", etc? That'd be pretty cool, and a neat way to help people transfer their skills from Scratch to Python. (Would "else" be in the same colour as "if"? What about "elif"?) ChrisA From rosuav at gmail.com Tue Apr 19 23:50:11 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Apr 2016 13:50:11 +1000 Subject: How much sanity checking is required for function inputs? In-Reply-To: <5716E77B.6030306@icloud.com> References: <5713E52D.3060407@icloud.com> <57145CB4.5040100@icloud.com> <5716E77B.6030306@icloud.com> Message-ID: On Wed, Apr 20, 2016 at 12:20 PM, Christopher Reimer wrote: > I think you misread my code. No dictionary exception occurs in the sanity > checks. Below is the full function with the revised sanity check for > positions that compares the input list with the two valid lists of board > positions. > > > def generate_set(color, positions): > > if positions not in [VARS['COORDINATES'][VARS['BOARD_BOTTOM']], > VARS['COORDINATES'][VARS['BOARD_TOP']]]: > raise Exception("List for positions contains no valid coordinates, " > "got {} instead.".format(positions)) > > # generate objects according to color and position > for position in positions: > rank, file = position > if rank in VARS['RANK_NOBILITY']: > if file in VARS['FILE_ROOK']: > yield Rook(color, position) > elif file in VARS['FILE_BISHOP']: > yield Bishop(color, position) > elif file in VARS['FILE_KNIGHT']: > yield Knight(color, position) > elif file is VARS['FILE_QUEEN']: > yield Queen(color, position) > elif file is VARS['FILE_KING']: > yield King(color, position) > else: > yield Pawn(color, position) > If you nuke the check at the beginning, what happens? (By the way, I don't like this shouty "VARS" thing you have going on. It makes it hard to skim the code. I'm not entirely sure what your initial "not in" check is even doing.) You seem to have two slightly different ways of checking things: first something about BOARD_TOP and BOARD_BOTTOM, and then something else about RANK_NOBILITY and... everything else. It looks to me like all you need is to have a second check for RANK_PAWNS, and then raise an exception if it's neither of those. Then you don't need to pre-check, and the rules aren't split into two places. But if I were doing this, I'd make it far more data-driven. starting_positions = { VARS['FILE_ROOK']: Rook, VARS['FILE_BISHOP']: Bishop, ... } Or, even better, tie that to the definitions of your classes, in some way. (Metaprogramming is great here.) Then your code doesn't need an if/elif tree; you can generate starting positions easily by just looking up your table. BTW, it's usually best to not raise Exception, but a custom subclass of it. But I'm going to assume that this is just an example. ChrisA From rustompmody at gmail.com Wed Apr 20 00:04:43 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 19 Apr 2016 21:04:43 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <20160419124321.361751dc@bigbox.christie.dr> <1461092090.2638611.583593041.7C981FAD@webmail.messagingengine.com> Message-ID: <559dcbf9-5773-48d1-9a16-229ab91a4b82@googlegroups.com> On Wednesday, April 20, 2016 at 12:25:09 AM UTC+5:30, Random832 wrote: > On Tue, Apr 19, 2016, at 13:43, Tim Chase wrote: > > Well, let's take a look at their native file formats: > > > > Inkscape: SVG > > > > Libreoffice: compressed XML > > > > Firefox: HTML+CSS+JS > > > > Musescore: compressed text > > > > Dia: compressed XML > > None of those are "text" in the sense being discussed here, which is > "preferred method of viewing and editing is a text editor". O you are so pedestrian! Here let me show you how to enjoy beethoven9th.mp3 with emacs: $ python -m base64 beethoven9th.mp3 > beethoven9th.txt; emacs beethoven9th.txt Isnt it glorious? And did you note the ?hi?, p?nac?e and e?an with with I demonstrated it? [Yeah you guessed right: For me French consists of English ...um text.. with a squiggle on every 3rd letter] From rustompmody at gmail.com Wed Apr 20 00:13:17 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 19 Apr 2016 21:13:17 -0700 (PDT) Subject: Guido sees the light: PEP 8 updated In-Reply-To: <5716d558$0$1587$c3e8da3$5496439d@news.astraweb.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <854maxqq50.fsf@benfinney.id.au> <87potl2sfq.fsf@elektro.pacujo.net> <5716d558$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: <61c4cfb9-65e7-4056-a048-8665a57f1d35@googlegroups.com> On Wednesday, April 20, 2016 at 6:33:33 AM UTC+5:30, Steven D'Aprano wrote: > Anyone who thinks that we're heading back to hieroglyphics simply isn't > paying attention. Which are just text in the range 13000-1342F: http://unicode.org/charts/PDF/U13000.pdf From michael.selik at gmail.com Wed Apr 20 01:18:23 2016 From: michael.selik at gmail.com (Michael Selik) Date: Wed, 20 Apr 2016 05:18:23 +0000 Subject: How much sanity checking is required for function inputs? In-Reply-To: <5716E77B.6030306@icloud.com> References: <5713E52D.3060407@icloud.com> <57145CB4.5040100@icloud.com> <5716E77B.6030306@icloud.com> Message-ID: On Tue, Apr 19, 2016 at 11:23 PM Christopher Reimer < christopher_reimer at icloud.com> wrote: > On 4/19/2016 1:02 AM, Michael Selik wrote: > > > Why relocate rather than remove? What message would you provide that's > > better than ``KeyError: 42`` with a traceback that shows exactly which > > dictionary is being used and how? > > I think you misread my code. No dictionary exception occurs in the > sanity checks. Below is the full function with the revised sanity check > for positions that compares the input list with the two valid lists of > board positions. > Perhaps I did misread it. What is the purpose of the "sanity check"? If it's not obvious I suggest revising the code rather than adding comments. The first time I read your code, I thought the check was designed to avoid the possibility of a KeyError a few lines later. My suggestion was to simply allow bad inputs to cause KeyErrors and not clutter your code. This second time I'm reading, it seems to be a sort of boundary check, but using ``in`` which would cause a bug... Did you mean to use an inequality? > > I meant, what goes wrong if the number of positions input is other than > > 16? Without these "sanity" checks, your functions might be reusable in, > > say, a checkers game. > > I have no desire to write reusable code for two > similar but different games at the same time. > Reusability is a nice side-effect of fewer "sanity checks". Other goals are clarity, efficiency, and productivity. From me at ixokai.io Wed Apr 20 01:51:15 2016 From: me at ixokai.io (Stephen Hansen) Date: Tue, 19 Apr 2016 22:51:15 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <5713E52D.3060407@icloud.com> References: <5713E52D.3060407@icloud.com> Message-ID: <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> On Sun, Apr 17, 2016, at 12:34 PM, Christopher Reimer wrote: > if color not in [VARS['COLOR_BLACK'], VARS['COLOR_WHITE']]: > raise Exception("Require \'{}\' or \'{}\' for input value, got > \'{}\' instead.".format(VARS['COLOR_BLACK'], VARS['COLOR_WHITE'], color)) Do you think it likely you'll receive a 'color' value not in the list of black and white? Are you accepting colors from users? If you are, I'd sanity check *at user input*. Users are crazy, sanitize and check the heck out of their stuff. Your code, though? Your time and effort is better spent putting in a docstring documenting what's valid in color, and if some other coder puts in red, why, they'll get a KeyError, and it'll point to precisely what line is wrong, and be able to figure it out. Unit tests are where you try feeding invalid data into functions and see how they react-- and the correct reaction to bad data is usually exceptions. In this case, a KeyError thrown by [VARS['COLOR_BLACK'], VARS['COLOR_WHITE']][color] is more descriptive then your verbose Exception. (What's with the VARS business? Something smells bad there. You're doing something weird there) > How much sanity checking is too much in Python? IMHO, you've got too much. But that's a fuzzy question, there's no solid and clear answer. Did you see Ethan's response? I largely agree with his trinity: On Sun, Apr 17, 2016, at 10:26 PM, Ethan Furman wrote: > I sanity check for three reasons: > > 1) raise a nicer error message > > 2) keep the point of failure close to the error > > 3) the consequences of bad data are Bad Bad Things (tm) With a 4)th that exceptions aren't for users, only programmers. But ultimately, I'd rather a user see an exception if something weird goes wrong because they can send it to me and I can diagnose it and push an update. So I also: 4) Attempt to make sure all user errors result in user error messages, not exceptions. Note, 1) doesn't mean I always raise a nicer message, it means if "KeyError" is ambiguious or odd, I raise a better and more informative one. But you're getting nothing swapping out KeyError for Exception(lotsofwords). I use 1) more to be less 'nicer' and more, er, 'more specific'. Since I don't like exceptions to rise to the user level where niceness is needed. --Stephen m e @ i x o k a i . i o From tjreedy at udel.edu Wed Apr 20 02:08:19 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 20 Apr 2016 02:08:19 -0400 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <20160419124321.361751dc@bigbox.christie.dr> <1461092090.2638611.583593041.7C981FAD@webmail.messagingengine.com> <5716dda3$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/19/2016 11:41 PM, Chris Angelico wrote: > On Wed, Apr 20, 2016 at 1:23 PM, Terry Reedy wrote: >>> It kinda looks like Hypertalk syntax, which some of you may remember I'm >>> exceedingly fond of. There's no reason why a GUI editor couldn't display >>> Python code using such "building block" structure. E.g. indented blocks >>> could use colour and shape cues to reinforce the structure of the code, >>> just as Scratch does. >> >> >> That is an interesting idea. Perhaps I have been stuck in either/or >> thinking -- either graphical or textual. With tk Text (IDLE), it would be >> possible to tag each (4-space) indent with a color for the compound >> statememt keywork causing the indent. >> > > Interesting indeed! Tell me if I've understood you correctly. You'd > display this code: > > def func(x): > for n in range(1, x): > while n < x: > if n % 2: > n = (n + 1) * 3 / 2 > else: > n = n * 2 + 3 > > with stripes of colour, with the entire first column of spaces all > tied to the "def", and then the next block of four tied to the "for", > etc? Exactly. > That'd be pretty cool, and a neat way to help people transfer > their skills from Scratch to Python. > > (Would "else" be in the same colour as "if"? What about "elif"?) To be determined ;-). Perhaps different shades. Scratch uses one color for all control: while, if, else, but that would not work for python with so much more nesting. Scratch needs different colors for much broader categories as many are not for syntax but for groups of functions that in Python would be in imported modules. I would like nested for loops to have slightly different shades, but I would not necessarily start with that, unless each compound statement got a new tag and color. What makes the idea not completely ridiculous is that IDLE already keeps track of indents for its smart indenting and code context features. -- Terry Jan Reedy From ethan at stoneleaf.us Wed Apr 20 02:09:39 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 19 Apr 2016 23:09:39 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> Message-ID: <57171D23.40709@stoneleaf.us> On 04/19/2016 10:51 PM, Stephen Hansen wrote: > But that's a fuzzy question, there's no solid and clear answer. Did you > see Ethan's response? I largely agree with his trinity: > > On Sun, Apr 17, 2016, at 10:26 PM, Ethan Furman wrote: >> I sanity check for three reasons: >> >> 1) raise a nicer error message >> >> 2) keep the point of failure close to the error >> >> 3) the consequences of bad data are Bad Bad Things (tm) > > With a 4)th that exceptions aren't for users, only programmers. But > ultimately, I'd rather a user see an exception if something weird goes > wrong because they can send it to me and I can diagnose it and push an > update. So I also: > > 4) Attempt to make sure all user errors result in user error messages, > not exceptions. > > Note, 1) doesn't mean I always raise a nicer message, it means if > "KeyError" is ambiguious or odd, I raise a better and more informative > one. But you're getting nothing swapping out KeyError for > Exception(lotsofwords). > > I use 1) more to be less 'nicer' and more, er, 'more specific'. Since I > don't like exceptions to rise to the user level where niceness is > needed. Yeah, that's a better phrasing for (1); I meant more appropriate or informative, such as swapping an internal error (such as KeyError) for a more meaningful FieldNotFound error (or whatever) -- largely library code concerns. -- ~Ethan~ From me at ixokai.io Wed Apr 20 02:17:37 2016 From: me at ixokai.io (Stephen Hansen) Date: Tue, 19 Apr 2016 23:17:37 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <57171D23.40709@stoneleaf.us> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> Message-ID: <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> On Tue, Apr 19, 2016, at 11:09 PM, Ethan Furman wrote: > On 04/19/2016 10:51 PM, Stephen Hansen wrote: > > I use 1) more to be less 'nicer' and more, er, 'more specific'. Since I > > don't like exceptions to rise to the user level where niceness is > > needed. > > Yeah, that's a better phrasing for (1); I meant more appropriate or > informative, such as swapping an internal error (such as KeyError) for a > more meaningful FieldNotFound error (or whatever) -- largely library > code concerns. Yeah, and what the OP is doing is going the exact opposite-- from a more-specific exception (KeyError) to a more generic one (Exception). To me that's (usually) an anti-pattern. --S From greg.ewing at canterbury.ac.nz Wed Apr 20 02:39:09 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 20 Apr 2016 18:39:09 +1200 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <61c4cfb9-65e7-4056-a048-8665a57f1d35@googlegroups.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <854maxqq50.fsf@benfinney.id.au> <87potl2sfq.fsf@elektro.pacujo.net> <5716d558$0$1587$c3e8da3$5496439d@news.astraweb.com> <61c4cfb9-65e7-4056-a048-8665a57f1d35@googlegroups.com> Message-ID: Rustom Mody wrote: > On Wednesday, April 20, 2016 at 6:33:33 AM UTC+5:30, Steven D'Aprano wrote: > >>Anyone who thinks that we're heading back to hieroglyphics simply isn't >>paying attention. > > > Which are just text in the range 13000-1342F: > http://unicode.org/charts/PDF/U13000.pdf Moreover, the Egyptian heiroglyphs are *not* pictograms, they're a phonetic alphabet. It's a textual form of writing just as much as ours is. -- Greg From oscar.j.benjamin at gmail.com Wed Apr 20 05:24:08 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 20 Apr 2016 10:24:08 +0100 Subject: Guido sees the light: PEP 8 updated In-Reply-To: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <20160419124321.361751dc@bigbox.christie.dr> <1461092090.2638611.583593041.7C981FAD@webmail.messagingengine.com> <5716dda3$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 20 April 2016 at 07:08, Terry Reedy wrote: > On 4/19/2016 11:41 PM, Chris Angelico wrote: >> >> On Wed, Apr 20, 2016 at 1:23 PM, Terry Reedy wrote: >>>> >>>> It kinda looks like Hypertalk syntax, which some of you may remember I'm >>>> exceedingly fond of. There's no reason why a GUI editor couldn't display >>>> Python code using such "building block" structure. E.g. indented blocks >>>> could use colour and shape cues to reinforce the structure of the code, >>>> just as Scratch does. >>> >>> >>> >>> That is an interesting idea. Perhaps I have been stuck in either/or >>> thinking -- either graphical or textual. With tk Text (IDLE), it would be >>> possible to tag each (4-space) indent with a color for the compound >>> statememt keywork causing the indent. >>> >> >> Interesting indeed! Tell me if I've understood you correctly. You'd >> display this code: >> >> def func(x): >> for n in range(1, x): >> while n < x: >> if n % 2: >> n = (n + 1) * 3 / 2 >> else: >> n = n * 2 + 3 >> >> with stripes of colour, with the entire first column of spaces all >> tied to the "def", and then the next block of four tied to the "for", >> etc? > > > Exactly. Take a look at bluej which is for Java. It surrounds different constructs with different coloured rectangles. It also provides UML-ish views of the classes in a project. My students seemed to like it. -- Oscar From oscar.j.benjamin at gmail.com Wed Apr 20 05:26:16 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 20 Apr 2016 10:26:16 +0100 Subject: Guido sees the light: PEP 8 updated In-Reply-To: <5716dda3$0$1621$c3e8da3$5496439d@news.astraweb.com> References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <93639142-6b82-4b8a-8bd0-7f4593e1f692@googlegroups.com> <5716595b$0$1585$c3e8da3$5496439d@news.astraweb.com> <3d95437c-6427-46d2-8e9f-470f121194cd@googlegroups.com> <20160419124321.361751dc@bigbox.christie.dr> <1461092090.2638611.583593041.7C981FAD@webmail.messagingengine.com> <5716dda3$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 20 April 2016 at 02:38, Steven D'Aprano wrote: > > "Oh no! We're having trouble displaying this Scratch project. > > If you are on a mobile phone or tablet, try visiting this project on a > computer. > > If you're on a computer, your Flash player might be disabled, missing, or > out of date." > > Yeah, thanks guys. Really helpful. Having a flash-enabled browser is a lower barrier to entry for most people in the world than having a code editor and (being able to use) say a terminal to run your code. -- Oscar From Joaquin.Alzola at lebara.com Wed Apr 20 05:28:37 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Wed, 20 Apr 2016 09:28:37 +0000 Subject: Xlms namespace Message-ID: Hi Guys I am currently doing this: IP client(Python) --> send SOAPXML request --> IP Server (Python) SOAP request: test\ntest\ntest<{[??&%]}> From my IP Client: s.send(data_send.encode('utf-8')) From my IPServer: xml_decoded = data.decode('utf-8') xml_root = ET.ElementTree(ET.fromstring(xml_decoded)).getroot() for elem in xml_root.getiterator(): if('{http://request.messagepush.interfaces.comviva.com/xsd}shortCode'==elem.tag): shortCode = (elem.text).rstrip() if('{http://request.messagepush.interfaces.comviva.com/xsd}text'==elem.tag): send_text = (elem.text).rstrip() if('{http://request.messagepush.interfaces.comviva.com/xsd}item'==elem.tag): subscribers = (elem.text).rstrip() result_sms = send_sms(subscribers,shortCode,send_text) It is working fine but I am having problems with a couple of special characters, & and < The problem: test\ntest\ntest<{[??&%]}> It seems as if I send this: <> and the character & then I have a problem. I need to use utf-8 as I need to make sure I get 160 characters in one SMS. Error: Traceback (most recent call last): File "./ipserver.py", line 52, in main() File "./ipserver.py", line 36, in main xml_root = ET.ElementTree(ET.fromstring(xml_decoded)).getroot() File "/usr/lib64/python3.4/xml/etree/ElementTree.py", line 1325, in XML parser.feed(text) xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 19, column 48 This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. From asimkostas at gmail.com Wed Apr 20 07:00:55 2016 From: asimkostas at gmail.com (asimkon .) Date: Wed, 20 Apr 2016 14:00:55 +0300 Subject: djqgrid 0.2.4 error import json_helpers Message-ID: Hello! I want to use this wrapper for a module in my Django 1.9.4 version. I have configured all the steps mentioned successfully but in the end i get the following error message in my browser: Invalid template library specified. ImportError raised when trying to load 'djqgrid.templatetags.djqgrid': cannot import name json_helpers Inside my templatetags folder (djqgrid.py), i have the following commands: from django import template from djqgrid import json_helpers Any idea to get a solution ? I sent a few emails to the author of this wrapper but i have not got a reply yet! Regards Kostas Asimakopoulos Twitter @asimkon From liran.maymoni at gmail.com Wed Apr 20 07:08:56 2016 From: liran.maymoni at gmail.com (liran.maymoni at gmail.com) Date: Wed, 20 Apr 2016 04:08:56 -0700 (PDT) Subject: Failed install scipy lib In-Reply-To: References: <08215756-d9f5-4dba-b710-ab8626ebfe27@googlegroups.com> Message-ID: <3b6c95df-941d-41e7-8eb5-54b266cb5ce6@googlegroups.com> On Tuesday, April 19, 2016 at 9:21:42 PM UTC+3, eryk sun wrote: > On Tue, Apr 19, 2016 at 12:05 PM, Oscar Benjamin > wrote: > > On 19 Apr 2016 17:01, wrote: > >> > >> i'm trying to use: > >> "py -m pip install scipy" > >> and after couple of lines a get an error saying: > > > > I thought that binary wheels for scipy would be available on pypi for each > > OS now. Try updating pip and then using it to install scipy. > > PyPI only has Windows wheels for NumPy, not SciPy. You can use > Christoph Gohlke's unofficial packages: > > http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy > http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy Tried to install thouse packages and i'm getting the error: scipy-0.17.0-cp35-none-win_amd64.whl is not a supported wheel on this platform. i've also tried it with the versions: scipy-0.17.0-cp27-none-win_amd64.whl is not a supported wheel on this platform. scipy-0.17.0-cp34-none-win_amd64.whl is not a supported wheel on this platform. I'm using win 10 x64. And python 3.5 From liran.maymoni at gmail.com Wed Apr 20 07:30:35 2016 From: liran.maymoni at gmail.com (liran.maymoni at gmail.com) Date: Wed, 20 Apr 2016 04:30:35 -0700 (PDT) Subject: Failed install scipy lib In-Reply-To: <3b6c95df-941d-41e7-8eb5-54b266cb5ce6@googlegroups.com> References: <08215756-d9f5-4dba-b710-ab8626ebfe27@googlegroups.com> <3b6c95df-941d-41e7-8eb5-54b266cb5ce6@googlegroups.com> Message-ID: On Wednesday, April 20, 2016 at 2:09:10 PM UTC+3, liran.... at gmail.com wrote: > On Tuesday, April 19, 2016 at 9:21:42 PM UTC+3, eryk sun wrote: > > On Tue, Apr 19, 2016 at 12:05 PM, Oscar Benjamin > > wrote: > > > On 19 Apr 2016 17:01, wrote: > > >> > > >> i'm trying to use: > > >> "py -m pip install scipy" > > >> and after couple of lines a get an error saying: > > > > > > I thought that binary wheels for scipy would be available on pypi for each > > > OS now. Try updating pip and then using it to install scipy. > > > > PyPI only has Windows wheels for NumPy, not SciPy. You can use > > Christoph Gohlke's unofficial packages: > > > > http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy > > http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy > > Tried to install thouse packages and i'm getting the error: > > scipy-0.17.0-cp35-none-win_amd64.whl is not a supported wheel on this platform. > > i've also tried it with the versions: > scipy-0.17.0-cp27-none-win_amd64.whl is not a supported wheel on this platform. > > scipy-0.17.0-cp34-none-win_amd64.whl is not a supported wheel on this platform. > > > I'm using win 10 x64. And python 3.5 Ok i got it to install with the version: scipy-0.17.0-cp35-none-win32.whl I've also install this version: numpy-1.11.0+mkl-cp35-cp35m-win32.whl But when i try to run: >>> from scipy.stats.stats import pearsonr I get this error: Traceback (most recent call last): File "", line 1, in from scipy.stats.stats import pearsonr File "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scipy\stats\__init__.py", line 338, in from .stats import * File "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scipy\stats\stats.py", line 180, in import scipy.special as special File "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scipy\special\__init__.py", line 627, in from ._ufuncs import * File "scipy\special\_ufuncs.pyx", line 1, in init scipy.special._ufuncs (scipy\special\_ufuncs.c:26242) ImportError: DLL load failed: The specified module could not be found. :( From rosuav at gmail.com Wed Apr 20 07:43:44 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Apr 2016 21:43:44 +1000 Subject: djqgrid 0.2.4 error import json_helpers In-Reply-To: References: Message-ID: On Wed, Apr 20, 2016 at 9:00 PM, asimkon . wrote: > Inside my templatetags folder (djqgrid.py), i have the following commands: > > from django import template > from djqgrid import json_helpers > > Any idea to get a solution ? > You're attempting to import from yourself, there. Is that what you intend? Or should you be using a different name for one of those? ChrisA From ndbecker2 at gmail.com Wed Apr 20 08:34:41 2016 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 20 Apr 2016 08:34:41 -0400 Subject: Just-in-Time Static Type Checking for Dynamic Languages Message-ID: I saw this article, which might interest some of you. It discusses application to ruby, but perhaps might have ideas useful for python. https://arxiv.org/abs/1604.03641 From oscar.j.benjamin at gmail.com Wed Apr 20 09:04:52 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 20 Apr 2016 14:04:52 +0100 Subject: Failed install scipy lib In-Reply-To: References: <08215756-d9f5-4dba-b710-ab8626ebfe27@googlegroups.com> <3b6c95df-941d-41e7-8eb5-54b266cb5ce6@googlegroups.com> Message-ID: On 20 April 2016 at 12:30, wrote: > On Wednesday, April 20, 2016 at 2:09:10 PM UTC+3, liran.... at gmail.com wrote: >> On Tuesday, April 19, 2016 at 9:21:42 PM UTC+3, eryk sun wrote: >> > On Tue, Apr 19, 2016 at 12:05 PM, Oscar Benjamin >> > wrote: >> > > On 19 Apr 2016 17:01, wrote: >> > >> >> > >> i'm trying to use: >> > >> "py -m pip install scipy" >> > >> and after couple of lines a get an error saying: >> > > >> > > I thought that binary wheels for scipy would be available on pypi for each >> > > OS now. Try updating pip and then using it to install scipy. >> > >> > PyPI only has Windows wheels for NumPy, not SciPy. You can use >> > Christoph Gohlke's unofficial packages: >> > >> > http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy >> > http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy >> >> Tried to install thouse packages and i'm getting the error: >> >> scipy-0.17.0-cp35-none-win_amd64.whl is not a supported wheel on this platform. >> >> i've also tried it with the versions: >> scipy-0.17.0-cp27-none-win_amd64.whl is not a supported wheel on this platform. >> >> scipy-0.17.0-cp34-none-win_amd64.whl is not a supported wheel on this platform. >> >> >> I'm using win 10 x64. And python 3.5 > > Ok i got it to install with the version: > scipy-0.17.0-cp35-none-win32.whl > I've also install this version: > numpy-1.11.0+mkl-cp35-cp35m-win32.whl > > But when i try to run: >>>> from scipy.stats.stats import pearsonr > > I get this error: > Traceback (most recent call last): > File "", line 1, in > from scipy.stats.stats import pearsonr > File "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scipy\stats\__init__.py", line 338, in > from .stats import * > File "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scipy\stats\stats.py", line 180, in > import scipy.special as special > File "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scipy\special\__init__.py", line 627, in > from ._ufuncs import * > File "scipy\special\_ufuncs.pyx", line 1, in init scipy.special._ufuncs (scipy\special\_ufuncs.c:26242) > ImportError: DLL load failed: The specified module could not be found. Maybe this is the problem: http://stackoverflow.com/questions/36489487/error-of-import-scipy-stats-for-windows-7 -- Oscar From jldunn2000 at gmail.com Wed Apr 20 09:57:11 2016 From: jldunn2000 at gmail.com (loial) Date: Wed, 20 Apr 2016 06:57:11 -0700 (PDT) Subject: Running lpr on windows from python Message-ID: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> I am trying to run lpr from python 2.7.10 on windows However I always get the error 'C:/windows/system32/lpr.exe ' is not recognized as an internal or external command, operable program or batch file. Even though typing the same at the command prompt works OK Any ideas? I am using subprocess as follows process = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) where command line is C:/windows/system32/lpr.exe -S 172.28.84.38 -P RAW C:/john/myfile From rosuav at gmail.com Wed Apr 20 10:07:26 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Apr 2016 00:07:26 +1000 Subject: Running lpr on windows from python In-Reply-To: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> References: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> Message-ID: On Wed, Apr 20, 2016 at 11:57 PM, loial wrote: > I am trying to run lpr from python 2.7.10 on windows > > However I always get the error > 'C:/windows/system32/lpr.exe ' is not recognized as an internal or external command, > operable program or batch file. > > Even though typing the same at the command prompt works OK > > > Any ideas? > > I am using subprocess as follows > > process = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > where command line is > C:/windows/system32/lpr.exe -S 172.28.84.38 -P RAW C:/john/myfile You''re running that through the shell, which means you have to abide by shell rules. I don't have a Windows handy, but I'm pretty sure its shell isn't happy with forward slashes in the command line; I might be wrong there. My recommendation: Split that into separate arguments, pass them as a list, and remove shell=True. And unless you need to be completely explicit for some reason (eg to protect against path-based exploits), cut the first argument to just "lpr" and let the binary be found anywhere. ChrisA From mail at timgolden.me.uk Wed Apr 20 10:08:49 2016 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 20 Apr 2016 15:08:49 +0100 Subject: Running lpr on windows from python In-Reply-To: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> References: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> Message-ID: <57178D71.5050408@timgolden.me.uk> On 20/04/2016 14:57, loial wrote: > I am trying to run lpr from python 2.7.10 on windows > > However I always get the error > 'C:/windows/system32/lpr.exe ' is not recognized as an internal or external command, > operable program or batch file. > > Even though typing the same at the command prompt works OK > > > Any ideas? > > I am using subprocess as follows > > process = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > where command line is > C:/windows/system32/lpr.exe -S 172.28.84.38 -P RAW C:/john/myfile > Ummm.. Do you actually have a program called lpr.exe in that location? It's not usual on Windows. (I rather assume you do since you give the full path, but still...) IOW, what happens if you type: dir C:\windows\system32\lpr.exe at a command promopt? Also: are you on a 64-bit system? If so, c:\windows\system32 probably isn't where you think it is. cf, for example: https://mail.python.org/pipermail/python-win32/2012-March/012121.html TJG From random832 at fastmail.com Wed Apr 20 10:09:10 2016 From: random832 at fastmail.com (Random832) Date: Wed, 20 Apr 2016 10:09:10 -0400 Subject: Running lpr on windows from python In-Reply-To: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> References: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> Message-ID: <1461161350.2918798.584433545.40877410@webmail.messagingengine.com> On Wed, Apr 20, 2016, at 09:57, loial wrote: > I am trying to run lpr from python 2.7.10 on windows > > However I always get the error > 'C:/windows/system32/lpr.exe ' is not recognized as an internal or > external command, > operable program or batch file. > > Even though typing the same at the command prompt works OK It does? This command doesn't exist on my machine. It's not a standard part of windows. Just to check though, are you 64-bit windows, and 32 or 64 bit python? (To find out what kind of windows, go to the system control panel - to find out if python is 64-bit look at the value of sys.maxsize, it's 2147483647 on 32-bit systems and 9223372036854775807 on 64-bit) > Any ideas? > > I am using subprocess as follows > > process = subprocess.Popen(commandline, shell=True, > stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > where command line is > C:/windows/system32/lpr.exe -S 172.28.84.38 -P RAW C:/john/myfile If all you want to do is print a text file, see http://www.robvanderwoude.com/printfiles.php - these commands may not let you do whatever you're trying to do with that IP address though. From jldunn2000 at gmail.com Wed Apr 20 10:21:08 2016 From: jldunn2000 at gmail.com (loial) Date: Wed, 20 Apr 2016 07:21:08 -0700 (PDT) Subject: Running lpr on windows from python In-Reply-To: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> References: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> Message-ID: <7a7e2d01-fcf3-4f14-9531-f19a96700cf3@googlegroups.com> As I said, the lpr command works fine from the command prompt but not from python. Everything is 64-bit (windows server 2012). From jldunn2000 at gmail.com Wed Apr 20 10:25:42 2016 From: jldunn2000 at gmail.com (loial) Date: Wed, 20 Apr 2016 07:25:42 -0700 (PDT) Subject: Running lpr on windows from python In-Reply-To: References: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> Message-ID: <6171cb8a-988a-49ea-a767-d73824685fea@googlegroups.com> I get the same issue if I just specify "lpr" rather than a full path, i.e. it works from the command prompt(with forward slashes), but not from python From david.sims2 at nih.gov Wed Apr 20 10:43:05 2016 From: david.sims2 at nih.gov (Sims, David (NIH/NCI) [C]) Date: Wed, 20 Apr 2016 14:43:05 +0000 Subject: Creating Dict of Dict of Lists with joblib and Multiprocessing Message-ID: <65DB2690-8988-41A7-B5BC-EA0390CDA1DF@nih.gov> Hi, Cross posted at http://stackoverflow.com/questions/36726024/creating-dict-of-dicts-with-joblib-and-multiprocessing, but thought I'd try here too as no responses there so far. A bit new to python and very new to parallel processing in python. I have a script that will process a datafile and generate a dict of dicts. However, as I need to run this task on hundreds to thousands of these files and ultimately collate the data, I thought parallel processing made a lot of sense. However, I can't seem to figure out how to create a data structure. Minimal script without all the helper functions: #!/usr/bin/python import sys import os import re import subprocess import multiprocessing from joblib import Parallel, delayed from collections import defaultdict from pprint import pprint def proc_vcf(vcf,results): sample_name = vcf.rstrip('.vcf') results.setdefault(sample_name, {}) # Run Helper functions 'run_cmd()' and 'parse_variant_data()' to generate a list of entries. Expect a dict of dict of lists all_vars = run_cmd('vcfExtractor',vcf) results[sample_name]['all_vars'] = parse_variant_data(all_vars,'all') # Run Helper functions 'run_cmd()' and 'parse_variant_data()' to generate a different list of data based on a different set of criteria. mois = run_cmd('moi_report', vcf) results[sample_name]['mois'] = parse_variant_data(mois, 'moi') return results def main(): input_files = sys.argv[1:] # collected_data = defaultdict(lambda: defaultdict(dict)) collected_data = {} # Parallel Processing version # num_cores = multiprocessing.cpu_count() # Parallel(n_jobs=num_cores)(delayed(proc_vcf)(vcf,collected_data) for vcf in input_files) # for vcf in input_files: # proc_vcf(vcf, collected_data) pprint(dict(collected_data)) return if __name__=="__main__": main() Hard to provide source data as it's very large, but basically, the dataset will generate a dict of dicts of lists that contain two sets of data for each input keyed by sample and data type: { 'sample1' : { 'all_vars' : [ 'data_val1', 'data_val2', 'etc'], 'mois' : [ 'data_val_x', 'data_val_y', 'data_val_z'] } 'sample2' : { 'all_vars' : [ . . . ] } } If I run it without trying to multiprocess, not a problem. I can't figure out how to parallelize this and create the same data structure. I've tried to use defaultdict to create a defaultdict in main() to pass along, as well as a few other iterations, but I can't seem to get it right (getting key errors, pickle errors, etc.). Can anyone help me with the proper way to do this? I think I'm not making / initializing / working with the data structure correctly, but maybe my whole approach is ill conceived? From mail at timgolden.me.uk Wed Apr 20 10:58:38 2016 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 20 Apr 2016 15:58:38 +0100 Subject: Running lpr on windows from python In-Reply-To: <7a7e2d01-fcf3-4f14-9531-f19a96700cf3@googlegroups.com> References: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> <7a7e2d01-fcf3-4f14-9531-f19a96700cf3@googlegroups.com> Message-ID: <5717991E.70309@timgolden.me.uk> On 20/04/2016 15:21, loial wrote: > As I said, the lpr command works fine from the command prompt but not from python. Sorry; I did miss that. > Everything is 64-bit (windows server 2012). > Is the Python installation also 64-bit? c:\python27\python.exe -c "import platform; print platform.architecture()" If it is, then I'm not sure what's going on. If it's not, then try copying the lpr.exe to c:\windows\syswow64 and try again. (Or to some other place to which you have access). TJG From gvm2121 at gmail.com Wed Apr 20 11:03:43 2016 From: gvm2121 at gmail.com (Gonzalo V) Date: Wed, 20 Apr 2016 12:03:43 -0300 Subject: Failed install scipy lib In-Reply-To: References: <08215756-d9f5-4dba-b710-ab8626ebfe27@googlegroups.com> <3b6c95df-941d-41e7-8eb5-54b266cb5ce6@googlegroups.com> Message-ID: oscar inst?late mejor anaconda y listo. Saludos, Gonzalo 2016-04-20 10:04 GMT-03:00 Oscar Benjamin : > On 20 April 2016 at 12:30, wrote: > > On Wednesday, April 20, 2016 at 2:09:10 PM UTC+3, liran.... at gmail.com > wrote: > >> On Tuesday, April 19, 2016 at 9:21:42 PM UTC+3, eryk sun wrote: > >> > On Tue, Apr 19, 2016 at 12:05 PM, Oscar Benjamin > >> > wrote: > >> > > On 19 Apr 2016 17:01, wrote: > >> > >> > >> > >> i'm trying to use: > >> > >> "py -m pip install scipy" > >> > >> and after couple of lines a get an error saying: > >> > > > >> > > I thought that binary wheels for scipy would be available on pypi > for each > >> > > OS now. Try updating pip and then using it to install scipy. > >> > > >> > PyPI only has Windows wheels for NumPy, not SciPy. You can use > >> > Christoph Gohlke's unofficial packages: > >> > > >> > http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy > >> > http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy > >> > >> Tried to install thouse packages and i'm getting the error: > >> > >> scipy-0.17.0-cp35-none-win_amd64.whl is not a supported wheel on this > platform. > >> > >> i've also tried it with the versions: > >> scipy-0.17.0-cp27-none-win_amd64.whl is not a supported wheel on this > platform. > >> > >> scipy-0.17.0-cp34-none-win_amd64.whl is not a supported wheel on this > platform. > >> > >> > >> I'm using win 10 x64. And python 3.5 > > > > Ok i got it to install with the version: > > scipy-0.17.0-cp35-none-win32.whl > > I've also install this version: > > numpy-1.11.0+mkl-cp35-cp35m-win32.whl > > > > But when i try to run: > >>>> from scipy.stats.stats import pearsonr > > > > I get this error: > > Traceback (most recent call last): > > File "", line 1, in > > from scipy.stats.stats import pearsonr > > File > "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scipy\stats\__init__.py", > line 338, in > > from .stats import * > > File > "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scipy\stats\stats.py", > line 180, in > > import scipy.special as special > > File > "C:\Users\Liran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scipy\special\__init__.py", > line 627, in > > from ._ufuncs import * > > File "scipy\special\_ufuncs.pyx", line 1, in init > scipy.special._ufuncs (scipy\special\_ufuncs.c:26242) > > ImportError: DLL load failed: The specified module could not be found. > > Maybe this is the problem: > > > http://stackoverflow.com/questions/36489487/error-of-import-scipy-stats-for-windows-7 > > -- > Oscar > -- > https://mail.python.org/mailman/listinfo/python-list > From michael.selik at gmail.com Wed Apr 20 11:17:31 2016 From: michael.selik at gmail.com (Michael Selik) Date: Wed, 20 Apr 2016 15:17:31 +0000 Subject: Creating Dict of Dict of Lists with joblib and Multiprocessing In-Reply-To: <65DB2690-8988-41A7-B5BC-EA0390CDA1DF@nih.gov> References: <65DB2690-8988-41A7-B5BC-EA0390CDA1DF@nih.gov> Message-ID: On Wed, Apr 20, 2016 at 10:50 AM Sims, David (NIH/NCI) [C] < david.sims2 at nih.gov> wrote: > Hi, > > Cross posted at > http://stackoverflow.com/questions/36726024/creating-dict-of-dicts-with-joblib-and-multiprocessing, > but thought I'd try here too as no responses there so far. > > A bit new to python and very new to parallel processing in python. I have > a script that will process a datafile and generate a dict of dicts. > However, as I need to run this task on hundreds to thousands of these files > and ultimately collate the data, I thought parallel processing made a lot > of sense. However, I can't seem to figure out how to create a data > structure. Minimal script without all the helper functions: > > #!/usr/bin/python > import sys > import os > import re > import subprocess > import multiprocessing > from joblib import Parallel, delayed > from collections import defaultdict > from pprint import pprint > > def proc_vcf(vcf,results): > sample_name = vcf.rstrip('.vcf') > results.setdefault(sample_name, {}) > > # Run Helper functions 'run_cmd()' and 'parse_variant_data()' to > generate a list of entries. Expect a dict of dict of lists > all_vars = run_cmd('vcfExtractor',vcf) > results[sample_name]['all_vars'] = parse_variant_data(all_vars,'all') > > # Run Helper functions 'run_cmd()' and 'parse_variant_data()' to > generate a different list of data based on a different set of criteria. > mois = run_cmd('moi_report', vcf) > results[sample_name]['mois'] = parse_variant_data(mois, 'moi') > return results > > def main(): > input_files = sys.argv[1:] > > # collected_data = defaultdict(lambda: defaultdict(dict)) > collected_data = {} > > # Parallel Processing version > # num_cores = multiprocessing.cpu_count() > # Parallel(n_jobs=num_cores)(delayed(proc_vcf)(vcf,collected_data) for > vcf in input_files) > > # for vcf in input_files: > # proc_vcf(vcf, collected_data) > > pprint(dict(collected_data)) > return > > if __name__=="__main__": > main() > > > Hard to provide source data as it's very large, but basically, the dataset > will generate a dict of dicts of lists that contain two sets of data for > each input keyed by sample and data type: > > { 'sample1' : { > 'all_vars' : [ > 'data_val1', > 'data_val2', > 'etc'], > 'mois' : [ > 'data_val_x', > 'data_val_y', > 'data_val_z'] > } > 'sample2' : { > 'all_vars' : [ > . > . > . > ] > } > } > > If I run it without trying to multiprocess, not a problem. I can't figure > out how to parallelize this and create the same data structure. I've tried > to use defaultdict to create a defaultdict in main() to pass along, as well > as a few other iterations, but I can't seem to get it right (getting key > errors, pickle errors, etc.). Can anyone help me with the proper way to do > this? I think I'm not making / initializing / working with the data > structure correctly, but maybe my whole approach is ill conceived? > Processes cannot share memory, so your collected_data is only copied once, at the time you pass it to each subprocess. There's an undocumented ThreadPool that works the same as the process Pool ( https://docs.python.org/3.5/library/multiprocessing.html#using-a-pool-of-workers ) ThreadPool will share memory across your subthreads. In the example I liked to, just replace ``from multiprocessing import Pool`` with ``from multiprocessing.pool import ThreadPool``. How compute-intensive is your task? If it's mostly disk-read-intensive rather than compute-intensive, then threads is all you need. From sohcahtoa82 at gmail.com Wed Apr 20 13:52:12 2016 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Wed, 20 Apr 2016 10:52:12 -0700 (PDT) Subject: Xlms namespace In-Reply-To: References: Message-ID: On Wednesday, April 20, 2016 at 10:05:02 AM UTC-7, Joaquin Alzola wrote: > Hi Guys > > I am currently doing this: > > IP client(Python) --> send SOAPXML request --> IP Server (Python) > > SOAP request: > > test\ntest\ntest<{[? EURO&%]}> > > From my IP Client: > s.send(data_send.encode('utf-8')) > > From my IPServer: > xml_decoded = data.decode('utf-8') > xml_root = ET.ElementTree(ET.fromstring(xml_decoded)).getroot() > for elem in xml_root.getiterator(): > if('{http://request.messagepush.interfaces.comviva.com/xsd}shortCode'==elem.tag): > shortCode = (elem.text).rstrip() > if('{http://request.messagepush.interfaces.comviva.com/xsd}text'==elem.tag): > send_text = (elem.text).rstrip() > if('{http://request.messagepush.interfaces.comviva.com/xsd}item'==elem.tag): > subscribers = (elem.text).rstrip() > result_sms = send_sms(subscribers,shortCode,send_text) > > It is working fine but I am having problems with a couple of special characters, & and < > > The problem: > test\ntest\ntest<{[? EURO&%]}> > > It seems as if I send this: <> and the character & then I have a problem. > I need to use utf-8 as I need to make sure I get 160 characters in one SMS. > > Error: > Traceback (most recent call last): > File "./ipserver.py", line 52, in > main() > File "./ipserver.py", line 36, in main > xml_root = ET.ElementTree(ET.fromstring(xml_decoded)).getroot() > File "/usr/lib64/python3.4/xml/etree/ElementTree.py", line 1325, in XML > parser.feed(text) > xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 19, column 48 > This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. If I had to make a guess, you need to escape the <, >, and &characters or else they'll get parsed by the XML parser. Try sending "test\ntest\ntest<{[? EURO&%]}>" From k.seehart at partner.samsung.com Wed Apr 20 15:34:24 2016 From: k.seehart at partner.samsung.com (Ken Seehart) Date: Wed, 20 Apr 2016 19:34:24 +0000 Subject: PEP proposal: sequence expansion support for yield statement: yield * Message-ID: <573e61523bfc412ca8674b06d70f2fd7@sraex01sc.sisa.samsung.com> Currently the common pattern for yielding the elements in a sequence is as follows: for x in sequence: yield x I propose the following replacement (the result would be identical): yield *sequence The semantics are somewhat different from argument expansion (from which the syntax is borrowed), but intuitive: yield all of the elements of a sequence (as opposed to yield the sequence as a single item). This doesn't appear to have any syntactical collisions, as it is currently a syntax error. Motivation: More compact notation, and the compiler can produce more efficient bytecode than the former representation (the loop overhead is omitted). This pattern is very common in recursive generators, so a compact notation would be nice. Also, there is precedent: the proposed notation is implemented in javascript with identical semantics (though in javascript, the conventional spacing is different: yield* sequence ). Examples: yield *(1,2,3) ... instead of : yield 1; yield 2; yield 3 ... or: for x in (1,2,3): yield x yield *chain(seq1, seq2) ... instead of : for x in chain(seq1, seq2) yield x ~ Ken Seehart From random832 at fastmail.com Wed Apr 20 15:53:44 2016 From: random832 at fastmail.com (Random832) Date: Wed, 20 Apr 2016 15:53:44 -0400 Subject: PEP proposal: sequence expansion support for yield statement: yield * In-Reply-To: <573e61523bfc412ca8674b06d70f2fd7@sraex01sc.sisa.samsung.com> References: <573e61523bfc412ca8674b06d70f2fd7@sraex01sc.sisa.samsung.com> Message-ID: <1461182024.3047115.584804185.6B0800F9@webmail.messagingengine.com> On Wed, Apr 20, 2016, at 15:34, Ken Seehart wrote: > Currently the common pattern for yielding the elements in a sequence is > as follows: > > for x in sequence: yield x > > I propose the following replacement (the result would be identical): > > yield *sequence yield from sequence From alanoe at linux.vnet.ibm.com Wed Apr 20 15:54:48 2016 From: alanoe at linux.vnet.ibm.com (Alan Evangelista) Date: Wed, 20 Apr 2016 16:54:48 -0300 Subject: PEP proposal: sequence expansion support for yield statement: yield * In-Reply-To: <573e61523bfc412ca8674b06d70f2fd7@sraex01sc.sisa.samsung.com> References: <573e61523bfc412ca8674b06d70f2fd7@sraex01sc.sisa.samsung.com> Message-ID: <5717DE88.4070807@linux.vnet.ibm.com> > Currently the common pattern for yielding the elements in a sequence is as follows: > > for x in sequence: yield x > > I propose the following replacement (the result would be identical): > > yield *sequence imho the current syntax is much more intuitive, it is obvious to infer what it does by looking at it. I favor a more intuitive syntax over a more concise one. Regards, Alan Evangelista From ethan at stoneleaf.us Wed Apr 20 16:01:35 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 20 Apr 2016 13:01:35 -0700 Subject: PEP proposal: sequence expansion support for yield statement: yield * In-Reply-To: <573e61523bfc412ca8674b06d70f2fd7@sraex01sc.sisa.samsung.com> References: <573e61523bfc412ca8674b06d70f2fd7@sraex01sc.sisa.samsung.com> Message-ID: <5717E01F.3020804@stoneleaf.us> On 04/20/2016 12:34 PM, Ken Seehart wrote: New ideas for Python are typically vetted on Python Ideas. [1] > Currently the common pattern for yielding the elements in a sequence > is as follows: > > for x in sequence: yield x > > I propose the following replacement (the result would be identical): > > yield *sequence > > The semantics are somewhat different from argument expansion (from > which the syntax is borrowed), but intuitive: yield all of the elements > of a sequence (as opposed to yield the sequence as a single item). Your examples do not make clear what your result should be. If you mean the results are exactly the same you can get that behavior with yield from iter(x) which, while being slightly longer, has the advantage of already working. ;) -- ~Ethan~ [1] https://mail.python.org/mailman/listinfo/python-ideas From me+python at ixokai.io Wed Apr 20 17:01:59 2016 From: me+python at ixokai.io (Stephen Hansen) Date: Wed, 20 Apr 2016 14:01:59 -0700 Subject: Running lpr on windows from python In-Reply-To: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> References: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> Message-ID: <1461186119.52599.584860929.759DC943@webmail.messagingengine.com> On Wed, Apr 20, 2016, at 06:57 AM, loial wrote: > process = subprocess.Popen(commandline, shell=True, > stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > where command line is > C:/windows/system32/lpr.exe -S 172.28.84.38 -P RAW C:/john/myfile Try making command line: commandline = r"C:\windows\system32\lpr.exe -S 172.28.84.38 -P RAW C:\john\myfile" The r in front of the string makes it a raw string so you don't have to double up the slashes. --- Stephen Hansen m e @ i x o k a i . i o From Joaquin.Alzola at lebara.com Wed Apr 20 17:43:43 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Wed, 20 Apr 2016 21:43:43 +0000 Subject: Xlms namespace In-Reply-To: References: Message-ID: >> The problem: >> test\ntest\ntest<{[? EURO&%]}> >If I had to make a guess, you need to escape the <, >, and &characters or else they'll get parsed by the XML parser. Try sending "test\ntest\ntest<{[? EURO&%>]}>" Yes it is the xml itself. Putting the & and also the < I can make it work with the desire characters So the result: test\ntest\ntest<{[?&?%]}> Will print < and also &. Thanks. This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. From kenseehart at gmail.com Wed Apr 20 18:26:31 2016 From: kenseehart at gmail.com (kenseehart at gmail.com) Date: Wed, 20 Apr 2016 15:26:31 -0700 (PDT) Subject: PEP proposal: sequence expansion support for yield statement: yield * In-Reply-To: References: <573e61523bfc412ca8674b06d70f2fd7@sraex01sc.sisa.samsung.com> <5717E01F.3020804@stoneleaf.us> Message-ID: On Wednesday, April 20, 2016 at 1:00:45 PM UTC-7, Ethan Furman wrote: > On 04/20/2016 12:34 PM, Ken Seehart wrote: > > New ideas for Python are typically vetted on Python Ideas. [1] > > > Currently the common pattern for yielding the elements in a sequence > > is as follows: > > > > for x in sequence: yield x > > > > I propose the following replacement (the result would be identical): > > > > yield *sequence > > > > The semantics are somewhat different from argument expansion (from > > which the syntax is borrowed), but intuitive: yield all of the elements > > of a sequence (as opposed to yield the sequence as a single item). > > Your examples do not make clear what your result should be. If you mean > the results are exactly the same you can get that behavior with > > yield from iter(x) > > which, while being slightly longer, has the advantage of already > working. ;) > > -- > ~Ethan~ > > [1] https://mail.python.org/mailman/listinfo/python-ideas To be clear, the comment "...(the result would be identical)" is indicative that the result would be identical, meaning "exactly the same". Anyway, thanks for the link. And I suppose checking Python 3 for implementation would be a good prior step as well! Sadly, "yield from" is not in python 2.7, but it's presence in python 3.3 renders my proposal dead as a parrot without a liver. Regards, Ken From rosuav at gmail.com Wed Apr 20 19:23:58 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Apr 2016 09:23:58 +1000 Subject: PEP proposal: sequence expansion support for yield statement: yield * In-Reply-To: References: <573e61523bfc412ca8674b06d70f2fd7@sraex01sc.sisa.samsung.com> <5717E01F.3020804@stoneleaf.us> Message-ID: On Thu, Apr 21, 2016 at 8:26 AM, wrote: > Anyway, thanks for the link. And I suppose checking Python 3 for implementation would be a good prior step as well! Sadly, "yield from" is not in python 2.7, but it's presence in python 3.3 renders my proposal dead as a parrot without a liver. > This is what happens when you make proposals. Guido van Rossum has a time machine, and he'll go back in time, implement the feature, and quietly come back here :) Keep on thinking about what would make the language better. Ideas are great! But do remember to check the latest version of Python (currently 3.5, with 3.6 in development); no new features will be added to 2.7. In fact, I'd recommend making the switch to 3.5 as soon as possible; you'll gain quite a few cool new features. All the best! ChrisA From steve at pearwood.info Wed Apr 20 20:21:31 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 21 Apr 2016 10:21:31 +1000 Subject: PEP proposal: sequence expansion support for yield statement: yield * References: <573e61523bfc412ca8674b06d70f2fd7@sraex01sc.sisa.samsung.com> Message-ID: <57181d0e$0$1591$c3e8da3$5496439d@news.astraweb.com> On Thu, 21 Apr 2016 05:34 am, Ken Seehart wrote: > Currently the common pattern for yielding the elements in a sequence is as > follows: > > for x in sequence: yield x > > I propose the following replacement (the result would be identical): > > yield *sequence Others have already pointed out that this already exists as "yield from iter(sequence)", but I'd like to say that this syntax was not added merely to shorten the "for x in sequence: yield x" idiom. In its simplest case, "yield from expr" is equivalent to "for x in expr: yield x", and it is completely reasonable to use it for such simple purposes. But that's not why it was added to the language, and if that's *all* it did, it probably wouldn't have been. Rather, "yield from" was added to support the full set of generator behaviour, including their send(), close() and throw() methods. That makes "yield from expr" equivalent to this rather formidable chunk of code: _i = iter(EXPR) try: _y = next(_i) except StopIteration as _e: _r = _e.value else: while 1: try: _s = yield _y except GeneratorExit as _e: try: _m = _i.close except AttributeError: pass else: _m() raise _e except BaseException as _e: _x = sys.exc_info() try: _m = _i.throw except AttributeError: raise _e else: try: _y = _m(*_x) except StopIteration as _e: _r = _e.value break else: try: if _s is None: _y = next(_i) else: _y = _i.send(_s) except StopIteration as _e: _r = _e.value break RESULT = _r See PEP 380 for more info: https://www.python.org/dev/peps/pep-0380/ -- Steven From eryksun at gmail.com Wed Apr 20 22:05:06 2016 From: eryksun at gmail.com (eryk sun) Date: Wed, 20 Apr 2016 21:05:06 -0500 Subject: Failed install scipy lib In-Reply-To: References: <08215756-d9f5-4dba-b710-ab8626ebfe27@googlegroups.com> <3b6c95df-941d-41e7-8eb5-54b266cb5ce6@googlegroups.com> Message-ID: On Wed, Apr 20, 2016 at 8:04 AM, Oscar Benjamin wrote: > On 20 April 2016 at 12:30, wrote: > >> from ._ufuncs import * >> File "scipy\special\_ufuncs.pyx", line 1, in init scipy.special._ufuncs (scipy\special\_ufuncs.c:26242) >> ImportError: DLL load failed: The specified module could not be found. > > Maybe this is the problem: > > http://stackoverflow.com/questions/36489487/error-of-import-scipy-stats-for-windows-7 Here's the link for the VC++ Redistributable for VS 2015. Try installing the 32-bit version. https://www.microsoft.com/en-us/download/details.aspx?id=48145 From steve at pearwood.info Wed Apr 20 23:07:36 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 21 Apr 2016 13:07:36 +1000 Subject: Detecting repeated subsequences of identical items Message-ID: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> I want to group repeated items in a sequence. For example, I can group repeated sequences of a single item at a time using groupby: from itertools import groupby for key, group in groupby("AAAABBCDDEEEFFFF"): group = list(group) print(key, "count =", len(group)) outputs: A count = 4 B count = 2 C count = 1 D count = 2 E count = 3 F count = 4 Now I want to group subsequences. For example, I have: "ABCABCABCDEABCDEFABCABCABCB" and I want to group it into repeating subsequences. I can see two ways to group it: ABC ABC ABCDE ABCDE F ABC ABC ABC B giving counts: (ABC) count = 2 (ABCDE) count = 2 F count = 1 (ABC) count = 3 B repeats 1 time or: ABC ABC ABC D E A B C D E F ABC ABC ABC B giving counts: (ABC) count = 3 D count = 1 E count = 1 A count = 1 B count = 1 C count = 1 D count = 1 E count = 1 F count = 1 (ABC) count = 3 B count = 1 How can I do this? Does this problem have a standard name and/or solution? -- Steven From eryksun at gmail.com Wed Apr 20 23:10:47 2016 From: eryksun at gmail.com (eryk sun) Date: Wed, 20 Apr 2016 22:10:47 -0500 Subject: Running lpr on windows from python In-Reply-To: <5717991E.70309@timgolden.me.uk> References: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> <7a7e2d01-fcf3-4f14-9531-f19a96700cf3@googlegroups.com> <5717991E.70309@timgolden.me.uk> Message-ID: On Wed, Apr 20, 2016 at 9:58 AM, Tim Golden wrote: > If it's not, then try copying the lpr.exe to c:\windows\syswow64 and try > again. (Or to some other place to which you have access). WOW64 in Windows 7+ has a virtual "SysNative" directory that accesses the native 64-bit system directory: if '32bit' in platform.architecture(): lpr = os.path.join(os.environ['SystemRoot'], 'SysNative', 'lpr.exe') else: lpr = os.path.join(os.environ['SystemRoot'], 'System32', 'lpr.exe') From ethan at stoneleaf.us Wed Apr 20 23:57:13 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 20 Apr 2016 20:57:13 -0700 Subject: Detecting repeated subsequences of identical items In-Reply-To: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57184F99.4090808@stoneleaf.us> On 04/20/2016 08:07 PM, Steven D'Aprano wrote: > Now I want to group subsequences. For example, I have: > > "ABCABCABCDEABCDEFABCABCABCB" > > and I want to group it into repeating subsequences. I can see two ways to > group it: > > ABC ABC ABCDE ABCDE F ABC ABC ABC B > > giving counts: > > (ABC) count = 2 > (ABCDE) count = 2 > F count = 1 > (ABC) count = 3 > B repeats 1 time or ABC ABC ABC D E A B C D E F ABC ABC B -- ~Ethan~ From ethan at stoneleaf.us Thu Apr 21 00:15:02 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 20 Apr 2016 21:15:02 -0700 Subject: Detecting repeated subsequences of identical items In-Reply-To: <57184F99.4090808@stoneleaf.us> References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> <57184F99.4090808@stoneleaf.us> Message-ID: <571853C6.7030707@stoneleaf.us> On 04/20/2016 08:57 PM, Ethan Furman wrote: > [snip same pattern as Steven wrote] Nevermind. It's obviously time for me to go to bed. :/ -- ~Ethan~ From rosuav at gmail.com Thu Apr 21 01:37:38 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Apr 2016 15:37:38 +1000 Subject: Detecting repeated subsequences of identical items In-Reply-To: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Apr 21, 2016 at 1:07 PM, Steven D'Aprano wrote: > Now I want to group subsequences. For example, I have: > > "ABCABCABCDEABCDEFABCABCABCB" > > and I want to group it into repeating subsequences. I can see two ways to > group it: > > ABC ABC ABCDE ABCDE F ABC ABC ABC B > > or: > > ABC ABC ABC D E A B C D E F ABC ABC ABC B Interesting. I've *almost* managed to (ab)use re.split for this purpose. A one-step solution can be done with re.match: >>> txt = "ABCABCABCDEABCDEFABCABCABCB" >>> re.match(r'(.+)\1+', txt) <_sre.SRE_Match object; span=(0, 9), match='ABCABCABC'> But split then returns only the grouped part: >>> re.split(r'(.+)\1+', txt) ['', 'ABC', 'DEABCDEF', 'ABC', 'B'] or *all* the grouped parts: >>> re.split(r'((.+)\2+)', txt) ['', 'ABCABCABC', 'ABC', 'DEABCDEF', 'ABCABCABC', 'ABC', 'B'] There's definitely a partial solution happening here, but I can't quite make it work. And no, I don't know if there's a standard name for it. ChrisA From michael.selik at gmail.com Thu Apr 21 02:35:33 2016 From: michael.selik at gmail.com (Michael Selik) Date: Thu, 21 Apr 2016 06:35:33 +0000 Subject: Detecting repeated subsequences of identical items In-Reply-To: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 20, 2016 at 11:11 PM Steven D'Aprano wrote: > I want to group [repeated] subsequences. For example, I have: > "ABCABCABCDEABCDEFABCABCABCB" > and I want to group it into repeating subsequences. I can see two > ways... How can I do this? Does this problem have a standard name and/or > solution? > I'm not aware of a standard name. This sounds like an unsupervised learning problem. There's no objectively correct answer unless you add more specificity to the problem statement. Regexes may sound tempting at first, but because a repeating subsequence may have nested repeating subsequences and this can go on infinitely, I think we at least need a push-down automata. I checked out some links for clustering algorithms that work on series subsequences and I found some fun results. Clustering is meaningless! http://www.cs.ucr.edu/~eamonn/meaningless.pdf I think you're in "no free lunch" territory. "Clustering of subsequence time series remains an open issue in time series clustering" http://www.hindawi.com/journals/tswj/2014/312521/ Any more detail on the problem to add constraints? From michael.selik at gmail.com Thu Apr 21 02:49:52 2016 From: michael.selik at gmail.com (Michael Selik) Date: Thu, 21 Apr 2016 06:49:52 +0000 Subject: Detecting repeated subsequences of identical items In-Reply-To: References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Apr 21, 2016 at 2:35 AM Michael Selik wrote: > On Wed, Apr 20, 2016 at 11:11 PM Steven D'Aprano > wrote: > >> I want to group [repeated] subsequences. For example, I have: >> "ABCABCABCDEABCDEFABCABCABCB" >> and I want to group it into repeating subsequences. I can see two >> ways... How can I do this? Does this problem have a standard name and/or >> solution? >> > > I'm not aware of a standard name. This sounds like an unsupervised > learning problem. There's no objectively correct answer unless you add more > specificity to the problem statement. > > Regexes may sound tempting at first, but because a repeating subsequence > may have nested repeating subsequences and this can go on infinitely, I > think we at least need a push-down automata. > > I checked out some links for clustering algorithms that work on series > subsequences and I found some fun results. > > Clustering is meaningless! > http://www.cs.ucr.edu/~eamonn/meaningless.pdf > > I think you're in "no free lunch" territory. "Clustering of subsequence > time series remains an open issue in time series clustering" > http://www.hindawi.com/journals/tswj/2014/312521/ > > Any more detail on the problem to add constraints? > Some light reading suggests that you can improve your problem by defining a minimum size for a subsequence to qualify. One paper suggests calling these more interesting repetitions a "motif" to use a music metaphor. Looking for any repetitions results in too many trivial results. Is that valid for your usage? From vlastimil.brom at gmail.com Thu Apr 21 02:54:04 2016 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 21 Apr 2016 08:54:04 +0200 Subject: Detecting repeated subsequences of identical items In-Reply-To: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: 2016-04-21 5:07 GMT+02:00 Steven D'Aprano : > I want to group repeated items in a sequence. For example, I can group > repeated sequences of a single item at a time using groupby: > > > from itertools import groupby > for key, group in groupby("AAAABBCDDEEEFFFF"): > group = list(group) > print(key, "count =", len(group)) > > > outputs: > > A count = 4 > B count = 2 > C count = 1 > D count = 2 > E count = 3 > F count = 4 > > > Now I want to group subsequences. For example, I have: > > "ABCABCABCDEABCDEFABCABCABCB" > > and I want to group it into repeating subsequences. I can see two ways to > group it: > > ABC ABC ABCDE ABCDE F ABC ABC ABC B > > giving counts: > > (ABC) count = 2 > (ABCDE) count = 2 > F count = 1 > (ABC) count = 3 > B repeats 1 time > > > or: > > ABC ABC ABC D E A B C D E F ABC ABC ABC B > > giving counts: > > (ABC) count = 3 > D count = 1 > E count = 1 > A count = 1 > B count = 1 > C count = 1 > D count = 1 > E count = 1 > F count = 1 > (ABC) count = 3 > B count = 1 > > > > How can I do this? Does this problem have a standard name and/or solution? > > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list Hi, if I am not missing something, the latter form of grouping might be achieved with the following regex: t="ABCABCABCDEABCDEFABCABCABCB" grouped = re.findall(r"((?:(\w+?)\2+)|\w+?)", t) print(grouped) for grp, subseq in grouped: if subseq: print(subseq, grp.count(subseq)) else: print(grp, "1") the printed output is: [('ABCABCABC', 'ABC'), ('D', ''), ('E', ''), ('A', ''), ('B', ''), ('C', ''), ('D', ''), ('E', ''), ('F', ''), ('ABCABCABC', 'ABC'), ('B', '')] ABC 3 D 1 E 1 A 1 B 1 C 1 D 1 E 1 F 1 ABC 3 B 1 The former one seems to be more tricky... hth, vbr From michael.selik at gmail.com Thu Apr 21 03:05:29 2016 From: michael.selik at gmail.com (Michael Selik) Date: Thu, 21 Apr 2016 07:05:29 +0000 Subject: Detecting repeated subsequences of identical items In-Reply-To: References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Apr 21, 2016 at 2:55 AM Vlastimil Brom wrote: > 2016-04-21 5:07 GMT+02:00 Steven D'Aprano : > > I want to group subsequences. > > "ABCABCABCDEABCDEFABCABCABCB" > > ABC ABC ABCDE ABCDE F ABC ABC ABC B > > or: > > ABC ABC ABC D E A B C D E F ABC ABC ABC B > > if I am not missing something, the latter form of grouping might be > achieved with the following regex: [snip] > The former one seems to be more tricky... > Right. If the problem is constrained to say that repeated subsequences can have no nested repeated subsequences, it's much easier to solve. If you had "ABCABCABCABC" should that result in ABC ABC ABC ABC, with 4 repetitions or ABCABC ABCABC with 2 repetitions? In this example, one might say the higher count is obviously better, but I think it depends on the context. Maybe the user is looking for the biggest patterns rather than the biggest counts. From alain at universite-de-strasbourg.fr.invalid Thu Apr 21 03:25:16 2016 From: alain at universite-de-strasbourg.fr.invalid (Alain Ketterlin) Date: Thu, 21 Apr 2016 09:25:16 +0200 Subject: Detecting repeated subsequences of identical items References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87inzbjueb.fsf@universite-de-strasbourg.fr.invalid> Steven D'Aprano writes: > I want to group repeated items in a sequence. For example, I can group > repeated sequences of a single item at a time using groupby: [...] > Now I want to group subsequences. For example, I have: > > "ABCABCABCDEABCDEFABCABCABCB" > > and I want to group it into repeating subsequences. I can see two ways to > group it: > > ABC ABC ABCDE ABCDE F ABC ABC ABC B [...] > or: > > ABC ABC ABC D E A B C D E F ABC ABC ABC B [...] > How can I do this? Does this problem have a standard name and/or solution? Looks like a tough one. I don't think it has a name (I'm not even sure to be able to formally define it). Lets say it is an instance of "longest repeating substring" (https://en.wikipedia.org/wiki/Longest_repeated_substring_problem -- which really does not say much). Anyway, it looks like a job for a suffix trees. Depending on what you are after, you may also be interested in the sequitur algorithm (http://www.sequitur.info/). -- Alain. From steve+comp.lang.python at pearwood.info Thu Apr 21 04:05:40 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 21 Apr 2016 18:05:40 +1000 Subject: Detecting repeated subsequences of identical items References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: <571889d8$0$2820$c3e8da3$76491128@news.astraweb.com> On Thursday 21 April 2016 16:35, Michael Selik wrote: > On Wed, Apr 20, 2016 at 11:11 PM Steven D'Aprano > wrote: > >> I want to group [repeated] subsequences. For example, I have: >> "ABCABCABCDEABCDEFABCABCABCB" >> and I want to group it into repeating subsequences. I can see two >> ways... How can I do this? Does this problem have a standard name and/or >> solution? >> > > I'm not aware of a standard name. This sounds like an unsupervised > learning problem. There's no objectively correct answer unless you add > more specificity to the problem statement. > > Regexes may sound tempting at first, Ah, I may have mislead you all. I cannot use regexes, since the *actual* sequences I'm working on are sequences (lists, tuples, etc) or iterators of arbitrary items. The items themselves may be strings, but the sequence itself is definitely not a string. I just showed a string for convenience. Sorry about that. So no regexes. > but because a repeating subsequence > may have nested repeating subsequences and this can go on infinitely, I > think we at least need a push-down automata. Fortunately, for my *immediate* problem, I would be good with some fairly arbitrary restrictions on subsequence detection. > I checked out some links for clustering algorithms that work on series > subsequences and I found some fun results. > > Clustering is meaningless! > http://www.cs.ucr.edu/~eamonn/meaningless.pdf > > I think you're in "no free lunch" territory. "Clustering of subsequence > time series remains an open issue in time series clustering" > http://www.hindawi.com/journals/tswj/2014/312521/ > > Any more detail on the problem to add constraints? The specific problem I am trying to solve is that I have a sequence of strings (in this case, error messages from a Python traceback) and I'm looking for repeated groups that may indicate mutually recursive calls. E.g. suppose I have a function f which calls g, and g calls h, and h calls f again, and there's an exception, you will see a traceback in part: File "", line 2, in f File "", line 5, in g File "", line 9, in h File "", line 2, in f File "", line 5, in g File "", line 9, in h File "", line 2, in f File "", line 5, in g File "", line 9, in h File "", line 7, in f File "", line 5, in g File "", line 9, in h etc. Note that I only care about lines which are identical, e.g. if the line numbers differ (as in the last call to f), they will be treated as distinct items. So I'd like to group the above as: File "", line 2, in f File "", line 5, in g File "", line 9, in h *** above 3 calls repeated 3 times *** File "", line 7, in f File "", line 5, in g File "", line 9, in h -- Steve From oscar.j.benjamin at gmail.com Thu Apr 21 04:53:04 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 21 Apr 2016 09:53:04 +0100 Subject: Detecting repeated subsequences of identical items In-Reply-To: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 21 April 2016 at 04:07, Steven D'Aprano wrote: > I want to group repeated items in a sequence. For example, I can group > repeated sequences of a single item at a time using groupby: > > > from itertools import groupby > for key, group in groupby("AAAABBCDDEEEFFFF"): > group = list(group) > print(key, "count =", len(group)) > > > outputs: > > A count = 4 > B count = 2 > C count = 1 > D count = 2 > E count = 3 > F count = 4 > > > Now I want to group subsequences. For example, I have: > > "ABCABCABCDEABCDEFABCABCABCB" > > and I want to group it into repeating subsequences. I can see two ways to > group it: > > ABC ABC ABCDE ABCDE F ABC ABC ABC B There are some algorithms (helpfully shown in Python) here: https://en.wikipedia.org/wiki/Cycle_detection Note that those are for a sequence made as x[n+1] = f(x[n]) for some function f. In your case that's just the function that gets the next frame up/down in the call stack. -- Oscar -- Oscar From erissatallan at gmail.com Thu Apr 21 05:06:54 2016 From: erissatallan at gmail.com (Allan Leo) Date: Thu, 21 Apr 2016 10:06:54 +0100 Subject: Error 0*80070570 In-Reply-To: References: Message-ID: When running the setup for your 3.5.1(32-bit version), the setup experiences error 0*80070570 and tells me to check the log file. What could be the problem and whats the solution. On Apr 21, 2016 7:05 AM, "Allan Leo" wrote: > When running the setup for your 3.5.1(32-bit version) the setup > experiences error 0*80070570 and tells me to checkout the log file. What > could be the problem and whats the resolution. > From harirammanohar at gmail.com Thu Apr 21 06:17:59 2016 From: harirammanohar at gmail.com (harirammanohar at gmail.com) Date: Thu, 21 Apr 2016 03:17:59 -0700 (PDT) Subject: delete from pattern to pattern if it contains match In-Reply-To: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> Message-ID: <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, hariram... at gmail.com wrote: > HI All, > > can you help me out in doing below. > > file: > > guava > fruit > > > mango > fruit > > > orange > fruit > > > need to delete from start to end if it contains mango in a file... > > output should be: > > > guava > fruit > > > orange > fruit > > > Thank you any one can guide me ? why xml tree parsing is not working if i have root.tag and root.attrib as mentioned in earlier post... From __peter__ at web.de Thu Apr 21 07:24:08 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 21 Apr 2016 13:24:08 +0200 Subject: delete from pattern to pattern if it contains match References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> Message-ID: harirammanohar at gmail.com wrote: > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, hariram... at gmail.com > wrote: >> HI All, >> >> can you help me out in doing below. >> >> file: >> >> guava >> fruit >> >> >> mango >> fruit >> >> >> orange >> fruit >> Is that literally what you have in the file? > any one can guide me ? why xml tree parsing is not working if i have > root.tag and root.attrib as mentioned in earlier post... The data above is not valid xml. Instead of ... you need ... i. e. the end tag must be the same as the start tag, but with a leading "/". From storchaka at gmail.com Thu Apr 21 07:56:07 2016 From: storchaka at gmail.com (Serhiy Storchaka) Date: Thu, 21 Apr 2016 14:56:07 +0300 Subject: Detecting repeated subsequences of identical items In-Reply-To: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 21.04.16 06:07, Steven D'Aprano wrote: > Now I want to group subsequences. For example, I have: > > "ABCABCABCDEABCDEFABCABCABCB" > > and I want to group it into repeating subsequences. [...] > How can I do this? Does this problem have a standard name and/or solution? This is a part of lossless data compression algorithms. See for example LZ, LZW. From nobody at nowhere.invalid Thu Apr 21 08:02:20 2016 From: nobody at nowhere.invalid (Nobody) Date: Thu, 21 Apr 2016 13:02:20 +0100 Subject: Detecting repeated subsequences of identical items References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> <571889d8$0$2820$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, 21 Apr 2016 18:05:40 +1000, Steven D'Aprano wrote: > The specific problem I am trying to solve is that I have a sequence of > strings (in this case, error messages from a Python traceback) and I'm > looking for repeated groups that may indicate mutually recursive calls. E.g. > suppose I have a function f which calls g, and g calls h, and h calls f > again, and there's an exception, you will see a traceback in part: This is a specific case of finding cycles in a directed graph. But treating it as such probably isn't useful here, because you're interested in a specific traversal of that graph rather than the graph itself. One way to approach it is: sofar = [] for line in traceback: if line in sofar: j = sofar.index(line) if sofar[:j] == sofar[j:j*2]: # found repeat sofar = [line] + sofar Note that sofar needs to be in reverse order, because list doesn't have .rindex() or .rfind(). Detecting nested cycles is somewhat harder because given e.g. ababxabababababxababab you'd want the five repeats of ab in the middle to be treated as two repeats of ab followed by three repeats of ab, but there's no way to spot that until later. From steve at pearwood.info Thu Apr 21 08:15:16 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 21 Apr 2016 22:15:16 +1000 Subject: Detecting repeated subsequences of identical items References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5718c457$0$1605$c3e8da3$5496439d@news.astraweb.com> On Thu, 21 Apr 2016 06:53 pm, Oscar Benjamin wrote: > On 21 April 2016 at 04:07, Steven D'Aprano wrote: >> I want to group repeated items in a sequence. For example, I can group >> repeated sequences of a single item at a time using groupby: >> >> >> from itertools import groupby >> for key, group in groupby("AAAABBCDDEEEFFFF"): >> group = list(group) >> print(key, "count =", len(group)) >> >> >> outputs: >> >> A count = 4 >> B count = 2 >> C count = 1 >> D count = 2 >> E count = 3 >> F count = 4 >> >> >> Now I want to group subsequences. For example, I have: >> >> "ABCABCABCDEABCDEFABCABCABCB" >> >> and I want to group it into repeating subsequences. I can see two ways to >> group it: >> >> ABC ABC ABCDE ABCDE F ABC ABC ABC B > > There are some algorithms (helpfully shown in Python) here: > > https://en.wikipedia.org/wiki/Cycle_detection It's not necessarily a cycle though. Consider a sequence of function calls: def f(x): return g(x) def g(x): if x < 7: return h(x) elif x < 50: return g(x//2) else: return x+f(x-1) def h(x): raise ValueError # oops, a bug and a function call f(54). That will result in the chain of calls: f(54) -> g(54) -> f(53) -> g(53) -> f(52) -> g(52) -> f(51) -> g(51) -> f(50) -> g(50) -> g(25) -> g(12) -> g(6) -> h(6) raises So you have that almost-cycle f calls g calls f, but it isn't periodic because you break out of it. I'd still like to detect the repeated f->g calls. -- Steven From jussi.piitulainen at helsinki.fi Thu Apr 21 09:32:46 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Thu, 21 Apr 2016 16:32:46 +0300 Subject: delete from pattern to pattern if it contains match References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> Message-ID: harirammanohar at gmail.com writes: > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, > hariram... at gmail.com wrote: >> HI All, >> >> can you help me out in doing below. >> >> file: >> >> guava >> fruit >> >> >> mango >> fruit >> >> >> orange >> fruit >> >> >> need to delete from start to end if it contains mango in a file... >> >> output should be: >> >> >> guava >> fruit >> >> >> orange >> fruit >> >> >> Thank you > > any one can guide me ? why xml tree parsing is not working if i have > root.tag and root.attrib as mentioned in earlier post... Assuming the real consists of lines between a start marker and end marker, a winning plan is to collect a group of lines, deal with it, and move on. The following code implements something close to the plan. You need to adapt it a bit to have your own source of lines and to restore the end marker in the output and to account for your real use case and for differences in taste and judgment. - The plan is as described above, but there are many ways to implement it. from io import StringIO text = '''\ guava fruit mango fruit orange fruit ''' def records(source): current = [] for line in source: if line.startswith(''): yield current current = [] else: current.append(line) def hasmango(record): return any('mango' in it for it in record) for record in records(StringIO(text)): hasmango(record) or print(*record) From oscar.j.benjamin at gmail.com Thu Apr 21 10:01:27 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 21 Apr 2016 15:01:27 +0100 Subject: Detecting repeated subsequences of identical items In-Reply-To: <5718c457$0$1605$c3e8da3$5496439d@news.astraweb.com> References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> <5718c457$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 21 April 2016 at 13:15, Steven D'Aprano wrote: > On Thu, 21 Apr 2016 06:53 pm, Oscar Benjamin wrote: > >> On 21 April 2016 at 04:07, Steven D'Aprano wrote: >>> I want to group repeated items in a sequence. For example, I can group >>> repeated sequences of a single item at a time using groupby: >>> >>> >>> from itertools import groupby >>> for key, group in groupby("AAAABBCDDEEEFFFF"): >>> group = list(group) >>> print(key, "count =", len(group)) >>> >>> >>> outputs: >>> >>> A count = 4 >>> B count = 2 >>> C count = 1 >>> D count = 2 >>> E count = 3 >>> F count = 4 >>> >>> >>> Now I want to group subsequences. For example, I have: >>> >>> "ABCABCABCDEABCDEFABCABCABCB" >>> >>> and I want to group it into repeating subsequences. I can see two ways to >>> group it: >>> >>> ABC ABC ABCDE ABCDE F ABC ABC ABC B >> >> There are some algorithms (helpfully shown in Python) here: >> >> https://en.wikipedia.org/wiki/Cycle_detection > > It's not necessarily a cycle though. Consider a sequence of function calls: > > def f(x): > return g(x) > > def g(x): > if x < 7: > return h(x) > elif x < 50: > return g(x//2) > else: > return x+f(x-1) > > def h(x): > raise ValueError # oops, a bug > > > and a function call f(54). That will result in the chain of calls: > > f(54) -> g(54) -> f(53) -> g(53) -> f(52) -> g(52) -> f(51) -> g(51) -> > f(50) -> g(50) -> g(25) -> g(12) -> g(6) -> h(6) raises > > So you have that almost-cycle f calls g calls f, but it isn't periodic > because you break out of it. I'd still like to detect the repeated f->g > calls. It doesn't matter that you break out of it. It's periodic for some part and the algorithms listed on that page can find the cycle. In the recursive stack overflow case what you'll usually have is 1) A few frames leading up to the start of recursion 2) A long repetitive sequence of frames 3) A few frames at the end showing how the exception was ultimately triggered. You just need to find the cycle that makes that big long sequence. -- Oscar From rosuav at gmail.com Thu Apr 21 10:12:23 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Apr 2016 00:12:23 +1000 Subject: Detecting repeated subsequences of identical items In-Reply-To: References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> <5718c457$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 22, 2016 at 12:01 AM, Oscar Benjamin wrote: > In the recursive stack overflow case what you'll usually have is > > 1) A few frames leading up to the start of recursion > 2) A long repetitive sequence of frames > 3) A few frames at the end showing how the exception was ultimately triggered. > > You just need to find the cycle that makes that big long sequence. If the stack got overflowed, there won't usually be a part 3, as part 2 is the bit that hits sys.recursionlimit (unless increasing the recursion limit by a finite number would solve the problem). For other exceptions, yes, this is what you'd see. ChrisA From oscar.j.benjamin at gmail.com Thu Apr 21 10:30:36 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 21 Apr 2016 15:30:36 +0100 Subject: Detecting repeated subsequences of identical items In-Reply-To: References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> <5718c457$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 21 April 2016 at 15:12, Chris Angelico wrote: > On Fri, Apr 22, 2016 at 12:01 AM, Oscar Benjamin > wrote: >> In the recursive stack overflow case what you'll usually have is >> >> 1) A few frames leading up to the start of recursion >> 2) A long repetitive sequence of frames >> 3) A few frames at the end showing how the exception was ultimately triggered. >> >> You just need to find the cycle that makes that big long sequence. > > If the stack got overflowed, there won't usually be a part 3, as part > 2 is the bit that hits sys.recursionlimit (unless increasing the > recursion limit by a finite number would solve the problem). For other > exceptions, yes, this is what you'd see. If you have: def f(x): return g(x+1) def g(x): x = h(x) # <-- stack can overflow inside here return f(x+1) # etc. So you have a long sequence that goes f, g, f, g but at the end the stack can overflow while (not recursively) calling h leaving a small non-cyclic part at the end. -- Oscar From rosuav at gmail.com Thu Apr 21 11:02:27 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Apr 2016 01:02:27 +1000 Subject: Detecting repeated subsequences of identical items In-Reply-To: References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> <5718c457$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 22, 2016 at 12:30 AM, Oscar Benjamin wrote: > On 21 April 2016 at 15:12, Chris Angelico wrote: >> On Fri, Apr 22, 2016 at 12:01 AM, Oscar Benjamin >> wrote: >>> In the recursive stack overflow case what you'll usually have is >>> >>> 1) A few frames leading up to the start of recursion >>> 2) A long repetitive sequence of frames >>> 3) A few frames at the end showing how the exception was ultimately triggered. >>> >>> You just need to find the cycle that makes that big long sequence. >> >> If the stack got overflowed, there won't usually be a part 3, as part >> 2 is the bit that hits sys.recursionlimit (unless increasing the >> recursion limit by a finite number would solve the problem). For other >> exceptions, yes, this is what you'd see. > > If you have: > > def f(x): > return g(x+1) > > def g(x): > x = h(x) # <-- stack can overflow inside here > return f(x+1) > > # etc. > > So you have a long sequence that goes f, g, f, g but at the end the > stack can overflow while (not recursively) calling h leaving a small > non-cyclic part at the end. Right, good point. Forgot about that. So this situation can be triggered by anywhere up to lines up. Not as helpful an optimization now. Oh well. ChrisA From walters.justin01 at gmail.com Thu Apr 21 11:19:44 2016 From: walters.justin01 at gmail.com (justin walters) Date: Thu, 21 Apr 2016 08:19:44 -0700 Subject: PEP proposal: sequence expansion support for yield statement: yield * In-Reply-To: <57181d0e$0$1591$c3e8da3$5496439d@news.astraweb.com> References: <573e61523bfc412ca8674b06d70f2fd7@sraex01sc.sisa.samsung.com> <57181d0e$0$1591$c3e8da3$5496439d@news.astraweb.com> Message-ID: I agree with the others that the new syntax is not needed. I would also like to point out that I believe any new added syntax or functionality should avoid the use of '*' and '**' as both of these characters are already used for many things such as optional arguments and mathematical operators. Adding more uses for said characters only decreases the readability of the code. From walters.justin01 at gmail.com Thu Apr 21 11:20:36 2016 From: walters.justin01 at gmail.com (justin walters) Date: Thu, 21 Apr 2016 08:20:36 -0700 Subject: Error 0*80070570 In-Reply-To: References: Message-ID: On Thu, Apr 21, 2016 at 2:06 AM, Allan Leo wrote: > When running the setup for your 3.5.1(32-bit version), the setup > experiences error 0*80070570 and tells me to check the log file. What could > be the problem and whats the solution. > On Apr 21, 2016 7:05 AM, "Allan Leo" wrote: > > > When running the setup for your 3.5.1(32-bit version) the setup > > experiences error 0*80070570 and tells me to checkout the log file. What > > could be the problem and whats the resolution. > > > -- > https://mail.python.org/mailman/listinfo/python-list > Have you tried checking the log file or googling the error code? From rosuav at gmail.com Thu Apr 21 11:26:46 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Apr 2016 01:26:46 +1000 Subject: PEP proposal: sequence expansion support for yield statement: yield * In-Reply-To: References: <573e61523bfc412ca8674b06d70f2fd7@sraex01sc.sisa.samsung.com> <57181d0e$0$1591$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 22, 2016 at 1:19 AM, justin walters wrote: > I agree with the others that the new syntax is not needed. > > I would also like to point out that I believe any new added syntax or > functionality should avoid the use of '*' and '**' as both of these > characters are already used for many things such as optional arguments and > mathematical operators. Adding more uses for said characters only decreases > the readability of the code. The single asterisk is used for packing and unpacking, though. See PEP 448 [1] for some of the ways this can be used (in the context of "the ways this can NOW be used in Python 3.5"). So the proposed "yield *sequence" does make good sense; however, "yield from" has, as Steven pointed out, *far* more detailed semantics, as it basically allows generators to be refactored, with all their semantics (yield, send, throw, return). ChrisA [1] https://www.python.org/dev/peps/pep-0448/ From random832 at fastmail.com Thu Apr 21 12:35:56 2016 From: random832 at fastmail.com (Random832) Date: Thu, 21 Apr 2016 12:35:56 -0400 Subject: How are you supposed to define subclasses in C? Message-ID: <1461256556.38223.585724489.051B2155@webmail.messagingengine.com> I was trying to write a proof of concept on including descriptors (e.g. a "sys.recursionlimit" instead of set/get methods) in the sys module, and couldn't figure out how to "properly" define a type using PyType_FromSpecWithBases. Everything I tried just segfaulted. I ended up just calling PyObject_CallFunctionObjArgs((PyObject *)&PyType_Type, ...) but I assume there's a better way to do it. I couldn't find any examples or tutorial. From zachary.ware+pylist at gmail.com Thu Apr 21 12:39:09 2016 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Thu, 21 Apr 2016 11:39:09 -0500 Subject: How are you supposed to define subclasses in C? In-Reply-To: <1461256556.38223.585724489.051B2155@webmail.messagingengine.com> References: <1461256556.38223.585724489.051B2155@webmail.messagingengine.com> Message-ID: On Thu, Apr 21, 2016 at 11:35 AM, Random832 wrote: > I was trying to write a proof of concept on including descriptors (e.g. > a "sys.recursionlimit" instead of set/get methods) in the sys module, > and couldn't figure out how to "properly" define a type using > PyType_FromSpecWithBases. Everything I tried just segfaulted. I ended up > just calling PyObject_CallFunctionObjArgs((PyObject *)&PyType_Type, ...) > but I assume there's a better way to do it. I couldn't find any examples > or tutorial. Have a look at https://hg.python.org/cpython/file/default/Modules/xxsubtype.c -- Zach From erissatallan at gmail.com Thu Apr 21 13:46:45 2016 From: erissatallan at gmail.com (Allan Leo) Date: Thu, 21 Apr 2016 18:46:45 +0100 Subject: Fwd: Re: Error 0*80070570 In-Reply-To: References: Message-ID: I need help with this setup error. ---------- Forwarded message ---------- From: "Allan Leo" Date: Apr 21, 2016 10:06 AM Subject: Re: Error 0*80070570 To: Cc: When running the setup for your 3.5.1(32-bit version), the setup experiences error 0*80070570 and tells me to check the log file. What could be the problem and whats the solution. On Apr 21, 2016 7:05 AM, "Allan Leo" wrote: > When running the setup for your 3.5.1(32-bit version) the setup > experiences error 0*80070570 and tells me to checkout the log file. What > could be the problem and whats the resolution. > From stefan_ml at behnel.de Thu Apr 21 13:56:19 2016 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 21 Apr 2016 19:56:19 +0200 Subject: How are you supposed to define subclasses in C? In-Reply-To: <1461256556.38223.585724489.051B2155@webmail.messagingengine.com> References: <1461256556.38223.585724489.051B2155@webmail.messagingengine.com> Message-ID: Random832 schrieb am 21.04.2016 um 18:35: > I was trying to write a proof of concept on including descriptors (e.g. > a "sys.recursionlimit" instead of set/get methods) in the sys module, > and couldn't figure out how to "properly" define a type using > PyType_FromSpecWithBases. Everything I tried just segfaulted. I ended up > just calling PyObject_CallFunctionObjArgs((PyObject *)&PyType_Type, ...) > but I assume there's a better way to do it. I couldn't find any examples > or tutorial. I suppose you might find Cython useful: http://cython.org/ http://docs.cython.org/ In a nutshell, it lets you write beautiful Python code instead of ugly C code full of leaks and crashes, and then takes care of making it faster than the usual C-API calls you'd write by hand. It has some extended syntax for extension types and other C-ish things to make their usage explicit. Stefan From me at ixokai.io Thu Apr 21 14:47:08 2016 From: me at ixokai.io (Stephen Hansen) Date: Thu, 21 Apr 2016 11:47:08 -0700 Subject: Fwd: Re: Error 0*80070570 In-Reply-To: References: Message-ID: <1461264428.338499.585857225.582D6DE0@webmail.messagingengine.com> On Thu, Apr 21, 2016, at 10:46 AM, Allan Leo wrote: > I need help with this setup error. > ---------- Forwarded message ---------- > From: "Allan Leo" > Date: Apr 21, 2016 10:06 AM > Subject: Re: Error 0*80070570 > To: > Cc: > > When running the setup for your 3.5.1(32-bit version), the setup > experiences error 0*80070570 and tells me to check the log file. What > could > be the problem and whats the solution. > On Apr 21, 2016 7:05 AM, "Allan Leo" wrote: > > > When running the setup for your 3.5.1(32-bit version) the setup > > experiences error 0*80070570 and tells me to checkout the log file. What > > could be the problem and whats the resolution. What version of windows? From joel.goldstick at gmail.com Thu Apr 21 15:27:27 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 21 Apr 2016 15:27:27 -0400 Subject: python regex dna processing Message-ID: >From time to time there are DNA related question posted here. I came upon this in the hopes it may be useful to those who do that kind of software http://benchling.engineering/dna-regex-search/ -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From eliz at gnu.org Thu Apr 21 15:40:17 2016 From: eliz at gnu.org (Eli Zaretskii) Date: Thu, 21 Apr 2016 22:40:17 +0300 Subject: Different names for Unicode codepoint In-Reply-To: <87wpnqsrzz.fsf@metapensiero.it> (message from Lele Gaifax on Thu, 21 Apr 2016 21:04:32 +0200) References: <87wpnqsrzz.fsf@metapensiero.it> Message-ID: <83h9eu699a.fsf@gnu.org> > From: Lele Gaifax > Date: Thu, 21 Apr 2016 21:04:32 +0200 > Cc: python-list at python.org > > is there a particular reason for the slightly different names that Emacs > (version 25.0.92) and Python (version 3.6.0a0) give to a single Unicode entity? They don't. > Just to mention one codepoint, ? is called "LESS THAN WITH DOT" accordingly to > Emacs' C-x 8 RET TAB menu, while in Python: > > >>> import unicodedata > >>> unicodedata.name('?') > 'LESS-THAN WITH DOT' > >>> print("\N{LESS THAN WITH DOT}") > File "", line 1 > SyntaxError: (unicode error) ...: unknown Unicode character name Emacs shows both the "Name" and the "Old Name" properties of characters as completion candidates, while Python evidently supports only "Name". If you type "C-x 8 RET LESS TAB", then you will see among the completion candidates both "LESS THAN WITH DOT" and "LESS-THAN WITH DOT". The former is the "old name" of this character, according to the Unicode Character Database (which is where Emacs obtains the names and other properties of characters). From sohcahtoa82 at gmail.com Thu Apr 21 16:29:11 2016 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Thu, 21 Apr 2016 13:29:11 -0700 (PDT) Subject: Error 0*80070570 In-Reply-To: References: Message-ID: On Thursday, April 21, 2016 at 10:47:04 AM UTC-7, Allan Leo wrote: > I need help with this setup error. > ---------- Forwarded message ---------- > From: "Allan Leo" > Date: Apr 21, 2016 10:06 AM > Subject: Re: Error 0*80070570 > To: > Cc: > > When running the setup for your 3.5.1(32-bit version), the setup > experiences error 0*80070570 and tells me to check the log file. What could > be the problem and whats the solution. > On Apr 21, 2016 7:05 AM, "Allan Leo" wrote: > > > When running the setup for your 3.5.1(32-bit version) the setup > > experiences error 0*80070570 and tells me to checkout the log file. What > > could be the problem and whats the resolution. > > Justin already gave you something to try: read the log file and search Google for the error code. How about you try those before asking a FOURTH time? I'll even give you a handy link so you don't have to search yourself: http://lmgtfy.com/?q=0x80070570+error+when+installing+python From eryksun at gmail.com Thu Apr 21 16:51:03 2016 From: eryksun at gmail.com (eryk sun) Date: Thu, 21 Apr 2016 15:51:03 -0500 Subject: Error 0*80070570 In-Reply-To: References: Message-ID: On Thu, Apr 21, 2016 at 4:06 AM, Allan Leo wrote: > When running the setup for your 3.5.1(32-bit version), the setup > experiences error 0*80070570 and tells me to check the log file. What could > be the problem and whats the solution. ERROR_FILE_CORRUPT (0x0570) seems to occur frequently with the new installer. Are you using the web installer or the offline installer, i.e. what's the name of the file you downloaded? What version of Windows do you have, i.e. what does running "ver" print in the command prompt? Or, in more detail, what does the following print? wmic os get buildnumber,caption,csdversion,osarchitecture /value From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Thu Apr 21 17:43:05 2016 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Thu, 21 Apr 2016 22:43:05 +0100 Subject: A pickle problem! Message-ID: Hi. Why in this code fragment self.__name is not kept between pickle dumps/loads? How to fix it? Thanks. import pickle import pandas as pd import numpy as np class C(pd.DataFrame): def __init__(self,name,*a,**b): super(C,self).__init__(*a,**b) self.__name=name def GetName(self): return self.__name dates = pd.date_range('20130101', periods=6) c = C("FOO",np.random.randn(6,4), index=dates, columns=list('ABCD')) cd=pickle.dumps(c,pickle.HIGHEST_PROTOCOL) d=pickle.loads(cd) d.GetName() # AttributeError: 'C' object has no attribute '_C__name' From christopher_reimer at icloud.com Thu Apr 21 21:34:59 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Thu, 21 Apr 2016 18:34:59 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <57185E88.30201@yahoo.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> Message-ID: <57197FC3.4030701@icloud.com> Greetings, Thanks to everyone for providing feedback. Here's my revised code to generate a set of chess pieces. class PieceFactory(object): def factory(color, piece, position): if piece == 'Bishop': return Bishop(color, position) if piece == 'King': return King(color, position) if piece == 'Knight': return Knight(color, position) if piece == 'Pawn': return Pawn(color, position) if piece == 'Queen': return Queen(color, position) if piece == 'Rook': return Rook(color, position) raise PieceException('No valid Piece object for factory, got {}' ' instead'.format(piece)) factory = staticmethod(factory) def generate_set(color, pieces, positions): for piece, position in zip(pieces, positions): yield getattr(PieceFactory, 'factory')(color, piece, position) The input values for 'pieces' and 'positions' are 16-item lists zipped together to produce a piece name and a position coordinate for the factory method. With slight modifications to the code, the factory method could also return checker pieces. I got the factory method from here: http://python-3-patterns-idioms-test.readthedocs.org/en/latest/Factory.html I do plan to incorporate a sanity test in each Piece class to validate the initial position value. Pawns have 16 specific positions. Bishop, Knight and Rook each have four specific positions. King and Queen each have two specific positions. An invalid value will raise an exception. Finally, VARS['VARIABLE_NAME'] got change to const['variable_name']. Should smell better. Thanks, Chris R From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Thu Apr 21 21:52:27 2016 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Fri, 22 Apr 2016 02:52:27 +0100 Subject: A pickle problem! References: Message-ID: ?s 22:43 de 21-04-2016, Paulo da Silva escreveu: > Hi. > > Why in this code fragment self.__name is not kept between pickle > dumps/loads? How to fix it? > > Thanks. > > import pickle > import pandas as pd > import numpy as np > > class C(pd.DataFrame): > def __init__(self,name,*a,**b): > super(C,self).__init__(*a,**b) > self.__name=name > > def GetName(self): > return self.__name > # Adding this works but looks tricky! def __getstate__(self): dfstate=super(C,self).__getstate__() cstate=(dfstate,self.__name) return cstate def __setstate__(self,cstate): super(C,self).__setstate__(cstate[0]) self.__name=cstate[1] > > dates = pd.date_range('20130101', periods=6) > c = C("FOO",np.random.randn(6,4), index=dates, columns=list('ABCD')) > > cd=pickle.dumps(c,pickle.HIGHEST_PROTOCOL) > > d=pickle.loads(cd) > > d.GetName() > > # AttributeError: 'C' object has no attribute '_C__name' > From python.list at tim.thechases.com Thu Apr 21 21:54:59 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 21 Apr 2016 20:54:59 -0500 Subject: How much sanity checking is required for function inputs? In-Reply-To: <57197FC3.4030701@icloud.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> Message-ID: <20160421205459.23db0082@bigbox.christie.dr> On 2016-04-21 18:34, Christopher Reimer wrote: > class PieceFactory(object): > > def factory(color, piece, position): > if piece == 'Bishop': > return Bishop(color, position) > if piece == 'King': > return King(color, position) > if piece == 'Knight': > return Knight(color, position) > if piece == 'Pawn': > return Pawn(color, position) > if piece == 'Queen': > return Queen(color, position) > if piece == 'Rook': > return Rook(color, position) > > raise PieceException('No valid Piece object for > factory, got {}' > ' instead'.format(piece)) > > factory = staticmethod(factory) I'd simplify this code to something like class PieceFactory(object): @staticmethod def factory(color, piece, position): try: return { 'Bishop': Bishop, 'King': King, 'Knight': Knight, 'Pawn': Pawn, 'Queen': Queen, 'Rook': Rook, }[piece](color, position) except KeyError: raise PieceException(...) which removes some of the redundancy. I might even be tempted to simply ignore the exception and let the KeyError percolate up the call-stack if someone calls it with an unknown piece/key, rather than converting it into a PieceException. -tkc From ethan at stoneleaf.us Thu Apr 21 22:10:47 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 21 Apr 2016 19:10:47 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <57197FC3.4030701@icloud.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> Message-ID: <57198827.1020608@stoneleaf.us> On 04/21/2016 06:34 PM, Christopher Reimer wrote: > class PieceFactory(object): > [...] Better. > I do plan to incorporate a sanity test in each Piece class to validate > the initial position value. Pawns have 16 specific positions. Bishop, > Knight and Rook each have four specific positions. King and Queen each > have two specific positions. An invalid value will raise an exception. This will make it so you cannot use your PieceFactory for custom setups. -- ~Ethan~ From me at ixokai.io Thu Apr 21 22:20:13 2016 From: me at ixokai.io (Stephen Hansen) Date: Thu, 21 Apr 2016 19:20:13 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <57197FC3.4030701@icloud.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> Message-ID: <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> On Thu, Apr 21, 2016, at 06:34 PM, Christopher Reimer wrote: > class PieceFactory(object): > > def factory(color, piece, position): > if piece == 'Bishop': > return Bishop(color, position) > if piece == 'King': > return King(color, position) > if piece == 'Knight': > return Knight(color, position) > if piece == 'Pawn': > return Pawn(color, position) > if piece == 'Queen': > return Queen(color, position) > if piece == 'Rook': > return Rook(color, position) This whole section is begging for a dictionary. Like... _PIECE_TYPES= {"Bishop": Bishop, "King": King, ...] class PieceFactory(object): def factory(color, piece, position): klass = __PIECE_TYPES.get(piece) if klass is None: raise PieceException("...") return klass(color, position) Or something like that. That said, I'm not sure why its not just a function that does the same thing. Why is it in a class that only does one thing? You never even instantiate it. > def generate_set(color, pieces, positions): > for piece, position in zip(pieces, positions): > yield getattr(PieceFactory, 'factory')(color, piece, position) Whyyy are you using getattr? Something wrong with PieceFactory.factory(color, piece, position)? (Or, better yet, yield piece_factory(color, piece, position) where piece_factory is just a function) > I got the factory method from here: > http://python-3-patterns-idioms-test.readthedocs.org/en/latest/Factory.html I... that... what... I'd forget that link and pretend you never went there. Its not helpful. > Finally, VARS['VARIABLE_NAME'] got change to const['variable_name']. > Should smell better. I don't know that this changes anything about the small at all. What's the contents of this big dictionary that has everything in it for some reason? That said, dear god, 'piece' doesn't look like an english word to me anymore. I've never suffered semantic satiation from text before. --Stephen m e @ i x o k a i . i o From steve at pearwood.info Thu Apr 21 22:22:09 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 22 Apr 2016 12:22:09 +1000 Subject: How much sanity checking is required for function inputs? References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> Message-ID: <57198ad3$0$1604$c3e8da3$5496439d@news.astraweb.com> On Fri, 22 Apr 2016 11:34 am, Christopher Reimer wrote: > Greetings, > > Thanks to everyone for providing feedback. Here's my revised code to > generate a set of chess pieces. > class PieceFactory(object): > > def factory(color, piece, position): > if piece == 'Bishop': > return Bishop(color, position) > if piece == 'King': > return King(color, position) > if piece == 'Knight': > return Knight(color, position) > if piece == 'Pawn': > return Pawn(color, position) > if piece == 'Queen': > return Queen(color, position) > if piece == 'Rook': > return Rook(color, position) > > raise PieceException('No valid Piece object for factory, > got {}' > ' instead'.format(piece)) > > factory = staticmethod(factory) Eww :-) Creating an entire class with no state just to hold one method is an abuse of classes. If your class doesn't include both state (data) and behaviour (methods), it probably shouldn't be a class. class King: ... class Queeen: ... # etc. PIECES = dict((piece.__name__, piece) for piece in [King, Queen, Bishop, Knight, Rook, Pawn]) def make_piece(color, name, position): name = name.title() # Accept 'king', 'KING', 'King' etc. P = PIECES.get(name, None) if P is None: raise PieceException('unknown name %r' % name) return P(color, position) > def generate_set(color, pieces, positions): > for piece, position in zip(pieces, positions): > yield getattr(PieceFactory, 'factory')(color, piece, position) def generate_pieces(color, names, positions): for name, position in zip(names, positions): yield make_piece(color, name, position) -- Steven From christopher_reimer at icloud.com Thu Apr 21 22:55:18 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Thu, 21 Apr 2016 19:55:18 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <20160421205459.23db0082@bigbox.christie.dr> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <20160421205459.23db0082@bigbox.christie.dr> Message-ID: <57199296.4000404@icloud.com> On 4/21/2016 6:54 PM, Tim Chase wrote: > > I'd simplify this code to something like > > class PieceFactory(object): > @staticmethod > def factory(color, piece, position): > try: > return { > 'Bishop': Bishop, > 'King': King, > 'Knight': Knight, > 'Pawn': Pawn, > 'Queen': Queen, > 'Rook': Rook, > }[piece](color, position) > except KeyError: > raise PieceException(...) I like this better. I'll probably remove the try/except and let the KeyError filter up. Thanks, Chris R. From christopher_reimer at icloud.com Thu Apr 21 23:11:10 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Thu, 21 Apr 2016 20:11:10 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <57198827.1020608@stoneleaf.us> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <57198827.1020608@stoneleaf.us> Message-ID: <5719964E.2050400@icloud.com> On 4/21/2016 7:10 PM, Ethan Furman wrote: >> I do plan to incorporate a sanity test in each Piece class to validate >> the initial position value. Pawns have 16 specific positions. Bishop, >> Knight and Rook each have four specific positions. King and Queen each >> have two specific positions. An invalid value will raise an exception. > > This will make it so you cannot use your PieceFactory for custom setups. > The sanity check won't be in the PieceFactory, but in the Piece class as an interface and each Piece subclass will implement the correct positions for comparison. Thank you, Chris R. From christopher_reimer at icloud.com Thu Apr 21 23:33:57 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Thu, 21 Apr 2016 20:33:57 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> Message-ID: <57199BA5.4000703@icloud.com> On 4/21/2016 7:20 PM, Stephen Hansen wrote: > Whyyy are you using getattr? Something wrong with > PieceFactory.factory(color, piece, position)? (Or, better yet, yield > piece_factory(color, piece, position) where piece_factory is just a > function) Because the example I found used it, I implemented it, and it worked in my code. Based on feedback that I gotten from this list, I'll go back and clean it up. > I... that... what... I'd forget that link and pretend you never went > there. Its not helpful. I found it on the Internet, so it must be true -- and Pythonic at that! > What's the contents of this big dictionary that has everything in it > for some reason? Keep in mind that I'm coming from a Java background (not by choice) with a smattering of C programming. I initially had ALL THESE CONSTANTS in different parts of my code and couldn't easily use them across different modules. I didn't like all these constants, created a singleton class that uses ConfigParser, dumped everything into a .ini file, and accessed from in each module. As I learn to write Pythonic code, the constants may go away. Switching from my original code to the factory method eliminated a half-dozen constants. Thank you, Chris R. From ethan at stoneleaf.us Fri Apr 22 00:46:51 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 21 Apr 2016 21:46:51 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <57199BA5.4000703@icloud.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> Message-ID: <5719ACBB.8020905@stoneleaf.us> On 04/21/2016 08:33 PM, Christopher Reimer wrote: > On 4/21/2016 7:20 PM, Stephen Hansen wrote: > Keep in mind that I'm coming from a Java background (not by choice) with > a smattering of C programming. A refugee! Water! Food! import this!! :) Oh! and Enum!!! ;) -- ~Ethan~ From eryksun at gmail.com Fri Apr 22 01:06:08 2016 From: eryksun at gmail.com (eryk sun) Date: Fri, 22 Apr 2016 00:06:08 -0500 Subject: Error 0*80070570 In-Reply-To: References: Message-ID: On Thu, Apr 21, 2016 at 11:15 PM, Allan Leo wrote: > On Apr 21, 2016 9:51 PM, "eryk sun" wrote: >> On Thu, Apr 21, 2016 at 4:06 AM, Allan Leo wrote: >> > When running the setup for your 3.5.1(32-bit version), the setup >> > experiences error 0*80070570 and tells me to check the log file. What >> > could be the problem and whats the solution. >> >> ERROR_FILE_CORRUPT (0x0570) seems to occur frequently with the new >> installer. Are you using the web installer or the offline installer, >> i.e. what's the name of the file you downloaded? What version of >> Windows do you have, i.e. what does running "ver" print in the command >> prompt? Or, in more detail, what does the following print? >> >> wmic os get buildnumber,caption,csdversion,osarchitecture /value > > I'm using the offline installer, windows 7 pro, Java-8u92-windows-i586.exe. The 32-bit offline installer is named "python-3.5.1.exe". Delete the copy you downloaded, clear your browser cache, and try again. From me at ixokai.io Fri Apr 22 01:25:24 2016 From: me at ixokai.io (Stephen Hansen) Date: Thu, 21 Apr 2016 22:25:24 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <57199BA5.4000703@icloud.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> Message-ID: <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> On Thu, Apr 21, 2016, at 08:33 PM, Christopher Reimer wrote: > On 4/21/2016 7:20 PM, Stephen Hansen wrote: > > I... that... what... I'd forget that link and pretend you never went > > there. Its not helpful. > > I found it on the Internet, so it must be true -- and Pythonic at that! My advice is to not look at that site further. I can't count the number of things that are just... not useful or helpful. Directly translating the Gang of Four Design Pattern book to Python doesn't generally result in useful ideas, except in certain abstractions like the visitor pattern when you're designing big systems. > > > What's the contents of this big dictionary that has everything in it > > for some reason? > > Keep in mind that I'm coming from a Java background (not by choice) with > a smattering of C programming. I initially had ALL THESE CONSTANTS in > different parts of my code and couldn't easily use them across different > modules. I didn't like all these constants, created a singleton class > that uses ConfigParser, dumped everything into a .ini file, and accessed > from in each module. As I learn to write Pythonic code, the constants > may go away. Switching from my original code to the factory method > eliminated a half-dozen constants. I'm not criticizing, I'm *asking* in the hopes you'll explain what you're doing better, so I can understand and give advice that's more relevant: I don't understand what it is you're doing with the VARS or const dictionary. Even with your explanation here, I don't get it. Why do you need to read VARS["COLOR_BLACK"] or the new const["COLOR_BLACK"} from a configuration file? How is this stuff configurable? Why not, 'color in ("black", "white")'? The only reason I can think of why you'd want to read what is "black" or "white" out of a configuration file is internationalization, and if that's your aim, there's a couple really good projects I can recommend that solve that issue better. I can't think of any reason why you'd want a structure like: struct = {} struct["COLOR_BLACK"] = "black" struct["COLOR_WHITE"] = "white" "black" is a perfectly good way to express "black", you have this indirection/abstraction for a reason I don't understand. Granted, maybe this is a heavy javaism, and I'm utterly ignorant of Java, but my C/C++ mind can't think of a reason for this either. That said, if you're wanting to share constants across different parts of your code, use a module. Create a module, say, things.py, that itself doesn't import other things, and it says: black = "Black" white = "White" (Bear in mind I still don't know why you want or need this indirection) Then you "import things" and refer to those constants as things.black, things.white. You can then "if color in (things.black, things.white)". Maybe even "if color in things.colors" if in your things file you have things = (black, white). Modules are great for sharing information. The admonition of GLOBALS R BAD is not as strong in Python as you find in some other languages. (Don't take that to mean GLOBALS R GUD, granted. Passing state is best when it makes sense). --S m e @ i x o k a i . i o From dreamcreator2000 at gmail.com Fri Apr 22 04:07:00 2016 From: dreamcreator2000 at gmail.com (Kiril Bard) Date: Fri, 22 Apr 2016 02:07:00 -0600 Subject: a problem with importing pygame Message-ID: I use python for my school work and I wanted to download it at home. I had my teacher download the version to a flash drive and it still doesn't seem to work. The version that I got from the flash drive was python 3.4.2 and I think I got a 32 bit or a 64 bit pygame for a windows machine. The program does not import pygame, it says that there is no module named pygame. From harirammanohar at gmail.com Fri Apr 22 04:59:09 2016 From: harirammanohar at gmail.com (harirammanohar at gmail.com) Date: Fri, 22 Apr 2016 01:59:09 -0700 (PDT) Subject: delete from pattern to pattern if it contains match In-Reply-To: References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> Message-ID: <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> On Thursday, April 21, 2016 at 7:03:00 PM UTC+5:30, Jussi Piitulainen wrote: > harirammanohar at gmail.com writes: > > > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, > > hariram... at gmail.com wrote: > >> HI All, > >> > >> can you help me out in doing below. > >> > >> file: > >> > >> guava > >> fruit > >> > >> > >> mango > >> fruit > >> > >> > >> orange > >> fruit > >> > >> > >> need to delete from start to end if it contains mango in a file... > >> > >> output should be: > >> > >> > >> guava > >> fruit > >> > >> > >> orange > >> fruit > >> > >> > >> Thank you > > > > any one can guide me ? why xml tree parsing is not working if i have > > root.tag and root.attrib as mentioned in earlier post... > > Assuming the real consists of lines between a start marker and end > marker, a winning plan is to collect a group of lines, deal with it, and > move on. > > The following code implements something close to the plan. You need to > adapt it a bit to have your own source of lines and to restore the end > marker in the output and to account for your real use case and for > differences in taste and judgment. - The plan is as described above, but > there are many ways to implement it. > > from io import StringIO > > text = '''\ > > guava > fruit > > > mango > fruit > > > orange > fruit > > ''' > > def records(source): > current = [] > for line in source: > if line.startswith(''): > yield current > current = [] > else: > current.append(line) > > def hasmango(record): > return any('mango' in it for it in record) > > for record in records(StringIO(text)): > hasmango(record) or print(*record) Hi, not working....this is the output i am getting... \ guava fruit orange fruit From harirammanohar at gmail.com Fri Apr 22 05:00:30 2016 From: harirammanohar at gmail.com (harirammanohar at gmail.com) Date: Fri, 22 Apr 2016 02:00:30 -0700 (PDT) Subject: delete from pattern to pattern if it contains match In-Reply-To: References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> Message-ID: <7fc52496-baf8-41ef-8f5e-76d409c6df84@googlegroups.com> On Thursday, April 21, 2016 at 4:55:18 PM UTC+5:30, Peter Otten wrote: > harirammanohar at gmail.com wrote: > > > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, hariram... at gmail.com > > wrote: > >> HI All, > >> > >> can you help me out in doing below. > >> > >> file: > >> > >> guava > >> fruit > >> > >> > >> mango > >> fruit > >> > >> > >> orange > >> fruit > >> > > Is that literally what you have in the file? > > > any one can guide me ? why xml tree parsing is not working if i have > > root.tag and root.attrib as mentioned in earlier post... > > The data above is not valid xml. Instead of > > ... > > you need > > ... > > i. e. the end tag must be the same as the start tag, but with a leading "/". @peter yes here it is not xml, but real data is an xml..believe me.. From harirammanohar at gmail.com Fri Apr 22 05:14:07 2016 From: harirammanohar at gmail.com (harirammanohar at gmail.com) Date: Fri, 22 Apr 2016 02:14:07 -0700 (PDT) Subject: delete from pattern to pattern if it contains match In-Reply-To: <7fc52496-baf8-41ef-8f5e-76d409c6df84@googlegroups.com> References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <7fc52496-baf8-41ef-8f5e-76d409c6df84@googlegroups.com> Message-ID: On Friday, April 22, 2016 at 2:30:45 PM UTC+5:30, hariram... at gmail.com wrote: > On Thursday, April 21, 2016 at 4:55:18 PM UTC+5:30, Peter Otten wrote: > > harirammanohar at gmail.com wrote: > > > > > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, hariram... at gmail.com > > > wrote: > > >> HI All, > > >> > > >> can you help me out in doing below. > > >> > > >> file: > > >> > > >> guava > > >> fruit > > >> > > >> > > >> mango > > >> fruit > > >> > > >> > > >> orange > > >> fruit > > >> > > > > Is that literally what you have in the file? > > > > > any one can guide me ? why xml tree parsing is not working if i have > > > root.tag and root.attrib as mentioned in earlier post... > > > > The data above is not valid xml. Instead of > > > > ... > > > > you need > > > > ... > > > > i. e. the end tag must be the same as the start tag, but with a leading "/". > > @peter yes here it is not xml, but real data is an xml..believe me.. @peter this is the similar xml i am having, you can correlate. https://tomcat.apache.org/tomcat-5.5-doc/appdev/web.xml.txt From __peter__ at web.de Fri Apr 22 05:24:06 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 22 Apr 2016 11:24:06 +0200 Subject: delete from pattern to pattern if it contains match References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> Message-ID: harirammanohar at gmail.com wrote: > On Thursday, April 21, 2016 at 7:03:00 PM UTC+5:30, Jussi Piitulainen > wrote: >> harirammanohar at gmail.com writes: >> >> > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, >> > hariram... at gmail.com wrote: >> >> HI All, >> >> >> >> can you help me out in doing below. >> >> >> >> file: >> >> >> >> guava >> >> fruit >> >> >> >> >> >> mango >> >> fruit >> >> >> >> >> >> orange >> >> fruit >> >> >> >> >> >> need to delete from start to end if it contains mango in a file... >> >> >> >> output should be: >> >> >> >> >> >> guava >> >> fruit >> >> >> >> >> >> orange >> >> fruit >> >> >> >> >> >> Thank you >> > >> > any one can guide me ? why xml tree parsing is not working if i have >> > root.tag and root.attrib as mentioned in earlier post... >> >> Assuming the real consists of lines between a start marker and end >> marker, a winning plan is to collect a group of lines, deal with it, and >> move on. >> >> The following code implements something close to the plan. You need to >> adapt it a bit to have your own source of lines and to restore the end >> marker in the output and to account for your real use case and for >> differences in taste and judgment. - The plan is as described above, but >> there are many ways to implement it. >> >> from io import StringIO >> >> text = '''\ >> >> guava >> fruit >> >> >> mango >> fruit >> >> >> orange >> fruit >> >> ''' >> >> def records(source): >> current = [] >> for line in source: >> if line.startswith(''): >> yield current >> current = [] >> else: >> current.append(line) >> >> def hasmango(record): >> return any('mango' in it for it in record) >> >> for record in records(StringIO(text)): >> hasmango(record) or print(*record) > > Hi, > > not working....this is the output i am getting... > > \ This means that the line >> text = '''\ has trailing whitespace in your copy of the script. > > guava > fruit > > > orange > fruit Jussi forgot to add the "..." line to the group. To fix this change the generator to def records(source): current = [] for line in source: current.append(line) if line.startswith(''): yield current current = [] >> hasmango(record) or print(*record) The print(*record) inserts spaces between record entries (i. e. at the beginning of all lines except the first) and adds a trailing newline. You can avoid this by specifying the delimiters explicitly: if not hasmango(record): print(*record, sep="", end="") Even with these changes code still looks somewhat brittle... From __peter__ at web.de Fri Apr 22 05:50:14 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 22 Apr 2016 11:50:14 +0200 Subject: delete from pattern to pattern if it contains match References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <7fc52496-baf8-41ef-8f5e-76d409c6df84@googlegroups.com> Message-ID: harirammanohar at gmail.com wrote: >> @peter yes here it is not xml, but real data is an xml..believe me.. > > @peter this is the similar xml i am having, you can correlate. > > https://tomcat.apache.org/tomcat-5.5-doc/appdev/web.xml.txt This is still too vague. If you post the code you actually tried in a small standalone script together with a small sample xml file that produces the same failure as your actual data I or someone might help you fix it. From jussi.piitulainen at helsinki.fi Fri Apr 22 07:10:46 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 22 Apr 2016 14:10:46 +0300 Subject: delete from pattern to pattern if it contains match References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> Message-ID: Peter Otten writes: > harirammanohar at gmail.com wrote: > >> On Thursday, April 21, 2016 at 7:03:00 PM UTC+5:30, Jussi Piitulainen >> wrote: >>> harirammanohar at gmail.com writes: >>> >>> > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, >>> > hariram... at gmail.com wrote: >>> >> HI All, >>> >> >>> >> can you help me out in doing below. >>> >> >>> >> file: >>> >> >>> >> guava >>> >> fruit >>> >> >>> >> >>> >> mango >>> >> fruit >>> >> >>> >> >>> >> orange >>> >> fruit >>> >> >>> >> >>> >> need to delete from start to end if it contains mango in a file... >>> >> >>> >> output should be: >>> >> >>> >> >>> >> guava >>> >> fruit >>> >> >>> >> >>> >> orange >>> >> fruit >>> >> >>> >> >>> >> Thank you >>> > >>> > any one can guide me ? why xml tree parsing is not working if i have >>> > root.tag and root.attrib as mentioned in earlier post... >>> >>> Assuming the real consists of lines between a start marker and end >>> marker, a winning plan is to collect a group of lines, deal with it, and >>> move on. >>> >>> The following code implements something close to the plan. You need to >>> adapt it a bit to have your own source of lines and to restore the end >>> marker in the output and to account for your real use case and for >>> differences in taste and judgment. - The plan is as described above, but >>> there are many ways to implement it. >>> >>> from io import StringIO >>> >>> text = '''\ >>> >>> guava >>> fruit >>> >>> >>> mango >>> fruit >>> >>> >>> orange >>> fruit >>> >>> ''' >>> >>> def records(source): >>> current = [] >>> for line in source: >>> if line.startswith(''): >>> yield current >>> current = [] >>> else: >>> current.append(line) >>> >>> def hasmango(record): >>> return any('mango' in it for it in record) >>> >>> for record in records(StringIO(text)): >>> hasmango(record) or print(*record) >> >> Hi, >> >> not working....this is the output i am getting... >> >> \ > > This means that the line > >>> text = '''\ > > has trailing whitespace in your copy of the script. That's a nuisance. I wish otherwise undefined escape sequences in strings raised an error, similar to a stray space after a line continuation character. >> >> guava >> fruit >> >> >> orange >> fruit > > Jussi forgot to add the "..." line to the group. I didn't forget. I meant what I said when I said the OP needs to adapt the code to (among other things) restore the end marker in the output. If they can't be bothered to do anything at all, it's their problem. It was already known that this is not the actual format of the data. > To fix this change the generator to > > def records(source): > current = [] > for line in source: > current.append(line) > if line.startswith(''): > yield current > current = [] Oops, I notice that I forgot to start a new record only on encountering a '' line. That should probably be done, unless the format is intended to be exactly a sequence of "\n- -\n\n". >>> hasmango(record) or print(*record) > > The > > print(*record) > > inserts spaces between record entries (i. e. at the beginning of all > lines except the first) and adds a trailing newline. Yes, I forgot about the space. Sorry about that. The final newline was intentional. Perhaps I should have added the end marker there instead (given my preference to not drag it together with the data lines), like so: print(*record, sep = "", end = "\n") Or so: print(*record, sep = "") print("") Or so: for line in record: print(line.rstrip("\n") else: print("") Or: for line in record: print(line.rstrip("\n") else: if record and not record[-1].strip() == "": print("") But all this is beside the point that to deal with the stated problem one might want to obtain access to a whole record *first*, then check if it contains "mango" in the intended way (details missing but at least "mango\n" as a full line counts as an occurrence), and only *then* print the whole record (if it doesn't contain "mango"). I can think of two other ways - one if the data can be accessed only once - but they seem more complicated to me. Hm, well, if it's XML, as stated in another branch of this thread and contrary to the form of the example data in this branch, there's a third way that may be good, but here I'm responding to a line-oriented format. > You can avoid this by specifying the delimiters explicitly: > > if not hasmango(record): > print(*record, sep="", end="") > > Even with these changes code still looks somewhat brittle... That depends on the actual data format, and on what really is intended to trigger the filter. This approach is a complete waste of effort if there are no guarantees of things being there on their own lines, for example. Ok, that "\ " not only looks brittle but actually is brittle. The one time I used that slash, I now regret doing so. Here's a fixed version. (Not sure of the significance of the number of spaces that start the first data line. They seem to have doubled along the way.) text = ''' guava fruit mango fruit orange fruit ''' From jldunn2000 at gmail.com Fri Apr 22 07:30:15 2016 From: jldunn2000 at gmail.com (loial) Date: Fri, 22 Apr 2016 04:30:15 -0700 (PDT) Subject: Running lpr on windows from python In-Reply-To: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> References: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> Message-ID: <982a6a8e-f987-4e9b-ae2e-90f3d9aad4c9@googlegroups.com> Nothing seems to work. Even doing import os os.system("lpr") still returns 'lpr' is not recognized as an internal or external command,operable program or batch file. Even though I can run lpr fine from the command prompt From mail at timgolden.me.uk Fri Apr 22 08:22:03 2016 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 22 Apr 2016 13:22:03 +0100 Subject: a problem with importing pygame In-Reply-To: References: Message-ID: <571A176B.10009@timgolden.me.uk> On 22/04/2016 09:07, Kiril Bard wrote: > I use python for my school work and I wanted to download it at home. I had > my teacher download the version to a flash drive and it still doesn't seem > to work. The version that I got from the flash drive was python 3.4.2 and > I think I got a 32 bit or a 64 bit pygame for a windows machine. The > program does not import pygame, it says that there is no module named > pygame. > Kiril. Your description of the problem isn't quite clear. If you haven't, I suggest you: * Download Python 3.4 from here: https://www.python.org/downloads/release/python-343/ (Either the "Windows x86-64 MSI installer" or the "Windows x86 MSI installer" depending on whether you want 64 or 32-bit respectively) Run the installer and accept the defaults (unless you have a clear reason to do otherwise) * Then download the corresponding version of Pygame from here: https://bitbucket.org/pygame/pygame/downloads Either: https://bitbucket.org/pygame/pygame/downloads/pygame-1.9.2a0-hg_ea3b3bb8714a.win32-py3.4.msi for 32-bit; or https://bitbucket.org/pygame/pygame/downloads/pygame-1.9.2a0-hg_8d9e6a1f2635+.win-amd64-py3.4.msi for 64-bit Run the installer and accept the defaults * Then you should be able to start Python and import pygame If you still have problems, please post back here to see if we can help you. TJG From vmiacullo at gmail.com Fri Apr 22 09:33:59 2016 From: vmiacullo at gmail.com (vittorio maria iacullo) Date: Fri, 22 Apr 2016 15:33:59 +0200 Subject: help In-Reply-To: References: Message-ID: Done! Thank you! 2016-04-22 12:57 GMT+02:00 vittorio maria iacullo : > Hi > I've just installed on my laptop python 3.5.1 > > but I get a error message. I alredy ran the "repair session". May you tell > me please what should I do? > > Best, > > -- > > > *Vittorio Maria Iacullo?* > -- *Vittorio Maria Iacullo* From jldunn2000 at gmail.com Fri Apr 22 10:15:39 2016 From: jldunn2000 at gmail.com (loial) Date: Fri, 22 Apr 2016 07:15:39 -0700 (PDT) Subject: Can't run lpr from python on windows 2012 server Message-ID: I am reposting this question in a simpler form. I can run lpr from the command prompt but not from python os.system("notepad") works os.system("lpr") does not work. Basically it says lpr is not a known program or executable Why can I run lpr from the windows command prompt but not from python(2.7) From random832 at fastmail.com Fri Apr 22 10:26:47 2016 From: random832 at fastmail.com (Random832) Date: Fri, 22 Apr 2016 10:26:47 -0400 Subject: Can't run lpr from python on windows 2012 server In-Reply-To: References: Message-ID: <1461335207.353144.586657921.2B62BB45@webmail.messagingengine.com> On Fri, Apr 22, 2016, at 10:15, loial wrote: > I am reposting this question in a simpler form. > > I can run lpr from the command prompt but not from python > > os.system("notepad") works > os.system("lpr") does not work. Basically it says lpr is not a known > program or executable > > Why can I run lpr from the windows command prompt but not from > python(2.7) Does lpr.exe actually physically exist in c:\windows\system32 as you have indicated in the your earlier posts? I.e. if you actually browse system32 with the file manager will you see lpr.exe? The problem with your question is that it's not a standard command, so none of the rest of us have it, which means we're half-blind trying to find your problem. From steve at pearwood.info Fri Apr 22 10:56:33 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 23 Apr 2016 00:56:33 +1000 Subject: Remove directory tree without following symlinks Message-ID: <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com> I want to remove a directory, including all files and subdirectories under it, but without following symlinks. I want the symlinks to be deleted, not the files pointed to by those symlinks. E.g. if I have this tree: parent/ +-- spam/ : +-- a.txt : +-- b.txt : +-- eggs/ : : +-- c.txt : : +-- surprise -> ../../parent : +-- d.txt +-- e.txt and I call remove_tree("parent/spam"), I want the result to be: parent/ +-- e.txt (Assuming that I have permission to delete all the files and directories.) What should I use for "remove_tree"? Do I have to write my own, or does a solution already exist? -- Steven From steve at pearwood.info Fri Apr 22 11:00:08 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 23 Apr 2016 01:00:08 +1000 Subject: Detecting repeated subsequences of identical items References: <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> <5718c457$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: <571a3c78$0$1597$c3e8da3$5496439d@news.astraweb.com> On Fri, 22 Apr 2016 12:12 am, Chris Angelico wrote: > On Fri, Apr 22, 2016 at 12:01 AM, Oscar Benjamin > wrote: >> In the recursive stack overflow case what you'll usually have is >> >> 1) A few frames leading up to the start of recursion >> 2) A long repetitive sequence of frames >> 3) A few frames at the end showing how the exception was ultimately >> triggered. >> >> You just need to find the cycle that makes that big long sequence. I am not convinced that it is a cycle in the technical sense, or that the two algorithms that Oscar linked to will necessarily find them. They may, by chance, happen to find them sometimes, but the way the algorithms work is by detecting periodic behaviour, and this is not periodic. Look at the comment for Floyd's algorithm here: https://en.wikipedia.org/wiki/Cycle_detection # The hare moves twice as quickly as the tortoise and # the distance between them increases by 1 at each step. # Eventually they will both be inside the cycle and then, ... but that is violated in this scenario. The hare can escape the (non-)cycle before the tortoise even enters it. Even if both enter the "cycle", there's no guarantee that the termination condition `tortoise == hare` will ever be true because the cycle doesn't loop and doesn't go back to the beginning. Hence it is not a cycle. > If the stack got overflowed, there won't usually be a part 3, as part > 2 is the bit that hits sys.recursionlimit (unless increasing the > recursion limit by a finite number would solve the problem). Don't just think of breaking the recursion limit. You might be 100 calls deep in some complex chain of function calls when something raises ValueError. In principle, there might not even be any recursive calls at all. -- Steven From jldunn2000 at gmail.com Fri Apr 22 11:06:35 2016 From: jldunn2000 at gmail.com (loial) Date: Fri, 22 Apr 2016 08:06:35 -0700 (PDT) Subject: Can't run lpr from python on windows 2012 server In-Reply-To: References: <1461335207.353144.586657921.2B62BB45@webmail.messagingengine.com> Message-ID: Yes it does. I finally found the solution here : http://www.tomshardware.co.uk/forum/240019-44-error-windows Copied lpr.exe, lprhelp.dll, and lprmonui.dll from the System32 folder to the sysWOW64 folder On Friday, April 22, 2016 at 3:27:18 PM UTC+1, Random832 wrote: > On Fri, Apr 22, 2016, at 10:15, loial wrote: > > I am reposting this question in a simpler form. > > > > I can run lpr from the command prompt but not from python > > > > os.system("notepad") works > > os.system("lpr") does not work. Basically it says lpr is not a known > > program or executable > > > > Why can I run lpr from the windows command prompt but not from > > python(2.7) > > Does lpr.exe actually physically exist in c:\windows\system32 as you > have indicated in the your earlier posts? I.e. if you actually browse > system32 with the file manager will you see lpr.exe? The problem with > your question is that it's not a standard command, so none of the rest > of us have it, which means we're half-blind trying to find your problem. From jldunn2000 at gmail.com Fri Apr 22 11:07:48 2016 From: jldunn2000 at gmail.com (loial) Date: Fri, 22 Apr 2016 08:07:48 -0700 (PDT) Subject: Running lpr on windows from python In-Reply-To: <982a6a8e-f987-4e9b-ae2e-90f3d9aad4c9@googlegroups.com> References: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> <982a6a8e-f987-4e9b-ae2e-90f3d9aad4c9@googlegroups.com> Message-ID: I finally found the solution here : http://www.tomshardware.co.uk/forum/240019-44-error-windows Copied lpr.exe, lprhelp.dll, and lprmonui.dll from the System32 folder to the sysWOW64 folder Thanks for all your efforts From random832 at fastmail.com Fri Apr 22 11:09:26 2016 From: random832 at fastmail.com (Random832) Date: Fri, 22 Apr 2016 11:09:26 -0400 Subject: Remove directory tree without following symlinks In-Reply-To: <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com> References: <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1461337766.365000.586700849.0DDBDB0B@webmail.messagingengine.com> On Fri, Apr 22, 2016, at 10:56, Steven D'Aprano wrote: > What should I use for "remove_tree"? Do I have to write my own, or does a > solution already exist? In the os.walk documentation it provides a simple recipe and also mentions shutil.rmtree From random832 at fastmail.com Fri Apr 22 12:02:59 2016 From: random832 at fastmail.com (Random832) Date: Fri, 22 Apr 2016 12:02:59 -0400 Subject: Can't run lpr from python on windows 2012 server In-Reply-To: References: <1461335207.353144.586657921.2B62BB45@webmail.messagingengine.com> Message-ID: <1461340979.379556.586758089.00E10C42@webmail.messagingengine.com> On Fri, Apr 22, 2016, at 11:06, loial wrote: > Yes it does. I finally found the solution here : > > http://www.tomshardware.co.uk/forum/240019-44-error-windows > > Copied lpr.exe, lprhelp.dll, and lprmonui.dll from the System32 folder to > the sysWOW64 folder A better solution might be to install a 64-bit version of Python. From ian.g.kelly at gmail.com Fri Apr 22 12:27:34 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 22 Apr 2016 10:27:34 -0600 Subject: A pickle problem! In-Reply-To: References: Message-ID: On Thu, Apr 21, 2016 at 7:52 PM, Paulo da Silva wrote: > ?s 22:43 de 21-04-2016, Paulo da Silva escreveu: >> Hi. >> >> Why in this code fragment self.__name is not kept between pickle >> dumps/loads? How to fix it? >> >> Thanks. >> >> import pickle >> import pandas as pd >> import numpy as np >> >> class C(pd.DataFrame): >> def __init__(self,name,*a,**b): >> super(C,self).__init__(*a,**b) >> self.__name=name >> >> def GetName(self): >> return self.__name >> > # Adding this works but looks tricky! > > def __getstate__(self): > dfstate=super(C,self).__getstate__() > cstate=(dfstate,self.__name) > return cstate > > def __setstate__(self,cstate): > super(C,self).__setstate__(cstate[0]) > self.__name=cstate[1] Probably this is necessary because the DataFrame class is already customizing its pickle behavior without taking into account the possibility of added attributes by subclasses. I think that your solution of wrapping the state of the superclass looks fine. From eryksun at gmail.com Fri Apr 22 13:04:24 2016 From: eryksun at gmail.com (eryk sun) Date: Fri, 22 Apr 2016 12:04:24 -0500 Subject: Running lpr on windows from python In-Reply-To: References: <7ec37d41-61eb-4c93-ae21-28d108c261f1@googlegroups.com> <982a6a8e-f987-4e9b-ae2e-90f3d9aad4c9@googlegroups.com> Message-ID: On Fri, Apr 22, 2016 at 10:07 AM, loial wrote: > I finally found the solution here : > > http://www.tomshardware.co.uk/forum/240019-44-error-windows > > Copied lpr.exe, lprhelp.dll, and lprmonui.dll from the System32 folder to the sysWOW64 folder Using the virtual "SysNative" directory should work on Windows 7+ (Server 2008 R2). All you need is for CreateProcess to find the executable. Finding the DLLs is done during process initialization, so there's no need to copy them from the native System32 directory. It works for me in 32-bit Python running in Windows 10: >>> if '32bit' in platform.architecture(): ... lpr = os.path.join(os.environ['SystemRoot'], 'SysNative', 'lpr.exe') ... else: ... lpr = os.path.join(os.environ['SystemRoot'], 'System32', 'lpr.exe') ... >>> print(lpr) C:\Windows\SysNative\lpr.exe >>> subprocess.call(lpr) Sends a print job to a network printer Usage: lpr -S server -P printer [-C class] [-J job] [-o option] [-x] [-d] filename Options: -S server Name or ipaddress of the host providing lpd service -P printer Name of the print queue -C class Job classification for use on the burst page -J job Job name to print on the burst page -o option Indicates type of the file (by default assumes a text file) Use "-o l" for binary (e.g. postscript) files -x Compatibility with SunOS 4.1.x and prior -d Send data file first1 From steve at pearwood.info Fri Apr 22 13:14:12 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 23 Apr 2016 03:14:12 +1000 Subject: Remove directory tree without following symlinks References: <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com> <1461337766.365000.586700849.0DDBDB0B@webmail.messagingengine.com> Message-ID: <571a5be6$0$1590$c3e8da3$5496439d@news.astraweb.com> On Sat, 23 Apr 2016 01:09 am, Random832 wrote: > On Fri, Apr 22, 2016, at 10:56, Steven D'Aprano wrote: >> What should I use for "remove_tree"? Do I have to write my own, or does a >> solution already exist? > > In the os.walk documentation it provides a simple recipe and also > mentions shutil.rmtree Thanks for that. The os.walk recipe is described as a simple version of shutil.rmtree. The documentation for rmtree seems lacking to me, but after testing it, it appears to work as I want it: it removes symbolic links, it does not follow them. Is anyone else able to confirm that my understanding is correct? If so, the documentation should probably be a bit clearer. -- Steven From eryksun at gmail.com Fri Apr 22 13:17:07 2016 From: eryksun at gmail.com (eryk sun) Date: Fri, 22 Apr 2016 12:17:07 -0500 Subject: Can't run lpr from python on windows 2012 server In-Reply-To: <1461335207.353144.586657921.2B62BB45@webmail.messagingengine.com> References: <1461335207.353144.586657921.2B62BB45@webmail.messagingengine.com> Message-ID: On Fri, Apr 22, 2016 at 9:26 AM, Random832 wrote: > The problem with your question is that it's not a standard command, so none > of the rest of us have it, which means we're half-blind trying to find your problem. lpr is a Windows feature that you may be able to enable. It's under "Print and Document Services" -> "LPR Port Monitor". It only installs a 64-bit build, which is why loial is having trouble running it from 32-bit Python. But in Windows 7+ (Server 2008 R2), a 32-bit process can use the virtual "%SystemRoot%\SysNative" directory to access files in the native System32 directory. I can run lpr.exe from 32-bit Python using this method. From raguilar at churchs.com.mx Fri Apr 22 13:34:13 2016 From: raguilar at churchs.com.mx (Ricardo Aguilar) Date: Fri, 22 Apr 2016 12:34:13 -0500 Subject: dbf remove fields. Message-ID: <018601d19cbd$30440090$90cc01b0$@churchs.com.mx> Hi there i try to remove to fields in dbf table, how I can remove two fields? I wanna to remove because I have this error "ValueError: could not convert string to float: ****" But I no need this field. How I can remove this fields o ignore this ValueError? Any advice. Ricardo Alfonso Aguilar Pineda - raguilar at churchs.com.mx Depto. Sistemas 867 711-5151 ext. 136 867 119 6506 From sjeik_appie at hotmail.com Fri Apr 22 13:39:10 2016 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Fri, 22 Apr 2016 17:39:10 +0000 Subject: Remove directory tree without following symlinks In-Reply-To: <571a5be6$0$1590$c3e8da3$5496439d@news.astraweb.com> References: <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com>, <1461337766.365000.586700849.0DDBDB0B@webmail.messagingengine.com>, , <571a5be6$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: > From: steve at pearwood.info > Subject: Re: Remove directory tree without following symlinks > Date: Sat, 23 Apr 2016 03:14:12 +1000 > To: python-list at python.org > > On Sat, 23 Apr 2016 01:09 am, Random832 wrote: > > > On Fri, Apr 22, 2016, at 10:56, Steven D'Aprano wrote: > >> What should I use for "remove_tree"? Do I have to write my own, or does a > >> solution already exist? > > > > In the os.walk documentation it provides a simple recipe and also > > mentions shutil.rmtree > > Thanks for that. FYI, Just today I found out that shutil.rmtree raises a WindowsError if the dir is read-only (or its contents). Using 'ignore_errors', won't help. Sure, no error is raised, but the dir is not deleted either! A 'force' option would be a nice improvement. > The os.walk recipe is described as a simple version of shutil.rmtree. The > documentation for rmtree seems lacking to me, but after testing it, it > appears to work as I want it: it removes symbolic links, it does not follow > them. > > Is anyone else able to confirm that my understanding is correct? If so, the > documentation should probably be a bit clearer. > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list From eryksun at gmail.com Fri Apr 22 14:28:01 2016 From: eryksun at gmail.com (eryk sun) Date: Fri, 22 Apr 2016 13:28:01 -0500 Subject: Remove directory tree without following symlinks In-Reply-To: References: <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com> <1461337766.365000.586700849.0DDBDB0B@webmail.messagingengine.com> <571a5be6$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 22, 2016 at 12:39 PM, Albert-Jan Roskam wrote: > FYI, Just today I found out that shutil.rmtree raises a WindowsError if the dir is read- > only (or its contents). Using 'ignore_errors', won't help. Sure, no error is raised, but the > dir is not deleted either! A 'force' option would be a nice improvement. Use the onerror handler to call os.chmod(path, stat.S_IWRITE). For example, see pip's rmtree_errorhandler: https://github.com/pypa/pip/blob/8.1.1/pip/utils/__init__.py#L105 From ethan at stoneleaf.us Fri Apr 22 14:28:55 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 22 Apr 2016 11:28:55 -0700 Subject: dbf remove fields. In-Reply-To: <018601d19cbd$30440090$90cc01b0$@churchs.com.mx> References: <018601d19cbd$30440090$90cc01b0$@churchs.com.mx> Message-ID: <571A6D67.2080502@stoneleaf.us> On 04/22/2016 10:34 AM, Ricardo Aguilar wrote: > Hi there i try to remove to fields in dbf table, how I can remove two > fields? > > I wanna to remove because I have this error "ValueError: could not convert > string to float: ****" But I no need this field. Have you tried my dbf package? https://pypi.python.org/pypi/dbf I'm pretty sure it handles such values. -- ~Ethan~ From ethan at stoneleaf.us Fri Apr 22 14:32:43 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 22 Apr 2016 11:32:43 -0700 Subject: dbf remove fields. In-Reply-To: <571A6D67.2080502@stoneleaf.us> References: <018601d19cbd$30440090$90cc01b0$@churchs.com.mx> <571A6D67.2080502@stoneleaf.us> Message-ID: <571A6E4B.9090501@stoneleaf.us> On 04/22/2016 11:28 AM, Ethan Furman wrote: > On 04/22/2016 10:34 AM, Ricardo Aguilar wrote: > >> Hi there i try to remove to fields in dbf table, how I can remove two >> fields? >> >> I wanna to remove because I have this error "ValueError: could not >> convert >> string to float: ****" But I no need this field. > > Have you tried my dbf package? > > https://pypi.python.org/pypi/dbf > > I'm pretty sure it handles such values. Yup, just checked -- it transforms invalid **** values to None. Since you're not using those fields that won't be a problem (otherwise you would have filter them out). -- ~Ethan~ From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Fri Apr 22 16:21:17 2016 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Fri, 22 Apr 2016 21:21:17 +0100 Subject: A pickle problem! References: Message-ID: ?s 17:27 de 22-04-2016, Ian Kelly escreveu: > On Thu, Apr 21, 2016 at 7:52 PM, Paulo da Silva > wrote: >> ?s 22:43 de 21-04-2016, Paulo da Silva escreveu: ... > > Probably this is necessary because the DataFrame class is already > customizing its pickle behavior without taking into account the > possibility of added attributes by subclasses. I think that your > solution of wrapping the state of the superclass looks fine. > Thank you. For any other vars ... Is there a way to get the vars of only the derived class? From ian.g.kelly at gmail.com Fri Apr 22 16:33:39 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 22 Apr 2016 14:33:39 -0600 Subject: A pickle problem! In-Reply-To: References: Message-ID: On Fri, Apr 22, 2016 at 2:21 PM, Paulo da Silva wrote: > ?s 17:27 de 22-04-2016, Ian Kelly escreveu: >> On Thu, Apr 21, 2016 at 7:52 PM, Paulo da Silva >> wrote: >>> ?s 22:43 de 21-04-2016, Paulo da Silva escreveu: > ... > >> >> Probably this is necessary because the DataFrame class is already >> customizing its pickle behavior without taking into account the >> possibility of added attributes by subclasses. I think that your >> solution of wrapping the state of the superclass looks fine. >> > Thank you. > > For any other vars ... > Is there a way to get the vars of only the derived class? If they start with two underscores then you could use the name mangling to find them. If the class name is MyClass then look for any keys in the instance dict that start with '_MyClass__'. Otherwise no, you'd have to list them explicitly. From michael.selik at gmail.com Fri Apr 22 16:40:45 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 22 Apr 2016 20:40:45 +0000 Subject: How much sanity checking is required for function inputs? In-Reply-To: <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> Message-ID: On Fri, Apr 22, 2016, 1:26 AM Stephen Hansen wrote: > On Thu, Apr 21, 2016, at 08:33 PM, Christopher Reimer wrote: > > On 4/21/2016 7:20 PM, Stephen Hansen wrote: > > > I... that... what... I'd forget that link and pretend you never went > > > there. Its not helpful. > > > > I found it on the Internet, so it must be true -- and Pythonic at that! > > My advice is to not look at that site further. I can't count the number > of things that are just... not useful or helpful. > > Directly translating the Gang of Four Design Pattern book to Python > doesn't generally result in useful ideas, except in certain abstractions > like the visitor pattern when you're designing big systems. > Frankly, for someone coming from Java, the best advice is to not write any classes until you must. Of course classes in Python are very useful. It's just that your Java habits are unnecessary and often counter-productive. Just make some globals and some functions. Heck, even write procedurally for a while. Free yourself from the Kingdom of Nouns. http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html > From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Fri Apr 22 16:48:19 2016 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Fri, 22 Apr 2016 21:48:19 +0100 Subject: A pickle problem! References: Message-ID: ?s 21:33 de 22-04-2016, Ian Kelly escreveu: > On Fri, Apr 22, 2016 at 2:21 PM, Paulo da Silva > wrote: ... > > If they start with two underscores then you could use the name > mangling to find them. If the class name is MyClass then look for any > keys in the instance dict that start with '_MyClass__'. Otherwise no, > you'd have to list them explicitly. > OK, thanks. From wrh8609 at gmail.com Fri Apr 22 17:41:47 2016 From: wrh8609 at gmail.com (wrh8609 at gmail.com) Date: Fri, 22 Apr 2016 14:41:47 -0700 (PDT) Subject: how to setup for localhost:8000 In-Reply-To: <60e461a5-95ff-49c0-9beb-7bc595c057e1@googlegroups.com> References: <5ea1e31b-09ba-4b6a-be8b-58886c5c5f81@googlegroups.com> <2e597a56-00ab-4370-b337-667f34eac56a@googlegroups.com> <67abca1d-8ac5-4a9a-825d-3aa76d9ccf3f@googlegroups.com> <60e461a5-95ff-49c0-9beb-7bc595c057e1@googlegroups.com> Message-ID: <63f6da92-898b-4305-84ff-77cbdfa4d876@googlegroups.com> On Sunday, April 17, 2016 at 1:11:39 PM UTC-4, Pierre Quentel wrote: > > > 127.0.0.1 - - [15/Apr/2016 20:57:32] "GET / HTTP/1.1" 200 - > > Hi Pierre, > > > > When I type http://localhost:8000, I did not see anything in the console after the line "Serving HTTP on 0.0.0.0 port 8000 ... I believe the way I ran was not correct as shown below: > > > python -m http.server > > Serving HTTP on 0.0.0.0 port 8000 ... > > > > Also if I use internet Explorer, it shows HTTP 404 errors. > > Do you think the way I am doing of the localhost:8000 setting was not correct? > > > > Thanks, > > Wen-Ruey > > If you're not seeing anything there, it is sure that the Python server doesn't serve requests on port 8000. But if you're seeing a blank screen or a 404 error instead of a message saying that a connection couldn't be set up, it is likely that another HTTP server is running on your machine on port 8000. > > Could you try to start the server on another port, eg "python -m http.server 8085" and see what happens in the browser with "http://127.0.0.1:8085" ? I followed your instruction but the page shows: The 127.0.0.1 page isn't working 127.0.0.1 didn't send any data. ERR_EMPTY_RESPONSE and a lot of messages show on the command window.. From no.email at nospam.invalid Sat Apr 23 04:13:58 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 23 Apr 2016 01:13:58 -0700 Subject: Remove directory tree without following symlinks References: <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <877ffon3nd.fsf@nightsong.com> Steven D'Aprano writes: > I want to remove a directory, including all files and subdirectories under > it, but without following symlinks. I want the symlinks to be deleted, not > the files pointed to by those symlinks. rm -r shouldn't follow symlinks like you mention. From sjeik_appie at hotmail.com Sat Apr 23 05:34:12 2016 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Sat, 23 Apr 2016 09:34:12 +0000 Subject: Remove directory tree without following symlinks In-Reply-To: References: <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com>, <1461337766.365000.586700849.0DDBDB0B@webmail.messagingengine.com>, , <571a5be6$0$1590$c3e8da3$5496439d@news.astraweb.com>, , Message-ID: > From: eryksun at gmail.com > Date: Fri, 22 Apr 2016 13:28:01 -0500 > Subject: Re: Remove directory tree without following symlinks > To: python-list at python.org > > On Fri, Apr 22, 2016 at 12:39 PM, Albert-Jan Roskam > wrote: > > FYI, Just today I found out that shutil.rmtree raises a WindowsError if the dir is read- > > only (or its contents). Using 'ignore_errors', won't help. Sure, no error is raised, but the > > dir is not deleted either! A 'force' option would be a nice improvement. > > Use the onerror handler to call os.chmod(path, stat.S_IWRITE). For > example, see pip's rmtree_errorhandler: > > https://github.com/pypa/pip/blob/8.1.1/pip/utils/__init__.py#L105 Thanks, that looks useful indeed. I thought about os.chmod, but with os.walk. That seemed expensive. So I used subprocess.call('rmdir "%s" /s /q' % dirname). That's Windows only, of course, but aside of that, is using subprocess less preferable?Fun fact: I used it to remove .svn dirs, just like what is mentioned in the pip comments :-) From steve at pearwood.info Sat Apr 23 06:24:51 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 23 Apr 2016 20:24:51 +1000 Subject: Remove directory tree without following symlinks References: <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com> <877ffon3nd.fsf@nightsong.com> Message-ID: <571b4d75$0$1598$c3e8da3$5496439d@news.astraweb.com> On Sat, 23 Apr 2016 06:13 pm, Paul Rubin wrote: > Steven D'Aprano writes: >> I want to remove a directory, including all files and subdirectories >> under it, but without following symlinks. I want the symlinks to be >> deleted, not the files pointed to by those symlinks. > > rm -r shouldn't follow symlinks like you mention. "rm -r" gives me a NameError when I run it in my Python script :-) But seriously, where is that documented? I've read the man page for rm, and it doesn't say anything about treatment of symlinks, nor is there an option to follow/not follow symlinks. So I never trust rm -r unless I know what I'm deleting. -- Steven From greg.ewing at canterbury.ac.nz Sat Apr 23 07:37:35 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 23 Apr 2016 23:37:35 +1200 Subject: Remove directory tree without following symlinks In-Reply-To: <571b4d75$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com> <877ffon3nd.fsf@nightsong.com> <571b4d75$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > But seriously, where is that documented? I've read the man page for rm, and > it doesn't say anything about treatment of symlinks The Linux man page seems to be a bit deficient on this. The BSD version contains this sentence: The rm utility removes symbolic links, not the files referenced by the links. -- Greg From nobody at nowhere.invalid Sat Apr 23 12:29:06 2016 From: nobody at nowhere.invalid (Nobody) Date: Sat, 23 Apr 2016 17:29:06 +0100 Subject: Remove directory tree without following symlinks References: <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, 23 Apr 2016 00:56:33 +1000, Steven D'Aprano wrote: > I want to remove a directory, including all files and subdirectories under > it, but without following symlinks. I want the symlinks to be deleted, not > the files pointed to by those symlinks. Note that this is non-trivial to do securely, i.e. where an adversary has write permission on any of the directories involved. Due to the potential for race conditions between checking whether a name refers to a directory and recursing into it, the process can be tricked into deleting any directory tree for which it has the appropriate permissions. The solution requires: 1. That you always chdir() into each directory and remove entries using their plain filename, rather than trying to remove entries from a higher-level directory using a relative path. 2. When chdir()ing into each subdirectory, you need to do e.g.: st1 = os.stat(".") os.chdir(subdir) st2 = os.stat("..") if st1.st_dev != st2.st_dev or st1.st_ino != st2.st_ino: raise SomeKindOfException() If the test fails, it means that the directory you just chdir()d into isn't actually a subdirectory of the one you just left, e.g. because the directory entry was replaced between checking it and chdir()ing into it. On Linux, an alternative is to use fchdir() rather than chdir(), which changes to a directory specified by an open file descriptor for that directory rather than by name. Provided that the directory was open()ed without any race condition (e.g. using O_NOFOLLOW), subsequent fstat() and fchdir() calls are guaranteed to use the same directory regardless of any filesystem changes. From eryksun at gmail.com Sat Apr 23 16:22:35 2016 From: eryksun at gmail.com (eryk sun) Date: Sat, 23 Apr 2016 15:22:35 -0500 Subject: Remove directory tree without following symlinks In-Reply-To: References: <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com> <1461337766.365000.586700849.0DDBDB0B@webmail.messagingengine.com> <571a5be6$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 23, 2016 at 4:34 AM, Albert-Jan Roskam wrote: > >> From: eryksun at gmail.com >> Date: Fri, 22 Apr 2016 13:28:01 -0500 >> On Fri, Apr 22, 2016 at 12:39 PM, Albert-Jan Roskam >> wrote: >> > FYI, Just today I found out that shutil.rmtree raises a WindowsError if >> > the dir is read-only (or its contents). Using 'ignore_errors', won't help. >> > Sure, no error is raised, but the dir is not deleted either! A 'force' option >> > would be a nice improvement. >> >> Use the onerror handler to call os.chmod(path, stat.S_IWRITE). For >> example, see pip's rmtree_errorhandler: >> >> https://github.com/pypa/pip/blob/8.1.1/pip/utils/__init__.py#L105 > > Thanks, that looks useful indeed. I thought about os.chmod, but with > os.walk. That seemed expensive. So I used subprocess.call('rmdir "%s" /s /q' > % dirname). That's Windows only, of course, but aside of that, is using > subprocess less preferable? I assume you used shell=True in the above call, and not an external rmdir.exe. There are security concerns with using the shell if you're not in complete control of the command line. As to performance, cmd's rmdir wins without question, not only because it's implemented in C, but also because it uses the stat data from the WIN32_FIND_DATA returned by FindFirstFile/FindNextFile to check for FILE_ATTRIBUTE_DIRECTORY and FILE_ATTRIBUTE_READONLY. On the other hand, Python wins when it comes to working with deeply nested directories. Paths in cmd are limited to MAX_PATH characters. rmdir uses DOS 8.3 short names (i.e. cAlternateFileName in WIN32_FIND_DATA), but that could still exceed MAX_PATH for a deeply nested tree, or the volume may not even have 8.3 DOS filenames. shutil.rmtree allows you to work around the DOS limit by prefixing the path with "\\?\". For example: >>> subprocess.call(r'rmdir /q/s Z:\Temp\long', shell=True) The path Z:\Temp\long\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaa is too long. 0 >>> shutil.rmtree(r'\\?\Z:\Temp\long') >>> os.path.exists(r'Z:\Temp\long') False Using "\\?\" requires a path that's fully qualified, normalized (backslash only), and unicode (i.e. decode a Python 2 str). From random832 at fastmail.com Sat Apr 23 17:04:29 2016 From: random832 at fastmail.com (Random832) Date: Sat, 23 Apr 2016 17:04:29 -0400 Subject: Remove directory tree without following symlinks In-Reply-To: <571b4d75$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com> <877ffon3nd.fsf@nightsong.com> <571b4d75$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1461445469.3526344.587631697.21F2B303@webmail.messagingengine.com> On Sat, Apr 23, 2016, at 06:24, Steven D'Aprano wrote: > "rm -r" gives me a NameError when I run it in my Python script :-) > > But seriously, where is that documented? I've read the man page for > rm, and it doesn't say anything about treatment of symlinks, nor is > there an option to follow/not follow symlinks. So I never trust rm -r > unless I know what I'm deleting. The Unix Standard says "For each entry contained in file, other than dot or dot-dot, the four steps listed here (1 to 4) shall be taken with the entry as if it were a file operand. The rm utility shall not traverse directories by following symbolic links into other parts of the hierarchy, but shall remove the links themselves." and "The rm utility removes symbolic links themselves, not the files they refer to, as a consequence of the dependence on the unlink() functionality, per the DESCRIPTION. When removing hierarchies with -r or -R, the prohibition on following symbolic links has to be made explicit." OSX (and I assume other BSDs) says "The rm utility removes symbolic links, not the files referenced by the links." I don't know why GNU rm's documentation doesn't say anything about its treatment of symlinks - maybe it never occurred to anyone at GNU that someone might think it would do anything else. (I'd be less inclined to trust windows' treatment of symlinks, junctions, and other reparse points without doing some experiments) From random832 at fastmail.com Sat Apr 23 17:07:14 2016 From: random832 at fastmail.com (Random832) Date: Sat, 23 Apr 2016 17:07:14 -0400 Subject: Remove directory tree without following symlinks In-Reply-To: References: <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1461445634.3526932.587637385.4FF8AC49@webmail.messagingengine.com> On Sat, Apr 23, 2016, at 12:29, Nobody wrote: > On Linux, an alternative is to use fchdir() rather than chdir(), which > changes to a directory specified by an open file descriptor Of course, then there's also the risk of running out of open file descriptors. High-quality implementations of rm will fork to deal with this. From m at funkyhat.org Sat Apr 23 17:33:36 2016 From: m at funkyhat.org (Matt Wheeler) Date: Sat, 23 Apr 2016 22:33:36 +0100 Subject: How much sanity checking is required for function inputs? In-Reply-To: <5719964E.2050400@icloud.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <57198827.1020608@stoneleaf.us> <5719964E.2050400@icloud.com> Message-ID: On 22 April 2016 at 04:11, Christopher Reimer wrote: > On 4/21/2016 7:10 PM, Ethan Furman wrote: >>> I do plan to incorporate a sanity test in each Piece class to validate >>> the initial position value. Pawns have 16 specific positions. Bishop, >>> Knight and Rook each have four specific positions. King and Queen each >>> have two specific positions. An invalid value will raise an exception. >> >> This will make it so you cannot use your PieceFactory for custom setups. > > The sanity check won't be in the PieceFactory, but in the Piece class as an > interface and each Piece subclass will implement the correct positions for > comparison. This is still backwards to me. It prevents your classes from being suitable for restoring a stored game state, not just custom starting positions (which I think is what Ethan means by custom setups). If you need to put sanity checking in your initialisation at all it should be at some higher level, probably in a method named something like `start_chess_game`. But really I'd suggest just writing tests for that method to make sure it's doing the right thing. On the other hand (and I'm sure you've already thought of this) it probably does make sense to put piece move validation in to each of the piece classes: you could even have some fun with it... def move_straight(old, new): if old[0] == new[0] or old[1] == new[1]: return True def move_diag(old, new): diff_x = abs(old[0] - new[0]) diff_y = abs(old[1] - new[1]) if diff_x == diff_y: return True class Piece: ... def move(self, new): if self.validate_move(new): # do the move ... else: raise IllegalMove('or something') class Queen(Piece): def validate_move(self, new): return any((test(self.position, new) for test in (move_straight, move_diag))) Ok I'll stop before I get too carried away... This is completely untested so bugs will abound I'm sure :) -- Matt Wheeler http://funkyh.at From christopher_reimer at icloud.com Sat Apr 23 21:00:24 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sat, 23 Apr 2016 18:00:24 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <5719ACBB.8020905@stoneleaf.us> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <5719ACBB.8020905@stoneleaf.us> Message-ID: <571C1AA8.8000202@icloud.com> On 4/21/2016 9:46 PM, Ethan Furman wrote: > Oh! and Enum!!! ;) OMG! I totally forgot about Enum. Oh, look. Python supports Enum. Now I don't have to roll my own! Hmm... What do we use Enum for? :) Thank you, Chris R. From michael.selik at gmail.com Sat Apr 23 21:21:24 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sun, 24 Apr 2016 01:21:24 +0000 Subject: How much sanity checking is required for function inputs? In-Reply-To: <571C1AA8.8000202@icloud.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <5719ACBB.8020905@stoneleaf.us> <571C1AA8.8000202@icloud.com> Message-ID: On Sat, Apr 23, 2016 at 9:01 PM Christopher Reimer < christopher_reimer at icloud.com> wrote: > On 4/21/2016 9:46 PM, Ethan Furman wrote: > > Oh! and Enum!!! ;) > > OMG! I totally forgot about Enum. Oh, look. Python supports Enum. Now I > don't have to roll my own! > > Hmm... What do we use Enum for? :) > You can use Enum in certain circumstances to replace int or str constants. It can help avoid mistyping mistakes and might help your IDE give auto-complete suggestions. I haven't found a good use for them myself, but I'd been mostly stuck in Python 2 until recently. From ian.g.kelly at gmail.com Sat Apr 23 21:29:42 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 23 Apr 2016 19:29:42 -0600 Subject: How much sanity checking is required for function inputs? In-Reply-To: <571C1AA8.8000202@icloud.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <5719ACBB.8020905@stoneleaf.us> <571C1AA8.8000202@icloud.com> Message-ID: On Sat, Apr 23, 2016 at 7:00 PM, Christopher Reimer wrote: > On 4/21/2016 9:46 PM, Ethan Furman wrote: >> >> Oh! and Enum!!! ;) > > > OMG! I totally forgot about Enum. Oh, look. Python supports Enum. Now I > don't have to roll my own! > > Hmm... What do we use Enum for? :) Python enums are great. Sadly, they're still not quite as awesome as Java enums. From christopher_reimer at icloud.com Sat Apr 23 21:30:11 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sat, 23 Apr 2016 18:30:11 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> Message-ID: <571C21A3.5090507@icloud.com> On 4/21/2016 10:25 PM, Stephen Hansen wrote: > > Why not, 'color in ("black", "white")'? Checkers seems popular around here. What if I want to change "white" to "red," as red and black is a common color scheme for checkers. Do I change a single constant variable or replace all the occurrences in the files? Some of these constants are shortcuts. Instead of writing slice(0, 16) or slice(48, 64), and getting the two confused, I write const['board_bottom'] or const['board_top'], respectively, when I want to pull the correct set of positions from coordinates list. > That said, if you're wanting to share constants across different parts > of your code, use a module. I did that at first, made it into a dictionary class and added ConfigParser to the mix. I had a lot of fun putting that one together. However, as I refactor my code further as I learn new things, it will probably get changed or removed. Being a research project, I'm willing to dive into every rabbit hole that I come across to learn Python properly. Thank you, Chris R. From michael.selik at gmail.com Sat Apr 23 21:38:29 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sun, 24 Apr 2016 01:38:29 +0000 Subject: How much sanity checking is required for function inputs? In-Reply-To: <571C21A3.5090507@icloud.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> <571C21A3.5090507@icloud.com> Message-ID: On Sat, Apr 23, 2016 at 9:31 PM Christopher Reimer < christopher_reimer at icloud.com> wrote: > On 4/21/2016 10:25 PM, Stephen Hansen wrote: > > > > Why not, 'color in ("black", "white")'? > > Checkers seems popular around here. What if I want to change "white" to > "red," as red and black is a common color scheme for checkers. Do I > change a single constant variable or replace all the occurrences in the > files? > Why so many files? Python can easily support thousands of lines in a file. If it's just one file any text editor can do a quick find-replace. That said, it's easy to make some global ``red = 'red'``. Some of these constants are shortcuts. Instead of writing slice(0, 16) > or slice(48, 64), and getting the two confused, I write > const['board_bottom'] or const['board_top'], respectively, when I want > to pull the correct set of positions from coordinates list. > Why hide these things in a dict ``const`` instead of just making them top-level variables in the module themselves? ``board_top = slice(48, 64)`` > That said, if you're wanting to share constants across different parts > > of your code, use a module. > Or just use one file to keep things easier. But, yes, I agree a module of constants is appropriate for bigger projects. From christopher_reimer at icloud.com Sat Apr 23 21:45:37 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sat, 23 Apr 2016 18:45:37 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> Message-ID: <571C2541.9050309@icloud.com> On 4/22/2016 1:40 PM, Michael Selik wrote: > Frankly, for someone coming from Java, the best advice is to not write any > classes until you must. Of course classes in Python are very useful. It's > just that your Java habits are unnecessary and often counter-productive. I disagree. I wrote procedural scripts and translated old BASIC games into Python for two years. One day I came across a Python book that described the principles of subclassing from a base class for chess pieces, but there was no code to demonstrate the process. I had no problem creating the Python classes. That's how my research project got started to build a chess engine. If you ever check the academic literature for chess programming, this research project could turn into a lifelong endeavor. I had to confront all the bad habits I brought over Java and change my code to be more Pythonic. This is where I started having fun, learning the tricks and collapsing multi-line code into a single line code. I've learned more about Python in the few weeks than I had in two years of writing procedural scripts and translating BASIC goto hell. Thank you, Chris R. From christopher_reimer at icloud.com Sat Apr 23 22:03:03 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sat, 23 Apr 2016 19:03:03 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <57198827.1020608@stoneleaf.us> <5719964E.2050400@icloud.com> Message-ID: <571C2957.7060508@icloud.com> On 4/23/2016 2:33 PM, Matt Wheeler wrote: > This is still backwards to me. It prevents your classes from being > suitable for restoring a stored game state, not just custom starting > positions (which I think is what Ethan means by custom setups). I haven't thought that far about saving the game state. I'm under the impression that pickle (or something else) would save and load the instantiated object of each piece. If that's not the case, I'll change the code then. The sanity check does have an exemption for pawn promotion, where a pawn reaching the other side of the board can be promoted to another piece (typically a queen). I played Sargon II chess on the Commodore 64 for five years as a teenager. The worst game I ever won was when the computer had nine queens on the board. I thought the computer was cheating outrageously but a chess rule book confirmed that promotion was a legit move. https://en.wikipedia.org/wiki/Promotion_(chess) If I need to add an exemption to custom plays, I'll add it then. Right now I'm cleaning up the existing code from all the bad Java habits. Thank you, Chris R. From christopher_reimer at icloud.com Sat Apr 23 22:09:24 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sat, 23 Apr 2016 19:09:24 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <5719ACBB.8020905@stoneleaf.us> <571C1AA8.8000202@icloud.com> Message-ID: <571C2AD4.2060003@icloud.com> On 4/23/2016 6:29 PM, Ian Kelly wrote: > Python enums are great. Sadly, they're still not quite as awesome as > Java enums. I remember enums more from C than Java. Although I haven't used them much in either language. I'm planning to immerse myself back into C via Cython. Depending on far I get into this chess program, I might need a speed boost here and there. Thank you, Chris R. From christopher_reimer at icloud.com Sat Apr 23 22:32:12 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sat, 23 Apr 2016 19:32:12 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> <571C21A3.5090507@icloud.com> Message-ID: <571C302C.2010800@icloud.com> On 4/23/2016 6:38 PM, Michael Selik wrote: > Why so many files? Python can easily support thousands of lines in a > file. If it's just one file any text editor can do a quick find-replace. That goes back to the Java convention of having one class per file. It took a while to convince myself that mixing classes and functions in a single file was okay. Once I finished cleaning up the code for this round, I'll merge four files into one file (~500 lines) and have four files (main.py, display.py, engine.py and utility.py). > Or just use one file to keep things easier. But, yes, I agree a module > of constants is appropriate for bigger projects. That's the other problem I'm running into. Building a chess engine is a big project. This is probably bigger than the Java XML parser I built from scratch for a college project. I can't seem to find any information on how to build bigger programs. Community college taught me how to program, but it didn't teach me how to go beyond class inheritance. Thank you, Chris R. From torriem at gmail.com Sat Apr 23 22:34:48 2016 From: torriem at gmail.com (Michael Torrie) Date: Sat, 23 Apr 2016 20:34:48 -0600 Subject: How much sanity checking is required for function inputs? In-Reply-To: <571C2541.9050309@icloud.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> <571C2541.9050309@icloud.com> Message-ID: <571C30C8.5000208@gmail.com> On 04/23/2016 07:45 PM, Christopher Reimer wrote: > I had to confront all the bad habits I brought over Java and change my > code to be more Pythonic. This is where I started having fun, learning > the tricks and collapsing multi-line code into a single line code. I've > learned more about Python in the few weeks than I had in two years of > writing procedural scripts and translating BASIC goto hell. Procedural programming does not necessarily mean BASIC-style goto hell. Not sure why you would think that. In fact that's not really what procedural programming is about. However, Mr. Selik wasn't advocating procedural programming at all. Not defining a class does not make your code precdural. But using classes does not mean your code is *not* procedural. If you are using an event-driven framework then I will say, yes your code is not procedural. There are many aspects to Pythonic programming, not just OOP. For example using modules to store shared state for your program components is very pythonic, rather than using classes. A module is kind of like a singleton instance, and still is object-oriented by the way (the module is an object). Sadly Java really messed up people by using classes as a namespace mechanism. That was quite a mistake. Really messed with people's expectations of OOP. I would say that pythonic programming involves defining classes when it's appropriate, and not doing so when something else will work just as well and be simpler. From schilke.60 at gmail.com Sat Apr 23 23:05:45 2016 From: schilke.60 at gmail.com (Derek Klinge) Date: Sun, 24 Apr 2016 03:05:45 +0000 Subject: Optimizing Memory Allocation in a Simple, but Long Function Message-ID: I have been writing a python script to explore Euler's Method of approximating Euler's Number. I was hoping there might be a way to make this process work faster, as for sufficiently large eulerSteps, the process below becomes quite slow and sometimes memory intensive. I'm hoping someone can give me some insight as to how to optimize these algorithms, or ways I might decrease memory usage. I have been thinking about finding a way around importing the math module, as it seems a bit unneeded except as an easy reference. ## Write a method to approximate Euler's Number using Euler's Method import math class EulersNumber(): def __init__(self,n): self.eulerSteps = n self.e = self.EulersMethod(self.eulerSteps) def linearApproximation(self,x,h,d): # f(x+h)=f(x)+h*f'(x) return x + h * d def EulersMethod(self, numberOfSteps): # Repeat linear approximation over an even range e = 1 # e**0 = 1 for step in range(numberOfSteps): e = self.linearApproximation(e,1.0/numberOfSteps,e) # if f(x)= e**x, f'(x)=f(x) return e def EulerStepWithGuess(accuracy,guessForN): n = guessForN e = EulersNumber(n) while abs(e.e -math.e) > abs(accuracy): n +=1 e = EulersNumber(n) print('n={} \te= {} \tdelta(e)={}'.format(n,e.e,abs(e.e-math.e))) return e def EulersNumberToAccuracy(PowerOfTen): x = 1 theGuess = 1 thisE = EulersNumber(1) while x <= abs(PowerOfTen): thisE = EulerStepWithGuess(10**(-1*x),theGuess) theGuess = thisE.eulerSteps * 10 x += 1 return thisE Thanks, Derek From christopher_reimer at icloud.com Sat Apr 23 23:19:14 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sat, 23 Apr 2016 20:19:14 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <571C30C8.5000208@gmail.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> <571C2541.9050309@icloud.com> <571C30C8.5000208@gmail.com> Message-ID: <571C3B32.4040306@icloud.com> On 4/23/2016 7:34 PM, Michael Torrie wrote > Procedural programming does not necessarily mean BASIC-style goto hell. > Not sure why you would think that. In fact that's not really what > procedural programming is about. I mentioned several messages back that I spent two years writing procedural scripts AND translating BASIC games into Python, which can be goto hell if the program has a drop-down structure that makes sense only from following the entry point of the goto statement (see link for example). http://www.atariarchives.org/basicgames/showpage.php?page=9 I try to follow the BASIC program structure as closely as possible, get it working in Python, and use pylint to make my code PEP8-compliant. Pylint frequently complains about exceeding a dozen if branches in the main function. I then create helper functions to reduce the if branches. Sometimes that makes the Python version either shorter or longer than the original BASIC program. Thank you, Chris R. From torriem at gmail.com Sat Apr 23 23:19:56 2016 From: torriem at gmail.com (Michael Torrie) Date: Sat, 23 Apr 2016 21:19:56 -0600 Subject: How much sanity checking is required for function inputs? In-Reply-To: <571C302C.2010800@icloud.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> <571C21A3.5090507@icloud.com> <571C302C.2010800@icloud.com> Message-ID: <571C3B5C.8030403@gmail.com> On 04/23/2016 08:32 PM, Christopher Reimer wrote: > That's the other problem I'm running into. Building a chess engine is a > big project. This is probably bigger than the Java XML parser I built > from scratch for a college project. I can't seem to find any information > on how to build bigger programs. Community college taught me how to > program, but it didn't teach me how to go beyond class inheritance. The reason you weren't taught beyond class inheritance is because Java implements organization only through a class hierarchy. Whole generations of Java programmers think that program organization is through classes (a static main method means your code is procedural, by the way). Learn about Python namespaces and how to use them. I guess it just comes with experience, a lot of trial and a lot of error. And checking on how others are doing it. Take a look at examples from the Python standard library, as well as other projects. For example, Beautiful Soup. Not that you have to understand their code, but take a look at how they organize things. In my mind namespaces matter more than files as an organizational tool. Because namespaces are my primary organization, I will put multiple class definitions in the same file (if they belong in the same namespace), so they can be imported from the same module. If the classes and functions get more complicated, I can separate them into their own submodules and wrap them all up in one Python package (like a module but more flexible and has submodules). The nice thing about building with Python is you can start with one thing, like a module, and convert it to a package later on as needed. From christopher_reimer at icloud.com Sat Apr 23 23:41:38 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sat, 23 Apr 2016 20:41:38 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <571C3B5C.8030403@gmail.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> <571C21A3.5090507@icloud.com> <571C302C.2010800@icloud.com> <571C3B5C.8030403@gmail.com> Message-ID: <571C4072.1000005@icloud.com> On 4/23/2016 8:19 PM, Michael Torrie wrote: > The reason you weren't taught beyond class inheritance is because Java > implements organization only through a class hierarchy. Whole > generations of Java programmers think that program organization is > through classes (a static main method means your code is procedural, by > the way). I never wanted to learn Java in the first place. My community college couldn't afford to renew the Microsoft site license, which local employers required to learn C/C++ in MS Visual Studio, and all flavors of Java got taught for the programming classes instead. I wanted to learn C/C++. I even wanted to learn assembly language, but I was the only student who showed up for the class and it got cancelled. Of course, it probably doesn't help that I got a job in help desk support after I graduated with A.S. degree in Java and never programmed professionally. Thinking like a programmer helped me resolved many IT problems over the last 12 years. My current job in computer security requires tinkering with PowerShell scripts as Python is strictly prohibited in this Windows shop. I have made Python my main programming language at home. Thank you, Chris R. From torriem at gmail.com Sat Apr 23 23:58:09 2016 From: torriem at gmail.com (Michael Torrie) Date: Sat, 23 Apr 2016 21:58:09 -0600 Subject: How much sanity checking is required for function inputs? In-Reply-To: <571C4072.1000005@icloud.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> <571C21A3.5090507@icloud.com> <571C302C.2010800@icloud.com> <571C3B5C.8030403@gmail.com> <571C4072.1000005@icloud.com> Message-ID: <571C4451.2060905@gmail.com> On 04/23/2016 09:41 PM, Christopher Reimer wrote: > I never wanted to learn Java in the first place. My community college > couldn't afford to renew the Microsoft site license, which local > employers required to learn C/C++ in MS Visual Studio, and all flavors > of Java got taught for the programming classes instead. I wanted to > learn C/C++. I even wanted to learn assembly language, but I was the > only student who showed up for the class and it got cancelled. > > Of course, it probably doesn't help that I got a job in help desk > support after I graduated with A.S. degree in Java and never programmed > professionally. Thinking like a programmer helped me resolved many IT > problems over the last 12 years. My current job in computer security > requires tinkering with PowerShell scripts as Python is strictly > prohibited in this Windows shop. I have made Python my main programming > language at home. I don't mean to imply that I'm criticizing you for your Java experience! I am critical of Java, though. I'm very glad you've discovered Python and I hope you'll continue to have fun with it. I hope you'll take the advice offered by the others on this thread in stride and hopefully we'll all learn and benefit. I completely agree with you that learning to think like a programmer is so helpful in solving all kinds of problems, especially in IT! From steve at pearwood.info Sun Apr 24 01:38:25 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 24 Apr 2016 15:38:25 +1000 Subject: How much sanity checking is required for function inputs? References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <57198827.1020608@stoneleaf.us> <5719964E.2050400@icloud.com> <571C2957.7060508@icloud.com> Message-ID: <571c5bd3$0$1602$c3e8da3$5496439d@news.astraweb.com> On Sun, 24 Apr 2016 12:03 pm, Christopher Reimer wrote: > On 4/23/2016 2:33 PM, Matt Wheeler wrote: >> This is still backwards to me. It prevents your classes from being >> suitable for restoring a stored game state, not just custom starting >> positions (which I think is what Ethan means by custom setups). > > I haven't thought that far about saving the game state. I'm under the > impression that pickle (or something else) would save and load the > instantiated object of each piece. If that's not the case, I'll change > the code then. Pickle will do what you are thinking of, but pickle is not secure and involves executing arbitrary code. If you cannot trust the source of the pickle, then you should not use it. -- Steven From steve at pearwood.info Sun Apr 24 01:49:36 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 24 Apr 2016 15:49:36 +1000 Subject: How much sanity checking is required for function inputs? References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> <571C2541.9050309@icloud.com> <571C30C8.5000208@gmail.com> Message-ID: <571c5e72$0$1615$c3e8da3$5496439d@news.astraweb.com> On Sun, 24 Apr 2016 12:34 pm, Michael Torrie wrote: > There are many aspects to Pythonic programming, not just OOP. For > example using modules to store shared state for your program components > is very pythonic, rather than using classes. A module is kind of like a > singleton instance, and still is object-oriented by the way (the module > is an object). I find myself going backwards and forwards on whether or not that is a good idea. I think it depends on whether you are writing a library or an application. If you're writing an application, then storing state in module-level variables works fine. Your application is, effectively, a singleton, and if you try to run it twice, you'll (probably) be running it in two distinct processes, so that's okay. (If you're not, if somehow you perform some sort of trickery where you have a single Python interpreter running your script twice in the same process, then it will break horribly. But if you can do that, you're living on the edge already and can probably deal with it.) But if you're writing a library, then using module state is a Bad Idea. Your library may be used by more than one client in the same process, and they will conflict over each other's library-level state. "Global variables considered harmful." -- Steven From marko at pacujo.net Sun Apr 24 01:56:24 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 24 Apr 2016 08:56:24 +0300 Subject: How much sanity checking is required for function inputs? References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <57198827.1020608@stoneleaf.us> <5719964E.2050400@icloud.com> <571C2957.7060508@icloud.com> <571c5bd3$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8737qby2gn.fsf@elektro.pacujo.net> Steven D'Aprano : > On Sun, 24 Apr 2016 12:03 pm, Christopher Reimer wrote: > >> On 4/23/2016 2:33 PM, Matt Wheeler wrote: >>> This is still backwards to me. It prevents your classes from being >>> suitable for restoring a stored game state, not just custom starting >>> positions (which I think is what Ethan means by custom setups). >> >> I haven't thought that far about saving the game state. I'm under the >> impression that pickle (or something else) would save and load the >> instantiated object of each piece. If that's not the case, I'll change >> the code then. > > Pickle will do what you are thinking of, but pickle is not secure and > involves executing arbitrary code. If you cannot trust the source of > the pickle, then you should not use it. You shouldn't use your runtime objects as a storage format. Instead, design the storage objects separately and translate between runtime and storage objects as needed. JSON objects or straight Python dicts are good candidates for overall storage format. JSON would allow for easy interchange between different programming languages if need be. Marko From michael.selik at gmail.com Sun Apr 24 02:40:31 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sun, 24 Apr 2016 06:40:31 +0000 Subject: How much sanity checking is required for function inputs? In-Reply-To: <571c5e72$0$1615$c3e8da3$5496439d@news.astraweb.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> <571C2541.9050309@icloud.com> <571C30C8.5000208@gmail.com> <571c5e72$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 24, 2016, 1:51 AM Steven D'Aprano wrote: > On Sun, 24 Apr 2016 12:34 pm, Michael Torrie wrote: > > > There are many aspects to Pythonic programming, not just OOP. For > > example using modules to store shared state for your program components > > is very pythonic, rather than using classes. A module is kind of like a > > singleton instance, and still is object-oriented by the way (the module > > is an object). > > I find myself going backwards and forwards on whether or not that is a good > idea. I think it depends on whether you are writing a library or an > application. > > If you're writing an application, then storing state in module-level > variables works fine. Your application is, effectively, a singleton, and if > you try to run it twice, you'll (probably) be running it in two distinct > processes, so that's okay. > > (If you're not, if somehow you perform some sort of trickery where you have > a single Python interpreter running your script twice in the same process, > then it will break horribly. But if you can do that, you're living on the > edge already and can probably deal with it.) > > But if you're writing a library, then using module state is a Bad Idea. > Your > library may be used by more than one client in the same process, and they > will conflict over each other's library-level state. "Global variables > considered harmful." > I think we're giving mixed messages because we're conflating "constants" and globals that are expected to change. In our case here, I think two clients in the same process sharing state might be a feature rather than a bug. Or at least it has the same behavior as the current implementation. > From ethan at stoneleaf.us Sun Apr 24 03:20:58 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 24 Apr 2016 00:20:58 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <5719ACBB.8020905@stoneleaf.us> <571C1AA8.8000202@icloud.com> Message-ID: <571C73DA.8020608@stoneleaf.us> On 04/23/2016 06:29 PM, Ian Kelly wrote: > Python enums are great. Sadly, they're still not quite as awesome as Java enums. What fun things can Java enums do? -- ~Ethan~ From ethan at stoneleaf.us Sun Apr 24 03:22:58 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 24 Apr 2016 00:22:58 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <5719ACBB.8020905@stoneleaf.us> <571C1AA8.8000202@icloud.com> Message-ID: <571C7452.5060501@stoneleaf.us> On 04/23/2016 06:21 PM, Michael Selik wrote: > On Sat, Apr 23, 2016 at 9:01 PM Christopher Reimer wrote: >> Hmm... What do we use Enum for? :) > > You can use Enum in certain circumstances to replace int or str constants. > It can help avoid mistyping mistakes and might help your IDE give > auto-complete suggestions. I haven't found a good use for them myself, but > I'd been mostly stuck in Python 2 until recently. enum34 is the backport, aenum is the turbo charged version. https://pypi.python.org/pypi/enum34 https://pypi.python.org/pypi/aenum -- ~Ethan~ From fabien.maussion at gmail.com Sun Apr 24 06:20:33 2016 From: fabien.maussion at gmail.com (Fabien) Date: Sun, 24 Apr 2016 12:20:33 +0200 Subject: A pickle problem! References: Message-ID: On 04/21/2016 11:43 PM, Paulo da Silva wrote: > class C(pd.DataFrame): Note also that subclassing pandas is not always encouraged: http://pandas.pydata.org/pandas-docs/stable/internals.html#subclassing-pandas-data-structures Cheers, Fabien From sjeik_appie at hotmail.com Sun Apr 24 06:42:41 2016 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Sun, 24 Apr 2016 10:42:41 +0000 Subject: Remove directory tree without following symlinks In-Reply-To: References: <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com>, <1461337766.365000.586700849.0DDBDB0B@webmail.messagingengine.com>, , <571a5be6$0$1590$c3e8da3$5496439d@news.astraweb.com>, , , , Message-ID: > From: eryksun at gmail.com > Date: Sat, 23 Apr 2016 15:22:35 -0500 > Subject: Re: Remove directory tree without following symlinks > To: python-list at python.org > > On Sat, Apr 23, 2016 at 4:34 AM, Albert-Jan Roskam > wrote: >> >>> From: eryksun at gmail.com >>> Date: Fri, 22 Apr 2016 13:28:01 -0500 >>> On Fri, Apr 22, 2016 at 12:39 PM, Albert-Jan Roskam >>> wrote: >>>> FYI, Just today I found out that shutil.rmtree raises a WindowsError if >>>> the dir is read-only (or its contents). Using 'ignore_errors', won't help. >>>> Sure, no error is raised, but the dir is not deleted either! A 'force' option >>>> would be a nice improvement. >>> >>> Use the onerror handler to call os.chmod(path, stat.S_IWRITE). For >>> example, see pip's rmtree_errorhandler: >>> >>> https://github.com/pypa/pip/blob/8.1.1/pip/utils/__init__.py#L105 >> >> Thanks, that looks useful indeed. I thought about os.chmod, but with >> os.walk. That seemed expensive. So I used subprocess.call('rmdir "%s" /s /q' >> % dirname). That's Windows only, of course, but aside of that, is using >> subprocess less preferable? > > I assume you used shell=True in the above call, and not an external > rmdir.exe. There are security concerns with using the shell if you're > not in complete control of the command line. > > As to performance, cmd's rmdir wins without question, not only because > it's implemented in C, but also because it uses the stat data from the > WIN32_FIND_DATA returned by FindFirstFile/FindNextFile to check for > FILE_ATTRIBUTE_DIRECTORY and FILE_ATTRIBUTE_READONLY. > > On the other hand, Python wins when it comes to working with deeply > nested directories. Paths in cmd are limited to MAX_PATH characters. > rmdir uses DOS 8.3 short names (i.e. cAlternateFileName in > WIN32_FIND_DATA), but that could still exceed MAX_PATH for a deeply > nested tree, or the volume may not even have 8.3 DOS filenames. > shutil.rmtree allows you to work around the DOS limit by prefixing the > path with "\\?\". For example: > > >>> subprocess.call(r'rmdir /q/s Z:\Temp\long', shell=True) > The path Z:\Temp\long\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > aaaaa is too long. > 0 > > >>> shutil.rmtree(r'\\?\Z:\Temp\long') > >>> os.path.exists(r'Z:\Temp\long') > False > > Using "\\?\" requires a path that's fully qualified, normalized > (backslash only), and unicode (i.e. decode a Python 2 str). Aww, I kinda forgot about that already, but I came across this last year [1]. Apparently, shutil.rmtree(very_long_path) failed under Win 7, even with the "silly prefix". I believe very_long_path was a Python2-str. It seems useful if shutil or os.path would automatically prefix paths with "\\?\". It is rarely really needed, though. (in my case it was needed to copy a bunch of MS Outlook .msg files, which automatically get the subject line as the filename, and perhaps the first sentence of the mail of the mail has no subject). [1] https://mail.python.org/pipermail/python-list/2015-June/693156.html From ethan at stoneleaf.us Sun Apr 24 10:41:43 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 24 Apr 2016 07:41:43 -0700 Subject: How much sanity checking is required for function inputs? In-Reply-To: <571C1AA8.8000202@icloud.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <5719ACBB.8020905@stoneleaf.us> <571C1AA8.8000202@icloud.com> Message-ID: <571CDB27.7080909@stoneleaf.us> On 04/23/2016 06:00 PM, Christopher Reimer wrote: > Hmm... What do we use Enum for? :) from enum import Enum class Piece(Enum): king = 'one space, any direction' queen = 'many spaces, any direction' bishop = 'many spaces, diagonal' knight = 'two spaces cardinal, one space sideways, cannot be blocked' rook = 'many spaces, cardinal' pawn = 'first move: one or two spaces forward; subsequent moves: one space forward; attack: one space diagonal' --> list(Piece) [ , , , , , , ] --> p = Piece.bishop --> p in Piece True --> p is Piece.rook False --> p is Piece.bishop True -- ~Ethan~ From ian.g.kelly at gmail.com Sun Apr 24 11:20:24 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 24 Apr 2016 09:20:24 -0600 Subject: Comparing Python enums to Java, was: How much sanity checking is required for function inputs? Message-ID: On Sun, Apr 24, 2016 at 1:20 AM, Ethan Furman wrote: > On 04/23/2016 06:29 PM, Ian Kelly wrote: > >> Python enums are great. Sadly, they're still not quite as awesome as Java >> enums. > > > What fun things can Java enums do? Everything that Python enums can do, plus: * You can override methods of individual values, not just the class as a whole. Good for implementing the strategy pattern, or for defining a default method implementation that one or two values do differently. In Python you can emulate the same thing by adding the method directly to the instance dict of the enum value, so this isn't really all that much of a difference. * Java doesn't have the hokey notion of enum instances being distinct from their "value". The individual enum members *are* the values. Whereas in Python an enum member is an awkward class instance that contains a value of some other type. Python tries to get away from the C-like notion that enums are ints by making the enum members non-comparable, but then gives us IntEnum as a way to work around it if we really want to. Since Java enums don't depend on any other type for their values, there's nothing inviting the user to treat enums as ints in the first place. * As a consequence of the above, Java doesn't conflate enum values with their parameters. The Python enum docs give us this interesting example of an enum that takes arguments from its declaration: >>> class Planet(Enum): ... MERCURY = (3.303e+23, 2.4397e6) ... VENUS = (4.869e+24, 6.0518e6) ... EARTH = (5.976e+24, 6.37814e6) ... MARS = (6.421e+23, 3.3972e6) ... JUPITER = (1.9e+27, 7.1492e7) ... SATURN = (5.688e+26, 6.0268e7) ... URANUS = (8.686e+25, 2.5559e7) ... NEPTUNE = (1.024e+26, 2.4746e7) ... def __init__(self, mass, radius): ... self.mass = mass # in kilograms ... self.radius = radius # in meters ... @property ... def surface_gravity(self): ... # universal gravitational constant (m3 kg-1 s-2) ... G = 6.67300E-11 ... return G * self.mass / (self.radius * self.radius) ... >>> Planet.EARTH.value (5.976e+24, 6378140.0) >>> Planet.EARTH.surface_gravity 9.802652743337129 This is incredibly useful, but it has a flaw: the value of each member of the enum is just the tuple of its arguments. Suppose we added a value for COUNTER_EARTH describing a hypothetical planet with the same mass and radius existing on the other side of the sun. [1] Then: >>> Planet.EARTH is Planet.COUNTER_EARTH True Because they have the same "value", instead of creating a separate member, COUNTER_EARTH gets defined as an alias for EARTH. To work around this, one would have to add a third argument to the above to pass in an additional value for the sole purpose of distinguishing (or else adapt the AutoNumber recipe to work with this example). This example is a bit contrived since it's generally not likely to come up with floats, but it can easily arise (and in my experience frequently does) when the arguments are of more discrete types. It's notable that the Java enum docs feature this very same example but without this weakness. [2] * Speaking of AutoNumber, since Java enums don't have the instance/value distinction, they effectively do this implicitly, only without generating a bunch of ints that are entirely irrelevant to your enum type. With Python enums you have to follow a somewhat arcane recipe to avoid specifying values, which just generates some values and then hides them away. And it also breaks the Enum alias feature: >>> class Color(AutoNumber): ... red = default = () # not an alias! ... blue = () ... >>> Color.red is Color.default False Anyroad, I think that covers all my beefs with the way enums are implemented in Python. Despite the above, they're a great feature, and I use them and appreciate that we have them. [1] https://en.wikipedia.org/wiki/Counter-Earth [2] https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html From ethan at stoneleaf.us Sun Apr 24 12:04:59 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 24 Apr 2016 09:04:59 -0700 Subject: Comparing Python enums to Java, was: How much sanity checking is required for function inputs? In-Reply-To: References: Message-ID: <571CEEAB.6090300@stoneleaf.us> On 04/24/2016 08:20 AM, Ian Kelly wrote: > On Sun, Apr 24, 2016 at 1:20 AM, Ethan Furman wrote: >> On 04/23/2016 06:29 PM, Ian Kelly wrote: >>> Python enums are great. Sadly, they're still not quite as awesome as Java >>> enums. >> >> >> What fun things can Java enums do? > > Everything that Python enums can do, plus: > > * You can override methods of individual values, not just the class as > a whole. Good for implementing the strategy pattern, or for defining a > default method implementation that one or two values do differently. > In Python you can emulate the same thing by adding the method directly > to the instance dict of the enum value, so this isn't really all that > much of a difference. All non-dunder methods, at least. > * Java doesn't have the hokey notion of enum instances being distinct > from their "value". The individual enum members *are* the values. > Whereas in Python an enum member is an awkward class instance that > contains a value of some other type. Python tries to get away from the > C-like notion that enums are ints by making the enum members > non-comparable, but then gives us IntEnum as a way to work around it > if we really want to. Since Java enums don't depend on any other type > for their values, there's nothing inviting the user to treat enums as > ints in the first place. How does Java share enums with other programs, computers, and/or languages? As far as value-separate-from-instance: if you want/need them to be the same thing, mix-in the type: class Planet(float, Enum): ... [see below for "no-alias" ideas/questions] NB: The enum and the value are still different ('is' fails) but equal. > * As a consequence of the above, Java doesn't conflate enum values > with their parameters. The Python enum docs give us this interesting > example of an enum that takes arguments from its declaration: > >>>> class Planet(Enum): > ... MERCURY = (3.303e+23, 2.4397e6) > ... VENUS = (4.869e+24, 6.0518e6) > ... EARTH = (5.976e+24, 6.37814e6) > ... MARS = (6.421e+23, 3.3972e6) > ... JUPITER = (1.9e+27, 7.1492e7) > ... SATURN = (5.688e+26, 6.0268e7) > ... URANUS = (8.686e+25, 2.5559e7) > ... NEPTUNE = (1.024e+26, 2.4746e7) > ... def __init__(self, mass, radius): > ... self.mass = mass # in kilograms > ... self.radius = radius # in meters > ... @property > ... def surface_gravity(self): > ... # universal gravitational constant (m3 kg-1 s-2) > ... G = 6.67300E-11 > ... return G * self.mass / (self.radius * self.radius) > ... >>>> Planet.EARTH.value > (5.976e+24, 6378140.0) >>>> Planet.EARTH.surface_gravity > 9.802652743337129 > > This is incredibly useful, but it has a flaw: the value of each member > of the enum is just the tuple of its arguments. Suppose we added a > value for COUNTER_EARTH describing a hypothetical planet with the same > mass and radius existing on the other side of the sun. [1] Then: > >>>> Planet.EARTH is Planet.COUNTER_EARTH > True > > Because they have the same "value", instead of creating a separate > member, COUNTER_EARTH gets defined as an alias for EARTH. To work > around this, one would have to add a third argument to the above to > pass in an additional value for the sole purpose of distinguishing (or > else adapt the AutoNumber recipe to work with this example). This > example is a bit contrived since it's generally not likely to come up > with floats, but it can easily arise (and in my experience frequently > does) when the arguments are of more discrete types. It's notable that > the Java enum docs feature this very same example but without this > weakness. [2] One reason for this is that Python enums are lookup-able via the value: >>> Planet(9.80265274333129) Planet.EARTH Do Java enums not have such a feature, or this "feature" totally unnecessary in Java? I could certainly add a "no-alias" feature to aenum. What would be the appropriate value-lookup behaviour in such cases? - return the first match - return a list of matches - raise an error - disable value-lookups for that Enum > * Speaking of AutoNumber, since Java enums don't have the > instance/value distinction, they effectively do this implicitly, only > without generating a bunch of ints that are entirely irrelevant to > your enum type. With Python enums you have to follow a somewhat arcane > recipe to avoid specifying values, which just generates some values > and then hides them away. And it also breaks the Enum alias feature: > >>>> class Color(AutoNumber): > ... red = default = () # not an alias! > ... blue = () > ... >>>> Color.red is Color.default > False Unfortunately, the empty tuple tends to be a singleton, so there is no way to tell that red and default are (supposed to be) the same and blue is (supposed to be) different: --> a = b = () --> c = () --> a is b True --> a is c True If you have an idea on how to make that work I am interested. > Anyroad, I think that covers all my beefs with the way enums are > implemented in Python. Despite the above, they're a great feature, and > I use them and appreciate that we have them. Cool. The stdlib Enum (and therefore the enum34 backport) is unlikely to change much. However, aenum has a few fun things going on, and I'm happy to add more: - NamedTuple (metaclass-based) - NamedConstant (no aliases, no by-value lookups) - Enum - magic auto-numbering class Number(Enum, auto=True): one, two, three def by_seven(self): return self.value * 7 - auto-setting of attributes class Planet(Enum, init='mass radius'): MERCURY = 3.303e23, 2.4397e6 EARTH = 5.976e24, 6.37814e6 NEPTUNE = 1.024e26, 2.4746e7 --> Planet.EARTH.mass 5.976e24 -- ~Ethan~ From rosuav at gmail.com Sun Apr 24 12:10:05 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Apr 2016 02:10:05 +1000 Subject: Comparing Python enums to Java, was: How much sanity checking is required for function inputs? In-Reply-To: <571CEEAB.6090300@stoneleaf.us> References: <571CEEAB.6090300@stoneleaf.us> Message-ID: On Mon, Apr 25, 2016 at 2:04 AM, Ethan Furman wrote: > Unfortunately, the empty tuple tends to be a singleton, so there is no way > to tell that red and default are (supposed to be) the same and blue is > (supposed to be) different: > > --> a = b = () > --> c = () > --> a is b > True > --> a is c > True > > If you have an idea on how to make that work I am interested. Easy: allow an empty list to have the same meaning as an empty tuple. Every time you have [] in your source code, you're guaranteed to get a new (unique) empty list, and then multiple assignment will work. ChrisA From rosuav at gmail.com Sun Apr 24 12:19:26 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Apr 2016 02:19:26 +1000 Subject: Optimizing Memory Allocation in a Simple, but Long Function In-Reply-To: References: Message-ID: On Sun, Apr 24, 2016 at 1:05 PM, Derek Klinge wrote: > I have been writing a python script to explore Euler's Method of > approximating Euler's Number. I was hoping there might be a way to make > this process work faster, as for sufficiently large eulerSteps, the process > below becomes quite slow and sometimes memory intensive. I'm hoping someone > can give me some insight as to how to optimize these algorithms, or ways I > might decrease memory usage. I have been thinking about finding a way > around importing the math module, as it seems a bit unneeded except as an > easy reference. Are you sure memory is the real problem here? (The first problem you have, incidentally, is a formatting one. All your indentation has been lost. Try posting your code again, in a way that doesn't lose leading spaces/tabs, and then we'll be better able to figure out what's going on.) If I'm reading your code correctly, you have two parts: 1) class EulersNumber, which iterates up to some specific count 2) Module-level functions, which progressively increase the count of constructed EulersNumbers. Between them, you appear to have an O(n*n) algorithm for finding a "sufficiently-accurate" representation. You're starting over from nothing every time. If, instead, you were to start from the previous approximation and add another iteration, that ought to be immensely faster. ChrisA From ethan at stoneleaf.us Sun Apr 24 12:42:10 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 24 Apr 2016 09:42:10 -0700 Subject: Comparing Python enums to Java, was: How much sanity checking is required for function inputs? In-Reply-To: References: <571CEEAB.6090300@stoneleaf.us> Message-ID: <571CF762.4000809@stoneleaf.us> On 04/24/2016 09:10 AM, Chris Angelico wrote: > On Mon, Apr 25, 2016 at 2:04 AM, Ethan Furman wrote: >> Unfortunately, the empty tuple tends to be a singleton, so there is no way >> to tell that red and default are (supposed to be) the same and blue is >> (supposed to be) different: >> >> --> a = b = () >> --> c = () >> --> a is b >> True >> --> a is c >> True >> >> If you have an idea on how to make that work I am interested. > > Easy: allow an empty list to have the same meaning as an empty tuple. > Every time you have [] in your source code, you're guaranteed to get a > new (unique) empty list, and then multiple assignment will work. *sigh* Where were you three years ago? ;) Actually, thinking about it a bit more, if we did that then one could not use an empty list as an enum value. Why would one want to? No idea, but to make it nearly impossible I'd want a much better reason than a minor inconvenience: class Numbers: def __init__(self, value=0): self.value = value def __call__(self, value=None): if value is None: value = self.value self.value = value + 1 return value a = Numbers() class SomeNumbers(Enum): one = a() two = a() five = a(5) six = seis = a() One extra character, and done. -- ~Ethan~ From rosuav at gmail.com Sun Apr 24 12:47:36 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Apr 2016 02:47:36 +1000 Subject: Comparing Python enums to Java, was: How much sanity checking is required for function inputs? In-Reply-To: <571CF762.4000809@stoneleaf.us> References: <571CEEAB.6090300@stoneleaf.us> <571CF762.4000809@stoneleaf.us> Message-ID: On Mon, Apr 25, 2016 at 2:42 AM, Ethan Furman wrote: >> Easy: allow an empty list to have the same meaning as an empty tuple. >> Every time you have [] in your source code, you're guaranteed to get a >> new (unique) empty list, and then multiple assignment will work. > > > *sigh* > > Where were you three years ago? ;) > > Actually, thinking about it a bit more, if we did that then one could not > use an empty list as an enum value. Why would one want to? No idea, but to > make it nearly impossible I'd want a much better reason than a minor > inconvenience: I would normally expect enumerated values to be immutable and hashable, but that isn't actually required by the code AIUI. Under what circumstances is it useful to have mutable enum values? ChrisA From schilke.60 at gmail.com Sun Apr 24 13:02:41 2016 From: schilke.60 at gmail.com (Derek Klinge) Date: Sun, 24 Apr 2016 17:02:41 +0000 Subject: Optimizing Memory Allocation in a Simple, but Long Function In-Reply-To: References: Message-ID: Sorry about the code indentation, I was using Pythonista (iOS), and it did not have any problem with that indentation... Here is a new set of the code: ## Write a method to approximate Euler's Number using Euler's Method import math class EulersNumber(): def __init__(self,n): self.eulerSteps = n self.e = self.EulersMethod(self.eulerSteps) def linearApproximation(self,x,h,d): # f(x+h)=f(x)+h*f'(x) return x + h * d def EulersMethod(self, numberOfSteps): # Repeate linear approximation over an even range e = 1 # e**0 = 1 for step in range(numberOfSteps): e = self.linearApproximation(e,1.0/numberOfSteps,e) # if f(x)= e**x, f'(x)=f(x) return e def EulerStepWithGuess(accuracy,guessForN): n = guessForN e = EulersNumber(n) while abs(e.e - math.e) > abs(accuracy): n +=1 e = EulersNumber(n) print('n={} \te= {} \tdelta(e)={}'.format(n,e.e,abs(e.e - math.e))) return e def EulersNumberToAccuracy(PowerOfTen): x = 1 theGuess = 1 thisE = EulersNumber(1) while x <= abs(PowerOfTen): thisE = EulerStepWithGuess(10**(-1*x),theGuess) theGuess = thisE.eulerSteps * 10 x += 1 return thisE My problem is this: my attempt at Euler's Method involves creating a list of numbers that is n long. Is there a way I can iterate over the linear approximation method without creating a list of steps (maybe recursion, I am a bit new at this). Ideally I'd like to perform the linearApproximation method a arbitrary number of times (hopefully >10**10) and keep feeding the answers back into itself to get the new answer. I know this will be computationally time intensive, but how do I minimize memory usage (limit the size of my list)? I also may be misunderstanding the problem, in which case I am open to looking at it from a different perspective. Thanks, Derek On Sun, Apr 24, 2016 at 9:22 AM Chris Angelico wrote: > On Sun, Apr 24, 2016 at 1:05 PM, Derek Klinge > wrote: > > I have been writing a python script to explore Euler's Method of > > approximating Euler's Number. I was hoping there might be a way to make > > this process work faster, as for sufficiently large eulerSteps, the > process > > below becomes quite slow and sometimes memory intensive. I'm hoping > someone > > can give me some insight as to how to optimize these algorithms, or ways > I > > might decrease memory usage. I have been thinking about finding a way > > around importing the math module, as it seems a bit unneeded except as an > > easy reference. > > Are you sure memory is the real problem here? > > (The first problem you have, incidentally, is a formatting one. All > your indentation has been lost. Try posting your code again, in a way > that doesn't lose leading spaces/tabs, and then we'll be better able > to figure out what's going on.) > > If I'm reading your code correctly, you have two parts: > > 1) class EulersNumber, which iterates up to some specific count > 2) Module-level functions, which progressively increase the count of > constructed EulersNumbers. > > Between them, you appear to have an O(n*n) algorithm for finding a > "sufficiently-accurate" representation. You're starting over from > nothing every time. If, instead, you were to start from the previous > approximation and add another iteration, that ought to be immensely > faster. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From schilke.60 at gmail.com Sun Apr 24 13:06:22 2016 From: schilke.60 at gmail.com (Derek Klinge) Date: Sun, 24 Apr 2016 17:06:22 +0000 Subject: Optimizing Memory Allocation in a Simple, but Long Function In-Reply-To: References: Message-ID: I think my e-mail client may be stripping the indentation, here it is with 4-space indentation ## Write a method to approximate Euler's Number using Euler's Method import math class EulersNumber(): def __init__(self,n): self.eulerSteps = n self.e = self.EulersMethod(self.eulerSteps) def linearApproximation(self,x,h,d): # f(x+h)=f(x)+h*f'(x) return x + h * d def EulersMethod(self, numberOfSteps): # Repeate linear approximation over an even range e = 1 # e**0 = 1 for step in range(numberOfSteps): e = self.linearApproximation(e,1.0/numberOfSteps,e) # if f(x)= e**x, f'(x)=f(x) return e def EulerStepWithGuess(accuracy,guessForN): n = guessForN e = EulersNumber(n) while abs(e.e - math.e) > abs(accuracy): n +=1 e = EulersNumber(n) print('n={} \te= {} \tdelta(e)={}'.format(n,e.e,abs(e.e - math.e))) return e def EulersNumberToAccuracy(PowerOfTen): x = 1 theGuess = 1 thisE = EulersNumber(1) while x <= abs(PowerOfTen): thisE = EulerStepWithGuess(10**(-1*x),theGuess) theGuess = thisE.eulerSteps * 10 x += 1 return thisE On Sun, Apr 24, 2016 at 10:02 AM Derek Klinge wrote: > Sorry about the code indentation, I was using Pythonista (iOS), and it did > not have any problem with that indentation... > > Here is a new set of the code: > ## Write a method to approximate Euler's Number using Euler's Method > import math > > class EulersNumber(): > def __init__(self,n): > self.eulerSteps = n > self.e = self.EulersMethod(self.eulerSteps) > def linearApproximation(self,x,h,d): # f(x+h)=f(x)+h*f'(x) > return x + h * d > def EulersMethod(self, numberOfSteps): # Repeate linear approximation over > an even range > e = 1 # e**0 = 1 > for step in range(numberOfSteps): > e = self.linearApproximation(e,1.0/numberOfSteps,e) # if f(x)= e**x, > f'(x)=f(x) > return e > > def EulerStepWithGuess(accuracy,guessForN): > n = guessForN > e = EulersNumber(n) > while abs(e.e - math.e) > abs(accuracy): > n +=1 > e = EulersNumber(n) > print('n={} \te= {} \tdelta(e)={}'.format(n,e.e,abs(e.e - math.e))) > return e > > def EulersNumberToAccuracy(PowerOfTen): > x = 1 > theGuess = 1 > thisE = EulersNumber(1) > while x <= abs(PowerOfTen): > thisE = EulerStepWithGuess(10**(-1*x),theGuess) > theGuess = thisE.eulerSteps * 10 > x += 1 > return thisE > > My problem is this: my attempt at Euler's Method involves creating a list > of numbers that is n long. Is there a way I can iterate over the linear > approximation method without creating a list of steps (maybe recursion, I > am a bit new at this). Ideally I'd like to perform the linearApproximation > method a arbitrary number of times (hopefully >10**10) and keep feeding the > answers back into itself to get the new answer. I know this will be > computationally time intensive, but how do I minimize memory usage (limit > the size of my list)? I also may be misunderstanding the problem, in which > case I am open to looking at it from a different perspective. > > Thanks, > Derek > > On Sun, Apr 24, 2016 at 9:22 AM Chris Angelico wrote: > >> On Sun, Apr 24, 2016 at 1:05 PM, Derek Klinge >> wrote: >> > I have been writing a python script to explore Euler's Method of >> > approximating Euler's Number. I was hoping there might be a way to make >> > this process work faster, as for sufficiently large eulerSteps, the >> process >> > below becomes quite slow and sometimes memory intensive. I'm hoping >> someone >> > can give me some insight as to how to optimize these algorithms, or >> ways I >> > might decrease memory usage. I have been thinking about finding a way >> > around importing the math module, as it seems a bit unneeded except as >> an >> > easy reference. >> >> Are you sure memory is the real problem here? >> >> (The first problem you have, incidentally, is a formatting one. All >> your indentation has been lost. Try posting your code again, in a way >> that doesn't lose leading spaces/tabs, and then we'll be better able >> to figure out what's going on.) >> >> If I'm reading your code correctly, you have two parts: >> >> 1) class EulersNumber, which iterates up to some specific count >> 2) Module-level functions, which progressively increase the count of >> constructed EulersNumbers. >> >> Between them, you appear to have an O(n*n) algorithm for finding a >> "sufficiently-accurate" representation. You're starting over from >> nothing every time. If, instead, you were to start from the previous >> approximation and add another iteration, that ought to be immensely >> faster. >> >> ChrisA >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From rosuav at gmail.com Sun Apr 24 13:09:49 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Apr 2016 03:09:49 +1000 Subject: Challenge: Shadow lots of built-ins Message-ID: This is mostly just for the fun of it, but every now and then I have a discussion with people about why it's legal to shadow Python's built-in names, and it'd be handy to have a go-to piece of demo code. So here's the challenge: Write a short, readable block of code that shadows as many built-ins as possible. The rules: 1) The code has to be readable on its own. Doesn't have to be fully functional (it's okay to presume the existence of a back-end database, for instance), but a human should be able to parse it easily. 2) PEP 8, please, for consistency. 3) Code should be Python 3.x compatible. 4) Every shadowed name MUST make sense. You would have to plausibly use this exact same name in some other language. 5) Have fun! Enjoy writing suboptimal code! :) Here's a starter. def zip_all(root): """Compress a directory, skipping dotfiles Returns the created zip file and a list of stuff that got dropped into the bin. """ bin = [] with zipfile.ZipFile("temp.zip", "w") as zip: for root, dirs, files in os.walk("."): for dir in dirs: if dir.startswith("."): dirs.remove(dir) bin.append(os.path.join(root, dir)) for file in files: if not file.startswith("."): zip.write(os.path.join(root, file)) return zip, bin That's only four, and I know you folks can do way better than that! ChrisA From rosuav at gmail.com Sun Apr 24 13:11:44 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Apr 2016 03:11:44 +1000 Subject: Optimizing Memory Allocation in a Simple, but Long Function In-Reply-To: References: Message-ID: On Mon, Apr 25, 2016 at 3:06 AM, Derek Klinge wrote: > I think my e-mail client may be stripping the indentation, here it is with > 4-space indentation I think it is. Both your reposted versions have indentation lost. You may need to use a different client. My posts come from the Gmail web client and indentation usually comes through just fine (tabs are sometimes lost, but spaces never are). FWIW, I have "Rich Text" disabled - not sure if that makes a difference. ChrisA From rosuav at gmail.com Sun Apr 24 13:15:43 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Apr 2016 03:15:43 +1000 Subject: Optimizing Memory Allocation in a Simple, but Long Function In-Reply-To: References: Message-ID: On Mon, Apr 25, 2016 at 3:02 AM, Derek Klinge wrote: > My problem is this: my attempt at Euler's Method involves creating a list of > numbers that is n long. Is there a way I can iterate over the linear > approximation method without creating a list of steps (maybe recursion, I am > a bit new at this). Ideally I'd like to perform the linearApproximation > method a arbitrary number of times (hopefully >10**10) and keep feeding the > answers back into itself to get the new answer. I know this will be > computationally time intensive, but how do I minimize memory usage (limit > the size of my list)? I also may be misunderstanding the problem, in which > case I am open to looking at it from a different perspective. def EulersMethod(self, numberOfSteps): # Repeate linear approximation over an even range e = 1 # e**0 = 1 for step in range(numberOfSteps): e = self.linearApproximation(e,1.0/numberOfSteps,e) # if f(x)= e**x, f'(x)=f(x) return e This is your code, right? I'm not seeing anywhere in here that creates a list of numbers. It does exactly what you're hoping for: it feeds the answer back to itself for the next step. ChrisA From bc at freeuk.com Sun Apr 24 13:54:57 2016 From: bc at freeuk.com (BartC) Date: Sun, 24 Apr 2016 18:54:57 +0100 Subject: Comparing Python enums to Java, was: How much sanity checking is required for function inputs? In-Reply-To: References: <571CEEAB.6090300@stoneleaf.us> <571CF762.4000809@stoneleaf.us> Message-ID: On 24/04/2016 17:47, Chris Angelico wrote: > On Mon, Apr 25, 2016 at 2:42 AM, Ethan Furman wrote: >>> Easy: allow an empty list to have the same meaning as an empty tuple. >>> Every time you have [] in your source code, you're guaranteed to get a >>> new (unique) empty list, and then multiple assignment will work. >> >> >> *sigh* >> >> Where were you three years ago? ;) >> >> Actually, thinking about it a bit more, if we did that then one could not >> use an empty list as an enum value. Why would one want to? No idea, but to >> make it nearly impossible I'd want a much better reason than a minor >> inconvenience: > > I would normally expect enumerated values to be immutable and > hashable, And, perhaps, to be actual enumerations. (So that in the set (a,b,c,d), you don't know nor care about the underlying values, except that they are distinct.) -- Bartc From schilke.60 at gmail.com Sun Apr 24 13:56:10 2016 From: schilke.60 at gmail.com (Derek Klinge) Date: Sun, 24 Apr 2016 17:56:10 +0000 Subject: Optimizing Memory Allocation in a Simple, but Long Function In-Reply-To: References: Message-ID: Doesn't range(n) create a list n long? On Sun, Apr 24, 2016 at 10:21 AM Chris Angelico wrote: > On Mon, Apr 25, 2016 at 3:02 AM, Derek Klinge > wrote: > > My problem is this: my attempt at Euler's Method involves creating a > list of > > numbers that is n long. Is there a way I can iterate over the linear > > approximation method without creating a list of steps (maybe recursion, > I am > > a bit new at this). Ideally I'd like to perform the linearApproximation > > method a arbitrary number of times (hopefully >10**10) and keep feeding > the > > answers back into itself to get the new answer. I know this will be > > computationally time intensive, but how do I minimize memory usage (limit > > the size of my list)? I also may be misunderstanding the problem, in > which > > case I am open to looking at it from a different perspective. > > def EulersMethod(self, numberOfSteps): # Repeate linear approximation > over an even range > e = 1 # e**0 = 1 > for step in range(numberOfSteps): > e = self.linearApproximation(e,1.0/numberOfSteps,e) # if f(x)= > e**x, f'(x)=f(x) > return e > > This is your code, right? > > I'm not seeing anywhere in here that creates a list of numbers. It > does exactly what you're hoping for: it feeds the answer back to > itself for the next step. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sun Apr 24 14:00:01 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Apr 2016 04:00:01 +1000 Subject: Optimizing Memory Allocation in a Simple, but Long Function In-Reply-To: References: Message-ID: On Mon, Apr 25, 2016 at 3:56 AM, Derek Klinge wrote: > Doesn't range(n) create a list n long? Not in Python 3. If your code is running on Python 2, use xrange instead of range. I rather doubt that's your problem, though. ChrisA From steve at pearwood.info Sun Apr 24 14:00:07 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 25 Apr 2016 04:00:07 +1000 Subject: How much sanity checking is required for function inputs? References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> <571C2541.9050309@icloud.com> <571C30C8.5000208@gmail.com> <571c5e72$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <571d09aa$0$1618$c3e8da3$5496439d@news.astraweb.com> On Sun, 24 Apr 2016 04:40 pm, Michael Selik wrote: > I think we're giving mixed messages because we're conflating "constants" > and globals that are expected to change. When you talk about "state", that usually means "the current state of the program", not constants. math.pi is not "state". > In our case here, I think two clients in the same process sharing state > might be a feature rather than a bug. Or at least it has the same behavior > as the current implementation. I don't think so. Two clients sharing state is exactly what makes thread programming with shared state so exciting. Suppose you import the decimal module, and set the global context: py> import decimal py> decimal.setcontext(decimal.ExtendedContext) py> decimal.getcontext().prec = 18 py> decimal.Decimal(1)/3 Decimal('0.333333333333333333') Great. Now a millisecond later you do the same calculation: py> decimal.Decimal(1)/3 Decimal('0.33333') WTF just happened here??? The answer is, another client of the module, one you may not even know about, has set the global context: decimal.getcontext().prec = 5 and screwed you over but good. -- Steven From rosuav at gmail.com Sun Apr 24 14:01:40 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Apr 2016 04:01:40 +1000 Subject: Comparing Python enums to Java, was: How much sanity checking is required for function inputs? In-Reply-To: References: <571CEEAB.6090300@stoneleaf.us> <571CF762.4000809@stoneleaf.us> Message-ID: On Mon, Apr 25, 2016 at 3:54 AM, BartC wrote: > On 24/04/2016 17:47, Chris Angelico wrote: >> >> On Mon, Apr 25, 2016 at 2:42 AM, Ethan Furman wrote: >>>> >>>> Easy: allow an empty list to have the same meaning as an empty tuple. >>>> Every time you have [] in your source code, you're guaranteed to get a >>>> new (unique) empty list, and then multiple assignment will work. >>> >>> >>> >>> *sigh* >>> >>> Where were you three years ago? ;) >>> >>> Actually, thinking about it a bit more, if we did that then one could not >>> use an empty list as an enum value. Why would one want to? No idea, but >>> to >>> make it nearly impossible I'd want a much better reason than a minor >>> inconvenience: >> >> >> I would normally expect enumerated values to be immutable and >> hashable, > > > And, perhaps, to be actual enumerations. (So that in the set (a,b,c,d), you > don't know nor care about the underlying values, except that they are > distinct.) Not necessarily; often, the Python enumeration has to sync up with someone else's, possibly in C. It might not matter that BUTTON_OK is 1 and BUTTON_CANCEL is 2, but you have to make sure that everyone agrees on those meanings. So when you build the Python module, it's mandatory that those values be exactly what they are documented as. ChrisA From santanu01 at gmail.com Sun Apr 24 14:05:36 2016 From: santanu01 at gmail.com (San) Date: Sun, 24 Apr 2016 11:05:36 -0700 (PDT) Subject: from __future__ import print_function Message-ID: <59fb8aab-ff6b-4922-899a-f1b24739887f@googlegroups.com> Hi All, I want details explanation(why this statement used,when it can be used,etc) of following statement in python code "from __future__ import print_function" Thanks in advance. From ethan at stoneleaf.us Sun Apr 24 14:12:40 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 24 Apr 2016 11:12:40 -0700 Subject: Comparing Python enums to Java, was: How much sanity checking is required for function inputs? In-Reply-To: References: <571CEEAB.6090300@stoneleaf.us> <571CF762.4000809@stoneleaf.us> Message-ID: <571D0C98.2020403@stoneleaf.us> On 04/24/2016 09:47 AM, Chris Angelico wrote: > I would normally expect enumerated values to be immutable and > hashable, but that isn't actually required by the code AIUI. Under > what circumstances is it useful to have mutable enum values? Values can be anything. The names are immutable and hashable. -- ~Ethan~ From joel.goldstick at gmail.com Sun Apr 24 14:14:16 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 24 Apr 2016 14:14:16 -0400 Subject: from __future__ import print_function In-Reply-To: <59fb8aab-ff6b-4922-899a-f1b24739887f@googlegroups.com> References: <59fb8aab-ff6b-4922-899a-f1b24739887f@googlegroups.com> Message-ID: On Sun, Apr 24, 2016 at 2:05 PM, San wrote: > Hi All, > I want details explanation(why this statement used,when it can be used,etc) of following statement in python code > > "from __future__ import print_function" > > Thanks in advance. > -- > https://mail.python.org/mailman/listinfo/python-list It lets python 2.7 use python 3.x print function instead of the 2.7 print statement. You might like some of the options, and your code will be easier to upgrade to 3.x if you decide to do that -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From rosuav at gmail.com Sun Apr 24 14:21:51 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Apr 2016 04:21:51 +1000 Subject: Optimizing Memory Allocation in a Simple, but Long Function In-Reply-To: References: Message-ID: On Mon, Apr 25, 2016 at 4:03 AM, Derek Klinge wrote: > Ok, from the gmail web client: Bouncing this back to the list, and removing quote markers for other people's copy/paste convenience. ## Write a method to approximate Euler's Number using Euler's Method import math class EulersNumber(): def __init__(self,n): self.eulerSteps = n self.e = self.EulersMethod(self.eulerSteps) def linearApproximation(self,x,h,d): # f(x+h)=f(x)+h*f'(x) return x + h * d def EulersMethod(self, numberOfSteps): # Repeate linear approximation over an even range e = 1 # e**0 = 1 for step in range(numberOfSteps): e = self.linearApproximation(e,1.0/numberOfSteps,e) # if f(x)= e**x, f'(x)=f(x) return e def EulerStepWithGuess(accuracy,guessForN): n = guessForN e = EulersNumber(n) while abs(e.e - math.e) > abs(accuracy): n +=1 e = EulersNumber(n) print('n={} \te= {} \tdelta(e)={}'.format(n,e.e,abs(e.e - math.e))) return e def EulersNumberToAccuracy(PowerOfTen): x = 1 theGuess = 1 thisE = EulersNumber(1) while x <= abs(PowerOfTen): thisE = EulerStepWithGuess(10**(-1*x),theGuess) theGuess = thisE.eulerSteps * 10 x += 1 return thisE > To see an example of my problem try something like EulersNumberToAccuracy(-10) Yep, I see it. I invoked your script as "python3 -i euler.py" and then made that call interactively. It quickly ran through the first few iterations, and then had one CPU core saturated; but at no time did memory usage look too bad. You may be correct in Python 2, though - it started using about 4GB of RAM (not a problem to me - I had about 9GB available when I started it), and then I halted it. The Python 3 version has been running for a few minutes now. n=135914023 e= 2.718281818459972 delta(e)=9.999073125044333e-09 'top' says: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 7467 rosuav 20 0 32432 9072 4844 R 100.0 0.1 3:58.44 python3 In other words, it's saturating one CPU core ("%CPU 100.0"), but its memory usage (VIRT/RES/SHR) is very low. At best, this process can be blamed for 0.1% of memory. Adding these lines to the top makes it behave differently in Python 2: try: range = xrange except NameError: pass The Py3 behaviour won't change, but Py2 should now have the same kind of benefit (the xrange object is an iterable that doesn't need a concrete list of integers). ChrisA From rosuav at gmail.com Sun Apr 24 14:27:43 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Apr 2016 04:27:43 +1000 Subject: Comparing Python enums to Java, was: How much sanity checking is required for function inputs? In-Reply-To: <571D0C98.2020403@stoneleaf.us> References: <571CEEAB.6090300@stoneleaf.us> <571CF762.4000809@stoneleaf.us> <571D0C98.2020403@stoneleaf.us> Message-ID: On Mon, Apr 25, 2016 at 4:12 AM, Ethan Furman wrote: > On 04/24/2016 09:47 AM, Chris Angelico wrote: > >> I would normally expect enumerated values to be immutable and >> hashable, but that isn't actually required by the code AIUI. Under >> what circumstances is it useful to have mutable enum values? > > > Values can be anything. The names are immutable and hashable. I know they *can* be, because I looked in the docs; but does it make sense to a human? Sure, we can legally do this: >>> class Color(Enum): ... red = 1 ... green = 2 ... blue = 3 ... break_me = [0xA0, 0xF0, 0xC0] ... >>> Color([0xA0, 0xF0, 0xC0]) >>> Color([0xA0, 0xF0, 0xC0]).value.append(1) >>> Color([0xA0, 0xF0, 0xC0]).value.append(1) Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.6/enum.py", line 241, in __call__ return cls.__new__(cls, value) File "/usr/local/lib/python3.6/enum.py", line 476, in __new__ raise ValueError("%r is not a valid %s" % (value, cls.__name__)) ValueError: [160, 240, 192] is not a valid Color but I don't think it's a good thing to ever intentionally do. It's fine for the Enum class to not enforce it (it means you can use arbitrary objects as values, and that's fine), but if you actually do this, then . At some point, we're moving beyond the concept of "enumeration" and settling on "types.SimpleNamespace". ChrisA From ethan at stoneleaf.us Sun Apr 24 14:45:10 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 24 Apr 2016 11:45:10 -0700 Subject: Comparing Python enums to Java, was: How much sanity checking is required for function inputs? In-Reply-To: References: <571CEEAB.6090300@stoneleaf.us> <571CF762.4000809@stoneleaf.us> <571D0C98.2020403@stoneleaf.us> Message-ID: <571D1436.6040007@stoneleaf.us> On 04/24/2016 11:27 AM, Chris Angelico wrote: > On Mon, Apr 25, 2016 at 4:12 AM, Ethan Furman wrote: >> Values can be anything. The names are immutable and hashable. > > I know they *can* be, because I looked in the docs; but does it make > sense to a human? Sure, we can legally do this: Well, not me. ;) >--> class Color(Enum): > ... red = 1 > ... green = 2 > ... blue = 3 > ... break_me = [0xA0, 0xF0, 0xC0] > ... >--> Color([0xA0, 0xF0, 0xC0]) > >--> Color([0xA0, 0xF0, 0xC0]).value.append(1) >--> Color([0xA0, 0xF0, 0xC0]).value.append(1) If you are looking up by value, you have to use the current value. Looks like pebkac error to me. ;) > At some point, we're moving beyond the concept of "enumeration" and > settling on "types.SimpleNamespace". Sure. But like most things in Python I'm not going to enforce it. And if somebody somewhere has a really cool use-case for it, more power to 'em. -- ~Ethan~ From ethan at stoneleaf.us Sun Apr 24 14:48:55 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 24 Apr 2016 11:48:55 -0700 Subject: from __future__ import print_function In-Reply-To: References: <59fb8aab-ff6b-4922-899a-f1b24739887f@googlegroups.com> Message-ID: <571D1517.70500@stoneleaf.us> On 04/24/2016 11:14 AM, Joel Goldstick wrote: > On Sun, Apr 24, 2016 at 2:05 PM, San wrote: >> I want details explanation(why this statement used,when it can be used,etc) of following statement in python code >> >> "from __future__ import print_function" > > It lets python 2.7 use python 3.x print function instead of the 2.7 > print statement. You might like some of the options, and your code > will be easier to upgrade to 3.x if you decide to do that When it can be used: at the top of a python module; it must be the first executable line (only comments and doc-strings can be before it). -- ~Ethan~ From ian.g.kelly at gmail.com Sun Apr 24 14:55:28 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 24 Apr 2016 12:55:28 -0600 Subject: Comparing Python enums to Java, was: How much sanity checking is required for function inputs? In-Reply-To: <571CEEAB.6090300@stoneleaf.us> References: <571CEEAB.6090300@stoneleaf.us> Message-ID: On Sun, Apr 24, 2016 at 10:04 AM, Ethan Furman wrote: > On 04/24/2016 08:20 AM, Ian Kelly wrote: >> * Java doesn't have the hokey notion of enum instances being distinct >> from their "value". The individual enum members *are* the values. >> Whereas in Python an enum member is an awkward class instance that >> contains a value of some other type. Python tries to get away from the >> C-like notion that enums are ints by making the enum members >> non-comparable, but then gives us IntEnum as a way to work around it >> if we really want to. Since Java enums don't depend on any other type >> for their values, there's nothing inviting the user to treat enums as >> ints in the first place. > > > How does Java share enums with other programs, computers, and/or languages? Java enums are serializable using the name. If you need it to be interoperable with other languages where they're int-based, then you could attach that value as a field. But that would just be data; you wouldn't be making that value an integral part of the Java enum just because some other language does it that way. >> Because they have the same "value", instead of creating a separate >> member, COUNTER_EARTH gets defined as an alias for EARTH. To work >> around this, one would have to add a third argument to the above to >> pass in an additional value for the sole purpose of distinguishing (or >> else adapt the AutoNumber recipe to work with this example). This >> example is a bit contrived since it's generally not likely to come up >> with floats, but it can easily arise (and in my experience frequently >> does) when the arguments are of more discrete types. It's notable that >> the Java enum docs feature this very same example but without this >> weakness. [2] > > > One reason for this is that Python enums are lookup-able via the value: > >>>> Planet(9.80265274333129) > Planet.EARTH > > Do Java enums not have such a feature, or this "feature" totally unnecessary > in Java? It's unnecessary. If you want to look up an enum constant by something other than name, you'd provide a static method or mapping. I'd argue that it's unnecessary in Python too for the same reason. But as long as Python enums make a special distinction of their value, there might as well be a built-in way to do it. > I could certainly add a "no-alias" feature to aenum. What would be the > appropriate value-lookup behaviour in such cases? > > - return the first match > - return a list of matches > - raise an error > - disable value-lookups for that Enum Probably the third or fourth, as I think that value lookup would generally not be useful in such cases, and it can be overridden if desired. > Cool. The stdlib Enum (and therefore the enum34 backport) is unlikely to > change much. However, aenum has a few fun things going on, and I'm happy to > add more: > > - NamedTuple (metaclass-based) > - NamedConstant (no aliases, no by-value lookups) > - Enum > - magic auto-numbering > class Number(Enum, auto=True): > one, two, three > def by_seven(self): > return self.value * 7 > - auto-setting of attributes > class Planet(Enum, init='mass radius'): > MERCURY = 3.303e23, 2.4397e6 > EARTH = 5.976e24, 6.37814e6 > NEPTUNE = 1.024e26, 2.4746e7 > --> Planet.EARTH.mass > 5.976e24 Neat! From cmpython at gmail.com Sun Apr 24 14:58:26 2016 From: cmpython at gmail.com (CM) Date: Sun, 24 Apr 2016 11:58:26 -0700 (PDT) Subject: Scraping email to make invoice Message-ID: I would like to write a Pythons script to automate a tedious process and could use some advice. The source content will be an email that has 5-10 PO (purchase order) numbers and information for freelance work done. The target content will be an invoice. (There will be an email like this every week). Right now, the "recommended" way to go (from the company) from source to target is manually copying and pasting all the tedious details of the work done into the invoice. But this is laborious, error-prone...and just begging for automation. There is no human judgment necessary whatsoever in this. I'm comfortable with "scraping" a text file and have written scripts for this, but could use some pointers on other parts of this operation. 1. INPUT: What's the best way to scrape an email like this? The email is to a Gmail account, and the content shows up in the email as a series of basically 6x7 tables (HTML?), one table per PO number/task. I know if the freelancer were to copy and paste the whole set of tables into a text file and save it as plain text, Python could easily scrape that file, but I'd much prefer to save the user those steps. Is there a relatively easy way to go from the Gmail email to generating the invoice directly? (I know there is, but wasn't sure what is state of the art these days). 2. OUPUT: The invoice will have boilerplate content on top and then an Excel table at bottom that is mostly the same information from the source content. Ideally, so that the invoice looks good, the invoice should be a Word document. For the first pass at this, it looked best by laying out the entire invoice in Excel and then copy and pasting it into a Word doc as an image (since otherwise the columns ran over for some reason). In any case, the goal is to create a single page invoice that looks like a clean, professional looking invoice. 3. UI: I am comfortable with making GUI apps, so could use this as the interface for the (somewhat computer-uncomfortable) user. But the less user actions necessary, the better. The emails always come from the same sender, and always have the same boilerplate language ("Below please find your Purchase Order (PO)"), so I'm envisioning a small GUI window with a single button that says "MAKE NEWEST INVOICE" and the user presses it and it automatically searches the user's email for PO # emails and creates the newest invoice. I'm guessing I could keep a sqlite database or flat file on the computer to just track what is meant by "newest", and then the output would have the date created in the file, so the user can be sure what has been invoiced. I'm hoping I can write this in a couple of days. Any suggestions welcome! Thanks. From eryksun at gmail.com Sun Apr 24 15:42:29 2016 From: eryksun at gmail.com (eryk sun) Date: Sun, 24 Apr 2016 14:42:29 -0500 Subject: Remove directory tree without following symlinks In-Reply-To: References: <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com> <1461337766.365000.586700849.0DDBDB0B@webmail.messagingengine.com> <571a5be6$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 24, 2016 at 5:42 AM, Albert-Jan Roskam wrote: > Aww, I kinda forgot about that already, but I came across this last > year [1]. Apparently, shutil.rmtree(very_long_path) failed under Win 7, > even with the "silly prefix". I believe very_long_path was a > Python2-str. > [1] > https://mail.python.org/pipermail/python-list/2015-June/693156.html Python 2's str branch of the os functions gets implemented on Windows using the [A]NSI API, such as FindFirstFileA and FindNextFileA to implement listdir(). Generally the ANSI API is a light wrapper around the [W]ide-character API. It simply decodes byte strings to UTF-16 and calls the wide-character function (or a common internal function). IIRC, in Windows 7, byte strings are decoded using a per-thread buffer with size MAX_PATH (260), so prefixing the path with "\\?\" won't help. You have to use the wide-character API. Windows 10, on the other hand, decodes using a dynamically allocated buffer, so you can usually get away with using a long byte string. But not with Python 2 os.listdir(), which uses a stack-allocated MAX_PATH+5 buffer in the str branch. For example: Python 2 os.mkdir works: >>> path = os.path.normpath('//?/C:/Temp/long/' + 'a' * 255) >>> os.makedirs(path) but os.listdir requires unicode: >>> os.listdir(path) Traceback (most recent call last): File "", line 1, in TypeError: must be (buffer overflow), not str >>> os.listdir(path.decode('mbcs')) [] Also, the str branch of listdir appends "/*.*", with a forward slash, so it's incompatible with the "\\?\" prefix, even for short paths: >>> os.listdir(r'\\?\C:\Temp') Traceback (most recent call last): File "", line 1, in WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: '\\\\?\\C:\\Temp/*.*' > It seems useful if shutil or os.path would automatically prefix paths > with "\\?\". It is rarely really needed, though. (in my case it was > needed to copy a bunch of MS Outlook .msg files, which automatically > get the subject line as the filename, and perhaps the first sentence > of the mail of the mail has no subject). I doubt a change like that would get backported to 2.7. Recently there was a lengthy discussion about adding an __fspath__ protocol to Python 3. Possibly this can be automatically handled in the __fspath__ implementation of pathlib.WindowsPath and the DirEntry type returned by os.scandir. From arthur.m.sherman at gmail.com Sun Apr 24 16:26:52 2016 From: arthur.m.sherman at gmail.com (arthur sherman) Date: Sun, 24 Apr 2016 13:26:52 -0700 (PDT) Subject: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 54: Message-ID: <260a9e80-626a-4f5c-b2d4-dc44bc451fe5@googlegroups.com> m using a python web applic (adagios, a nagios configuration tool). when attempting a certain operation on the client side browser i get the above error. the client side is ubunti 14.04. servers side is debian 8. browser is ff or chrome. both show: echo $LANG en_US.UTF-8 before i dive into the code, r there any OS level things to try? here's the full error traceback: Traceback (most recent call last): File "/opt/adagios/adagios/views.py", line 43, in wrapper result = view_func(request, *args, **kwargs) File "/opt/adagios/adagios/objectbrowser/views.py", line 191, in edit_object c['form'] = PynagForm(pynag_object=my_object, initial=my_object._original_attributes) File "/opt/adagios/adagios/objectbrowser/forms.py", line 312, in __init__ self.fields[field_name] = self.get_pynagField(field_name, css_tag="inherited") File "/opt/adagios/adagios/objectbrowser/forms.py", line 418, in get_pynagField _('%(inherited_value)s (inherited from template)') % {'inherited_value': smart_str(inherited_value)} UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 54: ordinal not in range(128) tnx in advance for any assistance, ams avraham Posts: 2 Joined: Wed Mar 25, 2015 8:58 am Top From anthra.norell at bluewin.ch Sun Apr 24 16:38:11 2016 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Sun, 24 Apr 2016 22:38:11 +0200 Subject: Scraping email to make invoice In-Reply-To: References: Message-ID: <571D2EB3.90104@bluewin.ch> On 04/24/2016 08:58 PM, CM wrote: > I would like to write a Pythons script to automate a tedious process and could use some advice. > > The source content will be an email that has 5-10 PO (purchase order) numbers and information for freelance work done. The target content will be an invoice. (There will be an email like this every week). > > Right now, the "recommended" way to go (from the company) from source to target is manually copying and pasting all the tedious details of the work done into the invoice. But this is laborious, error-prone...and just begging for automation. There is no human judgment necessary whatsoever in this. > > I'm comfortable with "scraping" a text file and have written scripts for this, but could use some pointers on other parts of this operation. > > 1. INPUT: What's the best way to scrape an email like this? The email is to a Gmail account, and the content shows up in the email as a series of basically 6x7 tables (HTML?), one table per PO number/task. I know if the freelancer were to copy and paste the whole set of tables into a text file and save it as plain text, Python could easily scrape that file, but I'd much prefer to save the user those steps. Is there a relatively easy way to go from the Gmail email to generating the invoice directly? (I know there is, but wasn't sure what is state of the art these days). > > 2. OUPUT: The invoice will have boilerplate content on top and then an Excel table at bottom that is mostly the same information from the source content. Ideally, so that the invoice looks good, the invoice should be a Word document. For the first pass at this, it looked best by laying out the entire invoice in Excel and then copy and pasting it into a Word doc as an image (since otherwise the columns ran over for some reason). In any case, the goal is to create a single page invoice that looks like a clean, professional looking invoice. > > 3. UI: I am comfortable with making GUI apps, so could use this as the interface for the (somewhat computer-uncomfortable) user. But the less user actions necessary, the better. The emails always come from the same sender, and always have the same boilerplate language ("Below please find your Purchase Order (PO)"), so I'm envisioning a small GUI window with a single button that says "MAKE NEWEST INVOICE" and the user presses it and it automatically searches the user's email for PO # emails and creates the newest invoice. I'm guessing I could keep a sqlite database or flat file on the computer to just track what is meant by "newest", and then the output would have the date created in the file, so the user can be sure what has been invoiced. > > I'm hoping I can write this in a couple of days. > > Any suggestions welcome! Thanks. INPUT: What's the best way to scrape an email like this? -- Like what? You need to explain what exactly your input is or show an example. Frederic From oscar.j.benjamin at gmail.com Sun Apr 24 17:55:34 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sun, 24 Apr 2016 22:55:34 +0100 Subject: Optimizing Memory Allocation in a Simple, but Long Function In-Reply-To: References: Message-ID: On 24 April 2016 at 19:21, Chris Angelico wrote: > On Mon, Apr 25, 2016 at 4:03 AM, Derek Klinge wrote: >> Ok, from the gmail web client: > > Bouncing this back to the list, and removing quote markers for other > people's copy/paste convenience. > > ## Write a method to approximate Euler's Number using Euler's Method > import math > > class EulersNumber(): > def __init__(self,n): > self.eulerSteps = n > self.e = self.EulersMethod(self.eulerSteps) > def linearApproximation(self,x,h,d): # f(x+h)=f(x)+h*f'(x) > return x + h * d > def EulersMethod(self, numberOfSteps): # Repeate linear > approximation over an even range > e = 1 # e**0 = 1 > for step in range(numberOfSteps): > e = self.linearApproximation(e,1.0/numberOfSteps,e) # if > f(x)= e**x, f'(x)=f(x) > return e > > > def EulerStepWithGuess(accuracy,guessForN): > n = guessForN > e = EulersNumber(n) > while abs(e.e - math.e) > abs(accuracy): > n +=1 > e = EulersNumber(n) > print('n={} \te= {} \tdelta(e)={}'.format(n,e.e,abs(e.e - math.e))) > return e > > > def EulersNumberToAccuracy(PowerOfTen): > x = 1 > theGuess = 1 > thisE = EulersNumber(1) > while x <= abs(PowerOfTen): > thisE = EulerStepWithGuess(10**(-1*x),theGuess) > theGuess = thisE.eulerSteps * 10 > x += 1 > return thisE > > >> To see an example of my problem try something like EulersNumberToAccuracy(-10) Now that I can finally see your code I can see what the problem is. So essentially you want to calculate Euler's number in the following way: e = exp(1) and exp(t) is the solution of the initial value problem with ordinary differential equation dx/dt = x and initial condition x(0)=1. So you're using Euler's method to numerically solve the ODE from t=0 to t=1. Which gives you an estimate for x(1) = exp(1) = e. Euler's method solves this by going in steps from t=0 to t=1 with some step size e.g. dt = 0.1. You get a sequence of values x[n] where x[0] = x(0) = 1 # initial condition x[1] = x[0] + dt*f(x[0]) = x[0] + dt*x[0] x[2] = x[1] + dt*x[1] # etc. In order to get to t=1 in N steps you set dt = 1/N. So simplifying your code (all the classes and functions are just confusing the situation here): N = 1000 dt = 1.0 / N x = 1 for n in range(N): x = x + dt*x print(x) When I run that I get: 2.71692393224 Okay that's great but actually you want to be able to set the accuracy required and then steadily increase N until it's big enough to achieve the expected accuracy so you do this: import math error = 1 accuracy = 1e-2 N = 1 while error > accuracy: dt = 1.0 / N x = 1 for n in range(N): x = x + dt*x error = abs(math.e - x) N += 1 print(x) But what happens here? You have a loop in a loop. The inner loop takes n over N values. The outer loop takes N from 1 up to Nmin where Nmin is the smallest value of N such that we achieve the desired accuracy. This is a classic case of a quadratic performance algorithm. As you make the accuracy smaller you're implicitly increasing Nmin. However the algorithmic performance is quadratic in Nmin i.e. O(Nmin**2). The problem is the nested loops. If you have an outer loop that increases the length of an inner loop by 1 at each step then you have a quadratic algorithm akin to: # This loop is O(M**2) for n in range(N): for N in range(M): # do stuff To see that it is quadratic see: https://en.wikipedia.org/wiki/Triangular_number The simplest fix here is to replace N+=1 with N*=2. Instead of increasing the number of steps by one if the accuracy is not small enough then you should double the number of steps. That will give you an O(Nmin) algorithm. https://en.wikipedia.org/wiki/1/2_%2B_1/4_%2B_1/8_%2B_1/16_%2B_%E2%8B%AF A better method is to do a bit of algebra before putting down the code: x[1] = x[0] + h*x[0] = x[0]*(1+h) = x[0]*(1+1/N) = (1+1/N) x[2] = x[1]*(1+1/N) = (1+1/N)**2 ... x[n] = (1 + 1/n)**n So doing the loop for Euler's method is equivalent to just writing: x = (1 + 1.0/N)**N This considered as a sequence in N is well known as a sequence that converges to e. In fact this is how the number e was first discovered: https://en.wikipedia.org/wiki/E_%28mathematical_constant%29#Compound_interest Python can compute this much quicker than your previous version: N = 1 for _ in range(40): N *= 2 print((1 + 1.0/N) ** N) Which runs instantly and gives: 2.25 2.44140625 2.56578451395 2.63792849737 2.67699012938 2.69734495257 2.70773901969 2.71299162425 2.71563200017 2.71695572947 2.71761848234 2.71795008119 2.71811593627 2.71819887772 2.71824035193 2.7182610899 2.71827145911 2.71827664377 2.71827923611 2.71828053228 2.71828118037 2.71828150441 2.71828166644 2.71828174745 2.71828178795 2.71828180821 2.71828181833 2.7182818234 2.71828182593 2.71828182719 2.71828182783 2.71828182814 2.7182818283 2.71828182838 2.71828182842 2.71828182844 2.71828182845 2.71828182845 2.71828182846 2.71828182846 So your method is computing the above numbers but in a slower way that also has more potential for rounding error. The error here is 1e-13 for the last numbers in this sequence. But N=2**40 so your Euler method would need approximately 10**12 iterations in your inner loop to get the same result. That's going to be slow even if you don't use a quadratic algorithm. -- Oscar From dkeeney at travelbyroad.net Sun Apr 24 18:07:55 2016 From: dkeeney at travelbyroad.net (David) Date: Sun, 24 Apr 2016 15:07:55 -0700 (PDT) Subject: asyncio and subprocesses Message-ID: Is this a bug in the asyncio libraries? This code: ''' proc = yield from asyncio.create_subprocess_exec(*cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) # read all data from subprocess pipe, copy to nextCoro ln = yield from proc.stdout.read(1024) while ln: yield from nextCoro.process(ln) ln = yield from proc.stdout.read(1024) ''' will throw this exception: Traceback (most recent call last): File "/usr/project/bulk_aio.py", line 52, in db_source ln = yield from proc.stdout.read(1024) File "/usr/lib/python3.4/asyncio/streams.py", line 462, in read self._maybe_resume_transport() File "/usr/lib/python3.4/asyncio/streams.py", line 349, in _maybe_resume_transport self._transport.resume_reading() File "/usr/lib/python3.4/asyncio/unix_events.py", line 364, in resume_reading self._loop.add_reader(self._fileno, self._read_ready) AttributeError: 'NoneType' object has no attribute 'add_reader' The exception always happens at the end of the subprocess's run, in what would be the last read. Whether it happens correlates with the time needed for nextCoro.process. If each iteration takes more than about a millisecond, the exception will be thrown. It *seems* that when the transport loses the pipe connection, it schedules the event loop for removal immediately, and the _loop gets set to None before the data can all be read. This is the sequence in unix_events.py _UnixReadPipeTransport._read_ready. Is there a workaround to avoid this exception? Is this a fixed bug, already? I am using Python 3.4.2 as distributed in Ubuntu Lucid, with built-in asyncio. Thank you. David From __peter__ at web.de Sun Apr 24 18:14:32 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 25 Apr 2016 00:14:32 +0200 Subject: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 54: References: <260a9e80-626a-4f5c-b2d4-dc44bc451fe5@googlegroups.com> Message-ID: arthur sherman wrote: > m using a python web applic (adagios, a nagios configuration tool). > when attempting a certain operation on the client side browser i get the > above error. the client side is ubunti 14.04. servers side is debian 8. > browser is ff or chrome. both show: > echo $LANG > en_US.UTF-8 > > before i dive into the code, r there any OS level things to try? > here's the full error traceback: > > Traceback (most recent call last): > File "/opt/adagios/adagios/views.py", line 43, in wrapper > result = view_func(request, *args, **kwargs) > File "/opt/adagios/adagios/objectbrowser/views.py", line 191, in > edit_object c['form'] = PynagForm(pynag_object=my_object, > initial=my_object._original_attributes) File > "/opt/adagios/adagios/objectbrowser/forms.py", line 312, in __init__ > self.fields[field_name] = self.get_pynagField(field_name, > css_tag="inherited") File "/opt/adagios/adagios/objectbrowser/forms.py", > line 418, in get_pynagField _('%(inherited_value)s (inherited from > template)') % {'inherited_value': smart_str(inherited_value)} > UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 54: > ordinal not in range(128) Probably one of _(...) or smart_str(...) returns unicode and the other returns a non-ascii bytestring: >>> u"%s" % "\xe2" Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128) >>> "\xe2 %s" % u"foo" Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128) > before i dive into the code, r there any OS level things to try? Probably not. If you entered non-ascii text into a form, and can limit yourself to ascii-only then that might be a workaround... From peter.brittain.os at gmail.com Sun Apr 24 18:55:03 2016 From: peter.brittain.os at gmail.com (Peter Brittain) Date: Sun, 24 Apr 2016 15:55:03 -0700 (PDT) Subject: Python TUI that will work on DOS/Windows and Unix/Linux In-Reply-To: References: Message-ID: <74e76727-9dca-43d7-aceb-0b7b1a8bbec1@googlegroups.com> I noticed this trail on Google... if you're still interested, you could try out https://github.com/peterbrittain/asciimatics I ported it to Windows from Linux so exactly the same API works on both. From torriem at gmail.com Sun Apr 24 19:19:41 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 24 Apr 2016 17:19:41 -0600 Subject: Scraping email to make invoice In-Reply-To: References: Message-ID: <571D548D.2040500@gmail.com> On 04/24/2016 12:58 PM, CM wrote: > 1. INPUT: What's the best way to scrape an email like this? The > email is to a Gmail account, and the content shows up in the email as > a series of basically 6x7 tables (HTML?), one table per PO > number/task. I know if the freelancer were to copy and paste the > whole set of tables into a text file and save it as plain text, > Python could easily scrape that file, but I'd much prefer to save the > user those steps. Is there a relatively easy way to go from the Gmail > email to generating the invoice directly? (I know there is, but > wasn't sure what is state of the art these days). I would configure Gmail to allow IMAP access (you'll have to set up a special password for this most likely), and then use an imap library from Python to directly find the relevant messages and access the email message body. If the body is HTML-formatted (sounds like it is) I would use either BeautifulSoup or lxml to parse it and get out the relevant information. > 2. OUPUT: The invoice will have boilerplate content on top and then > an Excel table at bottom that is mostly the same information from > the source content. Ideally, so that the invoice looks good, the > invoice should be a Word document. For the first pass at this, it > looked best by laying out the entire invoice in Excel and then copy > and pasting it into a Word doc as an image (since otherwise the > columns ran over for some reason). In any case, the goal is to create > a single page invoice that looks like a clean, professional looking > invoice. There are several libraries for creating Excel and Word files, especially the XML-based formats, though I have little experience with them. There are also nice libraries for emitting PDF if that would work better. > 3. UI: I am comfortable with making GUI apps, so could use this as > the interface for the (somewhat computer-uncomfortable) user. But > the less user actions necessary, the better. The emails always come > from the same sender, and always have the same boilerplate language > ("Below please find your Purchase Order (PO)"), so I'm envisioning a > small GUI window with a single button that says "MAKE NEWEST > INVOICE" and the user presses it and it automatically searches the > user's email for PO # emails and creates the newest invoice. I'm > guessing I could keep a sqlite database or flat file on the computer > to just track what is meant by "newest", and then the output would > have the date created in the file, so the user can be sure what has > been invoiced. Once you have a working script, your GUI interface would be pretty easy. Though it seems to me that it would be unnecessary. This process sounds like it should just run automatically from a cron job or something. > I'm hoping I can write this in a couple of days. The automated part should be possible, but personally I'd give myself a week. From michael.selik at gmail.com Sun Apr 24 21:02:33 2016 From: michael.selik at gmail.com (Michael Selik) Date: Mon, 25 Apr 2016 01:02:33 +0000 Subject: How much sanity checking is required for function inputs? In-Reply-To: <571d09aa$0$1618$c3e8da3$5496439d@news.astraweb.com> References: <5713E52D.3060407@icloud.com> <1461131475.4042173.584042297.03DAB00E@webmail.messagingengine.com> <57171D23.40709@stoneleaf.us> <1461133057.4046578.584060569.2DD34821@webmail.messagingengine.com> <57185E88.30201@yahoo.com> <57197FC3.4030701@icloud.com> <1461291613.433097.586174185.01BB7E37@webmail.messagingengine.com> <57199BA5.4000703@icloud.com> <1461302724.477236.586265777.181ACCA0@webmail.messagingengine.com> <571C2541.9050309@icloud.com> <571C30C8.5000208@gmail.com> <571c5e72$0$1615$c3e8da3$5496439d@news.astraweb.com> <571d09aa$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 24, 2016 at 2:08 PM Steven D'Aprano wrote: > On Sun, 24 Apr 2016 04:40 pm, Michael Selik wrote: > > I think we're giving mixed messages because we're conflating > "constants" and globals that are expected to change. > > When you talk about "state", that usually means "the current state of the > program", not constants. math.pi is not "state". > Perhaps I was unclear. You provided an example of what I was trying to point out. From schilke.60 at gmail.com Sun Apr 24 23:12:23 2016 From: schilke.60 at gmail.com (Derek Klinge) Date: Sun, 24 Apr 2016 20:12:23 -0700 Subject: Optimizing Memory Allocation in a Simple, but Long Function In-Reply-To: References: Message-ID: Actually, I'm not trying to speed it up, just be able to handle a large number of n. (Thank you Chris for the suggestion to use xrange, I am on a Mac using the stock Python 2.7) I am looking at the number of iterations of linear approximation that are required to get a more accurate representation. My initial data suggest that to get 1 more digit of e (the difference between the calculated and expected value falls under 10**-n), I need a little more than 10 times the number of iterations of linear approximation. I actually intend to compare these to other methods, including limit definition that you provided, as well as the geometric series definition. I am trying to provide some real world data for my students to prove the point that although there are many ways to calculate a value, some are much more efficient than others. I tried your recommendation (Oscar) of trying a (1+1/n)**n approach, which gave me very similar values, but when I took the difference between your method and mine I consistently got differences of ~10**-15. Perhaps this is due the binary representation of the decimals? Also, it seems to me if the goal is to use the smallest value of n to get a particular level of accuracy, changing your guess of N by doubling seems to have a high chance of overshoot. I found that I was able to predict relatively accurately a value of N for achieving a desired accuracy. By this I mean, that I found that if I wanted my to be accurate to one additional decimal place I had to multiply my value of N by approximately 10 (I found that the new N required was always < 10N +10). Derek On Sun, Apr 24, 2016 at 4:45 PM, Derek Klinge wrote: > Actually, I'm not trying to speed it up, just be able to handle a large > number of n. > (Thank you Chris for the suggestion to use xrange, I am on a Mac using the > stock Python 2.7) > > I am looking at the number of iterations of linear approximation that are > required to get a more accurate representation. > My initial data suggest that to get 1 more digit of e (the difference > between the calculated and expected value falls under 10**-n), I need a > little more than 10 times the number of iterations of linear approximation. > > I actually intend to compare these to other methods, including limit > definition that you provided, as well as the geometric series definition. > > I am trying to provide some real world data for my students to prove the > point that although there are many ways to calculate a value, some are much > more efficient than others. > > Derek > > On Sun, Apr 24, 2016 at 2:55 PM, Oscar Benjamin < > oscar.j.benjamin at gmail.com> wrote: > >> On 24 April 2016 at 19:21, Chris Angelico wrote: >> > On Mon, Apr 25, 2016 at 4:03 AM, Derek Klinge >> wrote: >> >> Ok, from the gmail web client: >> > >> > Bouncing this back to the list, and removing quote markers for other >> > people's copy/paste convenience. >> > >> > ## Write a method to approximate Euler's Number using Euler's Method >> > import math >> > >> > class EulersNumber(): >> > def __init__(self,n): >> > self.eulerSteps = n >> > self.e = self.EulersMethod(self.eulerSteps) >> > def linearApproximation(self,x,h,d): # f(x+h)=f(x)+h*f'(x) >> > return x + h * d >> > def EulersMethod(self, numberOfSteps): # Repeate linear >> > approximation over an even range >> > e = 1 # e**0 >> = 1 >> > for step in range(numberOfSteps): >> > e = self.linearApproximation(e,1.0/numberOfSteps,e) # if >> > f(x)= e**x, f'(x)=f(x) >> > return e >> > >> > >> > def EulerStepWithGuess(accuracy,guessForN): >> > n = guessForN >> > e = EulersNumber(n) >> > while abs(e.e - math.e) > abs(accuracy): >> > n +=1 >> > e = EulersNumber(n) >> > print('n={} \te= {} \tdelta(e)={}'.format(n,e.e,abs(e.e - >> math.e))) >> > return e >> > >> > >> > def EulersNumberToAccuracy(PowerOfTen): >> > x = 1 >> > theGuess = 1 >> > thisE = EulersNumber(1) >> > while x <= abs(PowerOfTen): >> > thisE = EulerStepWithGuess(10**(-1*x),theGuess) >> > theGuess = thisE.eulerSteps * 10 >> > x += 1 >> > return thisE >> > >> > >> >> To see an example of my problem try something like >> EulersNumberToAccuracy(-10) >> >> Now that I can finally see your code I can see what the problem is. So >> essentially you want to calculate Euler's number in the following way: >> >> e = exp(1) and exp(t) is the solution of the initial value problem >> with ordinary differential equation dx/dt = x and initial condition >> x(0)=1. >> >> So you're using Euler's method to numerically solve the ODE from t=0 >> to t=1. Which gives you an estimate for x(1) = exp(1) = e. >> >> Euler's method solves this by going in steps from t=0 to t=1 with some >> step size e.g. dt = 0.1. You get a sequence of values x[n] where >> >> x[0] = x(0) = 1 # initial condition >> x[1] = x[0] + dt*f(x[0]) = x[0] + dt*x[0] >> x[2] = x[1] + dt*x[1] # etc. >> >> In order to get to t=1 in N steps you set dt = 1/N. So simplifying >> your code (all the classes and functions are just confusing the >> situation here): >> >> N = 1000 >> dt = 1.0 / N >> x = 1 >> for n in range(N): >> x = x + dt*x >> print(x) >> >> When I run that I get: >> 2.71692393224 >> >> Okay that's great but actually you want to be able to set the accuracy >> required and then steadily increase N until it's big enough to achieve >> the expected accuracy so you do this: >> >> import math >> >> error = 1 >> accuracy = 1e-2 >> >> N = 1 >> while error > accuracy: >> dt = 1.0 / N >> x = 1 >> for n in range(N): >> x = x + dt*x >> error = abs(math.e - x) >> N += 1 >> print(x) >> >> But what happens here? You have a loop in a loop. The inner loop takes >> n over N values. The outer loop takes N from 1 up to Nmin where Nmin >> is the smallest value of N such that we achieve the desired accuracy. >> >> This is a classic case of a quadratic performance algorithm. As you >> make the accuracy smaller you're implicitly increasing Nmin. However >> the algorithmic performance is quadratic in Nmin i.e. O(Nmin**2). The >> problem is the nested loops. If you have an outer loop that increases >> the length of an inner loop by 1 at each step then you have a >> quadratic algorithm akin to: >> >> # This loop is O(M**2) >> for n in range(N): >> for N in range(M): >> # do stuff >> >> To see that it is quadratic see: >> >> https://en.wikipedia.org/wiki/Triangular_number >> >> The simplest fix here is to replace N+=1 with N*=2. Instead of >> increasing the number of steps by one if the accuracy is not small >> enough then you should double the number of steps. That will give you >> an O(Nmin) algorithm. >> >> >> https://en.wikipedia.org/wiki/1/2_%2B_1/4_%2B_1/8_%2B_1/16_%2B_%E2%8B%AF >> >> A better method is to do a bit of algebra before putting down the code: >> >> x[1] = x[0] + h*x[0] = x[0]*(1+h) = x[0]*(1+1/N) = (1+1/N) >> x[2] = x[1]*(1+1/N) = (1+1/N)**2 >> ... >> x[n] = (1 + 1/n)**n >> >> So doing the loop for Euler's method is equivalent to just writing: >> >> x = (1 + 1.0/N)**N >> >> This considered as a sequence in N is well known as a sequence that >> converges to e. In fact this is how the number e was first discovered: >> >> >> https://en.wikipedia.org/wiki/E_%28mathematical_constant%29#Compound_interest >> >> Python can compute this much quicker than your previous version: >> >> N = 1 >> for _ in range(40): >> N *= 2 >> print((1 + 1.0/N) ** N) >> >> Which runs instantly and gives: >> >> 2.25 >> 2.44140625 >> 2.56578451395 >> 2.63792849737 >> 2.67699012938 >> 2.69734495257 >> 2.70773901969 >> 2.71299162425 >> 2.71563200017 >> 2.71695572947 >> 2.71761848234 >> 2.71795008119 >> 2.71811593627 >> 2.71819887772 >> 2.71824035193 >> 2.7182610899 >> 2.71827145911 >> 2.71827664377 >> 2.71827923611 >> 2.71828053228 >> 2.71828118037 >> 2.71828150441 >> 2.71828166644 >> 2.71828174745 >> 2.71828178795 >> 2.71828180821 >> 2.71828181833 >> 2.7182818234 >> 2.71828182593 >> 2.71828182719 >> 2.71828182783 >> 2.71828182814 >> 2.7182818283 >> 2.71828182838 >> 2.71828182842 >> 2.71828182844 >> 2.71828182845 >> 2.71828182845 >> 2.71828182846 >> 2.71828182846 >> >> So your method is computing the above numbers but in a slower way that >> also has more potential for rounding error. The error here is 1e-13 >> for the last numbers in this sequence. But N=2**40 so your Euler >> method would need approximately 10**12 iterations in your inner loop >> to get the same result. That's going to be slow even if you don't use >> a quadratic algorithm. >> >> -- >> Oscar >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > From schilke.60 at gmail.com Sun Apr 24 23:58:02 2016 From: schilke.60 at gmail.com (Derek Klinge) Date: Sun, 24 Apr 2016 20:58:02 -0700 Subject: Optimizing Memory Allocation in a Simple, but Long Function In-Reply-To: References: Message-ID: So I tried the recommended limit approach and got some interesting results. ## Write a method to approximate Euler's Number using Euler's Method import math class EulersNumber(): def __init__(self,n): self.n = n self.e = 2 def linearApproximation(self,x,h,d): # f(x+h)=f(x)+h*f'(x) return x + h * d def EulersMethod(self): # Repeat linear approximation over an even range e = 1 # e**0 = 1 for step in xrange(self.n): e = self.linearApproximation(e,1.0/self.n,e) # if f(x)= e**x, f'(x)=f(x) self.e = e return e def LimitMethod(self): self.e = (1 + 1.0/self.n) ** self.n return self.e def SeriesMethod(self): self.e = sum([1.0/math.factorial(i) for i in range(self.n+1)]) return self.e I found that the pattern of an additional digit of accuracy corresponding to 10*n did not hold as strongly for that value (I can post data if desired). I also got some results that seem to contradict the mathematical definition. For example try EulersNumber(10**15).LimitMethod(), the definition places this limit at e, and yet the (python) answer is >3.035. Please let me know if I've fouled up the implementation somehow. Also my reasoning for writing this up as a class was to be able to get the value of n used to generate that value e. If there is some other way to do that, I'd be happy to try it out. Thanks, Derek Derek On Sun, Apr 24, 2016 at 8:12 PM, Derek Klinge wrote: > Actually, I'm not trying to speed it up, just be able to handle a large > number of n. > (Thank you Chris for the suggestion to use xrange, I am on a Mac using the > stock Python 2.7) > > I am looking at the number of iterations of linear approximation that are > required to get a more accurate representation. > My initial data suggest that to get 1 more digit of e (the difference > between the calculated and expected value falls under 10**-n), I need a > little more than 10 times the number of iterations of linear approximation. > > I actually intend to compare these to other methods, including limit > definition that you provided, as well as the geometric series definition. > > I am trying to provide some real world data for my students to prove the > point that although there are many ways to calculate a value, some are much > more efficient than others. > > I tried your recommendation (Oscar) of trying a (1+1/n)**n approach, which > gave me very similar values, but when I took the difference between your > method and mine I consistently got differences of ~10**-15. Perhaps this is > due the binary representation of the decimals? > > Also, it seems to me if the goal is to use the smallest value of n to get > a particular level of accuracy, changing your guess of N by doubling seems > to have a high chance of overshoot. I found that I was able to predict > relatively accurately a value of N for achieving a desired accuracy. By > this I mean, that I found that if I wanted my to be accurate to one > additional decimal place I had to multiply my value of N by approximately > 10 (I found that the new N required was always < 10N +10). > > Derek > > On Sun, Apr 24, 2016 at 4:45 PM, Derek Klinge > wrote: > >> Actually, I'm not trying to speed it up, just be able to handle a large >> number of n. >> (Thank you Chris for the suggestion to use xrange, I am on a Mac using >> the stock Python 2.7) >> >> I am looking at the number of iterations of linear approximation that are >> required to get a more accurate representation. >> My initial data suggest that to get 1 more digit of e (the difference >> between the calculated and expected value falls under 10**-n), I need a >> little more than 10 times the number of iterations of linear approximation. >> >> I actually intend to compare these to other methods, including limit >> definition that you provided, as well as the geometric series definition. >> >> I am trying to provide some real world data for my students to prove the >> point that although there are many ways to calculate a value, some are much >> more efficient than others. >> >> Derek >> >> On Sun, Apr 24, 2016 at 2:55 PM, Oscar Benjamin < >> oscar.j.benjamin at gmail.com> wrote: >> >>> On 24 April 2016 at 19:21, Chris Angelico wrote: >>> > On Mon, Apr 25, 2016 at 4:03 AM, Derek Klinge >>> wrote: >>> >> Ok, from the gmail web client: >>> > >>> > Bouncing this back to the list, and removing quote markers for other >>> > people's copy/paste convenience. >>> > >>> > ## Write a method to approximate Euler's Number using Euler's Method >>> > import math >>> > >>> > class EulersNumber(): >>> > def __init__(self,n): >>> > self.eulerSteps = n >>> > self.e = self.EulersMethod(self.eulerSteps) >>> > def linearApproximation(self,x,h,d): # f(x+h)=f(x)+h*f'(x) >>> > return x + h * d >>> > def EulersMethod(self, numberOfSteps): # Repeate linear >>> > approximation over an even range >>> > e = 1 # >>> e**0 = 1 >>> > for step in range(numberOfSteps): >>> > e = self.linearApproximation(e,1.0/numberOfSteps,e) # if >>> > f(x)= e**x, f'(x)=f(x) >>> > return e >>> > >>> > >>> > def EulerStepWithGuess(accuracy,guessForN): >>> > n = guessForN >>> > e = EulersNumber(n) >>> > while abs(e.e - math.e) > abs(accuracy): >>> > n +=1 >>> > e = EulersNumber(n) >>> > print('n={} \te= {} \tdelta(e)={}'.format(n,e.e,abs(e.e - >>> math.e))) >>> > return e >>> > >>> > >>> > def EulersNumberToAccuracy(PowerOfTen): >>> > x = 1 >>> > theGuess = 1 >>> > thisE = EulersNumber(1) >>> > while x <= abs(PowerOfTen): >>> > thisE = EulerStepWithGuess(10**(-1*x),theGuess) >>> > theGuess = thisE.eulerSteps * 10 >>> > x += 1 >>> > return thisE >>> > >>> > >>> >> To see an example of my problem try something like >>> EulersNumberToAccuracy(-10) >>> >>> Now that I can finally see your code I can see what the problem is. So >>> essentially you want to calculate Euler's number in the following way: >>> >>> e = exp(1) and exp(t) is the solution of the initial value problem >>> with ordinary differential equation dx/dt = x and initial condition >>> x(0)=1. >>> >>> So you're using Euler's method to numerically solve the ODE from t=0 >>> to t=1. Which gives you an estimate for x(1) = exp(1) = e. >>> >>> Euler's method solves this by going in steps from t=0 to t=1 with some >>> step size e.g. dt = 0.1. You get a sequence of values x[n] where >>> >>> x[0] = x(0) = 1 # initial condition >>> x[1] = x[0] + dt*f(x[0]) = x[0] + dt*x[0] >>> x[2] = x[1] + dt*x[1] # etc. >>> >>> In order to get to t=1 in N steps you set dt = 1/N. So simplifying >>> your code (all the classes and functions are just confusing the >>> situation here): >>> >>> N = 1000 >>> dt = 1.0 / N >>> x = 1 >>> for n in range(N): >>> x = x + dt*x >>> print(x) >>> >>> When I run that I get: >>> 2.71692393224 >>> >>> Okay that's great but actually you want to be able to set the accuracy >>> required and then steadily increase N until it's big enough to achieve >>> the expected accuracy so you do this: >>> >>> import math >>> >>> error = 1 >>> accuracy = 1e-2 >>> >>> N = 1 >>> while error > accuracy: >>> dt = 1.0 / N >>> x = 1 >>> for n in range(N): >>> x = x + dt*x >>> error = abs(math.e - x) >>> N += 1 >>> print(x) >>> >>> But what happens here? You have a loop in a loop. The inner loop takes >>> n over N values. The outer loop takes N from 1 up to Nmin where Nmin >>> is the smallest value of N such that we achieve the desired accuracy. >>> >>> This is a classic case of a quadratic performance algorithm. As you >>> make the accuracy smaller you're implicitly increasing Nmin. However >>> the algorithmic performance is quadratic in Nmin i.e. O(Nmin**2). The >>> problem is the nested loops. If you have an outer loop that increases >>> the length of an inner loop by 1 at each step then you have a >>> quadratic algorithm akin to: >>> >>> # This loop is O(M**2) >>> for n in range(N): >>> for N in range(M): >>> # do stuff >>> >>> To see that it is quadratic see: >>> >>> https://en.wikipedia.org/wiki/Triangular_number >>> >>> The simplest fix here is to replace N+=1 with N*=2. Instead of >>> increasing the number of steps by one if the accuracy is not small >>> enough then you should double the number of steps. That will give you >>> an O(Nmin) algorithm. >>> >>> >>> https://en.wikipedia.org/wiki/1/2_%2B_1/4_%2B_1/8_%2B_1/16_%2B_%E2%8B%AF >>> >>> A better method is to do a bit of algebra before putting down the code: >>> >>> x[1] = x[0] + h*x[0] = x[0]*(1+h) = x[0]*(1+1/N) = (1+1/N) >>> x[2] = x[1]*(1+1/N) = (1+1/N)**2 >>> ... >>> x[n] = (1 + 1/n)**n >>> >>> So doing the loop for Euler's method is equivalent to just writing: >>> >>> x = (1 + 1.0/N)**N >>> >>> This considered as a sequence in N is well known as a sequence that >>> converges to e. In fact this is how the number e was first discovered: >>> >>> >>> https://en.wikipedia.org/wiki/E_%28mathematical_constant%29#Compound_interest >>> >>> Python can compute this much quicker than your previous version: >>> >>> N = 1 >>> for _ in range(40): >>> N *= 2 >>> print((1 + 1.0/N) ** N) >>> >>> Which runs instantly and gives: >>> >>> 2.25 >>> 2.44140625 >>> 2.56578451395 >>> 2.63792849737 >>> 2.67699012938 >>> 2.69734495257 >>> 2.70773901969 >>> 2.71299162425 >>> 2.71563200017 >>> 2.71695572947 >>> 2.71761848234 >>> 2.71795008119 >>> 2.71811593627 >>> 2.71819887772 >>> 2.71824035193 >>> 2.7182610899 >>> 2.71827145911 >>> 2.71827664377 >>> 2.71827923611 >>> 2.71828053228 >>> 2.71828118037 >>> 2.71828150441 >>> 2.71828166644 >>> 2.71828174745 >>> 2.71828178795 >>> 2.71828180821 >>> 2.71828181833 >>> 2.7182818234 >>> 2.71828182593 >>> 2.71828182719 >>> 2.71828182783 >>> 2.71828182814 >>> 2.7182818283 >>> 2.71828182838 >>> 2.71828182842 >>> 2.71828182844 >>> 2.71828182845 >>> 2.71828182845 >>> 2.71828182846 >>> 2.71828182846 >>> >>> So your method is computing the above numbers but in a slower way that >>> also has more potential for rounding error. The error here is 1e-13 >>> for the last numbers in this sequence. But N=2**40 so your Euler >>> method would need approximately 10**12 iterations in your inner loop >>> to get the same result. That's going to be slow even if you don't use >>> a quadratic algorithm. >>> >>> -- >>> Oscar >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> >> > From tjreedy at udel.edu Mon Apr 25 01:48:59 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 25 Apr 2016 01:48:59 -0400 Subject: asyncio and subprocesses In-Reply-To: References: Message-ID: On 4/24/2016 6:07 PM, David wrote: > > Is this a bug in the asyncio libraries? > Is this a fixed bug, already? I am using Python 3.4.2 as distributed in Ubuntu Lucid, with built-in asyncio. The people who patch asyncio do not read this list. Either install a current release or try the tulip release on Pypy (its purpose is to make asyncio available on versions before 3.4 but should also run on 3.4. I don't know if it conflicts with the included asyncio. -- Terry Jan Reedy From harirammanohar at gmail.com Mon Apr 25 02:24:52 2016 From: harirammanohar at gmail.com (harirammanohar at gmail.com) Date: Sun, 24 Apr 2016 23:24:52 -0700 (PDT) Subject: delete from pattern to pattern if it contains match In-Reply-To: References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <7fc52496-baf8-41ef-8f5e-76d409c6df84@googlegroups.com> Message-ID: <99c4bcaa-efc0-4127-b18e-61ea697558b5@googlegroups.com> On Friday, April 22, 2016 at 3:20:53 PM UTC+5:30, Peter Otten wrote: > harirammanohar at gmail.com wrote: > > >> @peter yes here it is not xml, but real data is an xml..believe me.. > > > > @peter this is the similar xml i am having, you can correlate. > > > > https://tomcat.apache.org/tomcat-5.5-doc/appdev/web.xml.txt > > This is still too vague. > > If you post the code you actually tried in a small standalone script > together with a small sample xml file that produces the same failure as your > actual data I or someone might help you fix it. yeah peter you are correct, i would have done that atleast by changing the strings, but i wasnt as here its an restricted data and the purpose...so i have taken sample xml data...ofcourse tags are missed.. From harirammanohar at gmail.com Mon Apr 25 02:29:00 2016 From: harirammanohar at gmail.com (harirammanohar at gmail.com) Date: Sun, 24 Apr 2016 23:29:00 -0700 (PDT) Subject: delete from pattern to pattern if it contains match In-Reply-To: References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> Message-ID: On Friday, April 22, 2016 at 4:41:08 PM UTC+5:30, Jussi Piitulainen wrote: > Peter Otten writes: > > > harirammanohar at gmail.com wrote: > > > >> On Thursday, April 21, 2016 at 7:03:00 PM UTC+5:30, Jussi Piitulainen > >> wrote: > >>> harirammanohar at gmail.com writes: > >>> > >>> > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, > >>> > hariram... at gmail.com wrote: > >>> >> HI All, > >>> >> > >>> >> can you help me out in doing below. > >>> >> > >>> >> file: > >>> >> > >>> >> guava > >>> >> fruit > >>> >> > >>> >> > >>> >> mango > >>> >> fruit > >>> >> > >>> >> > >>> >> orange > >>> >> fruit > >>> >> > >>> >> > >>> >> need to delete from start to end if it contains mango in a file... > >>> >> > >>> >> output should be: > >>> >> > >>> >> > >>> >> guava > >>> >> fruit > >>> >> > >>> >> > >>> >> orange > >>> >> fruit > >>> >> > >>> >> > >>> >> Thank you > >>> > > >>> > any one can guide me ? why xml tree parsing is not working if i have > >>> > root.tag and root.attrib as mentioned in earlier post... > >>> > >>> Assuming the real consists of lines between a start marker and end > >>> marker, a winning plan is to collect a group of lines, deal with it, and > >>> move on. > >>> > >>> The following code implements something close to the plan. You need to > >>> adapt it a bit to have your own source of lines and to restore the end > >>> marker in the output and to account for your real use case and for > >>> differences in taste and judgment. - The plan is as described above, but > >>> there are many ways to implement it. > >>> > >>> from io import StringIO > >>> > >>> text = '''\ > >>> > >>> guava > >>> fruit > >>> > >>> > >>> mango > >>> fruit > >>> > >>> > >>> orange > >>> fruit > >>> > >>> ''' > >>> > >>> def records(source): > >>> current = [] > >>> for line in source: > >>> if line.startswith(''): > >>> yield current > >>> current = [] > >>> else: > >>> current.append(line) > >>> > >>> def hasmango(record): > >>> return any('mango' in it for it in record) > >>> > >>> for record in records(StringIO(text)): > >>> hasmango(record) or print(*record) > >> > >> Hi, > >> > >> not working....this is the output i am getting... > >> > >> \ > > > > This means that the line > > > >>> text = '''\ > > > > has trailing whitespace in your copy of the script. > > That's a nuisance. I wish otherwise undefined escape sequences in > strings raised an error, similar to a stray space after a line > continuation character. > > >> > >> guava > >> fruit > >> > >> > >> orange > >> fruit > > > > Jussi forgot to add the "..." line to the group. > > I didn't forget. I meant what I said when I said the OP needs to adapt > the code to (among other things) restore the end marker in the output. > If they can't be bothered to do anything at all, it's their problem. > > It was already known that this is not the actual format of the data. > > > To fix this change the generator to > > > > def records(source): > > current = [] > > for line in source: > > current.append(line) > > if line.startswith(''): > > yield current > > current = [] > > Oops, I notice that I forgot to start a new record only on encountering > a '' line. That should probably be done, unless the format is > intended to be exactly a sequence of "\n- -\n\n". > > >>> hasmango(record) or print(*record) > > > > The > > > > print(*record) > > > > inserts spaces between record entries (i. e. at the beginning of all > > lines except the first) and adds a trailing newline. > > Yes, I forgot about the space. Sorry about that. > > The final newline was intentional. Perhaps I should have added the end > marker there instead (given my preference to not drag it together with > the data lines), like so: > > print(*record, sep = "", end = "\n") > > Or so: > > print(*record, sep = "") > print("") > > Or so: > > for line in record: > print(line.rstrip("\n") > else: > print("") > > Or: > > for line in record: > print(line.rstrip("\n") > else: > if record and not record[-1].strip() == "": > print("") > > But all this is beside the point that to deal with the stated problem > one might want to obtain access to a whole record *first*, then check if > it contains "mango" in the intended way (details missing but at least > "mango\n" as a full line counts as an occurrence), and only *then* print > the whole record (if it doesn't contain "mango"). > > I can think of two other ways - one if the data can be accessed only > once - but they seem more complicated to me. Hm, well, if it's XML, as > stated in another branch of this thread and contrary to the form of the > example data in this branch, there's a third way that may be good, but > here I'm responding to a line-oriented format. > > > You can avoid this by specifying the delimiters explicitly: > > > > if not hasmango(record): > > print(*record, sep="", end="") > > > > Even with these changes code still looks somewhat brittle... > > That depends on the actual data format, and on what really is intended > to trigger the filter. This approach is a complete waste of effort if > there are no guarantees of things being there on their own lines, for > example. > > Ok, that "\ " not only looks brittle but actually is brittle. The one > time I used that slash, I now regret doing so. Here's a fixed version. > (Not sure of the significance of the number of spaces that start the > first data line. They seem to have doubled along the way.) > > text = ''' > guava > fruit > > > mango > fruit > > > orange > fruit > > ''' Hi Jussi, i have seen you have written a definition to fulfill the requirement, can we do this same thing using xml parser, as i have failed to implement the thing using xml parser of python if the file is having the content as below... and entire thing works if it has as below: what i observe is xml tree parsing is not working if http tags are there in between web-app... From jussi.piitulainen at helsinki.fi Mon Apr 25 03:17:00 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 25 Apr 2016 10:17:00 +0300 Subject: delete from pattern to pattern if it contains match References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> Message-ID: harirammanohar at gmail.com writes: > Hi Jussi, > > i have seen you have written a definition to fulfill the requirement, > can we do this same thing using xml parser, as i have failed to > implement the thing using xml parser of python if the file is having > the content as below... > > PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" > "http://java.sun.com/dtd/web-app_2_3.dtd"> > > > > and entire thing works if it has as below: > > > what i observe is xml tree parsing is not working if http tags are > there in between web-app... Do you get an error message? My guess is that the parser needs the DTD but cannot access it. There appears to be a DTD at that address, http://java.sun.com/... (it redirects to Oracle, who bought Sun a while ago), but something might prevent the parser from accessing it by default. If so, the details depend on what parser you are trying to use. It may be possible to save that DTD as a local file and point the parser to that. Your problem is morphing rather wildly. A previous version had namespace declarations but no DTD or XSD if I remember right. The initial version wasn't XML at all. If you post (1) an actual, minimal document, (2) the actual Python commands that fail to parse it, and (3) the error message you get, someone will be able to help you. The content of the document need not be more than "hello, world" level. The DOCTYPE declaration and the outermost tags with all their attributes and namespace declarations, if any, are important. From palpandi111 at gmail.com Mon Apr 25 03:30:58 2016 From: palpandi111 at gmail.com (Palpandi) Date: Mon, 25 Apr 2016 00:30:58 -0700 (PDT) Subject: Writing different sections into a file Message-ID: Hi, I need to write different sections into a file. At any point of time, content can be added to any section. I don't want keep each section into a temporary file. What is the better way to store the contents of each section and write them into a file at the end? What is the better datatype to achieve this? Thanks and Regards, Palpandi From greg.ewing at canterbury.ac.nz Mon Apr 25 03:39:49 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 25 Apr 2016 19:39:49 +1200 Subject: Optimizing Memory Allocation in a Simple, but Long Function In-Reply-To: References: Message-ID: Derek Klinge wrote: > Also, it seems to me if the goal is to use the smallest value of n to get a > particular level of accuracy, changing your guess of N by doubling seems to > have a high chance of overshoot. If you want to find the exact n required, once you overshoot you could use a binary search to narrow it down. -- Greg From __peter__ at web.de Mon Apr 25 04:16:24 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 25 Apr 2016 10:16:24 +0200 Subject: Optimizing Memory Allocation in a Simple, but Long Function References: Message-ID: Derek Klinge wrote: > I found that the pattern of an additional digit of accuracy corresponding > to 10*n did not hold as strongly for that value (I can post data if > desired). I also got some results that seem to contradict the mathematical > definition. For example try EulersNumber(10**15).LimitMethod(), the > definition places this limit at e, and yet the (python) answer is >3.035. > Please let me know if I've fouled up the implementation somehow. There's nothing wrong with the formula, but floating point numbers have limited precision. At some point your calculation will become mostly a rounding error. You'll see the surprising >>> n = 10**14 >>> (1+1/n)**n 2.716110034087023 >>> n = 10**15 >>> (1+1/n)**n 3.035035206549262 on most modern computers with most programming langagues. https://docs.python.org/3.5/tutorial/floatingpoint.html has some introductory information. From __peter__ at web.de Mon Apr 25 04:48:39 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 25 Apr 2016 10:48:39 +0200 Subject: Writing different sections into a file References: Message-ID: Palpandi wrote: > I need to write different sections into a file. > At any point of time, content can be added to any section. > > I don't want keep each section into a temporary file. > What is the better way to store the contents of each section and write > them into a file at the end? What is the better datatype to achieve this? If the data easily fits into memory just keep it in one list per section header = [...] body = [...] footer = [...] ... body.append("something more\n") footer[:] = ["new footer\n"] ... with open(filename, "w") as f: for section in (header, body, footer): f.writelines(section) If the sections are not known in advance put them into a dictionary or a list. If you are free to choose the file format you may use https://docs.python.org/dev/library/configparser.html From harirammanohar at gmail.com Mon Apr 25 05:49:02 2016 From: harirammanohar at gmail.com (harirammanohar at gmail.com) Date: Mon, 25 Apr 2016 02:49:02 -0700 (PDT) Subject: delete from pattern to pattern if it contains match In-Reply-To: References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> Message-ID: <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> On Monday, April 25, 2016 at 12:47:14 PM UTC+5:30, Jussi Piitulainen wrote: > harirammanohar at gmail.com writes: > > > Hi Jussi, > > > > i have seen you have written a definition to fulfill the requirement, > > can we do this same thing using xml parser, as i have failed to > > implement the thing using xml parser of python if the file is having > > the content as below... > > > > > PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" > > "http://java.sun.com/dtd/web-app_2_3.dtd"> > > > > > > > > and entire thing works if it has as below: > > > > > > > what i observe is xml tree parsing is not working if http tags are > > there in between web-app... > > Do you get an error message? > > My guess is that the parser needs the DTD but cannot access it. There > appears to be a DTD at that address, http://java.sun.com/... (it > redirects to Oracle, who bought Sun a while ago), but something might > prevent the parser from accessing it by default. If so, the details > depend on what parser you are trying to use. It may be possible to save > that DTD as a local file and point the parser to that. > > Your problem is morphing rather wildly. A previous version had namespace > declarations but no DTD or XSD if I remember right. The initial version > wasn't XML at all. > > If you post (1) an actual, minimal document, (2) the actual Python > commands that fail to parse it, and (3) the error message you get, > someone will be able to help you. The content of the document need not > be more than "hello, world" level. The DOCTYPE declaration and the > outermost tags with all their attributes and namespace declarations, if > any, are important. Hi Jussi, Here is an input file...sample.xml controller com.mycompany.mypackage.ControllerServlet listOrders com.mycompany.myactions.ListOrdersAction saveCustomer com.mycompany.myactions.SaveCustomerAction 5 graph /graph 30 -------------------------------- Here is the code: import xml.etree.ElementTree as ET ET.register_namespace("", "http://xmlns.jcp.org/xml/ns/javaee") tree = ET.parse('sample.xml') root = tree.getroot() for servlet in root.findall('servlet'): servletname = servlet.find('servlet-name').text if servletname == "controller": root.remove(servlet) tree.write('output.xml') This will work if doesnt have below... xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" From harirammanohar at gmail.com Mon Apr 25 05:50:37 2016 From: harirammanohar at gmail.com (harirammanohar at gmail.com) Date: Mon, 25 Apr 2016 02:50:37 -0700 (PDT) Subject: Writing different sections into a file In-Reply-To: References: Message-ID: <3c1cfc62-fb1e-4538-8c8d-0a9525297f91@googlegroups.com> On Monday, April 25, 2016 at 1:01:12 PM UTC+5:30, Palpandi wrote: > Hi, > > I need to write different sections into a file. > At any point of time, content can be added to any section. > > I don't want keep each section into a temporary file. > What is the better way to store the contents of each section and write them into a file at the end? > What is the better datatype to achieve this? > > > Thanks and Regards, > Palpandi use ConfigParser.. From harirammanohar at gmail.com Mon Apr 25 05:53:02 2016 From: harirammanohar at gmail.com (harirammanohar at gmail.com) Date: Mon, 25 Apr 2016 02:53:02 -0700 (PDT) Subject: delete from pattern to pattern if it contains match In-Reply-To: <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> Message-ID: On Monday, April 25, 2016 at 3:19:15 PM UTC+5:30, hariram... at gmail.com wrote: > On Monday, April 25, 2016 at 12:47:14 PM UTC+5:30, Jussi Piitulainen wrote: > > harirammanohar at gmail.com writes: > > > > > Hi Jussi, > > > > > > i have seen you have written a definition to fulfill the requirement, > > > can we do this same thing using xml parser, as i have failed to > > > implement the thing using xml parser of python if the file is having > > > the content as below... > > > > > > > > PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" > > > "http://java.sun.com/dtd/web-app_2_3.dtd"> > > > > > > > > > > > > and entire thing works if it has as below: > > > > > > > > > > > what i observe is xml tree parsing is not working if http tags are > > > there in between web-app... > > > > Do you get an error message? > > > > My guess is that the parser needs the DTD but cannot access it. There > > appears to be a DTD at that address, http://java.sun.com/... (it > > redirects to Oracle, who bought Sun a while ago), but something might > > prevent the parser from accessing it by default. If so, the details > > depend on what parser you are trying to use. It may be possible to save > > that DTD as a local file and point the parser to that. > > > > Your problem is morphing rather wildly. A previous version had namespace > > declarations but no DTD or XSD if I remember right. The initial version > > wasn't XML at all. > > > > If you post (1) an actual, minimal document, (2) the actual Python > > commands that fail to parse it, and (3) the error message you get, > > someone will be able to help you. The content of the document need not > > be more than "hello, world" level. The DOCTYPE declaration and the > > outermost tags with all their attributes and namespace declarations, if > > any, are important. > > Hi Jussi, > > Here is an input file...sample.xml > > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee > http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" > version="3.1"> > > controller > com.mycompany.mypackage.ControllerServlet > > listOrders > com.mycompany.myactions.ListOrdersAction > > > saveCustomer > com.mycompany.myactions.SaveCustomerAction > > 5 > > > > > graph > /graph > > > > > 30 > > > > -------------------------------- > Here is the code: > > import xml.etree.ElementTree as ET > ET.register_namespace("", "http://xmlns.jcp.org/xml/ns/javaee") > tree = ET.parse('sample.xml') > root = tree.getroot() > > for servlet in root.findall('servlet'): > servletname = servlet.find('servlet-name').text > if servletname == "controller": > root.remove(servlet) > > tree.write('output.xml') > > This will work if doesnt have below... > > xmlns="http://xmlns.jcp.org/xml/ns/javaee" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee > http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" By the way i didnt get any error message and i am using version 3.4.3 From kliateni at gmail.com Mon Apr 25 06:04:27 2016 From: kliateni at gmail.com (Karim) Date: Mon, 25 Apr 2016 12:04:27 +0200 Subject: Writing different sections into a file In-Reply-To: References: Message-ID: <571DEBAB.6010503@gmail.com> On 25/04/2016 09:30, Palpandi wrote: > Hi, > > I need to write different sections into a file. > At any point of time, content can be added to any section. > > I don't want keep each section into a temporary file. > What is the better way to store the contents of each section and write them into a file at the end? > What is the better datatype to achieve this? > > > Thanks and Regards, > Palpandi Use Stringio: - from cStringIO import StringIO content = StringIO() # Header content.write('; Header\n') content.write('; Body'\n) content.write('; Footer\n') open('my_file', 'wb').write(content.getvalue()) - Karim From __peter__ at web.de Mon Apr 25 06:13:56 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 25 Apr 2016 12:13:56 +0200 Subject: delete from pattern to pattern if it contains match References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> Message-ID: harirammanohar at gmail.com wrote: > Here is the code: Finally ;) > import xml.etree.ElementTree as ET > ET.register_namespace("", "http://xmlns.jcp.org/xml/ns/javaee") I don't know what this does, but probably not what you expected. > tree = ET.parse('sample.xml') > root = tree.getroot() > > for servlet in root.findall('servlet'): > servletname = servlet.find('servlet-name').text I think you have to specify the namespace: for servlet in root.findall('{http://xmlns.jcp.org/xml/ns/javaee}servlet'): servletname = servlet.find( '{http://xmlns.jcp.org/xml/ns/javaee}servlet-name').text > if servletname == "controller": You could have added a print statement to verify that the line below is executed. > root.remove(servlet) > > tree.write('output.xml') > > This will work if doesnt have below... > > xmlns="http://xmlns.jcp.org/xml/ns/javaee" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee > http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" From Joaquin.Alzola at lebara.com Mon Apr 25 06:19:56 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Mon, 25 Apr 2016 10:19:56 +0000 Subject: delete from pattern to pattern if it contains match In-Reply-To: References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> Message-ID: I put some code I did before for the xmlns: xml_root = ET.ElementTree(ET.fromstring(xml_decoded)).getroot() for elem in xml_root.getiterator(): if('{http://request.messagepush.interfaces.comviva.com/xsd}shortCode'==elem.tag): shortCode = (elem.text).rstrip() if('{http://request.messagepush.interfaces.comviva.com/xsd}text'==elem.tag): send_text = (elem.text).rstrip() if('{http://request.messagepush.interfaces.comviva.com/xsd}item'==elem.tag): subscribers = (elem.text).rstrip() result_sms = send_sms(subscribers,shortCode,send_text) Reuse it. -----Original Message----- From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com at python.org] On Behalf Of Peter Otten Sent: 25 April 2016 11:14 To: python-list at python.org Subject: Re: delete from pattern to pattern if it contains match harirammanohar at gmail.com wrote: > Here is the code: Finally ;) > import xml.etree.ElementTree as ET > ET.register_namespace("", "http://xmlns.jcp.org/xml/ns/javaee") I don't know what this does, but probably not what you expected. > tree = ET.parse('sample.xml') > root = tree.getroot() > > for servlet in root.findall('servlet'): > servletname = servlet.find('servlet-name').text I think you have to specify the namespace: for servlet in root.findall('{http://xmlns.jcp.org/xml/ns/javaee}servlet'): servletname = servlet.find( '{http://xmlns.jcp.org/xml/ns/javaee}servlet-name').text > if servletname == "controller": You could have added a print statement to verify that the line below is executed. > root.remove(servlet) > > tree.write('output.xml') > > This will work if doesnt have below... > > xmlns="http://xmlns.jcp.org/xml/ns/javaee" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee > http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" -- https://mail.python.org/mailman/listinfo/python-list This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. From jussi.piitulainen at helsinki.fi Mon Apr 25 06:24:48 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 25 Apr 2016 13:24:48 +0300 Subject: delete from pattern to pattern if it contains match References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> Message-ID: harirammanohar at gmail.com writes: > On Monday, April 25, 2016 at 12:47:14 PM UTC+5:30, Jussi Piitulainen wrote: >> harirammanohar at gmail.com writes: >> >> > Hi Jussi, >> > >> > i have seen you have written a definition to fulfill the requirement, >> > can we do this same thing using xml parser, as i have failed to >> > implement the thing using xml parser of python if the file is having >> > the content as below... >> > >> > > > PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" >> > "http://java.sun.com/dtd/web-app_2_3.dtd"> >> > >> > >> > >> > and entire thing works if it has as below: >> > > > >> > >> > what i observe is xml tree parsing is not working if http tags are >> > there in between web-app... >> >> Do you get an error message? >> >> My guess is that the parser needs the DTD but cannot access it. There >> appears to be a DTD at that address, http://java.sun.com/... (it >> redirects to Oracle, who bought Sun a while ago), but something might >> prevent the parser from accessing it by default. If so, the details >> depend on what parser you are trying to use. It may be possible to save >> that DTD as a local file and point the parser to that. >> >> Your problem is morphing rather wildly. A previous version had namespace >> declarations but no DTD or XSD if I remember right. The initial version >> wasn't XML at all. >> >> If you post (1) an actual, minimal document, (2) the actual Python >> commands that fail to parse it, and (3) the error message you get, >> someone will be able to help you. The content of the document need not >> be more than "hello, world" level. The DOCTYPE declaration and the >> outermost tags with all their attributes and namespace declarations, if >> any, are important. > > Hi Jussi, > > Here is an input file...sample.xml > > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee > http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" > version="3.1"> > > controller > com.mycompany.mypackage.ControllerServlet > > listOrders > com.mycompany.myactions.ListOrdersAction > > > saveCustomer > com.mycompany.myactions.SaveCustomerAction > > 5 > > > > > graph > /graph > > > > > 30 > > > > -------------------------------- > Here is the code: > > import xml.etree.ElementTree as ET > ET.register_namespace("", "http://xmlns.jcp.org/xml/ns/javaee") > tree = ET.parse('sample.xml') > root = tree.getroot() > > for servlet in root.findall('servlet'): > servletname = servlet.find('servlet-name').text > if servletname == "controller": > root.remove(servlet) > > tree.write('output.xml') > > This will work if doesnt have below... > > xmlns="http://xmlns.jcp.org/xml/ns/javaee" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee > http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" It's a namespace issue, and your method of registering a default namespace isn't working. It's a frustrating failure mode: no error message, no nothing :) Try defining a namespace prefix in your method calls, and using that prefix in element names: ns = { 'x' : "http://xmlns.jcp.org/xml/ns/javaee" } for servlet in root.findall('x:servlet', ns): servletname = servlet.find('x:servlet-name', ns).text I got this from here: https://docs.python.org/3/library/xml.etree.elementtree.html#parsing-xml-with-namespaces Note that the namespace prefix - I chose to use 'x' - has no meaning. It's the association of the prefix that you use to the URI that is the name of the namespace that does the job. From jussi.piitulainen at helsinki.fi Mon Apr 25 06:37:39 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 25 Apr 2016 13:37:39 +0300 Subject: delete from pattern to pattern if it contains match References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> Message-ID: harirammanohar at gmail.com writes: > On Monday, April 25, 2016 at 3:19:15 PM UTC+5:30, hariram... at gmail.com wrote: [- -] >> Here is the code: >> >> import xml.etree.ElementTree as ET >> ET.register_namespace("", "http://xmlns.jcp.org/xml/ns/javaee") >> tree = ET.parse('sample.xml') >> root = tree.getroot() >> >> for servlet in root.findall('servlet'): >> servletname = servlet.find('servlet-name').text >> if servletname == "controller": >> root.remove(servlet) >> >> tree.write('output.xml') [- -] > By the way i didnt get any error message and i am using version 3.4.3 Right. The parsing succeeds but no 'servlet' elements are found and the loop simply has no effect. I may be missing some technical detail, but I think the 'servlet' elements in the document are in the default namespace (because one was declared) while your .findall and .find calls are looking for a 'servlet' element that is in no namespace at all. I seem to remember that there is such a distinction in XML. From jussi.piitulainen at helsinki.fi Mon Apr 25 06:39:14 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 25 Apr 2016 13:39:14 +0300 Subject: delete from pattern to pattern if it contains match References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> Message-ID: Peter Otten writes: > harirammanohar at gmail.com wrote: > >> Here is the code: > > Finally ;) :) From harirammanohar at gmail.com Mon Apr 25 07:02:00 2016 From: harirammanohar at gmail.com (harirammanohar at gmail.com) Date: Mon, 25 Apr 2016 04:02:00 -0700 (PDT) Subject: delete from pattern to pattern if it contains match In-Reply-To: References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> Message-ID: <95f0d9a7-69ff-43bf-a856-8fa62fe8a985@googlegroups.com> On Monday, April 25, 2016 at 4:09:26 PM UTC+5:30, Jussi Piitulainen wrote: > Peter Otten writes: > > > harirammanohar at gmail.com wrote: > > > >> Here is the code: > > > > Finally ;) > > :) name space issue can be resolved registering name space i have no issue with that, only concern is xml parser has no effect when http things are added... From jussi.piitulainen at helsinki.fi Mon Apr 25 07:28:00 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 25 Apr 2016 14:28:00 +0300 Subject: delete from pattern to pattern if it contains match References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> <95f0d9a7-69ff-43bf-a856-8fa62fe8a985@googlegroups.com> Message-ID: harirammanohar at gmail.com writes: > On Monday, April 25, 2016 at 4:09:26 PM UTC+5:30, Jussi Piitulainen wrote: >> Peter Otten writes: >> >> > harirammanohar at gmail.com wrote: >> > >> >> Here is the code: >> > >> > Finally ;) >> >> :) > > name space issue can be resolved registering name space i have no > issue with that, only concern is xml parser has no effect when http > things are added... No, the parser works fine. Your attempt to register a default namespace didn't work. Those "http things" *are* the namespace issue! The following version of your code works. *Try it.* It finds the servlet element in the document object, removes it, and writes out XML text without the servlet element. (It seems to invent another namespace prefix. That doesn't change the meaning of the document.) import xml.etree.ElementTree as ET ns = { 'x' : "http://xmlns.jcp.org/xml/ns/javaee" } tree = ET.parse('sample.xml') root = tree.getroot() for servlet in root.findall('x:servlet', ns): servletname = servlet.find('x:servlet-name', ns).text if servletname == "controller": root.remove(servlet) tree.write('output.xml') From harirammanohar at gmail.com Mon Apr 25 07:40:07 2016 From: harirammanohar at gmail.com (harirammanohar at gmail.com) Date: Mon, 25 Apr 2016 04:40:07 -0700 (PDT) Subject: delete from pattern to pattern if it contains match In-Reply-To: References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> <95f0d9a7-69ff-43bf-a856-8fa62fe8a985@googlegroups.com> Message-ID: <15f2e9ff-7624-4886-bcd9-c3e9d21db328@googlegroups.com> On Monday, April 25, 2016 at 4:58:15 PM UTC+5:30, Jussi Piitulainen wrote: > harirammanohar at gmail.com writes: > > > On Monday, April 25, 2016 at 4:09:26 PM UTC+5:30, Jussi Piitulainen wrote: > >> Peter Otten writes: > >> > >> > harirammanohar at gmail.com wrote: > >> > > >> >> Here is the code: > >> > > >> > Finally ;) > >> > >> :) > > > > name space issue can be resolved registering name space i have no > > issue with that, only concern is xml parser has no effect when http > > things are added... > > No, the parser works fine. Your attempt to register a default namespace > didn't work. Those "http things" *are* the namespace issue! > > The following version of your code works. *Try it.* It finds the servlet > element in the document object, removes it, and writes out XML text > without the servlet element. (It seems to invent another namespace > prefix. That doesn't change the meaning of the document.) > > import xml.etree.ElementTree as ET > > ns = { 'x' : "http://xmlns.jcp.org/xml/ns/javaee" } > > tree = ET.parse('sample.xml') > root = tree.getroot() > > for servlet in root.findall('x:servlet', ns): > servletname = servlet.find('x:servlet-name', ns).text > if servletname == "controller": > root.remove(servlet) > > tree.write('output.xml') yup its working well if i include register namespace, else i am getting ns:0 in every line of output.xml. But its removing top line From jussi.piitulainen at helsinki.fi Mon Apr 25 08:00:09 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 25 Apr 2016 15:00:09 +0300 Subject: delete from pattern to pattern if it contains match References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> <95f0d9a7-69ff-43bf-a856-8fa62fe8a985@googlegroups.com> <15f2e9ff-7624-4886-bcd9-c3e9d21db328@googlegroups.com> Message-ID: harirammanohar at gmail.com writes: > On Monday, April 25, 2016 at 4:58:15 PM UTC+5:30, Jussi Piitulainen wrote: >> harirammanohar at gmail.com writes: >> >> > On Monday, April 25, 2016 at 4:09:26 PM UTC+5:30, Jussi Piitulainen wrote: >> >> Peter Otten writes: >> >> >> >> > harirammanohar at gmail.com wrote: >> >> > >> >> >> Here is the code: >> >> > >> >> > Finally ;) >> >> >> >> :) >> > >> > name space issue can be resolved registering name space i have no >> > issue with that, only concern is xml parser has no effect when http >> > things are added... >> >> No, the parser works fine. Your attempt to register a default namespace >> didn't work. Those "http things" *are* the namespace issue! >> >> The following version of your code works. *Try it.* It finds the servlet >> element in the document object, removes it, and writes out XML text >> without the servlet element. (It seems to invent another namespace >> prefix. That doesn't change the meaning of the document.) >> >> import xml.etree.ElementTree as ET >> >> ns = { 'x' : "http://xmlns.jcp.org/xml/ns/javaee" } >> >> tree = ET.parse('sample.xml') >> root = tree.getroot() >> >> for servlet in root.findall('x:servlet', ns): >> servletname = servlet.find('x:servlet-name', ns).text >> if servletname == "controller": >> root.remove(servlet) >> >> tree.write('output.xml') > > yup its working well if i include register namespace, else i am > getting ns:0 in every line of output.xml. That's a namespace prefix for each element name that is in the default namespace. If the ET.register_namespace has the effect of making that the default namespace in the output, fine, you can use it. The important thing is that you can read your output.xml back in, using the XML parser, and it has the intended meaning. > But its removing top line > Not a problem. You can still read your output.xml back in, using the XML parser, and it will have the same meaning as it would have had with this declaration. From __peter__ at web.de Mon Apr 25 08:33:52 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 25 Apr 2016 14:33:52 +0200 Subject: delete from pattern to pattern if it contains match References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> <95f0d9a7-69ff-43bf-a856-8fa62fe8a985@googlegroups.com> <15f2e9ff-7624-4886-bcd9-c3e9d21db328@googlegroups.com> Message-ID: harirammanohar at gmail.com wrote: >> tree.write('output.xml') > > yup its working well if i include register namespace, else i am getting > ns:0 in every line of output.xml. > > But its removing top line > The write() method allows you to specify an encoding and/or require an xml declaration: https://docs.python.org/dev/library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree.write From oscar.j.benjamin at gmail.com Mon Apr 25 09:45:55 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 25 Apr 2016 14:45:55 +0100 Subject: Optimizing Memory Allocation in a Simple, but Long Function In-Reply-To: References: Message-ID: On 25 April 2016 at 08:39, Gregory Ewing wrote: > Derek Klinge wrote: >> >> Also, it seems to me if the goal is to use the smallest value of n to get >> a >> particular level of accuracy, changing your guess of N by doubling seems >> to >> have a high chance of overshoot. > > > If you want to find the exact n required, once you overshoot > you could use a binary search to narrow it down. Also you can calculate the truncation error for Euler's method. Since f(t) = f(t0) + f'(t0)*(t - t0) + (1/2)f''(t0)*(t - t0)**2 + O((t - t0)**3) Euler's method just uses the first two terms so x[n+1] = x[n] + dt*f(x[n]) the next term would be (1/2)*f'(x[n])*dt**2 Since in your case f'(x) = x and dt = 1/N that's (1/2)*x[n]*(1/N)**2 As a relative error (divide by x[n]) that's (1/2)*(1/N)**2 Let's add the relative error from N steps to get N*(1/2)*(1/N)**2 = 1/(2*N) So the relative error integrating from 0 to 1 with N steps is 1/(2*N). If we want a relative error of epsilon then the number of steps needed is 1/(2*epsilon). That is to say that for a relative error of 1e-4 we need N = 1/(2*1e-4) = 1e4/2 = 5e3 = 5000. >>> import math >>> N = 5000 >>> error = math.e - (1 + 1.0/N)**N >>> relative_error = error / math.e >>> relative_error 9.998167027596845e-05 Which is approximately 1e-4 as required. -- Oscar From lepto.python at gmail.com Mon Apr 25 10:13:56 2016 From: lepto.python at gmail.com (oyster) Date: Mon, 25 Apr 2016 22:13:56 +0800 Subject: what is the difference between one-line-operation and 2-line-operation Message-ID: for a simple code [code] vexList = [1, 2, 3] print('vexList', list(vexList)) vexList=map(lambda e: e+1, vexList) print('vexList', list(vexList)) vexList = list(vexList) print('vexList', list(vexList)) vexList=map(lambda e: e*2,vexList) print('vexList', list(vexList)) [/code] py27 says [quote] ('vexList', [1, 2, 3]) ('vexList', [2, 3, 4]) ('vexList', [2, 3, 4]) ('vexList', [4, 6, 8]) [/quote] but py34 says [quote] vexList [1, 2, 3] vexList [2, 3, 4] vexList [] vexList [] [/quote] if I change the above code in to one line [code] vexList = [1, 2, 3] print('vexList', list(vexList)) vexList=list(map(lambda e: e+1, vexList)) print('vexList', list(vexList)) vexList=map(lambda e: e*2,vexList) print('vexList', list(vexList)) [/code] then py27 and py34 get same verList [quote] ('vexList', [1, 2, 3]) ('vexList', [2, 3, 4]) ('vexList', [4, 6, 8]) [/quote] I found 'filter' function behaves likely I found type(map(lambda e: e, vexList)) is in py2 type(map(lambda e: e, vexList)) is in py3 so, what produces this difference between py2 and py3 in nature? is there more examples? where can I find the text abiut his difference? Thanks From schilke.60 at gmail.com Mon Apr 25 10:35:54 2016 From: schilke.60 at gmail.com (Derek Klinge) Date: Mon, 25 Apr 2016 14:35:54 +0000 Subject: Optimizing Memory Allocation in a Simple, but Long Function In-Reply-To: References: Message-ID: A couple thoughts. I think my original approach would be faster than binary search for finding the minimum value of N needed to get a decimal level of absolute accuracy from Euler's number. Here is my reasoning: EulerlersNumber(13).LimitMethod() - math.e < .1 and EulersNumber(135).LimitMethod - math.e < .01. N increased by a little more than a factor of 10. My method would use 130, 131, 132, 133, 134, and 135 as guesses after 13. Using the double + binary search the guesses would be 26, 52, 104, 208, 156, 130, 143, 137, 134, 136, and then 136 after using the information that n=13 gives an tolerance of < .1. If the trend holds, then to get the next decimal of accuracy, you would need to do less than 10 searches each time. When I was using my linear approximation method I found that I never had to do more than 10 additional guesses of N to get the next digit of accuracy. When I was using EulersMethod() I found this trend held for as long as I would allow my computer to do the calculations (though accuracy to 10**-10). What I find very interesting is that although the limit method is mathematically equivalent to the linear approximation method, they give different results, given sufficiently high values of N (at least in Python). The limit method does not follow my predictions as accurately, which leads to the question of whether or not the phenomenon I observed was an artifact of rounding error or not. Also, my explicit goal is to be able to handle large numbers of N, and to reduce rounding error to a minimum. Using the fractions module to perform the limit method with rational numbers rather than binary represented decimals and got an error that the integer was too long to convert to float and even when using smaller values of n (10**14) I seem to get values that are not the same as when using decimals. It seems to me (I'm just thinking about this at a low level and haven't written out any math to justify it yet) that because the linear approximation method only multiplies and adds the rounding error is smaller than in the limit method where numbers are being taken to exponents that have rounding errors. Although I see the value of relative error, I am just as interested in absolute error (though admittedly they are directly related values). Are there modules or libraries I can/should use to minimize rounding error and use very large values of N and get an accurate answer? How does the math module calculate the vale of e? Thanks, Derek On Mon, Apr 25, 2016 at 6:49 AM Oscar Benjamin wrote: > On 25 April 2016 at 08:39, Gregory Ewing > wrote: > > Derek Klinge wrote: > >> > >> Also, it seems to me if the goal is to use the smallest value of n to > get > >> a > >> particular level of accuracy, changing your guess of N by doubling seems > >> to > >> have a high chance of overshoot. > > > > > > If you want to find the exact n required, once you overshoot > > you could use a binary search to narrow it down. > > Also you can calculate the truncation error for Euler's method. Since > > f(t) = f(t0) + f'(t0)*(t - t0) + (1/2)f''(t0)*(t - t0)**2 + O((t - > t0)**3) > > Euler's method just uses the first two terms so > > x[n+1] = x[n] + dt*f(x[n]) > > the next term would be > > (1/2)*f'(x[n])*dt**2 > > Since in your case f'(x) = x and dt = 1/N that's > > (1/2)*x[n]*(1/N)**2 > > As a relative error (divide by x[n]) that's > > (1/2)*(1/N)**2 > > Let's add the relative error from N steps to get > > N*(1/2)*(1/N)**2 = 1/(2*N) > > So the relative error integrating from 0 to 1 with N steps is 1/(2*N). > If we want a relative error of epsilon then the number of steps needed > is 1/(2*epsilon). > > That is to say that for a relative error of 1e-4 we need N = > 1/(2*1e-4) = 1e4/2 = 5e3 = 5000. > > >>> import math > >>> N = 5000 > >>> error = math.e - (1 + 1.0/N)**N > >>> relative_error = error / math.e > >>> relative_error > 9.998167027596845e-05 > > Which is approximately 1e-4 as required. > > -- > Oscar > -- > https://mail.python.org/mailman/listinfo/python-list > From grant.b.edwards at gmail.com Mon Apr 25 10:39:45 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 25 Apr 2016 14:39:45 +0000 (UTC) Subject: Scraping email to make invoice References: <571D548D.2040500@gmail.com> Message-ID: On 2016-04-24, Michael Torrie wrote: > On 04/24/2016 12:58 PM, CM wrote: > >> 1. INPUT: What's the best way to scrape an email like this? The >> email is to a Gmail account, and the content shows up in the >> email as a series of basically 6x7 tables (HTML?), one table per >> PO number/task. I know if the freelancer were to copy and paste >> the whole set of tables into a text file and save it as plain >> text, Python could easily scrape that file, but I'd much prefer >> to save the user those steps. Is there a relatively easy way to >> go from the Gmail email to generating the invoice directly? (I >> know there is, but wasn't sure what is state of the art these >> days). > > I would configure Gmail to allow IMAP access (you'll have to set up a > special password for this most likely), Your normal gmail password is used for IMAP. > and then use an imap library from Python to directly find the > relevant messages and access the email message body. If the body is > HTML-formatted (sounds like it is) I would use either BeautifulSoup > or lxml to parse it and get out the relevant information. Warning: don't use the basic imaplib. IMAP is a miserable protocol, and imap lib is too thin a wrapper. It'll make you bleed from the ears and wish you were dead. Use imapclient or imaplib2. I've used both (with Gmail's IMAP server), and IMO both are pretty good. Either one is miles ahead of plain imaplib. -- Grant Edwards grant.b.edwards Yow! But they went to MARS at around 1953!! gmail.com From jussi.piitulainen at helsinki.fi Mon Apr 25 10:42:35 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 25 Apr 2016 17:42:35 +0300 Subject: what is the difference between one-line-operation and 2-line-operation References: Message-ID: oyster writes: - - > I found > type(map(lambda e: e, vexList)) is in py2 > type(map(lambda e: e, vexList)) is in py3 > > so, what produces this difference between py2 and py3 in nature? is > there more examples? where can I find the text abiut his difference? Yes, there are more ways obtain objects that behave like the map and filter objects on Python 3. One similar to map and filter is enumerate. Try iter('foo'), iter((1,2,4)), ..., iter(range(3)). This is used implicitly by certain Python constructions. Note that range objects themselves are different. Open a file for reading: open('example.txt'). You get lines out. A generator expression: ( "{}".format(x) for x in (1,2,3) ), where the outer parentheses are for grouping and not always needed. Define and call a generator function: def foo(o): yield '(' yield o yield ')' x = foo(31) '(-31-)' == '-'.join(foo('31')) You can ask for the next element from any of these, or collect their remaining elements in a list or tuple, or otherwise iterate or map over them. They will be consumed when you do so, otherwise they just wait. They can be huge, even infinite. Best not to collect their contents in a data structure if they are huge. They trade space for time. From grant.b.edwards at gmail.com Mon Apr 25 10:44:37 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 25 Apr 2016 14:44:37 +0000 (UTC) Subject: Writing different sections into a file References: Message-ID: On 2016-04-25, Palpandi wrote: > Hi, > > I need to write different sections into a file. At any point of > time, content can be added to any section. > > I don't want keep each section into a temporary file. What is the > better way to store the contents of each section and write them into > a file at the end? What makes you think a temporary file isn't best? > What is the better datatype to achieve this? When in doubt, try the simplest approach first: Use a string (or byte-string if it's not text) for each of the header, body, and footer. Append data to each as desired and then write them out to a file when you're done. If that's not workable, explain why, and we can tell you what to try next (probably a stringio for each section, or a list of strings or byte-strings for each section, or temporary files). -- Grant Edwards grant.b.edwards Yow! Wait ... is this a FUN at THING or the END of LIFE in gmail.com Petticoat Junction?? From torriem at gmail.com Mon Apr 25 10:46:31 2016 From: torriem at gmail.com (Michael Torrie) Date: Mon, 25 Apr 2016 08:46:31 -0600 Subject: what is the difference between one-line-operation and 2-line-operation In-Reply-To: References: Message-ID: <571E2DC7.6090902@gmail.com> On 04/25/2016 08:13 AM, oyster wrote: > so, what produces this difference between py2 and py3 in nature? is > there more examples? where can I find the text abiut his difference? One thing I see is that both your py2 and py3 examples are treating print as a function. It's only a function in Py3. By default in Py2 it's a statement. You passed it a tuple, and that's what it prints. If you add: from __future__ import print_function then py2 and py3 will behave the same in regards to print. From subhabangalore at gmail.com Mon Apr 25 10:56:52 2016 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Mon, 25 Apr 2016 07:56:52 -0700 (PDT) Subject: Question on List processing Message-ID: Dear Group, I have a list of tuples, as follows, list1=[u"('koteeswaram/BHPERSN engaged/NA himself/NA in/NA various/NA philanthropic/NA activities/NA ','class1')", u"('koteeswaram/BHPERSN is/NA a/NA very/NA nice/NA person/NA ','class1')", u"('koteeswaram/BHPERSN came/NA to/NA mumbai/LOC but/NA could/NA not/NA attend/NA the/ARTDEF board/NA meeting/NA ','class1')", u"('the/ARTDEF people/NA of/NA the/ARTDEF company ABCOMP did/NA not/NA vote/NA for/NA koteeswaram/LOC ','class2')", u"('the/ARTDEF director AHT of/NA the/ARTDEF company,/NA koteeswaram/BHPERSN had/NA been/NA advised/NA to/NA take/NA rest/NA for/NA a/NA while/NA ','class2')", u"('animesh/BHPERSN chauhan/BHPERSN arrived/NA by/NA his/PRNM3PAS private/NA aircraft/NA in/NA mumbai/LOC ','class2')", u"('animesh/BHPERSN chauhan/BHPERSN met/NA the/ARTDEF prime/HPLPERST minister/AHT of/NA india/LOCC over/NA some/NA issues/NA ','class2')", u"('animesh/BHPERSN chauhan/BHPERSN is/NA trying/NA to/NA set/NA up/NA a/NA plant/NA in/NA uk/LOCC ','class3')", u"('animesh/BHPERSN chauhan/BHPERSN is/NA trying/NA to/NA launch/NA a/NA new/ABCOMP office/AHT in/NA burdwan/LOC ','class3')", u"('animesh/BHPERSN chauhan/BHPERSN is/NA trying/NA to/NA work/NA out/NA the/ARTDEF launch/NA of/NA a/NA new/ABCOMP product/NA in/NA india/LOCC ','class3')"] I want to make it like, [('koteeswaram/BHPERSN engaged/NA himself/NA in/NA various/NA philanthropic/NA activities/NA','class1'), ('koteeswaram/BHPERSN is/NA a/NA very/NA nice/NA person/NA ','class1'), ('koteeswaram/BHPERSN came/NA to/NA mumbai/LOC but/NA could/NA not/NA attend/NA the/ARTDEF board/NA meeting/NA','class1'), ('the/ARTDEF people/NA of/NA the/ARTDEF company ABCOMP did/NA not/NA vote/NA for/NA koteeswaram/LOC ','class2'), ('the/ARTDEF director AHT of/NA the/ARTDEF company,/NA koteeswaram/BHPERSN had/NA been/NA advised/NA to/NA take/NA rest/NA for/NA a/NA while/NA ','class2'), ('animesh/BHPERSN chauhan/BHPERSN arrived/NA by/NA his/PRNM3PAS private/NA aircraft/NA in/NA mumbai/LOC','class2'), ('animesh/BHPERSN chauhan/BHPERSN met/NA the/ARTDEF prime/HPLPERST minister/AHT of/NA india/LOCC over/NA some/NA issues/NA','class2'), ('animesh/BHPERSN chauhan/BHPERSN is/NA trying/NA to/NA set/NA up/NA a/NA plant/NA in/NA uk/LOCC','class3'), ('animesh/BHPERSN chauhan/BHPERSN is/NA trying/NA to/NA launch/NA a/NA new/ABCOMP office/AHT in/NA burdwan/LOC','class3'), ('animesh/BHPERSN chauhan/BHPERSN is/NA trying/NA to/NA work/NA out/NA the/ARTDEF launch/NA of/NA a/NA new/ABCOMP product/NA in/NA india/LOCC','class3')] I tried to make it as follows, list2=[] for i in train_sents: a1=unicodedata.normalize('NFKD', i).encode('ascii','ignore') a2=a1.replace('"',"") list2.append(a2) and, for i in list1: a3=i[1:-1] list2.append(a3) but not helping. If any one may kindly suggest how may I approach it? Thanks in Advance, Regards, Subhabrata Banerjee. From walters.justin01 at gmail.com Mon Apr 25 11:00:05 2016 From: walters.justin01 at gmail.com (justin walters) Date: Mon, 25 Apr 2016 08:00:05 -0700 Subject: Writing different sections into a file In-Reply-To: <571DEBAB.6010503@gmail.com> References: <571DEBAB.6010503@gmail.com> Message-ID: On Mon, Apr 25, 2016 at 3:04 AM, Karim wrote: > > > On 25/04/2016 09:30, Palpandi wrote: > >> Hi, >> >> I need to write different sections into a file. >> At any point of time, content can be added to any section. >> >> I don't want keep each section into a temporary file. >> What is the better way to store the contents of each section and write >> them into a file at the end? >> What is the better datatype to achieve this? >> >> >> Thanks and Regards, >> Palpandi >> > > Use Stringio: > - > > from cStringIO import StringIO > > content = StringIO() > > # Header > content.write('; Header\n') > content.write('; Body'\n) > content.write('; Footer\n') > > open('my_file', 'wb').write(content.getvalue()) > > - > Karim > > > -- > https://mail.python.org/mailman/listinfo/python-list > All of the other answers are great too. I was thinking that you could format the text file to have dividers for each section. For instance it may look something like this: Header Lorem ipsum.... <---> Body Lorem ipsum... <---> Footer Lorem ipsum.. Then, you could create a list of sections like so: file = open('file.txt', 'r').read() section_list = file.split('<--->') print(section_list[0]) >>> Header Lorem ipsum... Say you wanted to get really fancy, you could even format the file to have named sections like so:
Lorem ipsum...
Lorem ipsum...
Lorem ipsum...
Then you can use the xmlparser library to parse the file into an xml object. Alternatively, you could also use JSON formatting: { sections: { header: { title: "header", content: "Lorem ipsum..." }, body: { title: "Body", content: "Lorem ipsum..." }, footer: { title: "Footer", content: "Lorem ipsum..." } } } I hope this helps. From kliateni at gmail.com Mon Apr 25 11:12:59 2016 From: kliateni at gmail.com (Karim) Date: Mon, 25 Apr 2016 17:12:59 +0200 Subject: Writing different sections into a file In-Reply-To: References: <571DEBAB.6010503@gmail.com> Message-ID: <571E33FB.3080200@gmail.com> On 25/04/2016 17:00, justin walters wrote: > On Mon, Apr 25, 2016 at 3:04 AM, Karim wrote: > >> >> On 25/04/2016 09:30, Palpandi wrote: >> >>> Hi, >>> >>> I need to write different sections into a file. >>> At any point of time, content can be added to any section. >>> >>> I don't want keep each section into a temporary file. >>> What is the better way to store the contents of each section and write >>> them into a file at the end? >>> What is the better datatype to achieve this? >>> >>> >>> Thanks and Regards, >>> Palpandi >>> >> Use Stringio: >> - >> >> from cStringIO import StringIO >> >> content = StringIO() >> >> # Header >> content.write('; Header\n') >> content.write('; Body'\n) >> content.write('; Footer\n') >> >> open('my_file', 'wb').write(content.getvalue()) >> >> - >> Karim >> >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > All of the other answers are great too. I was thinking that you could > format the text file to have dividers for each section. For instance it may > look something like this: > > Header > Lorem ipsum.... > <---> > Body > Lorem ipsum... > <---> > Footer > Lorem ipsum.. > > Then, you could create a list of sections like so: > > file = open('file.txt', 'r').read() > > section_list = file.split('<--->') > > print(section_list[0]) > > Header > Lorem ipsum... > > Say you wanted to get really fancy, you could even format the file to have > named sections like so: > >
> Lorem ipsum... >
>
> Lorem ipsum... >
>
> Lorem ipsum... >
> > Then you can use the xmlparser library to parse the file into an xml object. > > > Alternatively, you could also use JSON formatting: > > { > sections: { > header: { > title: "header", > content: "Lorem ipsum..." > }, > body: { > title: "Body", > content: "Lorem ipsum..." > }, > footer: { > title: "Footer", > content: "Lorem ipsum..." > } > } > } > > I hope this helps. Great ideas! From gherron at digipen.edu Mon Apr 25 11:42:00 2016 From: gherron at digipen.edu (Gary Herron) Date: Mon, 25 Apr 2016 08:42:00 -0700 Subject: what is the difference between one-line-operation and 2-line-operation In-Reply-To: References: Message-ID: <571E3AC8.8020209@digipen.edu> On 04/25/2016 07:13 AM, oyster wrote: > for a simple code > [code] > vexList = [1, 2, 3] > print('vexList', list(vexList)) > > vexList=map(lambda e: e+1, vexList) > print('vexList', list(vexList)) > > vexList = list(vexList) > print('vexList', list(vexList)) > > vexList=map(lambda e: e*2,vexList) > print('vexList', list(vexList)) > [/code] > > > py27 says > [quote] > ('vexList', [1, 2, 3]) > ('vexList', [2, 3, 4]) > ('vexList', [2, 3, 4]) > ('vexList', [4, 6, 8]) > [/quote] > > but py34 says > [quote] > vexList [1, 2, 3] > vexList [2, 3, 4] > vexList [] > vexList [] > [/quote] The difference in behaviour between Python2 and Python3 is the map function. In P2 it returned a list, while in P3 it returns an iterator. Your code runs through that iterator twice with the list() function. The first time it gets the elements of the list as expected, but the second time, the iterator is exhausted and returns no objects. A simpler example: "b" is a map object (iterator), then list(b) is run twice. >>> a = [1,2,3] >>> b = map(lambda e: e+1, a) >>> b >>> list(b) [2, 3, 4] >>> list(b) [] I hope that helps. Gary Herron -- Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology (425) 895-4418 From liyang1025 at gmail.com Mon Apr 25 11:44:26 2016 From: liyang1025 at gmail.com (=?UTF-8?B?5p2O5rSL?=) Date: Mon, 25 Apr 2016 08:44:26 -0700 (PDT) Subject: encoding issue help Message-ID: <12e04989-6429-435a-a118-bab0c9a833d8@googlegroups.com> hi: i want to decompress the string "\x1F\x8B\x08\x00\x00\x00\x00\x00\x00\x00UP]k\xC3 \x14\xFD+\xC3\xE7\xCD\xA8\xF9X\xE2\xEBX\xA1\x0CF\x1F\xBA\xEE%\x10\xAC\xB1\xAD\xC4h\x88f%\x8C\xFD\xF7]\x1B\xDA\xAD\xF8\xE29\xE7z\xEE9~#\xE7\x11G\xAF\xBB\x1C=\x22\xDFv_j\x04H+@\xBAW\x1A\xEEe\x91>SF\x18+i\x9Ef\x04\x84\xA1;\x02/]\x8F\xA5Q\xC2\xF6\xC2\x075\xE2\xFE8\x89\xB1m\xA4\x85\x89V\xFB\xC1\x88\x19\xA6\xDE\xB6\x1Fe\xB6y\x08\xCA\x87\xA7N\xCD\x1E\xC4^H\x10\xF6\x19'\x19/\x14g\x92K\xC1[\x06\xCA\xB2\x9Ca\x82K@\x07m\x8F\x17B\x98\xC1\xD7\xC9a2\xA6\xD9W\xA4j\xBAI\x9E\x84\xAB\x93\x7F\x80g\x18N\x9D,\xEB\xEA\x84fyJIAI\xCE'\xAF\xC6:\xB9\x0B\xE0\xF6\xDA\xA8\x95qg0\x8FE\x87Ke\x86iQbZU\x98\x924\xD6\x1C];\xC9\xB0n\xA3Jhd\x8C\x08\xB7\xCF\x1AN\xCE\xAA-|R\x94\xB3\x82\xA6\xE0\x902v\x19\xB4*l\xE7!*\x9F\xEB\xD5\x1A\x88\xB3>\xE8\xBF\x85\xC1u\xCA\x22n\xA1\x11\xA4\x99wj|\x17\x8B\x0F\x86\xF2\x8D\x8C\xE5\x85\x0Cn\x9Co\xDBt\xEF\xF5\xF2X\x1A\xADlx9\x09k\x95\xB9\x9A\xC8+DtI\xB0\xD116\xFA\xF9\x05\xBAs\xAET\xE0\x01\x00\x00" this string is compress gzip if i save this string in the file and read file to decompress that is not work ,otherwise i use the python interpreter mode and paste the string in the command line the code is work i suppose this is the character-set issue but i can't fix it !so i hope someone give me a solution! my cods blow ,and the work environment is linux import zlib file_obj=open("compress_data.log","r+") for gz_data in file_obj.readlines(): print gz_data decompressed_data = zlib.decompress(gz_data, 16+zlib.MAX_WBITS) print decompressed_data From mr.eightnoteight at gmail.com Mon Apr 25 11:46:10 2016 From: mr.eightnoteight at gmail.com (srinivas devaki) Date: Mon, 25 Apr 2016 21:16:10 +0530 Subject: how to set nth bit of large binary file. Message-ID: I use aria2c to download files, aria2c has this feature of allocating the memory to file before downloading the file and then it will download using multiple connections so filling the data into this file concurrently. So i wonder how to do it. I found a way to do that from here http://stackoverflow.com/questions/3407505/writing-binary-data-to-middle-of-a-sparse-file but it only supports if you are constructing the data in file from scratch and aria2c can resume the download too i.e not from scratch. -- Regards Srinivas Devaki Junior (3rd yr) student at Indian School of Mines,(IIT Dhanbad) Computer Science and Engineering Department ph: +91 9491 383 249 telegram_id: @eightnoteight From sourav524.itscient at gmail.com Mon Apr 25 12:28:48 2016 From: sourav524.itscient at gmail.com (sourav524.itscient at gmail.com) Date: Mon, 25 Apr 2016 09:28:48 -0700 (PDT) Subject: HOT REQ Closable Position :Websphere message broker at Edison, NJ Message-ID: <751df735-463b-466c-965d-2e74d6880edb@googlegroups.com> Hello Associates, Please go through the below job description and let me know your interest. Please revert me: Sourav.P at itscient.com or sourav524.itscient at gmail.com. Position: Websphere Message Broker Location:Edison , NJ Duration: 6+ MONTHS Requisition Details: Engineer with experience on working with the new generation messaging platforms such as RabbitMQ, ActiveMQ, JMS,AMQP. Cloudscale Runtime Engineering team is responsible for the Engineering and Delivery of Next Generation Light weight Open Standards-based Platforms for Application Development/Deployment, Caching, Messaging, and Integration Services in client Private Cloud. The responsibilities of the team include delivery and adoption of the Next Generation Runtime Platforms for strategic programs across client Business Lines. Key Responsisbilites: ? Engineer efficient Service Provisioning and Management of the Platforms in client Private cloud environment ? Develop Integrated monitoring and management of Cloud Messaging Platform consistent with the Cloud Platform Frameworks ? Enable On-demand scalability and Capacity Management of the services ? Engineer Platform Security Guidelines consistent with client Global Security Policies ? Provide key SME to enable rapid Application development and deployment leveraging the CloudScale messaging platforms ? Work closely with application development teams to handle escalations and provide timely issue resolutions ? This CloudScale Engineer position requires Evaluation and Assessments of Next Generation Application Messaging Platforms and develop usage Patterns and Recommendations for early adopter use-cases Must have skills ? About 2-3 years of hands-on working experience with messaging middleware platforms such as RabbitMQ, ActiveMQ TIBCO EMS, IBM MQ or JMS based systems. ? Experience in Engineering Messaging Platforms for efficient service provisioning, management and monitoring as well as Continuity of Business/Disaster recovery solutions ? Working experience on projects involving multiple services/component integration ? Experience in engineering platform security and integration with Security/Authentication/Authorization services ? Strong Exposure to Messaging Paradigms, Network Protocols and Resilient services ? Exposure to Application Programming Languages such as Ruby, Java, C/C++, C#. ? Exposure to REST/JSON and WebServices services ? Experience using either WebService or REST for managing application/messaging tasks. ? Working experience with scripting languages such as Python, Perl, PHP, JavaScript, Shell ? Excellent Oral and Written Communication Skills Nice to have Skills ? Strong Exposure to Cloud environments such as AWS/CloudFoundry/Google/Azune ? Hands on experience with Messaging Platforms in the Cloud such as RabbitMQ/ActiveMQ ? Exposure to API based Application Services Integration Frameworks ? Exposure to automation framework components such as Chef, Puppet ? Experience with service and application monitoring frameworks such as Graphite, Wily, RTView ? Log management in a distributed environment using utilities such as Logstash/Splunk ? Exposure to Middleware components such as WebServer and AppServer Thanks & Regards Sourav Paul | Technical Recruiter IT-SCIENT LLC, Fremont, CA, USA Email: sourav524.itscient at gmail.com Phone: 510-972-8633 | Fax: 877-701-5240 |web: www.itscient.com From steve at pearwood.info Mon Apr 25 12:36:56 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 26 Apr 2016 02:36:56 +1000 Subject: Question on List processing References: Message-ID: <571e47aa$0$1588$c3e8da3$5496439d@news.astraweb.com> On Tue, 26 Apr 2016 12:56 am, subhabangalore at gmail.com wrote: > Dear Group, > > I have a list of tuples, as follows, > > list1=[u"('koteeswaram/BHPERSN engaged/NA himself/NA in/NA various/NA [... 17 more lines of data ...] Hi Subhabrata, and thanks for the question. Please remember that we are offering help for free, in our own time. If you want help from us, you should help us to help you. It is very unlikely that many people will spend the time to study your data in close enough detail to understand your requirements. Please give a *simplified* example. Instead of 17 lines of repetitive data, use a "toy" example that matches the format but without all the complicated details. And format it so that it is easy to read: input = [u"('a/b/ ','A')", u"('z/x/ ','B')", u"('b/d/ ','C')", ] output = ???? > I tried to make it as follows, [...] > but not helping. What do you mean, "not helping"? What happens when you try? Please show a *simple* example, with no more than four or five lines of *short, easy to read* text. Remember, we are giving you advice and consulting for free. We are not paid to do this. If your questions are too difficult, boring, tedious, or unpleasant, we will just ignore them, so please help us to help you by simplifying them as much as possible. Thank you. -- Steven From torriem at gmail.com Mon Apr 25 13:16:47 2016 From: torriem at gmail.com (Michael Torrie) Date: Mon, 25 Apr 2016 11:16:47 -0600 Subject: Scraping email to make invoice In-Reply-To: References: <571D548D.2040500@gmail.com> Message-ID: <571E50FF.9010507@gmail.com> On 04/25/2016 08:39 AM, Grant Edwards wrote: > Your normal gmail password is used for IMAP. Actually, no, unless you explicitly tell Google to allow "less-secure" authentication. Otherwise you are required to set up a special, application-specific password. https://support.google.com/accounts/answer/185833?hl=en > Warning: don't use the basic imaplib. IMAP is a miserable protocol, > and imap lib is too thin a wrapper. It'll make you bleed from the ears > and wish you were dead. Use imapclient or imaplib2. I've used both > (with Gmail's IMAP server), and IMO both are pretty good. Either one > is miles ahead of plain imaplib. From grant.b.edwards at gmail.com Mon Apr 25 13:59:06 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 25 Apr 2016 17:59:06 +0000 (UTC) Subject: Scraping email to make invoice References: <571D548D.2040500@gmail.com> <571E50FF.9010507@gmail.com> Message-ID: On 2016-04-25, Michael Torrie wrote: > On 04/25/2016 08:39 AM, Grant Edwards wrote: >> Your normal gmail password is used for IMAP. > > Actually, no, unless you explicitly tell Google to allow "less-secure" > authentication. Otherwise you are required to set up a special, > application-specific password. > > https://support.google.com/accounts/answer/185833?hl=en You're right. I should have said your normal gmail password _can_be_ used for IMAP. -- Grant Edwards grant.b.edwards Yow! TAILFINS!! ... click at ... gmail.com From Seymore4Head at Hotmail.invalid Mon Apr 25 14:10:58 2016 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Mon, 25 Apr 2016 14:10:58 -0400 Subject: Python path and append References: Message-ID: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head wrote: I am going to forget using a directory path. I would like to take the file win.txt and append a space and the * symbol. f = open('win.txt', 'r+') for line in f: f.read(line) f.write(line+" *") This doesn't work. Would someone fix it please? It is for a task I am trying to accomplish just for a home task. From rgaddi at highlandtechnology.invalid Mon Apr 25 14:24:02 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Mon, 25 Apr 2016 18:24:02 -0000 (UTC) Subject: Python path and append References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Message-ID: Seymore4Head wrote: > On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head > wrote: > > I am going to forget using a directory path. > I would like to take the file win.txt and append a space and the * > symbol. > > f = open('win.txt', 'r+') > for line in f: > f.read(line) > f.write(line+" *") > > This doesn't work. Would someone fix it please? It is for a task I > am trying to accomplish just for a home task. "for line in f:" already means "make the variable line equal to each line in f sequentially". f.read is both superfluous and also doesn't do that. Leave it out entirely. The next problem you'll have is that iterating over the lines of the file leaves the newline at the end of line, so your * will end up on the wrong line. Do yourself a favor: https://docs.python.org/3/tutorial/inputoutput.html isn't very long. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From Seymore4Head at Hotmail.invalid Mon Apr 25 15:00:32 2016 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Mon, 25 Apr 2016 15:00:32 -0400 Subject: Python path and append References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Message-ID: On Mon, 25 Apr 2016 18:24:02 -0000 (UTC), Rob Gaddi wrote: >Seymore4Head wrote: > >> On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head >> wrote: >> >> I am going to forget using a directory path. >> I would like to take the file win.txt and append a space and the * >> symbol. >> >> f = open('win.txt', 'r+') >> for line in f: >> f.read(line) >> f.write(line+" *") >> >> This doesn't work. Would someone fix it please? It is for a task I >> am trying to accomplish just for a home task. > >"for line in f:" already means "make the variable line equal to each >line in f sequentially". f.read is both superfluous and also doesn't do >that. Leave it out entirely. > >The next problem you'll have is that iterating over the lines of the >file leaves the newline at the end of line, so your * will end up on the >wrong line. > >Do yourself a favor: https://docs.python.org/3/tutorial/inputoutput.html >isn't very long. I was reading that. I have read it before. I don't use python enough to even remember the simple stuff. Then when I try to use if for something simple I forget how. f = open('wout.txt', 'r+') for line in f: line=line.strip() f.write(line+" *") f.close() Still broke. How about just telling me where I missed? Please? From Joaquin.Alzola at lebara.com Mon Apr 25 15:08:56 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Mon, 25 Apr 2016 19:08:56 +0000 Subject: Python path and append In-Reply-To: References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Message-ID: Strip() = white spaces. Description The method strip() returns a copy of the string in which all chars have been stripped from the beginning and the end of the string (default whitespace characters). Use to remove return carriage--> line[:-1] -----Original Message----- From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com at python.org] On Behalf Of Seymore4Head Sent: 25 April 2016 20:01 To: python-list at python.org Subject: Re: Python path and append On Mon, 25 Apr 2016 18:24:02 -0000 (UTC), Rob Gaddi wrote: >Seymore4Head wrote: > >> On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head >> wrote: >> >> I am going to forget using a directory path. >> I would like to take the file win.txt and append a space and the * >> symbol. >> >> f = open('win.txt', 'r+') >> for line in f: >> f.read(line) >> f.write(line+" *") >> >> This doesn't work. Would someone fix it please? It is for a task I >> am trying to accomplish just for a home task. > >"for line in f:" already means "make the variable line equal to each >line in f sequentially". f.read is both superfluous and also doesn't >do that. Leave it out entirely. > >The next problem you'll have is that iterating over the lines of the >file leaves the newline at the end of line, so your * will end up on >the wrong line. > >Do yourself a favor: >https://docs.python.org/3/tutorial/inputoutput.html >isn't very long. I was reading that. I have read it before. I don't use python enough to even remember the simple stuff. Then when I try to use if for something simple I forget how. f = open('wout.txt', 'r+') for line in f: line=line.strip() f.write(line+" *") f.close() Still broke. How about just telling me where I missed? Please? -- https://mail.python.org/mailman/listinfo/python-list This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. From rgaddi at highlandtechnology.invalid Mon Apr 25 15:31:27 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Mon, 25 Apr 2016 19:31:27 -0000 (UTC) Subject: Python path and append References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Message-ID: Seymore4Head wrote: > On Mon, 25 Apr 2016 18:24:02 -0000 (UTC), Rob Gaddi > wrote: > >>Seymore4Head wrote: >> >>> On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head >>> wrote: >>> >>> I am going to forget using a directory path. >>> I would like to take the file win.txt and append a space and the * >>> symbol. >>> >>> f = open('win.txt', 'r+') >>> for line in f: >>> f.read(line) >>> f.write(line+" *") >>> >>> This doesn't work. Would someone fix it please? It is for a task I >>> am trying to accomplish just for a home task. >> >>"for line in f:" already means "make the variable line equal to each >>line in f sequentially". f.read is both superfluous and also doesn't do >>that. Leave it out entirely. >> >>The next problem you'll have is that iterating over the lines of the >>file leaves the newline at the end of line, so your * will end up on the >>wrong line. >> >>Do yourself a favor: https://docs.python.org/3/tutorial/inputoutput.html >>isn't very long. > > I was reading that. I have read it before. I don't use python enough > to even remember the simple stuff. Then when I try to use if for > something simple I forget how. > > f = open('wout.txt', 'r+') > for line in f: > line=line.strip() > f.write(line+" *") > f.close() > > Still broke. How about just telling me where I missed? Please? Depends on what "broke" means. I'm going to go out on a limb and guess that the problem now is that you get no newlines at all, because they've been stripped off of the line you read and .write doesn't put it back on, in which case you should be adding " *\n" instead. If that's not it, then reply hazy, please concentrate and ask again. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From python at mrabarnett.plus.com Mon Apr 25 15:44:50 2016 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 25 Apr 2016 20:44:50 +0100 Subject: Python path and append In-Reply-To: References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Message-ID: On 2016-04-25 20:08, Joaquin Alzola wrote: > Strip() = white spaces. > Description > The method strip() returns a copy of the string in which all chars have been stripped from the beginning and the end of the string (default whitespace characters). > > Use to remove return carriage--> line[:-1] > 1. In the file it might be a linefeed, or a carriage return, or a carriage return followed by a linefeed, depending on the operating system. Python translates it to a linefeed "\n" (or 'newline') on reading. 2. It's possible that the last line doesn't end have a line ending, so line[:-1] could be removing some other character. It's safer to use line.rstrip("\n"). > -----Original Message----- > From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com at python.org] On Behalf Of Seymore4Head > Sent: 25 April 2016 20:01 > To: python-list at python.org > Subject: Re: Python path and append > > On Mon, 25 Apr 2016 18:24:02 -0000 (UTC), Rob Gaddi wrote: > >>Seymore4Head wrote: >> >>> On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head >>> wrote: >>> >>> I am going to forget using a directory path. >>> I would like to take the file win.txt and append a space and the * >>> symbol. >>> >>> f = open('win.txt', 'r+') >>> for line in f: >>> f.read(line) >>> f.write(line+" *") >>> >>> This doesn't work. Would someone fix it please? It is for a task I >>> am trying to accomplish just for a home task. >> >>"for line in f:" already means "make the variable line equal to each >>line in f sequentially". f.read is both superfluous and also doesn't >>do that. Leave it out entirely. >> >>The next problem you'll have is that iterating over the lines of the >>file leaves the newline at the end of line, so your * will end up on >>the wrong line. >> >>Do yourself a favor: >>https://docs.python.org/3/tutorial/inputoutput.html >>isn't very long. > > I was reading that. I have read it before. I don't use python enough to even remember the simple stuff. Then when I try to use if for something simple I forget how. > > f = open('wout.txt', 'r+') > for line in f: > line=line.strip() > f.write(line+" *") > f.close() > > Still broke. How about just telling me where I missed? Please? > -- > https://mail.python.org/mailman/listinfo/python-list > This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. > From Seymore4Head at Hotmail.invalid Mon Apr 25 16:15:15 2016 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Mon, 25 Apr 2016 16:15:15 -0400 Subject: Python path and append References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Message-ID: <02ushb9mntvtedeg5c7l33uhapt2j6nivu@4ax.com> Thanks for the tip. Still broke. :( f = open('wout.txt', 'r+') for line in f: if line=="": exit line=line[:-1] line=line+" *" f.write(line) print line f.close() I did notice that it wrote the 3 lines of test file but it didn't append the * after the third entry and it starts printing garbage after that. On Mon, 25 Apr 2016 19:08:56 +0000, Joaquin Alzola wrote: >Strip() = white spaces. >Description >The method strip() returns a copy of the string in which all chars have been stripped from the beginning and the end of the string (default whitespace characters). > >Use to remove return carriage--> line[:-1] > >-----Original Message----- >From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com at python.org] On Behalf Of Seymore4Head >Sent: 25 April 2016 20:01 >To: python-list at python.org >Subject: Re: Python path and append > >On Mon, 25 Apr 2016 18:24:02 -0000 (UTC), Rob Gaddi wrote: > >>Seymore4Head wrote: >> >>> On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head >>> wrote: >>> >>> I am going to forget using a directory path. >>> I would like to take the file win.txt and append a space and the * >>> symbol. >>> >>> f = open('win.txt', 'r+') >>> for line in f: >>> f.read(line) >>> f.write(line+" *") >>> >>> This doesn't work. Would someone fix it please? It is for a task I >>> am trying to accomplish just for a home task. >> >>"for line in f:" already means "make the variable line equal to each >>line in f sequentially". f.read is both superfluous and also doesn't >>do that. Leave it out entirely. >> >>The next problem you'll have is that iterating over the lines of the >>file leaves the newline at the end of line, so your * will end up on >>the wrong line. >> >>Do yourself a favor: >>https://docs.python.org/3/tutorial/inputoutput.html >>isn't very long. > >I was reading that. I have read it before. I don't use python enough to even remember the simple stuff. Then when I try to use if for something simple I forget how. > >f = open('wout.txt', 'r+') >for line in f: > line=line.strip() > f.write(line+" *") >f.close() > >Still broke. How about just telling me where I missed? Please? From random832 at fastmail.com Mon Apr 25 16:28:32 2016 From: random832 at fastmail.com (Random832) Date: Mon, 25 Apr 2016 16:28:32 -0400 Subject: Python path and append In-Reply-To: <02ushb9mntvtedeg5c7l33uhapt2j6nivu@4ax.com> References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> <02ushb9mntvtedeg5c7l33uhapt2j6nivu@4ax.com> Message-ID: <1461616112.2223232.589261113.1AB67247@webmail.messagingengine.com> On Mon, Apr 25, 2016, at 16:15, Seymore4Head wrote: > Thanks for the tip. > > Still broke. :( > > f = open('wout.txt', 'r+') > for line in f: > if line=="": > exit > line=line[:-1] > line=line+" *" > f.write(line) > print line > f.close() Your problem is that after you read the first line, your file "cursor" is positioned after the end of that line. So when you write the modified version of the line, it ends up after that. And then when you write it, the cursor is wherever the end of that is. So if you start with this: AAA BBB CCC You'll end up with this: AAA AAA* [this overwrites "BBB_C" with "AAA*_" if _ is the line break] CC CC* There's no good way around this. You can either read the whole file into memory at once into a list, then rewind (look at the seek function) and write the lines out of the list, or you can write to a *different* file than the one you're reading. From m at funkyhat.org Mon Apr 25 16:31:28 2016 From: m at funkyhat.org (Matt Wheeler) Date: Mon, 25 Apr 2016 20:31:28 +0000 Subject: Question on List processing In-Reply-To: References: Message-ID: On Mon, 25 Apr 2016 15:56 , wrote: > Dear Group, > > I have a list of tuples, as follows, > > list1=[u"('koteeswaram/BHPERSN engaged/NA himself/NA in/NA various/NA > philanthropic/NA activities/NA ','class1')", u"('koteeswaram/BHPERSN is/NA > a/NA very/NA nice/NA person/NA ','class1')", u"('koteeswaram/BHPERSN > came/NA to/NA mumbai/LOC but/NA could/NA not/NA attend/NA the/ARTDEF > board/NA meeting/NA ','class1')", u"('the/ARTDEF people/NA of/NA > the/ARTDEF company ABCOMP did/NA not/NA vote/NA for/NA koteeswaram/LOC > ','class2')", u"('the/ARTDEF director AHT of/NA the/ARTDEF company,/NA > koteeswaram/BHPERSN had/NA been/NA advised/NA to/NA take/NA rest/NA for/NA > a/NA while/NA ','class2')", u"('animesh/BHPERSN chauhan/BHPERSN arrived/NA > by/NA his/PRNM3PAS private/NA aircraft/NA in/NA mumbai/LOC ','class2')", > u"('animesh/BHPERSN chauhan/BHPERSN met/NA the/ARTDEF prime/HPLPERST > minister/AHT of/NA india/LOCC over/NA some/NA issues/NA ','class2')", > u"('animesh/BHPERSN chauhan/BHPERSN is/NA trying/NA to/NA set/NA up/NA a/NA > plant/NA in/NA uk/LOCC ','class3')", u"('animesh/BHPERSN chauh > an/BHPERSN is/NA trying/NA to/NA launch/NA a/NA new/ABCOMP office/AHT > in/NA burdwan/LOC ','class3')", u"('animesh/BHPERSN chauhan/BHPERSN is/NA > trying/NA to/NA work/NA out/NA the/ARTDEF launch/NA of/NA a/NA new/ABCOMP > product/NA in/NA india/LOCC ','class3')"] > What you have is a list of strings, not tuples. > > I want to make it like, > > [('koteeswaram/BHPERSN engaged/NA himself/NA in/NA various/NA > philanthropic/NA activities/NA','class1'), > ('koteeswaram/BHPERSN is/NA a/NA very/NA nice/NA person/NA ','class1'), > ('koteeswaram/BHPERSN came/NA to/NA mumbai/LOC but/NA could/NA not/NA > attend/NA the/ARTDEF board/NA meeting/NA','class1'), ('the/ARTDEF people/NA > of/NA the/ARTDEF company ABCOMP did/NA not/NA vote/NA for/NA > koteeswaram/LOC ','class2'), ('the/ARTDEF director AHT of/NA > the/ARTDEF company,/NA koteeswaram/BHPERSN had/NA been/NA advised/NA to/NA > take/NA rest/NA for/NA a/NA while/NA ','class2'), ('animesh/BHPERSN > chauhan/BHPERSN arrived/NA by/NA his/PRNM3PAS private/NA aircraft/NA in/NA > mumbai/LOC','class2'), ('animesh/BHPERSN chauhan/BHPERSN met/NA the/ARTDEF > prime/HPLPERST minister/AHT of/NA india/LOCC over/NA some/NA > issues/NA','class2'), ('animesh/BHPERSN chauhan/BHPERSN is/NA trying/NA > to/NA set/NA up/NA a/NA plant/NA in/NA uk/LOCC','class3'), > ('animesh/BHPERSN chauhan/BHPERSN is/NA trying/NA to/NA launch/NA a/NA > new/ABCOMP office/AHT in/NA burdwan/LOC','class3'), > ('animesh/BHPERSN chauhan/BHPERSN is/NA trying/NA to/NA work/NA out/NA > the/ARTDEF launch/NA of/NA a/NA new/ABCOMP product/NA in/NA > india/LOCC','class3')] > > I tried to make it as follows, > list2=[] > for i in train_sents: > a1=unicodedata.normalize('NFKD', i).encode('ascii','ignore') > a2=a1.replace('"',"") > list2.append(a2) > and, > > for i in list1: > a3=i[1:-1] > list2.append(a3) > In both of these you seem to be trying to remove the double quote marks from the strings, but they aren't part of the strings in the first place, just delimiters. > > > but not helping. > If any one may kindly suggest how may I approach it? > Check out the documentation for ast.literal_eval > From Seymore4Head at Hotmail.invalid Mon Apr 25 16:43:42 2016 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Mon, 25 Apr 2016 16:43:42 -0400 Subject: Python path and append References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Message-ID: <280thb5v16q1ids78j6rbbcs95957osgja@4ax.com> I am using a test file that is only 3 lines: Punjabi .Mp3 Big Lake (DVD) SWV.avi Blue Balloon.AHC.RH.mkv The program correctly appends an * to the end of the line, but then it goes into a loop printing random looking stuff. f = open('wout.txt', 'r+') for line in f: if line=="": exit line=line[:-1] line=line+" *" f.write(line) print line f.close() On Mon, 25 Apr 2016 20:44:50 +0100, MRAB wrote: >On 2016-04-25 20:08, Joaquin Alzola wrote: >> Strip() = white spaces. >> Description >> The method strip() returns a copy of the string in which all chars have been stripped from the beginning and the end of the string (default whitespace characters). >> >> Use to remove return carriage--> line[:-1] >> >1. In the file it might be a linefeed, or a carriage return, or a >carriage return followed by a linefeed, depending on the operating >system. Python translates it to a linefeed "\n" (or 'newline') on >reading. > >2. It's possible that the last line doesn't end have a line ending, so >line[:-1] could be removing some other character. It's safer to use >line.rstrip("\n"). > >> -----Original Message----- >> From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com at python.org] On Behalf Of Seymore4Head >> Sent: 25 April 2016 20:01 >> To: python-list at python.org >> Subject: Re: Python path and append >> >> On Mon, 25 Apr 2016 18:24:02 -0000 (UTC), Rob Gaddi wrote: >> >>>Seymore4Head wrote: >>> >>>> On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head >>>> wrote: >>>> >>>> I am going to forget using a directory path. >>>> I would like to take the file win.txt and append a space and the * >>>> symbol. >>>> >>>> f = open('win.txt', 'r+') >>>> for line in f: >>>> f.read(line) >>>> f.write(line+" *") >>>> >>>> This doesn't work. Would someone fix it please? It is for a task I >>>> am trying to accomplish just for a home task. >>> >>>"for line in f:" already means "make the variable line equal to each >>>line in f sequentially". f.read is both superfluous and also doesn't >>>do that. Leave it out entirely. >>> >>>The next problem you'll have is that iterating over the lines of the >>>file leaves the newline at the end of line, so your * will end up on >>>the wrong line. >>> >>>Do yourself a favor: >>>https://docs.python.org/3/tutorial/inputoutput.html >>>isn't very long. >> >> I was reading that. I have read it before. I don't use python enough to even remember the simple stuff. Then when I try to use if for something simple I forget how. >> >> f = open('wout.txt', 'r+') >> for line in f: >> line=line.strip() >> f.write(line+" *") >> f.close() >> >> Still broke. How about just telling me where I missed? Please? >> -- >> https://mail.python.org/mailman/listinfo/python-list >> This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. >> From gordon at panix.com Mon Apr 25 17:26:34 2016 From: gordon at panix.com (John Gordon) Date: Mon, 25 Apr 2016 21:26:34 +0000 (UTC) Subject: Python path and append References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Message-ID: In <27nshbp40p1llr231dqm31p754tvurkb8i at 4ax.com> Seymore4Head writes: > On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head > wrote: > I am going to forget using a directory path. > I would like to take the file win.txt and append a space and the * > symbol. > f = open('win.txt', 'r+') > for line in f: > f.read(line) > f.write(line+" *") > This doesn't work. Would someone fix it please? It is for a task I > am trying to accomplish just for a home task. It's much easier to create a new file and then rename it afterwards, instead of rewriting the original file. import os f_in = open('win.txt', 'r') f_out = open('win_new.txt', 'w') for line in f_in.read().splitlines(): f_out.write(line + " *\n") f_in.close() f_out.close() os.rename('win.txt', 'win_old.txt') os.rename('win_new.txt', 'win.txt') -- 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 __peter__ at web.de Mon Apr 25 17:38:10 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 25 Apr 2016 23:38:10 +0200 Subject: Python path and append References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> <02ushb9mntvtedeg5c7l33uhapt2j6nivu@4ax.com> <1461616112.2223232.589261113.1AB67247@webmail.messagingengine.com> Message-ID: Random832 wrote: > On Mon, Apr 25, 2016, at 16:15, Seymore4Head wrote: >> Thanks for the tip. >> >> Still broke. :( >> >> f = open('wout.txt', 'r+') >> for line in f: >> if line=="": >> exit >> line=line[:-1] >> line=line+" *" >> f.write(line) >> print line >> f.close() > > Your problem is that after you read the first line, your file "cursor" > is positioned after the end of that line. So when you write the modified > version of the line, it ends up after that. And then when you write it, > the cursor is wherever the end of that is. > > So if you start with this: > AAA > BBB > CCC > > You'll end up with this: > AAA > AAA* [this overwrites "BBB_C" with "AAA*_" if _ is the line break] > CC > CC* > > There's no good way around this. You can either read the whole file into > memory at once into a list, then rewind (look at the seek function) and > write the lines out of the list, or you can write to a *different* file > than the one you're reading. You can leave the details to python though: $ cat sample.txt alpha beta gamma $ python Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import fileinput >>> for line in fileinput.input("sample.txt", inplace=True): ... print line.rstrip("\n"), "*" ... >>> $ cat sample.txt alpha * beta * gamma * Too much magic for my taste, but the OP might like it. From Seymore4Head at Hotmail.invalid Mon Apr 25 18:04:00 2016 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Mon, 25 Apr 2016 18:04:00 -0400 Subject: Python path and append References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Message-ID: On Mon, 25 Apr 2016 21:26:34 +0000 (UTC), John Gordon wrote: >In <27nshbp40p1llr231dqm31p754tvurkb8i at 4ax.com> Seymore4Head writes: > >> On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head >> wrote: > >> I am going to forget using a directory path. >> I would like to take the file win.txt and append a space and the * >> symbol. > >> f = open('win.txt', 'r+') >> for line in f: >> f.read(line) >> f.write(line+" *") > >> This doesn't work. Would someone fix it please? It is for a task I >> am trying to accomplish just for a home task. > >It's much easier to create a new file and then rename it afterwards, >instead of rewriting the original file. > > import os > > f_in = open('win.txt', 'r') > f_out = open('win_new.txt', 'w') > > for line in f_in.read().splitlines(): > f_out.write(line + " *\n") > > f_in.close() > f_out.close() > > os.rename('win.txt', 'win_old.txt') > os.rename('win_new.txt', 'win.txt') That is 100% spoon fed code and that is what I wanted. Thanks I learned enough python to complete an online course from Dr Chuck but I don't write enough code to remember how except for a simple task that is usually simpler to do manually than to remember how to code. http://www.dr-chuck.com/ Thanks to everyone else too. BTW I was trying to use a line like yours that used an output file that didn't exist and was getting an error. I assume that import os fixes that. From rosuav at gmail.com Mon Apr 25 20:25:46 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Apr 2016 10:25:46 +1000 Subject: Python path and append In-Reply-To: References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Message-ID: On Tue, Apr 26, 2016 at 7:26 AM, John Gordon wrote: > It's much easier to create a new file and then rename it afterwards, > instead of rewriting the original file. And more importantly, it's safer. If anything happens to your process while it's doing its work, you'll have a junk file sitting around, but you won't have lost everything. If you overwrite the existing file, you (often) depend on completely writing out the content you have in memory. ChrisA From steve at pearwood.info Mon Apr 25 21:51:23 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 26 Apr 2016 11:51:23 +1000 Subject: Python path and append References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Message-ID: <571ec99c$0$1607$c3e8da3$5496439d@news.astraweb.com> On Tue, 26 Apr 2016 05:00 am, Seymore4Head wrote: > I was reading that. I have read it before. I don't use python enough > to even remember the simple stuff. Then when I try to use if for > something simple I forget how. It is perfectly fine to forget things that you read weeks or months before. The point is, having forgotten it, you should go back and refresh your memory when you need to. > f = open('wout.txt', 'r+') > for line in f: > line=line.strip() > f.write(line+" *") > f.close() > > Still broke. How about just telling me where I missed? Please? The contents of files don't just magically get moved out of the way when you write to them. There is no "insert mode" for files -- they are always set to "overwrite" mode. (Possible a few very old operating systems on supercomputers from the 1970s or 80s may have supported inserting... I seem to recall that VMS may have allowed that... but don't quote me.) So you can append to the *end* of a file without disrupting the content, but you cannot insert to the middle or beginning of a file without overwriting. The basic way to insert data into a file is: * read the entire file into memory; * insert the new data into the memory; * write the entire file out again. with open("myfile.txt") as f: lines = f.readlines() for i, line in enumerate(lines): lines[i] = line.strip() + " *\n" # space, asterisk, newline with open("myfile.txt", "w") as f: f.writelines(lines) That's good enough for DIY or hobby use. But for professional use, it starts getting *very* complex quickly. What if the power goes off or your computer crashes half-way through writing the file? You've lost all your data. See here for the *start* of a more professional approach: http://code.activestate.com/recipes/579097-safely-and-atomically-write-to-a-file/ -- Steven From steve at pearwood.info Mon Apr 25 21:53:57 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 26 Apr 2016 11:53:57 +1000 Subject: Python path and append References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Message-ID: <571eca35$0$1607$c3e8da3$5496439d@news.astraweb.com> On Tue, 26 Apr 2016 08:04 am, Seymore4Head wrote: > BTW I was trying to use a line like yours that used an output file > that didn't exist and was getting an error. ?I assume that import os > fixes that. Why would you assume that? "Doctor, I have a problem with my arm, but I won't tell you what. I assume that if I take cough drops that will fix it." -- Steven From dan at tombstonezero.net Mon Apr 25 21:59:51 2016 From: dan at tombstonezero.net (Dan Sommers) Date: Tue, 26 Apr 2016 01:59:51 -0000 (UTC) Subject: Python path and append References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> <571ec99c$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 26 Apr 2016 11:51:23 +1000, Steven D'Aprano wrote: > ... (Possible a few very old operating systems on supercomputers from > the 1970s or 80s may have supported inserting... I seem to recall that > VMS may have allowed that... but don't quote me.) Some [non-supercomputer] OSes/filesystems/languages support(ed) the notion of fixed-length records, where a file acted as if it were an array of records. You could, e.g., replace Record Number 3 without disturbing Record Number 2 or Record Number 4. In the systems I remember like that, the records were simply ad hoc collections of whatever you wrote, not unlike the arguments to print, and it was up to your application to read and write the same structure. The limitation, of course, was that you had to declare the length up front, and that you ended up with wasted space somewhere if a lot of your records were "short." From pannis2013 at gmail.com Tue Apr 26 01:37:23 2016 From: pannis2013 at gmail.com (pannis2013 at gmail.com) Date: Mon, 25 Apr 2016 22:37:23 -0700 (PDT) Subject: Python email issues Message-ID: Hi, I am trying send email through smtplib import smtplib import os from libs import send_mail_status send_mail_status('test', False, 'ABCD', os.getcwd()) libs.py has a function as below: def send_status_mail(name, success, id, dir): #SERVER = "localhost" FROM = "localhost" TO = ["abc at nus.edu.sg"] SUBJECT = "test" body = "test" message = """\ From: %s To: %s Subject: %s %s """ % (FROM, ", ".join(TO), SUBJECT, body) But I receive an email as below: All the contents are in the email body: From: localhost To: abc at nus.edu.sg Subject: test test Why all the ocntents are written in the body where as email body should have just a string "test" Kindly clarify. Thanks. From santanu01 at gmail.com Tue Apr 26 02:21:23 2016 From: santanu01 at gmail.com (San) Date: Mon, 25 Apr 2016 23:21:23 -0700 (PDT) Subject: def __init__(self): Message-ID: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> Hi All, Pls let me why " def __init__(self): " declaration required, what's the use of this one.Pls explain me in details. Thanks in advance. From greg.ewing at canterbury.ac.nz Tue Apr 26 02:23:20 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 26 Apr 2016 18:23:20 +1200 Subject: Python path and append In-Reply-To: <571ec99c$0$1607$c3e8da3$5496439d@news.astraweb.com> References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> <571ec99c$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > (Possible a few very old operating systems on > supercomputers from the 1970s or 80s may have supported inserting... I seem > to recall that VMS may have allowed that... but don't quote me.) I wouldn't be surprised if VMS provided some sort of indexed random-access file structure that supported inserting records. OSes of that era tended to be big on things like that, since they were all about Serious Data Processing. But it probably wouldn't have let you insert data into the middle of a sequential file without explicitly moving everything that came after it. -- Greg From ben+python at benfinney.id.au Tue Apr 26 02:31:22 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 26 Apr 2016 16:31:22 +1000 Subject: def __init__(self): References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> Message-ID: <85inz4nao5.fsf@benfinney.id.au> San writes: > Pls let me why [?] declaration required, what's the use of this one. Welcome to Python! Congratulations on beginning to learn this language. > Pls explain me in details. You should participate in our collaborative tutoring forum, ?tutor? which is specially focussed on helping Python beginners. -- \ ?Giving every man a vote has no more made men wise and free | `\ than Christianity has made them good.? ?Henry L. Mencken | _o__) | Ben Finney From gherron at digipen.edu Tue Apr 26 03:06:09 2016 From: gherron at digipen.edu (Gary Herron) Date: Tue, 26 Apr 2016 00:06:09 -0700 Subject: def __init__(self): In-Reply-To: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> Message-ID: <571F1361.3010402@digipen.edu> On 04/25/2016 11:21 PM, San wrote: > Hi All, > > Pls let me why > " > def __init__(self): > > " > declaration required, what's the use of this one.Pls explain me in details. > > Thanks in advance. If you understand object-oriented-programming, then this will make sense: The __init__ method is the constructor for instances of a class. It is not required, but the situations in which a constructor is not needed are few and unusual. If you don't know object-oriented-programming, then I'd suggest you put that high on your list of things to learn. It's a valuable tool. Gary Herron -- Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology (425) 895-4418 From ben+python at benfinney.id.au Tue Apr 26 03:34:39 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 26 Apr 2016 17:34:39 +1000 Subject: def __init__(self): References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> Message-ID: <85eg9sn7qo.fsf@benfinney.id.au> Gary Herron writes: > The __init__ method is the constructor for instances of a class. It > is not required, but the situations in which a constructor is not > needed are few and unusual. That's needlessly confusing: ?__init__? is not a constructor because it does not construct the instance. The ?__new__? method is the constructor for a class (and returns the new instance). The ?__init__? method requests the already-constructed instance to initialise itself (and returns None). -- \ ?I still have my Christmas Tree. I looked at it today. Sure | `\ enough, I couldn't see any forests.? ?Steven Wright | _o__) | Ben Finney From marko at pacujo.net Tue Apr 26 04:25:39 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 26 Apr 2016 11:25:39 +0300 Subject: def __init__(self): References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> Message-ID: <87lh40pyik.fsf@elektro.pacujo.net> Ben Finney : > Gary Herron writes: > >> The __init__ method is the constructor for instances of a class. >> It is not required, but the situations in which a constructor is >> not needed are few and unusual. > > That's needlessly confusing: ?__init__? is not a constructor because > it does not construct the instance. The ?__new__? method is the > constructor for a class (and returns the new instance). I have never ever had a temptation to specify a __new__ method. I can't imagine a *beneficial* case of overriding it. > The ?__init__? method requests the already-constructed instance to > initialise itself (and returns None). It is a serious practical problem that an object can't guarantee that its __init__ has been called. Check out some of the stdlib source code for example: ======================================================================== class ThreadPoolExecutor(_base.Executor): def __init__(self, max_workers): """Initializes a new ThreadPoolExecutor instance. Args: max_workers: The maximum number of threads that can be used to execute the given calls. """ self._max_workers = max_workers self._work_queue = queue.Queue() self._threads = set() self._shutdown = False self._shutdown_lock = threading.Lock() ======================================================================== Notice how _base.Executor.__init__(self) does not get called. It can only work if _base.Executor does not specify an __init__. That's an assumption you really couldn't make with a clear conscience even if you were the author and maintainer of both modules (concurrent.futures.thread and concurrent.futures._base). Marko From oscar.j.benjamin at gmail.com Tue Apr 26 05:54:49 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 26 Apr 2016 10:54:49 +0100 Subject: Optimizing Memory Allocation in a Simple, but Long Function In-Reply-To: References: Message-ID: On 25 April 2016 at 15:35, Derek Klinge wrote: > > Although I see the value of relative error, I am just as interested in > absolute error (though admittedly they are directly related values). I was referring to relative error because the relative error is the same at each step making the calculation of the global error easier. > Are there modules or libraries I can/should use to minimize rounding error > and use very large values of N and get an accurate answer? from decimal import Decimal, localcontext def e(prec): with localcontext() as ctx: ctx.prec = 2*prec + 1 N = Decimal(10)**(prec) eapprox = (1 + 1/N)**N ctx.prec = prec return +eapprox print(e(50)) Alternatively you can just use Decimal(1).exp(). > How does the math > module calculate the vale of e? https://hg.python.org/cpython/file/tip/Include/pymath.h#l54 -- Oscar From harirammanohar at gmail.com Tue Apr 26 06:31:25 2016 From: harirammanohar at gmail.com (harirammanohar at gmail.com) Date: Tue, 26 Apr 2016 03:31:25 -0700 (PDT) Subject: delete from pattern to pattern if it contains match In-Reply-To: References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> <95f0d9a7-69ff-43bf-a856-8fa62fe8a985@googlegroups.com> <15f2e9ff-7624-4886-bcd9-c3e9d21db328@googlegroups.com> Message-ID: <32834ac1-cae6-4783-a3a9-f8a4ba5ad77d@googlegroups.com> On Monday, April 25, 2016 at 6:04:24 PM UTC+5:30, Peter Otten wrote: > harirammanohar at gmail.com wrote: > > >> tree.write('output.xml') > > > > yup its working well if i include register namespace, else i am getting > > ns:0 in every line of output.xml. > > > > But its removing top line > > > > The write() method allows you to specify an encoding and/or require an xml > declaration: > > https://docs.python.org/dev/library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree.write Hi Peter, Thanks for reminding about basic write method syntax...its working :) graph /graph 30 Here is the change: tree.write('output.xml',encoding="ISO-8859-1",xml_declaration=True) Thank you all especially jussi and pete.. From python.list at tim.thechases.com Tue Apr 26 06:41:14 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 26 Apr 2016 05:41:14 -0500 Subject: Python email issues In-Reply-To: References: Message-ID: <20160426054114.10a9c963@bigbox.christie.dr> On 2016-04-25 22:37, pannis2013 at gmail.com wrote: > I am trying send email through smtplib > body = "test" > message = """\ > From: %s > To: %s > Subject: %s > %s > """ % (FROM, ", ".join(TO), SUBJECT, body) Doesn't the email RFC require a blank line between the headers and the body of the message? I'd start by using Python's built-in tools for creating message bodies to make sure that the message is properly composed. -tkc From a24061 at ducksburg.com Tue Apr 26 09:30:14 2016 From: a24061 at ducksburg.com (Adam Funk) Date: Tue, 26 Apr 2016 14:30:14 +0100 Subject: Why does pathlib not have is_readable() & things like that? Message-ID: <6474vcx0q6.ln2@news.ducksburg.com> I recently discovered pathlib in the Python 3 standard library, & find it very useful, but I'm a bit surprised that it doesn't offer things like is_readable() and is_writable. Is there a good reason for that? I've been improvising with things like this: import pathlib, os path = pathlib.Path('some/directory') writable = os.access(str(path), os.W_OK | os.X_OK) Is that the best way to do it? -- Unix is a user-friendly operating system. It's just very choosy about its friends. From random832 at fastmail.com Tue Apr 26 09:49:22 2016 From: random832 at fastmail.com (Random832) Date: Tue, 26 Apr 2016 09:49:22 -0400 Subject: def __init__(self): In-Reply-To: <85eg9sn7qo.fsf@benfinney.id.au> References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> Message-ID: <1461678562.2463908.590020129.6D85452C@webmail.messagingengine.com> On Tue, Apr 26, 2016, at 03:34, Ben Finney wrote: > That's needlessly confusing: ?__init__? is not a constructor because it > does not construct the instance. The ?__new__? method is the constructor > for a class (and returns the new instance). the __new__ method is the *allocator*. "constructor" is used in many languages to name a method that initializes an object once it already "exists". Saying you can't call it that in Python is needlessly confusing. From random832 at fastmail.com Tue Apr 26 09:57:24 2016 From: random832 at fastmail.com (Random832) Date: Tue, 26 Apr 2016 09:57:24 -0400 Subject: Why does pathlib not have is_readable() & things like that? In-Reply-To: <6474vcx0q6.ln2@news.ducksburg.com> References: <6474vcx0q6.ln2@news.ducksburg.com> Message-ID: <1461679044.2467938.590028273.4DEA02AA@webmail.messagingengine.com> On Tue, Apr 26, 2016, at 09:30, Adam Funk wrote: > I recently discovered pathlib in the Python 3 standard library, & find > it very useful, but I'm a bit surprised that it doesn't offer things > like is_readable() and is_writable. Is there a good reason for that? Well, one reason would be EAFP. Just try to open the file and see if it gives you a PermissionError. From donald.ng at gmail.com Tue Apr 26 10:18:06 2016 From: donald.ng at gmail.com (+dime+) Date: Tue, 26 Apr 2016 07:18:06 -0700 (PDT) Subject: how to create a dictionary from csv file? Message-ID: <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> I am learning python. if I have a csv file, like this banana,4.0 apple,3.5 orange,3.0 Can anyone show me how to read the csv file line by line and then create a dictionary to contain these keys and values? Regards, +dime+ From gherron at digipen.edu Tue Apr 26 10:25:28 2016 From: gherron at digipen.edu (Gary Herron) Date: Tue, 26 Apr 2016 07:25:28 -0700 Subject: def __init__(self): In-Reply-To: <1461678562.2463908.590020129.6D85452C@webmail.messagingengine.com> References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> <1461678562.2463908.590020129.6D85452C@webmail.messagingengine.com> Message-ID: <571F7A58.1000505@digipen.edu> On 04/26/2016 06:49 AM, Random832 wrote: > On Tue, Apr 26, 2016, at 03:34, Ben Finney wrote: >> That's needlessly confusing: ?__init__? is not a constructor because it >> does not construct the instance. The ?__new__? method is the constructor >> for a class (and returns the new instance). > the __new__ method is the *allocator*. "constructor" is used in many > languages to name a method that initializes an object once it already > "exists". Saying you can't call it that in Python is needlessly > confusing. Agreed. For a newbie asking about __init__, I'll stick with my original answer (that it's the constructor), and suggest ignoring the overly pedantic (and confusing) response to the contrary. -- Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology (425) 895-4418 From python.list at tim.thechases.com Tue Apr 26 10:36:59 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 26 Apr 2016 09:36:59 -0500 Subject: how to create a dictionary from csv file? In-Reply-To: <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> References: <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> Message-ID: <20160426093659.5adc41c6@bigbox.christie.dr> On 2016-04-26 07:18, +dime+ wrote: > I am learning python. > > if I have a csv file, like this > banana,4.0 > apple,3.5 > orange,3.0 > > Can anyone show me how to read the csv file line by line and then > create a dictionary to contain these keys and values? import csv with open('data.csv') as f: data = dict(csv.reader(f)) Hard to get much more straight-forward. -tkc From __peter__ at web.de Tue Apr 26 10:40:37 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 26 Apr 2016 16:40:37 +0200 Subject: how to create a dictionary from csv file? References: <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> Message-ID: +dime+ wrote: > I am learning python. > > if I have a csv file, like this > banana,4.0 > apple,3.5 > orange,3.0 > > Can anyone show me how to read the csv file line by line and then create a > dictionary to contain these keys and values? Below is a spoiler, but learning Python is more fun and you'll see success sooner when you try to come up with a solution yourself, present it here (or on the tutor mailing list) and let us fill the gaps or suggest improvements. >>> import csv >>> with open("fruit.csv") as f: ... lookup = {k: float(v) for k, v in csv.reader(f)} ... >>> lookup {'orange': 3.0, 'apple': 3.5, 'banana': 4.0} >>> 2*lookup["banana"] + 3*lookup["orange"] 17.0 From helenadm89 at gmail.com Tue Apr 26 10:47:46 2016 From: helenadm89 at gmail.com (helena@rinocloud.com) Date: Tue, 26 Apr 2016 07:47:46 -0700 (PDT) Subject: new dataset management for python Message-ID: <0431029d-5b23-47c1-99fd-5c6fd8e2edcf@googlegroups.com> Hey guys, We just launched rinocloud.com, it aims to make it easy to manage datasets in python. I hope some of you could take a look at it and give us some feedback. We made the library to create a better way to organize datasets and parameters from simulations and experiments Instead of just saving files, and not recording parameters, Rinocloud is an easy way to attach essentially a dict to a file object. Meaning you can save all you parameters with your data. With rinocloud-python you can organize your datasets locally, and if you choose too, you can upload them to Rinocloud. If you upload them you then get a full query system. Soon we are implementing notebooks and collaboration features -so if your working in a team, you'll be able to discuss your results inside one central storage system. Please, let me know if you have suggestions of questions, you can get me at helena at rinocloud.com Cheers, Helena https://rinocloud.com/ From walters.justin01 at gmail.com Tue Apr 26 10:51:28 2016 From: walters.justin01 at gmail.com (justin walters) Date: Tue, 26 Apr 2016 07:51:28 -0700 Subject: how to create a dictionary from csv file? In-Reply-To: <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> References: <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> Message-ID: On Tue, Apr 26, 2016 at 7:18 AM, +dime+ wrote: > I am learning python. > > if I have a csv file, like this > banana,4.0 > apple,3.5 > orange,3.0 > > Can anyone show me how to read the csv file line by line and then create a > dictionary to contain these keys and values? > > > Regards, > +dime+ > -- > https://mail.python.org/mailman/listinfo/python-list > It's best if you look up how to do this in the docs yourself. An even better way would be to think about the steps necessary to do this and then writing them down in pseudo-code. After that you can look up the functions/tools that will help you accomplish this task. One of the most important skills a programmer can have is called 'algorithmic thinking'. That is, essentially, the ability to break a problem down into smaller pieces in order to eventually solve it. So, think about this: What steps do you need to take to turn this csv file into a Python dictionary object? Imagine that you were going to do this by hand. How would you do it? From hemla21 at gmail.com Tue Apr 26 11:33:22 2016 From: hemla21 at gmail.com (Heli) Date: Tue, 26 Apr 2016 08:33:22 -0700 (PDT) Subject: installing scipy Message-ID: Hi all, I have a python34 installed on a windows-64bit machine. I am using Eclipse pydev editor. I need to used griddata from scipy.interpolate. I have installed scipy using by downloading the followng wheel file: scipy-0.17.0-cp34-none-win_amd64 and isntalling using pip install. The install is successful, but It seems like scipy is not installed correctly and I get the following error when trying to import and use scipy modules: C:\Python34\Scripts>python -c "import scipy.interpolate" Traceback (most recent call last): File "", line 1, in File "C:\Python34\lib\site-packages\scipy\interpolate\__init__.py", line 158, in from .interpolate import * File "C:\Python34\lib\site-packages\scipy\interpolate\interpolate.py", line 11, in import scipy.linalg File "C:\Python34\lib\site-packages\scipy\linalg\__init__.py", line 174, in from .misc import * File "C:\Python34\lib\site-packages\scipy\linalg\misc.py", line 5, in from .blas import get_blas_funcs File "C:\Python34\lib\site-packages\scipy\linalg\blas.py", line 155, in from scipy.linalg import _fblas ImportError: DLL load failed How can I fix this problem? Thanks, From subhabangalore at gmail.com Tue Apr 26 11:38:27 2016 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Tue, 26 Apr 2016 08:38:27 -0700 (PDT) Subject: Question on List processing In-Reply-To: <571e47aa$0$1588$c3e8da3$5496439d@news.astraweb.com> References: <571e47aa$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: <594d024b-7880-4d45-911e-342ec90ac54c@googlegroups.com> On Monday, April 25, 2016 at 10:07:13 PM UTC+5:30, Steven D'Aprano wrote: > On Tue, 26 Apr 2016 12:56 am, wrote: > > > Dear Group, > > > > I have a list of tuples, as follows, > > > > list1=[u"('koteeswaram/BHPERSN engaged/NA himself/NA in/NA various/NA > [... 17 more lines of data ...] > > Hi Subhabrata, and thanks for the question. > > Please remember that we are offering help for free, in our own time. If you > want help from us, you should help us to help you. > > It is very unlikely that many people will spend the time to study your data > in close enough detail to understand your requirements. Please give a > *simplified* example. Instead of 17 lines of repetitive data, use a "toy" > example that matches the format but without all the complicated details. > And format it so that it is easy to read: > > input = [u"('a/b/ ','A')", > u"('z/x/ ','B')", > u"('b/d/ ','C')", > ] > > output = ???? > > > > > I tried to make it as follows, > [...] > > but not helping. > > What do you mean, "not helping"? What happens when you try? > > Please show a *simple* example, with no more than four or five lines of > *short, easy to read* text. > > Remember, we are giving you advice and consulting for free. We are not paid > to do this. If your questions are too difficult, boring, tedious, or > unpleasant, we will just ignore them, so please help us to help you by > simplifying them as much as possible. > > Thank you. > > > > > -- > Steven Dear Steven, Thank you for your kind suggestion. I will keep it in mind. I am trying to send you a revised example. list1=[u"('koteeswaram/BHPERSN engaged/NA ','class1')", u"('koteeswaram/BHPERSN is/NA ','class1')"] [('koteeswaram/BHPERSN engaged/NA ','class1'), ('koteeswaram/BHPERSN is/NA ','class1')] I tried to make it as follows, list2=[] for i in list1: a1=unicodedata.normalize('NFKD', i).encode('ascii','ignore') a2=a1.replace('"',"") list2.append(a2) and, for i in list1: a3=i[1:-1] list2.append(a3) but I am not getting desired output. If any one may kindly suggest how may I approach it? Regards, Subhabrata From subhabangalore at gmail.com Tue Apr 26 11:44:24 2016 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Tue, 26 Apr 2016 08:44:24 -0700 (PDT) Subject: Question on List processing In-Reply-To: <571e47aa$0$1588$c3e8da3$5496439d@news.astraweb.com> References: <571e47aa$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: <513f320f-c4ca-406b-b203-b21fdbf0c1fc@googlegroups.com> On Monday, April 25, 2016 at 10:07:13 PM UTC+5:30, Steven D'Aprano wrote: > > > > Dear Group, > > > > I have a list of tuples, as follows, > > > > list1=[u"('koteeswaram/BHPERSN engaged/NA himself/NA in/NA various/NA > [... 17 more lines of data ...] > > Hi Subhabrata, and thanks for the question. > > Please remember that we are offering help for free, in our own time. If you > want help from us, you should help us to help you. > > It is very unlikely that many people will spend the time to study your data > in close enough detail to understand your requirements. Please give a > *simplified* example. Instead of 17 lines of repetitive data, use a "toy" > example that matches the format but without all the complicated details. > And format it so that it is easy to read: > > input = [u"('a/b/ ','A')", > u"('z/x/ ','B')", > u"('b/d/ ','C')", > ] > > output = ???? > > > > > I tried to make it as follows, > [...] > > but not helping. > > What do you mean, "not helping"? What happens when you try? > > Please show a *simple* example, with no more than four or five lines of > *short, easy to read* text. > > Remember, we are giving you advice and consulting for free. We are not paid > to do this. If your questions are too difficult, boring, tedious, or > unpleasant, we will just ignore them, so please help us to help you by > simplifying them as much as possible. > > Thank you. > > > > > -- > Steven Dear Steven, Thank you for your kind suggestion. I am trying to send you a revised example. I have a list as, list1=[u"('koteeswaram/BHPERSN engaged/NA ','class1')", u"('koteeswaram/BHPERSN is/NA ','class1')"] I like to convert it as, list1=[('koteeswaram/BHPERSN engaged/NA ','class1'), ('koteeswaram/BHPERSN is/NA ','class1')] I tried to make it as follows, list2=[] for i in list1: a1=unicodedata.normalize('NFKD', i).encode('ascii','ignore') a2=a1.replace('"',"") list2.append(a2) and, for i in list1: a3=i[1:-1] list2.append(a3) but I am not getting desired output. If any one may kindly suggest how may I approach it? Regards, Subhabrata From steve at pearwood.info Tue Apr 26 11:46:26 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 27 Apr 2016 01:46:26 +1000 Subject: Why does pathlib not have is_readable() & things like that? References: <6474vcx0q6.ln2@news.ducksburg.com> Message-ID: <571f8d53$0$1608$c3e8da3$5496439d@news.astraweb.com> On Tue, 26 Apr 2016 11:30 pm, Adam Funk wrote: > I recently discovered pathlib in the Python 3 standard library, & find > it very useful, but I'm a bit surprised that it doesn't offer things > like is_readable() and is_writable. Is there a good reason for that? Maybe nobody thought of it. Why don't you propose a feature request on the bug tracker? > I've been improvising with things like this: > > import pathlib, os > > path = pathlib.Path('some/directory') > writable = os.access(str(path), os.W_OK | os.X_OK) > > Is that the best way to do it? No. All you have learned is that the directory is writable *now*. In a millisecond, or a minute, when you actually go to write to it, it may no longer be writable -- it may not even exist. There is a whole class of serious security vulnerabilities and bugs caused by the difference between the time you check something and the time you actually use it. "Time of check to time of use" bugs can be best avoided by not checking ahead of time whether the directory is writable, but just *attempting to write to it*, and catching the error if you can't. -- Steven From random832 at fastmail.com Tue Apr 26 11:49:28 2016 From: random832 at fastmail.com (Random832) Date: Tue, 26 Apr 2016 11:49:28 -0400 Subject: Question on List processing In-Reply-To: <594d024b-7880-4d45-911e-342ec90ac54c@googlegroups.com> References: <571e47aa$0$1588$c3e8da3$5496439d@news.astraweb.com> <594d024b-7880-4d45-911e-342ec90ac54c@googlegroups.com> Message-ID: <1461685768.2496584.590158745.357656B9@webmail.messagingengine.com> On Tue, Apr 26, 2016, at 11:38, subhabangalore at gmail.com wrote: > I am trying to send you a revised example. > list1=[u"('koteeswaram/BHPERSN engaged/NA ','class1')", > u"('koteeswaram/BHPERSN is/NA ','class1')"] > > [('koteeswaram/BHPERSN engaged/NA ','class1'), > ('koteeswaram/BHPERSN is/NA ','class1')] > > I tried to make it as follows, > list2=[] > for i in list1: > a1=unicodedata.normalize('NFKD', i).encode('ascii','ignore') > a2=a1.replace('"',"") > list2.append(a2) I think you're still a bit confused. The values don't actually contain '"' (or 'u'), that's just an indicator that they're strings. You can't turn a string into something else just by removing the quotes. Look at the ast.literal_eval function as others have recommended. From peakgraphicz at gmail.com Tue Apr 26 12:01:23 2016 From: peakgraphicz at gmail.com (peakgraphicz at gmail.com) Date: Tue, 26 Apr 2016 09:01:23 -0700 (PDT) Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) Message-ID: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> I am wondering how to make my code function so it does not allow any of the same values to be entered into a column in my CSV file created through python. So I need to read into the CSV file and check if any names have already been entered. If they have, the user must not be allowed to enter this value. Thanks in advance! From Joaquin.Alzola at lebara.com Tue Apr 26 12:07:19 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Tue, 26 Apr 2016 16:07:19 +0000 Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> Message-ID: import csv Use dictionary {key:value} -----Original Message----- From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com at python.org] On Behalf Of peakgraphicz at gmail.com Sent: 26 April 2016 17:01 To: python-list at python.org Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) I am wondering how to make my code function so it does not allow any of the same values to be entered into a column in my CSV file created through python. So I need to read into the CSV file and check if any names have already been entered. If they have, the user must not be allowed to enter this value. Thanks in advance! -- https://mail.python.org/mailman/listinfo/python-list This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. From joel.goldstick at gmail.com Tue Apr 26 12:08:47 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 26 Apr 2016 12:08:47 -0400 Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> Message-ID: On Tue, Apr 26, 2016 at 12:01 PM, wrote: > I am wondering how to make my code function so it does not allow any of the same values to be entered into a column in my CSV file created through python. So I need to read into the CSV file and check if any names have already been entered. If they have, the user must not be allowed to enter this value. > > Thanks in advance! > -- > https://mail.python.org/mailman/listinfo/python-list Show your code and a few lines of your file with useful data. Show the result you want -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From steve at pearwood.info Tue Apr 26 12:12:16 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 27 Apr 2016 02:12:16 +1000 Subject: def __init__(self): References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> <87lh40pyik.fsf@elektro.pacujo.net> Message-ID: <571f9362$0$1602$c3e8da3$5496439d@news.astraweb.com> On Tue, 26 Apr 2016 06:25 pm, Marko Rauhamaa wrote: > Ben Finney : > >> Gary Herron writes: >> >>> The __init__ method is the constructor for instances of a class. >>> It is not required, but the situations in which a constructor is >>> not needed are few and unusual. >> >> That's needlessly confusing: ?__init__? is not a constructor because >> it does not construct the instance. The ?__new__? method is the >> constructor for a class (and returns the new instance). > > I have never ever had a temptation to specify a __new__ method. I can't > imagine a *beneficial* case of overriding it. I'm afraid that's a failure of your imagination then. The obvious reason for overriding __new__ is to construct an immutable instance. You have to override __new__, because by the time it returns the instance is immutable and you can no longer initialise it. >> The ?__init__? method requests the already-constructed instance to >> initialise itself (and returns None). > > It is a serious practical problem that an object can't guarantee that > its __init__ has been called. No object can guarantee that any method is called. Python doesn't make an exception for __new__ or __init__. I'm not sure why you would want it to. > Check out some of the stdlib source code for example: > > ======================================================================== > class ThreadPoolExecutor(_base.Executor): > def __init__(self, max_workers): > """Initializes a new ThreadPoolExecutor instance. > > Args: > max_workers: The maximum number of threads that can be used to > execute the given calls. > """ > self._max_workers = max_workers > self._work_queue = queue.Queue() > self._threads = set() > self._shutdown = False > self._shutdown_lock = threading.Lock() > ======================================================================== > > Notice how _base.Executor.__init__(self) does not get called. What makes you think it needs to be called? > It can only work if _base.Executor does not specify an __init__. That's not the only way. For example, if the __init__ doesn't nothing, just like object.__init__. You can actually pass anything you like to object.__init__, and nothing happens: object.__init__([]) -- Steven From ian.g.kelly at gmail.com Tue Apr 26 12:13:38 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 26 Apr 2016 10:13:38 -0600 Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> Message-ID: On Tue, Apr 26, 2016 at 10:01 AM, wrote: > I am wondering how to make my code function so it does not allow any of the same values to be entered into a column in my CSV file created through python. So I need to read into the CSV file and check if any names have already been entered. If they have, the user must not be allowed to enter this value. Assuming the file is reasonably small enough to fit into memory, create a set and populate it with the values in the column. When the user enters a new value, check whether it's already in the set. From David.Aldrich at EMEA.NEC.COM Tue Apr 26 12:20:04 2016 From: David.Aldrich at EMEA.NEC.COM (David Aldrich) Date: Tue, 26 Apr 2016 16:20:04 +0000 Subject: How to read from serial port? Message-ID: <41302A7145AC054FA7A96CFD03835A0A0BAC66F9@EX10MBX02.EU.NEC.COM> Hi I have written a very simple program to read and print data from the serial port using pyserial: #!/usr/bin/python3 import serial ser=serial.Serial('COM1',115200) while True: out = ser.read() print('Receiving...'+out) When I run it and send data for it to read I get: C:\SVNProj\Raggio\trunk\hostconsole\gui\prototypes\serial_test>py serial_read.py Traceback (most recent call last): File "serial_read.py", line 9, in print('Receiving...'+out) TypeError: Can't convert 'bytes' object to str implicitly I am using Python 3.5. How would I fix this error please? Best regards David From random832 at fastmail.com Tue Apr 26 12:26:07 2016 From: random832 at fastmail.com (Random832) Date: Tue, 26 Apr 2016 12:26:07 -0400 Subject: def __init__(self): In-Reply-To: <571f9362$0$1602$c3e8da3$5496439d@news.astraweb.com> References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> <87lh40pyik.fsf@elektro.pacujo.net> <571f9362$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1461687967.2507874.590200129.102244C8@webmail.messagingengine.com> On Tue, Apr 26, 2016, at 12:12, Steven D'Aprano wrote: > The obvious reason for overriding __new__ is to construct an immutable > instance. You have to override __new__, because by the time it returns > the > instance is immutable and you can no longer initialise it. Other than by subclassing an existing immutable type written in C, is it actually possible to define a truly-immutable (rather than contract-immutable) class in python? (Of course, subclassing immutable C types is the more obvious answer to when you have to override __new__). From steve at pearwood.info Tue Apr 26 12:29:33 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 27 Apr 2016 02:29:33 +1000 Subject: Question on List processing References: <571e47aa$0$1588$c3e8da3$5496439d@news.astraweb.com> <594d024b-7880-4d45-911e-342ec90ac54c@googlegroups.com> Message-ID: <571f976e$0$1619$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Apr 2016 01:38 am, subhabangalore at gmail.com wrote: > I am trying to send you a revised example. > list1=[u"('koteeswaram/BHPERSN engaged/NA ','class1')", > u"('koteeswaram/BHPERSN is/NA ','class1')"] Please don't use generic names that mean nothing like "list1". We can see it is a list, but what is it for? Use a name that describes what the purpose of the list is. Even "input" and "output" are better names. > [('koteeswaram/BHPERSN engaged/NA ','class1'), > ('koteeswaram/BHPERSN is/NA ','class1')] What is this? The output? Don't make us guess what things are. My *guess* is that you have a list of Unicode strings that look like this: u"('aaa/TAG bbb/TAG ','class1')" and you want to do six things: - normalise the string; - convert the Unicode string to ASCII, ignoring anything that isn't ASCII; - delete the parentheses in the string; - delete the leading and trailing single quotes; - split the string on the comma; - combine them into a tuple. So let's make some functions: # Untested def remove_parentheses(string): if string.startswith("(") and string.endswith(")"): string = string[1:-1] return string def remove_single_quotes(string): if string.startswith("'") and string.endswith("'"): string = string[1:-1] return string def convert(string): if not isinstance(string, unicode): raise TypeError("expected unicode, but got %s" % type(string).__name__) string = unicodedata.normalize('NFKD', string) string = string.encode('ascii','ignore') string = remove_parentheses(string) first_part, second_part = string.split(",") first_part = remove_single_quotes(first_part) second_part = remove_single_quotes(second_part) return (first_part, second_part) input = [ ... ] # your input strings output = [] for string in input: output.append(convert(string)) -- Steven From steve at pearwood.info Tue Apr 26 12:32:53 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 27 Apr 2016 02:32:53 +1000 Subject: def __init__(self): References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> <87lh40pyik.fsf@elektro.pacujo.net> <571f9362$0$1602$c3e8da3$5496439d@news.astraweb.com> <1461687967.2507874.590200129.102244C8@webmail.messagingengine.com> Message-ID: <571f9836$0$1619$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Apr 2016 02:26 am, Random832 wrote: > On Tue, Apr 26, 2016, at 12:12, Steven D'Aprano wrote: >> The obvious reason for overriding __new__ is to construct an immutable >> instance. You have to override __new__, because by the time it returns >> the >> instance is immutable and you can no longer initialise it. > > Other than by subclassing an existing immutable type written in C, is it > actually possible to define a truly-immutable (rather than > contract-immutable) class in python? No. Subclassing immutable built-ins is the most obvious and simple (and probably common) way to get an immutable class. Actually immutable, short of doing wicked things with ctypes. > (Of course, subclassing immutable C types is the more obvious answer to > when you have to override __new__). Indeed. -- Steven From marko at pacujo.net Tue Apr 26 12:38:39 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 26 Apr 2016 19:38:39 +0300 Subject: def __init__(self): References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> <87lh40pyik.fsf@elektro.pacujo.net> <571f9362$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87inz4uxyo.fsf@elektro.pacujo.net> Steven D'Aprano : > On Tue, 26 Apr 2016 06:25 pm, Marko Rauhamaa wrote: >> Check out some of the stdlib source code for example: >> >> ======================================================================== >> class ThreadPoolExecutor(_base.Executor): >> def __init__(self, max_workers): >> """Initializes a new ThreadPoolExecutor instance. >> >> Args: >> max_workers: The maximum number of threads that can be used to >> execute the given calls. >> """ >> self._max_workers = max_workers >> self._work_queue = queue.Queue() >> self._threads = set() >> self._shutdown = False >> self._shutdown_lock = threading.Lock() >> ======================================================================== >> >> Notice how _base.Executor.__init__(self) does not get called. > > What makes you think it needs to be called? I would think that's somewhat of an axiom. Whenever I derive from a class, I consider it mandatory to delegate to its __init__ if my class specifies an __init__ itself. Otherwise, the underlying class must make a point to emphasize in its API documentation that __init__ is not needed. And the underlying class would be foolish to make such a contract because that would tie its hands in case the class needs refactoring in the future. Are you saying something else? See also : If a base class has an __init__() method, the derived class?s __init__() method, if any, must explicitly call it to ensure proper initialization of the base class part of the instance I'm saying the derived class *must not* make any conclusions on the presence or absence of __init__ in the base class because that would be a gross violation of encapsulation. Marko From ckaynor at zindagigames.com Tue Apr 26 12:59:39 2016 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 26 Apr 2016 09:59:39 -0700 Subject: def __init__(self): In-Reply-To: <571f9836$0$1619$c3e8da3$5496439d@news.astraweb.com> References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> <87lh40pyik.fsf@elektro.pacujo.net> <571f9362$0$1602$c3e8da3$5496439d@news.astraweb.com> <1461687967.2507874.590200129.102244C8@webmail.messagingengine.com> <571f9836$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 26, 2016 at 9:32 AM, Steven D'Aprano wrote: > Subclassing immutable built-ins is the most obvious and simple (and > probably > common) way to get an immutable class. Actually immutable, short of doing > wicked things with ctypes. > By wicked things with ctypes, do you mean something like this? By no means do I suggest this actually be used by anybody for any reason. Tested with '2.7.10 (default, Jul 14 2015, 19:46:27) \n[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)]' import ctypes def changeTuple(tuple, index, newValue): obj = ctypes.cast(id(tuple), ctypes.POINTER(ctypes.c_long)) obj[3+index] = id(newValue) >>> a = ('a','b','c') >>> changeTuple(a, 0, 1) >>> a (1, 'b', 'c') >>> changeTuple(a, 1, 3) >>> a (1, 3, 'c') Chris From peakgraphicz at gmail.com Tue Apr 26 13:00:52 2016 From: peakgraphicz at gmail.com (Adam Davis) Date: Tue, 26 Apr 2016 10:00:52 -0700 (PDT) Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> Message-ID: <514e507d-42de-400e-b999-14605c4456e8@googlegroups.com> On Tuesday, 26 April 2016 17:14:36 UTC+1, Ian wrote: > On Tue, Apr 26, 2016 at 10:01 AM, wrote: > > I am wondering how to make my code function so it does not allow any of the same values to be entered into a column in my CSV file created through python. So I need to read into the CSV file and check if any names have already been entered. If they have, the user must not be allowed to enter this value. > > Assuming the file is reasonably small enough to fit into memory, > create a set and populate it with the values in the column. When the > user enters a new value, check whether it's already in the set. That's exactly what I want to do, however, I'm unsure how to check whether it's in the set? From rosuav at gmail.com Tue Apr 26 13:04:07 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Apr 2016 03:04:07 +1000 Subject: def __init__(self): In-Reply-To: References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> <87lh40pyik.fsf@elektro.pacujo.net> <571f9362$0$1602$c3e8da3$5496439d@news.astraweb.com> <1461687967.2507874.590200129.102244C8@webmail.messagingengine.com> <571f9836$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 27, 2016 at 2:59 AM, Chris Kaynor wrote: > On Tue, Apr 26, 2016 at 9:32 AM, Steven D'Aprano > wrote: > >> Subclassing immutable built-ins is the most obvious and simple (and >> probably >> common) way to get an immutable class. Actually immutable, short of doing >> wicked things with ctypes. >> > > By wicked things with ctypes, do you mean something like this? By no means > do I suggest this actually be used by anybody for any reason. > > Tested with '2.7.10 (default, Jul 14 2015, 19:46:27) \n[GCC 4.2.1 > Compatible Apple LLVM 6.0 (clang-600.0.39)]' > > import ctypes > def changeTuple(tuple, index, newValue): > obj = ctypes.cast(id(tuple), ctypes.POINTER(ctypes.c_long)) > obj[3+index] = id(newValue) > >>>> a = ('a','b','c') >>>> changeTuple(a, 0, 1) >>>> a > (1, 'b', 'c') >>>> changeTuple(a, 1, 3) >>>> a > (1, 3, 'c') Yeah. By the look of things, you've just destroyed the reference counts. >>> a = ('a','b','c') >>> b = object() >>> changeTuple(a, 0, b) >>> a (, 'b', 'c') >>> del b >>> a Segmentation fault ChrisA From peakgraphicz at gmail.com Tue Apr 26 13:05:00 2016 From: peakgraphicz at gmail.com (Adam Davis) Date: Tue, 26 Apr 2016 10:05:00 -0700 (PDT) Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> Message-ID: <25b35d39-4163-414c-9495-f2ed4a2a90a8@googlegroups.com> On Tuesday, 26 April 2016 17:09:10 UTC+1, Joel Goldstick wrote: > On Tue, Apr 26, 2016 at 12:01 PM, wrote: > > I am wondering how to make my code function so it does not allow any of the same values to be entered into a column in my CSV file created through python. So I need to read into the CSV file and check if any names have already been entered. If they have, the user must not be allowed to enter this value. > > > > Thanks in advance! > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Show your code and a few lines of your file with useful data. Show > the result you want > > -- > Joel Goldstick > http://joelgoldstick.com/blog > http://cc-baseballstats.info/stats/birthdays Here's my section of code: with open(class_code+".csv", 'a') as csvfile: fieldnames = ["Name", "Score 1", "Score 2", "Score 3", "Average"] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) #writer.writeheader() writer.writerow({"Name": name, "Score 1": score1, "Score 2": score2, "Score 3": score3}) It prints when requested as: Adam,1,0,0,0.3333333333333333 Jake,9,10,6,8.333333333333334 Tom,5,3,3,3.6666666666666665 So basically, if anyone called Adam, Jake or Tom tries the quiz again, it will not let them. Thanks From peakgraphicz at gmail.com Tue Apr 26 13:05:17 2016 From: peakgraphicz at gmail.com (Adam Davis) Date: Tue, 26 Apr 2016 10:05:17 -0700 (PDT) Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> Message-ID: <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> On Tuesday, 26 April 2016 17:01:41 UTC+1, Adam Davis wrote: > I am wondering how to make my code function so it does not allow any of the same values to be entered into a column in my CSV file created through python. So I need to read into the CSV file and check if any names have already been entered. If they have, the user must not be allowed to enter this value. > > Thanks in advance! Here's my section of code: with open(class_code+".csv", 'a') as csvfile: fieldnames = ["Name", "Score 1", "Score 2", "Score 3", "Average"] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) #writer.writeheader() writer.writerow({"Name": name, "Score 1": score1, "Score 2": score2, "Score 3": score3}) It prints when requested as: Adam,1,0,0,0.3333333333333333 Jake,9,10,6,8.333333333333334 Tom,5,3,3,3.6666666666666665 So basically, if anyone called Adam, Jake or Tom tries the quiz again, it will not let them. Thanks From ckaynor at zindagigames.com Tue Apr 26 13:13:40 2016 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 26 Apr 2016 10:13:40 -0700 Subject: def __init__(self): In-Reply-To: References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> <87lh40pyik.fsf@elektro.pacujo.net> <571f9362$0$1602$c3e8da3$5496439d@news.astraweb.com> <1461687967.2507874.590200129.102244C8@webmail.messagingengine.com> <571f9836$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 26, 2016 at 10:04 AM, Chris Angelico wrote: > On Wed, Apr 27, 2016 at 2:59 AM, Chris Kaynor > wrote: > > On Tue, Apr 26, 2016 at 9:32 AM, Steven D'Aprano > > wrote: > > > >> Subclassing immutable built-ins is the most obvious and simple (and > >> probably > >> common) way to get an immutable class. Actually immutable, short of > doing > >> wicked things with ctypes. > >> > > > > By wicked things with ctypes, do you mean something like this? By no > means > > do I suggest this actually be used by anybody for any reason. > > > > Tested with '2.7.10 (default, Jul 14 2015, 19:46:27) \n[GCC 4.2.1 > > Compatible Apple LLVM 6.0 (clang-600.0.39)]' > > > > import ctypes > > def changeTuple(tuple, index, newValue): > > obj = ctypes.cast(id(tuple), ctypes.POINTER(ctypes.c_long)) > > obj[3+index] = id(newValue) > > > >>>> a = ('a','b','c') > >>>> changeTuple(a, 0, 1) > >>>> a > > (1, 'b', 'c') > >>>> changeTuple(a, 1, 3) > >>>> a > > (1, 3, 'c') > > Yeah. By the look of things, you've just destroyed the reference counts. > > >>> a = ('a','b','c') > >>> b = object() > >>> changeTuple(a, 0, b) > >>> a > (, 'b', 'c') > >>> del b > >>> a > Segmentation fault > Yah, if you really wanted to make it work properly, you'd need to incref the newValue, while decref the oldValue. The incref would not be that difficult, but the decref would be more challenging, as you may have to also destroy the old object, though that might be possible by casting it back to a python object without the incref,. One way or the other, I did not exactly spend a ton of time to make it work properly :) From ian.g.kelly at gmail.com Tue Apr 26 13:26:46 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 26 Apr 2016 11:26:46 -0600 Subject: def __init__(self): In-Reply-To: References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> <87lh40pyik.fsf@elektro.pacujo.net> <571f9362$0$1602$c3e8da3$5496439d@news.astraweb.com> <1461687967.2507874.590200129.102244C8@webmail.messagingengine.com> <571f9836$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 26, 2016 at 11:13 AM, Chris Kaynor wrote: > Yah, if you really wanted to make it work properly, you'd need to incref > the newValue, while decref the oldValue. The incref would not be that > difficult, but the decref would be more challenging, as you may have to > also destroy the old object, though that might be possible by casting it > back to a python object without the incref,. One way or the other, I did > not exactly spend a ton of time to make it work properly :) For the decref I'd probably just decrement it and leave it; if it's zero, the garbage collector will eventually take care of it. From rosuav at gmail.com Tue Apr 26 13:30:02 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Apr 2016 03:30:02 +1000 Subject: def __init__(self): In-Reply-To: References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> <87lh40pyik.fsf@elektro.pacujo.net> <571f9362$0$1602$c3e8da3$5496439d@news.astraweb.com> <1461687967.2507874.590200129.102244C8@webmail.messagingengine.com> <571f9836$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 27, 2016 at 3:13 AM, Chris Kaynor wrote: > Yah, if you really wanted to make it work properly, you'd need to incref > the newValue, while decref the oldValue. The incref would not be that > difficult, but the decref would be more challenging, as you may have to > also destroy the old object, though that might be possible by casting it > back to a python object without the incref,. One way or the other, I did > not exactly spend a ton of time to make it work properly :) Exactly. :) Actually, the easiest fix is probably this: import ctypes def low_change_tuple(tuple, index, newValue): obj = ctypes.cast(id(tuple), ctypes.POINTER(ctypes.c_long)) obj[3+index] = id(newValue) def change_tuple(tup, idx, val): dummy = (val,) low_change_tuple(dummy, 0, tup[idx]) low_change_tuple(tup, idx, val) Refcounts are handled by the switch. ChrisA From __peter__ at web.de Tue Apr 26 13:58:19 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 26 Apr 2016 19:58:19 +0200 Subject: How to read from serial port? References: <41302A7145AC054FA7A96CFD03835A0A0BAC66F9@EX10MBX02.EU.NEC.COM> Message-ID: David Aldrich wrote: > Hi > > I have written a very simple program to read and print data from the > serial port using pyserial: > > #!/usr/bin/python3 > import serial > > ser=serial.Serial('COM1',115200) > while True: > out = ser.read() > print('Receiving...'+out) > > When I run it and send data for it to read I get: > > C:\SVNProj\Raggio\trunk\hostconsole\gui\prototypes\serial_test>py > serial_read.py Traceback (most recent call last): > File "serial_read.py", line 9, in > print('Receiving...'+out) > TypeError: Can't convert 'bytes' object to str implicitly > > I am using Python 3.5. How would I fix this error please? Look at the traceback again. The line > out = ser.read() is executed, you are reading successfully. What fails is > print('Receiving...'+out) You are trying to concatenate a (unicode) string and bytes, like in >>> print("foo" + b"bar") Traceback (most recent call last): File "", line 1, in TypeError: Can't convert 'bytes' object to str implicitly You can avoid that by printing the string and the bytes independently >>> print("foo", b"bar") foo b'bar' If you don't like the b"..." stuff and want to treat the bytes as text rather than data you can decode them: >>> print("foo", b"bar".decode()) foo bar For more see . From bigbadmick2000 at hotmail.com Tue Apr 26 14:16:56 2016 From: bigbadmick2000 at hotmail.com (Michael) Date: Tue, 26 Apr 2016 19:16:56 +0100 Subject: Python path and append Message-ID: If you want to read an entire file, append a space and asterisk and write it to another file, this is the code you need: infile = open('win.txt', 'r') text = f.read() infile.close() text += " *" outfile = open('outfile.txt', 'w') outfile.write(text) outfile.close() If, on the other hand, you wish to read a file and append a space and asterisk TO THE END OF EVERY LINE, you require the following code: infile = open('win.txt', 'r') lines = infile.readlines() infile.close() outfile = open('outfile.txt', 'w') for line in lines: line = line.strip() + " *\n" outfile.write(line) outfile.close() Hope that helps! BigBadMick bigbadmick2000 at hotmail.com From grant.b.edwards at gmail.com Tue Apr 26 14:29:53 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 26 Apr 2016 18:29:53 +0000 (UTC) Subject: How to read from serial port? References: <41302A7145AC054FA7A96CFD03835A0A0BAC66F9@EX10MBX02.EU.NEC.COM> Message-ID: On 2016-04-26, David Aldrich wrote: > #!/usr/bin/python3 > import serial > > ser=serial.Serial('COM1',115200) > while True: > out = ser.read() > print('Receiving...'+out) > > When I run it and send data for it to read I get: > Traceback (most recent call last): > File "serial_read.py", line 9, in > print('Receiving...'+out) > TypeError: Can't convert 'bytes' object to str implicitly Try this: print('Receiving...',out) If you want to convert the bytes you read from the serial port into a string, you need to decode they bytes (and you have to specify what encoding to use): print('Receiving...' + out.decode('ascii')) If you google 'Python 3 bytes strings' you should find a bunch of info: https://docs.python.org/3.5/library/stdtypes.html http://www.diveintopython3.net/strings.html http://pythoncentral.io/encoding-and-decoding-strings-in-python-3-x/ https://www.safaribooksonline.com/library/view/fluent-python/9781491946237/ch04.html -- Grant Edwards grant.b.edwards Yow! I haven't been married at in over six years, but we gmail.com had sexual counseling every day from Oral Roberts!! From Joaquin.Alzola at lebara.com Tue Apr 26 15:05:37 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Tue, 26 Apr 2016 19:05:37 +0000 Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> Message-ID: Just an example. Didn't use the csv but just hope that it helps. name=[] name_exist="Dop" with open("dop.csv") as f: for line in f: line_split=line.split(',') name.append(line_strip[0]) if name_exist in name: print "found name " + name_exist + " Can not append" else: file = open("dop.csv",'a') print "No name found" file.write(name_exist) file.close() -----Original Message----- From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com at python.org] On Behalf Of Adam Davis Sent: 26 April 2016 18:05 To: python-list at python.org Subject: Re: Howw to prevent the duplication of any value in a column within a CSV file (python) On Tuesday, 26 April 2016 17:01:41 UTC+1, Adam Davis wrote: > I am wondering how to make my code function so it does not allow any of the same values to be entered into a column in my CSV file created through python. So I need to read into the CSV file and check if any names have already been entered. If they have, the user must not be allowed to enter this value. > > Thanks in advance! Here's my section of code: with open(class_code+".csv", 'a') as csvfile: fieldnames = ["Name", "Score 1", "Score 2", "Score 3", "Average"] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) #writer.writeheader() writer.writerow({"Name": name, "Score 1": score1, "Score 2": score2, "Score 3": score3}) It prints when requested as: Adam,1,0,0,0.3333333333333333 Jake,9,10,6,8.333333333333334 Tom,5,3,3,3.6666666666666665 So basically, if anyone called Adam, Jake or Tom tries the quiz again, it will not let them. Thanks -- https://mail.python.org/mailman/listinfo/python-list This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. From ian.g.kelly at gmail.com Tue Apr 26 15:50:20 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 26 Apr 2016 13:50:20 -0600 Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: <514e507d-42de-400e-b999-14605c4456e8@googlegroups.com> References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <514e507d-42de-400e-b999-14605c4456e8@googlegroups.com> Message-ID: On Tue, Apr 26, 2016 at 11:00 AM, Adam Davis wrote: > On Tuesday, 26 April 2016 17:14:36 UTC+1, Ian wrote: >> On Tue, Apr 26, 2016 at 10:01 AM, wrote: >> > I am wondering how to make my code function so it does not allow any of the same values to be entered into a column in my CSV file created through python. So I need to read into the CSV file and check if any names have already been entered. If they have, the user must not be allowed to enter this value. >> >> Assuming the file is reasonably small enough to fit into memory, >> create a set and populate it with the values in the column. When the >> user enters a new value, check whether it's already in the set. > > That's exactly what I want to do, however, I'm unsure how to check whether it's in the set? if value in the_set: # Forbid the value. else: # Allow the value. From ian.g.kelly at gmail.com Tue Apr 26 15:51:58 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 26 Apr 2016 13:51:58 -0600 Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> Message-ID: On Tue, Apr 26, 2016 at 1:05 PM, Joaquin Alzola wrote: > Just an example. Didn't use the csv but just hope that it helps. > > name=[] > name_exist="Dop" > > with open("dop.csv") as f: > for line in f: > line_split=line.split(',') > name.append(line_strip[0]) > if name_exist in name: > print "found name " + name_exist + " Can not append" > else: > file = open("dop.csv",'a') > print "No name found" > file.write(name_exist) > file.close() Except that as noted elsewhere in the thread a set would be a better choice than a list, since checking membership is much faster on a set. From peakgraphicz at gmail.com Tue Apr 26 16:07:39 2016 From: peakgraphicz at gmail.com (Adam Davis) Date: Tue, 26 Apr 2016 13:07:39 -0700 (PDT) Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> Message-ID: <49f4ffd8-d140-4f1b-95a9-75cb122e8b2f@googlegroups.com> On Tuesday, 26 April 2016 20:52:54 UTC+1, Ian wrote: > On Tue, Apr 26, 2016 at 1:05 PM, Joaquin Alzola > wrote: > > Just an example. Didn't use the csv but just hope that it helps. > > > > name=[] > > name_exist="Dop" > > > > with open("dop.csv") as f: > > for line in f: > > line_split=line.split(',') > > name.append(line_strip[0]) > > if name_exist in name: > > print "found name " + name_exist + " Can not append" > > else: > > file = open("dop.csv",'a') > > print "No name found" > > file.write(name_exist) > > file.close() > > Except that as noted elsewhere in the thread a set would be a better > choice than a list, since checking membership is much faster on a set. Thanks for your help Ian. I'm a beginner right now, could you instruct me as to how I would create a set? From ian.g.kelly at gmail.com Tue Apr 26 16:19:20 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 26 Apr 2016 14:19:20 -0600 Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: <49f4ffd8-d140-4f1b-95a9-75cb122e8b2f@googlegroups.com> References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> <49f4ffd8-d140-4f1b-95a9-75cb122e8b2f@googlegroups.com> Message-ID: On Tue, Apr 26, 2016 at 2:07 PM, Adam Davis wrote: > On Tuesday, 26 April 2016 20:52:54 UTC+1, Ian wrote: >> On Tue, Apr 26, 2016 at 1:05 PM, Joaquin Alzola >> wrote: >> > Just an example. Didn't use the csv but just hope that it helps. >> > >> > name=[] >> > name_exist="Dop" >> > >> > with open("dop.csv") as f: >> > for line in f: >> > line_split=line.split(',') >> > name.append(line_strip[0]) >> > if name_exist in name: >> > print "found name " + name_exist + " Can not append" >> > else: >> > file = open("dop.csv",'a') >> > print "No name found" >> > file.write(name_exist) >> > file.close() >> >> Except that as noted elsewhere in the thread a set would be a better >> choice than a list, since checking membership is much faster on a set. > > Thanks for your help Ian. I'm a beginner right now, could you instruct me as to how I would create a set? Create a new set: my_set = set() Add a value to the set: my_set.add(value) Check for membership: value in my_set See also the Python tutorial at https://docs.python.org/3/tutorial/datastructures.html#sets From python at mrabarnett.plus.com Tue Apr 26 16:23:32 2016 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 26 Apr 2016 21:23:32 +0100 Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: <49f4ffd8-d140-4f1b-95a9-75cb122e8b2f@googlegroups.com> References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> <49f4ffd8-d140-4f1b-95a9-75cb122e8b2f@googlegroups.com> Message-ID: On 2016-04-26 21:07, Adam Davis wrote: > On Tuesday, 26 April 2016 20:52:54 UTC+1, Ian wrote: >> On Tue, Apr 26, 2016 at 1:05 PM, Joaquin Alzola >> wrote: >> > Just an example. Didn't use the csv but just hope that it helps. >> > >> > name=[] >> > name_exist="Dop" >> > >> > with open("dop.csv") as f: >> > for line in f: >> > line_split=line.split(',') >> > name.append(line_strip[0]) >> > if name_exist in name: >> > print "found name " + name_exist + " Can not append" >> > else: >> > file = open("dop.csv",'a') >> > print "No name found" >> > file.write(name_exist) >> > file.close() >> >> Except that as noted elsewhere in the thread a set would be a better >> choice than a list, since checking membership is much faster on a set. > > Thanks for your help Ian. I'm a beginner right now, could you instruct me as to how I would create a set? > Create a set: the_set = set() Add an item to a set: the_set.add(item) From sourav524.itscient at gmail.com Tue Apr 26 17:05:07 2016 From: sourav524.itscient at gmail.com (sourav524.itscient at gmail.com) Date: Tue, 26 Apr 2016 14:05:07 -0700 (PDT) Subject: !! Immediate Requirement : IBM BPM Technical Lead at Warren, NJ !! Message-ID: <1e5aaf16-c650-44a3-acee-406c08c63870@googlegroups.com> Hello Associates, Please go through the below job description and let me know your interest. Please revert me: Sourav.P at itscient.com or sourav524.itscient at gmail.com. Position: IBM BPM Technical Lead Location: Warren, NJ Duration: 6+ Months Requisition Details: Skills, Required Experience and Job Responsibilities o 7 to 10 years' Experience o Hands on experience on the IBM BPM (IBM BPM 8.5) is must o Possess Java/J2EE skills o Good communication skills o Knowledge of Oracle BPM o Should understand BPM process, interact with SMES for queries etc. o Has Process, rules & deep IBM BPM solution skills. o Experience of designing workflows using Business process modeling tool o Migration experience from any BPM (preferably Oracle BPM)to IBM BPM o Awareness of banking domain Thanks & Regards Sourav Paul | Technical Recruiter IT-SCIENT LLC, Fremont, CA, USA Email: sourav524.itscient at gmail.com Phone: 510-972-8633 | Fax: 877-701-5240 |web: www.itscient.com From real-not-anti-spam-address at apple-juice.co.uk Tue Apr 26 17:33:51 2016 From: real-not-anti-spam-address at apple-juice.co.uk (D.M. Procida) Date: Tue, 26 Apr 2016 22:33:51 +0100 Subject: Running PyGame on OS X Message-ID: <1mmc3vc.xx6qbm6rzpsgN%real-not-anti-spam-address@apple-juice.co.uk> I have PyGame installed. As soon as I run pygame.init() or pygame.display.init(), a PyGame icon will pop up in the Dock, and then its application will simply stop responding. Needless to say, I can't actually do anything with it. What is this application, and what is likely the problem with it? Thanks, Daniele From ian.g.kelly at gmail.com Tue Apr 26 17:42:45 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 26 Apr 2016 15:42:45 -0600 Subject: Running PyGame on OS X In-Reply-To: <1mmc3vc.xx6qbm6rzpsgN%real-not-anti-spam-address@apple-juice.co.uk> References: <1mmc3vc.xx6qbm6rzpsgN%real-not-anti-spam-address@apple-juice.co.uk> Message-ID: On Tue, Apr 26, 2016 at 3:33 PM, D.M. Procida wrote: > I have PyGame installed. > > As soon as I run pygame.init() or pygame.display.init(), a PyGame icon > will pop up in the Dock, and then its application will simply stop > responding. Needless to say, I can't actually do anything with it. > > What is this application, and what is likely the problem with it? That sounds like it's just the PyGame display window. Likely it's not responding because you just called init() and didn't actually start running an event loop to process events on the window. I'd suggest working through a PyGame tutorial. From ben+python at benfinney.id.au Tue Apr 26 19:07:06 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 27 Apr 2016 09:07:06 +1000 Subject: Immediate Requirement: use the Python Job Board for recruitment (was: !! Immediate Requirement : IBM BPM Technical Lead at Warren, NJ !!) References: <1e5aaf16-c650-44a3-acee-406c08c63870@googlegroups.com> Message-ID: <85wpnkkm05.fsf@benfinney.id.au> sourav524.itscient at gmail.com writes: > Hello Associates, > Please go through the below job description and let me know your > interest. Hello recruiters, Please don't use Python discussion forums for recruiting. Instead, use the Python Job Board which is maintained specifically for that purpose . -- \ ?I don't care to belong to a club that accepts people like me | `\ as members.? ?Groucho Marx | _o__) | Ben Finney From hasandiwan+usenet at gmail.com Tue Apr 26 20:36:13 2016 From: hasandiwan+usenet at gmail.com (Hasan Diwan) Date: Wed, 27 Apr 2016 00:36:13 +0000 (UTC) Subject: how to create a dictionary from csv file? References: <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> <20160426093659.5adc41c6@bigbox.christie.dr> Message-ID: >> I am learning python. >> >> if I have a csv file, like this >> banana,4.0 >> apple,3.5 >> orange,3.0 >> >> Can anyone show me how to read the csv file line by line and then >> create a dictionary to contain these keys and values? with open('data.csv') as f: data = dict([[l.strip() for l in line] for line in csv.reader(f)]) data {'apple': '3.5', 'banana': '4.0', 'orange': '3.0'} From gvm2121 at gmail.com Tue Apr 26 21:21:00 2016 From: gvm2121 at gmail.com (Gonzalo V) Date: Tue, 26 Apr 2016 21:21:00 -0400 Subject: How to read from serial port? In-Reply-To: References: <41302A7145AC054FA7A96CFD03835A0A0BAC66F9@EX10MBX02.EU.NEC.COM> Message-ID: Try print('blaba'+str(out)) saludos, desde un m?vil. El abr 26, 2016 2:33 p.m., "Grant Edwards" escribi?: > On 2016-04-26, David Aldrich wrote: > > > #!/usr/bin/python3 > > import serial > > > > ser=serial.Serial('COM1',115200) > > while True: > > out = ser.read() > > print('Receiving...'+out) > > > > When I run it and send data for it to read I get: > > > Traceback (most recent call last): > > File "serial_read.py", line 9, in > > print('Receiving...'+out) > > TypeError: Can't convert 'bytes' object to str implicitly > > Try this: > > print('Receiving...',out) > > If you want to convert the bytes you read from the serial port into a > string, you need to decode they bytes (and you have to specify what > encoding to use): > > print('Receiving...' + out.decode('ascii')) > > If you google 'Python 3 bytes strings' you should find a bunch of info: > > https://docs.python.org/3.5/library/stdtypes.html > http://www.diveintopython3.net/strings.html > http://pythoncentral.io/encoding-and-decoding-strings-in-python-3-x/ > > https://www.safaribooksonline.com/library/view/fluent-python/9781491946237/ch04.html > > -- > Grant Edwards grant.b.edwards Yow! I haven't been > married > at in over six years, but > we > gmail.com had sexual counseling > every > day from Oral Roberts!! > > -- > https://mail.python.org/mailman/listinfo/python-list > From ben+python at benfinney.id.au Tue Apr 26 21:27:36 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 27 Apr 2016 11:27:36 +1000 Subject: How to read from serial port? References: <41302A7145AC054FA7A96CFD03835A0A0BAC66F9@EX10MBX02.EU.NEC.COM> Message-ID: <85k2jjlu2f.fsf@benfinney.id.au> Gonzalo V writes: > Try print('blaba'+str(out)) I doubt that gives the desired result for a bytes object. Did you try it? >>> foo = b'\xde\xad\xbe\xef' >>> str(foo) "b'\\xde\\xad\\xbe\\xef'" >>> print(str(foo)) b'\xde\xad\xbe\xef' Yes, the ?b'? and backslashes are all part of the output. > saludos, > desde un m?vil. Please don't top-post. If that means you need to wait until you are at a device with proper keyboard, then please do that. -- \ ?I have one rule to live by: Don't make it worse.? ?Hazel | `\ Woodcock | _o__) | Ben Finney From jfong at ms4.hinet.net Tue Apr 26 22:42:36 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Tue, 26 Apr 2016 19:42:36 -0700 (PDT) Subject: how to create a dictionary from csv file? In-Reply-To: <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> References: <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> Message-ID: Just curious:-) why everyone here open the csv file without using newline='' as suggested in Python 3.4.4 document section 14.1? From Seymore4Head at Hotmail.invalid Tue Apr 26 22:56:46 2016 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 26 Apr 2016 22:56:46 -0400 Subject: Python path and append References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> <571eca35$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 26 Apr 2016 11:53:57 +1000, Steven D'Aprano wrote: >On Tue, 26 Apr 2016 08:04 am, Seymore4Head wrote: > >> BTW I was trying to use a line like yours that used an output file >> that didn't exist and was getting an error. ?I assume that import os >> fixes that. > > >Why would you assume that? > > >"Doctor, I have a problem with my arm, but I won't tell you what. I assume >that if I take cough drops that will fix it." OK. Dumb question acknowledged. I got an error when I tried to write to a non existent file. I "incorrectly" assumed wrong. That is going to be a common theme. From Seymore4Head at Hotmail.invalid Tue Apr 26 22:57:16 2016 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 26 Apr 2016 22:57:16 -0400 Subject: Python path and append References: Message-ID: On Tue, 26 Apr 2016 19:16:56 +0100, Michael wrote: >If you want to read an entire file, append a space and asterisk and write it to another file, this is the code you need: > >infile = open('win.txt', 'r') >text = f.read() >infile.close() >text += " *" >outfile = open('outfile.txt', 'w') >outfile.write(text) >outfile.close() > >If, on the other hand, you wish to read a file and append a space and asterisk TO THE END OF EVERY LINE, you require the following code: >infile = open('win.txt', 'r') >lines = infile.readlines() >infile.close() >outfile = open('outfile.txt', 'w') >for line in lines: > line = line.strip() + " *\n" > outfile.write(line) >outfile.close() > >Hope that helps! > >BigBadMick >bigbadmick2000 at hotmail.com I will have a look at this. Thanks From rosuav at gmail.com Tue Apr 26 23:06:44 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Apr 2016 13:06:44 +1000 Subject: Python path and append In-Reply-To: References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> <571eca35$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 27, 2016 at 12:56 PM, Seymore4Head wrote: > On Tue, 26 Apr 2016 11:53:57 +1000, Steven D'Aprano > wrote: > >>On Tue, 26 Apr 2016 08:04 am, Seymore4Head wrote: >> >>> BTW I was trying to use a line like yours that used an output file >>> that didn't exist and was getting an error. I assume that import os >>> fixes that. >> >> >>Why would you assume that? >> >> >>"Doctor, I have a problem with my arm, but I won't tell you what. I assume >>that if I take cough drops that will fix it." > > OK. Dumb question acknowledged. > > I got an error when I tried to write to a non existent file. I > "incorrectly" assumed wrong. That is going to be a common theme. If you can acknowledge that, I suggest adopting a stance that will tend to avoid such assumptions in the future. The easiest way is to do less of your own analysis and more copy/paste of exact error messages. Don't say "getting an error" - quote the actual code and error. Don't say "I assume that", ask the question ("Would importing the os module fix that?"). We'll be able to help more easily with actual error text, and you won't look dumb :) ChrisA From christopher_reimer at icloud.com Tue Apr 26 23:43:55 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Tue, 26 Apr 2016 20:43:55 -0700 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? Message-ID: <5720357B.4060009@icloud.com> Greetings, If I'm using a dictionary to store variables for an object, and accessing the variable values from dictionary via property decorators, would it be better to derive the class from object or dict? class Test1(object): def __init__(self): self.state = {'key': 'value'} Or: class Test2(dict): def __init__(self): self.__dict__ = {'key', 'value'} I haven't seen a good pro/con discussion on the Internet for using one over the other. I played with both in my code. Doesn't seem to make a great difference either way. Using object seems to be the most simplest approach. Thank you, Chris R. From ben+python at benfinney.id.au Tue Apr 26 23:54:11 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 27 Apr 2016 13:54:11 +1000 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? References: <5720357B.4060009@icloud.com> Message-ID: <85bn4vlna4.fsf@benfinney.id.au> Christopher Reimer writes: > If I'm using a dictionary to store variables for an object, and > accessing the variable values from dictionary via property decorators Why not use the built-in ?dict? type? What does the new type do which isn't already better served by the built-in ?dict? type? (Note that ?allow attribute-syntax access to dictionary items? does not qualify as ?better?, IMO; it qualifies as ?needlessly confusing distinct concepts?.) > I haven't seen a good pro/con discussion on the Internet for using one > over the other. I haven't seen a good pro/con discussion of the use case you're trying to address :-) -- \ ?I'd take the awe of understanding over the awe of ignorance | `\ any day.? ?Douglas Adams | _o__) | Ben Finney From random832 at fastmail.com Tue Apr 26 23:56:00 2016 From: random832 at fastmail.com (Random832) Date: Tue, 26 Apr 2016 23:56:00 -0400 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? In-Reply-To: <5720357B.4060009@icloud.com> References: <5720357B.4060009@icloud.com> Message-ID: <1461729360.3276080.590752673.7A6E1041@webmail.messagingengine.com> On Tue, Apr 26, 2016, at 23:43, Christopher Reimer wrote: > Greetings, > > If I'm using a dictionary to store variables for an object, and > accessing the variable values from dictionary via property decorators, what exactly do you mean by property decorators? If you're just accessing them in a dictionary what's the benefit over having the values be simple attributes rather than properties? > would it be better to derive the class from object or dict? > > class Test1(object): > def __init__(self): > self.state = {'key': 'value'} > > Or: > > class Test2(dict): > def __init__(self): > self.__dict__ = {'key', 'value'} > > I haven't seen a good pro/con discussion on the Internet for using one > over the other. I played with both in my code. Doesn't seem to make a > great difference either way. Using object seems to be the most simplest > approach. I sometimes use dict (with self.__dict__ = self) if I want to be able to access values via either obj['key'] or obj.key (a la Javascript). Otherwise, there's no point in using dict. From steve+comp.lang.python at pearwood.info Wed Apr 27 00:54:27 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 27 Apr 2016 14:54:27 +1000 Subject: def __init__(self): References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> <87lh40pyik.fsf@elektro.pacujo.net> <571f9362$0$1602$c3e8da3$5496439d@news.astraweb.com> <1461687967.2507874.590200129.102244C8@webmail.messagingengine.com> <571f9836$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57204605$0$11115$c3e8da3@news.astraweb.com> On Wednesday 27 April 2016 02:59, Chris Kaynor wrote: > On Tue, Apr 26, 2016 at 9:32 AM, Steven D'Aprano > wrote: > >> Actually immutable, short of doing wicked things with ctypes. >> > > By wicked things with ctypes, do you mean something like this? By no means > do I suggest this actually be used by anybody for any reason. > > Tested with '2.7.10 (default, Jul 14 2015, 19:46:27) \n[GCC 4.2.1 > Compatible Apple LLVM 6.0 (clang-600.0.39)]' > > import ctypes > def changeTuple(tuple, index, newValue): > obj = ctypes.cast(id(tuple), ctypes.POINTER(ctypes.c_long)) > obj[3+index] = id(newValue) > >>>> a = ('a','b','c') >>>> changeTuple(a, 0, 1) >>>> a > (1, 'b', 'c') >>>> changeTuple(a, 1, 3) >>>> a > (1, 3, 'c') You're a bad, bad man :-) -- Steve From ethan at stoneleaf.us Wed Apr 27 01:31:18 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 26 Apr 2016 22:31:18 -0700 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? In-Reply-To: <5720357B.4060009@icloud.com> References: <5720357B.4060009@icloud.com> Message-ID: <57204EA6.7060007@stoneleaf.us> On 04/26/2016 08:43 PM, Christopher Reimer wrote: > If I'm using a dictionary to store variables for an object, and > accessing the variable values from dictionary via property decorators, > would it be better to derive the class from object or dict? > > class Test1(object): > def __init__(self): > self.state = {'key': 'value'} > > Or: > > class Test2(dict): > def __init__(self): > self.__dict__ = {'key', 'value'} > > I haven't seen a good pro/con discussion on the Internet for using one > over the other. I played with both in my code. Doesn't seem to make a > great difference either way. Using object seems to be the most simplest > approach. Using a dict gets you a bunch of methods for free: keys(), values(), items(), get(), etc., etc.. If you don't need any of those, subclass object. -- ~Ethan~ From ethan at stoneleaf.us Wed Apr 27 01:33:47 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 26 Apr 2016 22:33:47 -0700 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? In-Reply-To: <85bn4vlna4.fsf@benfinney.id.au> References: <5720357B.4060009@icloud.com> <85bn4vlna4.fsf@benfinney.id.au> Message-ID: <57204F3B.3060906@stoneleaf.us> On 04/26/2016 08:54 PM, Ben Finney wrote: > (Note that ?allow attribute-syntax access to dictionary items? does not > qualify as ?better?, IMO; it qualifies as ?needlessly confusing distinct > concepts?.) Well, since one of the side-effects of class instances is to provide "attribute-syntax access to" the instances' "dictionary items" I would say that distinction is pretty thin already. ;) -- ~Ethan~ From peakgraphicz at gmail.com Wed Apr 27 02:26:19 2016 From: peakgraphicz at gmail.com (Adam Davis) Date: Tue, 26 Apr 2016 23:26:19 -0700 (PDT) Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> <49f4ffd8-d140-4f1b-95a9-75cb122e8b2f@googlegroups.com> Message-ID: On Tuesday, 26 April 2016 21:23:58 UTC+1, MRAB wrote: > On 2016-04-26 21:07, Adam Davis wrote: > > On Tuesday, 26 April 2016 20:52:54 UTC+1, Ian wrote: > >> On Tue, Apr 26, 2016 at 1:05 PM, Joaquin Alzola > >> wrote: > >> > Just an example. Didn't use the csv but just hope that it helps. > >> > > >> > name=[] > >> > name_exist="Dop" > >> > > >> > with open("dop.csv") as f: > >> > for line in f: > >> > line_split=line.split(',') > >> > name.append(line_strip[0]) > >> > if name_exist in name: > >> > print "found name " + name_exist + " Can not append" > >> > else: > >> > file = open("dop.csv",'a') > >> > print "No name found" > >> > file.write(name_exist) > >> > file.close() > >> > >> Except that as noted elsewhere in the thread a set would be a better > >> choice than a list, since checking membership is much faster on a set. > > > > Thanks for your help Ian. I'm a beginner right now, could you instruct me as to how I would create a set? > > > Create a set: > > the_set = set() > > Add an item to a set: > > the_set.add(item) I understand what you're saying! But where you say: " the_set = set()", what would go within the set brackets? From bob.martin at excite.com Wed Apr 27 07:36:22 2016 From: bob.martin at excite.com (Bob Martin) Date: Wed, 27 Apr 2016 07:36:22 BST Subject: Immediate Requirement: use the Python Job Board for recruitment (was: References: <1e5aaf16-c650-44a3-acee-406c08c63870@googlegroups.com> Message-ID: in 758723 20160427 000706 Ben Finney wrote: >sourav524.itscient at gmail.com writes: > >> Hello Associates, >> Please go through the below job description and let me know your >> interest. > >Hello recruiters, > >Please don't use Python discussion forums for recruiting. Instead, use >the Python Job Board which is maintained specifically for that purpose >. Recruiters post everywhere but seem not to read anywhere. They have flooded the android developer lists to the point where they are no longer worth reading. From rosuav at gmail.com Wed Apr 27 02:37:27 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Apr 2016 16:37:27 +1000 Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> <49f4ffd8-d140-4f1b-95a9-75cb122e8b2f@googlegroups.com> Message-ID: On Wed, Apr 27, 2016 at 4:26 PM, Adam Davis wrote: > I understand what you're saying! But where you say: " the_set = set()", what would go within the set brackets? Nothing. The empty parentheses mean "call this with no arguments", and when you call the set constructor like that, you get back an empty set. ChrisA From steve+comp.lang.python at pearwood.info Wed Apr 27 04:31:42 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 27 Apr 2016 18:31:42 +1000 Subject: Immediate Requirement: use the Python Job Board for recruitment (was: References: <1e5aaf16-c650-44a3-acee-406c08c63870@googlegroups.com> Message-ID: <572078f0$0$1516$c3e8da3$5496439d@news.astraweb.com> On Wednesday 27 April 2016 16:36, Bob Martin wrote: > Recruiters post everywhere but seem not to read anywhere. > They have flooded the android developer lists to the point where > they are no longer worth reading. Wanted: Android developer. Must have five years experience with "Marshmellow" or ten years with any previous version. -- Steven From nulla.epistola at web.de Wed Apr 27 05:10:20 2016 From: nulla.epistola at web.de (Sibylle Koczian) Date: Wed, 27 Apr 2016 11:10:20 +0200 Subject: how to create a dictionary from csv file? In-Reply-To: References: <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> Message-ID: Am 27.04.2016 um 04:42 schrieb jfong at ms4.hinet.net: > Just curious:-) why everyone here open the csv file without using newline='' as suggested in Python 3.4.4 document section 14.1? > And if the csv module is used anyway, why not simply read into a DictReader? From smith at a-team.it Wed Apr 27 05:29:12 2016 From: smith at a-team.it (Smith) Date: Wed, 27 Apr 2016 11:29:12 +0200 Subject: Basic Concepts Message-ID: Fill in the blanks to declare a variable, add 5 to it and print its value: >>> x = 4 >>> x_ = 5 >>> print_ Any suggestion ? Thanks From __peter__ at web.de Wed Apr 27 05:31:02 2016 From: __peter__ at web.de (Peter Otten) Date: Wed, 27 Apr 2016 11:31:02 +0200 Subject: how to create a dictionary from csv file? References: <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> Message-ID: Sibylle Koczian wrote: > Am 27.04.2016 um 04:42 schrieb jfong at ms4.hinet.net: >> Just curious:-) why everyone here open the csv file without using >> newline='' as suggested in Python 3.4.4 document section 14.1? Carelessness, lack of knowledge (I plead guilty), not on Windows and no embedded newline in sight? > And if the csv module is used anyway, why not simply read into a > DictReader? How would that help with looking up 3.5 by "apple" given the OP's sample data banana,4.0 apple,3.5 orange,3.0 ? Please give a code example. Finally, why would you think that asking rhetorical questions is a good way to communicate? From Joaquin.Alzola at lebara.com Wed Apr 27 05:32:22 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Wed, 27 Apr 2016 09:32:22 +0000 Subject: Basic Concepts In-Reply-To: References: Message-ID: >>> x = 4 >>> x + 5 9 -----Original Message----- From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com at python.org] On Behalf Of Smith Sent: 27 April 2016 10:29 To: python-list at python.org Subject: Basic Concepts Fill in the blanks to declare a variable, add 5 to it and print its value: >>> x = 4 >>> x_ = 5 >>> print_ Any suggestion ? Thanks -- https://mail.python.org/mailman/listinfo/python-list This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. From ldompeling at casema.nl Wed Apr 27 06:05:28 2016 From: ldompeling at casema.nl (ldompeling at casema.nl) Date: Wed, 27 Apr 2016 03:05:28 -0700 (PDT) Subject: newsreader pan could not find my post Message-ID: Hello, I post a message in comp.lang python, but with caching new articles in the newsreader pan I don't see my article. How can I contact the administrater or this group. Thanks From alister.ware at ntlworld.com Wed Apr 27 06:53:46 2016 From: alister.ware at ntlworld.com (alister) Date: Wed, 27 Apr 2016 10:53:46 GMT Subject: Basic Concepts References: Message-ID: <_S0Uy.149982$ae3.79926@fx40.am4> On Wed, 27 Apr 2016 11:29:12 +0200, Smith wrote: > Fill in the blanks to declare a variable, add 5 to it and print its > value: > > >>> x = 4 x_ = 5 print_ > > > Any suggestion ? > > Thanks 2 suggestions:- 1) Stay awake during your class so that you can complete basic homework assignments. 2) Try reading the online python tutorial which covers this type of basic operation (& much more). assistance with homework can be obtained her but only if you have made some effort, posted your code and given some explanation of why you think it is not working. even then you will get suggestions to steer you in the right direction rather than working code. -- The more a man is imbued with the ordered regularity of all events, the firmer becomes his conviction that there is no room left by the side of this ordered regularity for causes of a different nature. For him neither the rule of human nor the rule of divine will exists as an independent cause of natural events. To be sure, the doctrine of a personal God interfering with natural events could never be refuted, in the real sense, by science, for this doctrine can always take refuge in those domains in which scientific knowledge has not yet been able to set foot. But I am persuaded that such behavior on the part of the representatives of religion would not only be unworthy but also fatal. For a doctrine which is able to maintain itself not in clear light, but only in the dark, will of necessity lose its effect on mankind, with incalculable harm to human progress. In their struggle for the ethical good, teachers of religion must have the stature to give up the doctrine of a personal God, that is, give up that source of fear and hope which in the past placed such vast powers in the hands of priests. In their labors they will have to avail themselves of those forces which are capable of cultivating the Good, the True, and the Beautiful in humanity itself. This is, to be sure, a more difficult but an incomparably more worthy task. - Albert Einstein From tuli.herscovici at gmail.com Wed Apr 27 07:23:26 2016 From: tuli.herscovici at gmail.com (Pierre) Date: Wed, 27 Apr 2016 04:23:26 -0700 (PDT) Subject: Python(x,y) 64 bit Message-ID: <5a83e402-96f3-473f-9bac-1dc95922e940@googlegroups.com> Hello, I installed Python(x,y) 64 bit version and ran it using a library that requires Python 64 bit. I got an error which indicated that I am using Python 32 bit. So, is the python used by Python(x,y) 64 bit, using Python 64 or 32 bit? Thanks From steve at pearwood.info Wed Apr 27 08:04:01 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 27 Apr 2016 22:04:01 +1000 Subject: Basic Concepts References: Message-ID: <5720aab3$0$1611$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Apr 2016 07:29 pm, Smith wrote: > Fill in the blanks to declare a variable, add 5 to it and print its value: > > >>> x = 4 > >>> x_ = 5 > >>> print_ > > > Any suggestion ? Okay, you have a variable x with the value of 4: x = 4 How do you think you would print the value of x? Hint: here I print the value of z instead: print z -- Steven From peakgraphicz at gmail.com Wed Apr 27 08:23:10 2016 From: peakgraphicz at gmail.com (Adam Davis) Date: Wed, 27 Apr 2016 05:23:10 -0700 (PDT) Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> <49f4ffd8-d140-4f1b-95a9-75cb122e8b2f@googlegroups.com> Message-ID: <75d2b984-0a1e-42fa-bb3d-f698d4f5e0a1@googlegroups.com> On Wednesday, 27 April 2016 07:37:42 UTC+1, Chris Angelico wrote: > On Wed, Apr 27, 2016 at 4:26 PM, Adam Davis wrote: > > I understand what you're saying! But where you say: " the_set = set()", what would go within the set brackets? > > Nothing. The empty parentheses mean "call this with no arguments", and > when you call the set constructor like that, you get back an empty > set. > > ChrisA Thanks Chris. Where Ian says 'the_set.add(item)', what would be put within item in terms of my codes function/aim? From andrew.ongko at gmail.com Wed Apr 27 08:57:58 2016 From: andrew.ongko at gmail.com (Andrew Ongko) Date: Wed, 27 Apr 2016 19:57:58 +0700 Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> <49f4ffd8-d140-4f1b-95a9-75cb122e8b2f@googlegroups.com> <75d2b984-0a1e-42fa-bb3d-f698d4f5e0a1@googlegroups.com> Message-ID: On Apr 27, 2016 7:25 PM, "Adam Davis" wrote: > > On Wednesday, 27 April 2016 07:37:42 UTC+1, Chris Angelico wrote: > > On Wed, Apr 27, 2016 at 4:26 PM, Adam Davis wrote: > > > I understand what you're saying! But where you say: " the_set = set()", what would go within the set brackets? > > > > Nothing. The empty parentheses mean "call this with no arguments", and > > when you call the set constructor like that, you get back an empty > > set. > > > > ChrisA > > Thanks Chris. Where Ian says 'the_set.add(item)', what would be put within item in terms of my codes function/aim? item is name in your case. Since it's the one you care about existing or not. It would be like: Read from csv, For each row, the_set.add(name) Now that you have the_set in memory, whenever you want to check whether a particular name has taken the quiz, just do: if name in the_set: # forbid else: # allow Regards, Andrew From ian.g.kelly at gmail.com Wed Apr 27 10:24:02 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 27 Apr 2016 08:24:02 -0600 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? In-Reply-To: <57204EA6.7060007@stoneleaf.us> References: <5720357B.4060009@icloud.com> <57204EA6.7060007@stoneleaf.us> Message-ID: On Tue, Apr 26, 2016 at 11:31 PM, Ethan Furman wrote: > On 04/26/2016 08:43 PM, Christopher Reimer wrote: > >> If I'm using a dictionary to store variables for an object, and >> accessing the variable values from dictionary via property decorators, >> would it be better to derive the class from object or dict? >> >> class Test1(object): >> def __init__(self): >> self.state = {'key': 'value'} >> >> Or: >> >> class Test2(dict): >> def __init__(self): >> self.__dict__ = {'key', 'value'} >> >> I haven't seen a good pro/con discussion on the Internet for using one >> over the other. I played with both in my code. Doesn't seem to make a >> great difference either way. Using object seems to be the most simplest >> approach. > > > Using a dict gets you a bunch of methods for free: keys(), values(), > items(), get(), etc., etc.. You get those for free either way; in the first case you just have use self.state.keys() instead of self.keys(). The question boils down to composition versus inheritance, and the prevailing wisdom is to prefer composition. For me the discerning test is "do the things that are in this dict make sense as items contained by my object?" If the answer is yes, then go ahead and subclass from dict. More often, the answer is no. Some other great questions to ask yourself are "do I really want len(my_object) to return the number of items in this dict" and "do I really want list(my_object) to return all the keys in this dict"? If the answer to all those is yes, then it's probably fair to say that your object is-a dict and should be modeled as such. From ian.g.kelly at gmail.com Wed Apr 27 10:33:40 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 27 Apr 2016 08:33:40 -0600 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? In-Reply-To: <5720357B.4060009@icloud.com> References: <5720357B.4060009@icloud.com> Message-ID: On Tue, Apr 26, 2016 at 9:43 PM, Christopher Reimer wrote: > class Test2(dict): > def __init__(self): > self.__dict__ = {'key', 'value'} This class definition looks muddled. Because Test2 inherits from dict, the object referred to by "self" will be a dict, and self.__dict__ is actually a *different* dict, containing the attributes of self. The line: self.__dict__ = {'key', 'value'} is essentially equivalent to: self.key = value and will be regardless of whether you inherit from object or dict. If you find this distinction confusing, then I recommend not inheriting from dict. From zachary.ware+pylist at gmail.com Wed Apr 27 11:16:50 2016 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Wed, 27 Apr 2016 10:16:50 -0500 Subject: Python(x,y) 64 bit In-Reply-To: <5a83e402-96f3-473f-9bac-1dc95922e940@googlegroups.com> References: <5a83e402-96f3-473f-9bac-1dc95922e940@googlegroups.com> Message-ID: Hi Pierre, On Wed, Apr 27, 2016 at 6:23 AM, Pierre wrote: > Hello, > > I installed Python(x,y) 64 bit version and ran it using a library that requires Python 64 bit. > I got an error which indicated that I am using Python 32 bit. > > So, is the python used by Python(x,y) 64 bit, using Python 64 or 32 bit? You can check by doing `python -c "import sys;print(sys.maxsize == 2**63-1)"`. You'll get True for 64-bit, False for 32-bit. There's a possibility that you've gotten a misleading error message, though. What version of Python(x,y) are you using, and what library? -- Zach From durganaveen.usit at gmail.com Wed Apr 27 11:17:24 2016 From: durganaveen.usit at gmail.com (durganaveen.usit at gmail.com) Date: Wed, 27 Apr 2016 08:17:24 -0700 (PDT) Subject: urgent requirement DB2 with AIX or LINUX@ Foster City,CA Message-ID: <1b0139be-f9cc-4873-829c-5ca0ad15bcaa@googlegroups.com> This is Naveen from SAGE IT INC. Hope you are doing great. Please send me your updated resume if you're interested for this position Title: DB2 with AIX or LINUX Location: Foster City, CA Duration: 12+ Months Job Description Strong DB2 LUW V10 (AIX/LINUX) expertise combined with sharp conceptual and analytical thinking! Working knowledge of Hadoop is a big plus. The successful candidate should have a working experience with Large (multi-terabytes) systems on DB2. Working experience with hadoop and Oracle-based systems as it pertains to the Datawarehousing environment is big plus. Should have hands-on advanced trouble-shooting and performance tuning knowledge/experience; understand and be able to define different DB2 partitioning strategies; be able to provide 3rd and 4th level support. The responsibilities will include but they will not be limited to * Requirement gathering and performing capacity planning, database physical design, architecture and configuration of large infrastructures, developing complex shell scripts, preparing specifications and defining best practices and standards. * Provide database expertise to other Global Engineering and Application teams; represent DB Engineering in project planning, sizing, design and defining backup/recovery strategies. * The successful candidate should be adaptive to the Visa's agile environment! * Experience with IBM DB2 for LUW Database Editions 9.x and 10.x * Must have experience in administrating DB2 LUW in DPF (Partitioning) envrionment. * Experience in IBM DB2 applicances like ISAS is preferred. * Experience in shell scripting (.ksh,.bash) in AIX and Linux platforms. * Experience IBM DB2 for LUW backup and recovery processes * Experience in troubleshooting and supporting DB2 for LUW database instances. * Experience in multiple methods of data movement technologies like Import, Export, and Ingest. * Experience in DB2 LUW performance tuning methodologies. * Knowledge of DB2 for LUW high availability and DR solutions Thanks& Regards Durga Naveen SageIT IT Solutions INC cnaveen at sageitinc.net 972-996-0650 Extn 349 www.sageitinc.com From nulla.epistola at web.de Wed Apr 27 11:37:10 2016 From: nulla.epistola at web.de (Sibylle Koczian) Date: Wed, 27 Apr 2016 17:37:10 +0200 Subject: how to create a dictionary from csv file? In-Reply-To: References: <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> Message-ID: Am 27.04.2016 um 11:31 schrieb Peter Otten: > Sibylle Koczian wrote: > >> And if the csv module is used anyway, why not simply read into a >> DictReader? > > How would that help with looking up 3.5 by "apple" given the OP's sample > data > > banana,4.0 > apple,3.5 > orange,3.0 > Quite right, it wouldn't. Misread the problem, sorry. From nulla.epistola at web.de Wed Apr 27 11:37:10 2016 From: nulla.epistola at web.de (Sibylle Koczian) Date: Wed, 27 Apr 2016 17:37:10 +0200 Subject: how to create a dictionary from csv file? In-Reply-To: References: <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> Message-ID: Am 27.04.2016 um 11:31 schrieb Peter Otten: > Sibylle Koczian wrote: > >> And if the csv module is used anyway, why not simply read into a >> DictReader? > > How would that help with looking up 3.5 by "apple" given the OP's sample > data > > banana,4.0 > apple,3.5 > orange,3.0 > Quite right, it wouldn't. Misread the problem, sorry. From darnold992000 at yahoo.com Wed Apr 27 11:49:09 2016 From: darnold992000 at yahoo.com (darnold) Date: Wed, 27 Apr 2016 08:49:09 -0700 (PDT) Subject: Howw to prevent the duplication of any value in a column within a CSV file (python) In-Reply-To: References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> <49f4ffd8-d140-4f1b-95a9-75cb122e8b2f@googlegroups.com> <75d2b984-0a1e-42fa-bb3d-f698d4f5e0a1@googlegroups.com> Message-ID: potential_passengers = ['bob','john','sue','wendy','chris','bob','jen','wendy'] accepted_passengers = set() for name in potential_passengers: print('checking on {}...'.format(name)) if name not in accepted_passengers: accepted_passengers.add(name) print('welcome aboard, {}!'.format(name)) else: print('i am sorry, we have already accepted a {}.'.format(name)) print() HTH, Don From bharadwajsrivatsa at gmail.com Wed Apr 27 13:13:45 2016 From: bharadwajsrivatsa at gmail.com (bharadwajsrivatsa at gmail.com) Date: Wed, 27 Apr 2016 10:13:45 -0700 (PDT) Subject: Importerror: cannot import name httpshandler linux Message-ID: <44d6df49-1504-404f-b82a-b034c003b9d7@googlegroups.com> I tried installing Python 2.7.11 on HP-UX which already has all the build and run time dependencies installed on it such as openssl, libffi, etc. But after installing python , I tried installing some open source packages using pip. But pip thows the error: Importerror: cannot import name httpshandler linux. PLease help me out to resolve this. From best_lay at yahoo.com Wed Apr 27 15:29:29 2016 From: best_lay at yahoo.com (Wildman) Date: Wed, 27 Apr 2016 14:29:29 -0500 Subject: Importerror: cannot import name httpshandler linux References: <44d6df49-1504-404f-b82a-b034c003b9d7@googlegroups.com> Message-ID: On Wed, 27 Apr 2016 10:13:45 -0700, bharadwajsrivatsa wrote: > I tried installing Python 2.7.11 on HP-UX which already has all > the build and run time dependencies installed on it such as > openssl, libffi, etc. But after installing python , I tried > installing some open source packages using pip. But pip thows the error: > Importerror: cannot import name httpshandler linux. > > PLease help me out to resolve this. Try installing the libssl-dev package. -- GNU/Linux user #557453 The cow died so I don't need your bull! From tuli.herscovici at gmail.com Wed Apr 27 19:25:37 2016 From: tuli.herscovici at gmail.com (Pierre) Date: Wed, 27 Apr 2016 16:25:37 -0700 (PDT) Subject: Python(x,y) 64 bit In-Reply-To: References: <5a83e402-96f3-473f-9bac-1dc95922e940@googlegroups.com> Message-ID: <855cf4b8-71ea-4067-a091-f78f9622619c@googlegroups.com> On Wednesday, April 27, 2016 at 11:17:32 AM UTC-4, Zachary Ware wrote: > Hi Pierre, > > On Wed, Apr 27, 2016 at 6:23 AM, Pierre wrote: > > Hello, > > > > I installed Python(x,y) 64 bit version and ran it using a library that requires Python 64 bit. > > I got an error which indicated that I am using Python 32 bit. > > > > So, is the python used by Python(x,y) 64 bit, using Python 64 or 32 bit? > > You can check by doing `python -c "import sys;print(sys.maxsize == > 2**63-1)"`. You'll get True for 64-bit, False for 32-bit. There's a > possibility that you've gotten a misleading error message, though. > What version of Python(x,y) are you using, and what library? > > -- > Zach Zach, I did check and it looks like the Python(x,y) 64 distribution I downloaded uses a 32 bit Python. The question is if there is ANY Python(x,y) 64 distribution that uses the 64 bit python version. I looked it up online and could not find anything related to this issue From me+python at ixokai.io Wed Apr 27 19:48:22 2016 From: me+python at ixokai.io (Stephen Hansen) Date: Wed, 27 Apr 2016 16:48:22 -0700 Subject: Python(x,y) 64 bit In-Reply-To: <855cf4b8-71ea-4067-a091-f78f9622619c@googlegroups.com> References: <5a83e402-96f3-473f-9bac-1dc95922e940@googlegroups.com> <855cf4b8-71ea-4067-a091-f78f9622619c@googlegroups.com> Message-ID: <1461800902.3160464.591757537.60D52B21@webmail.messagingengine.com> On Wed, Apr 27, 2016, at 04:25 PM, Pierre wrote: > I did check and it looks like the Python(x,y) 64 distribution I > downloaded uses a 32 bit Python. > The question is if there is ANY Python(x,y) 64 distribution that uses the > 64 bit python version. > I looked it up online and could not find anything related to this issue I don't know anything about Python(x,y), but from their website it looks like it doesn't offer 64-bit python. Note, Python(x,y) is not affiliated with Python itself. That said, perhaps you should check out https://www.continuum.io/downloads which is the Anaconda scientific distribution, which I know does offer 64-bit Python support. --- Stephen Hansen m e @ i x o k a i . i o From me+python at ixokai.io Wed Apr 27 20:24:34 2016 From: me+python at ixokai.io (Stephen Hansen) Date: Wed, 27 Apr 2016 17:24:34 -0700 Subject: Python path and append In-Reply-To: References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> <571eca35$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1461803074.3168509.591776529.05ACF2C5@webmail.messagingengine.com> On Tue, Apr 26, 2016, at 07:56 PM, Seymore4Head wrote: > On Tue, 26 Apr 2016 11:53:57 +1000, Steven D'Aprano > wrote: > > >On Tue, 26 Apr 2016 08:04 am, Seymore4Head wrote: > > > >> BTW I was trying to use a line like yours that used an output file > >> that didn't exist and was getting an error. ?I assume that import os > >> fixes that. > > > > > >Why would you assume that? > > > > > >"Doctor, I have a problem with my arm, but I won't tell you what. I assume > >that if I take cough drops that will fix it." > > OK. Dumb question acknowledged. > > I got an error when I tried to write to a non existent file. I > "incorrectly" assumed wrong. That is going to be a common theme. Oh, he wasn't saying it was a dumb question. He was complaining you said you were "getting an error". That's not a dumb question, that's a useless report of a problem. If you don't say what exactly the error is, we can't help you. If you want help, the two best things to do are: 1) Show actual code. 2) Show actual, complete tracebacks. Having a nice description of what you expect to happen is often nice too, especially if its doing something "wrong" and not giving an obvious traceback. Seeing specifically what the wrong behavior is, and you explaining why you think its wrong, can be invaluable. -- Stephen Hansen m e @ i x o k a i . i o From apporvajain06 at gmail.com Wed Apr 27 20:45:54 2016 From: apporvajain06 at gmail.com (Apporva Jain) Date: Wed, 27 Apr 2016 17:45:54 -0700 (PDT) Subject: Big World, Big Data, Big Mind : Spark | Scala | Python Message-ID: Become proficient in both Scala and python to implement programming skills on Apache spark and have independent understanding of all three platforms Objectives: Understand the difference between Apache Spark and Hadoop Learn Scala and its programming implementation Implement Spark on a cluster Write Spark Applications using Python, Java and Scala Understand Module 4-RDD and its operation Learn common Spark Algorithms Define and explain Spark Streaming Execute Pattern Matching in Scala Understand Scala Java Interoperability Understand the purpose, importance and Installation of Python Get expertise in Python core Data types, Regular Expressions, Looping, and object Oriented Programming Master the concepts of File Operations, Functions, Special methods of defining a Class and SQLite in Python Take a quick overview on Panda Learn how to manage Hadoop File System Get an understanding on Server logs, Pig script and Work Flow Editor Work on a detailed Project on Web Logging in Python and Implement everything you learnt on a live Project Work on Minor and Major Projects applying programming techniques of Scala to run on Spark applications Start learning Spark | Scala | Python from basics to advance levels. https://goo.gl/4SEsJR From christopher_reimer at yahoo.com Wed Apr 27 21:12:02 2016 From: christopher_reimer at yahoo.com (Christopher Reimer) Date: Wed, 27 Apr 2016 18:12:02 -0700 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? In-Reply-To: <1461729360.3276080.590752673.7A6E1041@webmail.messagingengine.com> References: <5720357B.4060009@icloud.com> <1461729360.3276080.590752673.7A6E1041@webmail.messagingengine.com> Message-ID: <57216362.8060209@yahoo.com> On 4/26/2016 8:56 PM, Random832 wrote: > what exactly do you mean by property decorators? If you're just > accessing them in a dictionary what's the benefit over having the > values be simple attributes rather than properties? After considering the feedback I got for sanity checking my code, I've decided to simplify the base class for the chess pieces (see code below). All the variables are stored inside a dictionary with most values accessible through properties. A custom dictionary can be loaded through the constructor and or saved out through the fetch_state method. The subclasses only have to implement the is_move_valid method, which is different for each type of chess piece. Thank you, Chris R. class Piece(object): def __init__(self, color, position, state=None): if state is None: self._state = { 'class': self.__class__.__name__, 'color': color, 'first_move': True, 'initial_position': position, 'move_count': 0, 'name': color.title() + ' ' + self.__class__.__name__, 'notation': color.title()[:1] + self.__class__.__name__[:1], 'position': position } else: self._state = state @property def color(self): return self._state['color'] def fetch_state(self): return self._state def is_move_valid(self, new_position, board_state): raise NotImplementedError @property def move_count(self): return self._state['move_count'] @property def name(self): return self._state['name'] @property def notation(self): return self._state['notation'] @property def position(self): return self._state['position'] @position.setter def position(self, position): self._state['position'] = position if self._state['first_move']: self._state['first_move'] = False self._state['move_count'] += 1 From christopher_reimer at icloud.com Wed Apr 27 21:12:57 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Wed, 27 Apr 2016 18:12:57 -0700 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? Message-ID: <57216399.1050702@icloud.com> On 4/26/2016 8:56 PM, Random832 wrote: > what exactly do you mean by property decorators? If you're just > accessing them in a dictionary what's the benefit over having the > values be simple attributes rather than properties? After considering the feedback I got for sanity checking my code, I've decided to simplify the base class for the chess pieces (see code below). All the variables are stored inside a dictionary with most values accessible through properties. A custom dictionary can be loaded through the constructor and or saved out through the fetch_state method. The subclasses only have to implement the is_move_valid method, which is different for each type of chess piece. Thank you, Chris R. class Piece(object): def __init__(self, color, position, state=None): if state is None: self._state = { 'class': self.__class__.__name__, 'color': color, 'first_move': True, 'initial_position': position, 'move_count': 0, 'name': color.title() + ' ' + self.__class__.__name__, 'notation': color.title()[:1] + self.__class__.__name__[:1], 'position': position } else: self._state = state @property def color(self): return self._state['color'] def fetch_state(self): return self._state def is_move_valid(self, new_position, board_state): raise NotImplementedError @property def move_count(self): return self._state['move_count'] @property def name(self): return self._state['name'] @property def notation(self): return self._state['notation'] @property def position(self): return self._state['position'] @position.setter def position(self, position): self._state['position'] = position if self._state['first_move']: self._state['first_move'] = False self._state['move_count'] += 1 From christopher_reimer at icloud.com Wed Apr 27 21:21:05 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Wed, 27 Apr 2016 18:21:05 -0700 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? In-Reply-To: References: <5720357B.4060009@icloud.com> <57204EA6.7060007@stoneleaf.us> Message-ID: <57216581.1070603@icloud.com> On 4/27/2016 7:24 AM, Ian Kelly wrote: > Some other great questions to ask yourself are "do I really want > len(my_object) to return the number of items in this dict" and "do I > really want list(my_object) to return all the keys in this dict"? If > the answer to all those is yes, then it's probably fair to say that > your object is-a dict and should be modeled as such. These questions are more useful for me to consider. For my chess piece base class, the answer is no. Thank you, Chris R. From christopher_reimer at icloud.com Wed Apr 27 21:27:22 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Wed, 27 Apr 2016 18:27:22 -0700 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? In-Reply-To: References: <5720357B.4060009@icloud.com> Message-ID: <572166FA.3020108@icloud.com> On 4/27/2016 7:33 AM, Ian Kelly wrote: > This class definition looks muddled. Because Test2 inherits from dict, > the object referred to by "self" will be a dict, and self.__dict__ is > actually a *different* dict, containing the attributes of self. The > line: > > self.__dict__ = {'key', 'value'} > > is essentially equivalent to: > > self.key = value > > and will be regardless of whether you inherit from object or dict. If > you find this distinction confusing, then I recommend not inheriting > from dict. Which expression is Pythonic? I've seen both used in various examples on the Internet. Thank you, Chris R. From torriem at gmail.com Wed Apr 27 22:00:08 2016 From: torriem at gmail.com (Michael Torrie) Date: Wed, 27 Apr 2016 20:00:08 -0600 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? In-Reply-To: <57216399.1050702@icloud.com> References: <57216399.1050702@icloud.com> Message-ID: <57216EA8.4060600@gmail.com> On 04/27/2016 07:12 PM, Christopher Reimer wrote: > class Piece(object): > def __init__(self, color, position, state=None): > if state is None: > self._state = { > 'class': self.__class__.__name__, > 'color': color, > 'first_move': True, > 'initial_position': position, > 'move_count': 0, > 'name': color.title() + ' ' + self.__class__.__name__, > 'notation': color.title()[:1] + > self.__class__.__name__[:1], > 'position': position > } I am guessing that the reason you are storing state as it's own dictionary is so that you can pass the state itself to the constructor? > else: > self._state = state I'm not sure why you are storing the class name in self._state above, but keep in mind that this part of the constructor will just reference whatever was in the passed-in state object, whether it's right or wrong. So the value of self._state.class and self._state.notation may or may not be right, compared to what is set in the previous section if None is passed in. Also self._state = state means that the state object passed will be the self._state object. Not a copy, but the exact same object. So multiple instances could have the exact object as self._state. Not sure if this is what you intended or not. Personally I would ditch the self._state dictionary entirely and store the state directly as instance attributes. self.color, self.first_move, etc. For the constructor if you want to duplicate another object's state, just pass the entire object as an argument and copy the attributes manually, rather than passing around the state dict. I know you've stated reasons for doing things the way you have, but this self._state dict smells a bit funny, especially where you have self._state = state, which means that several instances could have the exact same state object at the same time and strikes me as mildly un-pythonic and very confusing. "State" is what instances themselves are supposed to track by design. I recommend you use this feature rather than duplicating it with your own error-prone dict handling. From ben+python at benfinney.id.au Wed Apr 27 22:07:58 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 28 Apr 2016 12:07:58 +1000 Subject: Pythonic style (was: Differences between Class(Object) and Class(Dict) for dictionary usage?) References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> Message-ID: <85y47yjxj5.fsf_-_@benfinney.id.au> Christopher Reimer writes: > On 4/27/2016 7:33 AM, Ian Kelly wrote: > > > self.__dict__ = {'key', 'value'} > > > > self.key = value > > Which expression is Pythonic? (Note that assignment is not an expression in Python; assigment is a statement.) > I've seen both used in various examples on the Internet. I would say the latter is more Pythonic, because it: * Better conveys the intention (?set the value of the ?self.key? attribute?). * Uses the built-in mechanisms of Python (don't invoke magic attributes, instead use the system that makes use of them behind the scenes). * Expresses that intention more concisely (fewer terms). * Expresses that intention more clearly (less syntactic noise). -- \ ?Nothing so needs reforming as other people's habits.? ?Mark | `\ Twain, _Pudd'n'head Wilson_ | _o__) | Ben Finney From christopher_reimer at icloud.com Wed Apr 27 22:49:15 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Wed, 27 Apr 2016 19:49:15 -0700 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? In-Reply-To: <57216EA8.4060600@gmail.com> References: <57216399.1050702@icloud.com> <57216EA8.4060600@gmail.com> Message-ID: <57217A2B.4060709@icloud.com> On 4/27/2016 7:00 PM, Michael Torrie wrote: > I am guessing that the reason you are storing state as it's own > dictionary is so that you can pass the state itself to the constructor? Someone said it was bad to store the object itself to file (my original plan) and that I should use a dictionary instead. This is my implementation of that idea. However, saving and loading data is far down my to do list. > I know you've stated reasons for doing things the way you have, but > this self._state dict smells a bit funny, especially where you have > self._state = state, which means that several instances could have the > exact same state object at the same time and strikes me as mildly > un-pythonic and very confusing. "State" is what instances themselves > are supposed to track by design. I recommend you use this feature > rather than duplicating it with your own error-prone dict handling. So far the code is working as designed for new chess pieces (see below). Thank you, Chris R. Rook('white', (1, 1)) @ 2106251742008 Knight('white', (1, 2)) @ 2106251755648 Bishop('white', (1, 3)) @ 2106251755760 Queen('white', (1, 4)) @ 2106251755872 King('white', (1, 5)) @ 2106251755984 Bishop('white', (1, 6)) @ 2106251756096 Knight('white', (1, 7)) @ 2106251756208 Rook('white', (1, 8)) @ 2106251756320 Pawn('white', (2, 1)) @ 2106251756432 Pawn('white', (2, 2)) @ 2106251756544 Pawn('white', (2, 3)) @ 2106251756656 Pawn('white', (2, 4)) @ 2106251756768 Pawn('white', (2, 5)) @ 2106251756880 Pawn('white', (2, 6)) @ 2106251756992 Pawn('white', (2, 7)) @ 2106251757104 Pawn('white', (2, 8)) @ 2106251757216 Pawn('black', (7, 1)) @ 2106251742288 Pawn('black', (7, 2)) @ 2106251742400 Pawn('black', (7, 3)) @ 2106251742512 Pawn('black', (7, 4)) @ 2106251742624 Pawn('black', (7, 5)) @ 2106251742736 Pawn('black', (7, 6)) @ 2106251742848 Pawn('black', (7, 7)) @ 2106251742960 Pawn('black', (7, 8)) @ 2106251743072 Rook('black', (8, 1)) @ 2106251743184 Knight('black', (8, 2)) @ 2106251742120 Bishop('black', (8, 3)) @ 2106251740608 Queen('black', (8, 4)) @ 2106251740496 King('black', (8, 5)) @ 2106251740832 Bishop('black', (8, 6)) @ 2106251741672 Knight('black', (8, 7)) @ 2106251741784 Rook('black', (8, 8)) @ 2106251741896 From ethan at stoneleaf.us Wed Apr 27 23:05:27 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 27 Apr 2016 20:05:27 -0700 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? In-Reply-To: <57216399.1050702@icloud.com> References: <57216399.1050702@icloud.com> Message-ID: <57217DF7.1030509@stoneleaf.us> On 04/27/2016 06:12 PM, Christopher Reimer wrote: > After considering the feedback I got for sanity checking my code, I've > decided to simplify the base class for the chess pieces (see code > below). All the variables are stored inside a dictionary with most > values accessible through properties. A custom dictionary can be loaded > through the constructor and or saved out through the fetch_state method. > The subclasses only have to implement the is_move_valid method, which is > different for each type of chess piece. Much better. Here's my take on it: class Piece(object): def __init__(self, color, position): self._color = color self._first_move = True self._initial_position = position self._move_count = 0 self._name = color.title() + ' ' + self.__class__.__name__ self._notation = color.title()[:1] + self.__class__.__name__[:1] self._position = position @property def color(self): return self._color def is_move_valid(self, new_position, board_state): raise NotImplementedError @property def move_count(self): return self._move_count @property def name(self): return self._name @property def notation(self): return self._notation @property def position(self): return self._position @position.setter def position(self, position): self._position = position if self._first_move: self._first_move = False self._move_count += 1 Now all the attributes are, well, attributes of the instance (that's what instances are for). I ripped out the fetch_state because that will take more work -- you can't pass a Pawn's saved state in to Piece and get the results you want. pickle is worth looking at for saving/restoring. Also, your code will give the same notation to Kings and Knights. -- ~Ethan~ From christopher_reimer at icloud.com Wed Apr 27 23:07:31 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Wed, 27 Apr 2016 20:07:31 -0700 Subject: Pythonic style (was: Differences between Class(Object) and Class(Dict) for dictionary usage?) In-Reply-To: <85y47yjxj5.fsf_-_@benfinney.id.au> References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> Message-ID: <57217E73.9040907@icloud.com> On 4/27/2016 7:07 PM, Ben Finney wrote: > I would say the latter is more Pythonic, because it: > > * Better conveys the intention (?set the value of the ?self.key? > attribute?). > > * Uses the built-in mechanisms of Python (don't invoke magic attributes, > instead use the system that makes use of them behind the scenes). > > * Expresses that intention more concisely (fewer terms). > > * Expresses that intention more clearly (less syntactic noise). In short, my original code before I turned it into a separate dictionary. *sigh* Thank you, Chris R. From ben+python at benfinney.id.au Wed Apr 27 23:23:31 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 28 Apr 2016 13:23:31 +1000 Subject: Pythonic style References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> Message-ID: <85twimju18.fsf@benfinney.id.au> Christopher Reimer writes: > In short, my original code before I turned it into a separate > dictionary. *sigh* No, I think that misses the points that were being made. The discussion you're talking about was *not* to say ?attribute access is better than dictionary access?, or vice versa. Each is good for its purpose. Rather, the discussion was to drive home the point that in Python those are *two distinct concepts*, and you need to not conflate them. If you want items in a mapping, explicitly use a Python ?dict? instance. If you want attributes that describe an object, explicitly use attributes of that object. Deliberately choose which one makes more sense. -- \ ?The double standard that exempts religious activities from | `\ almost all standards of accountability should be dismantled | _o__) once and for all.? ?Daniel Dennett, 2010-01-12 | Ben Finney From ethan at stoneleaf.us Wed Apr 27 23:52:24 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 27 Apr 2016 20:52:24 -0700 Subject: Pythonic style In-Reply-To: <57217E73.9040907@icloud.com> References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> Message-ID: <572188F8.7010304@stoneleaf.us> On 04/27/2016 08:07 PM, Christopher Reimer wrote: > On 4/27/2016 7:07 PM, Ben Finney wrote: >> Ian Kelly wrote: >>> self.__dict__ = {'key', 'value'} >>> >>> is essentially equivalent to: >>> >>> self.key = value >> >> I would say the latter is more Pythonic, because it: >> >> [snip] >> >> * Uses the built-in mechanisms of Python (don't invoke magic attributes, >> instead use the system that makes use of them behind the scenes). > > In short, my original code before I turned it into a separate > dictionary. *sigh* No. The point Ben was trying to make is this: you should never* call __dunder__ methods in normal code; there is no need to do so: - use len(), not __len__() - use next(), not __next__() - use some_instance.an_attribute, not some_instance.__dict__['an_attribute'] -- ~Ethan~ * Okay, maybe /almost/ never. About the only time you need to is when giving your classes special methods, such as __add__ or __repr__. From torriem at gmail.com Wed Apr 27 23:52:37 2016 From: torriem at gmail.com (Michael Torrie) Date: Wed, 27 Apr 2016 21:52:37 -0600 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? In-Reply-To: <57217A2B.4060709@icloud.com> References: <57216399.1050702@icloud.com> <57216EA8.4060600@gmail.com> <57217A2B.4060709@icloud.com> Message-ID: <57218905.5090807@gmail.com> On 04/27/2016 08:49 PM, Christopher Reimer wrote: > On 4/27/2016 7:00 PM, Michael Torrie wrote: >> I am guessing that the reason you are storing state as it's own >> dictionary is so that you can pass the state itself to the constructor? > > Someone said it was bad to store the object itself to file (my original > plan) and that I should use a dictionary instead. This is my > implementation of that idea. However, saving and loading data is far > down my to do list. Pickle should be able to serialize an object that stores state as attributes, as that's what objects normally do. But you could also serialize and save the objects yourself manually too. In fact if it were me I would save game state to some kind of ini file, which would mean manually going through each object and writing out the relevant data to the ini file using the right syntax. And then reverse the process when restoring from a file. XML could be another format used for your file, if you're into that kind of thing. From christopher_reimer at icloud.com Wed Apr 27 23:53:00 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Wed, 27 Apr 2016 20:53:00 -0700 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? In-Reply-To: <57217DF7.1030509@stoneleaf.us> References: <57216399.1050702@icloud.com> <57217DF7.1030509@stoneleaf.us> Message-ID: <5721891C.1090904@icloud.com> On 4/27/2016 8:05 PM, Ethan Furman wrote: > I ripped out the fetch_state because that will take more work -- you > can't pass a Pawn's saved state in to Piece and get the results you > want. pickle is worth looking at for saving/restoring. The original idea was to pass a Pawn dictionary to the constructor of the Pawn object. The Piece object will throw a NotImplementedError if called directly. I guess I'll have to look at pickle sooner rather than later. > Also, your code will give the same notation to Kings and Knights. Good catch. I knew I was forgetting something. I overrode variable in the Knight class to produce the correct notation. Thank you, Chris R. From rosuav at gmail.com Wed Apr 27 23:56:05 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Apr 2016 13:56:05 +1000 Subject: Pythonic style In-Reply-To: <572188F8.7010304@stoneleaf.us> References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <572188F8.7010304@stoneleaf.us> Message-ID: On Thu, Apr 28, 2016 at 1:52 PM, Ethan Furman wrote: > > The point Ben was trying to make is this: you should never* call __dunder__ > methods in normal code; there is no need to do so: > > - use len(), not __len__() > - use next(), not __next__() > - use some_instance.an_attribute, not some_instance.__dict__['an_attribute'] > > -- > ~Ethan~ > > * Okay, maybe /almost/ never. About the only time you need to is when > giving your classes special methods, such as __add__ or __repr__. My rule of thumb is: Dunders are for defining, not for calling. It's not a hard-and-fast rule, but it'll get you through 99%+ of situations. ChrisA From christopher_reimer at icloud.com Thu Apr 28 00:00:44 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Wed, 27 Apr 2016 21:00:44 -0700 Subject: Pythonic style In-Reply-To: <85twimju18.fsf@benfinney.id.au> References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <85twimju18.fsf@benfinney.id.au> Message-ID: <57218AEC.6020302@icloud.com> On 4/27/2016 8:23 PM, Ben Finney wrote: > If you want items in a mapping, explicitly use a Python ?dict? instance. > If you want attributes that describe an object, explicitly use > attributes of that object. Deliberately choose which one makes more > sense. Okay, that makes sense. Thank you, Chris R. From christopher_reimer at icloud.com Thu Apr 28 00:03:58 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Wed, 27 Apr 2016 21:03:58 -0700 Subject: Pythonic style In-Reply-To: <572188F8.7010304@stoneleaf.us> References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <572188F8.7010304@stoneleaf.us> Message-ID: <57218BAE.1030408@icloud.com> On 4/27/2016 8:52 PM, Ethan Furman wrote: > > The point Ben was trying to make is this: you should never* call > __dunder__ methods in normal code; there is no need to do so: > > - use len(), not __len__() > - use next(), not __next__() > - use some_instance.an_attribute, not > some_instance.__dict__['an_attribute'] > DOH! I need a doughnut. :) Thank you, Chris R. From christopher_reimer at icloud.com Thu Apr 28 00:06:26 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Wed, 27 Apr 2016 21:06:26 -0700 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? In-Reply-To: <57218905.5090807@gmail.com> References: <57216399.1050702@icloud.com> <57216EA8.4060600@gmail.com> <57217A2B.4060709@icloud.com> <57218905.5090807@gmail.com> Message-ID: <57218C42.5040804@icloud.com> On 4/27/2016 8:52 PM, Michael Torrie wrote: > In fact if it were me I would save game state to some kind of ini file, > which would mean manually going through each object and writing out the > relevant data to the ini file using the right syntax. And then reverse > the process when restoring from a file. XML could be another format > used for your file, if you're into that kind of thing. Funny that you should mention the ini file. I wrote a ConfigParser class for my const['whatever'] variable. It wouldn't take much to use that in the meantime until I get a handle on pickle. Thank you, Chris R. From torriem at gmail.com Thu Apr 28 00:23:56 2016 From: torriem at gmail.com (Michael Torrie) Date: Wed, 27 Apr 2016 22:23:56 -0600 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? In-Reply-To: <57218C42.5040804@icloud.com> References: <57216399.1050702@icloud.com> <57216EA8.4060600@gmail.com> <57217A2B.4060709@icloud.com> <57218905.5090807@gmail.com> <57218C42.5040804@icloud.com> Message-ID: <5721905C.4040901@gmail.com> On 04/27/2016 10:06 PM, Christopher Reimer wrote: > On 4/27/2016 8:52 PM, Michael Torrie wrote: >> In fact if it were me I would save game state to some kind of ini file, >> which would mean manually going through each object and writing out the >> relevant data to the ini file using the right syntax. And then reverse >> the process when restoring from a file. XML could be another format >> used for your file, if you're into that kind of thing. > > Funny that you should mention the ini file. I wrote a ConfigParser class > for my const['whatever'] variable. It wouldn't take much to use that in > the meantime until I get a handle on pickle. I'm not sure pickle is the way to go anyway. Especially for your purposes. Definitely you could make a ConfigParser that could read and write your object instances. From gengyangcai at gmail.com Thu Apr 28 00:37:47 2016 From: gengyangcai at gmail.com (Cai Gengyang) Date: Wed, 27 Apr 2016 21:37:47 -0700 (PDT) Subject: Python Madlibs.py code and error message Message-ID: <3cff626c-28a2-499c-9877-de2df4d459d0@googlegroups.com> Python Madlibs.py code and error message --- Anyone can help? I keep getting stuck here ... # This program does the following ... writes a Mad Libs story # Author: Cai Gengyang print "Mad Libs is starting!" name = raw_input("Enter a name: ") adjective1 = raw_input("Enter an adjective: ") adjective2 = raw_input("Enter a second adjective: ") adjective3 = raw_input("Enter a third adjective: ") verb1 = raw_input("Enter a verb: ") verb2 = raw_input("Enter a second verb: ") verb3 = raw_input("Enter a third verb: ") noun1 = raw_input("Enter a noun: ") noun2 = raw_input("Enter a noun: ") noun3 = raw_input("Enter a noun: ") noun4 = raw_input("Enter a noun: ") animal = raw_input("Enter an animal: ") food = raw_input("Enter a food: ") fruit = raw_input("Enter a fruit: ") number = raw_input("Enter a number: ") superhero_name = raw_input("Enter a superhero_name: ") country = raw_input("Enter a country: ") dessert = raw_input("Enter a dessert: ") year = raw_input("Enter a year: ") #The template for the story STORY = "This morning I woke up and felt %s because _ was going to finally %s over the big _ %s. On the other side of the %s were many %ss protesting to keep %s in stores. The crowd began to _ to the rythym of the %s, which made all of the %ss very _. %s tried to _ into the sewers and found %s rats. Needing help, %s quickly called %s. %s appeared and saved %s by flying to %s and dropping _ into a puddle of %s. %s then fell asleep and woke up in the year _, in a world where %ss ruled the world." print STORY % (Adjective1, name, Verb1, Adjective2, Noun1, Noun2, animal, food, Verb2, Noun3, fruit, Adjective3, name, Verb3, number, name , superhero_name, superhero_name, name, country, name, dessert, name, year, Noun4) Terminal Output : $ python Madlibs.py Mad Libs is starting! Enter a name: Cai Gengyang Enter an adjective: beautiful Enter a second adjective: honest Enter a third adjective: huge Enter a verb: hit Enter a second verb: run Enter a third verb: jump Enter a noun: anger Enter a noun: belief Enter a noun: wealth Enter a noun: regret Enter an animal: elephant Enter a food: burger Enter a fruit: watermelon Enter a number: 6 Enter a superhero_name: batman Enter a country: America Enter a dessert: icekachang Enter a year: 1984 Traceback (most recent call last): File "Madlibs.py", line 34, in print STORY % (Adjective1, name, Verb1, Adjective2, Noun1, Noun2, an imal, food, Verb2, Noun3, fruit, Adj ective3, name, Verb3, number, name , superhero_name, superhero_name, nam e, country, name, dessert, name, yea r, Noun4) NameError: name 'Adjective1' is not defined From greg.ewing at canterbury.ac.nz Thu Apr 28 00:50:15 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 28 Apr 2016 16:50:15 +1200 Subject: Python Madlibs.py code and error message In-Reply-To: <3cff626c-28a2-499c-9877-de2df4d459d0@googlegroups.com> References: <3cff626c-28a2-499c-9877-de2df4d459d0@googlegroups.com> Message-ID: Cai Gengyang wrote: > adjective1 = raw_input("Enter an adjective: ") > > NameError: name 'Adjective1' is not defined Python is case-sensitive. You've spelled it "adjective1" in one place and "Adjective1" in another. You need to be consistent. -- Greg From me+python at ixokai.io Thu Apr 28 00:55:59 2016 From: me+python at ixokai.io (Stephen Hansen) Date: Wed, 27 Apr 2016 21:55:59 -0700 Subject: Python Madlibs.py code and error message In-Reply-To: <3cff626c-28a2-499c-9877-de2df4d459d0@googlegroups.com> References: <3cff626c-28a2-499c-9877-de2df4d459d0@googlegroups.com> Message-ID: <1461819359.3234904.591932537.54A7076B@webmail.messagingengine.com> On Wed, Apr 27, 2016, at 09:37 PM, Cai Gengyang wrote: > print STORY % (Adjective1, name, Verb1, Adjective2, Noun1, Noun2, animal, > food, Verb2, Noun3, fruit, Adjective3, name, Verb3, number, name , > superhero_name, superhero_name, name, country, name, dessert, name, year, > Noun4) Python is case-sensitive. "Adjective1" and "adjective1" are separate things. In your code you're reading into "adjective1". -- Stephen Hansen m e @ i x o k a i . i o From gengyangcai at gmail.com Thu Apr 28 01:01:21 2016 From: gengyangcai at gmail.com (Cai Gengyang) Date: Wed, 27 Apr 2016 22:01:21 -0700 (PDT) Subject: Python Madlibs.py code and error message In-Reply-To: References: <3cff626c-28a2-499c-9877-de2df4d459d0@googlegroups.com> Message-ID: <6c0d96c5-c7f5-4659-a2e9-20f8d202d701@googlegroups.com> I changed it to all lowercase, this time I get a different error message though (a TypeError message) # This program does the following ... writes a Mad Libs story # Author: Cai Gengyang print "Mad Libs is starting!" name = raw_input("Enter a name: ") adjective1 = raw_input("Enter an adjective: ") adjective2 = raw_input("Enter a second adjective: ") adjective3 = raw_input("Enter a third adjective: ") verb1 = raw_input("Enter a verb: ") verb2 = raw_input("Enter a second verb: ") verb3 = raw_input("Enter a third verb: ") noun1 = raw_input("Enter a noun: ") noun2 = raw_input("Enter a noun: ") noun3 = raw_input("Enter a noun: ") noun4 = raw_input("Enter a noun: ") animal = raw_input("Enter an animal: ") food = raw_input("Enter a food: ") fruit = raw_input("Enter a fruit: ") number = raw_input("Enter a number: ") superhero_name = raw_input("Enter a superhero_name: ") country = raw_input("Enter a country: ") dessert = raw_input("Enter a dessert: ") year = raw_input("Enter a year: ") #The template for the story STORY = "This morning I woke up and felt %s because _ was going to finally %s over the big _ %s. On the other side of the %s were many %ss protesting to keep %s in stores. The crowd began to _ to the rythym of the %s, which made all of the %ss very _. %s tried to _ into the sewers and found %s rats. Needing help, %s quickly called %s. %s appeared and saved %s by flying to %s and dropping _ into a puddle of %s. %s then fell asleep and woke up in the year _, in a world where %ss ruled the world." print STORY % (adjective1, name, verb1, adjective2, noun1, noun2, animal, food, verb2, noun3, fruit, adjective3, name, verb3, number, name , superhero_name, superhero_name, name, country, name, dessert, name, year, noun4) Terminal Output : $ python Madlibs.py Mad Libs is starting! Enter a name: andrew Enter an adjective: beautiful Enter a second adjective: honest Enter a third adjective: pretty Enter a verb: hit Enter a second verb: run Enter a third verb: fire Enter a noun: honesty Enter a noun: love Enter a noun: peace Enter a noun: wisdom Enter an animal: elephant Enter a food: burger Enter a fruit: watermelon Enter a number: 1985 Enter a superhero_name: batman Enter a country: america Enter a dessert: icekachang Enter a year: 1982 Traceback (most recent call last): File "Madlibs.py", line 34, in print STORY % (adjective1, name, verb1, adjective2, noun1, noun2, an imal, food, verb2, noun3, fruit, adj ective3, name, verb3, number, name , superhero_name, superhero_name, nam e, country, name, dessert, name, yea r, noun4) TypeError: not all arguments converted during string formatting On Thursday, April 28, 2016 at 12:50:28 PM UTC+8, Gregory Ewing wrote: > Cai Gengyang wrote: > > > adjective1 = raw_input("Enter an adjective: ") > > > > NameError: name 'Adjective1' is not defined > > Python is case-sensitive. You've spelled it "adjective1" in one > place and "Adjective1" in another. You need to be consistent. > > -- > Greg From rustompmody at gmail.com Thu Apr 28 01:16:40 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 27 Apr 2016 22:16:40 -0700 (PDT) Subject: Pythonic style In-Reply-To: References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <572188F8.7010304@stoneleaf.us> Message-ID: On Thursday, April 28, 2016 at 9:26:21 AM UTC+5:30, Chris Angelico wrote: > My rule of thumb is: Dunders are for defining, not for calling. It's > not a hard-and-fast rule, but it'll get you through 99%+ of > situations. Neat and clever. Should get in the docs somewhere From me+python at ixokai.io Thu Apr 28 01:16:57 2016 From: me+python at ixokai.io (Stephen Hansen) Date: Wed, 27 Apr 2016 22:16:57 -0700 Subject: Python Madlibs.py code and error message In-Reply-To: <6c0d96c5-c7f5-4659-a2e9-20f8d202d701@googlegroups.com> References: <3cff626c-28a2-499c-9877-de2df4d459d0@googlegroups.com> <6c0d96c5-c7f5-4659-a2e9-20f8d202d701@googlegroups.com> Message-ID: <1461820617.3238425.591942249.1484DAC3@webmail.messagingengine.com> On Wed, Apr 27, 2016, at 10:01 PM, Cai Gengyang wrote: > I changed it to all lowercase, this time I get a different error message > though (a TypeError message) The error message means there's a mismatch between the number of formatting instructions (ie, %s) and arguments passed to formatting. I leave it to you to count and find what's missing or extra, because I'm seriously not going to do that :) -- Stephen Hansen m e @ i x o k a i . i o From steve+comp.lang.python at pearwood.info Thu Apr 28 01:31:55 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 28 Apr 2016 15:31:55 +1000 Subject: Pythonic style References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <85twimju18.fsf@benfinney.id.au> Message-ID: <5721a04d$0$2781$c3e8da3$76491128@news.astraweb.com> On Thursday 28 April 2016 13:23, Ben Finney wrote: > Christopher Reimer writes: > >> In short, my original code before I turned it into a separate >> dictionary. *sigh* > > No, I think that misses the points that were being made. The discussion > you're talking about was *not* to say ?attribute access is better than > dictionary access?, or vice versa. Each is good for its purpose. > > Rather, the discussion was to drive home the point that in Python those > are *two distinct concepts*, and you need to not conflate them. > > If you want items in a mapping, explicitly use a Python ?dict? instance. > If you want attributes that describe an object, explicitly use > attributes of that object. Deliberately choose which one makes more > sense. Think of it like this: attribute access is for accessing parts of a thing: dog.tail car.engine cup.handle or one of a small number of fixed fields from a record: employment_record.start_date employee.salary autopsy.cause_of_death person.title Mappings (dicts) are for recording a potentially unlimited number of distinct records with arbitrary keys, especially since the keys don't have to be valid identifiers: employees['Fred Smith'] students['Joanna McTavish'] prisoners[12345] catalog['Widgets']['GMH-12345'] dictionary['update'] While Python allows you to write code to use attribute syntax for item access, doing so is a category mistake and leads to semantic confusion and potential bugs: employees.Fred_Smith students.Joanna_McTavish prisoners.P12345 parts.widgets.GMH_12345 dictionary.update The last example shows how mixing up these two distinct concepts can lead to problems. Should dictionary.update refer to the update method, or the entry for the word "update"? -- Steve From ben+python at benfinney.id.au Thu Apr 28 01:32:51 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 28 Apr 2016 15:32:51 +1000 Subject: Python Madlibs.py code and error message References: <3cff626c-28a2-499c-9877-de2df4d459d0@googlegroups.com> <6c0d96c5-c7f5-4659-a2e9-20f8d202d701@googlegroups.com> <1461820617.3238425.591942249.1484DAC3@webmail.messagingengine.com> Message-ID: <85fuu6jo1o.fsf@benfinney.id.au> Stephen Hansen writes: > The error message means there's a mismatch between the number of > formatting instructions (ie, %s) and arguments passed to formatting. I > leave it to you to count and find what's missing or extra, because I'm > seriously not going to do that :) Better: when you have many semantically-different values, use named (not positional) parameters in the format string. Some simple format string examples: "First, thou shalt count to {0}" # References first positional argument "Bring me a {}" # Implicitly references the first positional argument "From {} to {}" # Same as "From {0} to {1}" "My quest is {name}" # References keyword argument 'name' [?] By using names, you will not need to count positional arguments; and when there's an error, the error will state the name, making it easier to debug. Also feasible with ?%? syntax. But, if you're writing new code, you may as well use the more powerful ?str.format? described at that URL. -- \ ?To have the choice between proprietary software packages, is | `\ being able to choose your master. Freedom means not having a | _o__) master.? ?Richard M. Stallman, 2007-05-16 | Ben Finney From ethan at stoneleaf.us Thu Apr 28 02:12:58 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 27 Apr 2016 23:12:58 -0700 Subject: Differences between Class(Object) and Class(Dict) for dictionary usage? In-Reply-To: <57218C42.5040804@icloud.com> References: <57216399.1050702@icloud.com> <57216EA8.4060600@gmail.com> <57217A2B.4060709@icloud.com> <57218905.5090807@gmail.com> <57218C42.5040804@icloud.com> Message-ID: <5721A9EA.1050205@stoneleaf.us> On 04/27/2016 09:06 PM, Christopher Reimer wrote: > On 4/27/2016 8:52 PM, Michael Torrie wrote: >> In fact if it were me I would save game state to some kind of ini file, >> which would mean manually going through each object and writing out the >> relevant data to the ini file using the right syntax. And then reverse >> the process when restoring from a file. XML could be another format >> used for your file, if you're into that kind of thing. > > Funny that you should mention the ini file. I wrote a ConfigParser class > for my const['whatever'] variable. It wouldn't take much to use that in > the meantime until I get a handle on pickle. If you are saving chess game state, you should look at the Portable Game Notation format: https://en.wikipedia.org/wiki/Portable_Game_Notation -- ~Ethan~ From me at ixokai.io Thu Apr 28 02:50:46 2016 From: me at ixokai.io (Stephen Hansen) Date: Wed, 27 Apr 2016 23:50:46 -0700 Subject: Python Madlibs.py code and error message In-Reply-To: <85fuu6jo1o.fsf@benfinney.id.au> References: <3cff626c-28a2-499c-9877-de2df4d459d0@googlegroups.com> <6c0d96c5-c7f5-4659-a2e9-20f8d202d701@googlegroups.com> <1461820617.3238425.591942249.1484DAC3@webmail.messagingengine.com> <85fuu6jo1o.fsf@benfinney.id.au> Message-ID: <1461826246.3257796.591992793.54C5CC58@webmail.messagingengine.com> On Wed, Apr 27, 2016, at 10:32 PM, Ben Finney wrote: > Stephen Hansen writes: > > > The error message means there's a mismatch between the number of > > formatting instructions (ie, %s) and arguments passed to formatting. I > > leave it to you to count and find what's missing or extra, because I'm > > seriously not going to do that :) > > Better: when you have many semantically-different values, use named (not > positional) parameters in the format string. > > Some simple format string examples: > > "First, thou shalt count to {0}" # References first positional > argument > "Bring me a {}" # Implicitly references the first > positional argument > "From {} to {}" # Same as "From {0} to {1}" > "My quest is {name}" # References keyword argument 'name' > [?] > > Except the poster is not using Python 3, so all of this is for naught. -- Stephen Hansen m e @ i x o k a i . i o From ben+python at benfinney.id.au Thu Apr 28 02:55:38 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 28 Apr 2016 16:55:38 +1000 Subject: Python Madlibs.py code and error message References: <3cff626c-28a2-499c-9877-de2df4d459d0@googlegroups.com> <6c0d96c5-c7f5-4659-a2e9-20f8d202d701@googlegroups.com> <1461820617.3238425.591942249.1484DAC3@webmail.messagingengine.com> <85fuu6jo1o.fsf@benfinney.id.au> <1461826246.3257796.591992793.54C5CC58@webmail.messagingengine.com> Message-ID: <85bn4ujk7p.fsf@benfinney.id.au> Stephen Hansen writes: > On Wed, Apr 27, 2016, at 10:32 PM, Ben Finney wrote: > > Better: when you have many semantically-different values, use named > > (not positional) parameters in the format string. [?] > > > > > > Except the poster is not using Python 3, so all of this is for naught. Everything I described above works fine in Python 2. Any still-supported version has ?str.format?. -- \ ?The deepest sin against the human mind is to believe things | `\ without evidence.? ?Thomas Henry Huxley, _Evolution and | _o__) Ethics_, 1893 | Ben Finney From me at ixokai.io Thu Apr 28 03:08:50 2016 From: me at ixokai.io (Stephen Hansen) Date: Thu, 28 Apr 2016 00:08:50 -0700 Subject: Python Madlibs.py code and error message In-Reply-To: <85bn4ujk7p.fsf@benfinney.id.au> References: <3cff626c-28a2-499c-9877-de2df4d459d0@googlegroups.com> <6c0d96c5-c7f5-4659-a2e9-20f8d202d701@googlegroups.com> <1461820617.3238425.591942249.1484DAC3@webmail.messagingengine.com> <85fuu6jo1o.fsf@benfinney.id.au> <1461826246.3257796.591992793.54C5CC58@webmail.messagingengine.com> <85bn4ujk7p.fsf@benfinney.id.au> Message-ID: <1461827330.3261212.591998673.4D215991@webmail.messagingengine.com> On Wed, Apr 27, 2016, at 11:55 PM, Ben Finney wrote: > Stephen Hansen writes: > > > On Wed, Apr 27, 2016, at 10:32 PM, Ben Finney wrote: > > > Better: when you have many semantically-different values, use named > > > (not positional) parameters in the format string. [?] > > > > > > > > > > Except the poster is not using Python 3, so all of this is for naught. > > Everything I described above works fine in Python 2. Any still-supported > version has ?str.format?. This response is completely unhelpful. The OP is using Python 2, and using %-formatting, and so you give a series of examples of using str.format, to, what? Confuse matters? You can show using non-positional values using the format the user is using -- "%(name)s" formatting. You even reference a link to the Python 3 docs, even though the OP is running code which isn't 3.x compatible. Confusion. Wishing Python2 away isn't helpful. -- Stephen Hansen m e @ i x o k a i . i o From ben+python at benfinney.id.au Thu Apr 28 03:17:47 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 28 Apr 2016 17:17:47 +1000 Subject: Python Madlibs.py code and error message References: <3cff626c-28a2-499c-9877-de2df4d459d0@googlegroups.com> <6c0d96c5-c7f5-4659-a2e9-20f8d202d701@googlegroups.com> <1461820617.3238425.591942249.1484DAC3@webmail.messagingengine.com> <85fuu6jo1o.fsf@benfinney.id.au> <1461826246.3257796.591992793.54C5CC58@webmail.messagingengine.com> <85bn4ujk7p.fsf@benfinney.id.au> <1461827330.3261212.591998673.4D215991@webmail.messagingengine.com> Message-ID: <857ffijj6s.fsf@benfinney.id.au> Stephen Hansen writes: > On Wed, Apr 27, 2016, at 11:55 PM, Ben Finney wrote: > > Everything I described above works fine in Python 2. > > This response is completely unhelpful. I'll let the OP be the judge of that. > The OP is using Python 2, and using %-formatting, and so you give a > series of examples of using str.format, to, what? Confuse matters? I don't know why you keep raising Python 2 as though it matters. As I pointed out, everything I discussed works fine on Python 2 without any change. More to the point, *even if* they continue using ?%? formatting, the primary point was to use named parameters. That is relevant to Python 3 and Python 2; it is relevant to ?%? formatting and ?str.format? formatting. None of those need to change. So I encourage the OP to try using named format parameters in *any* of those, and then judge whether it is helpful. -- \ ?Begin with false premises and you risk reaching false | `\ conclusions. Begin with falsified premises and you forfeit your | _o__) authority.? ?Kathryn Schulz, 2015-10-19 | Ben Finney From steve+comp.lang.python at pearwood.info Thu Apr 28 03:25:32 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 28 Apr 2016 17:25:32 +1000 Subject: Python Madlibs.py code and error message References: <3cff626c-28a2-499c-9877-de2df4d459d0@googlegroups.com> <6c0d96c5-c7f5-4659-a2e9-20f8d202d701@googlegroups.com> <1461820617.3238425.591942249.1484DAC3@webmail.messagingengine.com> <85fuu6jo1o.fsf@benfinney.id.au> <1461826246.3257796.591992793.54C5CC58@webmail.messagingengine.com> <85bn4ujk7p.fsf@benfinney.id.au> <1461827330.3261212.591998673.4D215991@webmail.messagingengine.com> Message-ID: <5721baee$0$22141$c3e8da3$5496439d@news.astraweb.com> On Thursday 28 April 2016 17:08, Stephen Hansen wrote: > On Wed, Apr 27, 2016, at 11:55 PM, Ben Finney wrote: >> Stephen Hansen writes: >> >> > On Wed, Apr 27, 2016, at 10:32 PM, Ben Finney wrote: >> > > Better: when you have many semantically-different values, use named >> > > (not positional) parameters in the format string. [?] >> > > >> > > >> > >> > Except the poster is not using Python 3, so all of this is for naught. >> >> Everything I described above works fine in Python 2. Any still-supported >> version has ?str.format?. > > This response is completely unhelpful. The OP is using Python 2, and > using %-formatting, and so you give a series of examples of using > str.format, to, what? Confuse matters? How about we assume good faith and give Ben the benefit of the doubt that he simply made a minor and trivial misjudgement rather than accusing him of intentionally trying to confuse matters? You are correct that the OP can use % formatting with named arguments. Ben is correct that the OP can also change his code to use str.format. Some people hate %-formatting and cannot wait to migrate to {}-formatting, and some people don't. (For the record, Internet rumours that %-formatting is deprecated are simply not correct.) -- Steve From jfong at ms4.hinet.net Thu Apr 28 04:27:06 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Thu, 28 Apr 2016 01:27:06 -0700 (PDT) Subject: Dictionary is really not easy to handle Message-ID: <8d6491e6-c266-49e9-bc47-c5e957d233ad@googlegroups.com> I have a dictionary like this: >>> dct ={1: 'D', 5: 'A', 2: 'B', 3: 'B', 4: 'E'} The following code works: >>> for k in dct: print(k, dct[k]) ... 1 D 2 B 3 B 4 E 5 A and this one too: >>> for k,v in dct.items(): print(k,v) ... 1 D 2 B 3 B 4 E 5 A But...this one? >>> for k,v in dct: print(k,v) ... Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not iterable No idea what the error message means:-( Can anyone explain it? Thanks ahead. From rahulraghu94 at gmail.com Thu Apr 28 04:36:01 2016 From: rahulraghu94 at gmail.com (Rahul Raghunath) Date: Thu, 28 Apr 2016 01:36:01 -0700 (PDT) Subject: do_POST not working on http.server with python Message-ID: 0 down vote favorite I'm trying to create a simple http server with basic GET and POST functionality. The program is supposed to GET requests by printing out a simple webpage that greets a user and askes how he would rather be greeted. When the user enters a greeting of his choice, the webpage should now greet him as he had chosen. While GET seems to be working fine, POST is not. I tried debugging by printing at every code execution and it seems to be getting stuck here: ctype, pdict = cgi.parse_header(self.headers.getheader('content-type')) I'll paste the code full code below, along with my terminal output. Code: from http.server import BaseHTTPRequestHandler, HTTPServer import cgi class webServerHandler(BaseHTTPRequestHandler): def do_GET(self): try: if self.path.endswith("/hello"): self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() output = "" output += "" output += "

Hello!

" output += '''

What would you like me to say?

''' output += "" self.wfile.write(output.encode(encoding = 'utf_8')) print (output) return if self.path.endswith("/hola"): self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() output = "" output += "" output += "

¡ Hola !

" output += '''

What would you like me to say?

''' output += "" self.wfile.write(output.encode(encoding = 'utf_8')) print (output) return except IOError: self.send_error(404, 'File Not Found: %s' % self.path) def do_POST(self): try: self.send_response(201) print("Sent response") self.send_header('Content-type', 'text/html') print("Sent headers") self.end_headers() print("Ended header") ctype, pdict = cgi.parse_header(self.headers.getheader('content-type')) print("Parsed headers") if ctype == 'multipart/form-data': fields = cgi.parse_multipart(self.rfile, pdict) messagecontent = fields.get('message') print("Receiver message content") output = "" output += "" output += "

Okay, how about this:

" output += "

%s

" % messagecontent[0] output += '''

What would you like me to say?

''' output += "" print(output) self.wfile.write(output.encode(encoding = 'utf_8')) print ("Wrote through CGI") except: pass def main(): try: port = 8080 server = HTTPServer(('', port), webServerHandler) print ("Web Server running on port", port) server.serve_forever() except KeyboardInterrupt: print (" ^C entered, stopping web server....") server.socket.close() if __name__ == '__main__': main() Terminal Output: Web Server running on port 8080 127.0.0.1 - - [28/Apr/2016 13:28:59] "GET /hello HTTP/1.1" 200 -

Hello!

What would you like me to say?

127.0.0.1 - - [28/Apr/2016 13:29:09] "POST /hello HTTP/1.1" 201 - Sent response Sent headers Ended header As you can see, the POST function does not seem to go beyong the parse_header command. I cannot figure this out, and any help would be usefu! From rustompmody at gmail.com Thu Apr 28 04:43:05 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 28 Apr 2016 01:43:05 -0700 (PDT) Subject: Dictionary is really not easy to handle In-Reply-To: <8d6491e6-c266-49e9-bc47-c5e957d233ad@googlegroups.com> References: <8d6491e6-c266-49e9-bc47-c5e957d233ad@googlegroups.com> Message-ID: <71dba1fb-d69c-4d79-888d-7356acd7ce32@googlegroups.com> On Thursday, April 28, 2016 at 1:57:40 PM UTC+5:30, jf... at ms4.hinet.net wrote: > I have a dictionary like this: > > >>> dct ={1: 'D', 5: 'A', 2: 'B', 3: 'B', 4: 'E'} > > The following code works: > > >>> for k in dct: print(k, dct[k]) > ... > 1 D > 2 B > 3 B > 4 E > 5 A > > and this one too: > > >>> for k,v in dct.items(): print(k,v) > ... > 1 D > 2 B > 3 B > 4 E > 5 A > > But...this one? > > >>> for k,v in dct: print(k,v) > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: 'int' object is not iterable > > No idea what the error message means:-( Can anyone explain it? Thanks ahead. Yes thats an unkind error message Wont try to explain it. But lets remove it instead: >>> dct ={(1,2): 'D', (4,5): 'A'} >>> >>> for k,v in dct: ... print (k,v) ... 1 2 4 5 >>> From __peter__ at web.de Thu Apr 28 05:17:23 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 Apr 2016 11:17:23 +0200 Subject: Dictionary is really not easy to handle References: <8d6491e6-c266-49e9-bc47-c5e957d233ad@googlegroups.com> Message-ID: jfong at ms4.hinet.net wrote: > I have a dictionary like this: > >>>> dct ={1: 'D', 5: 'A', 2: 'B', 3: 'B', 4: 'E'} > > The following code works: > But...this one? > >>>> for k,v in dct: print(k,v) > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: 'int' object is not iterable > > No idea what the error message means:-( Can anyone explain it? Thanks > ahead. for k, v in items: ... is basically a shortcut for for x in items: k, v = x The assignment with multiple names on the left side triggers what is called "unpacking", i. e. k, v = x is basically a shortcut for it = iter(x) try: k = next(it) v = next(it) except StopIteration: raise ValueError # not enough items try: next(it) # too many item if this succeeds except StopIteration: pass else raise ValueError Now remember that in for x in dct: ... x is actually the key and only the key -- an int in your example dict. Then iter(x) raises the exception you saw: >>> iter(42) Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not iterable If x were (for example) a string this would succeed it = iter("some string") as you can iterate over the string's characters -- but you'd get a ValueError for string lengths != 2: >>> k, v = "" Traceback (most recent call last): File "", line 1, in ValueError: need more than 0 values to unpack >>> k, v = "ab" >>> k 'a' >>> v 'b' >>> k, v = "abc" Traceback (most recent call last): File "", line 1, in ValueError: too many values to unpack (expected 2) With that information, can you predict what for k, v in {(1, 2): "three"}: print(k, v) will print? From g.v.aarthi at skct.edu.in Thu Apr 28 05:34:13 2016 From: g.v.aarthi at skct.edu.in (g.v.aarthi at skct.edu.in) Date: Thu, 28 Apr 2016 02:34:13 -0700 (PDT) Subject: for loop in python Message-ID: <8d628aaf-69cd-499e-b4b6-c5ba806cfcdb@googlegroups.com> start_list = [5, 3, 1, 2, 4] square_list = [] # Your code here! for square_list in start_list: x = pow(start_list, 2) square_list.append(x) square_list.sort() print square_list TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int' Please provide me the solution for the above problem From steve at pearwood.info Thu Apr 28 05:48:37 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 28 Apr 2016 19:48:37 +1000 Subject: for loop in python References: <8d628aaf-69cd-499e-b4b6-c5ba806cfcdb@googlegroups.com> Message-ID: <5721dc77$0$1619$c3e8da3$5496439d@news.astraweb.com> On Thu, 28 Apr 2016 07:34 pm, g.v.aarthi at skct.edu.in wrote: > start_list = [5, 3, 1, 2, 4] > square_list = [] Here you set square_list to a list. > # Your code here! > for square_list in start_list: .....^^^^^^^^^^^^^ Here you set square_list to each item of the start_list. So the first time around the loop, you have: square_list = 5 The second time: square_list = 3 The third time: square_list = 1 and so on. Except that the next line: > x = pow(start_list, 2) tries to raise *start_list* to the power of 2: [5, 3, 1, 2, 4]**2 which will raise an exception: > TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int' So you need to do this: start_list = [5, 3, 1, 2, 4] square_list = [] # Your code here! for ????? in start_list: Choose a different name! Not one you have already used. Something like "value" or "x" or "the_number_we_want_to_square". x = pow(?????, 2) square_list.append(x) And you only need to sort the square list once, at the end, *outside* of the for-loop, not inside it. (No need to indent the sort line.) -- Steven From __peter__ at web.de Thu Apr 28 05:54:19 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 Apr 2016 11:54:19 +0200 Subject: for loop in python References: <8d628aaf-69cd-499e-b4b6-c5ba806cfcdb@googlegroups.com> Message-ID: g.v.aarthi at skct.edu.in wrote: > start_list = [5, 3, 1, 2, 4] > square_list = [] > > # Your code here! > for square_list in start_list: You are iterating over start_list, that's OK. But you are assigning the current value to square_list, a variable name that you already use for the list where you put result of your calculations. Pick another name. > x = pow(start_list, 2) Look at the line above once more: did you really want the square of the complete start_list or only one item? > square_list.append(x) > square_list.sort() > print square_list > > TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int' > Please provide me the solution for the above problem From steve at pearwood.info Thu Apr 28 06:00:52 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 28 Apr 2016 20:00:52 +1000 Subject: Dictionary is really not easy to handle References: <8d6491e6-c266-49e9-bc47-c5e957d233ad@googlegroups.com> Message-ID: <5721df56$0$1608$c3e8da3$5496439d@news.astraweb.com> On Thu, 28 Apr 2016 06:27 pm, jfong at ms4.hinet.net wrote: > I have a dictionary like this: > >>>> dct ={1: 'D', 5: 'A', 2: 'B', 3: 'B', 4: 'E'} > > The following code works: > >>>> for k in dct: print(k, dct[k]) > ... > 1 D > 2 B > 3 B > 4 E > 5 A When you iterate over the dictionary, you get a single object each time, the key. So you have: k = 1 k = 2 etc. (It is a coincidence that they are in numeric order. That won't happen for all dicts, in all versions of Python. Normally they are in arbitrary order.) > and this one too: > >>>> for k,v in dct.items(): print(k,v) > ... > 1 D > 2 B > 3 B > 4 E > 5 A When you iterate over the dictionary items, you get a *pair* of objects, namely the key and the value in a tuple. So each time through the loop, you have something like: k, v = (1, 'D') # a tuple with two items which is equivalent to: k = 1 # first item v = 'D' # second item > But...this one? > >>>> for k,v in dct: print(k,v) > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: 'int' object is not iterable > > No idea what the error message means:-( Can anyone explain it? Thanks > ahead. Remember that iterating over the dictionary gives you the keys alone. In this case, the keys are *integers*, not strings or lists or tuples. So you are asking Python to do this: k, v = 1 which you remember is equivalent to this: k = ??? # first item of int 1 v = ??? # second item of int 1 What goes into the ??? on each line? You cannot split 1 into two items, because it is not an iterable sequence (not a string, not a list, not a tuple). What you are asking Python to do makes no sense, so it gives a TypeError. -- Steven From bc at freeuk.com Thu Apr 28 06:04:51 2016 From: bc at freeuk.com (BartC) Date: Thu, 28 Apr 2016 11:04:51 +0100 Subject: for loop in python In-Reply-To: <8d628aaf-69cd-499e-b4b6-c5ba806cfcdb@googlegroups.com> References: <8d628aaf-69cd-499e-b4b6-c5ba806cfcdb@googlegroups.com> Message-ID: On 28/04/2016 10:34, g.v.aarthi at skct.edu.in wrote: > start_list = [5, 3, 1, 2, 4] > square_list = [] > > # Your code here! > for square_list in start_list: > x = pow(start_list, 2) > square_list.append(x) > square_list.sort() > print square_list > > TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int' > Please provide me the solution for the above problem Try: start_list = [5, 3, 1, 2, 4] square_list = [] # Your code here! for i in start_list: x = pow(i, 2) square_list.append(x) square_list.sort() print (square_list) From jfong at ms4.hinet.net Thu Apr 28 07:14:23 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Thu, 28 Apr 2016 04:14:23 -0700 (PDT) Subject: Dictionary is really not easy to handle In-Reply-To: <8d6491e6-c266-49e9-bc47-c5e957d233ad@googlegroups.com> References: <8d6491e6-c266-49e9-bc47-c5e957d233ad@googlegroups.com> Message-ID: I was overwhelmed that three gurus inspire me in three different ways in their own flavour:-) That's really appreciated! Now I understand why it's so, thanks to all of you. To Peter: > With that information, can you predict what > for k, v in {(1, 2): "three"}: print(k, v) > will print? It's 1 2. (Although Rustom had given the answer in his reply, I didn't figure out until after reading you and Steven's answers:-) From python at mrabarnett.plus.com Thu Apr 28 07:16:17 2016 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 28 Apr 2016 12:16:17 +0100 Subject: Pythonic style In-Reply-To: References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <572188F8.7010304@stoneleaf.us> Message-ID: <540fc958-52d6-6049-75f2-5ee42657688e@mrabarnett.plus.com> On 2016-04-28 06:16, Rustom Mody wrote: > On Thursday, April 28, 2016 at 9:26:21 AM UTC+5:30, Chris Angelico wrote: >> My rule of thumb is: Dunders are for defining, not for calling. It's >> not a hard-and-fast rule, but it'll get you through 99%+ of >> situations. > > Neat and clever. > Should get in the docs somewhere > Is it worthy of being in the Zen of Python? From rustompmody at gmail.com Thu Apr 28 07:45:41 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 28 Apr 2016 04:45:41 -0700 (PDT) Subject: Dunder docs again (was Pythonic style) In-Reply-To: References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <572188F8.7010304@stoneleaf.us> <540fc958-52d6-6049-75f2-5ee42657688e@mrabarnett.plus.com> Message-ID: On Thursday, April 28, 2016 at 4:46:43 PM UTC+5:30, MRAB wrote: > On 2016-04-28 06:16, Rustom Mody wrote: > > On Thursday, April 28, 2016 at 9:26:21 AM UTC+5:30, Chris Angelico wrote: > >> My rule of thumb is: Dunders are for defining, not for calling. It's > >> not a hard-and-fast rule, but it'll get you through 99%+ of > >> situations. > > > > Neat and clever. > > Should get in the docs somewhere > > > Is it worthy of being in the Zen of Python? :-) Thats more than I intended... But heck why not?! I find that dunder methods are poorly documented, especially when compared to their 'pythonic-ness'. Ive spoken of this on and off, eg https://mail.python.org/pipermail/python-list/2015-May/691329.html From flebber.crue at gmail.com Thu Apr 28 08:02:06 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 28 Apr 2016 05:02:06 -0700 (PDT) Subject: Controlling the passing of data Message-ID: Hi This file contains my biggest roadblock with programming and that's the abstract nature of needing to pass data from one thing to the next. In my file here I needed to traverse and modify the XML file I don't want to restore it or put it in a new variable or other format I just want to alter it and let it flow onto the list comprehensions as they were. Once I can get on top of this mentally I will be able to do so much better, I think I am trying to manage it in my head as if it was water and plumbing. In particular here I am taking the id from race and putting it into the children of each race called nomination. I have put a comment above the new code which is causing the difficulty. from pyquery import PyQuery as pq import pandas as pd import argparse import numpy as np # from glob import glob parser = argparse.ArgumentParser(description=None) def GetArgs(parser): """Parser function using argparse""" # parser.add_argument('directory', help='directory use', # action='store', nargs='*') parser.add_argument("files", nargs="+") return parser.parse_args() fileList = GetArgs(parser) # print(fileList.files) data = [] horseattrs = ('race_id', 'id', 'horse', 'number', 'finished', 'age', 'sex', 'blinkers', 'trainernumber', 'career', 'thistrack', 'firstup', 'secondup', 'variedweight', 'weight', 'pricestarting') meetattrs = ('id', 'venue', 'date', 'rail', 'weather', 'trackcondition') raceattrs = ('id', 'number', 'shortname', 'stage', 'distance', 'grade', 'age', 'weightcondition', 'fastesttime', 'sectionaltime') clubattrs = ('code') frames = pd.DataFrame([]) noms = [] for items in fileList.files: d = pq(filename=items) meet = d('meeting') club = d('club') race = d('race') res = d('nomination') # d('p').filter(lambda i: i == 1) # Here i need to traverse and modify but I don't want to restore the # structure just pass it on. So I can use it in the following list # comprehensions as I had before. for race_el in d('race'): race = pq(race_el) race_id = race.attr('id') for nom_el in race.items('nomination'): res.append((pq(nom_el).attr('raceid', race_id))) resdata = [[res.eq(i).attr(x) for x in horseattrs] for i in range(len(res))] # print(dataSets) meetdata = [[meet.eq(i).attr(x) for x in meetattrs] for i in range(len(meet))] racedata = [[race.eq(i).attr(x) for x in raceattrs] for i in range(len(race))] clubdata = [[club.eq(i).attr(x) for x in clubattrs] for i in range(len(club))] raceid = [row[0] for row in racedata] # L = [x + [0] for x in L] # print(resdata) # resdata = [raceid[i] for i in raceid x + i for x in resdata] # for number of classes equalling nomination in the each category of # race inset raceid into resdata # # print(resdata) # clubdf = pd.DataFrame(clubdata) # meetdf = pd.DataFrame(meetdata) # racedf = pd.DataFrame(racedata) # resdf = pd.DataFrame(resdata) # frames = frames.append(clubdf) # frames = frames.append(meetdf) # # frames = frames.append(racedf) # frames = frames.append(resdf) # print(frames) # frames.to_csv('~/testingFrame5.csv', encoding='utf-8') Thanks Sayth From python at mrabarnett.plus.com Thu Apr 28 08:02:51 2016 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 28 Apr 2016 13:02:51 +0100 Subject: Dunder docs again (was Pythonic style) In-Reply-To: References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <572188F8.7010304@stoneleaf.us> <540fc958-52d6-6049-75f2-5ee42657688e@mrabarnett.plus.com> Message-ID: On 2016-04-28 12:45, Rustom Mody wrote: > On Thursday, April 28, 2016 at 4:46:43 PM UTC+5:30, MRAB wrote: >> On 2016-04-28 06:16, Rustom Mody wrote: >> > On Thursday, April 28, 2016 at 9:26:21 AM UTC+5:30, Chris Angelico wrote: >> >> My rule of thumb is: Dunders are for defining, not for calling. It's >> >> not a hard-and-fast rule, but it'll get you through 99%+ of >> >> situations. >> > >> > Neat and clever. >> > Should get in the docs somewhere >> > >> Is it worthy of being in the Zen of Python? > > :-) > Thats more than I intended... But heck why not?! > I find that dunder methods are poorly documented, especially when compared to > their 'pythonic-ness'. > Ive spoken of this on and off, eg https://mail.python.org/pipermail/python-list/2015-May/691329.html > 'pythonic-ness'? Surely it's 'pythonicity'! :-) From marko at pacujo.net Thu Apr 28 08:25:32 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 28 Apr 2016 15:25:32 +0300 Subject: Dunder docs again (was Pythonic style) References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <572188F8.7010304@stoneleaf.us> <540fc958-52d6-6049-75f2-5ee42657688e@mrabarnett.plus.com> Message-ID: <87h9elor7n.fsf@elektro.pacujo.net> MRAB : > 'pythonic-ness'? Surely it's 'pythonicity'! :-) Doubt it: Full Definition of generic [...] ?generically \-i-k(?-)l?\ adverb ?genericness noun Marko From a24061 at ducksburg.com Thu Apr 28 08:57:44 2016 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 28 Apr 2016 13:57:44 +0100 Subject: Why does pathlib not have is_readable() & things like that? References: <6474vcx0q6.ln2@news.ducksburg.com> <571f8d53$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8vd9vcxf2a.ln2@news.ducksburg.com> On 2016-04-26, Steven D'Aprano wrote: > On Tue, 26 Apr 2016 11:30 pm, Adam Funk wrote: >> I've been improvising with things like this: >> >> import pathlib, os >> >> path = pathlib.Path('some/directory') >> writable = os.access(str(path), os.W_OK | os.X_OK) >> >> Is that the best way to do it? > > No. All you have learned is that the directory is writable *now*. In a > millisecond, or a minute, when you actually go to write to it, it may no > longer be writable -- it may not even exist. > > There is a whole class of serious security vulnerabilities and bugs caused > by the difference between the time you check something and the time you > actually use it. "Time of check to time of use" bugs can be best avoided by > not checking ahead of time whether the directory is writable, but just > *attempting to write to it*, and catching the error if you can't. I appreciate the general principle, but the situation here is a tool that iterates over a loop of the following: GET some chunks of data from a REST service, process them, PUT something back to existing documents through the REST service, & save the result in a directory specified as a command-line option. I don't want the tool to modify the first batch of data in the REST service, be unable to store the results locally, & crash as a result. -- A mathematical formula should never be "owned" by anybody! Mathematics belongs to God. --- Donald Knuth From a24061 at ducksburg.com Thu Apr 28 09:02:51 2016 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 28 Apr 2016 14:02:51 +0100 Subject: Why does pathlib not have is_readable() & things like that? References: <6474vcx0q6.ln2@news.ducksburg.com> <1461679044.2467938.590028273.4DEA02AA@webmail.messagingengine.com> Message-ID: On 2016-04-26, Random832 wrote: > On Tue, Apr 26, 2016, at 09:30, Adam Funk wrote: >> I recently discovered pathlib in the Python 3 standard library, & find >> it very useful, but I'm a bit surprised that it doesn't offer things >> like is_readable() and is_writable. Is there a good reason for that? > > Well, one reason would be EAFP. Just try to open the file and see if it > gives you a PermissionError. I understand that in general, but the tool I'm working on here takes a command-line option to specify an output directory, & I'd rather not start processing the data (which involves GETting from a REST service, processing, and PUTting back modifications to the data) only to crash after the first batch because of a user error. -- Specifications are for the weak & timid! --- Klingon Programmer's Guide From python at mrabarnett.plus.com Thu Apr 28 09:22:45 2016 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 28 Apr 2016 14:22:45 +0100 Subject: Dunder docs again (was Pythonic style) In-Reply-To: <87h9elor7n.fsf@elektro.pacujo.net> References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <572188F8.7010304@stoneleaf.us> <540fc958-52d6-6049-75f2-5ee42657688e@mrabarnett.plus.com> <87h9elor7n.fsf@elektro.pacujo.net> Message-ID: On 2016-04-28 13:25, Marko Rauhamaa wrote: > MRAB : > >> 'pythonic-ness'? Surely it's 'pythonicity'! :-) > > Doubt it: > > Full Definition of generic > [...] > > ?generically \-i-k(?-)l?\ adverb > ?genericness noun > > > I can point you to 3 alternatives, from oldest to newest: http://www.oxforddictionaries.com/definition/english/genericalness http://www.oxforddictionaries.com/definition/english/genericness http://www.oxforddictionaries.com/definition/english/genericity From jussi.piitulainen at helsinki.fi Thu Apr 28 09:24:36 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Thu, 28 Apr 2016 16:24:36 +0300 Subject: Why does pathlib not have is_readable() & things like that? References: <6474vcx0q6.ln2@news.ducksburg.com> <1461679044.2467938.590028273.4DEA02AA@webmail.messagingengine.com> Message-ID: Adam Funk writes: > On 2016-04-26, Random832 wrote: > >> On Tue, Apr 26, 2016, at 09:30, Adam Funk wrote: >>> I recently discovered pathlib in the Python 3 standard library, & find >>> it very useful, but I'm a bit surprised that it doesn't offer things >>> like is_readable() and is_writable. Is there a good reason for that? >> >> Well, one reason would be EAFP. Just try to open the file and see if it >> gives you a PermissionError. > > I understand that in general, but the tool I'm working on here takes a > command-line option to specify an output directory, & I'd rather not > start processing the data (which involves GETting from a REST service, > processing, and PUTting back modifications to the data) only to crash > after the first batch because of a user error. Open an output file first. Crash before reading the first batch. From random832 at fastmail.com Thu Apr 28 09:31:58 2016 From: random832 at fastmail.com (Random832) Date: Thu, 28 Apr 2016 09:31:58 -0400 Subject: Pythonic style In-Reply-To: References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <572188F8.7010304@stoneleaf.us> Message-ID: <1461850318.3155238.592303449.6271E6A3@webmail.messagingengine.com> On Thu, Apr 28, 2016, at 01:16, Rustom Mody wrote: > On Thursday, April 28, 2016 at 9:26:21 AM UTC+5:30, Chris Angelico wrote: > > My rule of thumb is: Dunders are for defining, not for calling. It's > > not a hard-and-fast rule, but it'll get you through 99%+ of > > situations. > > Neat and clever. > Should get in the docs somewhere And even most of the obvious cases where you would want to call one [e.g. on super] are in the course of implementing one. From grant.b.edwards at gmail.com Thu Apr 28 09:34:31 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 28 Apr 2016 13:34:31 +0000 (UTC) Subject: Why does pathlib not have is_readable() & things like that? References: <6474vcx0q6.ln2@news.ducksburg.com> <1461679044.2467938.590028273.4DEA02AA@webmail.messagingengine.com> Message-ID: On 2016-04-28, Adam Funk wrote: > On 2016-04-26, Random832 wrote: > >> On Tue, Apr 26, 2016, at 09:30, Adam Funk wrote: >>> I recently discovered pathlib in the Python 3 standard library, & find >>> it very useful, but I'm a bit surprised that it doesn't offer things >>> like is_readable() and is_writable. Is there a good reason for that? >> >> Well, one reason would be EAFP. Just try to open the file and see if it >> gives you a PermissionError. > > I understand that in general, but the tool I'm working on here takes a > command-line option to specify an output directory, & I'd rather not > start processing the data (which involves GETting from a REST service, > processing, and PUTting back modifications to the data) only to crash > after the first batch because of a user error. Then open the output file before you do the GET. Or just do os.access("directory/where/you/want/to/open/a/file",os.W_OK) -- Grant Edwards grant.b.edwards Yow! Jesus is my POSTMASTER at GENERAL ... gmail.com From __peter__ at web.de Thu Apr 28 09:40:23 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 Apr 2016 15:40:23 +0200 Subject: Controlling the passing of data References: Message-ID: Sayth Renshaw wrote: > In my file here I needed to traverse and modify the XML file I don't want > to restore it or put it in a new variable or other format I just want to > alter it and let it flow onto the list comprehensions as they were. That looks like an arbitrary limitation to me. It's a bit like "I want to repair my car with this big hammer". > In particular here I am taking the id from race and putting it into the > children of each race called nomination. > > I have put a comment above the new code which is causing the difficulty. Your actual problem is drowned in too much source code. Can you restate it in English, optionally with a few small snippets of Python? It is not even clear what the code you provide should accomplish once it's running as desired. To give at least one code-related advice: You have a few repetitions of the following structure > meetattrs = ('id', 'venue', 'date', 'rail', 'weather', 'trackcondition') > meet = d('meeting') > meetdata = [[meet.eq(i).attr(x) > for x in meetattrs] for i in range(len(meet))] You should move the pieces into a function that works for meetings, clubs, races, and so on. Finally (If I am repeating myself so be it): the occurence of range(len(something)) in your code is a strong indication that you are not using Python the way Guido intended it. Iterate over the `something` directly whenever possible. From flebber.crue at gmail.com Thu Apr 28 09:59:47 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 28 Apr 2016 06:59:47 -0700 (PDT) Subject: Controlling the passing of data In-Reply-To: References: Message-ID: > > Your actual problem is drowned in too much source code. Can you restate it > in English, optionally with a few small snippets of Python? > > It is not even clear what the code you provide should accomplish once it's > running as desired. > > To give at least one code-related advice: You have a few repetitions of the > following structure > > > meetattrs = ('id', 'venue', 'date', 'rail', 'weather', 'trackcondition') > > > meet = d('meeting') > > > meetdata = [[meet.eq(i).attr(x) > > for x in meetattrs] for i in range(len(meet))] > > You should move the pieces into a function that works for meetings, clubs, > races, and so on. Finally (If I am repeating myself so be it): the occurence > of range(len(something)) in your code is a strong indication that you are > not using Python the way Guido intended it. Iterate over the `something` > directly whenever possible. Hi Peter > meetattrs = ('id', 'venue', 'date', 'rail', 'weather', 'trackcondition') is created to define a list of attr in the XML rather than referencing each attr individually I create a list and pass it into > meetdata = [[meet.eq(i).attr(x) > > for x in meetattrs] for i in range(len(meet))] This list comprehension reads the XML attr by attr using meet = d('meeting') as the call to pyquery to locate the class in the XML and identify the attr's. I do apologise for the lack of output, I asked a question about parsing that I always seem to get wrong over think and then find the solution simpler than I thought. The output is 4 tables of the class and selected attributes eg meetattrs = ('id', 'venue', 'date', 'rail', 'weather', 'trackcondition') from the meeting class of the XML. In order to give flexibility and keep the relational nature they have defined in the table I found when exporting the nominations section via pandas to csv that i had no way to determine which id belonged to each race that is there was no race_id in the nominations to relate back to the race, and also no meeting id in the raceid to relate it back to the meeting. So I wanted to traverse all the classes Meeting, Race and Nomination and insert the id of the class into its direct children only and since there were many races a meeting and many nomnations a race I need to ensure that it is the direct children only. It was otherwise working as parsed output in code supplied using to push to pandas and use its csv write capability. So I inserted for race_el in d('race'): race = pq(race_el) race_id = race.attr('id') for nom_el in race.items('nomination'): res.append((pq(nom_el).attr('raceid', race_id))) which traverses and inserts the race_id into the child nominations. However, my boggles is how to pass this to the list comprehension that was working without changing the data from XML or creating another intermediate step and variable. Just to parse it as it was but with the extra included race_id. Thanks Sayth From ldompeling at casema.nl Thu Apr 28 10:15:04 2016 From: ldompeling at casema.nl (ldompeling at casema.nl) Date: Thu, 28 Apr 2016 07:15:04 -0700 (PDT) Subject: online python courses Message-ID: <8f5cc7b6-dce5-4bec-b734-0453a57cec2e@googlegroups.com> I am follows on this moment two online pythoncourses from code.tutsplus.com But I am interested in following more online pythoncourses. Maby someone have some links to websites for me what handles python online courses. thanks From D.Strohl at F5.com Thu Apr 28 10:40:01 2016 From: D.Strohl at F5.com (Dan Strohl) Date: Thu, 28 Apr 2016 14:40:01 +0000 Subject: Controlling the passing of data In-Reply-To: References: Message-ID: <4a16db24a11c4231b3d006bcca10f502@seaexchmbx03.olympus.F5Net.com> In addition to Peter's points, - I would suggest breaking out the list comprehensions into standard for loops and/or functions. That makes it easier to read and troubleshoot. (you can always re-optimize It if needed.) - Peter's point about making things into functions will also help troubleshooting. You can better test the data going into and out of the function. In my code, I will often have the file access and data processing as separate functions, then the main routine just calls the function to get data, passes that data to a function that manipulates it, and then pass the results to a function that writes it out. This allows for much easier testing and troubleshooting of the individual functions. (sometimes I will reassemble them into one function when I am done, depending on my needs) More importantly though in terms of your getting help for your problem, the post is unclear (to me at least) in terms of what you are trying to achieve and what isn't working, Try considering the following suggestions: - It is unclear what the problem is that you are having, you say you are trying to do x, and you are having problems in a part after a comment, but none of the comments say "this is breaking". I assume you are talking about the comment that starts "Here I need to traverse", but don't know for sure, and even if it is, you don't specify what the problem actually is; are you receiving an exception message (please let us know what it is), is it running, but not doing anything? is it returning incorrect data? or??? - When posting, rather than commenting out code that you aren't using right now, and code that is working and not related to the problem, I recommend just deleting them so that people don't have to try to work through it.... for example, just remove the GetArgs function and just say fileList = "/xml_dir", and the section at the end that is all commented out, just remove it. You should just have the minimum needed to replicate the problem. This will also help in troubleshooting, when I have a problem like this, and I can't figure out what is going on, I will copy the code to a new file and make a program that will handle a specific set of data, and try to do the one thing that is breaking, removing all the rest of the stuff, and test the results.. so, for example, copy a sample of the xml with a couple of data items into a string var, and have a program that processes that and checks to see if at the end you end up with a list of the right values by printing a list rather than muddying the waters with file access, and writing out csv's. (by the way, this is a great time to start working with unit testing if you aren't already, it is simple to create this as a test case and you will find that if you start doing testing along the way, the time it takes to troubleshoot errors along the way will go down dramatically.) - Be clear at the end what you expect to get, especially if it is not what you are getting... so, either in the code as a comment, or in a descriptive paragraph, have a section that said something like: "At the end of the snippet, meetdata, racedata, clubdata, and raceid should be a list of dictionaries with the data from the xml" (or whatever... possibly with an example of what you would expect). This is even more important if the problem you are having is that the code is not returning correct data. This may not be as needed if the code is simply blowing up at line xx, though it would still help people understand your goal. - For the example at least (you may choose to do differently in your live code), use nice explanatory variable names and don't rename imports, so it would be clearer to say "import pandas", then "frames = pandas.DataFrame[])". That way the reader doesn't have to keep referring to the imports to figure out what is going on. Remember, you are asking a large number of people for help, most of which are pretty busy already, so the more you can do to simplify and show the exact problem, the more (and more useful) help you are likely to receive. To this lists credit, even if you are completely unclear in your question, you will likely get *something* back, (as you saw with Peters response), but what you get back is more likely to be a general suggestion rather than a specific fix for your problem. Dan Strohl > -----Original Message----- > From: Python-list [mailto:python-list-bounces+d.strohl=f5.com at python.org] > On Behalf Of Peter Otten > Sent: Thursday, April 28, 2016 6:40 AM > To: python-list at python.org > Subject: Re: Controlling the passing of data > > Sayth Renshaw wrote: > > > In my file here I needed to traverse and modify the XML file I don't > > want to restore it or put it in a new variable or other format I just > > want to alter it and let it flow onto the list comprehensions as they were. > > That looks like an arbitrary limitation to me. It's a bit like "I want to repair my > car with this big hammer". > > > In particular here I am taking the id from race and putting it into > > the children of each race called nomination. > > > > I have put a comment above the new code which is causing the difficulty. > > Your actual problem is drowned in too much source code. Can you restate it > in English, optionally with a few small snippets of Python? > > It is not even clear what the code you provide should accomplish once it's > running as desired. > > To give at least one code-related advice: You have a few repetitions of the > following structure > > > meetattrs = ('id', 'venue', 'date', 'rail', 'weather', > > 'trackcondition') > > > meet = d('meeting') > > > meetdata = [[meet.eq(i).attr(x) > > for x in meetattrs] for i in range(len(meet))] > > You should move the pieces into a function that works for meetings, clubs, > races, and so on. Finally (If I am repeating myself so be it): the occurence of > range(len(something)) in your code is a strong indication that you are not > using Python the way Guido intended it. Iterate over the `something` directly > whenever possible. > > -- > https://mail.python.org/mailman/listinfo/python-list From rustompmody at gmail.com Thu Apr 28 10:52:55 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 28 Apr 2016 07:52:55 -0700 (PDT) Subject: Controlling the passing of data In-Reply-To: References: <4a16db24a11c4231b3d006bcca10f502@seaexchmbx03.olympus.F5Net.com> Message-ID: On Thursday, April 28, 2016 at 8:11:26 PM UTC+5:30, Dan Strohl wrote: > In addition to Peter's points, > - I would suggest breaking out the list comprehensions into standard for loops and/or functions. That makes it easier to read and troubleshoot. (you can always re-optimize It if needed.) > - Peter's point about making things into functions will also help troubleshooting. You can better test the data going into and out of the function. In my code, I will often have the file access and data processing as separate functions, then the main routine just calls the function to get data, passes that data to a function that manipulates it, and then pass the results to a function that writes it out. This allows for much easier testing and troubleshooting of the individual functions. (sometimes I will reassemble them into one function when I am done, depending on my needs) > > More importantly though in terms of your getting help for your problem, the post is unclear (to me at least) in terms of what you are trying to achieve and what isn't working, > > Try considering the following suggestions: > > - It is unclear what the problem is that you are having, you say you are trying to do x, and you are having problems in a part after a comment, but none of the comments say "this is breaking". I assume you are talking about the comment that starts "Here I need to traverse", but don't know for sure, and even if it is, you don't specify what the problem actually is; are you receiving an exception message (please let us know what it is), is it running, but not doing anything? is it returning incorrect data? or??? > > - When posting, rather than commenting out code that you aren't using right now, and code that is working and not related to the problem, I recommend just deleting them so that people don't have to try to work through it.... for example, just remove the GetArgs function and just say fileList = "/xml_dir", and the section at the end that is all commented out, just remove it. You should just have the minimum needed to replicate the problem. > > This will also help in troubleshooting, when I have a problem like this, and I can't figure out what is going on, I will copy the code to a new file and make a program that will handle a specific set of data, and try to do the one thing that is breaking, removing all the rest of the stuff, and test the results.. so, for example, copy a sample of the xml with a couple of data items into a string var, and have a program that processes that and checks to see if at the end you end up with a list of the right values by printing a list rather than muddying the waters with file access, and writing out csv's. (by the way, this is a great time to start working with unit testing if you aren't already, it is simple to create this as a test case and you will find that if you start doing testing along the way, the time it takes to troubleshoot errors along the way will go down dramatically.) > > - Be clear at the end what you expect to get, especially if it is not what you are getting... so, either in the code as a comment, or in a descriptive paragraph, have a section that said something like: "At the end of the snippet, meetdata, racedata, clubdata, and raceid should be a list of dictionaries with the data from the xml" (or whatever... possibly with an example of what you would expect). This is even more important if the problem you are having is that the code is not returning correct data. This may not be as needed if the code is simply blowing up at line xx, though it would still help people understand your goal. > > - For the example at least (you may choose to do differently in your live code), use nice explanatory variable names and don't rename imports, so it would be clearer to say "import pandas", then "frames = pandas.DataFrame[])". That way the reader doesn't have to keep referring to the imports to figure out what is going on. > > Remember, you are asking a large number of people for help, most of which are pretty busy already, so the more you can do to simplify and show the exact problem, the more (and more useful) help you are likely to receive. To this lists credit, even if you are completely unclear in your question, you will likely get *something* back, (as you saw with Peters response), but what you get back is more likely to be a general suggestion rather than a specific fix for your problem. > > Dan Strohl > > > > > > -----Original Message----- > > > > Sayth Renshaw wrote: > > > > > In my file here I needed to traverse and modify the XML file I don't > > > want to restore it or put it in a new variable or other format I just > > > want to alter it and let it flow onto the list comprehensions as they were. > > > > That looks like an arbitrary limitation to me. It's a bit like "I want to repair my > > car with this big hammer". > > > > > In particular here I am taking the id from race and putting it into > > > the children of each race called nomination. > > > > > > I have put a comment above the new code which is causing the difficulty. > > > > Your actual problem is drowned in too much source code. Can you restate it > > in English, optionally with a few small snippets of Python? > > > > It is not even clear what the code you provide should accomplish once it's > > running as desired. > > > > To give at least one code-related advice: You have a few repetitions of the > > following structure > > > > > meetattrs = ('id', 'venue', 'date', 'rail', 'weather', > > > 'trackcondition') > > > > > meet = d('meeting') > > > > > meetdata = [[meet.eq(i).attr(x) > > > for x in meetattrs] for i in range(len(meet))] > > > > You should move the pieces into a function that works for meetings, clubs, > > races, and so on. Finally (If I am repeating myself so be it): the occurence of > > range(len(something)) in your code is a strong indication that you are not > > using Python the way Guido intended it. Iterate over the `something` directly > > whenever possible. > > > > -- > > https://mail.python.org/mailman/listinfo/python-list To add to that: It is right to have a dislike for bad code and a desire for good code. But this desire odes not translate into an effective communication. In particular: I dont think anyone quite gets exactly you are after in: > I don't want to restore it or put it in a new variable or other format I > just want to alter it and let it flow onto the list comprehensions as they were. So please cut down your example to 1/4 the size: - Tiny inline triple-quoted xml - Your attempt so far - What you would like to do different From joel.goldstick at gmail.com Thu Apr 28 10:57:11 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 28 Apr 2016 10:57:11 -0400 Subject: online python courses In-Reply-To: <8f5cc7b6-dce5-4bec-b734-0453a57cec2e@googlegroups.com> References: <8f5cc7b6-dce5-4bec-b734-0453a57cec2e@googlegroups.com> Message-ID: On Thu, Apr 28, 2016 at 10:15 AM, wrote: > I am follows on this moment two online pythoncourses from code.tutsplus.com > But I am interested in following more online pythoncourses. > Maby someone have some links to websites for me what handles python online courses. > > thanks > -- > https://mail.python.org/mailman/listinfo/python-list Try here: http://lmgtfy.com/?q=python+online+courses#seen -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From D.Strohl at F5.com Thu Apr 28 11:04:01 2016 From: D.Strohl at F5.com (Dan Strohl) Date: Thu, 28 Apr 2016 15:04:01 +0000 Subject: online python courses In-Reply-To: <8f5cc7b6-dce5-4bec-b734-0453a57cec2e@googlegroups.com> References: <8f5cc7b6-dce5-4bec-b734-0453a57cec2e@googlegroups.com> Message-ID: I've heard good things about codeacademy.com and learnpython.org. Also, I've heard that pycharm educational edition is helpful. (https://www.jetbrains.com/pycharm-edu/ ) I haven't personally tried any of these though, so your mileage may vary. Good Luck! Dan Strohl > -----Original Message----- > From: Python-list [mailto:python-list-bounces+d.strohl=f5.com at python.org] > On Behalf Of ldompeling at casema.nl > Sent: Thursday, April 28, 2016 7:15 AM > To: python-list at python.org > Subject: online python courses > > I am follows on this moment two online pythoncourses from > code.tutsplus.com But I am interested in following more online > pythoncourses. > Maby someone have some links to websites for me what handles python > online courses. > > thanks > -- > https://mail.python.org/mailman/listinfo/python-list From walters.justin01 at gmail.com Thu Apr 28 11:04:07 2016 From: walters.justin01 at gmail.com (justin walters) Date: Thu, 28 Apr 2016 08:04:07 -0700 Subject: online python courses In-Reply-To: References: <8f5cc7b6-dce5-4bec-b734-0453a57cec2e@googlegroups.com> Message-ID: On Thu, Apr 28, 2016 at 7:57 AM, Joel Goldstick wrote: > On Thu, Apr 28, 2016 at 10:15 AM, wrote: > > I am follows on this moment two online pythoncourses from > code.tutsplus.com > > But I am interested in following more online pythoncourses. > > Maby someone have some links to websites for me what handles python > online courses. > > > > thanks > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Try here: > > http://lmgtfy.com/?q=python+online+courses#seen > > > -- > Joel Goldstick > http://joelgoldstick.com/blog > http://cc-baseballstats.info/stats/birthdays > -- > https://mail.python.org/mailman/listinfo/python-list > SICP in Python: http://composingprograms.com/ From rustompmody at gmail.com Thu Apr 28 11:13:24 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 28 Apr 2016 08:13:24 -0700 (PDT) Subject: online python courses In-Reply-To: <8f5cc7b6-dce5-4bec-b734-0453a57cec2e@googlegroups.com> References: <8f5cc7b6-dce5-4bec-b734-0453a57cec2e@googlegroups.com> Message-ID: On Thursday, April 28, 2016 at 7:45:22 PM UTC+5:30, ldomp... at casema.nl wrote: > I am follows on this moment two online pythoncourses from code.tutsplus.com > But I am interested in following more online pythoncourses. > Maby someone have some links to websites for me what handles python online courses. > > thanks Start with this: https://docs.python.org/3.5/tutorial/ From D.Strohl at F5.com Thu Apr 28 11:19:09 2016 From: D.Strohl at F5.com (Dan Strohl) Date: Thu, 28 Apr 2016 15:19:09 +0000 Subject: Controlling the passing of data In-Reply-To: References: Message-ID: <5c94882cb24c441bad13fd122851bd38@seaexchmbx03.olympus.F5Net.com> If I am reading this correctly... you have something like (you will have to excuse my lack of knowledge about what kinds of information these actually are): 1234 first 5678 second And you want something like: nominations = [(1,1234), (2,5678)] meetings = [(1,'first'),(2,'second')] if that is correct, my suggestion is to do something like (this is psudeo code, I didn't look up the exact calls to use): nomination_list = [] meeting_list = [] for race_element in xml_file('race'): id = race_element.get_attr('id') for nomination_element in race_element('nomination'): nomination = nomination_element.get_text() nomination_list.append((id, nomination)) for meeting_element in race_element('meeting'): meeting = meeting_element.get_text() meeting_list.append((id, meeting)) > -----Original Message----- > From: Python-list [mailto:python-list-bounces+d.strohl=f5.com at python.org] > On Behalf Of Sayth Renshaw > Sent: Thursday, April 28, 2016 7:00 AM > To: python-list at python.org > Subject: Re: Controlling the passing of data > > > > > > Your actual problem is drowned in too much source code. Can you > > restate it in English, optionally with a few small snippets of Python? > > > > It is not even clear what the code you provide should accomplish once > > it's running as desired. > > > > To give at least one code-related advice: You have a few repetitions > > of the following structure > > > > > meetattrs = ('id', 'venue', 'date', 'rail', 'weather', > > > 'trackcondition') > > > > > meet = d('meeting') > > > > > meetdata = [[meet.eq(i).attr(x) > > > for x in meetattrs] for i in range(len(meet))] > > > > You should move the pieces into a function that works for meetings, > > clubs, races, and so on. Finally (If I am repeating myself so be it): > > the occurence of range(len(something)) in your code is a strong > > indication that you are not using Python the way Guido intended it. > > Iterate over the `something` directly whenever possible. > > Hi Peter > > > meetattrs = ('id', 'venue', 'date', 'rail', 'weather', > > 'trackcondition') > > is created to define a list of attr in the XML rather than referencing each attr > individually I create a list and pass it into > > > meetdata = [[meet.eq(i).attr(x) > > > for x in meetattrs] for i in range(len(meet))] > > This list comprehension reads the XML attr by attr using meet = d('meeting') > as the call to pyquery to locate the class in the XML and identify the attr's. > > I do apologise for the lack of output, I asked a question about parsing that I > always seem to get wrong over think and then find the solution simpler than > I thought. > > The output is 4 tables of the class and selected attributes eg meetattrs = ('id', > 'venue', 'date', 'rail', 'weather', 'trackcondition') from the meeting class of the > XML. > > In order to give flexibility and keep the relational nature they have defined in > the table I found when exporting the nominations section via pandas to csv > that i had no way to determine which id belonged to each race that is there > was no race_id in the nominations to relate back to the race, and also no > meeting id in the raceid to relate it back to the meeting. > > > So I wanted to traverse all the classes Meeting, Race and Nomination and > insert the id of the class into its direct children only and since there were > many races a meeting and many nomnations a race I need to ensure that it is > the direct children only. > > It was otherwise working as parsed output in code supplied using to push to > pandas and use its csv write capability. > > So I inserted > > for race_el in d('race'): > race = pq(race_el) > race_id = race.attr('id') > > for nom_el in race.items('nomination'): > res.append((pq(nom_el).attr('raceid', race_id))) > > which traverses and inserts the race_id into the child nominations. However, > my boggles is how to pass this to the list comprehension that was working > without changing the data from XML or creating another intermediate step > and variable. Just to parse it as it was but with the extra included race_id. > > > Thanks > > Sayth > -- > https://mail.python.org/mailman/listinfo/python-list From lijin.abc at gmail.com Thu Apr 28 12:23:44 2016 From: lijin.abc at gmail.com (Jin Li) Date: Thu, 28 Apr 2016 09:23:44 -0700 (PDT) Subject: How to get the closure environment in Python? Message-ID: <9ac71307-b9eb-4cfd-a5c9-31c2144f0b43@googlegroups.com> Hi all, I want to get the closure environment in Python. As in the following example: def func1(): x = 10 def func2(): return 0 return func2 f=func1() print f() How could I get the variable `x` in the environment of `func2()`? i.e. `f()`. Best regards, Jin From steve at pearwood.info Thu Apr 28 12:33:56 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 29 Apr 2016 02:33:56 +1000 Subject: What should Python apps do when asked to show help? Message-ID: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> I have an application written in Python which accepts -h or --help to show help. I can: (1) print the help text to stdout; (2) run the help text through a pager; (3) do something else? Many command line tools simply output help to stdout (or stderr, if they're evil), which makes it easy to redirect the help to a file, pass it to grep, etc. For example: [steve at ando ~]$ wget --help | wc -l 136 Other tools automatically launch a pager, e.g. man. (Admittedly, man --help does not use a pager.) The Python help system, pydoc, does the same. I was thinking that my application could use pydoc: def do_help(): import pydoc pydoc.pager(HELPTEXT) or just print the help text: def do_help(): # Do I really need to show this??? print(HELPTEXT) but I was thinking of doing both: give my application a subcommand or an option to display help directly in a pager, while -h and --help print to stdout as normal. What do you think? Too clever? -- Steven From rgaddi at highlandtechnology.invalid Thu Apr 28 12:42:02 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Thu, 28 Apr 2016 16:42:02 -0000 (UTC) Subject: How to get the closure environment in Python? References: <9ac71307-b9eb-4cfd-a5c9-31c2144f0b43@googlegroups.com> Message-ID: Jin Li wrote: > Hi all, > > I want to get the closure environment in Python. As in the following example: > > def func1(): > x = 10 > def func2(): > return 0 > > return func2 > > f=func1() > print f() > > > How could I get the variable `x` in the environment of `func2()`? i.e. `f()`. > > Best regards, > Jin By using class instances instead of closures. class Foo: def __init__(self, x): self.x == x def __call__(self): return 0 def func1(): return Foo(10) -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From alister.ware at ntlworld.com Thu Apr 28 12:45:09 2016 From: alister.ware at ntlworld.com (alister) Date: Thu, 28 Apr 2016 16:45:09 GMT Subject: What should Python apps do when asked to show help? References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 29 Apr 2016 02:33:56 +1000, Steven D'Aprano wrote: > I have an application written in Python which accepts -h or --help to > show help. I can: > > (1) print the help text to stdout; > > (2) run the help text through a pager; > > (3) do something else? > > > Many command line tools simply output help to stdout (or stderr, if > they're evil), which makes it easy to redirect the help to a file, pass > it to grep, > etc. For example: > > [steve at ando ~]$ wget --help | wc -l 136 > > Other tools automatically launch a pager, e.g. man. (Admittedly, man > --help does not use a pager.) The Python help system, pydoc, does the > same. > > I was thinking that my application could use pydoc: > > def do_help(): > import pydoc pydoc.pager(HELPTEXT) > > or just print the help text: > > def do_help(): > # Do I really need to show this??? > print(HELPTEXT) > > > but I was thinking of doing both: give my application a subcommand or an > option to display help directly in a pager, while -h and --help print to > stdout as normal. > > What do you think? Too clever? Send it to stdout, this gives the user the most choice. if there is enough that I want it paged then I will pipe it to a pager. do one job, do it well and don't reinvent the wheel unnecessarily. -- Nobody shot me. -- Frank Gusenberg, his last words, when asked by police who had shot him 14 times with a machine gun in the Saint Valentine's Day Massacre. Only Capone kills like that. -- George "Bugs" Moran, on the Saint Valentine's Day Massacre The only man who kills like that is Bugs Moran. -- Al Capone, on the Saint Valentine's Day Massacre From yuancao85 at gmail.com Thu Apr 28 12:46:10 2016 From: yuancao85 at gmail.com (Yuan Cao) Date: Thu, 28 Apr 2016 12:46:10 -0400 Subject: How to get the closure environment in Python? In-Reply-To: <9ac71307-b9eb-4cfd-a5c9-31c2144f0b43@googlegroups.com> References: <9ac71307-b9eb-4cfd-a5c9-31c2144f0b43@googlegroups.com> Message-ID: On Thu, Apr 28, 2016 at 12:23 PM, Jin Li wrote: > Hi all, > > I want to get the closure environment in Python. As in the following > example: > > def func1(): > x = 10 > def func2(): > return 0 > > return func2 > > f=func1() > print f() > > > How could I get the variable `x` in the environment of `func2()`? i.e. > `f()`. > > Best regards, > Jin > -- > https://mail.python.org/mailman/listinfo/python-list Hello, You can sort of look into the underlying code by using __code__, and it's associated methods. I was able to get the variable names with: print(funct1.__code__.co_varnames). I was sort of able to get to the value 10 with: print(func1.__code__.co_consts). This way seems pretty messy. Other people probably have more elegant ways of doing this. I hope this helps. Best Regards, Yuan From steve at pearwood.info Thu Apr 28 12:46:31 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 29 Apr 2016 02:46:31 +1000 Subject: How to get the closure environment in Python? References: <9ac71307-b9eb-4cfd-a5c9-31c2144f0b43@googlegroups.com> Message-ID: <57223e69$0$1593$c3e8da3$5496439d@news.astraweb.com> On Fri, 29 Apr 2016 02:23 am, Jin Li wrote: > I want to get the closure environment in Python. As in the following > example: > > def func1(): > x = 10 > def func2(): > return 0 > return func2 > > f=func1() > print f() > > > How could I get the variable `x` in the environment of `func2()`? i.e. > `f()`. In this case, you can't, because f is not a closure. The inner function has to actually use a variable from the enclosing scope to be a closure -- it's just a regular function that simply returns 0. The enclosing x does nothing. You can see this by inspecting f.__closure__, which is None. If we use a better example: def outer(): x = 10 def inner(): return x + 1 return inner f = outer() then you can inspect f.__closure__[0].cell_contents which will return 10 (the value of x). -- Steven From ethan at stoneleaf.us Thu Apr 28 12:49:04 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 28 Apr 2016 09:49:04 -0700 Subject: What should Python apps do when asked to show help? In-Reply-To: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57223F00.5000602@stoneleaf.us> On 04/28/2016 09:33 AM, Steven D'Aprano wrote: > I have an application written in Python which accepts -h or --help to show > help. I can: > > (1) print the help text to stdout; > > (2) run the help text through a pager; > > (3) do something else? I think if the user is proficient enough to: a) run the program from the command line, and b) use the -h / --help switch that they are proficient enough to efficiently use said help when output to stdout. -- ~Ethan~ From D.Strohl at F5.com Thu Apr 28 13:02:23 2016 From: D.Strohl at F5.com (Dan Strohl) Date: Thu, 28 Apr 2016 17:02:23 +0000 Subject: What should Python apps do when asked to show help? In-Reply-To: References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: <118360c7f0a4498e8ed35d6dd15b7ac0@seaexchmbx03.olympus.F5Net.com> I would suggest using argparse https://docs.python.org/3/library/argparse.html as it handles all of that natively... including validating arguments, showing errors, help, etc... however, assuming you don't want to; Send it to stdout, that allows the user to redirect it if they want to (and plays better with other dev-ops tools) Don't run it through a pager, the user can do that if needed... HOWEVER - If you have enough help that you need to page it, consider moving much of it to application documentation (either hosted, or as a doc / txt file). The command line help should simply be enough hints to remember what the various parameters are, not a full explanation about what it can do (unless the app is really simple). - Alternatively, you can have a multi-level help approach where the user can type "app_name argument /help" and get more detailed information about that specific argument. > -----Original Message----- > From: Python-list [mailto:python-list-bounces+d.strohl=f5.com at python.org] > On Behalf Of alister > Sent: Thursday, April 28, 2016 9:45 AM > To: python-list at python.org > Subject: Re: What should Python apps do when asked to show help? > > On Fri, 29 Apr 2016 02:33:56 +1000, Steven D'Aprano wrote: > > > I have an application written in Python which accepts -h or --help to > > show help. I can: > > > > (1) print the help text to stdout; > > > > (2) run the help text through a pager; > > > > (3) do something else? > > > > > > Many command line tools simply output help to stdout (or stderr, if > > they're evil), which makes it easy to redirect the help to a file, > > pass it to grep, etc. For example: > > > > [steve at ando ~]$ wget --help | wc -l 136 > > > > Other tools automatically launch a pager, e.g. man. (Admittedly, man > > --help does not use a pager.) The Python help system, pydoc, does the > > same. > > > > I was thinking that my application could use pydoc: > > > > def do_help(): > > import pydoc pydoc.pager(HELPTEXT) > > > > or just print the help text: > > > > def do_help(): > > # Do I really need to show this??? > > print(HELPTEXT) > > > > > > but I was thinking of doing both: give my application a subcommand or > > an option to display help directly in a pager, while -h and --help > > print to stdout as normal. > > > > What do you think? Too clever? > > Send it to stdout, this gives the user the most choice. > > if there is enough that I want it paged then I will pipe it to a pager. > > do one job, do it well and don't reinvent the wheel unnecessarily. > > > > -- > Nobody shot me. > -- Frank Gusenberg, his last words, when asked by police > who had shot him 14 times with a machine gun in the Saint > Valentine's Day Massacre. > > Only Capone kills like that. > -- George "Bugs" Moran, on the Saint Valentine's Day > Massacre > > The only man who kills like that is Bugs Moran. > -- Al Capone, on the Saint Valentine's Day Massacre > -- > https://mail.python.org/mailman/listinfo/python-list From gokoproject at gmail.com Thu Apr 28 13:05:51 2016 From: gokoproject at gmail.com (John Wong) Date: Thu, 28 Apr 2016 13:05:51 -0400 Subject: What should Python apps do when asked to show help? In-Reply-To: <118360c7f0a4498e8ed35d6dd15b7ac0@seaexchmbx03.olympus.F5Net.com> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <118360c7f0a4498e8ed35d6dd15b7ac0@seaexchmbx03.olympus.F5Net.com> Message-ID: On Thu, Apr 28, 2016 at 1:02 PM, Dan Strohl via Python-list < python-list at python.org> wrote: > I would suggest using argparse > https://docs.python.org/3/library/argparse.html as it handles all of that > natively... including validating arguments, showing errors, help, etc... > however, assuming you don't want to; > > Totally agree with this approach. Command line should stick with argparse. Personally I'd stick with argparse and not other open source projects which is built on argparse (or optparse, the one you don't want to use, but eh some people decided to do that anyway because of some limitations in argparse). In fact you shouldn't need to implement -h/--help when you use argparse. If a user is going to use the command line, you can almost always assume the user can use -h/--help, or for those familiar with Linux just provide a man page. After all, what you need is a very clear documentation upfront prior to the installation so your users can refer to that for ultimate help. From rosuav at gmail.com Thu Apr 28 13:06:22 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Apr 2016 03:06:22 +1000 Subject: What should Python apps do when asked to show help? In-Reply-To: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 29, 2016 at 2:33 AM, Steven D'Aprano wrote: > I have an application written in Python which accepts -h or --help to show > help. I can: > > (1) print the help text to stdout; > > (2) run the help text through a pager; > > (3) do something else? > > > Many command line tools simply output help to stdout (or stderr, if they're > evil), I'm not sure stderr is particularly more evil than stdout, but whatever :) What you could do is run the help text through a pager only if stdout is a TTY. That allows it to be grepped conveniently, but also browsed easily. But I wouldn't worry about that unless you have at least 3-5 pages of screed - for most programs, just dumping the text to a standard stream is usually enough. ChrisA From irmen.NOSPAM at xs4all.nl Thu Apr 28 13:08:14 2016 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Thu, 28 Apr 2016 19:08:14 +0200 Subject: What should Python apps do when asked to show help? In-Reply-To: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57224382$0$5808$e4fe514c@news.xs4all.nl> On 28-4-2016 18:33, Steven D'Aprano wrote: > but I was thinking of doing both: give my application a subcommand or an > option to display help directly in a pager, while -h and --help print to > stdout as normal. > > What do you think? Too clever? An idea: Use just one help option, then if sys.stdout.isatty(): #....use a pager to display help text else: #....print all help text normally Irmen From D.Strohl at F5.com Thu Apr 28 13:25:54 2016 From: D.Strohl at F5.com (Dan Strohl) Date: Thu, 28 Apr 2016 17:25:54 +0000 Subject: What should Python apps do when asked to show help? In-Reply-To: References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <118360c7f0a4498e8ed35d6dd15b7ac0@seaexchmbx03.olympus.F5Net.com> Message-ID: Yeah, if I am handling arguments from the command line, I use argparse, if I am doing a cli based app (so, going back and forth in interacting with the command line), I would look at clint (https://github.com/kennethreitz/clint) As many people have said here, don?t reinvent the wheel. Dan From: John Wong [mailto:gokoproject at gmail.com] Sent: Thursday, April 28, 2016 10:06 AM To: Dan Strohl Cc: alister ; python-list at python.org Subject: Re: What should Python apps do when asked to show help? On Thu, Apr 28, 2016 at 1:02 PM, Dan Strohl via Python-list > wrote: I would suggest using argparse https://docs.python.org/3/library/argparse.html as it handles all of that natively... including validating arguments, showing errors, help, etc... however, assuming you don't want to; Totally agree with this approach. Command line should stick with argparse. Personally I'd stick with argparse and not other open source projects which is built on argparse (or optparse, the one you don't want to use, but eh some people decided to do that anyway because of some limitations in argparse). In fact you shouldn't need to implement -h/--help when you use argparse. If a user is going to use the command line, you can almost always assume the user can use -h/--help, or for those familiar with Linux just provide a man page. After all, what you need is a very clear documentation upfront prior to the installation so your users can refer to that for ultimate help. From ethan at stoneleaf.us Thu Apr 28 13:27:42 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 28 Apr 2016 10:27:42 -0700 Subject: What should Python apps do when asked to show help? In-Reply-To: <118360c7f0a4498e8ed35d6dd15b7ac0@seaexchmbx03.olympus.F5Net.com> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <118360c7f0a4498e8ed35d6dd15b7ac0@seaexchmbx03.olympus.F5Net.com> Message-ID: <5722480E.7020102@stoneleaf.us> On 04/28/2016 10:02 AM, Dan Strohl via Python-list wrote: > I would suggest using argparse https://docs.python.org/3/library/argparse.html as it handles all of that natively... On the other hand, if you feel that argparse is akin to using a canon to kill a mosquito, you can try scription*: - not argparse based - simple to use - supports flags, options, multioptions - supports --help (and -h if no other parameter uses that abbreviation) - supports --verbose (and -v of no other . . .) - supports --version - script parameters are global - (sub)command parameters are local -- ~Ethan~ * https://pypi.python.org/pypi/scription P.S. Yes, my package. ;) Created both for the learning, and because I feel like argparse is overpowered, complicated, and un-fun for scripts. From jussi.piitulainen at helsinki.fi Thu Apr 28 13:30:04 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Thu, 28 Apr 2016 20:30:04 +0300 Subject: What should Python apps do when asked to show help? References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > I have an application written in Python which accepts -h or --help to > show help. I can: > > (1) print the help text to stdout; > > (2) run the help text through a pager; > > (3) do something else? > > > Many command line tools simply output help to stdout (or stderr, if > they're evil), which makes it easy to redirect the help to a file, > pass it to grep, etc. For example: > > [steve at ando ~]$ wget --help | wc -l > 136 > > Other tools automatically launch a pager, e.g. man. (Admittedly, man > --help does not use a pager.) The Python help system, pydoc, does the > same. > > I was thinking that my application could use pydoc: > > def do_help(): > import pydoc > pydoc.pager(HELPTEXT) > > or just print the help text: > > def do_help(): > # Do I really need to show this??? > print(HELPTEXT) > > > but I was thinking of doing both: give my application a subcommand or > an option to display help directly in a pager, while -h and --help > print to stdout as normal. > > What do you think? Too clever? Keep --help, -h reasonably short and print it to stdout. That's what I expect and then I know what to do with it. An actual man page is the obvious place for more documentation. The --help text can tell where more information is available. From random832 at fastmail.com Thu Apr 28 13:30:06 2016 From: random832 at fastmail.com (Random832) Date: Thu, 28 Apr 2016 13:30:06 -0400 Subject: What should Python apps do when asked to show help? In-Reply-To: References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1461864606.3216317.592558881.0591528C@webmail.messagingengine.com> On Thu, Apr 28, 2016, at 13:06, Chris Angelico wrote: > On Fri, Apr 29, 2016 at 2:33 AM, Steven D'Aprano > wrote: > > Many command line tools simply output help to stdout (or stderr, if they're > > evil), > > I'm not sure stderr is particularly more evil than stdout, but whatever > :) When a tool has very long help and sends it to stderr: $ foo --help ok, it's scrolled off the top, and I could just scroll up, but it's so long I'll have to search for what I want anyway. $ foo --help | less *help flashes on the screen, then blank ~~~~~~ screen from less* #@!@#$#$!#$!@#$@#!$@!#$!@#$!@#$!@#$!@#$ $ foo --help 2>&1 | less Basically the only reason this ever happens is that programmers get lazy and use the same function for usage errors as for --help. A usage error message *should* go to stderr (in order to show up if the program's output has been redirected to null, and so as not to be silently piped to something that expects the program's normal output), but it should be short. Help should go to stdout because the user actually requested it. The obvious exception, and probably the bad example that people are following, is programs that don't actually *have* --help, but briefly summarize all their options and the meanings of positional arguments in the usage error. People start with that, and then expand it to a full-blown GNU-style --help message, but continue sending it to stderr. From marko at pacujo.net Thu Apr 28 13:31:37 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 28 Apr 2016 20:31:37 +0300 Subject: What should Python apps do when asked to show help? References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <57224382$0$5808$e4fe514c@news.xs4all.nl> Message-ID: <87pot9skqu.fsf@elektro.pacujo.net> Irmen de Jong : > An idea: Use just one help option, then > > if sys.stdout.isatty(): > #....use a pager to display help text > else: > #....print all help text normally I've seen that used, but I find it annoying: ======================================================================== $ man ls WARNING: terminal is not fully functional - (press RETURN) ======================================================================== ======================================================================== $ git diff WARNING: terminal is not fully functional - (press RETURN) ======================================================================== when run in emacs' Shell Mode. Even Ctrl-C doesn't get me out of it. I curse to myself and run again: ======================================================================== $ git diff | cat ... ======================================================================== Marko From D.Strohl at F5.com Thu Apr 28 13:32:29 2016 From: D.Strohl at F5.com (Dan Strohl) Date: Thu, 28 Apr 2016 17:32:29 +0000 Subject: What should Python apps do when asked to show help? In-Reply-To: <57224382$0$5808$e4fe514c@news.xs4all.nl> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <57224382$0$5808$e4fe514c@news.xs4all.nl> Message-ID: I would hesitate to take this approach unless the tool was one that only I was going to be using, and I knew exactly what environments it was going to be in. I know that many of the system items in python work differently in different operating systems, and different os's report things differently as well as different ways of launching things. So, for example, I have seen cases where tools such as webmin will try to run a command line tool, and end up hung because they are waiting on a keypress for the next screen... While I might do it as a way of setting a default, I would still want to have the ability to force a pager, or force no pager. I've been bit too many times by programmers doing things automatically for me that I didn't want. I think that most people who use command line tools these days will be able to figure out how to pipe it to "more" if needed (or whatever). Dan > -----Original Message----- > From: Python-list [mailto:python-list-bounces+d.strohl=f5.com at python.org] > On Behalf Of Irmen de Jong > Sent: Thursday, April 28, 2016 10:08 AM > To: python-list at python.org > Subject: Re: What should Python apps do when asked to show help? > > On 28-4-2016 18:33, Steven D'Aprano wrote: > > > > but I was thinking of doing both: give my application a subcommand or > > an option to display help directly in a pager, while -h and --help > > print to stdout as normal. > > > > What do you think? Too clever? > > An idea: Use just one help option, then > > if sys.stdout.isatty(): > #....use a pager to display help text > else: > #....print all help text normally > > > Irmen > > -- > https://mail.python.org/mailman/listinfo/python-list From grant.b.edwards at gmail.com Thu Apr 28 13:33:48 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 28 Apr 2016 17:33:48 +0000 (UTC) Subject: What should Python apps do when asked to show help? References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-04-28, Steven D'Aprano wrote: > I have an application written in Python which accepts -h or --help to show > help. I can: > > (1) print the help text to stdout; Yep: just write it to stdout. > (2) run the help text through a pager; If you do (1), and I can do that myself if that's what I want. > (3) do something else? Nope (at least not by default). > Many command line tools simply output help to stdout (or stderr, if > they're evil), Yep, writing help output to stderr is annoying. > which makes it easy to redirect the help to a file, pass it to grep, > etc. Exactly. > but I was thinking of doing both: give my application a subcommand or an > option to display help directly in a pager, while -h and --help print to > stdout as normal. > > What do you think? Too clever? As long as -? -h --help just write stuff to stdout you can add whatever other options you like that run pagers, start up web browsers, or show mp4 movies on the wall without annoying grouchy old Unix users like me. ;) -- Grant Edwards grant.b.edwards Yow! FOOLED you! Absorb at EGO SHATTERING impulse gmail.com rays, polyester poltroon!! From D.Strohl at F5.com Thu Apr 28 13:39:57 2016 From: D.Strohl at F5.com (Dan Strohl) Date: Thu, 28 Apr 2016 17:39:57 +0000 Subject: What should Python apps do when asked to show help? In-Reply-To: <1461864606.3216317.592558881.0591528C@webmail.messagingengine.com> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461864606.3216317.592558881.0591528C@webmail.messagingengine.com> Message-ID: Yup.. another reason to use something like argparse... you define the argument descriptions, help, and when you raise an error, it automatically handles the output, sending it to the right place (stderr/stdout)... as well as allowing you to define different levels of verbosity easily... (or not if you don't want) Argparse isn't the best tool in the world, and there are some things that annoy me about it sometimes, but it works pretty well within its boundaries. (and if the code's already written, I'm not suggesting that it be re-written just to move it to a common library. > -----Original Message----- > From: Python-list [mailto:python-list-bounces+d.strohl=f5.com at python.org] > On Behalf Of Random832 > Sent: Thursday, April 28, 2016 10:30 AM > To: python-list at python.org > Subject: Re: What should Python apps do when asked to show help? > > On Thu, Apr 28, 2016, at 13:06, Chris Angelico wrote: > > On Fri, Apr 29, 2016 at 2:33 AM, Steven D'Aprano > > wrote: > > > Many command line tools simply output help to stdout (or stderr, if > > > they're evil), > > > > I'm not sure stderr is particularly more evil than stdout, but > > whatever > > :) > > When a tool has very long help and sends it to stderr: > > $ foo --help > ok, it's scrolled off the top, and I could just scroll up, but it's so long I'll have to > search for what I want anyway. > $ foo --help | less > *help flashes on the screen, then blank ~~~~~~ screen from less* > #@!@#$#$!#$!@#$@#!$@!#$!@#$!@#$!@#$!@#$ > $ foo --help 2>&1 | less > > Basically the only reason this ever happens is that programmers get lazy and > use the same function for usage errors as for --help. A usage error message > *should* go to stderr (in order to show up if the program's output has been > redirected to null, and so as not to be silently piped to something that > expects the program's normal output), but it should be short. Help should go > to stdout because the user actually requested it. > > The obvious exception, and probably the bad example that people are > following, is programs that don't actually *have* --help, but briefly > summarize all their options and the meanings of positional arguments in the > usage error. People start with that, and then expand it to a full-blown GNU- > style --help message, but continue sending it to stderr. > -- > https://mail.python.org/mailman/listinfo/python-list From random832 at fastmail.com Thu Apr 28 13:40:10 2016 From: random832 at fastmail.com (Random832) Date: Thu, 28 Apr 2016 13:40:10 -0400 Subject: What should Python apps do when asked to show help? In-Reply-To: References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1461865210.3218352.592571425.2069E4EB@webmail.messagingengine.com> On Thu, Apr 28, 2016, at 13:33, Grant Edwards wrote: > As long as -? -h --help just write stuff to stdout you can add > whatever other options you like that run pagers, start up web > browsers, or show mp4 movies on the wall without annoying grouchy old > Unix users like me. ;) One disadvantage is that you have to compose two forms of documentation. I suspect this is why git [command] --help just opens the manpage. (It helps that man itself just sends output to stdout when not outputting to a tty... though it's very annoying that on Windows it opens it in a web browser instead.) From grant.b.edwards at gmail.com Thu Apr 28 14:14:41 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 28 Apr 2016 18:14:41 +0000 (UTC) Subject: What should Python apps do when asked to show help? References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461865210.3218352.592571425.2069E4EB@webmail.messagingengine.com> Message-ID: On 2016-04-28, Random832 wrote: > > > On Thu, Apr 28, 2016, at 13:33, Grant Edwards wrote: >> As long as -? -h --help just write stuff to stdout you can add >> whatever other options you like that run pagers, start up web >> browsers, or show mp4 movies on the wall without annoying grouchy old >> Unix users like me. ;) > > One disadvantage is that you have to compose two forms of documentation. Only if you want two forms of documentation. If you add an option to run the help info through a pager, I don't see how that requires you to compose two forms for documentation. If you want both plaintext and video help, then yes you'll have to prepare two forms of documentation. > I suspect this is why git [command] --help just opens the > manpage. (It helps that man itself just sends output to stdout when > not outputting to a tty... though it's very annoying that on Windows > it opens it in a web browser instead.) I don't understand. If you want your comand-line help info to be in manpage format, that doesn't mean you have to run it through a pager or open a new window running the man command, just write the formatted text to stdout. -- Grant Edwards grant.b.edwards Yow! My mind is making at ashtrays in Dayton ... gmail.com From marko at pacujo.net Thu Apr 28 14:31:50 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 28 Apr 2016 21:31:50 +0300 Subject: What should Python apps do when asked to show help? References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461865210.3218352.592571425.2069E4EB@webmail.messagingengine.com> Message-ID: <87a8kdshyh.fsf@elektro.pacujo.net> Grant Edwards : > On 2016-04-28, Random832 wrote: >> One disadvantage is that you have to compose two forms of >> documentation. > > Only if you want two forms of documentation. > > If you add an option to run the help info through a pager, I don't see > how that requires you to compose two forms for documentation. If you > want both plaintext and video help, then yes you'll have to prepare > two forms of documentation. I wouldn't want --help to output a reference manual. Consider GNU tar: tar --help ==> a list of options man tar ==> a description of the command and the options info tar ==> a user manual Marko From grant.b.edwards at gmail.com Thu Apr 28 14:36:37 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 28 Apr 2016 18:36:37 +0000 (UTC) Subject: Best way to do subversion stuff Message-ID: I'd like to write some small command-line utilities to do some tasks in subversion: * Do a commit that includes all modified externals. * Do a status that includes status of all externals. * Do a log that combines logs of . and all externals. There appear to be three options: 1) pysvn This seems to be the canonical Python API, but is a little out of date (I'd have to downgrade subversion from 1.9.3 to 1.9.1). 2) PySvn Doesn't do commit or status operations and doesn't handle externals at all. AFIACT it's running the the command-line /usr/bin/svn with various options. Nice job picking a name that's not going to get mixed up with pysvn. ;) 3) os.subproces + /usr/bin/svn This is more or less re-inventing 2) The xml output option makes this approach fairly easy. It might be faster to write something special-purpose from scratch than to figure out the internals of PySvn and modify it to add the operations/options I want. Any recommendations? -- Grant Edwards grant.b.edwards Yow! Finally, Zippy at drives his 1958 RAMBLER gmail.com METROPOLITAN into the faculty dining room. From davidgshi at yahoo.co.uk Thu Apr 28 14:37:55 2016 From: davidgshi at yahoo.co.uk (David Shi) Date: Thu, 28 Apr 2016 18:37:55 +0000 (UTC) Subject: Simplest way to locate a string in a column and get the value on the same row in another column In-Reply-To: <759417988.6710506.1461868599459.JavaMail.yahoo@mail.yahoo.com> References: <759417988.6710506.1461868599459.JavaMail.yahoo.ref@mail.yahoo.com> <759417988.6710506.1461868599459.JavaMail.yahoo@mail.yahoo.com> Message-ID: <1650815019.6612341.1461868675273.JavaMail.yahoo@mail.yahoo.com> What is the simplest way to locate a string in a column and get the value on the same row in another column ? 1 ?a2 ?b3 ?c Locate b and obtain 2 in a table. Looking forward to hearing from you. Regards. David From python.list at tim.thechases.com Thu Apr 28 15:06:51 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 28 Apr 2016 14:06:51 -0500 Subject: Simplest way to locate a string in a column and get the value on the same row in another column In-Reply-To: <1650815019.6612341.1461868675273.JavaMail.yahoo@mail.yahoo.com> References: <759417988.6710506.1461868599459.JavaMail.yahoo.ref@mail.yahoo.com> <759417988.6710506.1461868599459.JavaMail.yahoo@mail.yahoo.com> <1650815019.6612341.1461868675273.JavaMail.yahoo@mail.yahoo.com> Message-ID: <20160428140651.36ce5e63@bigbox.christie.dr> On 2016-04-28 18:37, David Shi via Python-list wrote: > What is the simplest way to locate a string in a column and get > the value on the same row in another column ? 1 ?a2 ?b3 ?c > Locate b and obtain 2 in a table. > Looking forward to hearing from you. I've had success with using regexp matches with their start/stop location information: s1 = "1 a2 b3 c" s2 = "abcdefghijklmn" import re r = re.compile(r"a2\s*") # define the pattern you want m = r.search(s1) if m: # if our pattern was in the header # take the corresponding slice out of s2 result = s2[m.start():m.end()] # 'defghi' This also works nicely with re.finditer() as I've had column-delimited files where each header had no spaces EMPID FIRST_NAME LAST_NAME 123456 John Smith 234567 Ellen Miller so I did something like r = re.compile(r"(\S+)\s*") with open("data.txt") as f: headers = next(f) header_map = dict( (m.group(1), slice(m.start(), m.end())) for m in r.finditer(headers) ) for row in f: empid = row[header_map["EMPID"]].rstrip() fname = row[header_map["FIRST_NAME"]].rstrip() lname = row[header_map["LAST_NAME"]].rstrip() process(empid, fname, lname) # or # data = dict( # (field, row[slc]) # for field, slc in row.items() # ) # process(data) Hope this gives you some helpful techniques. -tkc From gordon at panix.com Thu Apr 28 15:08:56 2016 From: gordon at panix.com (John Gordon) Date: Thu, 28 Apr 2016 19:08:56 +0000 (UTC) Subject: Simplest way to locate a string in a column and get the value on the same row in another column References: <759417988.6710506.1461868599459.JavaMail.yahoo.ref@mail.yahoo.com> <759417988.6710506.1461868599459.JavaMail.yahoo@mail.yahoo.com> <1650815019.6612341.1461868675273.JavaMail.yahoo@mail.yahoo.com> Message-ID: In David Shi writes: > What is the simplest way to locate a string in a column and get the value > on the same row in another column ? You haven't given enough context for us to be able to answer. Are you talking about a spreadsheet, a database table, an HTML table, or something else? -- 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 grant.b.edwards at gmail.com Thu Apr 28 15:39:19 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 28 Apr 2016 19:39:19 +0000 (UTC) Subject: What should Python apps do when asked to show help? References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461865210.3218352.592571425.2069E4EB@webmail.messagingengine.com> <87a8kdshyh.fsf@elektro.pacujo.net> Message-ID: On 2016-04-28, Marko Rauhamaa wrote: > Grant Edwards : > >> On 2016-04-28, Random832 wrote: >>> One disadvantage is that you have to compose two forms of >>> documentation. >> >> Only if you want two forms of documentation. >> >> If you add an option to run the help info through a pager, I don't see >> how that requires you to compose two forms for documentation. If you >> want both plaintext and video help, then yes you'll have to prepare >> two forms of documentation. > > I wouldn't want --help to output a reference manual. > > Consider GNU tar: > > tar --help ==> a list of options > man tar ==> a description of the command and the options > info tar ==> a user manual That's fine. If you want two or three forms of documentation then you prepare two or three forms of documentation. Adding an option to run the default 'help' output through a pager or display it in a web browser doesn't somehow force you "to compose two forms of documentation" unless you want two forms of documentation. -- Grant Edwards grant.b.edwards Yow! A dwarf is passing out at somewhere in Detroit! gmail.com From cs at zip.com.au Thu Apr 28 15:49:36 2016 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 29 Apr 2016 05:49:36 +1000 Subject: What should Python apps do when asked to show help? In-Reply-To: References: Message-ID: <20160428194936.GA19597@cskk.homeip.net> On 29Apr2016 03:06, Chris Angelico wrote: >On Fri, Apr 29, 2016 at 2:33 AM, Steven D'Aprano wrote: >> I have an application written in Python which accepts -h or --help to show >> help. I can: >> >> (1) print the help text to stdout; >> >> (2) run the help text through a pager; >> >> (3) do something else? >> >> >> Many command line tools simply output help to stdout (or stderr, if they're >> evil), > >I'm not sure stderr is particularly more evil than stdout, but whatever :) I'm sure. If I _ask_ for the help information, it is not an error message. Instead it is desired output. The logic is clear. If I screw up and elicit an error and the usage message (which might be the help text), that is an error message. But -h/--help? That is standard output, even if it is the same usage text. And on this topic, let me preemptively flame commands whose entire usage message is "use -h/--help for usage". More evil. >What you could do is run the help text through a pager only if stdout >is a TTY. That allows it to be grepped conveniently, but also browsed >easily. But I wouldn't worry about that unless you have at least 3-5 >pages of screed - for most programs, just dumping the text to a >standard stream is usually enough. +1 to this. I'm -0 on conditionally offering a pager based on isatty; Marko Rauhamaa has illustrated one downside, and personally I find _unexpectedly_ paged output to be jarring, requiring me to modeshift my brain. So I'm for keeping it simple and just sending it to stdout. Cheers, Cameron Simpson From random832 at fastmail.com Thu Apr 28 15:51:25 2016 From: random832 at fastmail.com (Random832) Date: Thu, 28 Apr 2016 15:51:25 -0400 Subject: What should Python apps do when asked to show help? In-Reply-To: References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461865210.3218352.592571425.2069E4EB@webmail.messagingengine.com> <87a8kdshyh.fsf@elektro.pacujo.net> Message-ID: <1461873085.3251720.592695601.44633E5E@webmail.messagingengine.com> On Thu, Apr 28, 2016, at 15:39, Grant Edwards wrote: > That's fine. If you want two or three forms of documentation then you > prepare two or three forms of documentation. > > Adding an option to run the default 'help' output through a pager or > display it in a web browser doesn't somehow force you "to compose two > forms of documentation" unless you want two forms of documentation. The point is that having "help" output at all (beyond either a cursory "see the manpage") implies two forms of documentation (given you already have a manpage), and some people choose not to do that, instead launching directly into the manpage (which implies using a pager) From alister.ware at ntlworld.com Thu Apr 28 16:11:27 2016 From: alister.ware at ntlworld.com (alister) Date: Thu, 28 Apr 2016 20:11:27 GMT Subject: Have I ofended someone? Message-ID: I don't see my posts appearing, posting to news group using Pan on Linux. posts to other news groups are fine -- Just about every computer on the market today runs Unix, except the Mac (and nobody cares about it). -- Bill Joy 6/21/85 From marko at pacujo.net Thu Apr 28 16:12:08 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 28 Apr 2016 23:12:08 +0300 Subject: Have I ofended someone? References: Message-ID: <8760v1sdbb.fsf@elektro.pacujo.net> alister : > I don't see my posts appearing, posting to news group using Pan on > Linux. posts to other news groups are fine Take yourself out of your killfile. Marko From alister.ware at ntlworld.com Thu Apr 28 16:13:38 2016 From: alister.ware at ntlworld.com (alister) Date: Thu, 28 Apr 2016 20:13:38 GMT Subject: Have I ofended someone? References: Message-ID: On Thu, 28 Apr 2016 20:11:27 +0000, alister wrote: > I don't see my posts appearing, posting to news group using Pan on > Linux. > posts to other news groups are fine No just going blind Someone top-posted to my last reply & then everything got snipped to restore readability. -- Be careful what you set your heart on -- for it will surely be yours. -- James Baldwin, "Nobody Knows My Name" From grant.b.edwards at gmail.com Thu Apr 28 17:08:47 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 28 Apr 2016 21:08:47 +0000 (UTC) Subject: What should Python apps do when asked to show help? References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461865210.3218352.592571425.2069E4EB@webmail.messagingengine.com> <87a8kdshyh.fsf@elektro.pacujo.net> <1461873085.3251720.592695601.44633E5E@webmail.messagingengine.com> Message-ID: On 2016-04-28, Random832 wrote: > On Thu, Apr 28, 2016, at 15:39, Grant Edwards wrote: >> That's fine. If you want two or three forms of documentation then you >> prepare two or three forms of documentation. >> >> Adding an option to run the default 'help' output through a pager or >> display it in a web browser doesn't somehow force you "to compose two >> forms of documentation" unless you want two forms of documentation. > > The point is that having "help" output at all (beyond either a cursory > "see the manpage") implies two forms of documentation (given you already > have a manpage), and some people choose not to do that, instead > launching directly into the manpage (which implies using a pager) But I'm saying that having --help output the manpage should not imply using a pager. If --help is going to output the manpage, then I'm saying it can (and should) be written to stdout without use of pager (and it shouldn't have escape sequences or backspaces in it either). The Unix way is that the output from whatever --help should be plain text written to stdout (regardless of length). If you want to output the man page, this can be accomplished simply by doing someting like: os.environ["GROFF_NO_SGR"] = "1"; os.system("man -Tascii mycmd | col -bx"); If I want the --help output run through a pager, I'll do it myself. I agree that a good argument can be made that the --help output should be a concise summary, and that a separate longer man page might be a good idea. But whatever you decide to provide when invoked with --help it should be plaintext written to stdout. No pagers, no colors, no HTML. [if you're really going to invoke the 'man' command, you should do it with the subprocess module with shell=False -- but examples with os.system() are easier to grok] -- Grant Edwards grant.b.edwards Yow! Sometime in 1993 at NANCY SINATRA will lead a gmail.com BLOODLESS COUP on GUAM!! From davidgshi at yahoo.co.uk Thu Apr 28 19:38:41 2016 From: davidgshi at yahoo.co.uk (David Shi) Date: Thu, 28 Apr 2016 23:38:41 +0000 (UTC) Subject: Pivot table of Pandas In-Reply-To: <1369944594.6701652.1461886649215.JavaMail.yahoo@mail.yahoo.com> References: <1369944594.6701652.1461886649215.JavaMail.yahoo.ref@mail.yahoo.com> <1369944594.6701652.1461886649215.JavaMail.yahoo@mail.yahoo.com> Message-ID: <165702145.6760238.1461886721299.JavaMail.yahoo@mail.yahoo.com> Hello, Matt, Please see the web link.Pandas Pivot Table?Explained | ? | | ? | ? | ? | ? | ? | | Pandas Pivot Table?ExplainedExplanation of pandas pivot_table function. | | | | View on?pbpython.com | Preview by Yahoo | | | | ? | Debra and Fred have their own groups. How to split the pivot table into separate tables? What types of objects are these pivot tables? How to access the "manager" column? the pivot table is interesting to users, but it is very different from databases which we normally know. Looking forward to hearing from you. Regards. David From greg.ewing at canterbury.ac.nz Thu Apr 28 20:48:05 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 29 Apr 2016 12:48:05 +1200 Subject: Pythonic style In-Reply-To: References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <572188F8.7010304@stoneleaf.us> <540fc958-52d6-6049-75f2-5ee42657688e@mrabarnett.plus.com> Message-ID: MRAB wrote: > Is it worthy of being in the Zen of Python? +1. Maybe something along the lines of: Dunder methods are for defining, not calling. Unless you're a dunderhead[1]. [1] Meant in the sense of an enthusiast, cf. gearhead. -- Greg From rosuav at gmail.com Thu Apr 28 20:57:11 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Apr 2016 10:57:11 +1000 Subject: Pythonic style In-Reply-To: References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <572188F8.7010304@stoneleaf.us> <540fc958-52d6-6049-75f2-5ee42657688e@mrabarnett.plus.com> Message-ID: On Fri, Apr 29, 2016 at 10:48 AM, Gregory Ewing wrote: > MRAB wrote: > >> Is it worthy of being in the Zen of Python? > > > +1. Maybe something along the lines of: > > Dunder methods are for defining, not calling. > Unless you're a dunderhead[1]. > > [1] Meant in the sense of an enthusiast, cf. gearhead. I thought the twentieth zen would never be found? ChrisA From steve at pearwood.info Thu Apr 28 21:40:17 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 29 Apr 2016 11:40:17 +1000 Subject: What should Python apps do when asked to show help? References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461865210.3218352.592571425.2069E4EB@webmail.messagingengine.com> <87a8kdshyh.fsf@elektro.pacujo.net> <1461873085.3251720.592695601.44633E5E@webmail.messagingengine.com> Message-ID: <5722bb82$0$1600$c3e8da3$5496439d@news.astraweb.com> On Fri, 29 Apr 2016 07:08 am, Grant Edwards wrote: > On 2016-04-28, Random832 wrote: >> On Thu, Apr 28, 2016, at 15:39, Grant Edwards wrote: >>> That's fine. If you want two or three forms of documentation then you >>> prepare two or three forms of documentation. >>> >>> Adding an option to run the default 'help' output through a pager or >>> display it in a web browser doesn't somehow force you "to compose two >>> forms of documentation" unless you want two forms of documentation. >> >> The point is that having "help" output at all (beyond either a cursory >> "see the manpage") implies two forms of documentation (given you already >> have a manpage), and some people choose not to do that, instead >> launching directly into the manpage (which implies using a pager) > > But I'm saying that having --help output the manpage should not imply > using a pager. What manpage? I don't have a manpage. The only help my application has is whatever it outputs (which it gets from its docstring). What is a good place where I can find out more about writing manpages? > If --help is going to output the manpage, then I'm saying it can (and > should) be written to stdout without use of pager (and it shouldn't > have escape sequences or backspaces in it either). The Unix way is > that the output from whatever --help should be plain text written to > stdout (regardless of length). Agree. The -h/--help option will output plain text to stdout. > If you want to output the man page, this can be accomplished simply by > doing someting like: > > os.environ["GROFF_NO_SGR"] = "1"; > os.system("man -Tascii mycmd | col -bx"); That doesn't work for me: [steve at ando ~]$ man -Tasciii rm man: invalid option -- T However, this almost works: man -Pcat rm appears to output unformatted, plain text to stdout. However, if you capture the output (say, to a file) you'll see it is full of backspaces, e.g.: N^HNA^HAM^HME^HE rm - remove files or directories S^HSY^HYN^HNO^HOP^HPS^HSI^HIS^HS r^Hrm^Hm [_^HO_^HP_^HT_^HI_^HO_^HN]... _^HF_^HI_^HL_^HE... instead of NAME rm - remove files or directories SYNOPSIS rm [OPTION]... FILE... Apparently `less` understands overstriking and displays it as bold (or underlining in the case of _^H. That's very clever, but how do I get actual plain text out of `man` without the backspaces? > If I want the --help output run through a pager, I'll do it myself. Easy enough to say for Linux/Unix users, but there are those who might not have a pager that is easy to use, or at all. pydoc goes to considerable trouble to work out the best pager available for your platform, falling back to its own if needed. To use that is literally a two liner: import pydoc pydoc.pager(HELPTEXT) -- Steven From flebber.crue at gmail.com Thu Apr 28 21:49:14 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 28 Apr 2016 18:49:14 -0700 (PDT) Subject: Controlling the passing of data In-Reply-To: References: <5c94882cb24c441bad13fd122851bd38@seaexchmbx03.olympus.F5Net.com> Message-ID: <892ed2df-b5ee-48ba-9cdc-4c05a8f097ab@googlegroups.com> On Friday, 29 April 2016 01:19:28 UTC+10, Dan Strohl wrote: > If I am reading this correctly... you have something like (you will have to excuse my lack of knowledge about what kinds of information these actually are): > > > 1234 > first > > > 5678 > second > > > > And you want something like: > nominations = [(1,1234), (2,5678)] > meetings = [(1,'first'),(2,'second')] > > if that is correct, my suggestion is to do something like (this is psudeo code, I didn't look up the exact calls to use): > > nomination_list = [] > meeting_list = [] > > for race_element in xml_file('race'): > id = race_element.get_attr('id') > for nomination_element in race_element('nomination'): > nomination = nomination_element.get_text() > nomination_list.append((id, nomination)) > > for meeting_element in race_element('meeting'): > meeting = meeting_element.get_text() > meeting_list.append((id, meeting)) > > > > Yes in essence that is what I am trying to acheive however the XML I have has many attributes like this. for example this is one nomination. Therefore I thought that if I tried to do it like the code you posted it would soon become unweildy. > for race_element in xml_file('race'): > id = race_element.get_attr('id') > for nomination_element in race_element('nomination'): > nomination = nomination_element.get_text() > nomination_list.append((id, nomination)) So I created a list of the attributes of each class meeting race nomination and then parsed that list through the list comprehension. On putting out the code though I realised that whilst each class worked I had no way to relate the race to the meeting, the nomination to the race so if I then loaded the csv or created sql to push it to a db it would loose its relation. So when I say meetattrs = ('id', 'venue', 'date', 'rail', 'weather', 'trackcondition') In my thinking this is a table. Meeting id venue date rail weather trackcondition There is no foreign key relation to race, so in this question I am saying shouldn't I put the meeting_id as a foreign key into the race attributes before parsing race and then I can have a 'id' in meeting related to the new 'race_id' in race. The id of race would then be put in nomnation before parsing and I would do the same? Hoping this is clearer, probably a little close to the problem to express it clearly so I apologise for that. Sayth From flebber.crue at gmail.com Thu Apr 28 21:59:21 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 28 Apr 2016 18:59:21 -0700 (PDT) Subject: Pivot table of Pandas In-Reply-To: References: <1369944594.6701652.1461886649215.JavaMail.yahoo.ref@mail.yahoo.com> <1369944594.6701652.1461886649215.JavaMail.yahoo@mail.yahoo.com> <165702145.6760238.1461886721299.JavaMail.yahoo@mail.yahoo.com> Message-ID: On Friday, 29 April 2016 09:56:13 UTC+10, David Shi wrote: > Hello, Matt, > Please see the web link.Pandas Pivot Table?Explained > > | ? | > | ? | ? | ? | ? | ? | > | Pandas Pivot Table?ExplainedExplanation of pandas pivot_table function. | > | | > | View on?pbpython.com | Preview by Yahoo | > | | > | ? | > > > Debra and Fred have their own groups. > How to split the pivot table into separate tables? > What types of objects are these pivot tables? > How to access the "manager" column? > the pivot table is interesting to users, but it is very different from databases which we normally know. > Looking forward to hearing from you. > Regards. > David Unsure of your exact requirements but this doc on reshaping seems to cover the requirements posted. You would not get 2 tables that would be counter-intuitive to a pivottable. You would just define a group in rows and the columns as the data or vice versa. So Debra data of some sort team_member1 44 team_member2 56 Fred team_memeber1 62 team_memeber2 33 http://pandas.pydata.org/pandas-docs/stable/reshaping.html Sayth From no.email at nospam.invalid Thu Apr 28 22:15:20 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 28 Apr 2016 19:15:20 -0700 Subject: What should Python apps do when asked to show help? References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: <877ffhgnyf.fsf@nightsong.com> Steven D'Aprano writes: > (1) print the help text to stdout; > (2) run the help text through a pager; Stdout unless the PAGER env var is set. Otherwise, I'd say still stdout since the person can pipe it through a pager if they want, but you could use the pager or be fancy and try to detect if stdout is a pty/tty before using the pager. Git pages by default and it bugs me because I tend to use git commands in emacs shell windows and the pager makes a mess. From rustompmody at gmail.com Fri Apr 29 01:00:23 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 28 Apr 2016 22:00:23 -0700 (PDT) Subject: What should Python apps do when asked to show help? In-Reply-To: <877ffhgnyf.fsf@nightsong.com> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> Message-ID: <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> On Friday, April 29, 2016 at 7:45:35 AM UTC+5:30, Paul Rubin wrote: > Steven D'Aprano writes: > > (1) print the help text to stdout; > > (2) run the help text through a pager; > > Stdout unless the PAGER env var is set. Otherwise, I'd say still stdout > since the person can pipe it through a pager if they want, but you could > use the pager or be fancy and try to detect if stdout is a pty/tty > before using the pager. Git pages by default and it bugs me because I > tend to use git commands in emacs shell windows and the pager makes a > mess. Quite bewildered by this thread... Are we in 2016? [Reminds me of the bizarre claim that world has not moved on from text] eg I am on on Ubuntu 16.4 (vanilla) right now. This means that when I pull up a terminal I get gnome-terminal. Which means that when the screen fills up I get a scroll bar Now I can get perverse and use xterm/rxvt. Or a console outside of X (ctrl-Alt-F[1-6] ) And even there Shift-pgup works Of course there is the 1 in 100 times this does not hold; - ssh to a remote machine - Upgraded ubuntu and broke X - etc [What happens in windows on a cmd-box... not sure] IOW pager functionality is quite builtin in shells nowadays Why replicate and cause annoyance? From jussi.piitulainen at helsinki.fi Fri Apr 29 02:02:00 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 29 Apr 2016 09:02:00 +0300 Subject: What should Python apps do when asked to show help? References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> Message-ID: Rustom Mody writes: > On Friday, April 29, 2016 at 7:45:35 AM UTC+5:30, Paul Rubin wrote: >> Steven D'Aprano writes: >> > (1) print the help text to stdout; >> > (2) run the help text through a pager; >> >> Stdout unless the PAGER env var is set. Otherwise, I'd say still stdout >> since the person can pipe it through a pager if they want, but you could >> use the pager or be fancy and try to detect if stdout is a pty/tty >> before using the pager. Git pages by default and it bugs me because I >> tend to use git commands in emacs shell windows and the pager makes a >> mess. > > Quite bewildered by this thread... Yet you seem to agree with everybody else in this thread? Including the two persons you quote above, if I read them right :) > Are we in 2016? $ date '+Yes: %F %T' Yes: 2016-04-29 08:11:07 > [Reminds me of the bizarre claim that world has not moved on from text] > eg I am on on Ubuntu 16.4 (vanilla) right now. > This means that when I pull up a terminal I get gnome-terminal. > Which means that when the screen fills up I get a scroll bar > Now I can get perverse and use xterm/rxvt. > Or a console outside of X (ctrl-Alt-F[1-6] ) > And even there Shift-pgup works > > Of course there is the 1 in 100 times this does not hold; > - ssh to a remote machine > - Upgraded ubuntu and broke X > - etc Remote shell works fine. I spend most of my time in a shell on a remote machine over ssh, without X forwarding. I have turned scrollbars off. If I need to scroll back the remote shell session a screen or more, I just slide my index finger along the touchpad edge, or index and middle finger over the touchpad on the other laptop. In Emacs in that remote shell, including a shell session in the Emacs, I use the normal keys to scroll back and forth. There the touchpad doesn't scroll at all, and I don't expect it to, either. > [What happens in windows on a cmd-box... not sure] If that happens to be crippled, there must be other terminal programs that work. > IOW pager functionality is quite builtin in shells nowadays > Why replicate and cause annoyance? First, more and less do more than just scroll and they may be nicer even for just scrolling. Second, if things are set up the way that just about everybody in this thread has been advocating, you have full control over your use of a pager. If it hurts, don't do it. Does it annoy you that somebody else is doing it? It's the *default* paging that is mildly annoying when it works and a major pain when it doesn't. (Another major pain is a command-line tool that tries to open a window and can't because I haven't enabled it. Please don't make this the default either. :) From greg.ewing at canterbury.ac.nz Fri Apr 29 02:04:34 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 29 Apr 2016 18:04:34 +1200 Subject: What should Python apps do when asked to show help? In-Reply-To: <87pot9skqu.fsf@elektro.pacujo.net> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <57224382$0$5808$e4fe514c@news.xs4all.nl> <87pot9skqu.fsf@elektro.pacujo.net> Message-ID: > Irmen de Jong : > >>if sys.stdout.isatty(): >> #....use a pager to display help text >>else: >> #....print all help text normally I think nowadays it's an anti-pattern for programs to do their own pagination. Very often the "terminal" is a GUI application with its own facilities for scrolling and searching that are much nicer to use. I prefer the program to just give me the output and get out of the way. If I want a clunky tty-oriented pager I'll pipe it to "more". -- Greg From greg.ewing at canterbury.ac.nz Fri Apr 29 02:12:14 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 29 Apr 2016 18:12:14 +1200 Subject: Pythonic style In-Reply-To: References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <572188F8.7010304@stoneleaf.us> <540fc958-52d6-6049-75f2-5ee42657688e@mrabarnett.plus.com> Message-ID: Chris Angelico wrote: > I thought the twentieth zen would never be found? Yes. This will have to be numbered the 21st zen to maintain that invariant. -- Greg From rosuav at gmail.com Fri Apr 29 02:45:48 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Apr 2016 16:45:48 +1000 Subject: Pythonic style In-Reply-To: References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <572188F8.7010304@stoneleaf.us> <540fc958-52d6-6049-75f2-5ee42657688e@mrabarnett.plus.com> Message-ID: On Fri, Apr 29, 2016 at 4:12 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> I thought the twentieth zen would never be found? > > > Yes. This will have to be numbered the 21st zen > to maintain that invariant. > Python for the 21st Century. In a hundred years, another zen! ChrisA From steve at pearwood.info Fri Apr 29 05:36:50 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 29 Apr 2016 19:36:50 +1000 Subject: What should Python apps do when asked to show help? References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> Message-ID: <57232b34$0$1595$c3e8da3$5496439d@news.astraweb.com> On Fri, 29 Apr 2016 03:00 pm, Rustom Mody wafted information-rich pheromones into the air, where they diffused rapidly: > Quite bewildered by this thread... > Are we in 2016? > [Reminds me of the bizarre claim that world has not moved on from text] (For the benefit of those of us still stuck in the 2000s, I have transcribed Rustom's pheromones into the obsolete medium of text.) > eg I am on on Ubuntu 16.4 (vanilla) right now. > This means that when I pull up a terminal I get gnome-terminal. > Which means that when the screen fills up I get a scroll bar Yes. So do I. Of course, some applications (like screen) interfere with that, but even when you have a scroll bar, having to scroll back more than a few pages is a PITA. If you set the number of scrollback lines too low, you run out and the things you are interested in disappears past the top... and if you set it too high, it's too hard to locate the section that you actually want. The bottom line is, screen real estate is a valuable resource, but even more valuable is human attention, and pagers are a way of managing attention. Screen space is not necessary rare, but neither is it something that we can just consume thoughtlessly. Hence we have a whole range of options available to us, to make the most of screen space: - multiple windows; - multiple tabs within each window; - scroll bars within each tab; - and pagers. Think of a pager as being somewhat like a popup window for text: at the very low cost of a single line of space in your terminal, you can "pop up" the text, read it, and dismiss it again without using up any of the screen space in your scrolling text view. (Apart from that one line.) > IOW pager functionality is quite builtin in shells nowadays Apart from those where they're not. > Why replicate and cause annoyance? If you don't want to use the functionality, don't. -- Steven From santanu01 at gmail.com Fri Apr 29 05:47:49 2016 From: santanu01 at gmail.com (San) Date: Fri, 29 Apr 2016 02:47:49 -0700 (PDT) Subject: def __init__(self,cls): Message-ID: <70f3b5f6-33b7-4dc8-9c30-92fcc1b1f223@googlegroups.com> Dear Group, Please explain the following in details. " def __init__(self,cls): self.cls = cls " Thanks in Advance. San From a24061 at ducksburg.com Fri Apr 29 05:49:42 2016 From: a24061 at ducksburg.com (Adam Funk) Date: Fri, 29 Apr 2016 10:49:42 +0100 Subject: Why does pathlib not have is_readable() & things like that? References: <6474vcx0q6.ln2@news.ducksburg.com> <1461679044.2467938.590028273.4DEA02AA@webmail.messagingengine.com> Message-ID: On 2016-04-28, Grant Edwards wrote: > On 2016-04-28, Adam Funk wrote: >> On 2016-04-26, Random832 wrote: >> >>> On Tue, Apr 26, 2016, at 09:30, Adam Funk wrote: >>>> I recently discovered pathlib in the Python 3 standard library, & find >>>> it very useful, but I'm a bit surprised that it doesn't offer things >>>> like is_readable() and is_writable. Is there a good reason for that? >>> >>> Well, one reason would be EAFP. Just try to open the file and see if it >>> gives you a PermissionError. >> >> I understand that in general, but the tool I'm working on here takes a >> command-line option to specify an output directory, & I'd rather not >> start processing the data (which involves GETting from a REST service, >> processing, and PUTting back modifications to the data) only to crash >> after the first batch because of a user error. > > Then open the output file before you do the GET. I guess I could, but fetching the data actually involves a whole lot of GET requests (the first one includes cross-references to the URLs where the rest of the data is found), some BeautifulSoup processing, & a lot of other processing to produce a big dict, which I then write out as json using what I think is the best way (output_file is an instance of pathlib.Path): with output_file.open(mode='w', encoding='UTF-8', errors='replace') as f: json.dump(output, f, sort_keys=True, indent=2) > Or just do os.access("directory/where/you/want/to/open/a/file",os.W_OK) That's what I'm doing now, but I prefer to give the user the error message early on. From rustompmody at gmail.com Fri Apr 29 05:53:19 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 29 Apr 2016 02:53:19 -0700 (PDT) Subject: What should Python apps do when asked to show help? In-Reply-To: <57232b34$0$1595$c3e8da3$5496439d@news.astraweb.com> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> <57232b34$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: <72444f12-784b-47b4-a80c-0ae53cf3b5a3@googlegroups.com> On Friday, April 29, 2016 at 3:07:09 PM UTC+5:30, Steven D'Aprano wrote: > On Fri, 29 Apr 2016 03:00 pm, Rustom Mody wafted information-rich pheromones > into the air, where they diffused rapidly: > > Why replicate and cause annoyance? > > If you don't want to use the functionality, don't. You asked about calling up pagers!! JFTR I find git behavior annoying -- as it seems do others -- but Ive figured getting round it by calling it with -w (show in web browser) is ok (with me) With python's help I find it annoying and Ive not figured out how to not get paging From steve at pearwood.info Fri Apr 29 05:59:11 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 29 Apr 2016 19:59:11 +1000 Subject: Pythonic style References: <5720357B.4060009@icloud.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <572188F8.7010304@stoneleaf.us> <540fc958-52d6-6049-75f2-5ee42657688e@mrabarnett.plus.com> Message-ID: <57233071$0$1589$c3e8da3$5496439d@news.astraweb.com> On Fri, 29 Apr 2016 10:48 am, Gregory Ewing wrote: > MRAB wrote: > >> Is it worthy of being in the Zen of Python? > > +1. Maybe something along the lines of: > > Dunder methods are for defining, not calling. > Unless you're a dunderhead[1]. > > [1] Meant in the sense of an enthusiast, cf. gearhead. I think that the advice to not call dundermethods directly is excellent advice, but it doesn't belong in the Zen. Look at the Zen: it's all pretty abstract: Beautiful is better than ugly. Explicit is better than implicit. etc. There's very little[1] concrete advice in the way of specificities such as: - don't use floats for money; - use namedtuple for the equivalent of a C struct or Pascal record; - composition should be preferred over inheritance; etc. "Don't use dunders" is much closer to the second, more specific type of advice which doesn't really fall into the Zen's bailiwick. Better suited for the Zen would be: "Not everything needs to be a one-liner." which is nicely abstract and also completely useless for deciding which things should and shouldn't be, as good koans ought to be. [1] By which I mean none. -- Steven From __peter__ at web.de Fri Apr 29 07:26:16 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 29 Apr 2016 13:26:16 +0200 Subject: Controlling the passing of data References: Message-ID: Sayth Renshaw wrote: > >> >> Your actual problem is drowned in too much source code. Can you restate >> it in English, optionally with a few small snippets of Python? >> >> It is not even clear what the code you provide should accomplish once >> it's running as desired. >> >> To give at least one code-related advice: You have a few repetitions of >> the following structure >> >> > meetattrs = ('id', 'venue', 'date', 'rail', 'weather', >> > 'trackcondition') >> >> > meet = d('meeting') >> >> > meetdata = [[meet.eq(i).attr(x) >> > for x in meetattrs] for i in range(len(meet))] >> >> You should move the pieces into a function that works for meetings, >> clubs, races, and so on. Finally (If I am repeating myself so be it): the >> occurence of range(len(something)) in your code is a strong indication >> that you are not using Python the way Guido intended it. Iterate over the >> `something` directly whenever possible. > > Hi Peter > >> meetattrs = ('id', 'venue', 'date', 'rail', 'weather', 'trackcondition') > > is created to define a list of attr in the XML rather than referencing > each attr individually I create a list and pass it into > > > meetdata = [[meet.eq(i).attr(x) >> > for x in meetattrs] for i in range(len(meet))] > > This list comprehension reads the XML attr by attr using meet = > d('meeting') as the call to pyquery to locate the class in the XML and > identify the attr's. You misunderstood me. I do understand what your code does, I just have no idea what you want to do, in terms of the domain, like e. g. "Print horses with the last three races they took part in." Why does this matter? Here's an extreme example: bars = [] for foo in whatever: bars.append(foo.baz) What does this do? The description "It puts all baz attributes of the items in whatever into a list" doesn't help. If you say "I want to make a list of all brands in the car park I could recommend a change to brand = set(car.brand for car in car_park) because a set avoids duplicates. If you say "I want to document my achievements for posterity" I would recommend that you print to a file rather than append to a list and the original code could be changed to with open("somefile") as f: for achievement in my_achievements: print(achievement.description, file=f) Back to my coding hint: Don't repeat yourself. If you move the pieces >> > meetattrs = ('id', 'venue', 'date', 'rail', 'weather', >> > 'trackcondition') >> >> > meet = d('meeting') >> >> > meetdata = [[meet.eq(i).attr(x) >> > for x in meetattrs] for i in range(len(meet))] into a function def extract_attrs(nodes, attrs): return [[nodes.eq(i).attr(name) for name in attrs] for i in range(len(nodes))] You can reuse it for clubs, races, etc.: meetdata = extract_attrs(d("meeting"), meetattrs) racedata = extract_attrs(d("race"), raceattrs) If you put the parts into a dict you can generalize even further: tables = { "meeting": ([], meetattrs), "race": ([], raceattrs), } for name, (data, attrs) in tables.items(): data.extend(extract_attrs(d(name), attrs)) > > I do apologise for the lack of output, I asked a question about parsing > that I always seem to get wrong over think and then find the solution > simpler than I thought. > > The output is 4 tables of the class and selected attributes eg meetattrs = > ('id', 'venue', 'date', 'rail', 'weather', 'trackcondition') from the > meeting class of the XML. > > In order to give flexibility and keep the relational nature they have > defined in the table I found when exporting the nominations section via > pandas to csv that i had no way to determine which id belonged to each > race that is there was no race_id in the nominations to relate back to the > race, and also no meeting id in the raceid to relate it back to the > meeting. > So I wanted to traverse all the classes Meeting, Race and Nomination and > insert the id of the class into its direct children only and since there > were many races a meeting and many nomnations a race I need to ensure that > it is the direct children only. > > It was otherwise working as parsed output in code supplied using to push > to pandas and use its csv write capability. > > So I inserted > > for race_el in d('race'): > race = pq(race_el) > race_id = race.attr('id') > > for nom_el in race.items('nomination'): > res.append((pq(nom_el).attr('raceid', race_id))) > > which traverses and inserts the race_id into the child nominations. > However, my boggles is how to pass this to the list comprehension that was > working without changing the data from XML or creating another > intermediate step and variable. Just to parse it as it was but with the > extra included race_id. So you want to go from a tree structure to a set of tables that preserves the structure by adding foreign keys. You could try a slightly different approach, something like for meeting in meetings: meeting_table.append(...meeting attrs...) meeting_id = ... for race in meeting: race_table.append(meeting_id, ...meeting attrs...) race_id = ... for nomination in race: nomination_table.append(race_id, ...nomination attrs...) I don't know how to spell this in PyQuery -- with lxml you could do something like meeting_table = [] race_table = [] nomination_table = [] tree = lxml.etree.parse(filename) for meeting in tree.xpath("/meeting"): meeting_table.append([meeting.attrib[name] for name in meetattrs]) meeting_id = meeting.attrib["id"] for race in meeting.xpath("./race"): race_table.append( [meeting_id] + [race.attrib[name] for name in raceattrs]) race_id = race.attrib["id"] for nomination in race.xpath("./nomination"): nomination_table.append( [race_id] + [nomination.attrib[name] for name in horseattrs]) Not as clean and not as general as I would hope -- basically I'm neglecting my recommendation from above -- but if it works for you I might take a second look later. From __peter__ at web.de Fri Apr 29 07:36:00 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 29 Apr 2016 13:36 +0200 Subject: Controlling the passing of data References: Message-ID: Sayth Renshaw wrote: > >> >> Your actual problem is drowned in too much source code. Can you restate >> it in English, optionally with a few small snippets of Python? >> >> It is not even clear what the code you provide should accomplish once >> it's running as desired. >> >> To give at least one code-related advice: You have a few repetitions of >> the following structure >> >> > meetattrs = ('id', 'venue', 'date', 'rail', 'weather', >> > 'trackcondition') >> >> > meet = d('meeting') >> >> > meetdata = [[meet.eq(i).attr(x) >> > for x in meetattrs] for i in range(len(meet))] >> >> You should move the pieces into a function that works for meetings, >> clubs, races, and so on. Finally (If I am repeating myself so be it): the >> occurence of range(len(something)) in your code is a strong indication >> that you are not using Python the way Guido intended it. Iterate over the >> `something` directly whenever possible. > > Hi Peter > >> meetattrs = ('id', 'venue', 'date', 'rail', 'weather', 'trackcondition') > > is created to define a list of attr in the XML rather than referencing > each attr individually I create a list and pass it into > > > meetdata = [[meet.eq(i).attr(x) >> > for x in meetattrs] for i in range(len(meet))] > > This list comprehension reads the XML attr by attr using meet = > d('meeting') as the call to pyquery to locate the class in the XML and > identify the attr's. You misunderstood me. I do understand what your code does, I just have no idea what you want to do, in terms of the domain, like e. g. "Print horses with the last three races they took part in." Why does this matter? Here's an extreme example: bars = [] for foo in whatever: bars.append(foo.baz) What does this do? The description "It puts all baz attributes of the items in whatever into a list" doesn't help. If you say "I want to make a list of all brands in the car park I could recommend a change to brand = set(car.brand for car in car_park) because a set avoids duplicates. If you say "I want to document my achievements for posterity" I would recommend that you print to a file rather than append to a list and the original code could be changed to with open("somefile") as f: for achievement in my_achievements: print(achievement.description, file=f) Back to my coding hint: Don't repeat yourself. If you move the pieces >> > meetattrs = ('id', 'venue', 'date', 'rail', 'weather', >> > 'trackcondition') >> >> > meet = d('meeting') >> >> > meetdata = [[meet.eq(i).attr(x) >> > for x in meetattrs] for i in range(len(meet))] into a function def extract_attrs(nodes, attrs): return [[nodes.eq(i).attr(name) for name in attrs] for i in range(len(nodes))] You can reuse it for clubs, races, etc.: meetdata = extract_attrs(d("meeting"), meetattrs) racedata = extract_attrs(d("race"), raceattrs) If you put the parts into a dict you can generalize even further: tables = { "meeting": ([], meetattrs), "race": ([], raceattrs), } for name, (data, attrs) in tables.items(): data.extend(extract_attrs(d(name), attrs)) > > I do apologise for the lack of output, I asked a question about parsing > that I always seem to get wrong over think and then find the solution > simpler than I thought. > > The output is 4 tables of the class and selected attributes eg meetattrs = > ('id', 'venue', 'date', 'rail', 'weather', 'trackcondition') from the > meeting class of the XML. > > In order to give flexibility and keep the relational nature they have > defined in the table I found when exporting the nominations section via > pandas to csv that i had no way to determine which id belonged to each > race that is there was no race_id in the nominations to relate back to the > race, and also no meeting id in the raceid to relate it back to the > meeting. > > > So I wanted to traverse all the classes Meeting, Race and Nomination and > insert the id of the class into its direct children only and since there > were many races a meeting and many nomnations a race I need to ensure that > it is the direct children only. > > It was otherwise working as parsed output in code supplied using to push > to pandas and use its csv write capability. > > So I inserted > > for race_el in d('race'): > race = pq(race_el) > race_id = race.attr('id') > > for nom_el in race.items('nomination'): > res.append((pq(nom_el).attr('raceid', race_id))) > > which traverses and inserts the race_id into the child nominations. > However, my boggles is how to pass this to the list comprehension that was > working without changing the data from XML or creating another > intermediate step and variable. Just to parse it as it was but with the > extra included race_id. So you want to go from a tree structure to a set of tables and preserve the structural information: for meeting in meetings meeting_table.append(...meeting attributes...) meeting_id = ... for race in meeting.races: race_table.append(meeting_id, ...race attributes...) race_id = ... for nomination in race.nominations: nomination_table.append(race_id, ...nomination attributes...) I don't know how to spell that in PyQuery, so here's how to do it with lxml: meeting_table = [] race_table = [] nomination_table = [] tree = lxml.etree.parse(filename) for meeting in tree.xpath("/meeting"): meeting_table.append([meeting.attrib[name] for name in meetattrs]) meeting_id = meeting.attrib["id"] for race in meeting.xpath("./race"): race_table.append( [meeting_id] + [race.attrib[name] for name in raceattrs]) race_id = race.attrib["id"] for nomination in race.xpath("./nomination"): nomination_table.append( [race_id] + [nomination.attrib[name] for name in horseattrs]) Not as clean and not as general as I would hope -- basically I'm neglecting my recommendations from above -- but if it works for you I might have a second look later. From jussi.piitulainen at helsinki.fi Fri Apr 29 07:51:05 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 29 Apr 2016 14:51:05 +0300 Subject: Why does pathlib not have is_readable() & things like that? References: <6474vcx0q6.ln2@news.ducksburg.com> <1461679044.2467938.590028273.4DEA02AA@webmail.messagingengine.com> Message-ID: Adam Funk writes: > On 2016-04-28, Grant Edwards wrote: >> >> Then open the output file before you do the GET. > > I guess I could, but fetching the data actually involves a whole lot > of GET requests (the first one includes cross-references to the URLs > where the rest of the data is found), some BeautifulSoup processing, & > a lot of other processing to produce a big dict, which I then write > out as json using what I think is the best way (output_file is an > instance of pathlib.Path): > > with output_file.open(mode='w', encoding='UTF-8', errors='replace') as f: > json.dump(output, f, sort_keys=True, indent=2) It doesn't matter how much work it actually is. Make it conceptually a single unit: def get_output(): ... with output_file.open(mode='w', encoding='UTF-8', errors='replace') as f: output = get_output() json.dump(output, f, sort_keys=True, indent=2) >> Or just do os.access("directory/where/you/want/to/open/a/file",os.W_OK) > > That's what I'm doing now, but I prefer to give the user the error > message early on. Then do that early on. From motoom at xs4all.nl Fri Apr 29 08:29:16 2016 From: motoom at xs4all.nl (Michiel Overtoom) Date: Fri, 29 Apr 2016 14:29:16 +0200 Subject: def __init__(self,cls): In-Reply-To: <70f3b5f6-33b7-4dc8-9c30-92fcc1b1f223@googlegroups.com> References: <70f3b5f6-33b7-4dc8-9c30-92fcc1b1f223@googlegroups.com> Message-ID: <2BA284BC-814B-47FD-AB2C-ACA45304FD89@xs4all.nl> > On 2016-04-29, at 11:47, San wrote: > > Dear Group, please explain the following in details. Thanks in Advance. > > def __init__(self,cls): > self.cls = cls Is this homework? Why don't you explain it first in your own words, then let us comment on it? Greetings, From flebber.crue at gmail.com Fri Apr 29 09:17:44 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Fri, 29 Apr 2016 06:17:44 -0700 (PDT) Subject: Controlling the passing of data In-Reply-To: References: Message-ID: <03178a33-04cb-491e-8cfb-9e6545fa092d@googlegroups.com> > because a set avoids duplicates. If you say "I want to document my > achievements for posterity" I would recommend that you print to a file > rather than append to a list and the original code could be changed to > > with open("somefile") as f: > for achievement in my_achievements: > print(achievement.description, file=f) > > > Back to my coding hint: Don't repeat yourself. If you move the pieces > > >> > meetattrs = ('id', 'venue', 'date', 'rail', 'weather', > >> > 'trackcondition') > >> > >> > meet = d('meeting') > >> > >> > meetdata = [[meet.eq(i).attr(x) > >> > for x in meetattrs] for i in range(len(meet))] > > into a function > > def extract_attrs(nodes, attrs): > return [[nodes.eq(i).attr(name) for name in attrs] > for i in range(len(nodes))] > > You can reuse it for clubs, races, etc.: > > meetdata = extract_attrs(d("meeting"), meetattrs) > racedata = extract_attrs(d("race"), raceattrs) > > If you put the parts into a dict you can generalize even further: > > tables = { > "meeting": ([], meetattrs), > "race": ([], raceattrs), > } > for name, (data, attrs) in tables.items(): > data.extend(extract_attrs(d(name), attrs)) > I find that really cool. Reads well to, hadn't considered approaching it that way at all. > So you want to go from a tree structure to a set of tables that preserves > the structure by adding foreign keys. You could try a slightly different > approach, something like > > for meeting in meetings: > meeting_table.append(...meeting attrs...) > meeting_id = ... > for race in meeting: > race_table.append(meeting_id, ...meeting attrs...) > race_id = ... > for nomination in race: > nomination_table.append(race_id, ...nomination attrs...) > > I don't know how to spell this in PyQuery -- with lxml you could do > something like > > meeting_table = [] > race_table = [] > nomination_table = [] > tree = lxml.etree.parse(filename) > for meeting in tree.xpath("/meeting"): > meeting_table.append([meeting.attrib[name] for name in meetattrs]) > meeting_id = meeting.attrib["id"] > for race in meeting.xpath("./race"): > race_table.append( > [meeting_id] + [race.attrib[name] for name in raceattrs]) > race_id = race.attrib["id"] > for nomination in race.xpath("./nomination"): > nomination_table.append( > [race_id] > + [nomination.attrib[name] for name in horseattrs]) > > Not as clean and not as general as I would hope -- basically I'm neglecting > my recommendation from above -- but if it works for you I might take a > second look later. I need to play around with this just to understand it more, really like it. Might try and implement your advice from before and put it in a function. Sayth From martin at linux-ip.net Fri Apr 29 09:32:54 2016 From: martin at linux-ip.net (Martin A. Brown) Date: Fri, 29 Apr 2016 06:32:54 -0700 Subject: manpage writing [rst, asciidoc, pod] was [Re: What should Python apps do when asked to show help?] In-Reply-To: <5722bb82$0$1600$c3e8da3$5496439d@news.astraweb.com> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461865210.3218352.592571425.2069E4EB@webmail.messagingengine.com> <87a8kdshyh.fsf@elektro.pacujo.net> <1461873085.3251720.592695601.44633E5E@webmail.messagingengine.com> <5722bb82$0$1600$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hello, >What is a good place where I can find out more about writing >manpage? I don't know of a single place where manpage authorship is particularly documented. This seems to be one of the common target links. In addition to introducing the breakdown of manpages by type (section) and providing some suggestions for content, it introduces the *roff markup: http://www.schweikhardt.net/man_page_howto.html It's been many years since I have written that stuff directly. I prefer one of the lightweight, general documentation or markup languages. So, below, I'll mention and give examples for creating manpages from reStructuredtext, AsciiDoc and Plain Old Documentation. With the reStructuredText format [0] [1], you can convert an .rst file to a manpage using two different document processors; you can use sphinx-build from the sphinx-project [2] or rst2man from the docutils project. The outputs are largely the same (as far as I can tell). There's also the AsciiDoc [3] format, which is a near to text and reads like text, but has a clear structure. With the tooling (written in Python), you can produce docbook, latex, html and a bunch of other output formats. Oh, and manpages [4], too. There is a tool called 'asciidoc' which processes AsciiDoc formats into a variety of backend formats. The 'a2x' tool converts AsciiDoc sources into some other (x) desired output. If you don't like .rst or AsciiDoc, there's also the Plain Old Documentation (POD) format. This is the oldest tool (of which I'm aware) which other than the direct *roff processing tools. You run 'pod2man' (written in Perl) on your .pod file. POD is another dead simple documentation language, supported by the pod2man [5] tool. For more on the format, read also 'man 1 perlpod'. sphinx-build: the sphinx documentation system is geared for handling project-scoped documentation and provides many additional features to reStructuredText. It can produce all kinds of output formats, HTML single-page, help, multipage, texinfo, latex, text, epub and ....oh, yeah, manpages. It's a rich set of tools. If you wish to use sphinx, I can give you an example .rst file [6] which I recently wrote and the following instructions for how to process this with sphinx. When processing docs with sphinx, a 'conf.py' file is required. It can be generated with an ancillary tool from the sphinx suite: I know that I always find an example helpful. So, here are some examples to help you launch. mkdir sampledir && cd sampledir sphinx-quickstart # -- and answer a bunch of questions # -- examine conf.py and adjust to your heart's content # confirm that master_doc is your single document for a manpage # confirm that there's an entry for your document in man_pages sphinx-build -b man -d _build/doctrees . _build/man # -- or grab the files from my recent project [6] and try yourself rst2man: even more simply, if you don't need the kitchen sink... wget https://gitlab.com/pdftools/pdfposter/raw/develop/pdfposter.rst rst2man < pdfposter.rst > pdfposter.1 # -- will complain about this, but still produces a manpage # :10: (ERROR/3) Undefined substitution referenced: "VERSION". man ./pdfposter.1 asciidoc (a randomly selected example asciidoc file [7]): wget https://raw.githubusercontent.com/DavidGamba/grepp/master/grepp.adoc a2x -f manpage grepp.adoc man ./grepp.1 perlpod: wget https://api.metacpan.org/source/RJBS/perl-5.18.1/pod/perlrun.pod pod2man --section 1 < perlrun.pod > perlrun.1 man ./perlrun.1 I know there are other tools for generating manpages; the original *roff tools, visual manpage editors, DocBook, help2man, manpage generators from argparse.ArgumentParser instances, And, of course, make sure to use version control for your documentation. These git manpages may be helpful for the uninitiated (joke, joke): https://git-man-page-generator.lokaltog.net/ # -- humour! Good luck, -Martin [0] http://docutils.sourceforge.net/docs/user/rst/quickref.html [1] http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html [2] http://www.sphinx-doc.org/en/stable/rest.html [3] http://www.methods.co.nz/asciidoc/ [4] http://www.methods.co.nz/asciidoc/chunked/ch24.html [5] http://perldoc.perl.org/pod2man.html [6] https://raw.githubusercontent.com/tLDP/python-tldp/master/docs/ldptool-man.rst [7] https://raw.githubusercontent.com/DavidGamba/grepp/master/grepp.adoc -- Martin A. Brown http://linux-ip.net/ From ethan at stoneleaf.us Fri Apr 29 10:06:51 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 29 Apr 2016 07:06:51 -0700 Subject: manpage writing [rst, asciidoc, pod] was [Re: What should Python apps do when asked to show help?] In-Reply-To: References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461865210.3218352.592571425.2069E4EB@webmail.messagingengine.com> <87a8kdshyh.fsf@elektro.pacujo.net> <1461873085.3251720.592695601.44633E5E@webmail.messagingengine.com> <5722bb82$0$1600$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57236A7B.5000203@stoneleaf.us> Wow. Thank you for that very informative post! -- ~Ethan~ From eryksun at gmail.com Fri Apr 29 11:09:41 2016 From: eryksun at gmail.com (eryk sun) Date: Fri, 29 Apr 2016 10:09:41 -0500 Subject: Why does pathlib not have is_readable() & things like that? In-Reply-To: References: <6474vcx0q6.ln2@news.ducksburg.com> <1461679044.2467938.590028273.4DEA02AA@webmail.messagingengine.com> Message-ID: On Fri, Apr 29, 2016 at 6:51 AM, Jussi Piitulainen wrote: > Adam Funk writes: >> On 2016-04-28, Grant Edwards wrote: > >>> Or just do os.access("directory/where/you/want/to/open/a/file",os.W_OK) >> >> That's what I'm doing now, but I prefer to give the user the error >> message early on. > > Then do that early on. Note that on Windows os.access only checks if a file is read-only. There's a proposed update to check the file security. The patch needs to be updated and needs to be reworked, but it's a low priority. For the most part calling os.access isn't recommended. From rustompmody at gmail.com Fri Apr 29 11:17:45 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 29 Apr 2016 08:17:45 -0700 (PDT) Subject: manpage writing [rst, asciidoc, pod] was [Re: What should Python apps do when asked to show help?] In-Reply-To: References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461865210.3218352.592571425.2069E4EB@webmail.messagingengine.com> <87a8kdshyh.fsf@elektro.pacujo.net> <1461873085.3251720.592695601.44633E5E@webmail.messagingengine.com> <5722bb82$0$1600$c3e8da3$5496439d@news.astraweb.com> <57236A7B.5000203@stoneleaf.us> Message-ID: On Friday, April 29, 2016 at 7:35:55 PM UTC+5:30, Ethan Furman wrote: > Wow. Thank you for that very informative post! > > -- > ~Ethan~ For emacs junkies there is also org-e-man [1] http://orgmode.org/worg/org-tutorials/org-e-man-documentation.html [2] https://github.com/tkf/org-mode/blob/master/contrib/lisp/org-e-man.el [No I havent used this but I use org mode heavily] From michael.selik at gmail.com Fri Apr 29 14:23:21 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 29 Apr 2016 18:23:21 +0000 Subject: Query regarding python 2.7.11 release In-Reply-To: References: Message-ID: >From searching bugs.python.org, I see that issues referencing CVE-2014-7185, CVE-2013-1752, and CVE-2014-1912 have all been marked as closed. I don't see any issues referencing CVE-2014-4650 via Python's bug tracker, but did spot it on Red Hat's. It appears to be related to issue 21766 ( http://bugs.python.org/issue21766) which has been marked closed, fixed. So, yes, looks like they're all fixed. On Thu, Apr 14, 2016 at 3:26 AM Gaurav Rastogi -X (garastog - ARICENT TECHNOLOGIES MAURIITIUS LIMITED at Cisco) wrote: > Hi, > > We are currently using Python 2.6.7 in our product. > We have received below vulnerabilities from field: > > CVE-2014-7185 > > Integer overflow in bufferobject.c in Python before 2.7.8 allows > context-dependent attackers to > obtain sensitive information from process memory via a large size and > offset in a "buffer" function. > > CVE-2013-1752 > > python: multiple unbound readline() DoS flaws in python stdlib > > CVE-2014-1912 > > python: buffer overflow in socket.recvfrom_into() > > CVE-2014-4650 > > It was discovered that the CGIHTTPServer module incorrectly handled URL > encoded paths. > A remote attacker could use this flaw to execute scripts outside of the > cgi-bin directory, or disclose source of scripts in the cgi-bin directory > > > Currently I can see the 2.7.11 is the latest release as per the below link: > https://www.python.org/downloads/ > > Could you please suggest if the above mentioned vulnerabilities are > resolved in the latest release? > > Regards > Gaurav > -- > https://mail.python.org/mailman/listinfo/python-list > From zljubisic at gmail.com Fri Apr 29 15:21:36 2016 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Fri, 29 Apr 2016 12:21:36 -0700 (PDT) Subject: How to download a flash video from this site? Message-ID: <0c9d5a3b-ee58-49a6-973a-6125473fea06@googlegroups.com> Hi, I am looking for a way to download a flash video from the page: https://hrti.hrt.hr/#/video/show/2203605/trebizat-prica-o-jednoj-vodi-i-jednom-narodu-dokumentarni-film The html code bellow the page is fairly simple, but I can't figure out how to get the file. In case somebody have an idea, you can login to the site with: Username: gluperegistarcije at yahoo.com Password: public Regards. From andrea.gavana at gmail.com Fri Apr 29 15:45:58 2016 From: andrea.gavana at gmail.com (andrea.gavana at gmail.com) Date: Fri, 29 Apr 2016 12:45:58 -0700 (PDT) Subject: Compiling extensions on Python 2.7, Windows 10 64 bit Message-ID: Dear list, I have been trying to compile wxPython Phoenix (https://github.com/wxWidgets/Phoenix) from source on Windows 10 64 bit, Python 2.7 64 bit, using the very handy Microsoft Visual C++ Compiler for Python 2.7 (https://www.microsoft.com/en-us/download/details.aspx?id=44266). I started with Python 2.7.8, then wiped out that installation and used Python 2.7.11: cleaned the build directory, everything, and rebuilt the Phoenix modules from scratch. Upon starting the Phoenix demo, I got the same error message I had with Python 2.7.8: D:\MyProjects\Phoenix\demo>python Main.py Traceback (most recent call last): File "C:\Python27\lib\site-packages\wxPhoenix\wx\core.py", line 1955, in Notify self.notify() File "C:\Python27\lib\site-packages\wxPhoenix\wx\core.py", line 3034, in Notify self.result = self.callable(*self.args, **self.kwargs) File "Main.py", line 2601, in ShowMain frame = wxPythonDemo(None, "wxPython: (A Demonstration)") File "Main.py", line 1531, in __init__ self.SetOverview(self.overviewText, mainOverview) File "Main.py", line 2130, in SetOverview self.nb.SetPageText(0, os.path.split(name)[1]) SystemError: ..\Objects\longobject.c:998: bad argument to internal function The error message refers (apparently) to this Python bug: https://bugs.python.org/issue23842 But I assumed that it had been fixed waaaaay before 2.7.11. Now I am stuck and I have no idea on what to try next. Does anyone have suggestions/comments on where I should look for/what I should do/what I should change in order to get the extension running on Python 2.7? Thank you in advance for your suggestions :-) . Andrea. From ikorot01 at gmail.com Fri Apr 29 16:24:57 2016 From: ikorot01 at gmail.com (Igor Korot) Date: Fri, 29 Apr 2016 16:24:57 -0400 Subject: Compiling extensions on Python 2.7, Windows 10 64 bit In-Reply-To: References: Message-ID: Andrea, On Fri, Apr 29, 2016 at 3:45 PM, wrote: > Dear list, > > I have been trying to compile wxPython Phoenix (https://github.com/wxWidgets/Phoenix) from source on Windows 10 64 bit, Python 2.7 64 bit, using the very handy Microsoft Visual C++ Compiler for Python 2.7 (https://www.microsoft.com/en-us/download/details.aspx?id=44266). > > I started with Python 2.7.8, then wiped out that installation and used Python 2.7.11: cleaned the build directory, everything, and rebuilt the Phoenix modules from scratch. > > Upon starting the Phoenix demo, I got the same error message I had with Python 2.7.8: > > D:\MyProjects\Phoenix\demo>python Main.py > > Traceback (most recent call last): > File "C:\Python27\lib\site-packages\wxPhoenix\wx\core.py", line 1955, in Notify > self.notify() > File "C:\Python27\lib\site-packages\wxPhoenix\wx\core.py", line 3034, in Notify > self.result = self.callable(*self.args, **self.kwargs) > File "Main.py", line 2601, in ShowMain > frame = wxPythonDemo(None, "wxPython: (A Demonstration)") > File "Main.py", line 1531, in __init__ > self.SetOverview(self.overviewText, mainOverview) > File "Main.py", line 2130, in SetOverview > self.nb.SetPageText(0, os.path.split(name)[1]) > SystemError: ..\Objects\longobject.c:998: bad argument to internal function > > The error message refers (apparently) to this Python bug: > > https://bugs.python.org/issue23842 > > But I assumed that it had been fixed waaaaay before 2.7.11. Now I am stuck and I have no idea on what to try next. > > Does anyone have suggestions/comments on where I should look for/what I should do/what I should change in order to get the extension running on Python 2.7? > > Thank you in advance for your suggestions :-) Did you try with python 3.x? IIUC, Phoenix should be made for python 3.x, and classic is for 2.7 series. Thank you. . > > Andrea. > -- > https://mail.python.org/mailman/listinfo/python-list From robertvstepp at gmail.com Fri Apr 29 16:26:43 2016 From: robertvstepp at gmail.com (boB Stepp) Date: Fri, 29 Apr 2016 15:26:43 -0500 Subject: Python path and append In-Reply-To: <571ec99c$0$1607$c3e8da3$5496439d@news.astraweb.com> References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> <571ec99c$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Apr 25, 2016 at 8:51 PM, Steven D'Aprano wrote: > See here for the *start* of a more professional approach: > > http://code.activestate.com/recipes/579097-safely-and-atomically-write-to-a-file/ What else would I need to know/consider in order to have a *complete* professional approach? -- boB From andrea.gavana at gmail.com Fri Apr 29 16:27:25 2016 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Fri, 29 Apr 2016 22:27:25 +0200 Subject: Compiling extensions on Python 2.7, Windows 10 64 bit In-Reply-To: References: Message-ID: Hi, On Friday, 29 April 2016, Igor Korot wrote: > Andrea, > > On Fri, Apr 29, 2016 at 3:45 PM, > > wrote: > > Dear list, > > > > I have been trying to compile wxPython Phoenix ( > https://github.com/wxWidgets/Phoenix) from source on Windows 10 64 bit, > Python 2.7 64 bit, using the very handy Microsoft Visual C++ Compiler for > Python 2.7 (https://www.microsoft.com/en-us/download/details.aspx?id=44266 > ). > > > > I started with Python 2.7.8, then wiped out that installation and used > Python 2.7.11: cleaned the build directory, everything, and rebuilt the > Phoenix modules from scratch. > > > > Upon starting the Phoenix demo, I got the same error message I had with > Python 2.7.8: > > > > D:\MyProjects\Phoenix\demo>python Main.py > > > > Traceback (most recent call last): > > File "C:\Python27\lib\site-packages\wxPhoenix\wx\core.py", line 1955, > in Notify > > self.notify() > > File "C:\Python27\lib\site-packages\wxPhoenix\wx\core.py", line 3034, > in Notify > > self.result = self.callable(*self.args, **self.kwargs) > > File "Main.py", line 2601, in ShowMain > > frame = wxPythonDemo(None, "wxPython: (A Demonstration)") > > File "Main.py", line 1531, in __init__ > > self.SetOverview(self.overviewText, mainOverview) > > File "Main.py", line 2130, in SetOverview > > self.nb.SetPageText(0, os.path.split(name)[1]) > > SystemError: ..\Objects\longobject.c:998: bad argument to internal > function > > > > The error message refers (apparently) to this Python bug: > > > > https://bugs.python.org/issue23842 > > > > But I assumed that it had been fixed waaaaay before 2.7.11. Now I am > stuck and I have no idea on what to try next. > > > > Does anyone have suggestions/comments on where I should look for/what I > should do/what I should change in order to get the extension running on > Python 2.7? > > > > Thank you in advance for your suggestions :-) > > Did you try with python 3.x? > > IIUC, Phoenix should be made for python 3.x, and classic is for 2.7 series. > > No, Phoenix is meant to work on Python 2 and 3 at the same time. That's the very reason it was created. Andrea. -- From ikorot01 at gmail.com Fri Apr 29 16:28:59 2016 From: ikorot01 at gmail.com (Igor Korot) Date: Fri, 29 Apr 2016 16:28:59 -0400 Subject: Compiling extensions on Python 2.7, Windows 10 64 bit In-Reply-To: References: Message-ID: Andrea, On Fri, Apr 29, 2016 at 4:27 PM, Andrea Gavana wrote: > Hi, > > > On Friday, 29 April 2016, Igor Korot wrote: >> >> Andrea, >> >> On Fri, Apr 29, 2016 at 3:45 PM, wrote: >> > Dear list, >> > >> > I have been trying to compile wxPython Phoenix >> > (https://github.com/wxWidgets/Phoenix) from source on Windows 10 64 bit, >> > Python 2.7 64 bit, using the very handy Microsoft Visual C++ Compiler for >> > Python 2.7 (https://www.microsoft.com/en-us/download/details.aspx?id=44266). >> > >> > I started with Python 2.7.8, then wiped out that installation and used >> > Python 2.7.11: cleaned the build directory, everything, and rebuilt the >> > Phoenix modules from scratch. >> > >> > Upon starting the Phoenix demo, I got the same error message I had with >> > Python 2.7.8: >> > >> > D:\MyProjects\Phoenix\demo>python Main.py >> > >> > Traceback (most recent call last): >> > File "C:\Python27\lib\site-packages\wxPhoenix\wx\core.py", line 1955, >> > in Notify >> > self.notify() >> > File "C:\Python27\lib\site-packages\wxPhoenix\wx\core.py", line 3034, >> > in Notify >> > self.result = self.callable(*self.args, **self.kwargs) >> > File "Main.py", line 2601, in ShowMain >> > frame = wxPythonDemo(None, "wxPython: (A Demonstration)") >> > File "Main.py", line 1531, in __init__ >> > self.SetOverview(self.overviewText, mainOverview) >> > File "Main.py", line 2130, in SetOverview >> > self.nb.SetPageText(0, os.path.split(name)[1]) >> > SystemError: ..\Objects\longobject.c:998: bad argument to internal >> > function >> > >> > The error message refers (apparently) to this Python bug: >> > >> > https://bugs.python.org/issue23842 >> > >> > But I assumed that it had been fixed waaaaay before 2.7.11. Now I am >> > stuck and I have no idea on what to try next. >> > >> > Does anyone have suggestions/comments on where I should look for/what I >> > should do/what I should change in order to get the extension running on >> > Python 2.7? >> > >> > Thank you in advance for your suggestions :-) >> >> Did you try with python 3.x? >> >> IIUC, Phoenix should be made for python 3.x, and classic is for 2.7 >> series. >> > > > No, Phoenix is meant to work on Python 2 and 3 at the same time. That's the > very reason it was created. But is it compiling with python 3.x? Because the bug should be definitely fixed there. Thank you. > > Andrea. > > > > -- > From rosuav at gmail.com Fri Apr 29 16:39:54 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Apr 2016 06:39:54 +1000 Subject: How to download a flash video from this site? In-Reply-To: <0c9d5a3b-ee58-49a6-973a-6125473fea06@googlegroups.com> References: <0c9d5a3b-ee58-49a6-973a-6125473fea06@googlegroups.com> Message-ID: On Sat, Apr 30, 2016 at 5:21 AM, wrote: > I am looking for a way to download a flash video from the page: > > https://hrti.hrt.hr/#/video/show/2203605/trebizat-prica-o-jednoj-vodi-i-jednom-narodu-dokumentarni-film > > The html code bellow the page is fairly simple, but I can't figure out how to get the file. Since you're asking on this list, I'll assume you're using Beautiful Soup and/or youtube-dl. You'll need to go into more detail about what you're trying to do, and where the Python problem is. ChrisA From fetchinson at googlemail.com Fri Apr 29 18:29:38 2016 From: fetchinson at googlemail.com (Fetchinson .) Date: Sat, 30 Apr 2016 00:29:38 +0200 Subject: web facing static text db In-Reply-To: References: Message-ID: Hi folks, I have a very specific set of requirements for a task and was wondering if anyone had good suggestions for the best set of tools: * store text documents (about 100000 pages) * the data set is static (i.e. only lookups are performed, no delete, no edit, no addition) * only one operation required: lookup of pages by matching words in them * very simple web frontend for querying the words to be matched * no authentication or authorization, frontend completely public * deployment at webfaction * deadline: yesterday :) Which web framework and db engine would you recommend? So far I'm familiar with turbogears but would be willing to learn anything if sufficiently basic since my needs are pretty basic (I think). Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From rosuav at gmail.com Fri Apr 29 19:23:30 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Apr 2016 09:23:30 +1000 Subject: web facing static text db In-Reply-To: References: Message-ID: On Sat, Apr 30, 2016 at 8:29 AM, Fetchinson . via Python-list wrote: > * store text documents (about 100000 pages) > * the data set is static (i.e. only lookups are performed, no delete, > no edit, no addition) > * only one operation required: lookup of pages by matching words in them > * very simple web frontend for querying the words to be matched > * no authentication or authorization, frontend completely public > * deployment at webfaction > * deadline: yesterday :) > > Which web framework and db engine would you recommend? PostgreSQL has decent facilities for text search. You can access that from Python using the psycopg2 module, and use something like Flask to help you put together your front end. ChrisA From fanjianling at gmail.com Fri Apr 29 19:33:12 2016 From: fanjianling at gmail.com (Jianling Fan) Date: Fri, 29 Apr 2016 17:33:12 -0600 Subject: about special characters Message-ID: Hello everyone, I am trying to use python 27 copying some of my folders and files to another directory. My code works good for other files but I have some problem to copy files that have some special characters in the filename. like filenames contain Greek "?" or latin "?". it always gave a error that "No such file or directory:" Any help will be appreciate! Thanks! Regards, Jianling From ben+python at benfinney.id.au Fri Apr 29 19:52:25 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 30 Apr 2016 09:52:25 +1000 Subject: about special characters References: Message-ID: <85zischt1i.fsf@benfinney.id.au> Jianling Fan writes: > I am trying to use python 27 copying some of my folders and files to > another directory. (There has never been a Python 27. I assume Python 2.7 is what you meant.) > My code works good for other files but I have some problem to copy > files that have some special characters in the filename. like > filenames contain Greek "?" or latin "?". You may already know that Python 2 handles international text a lot less consistently than Python 3. Is it at all feasible for you to use Python 3 instead? Text handling is specifically a big advantage of Python 3. > it always gave a error that "No such file or directory:" Please give a complete, small example: * The actual filenames. * The exact filesystem encoding that filesystem uses. Be sure to verify that! * A very small, but complete, Python program which exhibits the behaviour. We will need to be able to run the same program. * The complete error output (the full traceback). -- \ ?Corporation, n. An ingenious device for obtaining individual | `\ profit without individual responsibility.? ?Ambrose Bierce, | _o__) _The Devil's Dictionary_, 1906 | Ben Finney From grant.b.edwards at gmail.com Fri Apr 29 19:53:03 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 29 Apr 2016 23:53:03 +0000 (UTC) Subject: Why does pathlib not have is_readable() & things like that? References: <6474vcx0q6.ln2@news.ducksburg.com> <1461679044.2467938.590028273.4DEA02AA@webmail.messagingengine.com> Message-ID: On 2016-04-29, eryk sun wrote: > On Fri, Apr 29, 2016 at 6:51 AM, Jussi Piitulainen > wrote: >> Adam Funk writes: >>> On 2016-04-28, Grant Edwards wrote: >> >>>> Or just do os.access("directory/where/you/want/to/open/a/file",os.W_OK) >>> >>> That's what I'm doing now, but I prefer to give the user the error >>> message early on. >> >> Then do that early on. > > Note that on Windows os.access only checks if a file is read-only. > There's a proposed update to check the file security. The patch needs > to be updated and needs to be reworked, but it's a low priority. For > the most part calling os.access isn't recommended. I'm sure there are probably other ways that it fails also. That's why it's almost always simpler and better to just open the file in write mode and see if it works. -- Grant From python at mrabarnett.plus.com Fri Apr 29 20:32:35 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 30 Apr 2016 01:32:35 +0100 Subject: about special characters In-Reply-To: <85zischt1i.fsf@benfinney.id.au> References: <85zischt1i.fsf@benfinney.id.au> Message-ID: <77665750-2d18-c0a0-1777-40139a5132c3@mrabarnett.plus.com> On 2016-04-30 00:52, Ben Finney wrote: > Jianling Fan writes: > >> I am trying to use python 27 copying some of my folders and files to >> another directory. > > (There has never been a Python 27. I assume Python 2.7 is what you meant.) > >> My code works good for other files but I have some problem to copy >> files that have some special characters in the filename. like >> filenames contain Greek "?" or latin "?". > > You may already know that Python 2 handles international text a lot less > consistently than Python 3. > > Is it at all feasible for you to use Python 3 instead? Text handling is > specifically a big advantage of Python 3. > >> it always gave a error that "No such file or directory:" > > Please give a complete, small example: > > * The actual filenames. > > * The exact filesystem encoding that filesystem uses. Be sure to verify that! > > * A very small, but complete, Python program which exhibits the > behaviour. We will need to be able to run the same program. > > * The complete error output (the full traceback). > It might be a Unicode problem, i.e. trying to work with bytestrings (str) instead of Unicode strings (unicode) and using the wrong encoding. From steve at pearwood.info Fri Apr 29 20:35:57 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 30 Apr 2016 10:35:57 +1000 Subject: def __init__(self,cls): References: <70f3b5f6-33b7-4dc8-9c30-92fcc1b1f223@googlegroups.com> Message-ID: <5723fdf0$0$1598$c3e8da3$5496439d@news.astraweb.com> On Fri, 29 Apr 2016 07:47 pm, San wrote: > Dear Group, > > Please explain the following in details. > > " > def __init__(self,cls): > self.cls = cls The answer is the same as the answer you were given when you asked this question on the tutor mailing list. Did you read the answers you were given there? Your question: https://mail.python.org/pipermail/tutor/2016-April/108689.html My answer then: https://mail.python.org/pipermail/tutor/2016-April/108707.html The difference here is that you take a single argument called "cls". -- Steven From steve at pearwood.info Fri Apr 29 20:56:57 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 30 Apr 2016 10:56:57 +1000 Subject: about special characters References: <85zischt1i.fsf@benfinney.id.au> Message-ID: <572402db$0$1583$c3e8da3$5496439d@news.astraweb.com> On Sat, 30 Apr 2016 09:52 am, Ben Finney wrote: > Jianling Fan writes: > >> I am trying to use python 27 copying some of my folders and files to >> another directory. > > (There has never been a Python 27. I assume Python 2.7 is what you meant.) I believe that Python X.Y shows up as "PythonXY" under Windows. -- Steven From steve at pearwood.info Fri Apr 29 21:01:17 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 30 Apr 2016 11:01:17 +1000 Subject: about special characters References: Message-ID: <572403de$0$1601$c3e8da3$5496439d@news.astraweb.com> On Sat, 30 Apr 2016 09:33 am, Jianling Fan wrote: > Hello everyone, > > I am trying to use python 27 copying some of my folders and files to > another directory. > My code works good for other files but I have some problem to copy > files that have some special characters in the filename. like > filenames contain Greek "?" or latin "?". > it always gave a error that "No such file or directory:" > > Any help will be appreciate! Please put yourself in our shoes. Read your message above, and, imagine that you know NOTHING else about your program than what you write above. What answer would you give? Please tell us what you have actually done. How do you copy the files? How do you enter the file names? What OS are you using? -- Steven From christopher_reimer at yahoo.com Fri Apr 29 21:14:45 2016 From: christopher_reimer at yahoo.com (Christopher Reimer) Date: Fri, 29 Apr 2016 18:14:45 -0700 Subject: Not x.islower() Versus x.isupper Output Results Message-ID: <57240705.3060003@yahoo.com> Greetings, I was playing around with a piece of code to remove lowercase letters and leave behind uppercase letters from a string when I got unexpected results. string = 'Whiskey Tango Foxtrot' list(filter((lambda x: not x.islower()), string)) ['W', ' ', 'T', ' ', 'F'] Note the space characters in the list. list(filter((lambda x: x.isupper()), string)) ['W', 'T', 'F'] Note that there are no space characters in the list. Shouldn't the results between 'not x.islower()' and 'x.isupper()' be identical? The final form of this code is this: list(filter(str.isupper, string)) ['W', 'T', 'F'] Thank you, Chris R. From christopher_reimer at icloud.com Fri Apr 29 21:17:34 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Fri, 29 Apr 2016 18:17:34 -0700 Subject: Not x.islower() has different output than x.isupper() in list output... Message-ID: <572407AE.1070703@icloud.com> Greetings, I was playing around with a piece of code to remove lowercase letters and leave behind uppercase letters from a string when I got unexpected results. string = 'Whiskey Tango Foxtrot' list(filter((lambda x: not x.islower()), string)) ['W', ' ', 'T', ' ', 'F'] Note the space characters in the list. list(filter((lambda x: x.isupper()), string)) ['W', 'T', 'F'] Note that there are no space characters in the list. Shouldn't the results between 'not x.islower()' and 'x.isupper()' be identical? The final form of this code is this: list(filter(str.isupper, string)) ['W', 'T', 'F'] Thank you, Chris R. From steve at pearwood.info Fri Apr 29 21:20:21 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 30 Apr 2016 11:20:21 +1000 Subject: What should Python apps do when asked to show help? References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> <57232b34$0$1595$c3e8da3$5496439d@news.astraweb.com> <72444f12-784b-47b4-a80c-0ae53cf3b5a3@googlegroups.com> Message-ID: <57240856$0$1590$c3e8da3$5496439d@news.astraweb.com> On Fri, 29 Apr 2016 07:53 pm, Rustom Mody wrote: > On Friday, April 29, 2016 at 3:07:09 PM UTC+5:30, Steven D'Aprano wrote: >> On Fri, 29 Apr 2016 03:00 pm, Rustom Mody wafted information-rich >> pheromones into the air, where they diffused rapidly: >> > Why replicate and cause annoyance? >> >> If you don't want to use the functionality, don't. > > You asked about calling up pagers!! Right. And options -h/--help will behave exactly as people have requested, by printing to stdout. > JFTR I find git behavior annoying -- as it seems do others `git --help` behaves as the Unix standard: it prints help output to stdout. Is that the annoying behaviour? `git help ` and `git --help` call `man`. Is that the annoying behaviour? Then presumably `man` is also annoying, and the advise I was given to just use man pages is bad advice. > -- but Ive > figured getting round it by calling it with -w (show in web browser) is ok > (with me) You would rather output be shown in a web browser than paged in your terminal? That's weird, but okay, whatever floats your boat. > With python's help I find it annoying and Ive not figured out how to not > get paging o_O Okay, now I'm feeling as if you had said "I find it annoying to be fit and healthy, I've not found a way to feel sufficiently sick, tired and out-of-shape all the time." But I see your point. The pydoc documentation itself is lacking. But from reading the source code, I see that if you set the PAGER environment variable to your preferred pager, it will use that. So setting it to "cat" should work. I've just tested this under Linux, and it works for me: [steve at ando ~]$ PAGER=cat python3.3 Python 3.3.0rc3 (default, Sep 27 2012, 18:44:58) [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux Type "help", "copyright", "credits" or "license" for more information. py> help(len) Help on built-in function len in module builtins: len(...) len(object) -> integer Return the number of items of a sequence or mapping. py> -- Steven From me at ixokai.io Fri Apr 29 21:29:57 2016 From: me at ixokai.io (Stephen Hansen) Date: Fri, 29 Apr 2016 18:29:57 -0700 Subject: Not x.islower() has different output than x.isupper() in list output... In-Reply-To: <572407AE.1070703@icloud.com> References: <572407AE.1070703@icloud.com> Message-ID: <1461979797.3824480.593944273.0B8D8DF3@webmail.messagingengine.com> On Fri, Apr 29, 2016, at 06:17 PM, Christopher Reimer wrote: > Greetings, > > I was playing around with a piece of code to remove lowercase letters > and leave behind uppercase letters from a string when I got unexpected > results. > > string = 'Whiskey Tango Foxtrot' > > list(filter((lambda x: not x.islower()), string)) > > ['W', ' ', 'T', ' ', 'F'] > > Note the space characters in the list. > > list(filter((lambda x: x.isupper()), string)) > > ['W', 'T', 'F'] > > Note that there are no space characters in the list. > > Shouldn't the results between 'not x.islower()' and 'x.isupper()' be > identical? Absolutely not. There are characters which are neither uppercase or lowercase: specifically, whitespace in your situation. "x.islower()" is true for everything that is lowercase, and false for everything else. (Including things which have no case). If you invert with not, then its false for everything that is lowercase, but true for everything else: including things which have no case. "x.isupper()" is true for everything that is uppercase, and false for everything else. This is therefore a narrower test then "not x.islower()" x.isupper() is a narrower, more specific test then "not x.islower()". If you used "not x.isupper()" you'd get the whitespace in it too (along with all the lower case characters). If isupper/islower were perfect opposites of each-other, there'd be no need for both. But since characters can be upper, lower, or *neither*, you run into this situation. -- Stephen Hansen m e @ i x o k a i . i o From steve at pearwood.info Fri Apr 29 21:31:23 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 30 Apr 2016 11:31:23 +1000 Subject: Not x.islower() Versus x.isupper Output Results References: <57240705.3060003@yahoo.com> Message-ID: <57240aec$0$1615$c3e8da3$5496439d@news.astraweb.com> On Sat, 30 Apr 2016 11:14 am, Christopher Reimer wrote: > Shouldn't the results between 'not x.islower()' and 'x.isupper()' be > identical? Of course not. py> "2 #".islower(), "2 #".isupper() (False, False) py> not "2 #".islower(), "2 #".isupper() (True, False) "Is Lower" versus "Is Upper" is not a dichotomy. There are: - lowercase characters, like "abc" - uppercase characters, like "ABC" - characters which are neither lowercase nor uppercase, like "2 #" In unicode, there are also: - titlecase characters, like "???" If those characters don't show up for you, they are: U+01C5 LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON U+01C8 LATIN CAPITAL LETTER L WITH SMALL LETTER J U+1FFC GREEK CAPITAL LETTER OMEGA WITH PROSGEGRAMMENI So not islower() is very different from isupper. -- Steven From steve at pearwood.info Fri Apr 29 21:44:52 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 30 Apr 2016 11:44:52 +1000 Subject: Python path and append References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> <571ec99c$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57240e15$0$1607$c3e8da3$5496439d@news.astraweb.com> On Sat, 30 Apr 2016 06:26 am, boB Stepp wrote: > On Mon, Apr 25, 2016 at 8:51 PM, Steven D'Aprano > wrote: > >> See here for the *start* of a more professional approach: >> >> http://code.activestate.com/recipes/579097-safely-and-atomically-write-to-a-file/ > > What else would I need to know/consider in order to have a *complete* > professional approach? When I know, I'll tell you. I think the answer depends in part on what you're trying to do. The requirements for, say, an ACID-compliant database are much heavier than for most applications. As far as regular applications go, I'd like to see: - the above tested and debugged for Windows and MacOS; - should it save the previous version of the file? - if so, how many backup files should it keep? - should it try to sync and flush the disk on saving the file? - anything I haven't thought of? Some of those (like the keeping of backups) is probably something that should be given as an option to the end-user. -- Steven From ben+python at benfinney.id.au Fri Apr 29 21:48:58 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 30 Apr 2016 11:48:58 +1000 Subject: about special characters References: <85zischt1i.fsf@benfinney.id.au> <572402db$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85vb2zj27p.fsf@benfinney.id.au> Steven D'Aprano writes: > On Sat, 30 Apr 2016 09:52 am, Ben Finney wrote: > > > (There has never been a Python 27. I assume Python 2.7 is what you > > meant.) > > I believe that Python X.Y shows up as "PythonXY" under Windows. Then that's a bug which should be fixed, IMO. An MS Windows user (i.e., not me) would be well placed to describe the behaviour in a bug report. -- \ ?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 steve at pearwood.info Fri Apr 29 21:51:13 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 30 Apr 2016 11:51:13 +1000 Subject: Not x.islower() Versus x.isupper Output Results References: <57240705.3060003@yahoo.com> <57240aec$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57240f92$0$1606$c3e8da3$5496439d@news.astraweb.com> On Sat, 30 Apr 2016 11:31 am, Steven D'Aprano wrote: > In unicode, there are also: > > - titlecase characters, like "???" To be clear, each of those three characters is considered titlecased individually. The three of them together is not considered a title-cased string. "Is Title" is not just for Unicode. In Python 2, strings (ASCII byte strings) also have an istitle() method: py> "Dz".istitle() True py> "DZ".istitle() False -- Steven From christopher_reimer at icloud.com Fri Apr 29 21:55:35 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Fri, 29 Apr 2016 18:55:35 -0700 Subject: Not x.islower() has different output than x.isupper() in list output... In-Reply-To: <1461979797.3824480.593944273.0B8D8DF3@webmail.messagingengine.com> References: <572407AE.1070703@icloud.com> <1461979797.3824480.593944273.0B8D8DF3@webmail.messagingengine.com> Message-ID: <57241097.7020801@icloud.com> On 4/29/2016 6:29 PM, Stephen Hansen wrote: > If isupper/islower were perfect opposites of each-other, there'd be no > need for both. But since characters can be upper, lower, or *neither*, > you run into this situation. Based upon the official documentation, I was expecting perfect opposites. str.islower(): "Return true if all cased characters [4] in the string are lowercase and there is at least one cased character, false otherwise." https://docs.python.org/3/library/stdtypes.html?highlight=islower#str.islower str.isupper(): "Return true if all cased characters [4] in the string are uppercase and there is at least one cased character, false otherwise." https://docs.python.org/3/library/stdtypes.html?highlight=isupper#str.isupper Here's the footnote that may or not be relevant to this discussion: "[4] Cased characters are those with general category property being one of ?Lu? (Letter, uppercase), ?Ll? (Letter, lowercase), or ?Lt? (Letter, titlecase)." A bug in the docs? Thank you, Chris R. From ethan at stoneleaf.us Fri Apr 29 22:09:13 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 29 Apr 2016 19:09:13 -0700 Subject: What should Python apps do when asked to show help? In-Reply-To: <57240856$0$1590$c3e8da3$5496439d@news.astraweb.com> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> <57232b34$0$1595$c3e8da3$5496439d@news.astraweb.com> <72444f12-784b-47b4-a80c-0ae53cf3b5a3@googlegroups.com> <57240856$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: <572413C9.2070405@stoneleaf.us> On 04/29/2016 06:20 PM, Steven D'Aprano wrote: > On Fri, 29 Apr 2016 07:53 pm, Rustom Mody wrote: >> JFTR I find git behavior annoying -- as it seems do others > > `git --help` behaves as the Unix standard: it prints help output to stdout. > Is that the annoying behaviour? No. > `git help ` and `git --help` call `man`. Is that the > annoying behaviour? Yes. > Then presumably `man` is also annoying, No. > and the advise I was given to just use man pages is bad advice. The advice to call man from --help is bad; the advice to have a man page for use with man is not. >> With python's help I find it annoying and Ive not figured out how to not >> get paging > > o_O > > Okay, now I'm feeling as if you had said "I find it annoying to be fit and > healthy, I've not found a way to feel sufficiently sick, tired and > out-of-shape all the time." And exactly what is healthy and fit about calling "help(something)" and then having that help disappear? I find that *extremely* annoying. > But I see your point. The pydoc documentation itself is lacking. But from > reading the source code, I see that if you set the PAGER environment > variable to your preferred pager, it will use that. So setting it to "cat" > should work. I've just tested this under Linux, and it works for me: So I have to cripple my shell to get pydoc help to work nicely? Neat! Actually, not so much. :( -- ~Ethan~ From rosuav at gmail.com Fri Apr 29 22:10:50 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Apr 2016 12:10:50 +1000 Subject: Not x.islower() has different output than x.isupper() in list output... In-Reply-To: <57241097.7020801@icloud.com> References: <572407AE.1070703@icloud.com> <1461979797.3824480.593944273.0B8D8DF3@webmail.messagingengine.com> <57241097.7020801@icloud.com> Message-ID: On Sat, Apr 30, 2016 at 11:55 AM, Christopher Reimer wrote: > On 4/29/2016 6:29 PM, Stephen Hansen wrote: >> >> If isupper/islower were perfect opposites of each-other, there'd be no >> need for both. But since characters can be upper, lower, or *neither*, you >> run into this situation. > > > Based upon the official documentation, I was expecting perfect opposites. > > str.islower(): "Return true if all cased characters [4] in the string are > lowercase and there is at least one cased character, false otherwise." > > https://docs.python.org/3/library/stdtypes.html?highlight=islower#str.islower > > str.isupper(): "Return true if all cased characters [4] in the string are > uppercase and there is at least one cased character, false otherwise." > > https://docs.python.org/3/library/stdtypes.html?highlight=isupper#str.isupper > > Here's the footnote that may or not be relevant to this discussion: "[4] > Cased characters are those with general category property being one of ?Lu? > (Letter, uppercase), ?Ll? (Letter, lowercase), or ?Lt? (Letter, titlecase)." > > A bug in the docs? >>> def case(ch): ... return ( ... ("Lower " if ch.islower() else "") + ... ("Upper " if ch.isupper() else "") + ... unicodedata.category(ch) ... ) Both functions require that there be at least one cased character: >>> case("@") 'Po' And then each one requires a specific character class: >>> case("a") 'Lower Ll' >>> case("A") 'Upper Lu' Other classes don't count: >>> case("\u01C5") 'Lt' There are three categories of "cased characters". Both functions check for exactly one of those categories. Thus they are not opposites. ChrisA From random832 at fastmail.com Fri Apr 29 22:16:52 2016 From: random832 at fastmail.com (Random832) Date: Fri, 29 Apr 2016 22:16:52 -0400 Subject: What should Python apps do when asked to show help? In-Reply-To: <572413C9.2070405@stoneleaf.us> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> <57232b34$0$1595$c3e8da3$5496439d@news.astraweb.com> <72444f12-784b-47b4-a80c-0ae53cf3b5a3@googlegroups.com> <57240856$0$1590$c3e8da3$5496439d@news.astraweb.com> <572413C9.2070405@stoneleaf.us> Message-ID: <1461982612.3299155.593966809.3D1A53FF@webmail.messagingengine.com> On Fri, Apr 29, 2016, at 22:09, Ethan Furman wrote: > So I have to cripple my shell to get pydoc help to work nicely? Neat! > Actually, not so much. :( If you don't want a pager with pydoc, when exactly do you want it? From ben+python at benfinney.id.au Fri Apr 29 22:25:21 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 30 Apr 2016 12:25:21 +1000 Subject: manpage writing [rst, asciidoc, pod] was [Re: What should Python apps do when asked to show help?] References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461865210.3218352.592571425.2069E4EB@webmail.messagingengine.com> <87a8kdshyh.fsf@elektro.pacujo.net> <1461873085.3251720.592695601.44633E5E@webmail.messagingengine.com> <5722bb82$0$1600$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85r3dnj0j2.fsf@benfinney.id.au> "Martin A. Brown" writes: > Hello [Steven D'Aprano], > > >What is a good place where I can find out more about writing manpage? Writing them directly in GNU troff markup is easy enough . For writing manual pages programmatically via Python code, I am working on a ?manpage? library. It is not yet at PyPI, but Steven may find the existing library useful. It's free software under the GNU GPL v3 or later. Steven, if you want to use that library for making manual pages, I'd love to get feedback. Currently it works on an ArgumentParser instance (to get the program's name and option help), and a Distutils distribution (to get the boader metadata about the package). What ?manpage? doesn't yet have is a more generic way to specify the metadata of a manual page. Everything is done by directly modifying a Document instance. I have yet to decide a data format for the data which specifies a manual page. Getting several more code bases using this library would make it clearer what use cases are important, and thereby inform a data format for the specification. Please experiment! -- \ ?The process by which banks create money is so simple that the | `\ mind is repelled.? ?John Kenneth Galbraith, _Money: Whence It | _o__) Came, Where It Went_, 1975 | Ben Finney From ben+python at benfinney.id.au Fri Apr 29 22:25:21 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 30 Apr 2016 12:25:21 +1000 Subject: Writing manual pages using Python code (was: manpage writing) References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461865210.3218352.592571425.2069E4EB@webmail.messagingengine.com> <87a8kdshyh.fsf@elektro.pacujo.net> <1461873085.3251720.592695601.44633E5E@webmail.messagingengine.com> <5722bb82$0$1600$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85k2jfj036.fsf@benfinney.id.au> "Martin A. Brown" writes: > Hello [Steven D'Aprano], > > >What is a good place where I can find out more about writing manpage? Writing manual pages directly in standard GNU troff markup is simple enough . It's not a pretty markup language, but it's workable. For writing manual page documents programmatically via Python code, I am working on a ?manpage? library. It is not yet at PyPI, but Steven may find the existing library useful. It's free software under the GNU GPL v3 or later. Steven, if you want to use that library for making manual pages, I'd love to get feedback. Currently it works on an ArgumentParser instance (to get the program's name and option help), and a Distutils distribution (to get the boader metadata about the package). What ?manpage? doesn't yet have is a more generic way to specify the metadata of a manual page; the above inputs are the only ones that I've tested. Everything is done by directly modifying a Document instance. I have yet to decide a data format for the data which specifies a manual page. If several more code bases could use this library to generate manual pages, that would make it clearer what use cases are important, and thereby inform a data format for the specification. Please experiment! -- \ ?The process by which banks create money is so simple that the | `\ mind is repelled.? ?John Kenneth Galbraith, _Money: Whence It | _o__) Came, Where It Went_, 1975 | Ben Finney From rustompmody at gmail.com Fri Apr 29 22:27:28 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 29 Apr 2016 19:27:28 -0700 (PDT) Subject: What should Python apps do when asked to show help? In-Reply-To: References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> <57232b34$0$1595$c3e8da3$5496439d@news.astraweb.com> <72444f12-784b-47b4-a80c-0ae53cf3b5a3@googlegroups.com> <57240856$0$1590$c3e8da3$5496439d@news.astraweb.com> <572413C9.2070405@stoneleaf.us> <1461982612.3299155.593966809.3D1A53FF@webmail.messagingengine.com> Message-ID: <41ec5af0-2ffa-4202-a5df-08f9660f7c57@googlegroups.com> On Saturday, April 30, 2016 at 7:47:11 AM UTC+5:30, Random832 wrote: > On Fri, Apr 29, 2016, at 22:09, Ethan Furman wrote: > > So I have to cripple my shell to get pydoc help to work nicely? Neat! > > Actually, not so much. :( > > If you don't want a pager with pydoc, when exactly do you want it? - I start a python interpreter - ... Am pottering around for a while - ... Need help on something... [So with Steven's solution of PAGER=cat Ive to restart python!! Leaving that aside...] - ... help can do one of two valid things [remember I am on a modern windowing system] -- start help inline, inband (cat) -- start help out of band (browser, yelp, etc ie some other app) Instead it does some ?-assed fall-between-the-stools of both From eryksun at gmail.com Fri Apr 29 22:35:42 2016 From: eryksun at gmail.com (eryk sun) Date: Fri, 29 Apr 2016 21:35:42 -0500 Subject: about special characters In-Reply-To: <85vb2zj27p.fsf@benfinney.id.au> References: <85zischt1i.fsf@benfinney.id.au> <572402db$0$1583$c3e8da3$5496439d@news.astraweb.com> <85vb2zj27p.fsf@benfinney.id.au> Message-ID: On Fri, Apr 29, 2016 at 8:48 PM, Ben Finney wrote: > Steven D'Aprano writes: >> On Sat, 30 Apr 2016 09:52 am, Ben Finney wrote: >> >> > (There has never been a Python 27. I assume Python 2.7 is what you >> > meant.) >> >> I believe that Python X.Y shows up as "PythonXY" under Windows. > > Then that's a bug which should be fixed, IMO. An MS Windows user (i.e., > not me) would be well placed to describe the behaviour in a bug report. It's Python X.Y in the start menu and Python X.Y.Z in sys.version. The default installation directory is PythonXY (for 3.5.0 it was "Python 3.5"; this was reverted in 3.5.1), and the DLL is pythonXY.dll. The executables are python.exe and pythonw.exe. From random832 at fastmail.com Fri Apr 29 22:36:31 2016 From: random832 at fastmail.com (Random832) Date: Fri, 29 Apr 2016 22:36:31 -0400 Subject: What should Python apps do when asked to show help? In-Reply-To: <41ec5af0-2ffa-4202-a5df-08f9660f7c57@googlegroups.com> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> <57232b34$0$1595$c3e8da3$5496439d@news.astraweb.com> <72444f12-784b-47b4-a80c-0ae53cf3b5a3@googlegroups.com> <57240856$0$1590$c3e8da3$5496439d@news.astraweb.com> <572413C9.2070405@stoneleaf.us> <1461982612.3299155.593966809.3D1A53FF@webmail.messagingengine.com> <41ec5af0-2ffa-4202-a5df-08f9660f7c57@googlegroups.com> Message-ID: <1461983791.3302675.593974129.5625C3C3@webmail.messagingengine.com> On Fri, Apr 29, 2016, at 22:27, Rustom Mody wrote: > On Saturday, April 30, 2016 at 7:47:11 AM UTC+5:30, Random832 wrote: > > On Fri, Apr 29, 2016, at 22:09, Ethan Furman wrote: > > > So I have to cripple my shell to get pydoc help to work nicely? Neat! > > > Actually, not so much. :( > > > > If you don't want a pager with pydoc, when exactly do you want it? > > - I start a python interpreter > - ... Am pottering around for a while > - ... Need help on something... > [So with Steven's solution of PAGER=cat Ive to restart python!! > Leaving that aside...] > - ... help can do one of two valid things [remember I am on a modern > windowing > system] > -- start help inline, inband (cat) > -- start help out of band (browser, yelp, etc ie some other app) > > Instead it does some ?-assed fall-between-the-stools of both That doesn't answer the question of why, if you (Well, Ethan, but you're taking the same position here) hate pagers so much, why you can't just set PAGER=cat in your profile once, now, and never see one again. How does this "cripple your shell"; if you hate pagers so much why do you want man or git to use one any more than pydoc? From tjreedy at udel.edu Fri Apr 29 22:37:38 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Apr 2016 22:37:38 -0400 Subject: about special characters In-Reply-To: <85vb2zj27p.fsf@benfinney.id.au> References: <85zischt1i.fsf@benfinney.id.au> <572402db$0$1583$c3e8da3$5496439d@news.astraweb.com> <85vb2zj27p.fsf@benfinney.id.au> Message-ID: On 4/29/2016 9:48 PM, Ben Finney wrote: > Steven D'Aprano writes: > >> On Sat, 30 Apr 2016 09:52 am, Ben Finney wrote: >> >>> (There has never been a Python 27. I assume Python 2.7 is what you >>> meant.) >> >> I believe that Python X.Y shows up as "PythonXY" under Windows. As a directory name that also omits the space, yes. Start Menu entries have both the space and and the '.'. > Then that's a bug which should be fixed, IMO. An MS Windows user (i.e., > not me) would be well placed to describe the behaviour in a bug report. I disagree. .0, .1, etc, would look like extensions, but are not. -- Terry Jan Reedy From ben+python at benfinney.id.au Fri Apr 29 22:43:29 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 30 Apr 2016 12:43:29 +1000 Subject: about special characters References: <85zischt1i.fsf@benfinney.id.au> <572402db$0$1583$c3e8da3$5496439d@news.astraweb.com> <85vb2zj27p.fsf@benfinney.id.au> Message-ID: <85fuu3izou.fsf@benfinney.id.au> Terry Reedy writes: > On 4/29/2016 9:48 PM, Ben Finney wrote: > > Steven D'Aprano writes: > > > >> On Sat, 30 Apr 2016 09:52 am, Ben Finney wrote: > >> > >>> (There has never been a Python 27. I assume Python 2.7 is what you > >>> meant.) > >> > >> I believe that Python X.Y shows up as "PythonXY" under Windows. > > As a directory name that also omits the space, yes. Start Menu entries > have both the space and and the '.'. Okay. So as you describe the behaviour on MS Windows, it doesn't support the OP's choice of saying ?python 27? to specify Python 2.7 ? MS Windows appears to be irrelevant to that. -- \ ?Computer perspective on Moore's Law: Human effort becomes | `\ twice as expensive roughly every two years.? ?anonymous | _o__) | Ben Finney From rustompmody at gmail.com Fri Apr 29 22:46:04 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 29 Apr 2016 19:46:04 -0700 (PDT) Subject: What should Python apps do when asked to show help? In-Reply-To: References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> <57232b34$0$1595$c3e8da3$5496439d@news.astraweb.com> <72444f12-784b-47b4-a80c-0ae53cf3b5a3@googlegroups.com> <57240856$0$1590$c3e8da3$5496439d@news.astraweb.com> <572413C9.2070405@stoneleaf.us> <1461982612.3299155.593966809.3D1A53FF@webmail.messagingengine.com> <41ec5af0-2ffa-4202-a5df-08f9660f7c57@googlegroups.com> <1461983791.3302675.593974129.5625C3C3@webmail.messagingengine.com> Message-ID: <875ab1a2-bd23-4b1e-92ca-4079b8e86e6b@googlegroups.com> On Saturday, April 30, 2016 at 8:06:46 AM UTC+5:30, Random832 wrote: > On Fri, Apr 29, 2016, at 22:27, Rustom Mody wrote: > > On Saturday, April 30, 2016 at 7:47:11 AM UTC+5:30, Random832 wrote: > > > On Fri, Apr 29, 2016, at 22:09, Ethan Furman wrote: > > > > So I have to cripple my shell to get pydoc help to work nicely? Neat! > > > > Actually, not so much. :( > > > > > > If you don't want a pager with pydoc, when exactly do you want it? > > > > - I start a python interpreter > > - ... Am pottering around for a while > > - ... Need help on something... > > [So with Steven's solution of PAGER=cat Ive to restart python!! > > Leaving that aside...] > > - ... help can do one of two valid things [remember I am on a modern > > windowing > > system] > > -- start help inline, inband (cat) > > -- start help out of band (browser, yelp, etc ie some other app) > > > > Instead it does some ?-assed fall-between-the-stools of both > > That doesn't answer the question of why, if you (Well, Ethan, but you're > taking the same position here) hate pagers so much, why you can't just > set PAGER=cat in your profile once, now, and never see one again. How > does this "cripple your shell"; if you hate pagers so much why do you > want man or git to use one any more than pydoc? I dont get whats so hard to get in this: When we need pagers we know where to get them When we dont, please dont thump them on us I dont know that anyone has taken the "I-HATE-pagers' view so much as "Let me get them when I want them" From ben+python at benfinney.id.au Fri Apr 29 22:49:20 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 30 Apr 2016 12:49:20 +1000 Subject: What should Python apps do when asked to show help? References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> <57232b34$0$1595$c3e8da3$5496439d@news.astraweb.com> <72444f12-784b-47b4-a80c-0ae53cf3b5a3@googlegroups.com> <57240856$0$1590$c3e8da3$5496439d@news.astraweb.com> <572413C9.2070405@stoneleaf.us> <1461982612.3299155.593966809.3D1A53FF@webmail.messagingengine.com> <41ec5af0-2ffa-4202-a5df-08f9660f7c57@googlegroups.com> <1461983791.3302675.593974129.5625C3C3@webmail.messagingengine.com> Message-ID: <85bn4rizf3.fsf@benfinney.id.au> Random832 writes: > On Fri, Apr 29, 2016, at 22:27, Rustom Mody wrote: > > Instead it does some ?-assed fall-between-the-stools of both > > That doesn't answer the question of why, if you (Well, Ethan, but > you're taking the same position here) hate pagers so much That's not a question relevant here; nobody inthe discussion has a position fairly characterised as ?hate pagers so much?. So you're arguing against a straw man. Rather, the position being argued is that they *do* like pagers; they like pagers enough that they want the existing ?PAGER? environment variable setting to remain untouched. And, simulatenously, they want Python's help to not use a pager at the interactive prompt. -- \ ?The difference between religions and cults is determined by | `\ how much real estate is owned.? ?Frank Zappa | _o__) | Ben Finney From python at mrabarnett.plus.com Fri Apr 29 22:53:16 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 30 Apr 2016 03:53:16 +0100 Subject: about special characters In-Reply-To: References: <85zischt1i.fsf@benfinney.id.au> <572402db$0$1583$c3e8da3$5496439d@news.astraweb.com> <85vb2zj27p.fsf@benfinney.id.au> Message-ID: <7ee9728b-e4e7-9c1d-3ba5-763b514282a2@mrabarnett.plus.com> On 2016-04-30 03:35, eryk sun wrote: > On Fri, Apr 29, 2016 at 8:48 PM, Ben Finney wrote: >> Steven D'Aprano writes: >>> On Sat, 30 Apr 2016 09:52 am, Ben Finney wrote: >>> >>> > (There has never been a Python 27. I assume Python 2.7 is what you >>> > meant.) >>> >>> I believe that Python X.Y shows up as "PythonXY" under Windows. >> >> Then that's a bug which should be fixed, IMO. An MS Windows user (i.e., >> not me) would be well placed to describe the behaviour in a bug report. > > It's Python X.Y in the start menu and Python X.Y.Z in sys.version. The > default installation directory is PythonXY (for 3.5.0 it was "Python > 3.5"; this was reverted in 3.5.1), and the DLL is pythonXY.dll. The > executables are python.exe and pythonw.exe. > There's an option in Windows to hide the extension. I wondered whether that had something to do with it. It turns out that it applies only to file names, not folder names, so you can have multiple files apparently with the same name, but folder names remain distinct. From random832 at fastmail.com Fri Apr 29 23:14:03 2016 From: random832 at fastmail.com (Random832) Date: Fri, 29 Apr 2016 23:14:03 -0400 Subject: What should Python apps do when asked to show help? In-Reply-To: <875ab1a2-bd23-4b1e-92ca-4079b8e86e6b@googlegroups.com> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> <57232b34$0$1595$c3e8da3$5496439d@news.astraweb.com> <72444f12-784b-47b4-a80c-0ae53cf3b5a3@googlegroups.com> <57240856$0$1590$c3e8da3$5496439d@news.astraweb.com> <572413C9.2070405@stoneleaf.us> <1461982612.3299155.593966809.3D1A53FF@webmail.messagingengine.com> <41ec5af0-2ffa-4202-a5df-08f9660f7c57@googlegroups.com> <1461983791.3302675.593974129.5625C3C3@webmail.messagingengine.com> <875ab1a2-bd23-4b1e-92ca-4079b8e86e6b@googlegroups.com> Message-ID: <1461986043.3312511.593988601.278FD12E@webmail.messagingengine.com> On Fri, Apr 29, 2016, at 22:46, Rustom Mody wrote: > I dont get whats so hard to get in this: > When we need pagers we know where to get them And if you set PAGER=cat (thus "crippling your shell"), you will likewise know where to get them when you want to page the output from man or git. Why is pydoc less of a "place where a pager should be used by default" than man or git (diff, log, etc), if you accept the latter? > When we dont, please dont thump them on us > I dont know that anyone has taken the "I-HATE-pagers' view so much as > "Let me get them when I want them" Sure. And if you set PAGER=cat, then you won't ever see a pager unless you specifically request one. Everyone wins. From rustompmody at gmail.com Fri Apr 29 23:20:33 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 29 Apr 2016 20:20:33 -0700 (PDT) Subject: manpage writing [rst, asciidoc, pod] was [Re: What should Python apps do when asked to show help?] In-Reply-To: References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461865210.3218352.592571425.2069E4EB@webmail.messagingengine.com> <87a8kdshyh.fsf@elektro.pacujo.net> <1461873085.3251720.592695601.44633E5E@webmail.messagingengine.com> <5722bb82$0$1600$c3e8da3$5496439d@news.astraweb.com> <85r3dnj0j2.fsf@benfinney.id.au> Message-ID: On Saturday, April 30, 2016 at 7:55:47 AM UTC+5:30, Ben Finney wrote: > "Martin A. Brown" writes: > > > Hello [Steven D'Aprano], > > > > >What is a good place where I can find out more about writing manpage? > > Writing them directly in GNU troff markup is easy enough > . > > For writing manual pages programmatically via Python code, I am working > on a 'manpage' library. It is not yet at PyPI, but Steven may find > the existing library > useful. It's free software under the GNU GPL v3 or later. > > Steven, if you want to use that library for making manual pages, I'd > love to get feedback. Currently it works on an ArgumentParser instance > (to get the program's name and option help), and a Distutils > distribution (to get the boader metadata about the package). > > What 'manpage' doesn't yet have is a more generic way to specify the > metadata of a manual page. Everything is done by directly modifying a > Document instance. I have yet to decide a data format for the data which > specifies a manual page. > > Getting several more code bases using this library would make it clearer > what use cases are important, and thereby inform a data format for the > specification. Please experiment! Some general thoughts and comments: Documentation in linux is a train-wreck in slow motion -- 30 years of slow motion!! tl;dr If you want to be helpful to the community please dont create a new format Instead try to make existing formats interoperate/work better with each other In more detail: First there was man Then gnu/rms created info to better man with hypertext capabilities However another hypertext standard beat the gnu standard -- html [No I am not talking of quality just general acceptance] As with all things rms, its taking him decades to realize this defeat [Latest makeinfo is 18 times slower than previous version!! https://lists.gnu.org/archive/html/bug-texinfo/2013-01/msg00012.html ] In the meantime the so called lightweight formats have multiplied: rst, textile, markdown, asciidoc etc with their own 'stacks' Alongside siloed, incompatible help systems: manpages, infodocs, yelp... From steve at pearwood.info Fri Apr 29 23:23:40 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 30 Apr 2016 13:23:40 +1000 Subject: What should Python apps do when asked to show help? References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> <57232b34$0$1595$c3e8da3$5496439d@news.astraweb.com> <72444f12-784b-47b4-a80c-0ae53cf3b5a3@googlegroups.com> <57240856$0$1590$c3e8da3$5496439d@news.astraweb.com> <572413C9.2070405@stoneleaf.us> <1461982612.3299155.593966809.3D1A53FF@webmail.messagingengine.com> <41ec5af0-2ffa-4202-a5df-08f9660f7c57@googlegroups.com> <1461983791.3302675.593974129.5625C3C3@webmail.messagingengine.com> <85bn4rizf3.fsf@benfinney.id.au> Message-ID: <5724253e$0$22142$c3e8da3$5496439d@news.astraweb.com> On Sat, 30 Apr 2016 12:49 pm, Ben Finney wrote: > Random832 writes: > >> On Fri, Apr 29, 2016, at 22:27, Rustom Mody wrote: >> > Instead it does some ?-assed fall-between-the-stools of both >> >> That doesn't answer the question of why, if you (Well, Ethan, but >> you're taking the same position here) hate pagers so much > > That's not a question relevant here; nobody inthe discussion has a > position fairly characterised as ?hate pagers so much?. So you're > arguing against a straw man. > > Rather, the position being argued is that they *do* like pagers; they > like pagers enough that they want the existing ?PAGER? environment > variable setting to remain untouched. So they want the PAGER environment variable to specify what pager they want... > And, simulatenously, they want > Python's help to not use a pager at the interactive prompt. ...so long as applications don't actually make use of that PAGER environment variable to determine the pager they want to use. (1) If you want man, and nothing else in the universe, to automatically use a pager, then set MANPAGER="less" (or whatever you wish to use), and unset PAGER. (2) If you don't want *anything* to use a pager, then unset both MANPAGER and PAGER. You may have to report a feature request / bug report for applications which force their own pager. (3) In Python specifically, you can trivially and easily tell help() to output directly to stdout. (At least on Linux, I haven't tested it elsewhere.) Simply use PAGER=cat on the command line you use to launch the interactive environment. This will affect no other running or future processes (apart from subprocesses launched from your interactive Python session), allowing you to keep your PAGER for everything else. (4) If you want more than that, then patches are welcome :-) Seriously, I'm thinking that a keyword argument to help might be useful: help(object, pager=None) where: - pager=None gives the current behaviour; - pager="foo" calls out to the external program "foo"; - pager=callable passes the help text to callable(). pager=print would do exactly what people are asking for, and you could then create your own wrapper to change the default: help = functools.partial(builtins.help, pager=print) I think that would make it easier to test help(). Thoughts? -- Steven From ben+python at benfinney.id.au Sat Apr 30 00:06:05 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 30 Apr 2016 14:06:05 +1000 Subject: What should Python apps do when asked to show help? References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> <57232b34$0$1595$c3e8da3$5496439d@news.astraweb.com> <72444f12-784b-47b4-a80c-0ae53cf3b5a3@googlegroups.com> <57240856$0$1590$c3e8da3$5496439d@news.astraweb.com> <572413C9.2070405@stoneleaf.us> <1461982612.3299155.593966809.3D1A53FF@webmail.messagingengine.com> <41ec5af0-2ffa-4202-a5df-08f9660f7c57@googlegroups.com> <1461983791.3302675.593974129.5625C3C3@webmail.messagingengine.com> <85bn4rizf3.fsf@benfinney.id.au> <5724253e$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: <857fffivv6.fsf@benfinney.id.au> Steven D'Aprano writes: > So they want the PAGER environment variable to specify what pager they > want... > > ...so long as applications don't actually make use of that PAGER > environment variable to determine the pager they want to use. This at least does not baldly misrepresent the position being made :-) -- \ ?My doctor told me to stop having intimate dinners for four. | `\ Unless there are three other people.? ?Orson Welles | _o__) | Ben Finney From no.email at nospam.invalid Sat Apr 30 00:06:31 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 29 Apr 2016 21:06:31 -0700 Subject: manpage writing [rst, asciidoc, pod] was [Re: What should Python apps do when asked to show help?] References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461865210.3218352.592571425.2069E4EB@webmail.messagingengine.com> <87a8kdshyh.fsf@elektro.pacujo.net> <1461873085.3251720.592695601.44633E5E@webmail.messagingengine.com> <5722bb82$0$1600$c3e8da3$5496439d@news.astraweb.com> <85r3dnj0j2.fsf@benfinney.id.au> Message-ID: <87y47vg2pk.fsf@nightsong.com> Rustom Mody writes: > As with all things rms, its taking him decades to realize this defeat > [Latest makeinfo is 18 times slower than previous version!! > https://lists.gnu.org/archive/html/bug-texinfo/2013-01/msg00012.html Wait, what's it written in now? > In the meantime the so called lightweight formats have multiplied: > rst, textile, markdown, asciidoc etc Pandoc can interconvert between most of those... maybe texinfo should be folded into it if it's not already. From random832 at fastmail.com Sat Apr 30 00:16:03 2016 From: random832 at fastmail.com (Random832) Date: Sat, 30 Apr 2016 00:16:03 -0400 Subject: What should Python apps do when asked to show help? In-Reply-To: <857fffivv6.fsf@benfinney.id.au> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> <57232b34$0$1595$c3e8da3$5496439d@news.astraweb.com> <72444f12-784b-47b4-a80c-0ae53cf3b5a3@googlegroups.com> <57240856$0$1590$c3e8da3$5496439d@news.astraweb.com> <572413C9.2070405@stoneleaf.us> <1461982612.3299155.593966809.3D1A53FF@webmail.messagingengine.com> <41ec5af0-2ffa-4202-a5df-08f9660f7c57@googlegroups.com> <1461983791.3302675.593974129.5625C3C3@webmail.messagingengine.com> <85bn4rizf3.fsf@benfinney.id.au> <5724253e$0$22142$c3e8da3$5496439d@news.astraweb.com> <857fffivv6.fsf@benfinney.id.au> Message-ID: <1461989763.3328622.594009561.22923A0D@webmail.messagingengine.com> On Sat, Apr 30, 2016, at 00:06, Ben Finney wrote: > Steven D'Aprano writes: > > > So they want the PAGER environment variable to specify what pager they > > want... > > > > ...so long as applications don't actually make use of that PAGER > > environment variable to determine the pager they want to use. > > This at least does not baldly misrepresent the position being made :-) I still don't understand how it's a misrepresentation. They said they don't want stuff (where "stuff" includes pydoc but it's not clear why or where it ends) to automatically use a pager without being requested, and provided absolutely no criteria by which pydoc is special and shouldn't behave the same as git and man do (since the entire reason PAGER=cat is an unacceptable solution is that it "cripples" git and man). From rustompmody at gmail.com Sat Apr 30 00:34:01 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 29 Apr 2016 21:34:01 -0700 (PDT) Subject: What should Python apps do when asked to show help? In-Reply-To: References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> <57232b34$0$1595$c3e8da3$5496439d@news.astraweb.com> <72444f12-784b-47b4-a80c-0ae53cf3b5a3@googlegroups.com> <57240856$0$1590$c3e8da3$5496439d@news.astraweb.com> <572413C9.2070405@stoneleaf.us> <1461982612.3299155.593966809.3D1A53FF@webmail.messagingengine.com> <41ec5af0-2ffa-4202-a5df-08f9660f7c57@googlegroups.com> <1461983791.3302675.593974129.5625C3C3@webmail.messagingengine.com> <85bn4rizf3.fsf@benfinney.id.au> <5724253e$0$22142$c3e8da3$5496439d@news.astraweb.com> <857fffivv6.fsf@benfinney.id.au> <1461989763.3328622.594009561.22923A0D@webmail.messagingengine.com> Message-ID: On Saturday, April 30, 2016 at 9:46:19 AM UTC+5:30, Random832 wrote: > On Sat, Apr 30, 2016, at 00:06, Ben Finney wrote: > > Steven D'Aprano writes: > > > > > So they want the PAGER environment variable to specify what pager they > > > want... > > > > > > ...so long as applications don't actually make use of that PAGER > > > environment variable to determine the pager they want to use. > > > > This at least does not baldly misrepresent the position being made :-) > > I still don't understand how it's a misrepresentation. They said they > don't want stuff (where "stuff" includes pydoc but it's not clear why or > where it ends) to automatically use a pager without being requested, and > provided absolutely no criteria by which pydoc is special and shouldn't > behave the same as git and man do (since the entire reason PAGER=cat is > an unacceptable solution is that it "cripples" git and man). Also environment variables are a nuisance and an antipattern: http://peterlyons.com/problog/2010/02/environment-variables-considered-harmful From random832 at fastmail.com Sat Apr 30 01:20:11 2016 From: random832 at fastmail.com (Random832) Date: Sat, 30 Apr 2016 01:20:11 -0400 Subject: What should Python apps do when asked to show help? In-Reply-To: <5724253e$0$22142$c3e8da3$5496439d@news.astraweb.com> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <877ffhgnyf.fsf@nightsong.com> <0d5b5562-7a08-41de-8b84-a13f0792e767@googlegroups.com> <57232b34$0$1595$c3e8da3$5496439d@news.astraweb.com> <72444f12-784b-47b4-a80c-0ae53cf3b5a3@googlegroups.com> <57240856$0$1590$c3e8da3$5496439d@news.astraweb.com> <572413C9.2070405@stoneleaf.us> <1461982612.3299155.593966809.3D1A53FF@webmail.messagingengine.com> <41ec5af0-2ffa-4202-a5df-08f9660f7c57@googlegroups.com> <1461983791.3302675.593974129.5625C3C3@webmail.messagingengine.com> <85bn4rizf3.fsf@benfinney.id.au> <5724253e$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1461993611.3340362.594023513.1E745BA1@webmail.messagingengine.com> On Fri, Apr 29, 2016, at 23:23, Steven D'Aprano wrote: > Seriously, I'm thinking that a keyword argument to help might be useful: > > help(object, pager=None) I'd call it something more generic like "output". > where: > > - pager=None gives the current behaviour; > > - pager="foo" calls out to the external program "foo"; > > - pager=callable passes the help text to callable(). > > > pager=print would do exactly what people are asking for, and you could > then > create your own wrapper to change the default: > > help = functools.partial(builtins.help, pager=print) > > > I think that would make it easier to test help(). Thoughts? For testing purposes, help could return the result of the output function, so that you can use lambda x: x to have it return the help text. More general thoughts: It might also be useful to move the pager machinery from pydoc to an independent module. It's got, among other things, a simple pager written in pure python, for use as a fallback. There's a lot of stuff that could be improved in the pager stuff, while we're at it. Probably needs a single function to handle "use external program as a pager", rather than having a bunch of logic embedded in getpager() which only works for os.environ['PAGER']. The "pager" function doesn't behave "properly" (in its intended behavior of calling the expensive getpager() once when it is first called and subsequently reusing the cached value) if a reference to it is stored elsewhere (e.g. by importing it to another module); it should store the cached pager function somewhere else rather than by replacing itself. The pure-python pager only works on unix-style ttys, an analogous function could be written for windows using msvcrt.getwch. From greg.ewing at canterbury.ac.nz Sat Apr 30 01:47:40 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 30 Apr 2016 17:47:40 +1200 Subject: Not x.islower() has different output than x.isupper() in list output... In-Reply-To: References: <572407AE.1070703@icloud.com> <1461979797.3824480.593944273.0B8D8DF3@webmail.messagingengine.com> <57241097.7020801@icloud.com> Message-ID: Christopher Reimer wrote: > str.islower(): "Return true if all cased characters [4] in the string > are lowercase and there is at least one cased character, false otherwise." > > str.isupper(): "Return true if all cased characters [4] in the string > are uppercase and there is at least one cased character, false otherwise." A string consisting of a single space doesn't contain any cased characters, so both islower(" ") and isupper(" ") return false according to these rules. The docs are correct. -- Greg From rustompmody at gmail.com Sat Apr 30 02:37:22 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 29 Apr 2016 23:37:22 -0700 (PDT) Subject: manpage writing [rst, asciidoc, pod] was [Re: What should Python apps do when asked to show help?] In-Reply-To: <87y47vg2pk.fsf@nightsong.com> References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461865210.3218352.592571425.2069E4EB@webmail.messagingengine.com> <87a8kdshyh.fsf@elektro.pacujo.net> <1461873085.3251720.592695601.44633E5E@webmail.messagingengine.com> <5722bb82$0$1600$c3e8da3$5496439d@news.astraweb.com> <85r3dnj0j2.fsf@benfinney.id.au> <87y47vg2pk.fsf@nightsong.com> Message-ID: <8b19410d-aea7-492f-91a1-38beaab87228@googlegroups.com> On Saturday, April 30, 2016 at 9:36:42 AM UTC+5:30, Paul Rubin wrote: > Rustom Mody writes: > > As with all things rms, its taking him decades to realize this defeat > > [Latest makeinfo is 18 times slower than previous version!! > > https://lists.gnu.org/archive/html/bug-texinfo/2013-01/msg00012.html > > Wait, what's it written in now? Have you any data that its moved on? At that point what I gleaned was that original makeinfo was in C New one was rewritten in perl. [Yeah they could have taken a leaf out of pandoc -- written in haskell] From me at ixokai.io Sat Apr 30 02:43:24 2016 From: me at ixokai.io (Stephen Hansen) Date: Fri, 29 Apr 2016 23:43:24 -0700 Subject: Not x.islower() has different output than x.isupper() in list output... In-Reply-To: <57241097.7020801@icloud.com> References: <572407AE.1070703@icloud.com> <1461979797.3824480.593944273.0B8D8DF3@webmail.messagingengine.com> <57241097.7020801@icloud.com> Message-ID: <1461998604.3888861.594056577.710E696D@webmail.messagingengine.com> On Fri, Apr 29, 2016, at 06:55 PM, Christopher Reimer wrote: > On 4/29/2016 6:29 PM, Stephen Hansen wrote: > > If isupper/islower were perfect opposites of each-other, there'd be no > > need for both. But since characters can be upper, lower, or *neither*, > > you run into this situation. > > Based upon the official documentation, I was expecting perfect opposites. > > str.islower(): "Return true if all cased characters [4] in the string > are lowercase and there is at least one cased character, false > otherwise." The thing is, your use of filter is passing a string of 1 character long to your function, and so when it comes up against a string " ", there are no cased characters. Therefore, false. The documentation holds true. Your use of filter is breaking "Whiskey Tango Foxtrot" into ["W", "h", "i", ... "o" t"] and calling not x.islower() vs x.isupper() on each. When it comes up against " ", it doesn't pass the documented definition of what islower defines. The official documentation is accurate. -- Stephen Hansen m e @ i x o k a i . i o From andrea.gavana at gmail.com Sat Apr 30 03:04:52 2016 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Sat, 30 Apr 2016 09:04:52 +0200 Subject: Compiling extensions on Python 2.7, Windows 10 64 bit In-Reply-To: References: Message-ID: Hi, On Friday, 29 April 2016, Igor Korot wrote: > Andrea, > > On Fri, Apr 29, 2016 at 4:27 PM, Andrea Gavana > wrote: > > Hi, > > > > > > On Friday, 29 April 2016, Igor Korot > > wrote: > >> > >> Andrea, > >> > >> On Fri, Apr 29, 2016 at 3:45 PM, > wrote: > >> > Dear list, > >> > > >> > I have been trying to compile wxPython Phoenix > >> > (https://github.com/wxWidgets/Phoenix) from source on Windows 10 64 > bit, > >> > Python 2.7 64 bit, using the very handy Microsoft Visual C++ Compiler > for > >> > Python 2.7 ( > https://www.microsoft.com/en-us/download/details.aspx?id=44266). > >> > > >> > I started with Python 2.7.8, then wiped out that installation and used > >> > Python 2.7.11: cleaned the build directory, everything, and rebuilt > the > >> > Phoenix modules from scratch. > >> > > >> > Upon starting the Phoenix demo, I got the same error message I had > with > >> > Python 2.7.8: > >> > > >> > D:\MyProjects\Phoenix\demo>python Main.py > >> > > >> > Traceback (most recent call last): > >> > File "C:\Python27\lib\site-packages\wxPhoenix\wx\core.py", line > 1955, > >> > in Notify > >> > self.notify() > >> > File "C:\Python27\lib\site-packages\wxPhoenix\wx\core.py", line > 3034, > >> > in Notify > >> > self.result = self.callable(*self.args, **self.kwargs) > >> > File "Main.py", line 2601, in ShowMain > >> > frame = wxPythonDemo(None, "wxPython: (A Demonstration)") > >> > File "Main.py", line 1531, in __init__ > >> > self.SetOverview(self.overviewText, mainOverview) > >> > File "Main.py", line 2130, in SetOverview > >> > self.nb.SetPageText(0, os.path.split(name)[1]) > >> > SystemError: ..\Objects\longobject.c:998: bad argument to internal > >> > function > >> > > >> > The error message refers (apparently) to this Python bug: > >> > > >> > https://bugs.python.org/issue23842 > >> > > >> > But I assumed that it had been fixed waaaaay before 2.7.11. Now I am > >> > stuck and I have no idea on what to try next. > >> > > >> > Does anyone have suggestions/comments on where I should look for/what > I > >> > should do/what I should change in order to get the extension running > on > >> > Python 2.7? > >> > > >> > Thank you in advance for your suggestions :-) > >> > >> Did you try with python 3.x? > >> > >> IIUC, Phoenix should be made for python 3.x, and classic is for 2.7 > >> series. > >> > > > > > > No, Phoenix is meant to work on Python 2 and 3 at the same time. That's > the > > very reason it was created. > > But is it compiling with python 3.x? > Because the bug should be definitely fixed there. > This is not relevant to the question I have asked. I will be using it with Python 3 as well, but I would like to know if anybody has a suggestion on what I may be doing wrong on Python *2*, since I have many projects happily running with that version of Python. Andrea. -- From no.email at nospam.invalid Sat Apr 30 03:44:29 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 30 Apr 2016 00:44:29 -0700 Subject: manpage writing [rst, asciidoc, pod] was [Re: What should Python apps do when asked to show help?] References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461865210.3218352.592571425.2069E4EB@webmail.messagingengine.com> <87a8kdshyh.fsf@elektro.pacujo.net> <1461873085.3251720.592695601.44633E5E@webmail.messagingengine.com> <5722bb82$0$1600$c3e8da3$5496439d@news.astraweb.com> <85r3dnj0j2.fsf@benfinney.id.au> <87y47vg2pk.fsf@nightsong.com> <8b19410d-aea7-492f-91a1-38beaab87228@googlegroups.com> Message-ID: <87twijfsma.fsf@nightsong.com> Rustom Mody writes: > At that point what I gleaned was that original makeinfo was in C > New one was rewritten in perl. The previous one was definitely written in C and I've looked at the code some. I hadn't known there was a new one. The C one was actually the second one. The first one was written in Emacs Lisp but it was painfully slow on the hardware of that era. The C version was cumbersome by comparison. If they wanted to get rid of the C version now that the hardware is 100x faster or more, it's amusing that they did a Perl rewrite instead of reviving the Lisp version. Pandoc has a significant user base now though, and it looks like it also supports texinfo. So I wonder what the new Makeinfo does that pandoc doesn't. Maybe pandoc doesn't support Info? That could be added, I'm sure. From gordon at address.invalid Sat Apr 30 04:17:52 2016 From: gordon at address.invalid (Gordon Levi) Date: Sat, 30 Apr 2016 18:17:52 +1000 Subject: web facing static text db References: Message-ID: "Fetchinson ." wrote: >Hi folks, > >I have a very specific set of requirements for a task and was >wondering if anyone had good suggestions for the best set of tools: > >* store text documents (about 100000 pages) >* the data set is static (i.e. only lookups are performed, no delete, >no edit, no addition) >* only one operation required: lookup of pages by matching words in them >* very simple web frontend for querying the words to be matched >* no authentication or authorization, frontend completely public >* deployment at webfaction >* deadline: yesterday :) > >Which web framework and db engine would you recommend? > >So far I'm familiar with turbogears but would be willing to learn >anything if sufficiently basic since my needs are pretty basic (I >think). > What do need that storing the documents in HTML format and Google Custom Search does not provide ? From mal at europython.eu Sat Apr 30 06:02:12 2016 From: mal at europython.eu (M.-A. Lemburg) Date: Sat, 30 Apr 2016 12:02:12 +0200 Subject: EuroPython 2016: Extra Hot Topics - Call for Proposals Message-ID: <572482A4.2050606@europython.eu> The Program work group is happy to announce that there will be an extra Call for Proposals early in June. This call is limited to hot topics and most recent developments in software and technology. Why is there a second call ? ---------------------------- Planning a big conference is a challenge: On one hand people like to know what will be on our talk schedule to make up their mind and make travel arrangements early. On the other hand technology is progressing at the speed of light these days. So what?s the solution ? Attend anyway - EuroPython is always a great idea ! Seriously, we have given this some thought and decided to make another extra Call for Proposals just weeks before the conference. This CfP is strictly reserved for * hot topics * emerging technologies * brand new developments in software & hardware * recent results in research and science Some suggestions for topics: * Exciting new hardware & Internet of Things * Robotics * Virtual Reality * AI & Deep Learning This call will be open for nine days only: *** Saturday June 4th 0:00 to Sunday June 12th 24:00 CEST *** The program work group will select the most exciting and intriguing submissions and will notify the winners on short notice. With gravitational regards, -- EuroPython 2016 Team http://ep2016.europython.eu/ http://www.europython-society.org/ From zljubisic at gmail.com Sat Apr 30 09:07:00 2016 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Sat, 30 Apr 2016 06:07:00 -0700 (PDT) Subject: How to download a flash video from this site? In-Reply-To: References: <0c9d5a3b-ee58-49a6-973a-6125473fea06@googlegroups.com> Message-ID: On Friday, 29 April 2016 22:40:10 UTC+2, Chris Angelico wrote: > Since you're asking on this list, I'll assume you're using Beautiful > Soup and/or youtube-dl. You'll need to go into more detail about what > you're trying to do, and where the Python problem is. > > ChrisA The situation is very simple. I would like to use a beutifullsoap but I can't figure out how to get the filename that I could download. For example I opened the page https://hrti.hrt.hr/#/video/show/2203605/trebizat-prica-o-jednoj-vodi-i-jednom-narodu-dokumentarni-film in firefox and than from menu Tools > Web Developer > Network I found that there is a playlist on page https://prd-hrt.spectar.tv/player/get_smil/id/2203605/video_id/2203605/token/Cny6ga5VEQSJ2uZaD2G8pg/token_expiration/1462043309/asset_type/Movie/playlist_template/nginx/channel_name/trebiat__pria_o_jednoj_vodi_i_jednom_narodu_dokumentarni_film/playlist.m3u8?foo=bar in which chunks of video are listed like this: 01_1461582488.0329_000000.ts 01_1461582488.0329_000001.ts 01_1461582488.0329_000002.ts ... 01_1461582488.0329_000359.ts >From the m3u8 list I can get the first chunk by downloading the following: https://prd-hrt-vod.spectar.tv/OD/VoD/c2v_production_2201645/03_1461582488.0329_000000.ts My poblem is how to get from https://hrti.hrt.hr/#/video/show/2203605/trebizat-prica-o-jednoj-vodi-i-jednom-narodu-dokumentarni-film a m3u8 list? After getting the m3u8 list file, I will be able to download all chunks and record the video. Regards. From suabiut at gmail.com Sat Apr 30 12:44:15 2016 From: suabiut at gmail.com (sum abiut) Date: Sun, 1 May 2016 03:44:15 +1100 Subject: web facing static text db In-Reply-To: References: Message-ID: Django is an excellent framework. you can use it with sqlite. cheers On Sat, Apr 30, 2016 at 7:17 PM, Gordon Levi wrote: > "Fetchinson ." wrote: > > >Hi folks,go > > >I have a vo ery specific set of requirements for a task and was > >wondering if anyone had good suggestions for the best set of tools: > > > >* store text documents (about 100000 pages) > >* the data set is static (i.e. only lookups are performed, no delete, > >no edit, no addition) > >* only one operation required: lookup of pages by matching words in them > >* very simple web frontend for querying the words to be matched > >* no authentication or authorization, frontend completely public > >* deployment at webfaction > >* deadline: yesterday :) > > > >Which web framework and db engine would you recommend? > > > >So far I'm familiar with turbogears but would be willing to learn > >anything if sufficiently basic since my needs are pretty basic (I > >think). > > > > What do need that storing the documents in HTML format and Google > Custom Search does not provide > ? > -- > https://mail.python.org/mailman/listinfo/python-list > From christopher_reimer at icloud.com Sat Apr 30 12:48:15 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sat, 30 Apr 2016 09:48:15 -0700 Subject: Not x.islower() has different output than x.isupper() in list output... In-Reply-To: <1461998604.3888861.594056577.710E696D@webmail.messagingengine.com> References: <572407AE.1070703@icloud.com> <1461979797.3824480.593944273.0B8D8DF3@webmail.messagingengine.com> <57241097.7020801@icloud.com> <1461998604.3888861.594056577.710E696D@webmail.messagingengine.com> Message-ID: <5724E1CF.9060905@icloud.com> On 4/29/2016 11:43 PM, Stephen Hansen wrote: > The official documentation is accurate. That may be true on a technical level. But the identically worded text in the documentation implies otherwise. Maybe I'm nitpicking this. Even if I submitted a bug to request a clearer explanation in the documentation, I doubt it would get change. The programmer still has an obligation to test the code to make sure that it works as expected, which was what I did that until I found the concise statement that worked exactly as I wanted it to. Thank you, Chris R. From rosuav at gmail.com Sat Apr 30 13:00:02 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 May 2016 03:00:02 +1000 Subject: Not x.islower() has different output than x.isupper() in list output... In-Reply-To: <5724E1CF.9060905@icloud.com> References: <572407AE.1070703@icloud.com> <1461979797.3824480.593944273.0B8D8DF3@webmail.messagingengine.com> <57241097.7020801@icloud.com> <1461998604.3888861.594056577.710E696D@webmail.messagingengine.com> <5724E1CF.9060905@icloud.com> Message-ID: On Sun, May 1, 2016 at 2:48 AM, Christopher Reimer wrote: > On 4/29/2016 11:43 PM, Stephen Hansen wrote: >> >> The official documentation is accurate. > > > That may be true on a technical level. But the identically worded text in > the documentation implies otherwise. Maybe I'm nitpicking this. Even if I > submitted a bug to request a clearer explanation in the documentation, I > doubt it would get change. The programmer still has an obligation to test > the code to make sure that it works as expected, which was what I did that > until I found the concise statement that worked exactly as I wanted it to. Let's take it away from letter case and to something that everyone should be able to grok. isalpha(...) method of builtins.str instance S.isalpha() -> bool Return True if all characters in S are alphabetic and there is at least one character in S, False otherwise. isdigit(...) method of builtins.str instance S.isdigit() -> bool Return True if all characters in S are digits and there is at least one character in S, False otherwise. It should be pretty obvious that there are some strings which are neither alphabetic nor digits. Thus these two are not opposites, despite the identical wording in the docs. It's exactly the same with letter case. Some strings are neither uppercase nor lowercase, and thus they'll be False on both checks. ChrisA From me at ixokai.io Sat Apr 30 13:11:49 2016 From: me at ixokai.io (Stephen Hansen) Date: Sat, 30 Apr 2016 10:11:49 -0700 Subject: Not x.islower() has different output than x.isupper() in list output... In-Reply-To: <5724E1CF.9060905@icloud.com> References: <572407AE.1070703@icloud.com> <1461979797.3824480.593944273.0B8D8DF3@webmail.messagingengine.com> <57241097.7020801@icloud.com> <1461998604.3888861.594056577.710E696D@webmail.messagingengine.com> <5724E1CF.9060905@icloud.com> Message-ID: <1462036309.4005755.594329209.1106AF27@webmail.messagingengine.com> On Sat, Apr 30, 2016, at 09:48 AM, Christopher Reimer wrote: > On 4/29/2016 11:43 PM, Stephen Hansen wrote: > > The official documentation is accurate. > > That may be true on a technical level. But the identically worded text > in the documentation implies otherwise. That's the thing -- no it doesn't. The documentation is very specific: if all cased characters in the string are lowercase, and there's at least one cased character. It only seems to because you're packing a loop and test on substrings into an operation. list(filter((lambda x: not x.islower()), string)) Let's unpack that. This is basically what you're doing: result = [] for ch in string: if not ch.islower(): result.append(ch) You're thinking of the whole "string", but you're operating on single-character substrings, and when " ".islower() is run, its false. Because the two-pronged test, a) if all cased characters are lowercase and b) there is at least one cased character. b) is failing. Ergo, you're getting the underscores. -- Stephen Hansen m e @ i x o k a i . i o From fetchinson at googlemail.com Sat Apr 30 13:34:26 2016 From: fetchinson at googlemail.com (Fetchinson .) Date: Sat, 30 Apr 2016 19:34:26 +0200 Subject: web facing static text db In-Reply-To: References: Message-ID: On 4/30/16, Gordon Levi wrote: > "Fetchinson ." wrote: > >>Hi folks, >> >>I have a very specific set of requirements for a task and was >>wondering if anyone had good suggestions for the best set of tools: >> >>* store text documents (about 100000 pages) >>* the data set is static (i.e. only lookups are performed, no delete, >>no edit, no addition) >>* only one operation required: lookup of pages by matching words in them >>* very simple web frontend for querying the words to be matched >>* no authentication or authorization, frontend completely public >>* deployment at webfaction >>* deadline: yesterday :) >> >>Which web framework and db engine would you recommend? >> >>So far I'm familiar with turbogears but would be willing to learn >>anything if sufficiently basic since my needs are pretty basic (I >>think). >> > > What do need that storing the documents in HTML format and Google > Custom Search does not provide > ? Wow! Thanks, I was not aware of that, sounds exactly what I need. Thanks for all the other ideas too. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From christopher_reimer at icloud.com Sat Apr 30 13:36:19 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sat, 30 Apr 2016 10:36:19 -0700 Subject: Not x.islower() has different output than x.isupper() in list output... In-Reply-To: <1462036309.4005755.594329209.1106AF27@webmail.messagingengine.com> References: <572407AE.1070703@icloud.com> <1461979797.3824480.593944273.0B8D8DF3@webmail.messagingengine.com> <57241097.7020801@icloud.com> <1461998604.3888861.594056577.710E696D@webmail.messagingengine.com> <5724E1CF.9060905@icloud.com> <1462036309.4005755.594329209.1106AF27@webmail.messagingengine.com> Message-ID: <5724ED13.9070606@icloud.com> On 4/30/2016 10:11 AM, Stephen Hansen wrote: > You're thinking of the whole "string", but you're operating on > single-character substrings, and when " ".islower() is run, its false. > Because the two-pronged test, a) if all cased characters are lowercase > and b) there is at least one cased character. b) is failing. Ergo, > you're getting the underscores. I see where the problem lies in my thinking. I went looking for a single line solution for the whole string. If I had constructed a for loop and tried to reduce it to a single line, I *may* have understood the relationship between the different parts. Or maybe not. Blaming the documentation is a lot easier. ;) Thank you, Chris R. From fanjianling at gmail.com Sat Apr 30 14:13:51 2016 From: fanjianling at gmail.com (Jianling Fan) Date: Sat, 30 Apr 2016 12:13:51 -0600 Subject: about special characters In-Reply-To: <572403de$0$1601$c3e8da3$5496439d@news.astraweb.com> References: <572403de$0$1601$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hello everyone, Thanks very much for all your replies and sorry for the inconvience. This is my first time to post question in this list. I am using python 2.7 in Windows 7 Enterprise version. Here is the the filename that cause the problem: "Decock-2013-On the potential of ?18O and ?15N.pdf" When I delete the "?" in the filename, the script works good. Here is the output: Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> runfile('P:/sync.py', wdir='P:') Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile execfile(filename, namespace) File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc) File "P:/sync.py", line 50, in sync_files(src, dest) File "P:/sync.py", line 43, in sync_files sync(dir_cmp) File "P:/sync.py", line 20, in sync shutil.rmtree(f_right) File "C:\Python27\lib\shutil.py", line 236, in rmtree onerror(os.listdir, path, sys.exc_info()) File "C:\Python27\lib\shutil.py", line 234, in rmtree names = os.listdir(path) WindowsError: [Error 3] The system cannot find the path specified: 'P:/mystuff\\Decock-2013-On the potential of d18O and d15N.pdf/*.*' Here is my code to do this work: I am using this script to sync my files between different disks. #coding=utf-8 import filecmp, shutil, os, sys SRC = r'C:/Disk/mystuff' DEST = r'P:/mystuff' IGNORE = ['Thumbs.db'] def get_cmp_paths(dir_cmp, filenames): return ((os.path.join(dir_cmp.left, f), os.path.join(dir_cmp.right, f)) for f in filenames) def sync(dir_cmp): for f_left, f_right in get_cmp_paths(dir_cmp, dir_cmp.right_only): if os.path.isfile(f_right): os.remove(f_right) else: shutil.rmtree(f_right) print('delete %s' % f_right) for f_left, f_right in get_cmp_paths(dir_cmp, dir_cmp.left_only+dir_cmp.diff_files): if os.path.isfile(f_left): shutil.copy2(f_left, f_right) else: shutil.copytree(f_left, f_right) print('copy %s' % f_left) for sub_cmp_dir in dir_cmp.subdirs.values(): sync(sub_cmp_dir) def sync_files(src, dest, ignore=IGNORE): if not os.path.exists(src): print('= =b Please check the source directory was exist') print('- -b Sync file failure !!!') return if os.path.isfile(src): print('#_# We only support for sync directory but not a single file,one file please do it by yourself') print('- -b Sync file failure !!!') return if not os.path.exists(dest): os.makedirs(dest) dir_cmp = filecmp.dircmp(src, dest, ignore=IGNORE) sync(dir_cmp) print('^_^ Sync file finished!') if __name__ == '__main__': src, dest = SRC, DEST if len(sys.argv) == 3: src, dest = sys.argv[1:3] sync_files(src, dest) Thanks again! On 29 April 2016 at 19:01, Steven D'Aprano wrote: > On Sat, 30 Apr 2016 09:33 am, Jianling Fan wrote: > >> Hello everyone, >> >> I am trying to use python 27 copying some of my folders and files to >> another directory. >> My code works good for other files but I have some problem to copy >> files that have some special characters in the filename. like >> filenames contain Greek "?" or latin "?". >> it always gave a error that "No such file or directory:" >> >> Any help will be appreciate! > > Please put yourself in our shoes. Read your message above, and, imagine that > you know NOTHING else about your program than what you write above. What > answer would you give? > > Please tell us what you have actually done. How do you copy the files? How > do you enter the file names? What OS are you using? > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list -- Jianling Fan ??? From tjreedy at udel.edu Sat Apr 30 15:36:06 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 30 Apr 2016 15:36:06 -0400 Subject: about special characters In-Reply-To: References: <572403de$0$1601$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/30/2016 2:13 PM, Jianling Fan wrote: > I am using python 2.7 in Windows 7 Enterprise version. > > Here is the the filename that cause the problem: "Decock-2013-On the > potential of ?18O and ?15N.pdf" > When I delete the "?" in the filename, the script works good. You may be able to get "?" (and other Greek characters) to work on your system with 2.7, but if you want to be able to work with any filename on Windows, get Python 3.4 or later and use text strings, not byte strings. You may someday run into a Name-your-title.pdf file name with other 'strange' characters from other Windows filenames are unicode strings and are stored, I believe, with utf-16 encoding. Even in early 3.x versions, there were Windows path problems, for instance with east Asian characters. Multiple 3.x patches seem to have fixed the problems. So merely using unicode is not, in general, sufficient. -- Terry Jan Reedy From python at mrabarnett.plus.com Sat Apr 30 15:42:16 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 30 Apr 2016 20:42:16 +0100 Subject: about special characters In-Reply-To: References: <572403de$0$1601$c3e8da3$5496439d@news.astraweb.com> Message-ID: <142f82f4-b266-3b85-f606-e1b6d3246021@mrabarnett.plus.com> On 2016-04-30 19:13, Jianling Fan wrote: > Hello everyone, > > Thanks very much for all your replies and sorry for the inconvience. > This is my first time to post question in this list. > > I am using python 2.7 in Windows 7 Enterprise version. > > Here is the the filename that cause the problem: "Decock-2013-On the > potential of ?18O and ?15N.pdf" > When I delete the "?" in the filename, the script works good. > > Here is the output: > > Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> runfile('P:/sync.py', wdir='P:') > Traceback (most recent call last): > File "", line 1, in > File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", > line 699, in runfile > execfile(filename, namespace) > File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", > line 74, in execfile > exec(compile(scripttext, filename, 'exec'), glob, loc) > File "P:/sync.py", line 50, in > sync_files(src, dest) > File "P:/sync.py", line 43, in sync_files > sync(dir_cmp) > File "P:/sync.py", line 20, in sync > shutil.rmtree(f_right) > File "C:\Python27\lib\shutil.py", line 236, in rmtree > onerror(os.listdir, path, sys.exc_info()) > File "C:\Python27\lib\shutil.py", line 234, in rmtree > names = os.listdir(path) > WindowsError: [Error 3] The system cannot find the path specified: > 'P:/mystuff\\Decock-2013-On the potential of d18O and d15N.pdf/*.*' > > > Here is my code to do this work: I am using this script to sync my > files between different disks. > > #coding=utf-8 > > import filecmp, shutil, os, sys > > SRC = r'C:/Disk/mystuff' > DEST = r'P:/mystuff' > > IGNORE = ['Thumbs.db'] > > def get_cmp_paths(dir_cmp, filenames): > return ((os.path.join(dir_cmp.left, f), > os.path.join(dir_cmp.right, f)) for f in filenames) > > def sync(dir_cmp): > for f_left, f_right in get_cmp_paths(dir_cmp, dir_cmp.right_only): > if os.path.isfile(f_right): > os.remove(f_right) > else: > shutil.rmtree(f_right) > print('delete %s' % f_right) > for f_left, f_right in get_cmp_paths(dir_cmp, > dir_cmp.left_only+dir_cmp.diff_files): > if os.path.isfile(f_left): > shutil.copy2(f_left, f_right) > else: > shutil.copytree(f_left, f_right) > print('copy %s' % f_left) > for sub_cmp_dir in dir_cmp.subdirs.values(): > sync(sub_cmp_dir) > > def sync_files(src, dest, ignore=IGNORE): > if not os.path.exists(src): > print('= =b Please check the source directory was exist') > print('- -b Sync file failure !!!') > return > if os.path.isfile(src): > print('#_# We only support for sync directory but not a single > file,one file please do it by yourself') > print('- -b Sync file failure !!!') > return > if not os.path.exists(dest): > os.makedirs(dest) > dir_cmp = filecmp.dircmp(src, dest, ignore=IGNORE) > sync(dir_cmp) > print('^_^ Sync file finished!') > > if __name__ == '__main__': > src, dest = SRC, DEST > if len(sys.argv) == 3: > src, dest = sys.argv[1:3] > sync_files(src, dest) > [snip] You're using bytestrings (str). As soon as you step out of the ASCII range, you can face problems with which encoding it's using. The simplest fix is to switch to using Unicode. Start with this change: SRC = ur'C:/Disk/mystuff' DEST = ur'P:/mystuff' From fanjianling at gmail.com Sat Apr 30 15:48:05 2016 From: fanjianling at gmail.com (Jianling Fan) Date: Sat, 30 Apr 2016 13:48:05 -0600 Subject: about special characters In-Reply-To: <142f82f4-b266-3b85-f606-e1b6d3246021@mrabarnett.plus.com> References: <572403de$0$1601$c3e8da3$5496439d@news.astraweb.com> <142f82f4-b266-3b85-f606-e1b6d3246021@mrabarnett.plus.com> Message-ID: Oh, it works! This is the simplest and best way! Thanks very much! On 30 April 2016 at 13:42, MRAB wrote: > On 2016-04-30 19:13, Jianling Fan wrote: >> >> Hello everyone, >> >> Thanks very much for all your replies and sorry for the inconvience. >> This is my first time to post question in this list. >> >> I am using python 2.7 in Windows 7 Enterprise version. >> >> Here is the the filename that cause the problem: "Decock-2013-On the >> potential of ?18O and ?15N.pdf" >> When I delete the "?" in the filename, the script works good. >> >> Here is the output: >> >> Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit >> (Intel)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> >>>>> runfile('P:/sync.py', wdir='P:') >> >> Traceback (most recent call last): >> File "", line 1, in >> File >> "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", >> line 699, in runfile >> execfile(filename, namespace) >> File >> "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", >> line 74, in execfile >> exec(compile(scripttext, filename, 'exec'), glob, loc) >> File "P:/sync.py", line 50, in >> sync_files(src, dest) >> File "P:/sync.py", line 43, in sync_files >> sync(dir_cmp) >> File "P:/sync.py", line 20, in sync >> shutil.rmtree(f_right) >> File "C:\Python27\lib\shutil.py", line 236, in rmtree >> onerror(os.listdir, path, sys.exc_info()) >> File "C:\Python27\lib\shutil.py", line 234, in rmtree >> names = os.listdir(path) >> WindowsError: [Error 3] The system cannot find the path specified: >> 'P:/mystuff\\Decock-2013-On the potential of d18O and d15N.pdf/*.*' >> >> >> Here is my code to do this work: I am using this script to sync my >> files between different disks. >> >> #coding=utf-8 >> >> import filecmp, shutil, os, sys >> >> SRC = r'C:/Disk/mystuff' >> DEST = r'P:/mystuff' >> >> IGNORE = ['Thumbs.db'] >> >> def get_cmp_paths(dir_cmp, filenames): >> return ((os.path.join(dir_cmp.left, f), >> os.path.join(dir_cmp.right, f)) for f in filenames) >> >> def sync(dir_cmp): >> for f_left, f_right in get_cmp_paths(dir_cmp, dir_cmp.right_only): >> if os.path.isfile(f_right): >> os.remove(f_right) >> else: >> shutil.rmtree(f_right) >> print('delete %s' % f_right) >> for f_left, f_right in get_cmp_paths(dir_cmp, >> dir_cmp.left_only+dir_cmp.diff_files): >> if os.path.isfile(f_left): >> shutil.copy2(f_left, f_right) >> else: >> shutil.copytree(f_left, f_right) >> print('copy %s' % f_left) >> for sub_cmp_dir in dir_cmp.subdirs.values(): >> sync(sub_cmp_dir) >> >> def sync_files(src, dest, ignore=IGNORE): >> if not os.path.exists(src): >> print('= =b Please check the source directory was exist') >> print('- -b Sync file failure !!!') >> return >> if os.path.isfile(src): >> print('#_# We only support for sync directory but not a single >> file,one file please do it by yourself') >> print('- -b Sync file failure !!!') >> return >> if not os.path.exists(dest): >> os.makedirs(dest) >> dir_cmp = filecmp.dircmp(src, dest, ignore=IGNORE) >> sync(dir_cmp) >> print('^_^ Sync file finished!') >> >> if __name__ == '__main__': >> src, dest = SRC, DEST >> if len(sys.argv) == 3: >> src, dest = sys.argv[1:3] >> sync_files(src, dest) >> > [snip] > You're using bytestrings (str). As soon as you step out of the ASCII > range, you can face problems with which encoding it's using. > > The simplest fix is to switch to using Unicode. > > Start with this change: > > SRC = ur'C:/Disk/mystuff' > DEST = ur'P:/mystuff' > > -- > https://mail.python.org/mailman/listinfo/python-list -- Jianling Fan ??? From davidgshi at yahoo.co.uk Sat Apr 30 16:40:31 2016 From: davidgshi at yahoo.co.uk (David Shi) Date: Sat, 30 Apr 2016 20:40:31 +0000 (UTC) Subject: How to fill in abbreviation in one column based on state name in another column? References: <225454564.8325693.1462048831951.JavaMail.yahoo.ref@mail.yahoo.com> Message-ID: <225454564.8325693.1462048831951.JavaMail.yahoo@mail.yahoo.com> I am trying to use apply to execute a lookup function, so that we can put abbreviation in a new column, in accordance to a state name in another column. Does anyone knows how to make this to work? Regards. David state_to_code = {"VERMONT": "VT", "GEORGIA": "GA", "IOWA": "IA", "Armed Forces Pacific": "AP", "GUAM": "GU",? ? ? ? ? ? ? ? ?"KANSAS": "KS", "FLORIDA": "FL", "AMERICAN SAMOA": "AS", "NORTH CAROLINA": "NC", "HAWAII": "HI",? ? ? ? ? ? ? ? ?"NEW YORK": "NY", "CALIFORNIA": "CA", "ALABAMA": "AL", "IDAHO": "ID", "FEDERATED STATES OF MICRONESIA": "FM",? ? ? ? ? ? ? ? ?"Armed Forces Americas": "AA", "DELAWARE": "DE", "ALASKA": "AK", "ILLINOIS": "IL",? ? ? ? ? ? ? ? ?"Armed Forces Africa": "AE", "SOUTH DAKOTA": "SD", "CONNECTICUT": "CT", "MONTANA": "MT", "MASSACHUSETTS": "MA",? ? ? ? ? ? ? ? ?"PUERTO RICO": "PR", "Armed Forces Canada": "AE", "NEW HAMPSHIRE": "NH", "MARYLAND": "MD", "NEW MEXICO": "NM",? ? ? ? ? ? ? ? ?"MISSISSIPPI": "MS", "TENNESSEE": "TN", "PALAU": "PW", "COLORADO": "CO", "Armed Forces Middle East": "AE",? ? ? ? ? ? ? ? ?"NEW JERSEY": "NJ", "UTAH": "UT", "MICHIGAN": "MI", "WEST VIRGINIA": "WV", "WASHINGTON": "WA",? ? ? ? ? ? ? ? ?"MINNESOTA": "MN", "OREGON": "OR", "VIRGINIA": "VA", "VIRGIN ISLANDS": "VI", "MARSHALL ISLANDS": "MH",? ? ? ? ? ? ? ? ?"WYOMING": "WY", "OHIO": "OH", "SOUTH CAROLINA": "SC", "INDIANA": "IN", "NEVADA": "NV", "LOUISIANA": "LA",? ? ? ? ? ? ? ? ?"NORTHERN MARIANA ISLANDS": "MP", "NEBRASKA": "NE", "ARIZONA": "AZ", "WISCONSIN": "WI", "NORTH DAKOTA": "ND",? ? ? ? ? ? ? ? ?"Armed Forces Europe": "AE", "PENNSYLVANIA": "PA", "OKLAHOMA": "OK", "KENTUCKY": "KY", "RHODE ISLAND": "RI",? ? ? ? ? ? ? ? ?"DISTRICT OF COLUMBIA": "DC", "ARKANSAS": "AR", "MISSOURI": "MO", "TEXAS": "TX", "MAINE": "ME"} #table['moa_state_name'] = map(lambda x: x.upper(), table['moa_state_name'])def convert_state(row):? ? abbrev1 = ?state_to_code(table['moa_state_name']) #'aatest'? ? if abbrev1:? ? ? ? ?return abbrev1 ##state_to_code[abbrev[0]]? ? return np.nan#print convert_state(table['moa_state_name']) table.insert(0, "abbrev", np.nan)table['abbrev'] = table.apply(convert_state, axis=1) print state_to_code['ARKANSAS'] From joel.goldstick at gmail.com Sat Apr 30 16:49:50 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 30 Apr 2016 16:49:50 -0400 Subject: How to fill in abbreviation in one column based on state name in another column? In-Reply-To: <225454564.8325693.1462048831951.JavaMail.yahoo@mail.yahoo.com> References: <225454564.8325693.1462048831951.JavaMail.yahoo.ref@mail.yahoo.com> <225454564.8325693.1462048831951.JavaMail.yahoo@mail.yahoo.com> Message-ID: could you post in plaintext as its really hard to figure out what your code is doing On Sat, Apr 30, 2016 at 4:40 PM, David Shi via Python-list wrote: > I am trying to use apply to execute a lookup function, so that we can put abbreviation in a new column, in accordance to a state name in another column. > Does anyone knows how to make this to work? > Regards. > David > state_to_code = {"VERMONT": "VT", "GEORGIA": "GA", "IOWA": "IA", "Armed Forces Pacific": "AP", "GUAM": "GU", "KANSAS": "KS", "FLORIDA": "FL", "AMERICAN SAMOA": "AS", "NORTH CAROLINA": "NC", "HAWAII": "HI", "NEW YORK": "NY", "CALIFORNIA": "CA", "ALABAMA": "AL", "IDAHO": "ID", "FEDERATED STATES OF MICRONESIA": "FM", "Armed Forces Americas": "AA", "DELAWARE": "DE", "ALASKA": "AK", "ILLINOIS": "IL", "Armed Forces Africa": "AE", "SOUTH DAKOTA": "SD", "CONNECTICUT": "CT", "MONTANA": "MT", "MASSACHUSETTS": "MA", "PUERTO RICO": "PR", "Armed Forces Canada": "AE", "NEW HAMPSHIRE": "NH", "MARYLAND": "MD", "NEW MEXICO": "NM", "MISSISSIPPI": "MS", "TENNESSEE": "TN", "PALAU": "PW", "COLORADO": "CO", "Armed Forces Middle East": "AE", "NEW JERSEY": "NJ", "UTAH": "UT", "MICHIGAN": "MI", "WEST VIRGINIA": "WV", "WASHINGTON": "WA", "MINNESOTA": "MN", "OREGON": "OR", "VIRGINIA": "VA", "VIRGIN ISLANDS": "VI", "MARSHALL ISLANDS": "MH", "WYOMING": "WY", "OHIO": "OH", "SOUTH CAROLINA": "SC", "INDIANA": "IN", "NEVADA": "NV", "LOUISIANA": "LA", "NORTHERN MARIANA ISLANDS": "MP", "NEBRASKA": "NE", "ARIZONA": "AZ", "WISCONSIN": "WI", "NORTH DAKOTA": "ND", "Armed Forces Europe": "AE", "PENNSYLVANIA": "PA", "OKLAHOMA": "OK", "KENTUCKY": "KY", "RHODE ISLAND": "RI", "DISTRICT OF COLUMBIA": "DC", "ARKANSAS": "AR", "MISSOURI": "MO", "TEXAS": "TX", "MAINE": "ME"} > #table['moa_state_name'] = map(lambda x: x.upper(), table['moa_state_name'])def convert_state(row): abbrev1 = state_to_code(table['moa_state_name']) #'aatest' if abbrev1: return abbrev1 ##state_to_code[abbrev[0]] return np.nan#print convert_state(table['moa_state_name']) > table.insert(0, "abbrev", np.nan)table['abbrev'] = table.apply(convert_state, axis=1) > print state_to_code['ARKANSAS'] > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From bgailer at gmail.com Sat Apr 30 17:11:54 2016 From: bgailer at gmail.com (Bob Gailer) Date: Sat, 30 Apr 2016 17:11:54 -0400 Subject: How to fill in abbreviation in one column based on state name in another column? In-Reply-To: References: <225454564.8325693.1462048831951.JavaMail.yahoo.ref@mail.yahoo.com> <225454564.8325693.1462048831951.JavaMail.yahoo@mail.yahoo.com> Message-ID: 1) Your code seems to be missing a lot. 2) it's better to post a small sample of the dictionary rather than the whole thing. 3) remove the comments that don't seem to say anything useful. 4) tell us what problems you are having From cs at zip.com.au Sat Apr 30 19:51:32 2016 From: cs at zip.com.au (cs at zip.com.au) Date: Sun, 1 May 2016 09:51:32 +1000 Subject: What should Python apps do when asked to show help? In-Reply-To: <5724253e$0$22142$c3e8da3$5496439d@news.astraweb.com> References: <5724253e$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20160430235132.GA83556@cskk.homeip.net> On 30Apr2016 13:23, Steven D'Aprano wrote: >On Sat, 30 Apr 2016 12:49 pm, Ben Finney wrote: >> Random832 writes: >>> On Fri, Apr 29, 2016, at 22:27, Rustom Mody wrote: >>> > Instead it does some ?-assed fall-between-the-stools of both >>> >>> That doesn't answer the question of why, if you (Well, Ethan, but >>> you're taking the same position here) hate pagers so much >> >> That's not a question relevant here; nobody inthe discussion has a >> position fairly characterised as ?hate pagers so much?. So you're >> arguing against a straw man. >> >> Rather, the position being argued is that they *do* like pagers; they >> like pagers enough that they want the existing ?PAGER? environment >> variable setting to remain untouched. > >So they want the PAGER environment variable to specify what pager they >want... _When_ they want a pager. >> And, simulatenously, they want >> Python's help to not use a pager at the interactive prompt. > >...so long as applications don't actually make use of that PAGER environment >variable to determine the pager they want to use. _When_ it is asked to use a pager. What they (and, very often, me) want is that most things, including pydoc, to _NOT_ invoke a pager automatically, _unasked_. So tools which page without asking are unwelcome, because that requires a mode switch when everything else (sed/grep/print/write/ls) do straight up unpaged output. >(1) If you want man, and nothing else in the universe, to automatically use >a pager, then set MANPAGER="less" (or whatever you wish to use), and unset >PAGER. > >(2) If you don't want *anything* to use a pager, then unset both MANPAGER >and PAGER. You may have to report a feature request / bug report for >applications which force their own pager. > >(3) In Python specifically, you can trivially and easily tell help() to >output directly to stdout. (At least on Linux, I haven't tested it >elsewhere.) Simply use PAGER=cat on the command line you use to launch the >interactive environment. This will affect no other running or future >processes (apart from subprocesses launched from your interactive Python >session), allowing you to keep your PAGER for everything else. > >(4) If you want more than that, then patches are welcome :-) This requires terrible domain specific knowledge. What about programs other than man? And setting PAGER=cat before invoking interactive python is no better, because it will screw with $PAGER in any subprocess spawned from that environment. What those of use in the "my terminal emulator scrolls nicely thank you" camp want is that most command line things, when asked to simply print some help text, _print_ it and do not page it. And often would like a way to tell pydoc to not page, such as a pydoc specific switch (possibly an environment variable). >Seriously, I'm thinking that a keyword argument to help might be useful: > >help(object, pager=None) > >where: >- pager=None gives the current behaviour; >- pager="foo" calls out to the external program "foo"; >- pager=callable passes the help text to callable(). I'd be asking for pager=None to look at help.default_pager, which itself might obey your rules above. That way help.default_pager can be a callable which consults $PAGER or falls back to some inbuilt pager (presumably as now), but which a user can sumply go: help.default_pager=None at the Python prompt and have unpaged output from there on. >I think that would make it easier to test help(). Thoughts? Yes it would. I'm +1 _provided_ the user can set a global to tune the default mode, as otherwise it burdens the user with saying: help(foo, stdout.write) # or "print" ? whenever they want help. Not helpful! Let me recite one of my favourite rules of thumb: If it can't be turned off, it's not a feature. - Karl Heuer Cheers, Cameron Simpson From cs at zip.com.au Sat Apr 30 20:06:28 2016 From: cs at zip.com.au (cs at zip.com.au) Date: Sun, 1 May 2016 10:06:28 +1000 Subject: What should Python apps do when asked to show help? In-Reply-To: <5722bb82$0$1600$c3e8da3$5496439d@news.astraweb.com> References: <5722bb82$0$1600$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20160501000628.GA56167@cskk.homeip.net> On 29Apr2016 11:40, Steven D'Aprano wrote: >On Fri, 29 Apr 2016 07:08 am, Grant Edwards wrote: >> On 2016-04-28, Random832 wrote: >>> On Thu, Apr 28, 2016, at 15:39, Grant Edwards wrote: >>>> That's fine. If you want two or three forms of documentation then you >>>> prepare two or three forms of documentation. >>>> >>>> Adding an option to run the default 'help' output through a pager or >>>> display it in a web browser doesn't somehow force you "to compose two >>>> forms of documentation" unless you want two forms of documentation. >>> >>> The point is that having "help" output at all (beyond either a cursory >>> "see the manpage") implies two forms of documentation (given you already >>> have a manpage), and some people choose not to do that, instead >>> launching directly into the manpage (which implies using a pager) >> >> But I'm saying that having --help output the manpage should not imply >> using a pager. > > >What manpage? I don't have a manpage. The only help my application has is >whatever it outputs (which it gets from its docstring). > >What is a good place where I can find out more about writing manpages? "man 5 man"? Describes the internal format of man pages (the [ntg]roff -man macro set). Many people use an intermediate more human friendly format and use a tool to transcribe -man format text. For standalone things I find Perl's "POD" format fairly easy to use (the pod2man tool itself does have shortcomings though). >> If --help is going to output the manpage, then I'm saying it can (and >> should) be written to stdout without use of pager (and it shouldn't >> have escape sequences or backspaces in it either). The Unix way is >> that the output from whatever --help should be plain text written to >> stdout (regardless of length). > >Agree. The -h/--help option will output plain text to stdout. Yay. >> If you want to output the man page, this can be accomplished simply by >> doing someting like: >> os.environ["GROFF_NO_SGR"] = "1"; >> os.system("man -Tascii mycmd | col -bx"); > >That doesn't work for me: >[steve at ando ~]$ man -Tasciii rm >man: invalid option -- T Yes, it is nonportable. Presumes groff possibly, and GNU "man". >However, this almost works: > >man -Pcat rm > >appears to output unformatted, plain text to stdout. As should: man rm | cat without obscure options. >However, if you capture >the output (say, to a file) you'll see it is full of backspaces, e.g.: > >N^HNA^HAM^HME^HE > rm - remove files or directories > >S^HSY^HYN^HNO^HOP^HPS^HSI^HIS^HS > r^Hrm^Hm [_^HO_^HP_^HT_^HI_^HO_^HN]... _^HF_^HI_^HL_^HE... Yes. >instead of > >NAME > rm - remove files or directories [...] > >Apparently `less` understands overstriking and displays it as bold (or >underlining in the case of _^H. That's very clever, but how do I get actual >plain text out of `man` without the backspaces? That is what Grant Edwards' "col -bx" does. (Actually, col can do more, because tables also do funky things; let us not go there.) But removing the overstriking is pretty easy even without col. My "unbs" script does it, and its core operation is this: s/[^^H]^H//g Those ^Hs are literal backspace characters: remove any non-backspace followed by a backspace. Full script here: https://bitbucket.org/cameron_simpson/css/src/tip/bin/unbs >> If I want the --help output run through a pager, I'll do it myself. > >Easy enough to say for Linux/Unix users, but there are those who might not >have a pager that is easy to use, or at all. pydoc goes to considerable >trouble to work out the best pager available for your platform, falling >back to its own if needed. To use that is literally a two liner: > >import pydoc >pydoc.pager(HELPTEXT) Aye, but what is wanted by some of us is an easy incantation to tune that to plain old sys.stdout.write in some flavour. Cheers, Cameron Simpson From random832 at fastmail.com Sat Apr 30 20:41:51 2016 From: random832 at fastmail.com (Random832) Date: Sat, 30 Apr 2016 20:41:51 -0400 Subject: What should Python apps do when asked to show help? In-Reply-To: <20160430235132.GA83556@cskk.homeip.net> References: <5724253e$0$22142$c3e8da3$5496439d@news.astraweb.com> <20160430235132.GA83556@cskk.homeip.net> Message-ID: <1462063311.237252.594520729.52D9D362@webmail.messagingengine.com> On Sat, Apr 30, 2016, at 19:51, cs at zip.com.au wrote: > _When_ they want a pager. Why would they need an environment variable at all in that case, rather than explicitly invoking the pager by name? To me, *not* having PAGER=cat signifies that someone *does* want a pager. That may be a crappy convention, but it's the one we're stuck with. > And setting PAGER=cat before invoking interactive python is no better, > because > it will screw with $PAGER in any subprocess spawned from that > environment. But why would you not *also* want PAGER=cat in those subprocesses? You don't want those things to spawn pagers that you haven't asked explicitly for, either, right? I don't get the "It's terrible if I run man or git it won't open a pager, but I don't want pydoc to use a pager" viewpoint. It just doesn't make any sense to me. > Let me recite one of my favourite rules of thumb: > > If it can't be turned off, it's not a feature. - Karl Heuer You turn it off by setting PAGER=cat. The fact that pydoc uses a pager is the *same* feature as the fact that git and man do. From grant.b.edwards at gmail.com Sat Apr 30 22:30:40 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 1 May 2016 02:30:40 +0000 (UTC) Subject: What should Python apps do when asked to show help? References: <5724253e$0$22142$c3e8da3$5496439d@news.astraweb.com> <20160430235132.GA83556@cskk.homeip.net> <1462063311.237252.594520729.52D9D362@webmail.messagingengine.com> Message-ID: On 2016-05-01, Random832 wrote: > On Sat, Apr 30, 2016, at 19:51, cs at zip.com.au wrote: >> _When_ they want a pager. > > Why would they need an environment variable at all in that case, rather > than explicitly invoking the pager by name? We don't want to use a PAGER variable to specify when we want a pager and when we don't want a pager. If we want a pager we append "| less" to the command. If we don't want a pager, we don't append that to the command. For historical reasons, "man" invokes a pager by default. I'm not crazy about that. If you want to argue that it's being inconsistent then you're right: man shouldn't invoke a pager either. -- Grant From random832 at fastmail.com Sat Apr 30 23:46:28 2016 From: random832 at fastmail.com (Random832) Date: Sat, 30 Apr 2016 23:46:28 -0400 Subject: What should Python apps do when asked to show help? In-Reply-To: References: <5724253e$0$22142$c3e8da3$5496439d@news.astraweb.com> <20160430235132.GA83556@cskk.homeip.net> <1462063311.237252.594520729.52D9D362@webmail.messagingengine.com> Message-ID: <1462074388.273747.594588777.5E705539@webmail.messagingengine.com> On Sat, Apr 30, 2016, at 22:30, Grant Edwards wrote: > We don't want to use a PAGER variable to specify when we want a pager > and when we don't want a pager. If we want a pager we append "| less" > to the command. If we don't want a pager, we don't append that to the > command. Setting PAGER=cat - permanently, in your profile, and never ever changing it - gives this result, yet it's described by some people here as "So I have to cripple my shell [...]?" What is crippled? Evidently you're not "we", since this "crippled" state of affairs seems to be a perfectly acceptable one to you.