From cs at zip.com.au Fri Jan 1 01:30:43 2016 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 1 Jan 2016 17:30:43 +1100 Subject: Newbie: Check first two non-whitespace characters In-Reply-To: <56857609.9080603@mrabarnett.plus.com> References: <56857609.9080603@mrabarnett.plus.com> Message-ID: <20160101063043.GA11672@cskk.homeip.net> On 31Dec2015 18:38, MRAB wrote: >On 2015-12-31 18:18, otaksoftspamtrap at gmail.com wrote: >>I need to check a string over which I have no control for the first 2 non-white space characters (which should be '[{'). >> >>The string would ideally be: '[{...' but could also be something like >>' [ { ....'. >> >>Best to use re and how? Something else? >> >I would use .split and then ''.join: > >>>> ''.join(' [ { ....'.split()) >'[{....' This presumes it is ok to drop/mangle/lose the whitespace elsewhere in the string. If it contains quoted text I'd expect that to be very bad. >It might be faster if you provide a maximum for the number of splits: >>>> ''.join(' [ { ....'.split(None, 1)) >'[{ ....' Not to mention safer. I would use lstrip and startswith: s = lstrip(s) if s.startswith('['): s = s[1:].lstrip() if s.startswith('{'): ... deal with s[1:] here ... It is wordier, but far more basic and direct. Cheers, Cameron Simpson From besimms at gmail.com Fri Jan 1 01:43:37 2016 From: besimms at gmail.com (Brian Simms) Date: Thu, 31 Dec 2015 22:43:37 -0800 (PST) Subject: Converting py files to .exe and .dmg In-Reply-To: References: <9b206057-0593-4560-af40-442d03111770@googlegroups.com> Message-ID: On Tuesday, 29 December 2015 01:09:30 UTC+9, Adam M wrote: > On Monday, December 28, 2015 at 10:35:41 AM UTC-5, Brian Simms wrote: > > Hi there, > > > > I have done a lot of looking around online to find out how to convert Python files to .exe and .dmg files, but I am confused. Could someone provide pointers/advice as to how I can turn a Python file into a Windows .exe and Mac .dmg file. > > > > Thanks for any help. > > Please check this website: > http://www.pyinstaller.org/ > It should solve your problem. Hi Adam M, I went to www.pyinstaller.org and downloaded the software. I don;t know if you are using Windows or Mac. I have a Mac and when I go into Terminal to run "setup.py install" I keep getting "-bash: command not found". I have read the manual and done what it suggested, but still no joy. I have MacPorts (which I downloaded several days ago. If you could provide any pointers as to how I could run the "setup.py" on my Mac, it would be hugely appreciated. Thanks. :-) From motoom at xs4all.nl Fri Jan 1 03:11:22 2016 From: motoom at xs4all.nl (Michiel Overtoom) Date: Fri, 1 Jan 2016 09:11:22 +0100 Subject: Converting py files to .exe and .dmg In-Reply-To: References: <9b206057-0593-4560-af40-442d03111770@googlegroups.com> Message-ID: <388DDFF7-4094-4998-8CEC-B7A29C01ED78@xs4all.nl> > On 2016-01-01, at 07:43, Brian Simms wrote: > > when I go into Terminal to run "setup.py install" I keep getting "-bash: command not found". Try: python setup.py install Greetings, From harvesting at is.invalid Fri Jan 1 03:16:29 2016 From: harvesting at is.invalid (Jussi Piitulainen) Date: Fri, 01 Jan 2016 10:16:29 +0200 Subject: Newbie: Check first two non-whitespace characters References: <240ab049-68a0-4a00-b911-d58cae9bfbcf@googlegroups.com> Message-ID: otaksoftspamtrap at gmail.com writes: > I need to check a string over which I have no control for the first 2 > non-white space characters (which should be '[{'). > > The string would ideally be: '[{...' but could also be something like > ' [ { ....'. > > Best to use re and how? Something else? No comment on whether re is good for your use case but another comment on how. First, some test data: >>> data = '\r\n {\r\n\t[ "etc" ]}\n\n\n') Then the actual comment - there's a special regex type, \S, to match a non-whitespace character, and a method to produce matches on demand: >>> black = re.compile(r'\S') >>> matches = re.finditer(black, data) Then the demonstration. This accesses the first, then second, then third match: >>> empty = re.match('', '') >>> next(matches, empty).group() '{' >>> next(matches, empty).group() '[' >>> next(matches, empty).group() '"' The empty match object provides an appropriate .group() when there is no first or second (and so on) non-whitespace character in the data: >>> matches = re.finditer(black, '\r\t\n') >>> next(matches, empty).group() '' >>> next(matches, empty).group() '' From kliateni at gmail.com Fri Jan 1 04:43:39 2016 From: kliateni at gmail.com (Karim) Date: Fri, 1 Jan 2016 10:43:39 +0100 Subject: Newbie: Check first two non-whitespace characters In-Reply-To: References: <240ab049-68a0-4a00-b911-d58cae9bfbcf@googlegroups.com> <568579DF.50805@gmail.com> Message-ID: <56864A4B.1090704@gmail.com> On 01/01/2016 00:25, Mark Lawrence wrote: > On 31/12/2015 18:54, Karim wrote: >> >> >> On 31/12/2015 19:18, otaksoftspamtrap at gmail.com wrote: >>> I need to check a string over which I have no control for the first 2 >>> non-white space characters (which should be '[{'). >>> >>> The string would ideally be: '[{...' but could also be something like >>> ' [ { ....'. >>> >>> Best to use re and how? Something else? >> >> Use pyparsing it is straight forward: >> >> >>> from pyparsing import Suppress, restOfLine >> >> >>> mystring = Suppress('[') + Suppress('{') + restOfLine >> >> >>> result = mystring.parse(' [ { .... I am learning pyparsing' ) >> >> >>> print result.asList() >> >> ['.... I am learning pyparsing'] >> >> You'll get your string inside the list. >> >> Hope this help see pyparsing doc for in depth study. >> >> Karim > > Congratulations for writing up one of the most overengineered pile of > cobblers I've ever seen. > You welcome ! The intent was to make a simple introduction to pyparsing which is a powerful tool for more complex parser build. Karim From tdsperth at gmail.com Fri Jan 1 05:56:24 2016 From: tdsperth at gmail.com (tdsperth at gmail.com) Date: Fri, 1 Jan 2016 02:56:24 -0800 (PST) Subject: Mac Question Message-ID: <5d9432dc-220f-457b-945c-a864e7255520@googlegroups.com> Hi All I am trying to create a directory on a windows drive from my macbook air with python but get a permissions error because the windows ntfs drive is read only - does anyone know away to overcome this issue - I have looked for a utility but have yet to find an answer. Regards and Happy New Year Colin From rosuav at gmail.com Fri Jan 1 06:13:15 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Jan 2016 22:13:15 +1100 Subject: Mac Question In-Reply-To: <5d9432dc-220f-457b-945c-a864e7255520@googlegroups.com> References: <5d9432dc-220f-457b-945c-a864e7255520@googlegroups.com> Message-ID: On Fri, Jan 1, 2016 at 9:56 PM, wrote: > Hi All > > I am trying to create a directory on a windows drive from my macbook air with python but get a permissions error because the windows ntfs drive is read only - does anyone know away to overcome this issue - I have looked for a utility but have yet to find an answer. > This isn't a Python question - it's a Windows question. I'll help as best I can, but you might find better results elsewhere. Is this a drive you've mounted across a network, or is it something local to your computer? Is it a hard drive, a Flash drive (USB stick), or some other device? What are the mount options? (Typing 'mount' in a terminal might tell you this.) Who owns the files and directories? Can you create stuff on there using 'sudo'? ChrisA From tdsperth at gmail.com Fri Jan 1 06:27:13 2016 From: tdsperth at gmail.com (tdsperth at gmail.com) Date: Fri, 1 Jan 2016 03:27:13 -0800 (PST) Subject: Mac Question In-Reply-To: References: <5d9432dc-220f-457b-945c-a864e7255520@googlegroups.com> Message-ID: <823e9751-2ca3-470c-8f2c-20ab82f09ed9@googlegroups.com> On Friday, January 1, 2016 at 7:13:41 PM UTC+8, Chris Angelico wrote: > On Fri, Jan 1, 2016 at 9:56 PM, wrote: > > Hi All > > > > I am trying to create a directory on a windows drive from my macbook air with python but get a permissions error because the windows ntfs drive is read only - does anyone know away to overcome this issue - I have looked for a utility but have yet to find an answer. > > > > This isn't a Python question - it's a Windows question. I'll help as > best I can, but you might find better results elsewhere. > > Is this a drive you've mounted across a network, or is it something > local to your computer? Is it a hard drive, a Flash drive (USB stick), > or some other device? > > What are the mount options? (Typing 'mount' in a terminal might tell > you this.) Who owns the files and directories? Can you create stuff on > there using 'sudo'? > > ChrisA Hi ChrisA I know it is not a python issue - I just thought some other python programmers might have come across the problem. I connect to a drive in a windows 10 computer smb://192.168.50.58/c from my mac but the drive is read only - i am looking for away to make the drive writable so I can make a directory on the drive from my python script. Regards Colin From rosuav at gmail.com Fri Jan 1 06:47:47 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Jan 2016 22:47:47 +1100 Subject: Mac Question In-Reply-To: <823e9751-2ca3-470c-8f2c-20ab82f09ed9@googlegroups.com> References: <5d9432dc-220f-457b-945c-a864e7255520@googlegroups.com> <823e9751-2ca3-470c-8f2c-20ab82f09ed9@googlegroups.com> Message-ID: On Fri, Jan 1, 2016 at 10:27 PM, wrote: > I connect to a drive in a windows 10 computer smb://192.168.50.58/c from my mac but the drive is read only - i am looking for away to make the drive writable so I can make a directory on the drive from my python script. > You'll have to look into the permissions setup on both the Windows computer and the Mac. Try connecting from a different computer to that server, or from that Mac to a different server, and see what's going on. ChrisA From wrw at mac.com Fri Jan 1 10:21:46 2016 From: wrw at mac.com (William Ray Wing) Date: Fri, 01 Jan 2016 10:21:46 -0500 Subject: Mac Question In-Reply-To: <5d9432dc-220f-457b-945c-a864e7255520@googlegroups.com> References: <5d9432dc-220f-457b-945c-a864e7255520@googlegroups.com> Message-ID: <1788AE71-040C-45CC-873B-21250B25766B@mac.com> > On Jan 1, 2016, at 5:56 AM, tdsperth at gmail.com wrote: > > Hi All > > I am trying to create a directory on a windows drive from my macbook air with python but get a permissions error because the windows ntfs drive is read only - does anyone know away to overcome this issue - I have looked for a utility but have yet to find an answer. > > Regards and Happy New Year > > Colin > > -- > https://mail.python.org/mailman/listinfo/python-list OS-X can read NTFS drives, but by default cannot write to them, hence the read-only mount. If you have control over that external drive you can format it (on OS-X) as ExFAT, and it can then be written to and read from by both OS-X and Windows. If the drive must be formatted NTFS, you can turn on writing via terminal commands (which works ONLY on a volume-by-volume basis) or using a third party utility. There is a pretty good summary here: http://www.cnet.com/news/how-to-manually-enable-ntfs-read-and-write-in-os-x/ -Bill From sameer.grover.1 at gmail.com Fri Jan 1 12:55:56 2016 From: sameer.grover.1 at gmail.com (Sameer Grover) Date: Fri, 1 Jan 2016 23:25:56 +0530 Subject: Python Data Analysis Recommendations In-Reply-To: References: Message-ID: I also collect data by sweeping multiple parameters in a similar fashion. I find pandas very convenient for analysis. I don't use all the features of pandas. I mainly use it for selecting certain rows from the data, sometimes using database style merge operations, and plotting using matplotlib. This can also be done using pure numpy but with pandas, I don't have to keep track of all the indices This is what my workflow is like (waarning - sloppy code): data = pd.DataFrame() data.columns = ['temperature', 'voltage_measured', 'voltage_applied', 'channels'] for channel in data.channels.unique(): for temperature in data.temperature.unique(): slope = fit_slope(data[data['temperature']==temperature and data['channels']==channel]) # fit_slope(x) -> fits x.voltage_measured and x.voltage_applied and returns slope # append (channel, temperature, slope) to final plotting array etc I imagine your database driven approach would do something similar but you might find pandas more convenient given that it can all be done in python and that you won't have to resort to SQL queries. My data is small enough to get away with storing as plain text. But hdf5 is definitely a better solution. In addition to pytables, there is also h5py (http://www.h5py.org/). I prefer the latter. You might like pytables because it is more database-like. Sameer On 31 December 2015 at 22:45, Rob Gaddi wrote: > I'm looking for some advice on handling data collection/analysis in > Python. I do a lot of big, time consuming experiments in which I run a > long data collection (a day or a weekend) in which I sweep a bunch of > variables, then come back offline and try to cut the data into something > that makes sense. > > For example, my last data collection looked (neglecting all the actual > equipment control code in each loop) like: > > for t in temperatures: > for r in voltage_ranges: > for v in test_voltages[r]: > for c in channels: > for n in range(100): > record_data() > > I've been using Sqlite (through peewee) as the data backend, setting up > a couple tables with a basically hierarchical relationship, and then > handling analysis with a rough cut of SQL queries against the > original data, Numpy/Scipy for further refinement, and Matplotlib > to actually do the visualization. For example, one graph was "How does > the slope of straight line fit between measured and applied voltage vary > as a function of temperature on each channel?" > > The whole process feels a bit grindy; like I keep having to do a lot of > ad-hoc stitching things together. And I keep hearing about pandas, > PyTables, and HDF5. Would that be making my life notably easier? If > so, does anyone have any references on it that they've found > particularly useful? The tutorials I've seen so far seem to not give > much detail on what the point of what they're doing is; it's all "how > you write the code" rather than "why you write the code". Paying money > for books is acceptable; this is all on the company's time/dime. > > Thanks, > Rob > > -- > Rob Gaddi, Highland Technology -- www.highlandtechnology.com > Email address domain is currently out of order. See above to fix. > -- > https://mail.python.org/mailman/listinfo/python-list > From paul.hermeneutic at gmail.com Fri Jan 1 14:00:32 2016 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Fri, 1 Jan 2016 12:00:32 -0700 Subject: Stupid Python tricks In-Reply-To: <5684c69a$0$1589$c3e8da3$5496439d@news.astraweb.com> References: <5684a63b$0$1595$c3e8da3$5496439d@news.astraweb.com> <5684c69a$0$1589$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Dec 30, 2015 at 11:09 PM, Steven D'Aprano wrote: > On Thu, 31 Dec 2015 04:02 pm, Rick Johnson wrote: > > >> Fifteen years later, and Tim Peters' Stupid Python Trick is still the > >> undisputed champion! > > > > And should we be happy about that revelation, or sad? > > Yes! > > Which one, Steve? Happy or sad? From lazyabhinav at gmail.com Fri Jan 1 14:16:07 2016 From: lazyabhinav at gmail.com (PythonLearner) Date: Fri, 1 Jan 2016 11:16:07 -0800 (PST) Subject: Example for Multiple and Multilevel Inheritance Message-ID: <40aade52-3674-4659-8a50-0334fedf333c@googlegroups.com> Hello All, I'm new to this group. I'm looking for examples for Multiple and Multilevel Inheritance without the use of super(). Thanks An Avid Python Learner From breamoreboy at yahoo.co.uk Fri Jan 1 14:32:25 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 1 Jan 2016 19:32:25 +0000 Subject: Example for Multiple and Multilevel Inheritance In-Reply-To: <40aade52-3674-4659-8a50-0334fedf333c@googlegroups.com> References: <40aade52-3674-4659-8a50-0334fedf333c@googlegroups.com> Message-ID: On 01/01/2016 19:16, PythonLearner wrote: > Hello All, > I'm new to this group. > I'm looking for examples for Multiple and Multilevel Inheritance without the use of super(). > Thanks > An Avid Python Learner > Please tell us what you're trying to achive, as without super() you'll be throwing DRY right out of the window. You might like to read this, noting especially the first line "If you aren?t wowed by Python?s super() builtin, chances are you don?t really know what it is capable of doing or how to use it effectively.". -- 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 Jan 1 14:39:40 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 1 Jan 2016 19:39:40 +0000 Subject: We will be moving to GitHub Message-ID: Please see https://mail.python.org/pipermail/core-workflow/2016-January/000345.html This should encourage developers at all levels to help out, such that the list of open issues on the bug tracker falls drastically. -- 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 Fri Jan 1 14:46:47 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jan 2016 06:46:47 +1100 Subject: We will be moving to GitHub In-Reply-To: References: Message-ID: On Sat, Jan 2, 2016 at 6:39 AM, Mark Lawrence wrote: > Please see > https://mail.python.org/pipermail/core-workflow/2016-January/000345.html > > This should encourage developers at all levels to help out, such that the > list of open issues on the bug tracker falls drastically. How does that interact with the still-Draft status of PEP 481? The email seems to mainly be saying "not GitLab", but until PEP 481 is accepted, I'm not certain that GitHub is accepted either. It's not entirely clear whether that message is an acceptance of PEP 481 or not. ChrisA From zachary.ware+pylist at gmail.com Fri Jan 1 14:58:59 2016 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Fri, 1 Jan 2016 13:58:59 -0600 Subject: We will be moving to GitHub In-Reply-To: References: Message-ID: On Jan 1, 2016 1:47 PM, "Chris Angelico" wrote: > > On Sat, Jan 2, 2016 at 6:39 AM, Mark Lawrence wrote: > > Please see > > https://mail.python.org/pipermail/core-workflow/2016-January/000345.html > > > > This should encourage developers at all levels to help out, such that the > > list of open issues on the bug tracker falls drastically. > > How does that interact with the still-Draft status of PEP 481? The > email seems to mainly be saying "not GitLab", but until PEP 481 is > accepted, I'm not certain that GitHub is accepted either. > > It's not entirely clear whether that message is an acceptance of PEP 481 or not. I've lost track of the pep numbers, but Brett's decision is final; the canonical CPython repository will be moving to GitHub in the near future. Note that we will *not* be using the GitHub issue tracker or wiki, just the hosting and review/pull request system. There are still several details to be worked out, though. -- Zach (On a phone) From paul.hermeneutic at gmail.com Fri Jan 1 15:03:44 2016 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Fri, 1 Jan 2016 13:03:44 -0700 Subject: We will be moving to GitHub In-Reply-To: References: Message-ID: Mark, it is good to know that a decision has been made so that we can move forward. Is there a summary document that discusses the options examined and why others did not meet the requirements? I am -NOT- trying to dredge up arguments about the choice. I am guessing that there have been some. If this fact-based decision was based solely on the fact that the BDFL prefers GitHub, please just say so. It is clear that git is a capable tool. From rosuav at gmail.com Fri Jan 1 15:09:42 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jan 2016 07:09:42 +1100 Subject: We will be moving to GitHub In-Reply-To: References: Message-ID: On Sat, Jan 2, 2016 at 6:58 AM, Zachary Ware wrote: >> It's not entirely clear whether that message is an acceptance of PEP 481 > or not. > > I've lost track of the pep numbers, but Brett's decision is final; the > canonical CPython repository will be moving to GitHub in the near future. > Note that we will *not* be using the GitHub issue tracker or wiki, just the > hosting and review/pull request system. There are still several details to > be worked out, though. Okay, so that means it broadly is an acceptance of PEP 481. Hopefully someone who's been involved in the discussions can check over the PEP text and adjust as necessary to make it accurate to what's going to happen. On Sat, Jan 2, 2016 at 7:03 AM, wrote: > Mark, it is good to know that a decision has been made so that we can move > forward. > > Is there a summary document that discusses the options examined and why > others did not meet the requirements? I am -NOT- trying to dredge up > arguments about the choice. I am guessing that there have been some. > > If this fact-based decision was based solely on the fact that the BDFL > prefers GitHub, please just say so. It is clear that git is a capable tool. That's what the PEP is for. Here's the link: https://www.python.org/dev/peps/pep-0481/ Yes, git is a capable tool. But so is Mercurial, and the arguments weren't primarily based on differences in functionality (which are pretty minor). It's mainly about the network effect. ChrisA From paul.hermeneutic at gmail.com Fri Jan 1 15:21:13 2016 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Fri, 1 Jan 2016 13:21:13 -0700 Subject: Python.Exe Problem In-Reply-To: References: Message-ID: Daniel, after the download, please be sure to verify the MD5 checksum to know that the download is correct. On Tue, Dec 29, 2015 at 1:44 PM, Terry Reedy wrote: > On 12/29/2015 11:24 AM, Daniel Lee wrote: > >> Hello, >> >> When I try to run python.exe on my computer with Windows 8, >> > > Which exact version? From what source? How did you download (from where) > or compile? How did you install? How do you try to run it? > > I get the following error: >> >> "Python.exe - Entry Point Not Found" >> >> "The Procedure entry point ?terminate@@YAXXZ could not be located in the >> dynamic link library C:\Program Files\Python3.5\python.exe." >> > > Google return 76000 hits for 'terminate@@YAXXZ', so this appears to not > be a unique issue in some form or another. > > What does this error mean and how can I fix it? >> > > It seems like your installed python.exe is corrupt. Make sure you have a > final release. I would re-install, possibly after re-downloading from > python.org. If you download from anywhere else, *they* are responsible > for getting the compile options correct. > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list > From no.email at nospam.invalid Fri Jan 1 15:33:24 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 01 Jan 2016 12:33:24 -0800 Subject: We will be moving to GitHub References: Message-ID: <87si2hdoq3.fsf@jester.gateway.pace.com> Zachary Ware writes: > ... the canonical CPython repository will be moving to GitHub in the > near future. Note that we will *not* be using the GitHub issue > tracker or wiki, just the hosting and review/pull request system. Will everyone wanting to submit patches be required to use a Github account? Or will it be enough to put the patch in an outside repo and link to it in the Python issue tracker? I'm glad that (it sounds like) no Github account will be needed to submit bug reports. From zachary.ware+pylist at gmail.com Fri Jan 1 15:46:39 2016 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Fri, 1 Jan 2016 14:46:39 -0600 Subject: We will be moving to GitHub In-Reply-To: <87si2hdoq3.fsf@jester.gateway.pace.com> References: <87si2hdoq3.fsf@jester.gateway.pace.com> Message-ID: On Jan 1, 2016 2:35 PM, "Paul Rubin" wrote: > > Zachary Ware writes: > > ... the canonical CPython repository will be moving to GitHub in the > > near future. Note that we will *not* be using the GitHub issue > > tracker or wiki, just the hosting and review/pull request system. > > Will everyone wanting to submit patches be required to use a Github > account? Or will it be enough to put the patch in an outside repo and > link to it in the Python issue tracker? I'm glad that (it sounds like) > no Github account will be needed to submit bug reports. Correct, no GitHub account will be required for interactions on the bugs.python.org tracker, and a patch can move all the way through to commit entirely on the b.p.o tracker (just as currently). -- Zach (On a phone) From breamoreboy at yahoo.co.uk Fri Jan 1 15:48:30 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 1 Jan 2016 20:48:30 +0000 Subject: We will be moving to GitHub In-Reply-To: References: Message-ID: On 01/01/2016 20:03, paul.hermeneutic at gmail.com wrote: > Mark, it is good to know that a decision has been made so that we can move > forward. > > Is there a summary document that discusses the options examined and why > others did not meet the requirements? I am -NOT- trying to dredge up > arguments about the choice. I am guessing that there have been some. > > If this fact-based decision was based solely on the fact that the BDFL > prefers GitHub, please just say so. It is clear that git is a capable tool. > There is no point in targetting any queries at me, I'm just the messenger :) I've loosly followed the discussion on the core workflow mailing list, but frankly much of that said goes right over my head, as my knowledge of GitHub, GitLab, Mercurial and all the rest of them is roughly zero. There is all ready disagreement over the decision. I'll sit back and let the core developers sort that out, confident that eventually we'll end up with working processes backed up by working systems. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From zachary.ware+pylist at gmail.com Fri Jan 1 16:08:15 2016 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Fri, 1 Jan 2016 15:08:15 -0600 Subject: We will be moving to GitHub In-Reply-To: References: Message-ID: On Fri, Jan 1, 2016 at 2:03 PM, wrote: > Is there a summary document that discusses the options examined and why > others did not meet the requirements? I am -NOT- trying to dredge up > arguments about the choice. I am guessing that there have been some. Easiest would be to look through the archives of the core-workflow mailing list: https://mail.python.org/pipermail/core-workflow/ > If this fact-based decision was based solely on the fact that the BDFL > prefers GitHub, please just say so. It is clear that git is a capable tool. There were three reasons given in Brett's decision message: 1. No major distinguishing features between GitHub or GitLab Note that GitHub and GitLab were the only proposals under consideration; nobody else stepped up to champion any other solution. 2. Familiarity amongst core devs -- and external contributors -- with GitHub 3. Guido prefers GitHub Guido repeatedly stated that his preference should not be taken into account. I believe Brett gave it little weight, but obviously it was in his mind. -- Zach From no.email at nospam.invalid Fri Jan 1 16:19:59 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 01 Jan 2016 13:19:59 -0800 Subject: We will be moving to GitHub References: <87si2hdoq3.fsf@jester.gateway.pace.com> Message-ID: <87oad5dmkg.fsf@jester.gateway.pace.com> Zachary Ware writes: > Correct, no GitHub account will be required for interactions on the > bugs.python.org tracker, and a patch can move all the way through to commit > entirely on the b.p.o tracker (just as currently). Thanks. From breamoreboy at yahoo.co.uk Fri Jan 1 16:24:27 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 1 Jan 2016 21:24:27 +0000 Subject: Python Data Analysis Recommendations In-Reply-To: References: Message-ID: On 31/12/2015 17:15, Rob Gaddi wrote: > I'm looking for some advice on handling data collection/analysis in > Python. I do a lot of big, time consuming experiments in which I run a > long data collection (a day or a weekend) in which I sweep a bunch of > variables, then come back offline and try to cut the data into something > that makes sense. > > For example, my last data collection looked (neglecting all the actual > equipment control code in each loop) like: > > for t in temperatures: > for r in voltage_ranges: > for v in test_voltages[r]: > for c in channels: > for n in range(100): > record_data() > > I've been using Sqlite (through peewee) as the data backend, setting up > a couple tables with a basically hierarchical relationship, and then > handling analysis with a rough cut of SQL queries against the > original data, Numpy/Scipy for further refinement, and Matplotlib > to actually do the visualization. For example, one graph was "How does > the slope of straight line fit between measured and applied voltage vary > as a function of temperature on each channel?" > > The whole process feels a bit grindy; like I keep having to do a lot of > ad-hoc stitching things together. And I keep hearing about pandas, > PyTables, and HDF5. Would that be making my life notably easier? If > so, does anyone have any references on it that they've found > particularly useful? The tutorials I've seen so far seem to not give > much detail on what the point of what they're doing is; it's all "how > you write the code" rather than "why you write the code". Paying money > for books is acceptable; this is all on the company's time/dime. > > Thanks, > Rob > I'd start with pandas http://pandas.pydata.org/and see how you get on. If and only if pandas isn't adequate, and I think that highly unlikely, try PyTables. Quoting from http://www.pytables.org/ "PyTables is a package for managing hierarchical datasets and designed to efficiently and easily cope with extremely large amounts of data." and "PyTables is built on top of the HDF5 library". I've no idea what the definition of "extremely large" is in this case. How much data are you dealing with? I don't understand your comment about tutorials. Once they've given you an introduction to the tool, isn't it your responsibility to manipulate your data in the way that suits you? If you can't do that, either you're doing something wrong, or the tool is inadequate for the task. For the latter I believe you've two options, find another tool or write your own. I would not buy books, on the simple grounds that they go out of date far faster then the online docs :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From storchaka at gmail.com Fri Jan 1 17:16:43 2016 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sat, 2 Jan 2016 00:16:43 +0200 Subject: Stupid Python tricks In-Reply-To: References: <5684a63b$0$1595$c3e8da3$5496439d@news.astraweb.com> <5684c69a$0$1589$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01.01.16 21:00, paul.hermeneutic at gmail.com wrote: > On Wed, Dec 30, 2015 at 11:09 PM, Steven D'Aprano > wrote: > >> On Thu, 31 Dec 2015 04:02 pm, Rick Johnson wrote: >> >>>> Fifteen years later, and Tim Peters' Stupid Python Trick is still the >>>> undisputed champion! >>> >>> And should we be happy about that revelation, or sad? >> >> Yes! >> >> > Which one, Steve? Happy or sad? True. From backscatter at rettacs.org Fri Jan 1 17:16:51 2016 From: backscatter at rettacs.org (Ravi Narasimhan) Date: Fri, 1 Jan 2016 14:16:51 -0800 Subject: Python Data Analysis Recommendations In-Reply-To: References: Message-ID: On 1/1/16 1:24 PM, Mark Lawrence wrote: > On 31/12/2015 17:15, Rob Gaddi wrote: >> I'm looking for some advice on handling data collection/analysis in >> Python. ... >> The whole process feels a bit grindy; like I keep having to do a lot of >> ad-hoc stitching things together. And I keep hearing about pandas, >> PyTables, and HDF5. Would that be making my life notably easier? If >> so, does anyone have any references on it that they've found >> particularly useful? The tutorials I've seen so far seem to not give >> much detail on what the point of what they're doing is; it's all "how >> you write the code" rather than "why you write the code". Paying money >> for books is acceptable; this is all on the company's time/dime. >> >> Thanks, >> Rob Cyrille Rossant's books may meet your needs. The Interactive Computing and Visualization Cookbook offers more than just recipes. As the topics get advanced, he explains the whys in addition to the hows. It may not have specific answers to parameter sweep experiments but I understood more about Python's internals and packages as they related to my work. It helped me to refine when to use Python and when to use other languages. Currently US $5 via the publisher: https://www.packtpub.com/books/info/authors/cyrille-rossant (I have no affiliation with the author or publisher) Mark Lawrence writes: > I don't understand your comment about tutorials. Once they've given you > an introduction to the tool, isn't it your responsibility to manipulate > your data in the way that suits you? If you can't do that, either > you're doing something wrong, or the tool is inadequate for the task. > For the latter I believe you've two options, find another tool or write > your own. Without second-guessing the OP, I've found Python tutorials and documents to be helpful but not always complete in a way that beginners and casual users would need. There is usually a package that will do some job but one first has to find it. A lot of power can also be located deep within a hierarchy of dots: package.something.subsomething.subsubsomething ... Some documentation sets are very complete, others aren't. I often have the nagging feeling that if I just knew what question to ask and knew the right terminology, that I could benefit from code someone has already written and/or develop a smarter plan of attack. Ravi Narasimhan http://www.rettacs.org From storchaka at gmail.com Fri Jan 1 17:22:18 2016 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sat, 2 Jan 2016 00:22:18 +0200 Subject: Stupid Python tricks In-Reply-To: <5684a63b$0$1595$c3e8da3$5496439d@news.astraweb.com> References: <5684a63b$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 31.12.15 05:51, Steven D'Aprano wrote: > Fifteen years later, and Tim Peters' Stupid Python Trick is still the > undisputed champion! It may be platform depended, but on my computer the obvious way is 10% faster the Stupid Python Trick. From xaviertim017 at gmail.com Fri Jan 1 18:15:35 2016 From: xaviertim017 at gmail.com (xaviertim017 at gmail.com) Date: Fri, 1 Jan 2016 15:15:35 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <1e0feecd-6292-406d-ac27-d32742a4023a@googlegroups.com> <8297515b-834b-4829-abb4-0191a66222bb@googlegroups.com> Message-ID: <02c64730-8efc-4c84-8739-12e0bcabd3e2@googlegroups.com> On Saturday, December 26, 2015 at 12:06:07 AM UTC+1, Won Chang wrote: > i have gotten the answer of that problem Please Can you post the answer you got. If convenient send to my email xaviertim017 at gmail.com. Thanks in advance. From xaviertim017 at gmail.com Fri Jan 1 19:24:10 2016 From: xaviertim017 at gmail.com (xaviertim017 at gmail.com) Date: Fri, 1 Jan 2016 16:24:10 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> Message-ID: <6299b5ff-48af-4a7b-b51c-b2f9fd26f047@googlegroups.com> On Saturday, December 12, 2015 at 10:05:29 AM UTC+1, Harbey Leke wrote: > Create a class called BankAccount > > .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 > > Please i need help on this i am a beginer into python programming. > > > Also below is a test case given for this project > > > import unittest > class AccountBalanceTestCases(unittest.TestCase): > def setUp(self): > self.my_account = BankAccount(90) > > def test_balance(self): > self.assertEqual(self.my_account.balance, 90, msg='Account Balance Invalid') > > def test_deposit(self): > self.my_account.deposit(90) > self.assertEqual(self.my_account.balance, 180, msg='Deposit method inaccurate') > > def test_withdraw(self): > self.my_account.withdraw(40) > self.assertEqual(self.my_account.balance, 50, msg='Withdraw method inaccurate') > > def test_invalid_operation(self): > self.assertEqual(self.my_account.withdraw(1000), "invalid transaction", msg='Invalid transaction') > > def test_sub_class(self): > self.assertTrue(issubclass(MinimumBalanceAccount, BankAccount), msg='No true subclass of BankAccount') Thank God for this group, its a very helpful. It turns out i had a correct code all the while. i found out that the "line 23 test" failed because of the case sensitivity. i used - return ("Invalid Transaction") instead of return ("invalid transaction") Notice the "i" and "t" Thanks again From tjreedy at udel.edu Fri Jan 1 19:24:59 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 1 Jan 2016 19:24:59 -0500 Subject: We will be moving to GitHub In-Reply-To: References: Message-ID: On 1/1/2016 4:08 PM, Zachary Ware wrote: > On Fri, Jan 1, 2016 at 2:03 PM, wrote: >> Is there a summary document that discusses the options examined and why >> others did not meet the requirements? I am -NOT- trying to dredge up >> arguments about the choice. I am guessing that there have been some. > > Easiest would be to look through the archives of the core-workflow > mailing list: https://mail.python.org/pipermail/core-workflow/ In particular: https://mail.python.org/pipermail/core-workflow/2016-January/000345.html . >> If this fact-based decision was based solely on the fact that the BDFL >> prefers GitHub, please just say so. It is clear that git is a capable tool. > > There were three reasons given in Brett's decision message: > > 1. No major distinguishing features between GitHub or GitLab > > Note that GitHub and GitLab were the only proposals under > consideration; nobody else stepped up to champion any other solution. > > 2. Familiarity amongst core devs -- and external contributors -- with GitHub In particular, some inactive contributors who use git and github apparently emailed Brett to say that they might re-activate if they could use the process they otherwise use all the time instead of Python's idiosyncratic workflow. While the decision might not be my personal first choice, we absolutely need more core developers contributing, including reviewing contributed patches. > 3. Guido prefers GitHub > > Guido repeatedly stated that his preference should not be taken into > account. I believe Brett gave it little weight, but obviously it was > in his mind. -- Terry Jan Reedy From no.email at nospam.invalid Fri Jan 1 20:28:21 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 01 Jan 2016 17:28:21 -0800 Subject: We will be moving to GitHub References: Message-ID: <87fuygepmy.fsf@jester.gateway.pace.com> Terry Reedy writes: > While the decision might not be my personal first choice, we > absolutely need more core developers contributing, including reviewing > contributed patches. Yeah, I'm not delighted by the choice either, but as long as the core devs have bought in and it doesn't affect non-core devs (occasional contributors and bug reporters), then whatever. FWIW, Scaleway has a 1-click (well, several clicks) Gitlab installer: https://www.scaleway.com/imagehub/gitlab/ It launches a 3 euro/month ARM dedicated server and deploys Gitlab on it. I haven't used Gitlab yet but have been using Gogs (gogs.io) a little. It's a lighter-weight Github-like thing written in Go, that however is still missing some important features like pull requests. I like it though. It runs nicely on cheap VPS where Gitlab is a resource hog. From steve at pearwood.info Sat Jan 2 01:43:23 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 02 Jan 2016 17:43:23 +1100 Subject: We will be moving to GitHub References: Message-ID: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> On Sat, 2 Jan 2016 07:09 am, Chris Angelico wrote: > Yes, git is a capable tool. But so is Mercurial, and the arguments > weren't primarily based on differences in functionality (which are > pretty minor). It's mainly about the network effect. You call it the network effect. I call it monoculture. This decision is socially irresponsible. For all the cheap talk about diversity, the Python core-devs are now about to move to (and probably give money to) a company with a well-deserved reputation of being hostile to women. Even if you believe that Github has reformed (and I see no credible evidence that they have, apart from Github's own self-serving statements that they have), diversity doesn't just apply to human individuals, it also applies to technologies. The fact that Github is so popular should count *against* it, not in favour. There are times where everybody should do the same thing -- choosing whether to drive on the left or the right side of the road, for example. And there are times where following the crowd like lemmings is actively harmful, no matter how convenient it seems in the short-run. http://nedbatchelder.com/blog/201405/github_monoculture.html Oh, and talking about DVCS: https://bitquabit.com/post/unorthodocs-abandon-your-dvcs-and-return-to-sanity/ -- Steven From ben+python at benfinney.id.au Sat Jan 2 02:02:17 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 02 Jan 2016 18:02:17 +1100 Subject: We will be moving to GitHub References: <87si2hdoq3.fsf@jester.gateway.pace.com> Message-ID: <8560zcsbuu.fsf@benfinney.id.au> Zachary Ware writes: > On Jan 1, 2016 2:35 PM, "Paul Rubin" wrote: > > Will everyone wanting to submit patches be required to use a Github > > account? Or will it be enough to put the patch in an outside repo > > and link to it in the Python issue tracker? I'm glad that (it sounds > > like) no Github account will be needed to submit bug reports. > > Correct, no GitHub account will be required for interactions on the > bugs.python.org tracker, and a patch can move all the way through to > commit entirely on the b.p.o tracker (just as currently). My experience with contributing to repositories hosted on GitHub, from repositories hosted elsewhere, necessitates the question: What is being done to stave off the common response, addressed by GitHub users to people submitting a change as a link to their Git repository, of ?can you please submit that as a GitHub pull request?? That common response makes for an unnecessary and IMO unacceptable pressure toward centralisation. GitHub's ?pull request? workflow is entirely proprietary and can only be done within GitHub. What will be done to ensure other Git repositories remain on a level playing field not only technically, but socially? -- \ ?Ours is a world where people don't know what they want and are | `\ willing to go through hell to get it.? ?Donald Robert Perry | _o__) Marquis | Ben Finney From ben+python at benfinney.id.au Sat Jan 2 02:09:03 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 02 Jan 2016 18:09:03 +1100 Subject: We will be moving to GitHub References: Message-ID: <851ta0sbjk.fsf@benfinney.id.au> Terry Reedy writes: > On 1/1/2016 4:08 PM, Zachary Ware wrote: > > There were three reasons given in Brett's decision message: > > > > 1. No major distinguishing features between GitHub or GitLab It seems ?complete source code available and freely licensed, allowing the community to implement the entire tool set elsewhere, without any need to consult the existing service provider? ? i.e. community control over their own tools ? is not considered a major distinguishing feature. > In particular, some inactive contributors who use git and github > apparently emailed Brett to say that they might re-activate if they > could use the process they otherwise use all the time instead of > Python's idiosyncratic workflow. This is a grave concern. A strong implication of ?use the process they otherwise use all the time? is that these people expect to use GitHub's proprietary, centralised, single-vendor workflow tools. This implication necessarily entails rejecting contributions from other community members who don't use those single-vendor tools. The decision to take tools that were expressly designed to escape single-vendor centralisation, and then willingly build single-vendor workflows around them which divide the free software community along vendor lines, is a foolish and worrying trend. I am alarmed to see the Python core team go further down that path. -- \ ?? whoever claims any right that he is unwilling to accord to | `\ his fellow-men is dishonest and infamous.? ?Robert G. | _o__) Ingersoll, _The Liberty of Man, Woman and Child_, 1877 | Ben Finney From rosuav at gmail.com Sat Jan 2 02:12:35 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jan 2016 18:12:35 +1100 Subject: We will be moving to GitHub In-Reply-To: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jan 2, 2016 at 5:43 PM, Steven D'Aprano wrote: > On Sat, 2 Jan 2016 07:09 am, Chris Angelico wrote: > >> Yes, git is a capable tool. But so is Mercurial, and the arguments >> weren't primarily based on differences in functionality (which are >> pretty minor). It's mainly about the network effect. > > You call it the network effect. I call it monoculture. The "you" here is the generic "you" rather than specifically addressing me; I'm merely citing the discussions already given. I'm going to assume that everyone here has read PEP 481, so if you haven't, please go read it before responding. https://www.python.org/dev/peps/pep-0481/ > This decision is socially irresponsible. For all the cheap talk about > diversity, the Python core-devs are now about to move to (and probably give > money to) a company with a well-deserved reputation of being hostile to > women. Even if you believe that Github has reformed (and I see no credible > evidence that they have, apart from Github's own self-serving statements > that they have), diversity doesn't just apply to human individuals, it also > applies to technologies. The fact that Github is so popular should count > *against* it, not in favour. If that is an argument, then it's one to push people to GitLab over GitHub, but nothing about git vs hg. > There are times where everybody should do the same thing -- choosing whether > to drive on the left or the right side of the road, for example. And there > are times where following the crowd like lemmings is actively harmful, no > matter how convenient it seems in the short-run. The popularity of technology IS an argument in its favour, though. How many people here use Gopher instead of HTTP? Would it be better to serve Python content on the obscure protocol rather than the popular one? When 99% of people know how to use one technology and 1% know how to use a different one, it's advantageous to go where the people are. (Of course, there are other considerations, too - PHP is popular, but that alone isn't a reason to use it. The context here is of technologies so similar in functionality that we really CAN make a decision on these kinds of bases.) The Python project *needs* new contributors. This is not in question. You can't expect to keep the project going solely on the basis of the people currently writing and applying patches. So there are two options: 1) Do everything using a workflow peculiar to Python, using a less-popular technology 2) Put everything on a massively-popular web site using the more popular technology, and do everything exactly the way everyone else does. Yes, the latter might be the lemming approach. But do we actually have a problem with git and a pull-request workflow? (Concerns about GitHub as a company are a separate consideration. As mentioned above, GitLab is a similar option, and would allow python.org to host its own instance if desired.) I have worked one-on-one with about 70 students over the past two years, introducing them to Python and web development, and using git and GitHub for their projects. They can now go on to contribute to any of a huge number of projects. If, instead, we'd taught them to use Mercurial, they still wouldn't be able to immediately contribute to CPython, because the workflow is custom. (You don't actually create a commit, you just use 'hg diff >patchfile' and upload that. And if you're actually a core contributor, you need to be careful about where you merge things, and which direction.) Moving CPython to GitHub would mean anyone could simply fork it on the server and push a commit, then paste a link into bugs.python.org and let someone decide to merge it. So which would you prefer? Arbitrary technological diversity, or a large pool of potential contributors? ChrisA From marko at pacujo.net Sat Jan 2 04:48:39 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 02 Jan 2016 11:48:39 +0200 Subject: We will be moving to GitHub References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87oad41fd4.fsf@elektro.pacujo.net> Steven D'Aprano : > Oh, and talking about DVCS: > > https://bitquabit.com/post/unorthodocs-abandon-your-dvcs-and-retur > n-to-sanity/ It's interesting how different opinions people can have about version control. I also have mine. I have seen the paradise, which was Sun's Teamware. I haven't tried Bitkeeper, it's successor. Having struggled with Perforce, SVN and CVS, I was hopeful Mercurial would be everything Teamware was. Unfortunately, it wasn't. The big disappointment was the treatment of a repository as the atomic unit. Git's no better than Mercurial. Also, Git is conceptually cluttered. Well, Git and Mercurial are not all that bad as long as only a single person is working on the repository at any given time and you have a strictly linear version history. That would be advisable anyway as you should have a separate repository for each conceptual unit. Marko From rosuav at gmail.com Sat Jan 2 05:29:20 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jan 2016 21:29:20 +1100 Subject: We will be moving to GitHub In-Reply-To: <87oad41fd4.fsf@elektro.pacujo.net> References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> <87oad41fd4.fsf@elektro.pacujo.net> Message-ID: On Sat, Jan 2, 2016 at 8:48 PM, Marko Rauhamaa wrote: > Having struggled with Perforce, SVN and CVS, I was hopeful Mercurial > would be everything Teamware was. > > Unfortunately, it wasn't. The big disappointment was the treatment of a > repository as the atomic unit. You'll need to elaborate on this. Is a repository too large or too small as an atomic unit? What is the Teamware style, and what is the advantage? Remember, you can always build structures around the outside of a repository - hg.python.org has half a dozen major repos, plus a large number of others. ChrisA From marko at pacujo.net Sat Jan 2 06:22:42 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 02 Jan 2016 13:22:42 +0200 Subject: We will be moving to GitHub References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> <87oad41fd4.fsf@elektro.pacujo.net> Message-ID: <87k2ns1b0d.fsf@elektro.pacujo.net> Chris Angelico : > On Sat, Jan 2, 2016 at 8:48 PM, Marko Rauhamaa wrote: >> Having struggled with Perforce, SVN and CVS, I was hopeful Mercurial >> would be everything Teamware was. >> >> Unfortunately, it wasn't. The big disappointment was the treatment of >> a repository as the atomic unit. > > You'll need to elaborate on this. Is a repository too large or too > small as an atomic unit? If a repository contains independent changes, Hg and Git fail to understand that the changes could be independent and force you to resolve a merge conflict where no real conflict exists. The whole philosophy of dependent and independent changes is complicated; only Darcs has attempted to address the issue scientifically (). However, Teamware chose an opportune approximation by treating each file's version history independently. Teamware's approach works nicely for backporting. You often fix a bug in the development version and would like to propagate the fix to an older version (= branch/stream/fork) of the product. In Teamware, the propagation would not generate a conflict so it doesn't need to be resolved. No special cherrypicking is involved, and afterwards, you can't tell if the change was made first to the old version/branch/stream/fork or the new one. (Teamware didn't have branches. It always used forks. I believe Hg is/was the same way. Git, which is what I have to use nowadays, has branches but I find little use for them.) Marko From rosuav at gmail.com Sat Jan 2 06:40:51 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jan 2016 22:40:51 +1100 Subject: We will be moving to GitHub In-Reply-To: <87k2ns1b0d.fsf@elektro.pacujo.net> References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> <87oad41fd4.fsf@elektro.pacujo.net> <87k2ns1b0d.fsf@elektro.pacujo.net> Message-ID: On Sat, Jan 2, 2016 at 10:22 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sat, Jan 2, 2016 at 8:48 PM, Marko Rauhamaa wrote: >>> Having struggled with Perforce, SVN and CVS, I was hopeful Mercurial >>> would be everything Teamware was. >>> >>> Unfortunately, it wasn't. The big disappointment was the treatment of >>> a repository as the atomic unit. >> >> You'll need to elaborate on this. Is a repository too large or too >> small as an atomic unit? > > If a repository contains independent changes, Hg and Git fail to > understand that the changes could be independent and force you to > resolve a merge conflict where no real conflict exists. > > The whole philosophy of dependent and independent changes is > complicated; only Darcs has attempted to address the issue > scientifically (). > However, Teamware chose an opportune approximation by treating each > file's version history independently. I don't think you understand the meaning of "merge conflict", then. A merge conflict is when you cannot simply merge the changes. If the changes are on separate files, neither git nor hg will find this to be a conflict, and the merge will happen automatically. Alternatively, you can rebase rather than merging (git's term; Mercurial has a similar concept for saying "put my private changes on top of the history", but I can't remember the name), which again will succeed automatically if the changes are to different files. Even better, the merge/rebase will generally succeed even if the changes are to the same file, as long as they're to different parts of it. Play to a tool's strengths rather than its weaknesses, and you'll find life a lot less frustrating. I'm fairly sure you could use the same workflow with git as you were accustomed to with Teamware, only with a few different names for things. And most likely Mercurial too, but again, there'll be different names. Maybe you'll use branches for what you used to use forks for, or maybe you'll have multiple clones of the same repository, or maybe some other arrangement. Get to know some of the myriad ways you can use modern source control systems, and find a workflow that suits you. ChrisA From dfnsonfsduifb at gmx.de Sat Jan 2 06:47:45 2016 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Sat, 2 Jan 2016 12:47:45 +0100 Subject: raise None In-Reply-To: References: <56847239$0$1590$c3e8da3$5496439d@news.astraweb.com> <5684842a$0$1596$c3e8da3$5496439d@news.astraweb.com> <5684aa1a$0$1602$c3e8da3$5496439d@news.astraweb.com> <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 31.12.2015 21:18, Ben Finney wrote: > As best I can tell, Steven is advocating a way to obscure information > from the traceback, on the assumption the writer of a library knows that > I don't want to see it. How do you arrive at that conclusion? The line that raises the exception is exactly the line that you would expect the exception to be raised. I.e., the one containing the "raise" statement. What you seem to advocate against is a feature that is ALREADY part of the language, i.e. raising exceptions by reference to a variable, not constructing them on-the-go. Your argumentation makes therefore no sense in this context. Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From katye2007 at gmail.com Sat Jan 2 06:49:35 2016 From: katye2007 at gmail.com (katye2007 at gmail.com) Date: Sat, 2 Jan 2016 03:49:35 -0800 (PST) Subject: Trailing zeros of 100! Message-ID: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Hi, newbie here! I'm trying to write a python program to find how many trailing zeros are in 100! (factorial of 100). I used factorial from the math module, but my efforts to continue failed. Please help. Thank you, Yehuda From bouncingcats at gmail.com Sat Jan 2 07:19:00 2016 From: bouncingcats at gmail.com (David) Date: Sat, 2 Jan 2016 23:19:00 +1100 Subject: Trailing zeros of 100! In-Reply-To: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: On 2 January 2016 at 22:49, wrote: > Hi, newbie here! Hi Yehuda > I'm trying to write a python program to find how many trailing zeros are in 100! (factorial of 100). > I used factorial from the math module, but my efforts to continue failed. Please help. There is a special mailing list to help newbies write code: https://mail.python.org/mailman/listinfo/tutor Subscribe to that list and post whatever *code you have already written* there, and explain exactly how you want it to be better. From katye2007 at gmail.com Sat Jan 2 07:34:24 2016 From: katye2007 at gmail.com (katye2007 at gmail.com) Date: Sat, 2 Jan 2016 04:34:24 -0800 (PST) Subject: Trailing zeros of 100! In-Reply-To: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: On Saturday, January 2, 2016 at 1:49:47 PM UTC+2, katy... at gmail.com wrote: > Hi, newbie here! > I'm trying to write a python program to find how many trailing zeros are in 100! (factorial of 100). > I used factorial from the math module, but my efforts to continue failed. Please help. > > Thank you, > Yehuda Thank ou, David, for your help and kindness. From rxjwg98 at gmail.com Sat Jan 2 07:44:10 2016 From: rxjwg98 at gmail.com (Robert) Date: Sat, 2 Jan 2016 04:44:10 -0800 (PST) Subject: What meaning is '[: , None]'? Message-ID: <5607ba13-100b-411c-824a-de80c3c52e33@googlegroups.com> Hi, I read a code snippet, in which object w_A is: w_A Out[48]: array([ 0.10708809, 0.94933575, 0.8412686 , 0.03280939, 0.59985308]) Then, I don't know what is '[: ' below: vs_A = w_A[:, None] * xs I don't find the answer after searching around Could you explain above code to me? Thanks, From vlastimil.brom at gmail.com Sat Jan 2 07:44:26 2016 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 2 Jan 2016 13:44:26 +0100 Subject: Trailing zeros of 100! In-Reply-To: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: 2016-01-02 12:49 GMT+01:00 : > Hi, newbie here! > I'm trying to write a python program to find how many trailing zeros are in 100! (factorial of 100). > I used factorial from the math module, but my efforts to continue failed. Please help. > > Thank you, > Yehuda > -- > https://mail.python.org/mailman/listinfo/python-list Hi, rather an illustration of the available tools in python, than a (submittable) solution: >>> import re, math >>> len(re.search(r"0*$", str(math.factorial(100))).group()) 24 [or the same code on more lines with some indentation - if it is preserved via e-mail] >>> len( ... re.search( ... r"0*$", ... str( ... math.factorial(100) ... ) ... ).group() ... ) 24 >>> I.e. You need the length of the string resulting as the match of the regular expression search for a pattern representing zero or more "0" at the end of the input text, which is the string version of 100! Of course, there are other ways to get this result :-) regards, vbr From python.list at tim.thechases.com Sat Jan 2 07:58:17 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 2 Jan 2016 06:58:17 -0600 Subject: We will be moving to GitHub In-Reply-To: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20160102065817.7c545f94@bigbox.christie.dr> On 2016-01-02 17:43, Steven D'Aprano wrote: > Oh, and talking about DVCS: > > https://bitquabit.com/post/unorthodocs-abandon-your-dvcs-and-return-to-sanity/ The arguments there are pretty weak. Not working offline? I use that *ALL* *THE* *TIME*. Maybe the author lives some place where the main internet connection doesn't go down for a week because some dim bulb at AT&T disconnected the wrong cable and failed to log the fact. Maybe the author is willing to shell out highway-robbery prices for wifi on an airplane just to access repo history. Maybe the author has an unlimited data plan and good coverage. But for me, disconnected usage (along with the much easier/smarter branching & merging) is one of the indispensable features. Just because the author doesn't use a feature, doesn't mean it's useful. Consider the author's case for storing large binary blobs in a VCS and then not wanting to check out the entire repo. However, to use/tweak the logic & phrasing of the article, "Let me tell you something. Of all the time I have ever used DVCSes, over the last 15 years if we count dropping large binary files in a shared folder and eight or so if you don?t, I have wanted to store large binary files in the repository a grand total of maybe about zero times. And this is merely going down over time as CPU, memory, and storage capacity ever increases. If you work as a CGI animator/artist, or produce audio, or don't know what you're doing because you're storing generated output, then okay, sure, this is a huge feature for you. But for the rest of us, I am going to assert that this is not the use case you need to optimize for when choosing a VCS." So while I don't really have dog in the fight of git-vs-hg-vs-bzr-vs-fossil or the GitHub-vs-Bitbucket-vs-GitLab-vs-privately-hosted fight, I find the logic of that article as strained as when I first read it. -tkc From katye2007 at gmail.com Sat Jan 2 08:14:34 2016 From: katye2007 at gmail.com (yehudak .) Date: Sat, 2 Jan 2016 15:14:34 +0200 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: Vlastimil, Thank you so much, but... All that is Chinese for me. Can you show a 'normal' Python code for me? Yehuda On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom wrote: > 2016-01-02 12:49 GMT+01:00 : > > Hi, newbie here! > > I'm trying to write a python program to find how many trailing zeros are > in 100! (factorial of 100). > > I used factorial from the math module, but my efforts to continue > failed. Please help. > > > > Thank you, > > Yehuda > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Hi, > rather an illustration of the available tools in python, than a > (submittable) solution: > > >>> import re, math > >>> len(re.search(r"0*$", str(math.factorial(100))).group()) > 24 > [or the same code on more lines with some indentation - if it is > preserved via e-mail] > >>> len( > ... re.search( > ... r"0*$", > ... str( > ... math.factorial(100) > ... ) > ... ).group() > ... ) > 24 > >>> > > I.e. You need the length of the string resulting as the match of the > regular expression search for a pattern representing zero or more "0" > at the end of the input text, which is the string version of 100! > > Of course, there are other ways to get this result :-) > > regards, > vbr > From mafagafogigante at gmail.com Sat Jan 2 09:13:18 2016 From: mafagafogigante at gmail.com (Bernardo Sulzbach) Date: Sat, 2 Jan 2016 12:13:18 -0200 Subject: We will be moving to GitHub In-Reply-To: References: Message-ID: On Sat, Jan 2, 2016 at 5:12 AM, Chris Angelico wrote: > On Sat, Jan 2, 2016 at 5:43 PM, Steven D'Aprano wrote: >> There are times where everybody should do the same thing -- choosing whether >> to drive on the left or the right side of the road, for example. And there >> are times where following the crowd like lemmings is actively harmful, no >> matter how convenient it seems in the short-run. > > The popularity of technology IS an argument in its favour, though. How > many people here use Gopher instead of HTTP? Would it be better to > serve Python content on the obscure protocol rather than the popular > one? When 99% of people know how to use one technology and 1% know how > to use a different one, it's advantageous to go where the people are. > (Of course, there are other considerations, too - PHP is popular, but > that alone isn't a reason to use it. The context here is of > technologies so similar in functionality that we really CAN make a > decision on these kinds of bases.) > > The Python project *needs* new contributors. This is not in question. > You can't expect to keep the project going solely on the basis of the > people currently writing and applying patches. So there are two > options: > I must agree with Chris, visibility in OSS is key of it. If you write a library and license it under BSD 3-Clause but keep it in your local network forever it is not as open as if you would throw it in GitHub. There are many people there, and there are many people willing to at least review the code of interesting projects. From marko at pacujo.net Sat Jan 2 09:26:26 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 02 Jan 2016 16:26:26 +0200 Subject: We will be moving to GitHub References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> <87oad41fd4.fsf@elektro.pacujo.net> <87k2ns1b0d.fsf@elektro.pacujo.net> Message-ID: <87ege012i5.fsf@elektro.pacujo.net> Chris Angelico : > I don't think you understand the meaning of "merge conflict", then. A > merge conflict is when you cannot simply merge the changes. A conflict is when there have been two parallel changes to the same versioned target. In the case of Hg and Git, the whole repo is the target. > If the changes are on separate files, neither git nor hg will find > this to be a conflict, and the merge will happen automatically. They can propose to resolve the conflict automatically, which, BTW, undermines the very idea of treating the whole repo as an atomic target. Hg and Git think it's too dangerous to trust changes to individual files are independent, but then, the alleviate the resulting pain, they offer to treat the changes independently anyway, giving you the downsides while sacrificing the (purported) upsides. > Alternatively, you can rebase rather than merging (git's term; > Mercurial has a similar concept for saying "put my private changes on > top of the history", but I can't remember the name), which again will > succeed automatically if the changes are to different files. Even > better, the merge/rebase will generally succeed even if the changes > are to the same file, as long as they're to different parts of it. In Teamware, push ("putback") will simply succeed without any need to resolve the merge conflict (automatically, or otherwise). > Play to a tool's strengths rather than its weaknesses, and you'll find > life a lot less frustrating. I'm fairly sure you could use the same > workflow with git as you were accustomed to with Teamware, only with a > few different names for things. And most likely Mercurial too, but > again, there'll be different names. Maybe you'll use branches for what > you used to use forks for, or maybe you'll have multiple clones of the > same repository, or maybe some other arrangement. Get to know some of > the myriad ways you can use modern source control systems, and find a > workflow that suits you. As I said, the problem is nonexistent when your repositories are tiny (~ 5-20 files) and each is actively maintained by a single person. Marko From rosuav at gmail.com Sat Jan 2 09:38:32 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jan 2016 01:38:32 +1100 Subject: We will be moving to GitHub In-Reply-To: <87ege012i5.fsf@elektro.pacujo.net> References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> <87oad41fd4.fsf@elektro.pacujo.net> <87k2ns1b0d.fsf@elektro.pacujo.net> <87ege012i5.fsf@elektro.pacujo.net> Message-ID: On Sun, Jan 3, 2016 at 1:26 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> I don't think you understand the meaning of "merge conflict", then. A >> merge conflict is when you cannot simply merge the changes. > > A conflict is when there have been two parallel changes to the same > versioned target. In the case of Hg and Git, the whole repo is the > target. No, that's just a merge. https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging ChrisA From marko at pacujo.net Sat Jan 2 09:52:15 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 02 Jan 2016 16:52:15 +0200 Subject: We will be moving to GitHub References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> <87oad41fd4.fsf@elektro.pacujo.net> <87k2ns1b0d.fsf@elektro.pacujo.net> <87ege012i5.fsf@elektro.pacujo.net> Message-ID: <87a8oo11b4.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Jan 3, 2016 at 1:26 AM, Marko Rauhamaa wrote: >> A conflict is when there have been two parallel changes to the same >> versioned target. In the case of Hg and Git, the whole repo is the >> target. > > No, that's just a merge. > > https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging Terminology aside, if I do this with Git: -----+--------------------+--------> \ ^ \pull /push v / +--------------+ edit everything goes in without any further ado. However, this operation will be blocked by Git: --+--+--------------------+----+---> \ \ ^ X \ \pull /push/ \ v / / pull\ +--------------+ /push \ edit / v / +-----------------+ Not so by Teamware as long as the pushes don't have files in common. Marko From joel.goldstick at gmail.com Sat Jan 2 09:57:26 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 2 Jan 2016 09:57:26 -0500 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: On Sat, Jan 2, 2016 at 8:14 AM, yehudak . wrote: > Vlastimil, > Thank you so much, but... > All that is Chinese for me. > Can you show a 'normal' Python code for me? > > Yehuda > > On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom > wrote: > > > 2016-01-02 12:49 GMT+01:00 : > > > Hi, newbie here! > > > I'm trying to write a python program to find how many trailing zeros > are > > in 100! (factorial of 100). > > > I used factorial from the math module, but my efforts to continue > > failed. Please help. > > > > > > Thank you, > > > Yehuda > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > Hi, > > rather an illustration of the available tools in python, than a > > (submittable) solution: > > > > >>> import re, math > > >>> len(re.search(r"0*$", str(math.factorial(100))).group()) > > 24 > > [or the same code on more lines with some indentation - if it is > > preserved via e-mail] > > >>> len( > > ... re.search( > > ... r"0*$", > > ... str( > > ... math.factorial(100) > > ... ) > > ... ).group() > > ... ) > > 24 > > >>> > > > > I.e. You need the length of the string resulting as the match of the > > regular expression search for a pattern representing zero or more "0" > > at the end of the input text, which is the string version of 100! > > > > Of course, there are other ways to get this result :-) > > > > regards, > > vbr > > > -- > https://mail.python.org/mailman/listinfo/python-list > Can you improve your question? Which python version, which os are standard to tell. Also, show the code you have written, its output, and what you think is wrong with it. This might be homework, since it is a very contrived problem. But to push you forward: Can you get the factorial? Can you get the string of that result? Do you know about lists, and slicing, and reversing a list (hint: a = "123", b = a[::-1] will return "321" If you know these concepts, and know how to loop and count, you can solve your puzzle -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From rosuav at gmail.com Sat Jan 2 10:12:44 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jan 2016 02:12:44 +1100 Subject: We will be moving to GitHub In-Reply-To: <87a8oo11b4.fsf@elektro.pacujo.net> References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> <87oad41fd4.fsf@elektro.pacujo.net> <87k2ns1b0d.fsf@elektro.pacujo.net> <87ege012i5.fsf@elektro.pacujo.net> <87a8oo11b4.fsf@elektro.pacujo.net> Message-ID: On Sun, Jan 3, 2016 at 1:52 AM, Marko Rauhamaa wrote: > Terminology aside, if I do this with Git: > > -----+--------------------+--------> > \ ^ > \pull /push > v / > +--------------+ > edit > > everything goes in without any further ado. > > However, this operation will be blocked by Git: > > > --+--+--------------------+----+---> > \ \ ^ X > \ \pull /push/ > \ v / / > pull\ +--------------+ /push > \ edit / > v / > +-----------------+ > > Not so by Teamware as long as the pushes don't have files in common. Ah, I see what you mean. That's a constantly-debated point, and it's actually possible to make git accept this, although it's not a normal workflow. Instead, you just 'git pull' (possibly with --rebase) before you 'git push'. You either create a new merge commit, or make it very clear that you are changing your commits to pretend they were committed after the already-pushed ones. Or you do a force-push and discard the other commits (this is correct if you amended a commit). You HAVE to choose because these are three viable solutions, and only a human can make the decision. Teamware presumably picked one of them, and doesn't give you the other two choices. The price you pay for power is complexity. But with a little bit of tooling, you can hide that complexity from day-to-day usage - it means writing a git hook, but don't be scared off by that; they're just simple scripts! ChrisA From vlastimil.brom at gmail.com Sat Jan 2 10:24:36 2016 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 2 Jan 2016 16:24:36 +0100 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: 2016-01-02 14:14 GMT+01:00 yehudak . : > Vlastimil, > Thank you so much, but... > All that is Chinese for me. > Can you show a 'normal' Python code for me? > > Yehuda > > On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom > wrote: >> >> 2016-01-02 12:49 GMT+01:00 : >> > Hi, newbie here! >> > I'm trying to write a python program to find how many trailing zeros are >> > in 100! (factorial of 100). >> > I used factorial from the math module, but my efforts to continue >> > failed. Please help. >> > >> > Thank you, >> > Yehuda >> > -- >> > https://mail.python.org/mailman/listinfo/python-list >> >> Hi, >> rather an illustration of the available tools in python, than a >> (submittable) solution: >> >> >>> import re, math >> >>> len(re.search(r"0*$", str(math.factorial(100))).group()) >> 24 >> [or the same code on more lines with some indentation - if it is >> preserved via e-mail] >> >>> len( >> ... re.search( >> ... r"0*$", >> ... str( >> ... math.factorial(100) >> ... ) >> ... ).group() >> ... ) >> 24 >> >>> >> >> I.e. You need the length of the string resulting as the match of the >> regular expression search for a pattern representing zero or more "0" >> at the end of the input text, which is the string version of 100! >> >> Of course, there are other ways to get this result :-) >> >> regards, >> vbr > > Hi, If you eventually have this as an assignment or other kind of (self)learning task, you would want to approach this with the methods you know, or are supposed to use. For the math context, you may find this explanations useful: http://www.purplemath.com/modules/factzero.htm a rather straightforward python implementation of this seems to be e.g. this recipe: http://code.activestate.com/recipes/577844-calculate-trailing-zeroes-in-a-factorial/ Note, that you don't need to calculate the value of the factorial itself using this way. If you have problems with following or understanding the code, you may show your own attempts and tell what problems you encounter with your approach. My previous code sample is based on another - "brute-force" approach, the factorial is calculated (e.g. via the math module as you have found), then the integer is converted to a string, afterwards the part of the result consisting only of zeros - at the end of the string is matched with a regular expression and finally the length of it is determined. Regular expressions might be handy, but are not necesarilly elementary stuff for a newcomer in python programming. You can count the trailing zeros in other ways too - as was suggested - you can reverse the string and count from the beginning then, stopping before the first non-zero digit. The most straightforward way could be to loop (characterwise) through the (reversed) string, check each character whether it equals to "0" and stop as soon as there is another digit. hth, vbr From breamoreboy at yahoo.co.uk Sat Jan 2 10:30:09 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 2 Jan 2016 15:30:09 +0000 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: On 02/01/2016 13:14, yehudak . wrote: > Vlastimil, > Thank you so much, but... > All that is Chinese for me. > Can you show a 'normal' Python code for me? > > Yehuda > > On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom > wrote: > >> 2016-01-02 12:49 GMT+01:00 : >>> Hi, newbie here! >>> I'm trying to write a python program to find how many trailing zeros are >> in 100! (factorial of 100). >>> I used factorial from the math module, but my efforts to continue >> failed. Please help. >>> >>> Thank you, >>> Yehuda >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >> >> Hi, >> rather an illustration of the available tools in python, than a >> (submittable) solution: >> >>>>> import re, math >>>>> len(re.search(r"0*$", str(math.factorial(100))).group()) >> 24 >> [or the same code on more lines with some indentation - if it is >> preserved via e-mail] >>>>> len( >> ... re.search( >> ... r"0*$", >> ... str( >> ... math.factorial(100) >> ... ) >> ... ).group() >> ... ) >> 24 >>>>> >> >> I.e. You need the length of the string resulting as the match of the >> regular expression search for a pattern representing zero or more "0" >> at the end of the input text, which is the string version of 100! >> >> Of course, there are other ways to get this result :-) >> >> regards, >> vbr >> I'll explain it if you stop top posting. -- 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 Jan 2 10:39:36 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 03 Jan 2016 02:39:36 +1100 Subject: What meaning is '[: , None]'? References: <5607ba13-100b-411c-824a-de80c3c52e33@googlegroups.com> Message-ID: <5687ef39$0$1588$c3e8da3$5496439d@news.astraweb.com> On Sat, 2 Jan 2016 11:44 pm, Robert wrote: > Hi, > > I read a code snippet, in which object w_A is: > > > w_A > Out[48]: array([ 0.10708809, 0.94933575, 0.8412686 , 0.03280939, > 0.59985308]) w_A looks like a numpy array of five values. http://docs.scipy.org/doc/numpy/reference/arrays.html > Then, I don't know what is '[: ' below: > vs_A = w_A[:, None] * xs The syntax w_A[ ... ] is a "slice" of array w_A. Slicing means to create a new array from part of the original. None inside a numpy slice behaves as an alias for numpy.newaxis. http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html In this case, w_A[:, None] returns a "view" of the original w_A array. -- Steven From rustompmody at gmail.com Sat Jan 2 10:41:51 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 2 Jan 2016 07:41:51 -0800 (PST) Subject: What meaning is '[: , None]'? In-Reply-To: <5607ba13-100b-411c-824a-de80c3c52e33@googlegroups.com> References: <5607ba13-100b-411c-824a-de80c3c52e33@googlegroups.com> Message-ID: <335bf0cc-b25e-43b6-be0a-94a94ce0eb73@googlegroups.com> On Saturday, January 2, 2016 at 6:14:24 PM UTC+5:30, Robert wrote: > Hi, > > I read a code snippet, in which object w_A is: > > > w_A > Out[48]: array([ 0.10708809, 0.94933575, 0.8412686 , 0.03280939, 0.59985308]) > > > Then, I don't know what is '[: ' below: > vs_A = w_A[:, None] * xs > > > I don't find the answer after searching around > Could you explain above code to me? > Thanks, You probably want to search for 'slice/slicing' and 'indexing' I get this http://docs.scipy.org/doc/numpy-1.10.0/reference/arrays.indexing.html [Note: I dont know much about this] From robin.koch at t-online.de Sat Jan 2 10:54:23 2016 From: robin.koch at t-online.de (Robin Koch) Date: Sat, 2 Jan 2016 16:54:23 +0100 Subject: Trailing zeros of 100! In-Reply-To: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: Am 02.01.2016 um 12:49 schrieb katye2007 at gmail.com: > I'm trying to write a python program to find how many trailing zeros > are in 100! (factorial of 100). I used factorial from the math > module, but my efforts to continue failed. Please help. Using not Python, but math: Every "0" at the end of 100! represents a multiplication by the factor 10 or the factors 2 and 5. There are 20 numbers with at least one factor 5. There are 4 numbers with at least two factors 5 (=25). There are no numbers with three factors 5 (=125). There are 50 numbers with at least one factor 2. So 100! contains 24 factors 5 and even more factors 2. So 100! contains 24 facotrs 10 and therefore has 24 trailing zeros. -- Robin Koch From robin.koch at t-online.de Sat Jan 2 10:57:48 2016 From: robin.koch at t-online.de (Robin Koch) Date: Sat, 2 Jan 2016 16:57:48 +0100 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: Am 02.01.2016 um 14:14 schrieb yehudak .: > Thank you so much, but... > All that is Chinese for me. > Can you show a 'normal' Python code for me? How about: >>> from math import log >>> sum([int(0.2**k*n) for k in range(1, int(log(n, 5))+1)]) }:-) (That implements my procedure in my other answer.) -- Robin Koch From tony at vanderhoff.org Sat Jan 2 11:09:06 2016 From: tony at vanderhoff.org (Tony van der Hoff) Date: Sat, 02 Jan 2016 17:09:06 +0100 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: <5687F622.3010208@vanderhoff.org> On 02/01/16 16:57, Robin Koch wrote: > sum([int(0.2**k*n) for k in range(1, int(log(n, 5))+1)]) But did you actually test it? -- Tony van der Hoff | mailto:tony at vanderhoff.org Ari?ge, France | From python.list at tim.thechases.com Sat Jan 2 11:33:01 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 2 Jan 2016 10:33:01 -0600 Subject: Trailing zeros of 100! In-Reply-To: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: <20160102103301.58b3e8ff@bigbox.christie.dr> On 2016-01-02 03:49, katye2007 at gmail.com wrote: > I'm trying to write a python program to find how many trailing > zeros are in 100! (factorial of 100). I used factorial from the > math module, but my efforts to continue failed. Please help. Pretty easy to do with strings: from math import factorial n = factorial(100) s = str(n) print(len(s) - len(s.rstrip('0'))) or count them: from itertools import takewhile sum(1 for _ in takewhile(lambda c: c == '0', reversed(s))) or mathematically: sum(1 for _ in itertools.takewhile( lambda x: n % (10**x) == 0, itertools.count(1))) -tkc From robin.koch at t-online.de Sat Jan 2 11:56:44 2016 From: robin.koch at t-online.de (Robin Koch) Date: Sat, 2 Jan 2016 17:56:44 +0100 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: Am 02.01.2016 um 17:09 schrieb Tony van der Hoff: > On 02/01/16 16:57, Robin Koch wrote: >> sum([int(0.2**k*n) for k in range(1, int(log(n, 5))+1)]) > > But did you actually test it? Yes, should work for n >= 1. Why do you ask? -- Robin Koch From __peter__ at web.de Sat Jan 2 12:18:05 2016 From: __peter__ at web.de (Peter Otten) Date: Sat, 02 Jan 2016 18:18:05 +0100 Subject: Trailing zeros of 100! References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: Robin Koch wrote: > Am 02.01.2016 um 12:49 schrieb katye2007 at gmail.com: > >> I'm trying to write a python program to find how many trailing zeros >> are in 100! (factorial of 100). I used factorial from the math >> module, but my efforts to continue failed. Please help. > > Using not Python, but math: > > Every "0" at the end of 100! represents a multiplication by the factor > 10 or the factors 2 and 5. > > There are 20 numbers with at least one factor 5. > There are 4 numbers with at least two factors 5 (=25). > There are no numbers with three factors 5 (=125). > > There are 50 numbers with at least one factor 2. > > So 100! contains 24 factors 5 and even more factors 2. > So 100! contains 24 facotrs 10 and therefore has 24 trailing zeros. Spelt in Python: >>> def trailing_zeros_fact(n): ... total = 0 ... while n: ... n //= 5 ... total += n ... return total ... >>> trailing_zeros_fact(100) 24 >>> trailing_zeros_fact(math.factorial(100)) 23331553860986038170424809714066675122678992066095405367148240973804399998307478902235365994039129571563424480206805939562796302729215999999999999999999999901 From mafagafogigante at gmail.com Sat Jan 2 12:24:24 2016 From: mafagafogigante at gmail.com (Bernardo Sulzbach) Date: Sat, 2 Jan 2016 15:24:24 -0200 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: On Sat, Jan 2, 2016 at 2:56 PM, Robin Koch wrote: > > Yes, should work for n >= 1. > The first power of 10 for which it fails in my machine is 10 ^ 17, which is not that much for modern computers. Discrete math should not meet floating points. I would post the "canonical" solution here if Peter Otten hadn't just posted it. You can use Wolfram Alpha - or Otten's solution - to see that your solution fails for inputs equal to and larger than 10^17 (there likely is a lower bound, but I won't do binary search to find it). -- Bernardo Sulzbach From katye2007 at gmail.com Sat Jan 2 12:34:19 2016 From: katye2007 at gmail.com (yehudak .) Date: Sat, 2 Jan 2016 19:34:19 +0200 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: vbr, I tried using .pop() but could not get what I wanted .Also, I can't see an advantage in reversing the number. Would you care to write explicitly the program for me (and probably for other too)? Brute Force is the style I'm thinking about. Sorry, but I learn most from viewing the code. Appreciated, Yehuda On Sat, Jan 2, 2016 at 5:24 PM, Vlastimil Brom wrote: > 2016-01-02 14:14 GMT+01:00 yehudak . : > > Vlastimil, > > Thank you so much, but... > > All that is Chinese for me. > > Can you show a 'normal' Python code for me? > > > > Yehuda > > > > On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom > > > wrote: > >> > >> 2016-01-02 12:49 GMT+01:00 : > >> > Hi, newbie here! > >> > I'm trying to write a python program to find how many trailing zeros > are > >> > in 100! (factorial of 100). > >> > I used factorial from the math module, but my efforts to continue > >> > failed. Please help. > >> > > >> > Thank you, > >> > Yehuda > >> > -- > >> > https://mail.python.org/mailman/listinfo/python-list > >> > >> Hi, > >> rather an illustration of the available tools in python, than a > >> (submittable) solution: > >> > >> >>> import re, math > >> >>> len(re.search(r"0*$", str(math.factorial(100))).group()) > >> 24 > >> [or the same code on more lines with some indentation - if it is > >> preserved via e-mail] > >> >>> len( > >> ... re.search( > >> ... r"0*$", > >> ... str( > >> ... math.factorial(100) > >> ... ) > >> ... ).group() > >> ... ) > >> 24 > >> >>> > >> > >> I.e. You need the length of the string resulting as the match of the > >> regular expression search for a pattern representing zero or more "0" > >> at the end of the input text, which is the string version of 100! > >> > >> Of course, there are other ways to get this result :-) > >> > >> regards, > >> vbr > > > > > Hi, > If you eventually have this as an assignment or other kind of > (self)learning task, you would want to approach this with the methods > you know, or are supposed to use. > For the math context, you may find this explanations useful: > http://www.purplemath.com/modules/factzero.htm > a rather straightforward python implementation of this seems to be > e.g. this recipe: > > http://code.activestate.com/recipes/577844-calculate-trailing-zeroes-in-a-factorial/ > Note, that you don't need to calculate the value of the factorial > itself using this way. > If you have problems with following or understanding the code, you may > show your own attempts and tell what problems you encounter with your > approach. > > My previous code sample is based on another - "brute-force" approach, > the factorial is calculated (e.g. via the math module as you have > found), then the integer is converted to a string, afterwards the part > of the result consisting only of zeros - at the end of the string is > matched with a regular expression and finally the length of it is > determined. > > Regular expressions might be handy, but are not necesarilly elementary > stuff for a newcomer in python programming. > You can count the trailing zeros in other ways too - as was suggested > - you can reverse the string and count from the beginning then, > stopping before the first non-zero digit. > The most straightforward way could be to loop (characterwise) through > the (reversed) string, check each character whether it equals to "0" > and stop as soon as there is another digit. > > hth, > vbr > From breamoreboy at yahoo.co.uk Sat Jan 2 12:44:06 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 2 Jan 2016 17:44:06 +0000 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: On 02/01/2016 17:34, yehudak . wrote: > vbr, > I tried using .pop() but could not get what I wanted .Also, I can't see an > advantage in reversing the number. > Would you care to write explicitly the program for me (and probably for > other too)? > Brute Force is the style I'm thinking about. > > Sorry, but I learn most from viewing the code. > > Appreciated, > Yehuda > > On Sat, Jan 2, 2016 at 5:24 PM, Vlastimil Brom > wrote: > >> 2016-01-02 14:14 GMT+01:00 yehudak . : >>> Vlastimil, >>> Thank you so much, but... >>> All that is Chinese for me. >>> Can you show a 'normal' Python code for me? >>> >>> Yehuda >>> >>> On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom >> >>> wrote: >>>> >>>> 2016-01-02 12:49 GMT+01:00 : >>>>> Hi, newbie here! >>>>> I'm trying to write a python program to find how many trailing zeros >> are >>>>> in 100! (factorial of 100). >>>>> I used factorial from the math module, but my efforts to continue >>>>> failed. Please help. >>>>> >>>>> Thank you, >>>>> Yehuda >>>>> -- >>>>> https://mail.python.org/mailman/listinfo/python-list >>>> >>>> Hi, >>>> rather an illustration of the available tools in python, than a >>>> (submittable) solution: >>>> >>>>>>> import re, math >>>>>>> len(re.search(r"0*$", str(math.factorial(100))).group()) >>>> 24 >>>> [or the same code on more lines with some indentation - if it is >>>> preserved via e-mail] >>>>>>> len( >>>> ... re.search( >>>> ... r"0*$", >>>> ... str( >>>> ... math.factorial(100) >>>> ... ) >>>> ... ).group() >>>> ... ) >>>> 24 >>>>>>> >>>> >>>> I.e. You need the length of the string resulting as the match of the >>>> regular expression search for a pattern representing zero or more "0" >>>> at the end of the input text, which is the string version of 100! >>>> >>>> Of course, there are other ways to get this result :-) >>>> >>>> regards, >>>> vbr >>> >>> >> Hi, >> If you eventually have this as an assignment or other kind of >> (self)learning task, you would want to approach this with the methods >> you know, or are supposed to use. >> For the math context, you may find this explanations useful: >> http://www.purplemath.com/modules/factzero.htm >> a rather straightforward python implementation of this seems to be >> e.g. this recipe: >> >> http://code.activestate.com/recipes/577844-calculate-trailing-zeroes-in-a-factorial/ >> Note, that you don't need to calculate the value of the factorial >> itself using this way. >> If you have problems with following or understanding the code, you may >> show your own attempts and tell what problems you encounter with your >> approach. >> >> My previous code sample is based on another - "brute-force" approach, >> the factorial is calculated (e.g. via the math module as you have >> found), then the integer is converted to a string, afterwards the part >> of the result consisting only of zeros - at the end of the string is >> matched with a regular expression and finally the length of it is >> determined. >> >> Regular expressions might be handy, but are not necesarilly elementary >> stuff for a newcomer in python programming. >> You can count the trailing zeros in other ways too - as was suggested >> - you can reverse the string and count from the beginning then, >> stopping before the first non-zero digit. >> The most straightforward way could be to loop (characterwise) through >> the (reversed) string, check each character whether it equals to "0" >> and stop as soon as there is another digit. >> >> hth, >> vbr >> You'll learn far more if you try writing code and then get help if it doesn't work, rather than get other people to write the code for you. Please don't top post, it's extremely annoying when trying to follow long threads. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From storchaka at gmail.com Sat Jan 2 13:28:36 2016 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sat, 2 Jan 2016 20:28:36 +0200 Subject: Trailing zeros of 100! In-Reply-To: <20160102103301.58b3e8ff@bigbox.christie.dr> References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> <20160102103301.58b3e8ff@bigbox.christie.dr> Message-ID: On 02.01.16 18:33, Tim Chase wrote: > or mathematically: > > sum(1 for _ in itertools.takewhile( > lambda x: n % (10**x) == 0, > itertools.count(1))) The mathematician would prove that the result is not larger than 100/4. From vlastimil.brom at gmail.com Sat Jan 2 13:29:37 2016 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 2 Jan 2016 19:29:37 +0100 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: 2016-01-02 18:34 GMT+01:00 yehudak . : [partly edited for bottom posting] > On Sat, Jan 2, 2016 at 5:24 PM, Vlastimil Brom > wrote: >> >> 2016-01-02 14:14 GMT+01:00 yehudak . : >> > [...]>> > On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom >> > >> > wrote: >> >> >> >> 2016-01-02 12:49 GMT+01:00 : >> >> > Hi, newbie here! >> >> > I'm trying to write a python program to find how many trailing zeros >> >> > are >> >> > in 100! (factorial of 100). >> >> > I used factorial from the math module, but my efforts to continue >> >> > failed. Please help. >> >> > >> >> > Thank you, >> >> > Yehuda >> >> > -- >> >> > https://mail.python.org/mailman/listinfo/python-list >> >> >> > [...] >> > >> Hi, >> If you eventually have this as an assignment or other kind of >> (self)learning task, you would want to approach this with the methods >> you know, or are supposed to use. >> For the math context, you may find this explanations useful: >> http://www.purplemath.com/modules/factzero.htm >> a rather straightforward python implementation of this seems to be >> e.g. this recipe: >> >> http://code.activestate.com/recipes/577844-calculate-trailing-zeroes-in-a-factorial/ >> Note, that you don't need to calculate the value of the factorial >> itself using this way. >> If you have problems with following or understanding the code, you may >> show your own attempts and tell what problems you encounter with your >> approach. >> >> My previous code sample is based on another - "brute-force" approach, >> the factorial is calculated (e.g. via the math module as you have >> found), then the integer is converted to a string, afterwards the part >> of the result consisting only of zeros - at the end of the string is >> matched with a regular expression and finally the length of it is >> determined. >> >> Regular expressions might be handy, but are not necesarilly elementary >> stuff for a newcomer in python programming. >> You can count the trailing zeros in other ways too - as was suggested >> - you can reverse the string and count from the beginning then, >> stopping before the first non-zero digit. >> The most straightforward way could be to loop (characterwise) through >> the (reversed) string, check each character whether it equals to "0" >> and stop as soon as there is another digit. >> >> hth, >> vbr > > > vbr, > I tried using .pop() but could not get what I wanted .Also, I can't see an > advantage in reversing the number. > Would you care to write explicitly the program for me (and probably for > other too)? > Brute Force is the style I'm thinking about. > > Sorry, but I learn most from viewing the code. > > Appreciated, > Yehuda > Hi, reversing the string would be useful for directly looping over the string (the interesting zeros would be at the beginning of the reversed string. If you use pop() on a list of the digits, the items are taken from the end of the list by default, hence no reversing is needed. What problems do you have with this route? (you will need to convert from the integer result to string, then to list and use pop() and count the steps until you reach a non-zero digit) If you need this kind of soulution (computing the factorial, converting to string, counting the trailing zero digits), I believe, the most easily comprehensible version was posted by Tim Chase a bit earlier. In the interactive interpreter, with some intermediate steps added, it can look like this: >>> from math import factorial >>> fact100_int = factorial(100) >>> fact100_string = str(fact100_int) >>> fact100_string_without_trailing_zeros = fact100_string.rstrip("0") >>> len(fact100_string) - len(fact100_string_without_trailing_zeros) 24 >>> [aditional info on the rstrip method of any string ("abcd" used for illustration here): ] >>> print("abcd".rstrip.__doc__) S.rstrip([chars]) -> str Return a copy of the string S with trailing whitespace removed. If chars is given and not None, remove characters in chars instead. >>> It should be noted that the approaches which involve computing of the factorial itself have much lower limits on the size compared to the algorithmic ones, but for the given case both are sufficient. hth, vbr From katye2007 at gmail.com Sat Jan 2 15:02:17 2016 From: katye2007 at gmail.com (yehudak .) Date: Sat, 2 Jan 2016 22:02:17 +0200 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: Hello vbr, That's EXACTLY what I needed. rstrip is new for me so I'm going to Dr. Google to learn. On my efforts I was struggling with .pop() but wasn't very successful... Thank you so much, Yehuda On Sat, Jan 2, 2016 at 8:29 PM, Vlastimil Brom wrote: > 2016-01-02 18:34 GMT+01:00 yehudak . : > [partly edited for bottom posting] > > On Sat, Jan 2, 2016 at 5:24 PM, Vlastimil Brom > > > wrote: > >> > >> 2016-01-02 14:14 GMT+01:00 yehudak . : > >> > > [...]>> > On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom > >> > > >> > wrote: > >> >> > >> >> 2016-01-02 12:49 GMT+01:00 : > >> >> > Hi, newbie here! > >> >> > I'm trying to write a python program to find how many trailing > zeros > >> >> > are > >> >> > in 100! (factorial of 100). > >> >> > I used factorial from the math module, but my efforts to continue > >> >> > failed. Please help. > >> >> > > >> >> > Thank you, > >> >> > Yehuda > >> >> > -- > >> >> > https://mail.python.org/mailman/listinfo/python-list > >> >> > >> > [...] > >> > > >> Hi, > >> If you eventually have this as an assignment or other kind of > >> (self)learning task, you would want to approach this with the methods > >> you know, or are supposed to use. > >> For the math context, you may find this explanations useful: > >> http://www.purplemath.com/modules/factzero.htm > >> a rather straightforward python implementation of this seems to be > >> e.g. this recipe: > >> > >> > http://code.activestate.com/recipes/577844-calculate-trailing-zeroes-in-a-factorial/ > >> Note, that you don't need to calculate the value of the factorial > >> itself using this way. > >> If you have problems with following or understanding the code, you may > >> show your own attempts and tell what problems you encounter with your > >> approach. > >> > >> My previous code sample is based on another - "brute-force" approach, > >> the factorial is calculated (e.g. via the math module as you have > >> found), then the integer is converted to a string, afterwards the part > >> of the result consisting only of zeros - at the end of the string is > >> matched with a regular expression and finally the length of it is > >> determined. > >> > >> Regular expressions might be handy, but are not necesarilly elementary > >> stuff for a newcomer in python programming. > >> You can count the trailing zeros in other ways too - as was suggested > >> - you can reverse the string and count from the beginning then, > >> stopping before the first non-zero digit. > >> The most straightforward way could be to loop (characterwise) through > >> the (reversed) string, check each character whether it equals to "0" > >> and stop as soon as there is another digit. > >> > >> hth, > >> vbr > > > > > > vbr, > > I tried using .pop() but could not get what I wanted .Also, I can't see > an > > advantage in reversing the number. > > Would you care to write explicitly the program for me (and probably for > > other too)? > > Brute Force is the style I'm thinking about. > > > > Sorry, but I learn most from viewing the code. > > > > Appreciated, > > Yehuda > > > Hi, > reversing the string would be useful for directly looping over the > string (the interesting zeros would be at the beginning of the > reversed string. > If you use pop() on a list of the digits, the items are taken from the > end of the list by default, hence no reversing is needed. > What problems do you have with this route? (you will need to convert > from the integer result to string, then to list and use pop() and > count the steps until you reach a non-zero digit) > > If you need this kind of soulution (computing the factorial, > converting to string, counting the trailing zero digits), I believe, > the most easily comprehensible version was posted by Tim Chase a bit > earlier. > In the interactive interpreter, with some intermediate steps added, it > can look like this: > > >>> from math import factorial > >>> fact100_int = factorial(100) > >>> fact100_string = str(fact100_int) > >>> fact100_string_without_trailing_zeros = fact100_string.rstrip("0") > >>> len(fact100_string) - len(fact100_string_without_trailing_zeros) > 24 > >>> > > [aditional info on the rstrip method of any string ("abcd" used for > illustration here): ] > >>> print("abcd".rstrip.__doc__) > S.rstrip([chars]) -> str > > Return a copy of the string S with trailing whitespace removed. > If chars is given and not None, remove characters in chars instead. > >>> > > It should be noted that the approaches which involve computing of the > factorial itself have much lower limits on the size compared to the > algorithmic ones, but for the given case both are sufficient. > > hth, > vbr > From katye2007 at gmail.com Sat Jan 2 15:09:04 2016 From: katye2007 at gmail.com (yehudak .) Date: Sat, 2 Jan 2016 22:09:04 +0200 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: Hi again, I looked a little deeper at your code. Smart solution and kudos. Yehuda On Sat, Jan 2, 2016 at 10:02 PM, yehudak . wrote: > Hello vbr, > That's EXACTLY what I needed. rstrip is new for me so I'm going to Dr. > Google to learn. > > On my efforts I was struggling with .pop() but wasn't very successful... > > Thank you so much, > Yehuda > > On Sat, Jan 2, 2016 at 8:29 PM, Vlastimil Brom > wrote: > >> 2016-01-02 18:34 GMT+01:00 yehudak . : >> [partly edited for bottom posting] >> > On Sat, Jan 2, 2016 at 5:24 PM, Vlastimil Brom < >> vlastimil.brom at gmail.com> >> > wrote: >> >> >> >> 2016-01-02 14:14 GMT+01:00 yehudak . : >> >> > >> [...]>> > On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom >> >> > >> >> > wrote: >> >> >> >> >> >> 2016-01-02 12:49 GMT+01:00 : >> >> >> > Hi, newbie here! >> >> >> > I'm trying to write a python program to find how many trailing >> zeros >> >> >> > are >> >> >> > in 100! (factorial of 100). >> >> >> > I used factorial from the math module, but my efforts to continue >> >> >> > failed. Please help. >> >> >> > >> >> >> > Thank you, >> >> >> > Yehuda >> >> >> > -- >> >> >> > https://mail.python.org/mailman/listinfo/python-list >> >> >> >> >> > [...] >> >> > >> >> Hi, >> >> If you eventually have this as an assignment or other kind of >> >> (self)learning task, you would want to approach this with the methods >> >> you know, or are supposed to use. >> >> For the math context, you may find this explanations useful: >> >> http://www.purplemath.com/modules/factzero.htm >> >> a rather straightforward python implementation of this seems to be >> >> e.g. this recipe: >> >> >> >> >> http://code.activestate.com/recipes/577844-calculate-trailing-zeroes-in-a-factorial/ >> >> Note, that you don't need to calculate the value of the factorial >> >> itself using this way. >> >> If you have problems with following or understanding the code, you may >> >> show your own attempts and tell what problems you encounter with your >> >> approach. >> >> >> >> My previous code sample is based on another - "brute-force" approach, >> >> the factorial is calculated (e.g. via the math module as you have >> >> found), then the integer is converted to a string, afterwards the part >> >> of the result consisting only of zeros - at the end of the string is >> >> matched with a regular expression and finally the length of it is >> >> determined. >> >> >> >> Regular expressions might be handy, but are not necesarilly elementary >> >> stuff for a newcomer in python programming. >> >> You can count the trailing zeros in other ways too - as was suggested >> >> - you can reverse the string and count from the beginning then, >> >> stopping before the first non-zero digit. >> >> The most straightforward way could be to loop (characterwise) through >> >> the (reversed) string, check each character whether it equals to "0" >> >> and stop as soon as there is another digit. >> >> >> >> hth, >> >> vbr >> > >> > >> > vbr, >> > I tried using .pop() but could not get what I wanted .Also, I can't see >> an >> > advantage in reversing the number. >> > Would you care to write explicitly the program for me (and probably for >> > other too)? >> > Brute Force is the style I'm thinking about. >> > >> > Sorry, but I learn most from viewing the code. >> > >> > Appreciated, >> > Yehuda >> > >> Hi, >> reversing the string would be useful for directly looping over the >> string (the interesting zeros would be at the beginning of the >> reversed string. >> If you use pop() on a list of the digits, the items are taken from the >> end of the list by default, hence no reversing is needed. >> What problems do you have with this route? (you will need to convert >> from the integer result to string, then to list and use pop() and >> count the steps until you reach a non-zero digit) >> >> If you need this kind of soulution (computing the factorial, >> converting to string, counting the trailing zero digits), I believe, >> the most easily comprehensible version was posted by Tim Chase a bit >> earlier. >> In the interactive interpreter, with some intermediate steps added, it >> can look like this: >> >> >>> from math import factorial >> >>> fact100_int = factorial(100) >> >>> fact100_string = str(fact100_int) >> >>> fact100_string_without_trailing_zeros = fact100_string.rstrip("0") >> >>> len(fact100_string) - len(fact100_string_without_trailing_zeros) >> 24 >> >>> >> >> [aditional info on the rstrip method of any string ("abcd" used for >> illustration here): ] >> >>> print("abcd".rstrip.__doc__) >> S.rstrip([chars]) -> str >> >> Return a copy of the string S with trailing whitespace removed. >> If chars is given and not None, remove characters in chars instead. >> >>> >> >> It should be noted that the approaches which involve computing of the >> factorial itself have much lower limits on the size compared to the >> algorithmic ones, but for the given case both are sufficient. >> >> hth, >> vbr >> > > From carlos.barera at gmail.com Sat Jan 2 15:39:09 2016 From: carlos.barera at gmail.com (Carlos Barera) Date: Sat, 02 Jan 2016 20:39:09 +0000 Subject: subprocess check_output In-Reply-To: <20151230210227.GA88234@cskk.homeip.net> References: <20151230210227.GA88234@cskk.homeip.net> Message-ID: Turns out it wasn't running against the server I thought it was. Apologies for the spam. -carlos On Wed, Dec 30, 2015 at 11:02 PM Cameron Simpson wrote: > On 30Dec2015 21:14, Carlos Barera wrote: > >Trying to run a specific command (ibstat) installed in /usr/sbin on an > >Ubuntu 15.04 machine, using subprocess.check_output and getting "/bin/sh: > >/usr/sbin/ibstat: No such file or directory" > > > >I tried the following: > >- running the command providing full path > >- running with executable=bash > >- running with (['/bin/bash', '-c' , "/usr/sbin/ibstat"]) > > > >Nothing worked ... > > The first check is to run the command from a shell. Does it work? Does > "which > ibstat" confirm that the command exist at that path? Is it even installed? > > If it does, you should be able to run it directly without using a shell: > > subprocess.call(['/usr/sbin/ibstat'], ...) > > or just plain ['ibstat']. Also remember that using "sh -c blah" or "bash -c > blah" is subject to all the same security issues that subprocess' > "shell=True" > parameter is, and that it should be avoided without special reason. > > Finally, remember to drop the common Linux fetish with "bash". Just use > "sh"; > on many systems it _is_ bash, but it will provide portable use. The bash is > just a partiular Bourne style shell, not installed everywhere, and rarely > of > any special benefit for scripts over the system /bin/sh (which _every_ UNIX > system has). > > If none of this solves your problem, please reply including the failing > code > and a transcript of the failure output. > > Thanks, > Cameron Simpson > From breamoreboy at yahoo.co.uk Sat Jan 2 16:25:29 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 2 Jan 2016 21:25:29 +0000 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: On 02/01/2016 20:02, yehudak . wrote: > Hello vbr, > That's EXACTLY what I needed. rstrip is new for me so I'm going to Dr. > Google to learn. > > On my efforts I was struggling with .pop() but wasn't very successful... > > Thank you so much, > Yehuda > How many times do you have to be asked to not top post? Just how thick are you? -- 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 Jan 2 16:26:18 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 2 Jan 2016 21:26:18 +0000 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: On 02/01/2016 20:09, yehudak . wrote: > Hi again, > I looked a little deeper at your code. Smart solution and kudos. > > Yehuda > Still top posting? Thanks a bunch. -- 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 Jan 2 16:57:36 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jan 2016 08:57:36 +1100 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: On Sun, Jan 3, 2016 at 3:56 AM, Robin Koch wrote: > Am 02.01.2016 um 17:09 schrieb Tony van der Hoff: >> >> On 02/01/16 16:57, Robin Koch wrote: >>> >>> sum([int(0.2**k*n) for k in range(1, int(log(n, 5))+1)]) >> >> >> But did you actually test it? > > > Yes, should work for n >= 1. > > Why do you ask? Your "should work" does not sound good as a response to "actually test". Normally I would expect the response to be "Yes, and it worked for me" (maybe with a log of an interactive session). Floating point can't represent every integer, and above 2**53 you end up able to represent only those which are multiples of ever-increasing powers of two; 100! is between 2**524 and 2**525, so any float operations are going to be rounding off to the nearest 2**471 or thereabouts. That's... a lot of rounding. That's like trying to calculate whether pi is rational, but basing your calculations on the approximation 3.14. :) ChrisA From rosuav at gmail.com Sat Jan 2 17:01:45 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jan 2016 09:01:45 +1100 Subject: subprocess check_output In-Reply-To: References: <20151230210227.GA88234@cskk.homeip.net> Message-ID: On Sun, Jan 3, 2016 at 7:39 AM, Carlos Barera wrote: > Turns out it wasn't running against the server I thought it was. > Apologies for the spam. Heh. No problem. That's part of why I suggested running it from the shell. There are two possibilities: either it also fails from the shell (in which case you've eliminated Python as the problem, and can concentrate on "why is my command not working"), or it succeeds when run manually and still fails from Python (in which case you can start investigating the differences). And every now and then, it's worth doing a stupid smoke test just to see if your changes are even having effect. You have no idea how many times a bug investigation has come down to "whoops, I forgot to save the file" or "whoops, I was in the wrong directory"... ChrisA From PointedEars at web.de Sat Jan 2 18:36:44 2016 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sun, 03 Jan 2016 00:36:44 +0100 Subject: Trailing zeros of 100! References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: <1507703.vSOp0aCa7u@PointedEars.de> Mark Lawrence wrote: > Please don't top post, it's extremely annoying when trying to follow > long threads. As are full quotes. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From robin.koch at t-online.de Sat Jan 2 19:02:38 2016 From: robin.koch at t-online.de (Robin Koch) Date: Sun, 3 Jan 2016 01:02:38 +0100 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: Am 02.01.2016 um 22:57 schrieb Chris Angelico: > On Sun, Jan 3, 2016 at 3:56 AM, Robin Koch wrote: >> Am 02.01.2016 um 17:09 schrieb Tony van der Hoff: >>> >>> On 02/01/16 16:57, Robin Koch wrote: >>>> >>>> sum([int(0.2**k*n) for k in range(1, int(log(n, 5))+1)]) >>> >>> >>> But did you actually test it? >> >> >> Yes, should work for n >= 1. >> >> Why do you ask? > > Your "should work" does not sound good as a response to "actually > test". Normally I would expect the response to be "Yes, and it worked > for me" (maybe with a log of an interactive session). Well, honestly, I trusted my math and didn't thought much about the technical limitations. I only tried values from 1 to 100 and then again 12345, I believe, to test the algorithm. > Floating point > can't represent every integer, and above 2**53 you end up able to > represent only those which are multiples of ever-increasing powers of > two; 100! is between 2**524 and 2**525, so any float operations are > going to be rounding off to the nearest 2**471 or thereabouts. > That's... a lot of rounding. That's like trying to calculate whether > pi is rational, but basing your calculations on the approximation > 3.14. :) When I find more time I take a closer look at it. Thank you (and Bernardo) for your clarification. I hope everyone who read my article reads yours, too and learns from it. ;-) -- Robin Koch From ben+python at benfinney.id.au Sat Jan 2 19:20:52 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 03 Jan 2016 11:20:52 +1100 Subject: Trailing zeros of 100! References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: <85twmvqzrv.fsf@benfinney.id.au> Robin Koch writes: > Am 02.01.2016 um 22:57 schrieb Chris Angelico: > >>> But did you actually test it? > >> > >> Yes, should work for n >= 1. By ?test it?, Chris of course means test it *by implementing it in a program and running that program in Python*. > >> Why do you ask? > > > > Your "should work" does not sound good as a response to "actually > > test". Normally I would expect the response to be "Yes, and it > > worked for me" (maybe with a log of an interactive session). > > Well, honestly, I trusted my math and didn't thought much about the > technical limitations. That's why it's good to actually test the hypothesis in a real computer program, run on the actual computer system you're going to use. Computers are physical systems, with technical compromises to the physical constraints under which they were built. They are not perfect implementations of our ideal mathematics, and testing the mathematics is no guarantee the mathematical assumptions will survive your program unscathed. So, a request ?Did you actually test it?? is both a polite reminder to do that, and an attempt to get you to do so if you didn't. If you didn't, then answering ?yes? is wasting everyone's time. -- \ ?As the most participatory form of mass speech yet developed, | `\ the Internet deserves the highest protection from governmental | _o__) intrusion.? ?U.S. District Court Judge Dalzell | Ben Finney From marko at pacujo.net Sat Jan 2 19:33:26 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 03 Jan 2016 02:33:26 +0200 Subject: We will be moving to GitHub References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> <87oad41fd4.fsf@elektro.pacujo.net> <87k2ns1b0d.fsf@elektro.pacujo.net> <87ege012i5.fsf@elektro.pacujo.net> <87a8oo11b4.fsf@elektro.pacujo.net> Message-ID: <8737uf1oyx.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Jan 3, 2016 at 1:52 AM, Marko Rauhamaa wrote: >> Terminology aside, if I do this with Git: >> >> -----+--------------------+--------> >> \ ^ >> \pull /push >> v / >> +--------------+ >> edit >> >> everything goes in without any further ado. >> >> However, this operation will be blocked by Git: >> >> >> --+--+--------------------+----+---> >> \ \ ^ X >> \ \pull /push/ >> \ v / / >> pull\ +--------------+ /push >> \ edit / >> v / >> +-----------------+ >> >> Not so by Teamware as long as the pushes don't have files in common. > > Ah, I see what you mean. > > That's a constantly-debated point, and it's actually possible to make > git accept this, although it's not a normal workflow. Instead, you > just 'git pull' (possibly with --rebase) before you 'git push'. You > either create a new merge commit, or make it very clear that you are > changing your commits to pretend they were committed after the > already-pushed ones. Or you do a force-push and discard the other > commits (this is correct if you amended a commit). You HAVE to choose > because these are three viable solutions, and only a human can make > the decision. > > Teamware presumably picked one of them, Teamware didn't have to pick any of them since Teamware's commits were done per individual files. The repository didn't have a commit history. Thus, Teamware was equivalent to Hg/Git with each file treated as an independent repository. Marko From breamoreboy at yahoo.co.uk Sat Jan 2 19:34:40 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 3 Jan 2016 00:34:40 +0000 Subject: We will be moving to GitHub In-Reply-To: References: Message-ID: On 01/01/2016 19:39, Mark Lawrence wrote: > Please see > https://mail.python.org/pipermail/core-workflow/2016-January/000345.html > > This should encourage developers at all levels to help out, such that > the list of open issues on the bug tracker falls drastically. > One thing that I forgot is that if nobody responds to something on the bug tracker, then nothing happens. As I write there are 516 issues with only one message. Obviously some can be discarded as e.g. they are place holders for core devs, but it certainly leaves a large number that give the OP the impression that they are an irrelevance. -- 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 Jan 2 19:42:04 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jan 2016 11:42:04 +1100 Subject: We will be moving to GitHub In-Reply-To: <8737uf1oyx.fsf@elektro.pacujo.net> References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> <87oad41fd4.fsf@elektro.pacujo.net> <87k2ns1b0d.fsf@elektro.pacujo.net> <87ege012i5.fsf@elektro.pacujo.net> <87a8oo11b4.fsf@elektro.pacujo.net> <8737uf1oyx.fsf@elektro.pacujo.net> Message-ID: On Sun, Jan 3, 2016 at 11:33 AM, Marko Rauhamaa wrote: >> That's a constantly-debated point, and it's actually possible to make >> git accept this, although it's not a normal workflow. Instead, you >> just 'git pull' (possibly with --rebase) before you 'git push'. You >> either create a new merge commit, or make it very clear that you are >> changing your commits to pretend they were committed after the >> already-pushed ones. Or you do a force-push and discard the other >> commits (this is correct if you amended a commit). You HAVE to choose >> because these are three viable solutions, and only a human can make >> the decision. >> >> Teamware presumably picked one of them, > > Teamware didn't have to pick any of them since Teamware's commits were > done per individual files. The repository didn't have a commit history. > > Thus, Teamware was equivalent to Hg/Git with each file treated as an > independent repository. And what if you and someone else edit different parts of the same file? How is that handled? Why should the top and bottom of one file be dramatically different from two separate files? ChrisA From marko at pacujo.net Sat Jan 2 20:14:30 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 03 Jan 2016 03:14:30 +0200 Subject: We will be moving to GitHub References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> <87oad41fd4.fsf@elektro.pacujo.net> <87k2ns1b0d.fsf@elektro.pacujo.net> <87ege012i5.fsf@elektro.pacujo.net> <87a8oo11b4.fsf@elektro.pacujo.net> <8737uf1oyx.fsf@elektro.pacujo.net> Message-ID: <87vb7bzcp5.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Jan 3, 2016 at 11:33 AM, Marko Rauhamaa wrote: >> Teamware didn't have to pick any of them since Teamware's commits >> were done per individual files. The repository didn't have a commit >> history. >> >> Thus, Teamware was equivalent to Hg/Git with each file treated as an >> independent repository. > > And what if you and someone else edit different parts of the same > file? How is that handled? Why should the top and bottom of one file > be dramatically different from two separate files? Files are a natural unit of granularity; that's why we don't place all source code in a single source code file. There are exceptions, but in general I'd say only one person should be editing one file at any given time. As I mentioned before, Darcs tries to eat the cake and have it, too. It provides Git-like repository semantics and a clearly defined concept of parallel changes. It does *not* make a distinction between two files and two parts of a file. Unfortunately, rumor has it that Darcs can run into serious performance issues as it enforces the conceptual purity. That's why I think Teamware's file-level focus is the practical sweet spot of distributed version control. Marko From skybuck2000 at hotmail.com Sat Jan 2 20:18:23 2016 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Sun, 3 Jan 2016 02:18:23 +0100 Subject: (Execution) Termination bit, Alternation bit. In-Reply-To: References: <9Bldy.3723$Bz5.1578@fx04.iad> <864af$56760c5f$d47876e2$48630@news.ziggo.nl> <6f90e$56826d92$d47876e2$48098@news.ziggo.nl> <5682892c$0$1587$c3e8da3$5496439d@news.astraweb.com> <45686$5682fe60$d47876e2$14175@news.ziggo.nl> Message-ID: "Chris Angelico" wrote in message news:mailman.64.1451433611.11925.python-list at python.org... On Wed, Dec 30, 2015 at 8:43 AM, Skybuck Flying wrote: > Not at all, these assembler statements can be replaced with python > statements and then you have the exact same problem ! ;) " Then do so. Give us an example where this problem occurs in pure Python. " I basically already did... The while loops and calls themselfes already enough of a burdon... Should be easy to turn that somewhat pseudo code into python code ! :) Bye, Skybuck. From mr.eightnoteight at gmail.com Sat Jan 2 20:46:43 2016 From: mr.eightnoteight at gmail.com (srinivas devaki) Date: Sun, 3 Jan 2016 07:16:43 +0530 Subject: Trailing zeros of 100! In-Reply-To: <85twmvqzrv.fsf@benfinney.id.au> References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> <85twmvqzrv.fsf@benfinney.id.au> Message-ID: let's put an end to this. from math import log # simple one to understand. complexity: O(n*log(n)) def countzeros_va(n): count = 0 for x in xrange(1, n + 1): while x % 5 == 0: count += 1 x //= 5 return count # better approach. complexity: O(log(n)) def countzeros_vb(n): count, c5 = 0, 5 while c5 <= n: count += (n // c5) c5 *= 5 return count # this is same as before, its just that while loops irk me def countzeros_vc(n): return sum(n // (5**x) for x in range(1, int(log(n, 5) + 3))) # adding +3 to be sure. never trust approximations. def run_sample_tests(): precal = {3: 0, 60: 14, 100: 24, 1024: 253, 23456: 5861, 8735373: 2183837} for x in precal: assert precal[x] == countzeros_va(x) == countzeros_vb(x) == countzeros_vc(x) if __name__ == '__main__': run_sample_tests() Although the code is deterministic, it can be further tested from http://www.wolframalpha.com/widgets/view.jsp?id=54da27e6e09dc404890a578735b9f7d8 http://www.spoj.com/problems/FCTRL/ On Jan 2, 2016 5:22 PM, wrote: > > Hi, newbie here! > I'm trying to write a python program to find how many trailing zeros are in 100! (factorial of 100). > I used factorial from the math module, but my efforts to continue failed. Please help. > > Thank you, > Yehuda > -- > https://mail.python.org/mailman/listinfo/python-list On Sun, Jan 3, 2016 at 5:50 AM, Ben Finney wrote: > Robin Koch writes: > >> Am 02.01.2016 um 22:57 schrieb Chris Angelico: >> >>> But did you actually test it? >> >> >> >> Yes, should work for n >= 1. > > By ?test it?, Chris of course means test it *by implementing it in a > program and running that program in Python*. > >> >> Why do you ask? >> > >> > Your "should work" does not sound good as a response to "actually >> > test". Normally I would expect the response to be "Yes, and it >> > worked for me" (maybe with a log of an interactive session). >> >> Well, honestly, I trusted my math and didn't thought much about the >> technical limitations. > > That's why it's good to actually test the hypothesis in a real computer > program, run on the actual computer system you're going to use. > > Computers are physical systems, with technical compromises to the > physical constraints under which they were built. > > They are not perfect implementations of our ideal mathematics, and > testing the mathematics is no guarantee the mathematical assumptions > will survive your program unscathed. > > So, a request ?Did you actually test it?? is both a polite reminder to > do that, and an attempt to get you to do so if you didn't. > > If you didn't, then answering ?yes? is wasting everyone's time. > > -- > \ ?As the most participatory form of mass speech yet developed, | > `\ the Internet deserves the highest protection from governmental | > _o__) intrusion.? ?U.S. District Court Judge Dalzell | > Ben Finney > > -- > https://mail.python.org/mailman/listinfo/python-list From torriem at gmail.com Sat Jan 2 22:24:50 2016 From: torriem at gmail.com (Michael Torrie) Date: Sat, 02 Jan 2016 20:24:50 -0700 Subject: We will be moving to GitHub In-Reply-To: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: <56889482.3030700@gmail.com> On 01/01/2016 11:43 PM, Steven D'Aprano wrote: > On Sat, 2 Jan 2016 07:09 am, Chris Angelico wrote: > >> Yes, git is a capable tool. But so is Mercurial, and the arguments >> weren't primarily based on differences in functionality (which are >> pretty minor). It's mainly about the network effect. > > You call it the network effect. I call it monoculture. Indeed. The whole purpose of git is to allow development to be distributed. Is it a matter of hosting space? Is it too expensive for python.org to host their own public-facing git repository? Especially if python.org has no plans to use github's issue tracker this move makes little sense to me. A pull request can be made from any developer's own git repository without github, or even from github if other developers really want to work there. I can understand why OSS projects like github given its complete project-management options. But if it's just the repository you're after, I get far more mileage from my own locally-hosted git repositories. It's not at all hard to push to a read-only public http git repository. Pull requests can be made against individual developers' http repos or hosted git providers. From torriem at gmail.com Sat Jan 2 22:31:20 2016 From: torriem at gmail.com (Michael Torrie) Date: Sat, 02 Jan 2016 20:31:20 -0700 Subject: We will be moving to GitHub In-Reply-To: <8560zcsbuu.fsf@benfinney.id.au> References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> Message-ID: <56889608.50504@gmail.com> On 01/02/2016 12:02 AM, Ben Finney wrote: > What is being done to stave off the common response, addressed by GitHub > users to people submitting a change as a link to their Git repository, > of ?can you please submit that as a GitHub pull request?? > > That common response makes for an unnecessary and IMO unacceptable > pressure toward centralisation. GitHub's ?pull request? workflow is > entirely proprietary and can only be done within GitHub. Really? This seems like an entirely artificial github requirement. There's absolutely no reason why github couldn't do a pull request from any arbitrary, valid git url. From ben+python at benfinney.id.au Sat Jan 2 23:43:52 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 03 Jan 2016 15:43:52 +1100 Subject: GitHub's =?utf-8?Q?=E2=80=9Cpull_request=E2=80=9D?= is proprietary lock-in (was: We will be moving to GitHub) References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> Message-ID: <85poxjqnlj.fsf_-_@benfinney.id.au> Michael Torrie writes: > On 01/02/2016 12:02 AM, Ben Finney wrote: > > GitHub's ?pull request? workflow is entirely proprietary and can > > only be done within GitHub. > > Really? This seems like an entirely artificial github requirement. Yes, it is. > There's absolutely no reason why github couldn't do a pull request from > any arbitrary, valid git url. Right. The proprietary GitHub ?pull request? has many more features (including a code review tool and discussion thread that are automatically tied to the pull request) which make it attractive. The fact these features (unlike Git) are wholly proprietary, and the valuable processes and data they generate cannot be exported and continued easily in another instance when a community chooses, are what makes GitHub's ?pull request? an attractive nuisance. That and other vendor-locked workflow aspects of GitHub makes it a poor choice for communities that want to retain the option of control over their processes and data. -- \ ?Try adding ?as long as you don't breach the terms of service ? | `\ according to our sole judgement? to the end of any cloud | _o__) computing pitch.? ?Simon Phipps, 2010-12-11 | Ben Finney From esj at harvee.org Sun Jan 3 01:29:16 2016 From: esj at harvee.org (eric johansson) Date: Sun, 3 Jan 2016 08:29:16 +0200 (EET) Subject: installing python 2.7.11 + win32 on win 10 Message-ID: <1001243855.12986.1451802556307.JavaMail.zimbra@harvee.org> the install of the basic 2.7 seems to go ok but when installing the win32 extensions, I get: close failed in file object destructor: sys.excepthook is missing lost sys.stderr I've tried installing as administrator but no joy. what should I try next? From random832 at fastmail.com Sun Jan 3 02:04:12 2016 From: random832 at fastmail.com (Random832) Date: Sun, 03 Jan 2016 02:04:12 -0500 Subject: GitHub's =?utf-8?Q?=C2=B3pull_request=C2=B2?= is proprietary lock-in References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> Message-ID: Michael Vilain writes: > We used stash/bitbucket at my last contract. It's the second site I've > come across that used Atlasian's toolset. Yes, I know it's not > statistically significant. > > Anyway, the pull/merge request workflow is becoming pretty standard. I think you're missing a distinction between "pull/merge request workflow" and the specific artifact that github _calls_ a "pull request", which includes references to specific github accounts, a discussion thread on their proprietary discussion software (vs an email list or the python issue tracker) maintained on their servers and not servers that PSF controls, etc. From auriocus at gmx.de Sun Jan 3 02:44:48 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 3 Jan 2016 08:44:48 +0100 Subject: =?UTF-8?Q?Re:_GitHub's_=c2=b3pull_request=c2=b2_is_proprietary_lock?= =?UTF-8?Q?-in?= In-Reply-To: References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> Message-ID: Am 03.01.16 um 08:04 schrieb Random832: > Michael Vilain writes: >> We used stash/bitbucket at my last contract. It's the second site I've >> come across that used Atlasian's toolset. Yes, I know it's not >> statistically significant. >> >> Anyway, the pull/merge request workflow is becoming pretty standard. > > I think you're missing a distinction between "pull/merge request > workflow" and the specific artifact that github _calls_ a "pull > request", which includes references to specific github accounts, a > discussion thread on their proprietary discussion software (vs an email > list or the python issue tracker) maintained on their servers and not > servers that PSF controls, etc. Arguably, the most valuable outcome of the pull request in the end is the patch, which is of course contained in the git repository. GitHub also sends email notifications if a pull request is edited. So if the account holder for GitHub keeps an archive of all mail from notifications at github.com, then also the big part of this discussion is preserved. I doubt that many people want to go back to see the arguments for a certain merge; this thread will also soon be abandoned, people will know that Python lives on GitHub and live with it, move on and do something more valuable. Christian From ben+python at benfinney.id.au Sun Jan 3 03:03:39 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 03 Jan 2016 19:03:39 +1100 Subject: GitHub's =?utf-8?Q?=C2=B3pull_request=C2=B2?= is proprietary lock-in References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> Message-ID: <85lh87qeck.fsf@benfinney.id.au> Christian Gollwitzer writes: > Arguably, the most valuable outcome of the pull request in the end is > the patch, which is of course contained in the git repository. Arguably, the most valuable outcome of a database system is the query result, which is of course contained in the result set of tuples contained in the response data. Arguably, the most valuable outcome of a version control system is the source code tree, which is of course contained in a filesystem directory. Arguably, the most valuable outcome of a programming language is the programs we write with it, which is of course contained in the compiled binary. By your reasoning, that means we should not care about handing the control over our database system, our version control system, or our programming language to a vendor-locked, proprietary, gratuitously centralised technology. I hope the analogy makes it clear why that's not an argument I think anyone would accept as sound. > I doubt that many people want to go back to see the arguments for a > certain merge I doubt many people want to go into the source code for my operating system and tell me exactly what it's doing, where my data is stored, how to get it from this operating system to a different one. My freedom to migrate from that system to a different one when I choose, is entirely dependent on *anyone* being able to do that, no matter how few people express an interest where you might see it. -- \ ?There's no excuse to be bored. Sad, yes. Angry, yes. | `\ Depressed, yes. Crazy, yes. But there's no excuse for boredom, | _o__) ever.? ?Viggo Mortensen | Ben Finney From auriocus at gmx.de Sun Jan 3 03:33:36 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 3 Jan 2016 09:33:36 +0100 Subject: =?UTF-8?Q?Re:_GitHub's_=c2=b3pull_request=c2=b2_is_proprietary_lock?= =?UTF-8?Q?-in?= In-Reply-To: References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> Message-ID: Am 03.01.16 um 09:03 schrieb Ben Finney: > Christian Gollwitzer writes: > >> Arguably, the most valuable outcome of the pull request in the end is >> the patch, which is of course contained in the git repository. > > Arguably, the most valuable outcome of a database system is the query > result, which is of course contained in the result set of tuples > contained in the response data. > > Arguably, the most valuable outcome of a version control system is the > source code tree, which is of course contained in a filesystem directory. > > Arguably, the most valuable outcome of a programming language is the > programs we write with it, which is of course contained in the compiled > binary. > > By your reasoning, that means we should not care about handing the > control over our database system, our version control system, or our > programming language to a vendor-locked, proprietary, gratuitously > centralised technology. > > I hope the analogy makes it clear why that's not an argument I think > anyone would accept as sound. There are layers. Below your Python code there is CPython, below that the C compiler, the OS, and finally the hardware. If you are using an Intel CPU, you can't control the interpreter of the x86-64 machine opcodes. At some point, nobody cares. It's a question where to put the border. In former times, people sent emails with patches attached. Nobody complains that those emails are lost to the community. Then somebody invented VCS and all became better. Pull requests are nothing but elaborated emails. >> I doubt that many people want to go back to see the arguments for a >> certain merge > > I doubt many people want to go into the source code for my operating > system and tell me exactly what it's doing, where my data is stored, how > to get it from this operating system to a different one. > > My freedom to migrate from that system to a different one when I choose, > is entirely dependent on *anyone* being able to do that, no matter how > few people express an interest where you might see it. You can still migrate, because git stays git. Christian From steve at pearwood.info Sun Jan 3 03:44:28 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 03 Jan 2016 19:44:28 +1100 Subject: (Execution) Termination bit, Alternation bit. References: <9Bldy.3723$Bz5.1578@fx04.iad> <864af$56760c5f$d47876e2$48630@news.ziggo.nl> <6f90e$56826d92$d47876e2$48098@news.ziggo.nl> <5682892c$0$1587$c3e8da3$5496439d@news.astraweb.com> <45686$5682fe60$d47876e2$14175@news.ziggo.nl> Message-ID: <5688df6c$0$1601$c3e8da3$5496439d@news.astraweb.com> On Sun, 3 Jan 2016 12:18 pm, Skybuck Flying wrote: > Should be easy to turn that somewhat pseudo code into python code ! :) If it is so easy, why won't you do it? -- Steven From ben+python at benfinney.id.au Sun Jan 3 03:45:25 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 03 Jan 2016 19:45:25 +1100 Subject: GitHub's =?utf-8?Q?=C2=B3pull_request=C2=B2?= is proprietary lock-in References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> Message-ID: <85h9ivqcey.fsf@benfinney.id.au> Christian Gollwitzer writes: > There are layers. Below your Python code there is CPython, below that > the C compiler, the OS, and finally the hardware. Yes. There are continual motivations to take the technology at any of those levels and make it less free, make it more locked to single vendors, make it more difficult to migrate our valuable data to a system under our control. Asserting that one level is currently less free, is in no measure an argument to allow a different level to be moved further from the community's control. > At some point, nobody cares. You clearly do care, since you are participating in this discussion and attempting to argue that people *should not* care. > In former times, people sent emails with patches attached. Nobody > complains that those emails are lost to the community. You make my point for me: Nothing about that method of transferring code changes was actively controlled by a single vendor, nor gratuitously centralised, nor handed to an unexaminable, unaccountable system. > Then somebody invented VCS and all became better. Pull requests are > nothing but elaborated emails. Email is decentralised; it has no gratuitous barriers between diverse implementations of the standards; it has standards that are energetically guarded against vendor lock-in. Anyone can take email data from the email server, migrate it to a different implementation of the same email system, keep it running with the same data and allow the same people to continue interacting with it as before. Those are traits I think a community should require of any system that controls vital discussions like pull requests. If GitHub pull requests could be verified to work that way, I would have no complaint here. Until they do, it is foolish for a community to willingly put their correspondence data into it. -- \ ?Come on Milhouse, there?s no such thing as a soul! It?s just | `\ something they made up to scare kids, like the Boogie Man or | _o__) Michael Jackson.? ?Bart, _The Simpsons_ | Ben Finney From rosuav at gmail.com Sun Jan 3 04:18:11 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jan 2016 20:18:11 +1100 Subject: =?UTF-8?Q?Re=3A_GitHub=27s_=C2=B3pull_request=C2=B2_is_proprietary_lock=2Din?= In-Reply-To: <85h9ivqcey.fsf@benfinney.id.au> References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <85h9ivqcey.fsf@benfinney.id.au> Message-ID: On Sun, Jan 3, 2016 at 7:45 PM, Ben Finney wrote: > Anyone can take email data from the email server, migrate it to a > different implementation of the same email system, keep it running with > the same data and allow the same people to continue interacting with it > as before. > > Those are traits I think a community should require of any system that > controls vital discussions like pull requests. > > If GitHub pull requests could be verified to work that way, I would have > no complaint here. Until they do, it is foolish for a community to > willingly put their correspondence data into it. They are. Ultimately, a GitHub pull request is backed by a git pull request. Here's an example: https://github.com/MikeiLL/appension/pull/187 That's a request to pull https://github.com/Rosuav/appension's log_to_file branch (https://github.com/Rosuav/appension/tree/log_to_file) into the master branch. That can be fetched and merged into a local repository: git pull https://github.com/Rosuav/appension log_to_file If the official workflow is built on these commands, then it doesn't depend on GitHub at all. Someone puts through a GH PR and it'll create an email that provides all the necessary info; but equally, someone can use any other git hosting and send through an identical pull request without ever touching GH. Since actual bug discussion isn't being moved away from bugs.python.org, this should be safe. ChrisA From random832 at fastmail.com Sun Jan 3 04:31:55 2016 From: random832 at fastmail.com (Random832) Date: Sun, 03 Jan 2016 04:31:55 -0500 Subject: GitHub's =?utf-8?Q?=C2=B3pull_request=C2=B2?= is proprietary lock-in References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <85h9ivqcey.fsf@benfinney.id.au> Message-ID: Chris Angelico writes: > They are. Ultimately, a GitHub pull request is backed by a git pull > request. There is no such thing as a "git pull request", except in the ordinary english meaning of the word request. It is true that a pull request is, from one angle, a formalized request for someone to execute a git pull command. But there is no command to create a "pull request", nowhere for such a thing to exist in the repository, etc. It is, in essence, a parallel bug tracker, with its own discussion system, its own statuses, etc. > Here's an example: > > https://github.com/MikeiLL/appension/pull/187 > > That's a request to pull https://github.com/Rosuav/appension's > log_to_file branch > (https://github.com/Rosuav/appension/tree/log_to_file) into the master > branch. That can be fetched and merged into a local repository: > > git pull https://github.com/Rosuav/appension log_to_file > > If the official workflow is built on these commands, then it doesn't > depend on GitHub at all. Someone puts through a GH PR and it'll create > an email that provides all the necessary info; but equally, someone > can use any other git hosting and send through an identical pull > request without ever touching GH. When I tried github it was also very unclear how someone can pull to a github repository from a source other than another github repository with an associated github pull request. I suppose they could pull into their local repository and then push to github. Also if someone puts through a github pull request and then their patch is accepted, my understanding is that the pull request has to be "closed" through a github online interface and merely merging the patch through the git command line will not update the status on the pull request. > Since actual bug discussion isn't > being moved away from bugs.python.org, this should be safe. I don't think you can really narrow "actual bug discussion" like that. Some discussion takes place on the bug tracker, some discussion takes place here, some discussion takes place on python-ideas, some discussion takes place on other mailing lists... and it's suspected that some discussion will take place on github. All of that discussion has value, and it's not good to have any of it locked up in a place that cannot be exported. From wking at tremily.us Sun Jan 3 04:42:48 2016 From: wking at tremily.us (W. Trevor King) Date: Sun, 3 Jan 2016 01:42:48 -0800 Subject: [python] Re: =?iso-8859-1?Q?GitHub's_?= =?iso-8859-1?Q?=B3pull_request=B2?= is proprietary lock-in In-Reply-To: References: <56889608.50504@gmail.com> <85h9ivqcey.fsf@benfinney.id.au> Message-ID: <20160103094248.GV3680@odin.tremily.us> On Sun, Jan 03, 2016 at 04:31:55AM -0500, Random832 wrote: > But there is no command to create a "pull request", nowhere for such > a thing to exist in the repository, etc. There is this [1]. > Also if someone puts through a github pull request and then their > patch is accepted, my understanding is that the pull request has to > be "closed" through a github online interface and merely merging the > patch through the git command line will not update the status on the > pull request. This is incorrect. GitHub will automatically mark PRs as ?Merged? when their tip commit lands in the target branch. I haven't looked up docs for when this landed (if it was even announced), but next to GitHub's ?Merge pull request? button there's currently an ?or view command line instructions? link which sketches out some command-line Git to accomplish the same thing. But I agree that it's nice to keep the discussion around pull requests somewhere portable. Cheers, Trevor [1]: http://git-scm.com/docs/git-request-pull -- This email may be signed or encrypted with GnuPG (http://www.gnupg.org). For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: OpenPGP digital signature URL: From ben+python at benfinney.id.au Sun Jan 3 04:46:19 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 03 Jan 2016 20:46:19 +1100 Subject: GitHub's =?utf-8?Q?=C2=B3pull_request=C2=B2?= is proprietary lock-in References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <85h9ivqcey.fsf@benfinney.id.au> Message-ID: <85d1tjq9lg.fsf@benfinney.id.au> Chris Angelico writes: > On Sun, Jan 3, 2016 at 7:45 PM, Ben Finney wrote: > > Anyone can take email data from the email server, migrate it to a > > different implementation of the same email system, keep it running > > with the same data and allow the same people to continue interacting > > with it as before. > > > > Those are traits I think a community should require of any system > > that controls vital discussions like pull requests. > > They are. Ultimately, a GitHub pull request is backed by a git pull > request. Here's an example: > > https://github.com/MikeiLL/appension/pull/187 Yes, of course the VCS data is in Git and therefore can be accessed with Git. Please stop raising that when *I'm not talking about* the VCS data alone, I'm talking also about the data of the pull request feature. The discussion data, code review data, etc. is all part of ?GitHub pull request?. How do we export, along with the VCS data, the data and system that control the code review discussino and other useful features entailed by ?GitHub pull request?? How do we get that data and confidently and quickly set up a system hosted on a different provider that allows everyone involved to continue the same code reviews and discussions etc. without GitHub? To my knowledge we can't, short of re-implementing an expressly proprietary non-standard system against the wishes of the vendor. That's valuable community data being locked into a single-vendor system, who explicitly rejects community access to the system and the data needed to continue on a different provider. It boggles my mind that so many people ? even when the conversation has directly raised the notion of different layers of technology that control different layers of valuable data ? blithely ignore the fact that *the discussion itself* is dependent on a software system and data. Control over that software system and data is important to control over the valuable discussions, just as control over the VCS system and data is important to control over the valuable source code. Conversely, as Ned Batchelder points out, without all the proprietary vendor lock-in centralised features, GitHub is a fairly unimpressive Git hosting provider. The ?but Git is free software, no one is locked in!? is trivially true, and has an obvious response in ?then there's no good reason to move anything there?. Please, those who are going to advocate for GitHub especially over other Git hosting providers because it has specially valuable features, be honest that you're advocating moving control of valuable information away from the community that values them. -- \ ?First things first, but not necessarily in that order.? ?The | `\ Doctor, _Doctor Who_ | _o__) | Ben Finney From no.email at nospam.invalid Sun Jan 3 04:50:33 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 03 Jan 2016 01:50:33 -0800 Subject: GitHub's =?utf-8?Q?=C2=B3pull_request=C2=B2?= is proprietary lock-in References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <85h9ivqcey.fsf@benfinney.id.au> Message-ID: <87k2nrc7py.fsf@jester.gateway.pace.com> Random832 writes: > All of that discussion has value, and it's not good to > have any of it locked up in a place that cannot be exported. I have a dim recollection of Python moving from Trac to a proprietary, hosted bug tracker for a while, but now they're back to an open(?) system but are about to do the same thing with Github. It's ironic that Git itself was written to escape the debacle of the Linux kernel using hosted (Bitkeeper) source control for a while. As for patch review discussions, didn't Guido himself write Gerrit? Somehow it's never been mentioned here. From rosuav at gmail.com Sun Jan 3 05:17:02 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jan 2016 21:17:02 +1100 Subject: =?UTF-8?Q?Re=3A_GitHub=27s_=C2=B3pull_request=C2=B2_is_proprietary_lock=2Din?= In-Reply-To: <85d1tjq9lg.fsf@benfinney.id.au> References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <85h9ivqcey.fsf@benfinney.id.au> <85d1tjq9lg.fsf@benfinney.id.au> Message-ID: On Sun, Jan 3, 2016 at 8:46 PM, Ben Finney wrote: > Chris Angelico writes: > >> On Sun, Jan 3, 2016 at 7:45 PM, Ben Finney wrote: >> > Anyone can take email data from the email server, migrate it to a >> > different implementation of the same email system, keep it running >> > with the same data and allow the same people to continue interacting >> > with it as before. >> > >> > Those are traits I think a community should require of any system >> > that controls vital discussions like pull requests. >> >> They are. Ultimately, a GitHub pull request is backed by a git pull >> request. Here's an example: >> >> https://github.com/MikeiLL/appension/pull/187 > > Yes, of course the VCS data is in Git and therefore can be accessed with > Git. Please stop raising that when *I'm not talking about* the VCS data > alone, I'm talking also about the data of the pull request feature. Uh, that's a pull request link. I'm talking specifically about the pull request feature here. > The discussion data, code review data, etc. is all part of ?GitHub pull > request?. How do we export, along with the VCS data, the data and system > that control the code review discussino and other useful features > entailed by ?GitHub pull request?? > > How do we get that data and confidently and quickly set up a system > hosted on a different provider that allows everyone involved to continue > the same code reviews and discussions etc. without GitHub? That's why I talked about what it's like if discussion continues to happen on b.p.o. Which is the current proposal. ChrisA From rosuav at gmail.com Sun Jan 3 05:24:25 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jan 2016 21:24:25 +1100 Subject: =?UTF-8?Q?Re=3A_GitHub=27s_=C2=B3pull_request=C2=B2_is_proprietary_lock=2Din?= In-Reply-To: References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <85h9ivqcey.fsf@benfinney.id.au> Message-ID: On Sun, Jan 3, 2016 at 8:31 PM, Random832 wrote: > Chris Angelico writes: >> They are. Ultimately, a GitHub pull request is backed by a git pull >> request. > > There is no such thing as a "git pull request", except in the > ordinary english meaning of the word request. It is true that a > pull request is, from one angle, a formalized request for someone > to execute a git pull command. But there is no command to create > a "pull request", nowhere for such a thing to exist in the > repository, etc. As Trevor mentioned, git does have such a thing - it's not as well known as some other uses of the term, but it definitely does exist. Ultimately, though, it's simply a request: "please pull from here". There's not a lot to store. > When I tried github it was also very unclear how someone can pull > to a github repository from a source other than another github > repository with an associated github pull request. I suppose they > could pull into their local repository and then push to github. If you're not using a GitHub PR, then what you're doing is using GH to host your repository. So yes, you pull into your local repo and then push to GH. That's exactly what you'd do with pretty much any other workflow; currently, how would a core committer apply a patch to CPython? Apply it locally, then push. DVCSes pretty much exclusively work that way. > Also if someone puts through a github pull request and then their > patch is accepted, my understanding is that the pull request has > to be "closed" through a github online interface and merely > merging the patch through the git command line will not update the > status on the pull request. GitHub is smart enough to recognize a straight-forward merge; otherwise (maybe you cherry-picked some commits only, or something), you can use standard notation like "Closes #1234" to signal what you're doing. But... >> Since actual bug discussion isn't >> being moved away from bugs.python.org, this should be safe. ... this is still true. > I don't think you can really narrow "actual bug discussion" like > that. Some discussion takes place on the bug tracker, some > discussion takes place here, some discussion takes place on > python-ideas, some discussion takes place on other mailing > lists... and it's suspected that some discussion will take place > on github. All of that discussion has value, and it's not good to > have any of it locked up in a place that cannot be exported. Sure, some discussion takes place on mailing lists. And I'm sure some of the discussion takes place on IRC, and in elevators on the way up to the 34th floor of some building somewhere. Are we going demand a logging IRCbot, and panic because we still can't capture the latter? No. If the discussion is important enough to be kept, it can be done on a place that's designed for keeping it: b.p.o. ChrisA From no.email at nospam.invalid Sun Jan 3 05:42:58 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 03 Jan 2016 02:42:58 -0800 Subject: GitHub's =?utf-8?Q?=C2=B3pull_request=C2=B2?= is proprietary lock-in References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <85h9ivqcey.fsf@benfinney.id.au> Message-ID: <87d1tjc5al.fsf@jester.gateway.pace.com> Chris Angelico writes: > If you're not using a GitHub PR, then what you're doing is using GH to > host your repository. So yes, you pull into your local repo and then > push to GH. What's the point of GH in that situation? From tony at vanderhoff.org Sun Jan 3 05:53:02 2016 From: tony at vanderhoff.org (Tony van der Hoff) Date: Sun, 03 Jan 2016 11:53:02 +0100 Subject: Trailing zeros of 100! In-Reply-To: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Message-ID: <5688FD8E.5070102@vanderhoff.org> On 02/01/16 17:56, Robin Koch wrote: > Am 02.01.2016 um 17:09 schrieb Tony van der Hoff: >> On 02/01/16 16:57, Robin Koch wrote: >>> sum([int(0.2**k*n) for k in range(1, int(log(n, 5))+1)]) >> >> But did you actually test it? > > Yes, should work for n >= 1. > > Why do you ask? > >From your original post: How about: >>> from math import log >>> sum([int(0.2**k*n) for k in range(1, int(log(n, 5))+1)]) That would never work; n is undefined. Now, you may have left that as an exercise for the reader, but without warning, for an obvious newbie such as the OP, that would have been unnecessarily confusing. -- Tony van der Hoff | mailto:tony at vanderhoff.org Ari?ge, France | From jonafleuraime at gmail.com Sun Jan 3 06:03:30 2016 From: jonafleuraime at gmail.com (jonafleuraime at gmail.com) Date: Sun, 3 Jan 2016 03:03:30 -0800 (PST) Subject: Ajax Request + Write to Json Extremely Slow (Webpage Crawler) Message-ID: <43ddcfac-c810-4f85-9b6b-806503ea2b3d@googlegroups.com> I'm editing a simple scraper that crawls a Youtube video's comment page. The crawler uses Ajax to page through comments on the page (infinite scroll) and then saves them to a json file. Even with small number of comments (< 5), it still takes 3+ min for the comments to be added to the json file. I've tried including requests-cache and using ujson instead of json to see if there are any benefits but there's no noticeable difference. You can view the code here: http://stackoverflow.com/questions/34575586/how-to-speed-up-ajax-requests-python-youtube-scraper I'm new to Python so I'm not sure where the bottlenecks are. The finished script will be used to parse through 100,000+ comments so performance is a large factor. -Would using multithreading solve the issue? And if so how would I refactor this to benefit from it? -Or is this strictly a network issue? Thanks! From rosuav at gmail.com Sun Jan 3 07:33:47 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jan 2016 23:33:47 +1100 Subject: =?UTF-8?Q?Re=3A_GitHub=27s_=C2=B3pull_request=C2=B2_is_proprietary_lock=2Din?= In-Reply-To: <87d1tjc5al.fsf@jester.gateway.pace.com> References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <85h9ivqcey.fsf@benfinney.id.au> <87d1tjc5al.fsf@jester.gateway.pace.com> Message-ID: On Sun, Jan 3, 2016 at 9:42 PM, Paul Rubin wrote: > Chris Angelico writes: >> If you're not using a GitHub PR, then what you're doing is using GH to >> host your repository. So yes, you pull into your local repo and then >> push to GH. > > What's the point of GH in that situation? Mainly hosting, plus you can use gh-pages and other features. Plenty. ChrisA From cc.fezeribe at gmail.com Sun Jan 3 09:35:02 2016 From: cc.fezeribe at gmail.com (cc.fezeribe at gmail.com) Date: Sun, 3 Jan 2016 06:35:02 -0800 (PST) Subject: Consistent error Message-ID: <6f54629c-745f-4f75-a267-0f174cc1aea1@googlegroups.com> Good day, please I'm writing the algorithm below in python but unittest keeps giving error no matter how i rewrite it. This is the algorithm: ? Create a function get_algorithm_result to implement the algorithm below Get a list of numbers L1, L2, L3....LN as argument Assume L1 is the largest, ?Largest = L1 Take next number Li from the list and do the following If Largest is less than Li ? ?Largest = Li ?If Li is last number from ?the list then ? return Largest and come out ?Else repeat same process starting from step 3 ? Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime Here's my code in python : def get_algorithm_result( numlist ): ?largest = numlist[0] ?i = 1 ?while ( i < len(numlist) ): ? ?if ( largest < numlist[i]): ? ? ?largest = numlist[i] ? ? ?i = i + 1 numlist[i] = numlist[-1] ? ? ?return largest ? ? ?numlist = [1,2,3,4,5] ? ? ?largest = get_algorithm_result(numlist) ? ? ?print largest def prime_number(x): ?return len([n for n in range(1, x + 1) if x % n == 0]) <= 2 With this code it gives error message saying failure in test_maximum_number_two Then when I remove the numlist[i] = numlist[-1] The error message becomes failure in test_maximum_number_one (Using unit test) Please help, what am I writing wrong? Thanks! From rosuav at gmail.com Sun Jan 3 09:47:45 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Jan 2016 01:47:45 +1100 Subject: Consistent error In-Reply-To: <6f54629c-745f-4f75-a267-0f174cc1aea1@googlegroups.com> References: <6f54629c-745f-4f75-a267-0f174cc1aea1@googlegroups.com> Message-ID: On Mon, Jan 4, 2016 at 1:35 AM, wrote: > Here's my code in python : > > def get_algorithm_result( numlist ): > largest = numlist[0] > i = 1 > while ( i < len(numlist) ): > if ( largest < numlist[i]): > largest = numlist[i] > i = i + 1 > numlist[i] = numlist[-1] > return largest > numlist = [1,2,3,4,5] > largest = get_algorithm_result(numlist) > print largest > def prime_number(x): > return len([n for n in range(1, x + 1) if x % n == 0]) <= 2 I'm a bit uncertain of your indentation here, partly because there's so little of it; what happens in the while loop if the 'if' condition is false? After a 'return' statement, nothing will be executed. If you write code like this: if some_condition: do_stuff() return something do_more_stuff() the second call will never happen - the function will immediately bail out. Maybe you meant for the subsequent code to be unindented? I'm not sure. Have a very careful read of your requirements, and try to lay your code out the exact same way. Put comments against each block of code to show which part of the required algorithm it's performing. That way, you divide the problem up some, and you can look at each piece separately. ChrisA From torriem at gmail.com Sun Jan 3 10:05:00 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 03 Jan 2016 08:05:00 -0700 Subject: GitHub's =?UTF-8?B?77+9cHVsbCByZXF1ZXN077+9IGlzIHByb3ByaWV0YQ==?= =?UTF-8?B?cnkgbG9jay1pbg==?= In-Reply-To: References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> Message-ID: <5689389C.2060803@gmail.com> On 01/02/2016 09:56 PM, Michael Vilain wrote: > Seriously, don't like git and the gitflow, find a project where they do > things more to your liking. I do like git and the git work-flow. Seems like github is doing an end-run around several of the key features of git and the git work-flow to keep people from going outside their environment. This is definitely not the work flow Linus originally had in mind, though he is not terribly upset about it all as I think kernel development is now exclusively on github. From torriem at gmail.com Sun Jan 3 10:14:48 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 03 Jan 2016 08:14:48 -0700 Subject: GitHub's =?UTF-8?B?77+9cHVsbCByZXF1ZXN077+9IGlzIHByb3ByaWV0YQ==?= =?UTF-8?B?cnkgbG9jay1pbg==?= In-Reply-To: References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <5689389C.2060803@gmail.com> Message-ID: <56893AE8.8050204@gmail.com> On 01/03/2016 08:09 AM, Bernardo Sulzbach wrote: > On Sun, Jan 3, 2016 at 1:05 PM, Michael Torrie wrote: >> kernel development is now exclusively on github. >> > > No it is not. If they have (now) 88 PR is because people don't RTFM. Good to know. From steve at pearwood.info Sun Jan 3 10:42:00 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 04 Jan 2016 02:42:00 +1100 Subject: Ajax Request + Write to Json Extremely Slow (Webpage Crawler) References: <43ddcfac-c810-4f85-9b6b-806503ea2b3d@googlegroups.com> Message-ID: <5689414a$0$1616$c3e8da3$5496439d@news.astraweb.com> On Sun, 3 Jan 2016 10:03 pm, jonafleuraime at gmail.com wrote: > I'm editing a simple scraper that crawls a Youtube video's comment page. > The crawler uses Ajax to page through comments on the page (infinite > scroll) and then saves them to a json file. Even with small number of > comments (< 5), it still takes 3+ min for the comments to be added to the > json file. > > I've tried including requests-cache and using ujson instead of json to see > if there are any benefits but there's no noticeable difference. Before making random changes to the code to see if it speeds it up, try running it under the profiler and see what it says. https://pymotw.com/2/profile/index.html#module-profile https://docs.python.org/2/library/profile.html > You can view the code here: > http://stackoverflow.com/questions/34575586/how-to-speed-up-ajax-requests-python-youtube-scraper I see that you already have an answer that you should try using threads since the process is I/O bound. (The time taken is supposedly dominated by the time it takes to download data from the internet.) That may be true, but I also see something which *may* be a warning sign: while page_token: [...] page_token, html = response reply_cids += extract_reply_cids(html) `reply_cids` is a list, and repeatedly calling += on a list *may* be slow. If += is implemented the naive way, as addition and assignment, it probably will be slow. This may entirely be a red herring, but if it were my code, I'd try replacing that last line with: reply_cids.extend(extract_reply_cids(html)) and see if it makes any difference. If it doesn't, you can keep the new version or revert back to the version using +=, entirely up to you. -- Steven From cc.fezeribe at gmail.com Sun Jan 3 10:59:48 2016 From: cc.fezeribe at gmail.com (cc.fezeribe at gmail.com) Date: Sun, 3 Jan 2016 07:59:48 -0800 (PST) Subject: Consistent error In-Reply-To: References: <6f54629c-745f-4f75-a267-0f174cc1aea1@googlegroups.com> Message-ID: <2a7c4d1e-b7ba-4fb7-845f-440026af3b59@googlegroups.com> Thanks Chris! Don't worry about the indent, will fix it I've rewritten it to this- def get_algorithm_result( numlist ): > largest = numlist[0] > i = 1 > while ( i < len(numlist) ): i = i + 1 > if ( largest < numlist[i]): > largest = numlist[i] > numlist[i] = numlist[-1] > numlist = [1,2,3,4,5] return largest > def prime_number(x): > return len([n for n in range(1, x + 1) if x % n == 0]) <= 2 But it still gives the test_maximum_number_one error. Please if you have any ideas what else I should change or add, let me know. Thanks! From rosuav at gmail.com Sun Jan 3 11:14:07 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Jan 2016 03:14:07 +1100 Subject: Consistent error In-Reply-To: <2a7c4d1e-b7ba-4fb7-845f-440026af3b59@googlegroups.com> References: <6f54629c-745f-4f75-a267-0f174cc1aea1@googlegroups.com> <2a7c4d1e-b7ba-4fb7-845f-440026af3b59@googlegroups.com> Message-ID: On Mon, Jan 4, 2016 at 2:59 AM, wrote: > Thanks Chris! > Don't worry about the indent, will fix it > I've rewritten it to this- > > def get_algorithm_result( numlist ): >> largest = numlist[0] >> i = 1 >> while ( i < len(numlist) ): > i = i + 1 >> if ( largest < numlist[i]): >> largest = numlist[i] >> numlist[i] = numlist[-1] >> numlist = [1,2,3,4,5] > return largest >> def prime_number(x): >> return len([n for n in range(1, x + 1) if x % n == 0]) <= 2 > > But it still gives the test_maximum_number_one error. > Please if you have any ideas what else I should change or add, let me know. Thanks! Well, the algorithmic comments I mentioned would still help you to figure out what's going on :) ChrisA From ian.g.kelly at gmail.com Sun Jan 3 11:27:50 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 3 Jan 2016 09:27:50 -0700 Subject: Consistent error In-Reply-To: <2a7c4d1e-b7ba-4fb7-845f-440026af3b59@googlegroups.com> References: <6f54629c-745f-4f75-a267-0f174cc1aea1@googlegroups.com> <2a7c4d1e-b7ba-4fb7-845f-440026af3b59@googlegroups.com> Message-ID: On Sun, Jan 3, 2016 at 8:59 AM, wrote: > Thanks Chris! > Don't worry about the indent, will fix it > I've rewritten it to this- > > def get_algorithm_result( numlist ): >> largest = numlist[0] >> i = 1 >> while ( i < len(numlist) ): > i = i + 1 >> if ( largest < numlist[i]): >> largest = numlist[i] >> numlist[i] = numlist[-1] >> numlist = [1,2,3,4,5] > return largest This is even harder to read than before since some of the lines are now quoted and some are not. >> def prime_number(x): >> return len([n for n in range(1, x + 1) if x % n == 0]) <= 2 > > But it still gives the test_maximum_number_one error. > Please if you have any ideas what else I should change or add, let me know. Thanks! It's hard to give any specific advice about fixing the unittest failure without knowing what the test is testing. These two lines don't seem to have anything to do with the algorithm that you quoted in the first post, however: > numlist[i] = numlist[-1] > numlist = [1,2,3,4,5] It looks like you should kill everything in this function after the assignment to largest and then start reimplementing the algorithm again from the " If Li is last number from the list" step. From cc.fezeribe at gmail.com Sun Jan 3 11:55:29 2016 From: cc.fezeribe at gmail.com (cc.fezeribe at gmail.com) Date: Sun, 3 Jan 2016 08:55:29 -0800 (PST) Subject: Consistent error In-Reply-To: References: <6f54629c-745f-4f75-a267-0f174cc1aea1@googlegroups.com> <2a7c4d1e-b7ba-4fb7-845f-440026af3b59@googlegroups.com> Message-ID: <50a52770-8ee2-47fd-b947-514937edebd9@googlegroups.com> On Sunday, January 3, 2016 at 5:14:33 PM UTC+1, Chris Angelico wrote: > On Mon, Jan 4, 2016 at 2:59 AM, wrote: > > Thanks Chris! > > Don't worry about the indent, will fix it > > I've rewritten it to this- > > > > def get_algorithm_result( numlist ): > >> largest = numlist[0] > >> i = 1 > >> while ( i < len(numlist) ): > > i = i + 1 > >> if ( largest < numlist[i]): > >> largest = numlist[i] > >> numlist[i] = numlist[-1] > >> numlist = [1,2,3,4,5] > > return largest > >> def prime_number(x): > >> return len([n for n in range(1, x + 1) if x % n == 0]) <= 2 > > > > But it still gives the test_maximum_number_one error. > > Please if you have any ideas what else I should change or add, let me know. Thanks! > > Well, the algorithmic comments I mentioned would still help you to > figure out what's going on :) > > ChrisA Thanks Chris! You possess great knowledge I'd like to have... ... well I'm just a newbie... From cc.fezeribe at gmail.com Sun Jan 3 11:59:05 2016 From: cc.fezeribe at gmail.com (cc.fezeribe at gmail.com) Date: Sun, 3 Jan 2016 08:59:05 -0800 (PST) Subject: Consistent error In-Reply-To: References: <6f54629c-745f-4f75-a267-0f174cc1aea1@googlegroups.com> <2a7c4d1e-b7ba-4fb7-845f-440026af3b59@googlegroups.com> Message-ID: <0896ace8-60fe-44af-b6d8-b54186cc48e9@googlegroups.com> On Sunday, January 3, 2016 at 5:28:49 PM UTC+1, Ian wrote: > On Sun, Jan 3, 2016 at 8:59 AM, wrote: > > Thanks Chris! > > Don't worry about the indent, will fix it > > I've rewritten it to this- > > > > def get_algorithm_result( numlist ): > >> largest = numlist[0] > >> i = 1 > >> while ( i < len(numlist) ): > > i = i + 1 > >> if ( largest < numlist[i]): > >> largest = numlist[i] > >> numlist[i] = numlist[-1] > >> numlist = [1,2,3,4,5] > > return largest > > This is even harder to read than before since some of the lines are > now quoted and some are not. > > >> def prime_number(x): > >> return len([n for n in range(1, x + 1) if x % n == 0]) <= 2 > > > > But it still gives the test_maximum_number_one error. > > Please if you have any ideas what else I should change or add, let me know. Thanks! > > It's hard to give any specific advice about fixing the unittest > failure without knowing what the test is testing. These two lines > don't seem to have anything to do with the algorithm that you quoted > in the first post, however: > > > numlist[i] = numlist[-1] > > numlist = [1,2,3,4,5] > > It looks like you should kill everything in this function after the > assignment to largest and then start reimplementing the algorithm > again from the " If Li is last number from the list" step. Thanks Ian! The algorithm is actually two part question, that's why the prime number part in the answer. And good enough that part isn't raising any errors. Still going over it hoping to get it right. Appreciate your input, God bless! From alister.ware at ntlworld.com Sun Jan 3 13:22:57 2016 From: alister.ware at ntlworld.com (Alister) Date: Sun, 3 Jan 2016 18:22:57 +0000 Subject: Consistent error In-Reply-To: <50a52770-8ee2-47fd-b947-514937edebd9@googlegroups.com> References: <6f54629c-745f-4f75-a267-0f174cc1aea1@googlegroups.com> <2a7c4d1e-b7ba-4fb7-845f-440026af3b59@googlegroups.com> <50a52770-8ee2-47fd-b947-514937edebd9@googlegroups.com> Message-ID: <5Gdiy.666591$JF6.324978@fx39.am4> On 03/01/16 16:55, cc.fezeribe at gmail.com wrote: > On Sunday, January 3, 2016 at 5:14:33 PM UTC+1, Chris Angelico wrote: >> On Mon, Jan 4, 2016 at 2:59 AM, wrote: >>> Thanks Chris! >>> Don't worry about the indent, will fix it >>> I've rewritten it to this- >>> >>> def get_algorithm_result( numlist ): >>>> largest = numlist[0] >>>> i = 1 >>>> while ( i < len(numlist) ): >>> i = i + 1 >>>> if ( largest < numlist[i]): >>>> largest = numlist[i] >>>> numlist[i] = numlist[-1] >>>> numlist = [1,2,3,4,5] >>> return largest >>>> def prime_number(x): >>>> return len([n for n in range(1, x + 1) if x % n == 0]) <= 2 >>> >>> But it still gives the test_maximum_number_one error. >>> Please if you have any ideas what else I should change or add, let me know. Thanks! >> >> Well, the algorithmic comments I mentioned would still help you to >> figure out what's going on :) >> >> ChrisA > > > > Thanks Chris! > You possess great knowledge I'd like to have... > ... well I'm just a newbie... > this is why Criss has given you an indication on where to start with debugging your code. Had he simply given you corrected code you would not necessarily learn why. you learn much ore when things go wrong & you fix them that you ever will buy simply having correct code. From kw at codebykevin.com Sun Jan 3 16:58:05 2016 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 3 Jan 2016 16:58:05 -0500 Subject: =?UTF-8?Q?Re:_GitHub's_=e2=80=9cpull_request=e2=80=9d_is_proprietar?= =?UTF-8?Q?y_lock-in?= In-Reply-To: References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> Message-ID: On 1/2/16 11:43 PM, Ben Finney wrote: > That and other vendor-locked workflow aspects of GitHub makes it a poor > choice for communities that want to retain the option of control over > their processes and data. The Tcl community has moved to Fossil with great success: http://www.fossil-scm.org Lightweight DCVS, integrated bug tracking, rock-solid code (authored by D. Richard Hipp, uses SQLite as its store). The transition was non-trivial: the Tcl core developers had to move over a decade of commit history from CVS at Sourceforge to Fossil, which they did, successfully. One of the reasons Fossil was chosen is exactly this: to maintain the code independent of a third-party platform. (At the time of the transition, in 2011, Sourceforge was removing support for CVS, they had a server outage for over a week, and other issues were giving the community pause on continuing to use SF for hosting.) I'm not a hardcore Git user so have no substantive opinions on the merits of Git or Github per se: I have a Github account and have contributed code via pull requests to projects hosted on it. But I found learning Fossil very simple. And using Fossil does not preclude mirroring the codebase in Git; there is a Tcl/Tk mirror at Github. Just a thought. --Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com From rxjwg98 at gmail.com Sun Jan 3 19:28:30 2016 From: rxjwg98 at gmail.com (Robert) Date: Sun, 3 Jan 2016 16:28:30 -0800 (PST) Subject: What use of 'sum' in this line code? Message-ID: Hi, I find below code snippet on line: ////////// m = 10 theta_A = 0.8 theta_B = 0.3 theta_0 = [theta_A, theta_B] coin_A = bernoulli(theta_A) coin_B = bernoulli(theta_B) xs = map(sum, [coin_A.rvs(m), coin_A.rvs(m), coin_B.rvs(m), coin_A.rvs(m), coin_B.rvs(m)]) ///////// I see [coin_A.rvs(m), coin_A.rvs(m), coin_B.rvs(m), coin_A.rvs(m), coin_B.rvs(m)] is simply a list, but I don't know what use of 'sum' in this line. I replace the random number with a simple list: /////// yy=map(sum, [13, 22, 33, 41]) In [24]: yy Out[24]: [13, 22, 33, 41] /////// I don't see 'sum' has any effect above. The code source is from: #http://people.duke.edu/~ccc14/sta-663/EMAlgorithm.html What could you help me on the 'sum'? Thanks, From steve at pearwood.info Sun Jan 3 19:43:41 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 04 Jan 2016 11:43:41 +1100 Subject: What use of 'sum' in this line code? References: Message-ID: <5689c03f$0$1621$c3e8da3$5496439d@news.astraweb.com> On Mon, 4 Jan 2016 11:28 am, Robert wrote: > Hi, > > I find below code snippet on line: > > > ////////// > m = 10 > theta_A = 0.8 > theta_B = 0.3 > theta_0 = [theta_A, theta_B] > > coin_A = bernoulli(theta_A) > coin_B = bernoulli(theta_B) > > xs = map(sum, [coin_A.rvs(m), coin_A.rvs(m), coin_B.rvs(m), coin_A.rvs(m), > coin_B.rvs(m)]) ///////// > > I see > [coin_A.rvs(m), coin_A.rvs(m), coin_B.rvs(m), coin_A.rvs(m), > [coin_B.rvs(m)] > > is simply a list, A list of what? Without knowing what coin_A.rvs(m) returns, it is impossible to know what sum will do. > but I don't know what use of 'sum' in this line. > I replace the random number with a simple list: > /////// > yy=map(sum, [13, 22, 33, 41]) > In [24]: yy > Out[24]: [13, 22, 33, 41] I do not get that result. I get an error: py> yy = map(sum, [13, 22, 33, 41]) Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not iterable Try replacing the list-of-mystery-things with a list of lists: map(sum, [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) and see what you get. -- Steven From ben.usenet at bsb.me.uk Sun Jan 3 19:48:29 2016 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Mon, 04 Jan 2016 00:48:29 +0000 Subject: What use of 'sum' in this line code? References: Message-ID: <87ziwmrwyq.fsf@bsb.me.uk> Robert writes: > I find below code snippet on line: > > ////////// > m = 10 > theta_A = 0.8 > theta_B = 0.3 > theta_0 = [theta_A, theta_B] > > coin_A = bernoulli(theta_A) > coin_B = bernoulli(theta_B) > > xs = map(sum, [coin_A.rvs(m), coin_A.rvs(m), coin_B.rvs(m), > coin_A.rvs(m), coin_B.rvs(m)]) > ///////// > > I see > [coin_A.rvs(m), coin_A.rvs(m), coin_B.rvs(m), coin_A.rvs(m), coin_B.rvs(m)] > > is simply a list, but I don't know what use of 'sum' in this line. > I replace the random number with a simple list: > /////// > yy=map(sum, [13, 22, 33, 41]) > > In [24]: yy > Out[24]: [13, 22, 33, 41] > /////// > > I don't see 'sum' has any effect above. map applies the first argument (sum) to the elements of the second. You won't see any effect unless these elements are sequences that can be summed. For example: map(sum, [[1, 2], [2, 3], [3, 4]]) bernoulli(theta_A) is a statistical distribution, with the parameter frozen in ready to have samples drawn from it. coin_A.rvs(10) requests 10 random variates from the distribution -- it's an array containing ten 0/1 elements. Thus the map(sum, ...) call does have an array or array to work with. [Not being a Python expect I've probably got some of the terminology wrong but I hope the gist of it clear.] -- Ben. From random832 at fastmail.com Sun Jan 3 19:51:36 2016 From: random832 at fastmail.com (Random832) Date: Sun, 03 Jan 2016 19:51:36 -0500 Subject: GitHub's =?utf-8?Q?=E2=80=9Cpull_request=E2=80=9D?= is proprietary lock-in References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <85poxjqnlj.fsf_-_@benfinney.id.au> Message-ID: Just as a general comment, I note there are now at least four mangled versions of this subject header, and threading is already fragile enough on this list. I think in the future it would be best to avoid non-ASCII characters in subject lines. From __peter__ at web.de Sun Jan 3 19:53:51 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 Jan 2016 01:53:51 +0100 Subject: What use of 'sum' in this line code? References: Message-ID: Robert wrote: > Hi, > > I find below code snippet on line: > > > ////////// > m = 10 > theta_A = 0.8 > theta_B = 0.3 > theta_0 = [theta_A, theta_B] > > coin_A = bernoulli(theta_A) > coin_B = bernoulli(theta_B) > > xs = map(sum, [coin_A.rvs(m), coin_A.rvs(m), coin_B.rvs(m), coin_A.rvs(m), > coin_B.rvs(m)]) ///////// > > I see > [coin_A.rvs(m), coin_A.rvs(m), coin_B.rvs(m), coin_A.rvs(m), > [coin_B.rvs(m)] > > is simply a list, but I don't know what use of 'sum' in this line. > I replace the random number with a simple list: > /////// > yy=map(sum, [13, 22, 33, 41]) > > In [24]: yy > Out[24]: [13, 22, 33, 41] > /////// > > I don't see 'sum' has any effect above. > The code source is from: > #http://people.duke.edu/~ccc14/sta-663/EMAlgorithm.html > > > What could you help me on the 'sum'? >>> import numpy >>> values = [13, 22, 33, 41] >>> map(numpy.sum, values) [13, 22, 33, 41] >>> values2 = [[1, 2], [3, 4]] >>> map(numpy.sum, values2) [3, 7] In Python 2 map(sum, values) applies sum to every value in the list and returns the resulting list of sums. Apparently the numpy developers found it convenient that sum(scalar) == scalar holds. From mviljamaa at kapsi.fi Sun Jan 3 21:40:03 2016 From: mviljamaa at kapsi.fi (mviljamaa) Date: Mon, 04 Jan 2016 04:40:03 +0200 Subject: How to union nested Sets / A single set from nested sets? Message-ID: I'm forming sets by set.adding to sets and this leads to sets such as: Set([ImmutableSet(['a', ImmutableSet(['a'])]), ImmutableSet(['b', 'c'])]) Is there way union these to a single set, i.e. get Set(['a', 'b', 'c']) ? From rxjwg98 at gmail.com Sun Jan 3 21:44:03 2016 From: rxjwg98 at gmail.com (Robert) Date: Sun, 3 Jan 2016 18:44:03 -0800 (PST) Subject: What use of 'sum' in this line code? In-Reply-To: References: Message-ID: <23b6741e-55cf-4596-8fad-43c90c1e8556@googlegroups.com> On Sunday, January 3, 2016 at 7:54:13 PM UTC-5, Peter Otten wrote: > Robert wrote: > > > Hi, > > > > I find below code snippet on line: > > > > > > ////////// > > m = 10 > > theta_A = 0.8 > > theta_B = 0.3 > > theta_0 = [theta_A, theta_B] > > > > coin_A = bernoulli(theta_A) > > coin_B = bernoulli(theta_B) > > > > xs = map(sum, [coin_A.rvs(m), coin_A.rvs(m), coin_B.rvs(m), coin_A.rvs(m), > > coin_B.rvs(m)]) ///////// > > > > I see > > [coin_A.rvs(m), coin_A.rvs(m), coin_B.rvs(m), coin_A.rvs(m), > > [coin_B.rvs(m)] > > > > is simply a list, but I don't know what use of 'sum' in this line. > > I replace the random number with a simple list: > > /////// > > yy=map(sum, [13, 22, 33, 41]) > > > > In [24]: yy > > Out[24]: [13, 22, 33, 41] > > /////// > > > > I don't see 'sum' has any effect above. > > The code source is from: > > #http://people.duke.edu/~ccc14/sta-663/EMAlgorithm.html > > > > > > What could you help me on the 'sum'? > > >>> import numpy > >>> values = [13, 22, 33, 41] > >>> map(numpy.sum, values) > [13, 22, 33, 41] > >>> values2 = [[1, 2], [3, 4]] > >>> map(numpy.sum, values2) > [3, 7] > > In Python 2 map(sum, values) applies sum to every value in the list and > returns the resulting list of sums. Apparently the numpy developers found it > convenient that sum(scalar) == scalar holds. Thanks, all you say are correct in one way or the other. I just notice that it uses coin_A.rvs(m) (m=10). Thus, it sums 10 random numbers. From rustompmody at gmail.com Sun Jan 3 22:04:53 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 3 Jan 2016 19:04:53 -0800 (PST) Subject: raise None In-Reply-To: <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> References: <56847239$0$1590$c3e8da3$5496439d@news.astraweb.com> <5684842a$0$1596$c3e8da3$5496439d@news.astraweb.com> <5684aa1a$0$1602$c3e8da3$5496439d@news.astraweb.com> <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5c824139-510c-4afd-814a-03355187fa3f@googlegroups.com> On Thursday, December 31, 2015 at 9:05:58 PM UTC+5:30, Steven D'Aprano wrote: > But I think it is a real issue. I believe in beautiful tracebacks that give > you just the right amount of information, neither too little nor two much. > Debugging is hard enough with being given more information than you need > and having to decide what bits to ignore and which are important. It would be nice if the tutorial (FAQ? Lang-Ref??) had a section on how to wade tracebacks From rosuav at gmail.com Sun Jan 3 22:31:48 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Jan 2016 14:31:48 +1100 Subject: raise None In-Reply-To: <5c824139-510c-4afd-814a-03355187fa3f@googlegroups.com> References: <56847239$0$1590$c3e8da3$5496439d@news.astraweb.com> <5684842a$0$1596$c3e8da3$5496439d@news.astraweb.com> <5684aa1a$0$1602$c3e8da3$5496439d@news.astraweb.com> <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> <5c824139-510c-4afd-814a-03355187fa3f@googlegroups.com> Message-ID: On Mon, Jan 4, 2016 at 2:04 PM, Rustom Mody wrote: > On Thursday, December 31, 2015 at 9:05:58 PM UTC+5:30, Steven D'Aprano wrote: >> But I think it is a real issue. I believe in beautiful tracebacks that give >> you just the right amount of information, neither too little nor two much. >> Debugging is hard enough with being given more information than you need >> and having to decide what bits to ignore and which are important. > > > It would be nice if the tutorial (FAQ? Lang-Ref??) had a section on how to wade tracebacks Hmm, I don't think that's a language reference question. It's more something that I would put into a series of blog posts. But I agree - this is a great topic to discuss. Ultimately, debugging consists of two things: find out more about what's going on, and dig through the data from the first step to figure out what's significant. Tips for helping people master either half of that are well worth publishing. ChrisA From steve at pearwood.info Sun Jan 3 22:48:36 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 04 Jan 2016 14:48:36 +1100 Subject: raise None References: <56847239$0$1590$c3e8da3$5496439d@news.astraweb.com> <5684842a$0$1596$c3e8da3$5496439d@news.astraweb.com> <5684aa1a$0$1602$c3e8da3$5496439d@news.astraweb.com> <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> <5c824139-510c-4afd-814a-03355187fa3f@googlegroups.com> Message-ID: <5689eb94$0$1584$c3e8da3$5496439d@news.astraweb.com> On Mon, 4 Jan 2016 02:31 pm, Chris Angelico wrote: > On Mon, Jan 4, 2016 at 2:04 PM, Rustom Mody wrote: >> On Thursday, December 31, 2015 at 9:05:58 PM UTC+5:30, Steven D'Aprano >> wrote: >>> But I think it is a real issue. I believe in beautiful tracebacks that >>> give you just the right amount of information, neither too little nor >>> two much. Debugging is hard enough with being given more information >>> than you need and having to decide what bits to ignore and which are >>> important. >> >> >> It would be nice if the tutorial (FAQ? Lang-Ref??) had a section on how >> to wade tracebacks > > Hmm, I don't think that's a language reference question. It's more > something that I would put into a series of blog posts. Or the tutorial, like Rustom suggested :-) -- Steven From rosuav at gmail.com Sun Jan 3 22:56:45 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Jan 2016 14:56:45 +1100 Subject: raise None In-Reply-To: <5689eb94$0$1584$c3e8da3$5496439d@news.astraweb.com> References: <56847239$0$1590$c3e8da3$5496439d@news.astraweb.com> <5684842a$0$1596$c3e8da3$5496439d@news.astraweb.com> <5684aa1a$0$1602$c3e8da3$5496439d@news.astraweb.com> <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> <5c824139-510c-4afd-814a-03355187fa3f@googlegroups.com> <5689eb94$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 4, 2016 at 2:48 PM, Steven D'Aprano wrote: > On Mon, 4 Jan 2016 02:31 pm, Chris Angelico wrote: > >> On Mon, Jan 4, 2016 at 2:04 PM, Rustom Mody wrote: >>> On Thursday, December 31, 2015 at 9:05:58 PM UTC+5:30, Steven D'Aprano >>> wrote: >>>> But I think it is a real issue. I believe in beautiful tracebacks that >>>> give you just the right amount of information, neither too little nor >>>> two much. Debugging is hard enough with being given more information >>>> than you need and having to decide what bits to ignore and which are >>>> important. >>> >>> >>> It would be nice if the tutorial (FAQ? Lang-Ref??) had a section on how >>> to wade tracebacks >> >> Hmm, I don't think that's a language reference question. It's more >> something that I would put into a series of blog posts. > > Or the tutorial, like Rustom suggested :-) Not sure it really belongs there; the tutorial tends to keep to short and un-nested pieces of code, where this kind of technique really comes into its own with dozen-line tracebacks. The FAQ could have a link to it, but honestly, the best python.org place I can think of is the wiki. It's not something that has a single straight-forward answer; it's "when you're staring at this much info, here are some ideas for boiling it down to what matters". ChrisA From torriem at gmail.com Sun Jan 3 23:16:17 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 03 Jan 2016 21:16:17 -0700 Subject: GitHub's =?windows-1252?Q?=93pull_request=94_is_propri?= =?windows-1252?Q?etary_lock-in?= In-Reply-To: References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <85poxjqnlj.fsf_-_@benfinney.id.au> Message-ID: <5689F211.3060706@gmail.com> On 01/03/2016 05:51 PM, Random832 wrote: > Just as a general comment, I note there are now at least four mangled > versions of this subject header, and threading is already fragile enough > on this list. I think in the future it would be best to avoid non-ASCII > characters in subject lines. I noticed this too. Though threading based on message-id is working quite well, as designed! From rustompmody at gmail.com Sun Jan 3 23:46:29 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 3 Jan 2016 20:46:29 -0800 (PST) Subject: raise None In-Reply-To: References: <56847239$0$1590$c3e8da3$5496439d@news.astraweb.com> <5684842a$0$1596$c3e8da3$5496439d@news.astraweb.com> <5684aa1a$0$1602$c3e8da3$5496439d@news.astraweb.com> <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> <5c824139-510c-4afd-814a-03355187fa3f@googlegroups.com> Message-ID: <31bba90b-d098-4c42-bfca-4ff650dc8586@googlegroups.com> On Monday, January 4, 2016 at 9:02:16 AM UTC+5:30, Chris Angelico wrote: > On Mon, Jan 4, 2016 at 2:04 PM, Rustom Mody wrote: > > On Thursday, December 31, 2015 at 9:05:58 PM UTC+5:30, Steven D'Aprano wrote: > >> But I think it is a real issue. I believe in beautiful tracebacks that give > >> you just the right amount of information, neither too little nor two much. > >> Debugging is hard enough with being given more information than you need > >> and having to decide what bits to ignore and which are important. > > > > > > It would be nice if the tutorial (FAQ? Lang-Ref??) had a section on how to wade tracebacks > > Hmm, I don't think that's a language reference question. It's more > something that I would put into a series of blog posts. But I agree - > this is a great topic to discuss. Ultimately, debugging consists of > two things: find out more about what's going on, and dig through the > data from the first step to figure out what's significant. Tips for > helping people master either half of that are well worth publishing. Its one of the great paradoxes of programming pedagogy: - Everyone who talks programs by default talks right programs - Everyone who writes programs by default writes wrong programs And if you dont believe that, tell me after having taught programming for 30 odd years :-) From random832 at fastmail.com Sun Jan 3 23:58:36 2016 From: random832 at fastmail.com (Random832) Date: Sun, 03 Jan 2016 23:58:36 -0500 Subject: GitHub's =?utf-8?Q?=E2=80=9Cpull_request=E2=80=9D?= is proprietary lock-in References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <85poxjqnlj.fsf_-_@benfinney.id.au> <5689F211.3060706@gmail.com> Message-ID: Michael Torrie writes: > I noticed this too. Though threading based on message-id is working > quite well, as designed! It doesn't work as well here as elsewhere, though, because message-ids get rewritten by the usenet gateway, so the IDs referenced in people's headers differ depending on whether they're replying via usenet or the mailing list or gmane. Threads already get mangled enough by this even when the subject stays the same. From steve at pearwood.info Mon Jan 4 00:19:23 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 04 Jan 2016 16:19:23 +1100 Subject: raise None References: <56847239$0$1590$c3e8da3$5496439d@news.astraweb.com> <5684842a$0$1596$c3e8da3$5496439d@news.astraweb.com> <5684aa1a$0$1602$c3e8da3$5496439d@news.astraweb.com> <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> <85r3i2s776.fsf@benfinney.id.au> Message-ID: <568a00dc$0$1617$c3e8da3$5496439d@news.astraweb.com> On Fri, 1 Jan 2016 10:27 am, Ben Finney wrote: > If I could have the traceback continue into the C code and tell me the > line of C code that raised the exception, *that's* what I'd choose. If you are serious about believing this would be a good thing, you can open a ticket on the bug tracker and make an enhancement request that tracebacks generated from builtins should expose their internal details: >>> 7 + [] Traceback (most recent call last): File "", line 1, in File "longobject.c", line 3008, in long_add File "longobject.c", line 1425, in CHECK_BINOP TypeError: unsupported operand type(s) for +: 'int' and 'list' When you open that ticket, be so good as to add me to the Nosy list. -- Steven From steve at pearwood.info Mon Jan 4 00:19:51 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 04 Jan 2016 16:19:51 +1100 Subject: raise None References: <56847239$0$1590$c3e8da3$5496439d@news.astraweb.com> <5684842a$0$1596$c3e8da3$5496439d@news.astraweb.com> <5684aa1a$0$1602$c3e8da3$5496439d@news.astraweb.com> <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> <85r3i2s776.fsf@benfinney.id.au> Message-ID: <568a00f9$0$1617$c3e8da3$5496439d@news.astraweb.com> On Fri, 1 Jan 2016 09:48 am, Chris Angelico wrote: > On Fri, Jan 1, 2016 at 7:18 AM, Ben Finney > wrote: [...] >> As best I can tell, Steven is advocating a way to obscure information >> from the traceback, on the assumption the writer of a library knows that >> I don't want to see it. >> >> Given how very often such decisions make my debugging tasks needlessly >> difficult, I'm not seeing how that's a desirable feature. > > What Steven's actually advocating is removing a difference between > Python code and native code. Compare: Well, not quite. What I'm really doing is two-fold: (1) reminding people that the part of the code which determines the existence of an error need not be the part of the code which actually calls raise; and (2) suggesting a tiny change to the semantics of raise which would make this idiom easier to use. (Namely, have "raise None" be a no-op.) I'm saddened but not astonished at just how much opposition there is to point (1), even though it is something which Python has been capable of since the earliest 1.x days. Exceptions are first-class objects, and just because raising an exception immediately after a test is a common idiom: if condition: raise SomeError('whatever') doesn't mean it is *always* the best idiom. I have identified a common situation in my own code where I believe that there is a better idiom. From the reaction of others, one might think I've suggested getting rid of exceptions altogether and replacing them with GOTO :-) Let's step back a bit and consider what we might do if Python were a less capable language. We might be *forced* to perform error handling via status codes, passed from function to function as needed, until we reach the top level of code and either print the error code or the program's intended output. None of us want that, but maybe there are cases where a less extreme version of the same thing is useful. Just because I detect an error condition in one function doesn't necessarily mean I want to trigger an exception at that point. Sometimes it is useful to delay raising the exception. Suppose I write a validation function that returns a status code, perhaps an int, or a Enum: def _validate(arg): if condition(arg): return CONDITION_ERROR elif other_condition(arg): return OTHER_ERROR return SUCCESS def func(x): status = _validate(x) if status == CONDITION_ERROR: raise ConditionError("condition failed") elif status == OTHER_ERROR: raise OtherError("other condition failed") assert status == SUCCESS ... Don't worry about *why* I want to do this, I have my reasons. Maybe I want to queue up a whole bunch of exceptions before doing something with them, or conditionally decide whether or not raise, like unittest. Perhaps I can do different sorts of processing of different status codes, including recovery from some: def func(x): status = _validate(x) if status == CONDITION_ERROR: warnings.warn(msg) x = massage(x) status = SUCCESS elif status == OTHER_ERROR: raise SomeError("an error occurred") assert status == SUCCESS do_the_real_work(x) There's no reason to say that I *must* raise an exception the instant I see a problem. But why am I returning a status code? This is Python, not C or bash, and I have a much more powerful and richer set of values to work with. I can return an error type, and an error message: def _validate(arg): if condition(arg): return (ConditionError, "condition failed") elif other_condition(arg): return (OtherError, "something broke") return None But if we've come this far, why mess about with tuples when we have an object oriented language with first class exception objects? def _validate(arg): if condition(arg): return ConditionError("condition failed") elif other_condition(arg): return OtherError("something broke") return None The caller func still decides what to do with the status code, and can process it when needed. If the error is unrecoverable, it can raise. In that case, the source of the exception is func, not _validate. Just look at the source code, it tells you right there where the exception comes from: def func(x): exc = _validate(x) if exc is not None: raise exc # <<<< this is the line you see in the traceback do_the_real_work(x) This isn't "hiding information", but it might be *information hiding*, and it is certainly no worse than this: def spam(): if condition: some_long_message = "something ...".format( many, extra, arguments) exc = SomeError(some_long_message, data) raise exc # <<<< this is the line you see in the traceback If I have a lot of functions that use the same exception, I can refactor them so that building the exception object occurs elsewhere: def spam(): if condition: exc = _build_exception() raise exc # <<<< this is STILL the line you see in the traceback and likewise for actually checking the condition: def spam(): exc = _validate_and_build_exception() if exc is not None: raise exc # <<<<<<<<<<<< Fundamentally, _validate is an implementation detail. The semantics of func will remain unchanged whether it does error checking inside itself, or passes it off to another helper function. The very existence of the helper function is *irrelevant*. We have true separation of concerns: (1) _validate decides whether some condition (nominally an error condition) applies or not; (2) while the caller func decides whether it can recover from that error or needs to raise. (Aside: remember in my use-case I'm not talking about a single caller func. There might be dozens of them.) If func decides it needs to raise, the fact that _validate made the decision that the condition applies is irrelevant. The only time it is useful to see _validate in the traceback is if _validate fails and raises an exception itself. -- Steven From no.email at nospam.invalid Mon Jan 4 00:29:29 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 03 Jan 2016 21:29:29 -0800 Subject: GitHub's =?utf-8?Q?=C2=B3pull_request=C2=B2?= is proprietary lock-in References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <85h9ivqcey.fsf@benfinney.id.au> <87d1tjc5al.fsf@jester.gateway.pace.com> Message-ID: <878u45di9y.fsf@jester.gateway.pace.com> Chris Angelico writes: > On Sun, Jan 3, 2016 at 9:42 PM, Paul Rubin wrote: >> Chris Angelico writes: >>> If you're not using a GitHub PR, then what you're doing is using GH to >>> host your repository. >> What's the point of GH in that situation? > Mainly hosting, plus you can use gh-pages and other features. Plenty. GH pages are just normal web pages with markdown processing, right? What other features? And doesn't that come back around to getting locked into the walled garden? From rustompmody at gmail.com Mon Jan 4 00:53:08 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 3 Jan 2016 21:53:08 -0800 (PST) Subject: raise None In-Reply-To: <568a00dc$0$1617$c3e8da3$5496439d@news.astraweb.com> References: <56847239$0$1590$c3e8da3$5496439d@news.astraweb.com> <5684842a$0$1596$c3e8da3$5496439d@news.astraweb.com> <5684aa1a$0$1602$c3e8da3$5496439d@news.astraweb.com> <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> <85r3i2s776.fsf@benfinney.id.au> <568a00dc$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <639ece6c-bfed-470d-8c8c-c68138a986e0@googlegroups.com> On Monday, January 4, 2016 at 10:49:39 AM UTC+5:30, Steven D'Aprano wrote: > On Fri, 1 Jan 2016 10:27 am, Ben Finney wrote: > > > If I could have the traceback continue into the C code and tell me the > > line of C code that raised the exception, *that's* what I'd choose. > > If you are serious about believing this would be a good thing, you can open > a ticket on the bug tracker and make an enhancement request that tracebacks > generated from builtins should expose their internal details: > > > >>> 7 + [] > Traceback (most recent call last): > File "", line 1, in > File "longobject.c", line 3008, in long_add > File "longobject.c", line 1425, in CHECK_BINOP > TypeError: unsupported operand type(s) for +: 'int' and 'list' > > > When you open that ticket, be so good as to add me to the Nosy list. Prior Art: An emacs lisp error stops at the boundaries of emacs lisp if I use standard (debian/ubuntu packaged) emacs. OTOH if compiled from source it points to the C source (last I remember trying) From rustompmody at gmail.com Mon Jan 4 00:53:15 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 3 Jan 2016 21:53:15 -0800 (PST) Subject: raise None In-Reply-To: <568a00dc$0$1617$c3e8da3$5496439d@news.astraweb.com> References: <56847239$0$1590$c3e8da3$5496439d@news.astraweb.com> <5684842a$0$1596$c3e8da3$5496439d@news.astraweb.com> <5684aa1a$0$1602$c3e8da3$5496439d@news.astraweb.com> <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> <85r3i2s776.fsf@benfinney.id.au> <568a00dc$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7732e7c6-ea64-4e8b-802a-312d1dbd7877@googlegroups.com> On Monday, January 4, 2016 at 10:49:39 AM UTC+5:30, Steven D'Aprano wrote: > On Fri, 1 Jan 2016 10:27 am, Ben Finney wrote: > > > If I could have the traceback continue into the C code and tell me the > > line of C code that raised the exception, *that's* what I'd choose. > > If you are serious about believing this would be a good thing, you can open > a ticket on the bug tracker and make an enhancement request that tracebacks > generated from builtins should expose their internal details: > > > >>> 7 + [] > Traceback (most recent call last): > File "", line 1, in > File "longobject.c", line 3008, in long_add > File "longobject.c", line 1425, in CHECK_BINOP > TypeError: unsupported operand type(s) for +: 'int' and 'list' > > > When you open that ticket, be so good as to add me to the Nosy list. Prior Art: An emacs lisp error stops at the boundaries of emacs lisp if I use standard (debian/ubuntu packaged) emacs. OTOH if compiled from source it points to the C source (last I remember trying) From dan at tombstonezero.net Mon Jan 4 01:09:58 2016 From: dan at tombstonezero.net (Dan Sommers) Date: Mon, 4 Jan 2016 06:09:58 -0000 (UTC) Subject: raise None References: <56847239$0$1590$c3e8da3$5496439d@news.astraweb.com> <5684842a$0$1596$c3e8da3$5496439d@news.astraweb.com> <5684aa1a$0$1602$c3e8da3$5496439d@news.astraweb.com> <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> <85r3i2s776.fsf@benfinney.id.au> <568a00f9$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 04 Jan 2016 16:19:51 +1100, Steven D'Aprano wrote: > (1) reminding people that the part of the code which determines the > existence of an error need not be the part of the code which actually > calls raise [...] Do chained exceptions scratch your itch? I don't have experience with Python's version of chained exceptions, but I have used them in Java, and it seems to match your use case rather well. Essentially, each conceptual layer in the code effectively abstracts the details of the lower level layer(s), but preserves the details if you're really interested. (I've only been following this discussion partially; if this has been raised (pun intended) before, then just say so. Thanks.) > I'm saddened but not astonished at just how much opposition there is > to point (1) ... I'll echo the sentiment that we're all adults here, and my opinion that if you're reading tracebacks, then you want as much information as possible, even if it seemed irrelevant to the library author at the time. From rustompmody at gmail.com Mon Jan 4 01:39:35 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 3 Jan 2016 22:39:35 -0800 (PST) Subject: raise None In-Reply-To: References: <56847239$0$1590$c3e8da3$5496439d@news.astraweb.com> <5684842a$0$1596$c3e8da3$5496439d@news.astraweb.com> <5684aa1a$0$1602$c3e8da3$5496439d@news.astraweb.com> <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> <85r3i2s776.fsf@benfinney.id.au> <568a00f9$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, January 4, 2016 at 11:42:51 AM UTC+5:30, Dan Sommers wrote: > > I'm saddened but not astonished at just how much opposition there is > > to point (1) ... > > I'll echo the sentiment that we're all adults here, and my opinion that > if you're reading tracebacks, then you want as much information as > possible, even if it seemed irrelevant to the library author at the > time. And I am saddened at how often mediocre Linux system software can throw a traceback at me -- sometimes for things as basic as a missing command-line parameter. Increasingly often a python traceback. I guess most people here are programmers (and adults) but sometimes we want to wear a different hat (I think). Being a vanilla user of your OS is often one such time From auriocus at gmx.de Mon Jan 4 02:02:28 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 4 Jan 2016 08:02:28 +0100 Subject: =?UTF-8?Q?Re:_GitHub's_=c2=b3pull_request=c2=b2_is_proprietary_lock?= =?UTF-8?Q?-in?= In-Reply-To: <878u45di9y.fsf@jester.gateway.pace.com> References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <85h9ivqcey.fsf@benfinney.id.au> <87d1tjc5al.fsf@jester.gateway.pace.com> <878u45di9y.fsf@jester.gateway.pace.com> Message-ID: Am 04.01.16 um 06:29 schrieb Paul Rubin: > Chris Angelico writes: > >> On Sun, Jan 3, 2016 at 9:42 PM, Paul Rubin wrote: >>> Chris Angelico writes: >>>> If you're not using a GitHub PR, then what you're doing is using GH to >>>> host your repository. >>> What's the point of GH in that situation? >> Mainly hosting, plus you can use gh-pages and other features. Plenty. > > GH pages are just normal web pages with markdown processing, right? Yes. The processor is freely available (jekyll, written in Ruby). It's usual to put up a local server (jekyl --serve) while updating the pages, befor you publish them, which is done by a git commit/push to the gh-pages branch. > What other features? And doesn't that come back around to getting > locked into the walled garden? For the pages definitely not. Christian From auriocus at gmx.de Mon Jan 4 02:28:44 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 4 Jan 2016 08:28:44 +0100 Subject: raise None In-Reply-To: <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> References: <56847239$0$1590$c3e8da3$5496439d@news.astraweb.com> <5684842a$0$1596$c3e8da3$5496439d@news.astraweb.com> <5684aa1a$0$1602$c3e8da3$5496439d@news.astraweb.com> <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 31.12.15 um 16:35 schrieb Steven D'Aprano: > But I think it is a real issue. I believe in beautiful tracebacks that give > you just the right amount of information, neither too little nor two much. > Debugging is hard enough with being given more information than you need > and having to decide what bits to ignore and which are important. > > The principle is that errors should be raised as close to their cause as > possible. If I call spam(a, b) and provide bad arguments, the earliest I > can possibly detect that is in spam. (Only spam knows what it accepts as > arguments.) Any additional levels beyond spam (like _validate) is moving > further away: > > File "spam", line 19, in this > File "spam", line 29, in that <--- where the error really lies > File "spam", line 39, in other > File "spam", line 89, in spam <--- the first place we could detect it > File "spam", line 5, in _validate <--- where we actually detect it As a side note, this problem is solved by an enhanced return statement in Tcl. Translating the syntax to Python, it would read something like: def validate(a,b): if a>b: return(SomeError, code=error, level=1) "raise SomeError" would be identical to "return(SomeError, code=error, level=0)". In general you can return codes for continue, break and return to have the upper level act as if continue, break or raise was executed at the point where the function was called. Christian From jarosier at orange.fr Mon Jan 4 04:10:06 2016 From: jarosier at orange.fr (Jacques Rosier) Date: Mon, 4 Jan 2016 10:10:06 +0100 Subject: ouvrir python Message-ID: J?ai t?l?charg? Python 351. Il est dans la liste des applications de mon ordi (Lenovo; Windows 10). Mais impossible de l?ouvrir. Que faire? From mvoicem at gmail.com Mon Jan 4 05:13:00 2016 From: mvoicem at gmail.com (m) Date: Mon, 4 Jan 2016 11:13:00 +0100 Subject: We will be moving to GitHub In-Reply-To: <8737uf1oyx.fsf@elektro.pacujo.net> References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> <87oad41fd4.fsf@elektro.pacujo.net> <87k2ns1b0d.fsf@elektro.pacujo.net> <87ege012i5.fsf@elektro.pacujo.net> <87a8oo11b4.fsf@elektro.pacujo.net> <8737uf1oyx.fsf@elektro.pacujo.net> Message-ID: <568a459b$0$694$65785112@news.neostrada.pl> W dniu 03.01.2016 o 01:33, Marko Rauhamaa pisze: > Teamware didn't have to pick any of them since Teamware's commits were > done per individual files. The repository didn't have a commit history. > > Thus, Teamware was equivalent to Hg/Git with each file treated as an > independent repository. > It sounds like CVS. How can you be sure that your code is consistent if each of your file has it's own, independent history? Use tags like in CVS? r. m. From mvoicem at gmail.com Mon Jan 4 05:21:15 2016 From: mvoicem at gmail.com (m) Date: Mon, 4 Jan 2016 11:21:15 +0100 Subject: =?UTF-8?Q?Re:_GitHub's_=e2=80=9cpull_request=e2=80=9d_is_proprietar?= =?UTF-8?Q?y_lock-in?= In-Reply-To: References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> Message-ID: <568a4789$0$22822$65785112@news.neostrada.pl> W dniu 03.01.2016 o 05:43, Ben Finney pisze: > That and other vendor-locked workflow aspects of GitHub makes it a poor > choice for communities that want to retain the option of control over > their processes and data. I'm also afraid that Github will make to git the same thing as Google did to Jabber/XMPP. Decade ago, I had plenty of friends on my jabber contacts list. Next, Google made it's talk compatible with jabber, then my friends slowly migrated to gtalk, because if they used gmail anyway, then why not use it also for jabber? And then Google turned off XMPP support and suddenly I lost ability to contact with 80% of my friends without having stupid hangouts running, or without falling back to email (which is not so bad BTW). The same can be with Github and git. PPL will forget how to use git without github. When Github will make git-incompatible changes, vast majority will need/want to follow the changes and eg. will use Gitlabs propertiary binary. r. m. From marko at pacujo.net Mon Jan 4 06:28:57 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 04 Jan 2016 13:28:57 +0200 Subject: We will be moving to GitHub References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> <87oad41fd4.fsf@elektro.pacujo.net> <87k2ns1b0d.fsf@elektro.pacujo.net> <87ege012i5.fsf@elektro.pacujo.net> <87a8oo11b4.fsf@elektro.pacujo.net> <8737uf1oyx.fsf@elektro.pacujo.net> <568a459b$0$694$65785112@news.neostrada.pl> Message-ID: <87y4c5y45i.fsf@elektro.pacujo.net> m : > W dniu 03.01.2016 o 01:33, Marko Rauhamaa pisze: >> Teamware didn't have to pick any of them since Teamware's commits were >> done per individual files. The repository didn't have a commit history. >> >> Thus, Teamware was equivalent to Hg/Git with each file treated as an >> independent repository. >> > > It sounds like CVS. The main problem with CVS is that these operations don't commute: * edit : ----+--------------+---------------> \ \ : \ \ : \branch \merge : \ \ : v v : +--------------+----------> : : : : ----+-------------------+----------> \ ^ : \ / : \branch /merge : \ / : v edit / : +---------+---------------> : If you look at the edited file at *, CVS reveals the merge direction in the version history. In Teamware, you can't see afterwards, which way the change was made ("branches" and "merges" are not recorded). Additionally, CVS doesn't make the distinction between commits and merges, which both Hg/Git and Teamware do. The distinction could be emulated in CVS (as well as, say, Perforce) but very awkwardly. > How can you be sure that your code is consistent if each of your file > has it's own, independent history? Use tags like in CVS? Yes, tags ("checkpoints") can be used, although I don't remember us using them. Rather, we used distinct clones for tagging. Marko From rustompmody at gmail.com Mon Jan 4 06:55:58 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 4 Jan 2016 03:55:58 -0800 (PST) Subject: raise None In-Reply-To: <639ece6c-bfed-470d-8c8c-c68138a986e0@googlegroups.com> References: <56847239$0$1590$c3e8da3$5496439d@news.astraweb.com> <5684842a$0$1596$c3e8da3$5496439d@news.astraweb.com> <5684aa1a$0$1602$c3e8da3$5496439d@news.astraweb.com> <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> <85r3i2s776.fsf@benfinney.id.au> <568a00dc$0$1617$c3e8da3$5496439d@news.astraweb.com> <639ece6c-bfed-470d-8c8c-c68138a986e0@googlegroups.com> Message-ID: <8b292bf6-5a0f-410d-b059-0fb936cfc340@googlegroups.com> On Monday, January 4, 2016 at 11:23:24 AM UTC+5:30, Rustom Mody wrote: > On Monday, January 4, 2016 at 10:49:39 AM UTC+5:30, Steven D'Aprano wrote: > > On Fri, 1 Jan 2016 10:27 am, Ben Finney wrote: > > > > > If I could have the traceback continue into the C code and tell me the > > > line of C code that raised the exception, *that's* what I'd choose. > > > > If you are serious about believing this would be a good thing, you can open > > a ticket on the bug tracker and make an enhancement request that tracebacks > > generated from builtins should expose their internal details: > > > > > > >>> 7 + [] > > Traceback (most recent call last): > > File "", line 1, in > > File "longobject.c", line 3008, in long_add > > File "longobject.c", line 1425, in CHECK_BINOP > > TypeError: unsupported operand type(s) for +: 'int' and 'list' > > > > > > When you open that ticket, be so good as to add me to the Nosy list. > > Prior Art: > An emacs lisp error stops at the boundaries of emacs lisp if I use standard > (debian/ubuntu packaged) emacs. > OTOH if compiled from source it points to the C source (last I remember trying) I think I mis-remembered this: It is not tracebacks but docs that reach from front-facing lisp (commands) through internal lisp (functions) to C in elisp. From torriem at gmail.com Mon Jan 4 12:41:00 2016 From: torriem at gmail.com (Michael Torrie) Date: Mon, 04 Jan 2016 10:41:00 -0700 Subject: GitHub's =?windows-1252?Q?=93pull_request=94_is_propri?= =?windows-1252?Q?etary_lock-in?= In-Reply-To: <568a4789$0$22822$65785112@news.neostrada.pl> References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <568a4789$0$22822$65785112@news.neostrada.pl> Message-ID: <568AAEAC.5040506@gmail.com> On 01/04/2016 03:21 AM, m wrote: > W dniu 03.01.2016 o 05:43, Ben Finney pisze: >> That and other vendor-locked workflow aspects of GitHub makes it a poor >> choice for communities that want to retain the option of control over >> their processes and data. > > I'm also afraid that Github will make to git the same thing as Google > did to Jabber/XMPP. > > Decade ago, I had plenty of friends on my jabber contacts list. Next, > Google made it's talk compatible with jabber, then my friends slowly > migrated to gtalk, because if they used gmail anyway, then why not use > it also for jabber? > > And then Google turned off XMPP support and suddenly I lost ability to > contact with 80% of my friends without having stupid hangouts running, > or without falling back to email (which is not so bad BTW). I use gtalk with Pidgin every day using XMPP. So Google still supports XMPP. However what they stopped doing was allowing federated XMPP, which pretty much breaks XMPP, at least the spirit of it. So the only way to chat with gtalk users is to use your gtalk account. But you certainly don't need hangouts. XMPP works fine between your client and the Google server. I agree that Google really pulled a bad one with gtalk though. Dropping federated XMPP support was definitely not in keeping with their original "do no evil" mantra. > The same can be with Github and git. PPL will forget how to use git > without github. When Github will make git-incompatible changes, vast > majority will need/want to follow the changes and eg. will use Gitlabs > propertiary binary. Yup you are correct. However for the foreseeable future, you can still do a git clone from github, and you can still use your local repository normally. In fact I think this is really part of the github workflow. But who knows what the future will bring. I can sure see the wisdom of the GPLv3 as we move into a world of software as a service, where even Microsoft uses Linux, and charges us for it. From denmon at bergen.org Mon Jan 4 14:00:01 2016 From: denmon at bergen.org (Montone_Dennis) Date: Mon, 4 Jan 2016 19:00:01 +0000 Subject: trying to install Message-ID: <191C5999822F5A43BE0EA563E38EBA31A9E4092A@EXMB02.bergen.org> I am using Windows 7 and when I try to runt IDLE I get the following error. "The program can't start because api-ms-win-crt-runtime-I1-1-0.dll is missing from your computer." Do you have any suggestions for me? From security.veteran at gmail.com Mon Jan 4 15:30:16 2016 From: security.veteran at gmail.com (security veteran) Date: Mon, 4 Jan 2016 12:30:16 -0800 Subject: Python and OpenSSL FIPS module Message-ID: Hi, I was wondering does anyone have successful experiences integrating OpenSSL FIPS modules with Python 2.x? Is there any catch we need to be careful about in integrating Python with OpenSSL FIPS modules? Thanks. From livemsn22 at gmail.com Mon Jan 4 15:50:11 2016 From: livemsn22 at gmail.com (livemsn22 at gmail.com) Date: Mon, 4 Jan 2016 12:50:11 -0800 (PST) Subject: What is the fastest way to do 400 HTTP requests using requests library? Message-ID: <0e42a90b-b736-4050-a20c-6d387048daf3@googlegroups.com> So what is the fastest way to make 400 HTTP requests using "requests" library and also using tor proxy? Best regards From josef.pktd at gmail.com Mon Jan 4 16:29:12 2016 From: josef.pktd at gmail.com (Josef Pktd) Date: Mon, 4 Jan 2016 13:29:12 -0800 (PST) Subject: GitHub's "pull request" is proprietary lock-in In-Reply-To: References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <568a4789$0$22822$65785112@news.neostrada.pl> Message-ID: <46040271-6955-4835-bac7-d430f5aa5882@googlegroups.com> On Monday, January 4, 2016 at 12:41:32 PM UTC-5, Michael Torrie wrote: > On 01/04/2016 03:21 AM, m wrote: > > W dniu 03.01.2016 o 05:43, Ben Finney pisze: > >> That and other vendor-locked workflow aspects of GitHub makes it a poor > >> choice for communities that want to retain the option of control over > >> their processes and data. > > > > I'm also afraid that Github will make to git the same thing as Google > > did to Jabber/XMPP. > > > > Decade ago, I had plenty of friends on my jabber contacts list. Next, > > Google made it's talk compatible with jabber, then my friends slowly > > migrated to gtalk, because if they used gmail anyway, then why not use > > it also for jabber? > > > > And then Google turned off XMPP support and suddenly I lost ability to > > contact with 80% of my friends without having stupid hangouts running, > > or without falling back to email (which is not so bad BTW). > > I use gtalk with Pidgin every day using XMPP. So Google still supports > XMPP. However what they stopped doing was allowing federated XMPP, > which pretty much breaks XMPP, at least the spirit of it. So the only > way to chat with gtalk users is to use your gtalk account. But you > certainly don't need hangouts. XMPP works fine between your client and > the Google server. > > I agree that Google really pulled a bad one with gtalk though. Dropping > federated XMPP support was definitely not in keeping with their original > "do no evil" mantra. > > > The same can be with Github and git. PPL will forget how to use git > > without github. When Github will make git-incompatible changes, vast > > majority will need/want to follow the changes and eg. will use Gitlabs > > propertiary binary. > > Yup you are correct. However for the foreseeable future, you can still > do a git clone from github, and you can still use your local repository > normally. In fact I think this is really part of the github workflow. > But who knows what the future will bring. I can sure see the wisdom of > the GPLv3 as we move into a world of software as a service, where even > Microsoft uses Linux, and charges us for it. about: > PPL will forget how to use git without github. We cannot forget what we never learned. git is way to complicated for regular users without support like what github provides. I haven't done a merge without the Green Button in a long time. And when I did I always had to triple check to make sure to avoid any mistakes. I never needed to check what a pull request would be in pure git. Josef From PointedEars at web.de Mon Jan 4 17:53:04 2016 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Mon, 04 Jan 2016 23:53:04 +0100 Subject: We will be moving to GitHub References: <5687718d$0$1612$c3e8da3$5496439d@news.astraweb.com> <87oad41fd4.fsf@elektro.pacujo.net> Message-ID: <3140797.x9ZJFXmH5S@PointedEars.de> Marko Rauhamaa wrote: > Well, Git and Mercurial are not all that bad as long as only a single > person is working on the repository at any given time and you have a > strictly linear version history. I cannot confirm your observations(?) for Git. There was a time when three of four people of our team (me included) were working in the same and in different branches of the same repository without any serious problem (occasional merge conflicts cannot be avoided in such a scenario, of course). The resulting commit tree was fascinating to us :) Also, that Git appears to work well with Linux kernel development (for which it was created) where probably hundreds of developers, if not more, are working on at the same time, casts into doubt the correctness of your statement, and the amount of your work experience with Git. > That would be advisable anyway as you should have a separate repository > for each conceptual unit. Apples and oranges. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From steve at pearwood.info Mon Jan 4 18:38:35 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jan 2016 10:38:35 +1100 Subject: What is the fastest way to do 400 HTTP requests using requests library? References: <0e42a90b-b736-4050-a20c-6d387048daf3@googlegroups.com> Message-ID: <568b027c$0$1588$c3e8da3$5496439d@news.astraweb.com> On Tue, 5 Jan 2016 07:50 am, livemsn22 at gmail.com wrote: > So what is the fastest way to make 400 HTTP requests using "requests" > library and also using tor proxy? Since this will be I/O bound, not CPU bound, probably use separate threads. Push the 400 requests into a queue, then create N threads, where N will need to be determined by experiment, but will probably be something like 4 or 8, and let each thread pop a request from the queue as needed. Are you experienced with threads? Do you need further information about using threads and queues? -- Steven From ian.g.kelly at gmail.com Mon Jan 4 18:51:16 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 4 Jan 2016 16:51:16 -0700 Subject: What is the fastest way to do 400 HTTP requests using requests library? In-Reply-To: <568b027c$0$1588$c3e8da3$5496439d@news.astraweb.com> References: <0e42a90b-b736-4050-a20c-6d387048daf3@googlegroups.com> <568b027c$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 4, 2016 at 4:38 PM, Steven D'Aprano wrote: > On Tue, 5 Jan 2016 07:50 am, livemsn22 at gmail.com wrote: > >> So what is the fastest way to make 400 HTTP requests using "requests" >> library and also using tor proxy? > > > Since this will be I/O bound, not CPU bound, probably use separate threads. > > Push the 400 requests into a queue, then create N threads, where N will need > to be determined by experiment, but will probably be something like 4 or 8, > and let each thread pop a request from the queue as needed. > > Are you experienced with threads? Do you need further information about > using threads and queues? Also see the concurrent.futures module in the standard library, which makes this sort of setup very simple to implement. From mvoicem at gmail.com Mon Jan 4 19:24:52 2016 From: mvoicem at gmail.com (m) Date: Tue, 5 Jan 2016 01:24:52 +0100 Subject: =?UTF-8?Q?Re:_GitHub's_=e2=80=9cpull_request=e2=80=9d_is_proprietar?= =?UTF-8?Q?y_lock-in?= In-Reply-To: References: <87si2hdoq3.fsf@jester.gateway.pace.com> <8560zcsbuu.fsf@benfinney.id.au> <56889608.50504@gmail.com> <568a4789$0$22822$65785112@news.neostrada.pl> Message-ID: <568b0d43$0$22840$65785112@news.neostrada.pl> W dniu 04.01.2016 o 18:41, Michael Torrie pisze: >> Decade ago, I had plenty of friends on my jabber contacts list. Next, >> > Google made it's talk compatible with jabber, then my friends slowly >> > migrated to gtalk, because if they used gmail anyway, then why not use >> > it also for jabber? >> > >> > And then Google turned off XMPP support and suddenly I lost ability to >> > contact with 80% of my friends without having stupid hangouts running, >> > or without falling back to email (which is not so bad BTW). > I use gtalk with Pidgin every day using XMPP. So Google still supports > XMPP. However what they stopped doing was allowing federated XMPP, > which pretty much breaks XMPP, at least the spirit of it. So the only > way to chat with gtalk users is to use your gtalk account. Exactly. My friends slowly migrated to using gtalk instead of jabber client, because if they have open gmail anyways, then why should they bother with installing additional software. 80% never came back to jabber client. They don't need to, they still have communication between them and I'm minority which uses strange not supported technology :). > But you > certainly don't need hangouts. XMPP works fine between your client and > the Google server. Oh, and it's definitively what I want - talk with google server ;). > > I agree that Google really pulled a bad one with gtalk though. Dropping > federated XMPP support was definitely not in keeping with their original > "do no evil" mantra. > >> > The same can be with Github and git. PPL will forget how to use git >> > without github. When Github will make git-incompatible changes, vast >> > majority will need/want to follow the changes and eg. will use Gitlabs >> > propertiary binary. > Yup you are correct. However for the foreseeable future, you can still > do a git clone from github, and you can still use your local repository > normally. And I can do nothing with it, because nobody will want to cooperate with me - they will use github instead of git. Sad thing is that it's rather inevitable and not moving python repo to github or not won't stop the process. However - wise would be to have github-like software on own servers. p. m. From jfong at ms4.hinet.net Mon Jan 4 19:49:26 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 4 Jan 2016 16:49:26 -0800 (PST) Subject: Is there a way importing a string object? Message-ID: <9392813f-0f58-49a1-bf16-87436229eb03@googlegroups.com> For example, name = "test" # test.py is a module's file import name Regards, Jach From ian.g.kelly at gmail.com Mon Jan 4 19:56:09 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 4 Jan 2016 17:56:09 -0700 Subject: Is there a way importing a string object? In-Reply-To: <9392813f-0f58-49a1-bf16-87436229eb03@googlegroups.com> References: <9392813f-0f58-49a1-bf16-87436229eb03@googlegroups.com> Message-ID: On Mon, Jan 4, 2016 at 5:49 PM, wrote: > For example, > > name = "test" # test.py is a module's file > import name Yes, use the importlib.import_module function. From mailkufreakata at gmail.com Mon Jan 4 19:56:49 2016 From: mailkufreakata at gmail.com (Kufre Akata) Date: Mon, 4 Jan 2016 19:56:49 -0500 Subject: unable to run python 3.5.1 Message-ID: Dear All, Kindly be informed that I downloaded the new python 3.5.1 (32-bit) to install in my machine, after the download and set-up, each time I clicked on the icon to launch the program, it will give me 3 options - modify, repair and uninstall. I needed to launch python and use it to program.. Please assist. Thank you. Kufre From ben+python at benfinney.id.au Mon Jan 4 19:59:51 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 05 Jan 2016 11:59:51 +1100 Subject: Is there a way importing a string object? References: <9392813f-0f58-49a1-bf16-87436229eb03@googlegroups.com> Message-ID: <85y4c4q1rs.fsf@benfinney.id.au> jfong at ms4.hinet.net writes: > For example, (Please make the body of your message complete. The ?Subject? field should be a summary of your message's subject, and may not be read as the first line of your message.) > name = "test" # test.py is a module's file > import name The standard library ?importlib? module exports an API for the import machinery . You will likely want to use ?importlib.import_module? . -- \ ?The difference between a moral man and a man of honor is that | `\ the latter regrets a discreditable act, even when it has worked | _o__) and he has not been caught.? ?Henry L. Mencken | Ben Finney From rxjwg98 at gmail.com Mon Jan 4 21:16:05 2016 From: rxjwg98 at gmail.com (Robert) Date: Mon, 4 Jan 2016 18:16:05 -0800 (PST) Subject: Is '*args' useful in this example code? Message-ID: <6b0e236f-b240-486d-95e6-17bba9458cde@googlegroups.com> Hi, I find an example code on wrap at this link: http://stackoverflow.com/questions/308999/what-does-functools-wraps-do Here is the code: //////// def logged(func): def with_logging(*args, **kwargs): print func.__name__ + " was called" return func(*args, **kwargs) return with_logging /////// I understand now, but I feel the args usage is weird. I don't see any way to use *args and **kwargs in above code. What is your opinion on it? Thanks, From jfong at ms4.hinet.net Mon Jan 4 21:24:12 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 4 Jan 2016 18:24:12 -0800 (PST) Subject: Is there a way importing a string object? In-Reply-To: <9392813f-0f58-49a1-bf16-87436229eb03@googlegroups.com> References: <9392813f-0f58-49a1-bf16-87436229eb03@googlegroups.com> Message-ID: <865f4063-8a59-4c26-b37e-baa758fab7dd@googlegroups.com> jf... at ms4.hinet.net at 2016/1/5 UTC+8 8:49:56AM wrote: Thanks, Ian and Ben. This forum is really a good place for learning Python. I am glad I had join in. To Ben, > (Please make the body of your message complete. The "Subject" field > should be a summary of your message's subject, and may not be read as > the first line of your message.) Yes, The "Subject" seems a little strange, read likes a part of the body. I am bad on composition. Even after your reminder, I still can't think of a better one:-( From ben+python at benfinney.id.au Mon Jan 4 21:26:18 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 05 Jan 2016 13:26:18 +1100 Subject: Is '*args' useful in this example code? References: <6b0e236f-b240-486d-95e6-17bba9458cde@googlegroups.com> Message-ID: <85twmspxrp.fsf@benfinney.id.au> Robert writes: > I understand now, but I feel the args usage is weird. I don't see any way > to use *args and **kwargs in above code. What is your opinion on it? Can you show example code that you would expect, and specifically what about the actual code doesn't match what you expect? -- \ ?Of course, everybody says they're for peace. Hitler was for | `\ peace. Everybody is for peace. The question is: what kind of | _o__) peace?? ?Noam Chomsky, 1984-05-14 | Ben Finney From rxjwg98 at gmail.com Mon Jan 4 21:34:48 2016 From: rxjwg98 at gmail.com (Robert) Date: Mon, 4 Jan 2016 18:34:48 -0800 (PST) Subject: Is '*args' useful in this example code? In-Reply-To: References: <6b0e236f-b240-486d-95e6-17bba9458cde@googlegroups.com> Message-ID: On Monday, January 4, 2016 at 9:26:47 PM UTC-5, Ben Finney wrote: > Robert writes: > > > I understand now, but I feel the args usage is weird. I don't see any way > > to use *args and **kwargs in above code. What is your opinion on it? > > Can you show example code that you would expect, and specifically what about > the actual code doesn't match what you expect? > > -- > \ "Of course, everybody says they're for peace. Hitler was for | > `\ peace. Everybody is for peace. The question is: what kind of | > _o__) peace?" --Noam Chomsky, 1984-05-14 | > Ben Finney Excuse me for the incomplete info previously. If I call it with a = f(3) the result is 12. It is correct as below message. That is no use of *args and **kwargs. If I put more parameters in f, it will give errors as below. /////////// %run "C:/Users/pyprj/ipython0/decor0.py" f was called --------------------------------------------------------------------------- TypeError Traceback (most recent call last) C:\Users\pyprj\ipython0\decor0.py in () 11 return x + x * x 12 ---> 13 a = f(3, 4) 14 C:\Users\pyprj\ipython0\decor0.py in with_logging(*args, **kwargs) 3 def with_logging(*args, **kwargs): 4 print func.__name__ + " was called" ----> 5 return func(*args, **kwargs) 6 return with_logging 7 TypeError: f() takes exactly 1 argument (2 given) %run "C:/Users/rj/pyprj/ipython0/decor0.py" f was called a Out[13]: 12 /////////// I don't see *args and **kwargs can be used by other way yet. Do you think this internal function definition (with *args) is useful? Thanks, From ben+python at benfinney.id.au Mon Jan 4 22:28:03 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 05 Jan 2016 14:28:03 +1100 Subject: Is '*args' useful in this example code? References: <6b0e236f-b240-486d-95e6-17bba9458cde@googlegroups.com> Message-ID: <85poxgpuws.fsf@benfinney.id.au> Robert writes: > On Monday, January 4, 2016 at 9:26:47 PM UTC-5, Ben Finney wrote: > > Can you show example code that you would expect, and specifically what about > > the actual code doesn't match what you expect? > > Excuse me for the incomplete info previously. > If I call it with > a = f(3) > the result is 12. Can you show a *very* simple example of the ?f? you're talking about? Contrive a new one, make it behave the same way while keeping it very short, and once you have that, put that code in your message. With an actual function to examine it will be much easier to know where the confusion lies. -- \ ?When a well-packaged web of lies has been sold to the masses | `\ over generations, the truth will seem utterly preposterous and | _o__) its speaker a raving lunatic.? ?Dresden James | Ben Finney From akhokar1234 at wvu.edu Mon Jan 4 22:29:20 2016 From: akhokar1234 at wvu.edu (Arif Khokar) Date: Mon, 4 Jan 2016 22:29:20 -0500 Subject: Is '*args' useful in this example code? In-Reply-To: <6b0e236f-b240-486d-95e6-17bba9458cde@googlegroups.com> References: <6b0e236f-b240-486d-95e6-17bba9458cde@googlegroups.com> Message-ID: On 01/04/2016 09:16 PM, Robert wrote: > Hi, > > I find an example code on wrap at this link: > http://stackoverflow.com/questions/308999/what-does-functools-wraps-do > > Here is the code: > //////// > def logged(func): > def with_logging(*args, **kwargs): > print func.__name__ + " was called" > return func(*args, **kwargs) > return with_logging > /////// > > I understand now, but I feel the args usage is weird. I don't see any way > to use *args and **kwargs in above code. What is your opinion on it? The reason the inner method has *args, and **kwargs as parameters is so that it doesn't have to exactly match the signature of func. If func was a method that took 3 parameters, then if you didn't use *args, you would have to define the with_logging method to also take 3 parameters. If func takes one or more keyword parameters, then you would have to add that to the definition of the with_logging method if you don't use **kwargs. IOW, using *args and **kwargs in the wrapper method definition removes the requirement that its parameter list exactly match func's parameter list. From aezhil90 at gmail.com Tue Jan 5 01:39:37 2016 From: aezhil90 at gmail.com (Ezhilarasan Chandrasekar) Date: Tue, 5 Jan 2016 12:09:37 +0530 Subject: Need help - How to identify the cell display format? In-Reply-To: References: Message-ID: I tried the following, from openpyxl.reader.excel import load_workbook book = load_workbook(filename='transactions.xlsx') sheet = book.get_sheet_by_name('transactions') print sheet.cell("A12").style.number_format print sheet.cell("A13").style.number_format But there is some problem with the load_workbook package. I get a error in reading .xls file. Could anyone please help me out from this? Its really Urgent for me, Is there any other alternative way to read excel cell display format? -- Warm regards, Ezhilarasan On Tue, Dec 15, 2015 at 7:34 PM, Larry Martell wrote: > On Tue, Dec 15, 2015 at 2:29 AM, Ezhilarasan Chandrasekar > wrote: > > Hi folks, > > > > I just want to find the cell display format in Excel. I have a Expected > > excel file and Actual Excel file. > > > > I have some knowledge about, how to check the cell value, cell font, > > alignment. But I also want to know about what type of cell format is > being > > used. > > > > For example: If the cell value has "*04:05:00 AM*", but it displays as " > > *04:05:00*"(AM notation not needed) which is of format "*hh:mm:ss*" > > > > I want to identify the cell format *(hh:mm:ss)* from Expected Excel file > > and compare with the Actual Excel file > > You can do this with openpyxl, for example: > > from openpyxl.reader.excel import load_workbook > > book = load_workbook(filename='transactions.xlsx') > sheet = book.get_sheet_by_name('transactions') > print sheet.cell("A12").style.number_format > print sheet.cell("A13").style.number_format > -- > https://mail.python.org/mailman/listinfo/python-list > From omarray778 at yahoo.com Tue Jan 5 01:57:15 2016 From: omarray778 at yahoo.com (Omar Ray) Date: Tue, 5 Jan 2016 01:57:15 -0500 Subject: I can not install matplotlib, numpy, scipy, and pandas. Message-ID: <000001d14786$51434d50$f3c9e7f0$@yahoo.com> I have version 3.5 of Python for Windows. I have MS Visual C++ and also MS Visual Studio 2015. When I enter into the command window "pip install matplotlib", it reads this below (this is not the full version of it): Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\windows\system32>pip install matplotlib Collecting matplotlib Using cached matplotlib-1.5.0-cp35-none-win32.whl Requirement already satisfied (use --upgrade to upgrade): pytz in c:\users\---\a ppdata\local\programs\python\python35-32\lib\site-packages (from matplotlib) Requirement already satisfied (use --upgrade to upgrade): pyparsing!=2.0.4,>=1.5 .6 in c:\users\---\appdata\local\programs\python\python35-32\lib\site-packages ( from matplotlib) Requirement already satisfied (use --upgrade to upgrade): python-dateutil in c:\ users\---\appdata\local\programs\python\python35-32\lib\site-packages (from matp lotlib) Requirement already satisfied (use --upgrade to upgrade): cycler in c:\users\--- \appdata\local\programs\python\python35-32\lib\site-packages (from matplotlib) Collecting numpy>=1.6 (from matplotlib) Using cached numpy-1.10.2.tar.gz Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in c:\users\- --\appdata\local\programs\python\python35-32\lib\site-packages (from python-date util->matplotlib) Installing collected packages: numpy, matplotlib Running setup.py install for numpy Complete output from command c:\users\---\appdata\local\programs\python\pyth on35-32\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\\---\\App Data\\Local\\Temp\\pip-build-yrpyslwq\\numpy\\setup.py';exec(compile(getattr (tok enize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\---\AppData\Local\Temp\pip-o2xr7r52-record\install-re cord.txt --single-version-externally-managed --compile: blas_opt_info: blas_mkl_info: libraries mkl,vml,guide not found in ['c:\\users\\---\\appdata\\local\\pro grams\\python\\python35-32\\lib', 'C:\\', 'c:\\users\\---\\appdata\\local\\progr ams\\python\\python35-32\\libs'] NOT AVAILABLE How do I download matplotlib and the other packages mentioned in the subject line? -Omar Ray From john_ladasky at sbcglobal.net Tue Jan 5 02:02:43 2016 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Mon, 4 Jan 2016 23:02:43 -0800 (PST) Subject: Where are we in the Python 3 transition? In-Reply-To: References: Message-ID: I switched to Python 3 between three and four years ago, I think. I was actually eager to make the switch, as I could see the value of clean Unicode support and lazy evaluation. I had to wait until Matplotlib supported Py3, then I changed. From tony at vanderhoff.org Tue Jan 5 03:53:40 2016 From: tony at vanderhoff.org (Tony van der Hoff) Date: Tue, 05 Jan 2016 09:53:40 +0100 Subject: What is the fastest way to do 400 HTTP requests using requests library? In-Reply-To: References: <0e42a90b-b736-4050-a20c-6d387048daf3@googlegroups.com> <568b027c$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: <568B8494.2070000@vanderhoff.org> On 05/01/16 00:51, Ian Kelly wrote: > On Mon, Jan 4, 2016 at 4:38 PM, Steven D'Aprano wrote: >> On Tue, 5 Jan 2016 07:50 am, livemsn22 at gmail.com wrote: >> >>> So what is the fastest way to make 400 HTTP requests using "requests" >>> library and also using tor proxy? >> >> >> Since this will be I/O bound, not CPU bound, probably use separate threads. >> >> Push the 400 requests into a queue, then create N threads, where N will need >> to be determined by experiment, but will probably be something like 4 or 8, >> and let each thread pop a request from the queue as needed. >> >> Are you experienced with threads? Do you need further information about >> using threads and queues? > > Also see the concurrent.futures module in the standard library, which > makes this sort of setup very simple to implement. > Why would someone want to make 400 HTTP requests in a short time? -- Tony van der Hoff | mailto:tony at vanderhoff.org Ari?ge, France | From steve at pearwood.info Tue Jan 5 04:38:06 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jan 2016 20:38:06 +1100 Subject: What is the fastest way to do 400 HTTP requests using requests library? References: <0e42a90b-b736-4050-a20c-6d387048daf3@googlegroups.com> <568b027c$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: <568b8eff$0$1588$c3e8da3$5496439d@news.astraweb.com> On Tue, 5 Jan 2016 07:53 pm, Tony van der Hoff wrote: > Why would someone want to make 400 HTTP requests in a short time? For the same reason they want to make 400 HTTP requests over a long time, except that they're in a hurry. Maybe they're stress-testing a web server, or they just want to download things in a rush. -- Steven From hanaamohsin77 at gmail.com Tue Jan 5 05:08:08 2016 From: hanaamohsin77 at gmail.com (hanaamohsin77 at gmail.com) Date: Tue, 5 Jan 2016 02:08:08 -0800 (PST) Subject: PLease have problem in operate python 27 with pycharm environment, Message-ID: <4b834069-3ee5-47ec-9cc8-c984b2a89bcd@googlegroups.com> I need help in install packages like scipy by pip and conda on the in the pycharm environment From self at example.org Tue Jan 5 06:15:27 2016 From: self at example.org (me) Date: Tue, 5 Jan 2016 11:15:27 +0000 (UTC) Subject: subprocess check_output References: <20151230210227.GA88234@cskk.homeip.net> Message-ID: On 2016-01-02, Chris Angelico wrote: > down to "whoops, I forgot to save the file" or "whoops, I was in the > wrong directory"... Amen, bro. Exceptionally true if you ever need for some reason to put your code in another directory, but you forget to close the files in your editor. :D From rosuav at gmail.com Tue Jan 5 06:38:44 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jan 2016 22:38:44 +1100 Subject: subprocess check_output In-Reply-To: References: <20151230210227.GA88234@cskk.homeip.net> Message-ID: On Tue, Jan 5, 2016 at 10:15 PM, me wrote: > On 2016-01-02, Chris Angelico wrote: >> down to "whoops, I forgot to save the file" or "whoops, I was in the >> wrong directory"... > > Amen, bro. > > Exceptionally true if you ever need for some reason to put your code in > another directory, but you forget to close the files in your editor. :D Oh, and then you keep editing and save again? Nah, I've *never* done that... Never! ChrisA From python.list at tim.thechases.com Tue Jan 5 06:43:47 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 5 Jan 2016 05:43:47 -0600 Subject: What is the fastest way to do 400 HTTP requests using requests library? In-Reply-To: <568b8eff$0$1588$c3e8da3$5496439d@news.astraweb.com> References: <0e42a90b-b736-4050-a20c-6d387048daf3@googlegroups.com> <568b027c$0$1588$c3e8da3$5496439d@news.astraweb.com> <568b8eff$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20160105054347.19ae0c00@bigbox.christie.dr> On 2016-01-05 20:38, Steven D'Aprano wrote: > On Tue, 5 Jan 2016 07:53 pm, Tony van der Hoff wrote: > > > Why would someone want to make 400 HTTP requests in a short time? > > For the same reason they want to make 400 HTTP requests over a long > time, except that they're in a hurry. > > Maybe they're stress-testing a web server, or they just want to > download things in a rush. Maybe they just want to generate lots of errors. It's generally more productive to make lots of 200 HTTP requests[*]. ;-) -tkc [*] http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html From antoon.pardon at rece.vub.ac.be Tue Jan 5 06:51:52 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 5 Jan 2016 12:51:52 +0100 Subject: Is '*args' useful in this example code? In-Reply-To: <6b0e236f-b240-486d-95e6-17bba9458cde@googlegroups.com> References: <6b0e236f-b240-486d-95e6-17bba9458cde@googlegroups.com> Message-ID: <568BAE58.9000606@rece.vub.ac.be> Op 05-01-16 om 03:16 schreef Robert: > Hi, > > I find an example code on wrap at this link: > http://stackoverflow.com/questions/308999/what-does-functools-wraps-do > > Here is the code: > //////// > def logged(func): > def with_logging(*args, **kwargs): > print func.__name__ + " was called" > return func(*args, **kwargs) > return with_logging > /////// > > I understand now, but I feel the args usage is weird. I don't see any way > to use *args and **kwargs in above code. What is your opinion on it? > > > Thanks, You want the following to work def add(a, b): return a + b def double(n) return n + n logged_add = logged(add) logged_double = logged(double) s = logged_add(3, 5) d = logged_double(13) -- Antoon Pardon From rxjwg98 at gmail.com Tue Jan 5 08:04:08 2016 From: rxjwg98 at gmail.com (Robert) Date: Tue, 5 Jan 2016 05:04:08 -0800 (PST) Subject: Is '*args' useful in this example code? In-Reply-To: References: <6b0e236f-b240-486d-95e6-17bba9458cde@googlegroups.com> Message-ID: On Monday, January 4, 2016 at 10:28:31 PM UTC-5, Ben Finney wrote: > Robert <.com> writes: > > > On Monday, January 4, 2016 at 9:26:47 PM UTC-5, Ben Finney wrote: > > > Can you show example code that you would expect, and specifically what about > > > the actual code doesn't match what you expect? > > > > Excuse me for the incomplete info previously. > > If I call it with > > a = f(3) > > the result is 12. > > Can you show a *very* simple example of the 'f' you're talking about? > Contrive a new one, make it behave the same way while keeping it very > short, and once you have that, put that code in your message. > > With an actual function to examine it will be much easier to know where > the confusion lies. > > -- > \ "When a well-packaged web of lies has been sold to the masses | > `\ over generations, the truth will seem utterly preposterous and | > _o__) its speaker a raving lunatic." --Dresden James | > Ben Finney Excuse me, Ben. I forgot to add the f function. It is as below: @logged def f(x): """does some math""" return x + x * x a = f(3) My problem has been solved after all of your helpful posts. Thanks. From benph at sina.com Tue Jan 5 08:36:32 2016 From: benph at sina.com (=?GBK?B?73fvdw==?=) Date: Tue, 05 Jan 2016 21:36:32 +0800 Subject: insert many numbers to a list, a second method. Message-ID: <20160105133632.3C11C400C7@webmail.sinamail.sina.com.cn> -------------------------------- l = list(range(0,12)) numbers = [5,3,2,7] #insert numbers at 5th position. list1 = list(range(5,9)) list2 = list(range(0,5)) list2.extend(numbers) # for i in list1: l.insert(i,list2[i]) print(l)------> l = [0, 1, 2, 3, 4, 5, 3, 2, 7, 5, 6, 7, 8, 9, 10, 11] From robin.koch at t-online.de Tue Jan 5 09:20:47 2016 From: robin.koch at t-online.de (Robin Koch) Date: Tue, 5 Jan 2016 15:20:47 +0100 Subject: Is there a way importing a string object? In-Reply-To: <865f4063-8a59-4c26-b37e-baa758fab7dd@googlegroups.com> References: <9392813f-0f58-49a1-bf16-87436229eb03@googlegroups.com> <865f4063-8a59-4c26-b37e-baa758fab7dd@googlegroups.com> Message-ID: Am 05.01.2016 um 03:24 schrieb jfong at ms4.hinet.net: >> (Please make the body of your message complete. The "Subject" >> field should be a summary of your message's subject, and may not be >> read as the first line of your message.) > > Yes, The "Subject" seems a little strange, read likes a part of the > body. I am bad on composition. Even after your reminder, I still > can't think of a better one:-( I think the subject is fine. But you should have extended your message body a little so your question is understandable without reading the subject. -- Robin Koch From kevind0718 at gmail.com Tue Jan 5 10:27:03 2016 From: kevind0718 at gmail.com (kevind0718 at gmail.com) Date: Tue, 5 Jan 2016 07:27:03 -0800 (PST) Subject: create Email with multiple HTML blocks embedded Message-ID: <0f51af4b-dfef-4d27-92b7-be601677bf50@googlegroups.com> The below script will send an email with one HTML file embedded and the second attached. Not really what I need. I need a Python script to create an email that contains multiple blocks of HTML in the body of the email. There is a process that will create at least one HTML file but very often two. A summary and an exception web pages. These need to be emailed to a user group. The code below displays one file in the email, but the other shows up as an attachment. If I reverse the body.attach statements then the files switch. I need both to appear in the body of the email. I messed around with the boundary attribute, but could not get that to work. Your kind assistance is requested. Best Regards KD import smtplib from pprint import pprint from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText msg = MIMEMultipart() msg['Subject'] = 'email from Python with HTML content ' msg['From'] = 'kduf at xxx.com' msg['To'] = 'kduf at xxx.com' text = "\nBelow I hope will be the Summary Table in HTML\n\n" body = MIMEMultipart('multipart') with open("H:\\dev\\testHTML\\Exceptions_SheetDec30d.htm", "r") as fE: htmlE = fE.read().replace('\n', '') with open("H:\\dev\\testHTML\\Summary_SheetDec30d.htm", "r") as f: html = f.read().replace('\n', '') body.attach(MIMEText(html, 'html')) body.attach(MIMEText(htmlE, 'html')) msg.attach(body) s = smtplib.SMTP('smtp.aigfpc.com') # ('localhost') s.sendmail('kduf at xxx.com', ['kduf at xxx.com'], msg.as_string()) s.quit() From no.email at nospam.invalid Tue Jan 5 12:02:52 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 05 Jan 2016 09:02:52 -0800 Subject: What is the fastest way to do 400 HTTP requests using requests library? References: <0e42a90b-b736-4050-a20c-6d387048daf3@googlegroups.com> <568b027c$0$1588$c3e8da3$5496439d@news.astraweb.com> <568b8eff$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r3hwarib.fsf@jester.gateway.pace.com> Steven D'Aprano writes: > Maybe they're stress-testing a web server, or they just want to download > things in a rush. They're stress-testing a web server through a tor proxy? This sounds abusive to me. I also wonder whether 400 referred to the HTTP 400 error code rather than the number of requests to be sent. As in: - Layer 7 (?400 bad request?) attacks toward our web and application servers, causing Linode Manager outages from http://status.linode.com/incidents/mmdbljlglnfd regarding a big DDOS attack that's been running against Linode.com (a VPS host) over the past couple weeks. From ian.g.kelly at gmail.com Tue Jan 5 12:32:11 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 5 Jan 2016 10:32:11 -0700 Subject: What is the fastest way to do 400 HTTP requests using requests library? In-Reply-To: <87r3hwarib.fsf@jester.gateway.pace.com> References: <0e42a90b-b736-4050-a20c-6d387048daf3@googlegroups.com> <568b027c$0$1588$c3e8da3$5496439d@news.astraweb.com> <568b8eff$0$1588$c3e8da3$5496439d@news.astraweb.com> <87r3hwarib.fsf@jester.gateway.pace.com> Message-ID: On Tue, Jan 5, 2016 at 10:02 AM, Paul Rubin wrote: > Steven D'Aprano writes: >> Maybe they're stress-testing a web server, or they just want to download >> things in a rush. > > They're stress-testing a web server through a tor proxy? This sounds > abusive to me. > > I also wonder whether 400 referred to the HTTP 400 error code rather > than the number of requests to be sent. As in: > > - Layer 7 (?400 bad request?) attacks toward our web and application > servers, causing Linode Manager outages > > from http://status.linode.com/incidents/mmdbljlglnfd > regarding a big DDOS attack that's been running against Linode.com > (a VPS host) over the past couple weeks. I had the same initial thought about the status code but dismissed it, since why would somebody intentionally send a request that will return a 400 status? I was not thinking about abuse though, so the DDoS scenario did not occur to me. From rxjwg98 at gmail.com Tue Jan 5 15:25:48 2016 From: rxjwg98 at gmail.com (Robert) Date: Tue, 5 Jan 2016 12:25:48 -0800 (PST) Subject: Why is there difference between cmd line and .py file? Message-ID: Hi, I run below code, which is downloaded from link: http://stackoverflow.com/questions/15513792/expectation-maximization-coin-toss-examples?rq=1 //////////// # represent the experiments head_counts = np.array([5,9,8,4,7]) tail_counts = 10-head_counts experiments = zip(head_counts,tail_counts) # initialise the pA(heads) and pB(heads) pA_heads = np.zeros(100); pA_heads[0] = 0.60 pB_heads = np.zeros(100); pB_heads[0] = 0.50 # E-M begins! delta = 0.001 j = 0 # iteration counter improvement = float('inf') while (improvement>delta): expectation_A = np.zeros((5,2), dtype=float) expectation_B = np.zeros((5,2), dtype=float) for i in range(0,len(experiments)): e = experiments[i] # i'th experiment ll_A = get_mn_log_likelihood(e,np.array([pA_heads[j],1-pA_heads[j]])) # loglikelihood of e given coin A ll_B = get_mn_log_likelihood(e,np.array([pB_heads[j],1-pB_heads[j]])) # loglikelihood of e given coin B weightA = math.exp(ll_A) / ( math.exp(ll_A) + math.exp(ll_B) ) # corresponding weight of A proportional to likelihood of A weightB = math.exp(ll_B) / ( math.exp(ll_A) + math.exp(ll_B) ) # corresponding weight of B proportional to likelihood of B expectation_A[i] = np.dot(weightA, e) expectation_B[i] = np.dot(weightB, e) print "sum(expectation_A)[0]", sum(expectation_A)[0] pA_heads[j+1] = sum(expectation_A)[0] / sum(sum(expectation_A)); pB_heads[j+1] = sum(expectation_B)[0] / sum(sum(expectation_B)); ////////// The print message is: sum(expectation_A)[0] 21.2974818963 sum(expectation_A)[0] 19.2093824201 sum(expectation_A)[0] 19.4102767983 sum(expectation_A)[0] 19.7538328728 sum(expectation_A)[0] 19.9753285438 sum(expectation_A)[0] 20.0879016403 sum(expectation_A)[0] 20.139820175 sum(expectation_A)[0] 20.1628374165 When I check below in detail in interactive mode (Canopy Python shell), sum(expectation_A)[0] it has error: ///////////// sum(expectation_A)[0] --------------------------------------------------------------------------- IndexError Traceback (most recent call last) in () ----> 1 sum(expectation_A)[0] IndexError: invalid index to scalar variable. ////////////// I can see expectation_A content with: In[146]:expectation_A Out[146]: array([[ 0.52278641, 0.52278641], [ 8.55858656, 0.95095406], [ 6.75024946, 1.68756237], [ 0.1260128 , 0.1890192 ], [ 4.20520218, 1.80222951]]) It looks like sum(expectation_A)[0] can run in .py file, while it cannot be run in python shell. Is it true? Thanks, From gordon at panix.com Tue Jan 5 15:37:33 2016 From: gordon at panix.com (John Gordon) Date: Tue, 5 Jan 2016 20:37:33 +0000 (UTC) Subject: Why is there difference between cmd line and .py file? References: Message-ID: In Robert writes: > //////////// > # represent the experiments > head_counts = np.array([5,9,8,4,7]) The code doesn't define 'np', so this line should produce an error. The code you linked contains this import: import numpy as np However you didn't show it here, so I wonder if you posted the real code. > sum(expectation_A)[0] > --------------------------------------------------------------------------- > IndexError Traceback (most recent call last) > in () > ----> 1 sum(expectation_A)[0] > IndexError: invalid index to scalar variable. > ////////////// The built-in function sum() returns a single value, not a list, so this is a reasonable error. I suspect the code actually intended to call numpy.sum(), which does return a list (or something like a list). -- 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 rxjwg98 at gmail.com Tue Jan 5 15:41:41 2016 From: rxjwg98 at gmail.com (Robert) Date: Tue, 5 Jan 2016 12:41:41 -0800 (PST) Subject: Why is there difference between cmd line and .py file? In-Reply-To: References: Message-ID: On Tuesday, January 5, 2016 at 3:26:15 PM UTC-5, Robert wrote: > Hi, > > I run below code, which is downloaded from link: > > http://stackoverflow.com/questions/15513792/expectation-maximization-coin-toss-examples?rq=1 > > > > //////////// > # represent the experiments > head_counts = np.array([5,9,8,4,7]) > tail_counts = 10-head_counts > experiments = zip(head_counts,tail_counts) > > # initialise the pA(heads) and pB(heads) > pA_heads = np.zeros(100); pA_heads[0] = 0.60 > pB_heads = np.zeros(100); pB_heads[0] = 0.50 > > # E-M begins! > delta = 0.001 > j = 0 # iteration counter > improvement = float('inf') > while (improvement>delta): > expectation_A = np.zeros((5,2), dtype=float) > expectation_B = np.zeros((5,2), dtype=float) > for i in range(0,len(experiments)): > e = experiments[i] # i'th experiment > ll_A = get_mn_log_likelihood(e,np.array([pA_heads[j],1-pA_heads[j]])) # loglikelihood of e given coin A > ll_B = get_mn_log_likelihood(e,np.array([pB_heads[j],1-pB_heads[j]])) # loglikelihood of e given coin B > > weightA = math.exp(ll_A) / ( math.exp(ll_A) + math.exp(ll_B) ) # corresponding weight of A proportional to likelihood of A > weightB = math.exp(ll_B) / ( math.exp(ll_A) + math.exp(ll_B) ) # corresponding weight of B proportional to likelihood of B > > expectation_A[i] = np.dot(weightA, e) > expectation_B[i] = np.dot(weightB, e) > > print "sum(expectation_A)[0]", sum(expectation_A)[0] > pA_heads[j+1] = sum(expectation_A)[0] / sum(sum(expectation_A)); > pB_heads[j+1] = sum(expectation_B)[0] / sum(sum(expectation_B)); > ////////// > The print message is: > sum(expectation_A)[0] 21.2974818963 > sum(expectation_A)[0] 19.2093824201 > sum(expectation_A)[0] 19.4102767983 > sum(expectation_A)[0] 19.7538328728 > sum(expectation_A)[0] 19.9753285438 > sum(expectation_A)[0] 20.0879016403 > sum(expectation_A)[0] 20.139820175 > sum(expectation_A)[0] 20.1628374165 > > > > When I check below in detail in interactive mode (Canopy Python shell), > > sum(expectation_A)[0] > > it has error: > ///////////// > sum(expectation_A)[0] > --------------------------------------------------------------------------- > IndexError Traceback (most recent call last) > in () > ----> 1 sum(expectation_A)[0] > > IndexError: invalid index to scalar variable. > ////////////// > > I can see expectation_A content with: > > In[146]:expectation_A > Out[146]: > array([[ 0.52278641, 0.52278641], > [ 8.55858656, 0.95095406], > [ 6.75024946, 1.68756237], > [ 0.1260128 , 0.1890192 ], > [ 4.20520218, 1.80222951]]) > > It looks like > sum(expectation_A)[0] > > can run in .py file, while it cannot be run in python shell. > Is it true? > > Thanks, I just wonder that the cmd line function sum may be different from the .py file used. One is numpy package, the other is a general one. Then, how can I further make it clear for this guess? Thanks, From rxjwg98 at gmail.com Tue Jan 5 15:45:34 2016 From: rxjwg98 at gmail.com (Robert) Date: Tue, 5 Jan 2016 12:45:34 -0800 (PST) Subject: Why is there difference between cmd line and .py file? In-Reply-To: References: Message-ID: On Tuesday, January 5, 2016 at 3:37:53 PM UTC-5, John Gordon wrote: > In Robert writes: > > > //////////// > > # represent the experiments > > head_counts = np.array([5,9,8,4,7]) > > The code doesn't define 'np', so this line should produce an error. > > The code you linked contains this import: > > import numpy as np > > However you didn't show it here, so I wonder if you posted the real code. > > > sum(expectation_A)[0] > > --------------------------------------------------------------------------- > > IndexError Traceback (most recent call last) > > in () > > ----> 1 sum(expectation_A)[0] > > > IndexError: invalid index to scalar variable. > > ////////////// > > The built-in function sum() returns a single value, not a list, so this > is a reasonable error. > > I suspect the code actually intended to call numpy.sum(), which does > return a list (or something like a list). > > -- > 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" Thanks, John. When I typed my new thought, your reply came. You are right. The attached message missed numpy import (In my file, it had). Now, I cannot use np.sum. It has an error, see below please. How can I use the numpy sum()? Thanks, ///////// import numpy as np In [154]: np.sum(expectation_A)[0] --------------------------------------------------------------------------- IndexError Traceback (most recent call last) in () ----> 1 np.sum(expectation_A)[0] IndexError: invalid index to scalar variable. From joel.goldstick at gmail.com Tue Jan 5 15:58:18 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 5 Jan 2016 15:58:18 -0500 Subject: Why is there difference between cmd line and .py file? In-Reply-To: References: Message-ID: On Tue, Jan 5, 2016 at 3:45 PM, Robert wrote: > On Tuesday, January 5, 2016 at 3:37:53 PM UTC-5, John Gordon wrote: > > In Robert < > r-- at gmail.com> writes: > > > > > //////////// > > > # represent the experiments > > > head_counts = np.array([5,9,8,4,7]) > > > > The code doesn't define 'np', so this line should produce an error. > > > > The code you linked contains this import: > > > > import numpy as np > > > > However you didn't show it here, so I wonder if you posted the real code. > > > > > sum(expectation_A)[0] > > > > --------------------------------------------------------------------------- > > > IndexError Traceback (most recent call > last) > > > in () > > > ----> 1 sum(expectation_A)[0] > > > > > IndexError: invalid index to scalar variable. > > > ////////////// > > > > The built-in function sum() returns a single value, not a list, so this > > is a reasonable error. > > > > I suspect the code actually intended to call numpy.sum(), which does > > return a list (or something like a list). > > > > -- > > 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" > > Thanks, John. When I typed my new thought, your reply came. You are right. > The attached message missed numpy import (In my file, it had). > > Now, I cannot use np.sum. It has an error, see below please. How can I use > the numpy sum()? > > Thanks, > ///////// > import numpy as np > > In [154]: np.sum(expectation_A)[0] > --------------------------------------------------------------------------- > IndexError Traceback (most recent call last) > in () > ----> 1 np.sum(expectation_A)[0] > > IndexError: invalid index to scalar variable. > I've not used numpy, but you should print expectation_A to see what's in it. It may be empty, causing the index. It may be that expectation_A is an integer, not a list > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From rxjwg98 at gmail.com Tue Jan 5 16:05:45 2016 From: rxjwg98 at gmail.com (Robert) Date: Tue, 5 Jan 2016 13:05:45 -0800 (PST) Subject: Why is there difference between cmd line and .py file? In-Reply-To: References: Message-ID: On Tuesday, January 5, 2016 at 3:58:44 PM UTC-5, Joel Goldstick wrote: > On Tue, Jan 5, 2016 at 3:45 PM, Robert wrote: > > > On Tuesday, January 5, 2016 at 3:37:53 PM UTC-5, John Gordon wrote: > > > In Robert < > > r-- at gmail.com> writes: > > > > > > > //////////// > > > > # represent the experiments > > > > head_counts = np.array([5,9,8,4,7]) > > > > > > The code doesn't define 'np', so this line should produce an error. > > > > > > The code you linked contains this import: > > > > > > import numpy as np > > > > > > However you didn't show it here, so I wonder if you posted the real code. > > > > > > > sum(expectation_A)[0] > > > > > > --------------------------------------------------------------------------- > > > > IndexError Traceback (most recent call > > last) > > > > in () > > > > ----> 1 sum(expectation_A)[0] > > > > > > > IndexError: invalid index to scalar variable. > > > > ////////////// > > > > > > The built-in function sum() returns a single value, not a list, so this > > > is a reasonable error. > > > > > > I suspect the code actually intended to call numpy.sum(), which does > > > return a list (or something like a list). > > > > > > -- > > > 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" > > > > Thanks, John. When I typed my new thought, your reply came. You are right. > > The attached message missed numpy import (In my file, it had). > > > > Now, I cannot use np.sum. It has an error, see below please. How can I use > > the numpy sum()? > > > > Thanks, > > ///////// > > import numpy as np > > > > In [154]: np.sum(expectation_A)[0] > > --------------------------------------------------------------------------- > > IndexError Traceback (most recent call last) > > in () > > ----> 1 np.sum(expectation_A)[0] > > > > IndexError: invalid index to scalar variable. > > > > I've not used numpy, but you should print expectation_A to see what's in > it. It may be empty, causing the index. It may be that expectation_A is > an integer, not a list > > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > > > -- > Joel Goldstick > http://joelgoldstick.com/stats/birthdays Thanks. It has sum method. OK now. From PointedEars at web.de Tue Jan 5 18:21:44 2016 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Wed, 06 Jan 2016 00:21:44 +0100 Subject: Why is there difference between cmd line and .py file? References: Message-ID: <2962143.eoXFh7Ia7I@PointedEars.de> Joel Goldstick wrote: > On Tue, Jan 5, 2016 at 3:45 PM, Robert wrote: >> import numpy as np >> >> In [154]: np.sum(expectation_A)[0] >> [?] >> IndexError: invalid index to scalar variable. > > I've not used numpy, but you should print expectation_A to see what's in > it. It may be empty, causing the index. Did you mean ?IndexError? instead of ?index?? > It may be that expectation_A is an integer, not a list Please think about this again. | $ python3 | Python 3.4.4 (default, Dec 21 2015, 09:19:42) | [GCC 5.3.1 20151219] on linux | Type "help", "copyright", "credits" or "license" for more information. | >>> import numpy | >>> print(numpy.sum.__doc__) | | Sum of array elements over a given axis. The problem is instead that np.sum(?) *returns* a scalar value (as expected from a summation method when passed only scalar values) and _not_ a list (insofar the error message is misleading; there is no scalar *variable* causing the problem, but a scalar return *value*): | Parameters | ---------- | a : array_like | Elements to sum. | [?] | | Returns | ------- | sum_along_axis : ndarray | An array with the same shape as `a`, with the specified | axis removed. If `a` is a 0-d array, or if `axis` is None, a | scalar is returned. If an output array is specified, a reference | to `out` is returned. | | [?] | | Examples | -------- | >>> np.sum([0.5, 1.5]) | 2.0 | `---- So you cannot use the index notation with the *return* value. Try e.g. 42[0]; it does not work because it does not make sense. It is more likely that the index notation was misplaced: np.sum(expectation_A[0]) would make sense if the first element of the iterable referred to by ?expectation_A? were a numeric scalar or a reference to a list. Please trim your quotes to the relevant minimum. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From PointedEars at web.de Tue Jan 5 18:25:29 2016 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Wed, 06 Jan 2016 00:25:29 +0100 Subject: Why is there difference between cmd line and .py file? References: Message-ID: <1876022.WpuiDFLl9Z@PointedEars.de> Robert wrote: > I just wonder that the cmd line function sum may be different from the > .py file used. One is numpy package, the other is a general one. Then, > how can I further make it clear for this guess? Among other things: print(sum.__doc__) -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From PointedEars at web.de Tue Jan 5 18:58:59 2016 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Wed, 06 Jan 2016 00:58:59 +0100 Subject: create Email with multiple HTML blocks embedded References: <0f51af4b-dfef-4d27-92b7-be601677bf50@googlegroups.com> Message-ID: <1943475.7F1emcm5UF@PointedEars.de> kevind0718 at gmail.com wrote: ^^^^^^^^^^^^^^^^^^^^ Please either do not use Google Groups and configure your newsreader accordingly (recommended), or use Google Groups to subscribe to the newsgroup so that you can specify your real name. > body = MIMEMultipart('multipart') Obviously there is redundancy, so common sense should tell you already that this cannot be correct. The manual says: | class email.mime.multipart.MIMEMultipart(_subtype='mixed', boundary=None, | _subparts=None, **_params) | | Module: email.mime.multipart | | A subclass of MIMEBase, this is an intermediate base class for MIME | messages that are multipart. Optional _subtype defaults to mixed, but can | be used to specify the subtype of the message. A Content-Type header of | multipart/_subtype will be added to the message object. So this would add a ?Content-Type? header (field) with the value ?multipart/multipart? to the constructed *message object*, referred to by *body* (see below). It has to be ?multipart/mixed? in your case instead, which is the default. So you need to write *only* msg = MIMEMultipart() which you did. But: > with open("H:\\dev\\testHTML\\Exceptions_SheetDec30d.htm", "r") as fE: > htmlE = fE.read().replace('\n', '') > > > with open("H:\\dev\\testHTML\\Summary_SheetDec30d.htm", "r") as f: > html = f.read().replace('\n', '') > > body.attach(MIMEText(html, 'html')) > body.attach(MIMEText(htmlE, 'html')) > > msg.attach(body) Here you are attaching to a multi-part message a *multi-part message with two parts*: msg (multipart/mixed) '- body (multipart/multipart) :- html (text/html) '- htmlE (text/html) You want instead: msg (multipart/mixed) :- html (text/html) '- htmlE (text/html) In code: msg.attach(MIMEText(html, 'html')) msg.attach(MIMEText(htmlE, 'html')) So just skip ?body?. (Where else but to the body of the message would you attach parts? To the header? ;-)) You can see how it works *before* you sent the e-mail if you call print(msg) (Of course, you can also read the e-mail source after it was delivered.) It is unnecessary/wrong to remove the '\n's from the HTML before transfer encoding by MIMEText(). -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From eldiener at tropicsoft.invalid Tue Jan 5 19:48:18 2016 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Tue, 5 Jan 2016 19:48:18 -0500 Subject: Python launcher options Message-ID: The Python launcher in Windows is a neat tool for running multiple versions of Python 2 and Python 3 at different times. It allows as options the ability to specify the latest version of either Python 2 or Python 3 defaulting to the 64-bit version if both exist, or a specific 32-bit or 64-bit version of Python 2 or Python 3. What is missing is the ability to specify the latest 32-bit version of Python 2 or Python 3. The equivalent syntax would be '-2-32' or '-3-32'. Is there some reason why this option has been disallowed ? From steve+comp.lang.python at pearwood.info Wed Jan 6 00:18:30 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jan 2016 16:18:30 +1100 Subject: Why is there difference between cmd line and .py file? References: <1876022.WpuiDFLl9Z@PointedEars.de> Message-ID: <568ca3a7$0$11128$c3e8da3@news.astraweb.com> On Wednesday 06 January 2016 10:25, Thomas 'PointedEars' Lahn wrote: > Robert wrote: > >> I just wonder that the cmd line function sum may be different from the >> .py file used. One is numpy package, the other is a general one. Then, >> how can I further make it clear for this guess? > > Among other things: > > print(sum.__doc__) Better: help(sum) in the interactive shell. -- Steve From steve+comp.lang.python at pearwood.info Wed Jan 6 00:25:30 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jan 2016 16:25:30 +1100 Subject: Why is there difference between cmd line and .py file? References: Message-ID: <568ca54c$0$2868$c3e8da3$76491128@news.astraweb.com> On Wednesday 06 January 2016 07:37, John Gordon wrote: > The built-in function sum() returns a single value, not a list, so this > is a reasonable error. Not quite. It depends on what arguments you give it. py> a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] py> sum(a, []) [1, 2, 3, 4, 5, 6, 7, 8, 9] But your point is well taken. In this case, the call: sum(expectation_A) defaults to an initial value of 0, so expectation_A almost certainly is a list of numbers, in which case sum will return a single number, not a list or array. -- Steve From steve+comp.lang.python at pearwood.info Wed Jan 6 00:33:49 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jan 2016 16:33:49 +1100 Subject: Why is there difference between cmd line and .py file? References: Message-ID: <568ca73f$0$1596$c3e8da3$5496439d@news.astraweb.com> On Wednesday 06 January 2016 07:25, Robert wrote: > Why is there difference between cmd line and .py file? Almost certainly because you are not running exactly the same code each time. > I run below code, which is downloaded from link: Your code fails on the first line with NameError: name 'np' is not defined so you are obviously running something different from what you post here. Since we don't know what code you are actually running, we cannot tell you why it behaves differently when run as a .py file and in the interactive interpreter. But I am 99% sure that it is because you are running slightly different pieces of code. My *guess* is that in the code that works correctly, you are running: import numpy as np from numpy import sum at the beginning of the .py script, but in the interactive shell, you are just running: import numpy as np But there may be other differences as well. -- Steve From haniemmahmoodebraheim at gmail.com Wed Jan 6 07:08:14 2016 From: haniemmahmoodebraheim at gmail.com (haniemmahmoodebraheim at gmail.com) Date: Wed, 6 Jan 2016 04:08:14 -0800 (PST) Subject: =?windows-1256?B?yNHkx+PM?= Message-ID: <09181534-6a9f-4409-b7d2-bb4702ed4dc6@googlegroups.com> ?????? Ashampoo WinOptimizer 12.00.41 http://q.gs/9dVa5 Any Video Converter Ultimate 5.8.8 http://q.gs/9dVa5 ???? ??????? ??????? CCNA 200-120 Routing & Switching http://q.gs/9dVa5 Mozilla Firefox 43.0.4 RC http://q.gs/9dVa5 ALLPlayer 6.5.0 Final http://q.gs/9dVa5 ???? ?????? ?????? ??? ???? ????? ??????? EasiestSoft Movie Editor 4.8.0 http://q.gs/9dVa5 Wondershare MobileTrans 7.5.0.442 http://q.gs/9dVa5 ???? ???? ?????? ?????? Oracle developer g11 http://q.gs/9dVa5 ?????? ??? ? ?? ??? ??????? ??????? WinRAR 5.31 Beta 1 http://q.gs/9dVa5 YouTube Video Downloader Pro http://q.gs/9dVa5 ???? ?????? ????? ???????? Adobe Indesign ?? ??? ?????? ?????? http://q.gs/9dVa5 ???? ?????? ??????? ?? ????????? ??????? ESET 9.0.349.14 Final http://q.gs/9dVa5 ??????? ??????? ?????? SystemRescueCd 4.7.0 Final http://q.gs/9dVa5 Deep Freeze Enterprise 8.31.220.5051 http://q.gs/9dVa5 ???? ??????? ???????? ??????? ?? ??????? ??? ???????? ?? ???? 3D Max ???? http://q.gs/9dVa5 Skype 7.17.0.106 Final http://q.gs/9dVa5 DriverPack Solution 2015 Final http://q.gs/9dVa5 WebcamMax 7.9.7.2 http://q.gs/9dVa5 AIMP 4.00 Build 1683 Final http://q.gs/9dVa5 Internet Download Manager 6.25 Build 10 Final http://q.gs/9dVa5 ???? (??????? ?????) ??? ???? http://q.gs/9dVa5 Any Video Converter Ultimate 5.8.7 http://q.gs/9dVa5 ???? ???? ???? ????? ??????? ?????? ???? 2012 http://q.gs/9dVa5 Mozilla Firefox 43.0.3 Final http://q.gs/9dVa5 DVB Dream 2.8 Final http://q.gs/9dVa5 ProgDVB Pro 7.12.1 Final http://q.gs/9dVa5 Adobe Flash Player 20.0.0.267 Final http://q.gs/9dVa5 ????? ????? ?????? ??????? MAGIX Movie Edit Pro 2016 Premium 15.0.0.90 http://q.gs/9dVa5 ?????? ??????? ?????? ?????????? ???????? ????? ???? SpeedyFox 2.0.14.95 http://q.gs/9dVa5 ?????? ?????? ?????? K-Lite Mega Codec Pack 11.8.0 Final http://q.gs/9dVa5 Mozilla Firefox 43.0.3 RC http://q.gs/9dVa5 Super Hide IP 3.5.3.2 http://q.gs/9dVa5 ???? ????? ??? ??????? ???????? ?????????? Anti-Porn 23.3.12.1 Final http://q.gs/9dVa5 ???????? ??????? ?????? ???????? ?? ??????? WinToUSB Enterprise 2.7 Final http://q.gs/9dVa5 ???? ????? ??? ??????? ???????? ?????????? Anti-Porn 23.3.12.1 Final http://q.gs/9dVa5 Mozilla Firefox 43.0.2 Final http://q.gs/9dVa5 ???????? ?????? ?????? ???????? ?????? ??????Ashampoo WinOptimizer 12.00.4 Final http://q.gs/9dVa5 ?????? ????? ???????? ??????? AIMP 4.00 Build 1680 Final http://q.gs/9dVa5 From haniemmahmoodebraheim at gmail.com Wed Jan 6 07:08:25 2016 From: haniemmahmoodebraheim at gmail.com (haniemmahmoodebraheim at gmail.com) Date: Wed, 6 Jan 2016 04:08:25 -0800 (PST) Subject: =?windows-1256?B?yNHkx+PM?= Message-ID: ?????? Ashampoo WinOptimizer 12.00.41 http://q.gs/9dVa5 Any Video Converter Ultimate 5.8.8 http://q.gs/9dVa5 ???? ??????? ??????? CCNA 200-120 Routing & Switching http://q.gs/9dVa5 Mozilla Firefox 43.0.4 RC http://q.gs/9dVa5 ALLPlayer 6.5.0 Final http://q.gs/9dVa5 ???? ?????? ?????? ??? ???? ????? ??????? EasiestSoft Movie Editor 4.8.0 http://q.gs/9dVa5 Wondershare MobileTrans 7.5.0.442 http://q.gs/9dVa5 ???? ???? ?????? ?????? Oracle developer g11 http://q.gs/9dVa5 ?????? ??? ? ?? ??? ??????? ??????? WinRAR 5.31 Beta 1 http://q.gs/9dVa5 YouTube Video Downloader Pro http://q.gs/9dVa5 ???? ?????? ????? ???????? Adobe Indesign ?? ??? ?????? ?????? http://q.gs/9dVa5 ???? ?????? ??????? ?? ????????? ??????? ESET 9.0.349.14 Final http://q.gs/9dVa5 ??????? ??????? ?????? SystemRescueCd 4.7.0 Final http://q.gs/9dVa5 Deep Freeze Enterprise 8.31.220.5051 http://q.gs/9dVa5 ???? ??????? ???????? ??????? ?? ??????? ??? ???????? ?? ???? 3D Max ???? http://q.gs/9dVa5 Skype 7.17.0.106 Final http://q.gs/9dVa5 DriverPack Solution 2015 Final http://q.gs/9dVa5 WebcamMax 7.9.7.2 http://q.gs/9dVa5 AIMP 4.00 Build 1683 Final http://q.gs/9dVa5 Internet Download Manager 6.25 Build 10 Final http://q.gs/9dVa5 ???? (??????? ?????) ??? ???? http://q.gs/9dVa5 Any Video Converter Ultimate 5.8.7 http://q.gs/9dVa5 ???? ???? ???? ????? ??????? ?????? ???? 2012 http://q.gs/9dVa5 Mozilla Firefox 43.0.3 Final http://q.gs/9dVa5 DVB Dream 2.8 Final http://q.gs/9dVa5 ProgDVB Pro 7.12.1 Final http://q.gs/9dVa5 Adobe Flash Player 20.0.0.267 Final http://q.gs/9dVa5 ????? ????? ?????? ??????? MAGIX Movie Edit Pro 2016 Premium 15.0.0.90 http://q.gs/9dVa5 ?????? ??????? ?????? ?????????? ???????? ????? ???? SpeedyFox 2.0.14.95 http://q.gs/9dVa5 ?????? ?????? ?????? K-Lite Mega Codec Pack 11.8.0 Final http://q.gs/9dVa5 Mozilla Firefox 43.0.3 RC http://q.gs/9dVa5 Super Hide IP 3.5.3.2 http://q.gs/9dVa5 ???? ????? ??? ??????? ???????? ?????????? Anti-Porn 23.3.12.1 Final http://q.gs/9dVa5 ???????? ??????? ?????? ???????? ?? ??????? WinToUSB Enterprise 2.7 Final http://q.gs/9dVa5 ???? ????? ??? ??????? ???????? ?????????? Anti-Porn 23.3.12.1 Final http://q.gs/9dVa5 Mozilla Firefox 43.0.2 Final http://q.gs/9dVa5 ???????? ?????? ?????? ???????? ?????? ??????Ashampoo WinOptimizer 12.00.4 Final http://q.gs/9dVa5 ?????? ????? ???????? ??????? AIMP 4.00 Build 1680 Final http://q.gs/9dVa5 From vincent.vande.vyvre at telenet.be Wed Jan 6 08:28:54 2016 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Wed, 6 Jan 2016 14:28:54 +0100 Subject: ouvrir python In-Reply-To: References: Message-ID: <568D1696.10507@telenet.be> Le 04/01/2016 10:10, Jacques Rosier a ?crit : > J?ai t?l?charg? Python 351. Il est dans la liste des applications de mon ordi (Lenovo; Windows 10). Mais impossible de l?ouvrir. Que faire? Cette liste de diffusion est anglophone, je te recommande de poster sur ce forum: http://www.developpez.net/forums/f96/autres-langages/python-zope/ Vincent From __peter__ at web.de Wed Jan 6 08:39:32 2016 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Jan 2016 14:39:32 +0100 Subject: How to union nested Sets / A single set from nested sets? References: Message-ID: mviljamaa wrote: > I'm forming sets by set.adding to sets and this leads to sets such as: > > Set([ImmutableSet(['a', ImmutableSet(['a'])]), ImmutableSet(['b', > 'c'])]) > > Is there way union these to a single set, i.e. get > > Set(['a', 'b', 'c']) > > ? 1 What version of Python are you working with? Both Python 2.7 and 3.x have built-in set and frozenset types that you should use. 2 Instead of flattening the nested data I recommend that you avoid nesting in the first place by using update() instead of add() >>> x = {"a", "b"} >>> y = {"b", "c"} >>> z = {"a", "c", "d"} >>> result = set() >>> for subset in x, y, z: ... result.update(subset) # or: result |= subset ... >>> result {'b', 'a', 'd', 'c'} For a fixed number of subsets you can avoid the loop and write >>> result = set() >>> result.update(x, y, z) >>> result {'b', 'a', 'd', 'c'} or >>> x | y | z {'b', 'a', 'd', 'c'} From ganesh1pal at gmail.com Wed Jan 6 08:45:22 2016 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Wed, 6 Jan 2016 19:15:22 +0530 Subject: python unit test framework sample code Message-ID: Hello Team, I have written a small program using python unit test framework . I need your guidance to find out 1. If I have used the fixtures and classes properly ( first oop program) :) ) 2. why does unittest2.SkipTest not print the message when the failures are encountered ? 3. Also sys.stderr.write("Test run failed ({e})".format(e=e) ) does not display error on failure ? 4. Any other general comment's Iam on Python 2.6 and using Linux Sample code: class FileSystemTest(unittest2.TestCase): block_address = {} report = "" @classmethod def setUpClass(cls): cls.FileSystemSetup() @classmethod def FileSystemSetup(cls): """ Initial setup before unittest is run """ logging.info("SETUP.....Started !!!") try: inode_01 = corrupt.get_lin(os.path.join(CORRUPT_DIR,"inode_lin.txt")) test_01_log = os.path.join(LOG_DIR, "test_01_corrupt.log") cls.block_address['test_01'] = corrupt.inject_corruption(test_01_log, lin=inode_01, object="inode", offset="18", size="4", optype="set") time.sleep(10) except Exception, e: logging.error(e) raise unittest2.SkipTest("class setup failed") if not corrupt.run_scanner(): raise unittest2.SkipTest("class setup failed") else: try: cls.report = corrupt.run_report() except Exception, e: logging.error(e) raise unittest2.SkipTest("class setup failed") logging.info("SETUP.....Done !!!") def inode_corruption(self): """ test_01: inode corruption """ self.assertTrue(corrupt.run_query_tool(self.__class__.report, self.block_address['test_01'])) @classmethod def tearDownClass(cls): cls.tearDown() @classmethod def tearDown(cls): print "Entered tearDown()" try: cls.cleanup = cleanup() except Exception, e: logging.error(e) def main(): """ ---MAIN--- """ global LOG_DIR try: if len(sys.argv) > 1: LOG_DIR = str(sys.argv[1]) except Exception, e: print(USAGE) return errno.EINVAL functions = [create_logdir,create_dataset,corrupt.prep_cluster] for func in functions: try: func() except Exception, e: logging.error(e) sys.stderr.write("Test run failed ({e})".format(e=e)) unittest2.main() if __name__ == '__main__': main() PS : Happy New year Wishes to all the form members !! Regards, Ganesh From __peter__ at web.de Wed Jan 6 08:56:20 2016 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Jan 2016 14:56:20 +0100 Subject: insert many numbers to a list, a second method. References: <20160105133632.3C11C400C7@webmail.sinamail.sina.com.cn> Message-ID: ?? wrote: > l = list(range(0,12)) > numbers = [5,3,2,7] #insert numbers at 5th position. > list1 = list(range(5,9)) > list2 = list(range(0,5)) > list2.extend(numbers) # > for i in list1: > l.insert(i,list2[i]) > print(l)------> l = [0, 1, 2, 3, 4, 5, 3, 2, 7, 5, 6, 7, 8, 9, > 10, 11] Sorry, I cannot make sense of your sample code. If this is homework and your assignment is to find another way to insert items into a list have a look at slices. Example to get items three to five *out* of the list: >>> items [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> items[2:5] [2, 3, 4] Size zero is legal, too: >>> items[7:7] [] Assigning is similar, and the size of the slice on the left doesn't have to be the same as that of the list on the right. From kwpolska at gmail.com Wed Jan 6 09:22:08 2016 From: kwpolska at gmail.com (Chris Warrick) Date: Wed, 6 Jan 2016 15:22:08 +0100 Subject: I can not install matplotlib, numpy, scipy, and pandas. In-Reply-To: <000001d14786$51434d50$f3c9e7f0$@yahoo.com> References: <000001d14786$51434d50$f3c9e7f0$@yahoo.com> Message-ID: On 5 January 2016 at 07:57, Omar Ray via Python-list wrote: > I have version 3.5 of Python for Windows. I have MS Visual C++ and also MS > Visual Studio 2015. > > When I enter into the command window "pip install matplotlib", it reads this > below (this is not the full version of it): > > [snip] > > How do I download matplotlib and the other packages mentioned in the subject > line? > > > > -Omar Ray > > -- > https://mail.python.org/mailman/listinfo/python-list On Windows, using prebuilt binaries is recommended instead of building things yourself: 1. Installing matplotlib and pandas using pip, without mentioning scipy and numpy just yet. 2. Install scipy and numpy from http://www.lfd.uci.edu/~gohlke/pythonlibs/ (download matching files and run pip install c:\path\to\file.whl ). If anything in 1. fails, get a wheel package from the website mentioned in 2. Alternatively, try: https://www.scipy.org/install.html#individual-binary-and-source-packages -- Chris Warrick PGP: 5EAAEA16 From oscar.j.benjamin at gmail.com Wed Jan 6 09:45:01 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 6 Jan 2016 14:45:01 +0000 Subject: How to union nested Sets / A single set from nested sets? In-Reply-To: References: Message-ID: On 4 January 2016 at 02:40, mviljamaa wrote: > I'm forming sets by set.adding to sets and this leads to sets such as: > > Set([ImmutableSet(['a', ImmutableSet(['a'])]), ImmutableSet(['b', 'c'])]) > > Is there way union these to a single set, i.e. get > > Set(['a', 'b', 'c']) Where are you getting Set and ImmutableSet from? Is that sympy or something? -- Oscar From laurent.pointal at free.fr Wed Jan 6 11:10:24 2016 From: laurent.pointal at free.fr (Laurent Pointal) Date: Wed, 06 Jan 2016 17:10:24 +0100 Subject: ouvrir python References: Message-ID: <568d3c70$0$3870$426a34cc@news.free.fr> Vincent Vande Vyvre wrote: > Le 04/01/2016 10:10, Jacques Rosier a ?crit : >> J?ai t?l?charg? Python 351. Il est dans la liste des applications de mon >> ordi (Lenovo; Windows 10). Mais impossible de l?ouvrir. Que faire? > Cette liste de diffusion est anglophone, je te recommande de poster sur > ce forum: > > http://www.developpez.net/forums/f96/autres-langages/python-zope/ > > Vincent Il y a un groupe francophone sur Usenet: fr.comp.lang.python There is a french Usenet group: fr.comp.lang.python A+ Laurent. From rustompmody at gmail.com Wed Jan 6 11:19:21 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 6 Jan 2016 08:19:21 -0800 (PST) Subject: How to union nested Sets / A single set from nested sets? In-Reply-To: References: Message-ID: <41046824-5cef-4757-bc8d-8ade462c1478@googlegroups.com> On Wednesday, January 6, 2016 at 6:48:28 PM UTC+5:30, mviljamaa wrote: > I'm forming sets by set.adding to sets and this leads to sets such as: > > Set([ImmutableSet(['a', ImmutableSet(['a'])]), ImmutableSet(['b', > 'c'])]) > > Is there way union these to a single set, i.e. get > > Set(['a', 'b', 'c']) > > ? Dont know what version of python spells it that way.. seems old In 2.7 you can do this: >>> a=set([frozenset(['a']), frozenset(['b','c'])]) >>> {y for x in a for y in x} set(['a', 'c', 'b']) It may be easier to understand written the way set-expressions in math are normally written: {y | x ? a, y ? x} And then treat the python as an ASCII-fication of the math Likewise >>> frozenset(y for x in a for y in x) frozenset(['a', 'c', 'b']) >>> From no.email at nospam.invalid Wed Jan 6 11:45:29 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 06 Jan 2016 08:45:29 -0800 Subject: ouvrir python References: Message-ID: <871t9ubqs6.fsf@jester.gateway.pace.com> "Jacques Rosier" writes: > J?ai t?l?charg? Python 351. Il est dans la liste des applications de > mon ordi (Lenovo; Windows 10). Mais impossible de l?ouvrir. Que faire? T?l?charg?z .exe installer https://www.python.org/ftp/python/3.5.1/python-3.5.1-amd64.exe puis cliquez l'.exe pour marcher. (Download the .exe installer and click it to run). From kevind0718 at gmail.com Wed Jan 6 13:29:19 2016 From: kevind0718 at gmail.com (kevind0718 at gmail.com) Date: Wed, 6 Jan 2016 10:29:19 -0800 (PST) Subject: create Email with multiple HTML blocks embedded In-Reply-To: <0f51af4b-dfef-4d27-92b7-be601677bf50@googlegroups.com> References: <0f51af4b-dfef-4d27-92b7-be601677bf50@googlegroups.com> Message-ID: <27f1baec-e96b-4131-862c-b2d7e05e569e@googlegroups.com> On Tuesday, January 5, 2016 at 10:27:30 AM UTC-5, kevin... at gmail.com wrote: > The below script will send an email with one HTML file embedded and the second attached. Not really what I need. I need a Python script to create an email that contains multiple blocks of HTML in the body of the email. > > There is a process that will create at least one HTML file but very often two. A summary and an exception web pages. These need to be emailed to a user group. > > The code below displays one file in the email, but the other shows up as an attachment. If I reverse the body.attach statements then the files switch. I need both to appear in the body of the email. > > I messed around with the boundary attribute, but could not get that to work. > > Your kind assistance is requested. > > Best Regards > > KD > > > import smtplib > from pprint import pprint > from email.mime.multipart import MIMEMultipart > from email.mime.text import MIMEText > > msg = MIMEMultipart() > msg['Subject'] = 'email from Python with HTML content ' > msg['From'] = 'kduf at xxx.com' > msg['To'] = 'kduf at xxx.com' > > text = "\nBelow I hope will be the Summary Table in HTML\n\n" > body = MIMEMultipart('multipart') > > with open("H:\\dev\\testHTML\\Exceptions_SheetDec30d.htm", "r") as fE: > htmlE = fE.read().replace('\n', '') > > > with open("H:\\dev\\testHTML\\Summary_SheetDec30d.htm", "r") as f: > html = f.read().replace('\n', '') > > body.attach(MIMEText(html, 'html')) > body.attach(MIMEText(htmlE, 'html')) > > msg.attach(body) > > s = smtplib.SMTP('smtp.aigfpc.com') # ('localhost') > s.sendmail('kduf at xxx.com', ['kduf at xxx.com'], msg.as_string()) > s.quit() Thomas: Following your suggestions, I now have code that looks like the below. I get the same result. First HTML is displayed in body of email and second shows up as an attachment. A dump of the email message is also below. Maybe this would help. Thanks for your kind assistance KD ''' ''' import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from pprint import pprint ##msg = MIMEText("Hello KBD:\n\n" + "this is the query: select * from TSR.TSR_SRC \n\n" + rslt ) msg = MIMEMultipart() msg['Subject'] = 'email from Python with HTML content file name: wbOut\Summary_SheetOnly_Out' msg['From'] = 'kdff at xxx.com' msg['To'] = 'kduf at xxx.com' text = "\nBelow I hope will be the Summary Table in HTML\n\n" ## body = MIMEMultipart('multipart' ) ## summary_html.tmp.html ## with open ("H:\\dev\\wbOut\\Summary_SheetOnly_Out.htm", "r") as f: ## with open ("H:\\dev\\wbOut\\TSR_DQ_Summary_Dec30.HTML_Out.htm" , "r") as f: with open ("H:\\dev\\testHTML\\Exceptions_SheetDec30d.htm", "r") as fE: htmlE = fE.read() ##.replace('\n', '') with open ("H:\\dev\\testHTML\\Summary_SheetDec30d.htm", "r") as f: ##with open ("H:\\dev\\wbOutwbHTML.htm", "r") as f: html = f.read() ##.replace('\n', '') msg.attach( MIMEText(htmlE, 'html') ) msg.attach( MIMEText(html, 'html') ) print(msg) # Send the message via our own SMTP server, but don't include the # envelope header. s = smtplib.SMTP('smtp.xxxfpc.com') ## ('localhost') ##s.sendmail('kduf at xxx.com', ['kduf at xxx.com'], msg.as_string() ) s.sendmail('kduf at xxx.com', ['kduf at xxx.com'], msg.as_string() ) s.quit() ## body.attach( MIMEText(html, 'html') ) ## body.attach( MIMEText(htmlE, 'html') ) ##body.attach( MIMEText(html, 'html; charset=utf-8 ') ) ## msg.attach(body ) ##msg.attach(htmlPart) pydev debugger: starting (pid: 7516) >From nobody Wed Jan 06 13:16:01 2016 Content-Type: multipart/mixed; boundary="===============0399484825==" MIME-Version: 1.0 Subject: email from Python with HTML content file name: wbOut\Summary_SheetOnly_Out From: kduff at xxx.com To: kduff at xxx.com --===============0399484825== Content-Type: text/html; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit
Exception
As At: 30-Dec-2015 As Of:? 29-Dec-2015
There are Exceptions
?
Sheet Break Point / Exception
PX_Last Percent Change Break Point FALSE
PX_Last Dropped - Added TRUE
PX_LAST Stale PX_Last Stale Count TRUE
MarkIt Spread Percent Change Break Point FALSE
MarkIt Spread Dropped - Added TRUE
ARM Rate Match ARM Rate Match Count TRUE
************ ******************************
************ ******************************
--===============0399484825== Content-Type: text/html; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit
Summary As At: 30-Dec-2015 As Of:? 29-Dec-2015
PX_LAST???? Day - Over - Day Count Compare   Percent Change Break Point
SOURCE_CD FIELD CURRENT_DATE CURRENT_COUNT PREV_DATE PREV_COUNT PCT_CHANGE
BBG PX_LAST 12/29/2015 8349 12/28/2015 8358 -11.00% 10
PX_LAST??? Week - Over - Week Count Compare   Percent Change Break Point
SOURCE_CD FIELD CURRENT_DATE CURRENT_COUNT PREV_DATE PREV_COUNT PCT_CHANGE
BBG PX_LAST 12/29/2015 8349 12/22/2015 8376 -32.00% 10
MarkIt Spread???? Day - Over - Day Count Compare  
SOURCE_CD FIELD CURRENT_DATE CURRENT_COUNT PREV_DATE PREV_COUNT PCT_CHANGE
MARKIT SPREAD 12/29/2015 2204 12/28/2015 2197 32.00%
MarkIt Spread??? Week - Over - Week Count Compare  
SOURCE_CD FIELD CURRENT_DATE CURRENT_COUNT PREV_DATE PREV_COUNT PCT_CHANGE
MARKIT SPREAD 12/29/2015 2204 12/22/2015 2217 -59.00%
PX_YEILD???? Day - Over - Day Count Compare  
SOURCE_CD FIELD CURRENT_DATE CURRENT_COUNT PREV_DATE PREV_COUNT PCT_CHANGE
RM PX_YIELD 12/29/2015 4030 12/28/2015 4030 0.00%
PX_YIELD??? Week - Over - Week Count Compare  
SOURCE_CD FIELD CURRENT_DATE CURRENT_COUNT PREV_DATE PREV_COUNT PCT_CHANGE
RM PX_YIELD 12/29/2015 4030 12/22/2015 4030 0.00%
ARM Rate Matches
47
PX_Stale Greater then 40 Days
337
--===============0399484825==-- From tjreedy at udel.edu Wed Jan 6 16:17:10 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 6 Jan 2016 16:17:10 -0500 Subject: trying to install In-Reply-To: <191C5999822F5A43BE0EA563E38EBA31A9E4092A@EXMB02.bergen.org> References: <191C5999822F5A43BE0EA563E38EBA31A9E4092A@EXMB02.bergen.org> Message-ID: On 1/4/2016 2:00 PM, Montone_Dennis wrote: > I am using Windows 7 and when I try to runt IDLE I get the following error. > "The program can't start because api-ms-win-crt-runtime-I1-1-0.dll is missing from your computer." > > Do you have any suggestions for me? Download and install the required .dll. See previous posts. It might be easiest to search gmane.comp.python.general as news.gmane.org. -- Terry Jan Reedy From tjreedy at udel.edu Wed Jan 6 16:49:58 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 6 Jan 2016 16:49:58 -0500 Subject: python unit test framework sample code In-Reply-To: References: Message-ID: On 1/6/2016 8:45 AM, Ganesh Pal wrote: > Hello Team, > > I have written a small program using python unit test framework . I > need your guidance to find out > > 1. If I have used the fixtures and classes properly ( first oop program) :) ) > 2. why does unittest2.SkipTest not print the message when the failures > are encountered ? > 3. Also sys.stderr.write("Test run failed ({e})".format(e=e) ) does > not display error on failure ? > 4. Any other general comment's > > I am on Python 2.6 and using Linux Unless you have a large program already in 2.6 and are just adding tests (perhaps so you can more easily upgrade someday), consider upgrading to a newer version. > Sample code: > > class FileSystemTest(unittest2.TestCase): > block_address = {} > report = "" > > @classmethod > def setUpClass(cls): > cls.FileSystemSetup() This is senseless. Put the body of FileSystemSetup here. > @classmethod > def FileSystemSetup(cls): > """ > Initial setup before unittest is run > """ > logging.info("SETUP.....Started !!!") > try: > inode_01 = > corrupt.get_lin(os.path.join(CORRUPT_DIR,"inode_lin.txt")) > test_01_log = os.path.join(LOG_DIR, "test_01_corrupt.log") > cls.block_address['test_01'] = > corrupt.inject_corruption(test_01_log, > lin=inode_01, object="inode", offset="18", > size="4", optype="set") > time.sleep(10) > > except Exception, e: > logging.error(e) > raise unittest2.SkipTest("class setup failed") > if not corrupt.run_scanner(): > raise unittest2.SkipTest("class setup failed") > > else: > try: > cls.report = corrupt.run_report() > except Exception, e: > logging.error(e) > raise unittest2.SkipTest("class setup failed") > logging.info("SETUP.....Done !!!") > > def inode_corruption(self): > """ test_01: inode corruption """ > self.assertTrue(corrupt.run_query_tool(self.__class__.report, self.block_address['test_01'])) Assuming that unittest2 is same as unittest, test methods must be called test_xyz. So this is not run, hence no error. > @classmethod > def tearDownClass(cls): > cls.tearDown() Ditto. Put real body here. > @classmethod > def tearDown(cls): This is worse than setup. The name 'tearDown' is reserved for and called to teardown after each test_xyz method is called. So once you change 'inode'corruption' to 'test_inode_corruption', this should fail. > print "Entered tearDown()" > try: > cls.cleanup = cleanup() > except Exception, e: > logging.error(e) > > def main(): > """ ---MAIN--- """ > global LOG_DIR > try: > if len(sys.argv) > 1: > LOG_DIR = str(sys.argv[1]) > except Exception, e: > print(USAGE) > return errno.EINVAL > functions = [create_logdir,create_dataset,corrupt.prep_cluster] > for func in functions: > try: > func() > except Exception, e: > logging.error(e) > sys.stderr.write("Test run failed ({e})".format(e=e)) The above refers to functions you did not post. For current unittest, it looks likes you should be using a setUpModule (possible tearDownModule) functions, but I don't know if those are available in the older unittest2. > unittest2.main() > > if __name__ == '__main__': > main() I think the biggest mistake people make is to do too much new stuff at once. Python, with IDLE (or equivalent), makes incremental development easy. My first unittest program was about 10 lines. I expanded from there. I am still 'expanding' from my current knowledge. -- Terry Jan Reedy From darren.mcaffee at gmail.com Wed Jan 6 17:20:36 2016 From: darren.mcaffee at gmail.com (darren.mcaffee at gmail.com) Date: Wed, 6 Jan 2016 14:20:36 -0800 (PST) Subject: imshow keeps crashhing In-Reply-To: References: Message-ID: Hi John, I am on a mac and have set the following: SCIPY_PIL_IMAGE_VIEWER=/Applications/Preview.app/Contents/MacOS/Preview And when using imshow(), sure enough Preview attempts to open the fie, but it throws the following error: The file "tmp1zuvo7wn.png" couldn't be opened because you don't have permission to view it. I can open the temporary file manually no problem. And I have played around with chmod 0644 , but nothing seems to work. I have a feeling this is El Capitan specific. Do you have any suggestions? From gordon at panix.com Wed Jan 6 17:42:25 2016 From: gordon at panix.com (John Gordon) Date: Wed, 6 Jan 2016 22:42:25 +0000 (UTC) Subject: imshow keeps crashhing References: Message-ID: In darren.mcaffee at gmail.com writes: > Hi John, > I am on a mac and have set the following: > SCIPY_PIL_IMAGE_VIEWER=/Applications/Preview.app/Contents/MacOS/Preview > And when using imshow(), sure enough Preview attempts to open the fie, > but it throws the following error: The file "tmp1zuvo7wn.png" couldn't be > opened because you don't have permission to view it. > I can open the temporary file manually no problem. And I have played > around with chmod 0644 , but nothing seems to work. > I have a feeling this is El Capitan specific. Do you have any > suggestions? I don't really know much about Macs... Can you run Preview and open the temporary file successfully? When launched from scipy, Does Preview run as a user other than yourself? What are the permissions on the temporary file when it's originally created? -- 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 darren.mcaffee at gmail.com Wed Jan 6 18:10:29 2016 From: darren.mcaffee at gmail.com (darren.mcaffee at gmail.com) Date: Wed, 6 Jan 2016 15:10:29 -0800 (PST) Subject: imshow keeps crashhing In-Reply-To: References: Message-ID: Thanks for the quick reply! So scipy is making temporary files in /private/vars/folders/w4// 1. When in the correct folder within Terminal, on the command line I can do: open And it will open it in Preivew. 2. However, when opening Preview first, it is impossible (for me) to navigate to the /private directory to open the file that way, even with: defaults write com.apple.Finder AppleShowAllFiles YES turned on. 3. When I run imshow() (my attempt to 'launch Preview from scipy as you suggested). The UID of the process is 501, which is the same as when I do echo $UID. So I'm assuming the launched Preview is running as myself. 4. When the temporary file is originally created its permissions are -rw------ Does any of that information help? Thanks again. From gordon at panix.com Wed Jan 6 18:26:58 2016 From: gordon at panix.com (John Gordon) Date: Wed, 6 Jan 2016 23:26:58 +0000 (UTC) Subject: imshow keeps crashhing References: Message-ID: In darren.mcaffee at gmail.com writes: > So scipy is making temporary files in > /private/vars/folders/w4// Are there any unusual characters in ? That's usually more of a Windows issue, but I'm grasping at straws here :-) > 1. When in the correct folder within Terminal, on the command line I can do: > open > And it will open it in Preivew. So the actual command name for running Preview is "open"? Have you tried setting the SCIPY_PIL_IMAGE_VIEWER variable to that name? > 2. However, when opening Preview first, it is impossible (for me) to navigate to the /private directory to open the file that way, even with: > defaults write com.apple.Finder AppleShowAllFiles YES > turned on. You mean you can't use Preview's file-selection interface to select the desired file? The /private directory is not navigable? Does it even show up as a choice? Is there something special about the /private directory? -- 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 wrw at mac.com Wed Jan 6 18:37:58 2016 From: wrw at mac.com (William Ray Wing) Date: Wed, 06 Jan 2016 18:37:58 -0500 Subject: imshow keeps crashhing In-Reply-To: References: Message-ID: <95A41665-B3B1-4DDC-AFB8-9AD186EAD6C5@mac.com> > On Jan 6, 2016, at 6:10 PM, darren.mcaffee at gmail.com wrote: > > Thanks for the quick reply! > > So scipy is making temporary files in /private/vars/folders/w4// Is this a typo or did you really mean /private/vars? That is, did your create a ?vars? directory under /private at some point in the past (pre-Yosemite)? The usual directory there would be /var In any case, the whole /private directory tree is now part of the SIP (System Integrity Protection) system under Yosemite, and to open and manipulate files there you will have to either turn SIP off or jump through hoops. If you do a ls -al in /private, you will see that var is drwxr-xr-x 29 root wheel 986 Oct 23 11:20 var note the ?root? and ?wheel? owner and group names. I?d suggest moving your tests to a different directory that isn?t part of SIP, and debug there. If you MUST work under /private, you will have your work cut out for you. -Bill > > 1. When in the correct folder within Terminal, on the command line I can do: > open > And it will open it in Preivew. > > 2. However, when opening Preview first, it is impossible (for me) to navigate to the /private directory to open the file that way, even with: > defaults write com.apple.Finder AppleShowAllFiles YES > turned on. > > 3. When I run imshow() (my attempt to 'launch Preview from scipy as you suggested). The UID of the process is 501, which is the same as when I do echo $UID. So I'm assuming the launched Preview is running as myself. > > 4. When the temporary file is originally created its permissions are -rw------ > > Does any of that information help? Thanks again. > -- > https://mail.python.org/mailman/listinfo/python-list From darren.mcaffee at gmail.com Wed Jan 6 18:52:15 2016 From: darren.mcaffee at gmail.com (darren.mcaffee at gmail.com) Date: Wed, 6 Jan 2016 15:52:15 -0800 (PST) Subject: imshow keeps crashhing In-Reply-To: References: Message-ID: <23c59e11-c503-4b27-924b-66466c00570e@googlegroups.com> Thanks William and John, So the full path that scipy is using is: /private/var/folders/w4/wrnzszgd41d7064lx64nc10h0000gn/T/ I can't recall specifically adding the /var directory under /private. William - do you know how I can make scipy write temporary files in a non SIP folder? Thanks so much, Darren From darren.mcaffee at gmail.com Wed Jan 6 20:13:18 2016 From: darren.mcaffee at gmail.com (darren.mcaffee at gmail.com) Date: Wed, 6 Jan 2016 17:13:18 -0800 (PST) Subject: imshow keeps crashhing In-Reply-To: <23c59e11-c503-4b27-924b-66466c00570e@googlegroups.com> References: <23c59e11-c503-4b27-924b-66466c00570e@googlegroups.com> Message-ID: <89b99111-fb6e-4d78-bcad-3307754c5c60@googlegroups.com> Sorry you were right the path is in: /vars/folders not /private/var/folders. From high5storage at gmail.com Wed Jan 6 21:36:58 2016 From: high5storage at gmail.com (high5storage at gmail.com) Date: Wed, 6 Jan 2016 18:36:58 -0800 (PST) Subject: Fast pythonic way to process a huge integer list Message-ID: <7e2b93e4-c224-40c4-8e88-7dcc847edab1@googlegroups.com> I have a list of 163.840 integers. What is a fast & pythonic way to process this list in 1,280 chunks of 128 integers? From tjreedy at udel.edu Wed Jan 6 22:10:13 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 6 Jan 2016 22:10:13 -0500 Subject: Fast pythonic way to process a huge integer list In-Reply-To: <7e2b93e4-c224-40c4-8e88-7dcc847edab1@googlegroups.com> References: <7e2b93e4-c224-40c4-8e88-7dcc847edab1@googlegroups.com> Message-ID: On 1/6/2016 9:36 PM, high5storage at gmail.com wrote: > > I have a list of 163.840 integers. What is a fast & pythonic way to process this list in 1,280 chunks of 128 integers? What have you tried that did not work? This is really pretty simple, but the detail depend on the meaning of 'process a chunk'. -- Terry Jan Reedy From habyte at gmail.com Wed Jan 6 22:20:45 2016 From: habyte at gmail.com (Henrique Correa) Date: Thu, 7 Jan 2016 01:20:45 -0200 Subject: A newbie's doubt Message-ID: Is Python's Tutorial (by Guido) a good and complete reference for the language? I mean, after reading it, should I have a good basis on Python? I've came from js and php, and already know the very basics of py. Thank you! From python.list at tim.thechases.com Wed Jan 6 22:21:41 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 6 Jan 2016 21:21:41 -0600 Subject: Fast pythonic way to process a huge integer list In-Reply-To: <7e2b93e4-c224-40c4-8e88-7dcc847edab1@googlegroups.com> References: <7e2b93e4-c224-40c4-8e88-7dcc847edab1@googlegroups.com> Message-ID: <20160106212141.3ccb07d9@bigbox.christie.dr> On 2016-01-06 18:36, high5storage at gmail.com wrote: > I have a list of 163.840 integers. What is a fast & pythonic way to > process this list in 1,280 chunks of 128 integers? That's a modest list, far from huge. You have lots of options, but the following seems the most pythonic to me: # I don't know how you populate your data so # create some junk data from random import randint data = [randint(0,1000) for _ in range(163840)] import itertools as i GROUP_SIZE = 128 def do_something(grp, vals): for _, val in vals: # I don't know what you want to do with each # pair. You can print them: # print("%s: %s" % (grp, val)) # or write them to various chunked files: with open("chunk%04i.txt" % grp, "w") as f: f.write(str(val)) f.write("\n") # but here's the core logic: def key_fn(x): # x is a tuple of (index, value) return x[0] // GROUP_SIZE # actually iterate over the grouped data # and do something with it: for grp, vals in i.groupby(enumerate(data), key_fn): do_something(grp, vals) -tkc From cs at zip.com.au Wed Jan 6 22:31:56 2016 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 7 Jan 2016 14:31:56 +1100 Subject: Fast pythonic way to process a huge integer list In-Reply-To: <7e2b93e4-c224-40c4-8e88-7dcc847edab1@googlegroups.com> References: <7e2b93e4-c224-40c4-8e88-7dcc847edab1@googlegroups.com> Message-ID: <20160107033156.GA37287@cskk.homeip.net> On 06Jan2016 18:36, high5storage at gmail.com wrote: >I have a list of 163.840 integers. What is a fast & pythonic way to process >this list in 1,280 chunks of 128 integers? The depends. When you say "list", is it already a _python_ list? Or do you just mean that the intergers are in a file or something? If they're already in a python list you can probably just use a range: for offset in range(0, 163840, 128): ... do stuff with the elements starting at offset ... Cheers, Cameron Simpson From snailcoder at retrosite.invalid Wed Jan 6 23:59:34 2016 From: snailcoder at retrosite.invalid (Grobu) Date: Thu, 7 Jan 2016 05:59:34 +0100 Subject: How to union nested Sets / A single set from nested sets? In-Reply-To: References: Message-ID: On 04/01/16 03:40, mviljamaa wrote: > I'm forming sets by set.adding to sets and this leads to sets such as: > > Set([ImmutableSet(['a', ImmutableSet(['a'])]), ImmutableSet(['b', 'c'])]) > > Is there way union these to a single set, i.e. get > > Set(['a', 'b', 'c']) > > ? There's a built-in "union" method for sets : >>> a = set( ['a', 'b'] ) >>> b = set( ['c', 'd'] ) >>> a.union(b) set(['a', 'c', 'b', 'd']) HTH From joel.goldstick at gmail.com Thu Jan 7 00:33:49 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 7 Jan 2016 00:33:49 -0500 Subject: How to union nested Sets / A single set from nested sets? In-Reply-To: References: Message-ID: On Wed, Jan 6, 2016 at 11:59 PM, Grobu wrote: > On 04/01/16 03:40, mviljamaa wrote: > >> I'm forming sets by set.adding to sets and this leads to sets such as: >> >> Set([ImmutableSet(['a', ImmutableSet(['a'])]), ImmutableSet(['b', 'c'])]) >> >> Is there way union these to a single set, i.e. get >> >> Set(['a', 'b', 'c']) >> >> ? >> > > There's a built-in "union" method for sets : > > >>> a = set( ['a', 'b'] ) > >>> b = set( ['c', 'd'] ) > >>> a.union(b) > set(['a', 'c', 'b', 'd']) > > HTH > -- > https://mail.python.org/mailman/listinfo/python-list > plus 1 -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From miki.tebeka at gmail.com Thu Jan 7 02:09:47 2016 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 6 Jan 2016 23:09:47 -0800 (PST) Subject: I can not install matplotlib, numpy, scipy, and pandas. In-Reply-To: References: Message-ID: <17c75d81-6fcd-45ad-8aa2-9bfdf2442c81@googlegroups.com> > When I enter into the command window "pip install matplotlib", it reads this > below (this is not the full version of it): > ... Installing scientific packages can be a pain. I recommend you take a look at https://www.continuum.io/downloads From steve at pearwood.info Thu Jan 7 03:37:56 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jan 2016 19:37:56 +1100 Subject: How to union nested Sets / A single set from nested sets? References: Message-ID: <568e23e5$0$1590$c3e8da3$5496439d@news.astraweb.com> On Thu, 7 Jan 2016 01:45 am, Oscar Benjamin wrote: > On 4 January 2016 at 02:40, mviljamaa wrote: >> I'm forming sets by set.adding to sets and this leads to sets such as: >> >> Set([ImmutableSet(['a', ImmutableSet(['a'])]), ImmutableSet(['b', 'c'])]) >> >> Is there way union these to a single set, i.e. get >> >> Set(['a', 'b', 'c']) > > Where are you getting Set and ImmutableSet from? Is that sympy or > something? Set and ImmutableSet were the original versions from Python 2.3 before the builtins. They're still available up to Python 2.7 (gone in 3): py> import sets py> sets.Set but that's just for backwards compatibility, you should use the built-in versions if you can. -- Steven From steve at pearwood.info Thu Jan 7 04:25:48 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jan 2016 20:25:48 +1100 Subject: Fast pythonic way to process a huge integer list References: <7e2b93e4-c224-40c4-8e88-7dcc847edab1@googlegroups.com> Message-ID: <568e2f1d$0$1602$c3e8da3$5496439d@news.astraweb.com> On Thu, 7 Jan 2016 01:36 pm, high5storage at gmail.com wrote: > > I have a list of 163.840 integers. What is a fast & pythonic way to > process this list in 1,280 chunks of 128 integers? py> from itertools import izip_longest py> def grouper(iterable, n, fillvalue=None): ... "Collect data into fixed-length chunks or blocks" ... # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx ... args = [iter(iterable)] * n ... return izip_longest(fillvalue=fillvalue, *args) ... py> alist = range(163840) py> count = 0 py> for block in grouper(alist, 128): ... assert len(list(block)) == 128 ... count += 1 ... py> count 1280 This was almost instantaneous on my computer. 163840 isn't a very large number of ints. -- Steven From self at example.org Thu Jan 7 04:33:13 2016 From: self at example.org (me) Date: Thu, 7 Jan 2016 09:33:13 +0000 (UTC) Subject: subprocess check_output References: <20151230210227.GA88234@cskk.homeip.net> Message-ID: On 2016-01-05, Chris Angelico wrote: > Oh, and then you keep editing and save again? Nah, I've *never* done > that... Never! I'm quite surprised, buddy. You should definitely try. From rosuav at gmail.com Thu Jan 7 04:54:43 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jan 2016 20:54:43 +1100 Subject: subprocess check_output In-Reply-To: References: <20151230210227.GA88234@cskk.homeip.net> Message-ID: On Thu, Jan 7, 2016 at 8:33 PM, me wrote: > On 2016-01-05, Chris Angelico wrote: >> Oh, and then you keep editing and save again? Nah, I've *never* done >> that... Never! > > I'm quite surprised, buddy. You should definitely try. I know, right! It's so exciting to suddenly discover that you have two separate copies of a piece of code, and that one of them isn't where you think it is... makes life so interesting! Serious suggestion for people who run into weirdness: Sometimes it helps to make a deliberate and obvious syntax error (misuse a keyword, break the indentation, put a mass of symbols in someplace), just to see that your code is getting parsed. If it doesn't trigger an error, well, your deployment is failing somewhere. CSS gurus suggest, along similar lines, changing the background color of something to red. Saves ever so much fiddling around - instead of asking "why doesn't my padding work in IE?", you ask the correct question of "why isn't my CSS file being read?", upon which you discover that you were referencing it from the wrong directory. True story. ChrisA From marko at pacujo.net Thu Jan 7 05:12:00 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 07 Jan 2016 12:12:00 +0200 Subject: subprocess check_output References: <20151230210227.GA88234@cskk.homeip.net> Message-ID: <87lh817l73.fsf@elektro.pacujo.net> Chris Angelico : > you ask the correct question of "why isn't my CSS file being read?" TL;DR Marko From marko at pacujo.net Thu Jan 7 05:14:12 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 07 Jan 2016 12:14:12 +0200 Subject: subprocess check_output References: <20151230210227.GA88234@cskk.homeip.net> <87lh817l73.fsf@elektro.pacujo.net> Message-ID: <87d1td7l3f.fsf@elektro.pacujo.net> Marko Rauhamaa : > Chris Angelico : > >> you ask the correct question of "why isn't my CSS file being read?" > > TL;DR Sorry, getting confused with homonyms: >> CSS gurus suggest, along similar lines, changing the background color >> of something to red. Marko From __peter__ at web.de Thu Jan 7 05:21:03 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Jan 2016 11:21:03 +0100 Subject: Fast pythonic way to process a huge integer list References: <7e2b93e4-c224-40c4-8e88-7dcc847edab1@googlegroups.com> Message-ID: high5storage at gmail.com wrote: > I have a list of 163.840 integers. What is a fast & pythonic way to > process this list in 1,280 chunks of 128 integers? What kind of processing do you have in mind? If it is about numbercrunching use a numpy.array. This can also easily change its shape: >>> import numpy >>> a = numpy.array(range(12)) >>> a array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) >>> a.shape = (3, 4) >>> a array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) If it's really only(!) under a million integers slicing is also good: items = [1, 2, ...] CHUNKSIZE = 128 for i in range(0, len(items), CHUNKSIZE): process(items[start:start + CHUNKSIZE]) If the "list" is really huge (your system starts swapping memory) you can go completely lazy: from itertools import chain, islice def chunked(items, chunksize): items = iter(items) for first in items: chunk = chain((first,), islice(items, chunksize-1)) yield chunk for dummy in chunk: # consume items that may have been skipped # by your processing pass def produce_items(file): for line in file: yield int(line) CHUNKSIZE = 128 # this could also be "huge" # without affecting memory footprint with open("somefile") as file: for chunk in chunked(produce_items(file), CHUNKSIZE): process(chunk) From rosuav at gmail.com Thu Jan 7 05:25:31 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jan 2016 21:25:31 +1100 Subject: subprocess check_output In-Reply-To: <87d1td7l3f.fsf@elektro.pacujo.net> References: <20151230210227.GA88234@cskk.homeip.net> <87lh817l73.fsf@elektro.pacujo.net> <87d1td7l3f.fsf@elektro.pacujo.net> Message-ID: On Thu, Jan 7, 2016 at 9:14 PM, Marko Rauhamaa wrote: > Marko Rauhamaa : > >> Chris Angelico : >> >>> you ask the correct question of "why isn't my CSS file being read?" >> >> TL;DR > > Sorry, getting confused with homonyms: > > >>> CSS gurus suggest, along similar lines, changing the background color >>> of something to red. > > Oh. I think that wordplay was _exactly_ why the choice was red, rather than an equally-obvious yellow or green or blue or something. "If the body is red, the file was read". ChrisA From nomail at invalid.com Thu Jan 7 05:36:11 2016 From: nomail at invalid.com (ast) Date: Thu, 7 Jan 2016 11:36:11 +0100 Subject: True/False value testing Message-ID: <568e3fb4$0$659$426a74cc@news.free.fr> Hello For integer, 0 is considered False and any other value True >>> A=0 >>> A==False True >>> A==True False >>> A=1 >>> A==False False >>> A==True True It works fine For string, "" is considered False and any other value True, but it doesn't work >>> A = "" >>> A==False False >>> A==True False >>> A = 'Z' >>> A==False False >>> A==True False What happens ??? thx From __peter__ at web.de Thu Jan 7 05:48:41 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Jan 2016 11:48:41 +0100 Subject: True/False value testing References: <568e3fb4$0$659$426a74cc@news.free.fr> Message-ID: ast wrote: > Hello > > For integer, 0 is considered False and any other value True > >>>> A=0 >>>> A==False > True >>>> A==True > False >>>> A=1 >>>> A==False > False >>>> A==True > True > > It works fine But not the way you think: >>> 0 == False True >>> 1 == True True >>> 2 == True False >>> 2 == False False 0 equals False, 1 equals True, and any other integer equals neither, but "is true in a boolean context", i. e. >>> if 42: print("42 considered true") ... 42 considered true > For string, "" is considered False and any other value True, > but it doesn't work In a similar way there is no string that equals True or False, but the empty string "" is considered false in a boolean context while all other strings are considered true: >>> bool("") False >>> bool("whatever") True >>>> A = "" >>>> A==False > False >>>> A==True > False >>>> A = 'Z' >>>> A==False > False >>>> A==True > False > > > What happens ??? > > thx From rosuav at gmail.com Thu Jan 7 05:49:46 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jan 2016 21:49:46 +1100 Subject: True/False value testing In-Reply-To: <568e3fb4$0$659$426a74cc@news.free.fr> References: <568e3fb4$0$659$426a74cc@news.free.fr> Message-ID: On Thu, Jan 7, 2016 at 9:36 PM, ast wrote: > Hello > > For integer, 0 is considered False and any other value True > >>>> A=0 >>>> A==False > > True >>>> >>>> A==True > > False >>>> >>>> A=1 >>>> A==False > > False >>>> >>>> A==True > > True > > It works fine > > For string, "" is considered False and any other value True, > but it doesn't work > >>>> A = "" >>>> A==False > > False >>>> >>>> A==True > > False >>>> >>>> A = 'Z' >>>> A==False > > False >>>> >>>> A==True > > False > > > What happens ??? > > thx There's a difference between "is considered false" and "is equal to False". In Python, most collections are considered false if they are empty: def truthiness(x): if x: print(repr(x) + " is true") else: print(repr(x) + " is false") truthiness([]) truthiness([1,2,3]) truthiness("") truthiness("hello") truthiness(0) truthiness(73) truthiness({}) truthiness({1:2, 3:4}) However, none of these will compare *equal* to the Boolean values True and False, save for the integers 1 and 0. In fact, True is a special form of the integer 1, and False is a special form of the integer 0; they are considered to represent those numbers just as much as the floating point values 1.0 and 0.0 do: from decimal import Decimal from fractions import Fraction # Caveat, see footnote [1] if Fraction(0, 1) == 0.0 == 0 == False == Decimal("0"): print("See? All representations of zero are equal") Intuition tells you quite obviously that the integers 1 and 73 are not equal, but both of them are very definitely truthy values. In the same way, a non-empty list is truthy, but it's not equal to True. Does that answer your question? ChrisA [1] In Python 2.7, Decimal("0") != Fraction(0, 1). I suspect this is a bug, as it's been fixed in Python 3; both of them are equal to the integer 0, but they're not equal to each other. So the order of checks in that demo is actually significant. From nomail at invalid.com Thu Jan 7 06:11:07 2016 From: nomail at invalid.com (ast) Date: Thu, 7 Jan 2016 12:11:07 +0100 Subject: True/False value testing In-Reply-To: <568e3fb4$0$659$426a74cc@news.free.fr> References: <568e3fb4$0$659$426a74cc@news.free.fr> Message-ID: <568e47db$0$19774$426a74cc@news.free.fr> "ast" a ?crit dans le message de news:568e3fb4$0$659$426a74cc at news.free.fr... Thank you for answers. That's clear now. From marko at pacujo.net Thu Jan 7 06:19:15 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 07 Jan 2016 13:19:15 +0200 Subject: True/False value testing References: <568e3fb4$0$659$426a74cc@news.free.fr> Message-ID: <877fjl7i30.fsf@elektro.pacujo.net> Chris Angelico : > However, none of these will compare *equal* to the Boolean values True > and False, save for the integers 1 and 0. In fact, True is a special > form of the integer 1, and False is a special form of the integer 0; Stirring the pot: >>> (2 < 3) is True True but is that guaranteed? Marko From rosuav at gmail.com Thu Jan 7 06:50:28 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jan 2016 22:50:28 +1100 Subject: True/False value testing In-Reply-To: <877fjl7i30.fsf@elektro.pacujo.net> References: <568e3fb4$0$659$426a74cc@news.free.fr> <877fjl7i30.fsf@elektro.pacujo.net> Message-ID: On Thu, Jan 7, 2016 at 10:19 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> However, none of these will compare *equal* to the Boolean values True >> and False, save for the integers 1 and 0. In fact, True is a special >> form of the integer 1, and False is a special form of the integer 0; > > Stirring the pot: > > >>> (2 < 3) is True > True > > but is that guaranteed? Yes. When you do comparisons involving integers, the result is an actual boolean value - not just a truthy value, but the exact value True or False. Those values, being singletons (or a doubleton, or whatever you want to call it), will always be the same objects, ergo the "is True" part must always pass. However, if arbitrary objects are thrown into the mix, the guarantee doesn't hold. Here's one way of implementing a "sticky NaN" that infects all operations: class NaN: def __lt__(self, other): return self __gt__ = __ge__ = __le__ = __lt__ def __eq__(self, other): return False def __ne__(self, other): return True def __new__(cls): if not hasattr(cls, "_inst"): cls._inst = super().__new__(cls) return cls._inst def __repr__(self): return "NaN" NaN = NaN() And it looks something like this: >>> NaN < 1 NaN >>> 1 < NaN NaN >>> NaN > 1 NaN >>> 1 > NaN NaN >>> NaN == NaN False Similarly, numpy arrays overload operators to perform elementwise comparisons: >>> import numpy >>> numpy.array(range(10)) array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> _ < 5 array([ True, True, True, True, True, False, False, False, False, False], dtype=bool) But with integers, and with most other built-in types, the comparison operators are indeed guaranteed to return either True or False. ChrisA From marko at pacujo.net Thu Jan 7 07:07:26 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 07 Jan 2016 14:07:26 +0200 Subject: True/False value testing References: <568e3fb4$0$659$426a74cc@news.free.fr> <877fjl7i30.fsf@elektro.pacujo.net> Message-ID: <871t9t7fup.fsf@elektro.pacujo.net> Chris Angelico : >> Stirring the pot: >> >> >>> (2 < 3) is True >> True >> >> but is that guaranteed? > > Yes. When you do comparisons involving integers, the result is an > actual boolean value - not just a truthy value, but the exact value > True or False. I couldn't locate that bold statement in the language spec (see ). However, I *could* find this statement: 1. [or] is a short-circuit operator, so it only evaluates the second argument if the first one is False. 2. [and] is a short-circuit operator, so it only evaluates the second argument if the first one is True. The wording is very unfortunate (both the use of the word "is" and the explicit references to the builtin constants False and True). Marko From rosuav at gmail.com Thu Jan 7 07:38:16 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jan 2016 23:38:16 +1100 Subject: True/False value testing In-Reply-To: <871t9t7fup.fsf@elektro.pacujo.net> References: <568e3fb4$0$659$426a74cc@news.free.fr> <877fjl7i30.fsf@elektro.pacujo.net> <871t9t7fup.fsf@elektro.pacujo.net> Message-ID: On Thu, Jan 7, 2016 at 11:07 PM, Marko Rauhamaa wrote: > However, I *could* find this statement: > > 1. [or] is a short-circuit operator, so it only evaluates the second > argument if the first one is False. > > 2. [and] is a short-circuit operator, so it only evaluates the second > argument if the first one is True. > > erations-and-or-not> > > The wording is very unfortunate (both the use of the word "is" and the > explicit references to the builtin constants False and True). Actually, that's a good point. I would call that a docs error. The definition of the comparison operators is, more or less: 1) Call a.__lt__(b). If it doesn't return NotImplemented, that's the value. 2) Call b.__gt__(a). If it doesn't return NotImplemented, that's the value. 3) Raise TypeError. Massively simplified; steps 1 and 2 get switched around if b is a subclass of a, and there's stuff about slots, and so on. But that's basically it. The function is allowed to return anything it likes. The built-in types generally return instances of bool, but custom classes are free to generalize (as numpy has done to great effect). ChrisA From rosuav at gmail.com Thu Jan 7 08:35:20 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jan 2016 00:35:20 +1100 Subject: A newbie's doubt In-Reply-To: References: Message-ID: On Thu, Jan 7, 2016 at 2:20 PM, Henrique Correa wrote: > Is Python's Tutorial (by Guido) a good and complete reference for the > language? I mean, after reading it, should I have a good basis on Python? > > I've came from js and php, and already know the very basics of py. > > Thank you! If by "good and complete" you mean "enough to write code in", then yes, I would say it is. If you mean "enough to write applications that you can sell for money", then it's probably insufficient; you'll want to also learn a few libraries, possibly including third-party ones like Flask/Django (to write web applications) or numpy/pandas (to write computational code) or matplotlib (to crunch numbers and make graphs). If, on the other hand, you mean "enough to understand how Python works internally", then no, it's not. It's not meant to go into that kind of detail. But you don't need to know that anyway. I would recommend going through that tutorial. You'll get a decent handle on how Python works. As a general rule, Python's object model is similar to what you'll know from JS; the scoping rules are different (instead of "var x;" to declare that x is local, you would have "global x" to declare that x is global - but you need declare only those globals that you assign to, not those you reference). As you go through it, write down some notes of everything that interests or confuses you; once you've completed the tutorial, go through your notes again. Some of what you've written down will now make perfect sense, and you can delete it; some will still confuse you, but you'll understand more of *why* it confuses you. So then you come back here to python-list with the bits that confuse you, and we'll be happy to explain stuff! ChrisA From oscar.j.benjamin at gmail.com Thu Jan 7 10:19:28 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 7 Jan 2016 15:19:28 +0000 Subject: How to union nested Sets / A single set from nested sets? In-Reply-To: <568e23e5$0$1590$c3e8da3$5496439d@news.astraweb.com> References: <568e23e5$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 7 January 2016 at 08:37, Steven D'Aprano wrote: > On Thu, 7 Jan 2016 01:45 am, Oscar Benjamin wrote: > >> On 4 January 2016 at 02:40, mviljamaa wrote: >>> I'm forming sets by set.adding to sets and this leads to sets such as: >>> >>> Set([ImmutableSet(['a', ImmutableSet(['a'])]), ImmutableSet(['b', 'c'])]) >>> >>> Is there way union these to a single set, i.e. get >>> >>> Set(['a', 'b', 'c']) >> >> Where are you getting Set and ImmutableSet from? Is that sympy or >> something? > > Set and ImmutableSet were the original versions from Python 2.3 before the > builtins. They're still available up to Python 2.7 (gone in 3): > > > py> import sets > py> sets.Set > > > but that's just for backwards compatibility, you should use the built-in > versions if you can. Okay, thanks Steve. Then I translate the OP's problem as how to go from S = set([frozenset(['a', frozenset(['a'])]), frozenset(['b', 'c'])]) to set(['a', 'b', 'c']) This is not just a union of the elements of the set since: In [7]: {x for fs in S for x in fs} Out[7]: set(['a', 'c', 'b', frozenset(['a'])]) The reason for this is that there are multiple levels of nesting. I assume that the OP wants to recursively get all the elements from all the nested sets and create a set out of those. Here's a breadth-first search that can do that: def flat_nested(tree): flat = set() stack = [iter(tree)] while stack: branch = stack.pop(0) for x in branch: if isinstance(x, frozenset): stack.append(iter(x)) else: flat.add(x) return flat And now: In [15]: flat_nested(S) Out[15]: set(['a', 'c', 'b']) -- Oscar From SSaini at creditvalleyca.ca Thu Jan 7 10:36:34 2016 From: SSaini at creditvalleyca.ca (Saini, Sakshi) Date: Thu, 7 Jan 2016 10:36:34 -0500 Subject: graphs Message-ID: I have a complex dataset and I wish to write a code to create different graphs from it. I was wondering if it is possible for Python/ matplotlib/ seaborn to return a cumulative or mean distribution bar graph based on values in your dataset? E.g. I have a certain volume in m3 for each rainfall event in mm, and I wish to plot the total volume OR average volume for different rainfall depths; somewhat like the following: [cid:image002.jpg at 01D14937.476CB2F0] Any tips please? Sakshi Saini, BASc, EIT Water Resources Project Coordinator | Credit Valley Conservation The information contained in this Credit Valley Conservation electronic message is directed in confidence solely to the person(s) named above and may not be otherwise distributed, copied or disclosed including attachments. The message may contain information that is privileged, confidential and exempt from disclosure under the Municipal Freedom of Information and Protection and Privacy Act and by the Personal Information Protection Electronic Documents Act. The use of such personal information except in compliance with the Acts, is strictly prohibited. If you have received this message in error, please notify the sender immediately advising of the error and delete the message without making a copy. Thank you. From jfoxrabinovitz at gmail.com Thu Jan 7 11:14:10 2016 From: jfoxrabinovitz at gmail.com (Joseph Fox-Rabinovitz) Date: Thu, 7 Jan 2016 11:14:10 -0500 Subject: Unable to access module attribute with underscores in class method, Python 3 Message-ID: Hi, I have a module attribute whose name starts with a pair of underscores. I am apparently unable to access it directly in a class method (within the same module, but that is not relevant as far as I can tell). The following bit of code illustrates the situation: __a = 3 class B: def __init__(self): global __a self.a = __a b = B() This results in a NameError because of name-mangling, despite the global declaration: Traceback (most recent call last): File "", line 1, in File "", line 4, in __init__ NameError: name '_B__a' is not defined Not using global does not make a difference. I posted a similar question on Stack Overflow, where the only reasonable answer given was to wrap __a in a container whose name is not mangled. For example, doing `self.a = globals()['__a']` or manually creating a dictionary with a non-mangled name and accessing that. I feel that there should be some way of accessing __a within the class directly in Python 3. Clearly my expectation that global would fix the issue is incorrect. I would appreciate either a solution or an explanation of what is going on that would convince me that accessing a module attribute in such a way should be forbidden. -Joseph Fox-Rabinovitz P.S. For reference, the Stack Overflow question is here: http://stackoverflow.com/questions/34621484/how-to-access-private-variable-of-python-module-from-class From darren.mcaffee at gmail.com Thu Jan 7 11:23:08 2016 From: darren.mcaffee at gmail.com (darren.mcaffee at gmail.com) Date: Thu, 7 Jan 2016 08:23:08 -0800 (PST) Subject: imshow keeps crashhing In-Reply-To: References: Message-ID: I think I figured out the real problem, you can see my post here: http://stackoverflow.com/questions/34645512/scipy-imshow-conflict-with-el-capitan-sip-and-var-folders/34646093#34646093 Thanks again for helping to guide me in the right direction. From random832 at fastmail.com Thu Jan 7 11:45:28 2016 From: random832 at fastmail.com (Random832) Date: Thu, 07 Jan 2016 11:45:28 -0500 Subject: imshow keeps crashhing In-Reply-To: References: Message-ID: <1452185128.1146562.485645538.0F24DD02@webmail.messagingengine.com> On Wed, Jan 6, 2016, at 18:26, John Gordon wrote: > So the actual command name for running Preview is "open"? "open" is an OSX command that will open a file by whatever application is associated with it (same as if you double clicked it in Finder); similar to "start" on Windows. From random832 at fastmail.com Thu Jan 7 11:49:11 2016 From: random832 at fastmail.com (Random832) Date: Thu, 07 Jan 2016 11:49:11 -0500 Subject: imshow keeps crashhing In-Reply-To: <95A41665-B3B1-4DDC-AFB8-9AD186EAD6C5@mac.com> References: <95A41665-B3B1-4DDC-AFB8-9AD186EAD6C5@mac.com> Message-ID: <1452185351.1147500.485647754.3BD0D59A@webmail.messagingengine.com> On Wed, Jan 6, 2016, at 18:37, William Ray Wing wrote: > Is this a typo or did you really mean /private/vars? That is, did your > create a ?vars? directory under /private at some point in the past > (pre-Yosemite)? The usual directory there would be /var > > In any case, the whole /private directory tree is now part of the SIP > (System Integrity Protection) system under Yosemite, and to open and > manipulate files there you will have to either turn SIP off or jump > through hoops. If you do a ls -al in /private, you will see that var is /private/var/folders/...... is for per-user temporary directories [default value of TMPDIR], and the directories in question are writable by the users and not affected by SIP. But it's hidden (since people aren't expected to actually want to navigate to their temporary files - how often do you actually go look for something in /tmp?). I would suggest creating his files in the desktop or documents folder if he wants to be able to interactively use the files. From rxjwg98 at gmail.com Thu Jan 7 11:50:29 2016 From: rxjwg98 at gmail.com (Robert) Date: Thu, 7 Jan 2016 08:50:29 -0800 (PST) Subject: What meaning is 'from . import' Message-ID: <5cc5c4f2-ecc9-4ae4-b2d4-92a234012ae7@googlegroups.com> Hi, I see the following code. After searching around, I still don't know the meaning of '.'. Could you tell me that ? Thanks, from . import _hmmc from .utils import normalize From rosuav at gmail.com Thu Jan 7 12:00:06 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jan 2016 04:00:06 +1100 Subject: What meaning is 'from . import' In-Reply-To: <5cc5c4f2-ecc9-4ae4-b2d4-92a234012ae7@googlegroups.com> References: <5cc5c4f2-ecc9-4ae4-b2d4-92a234012ae7@googlegroups.com> Message-ID: On Fri, Jan 8, 2016 at 3:50 AM, Robert wrote: > Hi, > > I see the following code. After searching around, I still don't know the > meaning of '.'. Could you tell me that ? Thanks, > > > > > > from . import _hmmc > from .utils import normalize That's called a package-relative import. https://www.python.org/dev/peps/pep-0328/ If you create a package called (let's be really creative here) "package", an external script could do this: from package import _hmmc from package.utils import normalize Within the package, you can say "from myself import stuff". It's exactly the same thing, only it doesn't repeat the package name. If you think of a package as a directory (which it often will be anyway), the dot is similar to the common notation for "current directory". ChrisA From rxjwg98 at gmail.com Thu Jan 7 12:23:56 2016 From: rxjwg98 at gmail.com (Robert) Date: Thu, 7 Jan 2016 09:23:56 -0800 (PST) Subject: Question about a class member Message-ID: Hi, I am using a download package. When I read its code, see below please, I don't know what 'sample' is: ---------- model = hmm.GaussianHMM(n_components=4, covariance_type="full") model.startprob_ = startprob model.transmat_ = transmat model.means_ = means model.covars_ = covars # Generate samples X, Z = model.sample(50) ------------- When I read its (class) definition, I find the following part (which may not be sure 100% the above origination yet, but it is the only line being 'sample'). ////////////// self.gmms_ = [] for x in range(self.n_components): if covariance_type is None: gmm = GMM(n_mix) else: gmm = GMM(n_mix, covariance_type=covariance_type) self.gmms_.append(gmm) def _init(self, X, lengths=None): super(GMMHMM, self)._init(X, lengths=lengths) for g in self.gmms_: g.set_params(init_params=self.init_params, n_iter=0) g.fit(X) def _compute_log_likelihood(self, X): return np.array([g.score(X) for g in self.gmms_]).T def _generate_sample_from_state(self, state, random_state=None): return self.gmms_[state].sample(1, random_state=random_state).flatten() //////////// The above code looks like self.gmms is a list, which has an attribute 'sample'. But when I play with a list, there is no 'sample' attribute. .......... a=[1, 32.0, 4] a Out[68]: [1, 32.0, 4] type(a) Out[69]: list a[0].sample(1,5) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) in () ----> 1 a[0].sample(1,5) AttributeError: 'int' object has no attribute 'sample' a[1].sample(1,5) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) in () ----> 1 a[1].sample(1,5) AttributeError: 'float' object has no attribute 'sample' //////////// What is 'sample' do you think? Thanks, From jfoxrabinovitz at gmail.com Thu Jan 7 12:33:25 2016 From: jfoxrabinovitz at gmail.com (Joseph Fox-Rabinovitz) Date: Thu, 7 Jan 2016 12:33:25 -0500 Subject: Unable to access module attribute with underscores in class method, Python 3 In-Reply-To: References: Message-ID: > On Thu, Jan 7, 2016 at 11:14 AM, Joseph Fox-Rabinovitz wrote: > > Hi, > > I have a module attribute whose name starts with a pair of underscores. I am apparently unable to access it directly in a class method (within the same module, but that is not relevant as far as I can tell). The following bit of code illustrates the situation: > > __a = 3 > class B: > def __init__(self): > global __a > self.a = __a > b = B() > > This results in a NameError because of name-mangling, despite the global declaration: > > Traceback (most recent call last): > File "", line 1, in > File "", line 4, in __init__ > NameError: name '_B__a' is not defined > > Not using global does not make a difference. I posted a similar question on Stack Overflow, where the only reasonable answer given was to wrap __a in a container whose name is not mangled. For example, doing `self.a = globals()['__a']` or manually creating a dictionary with a non-mangled name and accessing that. > > I feel that there should be some way of accessing __a within the class directly in Python 3. Clearly my expectation that global would fix the issue is incorrect. I would appreciate either a solution or an explanation of what is going on that would convince me that accessing a module attribute in such a way should be forbidden. > > -Joseph Fox-Rabinovitz > > P.S. For reference, the Stack Overflow question is here: http://stackoverflow.com/questions/34621484/how-to-access-private-variable-of-python-module-from-class One more detail that makes me think that name mangling may be getting greedy to the point of bugginess: __a = 3 class B: def __init__(self): m = sys.modules[__name__] self.a = m.__a b = B() Raises the same exception as all the other way I tried to access __a: 'module' object has no attribute '_B__a'! -Joseph From rxjwg98 at gmail.com Thu Jan 7 12:39:17 2016 From: rxjwg98 at gmail.com (Robert) Date: Thu, 7 Jan 2016 09:39:17 -0800 (PST) Subject: Question about a class member In-Reply-To: References: Message-ID: <106d3b9b-a9ba-4c9e-abe8-ae06381b6bd2@googlegroups.com> On Thursday, January 7, 2016 at 12:24:53 PM UTC-5, Robert wrote: > Hi, > > I am using a download package. When I read its code, see below please, I > don't know what 'sample' is: > > > ---------- > model = hmm.GaussianHMM(n_components=4, covariance_type="full") > > model.startprob_ = startprob > model.transmat_ = transmat > model.means_ = means > model.covars_ = covars > > # Generate samples > X, Z = model.sample(50) > ------------- > > When I read its (class) definition, I find the following part (which may not > be sure 100% the above origination yet, but it is the only line being > 'sample'). > ////////////// > self.gmms_ = [] > for x in range(self.n_components): > if covariance_type is None: > gmm = GMM(n_mix) > else: > gmm = GMM(n_mix, covariance_type=covariance_type) > self.gmms_.append(gmm) > > def _init(self, X, lengths=None): > super(GMMHMM, self)._init(X, lengths=lengths) > > for g in self.gmms_: > g.set_params(init_params=self.init_params, n_iter=0) > g.fit(X) > > def _compute_log_likelihood(self, X): > return np.array([g.score(X) for g in self.gmms_]).T > > def _generate_sample_from_state(self, state, random_state=None): > return self.gmms_[state].sample(1, random_state=random_state).flatten() > //////////// > > The above code looks like self.gmms is a list, which has an attribute > 'sample'. But when I play with a list, there is no 'sample' attribute. > > .......... > a=[1, 32.0, 4] > > a > Out[68]: [1, 32.0, 4] > > type(a) > Out[69]: list > > a[0].sample(1,5) > --------------------------------------------------------------------------- > AttributeError Traceback (most recent call last) > in () > ----> 1 a[0].sample(1,5) > > AttributeError: 'int' object has no attribute 'sample' > > a[1].sample(1,5) > --------------------------------------------------------------------------- > AttributeError Traceback (most recent call last) > in () > ----> 1 a[1].sample(1,5) > > AttributeError: 'float' object has no attribute 'sample' > //////////// > > What is 'sample' do you think? > > Thanks, The code can be downloaded from: https://github.com/hmmlearn/hmmlearn/blob/master/examples/plot_hmm_sampling.py Hope it can help to answer my question. Thanks again. From gordon at panix.com Thu Jan 7 13:37:45 2016 From: gordon at panix.com (John Gordon) Date: Thu, 7 Jan 2016 18:37:45 +0000 (UTC) Subject: Question about a class member References: Message-ID: In Robert writes: > I am using a download package. When I read its code, see below please, I > don't know what 'sample' is: > ---------- > model = hmm.GaussianHMM(n_components=4, covariance_type="full") > model.startprob_ = startprob > model.transmat_ = transmat > model.means_ = means > model.covars_ = covars > # Generate samples > X, Z = model.sample(50) > ------------- sample() is a method in the GaussianHMM class. (In this case, it's a method in the _BaseHMM class, from which GaussianHMM inherits.) -- 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 ian.g.kelly at gmail.com Thu Jan 7 13:38:52 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 7 Jan 2016 11:38:52 -0700 Subject: Question about a class member In-Reply-To: References: Message-ID: On Thu, Jan 7, 2016 at 10:23 AM, Robert wrote: > When I read its (class) definition, I find the following part (which may not > be sure 100% the above origination yet, but it is the only line being > 'sample'). > ////////////// > self.gmms_ = [] > for x in range(self.n_components): > if covariance_type is None: > gmm = GMM(n_mix) > else: > gmm = GMM(n_mix, covariance_type=covariance_type) > self.gmms_.append(gmm) self.gmms_ is a list. The contents of the list are instances of the GMM class, which I can't tell you anything about because it isn't reproduced in your message. > def _generate_sample_from_state(self, state, random_state=None): > return self.gmms_[state].sample(1, random_state=random_state).flatten() > //////////// > > The above code looks like self.gmms is a list, which has an attribute > 'sample'. But when I play with a list, there is no 'sample' attribute. self.gmms_[state] refers to a particular element of the list, which per the above should be an instance of the GMM class. The sample method would be part of the GMM class. > .......... > a=[1, 32.0, 4] > > a > Out[68]: [1, 32.0, 4] > > type(a) > Out[69]: list > > a[0].sample(1,5) > --------------------------------------------------------------------------- > AttributeError Traceback (most recent call last) > in () > ----> 1 a[0].sample(1,5) > > AttributeError: 'int' object has no attribute 'sample' Because you're playing with a list of ints and floats, not GMMs. From v+python at g.nevcal.com Thu Jan 7 13:55:38 2016 From: v+python at g.nevcal.com (Glenn Linderman) Date: Thu, 7 Jan 2016 10:55:38 -0800 Subject: EOFError: marshal data too short -- causes? In-Reply-To: <568441DA.9000107@g.nevcal.com> References: <56822D4F.8070309@g.nevcal.com> <56823DBC.9010205@g.nevcal.com> <568441DA.9000107@g.nevcal.com> Message-ID: <568EB4AA.4020705@g.nevcal.com> On 12/30/2015 12:43 PM, Glenn Linderman wrote: > On 12/29/2015 1:00 PM, Terry Reedy wrote: >> I updated to 2.7.11, 3.4.4, and 3.5.1 a couple of weeks ago, so the >> timestamps are all fresh. So I don't know what happened with 3.4.3 >> timestamps from last April and whether Windows itself touches the >> files. I just tried importing a few and Python did not. > > I'm a Windows user, too, generally, but the web host runs Linux. > > I suppose, since the install does the compileall, that I could set all > the __pycache__ files to read-only, even for "owner". Like you said, > those files _can't_ be updated without Admin/root permission when it > is a root install... so there would be no need, once compileall has > been done, for the files to be updated until patches would be > applied. This isn't a root install, though, but a "user" install. > > Level1 support at the web host claims they never touch user files > unless the user calls and asks them to help with something that > requires it. And maybe Level1 support religiously follows that policy, > but other files have changed, so that policy doesn't appear to be > universally applied for all personnel there... so the answer isn't > really responsive to the question, but the tech I talked to was as > much a parrot as a tech... > > Glenn So this morning the problem happens again. 48 files or directories modified at 5:47am, while I'm sound asleep so the web site is down for over 3 hours until I wake up and notice (both because my bootup process always checks, and because I had several emails about it). 2 of the files had the suspicious 4096 EOF, and deleting the first caused it to be rebuilt and the second to be noticed, and deleting the second caused it to be rebuilt and cured the site. But all the touched files are .pyc files (and the directories __pycache__ directories). None of the source files were modified. So why would any .pyc files ever be updated if the source files are not? Are there _any_ Python-specific reasons? My only speculation is a problem accessing the .pyc file on first attempt, which would be a file system problem, not a Python problem? Are there other speculative reasons? And then why would a short file be built? Conflict with multiple processes trying to rebuild it at the same time? Or another file system problem? Or??? This-could-be-annoying-if-it-keeps-happening-ly yours, Glenn From steve at pearwood.info Thu Jan 7 17:05:15 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 08 Jan 2016 09:05:15 +1100 Subject: Question about a class member References: Message-ID: <568ee11c$0$1596$c3e8da3$5496439d@news.astraweb.com> On Fri, 8 Jan 2016 04:23 am, Robert wrote: > Hi, > > I am using a download package. When I read its code, see below please, I > don't know what 'sample' is: > > > ---------- > model = hmm.GaussianHMM(n_components=4, covariance_type="full") When I try running that code, I get an error: py> model = hmm.GaussianHMM(n_components=4, covariance_type="full") Traceback (most recent call last): File "", line 1, in NameError: name 'hmm' is not defined What's hmm? Where does it come from? Is it this? https://hmmlearn.github.io/hmmlearn/generated/hmmlearn.hmm.GaussianHMM.html It has a sample method here: https://hmmlearn.github.io/hmmlearn/generated/hmmlearn.hmm.GaussianHMM.html#hmmlearn.hmm.GaussianHMM.sample You should try googling for help before asking questions: https://duckduckgo.com/html/?q=hmm.GaussianHMM or use the search engine of your choice. -- Steven From srkunze at mail.de Thu Jan 7 17:52:48 2016 From: srkunze at mail.de (Sven R. Kunze) Date: Thu, 7 Jan 2016 23:52:48 +0100 Subject: How to remove item from heap efficiently? Message-ID: <568EEC40.7070807@mail.de> Hi everybody, suppose, I need items sorted by two criteria (say timestamp and priority). For that purpose, I use two heaps (heapq module): heapA # items sorted by timestamp heapB # items sorted by priority Now my actual problem. When popping an item of heapA (that's the oldest item), I need to remove the very same item from heapB, regardlessly where it is in heapB. And vice versa. Is there a datastructure or a simple trick to achieve that in an efficient matter? Best, Sven From rxjwg98 at gmail.com Thu Jan 7 18:02:58 2016 From: rxjwg98 at gmail.com (Robert) Date: Thu, 7 Jan 2016 15:02:58 -0800 (PST) Subject: Question about a class member In-Reply-To: <568ee11c$0$1596$c3e8da3$5496439d@news.astraweb.com> References: <568ee11c$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, January 7, 2016 at 5:06:07 PM UTC-5, Steven D'Aprano wrote: > On Fri, 8 Jan 2016 04:23 am, Robert wrote: > > > Hi, > > > > I am using a download package. When I read its code, see below please, I > > don't know what 'sample' is: > > > > > > ---------- > > model = hmm.GaussianHMM(n_components=4, covariance_type="full") > > > When I try running that code, I get an error: > > > py> model = hmm.GaussianHMM(n_components=4, covariance_type="full") > Traceback (most recent call last): > File "", line 1, in > NameError: name 'hmm' is not defined > > What's hmm? Where does it come from? Is it this? > > https://hmmlearn.github.io/hmmlearn/generated/hmmlearn.hmm.GaussianHMM.html > > It has a sample method here: > > https://hmmlearn.github.io/hmmlearn/generated/hmmlearn.hmm.GaussianHMM.html#hmmlearn.hmm.GaussianHMM.sample > > > You should try googling for help before asking questions: > > https://duckduckgo.com/html/?q=hmm.GaussianHMM > > or use the search engine of your choice. > > > -- > Steven Thanks. I just realized that my list assumption was wrong. I got that conclusion was incorrect. From phpro.ir at gmail.com Thu Jan 7 18:08:24 2016 From: phpro.ir at gmail.com (Saeed Moqadam) Date: Thu, 7 Jan 2016 15:08:24 -0800 (PST) Subject: PyFladesk :: create GUI apps by Python and HTML, CSS and Javascript. Message-ID: <23384de9-7909-41e8-8a63-ebadb583bf84@googlegroups.com> create multi platform desktop application by using Python, HTML, CSS and Javascript. source code is https://github.com/smoqadam/PyFladesk you can find RSS Reader app that made by PyFladesk in the following url : https://github.com/smoqadam/PyFladesk-rss-reader I'll waiting for your feedback. thanks From aaron.christensen at gmail.com Thu Jan 7 18:57:18 2016 From: aaron.christensen at gmail.com (Aaron Christensen) Date: Thu, 7 Jan 2016 16:57:18 -0700 Subject: A newbie's doubt In-Reply-To: References: Message-ID: That's an awesome response! On Jan 7, 2016 6:35 AM, "Chris Angelico" wrote: > On Thu, Jan 7, 2016 at 2:20 PM, Henrique Correa wrote: > > Is Python's Tutorial (by Guido) a good and complete reference for the > > language? I mean, after reading it, should I have a good basis on Python? > > > > I've came from js and php, and already know the very basics of py. > > > > Thank you! > > If by "good and complete" you mean "enough to write code in", then > yes, I would say it is. > > If you mean "enough to write applications that you can sell for > money", then it's probably insufficient; you'll want to also learn a > few libraries, possibly including third-party ones like Flask/Django > (to write web applications) or numpy/pandas (to write computational > code) or matplotlib (to crunch numbers and make graphs). > > If, on the other hand, you mean "enough to understand how Python works > internally", then no, it's not. It's not meant to go into that kind of > detail. But you don't need to know that anyway. > > I would recommend going through that tutorial. You'll get a decent > handle on how Python works. As a general rule, Python's object model > is similar to what you'll know from JS; the scoping rules are > different (instead of "var x;" to declare that x is local, you would > have "global x" to declare that x is global - but you need declare > only those globals that you assign to, not those you reference). As > you go through it, write down some notes of everything that interests > or confuses you; once you've completed the tutorial, go through your > notes again. Some of what you've written down will now make perfect > sense, and you can delete it; some will still confuse you, but you'll > understand more of *why* it confuses you. So then you come back here > to python-list with the bits that confuse you, and we'll be happy to > explain stuff! > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From kai.peters at gmail.com Thu Jan 7 19:33:41 2016 From: kai.peters at gmail.com (KP) Date: Thu, 7 Jan 2016 16:33:41 -0800 (PST) Subject: Fast pythonic way to process a huge integer list In-Reply-To: <7e2b93e4-c224-40c4-8e88-7dcc847edab1@googlegroups.com> References: <7e2b93e4-c224-40c4-8e88-7dcc847edab1@googlegroups.com> Message-ID: <17e513e2-fb15-47ba-8606-97b8a1b904ef@googlegroups.com> On Wednesday, 6 January 2016 18:37:22 UTC-8, high5s... at gmail.com wrote: > I have a list of 163.840 integers. What is a fast & pythonic way to process this list in 1,280 chunks of 128 integers? Thanks all for your valuable input - much appreciated! From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Thu Jan 7 20:38:45 2016 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Fri, 8 Jan 2016 01:38:45 +0000 Subject: A newbie's doubt References: Message-ID: ?s 03:20 de 07-01-2016, Henrique Correa escreveu: > Is Python's Tutorial (by Guido) a good and complete reference for the > language? Good yes. Complete no. I mean, after reading it, should I have a good basis on Python? Yes if you know how to program on another language. > HTH Paulo From jacob at blindza.co.za Thu Jan 7 22:54:45 2016 From: jacob at blindza.co.za (jacob Kruger) Date: Fri, 8 Jan 2016 05:54:45 +0200 Subject: PyFladesk :: create GUI apps by Python and HTML, CSS and Javascript. In-Reply-To: <23384de9-7909-41e8-8a63-ebadb583bf84@googlegroups.com> References: <23384de9-7909-41e8-8a63-ebadb583bf84@googlegroups.com> Message-ID: <568F3305.9080404@blindza.co.za> I would definitely like to try out something like this - I am primarily a web developer, and, partly since am 100% blind, any form of GUI design is at times an issue for me, whereas I have been working with HTML markup layouts for almost 20 years now, but, which versions of python should this work with, and, what does it actually then use to generate/handle GUI interface? Ask since, some of the GUI frameworks are not too accessible themselves. Also, downloaded both the main master, and the RSS reader master images, but, both python 2.7 and python 3.4 tell me that they have no urllib2, and under 3.4, pip install can't find it either..? TIA Jacob Kruger Blind Biker Skype: BlindZA "Roger Wilco wants to welcome you...to the space janitor's closet..." On 2016-01-08 1:08 AM, Saeed Moqadam wrote: > create multi platform desktop application by using Python, HTML, CSS and Javascript. > source code is https://github.com/smoqadam/PyFladesk > > you can find RSS Reader app that made by PyFladesk in the following url : > > https://github.com/smoqadam/PyFladesk-rss-reader > > I'll waiting for your feedback. > > thanks From davorinbajic at gmail.com Thu Jan 7 23:12:46 2016 From: davorinbajic at gmail.com (Davorin Bajic) Date: Thu, 7 Jan 2016 20:12:46 -0800 (PST) Subject: SUM only of positive numbers from array Message-ID: <50beb098-f854-4b17-b157-1be075d91f4d@googlegroups.com> Hi All, I should help... I want to calculate the sum of a positive number, for each row: x = ((mat_1 / s_1T)-(s_2 / total)) y = (np.sum(x > 0, axis=1)).reshape(-1, 1).tolist() However, this part of the code only calculation count, I need sum. Any ideas how to solve this problem? thanks in advance From mafagafogigante at gmail.com Fri Jan 8 00:07:34 2016 From: mafagafogigante at gmail.com (Bernardo Sulzbach) Date: Fri, 8 Jan 2016 03:07:34 -0200 Subject: PyFladesk :: create GUI apps by Python and HTML, CSS and Javascript. In-Reply-To: <568F3305.9080404@blindza.co.za> References: <23384de9-7909-41e8-8a63-ebadb583bf84@googlegroups.com> <568F3305.9080404@blindza.co.za> Message-ID: On Fri, Jan 8, 2016 at 1:54 AM, jacob Kruger wrote: > > Also, downloaded both the main master, and the RSS reader master images, > but, both python 2.7 and python 3.4 tell me that they have no urllib2, and > under 3.4, pip install can't find it either..? > > TIA > Python 3 does not have urllib2. It is a Python 2 module that has been split across several modules in Python 3. However, are you sure you tried it with Python 2.7? -- Bernardo Sulzbach From jacob at blindza.co.za Fri Jan 8 01:07:59 2016 From: jacob at blindza.co.za (jacob Kruger) Date: Fri, 8 Jan 2016 08:07:59 +0200 Subject: PyFladesk :: create GUI apps by Python and HTML, CSS and Javascript. In-Reply-To: References: <23384de9-7909-41e8-8a63-ebadb583bf84@googlegroups.com> <568F3305.9080404@blindza.co.za> Message-ID: <568F523F.5000002@blindza.co.za> Ok, double-checked again, and if force it to run under 2.7, then it complains about lack of pyQT4 - that's one of the issues was asking about relating to GUI frameworks - pyQT hasn't always worked too well under 2.7 in terms of accessibility API's in past, but, will 'see' if can get hold of that module for 2.7, and take it from there. Jacob Kruger Blind Biker Skype: BlindZA "Roger Wilco wants to welcome you...to the space janitor's closet..." On 2016-01-08 7:07 AM, Bernardo Sulzbach wrote: > On Fri, Jan 8, 2016 at 1:54 AM, jacob Kruger wrote: >> Also, downloaded both the main master, and the RSS reader master images, >> but, both python 2.7 and python 3.4 tell me that they have no urllib2, and >> under 3.4, pip install can't find it either..? >> >> TIA >> > Python 3 does not have urllib2. It is a Python 2 module that has been > split across several modules in Python 3. > > However, are you sure you tried it with Python 2.7? > From framstag at rus.uni-stuttgart.de Fri Jan 8 02:44:57 2016 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Fri, 8 Jan 2016 07:44:57 +0000 (UTC) Subject: extract script from executable made by pyinstaller? Message-ID: Is it possible to extract (and view) the Python script from the Windows executable which was made by pyinstller? -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From __peter__ at web.de Fri Jan 8 03:17:42 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 08 Jan 2016 09:17:42 +0100 Subject: SUM only of positive numbers from array References: <50beb098-f854-4b17-b157-1be075d91f4d@googlegroups.com> Message-ID: Davorin Bajic wrote: > Hi All, > > I should help... > > I want to calculate the sum of a positive number, for each row: > > > x = ((mat_1 / s_1T)-(s_2 / total)) > y = (np.sum(x > 0, axis=1)).reshape(-1, 1).tolist() > > However, this part of the code only calculation count, I need sum. > > Any ideas how to solve this problem? Use x>0 as "index": >>> import numpy >>> x = numpy.array([1, -2, 3]) >>> x>0 array([ True, False, True], dtype=bool) >>> x[x>0] array([1, 3]) >>> x[x>0].sum() 4 From rosuav at gmail.com Fri Jan 8 03:36:11 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jan 2016 19:36:11 +1100 Subject: extract script from executable made by pyinstaller? In-Reply-To: References: Message-ID: On Fri, Jan 8, 2016 at 6:44 PM, Ulli Horlacher wrote: > Is it possible to extract (and view) the Python script from the Windows > executable which was made by pyinstller? To some extent, yes. You might only get the .pyc files, rather than the proper source code, but you should be able to get something that will run on any system. ChrisA From wxjmfauth at gmail.com Fri Jan 8 04:50:39 2016 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 8 Jan 2016 01:50:39 -0800 (PST) Subject: PyFladesk :: create GUI apps by Python and HTML, CSS and Javascript. In-Reply-To: <23384de9-7909-41e8-8a63-ebadb583bf84@googlegroups.com> References: <23384de9-7909-41e8-8a63-ebadb583bf84@googlegroups.com> Message-ID: <9887800c-abc2-41ca-bdab-5b5b9ee2a55d@googlegroups.com> Le vendredi 8 janvier 2016 00:08:54 UTC+1, Saeed Moqadam a ?crit?: > create multi platform desktop application by using Python, HTML, CSS and Javascript. > source code is https://github.com/smoqadam/PyFladesk > > you can find RSS Reader app that made by PyFladesk in the following url : > > https://github.com/smoqadam/PyFladesk-rss-reader > > I'll waiting for your feedback. > > thanks And where is the "PyFladesk Rss Reader" running app/installer created with the pyinstaller? From nmcelwaine at outlook.com Fri Jan 8 05:57:20 2016 From: nmcelwaine at outlook.com (nick mcelwaine) Date: Fri, 8 Jan 2016 10:57:20 +0000 Subject: python 3.5.1 winsound bug Message-ID: Dear python team, On my 64bit windows10 the SND_ASYNC flag doesn?t cause the sound to play asynchronously. Nick McElwaine Sent from Mail for Windows 10 From skybuck2000 at hotmail.com Fri Jan 8 06:59:08 2016 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Fri, 8 Jan 2016 12:59:08 +0100 Subject: (Execution) Termination bit, Alternation bit. In-Reply-To: <5688df6c$0$1601$c3e8da3$5496439d@news.astraweb.com> References: <9Bldy.3723$Bz5.1578@fx04.iad> <864af$56760c5f$d47876e2$48630@news.ziggo.nl> <6f90e$56826d92$d47876e2$48098@news.ziggo.nl> <5682892c$0$1587$c3e8da3$5496439d@news.astraweb.com> <45686$5682fe60$d47876e2$14175@news.ziggo.nl> <5688df6c$0$1601$c3e8da3$5496439d@news.astraweb.com> Message-ID: > Should be easy to turn that somewhat pseudo code into python code ! :) If it is so easy, why won't you do it? Not sure why, I use SikuliX and it's kinda buggy and slow, and I also had little time, it's also pretty trivial and I doubt you guys will have a solution that will actually work, so it's time wasted most likely. However I will not let the missing of code be an excuse for you guys and gals :) So here is the code. It may also clearify some things cause some were already confused by the simple conditions it seems ! ;) :) # Begin of Code Condition1 = True Condition2 = True Condition3 = True Condition4 = True Condition5 = True Condition6 = True Condition7 = True def Routine2(): print "Entering Routine2()" global Condition6 global Condition7 while Condition6: while Condition7: print "routine 2: executing" print "Leaving Routine2()" def Routine1(): print "Entering Routine1()" global Condition4 global Condition5 while Condition4: while Condition5: Routine2() print "Leaving Routine1()" # main print "Entering main loop" while Condition1: while Condition2: while Condition3: Routine1() print "Leaving main loop" # End of Code Bye, Skybuck. From stephane at wirtel.be Fri Jan 8 07:32:38 2016 From: stephane at wirtel.be (Stephane Wirtel) Date: Fri, 8 Jan 2016 13:32:38 +0100 Subject: Schedule of PythonFOSDEM 2016 Message-ID: <20160108123238.GA2906@sg1> Hi all, Just to inform you that there is the PythonFOSDEM on 30th January and the PythonFOSDEM will have a room of 363 seats for the #python community. PythonFOSDEM is the name of the room for the Python community at FOSDEM. FOSDEM is a free event for software developers to meet, share ideas and collaborate in Brussels (Belgium). The event is free, no registration necessary. More details at these addresses: * About FOSDEM : https://fosdem.org/2016/ * About Schedule of PythonFOSDEM: https://fosdem.org/2016/schedule/track/python/ See you there, Stephane -- St?phane Wirtel - http://wirtel.be - @matrixise From davorinbajic at gmail.com Fri Jan 8 07:33:15 2016 From: davorinbajic at gmail.com (Davorin Bajic) Date: Fri, 8 Jan 2016 04:33:15 -0800 (PST) Subject: SUM only of positive numbers from array In-Reply-To: <50beb098-f854-4b17-b157-1be075d91f4d@googlegroups.com> References: <50beb098-f854-4b17-b157-1be075d91f4d@googlegroups.com> Message-ID: <73c7888d-d16d-4f93-9214-c287c5a9e2d0@googlegroups.com> On Friday, January 8, 2016 at 5:13:06 AM UTC+1, Davorin Bajic wrote: > Hi All, > > I should help... > > I want to calculate the sum of a positive number, for each row: > > > x = ((mat_1 / s_1T)-(s_2 / total)) > y = (np.sum(x > 0, axis=1)).reshape(-1, 1).tolist() > > However, this part of the code only calculation count, I need sum. > > Any ideas how to solve this problem? > > thanks in advance Tnx Peter, I solved using mask and filled x = ((mat_1 / s_1T)-(s_2 / total)) i_bolean = x < 0 amasked = np.ma.array(x, mask=i_bolean) fill_value = 0. aunmasked = np.ma.filled(amasked, fill_value) y = (aunmasked.sum(axis=1)).reshape(-1, 1).tolist() From mr.eightnoteight at gmail.com Fri Jan 8 08:21:36 2016 From: mr.eightnoteight at gmail.com (srinivas devaki) Date: Fri, 8 Jan 2016 18:51:36 +0530 Subject: How to remove item from heap efficiently? In-Reply-To: <568EEC40.7070807@mail.de> References: <568EEC40.7070807@mail.de> Message-ID: You can create a single heap with primary key as timestamp and secondary key as priority, i.e by creating a tuple insert the elements into the heap as (timestamp, priority) If there is any underlying meaning for creating 2 heaps. please mention. On Fri, Jan 8, 2016 at 4:22 AM, Sven R. Kunze wrote: > Hi everybody, > > suppose, I need items sorted by two criteria (say timestamp and priority). > For that purpose, I use two heaps (heapq module): > > heapA # items sorted by timestamp > heapB # items sorted by priority > > Now my actual problem. When popping an item of heapA (that's the oldest > item), I need to remove the very same item from heapB, regardlessly where it > is in heapB. And vice versa. > > Is there a datastructure or a simple trick to achieve that in an efficient > matter? > > Best, > Sven > -- > https://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Fri Jan 8 08:26:28 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 08 Jan 2016 14:26:28 +0100 Subject: How to remove item from heap efficiently? References: <568EEC40.7070807@mail.de> Message-ID: Sven R. Kunze wrote: > Hi everybody, > > suppose, I need items sorted by two criteria (say timestamp and > priority). For that purpose, I use two heaps (heapq module): > > heapA # items sorted by timestamp > heapB # items sorted by priority > > Now my actual problem. When popping an item of heapA (that's the oldest > item), I need to remove the very same item from heapB, regardlessly > where it is in heapB. And vice versa. > > Is there a datastructure or a simple trick to achieve that in an > efficient matter? The heapq docs mention marking as deleted as an alternative to removing. Another option is to try sorted lists and bisect. From __peter__ at web.de Fri Jan 8 08:49:11 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 08 Jan 2016 14:49:11 +0100 Subject: Unable to access module attribute with underscores in class method, Python 3 References: Message-ID: Joseph Fox-Rabinovitz wrote: > Hi, > > I have a module attribute whose name starts with a pair of underscores. I > am apparently unable to access it directly in a class method (within the > same module, but that is not relevant as far as I can tell). The following > bit of code illustrates the situation: > > __a = 3 > class B: > def __init__(self): > global __a > self.a = __a > b = B() > > This results in a NameError because of name-mangling, despite the global > declaration: > > Traceback (most recent call last): > File "", line 1, in > File "", line 4, in __init__ > NameError: name '_B__a' is not defined > > Not using global does not make a difference. I posted a similar question > on Stack Overflow, where the only reasonable answer given was to wrap __a > in a container whose name is not mangled. For example, doing `self.a = > globals()['__a']` or manually creating a dictionary with a non-mangled > name and accessing that. > > I feel that there should be some way of accessing __a within the class > directly in Python 3. Clearly my expectation that global would fix the > issue is incorrect. I would appreciate either a solution or an explanation > of what is going on that would convince me that accessing a module > attribute in such a way should be forbidden. The explanation is obvious: the approach taken by the compiler is very simple, and all names with two leading underscores (an no two trailing ones of course) are mangled. Other than improving the compiler you can wrap access to __a in a function defined outside the class def get_a(): return __a class B: def __init__(self): self.a = get_a() Or, the horror, you change the name __a to _a. From torriem at gmail.com Fri Jan 8 09:37:35 2016 From: torriem at gmail.com (Michael Torrie) Date: Fri, 08 Jan 2016 07:37:35 -0700 Subject: PyFladesk :: create GUI apps by Python and HTML, CSS and Javascript. In-Reply-To: <568F3305.9080404@blindza.co.za> References: <23384de9-7909-41e8-8a63-ebadb583bf84@googlegroups.com> <568F3305.9080404@blindza.co.za> Message-ID: <568FC9AF.9070402@gmail.com> On 01/07/2016 08:54 PM, jacob Kruger wrote: > I would definitely like to try out something like this - I am primarily > a web developer, and, partly since am 100% blind, any form of GUI design > is at times an issue for me, whereas I have been working with HTML > markup layouts for almost 20 years now, but, which versions of python > should this work with, and, what does it actually then use to > generate/handle GUI interface? Ask since, some of the GUI frameworks are > not too accessible themselves. This project is simply a web browser (qtwebkit) embedded in a bare window that automatically loads a python-based web application you write separately. That's all it is. It's not a GUI toolkit or even a web-based GUI toolkit. It's primary purpose is to allow you to wrap up a Python-based web app (using Flask, but I have no doubt it could handle Django) in a little self-contained package so you can run it as if it were a standalone app. Kind of like how Google Chrome let's you take a url and make a virtual app out of it. From robin at reportlab.com Fri Jan 8 10:03:23 2016 From: robin at reportlab.com (Robin Becker) Date: Fri, 8 Jan 2016 15:03:23 +0000 Subject: debugging uwsgi Message-ID: <568FCFBB.2080403@chamonix.reportlab.co.uk> I have an unusual bug in a large django project which has appeared when using nginx + uwsgi + django. The configuration nginx + flup + django or the django runserver don't seem to create the conditions for the error. Basically I am seeing an error > Traceback (most recent call last): > File "./project/fundfacts/api.py", line 33, in refresh_data > call_command('fe_data_load', month=period_id, datadir=upload_dir) > File "/home/rptlab/website/quilter.reportlab.com/quilter_2/lib/python2.7/site-packages/django/core/management/__init__.py", line 105, in call_command > command = load_command_class(app_name, name) > File "/home/rptlab/website/quilter.reportlab.com/quilter_2/lib/python2.7/site-packages/django/core/management/__init__.py", line 40, in load_command_class > module = import_module('%s.management.commands.%s' % (app_name, name)) > File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module > __import__(name) > ImportError: No module named fe_data_load some hack printouts along the error path seem to indicate that the import should be possible as executing module = import_module('%s.management.commands.%s' % (app_name, 'fe_data_load')) in the manage.py shell work fine and sys.path looks as expected. The uwsgi worker process (I'm forking) is corrupted after (or perhaps because of ) this error and causes previously working pages to fail; it looks like the python interpreter's gone wrong somehow. Any good ways forward with debugging this sort of issue? I'm not sure how I would remotely debug this using winpdb. -- Robin Becker From oscar.j.benjamin at gmail.com Fri Jan 8 10:26:26 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 8 Jan 2016 15:26:26 +0000 Subject: graphs In-Reply-To: References: Message-ID: On 7 January 2016 at 15:36, Saini, Sakshi wrote: > I have a complex dataset and I wish to write a code to create different graphs from it. I was wondering if it is possible for Python/ matplotlib/ seaborn to return a cumulative or mean distribution bar graph based on values in your dataset? I'm sure that it is although I don't fully understand what you mean. > E.g. I have a certain volume in m3 for each rainfall event in mm, and I wish to plot the total volume OR average volume for different rainfall depths; somewhat like the following: This image didn't come through: > [cid:image002.jpg at 01D14937.476CB2F0] This is a text-based mailing list/newsgroup so images will not generally work. > Any tips please? Which part are you unsure about? Do you know how to write and run a Python script? Do you know how to use matplotlib? If you can show some code that does something similar to what you want then I'm sure someone can suggest how to change it to do what you want. -- Oscar From oscar.j.benjamin at gmail.com Fri Jan 8 10:34:47 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 8 Jan 2016 15:34:47 +0000 Subject: extract script from executable made by pyinstaller? In-Reply-To: References: Message-ID: On 8 January 2016 at 07:44, Ulli Horlacher wrote: > Is it possible to extract (and view) the Python script from the Windows > executable which was made by pyinstller? I may be misremembering but I though that pyinstaller actually stores the main script uncompressed so that it's just in the raw .exe. In which case you just need to find the start and stop bytes of the script. If there are other packages etc. then I'm not sure how to do that but they are in some sense stored as a compressed archive inside the .exe file. -- Oscar From steve at pearwood.info Fri Jan 8 11:07:50 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 09 Jan 2016 03:07:50 +1100 Subject: Unable to access module attribute with underscores in class method, Python 3 References: Message-ID: <568fded7$0$1608$c3e8da3$5496439d@news.astraweb.com> On Fri, 8 Jan 2016 03:14 am, Joseph Fox-Rabinovitz wrote: > Hi, > > I have a module attribute whose name starts with a pair of underscores. Don't do that. The way to flag a module-level variable as private is with a single leading underscore. Double-leading underscores are intended for use in classes, to be name-mangled, and double-leading-and-trailing underscores are reserved for use by Python. > I am apparently unable to access it directly in a class method (within the > same module, but that is not relevant as far as I can tell). The following > bit of code illustrates the situation: > > __a = 3 > class B: > def __init__(self): > global __a > self.a = __a > b = B() > > This results in a NameError because of name-mangling, despite the global > declaration: The global declaration is name-mangled as well, as can be seen from the byte-code: py> from dis import dis py> class Test: ... def method(self): ... global __a ... x = __a ... py> dis(Test.method) 4 0 LOAD_GLOBAL 0 (_Test__a) 3 STORE_FAST 1 (x) 6 LOAD_CONST 0 (None) 9 RETURN_VALUE That's exactly as described: within a class, ALL references to double-leading underscore names are mangled. > Not using global does not make a difference. I posted a similar question > on Stack Overflow, where the only reasonable answer given was to wrap __a > in a container whose name is not mangled. That's not a reasonable answer. That's adding unreasonable complication to the code, just to support an unreasonable global name. > For example, doing `self.a = > globals()['__a']` or manually creating a dictionary with a non-mangled > name and accessing that. > > I feel that there should be some way of accessing __a within the class > directly in Python 3. Clearly my expectation that global would fix the > issue is incorrect. I would appreciate either a solution or an explanation > of what is going on that would convince me that accessing a module > attribute in such a way should be forbidden. You are trying to fight the language. __names are intended for a specific use in Python, and you're ignoring that and trying to use them for something else. That's fine so long as your use and the intended use don't clash, but if they do clash (as they are here) then there's only one reasonable answer: stop abusing name-mangled names. If you absolutely insist that you must must must continue to use a double underscore name, you could also try this: py> __a = 1 py> class Test: ... def method(self): ... x = eval("__a") ... print(x) ... py> Test().method() 1 But don't do that. -- Steven From rosuav at gmail.com Fri Jan 8 11:16:35 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Jan 2016 03:16:35 +1100 Subject: Unable to access module attribute with underscores in class method, Python 3 In-Reply-To: <568fded7$0$1608$c3e8da3$5496439d@news.astraweb.com> References: <568fded7$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jan 9, 2016 at 3:07 AM, Steven D'Aprano wrote: > If you absolutely insist that you must must must continue to use a double > underscore name, you could also try this: > > py> __a = 1 > py> class Test: > ... def method(self): > ... x = eval("__a") > ... print(x) > ... > py> Test().method() > 1 > > > But don't do that. Seriously? You consider that less bad than globals()["__a"]? But all of this is craziness to support craziness. It's not asking which inmate should run the asylum - it's asking which of my multiple personalities should be elected fourteen-year-old queen. ChrisA From gefle.rickard at gmail.com Fri Jan 8 11:18:38 2016 From: gefle.rickard at gmail.com (Rickard Englund) Date: Fri, 8 Jan 2016 08:18:38 -0800 (PST) Subject: Strange crash while running a script with a embedded python interpreter Message-ID: <4ac97a67-2527-424e-90e2-b714528977c8@googlegroups.com> First, some system info * Windows 7 (also tested on 8 and 10) * Python 3.5.1 64bit (previously also tested using several 3.x versions) (also tested with 32 bit, but with 3.4.2) * Microsoft Visual Studio 2015 (earlier version of python also tested with Visual Studio 2013) We have tested with both the debug and release libs for 3.5 and 3.5.1 (those available from python installer) with the same problem. The following problem has also been tested on Unix and on MacOS where it works as expected, the problem is only in Windows. Problem description: We have an application for scientific visualization in which we have enabled scripting using embedded python. We have exposed quite some features of our application to python using modules, this works perfectly fine. The problem we have is that the application crashes as soon as a script is trying to import some of python's default libraries, such as os or random. For example, running the single line code "import os" produces a crash with the following stacktrace: http://pastebin.com/QpfGrMY0 We initialize the python interpreter using the following: http://pastebin.com/uyx6gdMb We have tried with and without the Py_NoSiteFlag = 1. When removing that flag it works for some modules, for example "import os" works, but other modules, for example "import random" crashes. In the pastebin link above for the python initialization there are three lines commented out, "importModule("os")","importModule("glog")" and "importModule("random")", if I uncomment those lines the application will not crash when importing those modules. But that is not a viable solution, we can't import all possible modules that way. The following piece of code is how we execute python code: http://pastebin.com/HDUR2LKT It only crashes for modules that exists , if I try to import a module that does not at all exist (eg import unexisting_module) , it fails as expected with a nice error message saying it does not exist. I don't know if we are doing anything wrong in the initialization of the interpreter or when running the script. We can run scripts that are not using any modules or are only using the python modules we create in c++ to expose functionality of our application. Everything is working fine on MacOSX and Linux (tested with Ubuntu) which are the platforms we support. We had a similar setup before using python 2.x instead of 3.x which also worked without any problems. The software i am talking about is using QT for gui and and OpenGL for hardware accelerated graphics. But I have tested it in a minimal application where all QT stuff were omitted and the same issue is still there. The software is open source and can be downloaded/clones from github.com/inviwo/inviwo. The python initialization is done in https://github.com/inviwo/inviwo-dev/blob/master/modules/python3/pyinviwo.cpp and the script compiling and running is handled in https://github.com/inviwo/inviwo-dev/blob/master/modules/python3/pythonscript.cpp I have searched a lot on google and in the issue tracker for python but found nothing that can answer my questions. So I hope that someone here can us solve this. From gefle.rickard at gmail.com Fri Jan 8 11:29:32 2016 From: gefle.rickard at gmail.com (Rickard Englund) Date: Fri, 8 Jan 2016 08:29:32 -0800 (PST) Subject: Strange crash while running a script with a embedded python interpreter In-Reply-To: <4ac97a67-2527-424e-90e2-b714528977c8@googlegroups.com> References: <4ac97a67-2527-424e-90e2-b714528977c8@googlegroups.com> Message-ID: <0d1b7d7f-d263-45dc-b761-99024f83da59@googlegroups.com> On Friday, January 8, 2016 at 5:18:56 PM UTC+1, Rickard Englund wrote: > First, some system info > * Windows 7 (also tested on 8 and 10) > * Python 3.5.1 64bit (previously also tested using several 3.x versions) (also tested with 32 bit, but with 3.4.2) > * Microsoft Visual Studio 2015 (earlier version of python also tested with Visual Studio 2013) > > We have tested with both the debug and release libs for 3.5 and 3.5.1 (those available from python installer) with the same problem. > > The following problem has also been tested on Unix and on MacOS where it works as expected, the problem is only in Windows. > > > Problem description: > We have an application for scientific visualization in which we have enabled scripting using embedded python. We have exposed quite some features of our application to python using modules, this works perfectly fine. > The problem we have is that the application crashes as soon as a script is trying to import some of python's default libraries, such as os or random. For example, running the single line code "import os" produces a crash with the following stacktrace: > http://pastebin.com/QpfGrMY0 > > We initialize the python interpreter using the following: > http://pastebin.com/uyx6gdMb > > We have tried with and without the Py_NoSiteFlag = 1. When removing that flag it works for some modules, for example "import os" works, but other modules, for example "import random" crashes. > > > In the pastebin link above for the python initialization there are three lines commented out, "importModule("os")","importModule("glog")" and "importModule("random")", if I uncomment those lines the application will not crash when importing those modules. But that is not a viable solution, we can't import all possible modules that way. > > The following piece of code is how we execute python code: > http://pastebin.com/HDUR2LKT > > > It only crashes for modules that exists , if I try to import a module that does not at all exist (eg import unexisting_module) , it fails as expected with a nice error message saying it does not exist. > > > I don't know if we are doing anything wrong in the initialization of the interpreter or when running the script. We can run scripts that are not using any modules or are only using the python modules we create in c++ to expose functionality of our application. > Everything is working fine on MacOSX and Linux (tested with Ubuntu) which are the platforms we support. We had a similar setup before using python 2.x instead of 3.x which also worked without any problems. > > > The software i am talking about is using QT for gui and and OpenGL for hardware accelerated graphics. But I have tested it in a minimal application where all QT stuff were omitted and the same issue is still there. > > The software is open source and can be downloaded/clones from github.com/inviwo/inviwo. > > The python initialization is done in > https://github.com/inviwo/inviwo-dev/blob/master/modules/python3/pyinviwo.cpp > and the script compiling and running is handled in > https://github.com/inviwo/inviwo-dev/blob/master/modules/python3/pythonscript.cpp > > > I have searched a lot on google and in the issue tracker for python but found nothing that can answer my questions. So I hope that someone here can us solve this. I notice now that I have pasted 2 links to our private repository, which will not work. The correct links are: https://github.com/inviwo/inviwo/blob/master/modules/python3/pyinviwo.cpp https://github.com/inviwo/inviwo/blob/master/modules/python3/pythonscript.cpp From srkunze at mail.de Fri Jan 8 11:36:10 2016 From: srkunze at mail.de (Sven R. Kunze) Date: Fri, 8 Jan 2016 17:36:10 +0100 Subject: graphs In-Reply-To: References: Message-ID: <568FE57A.7030908@mail.de> Hi Saski, Python's dataset processing machine is *pandas*. Have a look at this cookbook entry here: http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.1/cookbook/Chapter%204%20-%20Find%20out%20on%20which%20weekday%20people%20bike%20the%20most%20with%20groupby%20and%20aggregate.ipynb Best, Sven On 07.01.2016 16:36, Saini, Sakshi wrote: > I have a complex dataset and I wish to write a code to create different graphs from it. I was wondering if it is possible for Python/ matplotlib/ seaborn to return a cumulative or mean distribution bar graph based on values in your dataset? > E.g. I have a certain volume in m3 for each rainfall event in mm, and I wish to plot the total volume OR average volume for different rainfall depths; somewhat like the following: > [cid:image002.jpg at 01D14937.476CB2F0] > > Any tips please? > > > > Sakshi Saini, BASc, EIT > Water Resources Project Coordinator | Credit Valley Conservation > > The information contained in this Credit Valley Conservation electronic message is directed in confidence solely to the person(s) named above and may not be otherwise distributed, copied or disclosed including attachments. The message may contain information that is privileged, confidential and exempt from disclosure under the Municipal Freedom of Information and Protection and Privacy Act and by the Personal Information Protection Electronic Documents Act. The use of such personal information except in compliance with the Acts, is strictly prohibited. If you have received this message in error, please notify the sender immediately advising of the error and delete the message without making a copy. Thank you. From acushla4real at gmail.com Fri Jan 8 11:37:38 2016 From: acushla4real at gmail.com (acushla4real at gmail.com) Date: Fri, 8 Jan 2016 08:37:38 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> Message-ID: On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > i have these task which i believe i have done well to some level > > Create a function get_algorithm_result to implement the algorithm below > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > so i came up with this code below > > def get_algorithm_result(my_list): > if not any(not type(y) is int for y in my_list): > largest = 0 > for item in range(0,len(my_list)): > if largest < my_list[item]: > largest = my_list[item] > return largest > else: > > return(my_list[-1]) > > def prime_number(integer): > if integer%2==0 and 2!=integer: > return False > else: > return True > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > prime_number(1) > prime_number(78) > prime_number(11) > for the question above, there is a unittes which reads > > import unittest > > class AlgorithmTestCases(unittest.TestCase): > def test_maximum_number_one(self): > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > self.assertEqual(result, 78, msg="Incorrect number") > > def test_maximum_number_two(self): > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > self.assertEqual(result, "zoo", msg="Incorrect number") > > def test_prime_number_one(self): > result = prime_number(1) > self.assertEqual(result, True, msg="Result is invalid") > > def test_prime_number_two(self): > result = prime_number(78) > self.assertEqual(result, False, msg="Result is invalid") > > def test_prime_number_three(self): > result = prime_number(11) > self.assertEqual(result, True, msg="Result is invalid") > but once i run my code ,it returns error saying Test Spec Failed > > Your solution failed to pass all the tests > what is actually wrong with my code? I had to use a hack to bypass it, worked and I moved on to next quiz From rxjwg98 at gmail.com Fri Jan 8 11:42:41 2016 From: rxjwg98 at gmail.com (Robert) Date: Fri, 8 Jan 2016 08:42:41 -0800 (PST) Subject: What use is '__reduce__'? Message-ID: <399e214a-552b-4d4a-a39f-8e917dadd6c6@googlegroups.com> Hi, When I try to run the following code: ///// from collections import Counter, OrderedDict class OrderedCounter(Counter, OrderedDict): 'Counter that remembers the order elements are first seen' def __repr__(self): return '%s(%r)' % (self.__class__.__name__, OrderedDict(self)) def __reduce__(self): return self.__class__, (OrderedDict(self),) oc = OrderedCounter('abracadabra') ----- I don't know the use of '__reduce__', even I look it up on Python website. On that website, it explains 'pickle' module: https://docs.python.org/2/library/pickle.html But the above example without import that module. Is it from built-in? Anyhow, I don't find a built-in explanation about '__reduce__'. What use of the above two new self methods are in class OrderedCounter? Thanks, From srkunze at mail.de Fri Jan 8 11:45:11 2016 From: srkunze at mail.de (Sven R. Kunze) Date: Fri, 8 Jan 2016 17:45:11 +0100 Subject: How to remove item from heap efficiently? In-Reply-To: References: <568EEC40.7070807@mail.de> Message-ID: <568FE797.6090808@mail.de> Thanks for your suggestion. On 08.01.2016 14:21, srinivas devaki wrote: > You can create a single heap with primary key as timestamp and > secondary key as priority, i.e by creating a tuple > insert the elements into the heap as > (timestamp, priority) I think I cannot use that because I need the list sorted by both criteria. > If there is any underlying meaning for creating 2 heaps. please mention. I use two heaps because I need to insert arbitrary items fast and remove the ones fast which are too old (timestamp) or are next in order (priority). Basically a task scheduler where tasks can be thrown away once they are too long in the queue. > On Fri, Jan 8, 2016 at 4:22 AM, Sven R. Kunze wrote: >> Hi everybody, >> >> suppose, I need items sorted by two criteria (say timestamp and priority). >> For that purpose, I use two heaps (heapq module): >> >> heapA # items sorted by timestamp >> heapB # items sorted by priority >> >> Now my actual problem. When popping an item of heapA (that's the oldest >> item), I need to remove the very same item from heapB, regardlessly where it >> is in heapB. And vice versa. >> >> Is there a datastructure or a simple trick to achieve that in an efficient >> matter? >> >> Best, >> Sven >> -- >> https://mail.python.org/mailman/listinfo/python-list From robin at reportlab.com Fri Jan 8 11:49:34 2016 From: robin at reportlab.com (Robin Becker) Date: Fri, 8 Jan 2016 16:49:34 +0000 Subject: debugging uwsgi In-Reply-To: <568FCFBB.2080403@chamonix.reportlab.co.uk> References: <568FCFBB.2080403@chamonix.reportlab.co.uk> Message-ID: <568FE89E.3080907@chamonix.reportlab.co.uk> On 08/01/2016 15:03, Robin Becker wrote: > I have an unusual bug in a large django project which has appeared when using > nginx + uwsgi + django. The configuration nginx + flup + django or the django > runserver don't seem to create the conditions for the error. > > Basically I am seeing an error > >> Traceback (most recent call last): >> File "./project/fundfacts/api.py", line 33, in refresh_data >> call_command('fe_data_load', month=period_id, datadir=upload_dir) >> File >> "/home/rptlab/website/quilter.reportlab.com/quilter_2/lib/python2.7/site-packages/django/core/management/__init__.py", >> line 105, in call_command >> command = load_command_class(app_name, name) >> File >> "/home/rptlab/website/quilter.reportlab.com/quilter_2/lib/python2.7/site-packages/django/core/management/__init__.py", >> line 40, in load_command_class >> module = import_module('%s.management.commands.%s' % (app_name, name)) >> File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module >> __import__(name) >> ImportError: No module named fe_data_load .......... I discovered by trial and error that a preceding call_command had caused a chdir; that seems to have deleterious effects on the uwsgi process in question. I'm not sure why the flup server is superior, but I guess something must be different about the python startup used by uwsgi compared to python manage.py runfcgi. I'm still interested to find out any sensible way to debug uwsgi + python. -- Robin Becker From srkunze at mail.de Fri Jan 8 11:52:28 2016 From: srkunze at mail.de (Sven R. Kunze) Date: Fri, 8 Jan 2016 17:52:28 +0100 Subject: How to remove item from heap efficiently? In-Reply-To: References: <568EEC40.7070807@mail.de> Message-ID: <568FE94C.40003@mail.de> Thanks for your reply. On 08.01.2016 14:26, Peter Otten wrote: > Sven R. Kunze wrote: > >> Hi everybody, >> >> suppose, I need items sorted by two criteria (say timestamp and >> priority). For that purpose, I use two heaps (heapq module): >> >> heapA # items sorted by timestamp >> heapB # items sorted by priority >> >> Now my actual problem. When popping an item of heapA (that's the oldest >> item), I need to remove the very same item from heapB, regardlessly >> where it is in heapB. And vice versa. >> >> Is there a datastructure or a simple trick to achieve that in an >> efficient matter? > The heapq docs mention marking as deleted as an alternative to removing. That is how I do it for now. However, the heap continues to grow which needs a periodic clean up. > Another option is to try sorted lists and bisect. The docs tell me that insertion is not really fast then. :/ Best, Sven From ian.g.kelly at gmail.com Fri Jan 8 12:03:21 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Jan 2016 10:03:21 -0700 Subject: What use is '__reduce__'? In-Reply-To: <399e214a-552b-4d4a-a39f-8e917dadd6c6@googlegroups.com> References: <399e214a-552b-4d4a-a39f-8e917dadd6c6@googlegroups.com> Message-ID: As you found by searching, __reduce__ is used to determine how instances of the class are pickled. If the example you're using doesn't do any pickling, then it's not really relevant to the example. It's probably included so that it won't be missed when the code is copied. On Fri, Jan 8, 2016 at 9:42 AM, Robert wrote: > Hi, > > When I try to run the following code: > > > > ///// > from collections import Counter, OrderedDict > > class OrderedCounter(Counter, OrderedDict): > 'Counter that remembers the order elements are first seen' > def __repr__(self): > return '%s(%r)' % (self.__class__.__name__, > OrderedDict(self)) > def __reduce__(self): > return self.__class__, (OrderedDict(self),) > > oc = OrderedCounter('abracadabra') > ----- > > I don't know the use of '__reduce__', even I look it up on Python website. > On that website, it explains 'pickle' module: > https://docs.python.org/2/library/pickle.html > > But the above example without import that module. Is it from built-in? > Anyhow, I don't find a built-in explanation about '__reduce__'. > > What use of the above two new self methods are in class OrderedCounter? > > Thanks, > > > -- > https://mail.python.org/mailman/listinfo/python-list From geraldjuwah at gmail.com Fri Jan 8 12:16:30 2016 From: geraldjuwah at gmail.com (geraldjuwah at gmail.com) Date: Fri, 8 Jan 2016 09:16:30 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> Message-ID: <1b4984ae-500e-460f-af99-802b8e533e8c@googlegroups.com> On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > i have these task which i believe i have done well to some level > > > > Create a function get_algorithm_result to implement the algorithm below > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > so i came up with this code below > > > > def get_algorithm_result(my_list): > > if not any(not type(y) is int for y in my_list): > > largest = 0 > > for item in range(0,len(my_list)): > > if largest < my_list[item]: > > largest = my_list[item] > > return largest > > else: > > > > return(my_list[-1]) > > > > def prime_number(integer): > > if integer%2==0 and 2!=integer: > > return False > > else: > > return True > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > prime_number(1) > > prime_number(78) > > prime_number(11) > > for the question above, there is a unittes which reads > > > > import unittest > > > > class AlgorithmTestCases(unittest.TestCase): > > def test_maximum_number_one(self): > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > self.assertEqual(result, 78, msg="Incorrect number") > > > > def test_maximum_number_two(self): > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > def test_prime_number_one(self): > > result = prime_number(1) > > self.assertEqual(result, True, msg="Result is invalid") > > > > def test_prime_number_two(self): > > result = prime_number(78) > > self.assertEqual(result, False, msg="Result is invalid") > > > > def test_prime_number_three(self): > > result = prime_number(11) > > self.assertEqual(result, True, msg="Result is invalid") > > but once i run my code ,it returns error saying Test Spec Failed > > > > Your solution failed to pass all the tests > > what is actually wrong with my code? > > I had to use a hack to bypass it, worked and I moved on to next quiz > could you please share how you bypassed it? On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > i have these task which i believe i have done well to some level > > > > Create a function get_algorithm_result to implement the algorithm below > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > so i came up with this code below > > > > def get_algorithm_result(my_list): > > if not any(not type(y) is int for y in my_list): > > largest = 0 > > for item in range(0,len(my_list)): > > if largest < my_list[item]: > > largest = my_list[item] > > return largest > > else: > > > > return(my_list[-1]) > > > > def prime_number(integer): > > if integer%2==0 and 2!=integer: > > return False > > else: > > return True > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > prime_number(1) > > prime_number(78) > > prime_number(11) > > for the question above, there is a unittes which reads > > > > import unittest > > > > class AlgorithmTestCases(unittest.TestCase): > > def test_maximum_number_one(self): > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > self.assertEqual(result, 78, msg="Incorrect number") > > > > def test_maximum_number_two(self): > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > def test_prime_number_one(self): > > result = prime_number(1) > > self.assertEqual(result, True, msg="Result is invalid") > > > > def test_prime_number_two(self): > > result = prime_number(78) > > self.assertEqual(result, False, msg="Result is invalid") > > > > def test_prime_number_three(self): > > result = prime_number(11) > > self.assertEqual(result, True, msg="Result is invalid") > > but once i run my code ,it returns error saying Test Spec Failed > > > > Your solution failed to pass all the tests > > what is actually wrong with my code? > > I had to use a hack to bypass it, worked and I moved on to next quiz On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > i have these task which i believe i have done well to some level > > > > Create a function get_algorithm_result to implement the algorithm below > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > so i came up with this code below > > > > def get_algorithm_result(my_list): > > if not any(not type(y) is int for y in my_list): > > largest = 0 > > for item in range(0,len(my_list)): > > if largest < my_list[item]: > > largest = my_list[item] > > return largest > > else: > > > > return(my_list[-1]) > > > > def prime_number(integer): > > if integer%2==0 and 2!=integer: > > return False > > else: > > return True > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > prime_number(1) > > prime_number(78) > > prime_number(11) > > for the question above, there is a unittes which reads > > > > import unittest > > > > class AlgorithmTestCases(unittest.TestCase): > > def test_maximum_number_one(self): > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > self.assertEqual(result, 78, msg="Incorrect number") > > > > def test_maximum_number_two(self): > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > def test_prime_number_one(self): > > result = prime_number(1) > > self.assertEqual(result, True, msg="Result is invalid") > > > > def test_prime_number_two(self): > > result = prime_number(78) > > self.assertEqual(result, False, msg="Result is invalid") > > > > def test_prime_number_three(self): > > result = prime_number(11) > > self.assertEqual(result, True, msg="Result is invalid") > > but once i run my code ,it returns error saying Test Spec Failed > > > > Your solution failed to pass all the tests > > what is actually wrong with my code? > > I had to use a hack to bypass it, worked and I moved on to next quiz On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > i have these task which i believe i have done well to some level > > > > Create a function get_algorithm_result to implement the algorithm below > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > so i came up with this code below > > > > def get_algorithm_result(my_list): > > if not any(not type(y) is int for y in my_list): > > largest = 0 > > for item in range(0,len(my_list)): > > if largest < my_list[item]: > > largest = my_list[item] > > return largest > > else: > > > > return(my_list[-1]) > > > > def prime_number(integer): > > if integer%2==0 and 2!=integer: > > return False > > else: > > return True > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > prime_number(1) > > prime_number(78) > > prime_number(11) > > for the question above, there is a unittes which reads > > > > import unittest > > > > class AlgorithmTestCases(unittest.TestCase): > > def test_maximum_number_one(self): > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > self.assertEqual(result, 78, msg="Incorrect number") > > > > def test_maximum_number_two(self): > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > def test_prime_number_one(self): > > result = prime_number(1) > > self.assertEqual(result, True, msg="Result is invalid") > > > > def test_prime_number_two(self): > > result = prime_number(78) > > self.assertEqual(result, False, msg="Result is invalid") > > > > def test_prime_number_three(self): > > result = prime_number(11) > > self.assertEqual(result, True, msg="Result is invalid") > > but once i run my code ,it returns error saying Test Spec Failed > > > > Your solution failed to pass all the tests > > what is actually wrong with my code? > > I had to use a hack to bypass it, worked and I moved on to next quiz On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > i have these task which i believe i have done well to some level > > > > Create a function get_algorithm_result to implement the algorithm below > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > so i came up with this code below > > > > def get_algorithm_result(my_list): > > if not any(not type(y) is int for y in my_list): > > largest = 0 > > for item in range(0,len(my_list)): > > if largest < my_list[item]: > > largest = my_list[item] > > return largest > > else: > > > > return(my_list[-1]) > > > > def prime_number(integer): > > if integer%2==0 and 2!=integer: > > return False > > else: > > return True > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > prime_number(1) > > prime_number(78) > > prime_number(11) > > for the question above, there is a unittes which reads > > > > import unittest > > > > class AlgorithmTestCases(unittest.TestCase): > > def test_maximum_number_one(self): > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > self.assertEqual(result, 78, msg="Incorrect number") > > > > def test_maximum_number_two(self): > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > def test_prime_number_one(self): > > result = prime_number(1) > > self.assertEqual(result, True, msg="Result is invalid") > > > > def test_prime_number_two(self): > > result = prime_number(78) > > self.assertEqual(result, False, msg="Result is invalid") > > > > def test_prime_number_three(self): > > result = prime_number(11) > > self.assertEqual(result, True, msg="Result is invalid") > > but once i run my code ,it returns error saying Test Spec Failed > > > > Your solution failed to pass all the tests > > what is actually wrong with my code? > > I had to use a hack to bypass it, worked and I moved on to next quiz On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > i have these task which i believe i have done well to some level > > > > Create a function get_algorithm_result to implement the algorithm below > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > so i came up with this code below > > > > def get_algorithm_result(my_list): > > if not any(not type(y) is int for y in my_list): > > largest = 0 > > for item in range(0,len(my_list)): > > if largest < my_list[item]: > > largest = my_list[item] > > return largest > > else: > > > > return(my_list[-1]) > > > > def prime_number(integer): > > if integer%2==0 and 2!=integer: > > return False > > else: > > return True > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > prime_number(1) > > prime_number(78) > > prime_number(11) > > for the question above, there is a unittes which reads > > > > import unittest > > > > class AlgorithmTestCases(unittest.TestCase): > > def test_maximum_number_one(self): > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > self.assertEqual(result, 78, msg="Incorrect number") > > > > def test_maximum_number_two(self): > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > def test_prime_number_one(self): > > result = prime_number(1) > > self.assertEqual(result, True, msg="Result is invalid") > > > > def test_prime_number_two(self): > > result = prime_number(78) > > self.assertEqual(result, False, msg="Result is invalid") > > > > def test_prime_number_three(self): > > result = prime_number(11) > > self.assertEqual(result, True, msg="Result is invalid") > > but once i run my code ,it returns error saying Test Spec Failed > > > > Your solution failed to pass all the tests > > what is actually wrong with my code? > > I had to use a hack to bypass it, worked and I moved on to next quiz On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > i have these task which i believe i have done well to some level > > > > Create a function get_algorithm_result to implement the algorithm below > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > so i came up with this code below > > > > def get_algorithm_result(my_list): > > if not any(not type(y) is int for y in my_list): > > largest = 0 > > for item in range(0,len(my_list)): > > if largest < my_list[item]: > > largest = my_list[item] > > return largest > > else: > > > > return(my_list[-1]) > > > > def prime_number(integer): > > if integer%2==0 and 2!=integer: > > return False > > else: > > return True > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > prime_number(1) > > prime_number(78) > > prime_number(11) > > for the question above, there is a unittes which reads > > > > import unittest > > > > class AlgorithmTestCases(unittest.TestCase): > > def test_maximum_number_one(self): > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > self.assertEqual(result, 78, msg="Incorrect number") > > > > def test_maximum_number_two(self): > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > def test_prime_number_one(self): > > result = prime_number(1) > > self.assertEqual(result, True, msg="Result is invalid") > > > > def test_prime_number_two(self): > > result = prime_number(78) > > self.assertEqual(result, False, msg="Result is invalid") > > > > def test_prime_number_three(self): > > result = prime_number(11) > > self.assertEqual(result, True, msg="Result is invalid") > > but once i run my code ,it returns error saying Test Spec Failed > > > > Your solution failed to pass all the tests > > what is actually wrong with my code? > > I had to use a hack to bypass it, worked and I moved on to next quiz On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > i have these task which i believe i have done well to some level > > > > Create a function get_algorithm_result to implement the algorithm below > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > so i came up with this code below > > > > def get_algorithm_result(my_list): > > if not any(not type(y) is int for y in my_list): > > largest = 0 > > for item in range(0,len(my_list)): > > if largest < my_list[item]: > > largest = my_list[item] > > return largest > > else: > > > > return(my_list[-1]) > > > > def prime_number(integer): > > if integer%2==0 and 2!=integer: > > return False > > else: > > return True > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > prime_number(1) > > prime_number(78) > > prime_number(11) > > for the question above, there is a unittes which reads > > > > import unittest > > > > class AlgorithmTestCases(unittest.TestCase): > > def test_maximum_number_one(self): > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > self.assertEqual(result, 78, msg="Incorrect number") > > > > def test_maximum_number_two(self): > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > def test_prime_number_one(self): > > result = prime_number(1) > > self.assertEqual(result, True, msg="Result is invalid") > > > > def test_prime_number_two(self): > > result = prime_number(78) > > self.assertEqual(result, False, msg="Result is invalid") > > > > def test_prime_number_three(self): > > result = prime_number(11) > > self.assertEqual(result, True, msg="Result is invalid") > > but once i run my code ,it returns error saying Test Spec Failed > > > > Your solution failed to pass all the tests > > what is actually wrong with my code? > > I had to use a hack to bypass it, worked and I moved on to next quiz On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > i have these task which i believe i have done well to some level > > > > Create a function get_algorithm_result to implement the algorithm below > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > so i came up with this code below > > > > def get_algorithm_result(my_list): > > if not any(not type(y) is int for y in my_list): > > largest = 0 > > for item in range(0,len(my_list)): > > if largest < my_list[item]: > > largest = my_list[item] > > return largest > > else: > > > > return(my_list[-1]) > > > > def prime_number(integer): > > if integer%2==0 and 2!=integer: > > return False > > else: > > return True > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > prime_number(1) > > prime_number(78) > > prime_number(11) > > for the question above, there is a unittes which reads > > > > import unittest > > > > class AlgorithmTestCases(unittest.TestCase): > > def test_maximum_number_one(self): > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > self.assertEqual(result, 78, msg="Incorrect number") > > > > def test_maximum_number_two(self): > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > def test_prime_number_one(self): > > result = prime_number(1) > > self.assertEqual(result, True, msg="Result is invalid") > > > > def test_prime_number_two(self): > > result = prime_number(78) > > self.assertEqual(result, False, msg="Result is invalid") > > > > def test_prime_number_three(self): > > result = prime_number(11) > > self.assertEqual(result, True, msg="Result is invalid") > > but once i run my code ,it returns error saying Test Spec Failed > > > > Your solution failed to pass all the tests > > what is actually wrong with my code? > > I had to use a hack to bypass it, worked and I moved on to next quiz On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > i have these task which i believe i have done well to some level > > > > Create a function get_algorithm_result to implement the algorithm below > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > so i came up with this code below > > > > def get_algorithm_result(my_list): > > if not any(not type(y) is int for y in my_list): > > largest = 0 > > for item in range(0,len(my_list)): > > if largest < my_list[item]: > > largest = my_list[item] > > return largest > > else: > > > > return(my_list[-1]) > > > > def prime_number(integer): > > if integer%2==0 and 2!=integer: > > return False > > else: > > return True > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > prime_number(1) > > prime_number(78) > > prime_number(11) > > for the question above, there is a unittes which reads > > > > import unittest > > > > class AlgorithmTestCases(unittest.TestCase): > > def test_maximum_number_one(self): > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > self.assertEqual(result, 78, msg="Incorrect number") > > > > def test_maximum_number_two(self): > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > def test_prime_number_one(self): > > result = prime_number(1) > > self.assertEqual(result, True, msg="Result is invalid") > > > > def test_prime_number_two(self): > > result = prime_number(78) > > self.assertEqual(result, False, msg="Result is invalid") > > > > def test_prime_number_three(self): > > result = prime_number(11) > > self.assertEqual(result, True, msg="Result is invalid") > > but once i run my code ,it returns error saying Test Spec Failed > > > > Your solution failed to pass all the tests > > what is actually wrong with my code? > > I had to use a hack to bypass it, worked and I moved on to next quiz On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > i have these task which i believe i have done well to some level > > > > Create a function get_algorithm_result to implement the algorithm below > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > so i came up with this code below > > > > def get_algorithm_result(my_list): > > if not any(not type(y) is int for y in my_list): > > largest = 0 > > for item in range(0,len(my_list)): > > if largest < my_list[item]: > > largest = my_list[item] > > return largest > > else: > > > > return(my_list[-1]) > > > > def prime_number(integer): > > if integer%2==0 and 2!=integer: > > return False > > else: > > return True > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > prime_number(1) > > prime_number(78) > > prime_number(11) > > for the question above, there is a unittes which reads > > > > import unittest > > > > class AlgorithmTestCases(unittest.TestCase): > > def test_maximum_number_one(self): > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > self.assertEqual(result, 78, msg="Incorrect number") > > > > def test_maximum_number_two(self): > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > def test_prime_number_one(self): > > result = prime_number(1) > > self.assertEqual(result, True, msg="Result is invalid") > > > > def test_prime_number_two(self): > > result = prime_number(78) > > self.assertEqual(result, False, msg="Result is invalid") > > > > def test_prime_number_three(self): > > result = prime_number(11) > > self.assertEqual(result, True, msg="Result is invalid") > > but once i run my code ,it returns error saying Test Spec Failed > > > > Your solution failed to pass all the tests > > what is actually wrong with my code? > > I had to use a hack to bypass it, worked and I moved on to next quiz On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > i have these task which i believe i have done well to some level > > > > Create a function get_algorithm_result to implement the algorithm below > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > so i came up with this code below > > > > def get_algorithm_result(my_list): > > if not any(not type(y) is int for y in my_list): > > largest = 0 > > for item in range(0,len(my_list)): > > if largest < my_list[item]: > > largest = my_list[item] > > return largest > > else: > > > > return(my_list[-1]) > > > > def prime_number(integer): > > if integer%2==0 and 2!=integer: > > return False > > else: > > return True > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > prime_number(1) > > prime_number(78) > > prime_number(11) > > for the question above, there is a unittes which reads > > > > import unittest > > > > class AlgorithmTestCases(unittest.TestCase): > > def test_maximum_number_one(self): > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > self.assertEqual(result, 78, msg="Incorrect number") > > > > def test_maximum_number_two(self): > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > def test_prime_number_one(self): > > result = prime_number(1) > > self.assertEqual(result, True, msg="Result is invalid") > > > > def test_prime_number_two(self): > > result = prime_number(78) > > self.assertEqual(result, False, msg="Result is invalid") > > > > def test_prime_number_three(self): > > result = prime_number(11) > > self.assertEqual(result, True, msg="Result is invalid") > > but once i run my code ,it returns error saying Test Spec Failed > > > > Your solution failed to pass all the tests > > what is actually wrong with my code? > > I had to use a hack to bypass it, worked and I moved on to next quiz On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > i have these task which i believe i have done well to some level > > > > Create a function get_algorithm_result to implement the algorithm below > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > so i came up with this code below > > > > def get_algorithm_result(my_list): > > if not any(not type(y) is int for y in my_list): > > largest = 0 > > for item in range(0,len(my_list)): > > if largest < my_list[item]: > > largest = my_list[item] > > return largest > > else: > > > > return(my_list[-1]) > > > > def prime_number(integer): > > if integer%2==0 and 2!=integer: > > return False > > else: > > return True > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > prime_number(1) > > prime_number(78) > > prime_number(11) > > for the question above, there is a unittes which reads > > > > import unittest > > > > class AlgorithmTestCases(unittest.TestCase): > > def test_maximum_number_one(self): > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > self.assertEqual(result, 78, msg="Incorrect number") > > > > def test_maximum_number_two(self): > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > def test_prime_number_one(self): > > result = prime_number(1) > > self.assertEqual(result, True, msg="Result is invalid") > > > > def test_prime_number_two(self): > > result = prime_number(78) > > self.assertEqual(result, False, msg="Result is invalid") > > > > def test_prime_number_three(self): > > result = prime_number(11) > > self.assertEqual(result, True, msg="Result is invalid") > > but once i run my code ,it returns error saying Test Spec Failed > > > > Your solution failed to pass all the tests > > what is actually wrong with my code? > > I had to use a hack to bypass it, worked and I moved on to next quiz On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > i have these task which i believe i have done well to some level > > > > Create a function get_algorithm_result to implement the algorithm below > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > so i came up with this code below > > > > def get_algorithm_result(my_list): > > if not any(not type(y) is int for y in my_list): > > largest = 0 > > for item in range(0,len(my_list)): > > if largest < my_list[item]: > > largest = my_list[item] > > return largest > > else: > > > > return(my_list[-1]) > > > > def prime_number(integer): > > if integer%2==0 and 2!=integer: > > return False > > else: > > return True > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > prime_number(1) > > prime_number(78) > > prime_number(11) > > for the question above, there is a unittes which reads > > > > import unittest > > > > class AlgorithmTestCases(unittest.TestCase): > > def test_maximum_number_one(self): > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > self.assertEqual(result, 78, msg="Incorrect number") > > > > def test_maximum_number_two(self): > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > def test_prime_number_one(self): > > result = prime_number(1) > > self.assertEqual(result, True, msg="Result is invalid") > > > > def test_prime_number_two(self): > > result = prime_number(78) > > self.assertEqual(result, False, msg="Result is invalid") > > > > def test_prime_number_three(self): > > result = prime_number(11) > > self.assertEqual(result, True, msg="Result is invalid") > > but once i run my code ,it returns error saying Test Spec Failed > > > > Your solution failed to pass all the tests > > what is actually wrong with my code? > > I had to use a hack to bypass it, worked and I moved on to next quiz On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > i have these task which i believe i have done well to some level > > > > Create a function get_algorithm_result to implement the algorithm below > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > so i came up with this code below > > > > def get_algorithm_result(my_list): > > if not any(not type(y) is int for y in my_list): > > largest = 0 > > for item in range(0,len(my_list)): > > if largest < my_list[item]: > > largest = my_list[item] > > return largest > > else: > > > > return(my_list[-1]) > > > > def prime_number(integer): > > if integer%2==0 and 2!=integer: > > return False > > else: > > return True > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > prime_number(1) > > prime_number(78) > > prime_number(11) > > for the question above, there is a unittes which reads > > > > import unittest > > > > class AlgorithmTestCases(unittest.TestCase): > > def test_maximum_number_one(self): > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > self.assertEqual(result, 78, msg="Incorrect number") > > > > def test_maximum_number_two(self): > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > def test_prime_number_one(self): > > result = prime_number(1) > > self.assertEqual(result, True, msg="Result is invalid") > > > > def test_prime_number_two(self): > > result = prime_number(78) > > self.assertEqual(result, False, msg="Result is invalid") > > > > def test_prime_number_three(self): > > result = prime_number(11) > > self.assertEqual(result, True, msg="Result is invalid") > > but once i run my code ,it returns error saying Test Spec Failed > > > > Your solution failed to pass all the tests > > what is actually wrong with my code? > > I had to use a hack to bypass it, worked and I moved on to next quiz On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > i have these task which i believe i have done well to some level > > > > Create a function get_algorithm_result to implement the algorithm below > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > so i came up with this code below > > > > def get_algorithm_result(my_list): > > if not any(not type(y) is int for y in my_list): > > largest = 0 > > for item in range(0,len(my_list)): > > if largest < my_list[item]: > > largest = my_list[item] > > return largest > > else: > > > > return(my_list[-1]) > > > > def prime_number(integer): > > if integer%2==0 and 2!=integer: > > return False > > else: > > return True > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > prime_number(1) > > prime_number(78) > > prime_number(11) > > for the question above, there is a unittes which reads > > > > import unittest > > > > class AlgorithmTestCases(unittest.TestCase): > > def test_maximum_number_one(self): > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > self.assertEqual(result, 78, msg="Incorrect number") > > > > def test_maximum_number_two(self): > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > def test_prime_number_one(self): > > result = prime_number(1) > > self.assertEqual(result, True, msg="Result is invalid") > > > > def test_prime_number_two(self): > > result = prime_number(78) > > self.assertEqual(result, False, msg="Result is invalid") > > > > def test_prime_number_three(self): > > result = prime_number(11) > > self.assertEqual(result, True, msg="Result is invalid") > > but once i run my code ,it returns error saying Test Spec Failed > > > > Your solution failed to pass all the tests > > what is actually wrong with my code? > > I had to use a hack to bypass it, worked and I moved on to next quiz Could you please share how you bypassed it through hacking? From rxjwg98 at gmail.com Fri Jan 8 12:43:30 2016 From: rxjwg98 at gmail.com (Robert) Date: Fri, 8 Jan 2016 09:43:30 -0800 (PST) Subject: What use is '() here? Message-ID: <7e131846-d180-4118-a584-69121de01e2a@googlegroups.com> Hi, Thanks Ian for replying to my previous post. Here is a further question on the 'return' line below. import collections import pickle class C(collections.defaultdict): def __init__(self): collections.defaultdict.__init__(self, list) def __reduce__(self): t = collections.defaultdict.__reduce__(self) return (t[0], ()) + t[2:] c=C() print c print c.__reduce__() c[1].append(200) c[2].append(223) c2 = pickle.loads(pickle.dumps(c)) c2 == c /////////// >From below command, I see 't' should be a tuple: c.__reduce__() Out[103]: (__main__.C, (), None, None, ) Then, I cannot get the idea what the two level parenthesis are for. Its result is a tuple? Then, it can add 't[2:]'. return (t[0], ()) + t[2:] It is not a tuple because there is no third level parenthesis, i.e. ((t[0], ()) + t[2:]) Do you have a simple way for me to make it clear? Thanks, From rxjwg98 at gmail.com Fri Jan 8 12:45:58 2016 From: rxjwg98 at gmail.com (Robert) Date: Fri, 8 Jan 2016 09:45:58 -0800 (PST) Subject: What use is '__reduce__'? In-Reply-To: References: <399e214a-552b-4d4a-a39f-8e917dadd6c6@googlegroups.com> Message-ID: On Friday, January 8, 2016 at 12:04:21 PM UTC-5, Ian wrote: > As you found by searching, __reduce__ is used to determine how > instances of the class are pickled. If the example you're using > doesn't do any pickling, then it's not really relevant to the example. > It's probably included so that it won't be missed when the code is > copied. > > On Fri, Jan 8, 2016 at 9:42 AM, Robert wrote: > > Hi, > > > > When I try to run the following code: > > > > > > > > ///// > > from collections import Counter, OrderedDict > > > > class OrderedCounter(Counter, OrderedDict): > > 'Counter that remembers the order elements are first seen' > > def __repr__(self): > > return '%s(%r)' % (self.__class__.__name__, > > OrderedDict(self)) > > def __reduce__(self): > > return self.__class__, (OrderedDict(self),) > > > > oc = OrderedCounter('abracadabra') > > ----- > > > > I don't know the use of '__reduce__', even I look it up on Python website. > > On that website, it explains 'pickle' module: > > https://docs.python.org/2/library/pickle.html > > > > But the above example without import that module. Is it from built-in? > > Anyhow, I don't find a built-in explanation about '__reduce__'. > > > > What use of the above two new self methods are in class OrderedCounter? > > > > Thanks, > > > > > > -- > > https://mail.python.org/mailman/listinfo/python-list Thanks for your reply. From rxjwg98 at gmail.com Fri Jan 8 13:04:07 2016 From: rxjwg98 at gmail.com (Robert) Date: Fri, 8 Jan 2016 10:04:07 -0800 (PST) Subject: What use is '() here? In-Reply-To: <7e131846-d180-4118-a584-69121de01e2a@googlegroups.com> References: <7e131846-d180-4118-a584-69121de01e2a@googlegroups.com> Message-ID: On Friday, January 8, 2016 at 12:44:01 PM UTC-5, Robert wrote: > Hi, > > Thanks Ian for replying to my previous post. Here is a further question on > the 'return' line below. > > > > > import collections > import pickle > class C(collections.defaultdict): > def __init__(self): > collections.defaultdict.__init__(self, list) > def __reduce__(self): > t = collections.defaultdict.__reduce__(self) > return (t[0], ()) + t[2:] > > > c=C() > print c > print c.__reduce__() > c[1].append(200) > c[2].append(223) > c2 = pickle.loads(pickle.dumps(c)) > c2 == c > /////////// > From below command, I see 't' should be a tuple: > > > c.__reduce__() > Out[103]: (__main__.C, (), None, None, ) > > > Then, I cannot get the idea what the two level parenthesis are for. > Its result is a tuple? Then, it can add 't[2:]'. > > return (t[0], ()) + t[2:] > > > It is not a tuple because there is no third level parenthesis, i.e. > > ((t[0], ()) + t[2:]) > > > Do you have a simple way for me to make it clear? Thanks, OK. I get my answer for it. It is a tuple. I should get familiar with the return line. Thanks, From framstag at rus.uni-stuttgart.de Fri Jan 8 14:12:19 2016 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Fri, 8 Jan 2016 19:12:19 +0000 (UTC) Subject: extract script from executable made by pyinstaller? References: Message-ID: Oscar Benjamin wrote: > On 8 January 2016 at 07:44, Ulli Horlacher > wrote: > > Is it possible to extract (and view) the Python script from the Windows > > executable which was made by pyinstller? > > I may be misremembering but I though that pyinstaller actually stores > the main script uncompressed so that it's just in the raw .exe. No. I tested it already with "strings". -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From naveen.v at maania.com Fri Jan 8 14:23:25 2016 From: naveen.v at maania.com (naveen.v at maania.com) Date: Fri, 8 Jan 2016 11:23:25 -0800 (PST) Subject: Required Python/Backend Engineer, Data in Redwood City, CA -- full time Message-ID: <04d01006-682e-46fd-9d36-53cb21f77ee1@googlegroups.com> Hi , One of our client seeking Python/Backend Engineer, Data in Redwood City, CA If you are interested please send me your updated resume at naveen.v at maania.com along with your expected salary. Title: Python/Backend Engineer, Data Location: Redwood City, CA Full time position Required: ?comfortable in Linux (Ubuntu) environment ?Java, Scala, Python and/or C++ proficiency ?experience using various RDBM and NoSQL dbs and when to use each ?BS or MS in Computer Science, related degree or equivalent experience ?great attitude, team player and ability to thrive and learn in a fast-paced environment From mr.eightnoteight at gmail.com Fri Jan 8 14:26:10 2016 From: mr.eightnoteight at gmail.com (srinivas devaki) Date: Sat, 9 Jan 2016 00:56:10 +0530 Subject: How to remove item from heap efficiently? In-Reply-To: <568FE797.6090808@mail.de> References: <568EEC40.7070807@mail.de> <568FE797.6090808@mail.de> Message-ID: So you need a task scheduler with expiration and priority on each task. Interesting Problem.. as peter said about marking the task in heapB to be deleted. but this needs searching everytime you pop off an old item [complexity: O(len(heapB))]. you may as well use python del on it as complexity is same. But if you already know the where to look in the heapB then you can avoid searching and thereby reducing the complexity. you can do this by saving the references of heapB in heapA and viceversa and if you marking delete on a number of low priority tasks, then it can increase your heapB enormously because being low priority items they can stagnate. to resolve this error you have to perform linear checking iterations at every critical length (this critical length can be obtained mathmatically), so that your amortized complexity of push, pop remains log(number_of_valid_tasks_at_any_time); the number of valid tasks at any time are those tasks which are not expired at the time. My Algorithm: version_a: https://gist.github.com/9ce7a0e534c6e768239e this version has simple scheduler which has methods for popping high priority one and popping oldest task. But this version has a disadvantage, i.e If lets say you are pushed some 10**5 tasks with priority 2, and then pushed some 10**5 tasks with priority 1. and then you decided to pop the oldest 10**5 items. in this version that 10**5 elements will stagnate in priority heap if in future all priorities are less than 1. now this is not a big issue but if you are running a webserver and over a span of 5 days there could be 10**10 tasks, and even if half of those tasks stagnate your server is going to crash with out of memory. version_b: https://gist.github.com/99b4d590753ba234eeed this version resolved that stagnation. this one will run sweeps whenever there are more than half of useless items, thereby giving us an amortized complexity of O(log(n)) for push, pop, etc but this version doesn't have the feature of expiration. version_c: https://gist.github.com/9dfd0d291672c0ffa5c3 in this one we simply keep a variable expiration, and relieve the expired tasks on any operation. i have coded it in such a way that expiration is specific time, you can change it to delta time if you want to. Time Complexity: O(log(n)) insertion, O(log(n)) deletion [amortized] Space Complexity: O(n) [amortized] here n is number of valid items i.e which are not expired. I hope this helps with your problem PS: sorry for posting links, it's just that the code is large for email. I'm using minimum number has highest priority convention. On Fri, Jan 8, 2016 at 10:15 PM, Sven R. Kunze wrote: > Thanks for your suggestion. > > On 08.01.2016 14:21, srinivas devaki wrote: >> >> You can create a single heap with primary key as timestamp and >> secondary key as priority, i.e by creating a tuple >> insert the elements into the heap as >> (timestamp, priority) > > I think I cannot use that because I need the list sorted by both criteria. >> >> If there is any underlying meaning for creating 2 heaps. please mention. > > > I use two heaps because I need to insert arbitrary items fast and remove the > ones fast which are too old (timestamp) or are next in order (priority). > > Basically a task scheduler where tasks can be thrown away once they are too > long in the queue. > > >> On Fri, Jan 8, 2016 at 4:22 AM, Sven R. Kunze wrote: >>> >>> Hi everybody, >>> >>> suppose, I need items sorted by two criteria (say timestamp and >>> priority). >>> For that purpose, I use two heaps (heapq module): >>> >>> heapA # items sorted by timestamp >>> heapB # items sorted by priority >>> >>> Now my actual problem. When popping an item of heapA (that's the oldest >>> item), I need to remove the very same item from heapB, regardlessly where >>> it >>> is in heapB. And vice versa. >>> >>> Is there a datastructure or a simple trick to achieve that in an >>> efficient >>> matter? >>> >>> Best, >>> Sven >>> -- >>> https://mail.python.org/mailman/listinfo/python-list > > From JorgeAlberto.Martinez at ge.com Fri Jan 8 14:41:56 2016 From: JorgeAlberto.Martinez at ge.com (Martinez, Jorge Alberto (GE Aviation)) Date: Fri, 8 Jan 2016 19:41:56 +0000 Subject: licenses Message-ID: <4C734AA4F3F9AC4891265961BD4D48539929AA@CINMBCNA07.e2k.ad.ge.com> Hello We develop applications here with Python and I want to know if there's issues by using. We use NumPy, PyDaqMx, Py Visa How can we cover this licensing? Regards Jorge Alberto Martinez GE Aviation Systems HW Team Manager GEIQ Power Engineering T +52 442 456 6446 E JorgeAlberto.Martinez at ge.com Calle Campo Real #1692, Residencial el Refugio, Quer?taro, Qro, CP 76146 Mexico. GE Imagination at work I have Feedback for GEIQ Jorge Alberto Martinez GE Aviation Systems HW Team Manager GEIQ Power Engineering T +52 442 456 6446 E JorgeAlberto.Martinez at ge.com Calle Campo Real #1692, Residencial el Refugio, Quer?taro, Qro, CP 76146 Mexico. GE Imagination at work I have Feedback for GEIQ From tgunrob at hotmail.co.uk Fri Jan 8 14:56:49 2016 From: tgunrob at hotmail.co.uk (tommy roberts) Date: Fri, 8 Jan 2016 19:56:49 +0000 Subject: No subject Message-ID: It will not allow my to run python 3.5.1 From v+python at g.nevcal.com Fri Jan 8 15:11:52 2016 From: v+python at g.nevcal.com (Glenn Linderman) Date: Fri, 8 Jan 2016 12:11:52 -0800 Subject: EOFError: marshal data too short -- causes? In-Reply-To: References: <56822D4F.8070309@g.nevcal.com> <56823DBC.9010205@g.nevcal.com> <568441DA.9000107@g.nevcal.com> <568EB4AA.4020705@g.nevcal.com> Message-ID: <56901808.5070608@g.nevcal.com> On 1/7/2016 7:44 PM, Dennis Lee Bieber wrote: > On Thu, 7 Jan 2016 10:55:38 -0800, Glenn Linderman > declaimed the following: > >> But all the touched files are .pyc files (and the directories >> __pycache__ directories). None of the source files were modified. So >> why would any .pyc files ever be updated if the source files are not? >> Are there _any_ Python-specific reasons? >> > Two different versions of Python accessing the same modules? That might > induce one to do a rebuild of the .pyc from the .py... Especially if the > variant is something being run (directly or indirectly) from some scheduled > task. Thanks for the idea, but there is only one version of Python installed in that directory structure (and all of my "shared host" portion of the server). > Some conflict with a backup process corrupting files? This seems more possible, simply because I don't understand their backup process. Still, if Python only reads shared, and there'd be no reason for a backup process to do more than read shared, there shouldn't be a conflict... But it seems clear that there _is_ some conflict or some mysterious bug that is triggering something. The installation happened really fast, when I did it, many many files seem to have the same timestamp. Maybe some of the sources are really close in touch time to the .pyc? But still, it seems that would have been resolved long ago... But I could go "touch" all the .pyc to give them nice new timestamps? Maybe I should mark all the current .pyc read-only even to myself? That would prevent them from being rebuilt by Python, and maybe when whatever goes wrong goes wrong, an error would return to the user, but maybe the next access would work.... that'd be better than letting whatever goes wrong modify/corrupt the .pyc, so that _every future_ access fails? Maybe before launching Python I should do a "find ~/py34 --name *.pyc > /dev/null" (or some log file) to cache the directory structure before Python looks at it, and give the mysterious bug a chance to happen with an irrelevant activity? From __peter__ at web.de Fri Jan 8 15:12:18 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 08 Jan 2016 21:12:18 +0100 Subject: What use is '__reduce__'? References: <399e214a-552b-4d4a-a39f-8e917dadd6c6@googlegroups.com> Message-ID: Ian Kelly wrote: > As you found by searching, __reduce__ is used to determine how > instances of the class are pickled. If the example you're using > doesn't do any pickling, then it's not really relevant to the example. > It's probably included so that it won't be missed when the code is > copied. __reduce__() also makes copying work as expected: >>> class OrderedCounter(Counter, OrderedDict): ... 'Counter that remembers the order elements are first seen' ... def __repr__(self): ... return '%s(%r)' % (self.__class__.__name__, ... OrderedDict(self)) ... def __reduce__(self): ... return self.__class__, (OrderedDict(self),) ... >>> oc = OrderedCounter('abracadabra') >>> import copy >>> copy.copy(oc) OrderedCounter(OrderedDict([('a', 5), ('b', 2), ('r', 2), ('c', 1), ('d', 1)])) Now take away the __reduce__ method: >>> del OrderedCounter.__reduce__ >>> copy.copy(oc) OrderedCounter(OrderedDict([('b', 2), ('a', 5), ('c', 1), ('r', 2), ('d', 1)])) From torriem at gmail.com Fri Jan 8 17:28:36 2016 From: torriem at gmail.com (Michael Torrie) Date: Fri, 08 Jan 2016 15:28:36 -0700 Subject: Strange crash while running a script with a embedded python interpreter In-Reply-To: <4ac97a67-2527-424e-90e2-b714528977c8@googlegroups.com> References: <4ac97a67-2527-424e-90e2-b714528977c8@googlegroups.com> Message-ID: <56903814.3040505@gmail.com> On 01/08/2016 09:18 AM, Rickard Englund wrote: > First, some system info > * Windows 7 (also tested on 8 and 10) > * Python 3.5.1 64bit (previously also tested using several 3.x versions) (also tested with 32 bit, but with 3.4.2) > * Microsoft Visual Studio 2015 (earlier version of python also tested with Visual Studio 2013) Are you using the same version of Visual Studio that Python itself was compiled with? If not there can be subtle problems with incompatible msvcrt dlls. No idea if this would be contributing to the problem or not, though. From gheskett at wdtv.com Fri Jan 8 19:19:57 2016 From: gheskett at wdtv.com (Gene Heskett) Date: Fri, 8 Jan 2016 19:19:57 -0500 Subject: OT, but Message-ID: <201601081919.57870.gheskett@wdtv.com> Greetings all; Where can I find the best tut for pyvcp? Thanks all. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From steve at pearwood.info Fri Jan 8 20:25:12 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 09 Jan 2016 12:25:12 +1100 Subject: Unable to access module attribute with underscores in class method, Python 3 References: <568fded7$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5690617b$0$1583$c3e8da3$5496439d@news.astraweb.com> On Sat, 9 Jan 2016 03:16 am, Chris Angelico wrote: > On Sat, Jan 9, 2016 at 3:07 AM, Steven D'Aprano > wrote: >> If you absolutely insist that you must must must continue to use a double >> underscore name, you could also try this: >> >> py> __a = 1 >> py> class Test: >> ... def method(self): >> ... x = eval("__a") >> ... print(x) >> ... >> py> Test().method() >> 1 >> >> >> But don't do that. > > Seriously? You consider that less bad than globals()["__a"]? No. That's why I said "don't do that" rather than "you should do this" :-) > But all of this is craziness to support craziness. It's not asking > which inmate should run the asylum - it's asking which of my multiple > personalities should be elected fourteen-year-old queen. Loretta, surely. -- Steven From pablogormi822 at gmail.com Sat Jan 9 06:40:16 2016 From: pablogormi822 at gmail.com (pablo gormi) Date: Sat, 9 Jan 2016 12:40:16 +0100 Subject: Problem with 'print' Message-ID: Hello, recently I downloaded python, but when I try to execute one file with the command 'print' it shows me a error. The error is: Missing parentheses in call to 'print' Please help mThank you. From rosuav at gmail.com Sat Jan 9 10:09:36 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Jan 2016 02:09:36 +1100 Subject: Problem with 'print' In-Reply-To: References: Message-ID: On Sat, Jan 9, 2016 at 10:40 PM, pablo gormi wrote: > Hello, recently I downloaded python, but when I try to execute one file > with the command 'print' it shows me a error. The error is: > > Missing parentheses in call to 'print' The error is telling you what you need to do. Put parentheses around the call to the print() function. :) ChrisA From darcy at VybeNetworks.com Sat Jan 9 10:19:29 2016 From: darcy at VybeNetworks.com (D'Arcy J.M. Cain) Date: Sat, 9 Jan 2016 10:19:29 -0500 Subject: Problem with 'print' In-Reply-To: References: Message-ID: <20160109101929.2bcb0918@imp> On Sat, 9 Jan 2016 12:40:16 +0100 pablo gormi wrote: > Hello, recently I downloaded python, but when I try to execute one > file with the command 'print' it shows me a error. The error is: > > Missing parentheses in call to 'print' You downloaded Python 3. but your script was written for Python 2.. You have a few choices. Remove Python and install Python 2.7. Edit your script to bring it up to the latest version. Run 2to3 on your script or even whole directories. The first may be the easiest but you will have to do one of the others eventually so I would discourage it. There are plenty of sites (GIYF) that explain the differences between 2 and 3. You can manually edit all of your files. Current Python comes with a program called 2to3 that does 99% of the work for you. You should probably review the changes it makes (capture the output) to see if anything needs to be tweaked. This is definitely the best solution IMO. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From __peter__ at web.de Sat Jan 9 10:26:17 2016 From: __peter__ at web.de (Peter Otten) Date: Sat, 09 Jan 2016 16:26:17 +0100 Subject: Problem with 'print' References: Message-ID: pablo gormi wrote: > Hello, recently I downloaded python, but when I try to execute one file > with the command 'print' it shows me a error. The error is: > > Missing parentheses in call to 'print' > > Please help mThank you. You have downloaded Python 3 and are using Python 2 syntax. Learning Python 3 from a book or tutorial that uses Python 2 is no fun; I recommend that you use another book that covers Python 3. If the book is mandated by your school download Python 2.7 from python.org and work through the examples with that interpreter. Both Python 2.7 and 3.x can be installed in parallel on the same machine, and you can pick up the differences later. From mail at timgolden.me.uk Sat Jan 9 10:50:46 2016 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 9 Jan 2016 15:50:46 +0000 Subject: licenses In-Reply-To: <4C734AA4F3F9AC4891265961BD4D48539929AA@CINMBCNA07.e2k.ad.ge.com> References: <4C734AA4F3F9AC4891265961BD4D48539929AA@CINMBCNA07.e2k.ad.ge.com> Message-ID: <56912C56.7090507@timgolden.me.uk> On 08/01/2016 19:41, Martinez, Jorge Alberto (GE Aviation) wrote: > Hello > We develop applications here with Python and I want to know if there's issues by using. > We use NumPy, PyDaqMx, Py Visa > > How can we cover this licensing? [copying the answer I've just given over at webmaster@] I'm not sure we're best placed to answer that, Jorge. You can see current details for the Python licensing here: https://docs.python.org/3.6/license.html The other packages you mention are third-party and you'll have to consult their websites / source code for licence details. TJG From mail at timgolden.me.uk Sat Jan 9 11:03:39 2016 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 9 Jan 2016 16:03:39 +0000 Subject: Python launcher options In-Reply-To: References: Message-ID: <56912F5B.3010508@timgolden.me.uk> On 06/01/2016 00:48, Edward Diener wrote: > The Python launcher in Windows is a neat tool for running multiple > versions of Python 2 and Python 3 at different times. It allows as > options the ability to specify the latest version of either Python 2 or > Python 3 defaulting to the 64-bit version if both exist, or a specific > 32-bit or 64-bit version of Python 2 or Python 3. What is missing is the > ability to specify the latest 32-bit version of Python 2 or Python 3. > The equivalent syntax would be '-2-32' or '-3-32'. Is there some reason > why this option has been disallowed ? As far as I can remember, it's not so much a question of "disallowed" as just "not thought of by anyone". If you wanted this to go anywhere, could I suggest you create an issue on the Python issue tracker: http://bugs.python.org and mark it as "Windows" in the [Components] field (that makes sure that some relevant people get to see it). It's got a much better chance of achieving traction if you can actually provide a code patch to implement the behaviour. Failing that, at least make a good case which might convince one of the developers that it would it be worth their while implementing the change. TJG From navbhatele at gmail.com Sat Jan 9 12:55:12 2016 From: navbhatele at gmail.com (navneet bhatele) Date: Sat, 9 Jan 2016 23:25:12 +0530 Subject: Python installation in windows Message-ID: I have been trying to install the "python-3.5.1-amd64-webinstall " many times and the Set up failed is shown up with named 0*80070002 - file doesn't exist in dialog box From no.email at nospam.invalid Sat Jan 9 13:32:32 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 09 Jan 2016 10:32:32 -0800 Subject: How to remove item from heap efficiently? References: <568EEC40.7070807@mail.de> Message-ID: <87lh7ywqm7.fsf@nightsong.com> "Sven R. Kunze" writes: > Basically a task scheduler where tasks can be thrown away once they > are too long in the queue. I don't think there's a real nice way to do this with heapq. The computer-sciencey way would involve separate balanced tree structures for the two sorting keys (think of a database table with indexes on two different columns). You could look up "timing wheels" for a simpler practical approach that the Linux kernel scheduler used to use (I think it changed a few years ago). From ahlusar.ahluwalia at gmail.com Sat Jan 9 15:54:09 2016 From: ahlusar.ahluwalia at gmail.com (kbtyo) Date: Sat, 9 Jan 2016 12:54:09 -0800 (PST) Subject: Understanding how to quote XML string in order to serialize using Python's ElementTree Message-ID: My specs: Python 3.4.3 Windows 7 IDE is Jupyter Notebooks What I have referenced: 1) http://stackoverflow.com/questions/1546717/python-escaping-strings-for-use-in-xml 2) http://stackoverflow.com/questions/7802418/how-to-properly-escape-single-and-double-quotes 3)http://stackoverflow.com/questions/4972210/escaping-characters-in-a-xml-file-with-python Here is the data (in CSV format) and script, respectively, (I have tried variations on serializing Column 'E' using both Sax and ElementTree): i) A,B,C,D,E,F,G,H,I,J "3","8","1","2312285SChecking10","0000',0001,0070,","1967-12-25 22:18:13.471000","2005-12-25 22:18:13.768000","2","70","0" ii) #!/usr/bin/python # -*- coding: utf-8 -*- import os.path import sys import csv from io import StringIO import xml.etree.cElementTree as ElementTree from xml.etree.ElementTree import XMLParser import xml import xml.sax from xml.sax import ContentHandler class MyHandler(xml.sax.handler.ContentHandler): def __init__(self): self._charBuffer = [] self._result = [] def _getCharacterData(self): data = ''.join(self._charBuffer).strip() self._charBuffer = [] return data.strip() #remove strip() if whitespace is important def parse(self, f): xml.sax.parse(f, self) return self._result def characters(self, data): self._charBuffer.append(data) def startElement(self, name, attrs): if name == 'Response': self._result.append({}) def endElement(self, name): if not name == 'Response': self._result[-1][name] = self._getCharacterData() def read_data(path): with open(path, 'rU', encoding='utf-8') as data: reader = csv.DictReader(data, delimiter =',', quotechar="'", skipinitialspace=True) for row in reader: yield row if __name__ == "__main__": empty = '' Response = 'sample.csv' for idx, row in enumerate(read_data(Response)): if idx > 10: break data = row['E'] print(data) # The before data = data[1:-1] data = ""'{}'"".format(data) print(data) # Sanity check # data = '0000',0001,0070,' try: root = ElementTree.XML(data) # print(root) except StopIteration: raise pass # xmlstring = StringIO(data) # print(xmlstring) # Handler = MyHandler().parse(xmlstring) Specifically, due to the quoting in the CSV file (which is beyond my control), I have had to resort to slicing the string (line 51) and then formatting it (line 52). However the print out from the above attempt is as follows: "0000' 0000 File "", line unknown ParseError: no element found: line 1, column 69 Interestingly - if I assign the variable "data" (as in line 54) I receive this: File "", line 56 data = '0000',0001,0070,' ^ SyntaxError: invalid token I seek feedback and information on how to address utilizing the most Pythonic means to do so. Ideally, is there a method that can leverage ElementTree. Thank you, in advance, for your feedback and guidance. From ben+python at benfinney.id.au Sat Jan 9 16:50:21 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 10 Jan 2016 08:50:21 +1100 Subject: licenses References: <4C734AA4F3F9AC4891265961BD4D48539929AA@CINMBCNA07.e2k.ad.ge.com> Message-ID: <85io32pgma.fsf@benfinney.id.au> "Martinez, Jorge Alberto (GE Aviation)" writes: > We develop applications here with Python and I want to know if there's > issues by using. We use NumPy, PyDaqMx, Py Visa Those are all free software: meaning, every recipient has freedom to execute, modify, and/or redistribute the work. So long as the code base you derive from them is also free software, you will not need to take special care. If you intend to make a proprietary work (restricting the freedom of recipients further), you should consult your lawyer about how to go about that legally. > How can we cover this licensing? The simplest way ? no need to get lawyers involved ? to comply is to grant a free-software license (e.g. GNU GPL) to all recipients of your work. When you want to derive from an existing work but restrict freedom of your recipients, that's when you need to pay a lawyer for advice. So I advise you don't make such a restrictive work. -- \ ?The way to build large Python applications is to componentize | `\ and loosely-couple the hell out of everything.? ?Aahz | _o__) | Ben Finney From kliateni at gmail.com Sat Jan 9 17:08:26 2016 From: kliateni at gmail.com (Karim) Date: Sat, 9 Jan 2016 23:08:26 +0100 Subject: Understanding how to quote XML string in order to serialize using Python's ElementTree In-Reply-To: References: Message-ID: <569184DA.4080009@gmail.com> On 09/01/2016 21:54, kbtyo wrote: > My specs: > > Python 3.4.3 > Windows 7 > IDE is Jupyter Notebooks > > What I have referenced: > > 1) http://stackoverflow.com/questions/1546717/python-escaping-strings-for-use-in-xml > > 2) > http://stackoverflow.com/questions/7802418/how-to-properly-escape-single-and-double-quotes > > 3)http://stackoverflow.com/questions/4972210/escaping-characters-in-a-xml-file-with-python > > > Here is the data (in CSV format) and script, respectively, (I have tried variations on serializing Column 'E' using both Sax and ElementTree): > > i) > > A,B,C,D,E,F,G,H,I,J > "3","8","1","2312285SChecking10","0000',0001,0070,","1967-12-25 22:18:13.471000","2005-12-25 22:18:13.768000","2","70","0" > > ii) > > #!/usr/bin/python > # -*- coding: utf-8 -*- > import os.path > import sys > import csv > from io import StringIO > import xml.etree.cElementTree as ElementTree > from xml.etree.ElementTree import XMLParser > import xml > import xml.sax > from xml.sax import ContentHandler > > class MyHandler(xml.sax.handler.ContentHandler): > def __init__(self): > self._charBuffer = [] > self._result = [] > > def _getCharacterData(self): > data = ''.join(self._charBuffer).strip() > self._charBuffer = [] > return data.strip() #remove strip() if whitespace is important > > def parse(self, f): > xml.sax.parse(f, self) > return self._result > > > def characters(self, data): > self._charBuffer.append(data) > > def startElement(self, name, attrs): > if name == 'Response': > self._result.append({}) > > def endElement(self, name): > if not name == 'Response': self._result[-1][name] = self._getCharacterData() > > def read_data(path): > with open(path, 'rU', encoding='utf-8') as data: > reader = csv.DictReader(data, delimiter =',', quotechar="'", skipinitialspace=True) > for row in reader: > yield row > > if __name__ == "__main__": > empty = '' > Response = 'sample.csv' > for idx, row in enumerate(read_data(Response)): > if idx > 10: break > data = row['E'] > print(data) # The before > data = data[1:-1] > data = ""'{}'"".format(data) > print(data) # Sanity check > # data = '0000',0001,0070,' > try: > root = ElementTree.XML(data) > # print(root) > except StopIteration: > raise > pass > # xmlstring = StringIO(data) > # print(xmlstring) > # Handler = MyHandler().parse(xmlstring) > > > Specifically, due to the quoting in the CSV file (which is beyond my control), I have had to resort to slicing the string (line 51) and then formatting it (line 52). > > However the print out from the above attempt is as follows: > > "0000' > 0000 > > File "", line unknown > ParseError: no element found: line 1, column 69 > Interestingly - if I assign the variable "data" (as in line 54) I receive this: > > File "", line 56 > data = '0000',0001,0070,' > ^ > SyntaxError: invalid token > > I seek feedback and information on how to address utilizing the most Pythonic means to do so. Ideally, is there a method that can leverage ElementTree. Thank you, in advance, for your feedback and guidance. I don't understand because this line 54 gives: >>> import xml.etree.cElementTree as ElementTree >>> data = '0000',0001,0070,' File "", line 1 data = '0000',0001,0070,' ^ SyntaxError: invalid syntax BUT IF you correct the string and remove the inner quote after 0000 everything's fine: >>> data = '0000,0001,0070, ' >>> root = ElementTree.XML(data) >>> root Karim From kliateni at gmail.com Sat Jan 9 17:23:54 2016 From: kliateni at gmail.com (Karim) Date: Sat, 9 Jan 2016 23:23:54 +0100 Subject: Understanding how to quote XML string in order to serialize using Python's ElementTree In-Reply-To: References: Message-ID: <5691887A.1080203@gmail.com> On 09/01/2016 21:54, kbtyo wrote: > My specs: > > Python 3.4.3 > Windows 7 > IDE is Jupyter Notebooks > > What I have referenced: > > 1) http://stackoverflow.com/questions/1546717/python-escaping-strings-for-use-in-xml > > 2) > http://stackoverflow.com/questions/7802418/how-to-properly-escape-single-and-double-quotes > > 3)http://stackoverflow.com/questions/4972210/escaping-characters-in-a-xml-file-with-python > > > Here is the data (in CSV format) and script, respectively, (I have tried variations on serializing Column 'E' using both Sax and ElementTree): > > i) > > A,B,C,D,E,F,G,H,I,J > "3","8","1","2312285SChecking10","0000',0001,0070,","1967-12-25 22:18:13.471000","2005-12-25 22:18:13.768000","2","70","0" > > ii) > > #!/usr/bin/python > # -*- coding: utf-8 -*- > import os.path > import sys > import csv > from io import StringIO > import xml.etree.cElementTree as ElementTree > from xml.etree.ElementTree import XMLParser > import xml > import xml.sax > from xml.sax import ContentHandler > > class MyHandler(xml.sax.handler.ContentHandler): > def __init__(self): > self._charBuffer = [] > self._result = [] > > def _getCharacterData(self): > data = ''.join(self._charBuffer).strip() > self._charBuffer = [] > return data.strip() #remove strip() if whitespace is important > > def parse(self, f): > xml.sax.parse(f, self) > return self._result > > > def characters(self, data): > self._charBuffer.append(data) > > def startElement(self, name, attrs): > if name == 'Response': > self._result.append({}) > > def endElement(self, name): > if not name == 'Response': self._result[-1][name] = self._getCharacterData() > > def read_data(path): > with open(path, 'rU', encoding='utf-8') as data: > reader = csv.DictReader(data, delimiter =',', quotechar="'", skipinitialspace=True) > for row in reader: > yield row > > if __name__ == "__main__": > empty = '' > Response = 'sample.csv' > for idx, row in enumerate(read_data(Response)): > if idx > 10: break > data = row['E'] > print(data) # The before > data = data[1:-1] > data = ""'{}'"".format(data) > print(data) # Sanity check > # data = '0000',0001,0070,' > try: > root = ElementTree.XML(data) > # print(root) > except StopIteration: > raise > pass > # xmlstring = StringIO(data) > # print(xmlstring) > # Handler = MyHandler().parse(xmlstring) > > > Specifically, due to the quoting in the CSV file (which is beyond my control), I have had to resort to slicing the string (line 51) and then formatting it (line 52). > > However the print out from the above attempt is as follows: > > "0000' > 0000 > > File "", line unknown > ParseError: no element found: line 1, column 69 > Interestingly - if I assign the variable "data" (as in line 54) I receive this: > > File "", line 56 > data = '0000',0001,0070,' > ^ > SyntaxError: invalid token > > I seek feedback and information on how to address utilizing the most Pythonic means to do so. Ideally, is there a method that can leverage ElementTree. Thank you, in advance, for your feedback and guidance. In fact to get rid of double quote simply create your csv reader like that: reader = csv.DictReader(data, dialect='excel', skipinitialspace=True) You should then don't need to slice data variable and reformat it. Karim From cjwilliams43 at gmail.com Sat Jan 9 17:25:40 2016 From: cjwilliams43 at gmail.com (Colin J. Williams) Date: Sat, 9 Jan 2016 14:25:40 -0800 (PST) Subject: Python 3.4.4 Install Message-ID: <64dd3d38-cecd-40ca-bf53-5427d9374a65@googlegroups.com> The reponse is not understood. *** Python 3.4.4rc1 (v3.4.4rc1:04f3f725896c, Dec 6 2015, 17:06:10) [MSC v.1600 64 bit (AMD64)] on win32. *** >>> File "C:\Users\Adm\AppData\Roaming\PyScripter\python_init.py", line 1 ??:V?t??{Z?N)??2%h??L"??w?,????J ^ SyntaxError: invalid syntax File "C:\Users\Adm\AppData\Roaming\PyScripter\pyscripter_init.py", line 1 ??:V?t??{Z?N)?t??2??.?T????????7l??(????? ^ SyntaxError: invalid syntax Help! Colin W. From vgr255 at live.ca Sat Jan 9 17:49:40 2016 From: vgr255 at live.ca (Emanuel Barry) Date: Sat, 9 Jan 2016 17:49:40 -0500 Subject: Python 3.4.4 Install In-Reply-To: <64dd3d38-cecd-40ca-bf53-5427d9374a65@googlegroups.com> References: <64dd3d38-cecd-40ca-bf53-5427d9374a65@googlegroups.com> Message-ID: > Date: Sat, 9 Jan 2016 14:25:40 -0800 > Subject: Python 3.4.4 Install > From: cjwilliams43 at gmail.com > To: python-list at python.org > > The reponse is not understood. Which response? Obviously Python's, but response to what? More context would be useful. > *** Python 3.4.4rc1 (v3.4.4rc1:04f3f725896c, Dec 6 2015, 17:06:10) [MSC v.1600 64 bit (AMD64)] on win32. *** > >>> File "C:\Users\Adm\AppData\Roaming\PyScripter\python_init.py", line 1 > ??:V?t??{Z?N)??2%h??L"??w?,????J > ^ > SyntaxError: invalid syntax > File "C:\Users\Adm\AppData\Roaming\PyScripter\pyscripter_init.py", line 1 > ??:V?t??{Z?N)?t??2??.?T????????7l??(????? > ^ > SyntaxError: invalid syntax What is this file, and where does it come from? What command are you issuing that gives you this result? -- Emanuel From tjreedy at udel.edu Sat Jan 9 17:54:41 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 9 Jan 2016 17:54:41 -0500 Subject: Python 3.4.4 Install In-Reply-To: <64dd3d38-cecd-40ca-bf53-5427d9374a65@googlegroups.com> References: <64dd3d38-cecd-40ca-bf53-5427d9374a65@googlegroups.com> Message-ID: On 1/9/2016 5:25 PM, Colin J. Williams wrote: > The reponse is not understood. What part of 'SyntaxError: invalid syntax' do you not understand? > *** Python 3.4.4rc1 (v3.4.4rc1:04f3f725896c, Dec 6 2015, 17:06:10) [MSC v.1600 64 bit (AMD64)] on win32. *** Consider replacing with 3.4.4, though not essential. > File "C:\Users\Adm\AppData\Roaming\PyScripter\python_init.py", line 1 This issue seems to be about PyScriptor, not 3.4. > ??:V?t??{Z?N)??2%h??L"??w?,????J > ^ This is obviously gibberish as interpreted. Perhaps you should re-install PyScriptor. Make sure you have a version meant to run with 3.x rather than 2.x. > SyntaxError: invalid syntax 'ab:' will give the same error in the same place. A colon cannot follow an identifier at the beginning of a line. -- Terry Jan Reedy From ahlusar.ahluwalia at gmail.com Sat Jan 9 18:13:29 2016 From: ahlusar.ahluwalia at gmail.com (Saran Ahluwalia) Date: Sat, 9 Jan 2016 18:13:29 -0500 Subject: Understanding how to quote XML string in order to serialize using Python's ElementTree In-Reply-To: <569184DA.4080009@gmail.com> References: <569184DA.4080009@gmail.com> Message-ID: As mentioned previously, I assigned the variable *data *to the string ''0000',0001,0070,". When any utility that attempts to parse this string (this is one example of millions found in my actual data source) you receive that error. You would need to comment out the following: data = row['E'] print(data) # The before data = data[1:-1] data = ""'{}'"".format(data) print(data) # Sanity check to achieve the readout. Unfortunately, I am wondering if there is a scalable solution to the above issue (perhaps using some form of escape character or regex?). I have ideas and have tried many but to no avail. There always seems to be an edge case that escapes me. Thanks. On Sat, Jan 9, 2016 at 5:08 PM, Karim wrote: > > > On 09/01/2016 21:54, kbtyo wrote: > >> My specs: >> >> Python 3.4.3 >> Windows 7 >> IDE is Jupyter Notebooks >> >> What I have referenced: >> >> 1) >> http://stackoverflow.com/questions/1546717/python-escaping-strings-for-use-in-xml >> >> 2) >> >> http://stackoverflow.com/questions/7802418/how-to-properly-escape-single-and-double-quotes >> >> 3) >> http://stackoverflow.com/questions/4972210/escaping-characters-in-a-xml-file-with-python >> >> >> Here is the data (in CSV format) and script, respectively, (I have tried >> variations on serializing Column 'E' using both Sax and ElementTree): >> >> i) >> >> A,B,C,D,E,F,G,H,I,J >> "3","8","1","> />2312> />285SChecking10","> TransactionID="2" >> RequestType="HoldInquiry">0000',0001,0070,","1967-12-25 >> 22:18:13.471000","2005-12-25 22:18:13.768000","2","70","0" >> >> ii) >> >> #!/usr/bin/python >> # -*- coding: utf-8 -*- >> import os.path >> import sys >> import csv >> from io import StringIO >> import xml.etree.cElementTree as ElementTree >> from xml.etree.ElementTree import XMLParser >> import xml >> import xml.sax >> from xml.sax import ContentHandler >> >> class MyHandler(xml.sax.handler.ContentHandler): >> def __init__(self): >> self._charBuffer = [] >> self._result = [] >> >> def _getCharacterData(self): >> data = ''.join(self._charBuffer).strip() >> self._charBuffer = [] >> return data.strip() #remove strip() if whitespace is important >> >> def parse(self, f): >> xml.sax.parse(f, self) >> return self._result >> >> def characters(self, data): >> self._charBuffer.append(data) >> >> def startElement(self, name, attrs): >> if name == 'Response': >> self._result.append({}) >> >> def endElement(self, name): >> if not name == 'Response': self._result[-1][name] = >> self._getCharacterData() >> >> def read_data(path): >> with open(path, 'rU', encoding='utf-8') as data: >> reader = csv.DictReader(data, delimiter =',', quotechar="'", >> skipinitialspace=True) >> for row in reader: >> yield row >> >> if __name__ == "__main__": >> empty = '' >> Response = 'sample.csv' >> for idx, row in enumerate(read_data(Response)): >> if idx > 10: break >> data = row['E'] >> print(data) # The before >> data = data[1:-1] >> data = ""'{}'"".format(data) >> print(data) # Sanity check >> # data = '> RequestType="HoldInquiry">0000',0001,0070,' >> try: >> root = ElementTree.XML(data) >> # print(root) >> except StopIteration: >> raise >> pass >> # xmlstring = StringIO(data) >> # print(xmlstring) >> # Handler = MyHandler().parse(xmlstring) >> >> >> Specifically, due to the quoting in the CSV file (which is beyond my >> control), I have had to resort to slicing the string (line 51) and then >> formatting it (line 52). >> >> However the print out from the above attempt is as follows: >> >> "0000' >> 0000 >> >> File "", line unknown >> ParseError: no element found: line 1, column 69 >> Interestingly - if I assign the variable "data" (as in line 54) I receive >> this: >> >> File "", line 56 >> data = '> RequestType="HoldInquiry">0000',0001,0070,' >> ^ >> SyntaxError: invalid token >> >> I seek feedback and information on how to address utilizing the most >> Pythonic means to do so. Ideally, is there a method that can leverage >> ElementTree. Thank you, in advance, for your feedback and guidance. >> > > I don't understand because this line 54 gives: > > >>> import xml.etree.cElementTree as ElementTree > >>> data = ' RequestType="HoldInquiry">0000',0001,0070,' > File "", line 1 > data = ' RequestType="HoldInquiry">0000',0001,0070,' > ^ > SyntaxError: invalid syntax > > > BUT IF you correct the string and remove the inner quote after 0000 > everything's fine: > >>> data = ' RequestType="HoldInquiry">0000,0001,0070, > ' > >>> root = ElementTree.XML(data) > >>> root > > Karim > > From ahlusar.ahluwalia at gmail.com Sat Jan 9 18:15:03 2016 From: ahlusar.ahluwalia at gmail.com (Saran Ahluwalia) Date: Sat, 9 Jan 2016 18:15:03 -0500 Subject: Understanding how to quote XML string in order to serialize using Python's ElementTree In-Reply-To: <5691887A.1080203@gmail.com> References: <5691887A.1080203@gmail.com> Message-ID: Thank you for the feedback on this. I believe that the excel dialect includes just that: class excel(Dialect): delimiter = ',' quotechar = '"' doublequote = True skipinitialspace = False lineterminator = '\r\n' quoting = QUOTE_MINIMAL On Sat, Jan 9, 2016 at 5:23 PM, Karim wrote: > > > On 09/01/2016 21:54, kbtyo wrote: > >> My specs: >> >> Python 3.4.3 >> Windows 7 >> IDE is Jupyter Notebooks >> >> What I have referenced: >> >> 1) >> http://stackoverflow.com/questions/1546717/python-escaping-strings-for-use-in-xml >> >> 2) >> >> http://stackoverflow.com/questions/7802418/how-to-properly-escape-single-and-double-quotes >> >> 3) >> http://stackoverflow.com/questions/4972210/escaping-characters-in-a-xml-file-with-python >> >> >> Here is the data (in CSV format) and script, respectively, (I have tried >> variations on serializing Column 'E' using both Sax and ElementTree): >> >> i) >> >> A,B,C,D,E,F,G,H,I,J >> "3","8","1","> />2312> />285SChecking10","> TransactionID="2" >> RequestType="HoldInquiry">0000',0001,0070,","1967-12-25 >> 22:18:13.471000","2005-12-25 22:18:13.768000","2","70","0" >> >> ii) >> >> #!/usr/bin/python >> # -*- coding: utf-8 -*- >> import os.path >> import sys >> import csv >> from io import StringIO >> import xml.etree.cElementTree as ElementTree >> from xml.etree.ElementTree import XMLParser >> import xml >> import xml.sax >> from xml.sax import ContentHandler >> >> class MyHandler(xml.sax.handler.ContentHandler): >> def __init__(self): >> self._charBuffer = [] >> self._result = [] >> >> def _getCharacterData(self): >> data = ''.join(self._charBuffer).strip() >> self._charBuffer = [] >> return data.strip() #remove strip() if whitespace is important >> >> def parse(self, f): >> xml.sax.parse(f, self) >> return self._result >> >> def characters(self, data): >> self._charBuffer.append(data) >> >> def startElement(self, name, attrs): >> if name == 'Response': >> self._result.append({}) >> >> def endElement(self, name): >> if not name == 'Response': self._result[-1][name] = >> self._getCharacterData() >> >> def read_data(path): >> with open(path, 'rU', encoding='utf-8') as data: >> reader = csv.DictReader(data, delimiter =',', quotechar="'", >> skipinitialspace=True) >> for row in reader: >> yield row >> >> if __name__ == "__main__": >> empty = '' >> Response = 'sample.csv' >> for idx, row in enumerate(read_data(Response)): >> if idx > 10: break >> data = row['E'] >> print(data) # The before >> data = data[1:-1] >> data = ""'{}'"".format(data) >> print(data) # Sanity check >> # data = '> RequestType="HoldInquiry">0000',0001,0070,' >> try: >> root = ElementTree.XML(data) >> # print(root) >> except StopIteration: >> raise >> pass >> # xmlstring = StringIO(data) >> # print(xmlstring) >> # Handler = MyHandler().parse(xmlstring) >> >> >> Specifically, due to the quoting in the CSV file (which is beyond my >> control), I have had to resort to slicing the string (line 51) and then >> formatting it (line 52). >> >> However the print out from the above attempt is as follows: >> >> "0000' >> 0000 >> >> File "", line unknown >> ParseError: no element found: line 1, column 69 >> Interestingly - if I assign the variable "data" (as in line 54) I receive >> this: >> >> File "", line 56 >> data = '> RequestType="HoldInquiry">0000',0001,0070,' >> ^ >> SyntaxError: invalid token >> >> I seek feedback and information on how to address utilizing the most >> Pythonic means to do so. Ideally, is there a method that can leverage >> ElementTree. Thank you, in advance, for your feedback and guidance. >> > > In fact to get rid of double quote simply create your csv reader like > that: > > reader = csv.DictReader(data, dialect='excel', skipinitialspace=True) > > You should then don't need to slice data variable and reformat it. > > Karim > > > From kliateni at gmail.com Sat Jan 9 18:30:48 2016 From: kliateni at gmail.com (Karim) Date: Sun, 10 Jan 2016 00:30:48 +0100 Subject: Understanding how to quote XML string in order to serialize using Python's ElementTree In-Reply-To: References: <5691887A.1080203@gmail.com> Message-ID: <56919828.5010409@gmail.com> Yes it changes your quotechar = "'" into quotechar = '"' You should no more get the double quoting of the data string and no more slicing step. Karim On 10/01/2016 00:15, Saran Ahluwalia wrote: > Thank you for the feedback on this. I believe that the excel dialect > includes just that: > > class excel(Dialect): > delimiter = ',' > quotechar = '"' > doublequote = True > skipinitialspace = False > lineterminator = '\r\n' > quoting = QUOTE_MINIMAL > > On Sat, Jan 9, 2016 at 5:23 PM, Karim > wrote: > > > > On 09/01/2016 21:54, kbtyo wrote: > > My specs: > > Python 3.4.3 > Windows 7 > IDE is Jupyter Notebooks > > What I have referenced: > > 1) > http://stackoverflow.com/questions/1546717/python-escaping-strings-for-use-in-xml > > 2) > http://stackoverflow.com/questions/7802418/how-to-properly-escape-single-and-double-quotes > > 3)http://stackoverflow.com/questions/4972210/escaping-characters-in-a-xml-file-with-python > > > Here is the data (in CSV format) and script, respectively, (I > have tried variations on serializing Column 'E' using both Sax > and ElementTree): > > i) > > A,B,C,D,E,F,G,H,I,J > "3","8","1"," RequestType="FOO"> />2312 />285SChecking10"," TransactionID="2" > RequestType="HoldInquiry">0000',0001,0070,","1967-12-25 > 22:18:13.471000","2005-12-25 22:18:13.768000","2","70","0" > > ii) > > #!/usr/bin/python > # -*- coding: utf-8 -*- > import os.path > import sys > import csv > from io import StringIO > import xml.etree.cElementTree as ElementTree > from xml.etree.ElementTree import XMLParser > import xml > import xml.sax > from xml.sax import ContentHandler > > class MyHandler(xml.sax.handler.ContentHandler): > def __init__(self): > self._charBuffer = [] > self._result = [] > > def _getCharacterData(self): > data = ''.join(self._charBuffer).strip() > self._charBuffer = [] > return data.strip() #remove strip() if whitespace is > important > > def parse(self, f): > xml.sax.parse(f, self) > return self._result > > def characters(self, data): > self._charBuffer.append(data) > > def startElement(self, name, attrs): > if name == 'Response': > self._result.append({}) > > def endElement(self, name): > if not name == 'Response': self._result[-1][name] = > self._getCharacterData() > > def read_data(path): > with open(path, 'rU', encoding='utf-8') as data: > reader = csv.DictReader(data, delimiter =',', > quotechar="'", skipinitialspace=True) > for row in reader: > yield row > > if __name__ == "__main__": > empty = '' > Response = 'sample.csv' > for idx, row in enumerate(read_data(Response)): > if idx > 10: break > data = row['E'] > print(data) # The before > data = data[1:-1] > data = ""'{}'"".format(data) > print(data) # Sanity check > # data = ' RequestType="HoldInquiry">0000',0001,0070,' > try: > root = ElementTree.XML(data) > # print(root) > except StopIteration: > raise > pass > # xmlstring = StringIO(data) > # print(xmlstring) > # Handler = MyHandler().parse(xmlstring) > > > Specifically, due to the quoting in the CSV file (which is > beyond my control), I have had to resort to slicing the string > (line 51) and then formatting it (line 52). > > However the print out from the above attempt is as follows: > > " RequestType="HoldInquiry">0000' > RequestType="HoldInquiry">0000 > > File "", line unknown > ParseError: no element found: line 1, column 69 > Interestingly - if I assign the variable "data" (as in line > 54) I receive this: > > File "", line 56 > data = ' RequestType="HoldInquiry">0000',0001,0070,' > ^ > SyntaxError: invalid token > > I seek feedback and information on how to address utilizing > the most Pythonic means to do so. Ideally, is there a method > that can leverage ElementTree. Thank you, in advance, for your > feedback and guidance. > > > In fact to get rid of double quote simply create your csv reader > like that: > > reader = csv.DictReader(data, dialect='excel', skipinitialspace=True) > > You should then don't need to slice data variable and reformat it. > > Karim > > > From paul.hermeneutic at gmail.com Sat Jan 9 18:46:22 2016 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Sat, 9 Jan 2016 16:46:22 -0700 Subject: No subject In-Reply-To: References: Message-ID: On Jan 9, 2016 7:56 AM, "tommy roberts" wrote: > > It will not allow my to run python 3.5.1 Python 3.4 is the last version that will run on Windows XP. If this is not your problem, please provide more information. From rxjwg98 at gmail.com Sat Jan 9 20:45:59 2016 From: rxjwg98 at gmail.com (Robert) Date: Sat, 9 Jan 2016 17:45:59 -0800 (PST) Subject: Help on return type(?) Message-ID: <68eca1ab-afd1-4bfb-af48-5ae41047ddad@googlegroups.com> Hi, I see below code snippet. The return line is not as the usual type. def make_cov(cov_type, n_comp, n_fea): mincv = 0.1 rand = np.random.random return { 'spherical': (mincv + mincv * np.dot(rand((n_components, 1)), np.ones((1, n_features)))) ** 2, 'tied': (make_spd_matrix(n_features) + mincv * np.eye(n_features)), 'diag': (mincv + mincv * rand((n_components, n_features))) ** 2, 'full': np.array([(make_spd_matrix(n_features) + mincv * np.eye(n_features)) for x in range(n_components)]) }[cov_type] Specifically, could you explain the meaning of { ... }[cov_type] to me? Thanks, From steve at pearwood.info Sat Jan 9 21:10:45 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jan 2016 13:10:45 +1100 Subject: licenses References: Message-ID: <5691bda5$0$1588$c3e8da3$5496439d@news.astraweb.com> On Sat, 9 Jan 2016 06:41 am, Martinez, Jorge Alberto (GE Aviation) wrote: > Hello > We develop applications here with Python and I want to know if there's > issues by using. We use NumPy, PyDaqMx, Py Visa > > How can we cover this licensing? What do you do with those applications? Do you use them in-house, for customers, or for sale? Do you distribute NumPy, PyDaqMx and PyVisa? If you do, then you have to abide by the terms of their licences. Have you read their licences? If not, you need to read them. Then you need to talk to your company's lawyer and get their advice. *** I AM NOT A LAWYER AND THIS IS NOT LEGAL ADVICE *** Seriously, talk to your lawyer. She or he is the only person who can SAFELY and ACCURATELY advise you. But, I would expect that you *probably* can legally distribute Numpy, since there are other companies which already do this. Numpy is distributed under the BSD licence, which is very liberal, and is compatible with most software licences (either free, copyleft, or proprietary/closed). It allows re-use with very few restrictions, so you shouldn't have any trouble obeying their terms in your own software. http://www.numpy.org/license.html The licence is in English, but it is very simple, less than one page. If you include Numpy in your software, all you need to do is include a copy of the Numpy licence. Read the licence for details. I do not know about PyDaqMx and PyVisa, but my recommendation is the same: - start by reading their licences; - if they use a well-known Open Source licence, such as BSD, MIT or GPL, you must obey the terms of the licence; - If they use a rare or unknown open source licence, you probably should not trust that the licence gives you enough protection. You should contact the project owner and ask him or her to give you a licence to the work using an approved open source licence: http://opensource.org/licenses/ - If they use a proprietary, closed-source licence, you probably will not be allowed to distribute their software, or you may have to pay them money. You still have to obey the licence. - But if there are special conditions that apply to you, it doesn't hurt for you to ask for a special licence. The worst that will happen is that they will ignore you, or say no. And finally: - Check with your lawyer. -- Steven From steve at pearwood.info Sat Jan 9 21:19:59 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jan 2016 13:19:59 +1100 Subject: Python 3.4.4 Install References: <64dd3d38-cecd-40ca-bf53-5427d9374a65@googlegroups.com> Message-ID: <5691bfd0$0$1603$c3e8da3$5496439d@news.astraweb.com> On Sun, 10 Jan 2016 09:25 am, Colin J. Williams wrote: > The reponse is not understood. > > *** Python 3.4.4rc1 (v3.4.4rc1:04f3f725896c, Dec 6 2015, 17:06:10) [MSC > v.1600 64 bit (AMD64)] on win32. *** >>>> File "C:\Users\Adm\AppData\Roaming\PyScripter\python_init.py", line 1 > ??:V?t??{Z?N)??2%h??L"??w?,????J > ^ > SyntaxError: invalid syntax That doesn't look anything like Python code to me. It looks like you have corrupted files. Who knows how they have been corrupted. Try re-installing Pyscripter, or revert from backup. Also, you should make sure you scan your system for viruses (possibly you have a randsomware virus encrypting files behind your back) and do a disk check in case the disk is dying. -- Steven From steve at pearwood.info Sat Jan 9 21:23:24 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jan 2016 13:23:24 +1100 Subject: Help on return type(?) References: <68eca1ab-afd1-4bfb-af48-5ae41047ddad@googlegroups.com> Message-ID: <5691c09c$0$1603$c3e8da3$5496439d@news.astraweb.com> On Sun, 10 Jan 2016 12:45 pm, Robert wrote: > Hi, > > I see below code snippet. The return line is not as the usual type. > > > > def make_cov(cov_type, n_comp, n_fea): > mincv = 0.1 > rand = np.random.random > return { > 'spherical': (mincv + mincv * np.dot(rand((n_components, 1)), > np.ones((1, n_features)))) ** > 2, > 'tied': (make_spd_matrix(n_features) > + mincv * np.eye(n_features)), > 'diag': (mincv + mincv * rand((n_components, n_features))) ** 2, > 'full': np.array([(make_spd_matrix(n_features) > + mincv * np.eye(n_features)) > for x in range(n_components)]) > }[cov_type] > > Specifically, could you explain the meaning of > > { > ... }[cov_type] > > to me? It is a dictionary lookup. { ... } sets up a dictionary with keys 'spherical' 'tied' 'diag' 'full' then { ... }[cov_type] extracts one of the values depending on whether cov_type is 'spherical', 'tied', 'diag', or 'full'. -- Steven From martin at linux-ip.net Sat Jan 9 22:10:42 2016 From: martin at linux-ip.net (Martin A. Brown) Date: Sat, 9 Jan 2016 19:10:42 -0800 Subject: Help on return type(?) In-Reply-To: <5691c09c$0$1603$c3e8da3$5496439d@news.astraweb.com> References: <68eca1ab-afd1-4bfb-af48-5ae41047ddad@googlegroups.com> <5691c09c$0$1603$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hello there, >> def make_cov(cov_type, n_comp, n_fea): >> mincv = 0.1 >> rand = np.random.random >> return { >> 'spherical': (mincv + mincv * np.dot(rand((n_components, 1)), >> np.ones((1, n_features)))) ** >> 2, >> 'tied': (make_spd_matrix(n_features) >> + mincv * np.eye(n_features)), >> 'diag': (mincv + mincv * rand((n_components, n_features))) ** 2, >> 'full': np.array([(make_spd_matrix(n_features) >> + mincv * np.eye(n_features)) >> for x in range(n_components)]) >> }[cov_type] >> >> Specifically, could you explain the meaning of >> >> { >> ... }[cov_type] >> >> to me? > >It is a dictionary lookup. { ... } sets up a dictionary with keys > > 'spherical' > 'tied' > 'diag' > 'full' > >then { ... }[cov_type] extracts one of the values depending on >whether cov_type is 'spherical', 'tied', 'diag', or 'full'. You will see that Steven has answered your question. I will add to his answer. Your original function could be improved many ways, but especially in terms of readability. Here's how I might go at improving the readability, without understanding anything about the actual computation. def make_cov_spherical(mincv, n_components, n_features): return (mincv + mincv * np.dot(np.random.random((n_components, 1)), np.ones((1, n_features)))) ** 2 def make_cov_diag(mincv, n_components, n_features): return (mincv + mincv * np.random.random((n_components, n_features))) ** 2 def make_cov_tied(mincv, n_components, n_features): return make_spd_matrix(n_features) + mincv * np.eye(n_features) def make_cov_full(mincv, n_components, n_features): return np.array([(make_spd_matrix(n_features) + mincv * np.eye(n_features)) for x in range(n_components)]) def make_cov(cov_type, n_comp, n_fea): mincv = 0.1 dispatch_table = { 'spherical': make_cov_spherical, 'tied': make_cov_tied, 'diag': make_cov_diag, 'full': make_cov_full, } func = dispatch_table[cov_type] return func(mincv, n_comp, n_fea) Some thoughts (and reaction to the prior code): * Your originally posted code referred to n_comp and n_fea in the signature, but then used n_components and n_features in the processing lines. Did this function ever work? * Individual functions are easier to read and understand. I would find it easier to write testing code (and docstrings) for these functions, also. * The assignment of a name (rand = np.random.random) can make sense, but I think it simply shows that the original function was trying to do too many things and was hoping to save space with this shorter name for the np.random.random. Not bad, but I dropped it anyway for the sake of clarity. * Each of the above functions (which I copied nearly verbatim) could probably now be broken into one or two lines. That would make the computation even clearer. * There may be a better way to make a function dispatch table than the one I demonstrate above, but I think it makes the point nicely. * If you break the individual computations into functions, then you only run the specific computation when it's needed. In the original example, all of the computations were run AND then, one of the results was selected. It may not matter, since computers are so fast, but, practicing basic parsimony can avoid little obvious performance hazards like this. * In short, longer, but much much clearer. Good luck, -Martin -- Martin A. Brown http://linux-ip.net/ From rustompmody at gmail.com Sat Jan 9 22:17:52 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 9 Jan 2016 19:17:52 -0800 (PST) Subject: Help on return type(?) In-Reply-To: <68eca1ab-afd1-4bfb-af48-5ae41047ddad@googlegroups.com> References: <68eca1ab-afd1-4bfb-af48-5ae41047ddad@googlegroups.com> Message-ID: <22a61e46-544e-44f4-b23a-ef2d000f3122@googlegroups.com> On Sunday, January 10, 2016 at 7:16:23 AM UTC+5:30, Robert wrote: > Hi, > > I see below code snippet. The return line is not as the usual type. > > > > def make_cov(cov_type, n_comp, n_fea): > mincv = 0.1 > rand = np.random.random > return { > 'spherical': (mincv + mincv * np.dot(rand((n_components, 1)), > np.ones((1, n_features)))) ** 2, > 'tied': (make_spd_matrix(n_features) > + mincv * np.eye(n_features)), > 'diag': (mincv + mincv * rand((n_components, n_features))) ** 2, > 'full': np.array([(make_spd_matrix(n_features) > + mincv * np.eye(n_features)) > for x in range(n_components)]) > }[cov_type] > > Specifically, could you explain the meaning of > > { > ... }[cov_type] > > to me? > > > Thanks, May help if you see it in pseudo-C like this switch (cov_type) case 'spherical': return (mincv + mincv * np.dot(rand((n_components, 1)), np.ones((1, n_features)))) ** 2, case 'tied': return (make_spd_matrix(n_features) + mincv * np.eye(n_features)), case 'diag': return (mincv + mincv * rand((n_components, n_features))) ** 2, case 'full': return np.array([(make_spd_matrix(n_features) + mincv * np.eye(n_features)) for x in range(n_components)]) Yeah looks backward in python compared to the C-ish The python is more powerful however because its *data-driven* ie what is code in C is data in python. BTW this is one of the motley components collected together under the somewhat inept moniker of 'functional programming': http://blog.languager.org/2012/10/functional-programming-lost-booty.html Also you can make the python look less backward by naming the dictionary, separate from the lookup: d = {'spherical' : ..., 'tied' :..., 'diag' : ...} return d[cov_type] From eldiener at tropicsoft.invalid Sun Jan 10 00:18:30 2016 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 10 Jan 2016 00:18:30 -0500 Subject: Python launcher options In-Reply-To: References: Message-ID: On 1/9/2016 11:03 AM, Tim Golden wrote: > On 06/01/2016 00:48, Edward Diener wrote: >> The Python launcher in Windows is a neat tool for running multiple >> versions of Python 2 and Python 3 at different times. It allows as >> options the ability to specify the latest version of either Python 2 or >> Python 3 defaulting to the 64-bit version if both exist, or a specific >> 32-bit or 64-bit version of Python 2 or Python 3. What is missing is the >> ability to specify the latest 32-bit version of Python 2 or Python 3. >> The equivalent syntax would be '-2-32' or '-3-32'. Is there some reason >> why this option has been disallowed ? > > As far as I can remember, it's not so much a question of "disallowed" as > just "not thought of by anyone". If you wanted this to go anywhere, > could I suggest you create an issue on the Python issue tracker: > > http://bugs.python.org > > and mark it as "Windows" in the [Components] field (that makes sure that > some relevant people get to see it). It's got a much better chance of > achieving traction if you can actually provide a code patch to implement > the behaviour. Failing that, at least make a good case which might > convince one of the developers that it would it be worth their while > implementing the change. I have tried to register with the link above so I can an issue with the Python Issue tracker but all attempts fail with: "Failed issue tracker submission An unexpected error occurred during the processing of your message. The tracker administrator is being notified." From palpandi111 at gmail.com Sun Jan 10 01:28:53 2016 From: palpandi111 at gmail.com (Palpandi) Date: Sat, 9 Jan 2016 22:28:53 -0800 (PST) Subject: pyd file for python package using cython Message-ID: Hi All, I have a package structure, A ( uses files from B and C) B ( init.py, a,py, b.py) C ( init.py, c.py, d.py) How to create a pyd file structure for above package structure? Is it possible to create a single pyd file? Do I need cython to run pyd file? Thanks. From lucifer.onetwothree at gmail.com Sun Jan 10 02:02:26 2016 From: lucifer.onetwothree at gmail.com (Lucifer onetwothree) Date: Sun, 10 Jan 2016 12:32:26 +0530 Subject: Continously opening modify setup Message-ID: When ever i open pycharm there is a pop-up opening continously with modify,repair,unistall options in it.even I've installed python correctly and specified path correctly. Please help me to sort this out. From arsh840 at gmail.com Sun Jan 10 02:29:53 2016 From: arsh840 at gmail.com (Arshpreet Singh) Date: Sat, 9 Jan 2016 23:29:53 -0800 (PST) Subject: When I need classes? Message-ID: Hello Friends, I am quite new to OOP(object oriented Programming), I did some projects with python which includes Data-Analysis, Flask Web Development and some simple scripts. I have only one question which is bothering me most of the time, When I will get the need to use Classes in Python? Or in other way is there any real-life example where you can tell me this problem/solution is kind of impossible in Python without Classes? From PointedEars at web.de Sun Jan 10 04:22:39 2016 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sun, 10 Jan 2016 10:22:39 +0100 Subject: licenses References: <4C734AA4F3F9AC4891265961BD4D48539929AA@CINMBCNA07.e2k.ad.ge.com> Message-ID: <5329709.fk8d0DcqZu@PointedEars.de> Ben Finney wrote: > "Martinez, Jorge Alberto (GE Aviation)" [?] writes: >> We develop applications here with Python and I want to know if there's >> issues by using. We use NumPy, PyDaqMx, Py Visa > > Those are all free software: meaning, every recipient has freedom to > execute, modify, and/or redistribute the work. Correct. > So long as the code base you derive from them is also free software, you > will not need to take special care. No, not all free software licenses (FSLs) are compatible with each other. Most notably, not all FSLs are compatible with the GNU General Public License (GPL), which also is a FSL. Software licenses are distinguished whether they are closed source or open source licenses, free or unfree, and enforce copyright or copyleft (the GPL are/does the latter, respectively). Also, patent issues have to be considered: Some free software licenses, like the Apache License, include stipulations that the grated patent license is void if the licensee sues the licenser for patent infringement; other licenses do not. A quick Google search shows: - NumPy is licensed under the ?BSD-new license?. - PyDAQmx can be licensed under either ,- | | (1) The BSD license. | (2) Any other license, as long as it is obtained from the original | author. - PyVISA is licensed under ?The MIT License? (X11 License) See also: IANAL. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From mail at timgolden.me.uk Sun Jan 10 06:38:51 2016 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 10 Jan 2016 11:38:51 +0000 Subject: Python launcher options In-Reply-To: References: Message-ID: <569242CB.7020403@timgolden.me.uk> On 10/01/2016 05:18, Edward Diener wrote: > On 1/9/2016 11:03 AM, Tim Golden wrote: >> On 06/01/2016 00:48, Edward Diener wrote: >>> The Python launcher in Windows is a neat tool for running multiple >>> versions of Python 2 and Python 3 at different times. It allows as >>> options the ability to specify the latest version of either Python 2 or >>> Python 3 defaulting to the 64-bit version if both exist, or a specific >>> 32-bit or 64-bit version of Python 2 or Python 3. What is missing is the >>> ability to specify the latest 32-bit version of Python 2 or Python 3. >>> The equivalent syntax would be '-2-32' or '-3-32'. Is there some reason >>> why this option has been disallowed ? >> >> As far as I can remember, it's not so much a question of "disallowed" as >> just "not thought of by anyone". If you wanted this to go anywhere, >> could I suggest you create an issue on the Python issue tracker: >> >> http://bugs.python.org >> >> and mark it as "Windows" in the [Components] field (that makes sure that >> some relevant people get to see it). It's got a much better chance of >> achieving traction if you can actually provide a code patch to implement >> the behaviour. Failing that, at least make a good case which might >> convince one of the developers that it would it be worth their while >> implementing the change. > > I have tried to register with the link above so I can an issue with the > Python Issue tracker but all attempts fail with: > > "Failed issue tracker submission > > An unexpected error occurred during the processing > of your message. The tracker administrator is being > notified." Hmmm. Thanks for making the effort -- and for reporting back. I've just successfully registered a (dummy) account there, so it's possible that there was a temporary glitch. If you wouldn't mind trying once more, that would be helpful. If not, I can create the issue on your behalf, and inform the tracker admins. Thanks TJG From ganesh1pal at gmail.com Sun Jan 10 08:41:03 2016 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Sun, 10 Jan 2016 19:11:03 +0530 Subject: Fwd: python unit test framework sample code In-Reply-To: References: Message-ID: Apologies, looks like I did a reply instead of reply-all. So forwarding this email , please provide guidance on the same ---------- Forwarded message ---------- From: Ganesh Pal Date: Thu, Jan 7, 2016 at 12:26 PM Subject: Re: python unit test framework sample code To: Terry Reedy > Unless you have a large program already in 2.6 and are just adding tests > (perhaps so you can more easily upgrade someday), consider upgrading to a > newer version. Sure , but for now Iam limited to use 2.6 , hence I cant upgrade need to work with 2.6 >> >> class FileSystemTest(unittest2.TestCase): >> block_address = {} >> report = "" >> >> @classmethod >> def setUpClass(cls): >> cls.FileSystemSetup() > > > This is senseless. Put the body of FileSystemSetup here. I didn't understand which line is senseless. I was trying to refer this example on stack overflow http://stackoverflow.com/questions/5938517/not-able-call-a-local-method-from-setupclass class TestSystemPromotion(unittest2.TestCase): @classmethod def setUpClass(cls): cls.setup_test_data() @classmethod def setup_test_data(cls): ... def test_something(self): ... class FileSystemTest(unittest2.TestCase): block_address = {} report = "" @classmethod def setUpClass(cls): cls.FileSystemSetup() @classmethod def FileSystemSetup(cls): """ Initial setup before unittest is run """ logging.info("SETUP.....Started !!!") >> def inode_corruption(self): >> """ test_01: inode corruption """ >> self.assertTrue(corrupt.run_query_tool(self.__class__.report, > > > self.block_address['test_01'])) > > Assuming that unittest2 is same as unittest, test methods must be called > test_xyz. So this is not run, hence no error. Sorry I have changed this from inode_corruption' to 'test_inode_corruption > >> @classmethod >> def tearDownClass(cls): >> cls.tearDown() > > > Ditto. Put real body here. > >> @classmethod >> def tearDown(cls): > > > The above refers to functions you did not post. For current unittest, it > looks likes you should be using a setUpModule (possible tearDownModule) > functions, but I don't know if those are available in the older unittest2. we have tearDownClass and setUpClass in python 2.6 and under unittest2 >>> help(unittest2.TestCase.tearDownClass) Help on method tearDownClass in module unittest2.case: tearDownClass(cls) method of __builtin__.type instance Hook method for deconstructing the class fixture after running all tests in the class. >>> help(unittest2.TestCase.setUpClass) Help on method setUpClass in module unittest2.case: setUpClass(cls) method of __builtin__.type instance Hook method for setting up class fixture before running tests in the class. Regards, Ganesh From torriem at gmail.com Sun Jan 10 10:02:41 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 10 Jan 2016 08:02:41 -0700 Subject: When I need classes? In-Reply-To: References: Message-ID: <56927291.6010009@gmail.com> On 01/10/2016 12:29 AM, Arshpreet Singh wrote: > Hello Friends, I am quite new to OOP(object oriented Programming), I > did some projects with python which includes Data-Analysis, Flask Web > Development and some simple scripts. > > I have only one question which is bothering me most of the time, When > I will get the need to use Classes in Python? Or in other way is > there any real-life example where you can tell me this > problem/solution is kind of impossible in Python without Classes? I can't speak to Flask or any other web development. But for simple scripts, I'll start out with no classes. Just functions as needed, and some main logic. I always use the idiom: if __name__ == '__main__': # do main logic here This way I can import functions defined in this script into another script later if I want. If I find I need to share state between functions, and if I find that I might need to have multiple situations of shared state possibly at the same time, then I will refactor the script into a class. Despite the apparent shame of using global variables, if I need to share state between functions, but I cannot ever foresee a time when I'll need to have multiple instances of that state, then I'll just use a module-level global variable and continue to use normal functions, rather than define a class. In the parlance of OOP, this use case would be referred to as a "singleton" and a python module (a script) is a form of singleton already, even without using classes. In the end my code often is a mix of classes and non-class -based code. From ahlusar.ahluwalia at gmail.com Sun Jan 10 10:04:54 2016 From: ahlusar.ahluwalia at gmail.com (kbtyo) Date: Sun, 10 Jan 2016 07:04:54 -0800 (PST) Subject: Understanding " 'xml.etree.ElementTree.Element' does not support the buffer interface" Message-ID: <876e5e0c-42c4-416a-90c0-ac2641e81949@googlegroups.com> Hello Everyone: I am curious to know why I receive the aforementioned message. I am using Python 3.4.3 and Windows 7. I am running the following script from Windows Powershell: Response = 's.csv' with open(Response, 'rU', encoding='utf-8') as data: separated = data.read().split('","') x = ElementTree.XML(separated[3]) y = ElementTree.XML(separated[4]) print(dict(flatten_dict(x))) print(dict(flatten_dict(y))) I am importing ElementTree as follows: import xml.etree.cElementTree as ElementTree from xml.etree.ElementTree import XMLParser The input data is as follows: A,B,C,D,E,F,G,H,I,J "3","8","1","2312285SChecking10","TrueFalseFalseFalseFalse0000',0001,0070,","1967-12-25 22:18:13.471000","2005-12-25 22:18:13.768000","2","70","0" Oddly, when I run the same script via WinPython' Jupyter Notebook, it works perfectly. The input string is an XML string and I am only interested in the 4th and 5th columns, (using zero based indexing). Thank you, in advance for your feedback and support. From steve at pearwood.info Sun Jan 10 10:19:11 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jan 2016 02:19:11 +1100 Subject: Understanding " 'xml.etree.ElementTree.Element' does not support the buffer interface" References: <876e5e0c-42c4-416a-90c0-ac2641e81949@googlegroups.com> Message-ID: <56927670$0$1616$c3e8da3$5496439d@news.astraweb.com> On Mon, 11 Jan 2016 02:04 am, kbtyo wrote: > Hello Everyone: > > I am curious to know why I receive the aforementioned message. It is impossible to be sure from the information you have given us, since we do not know which line of code caused the error. Please copy and paste the ENTIRE traceback, starting from the line: Traceback (most recent call last) to the end of the error message. This will (hopefully) show us which line of your code caused the error. -- Steven From steve at pearwood.info Sun Jan 10 10:39:34 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jan 2016 02:39:34 +1100 Subject: When I need classes? References: Message-ID: <56927b37$0$1586$c3e8da3$5496439d@news.astraweb.com> On Sun, 10 Jan 2016 06:29 pm, Arshpreet Singh wrote: > Hello Friends, I am quite new to OOP(object oriented Programming), I did > some projects with python which includes Data-Analysis, Flask Web > Development and some simple scripts. > > I have only one question which is bothering me most of the time, When I > will get the need to use Classes in Python? Or in other way is there any > real-life example where you can tell me this problem/solution is kind of > impossible in Python without Classes? There are *no* problems that are impossible to solve without classes, but sometimes classes will make problems easier to solve. And sometimes classes make problems harder to solve. It depends on the problem. This may help you: http://kentsjohnson.com/stories/00014.html -- Steven From ahlusar.ahluwalia at gmail.com Sun Jan 10 10:46:39 2016 From: ahlusar.ahluwalia at gmail.com (Saran Ahluwalia) Date: Sun, 10 Jan 2016 10:46:39 -0500 Subject: Understanding " 'xml.etree.ElementTree.Element' does not support the buffer interface" In-Reply-To: <56927670$0$1616$c3e8da3$5496439d@news.astraweb.com> References: <876e5e0c-42c4-416a-90c0-ac2641e81949@googlegroups.com> <56927670$0$1616$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hi Steven: That is the only message (*xml.etree.ElementTree.Element' does not support the buffer interface"*). There is no traceback. My apologies for not clarifying previously. On Sun, Jan 10, 2016 at 10:19 AM, Steven D'Aprano wrote: > On Mon, 11 Jan 2016 02:04 am, kbtyo wrote: > > > Hello Everyone: > > > > I am curious to know why I receive the aforementioned message. > > > It is impossible to be sure from the information you have given us, since > we > do not know which line of code caused the error. > > Please copy and paste the ENTIRE traceback, starting from the line: > > Traceback (most recent call last) > > to the end of the error message. This will (hopefully) show us which line > of > your code caused the error. > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list > From steve at pearwood.info Sun Jan 10 12:27:50 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jan 2016 04:27:50 +1100 Subject: Understanding " 'xml.etree.ElementTree.Element' does not support the buffer interface" References: <876e5e0c-42c4-416a-90c0-ac2641e81949@googlegroups.com> Message-ID: <56929498$0$1622$c3e8da3$5496439d@news.astraweb.com> On Mon, 11 Jan 2016 02:04 am, kbtyo wrote: > Hello Everyone: > > I am curious to know why I receive the aforementioned message. I am using > Python 3.4.3 and Windows 7. I am running the following script from Windows > Powershell: I created a file "data" containing the input data you said: > The input data is as follows: > > A,B,C,D,E,F,G,H,I,J > "3","8","1"," />2312 />285SChecking10"," TransactionID="2" > RequestType="HoldInquiry">TrueFalseFalseFalseFalse0000',0001,0070,","1967-12-25 > 22:18:13.471000","2005-12-25 22:18:13.768000","2","70","0" and then a script containing the code you said you used: > import xml.etree.cElementTree as ElementTree > from xml.etree.ElementTree import XMLParser > Response = 's.csv' > with open(Response, 'rU', encoding='utf-8') as data: > separated = data.read().split('","') > x = ElementTree.XML(separated[3]) > y = ElementTree.XML(separated[4]) > print(dict(flatten_dict(x))) > print(dict(flatten_dict(y))) I get a completely different error to you, complete with traceback as expected: Traceback (most recent call last): File "/tmp/testxml.py", line 9, in print(dict(flatten_dict(x))) NameError: name 'flatten_dict' is not defined This shows me three things: (1) The calls to ElementTree.XML work fine, and don't raise an exception; (2) There is no error message referring to xml.etree.ElementTree.Element or the buffer interface; (3) The code you posted is clearly not the code you actually ran. At the very least, it is not *all* the code you ran. We cannot tell what it wrong with your code if you don't show us the code that fails. I suggest you read this webpage: http://www.sscce.org/ and follow the advice given. It's written for Java, but applies to any programming language. Hopefully you will either solve your problem, or be able to generate a sufficiently small piece of code that we can work with. You also suggest that your code works when running in a Jupyter Notebook. It is unlikely (but not impossible!) that exactly the same code will run differently when run as a script and when run under Jupyter. More likely, there is some difference between the code, something you have written in the Notebook but not included in the script. If it is exactly the same code, then perhaps it is a difference in the two environments. Does Jupyter set up the environment differently to what you get when running a script? Finally, in another post, you state: "That is the only message (*xml.etree.ElementTree.Element' does not support the buffer interface"*). There is no traceback." That is very unlikely with the code sample you posted. If true, that gives more evidence that you are running code which is different from what you have posted here. Perhaps your ACTUAL code (not the pretend code you showed us) includes a try...except block like this: try: some code goes here except Exception as err: print(err) sys.exit() or similar. If so, TAKE IT OUT. That is destroying useful debugging information and making it more difficult to solve your problem. -- Steven From mafagafogigante at gmail.com Sun Jan 10 12:48:53 2016 From: mafagafogigante at gmail.com (Bernardo Sulzbach) Date: Sun, 10 Jan 2016 15:48:53 -0200 Subject: When I need classes? In-Reply-To: <56927b37$0$1586$c3e8da3$5496439d@news.astraweb.com> References: <56927b37$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: Essentially, classes (as modules) are used mainly for organizational purposes. Although you can solve any problem you would solve using classes without classes, solutions to some big problems may be cheaper and more feasible using classes. If Python is your everyday scripting tool, you will usually not need classes, they will add more complexity than you need and passing data between functions may be done with well-documented tuples and dictionaries. From ahlusar.ahluwalia at gmail.com Sun Jan 10 12:53:28 2016 From: ahlusar.ahluwalia at gmail.com (Saran Ahluwalia) Date: Sun, 10 Jan 2016 12:53:28 -0500 Subject: Understanding " 'xml.etree.ElementTree.Element' does not support the buffer interface" In-Reply-To: <56929498$0$1622$c3e8da3$5496439d@news.astraweb.com> References: <876e5e0c-42c4-416a-90c0-ac2641e81949@googlegroups.com> <56929498$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hi Steven: The previous code was a stand along under the " if __name__ == '__main__': ". The full function suite that I have made (and indeed includes a try and except block): import os.path import sys import csv from io import StringIO import xml.etree.cElementTree as ElementTree from xml.etree.ElementTree import XMLParser # import xml # import xml.sax # from xml.sax import ContentHandler def flatten_list(self, aList, prefix=''): for i, element in enumerate(aList, 1): eprefix = "{}{}".format(prefix, i) if element: # treat like dict if len(element) == 1 or element[0].tag != element[1].tag: yield from flatten_dict(element, eprefix) # treat like list elif element[0].tag == element[1].tag: yield from flatten_list(element, eprefix) elif element.text: text = element.text.strip() if text: yield eprefix[:].rstrip('.'), element.text def flatten_dict(parent_element, prefix=''): prefix = prefix + parent_element.tag if parent_element.items(): for k, v in parent_element.items(): yield prefix + k, v for element in parent_element: eprefix = element.tag if element: # treat like dict - we assume that if the first two tags # in a series are different, then they are all different. if len(element) == 1 or element[0].tag != element[1].tag: yield from flatten_dict(element, prefix=prefix) # treat like list - we assume that if the first two tags # in a series are the same, then the rest are the same. else: # here, we put the list in dictionary; the key is the # tag name the list elements all share in common, and # the value is the list itself yield from flatten_list(element, prefix=eprefix) # if the tag has attributes, add those to the dict if element.items(): for k, v in element.items(): yield eprefix+k # this assumes that if you've got an attribute in a tag, # you won't be having any text. This may or may not be a # good idea -- time will tell. It works for the way we are # currently doing XML configuration files... elif element.items(): for k, v in element.items(): yield eprefix+k # finally, if there are no child tags and no attributes, extract # the text else: yield eprefix, element.text def just_xml_data(path): with open(path, 'rU', encoding='UTF-8') as data: separated = data.read().split('","') print(separated) try: x = ElementTree.XML(separated[3]) print(x) xml.etree.ElementTree.dump(x) y = ElementTree.XML(separated[4]) xml.etree.ElementTree.dump(y) # response = ElementTree.XML(separated[4]) # work on the Response column # root = ElementTree.XML(response) #serialize and parse into XML object except Exception as e: print(e) else: xml_field = dict(flatten_dict(y)) return xml_field def read_data(path): headers= set() rows = [] with open(path, 'rU', encoding='utf-8') as data: reader = csv.DictReader(data, dialect=csv.excel, skipinitialspace=True) for row in reader: xml_field = row["CLIENT_RESP_DATA"] # xml_data = just_xml_data(xml_field) ## function if xml_data is not None: row.update(xml_data) headers.update(row.keys()) rows.append(row) else: print("Failure") pass with open(os.path.splitext(textFile)[0] + '_' + 'parsed' + '.csv', "wt", newline='') as output_file: wr = csv.writer(output_file) csv_headers = list(headers) wr.writerow(csv_headers) for row in rows: values = [] for field in csv_headers: value = row.get(field, None) values.append(value) wr.writerow(values) return output_file if __name__ == '__main__': Response = "s.csv" just_xml_data(Response) Hopefully this will provide you with enough information to emulate (apologies for any and all indentation errors during the copy and paste). FYI - I still receive the same error. On Sun, Jan 10, 2016 at 12:27 PM, Steven D'Aprano wrote: > On Mon, 11 Jan 2016 02:04 am, kbtyo wrote: > > > Hello Everyone: > > > > I am curious to know why I receive the aforementioned message. I am using > > Python 3.4.3 and Windows 7. I am running the following script from > Windows > > Powershell: > > I created a file "data" containing the input data you said: > > > The input data is as follows: > > > > A,B,C,D,E,F,G,H,I,J > > "3","8","1"," > />2312 > > />285SChecking10"," > TransactionID="2" > > > > RequestType="HoldInquiry">TrueFalseFalseFalseFalse0000',0001,0070,","1967-12-25 > > 22:18:13.471000","2005-12-25 22:18:13.768000","2","70","0" > > > > and then a script containing the code you said you used: > > > import xml.etree.cElementTree as ElementTree > > from xml.etree.ElementTree import XMLParser > > > Response = 's.csv' > > with open(Response, 'rU', encoding='utf-8') as data: > > separated = data.read().split('","') > > x = ElementTree.XML(separated[3]) > > y = ElementTree.XML(separated[4]) > > print(dict(flatten_dict(x))) > > print(dict(flatten_dict(y))) > > > I get a completely different error to you, complete with traceback as > expected: > > Traceback (most recent call last): > File "/tmp/testxml.py", line 9, in > print(dict(flatten_dict(x))) > NameError: name 'flatten_dict' is not defined > > > This shows me three things: > > (1) The calls to ElementTree.XML work fine, and don't raise an exception; > > (2) There is no error message referring to xml.etree.ElementTree.Element or > the buffer interface; > > (3) The code you posted is clearly not the code you actually ran. At the > very least, it is not *all* the code you ran. > > We cannot tell what it wrong with your code if you don't show us the code > that fails. I suggest you read this webpage: > > http://www.sscce.org/ > > and follow the advice given. It's written for Java, but applies to any > programming language. Hopefully you will either solve your problem, or be > able to generate a sufficiently small piece of code that we can work with. > > > You also suggest that your code works when running in a Jupyter Notebook. > It > is unlikely (but not impossible!) that exactly the same code will run > differently when run as a script and when run under Jupyter. More likely, > there is some difference between the code, something you have written in > the Notebook but not included in the script. > > If it is exactly the same code, then perhaps it is a difference in the two > environments. Does Jupyter set up the environment differently to what you > get when running a script? > > Finally, in another post, you state: > > "That is the only message (*xml.etree.ElementTree.Element' does not support > the buffer interface"*). There is no traceback." > > > That is very unlikely with the code sample you posted. If true, that gives > more evidence that you are running code which is different from what you > have posted here. Perhaps your ACTUAL code (not the pretend code you showed > us) includes a try...except block like this: > > try: > some code goes here > except Exception as err: > print(err) > sys.exit() > > > or similar. If so, TAKE IT OUT. That is destroying useful debugging > information and making it more difficult to solve your problem. > > > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list > From rxjwg98 at gmail.com Sun Jan 10 12:55:34 2016 From: rxjwg98 at gmail.com (Robert) Date: Sun, 10 Jan 2016 09:55:34 -0800 (PST) Subject: What use of these _ prefix members? Message-ID: <4ee5810e-abe9-4c4b-9ebd-d989b5c2b341@googlegroups.com> Hi, When I read a sample file from hmm learn package, which is on top of scikit-learn package, I see there are many member functions (prefix with '_') have no caller. That is, I don't see anything uses those functions. Below is a sample part from class GMMHMM(_BaseHMM): ////////// def __init__(self, n_components=1, n_mix=1,........ params="stmcw", init_params="stmcw"): _BaseHMM.__init__(self, n_components,......... params=params, init_params=init_params) # XXX: Hotfit for n_mix that is incompatible with the scikit's # BaseEstimator API self.n_mix = n_mix self.covariance_type = covariance_type self.covars_prior = covars_prior self.gmms_ = [] for x in range(self.n_components): if covariance_type is None: gmm = GMM(n_mix) else: gmm = GMM(n_mix, covariance_type=covariance_type) self.gmms_.append(gmm) def _init(self, X, lengths=None): super(GMMHMM, self)._init(X, lengths=lengths) for g in self.gmms_: g.set_params(init_params=self.init_params, n_iter=0) g.fit(X) def _compute_log_likelihood(self, X): return np.array([g.score(X) for g in self.gmms_]).T def _generate_sample_from_state(self, state, random_state=None): return self.gmms_[state].sample(1, random_state=random_state).flatten() //////////// Some online tutorials tell me '_' prefix is a kind of convention of private members. hmm is not a formal package. Do these '_' member functions are unfinished? Or, they may be used in some way I don't know yet? Thanks, From steve at pearwood.info Sun Jan 10 13:03:26 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jan 2016 05:03:26 +1100 Subject: What use of these _ prefix members? References: <4ee5810e-abe9-4c4b-9ebd-d989b5c2b341@googlegroups.com> Message-ID: <56929cef$0$1612$c3e8da3$5496439d@news.astraweb.com> On Mon, 11 Jan 2016 04:55 am, Robert wrote: > Some online tutorials tell me '_' prefix is a kind of convention of > private members. Correct. Not just private members, but private *anything*. Any time you see anything starting with a single underscore, whether it is a module, class, method, attribute or variable, you can assume that it is private (unless explicitly documented otherwise) and avoid it. -- Steven From __peter__ at web.de Sun Jan 10 13:34:52 2016 From: __peter__ at web.de (Peter Otten) Date: Sun, 10 Jan 2016 19:34:52 +0100 Subject: What use of these _ prefix members? References: <4ee5810e-abe9-4c4b-9ebd-d989b5c2b341@googlegroups.com> Message-ID: Robert wrote: > When I read a sample file from hmm learn package, which is on top of > scikit-learn package, I see there are many member functions (prefix with > '_') have no caller. That is, I don't see anything uses those functions. > Below is a sample part from class GMMHMM(_BaseHMM): I bet the caller is in the superclass _BaseHMM, like in the following made- up example: >>> class Base: ... def __init__(self, x): ... self._init(x) ... def _init(self, x): print("do something with", x) ... >>> class Derived(Base): ... def _init(self, x): ... super()._init(x) ... print("do something else with", x) ... >>> Derived(42) do something with 42 do something else with 42 <__main__.Derived object at 0x7f8e6b3e9b70> From srkunze at mail.de Sun Jan 10 13:48:53 2016 From: srkunze at mail.de (Sven R. Kunze) Date: Sun, 10 Jan 2016 19:48:53 +0100 Subject: How to remove item from heap efficiently? In-Reply-To: References: <568EEC40.7070807@mail.de> <568FE797.6090808@mail.de> Message-ID: <5692A795.3070904@mail.de> Wow. That's an impressive reply. On 08.01.2016 20:26, srinivas devaki wrote: > So you need a task scheduler with expiration and priority on each task. > Interesting Problem.. > > as peter said about marking the task in heapB to be deleted. but this > needs searching everytime you pop off an old item [complexity: > O(len(heapB))]. you may as well use python del on it as complexity is > same. > But if you already know the where to look in the heapB then you can > avoid searching and thereby reducing the complexity. you can do this > by saving the references of heapB in heapA and viceversa > > and if you marking delete on a number of low priority tasks, then it > can increase your heapB enormously because being low priority items > they can stagnate. to resolve this error you have to perform linear > checking iterations at every critical length (this critical length can > be obtained mathmatically), so that your amortized complexity of push, > pop remains log(number_of_valid_tasks_at_any_time); > the number of valid tasks at any time are those tasks which are not > expired at the time. > > My Algorithm: > version_a: https://gist.github.com/9ce7a0e534c6e768239e > this version has simple scheduler which has methods for popping high > priority one and popping oldest task. > But this version has a disadvantage, i.e If lets say you are pushed > some 10**5 tasks with priority 2, and then pushed some 10**5 tasks > with priority 1. and then you decided to pop the oldest 10**5 items. > in this version that 10**5 elements will stagnate in priority heap if > in future all priorities are less than 1. > now this is not a big issue but if you are running a webserver and > over a span of 5 days there could be 10**10 tasks, and even if half of > those tasks stagnate your server is going to crash with out of memory. > > version_b: https://gist.github.com/99b4d590753ba234eeed > this version resolved that stagnation. this one will run sweeps > whenever there are more than half of useless items, thereby giving us > an amortized complexity of O(log(n)) for push, pop, etc > > but this version doesn't have the feature of expiration. > > version_c: https://gist.github.com/9dfd0d291672c0ffa5c3 > in this one we simply keep a variable expiration, and relieve the > expired tasks on any operation. i have coded it in such a way that > expiration is specific time, you can change it to delta time if you > want to. > > Time Complexity: O(log(n)) insertion, O(log(n)) deletion [amortized] > Space Complexity: O(n) [amortized] > here n is number of valid items i.e which are not expired. > > I hope this helps with your problem Indeed. I already do the sweep method as you suggested. ;) Additionally, you provided me with a reasonable condition when to do the sweep in order to achieve O(log n). Thanks much for that. I currently used a time-bases approached (sweep each 20 iterations). PS: Could you add a note on how you got to the condition ( 2*self.useless_b > len(self.heap_b))? > PS: > sorry for posting links, it's just that the code is large for email. > I'm using minimum number has highest priority convention. I like Web technology, so no problem here. :) > On Fri, Jan 8, 2016 at 10:15 PM, Sven R. Kunze wrote: >> Thanks for your suggestion. >> >> On 08.01.2016 14:21, srinivas devaki wrote: >>> You can create a single heap with primary key as timestamp and >>> secondary key as priority, i.e by creating a tuple >>> insert the elements into the heap as >>> (timestamp, priority) >> I think I cannot use that because I need the list sorted by both criteria. >>> If there is any underlying meaning for creating 2 heaps. please mention. >> >> I use two heaps because I need to insert arbitrary items fast and remove the >> ones fast which are too old (timestamp) or are next in order (priority). >> >> Basically a task scheduler where tasks can be thrown away once they are too >> long in the queue. >> >> >>> On Fri, Jan 8, 2016 at 4:22 AM, Sven R. Kunze wrote: >>>> Hi everybody, >>>> >>>> suppose, I need items sorted by two criteria (say timestamp and >>>> priority). >>>> For that purpose, I use two heaps (heapq module): >>>> >>>> heapA # items sorted by timestamp >>>> heapB # items sorted by priority >>>> >>>> Now my actual problem. When popping an item of heapA (that's the oldest >>>> item), I need to remove the very same item from heapB, regardlessly where >>>> it >>>> is in heapB. And vice versa. >>>> >>>> Is there a datastructure or a simple trick to achieve that in an >>>> efficient >>>> matter? >>>> >>>> Best, >>>> Sven >>>> -- >>>> https://mail.python.org/mailman/listinfo/python-list >> From srkunze at mail.de Sun Jan 10 13:50:18 2016 From: srkunze at mail.de (Sven R. Kunze) Date: Sun, 10 Jan 2016 19:50:18 +0100 Subject: How to remove item from heap efficiently? In-Reply-To: <87lh7ywqm7.fsf@nightsong.com> References: <568EEC40.7070807@mail.de> <87lh7ywqm7.fsf@nightsong.com> Message-ID: <5692A7EA.2010600@mail.de> On 09.01.2016 19:32, Paul Rubin wrote: > "Sven R. Kunze" writes: >> Basically a task scheduler where tasks can be thrown away once they >> are too long in the queue. > I don't think there's a real nice way to do this with heapq. The > computer-sciencey way would involve separate balanced tree structures > for the two sorting keys (think of a database table with indexes on two > different columns). Others suggested using an additional dict where to store the indexes of the items. Then, when removing an item, I just need to query the dict. Best, Sven From rxjwg98 at gmail.com Sun Jan 10 14:38:17 2016 From: rxjwg98 at gmail.com (Robert) Date: Sun, 10 Jan 2016 11:38:17 -0800 (PST) Subject: Question on pytest example code Message-ID: <1c9f8fb6-b903-4204-86f6-9d8c81e69acd@googlegroups.com> Hi, Below is a code snippet from pytest package. It passes pytest, i.e. there is no failure report. # content of test_sysexit.py import pytest def f(): raise SystemExit(1) def test_mytest(): with pytest.raises(SystemExit): f() I see that f() will generate 'SystemExit(1)'. Then what does function test_mytest()? Is it missing some assert line? The above code is from page 5 (9 of 93) of 'pytest Documentation' Release 2.8.2 Thanks, From cody.piersall at gmail.com Sun Jan 10 14:42:51 2016 From: cody.piersall at gmail.com (Cody Piersall) Date: Sun, 10 Jan 2016 13:42:51 -0600 Subject: licenses In-Reply-To: <4C734AA4F3F9AC4891265961BD4D48539929AA@CINMBCNA07.e2k.ad.ge.com> References: <4C734AA4F3F9AC4891265961BD4D48539929AA@CINMBCNA07.e2k.ad.ge.com> Message-ID: On Fri, Jan 8, 2016 at 1:41 PM, Martinez, Jorge Alberto (GE Aviation) < JorgeAlberto.Martinez at ge.com> wrote: > > Hello > We develop applications here with Python and I want to know if there's issues by using. > We use NumPy, PyDaqMx, Py Visa > > How can we cover this licensing? I am not a lawyer, and this is not legal advice. * NumPy is BSD-licensed, which means you can use NumPy in a commercial product as long as you include its license. * PyDAQmx is BSD-licensed as well. (You can find that information in their GitHub repository's README, https://github.com/clade/PyDAQmx) * Py Visa is MIT licensed (info on their GitHub: https://github.com/hgrecco/pyvisa/blob/master/LICENSE), which means you can also use it in your software as long as you include the license. For summaries of lots of licenses, you can look at tldrlegal.com. * BSD license: https://tldrlegal.com/license/bsd-3-clause-license-(revised) * MIT license: https://tldrlegal.com/license/mit-license It's never a bad idea to consult a lawyer. Since you work for GE, I would imagine there is an army of lawyers happy to answer this question at your disposal. Finding out how to talk to them might be the hard part. Cody From mafagafogigante at gmail.com Sun Jan 10 14:51:54 2016 From: mafagafogigante at gmail.com (Bernardo Sulzbach) Date: Sun, 10 Jan 2016 17:51:54 -0200 Subject: licenses In-Reply-To: References: <4C734AA4F3F9AC4891265961BD4D48539929AA@CINMBCNA07.e2k.ad.ge.com> Message-ID: Cody wrote a good and correct answer. Everyone is going with "lawyers, lawyers, lawyers...". It is not any lawyer. Most big companies and consulting firms will have lawyers that are experienced with open source licenses, some that have even fought against GPL and whatnot. So look for the correct type of lawyer. Although any lawyer should be able to digest those licenses -- to be precise, any proficient English reader -- as most of them are quite simple and short, consulting an experienced professional is safer and a better investment of your time and money. Good luck with one of the worst parts of software development. From eldiener at tropicsoft.invalid Sun Jan 10 16:09:37 2016 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 10 Jan 2016 16:09:37 -0500 Subject: Python launcher options In-Reply-To: References: Message-ID: On 1/10/2016 6:38 AM, Tim Golden wrote: > > > On 10/01/2016 05:18, Edward Diener wrote: >> On 1/9/2016 11:03 AM, Tim Golden wrote: >>> On 06/01/2016 00:48, Edward Diener wrote: >>>> The Python launcher in Windows is a neat tool for running multiple >>>> versions of Python 2 and Python 3 at different times. It allows as >>>> options the ability to specify the latest version of either Python 2 or >>>> Python 3 defaulting to the 64-bit version if both exist, or a specific >>>> 32-bit or 64-bit version of Python 2 or Python 3. What is missing is >>>> the >>>> ability to specify the latest 32-bit version of Python 2 or Python 3. >>>> The equivalent syntax would be '-2-32' or '-3-32'. Is there some reason >>>> why this option has been disallowed ? >>> >>> As far as I can remember, it's not so much a question of "disallowed" as >>> just "not thought of by anyone". If you wanted this to go anywhere, >>> could I suggest you create an issue on the Python issue tracker: >>> >>> http://bugs.python.org >>> >>> and mark it as "Windows" in the [Components] field (that makes sure that >>> some relevant people get to see it). It's got a much better chance of >>> achieving traction if you can actually provide a code patch to implement >>> the behaviour. Failing that, at least make a good case which might >>> convince one of the developers that it would it be worth their while >>> implementing the change. >> >> I have tried to register with the link above so I can an issue with the >> Python Issue tracker but all attempts fail with: >> >> "Failed issue tracker submission >> >> An unexpected error occurred during the processing >> of your message. The tracker administrator is being >> notified." > > Hmmm. Thanks for making the effort -- and for reporting back. I've just > successfully registered a (dummy) account there, so it's possible that > there was a temporary glitch. > > If you wouldn't mind trying once more, that would be helpful. If not, I > can create the issue on your behalf, and inform the tracker admins. I tried again only to run into the exact same problem. I don't know what it means that I am not being allowed to register for the Python bug tracker. Needless to say the obscure error message is not telling me anything. Of course as a programmer who uses Python I would like to find out why I am not able to register. But in the meantime if you could create the issue on my behalf it would be appreciated. Thanks ! From eldiener at tropicsoft.invalid Sun Jan 10 16:19:24 2016 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 10 Jan 2016 16:19:24 -0500 Subject: Python launcher options In-Reply-To: References: Message-ID: On 1/10/2016 6:38 AM, Tim Golden wrote: > > > On 10/01/2016 05:18, Edward Diener wrote: >> On 1/9/2016 11:03 AM, Tim Golden wrote: >>> On 06/01/2016 00:48, Edward Diener wrote: >>>> The Python launcher in Windows is a neat tool for running multiple >>>> versions of Python 2 and Python 3 at different times. It allows as >>>> options the ability to specify the latest version of either Python 2 or >>>> Python 3 defaulting to the 64-bit version if both exist, or a specific >>>> 32-bit or 64-bit version of Python 2 or Python 3. What is missing is >>>> the >>>> ability to specify the latest 32-bit version of Python 2 or Python 3. >>>> The equivalent syntax would be '-2-32' or '-3-32'. Is there some reason >>>> why this option has been disallowed ? >>> >>> As far as I can remember, it's not so much a question of "disallowed" as >>> just "not thought of by anyone". If you wanted this to go anywhere, >>> could I suggest you create an issue on the Python issue tracker: >>> >>> http://bugs.python.org >>> >>> and mark it as "Windows" in the [Components] field (that makes sure that >>> some relevant people get to see it). It's got a much better chance of >>> achieving traction if you can actually provide a code patch to implement >>> the behaviour. Failing that, at least make a good case which might >>> convince one of the developers that it would it be worth their while >>> implementing the change. >> >> I have tried to register with the link above so I can an issue with the >> Python Issue tracker but all attempts fail with: >> >> "Failed issue tracker submission >> >> An unexpected error occurred during the processing >> of your message. The tracker administrator is being >> notified." > > Hmmm. Thanks for making the effort -- and for reporting back. I've just > successfully registered a (dummy) account there, so it's possible that > there was a temporary glitch. > > If you wouldn't mind trying once more, that would be helpful. If not, I > can create the issue on your behalf, and inform the tracker admins. I was finally able to register so I will report this issue on the Python issue tracker myself. From ahlusar.ahluwalia at gmail.com Sun Jan 10 20:39:40 2016 From: ahlusar.ahluwalia at gmail.com (kbtyo) Date: Sun, 10 Jan 2016 17:39:40 -0800 (PST) Subject: Improving code written in order to reduce verbosity and perhaps use a decorator? Message-ID: Hello everyone: A member on the Stack Overflow community advised me to post my question on this forum: http://codereview.stackexchange.com/questions/116395/opening-the-same-csv-file-in-two-different-ways-in-order-to-transform-data-in-on I appreciate your feedback immensely. Sincerely, Saran From rxjwg98 at gmail.com Sun Jan 10 20:57:26 2016 From: rxjwg98 at gmail.com (Robert) Date: Sun, 10 Jan 2016 17:57:26 -0800 (PST) Subject: Confusing on bool data object or class function? Message-ID: <582101e1-bb8b-446b-8a47-ce7bd17f11d0@googlegroups.com> Hi, When I use an on line code snippet, see below please, I find that 'converged' in class ConvergenceMonitor is seen as a data. --------- class ConvergenceMonitor(object): """Monitors and reports convergence to :data:`sys.stderr`. Parameters ---------- tol : double Convergence threshold. EM has converged either if the maximum number of iterations is reached or the log probability improvement between the two consecutive iterations is less than threshold. n_iter : int Maximum number of iterations to perform. verbose : bool If ``True`` then per-iteration convergence reports are printed, otherwise the monitor is mute. Attributes ---------- history : deque The log probability of the data for the last two training iterations. If the values are not strictly increasing, the model did not converge. iter : int Number of iterations performed while training the model. """ _template = "{iter:>10d} {logprob:>16.4f} {delta:>+16.4f}" def __init__(self, tol, n_iter, verbose): self.tol = tol self.n_iter = n_iter self.verbose = verbose self.history = deque(maxlen=2) self.iter = 0 def __repr__(self): class_name = self.__class__.__name__ params = dict(vars(self), history=list(self.history)) return "{0}({1})".format( class_name, _pprint(params, offset=len(class_name))) def report(self, logprob): """Reports convergence to :data:`sys.stderr`. The output consists of three columns: iteration number, log probability of the data at the current iteration and convergence rate. At the first iteration convergence rate is unknown and is thus denoted by NaN. Parameters ---------- logprob : float The log probability of the data as computed by EM algorithm in the current iteration. """ @property def converged(self): """``True`` if the EM algorithm converged and ``False`` otherwise.""" # XXX we might want to check that ``logprob`` is non-decreasing. return (self.iter == self.n_iter or (len(self.history) == 2 and self.history[1] - self.history[0] < self.tol)) ///////// Here is except of the online help content: | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | converged | ``True`` if the EM algorithm converged and ``False`` otherwise. The data conclusion is verified by the following test code: from hmmlearn.base import ConvergenceMonitor class TestMonitor(object): def test_converged_by_iterations(self): print 'self test0' m = ConvergenceMonitor(tol=1e-3, n_iter=2, verbose=False) print 'self test1', m.converged assert not m.converged print 'self test2', m.converged m.report(-0.01) assert not m.converged print 'self test3', m.converged m.report(-0.1) assert m.converged print 'self test4', m.converged tmp_obj=TestMonitor() print 'ttt', tmp_obj.test_converged_by_iterations() mm = ConvergenceMonitor(tol=1e-3, n_iter=2, verbose=False) print 'self test mm', mm.converged That is, I can only use: mm.converged If I use it in this way: mm.converged() it will have error: TypeError Traceback (most recent call last) C:\Users\rj\Documents\PythonDocPrj0\hmmlearn-master\hmmlearn\tests\test_base1.py in () 27 print None 28 mm = ConvergenceMonitor(tol=1e-3, n_iter=2, verbose=False) ---> 29 print 'self test mm', mm.converged() 30 TypeError: 'bool' object is not callable On the other hand, 'play' in the following class is seen as a member function: class Engine(object): def __init__(self, scene_map): pass def play(self): print 'play' return True a_game = Engine(scene_map=0.1) a_game.play() Why can 'converged' only be seen as a data, while 'play' can be seen as a function? Thanks, From jfong at ms4.hinet.net Sun Jan 10 20:59:58 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sun, 10 Jan 2016 17:59:58 -0800 (PST) Subject: Which Python editor has this feature? Message-ID: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> It lets you jump between the current cursor position and the line the upper level indentation start, something like the bracket matching in C editor. Because of Python use indentation as its code block mark, It might be helpful if we can jump between different level of it:-) --Jach Fong From python.list at tim.thechases.com Sun Jan 10 21:37:48 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 10 Jan 2016 20:37:48 -0600 Subject: Which Python editor has this feature? In-Reply-To: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> Message-ID: <20160110203748.331bd74f@bigbox.christie.dr> On 2016-01-10 17:59, jfong at ms4.hinet.net wrote: > It lets you jump between the current cursor position and the line > the upper level indentation start, something like the bracket > matching in C editor. Because of Python use indentation as its code > block mark, It might be helpful if we can jump between different > level of it:-) While not quite what you're asking for, vim offers an "indent text object" plugin[1] that allows you to use a block of indentation around the cursor as an object. So you can use vim's grammar to issue commands like "dai" to delete the current indentation-defined block; or you can use ">ii" to add a level of indentation to the indentation-defined block. If you want to make a vim mapping that will jump up to the top of the previous level of indentation, the following should do the trick :nnoremap Q '?^'.repeat(' ', (strlen(substitute(getline('.'), '\S.*', '', ''))-&sw)).'\S?e'."\" There might be some edge-cases that I haven't caught there, but, as long as you edit with spaces rather than tabs, it should work, including the accommodation of your 'shiftwidth', even if it's not PEP8 4-spaces-per-indent. -tkc [1] https://github.com/michaeljsmith/vim-indent-object From cs at zip.com.au Sun Jan 10 21:57:41 2016 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 11 Jan 2016 13:57:41 +1100 Subject: When I need classes? In-Reply-To: <56927291.6010009@gmail.com> References: <56927291.6010009@gmail.com> Message-ID: <20160111025741.GA37625@cskk.homeip.net> On 10Jan2016 08:02, Michael Torrie wrote: >I can't speak to Flask or any other web development. But for simple >scripts, I'll start out with no classes. Just functions as needed, and >some main logic. I always use the idiom: > >if __name__ == '__main__': > # do main logic here > >This way I can import functions defined in this script into another >script later if I want. I always structure this aspect as: ... at or near top of script ... def main(argv): ... do main logic here ... ... at bottom ... if __name__ == '__main__': sys.exit(main(sys.argv)) This has the benefits of (a) putting the main program at the top where it is easy to see/find and (b) avoiding accidently introduction of dependence on global variables - because verything is inside main() it has the same behaviour as any other function. Cheers, Cameron Simpson From rosuav at gmail.com Sun Jan 10 21:58:56 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jan 2016 13:58:56 +1100 Subject: Which Python editor has this feature? In-Reply-To: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> Message-ID: On Mon, Jan 11, 2016 at 12:59 PM, wrote: > It lets you jump between the current cursor position and the line the upper level indentation start, something like the bracket matching in C editor. Because of Python use indentation as its code block mark, It might be helpful if we can jump between different level of it:-) I coded this up as a patch for SciTE/Scintilla at one point, but it didn't get accepted. It was used for a while at my work, but never really settled in as being useful. Python code tends not to be as big and complex as C code often is, so it's not as useful to have a feature like this. If you want it, I can probably hunt down the patch file somewhere. ChrisA From steve at pearwood.info Sun Jan 10 22:17:01 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jan 2016 14:17:01 +1100 Subject: Confusing on bool data object or class function? References: <582101e1-bb8b-446b-8a47-ce7bd17f11d0@googlegroups.com> Message-ID: <56931ead$0$1600$c3e8da3$5496439d@news.astraweb.com> On Mon, 11 Jan 2016 12:57 pm, Robert wrote: > Hi, > > When I use an on line code snippet, see below please, I find that > 'converged' in class ConvergenceMonitor is seen as a data. That is because converged is a property. That makes it be seen as data. > @property > def converged(self): Properties are computed attributes. Although they have a function deep inside them, to perform the computation, they are seen from the outside as data attributes. See the documentation for "property" for more information, and google for "descriptor" for the underlying mechanism that allows this to work. (Warning: descriptors are considered very advanced material.) -- Steven From rosuav at gmail.com Sun Jan 10 22:19:12 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jan 2016 14:19:12 +1100 Subject: When I need classes? In-Reply-To: <20160111025741.GA37625@cskk.homeip.net> References: <56927291.6010009@gmail.com> <20160111025741.GA37625@cskk.homeip.net> Message-ID: On Mon, Jan 11, 2016 at 1:57 PM, Cameron Simpson wrote: > I always structure this aspect as: > > ... at or near top of script ... > > def main(argv): > ... do main logic here ... > > ... at bottom ... > if __name__ == '__main__': > sys.exit(main(sys.argv)) > > This has the benefits of (a) putting the main program at the top where it is > easy to see/find and (b) avoiding accidently introduction of dependence on > global variables - because verything is inside main() it has the same > behaviour as any other function. > Personally, I like to put 'def main()' at the bottom of the script, on the principle that, as much as possible, code should refer to stuff higher up rather than lower down. But otherwise, I agree. Your "if __name__" block is just the glue between sys.{argv,exit} and your main function, and that's how it should be. ChrisA From rustompmody at gmail.com Sun Jan 10 22:49:47 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Jan 2016 19:49:47 -0800 (PST) Subject: Which Python editor has this feature? In-Reply-To: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> Message-ID: <562ad3ae-5110-44f3-a4f1-4374ddde3ffb@googlegroups.com> On Monday, January 11, 2016 at 7:30:10 AM UTC+5:30, jf... at ms4.hinet.net wrote: > It lets you jump between the current cursor position and the line the upper level indentation start, something like the bracket matching in C editor. Because of Python use indentation as its code block mark, It might be helpful if we can jump between different level of it:-) > > > --Jach Fong Recent emacs' python mode has all these bunch of python-nav-* functions. You may have (as usual with emacs!) to choose which you like best, ie not all are not bound to keys. ---------------------------- Click on a completion to select it. In this buffer, type RET to select the completion near point. Possible completions are: python-nav--beginning-of-defun python-nav--forward-defun python-nav--forward-sexp python-nav--lisp-forward-sexp python-nav--lisp-forward-sexp-safe python-nav--syntactically python-nav--up-list python-nav-backward-block python-nav-backward-defun python-nav-backward-sexp python-nav-backward-sexp-safe python-nav-backward-statement python-nav-backward-up-list python-nav-beginning-of-block python-nav-beginning-of-defun python-nav-beginning-of-statement python-nav-end-of-block python-nav-end-of-defun python-nav-end-of-statement python-nav-forward-block python-nav-forward-defun python-nav-forward-sexp python-nav-forward-sexp-safe python-nav-forward-statement python-nav-if-name-main python-nav-up-list From tjreedy at udel.edu Sun Jan 10 23:00:47 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 10 Jan 2016 23:00:47 -0500 Subject: Question on pytest example code In-Reply-To: <1c9f8fb6-b903-4204-86f6-9d8c81e69acd@googlegroups.com> References: <1c9f8fb6-b903-4204-86f6-9d8c81e69acd@googlegroups.com> Message-ID: On 1/10/2016 2:38 PM, Robert wrote: > Hi, > > Below is a code snippet from pytest package. It passes pytest, i.e. there is > no failure report. > > > # content of test_sysexit.py > import pytest > > def f(): > raise SystemExit(1) > > def test_mytest(): > with pytest.raises(SystemExit): > f() > > > I see that f() will generate 'SystemExit(1)'. Then what does function > test_mytest()? What does test_mytest do? It tests that f() raises SystemExit. > Is it missing some assert line? The unittest version of 'pytest.raises' is 'self.assertRaises'. The latter context manager __exit__ method checks that it is passed the exception given to the __enter__ method and fails if not. I presume the pytest version is more or less identical. > The above code is from page 5 (9 of 93) of 'pytest Documentation' > Release 2.8.2 -- Terry Jan Reedy From arsh840 at gmail.com Mon Jan 11 01:24:04 2016 From: arsh840 at gmail.com (Arshpreet Singh) Date: Sun, 10 Jan 2016 22:24:04 -0800 (PST) Subject: When I need classes? In-Reply-To: References: <56927b37$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sunday, 10 January 2016 23:20:02 UTC+5:30, Bernardo Sulzbach wrote: > Essentially, classes (as modules) are used mainly for organizational purposes. > > Although you can solve any problem you would solve using classes > without classes, solutions to some big problems may be cheaper and > more feasible using classes. That seems coming to me as. I am going to start Kivy to build Android application and As I see there are lots of Example code with classes and stuff. From arsh840 at gmail.com Mon Jan 11 01:28:59 2016 From: arsh840 at gmail.com (Arshpreet Singh) Date: Sun, 10 Jan 2016 22:28:59 -0800 (PST) Subject: When I need classes? In-Reply-To: <56927b37$0$1586$c3e8da3$5496439d@news.astraweb.com> References: <56927b37$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2e8d63ca-904f-4d54-813e-560219677a24@googlegroups.com> On Sunday, 10 January 2016 21:09:52 UTC+5:30, Steven D'Aprano wrote: > There are *no* problems that are impossible to solve without classes, but > sometimes classes will make problems easier to solve. And sometimes classes > make problems harder to solve. It depends on the problem. Is there any particular situation in your experience or in your past like you felt this could be more suitable with classes? Actually a real life story from someone'e past experience could do much greater help. > This may help you: > > http://kentsjohnson.com/stories/00014.html Thanks That is good read to remember and practice. From arsh840 at gmail.com Mon Jan 11 01:45:25 2016 From: arsh840 at gmail.com (Arshpreet Singh) Date: Sun, 10 Jan 2016 22:45:25 -0800 (PST) Subject: When I need classes? In-Reply-To: References: Message-ID: On Sunday, 10 January 2016 20:33:20 UTC+5:30, Michael Torrie wrote: > This way I can import functions defined in this script into another > script later if I want. > > If I find I need to share state between functions, and if I find that I > might need to have multiple situations of shared state possibly at the > same time, then I will refactor the script into a class. Despite the > apparent shame of using global variables, if I need to share state > between functions, but I cannot ever foresee a time when I'll need to > have multiple instances of that state, I have a case in Flask-Oauth2 where one function returns Username, Email ID and Authorised Token. So I can make that function Global and access EMail,username and Authorised token from any other Script. Or I can make it class? >then I'll just use a module-level > global variable and continue to use normal functions, rather than define > a class. In the parlance of OOP, this use case would be referred to as > a "singleton" and a python module (a script) is a form of singleton > already, even without using classes. Is it also true that Classes(OOP) help to optimise code(uses less memory) rather than just doing things with functions. From cs at zip.com.au Mon Jan 11 02:27:10 2016 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 11 Jan 2016 18:27:10 +1100 Subject: When I need classes? In-Reply-To: References: Message-ID: <20160111072710.GA20153@cskk.homeip.net> On 10Jan2016 22:45, Arshpreet Singh wrote: >On Sunday, 10 January 2016 20:33:20 UTC+5:30, Michael Torrie wrote: >> This way I can import functions defined in this script into another >> script later if I want. >> >> If I find I need to share state between functions, and if I find that I >> might need to have multiple situations of shared state possibly at the >> same time, then I will refactor the script into a class. Despite the >> apparent shame of using global variables, if I need to share state >> between functions, but I cannot ever foresee a time when I'll need to >> have multiple instances of that state, > >I have a case in Flask-Oauth2 where one function returns Username, Email ID and Authorised Token. > >So I can make that function Global and access EMail,username and Authorised token from any other Script. Note: you can access the _function_ from another script or module. When your programs do something like: from os.path import basename they are doing exactly this. >Or >I can make it class? On its own it doesn't mean much. Michael Torrie's criterion said "share state between functions"; that state is normally an instance of the class. So you have some value and a bunch of standard things you would do with that kind of value. That is the situation where a class is a natural thing to use: you make a class to represent the value, and each of the standard things you would do with one of those values is a class method. In your situation above I would be inclined to make a class to represent the 3-tuple you outline above: Username, Email ID and Authorised Token. So: from collections import namedtuple Authorisation = namedtuple('Authorisation', 'username email authorised_token') now, where you would have obtained these as a tuple: # call your "in Flask-Oauth2 where one function returns Username..." authorisation = get_auth_info(...) and then access authorisation[0] for the username and so forth, you can go: # fetch the 3 values and make an "Authorisation" from them authorisation = Authorisation(get_auth_info(...)) and the access authorisation.username, authorisation.email etc. This avoids knowing special index numbers (0, 1 and 2) which makes your code more readable and also makes it easy to pass around the authorisation for use. Then, if you have things you routinely do with an "Authorisation" you can make methods for them. So that your code can say: authorisation.do_this(...) and so forth. >>then I'll just use a module-level >> global variable and continue to use normal functions, rather than define >> a class. In the parlance of OOP, this use case would be referred to as >> a "singleton" and a python module (a script) is a form of singleton >> already, even without using classes. > >Is it also true that Classes(OOP) help to optimise code(uses less memory) rather than just doing things with functions. Not really? I would not expect using a class to inherently get you less memory use, just better and more consistent naming. There are some special situations where you can use a class to reduce your memory usage, but they are fairly dependent on what you're doing. Cheers, Cameron Simpson From framstag at rus.uni-stuttgart.de Mon Jan 11 02:31:51 2016 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Mon, 11 Jan 2016 07:31:51 +0000 (UTC) Subject: When I need classes? References: <56927291.6010009@gmail.com> Message-ID: Cameron Simpson wrote: > I always structure this aspect as: > > ... at or near top of script ... > > def main(argv): > ... do main logic here ... > > ... at bottom ... > if __name__ == '__main__': > sys.exit(main(sys.argv)) I, as a Python beginner, came to the same solution! It seems, it was a good idea :-) -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From gefle.rickard at gmail.com Mon Jan 11 02:55:41 2016 From: gefle.rickard at gmail.com (Rickard Englund) Date: Sun, 10 Jan 2016 23:55:41 -0800 (PST) Subject: Strange crash while running a script with a embedded python interpreter In-Reply-To: References: <4ac97a67-2527-424e-90e2-b714528977c8@googlegroups.com> Message-ID: On Friday, January 8, 2016 at 11:28:53 PM UTC+1, Michael Torrie wrote: > On 01/08/2016 09:18 AM, Rickard Englund wrote: > > First, some system info > > * Windows 7 (also tested on 8 and 10) > > * Python 3.5.1 64bit (previously also tested using several 3.x versions) (also tested with 32 bit, but with 3.4.2) > > * Microsoft Visual Studio 2015 (earlier version of python also tested with Visual Studio 2013) > > Are you using the same version of Visual Studio that Python itself was > compiled with? If not there can be subtle problems with incompatible > msvcrt dlls. No idea if this would be contributing to the problem or > not, though. I've just downloaded the python source code and build it myself, the compiler settings in our project is the same as in the python projects. Though, your comment led me in the correct direction. When using the libs/binary I built my self it let me see the values of the PyObjects around the crash and it seems like it is related to our modules and/or how we expose them to the interpreter. When disabling our own modules everything seems to be working as it should. I think I got it wokring now, used some ugly hacks I need to clean up before I certain it works. Thanks for the help. From rosuav at gmail.com Mon Jan 11 03:09:40 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jan 2016 19:09:40 +1100 Subject: Strange crash while running a script with a embedded python interpreter In-Reply-To: References: <4ac97a67-2527-424e-90e2-b714528977c8@googlegroups.com> Message-ID: On Mon, Jan 11, 2016 at 6:55 PM, Rickard Englund wrote: > On Friday, January 8, 2016 at 11:28:53 PM UTC+1, Michael Torrie wrote: >> On 01/08/2016 09:18 AM, Rickard Englund wrote: >> > First, some system info >> > * Windows 7 (also tested on 8 and 10) >> > * Python 3.5.1 64bit (previously also tested using several 3.x versions) (also tested with 32 bit, but with 3.4.2) >> > * Microsoft Visual Studio 2015 (earlier version of python also tested with Visual Studio 2013) >> >> Are you using the same version of Visual Studio that Python itself was >> compiled with? If not there can be subtle problems with incompatible >> msvcrt dlls. No idea if this would be contributing to the problem or >> not, though. > > I've just downloaded the python source code and build it myself, the compiler settings in our project is the same as in the python projects. > > > Though, your comment led me in the correct direction. When using the libs/binary I built my self it let me see the values of the PyObjects around the crash and it seems like it is related to our modules and/or how we expose them to the interpreter. When disabling our own modules everything seems to be working as it should. > Interesting. So somewhere along the way, you have native code (C code?) that's creating a module, and that's where the trouble starts? I would first look at all your refcount management; if that goes wrong, all sorts of craziness could happen (if you still have a pointer to a block of memory that gets released and reused, hilarity will ensue - or, something will). Have you considered using Cython? That might let you do what you need without worrying about all those annoying internal API details. ChrisA From gordon at address.invalid Mon Jan 11 03:40:51 2016 From: gordon at address.invalid (Gordon Levi) Date: Mon, 11 Jan 2016 19:40:51 +1100 Subject: Which Python editor has this feature? References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> Message-ID: jfong at ms4.hinet.net wrote: >It lets you jump between the current cursor position and the line the upper level indentation start, something like the bracket matching in C editor. Because of Python use indentation as its code block mark, It might be helpful if we can jump between different level of it:-) Jetbrains Pycharm has "go to start of block" and "go to end of block" commands . Unfortunately the free version of Pycharm does not support remote debugging and my main use for Python is for programming a Raspberry Pi. I use Visual Studio instead and its "go to end of block" does not work in the Python editor . From framstag at rus.uni-stuttgart.de Mon Jan 11 04:57:22 2016 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Mon, 11 Jan 2016 09:57:22 +0000 (UTC) Subject: looking for windows testers Message-ID: I have written a Python client for F*EX(*). It is designed for Windows users, though it runs on UNIX, too. I am now looking for testers. If you are interested, I will give you an account on my server. (*) Frams' Fast File EXchange is a service to send files of any size to any user anywhere in the internet: http://fex.rus.uni-stuttgart.de:8080/index.html -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From ganesh1pal at gmail.com Mon Jan 11 05:05:51 2016 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Mon, 11 Jan 2016 15:35:51 +0530 Subject: Fwd: python unit test framework sample code In-Reply-To: References: Message-ID: Totally stuck with this On Jan 10, 2016 7:11 PM, "Ganesh Pal" wrote: > Apologies, looks like I did a reply instead of reply-all. So > forwarding this email , please provide guidance on the same > > ---------- Forwarded message ---------- > From: Ganesh Pal > Date: Thu, Jan 7, 2016 at 12:26 PM > Subject: Re: python unit test framework sample code > To: Terry Reedy > > > Unless you have a large program already in 2.6 and are just adding tests > > (perhaps so you can more easily upgrade someday), consider upgrading to a > > newer version. > > Sure , but for now Iam limited to use 2.6 , hence I cant upgrade need > to work with 2.6 > > >> > >> class FileSystemTest(unittest2.TestCase): > >> block_address = {} > >> report = "" > >> > >> @classmethod > >> def setUpClass(cls): > >> cls.FileSystemSetup() > > > > > > This is senseless. Put the body of FileSystemSetup here. > > I didn't understand which line is senseless. I was trying to refer > this example on stack overflow > > http://stackoverflow.com/questions/5938517/not-able-call-a-local-method-from-setupclass > > > class TestSystemPromotion(unittest2.TestCase): > > @classmethod > def setUpClass(cls): > cls.setup_test_data() > > > @classmethod > def setup_test_data(cls): > ... > > def test_something(self): > ... > > > class FileSystemTest(unittest2.TestCase): > block_address = {} > report = "" > > @classmethod > def setUpClass(cls): > cls.FileSystemSetup() > > @classmethod > def FileSystemSetup(cls): > """ > Initial setup before unittest is run > """ > logging.info("SETUP.....Started !!!") > > >> def inode_corruption(self): > >> """ test_01: inode corruption """ > >> self.assertTrue(corrupt.run_query_tool(self.__class__.report, > > > > > > self.block_address['test_01'])) > > > > Assuming that unittest2 is same as unittest, test methods must be called > > test_xyz. So this is not run, hence no error. > > Sorry I have changed this from inode_corruption' to 'test_inode_corruption > > > > >> @classmethod > >> def tearDownClass(cls): > >> cls.tearDown() > > > > > > Ditto. Put real body here. > > > >> @classmethod > >> def tearDown(cls): > > > > > > > The above refers to functions you did not post. For current unittest, it > > looks likes you should be using a setUpModule (possible tearDownModule) > > functions, but I don't know if those are available in the older > unittest2. > > > we have tearDownClass and setUpClass in python 2.6 and under unittest2 > > >>> help(unittest2.TestCase.tearDownClass) > Help on method tearDownClass in module unittest2.case: > > tearDownClass(cls) method of __builtin__.type instance > Hook method for deconstructing the class fixture after running all > tests in the class. > > >>> help(unittest2.TestCase.setUpClass) > Help on method setUpClass in module unittest2.case: > > setUpClass(cls) method of __builtin__.type instance > Hook method for setting up class fixture before running tests in the > class. > > Regards, > Ganesh > From jfong at ms4.hinet.net Mon Jan 11 06:04:09 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 11 Jan 2016 03:04:09 -0800 (PST) Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> Message-ID: <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> Chris Angelico at 2016/1/11 UTC+8 10:59:47AM wrote: > On Mon, Jan 11, 2016 at 12:59 PM, wrote: > > It lets you jump between the current cursor position and the line the upper level indentation start, something like the bracket matching in C editor. Because of Python use indentation as its code block mark, It might be helpful if we can jump between different level of it:-) > > I coded this up as a patch for SciTE/Scintilla at one point, but it > didn't get accepted. It was used for a while at my work, but never > really settled in as being useful. Python code tends not to be as big > and complex as C code often is, so it's not as useful to have a > feature like this. > > If you want it, I can probably hunt down the patch file somewhere. > > ChrisA I am studying the PyUSB package now as the learning object of how to write a Python program in a "formal" way. In those modules, there are many comment inserted between codes to explain what it does. It's good to the user comprehension, but also easily makes a Class size expanded to over 100 lines. Also many Classes has the same named method such as __getitem__ etc. When searching a specific name I usually have to roll back the screen a few times to find out what Class I am looking at. That's really annoy. But, just like you said, this feature may be not so useful to a Python programmer. I should try the editor I am using now to see if I can "patch" a such feature, just as you had did on SciTE before:-) --Jach From jfong at ms4.hinet.net Mon Jan 11 06:08:53 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 11 Jan 2016 03:08:53 -0800 (PST) Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> Message-ID: Tim Chase at 2016/1/11 UTC+8 11:16:27AM wrote? > On 2016-01-10 17:59, jfong at ms4.hinet.net wrote: > > It lets you jump between the current cursor position and the line > > the upper level indentation start, something like the bracket > > matching in C editor. Because of Python use indentation as its code > > block mark, It might be helpful if we can jump between different > > level of it:-) > > While not quite what you're asking for, vim offers an "indent text > object" plugin[1] that allows you to use a block of indentation > around the cursor as an object. So you can use vim's grammar to issue > commands like "dai" to delete the current indentation-defined block; > or you can use ">ii" to add a level of indentation to the > indentation-defined block. Thanks, Tim. I always admire people who can remember all those detail commands/parameters/options which a DOS-style editor as vim has. It's almost like a mission impossible to me:-( > If you want to make a vim mapping that will jump up to the top of the > previous level of indentation, the following should do the trick > > :nnoremap Q '?^'.repeat(' ', (strlen(substitute(getline('.'), '\S.*', '', ''))-&sw)).'\S?e'."\" But, but... this line??? won't it goes too far for a human being to read? --Jach > There might be some edge-cases that I haven't caught there, but, as > long as you edit with spaces rather than tabs, it should work, > including the accommodation of your 'shiftwidth', even if it's not > PEP8 4-spaces-per-indent. > > -tkc > > [1] > https://github.com/michaeljsmith/vim-indent-object From jfong at ms4.hinet.net Mon Jan 11 06:16:31 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 11 Jan 2016 03:16:31 -0800 (PST) Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> Message-ID: Gordon Levi at 2016/1/11 UTC+8 4:41:20PM wrote: > Jetbrains Pycharm has "go to start of block" and "go to end of block" > commands . Thanks, Gordon. But this seems only jump between the current code block's start and end, not to the code one level above:-( --Jach From fh at fhaun.de Mon Jan 11 06:54:45 2016 From: fh at fhaun.de (Frank Haun) Date: 11 Jan 2016 11:54:45 -0000 Subject: Which Python editor has this feature? References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <562ad3ae-5110-44f3-a4f1-4374ddde3ffb@googlegroups.com> Message-ID: <86egdouy0c.fsf@m7008.fhaun.de> On Sun, 10 Jan 2016 19:49:47 -0800 (PST), Rustom Mody wrote: > On Monday, January 11, 2016 at 7:30:10 AM UTC+5:30, jf... at ms4.hinet.net wrote: >> It lets you jump between the current cursor position and the line the >> upper level indentation start, something like the bracket matching in >> C editor. Because of Python use indentation as its code block mark, >> It might be helpful if we can jump between different level of it:-) >> >> >> --Jach Fong > > Recent emacs' python mode has all these bunch of python-nav-* > functions. You may have (as usual with emacs!) to choose which you > like best, ie not all are not bound to keys. Emacs is great for python editing. I use elpy-mode on top of emacs python-mode. And company-mode for completion. Frank From python.list at tim.thechases.com Mon Jan 11 06:59:53 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 11 Jan 2016 05:59:53 -0600 Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> Message-ID: <20160111055953.494f20c9@bigbox.christie.dr> On 2016-01-11 03:08, jfong at ms4.hinet.net wrote: > Tim Chase at 2016/1/11 UTC+8 11:16:27AM wrote? > > :nnoremap Q '?^'.repeat(' ', > > (strlen(substitute(getline('.'), '\S.*', '', > > ''))-&sw)).'\S?e'."\" > > But, but... this line??? won't it goes too far for a human being to > read? Yes, it's a bit obscure. But it's a mapping that creates a "Q" command (feel free to map to whatever other key you have available), so once you've created that mapping (you can put it in your vimrc), all you have to remember is that "Q", not the whole messy string. -tkc From cjw at ncf.ca Mon Jan 11 07:06:34 2016 From: cjw at ncf.ca (Colin W.) Date: Mon, 11 Jan 2016 12:06:34 +0000 (UTC) Subject: Python 3.4.4 Install References: <64dd3d38-cecd-40ca-bf53-5427d9374a65@googlegroups.com> <5691bfd0$0$1603$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano pearwood.info> writes: > > On Sun, 10 Jan 2016 09:25 am, Colin J. Williams wrote: > > > The reponse is not understood. > > > > *** Python 3.4.4rc1 (v3.4.4rc1:04f3f725896c, Dec 6 2015, 17:06:10) [MSC > > v.1600 64 bit (AMD64)] on win32. *** > >>>> File "C:\Users\Adm\AppData\Roaming\PyScripter\python_init.py", line 1 > > ??:V?t??{Z?N)??2%h??L"??w?,????J > > ^ > > SyntaxError: invalid syntax > > That doesn't look anything like Python code to me. It looks like you have > corrupted files. Who knows how they have been corrupted. Try re-installing > Pyscripter, or revert from backup. Also, you should make sure you scan your > system for viruses (possibly you have a randsomware virus encrypting files > behind your back) and do a disk check in case the disk is dying. > I am now trying o install the binary version, 64 bit, of Python 3.4.4 from Python.org. I get the message: Python 3.4.4 (64 bit) There is a problem with the Windows [10] Installer Package. A program required for this install to complete could not be run. Contact your support personnel or package vendor. Colin W. From JorgeAlberto.Martinez at ge.com Mon Jan 11 08:18:02 2016 From: JorgeAlberto.Martinez at ge.com (Martinez, Jorge Alberto (GE Aviation)) Date: Mon, 11 Jan 2016 13:18:02 +0000 Subject: licenses In-Reply-To: References: <4C734AA4F3F9AC4891265961BD4D48539929AA@CINMBCNA07.e2k.ad.ge.com> Message-ID: <4C734AA4F3F9AC4891265961BD4D4853992CF0@CINMBCNA07.e2k.ad.ge.com> Thank you very much for your reply. Best Regards From: Cody Piersall [mailto:cody.piersall at gmail.com] Sent: Sunday, January 10, 2016 1:43 PM To: python-list at python.org Cc: Martinez, Jorge Alberto (GE Aviation) Subject: Re: licenses On Fri, Jan 8, 2016 at 1:41 PM, Martinez, Jorge Alberto (GE Aviation) > wrote: > > Hello > We develop applications here with Python and I want to know if there's issues by using. > We use NumPy, PyDaqMx, Py Visa > > How can we cover this licensing? I am not a lawyer, and this is not legal advice. * NumPy is BSD-licensed, which means you can use NumPy in a commercial product as long as you include its license. * PyDAQmx is BSD-licensed as well. (You can find that information in their GitHub repository's README, https://github.com/clade/PyDAQmx) * Py Visa is MIT licensed (info on their GitHub: https://github.com/hgrecco/pyvisa/blob/master/LICENSE), which means you can also use it in your software as long as you include the license. For summaries of lots of licenses, you can look at tldrlegal.com. * BSD license: https://tldrlegal.com/license/bsd-3-clause-license-(revised) * MIT license: https://tldrlegal.com/license/mit-license It's never a bad idea to consult a lawyer. Since you work for GE, I would imagine there is an army of lawyers happy to answer this question at your disposal. Finding out how to talk to them might be the hard part. Cody From jldunn2000 at gmail.com Mon Jan 11 08:24:32 2016 From: jldunn2000 at gmail.com (loial) Date: Mon, 11 Jan 2016 05:24:32 -0800 (PST) Subject: can't decompress data; zlib not available Message-ID: I am migrating a python script from Red hat linux REL 6.6 to AIX 7.1 I am using python 2.7.10 On AIX I the ror zipimport.ZipImportError: can't decompress data; zlib not available Any ideas how to get this to work on AIX? From alister.ware at ntlworld.com Mon Jan 11 09:06:43 2016 From: alister.ware at ntlworld.com (Alister) Date: Mon, 11 Jan 2016 14:06:43 +0000 Subject: can't decompress data; zlib not available In-Reply-To: References: Message-ID: On 11/01/16 13:24, loial wrote: > I am migrating a python script from Red hat linux REL 6.6 to AIX 7.1 > > I am using python 2.7.10 > > On AIX I the ror > > zipimport.ZipImportError: can't decompress data; zlib not available > > Any ideas how to get this to work on AIX? > > > install the zlib library's (these are part of the OS & not Python) on a red hat system try : yum install zlib From mafagafogigante at gmail.com Mon Jan 11 09:22:43 2016 From: mafagafogigante at gmail.com (Bernardo Sulzbach) Date: Mon, 11 Jan 2016 12:22:43 -0200 Subject: Continously opening modify setup In-Reply-To: References: Message-ID: This seems to be an issue with your PyCharm installation, not with Python itself. Also, this looks a lot like malware to me. If you are sure it is not a problem with your (almost certainly Windows) machine, consider contacting JetBrains. From mr.eightnoteight at gmail.com Mon Jan 11 09:53:44 2016 From: mr.eightnoteight at gmail.com (srinivas devaki) Date: Mon, 11 Jan 2016 20:23:44 +0530 Subject: How to remove item from heap efficiently? In-Reply-To: <5692A795.3070904@mail.de> References: <568EEC40.7070807@mail.de> <568FE797.6090808@mail.de> <5692A795.3070904@mail.de> Message-ID: On Jan 11, 2016 12:18 AM, "Sven R. Kunze" wrote: > Indeed. I already do the sweep method as you suggested. ;) > > Additionally, you provided me with a reasonable condition when to do the sweep in order to achieve O(log n). Thanks much for that. I currently used a time-bases approached (sweep each 20 iterations). > > PS: Could you add a note on how you got to the condition ( 2*self.useless_b > len(self.heap_b))? > oh that's actually simple, that condition checks if more than half of heap is useless items. the sweep complexity is O(len(heap)), so to keep the extra amortized complexity as O(1), we have to split that work(virtually) with O(len(heap)) operations, so when our condition becomes true we have done len(heap) operations, so doing a sweep at that time means we splitted that work(O(len(heap))) with every operation. From rustompmody at gmail.com Mon Jan 11 10:19:41 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 11 Jan 2016 07:19:41 -0800 (PST) Subject: Python installation in windows In-Reply-To: References: Message-ID: <3d609795-016b-477c-be2c-8b37194df0ac@googlegroups.com> On Monday, January 11, 2016 at 6:32:14 PM UTC+5:30, navneet bhatele wrote: > I have been trying to install the "python-3.5.1-amd64-webinstall " many > times and the Set up failed is shown up with named 0*80070002 - file > doesn't exist in dialog box Which windows? XP and 3.5 are not compatible For XP use 3.4 From invalid at invalid.invalid Mon Jan 11 10:27:25 2016 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 11 Jan 2016 15:27:25 +0000 (UTC) Subject: licenses References: <4C734AA4F3F9AC4891265961BD4D48539929AA@CINMBCNA07.e2k.ad.ge.com> Message-ID: On 2016-01-10, Cody Piersall wrote: > It's never a bad idea to consult a lawyer. Since you work for GE, I would > imagine there is an army of lawyers That is udoubtedly true. > happy to answer this question Whether you can actually get an answer out of any of them within before the expiry of the project is another issue entirely. > at your disposal. Finding out how to talk to them might be the hard > part. -- Grant Edwards grant.b.edwards Yow! RELATIVES!! at gmail.com From callum.melville1 at gmail.com Mon Jan 11 14:17:42 2016 From: callum.melville1 at gmail.com (Sean Melville) Date: Mon, 11 Jan 2016 19:17:42 +0000 Subject: python Message-ID: Hello, I've downloaded python 3.5.1 but when I try and open it always says that I have to either uninstall it, repair it or modify it. However, I've tried all of them and it still doesn't work. >From Callum From cs at zip.com.au Mon Jan 11 15:16:43 2016 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 12 Jan 2016 07:16:43 +1100 Subject: Python installation in windows In-Reply-To: <3d609795-016b-477c-be2c-8b37194df0ac@googlegroups.com> References: <3d609795-016b-477c-be2c-8b37194df0ac@googlegroups.com> Message-ID: <20160111201643.GA27813@cskk.homeip.net> On 11Jan2016 07:19, rusi wrote: >On Monday, January 11, 2016 at 6:32:14 PM UTC+5:30, navneet bhatele wrote: >> I have been trying to install the "python-3.5.1-amd64-webinstall " many >> times and the Set up failed is shown up with named 0*80070002 - file >> doesn't exist in dialog box > >Which windows? >XP and 3.5 are not compatible >For XP use 3.4 I am not a Windows user, but this question occurs a lot. Is this cryptic message a missing dependency of the installer or of Python. Because if it is Python surely we should be doing potential users a favour and mentioning this 3.5 vs XP (and earlier?) issue in nice human friendly prose instead of complaining about an obscure missing library file? As things stand, many users infer that they have a corrupt or broken download, not that they needed a different version of Python. Should this be raised on python-dev? Cheers, Cameron Simpson From cs at zip.com.au Mon Jan 11 15:33:30 2016 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 12 Jan 2016 07:33:30 +1100 Subject: python In-Reply-To: References: Message-ID: <20160111203330.GA19364@cskk.homeip.net> On 11Jan2016 19:17, Sean Melville wrote: >I've downloaded python 3.5.1 but when I try and open it always says that I >have to either uninstall it, repair it or modify it. However, I've tried >all of them and it still doesn't work. On what operating system are you trying to install it? If you are using XP you need to download Python 3.4; Python 3.5 is not compatible with it. Cheers, Cameron Simpson From callum.melville1 at gmail.com Mon Jan 11 15:45:43 2016 From: callum.melville1 at gmail.com (Sean Melville) Date: Mon, 11 Jan 2016 20:45:43 +0000 Subject: python In-Reply-To: <20160111203330.GA19364@cskk.homeip.net> References: <20160111203330.GA19364@cskk.homeip.net> Message-ID: <4C610221-0D37-48AC-BC70-42FAC58C3CC6@gmail.com> I don't believe it's xp, it's a new laptop > On 11 Jan 2016, at 20:33, Cameron Simpson wrote: > >> On 11Jan2016 19:17, Sean Melville wrote: >> I've downloaded python 3.5.1 but when I try and open it always says that I >> have to either uninstall it, repair it or modify it. However, I've tried >> all of them and it still doesn't work. > > On what operating system are you trying to install it? > > If you are using XP you need to download Python 3.4; Python 3.5 is not compatible with it. > > Cheers, > Cameron Simpson From fanjianling at gmail.com Mon Jan 11 16:20:04 2016 From: fanjianling at gmail.com (Jianling Fan) Date: Mon, 11 Jan 2016 15:20:04 -0600 Subject: python In-Reply-To: <4C610221-0D37-48AC-BC70-42FAC58C3CC6@gmail.com> References: <20160111203330.GA19364@cskk.homeip.net> <4C610221-0D37-48AC-BC70-42FAC58C3CC6@gmail.com> Message-ID: It seems like that python was already installed in your computer. Please check . On 11 January 2016 at 14:45, Sean Melville wrote: > I don't believe it's xp, it's a new laptop > > > >> On 11 Jan 2016, at 20:33, Cameron Simpson wrote: >> >>> On 11Jan2016 19:17, Sean Melville wrote: >>> I've downloaded python 3.5.1 but when I try and open it always says that I >>> have to either uninstall it, repair it or modify it. However, I've tried >>> all of them and it still doesn't work. >> >> On what operating system are you trying to install it? >> >> If you are using XP you need to download Python 3.4; Python 3.5 is not compatible with it. >> >> Cheers, >> Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Mon Jan 11 16:21:54 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Jan 2016 16:21:54 -0500 Subject: Which Python editor has this feature? In-Reply-To: <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> Message-ID: On 1/11/2016 6:04 AM, jfong at ms4.hinet.net wrote: > I am studying the PyUSB package now as the learning object of how to > write a Python program in a "formal" way. In those modules, there are > many comment inserted between codes to explain what it does. It's > good to the user comprehension, but also easily makes a Class size > expanded to over 100 lines. Also many Classes has the same named > method such as __getitem__ etc. When searching a specific name I > usually have to roll back the screen a few times to find out what > Class I am looking at. That's really annoy. IDLE has an optional 'code context' feature that shows header lines that have scrolled up off the top of the screen. This would let you see which class you are in, In current releases, Code Context is configured in the Extensions tab of the Settings dialog. For previous releases after Aug 2014, it was configured in the separate Extensions dialog. The most important setting is the (fixed) number of lines in the context box (default 3). I would like to make the box re-size as needed, so the outermost context (like the class statement) is always visible without using more screen space than needed. The context is currently read-only. Clicking on context lines does nothing. As a result of this thread, I am thinking that clicking on a context line should scroll up the main text window to display that line at the top (and remove that line and any below from the context box). I *think* that this should be fairly easy. -- Terry Jan Reedy From homiemusa at gmail.com Mon Jan 11 16:22:30 2016 From: homiemusa at gmail.com (homiemusa at gmail.com) Date: Mon, 11 Jan 2016 13:22:30 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <79ce6cf5-4bad-47f6-8824-44ce9849d825@googlegroups.com> <098af50f-4aef-4b72-8e16-c011054f9a40@googlegroups.com> Message-ID: <63ccdec5-87ed-452d-8878-92403afb2c68@googlegroups.com> On Monday, December 28, 2015 at 12:39:41 PM UTC+3, Won Chang wrote: > def manipulate_data(kind, data): > if kind == 'list': > return list(data)[::-1] > elif kind == 'set': > return set(data) > elif kind == 'dictionary': > return dict.keys(data) > manipulate_data("list", range(1,6)) > manipulate_data("set", {"a", "b", "c", "d", "e",}) > manipulate_data("dictionary", {"apples": 23, "oranges": 15, "mangoes": 3, "grapes": 45}) > just use a function to add "ANDELA", "TIA", "AFRICA" to the set, the u are don how con i add a fuction From PointedEars at web.de Mon Jan 11 16:27:45 2016 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Mon, 11 Jan 2016 22:27:45 +0100 Subject: python References: <20160111203330.GA19364@cskk.homeip.net> Message-ID: <8457129.UGjNnsV0nl@PointedEars.de> Sean Melville wrote: >> On 11 Jan 2016, at 20:33, Cameron Simpson wrote: >>> On 11Jan2016 19:17, Sean Melville wrote: >>> I've downloaded python 3.5.1 but when I try and open it always says that >>> I have to either uninstall it, repair it or modify it. However, I've >>> tried all of them and it still doesn't work. >> >> On what operating system are you trying to install it? >> >> If you are using XP you need to download Python 3.4; Python 3.5 is not >> compatible with it. > > I don't believe it's xp, it's a new laptop You can quickly find out by pressing the key combination +. Please do not top-post. The bats are reading elsewhere ;-) -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From tjreedy at udel.edu Mon Jan 11 16:36:55 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Jan 2016 16:36:55 -0500 Subject: python In-Reply-To: References: Message-ID: On 1/11/2016 2:17 PM, Sean Melville wrote: > I've downloaded python 3.5.1 but when I try and open it You need to be more specific. (Is 'it' the python installer or python program?) 1. What version of Windows, including 32/64 bit. For pre-10, service packs matter (you should have the latest). 2. What installer did you download, from where? There are, I believe, 6 choices at python.org. 3. How did you run the installer? Admin or normal user? What options did you select. Did the installer say 'finished' or 'error'. 4. How you you try to run Python (if indeed you did)? Be very specific here, as this may be the problem. > always says that I > have to either uninstall it, repair it or modify it. However, I've tried > all of them and it still doesn't work. You see this if you open the installer after installing. You should not see this if you run python itself. You will not see this if python is properly installed and you run python and not the installer. -- Terry Jan Reedy From ahlusar.ahluwalia at gmail.com Mon Jan 11 16:54:48 2016 From: ahlusar.ahluwalia at gmail.com (Saran Ahluwalia) Date: Mon, 11 Jan 2016 16:54:48 -0500 Subject: Understanding " 'xml.etree.ElementTree.Element' does not support the buffer interface" In-Reply-To: References: <876e5e0c-42c4-416a-90c0-ac2641e81949@googlegroups.com> <56929498$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hi Steven: Just as an update - apparently there were bytes in the Windows Command Terminal that were interrupting the process execution. I didn't realize this was happening until I dug around Windows' Q&A forum. Cheers On Sun, Jan 10, 2016 at 12:53 PM, Saran Ahluwalia < ahlusar.ahluwalia at gmail.com> wrote: > Hi Steven: > > The previous code was a stand along under the " if __name__ == > '__main__': ". The full function suite that I have made (and indeed > includes a try and except block): > > import os.path > import sys > import csv > from io import StringIO > import xml.etree.cElementTree as ElementTree > from xml.etree.ElementTree import XMLParser > # import xml > # import xml.sax > # from xml.sax import ContentHandler > > > def flatten_list(self, aList, prefix=''): > > for i, element in enumerate(aList, 1): > eprefix = "{}{}".format(prefix, i) > if element: > # treat like dict > if len(element) == 1 or element[0].tag != element[1].tag: > yield from flatten_dict(element, eprefix) > # treat like list > elif element[0].tag == element[1].tag: > yield from flatten_list(element, eprefix) > elif element.text: > text = element.text.strip() > if text: > yield eprefix[:].rstrip('.'), element.text > > > def flatten_dict(parent_element, prefix=''): > > prefix = prefix + parent_element.tag > if parent_element.items(): > for k, v in parent_element.items(): > yield prefix + k, v > for element in parent_element: > eprefix = element.tag > if element: > # treat like dict - we assume that if the first two tags > # in a series are different, then they are all different. > if len(element) == 1 or element[0].tag != element[1].tag: > yield from flatten_dict(element, prefix=prefix) > # treat like list - we assume that if the first two tags > # in a series are the same, then the rest are the same. > else: > # here, we put the list in dictionary; the key is the > # tag name the list elements all share in common, and > # the value is the list itself > yield from flatten_list(element, prefix=eprefix) > # if the tag has attributes, add those to the dict > if element.items(): > for k, v in element.items(): > yield eprefix+k > # this assumes that if you've got an attribute in a tag, > # you won't be having any text. This may or may not be a > # good idea -- time will tell. It works for the way we are > # currently doing XML configuration files... > elif element.items(): > for k, v in element.items(): > yield eprefix+k > # finally, if there are no child tags and no attributes, extract > # the text > else: > yield eprefix, element.text > > > > def just_xml_data(path): > with open(path, 'rU', encoding='UTF-8') as data: > separated = data.read().split('","') > print(separated) > try: > x = ElementTree.XML(separated[3]) > print(x) > xml.etree.ElementTree.dump(x) > y = ElementTree.XML(separated[4]) > xml.etree.ElementTree.dump(y) > # response = ElementTree.XML(separated[4]) # work on the > Response column > # root = ElementTree.XML(response) #serialize and parse into > XML object > except Exception as e: > print(e) > else: > xml_field = dict(flatten_dict(y)) > return xml_field > > def read_data(path): > headers= set() > rows = [] > with open(path, 'rU', encoding='utf-8') as data: > reader = csv.DictReader(data, dialect=csv.excel, > skipinitialspace=True) > for row in reader: > xml_field = row["CLIENT_RESP_DATA"] > # xml_data = just_xml_data(xml_field) ## function > if xml_data is not None: > row.update(xml_data) > headers.update(row.keys()) > rows.append(row) > else: > print("Failure") > pass > with open(os.path.splitext(textFile)[0] + '_' + 'parsed' + '.csv', > "wt", newline='') as output_file: > wr = csv.writer(output_file) > csv_headers = list(headers) > wr.writerow(csv_headers) > for row in rows: > values = [] > for field in csv_headers: > value = row.get(field, None) > values.append(value) > wr.writerow(values) > return output_file > > > > if __name__ == '__main__': > Response = "s.csv" > just_xml_data(Response) > > > Hopefully this will provide you with enough information to emulate > (apologies for any and all indentation errors during the copy and paste). > FYI - I still receive the same error. > > > On Sun, Jan 10, 2016 at 12:27 PM, Steven D'Aprano > wrote: > >> On Mon, 11 Jan 2016 02:04 am, kbtyo wrote: >> >> > Hello Everyone: >> > >> > I am curious to know why I receive the aforementioned message. I am >> using >> > Python 3.4.3 and Windows 7. I am running the following script from >> Windows >> > Powershell: >> >> I created a file "data" containing the input data you said: >> >> > The input data is as follows: >> > >> > A,B,C,D,E,F,G,H,I,J >> > "3","8","1","> RequestType="FOO">> > />2312> > >> />285SChecking10","> > TransactionID="2" >> > >> >> RequestType="HoldInquiry">TrueFalseFalseFalseFalse0000',0001,0070,","1967-12-25 >> > 22:18:13.471000","2005-12-25 22:18:13.768000","2","70","0" >> >> >> >> and then a script containing the code you said you used: >> >> > import xml.etree.cElementTree as ElementTree >> > from xml.etree.ElementTree import XMLParser >> >> > Response = 's.csv' >> > with open(Response, 'rU', encoding='utf-8') as data: >> > separated = data.read().split('","') >> > x = ElementTree.XML(separated[3]) >> > y = ElementTree.XML(separated[4]) >> > print(dict(flatten_dict(x))) >> > print(dict(flatten_dict(y))) >> >> >> I get a completely different error to you, complete with traceback as >> expected: >> >> Traceback (most recent call last): >> File "/tmp/testxml.py", line 9, in >> print(dict(flatten_dict(x))) >> NameError: name 'flatten_dict' is not defined >> >> >> This shows me three things: >> >> (1) The calls to ElementTree.XML work fine, and don't raise an exception; >> >> (2) There is no error message referring to xml.etree.ElementTree.Element >> or >> the buffer interface; >> >> (3) The code you posted is clearly not the code you actually ran. At the >> very least, it is not *all* the code you ran. >> >> We cannot tell what it wrong with your code if you don't show us the code >> that fails. I suggest you read this webpage: >> >> http://www.sscce.org/ >> >> and follow the advice given. It's written for Java, but applies to any >> programming language. Hopefully you will either solve your problem, or be >> able to generate a sufficiently small piece of code that we can work with. >> >> >> You also suggest that your code works when running in a Jupyter Notebook. >> It >> is unlikely (but not impossible!) that exactly the same code will run >> differently when run as a script and when run under Jupyter. More likely, >> there is some difference between the code, something you have written in >> the Notebook but not included in the script. >> >> If it is exactly the same code, then perhaps it is a difference in the two >> environments. Does Jupyter set up the environment differently to what you >> get when running a script? >> >> Finally, in another post, you state: >> >> "That is the only message (*xml.etree.ElementTree.Element' does not >> support >> the buffer interface"*). There is no traceback." >> >> >> That is very unlikely with the code sample you posted. If true, that gives >> more evidence that you are running code which is different from what you >> have posted here. Perhaps your ACTUAL code (not the pretend code you >> showed >> us) includes a try...except block like this: >> >> try: >> some code goes here >> except Exception as err: >> print(err) >> sys.exit() >> >> >> or similar. If so, TAKE IT OUT. That is destroying useful debugging >> information and making it more difficult to solve your problem. >> >> >> >> >> >> -- >> Steven >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > From homiemusa at gmail.com Mon Jan 11 17:07:49 2016 From: homiemusa at gmail.com (homiemusa at gmail.com) Date: Mon, 11 Jan 2016 14:07:49 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: References: <57a7133b-8ee0-4196-b2e5-6aa393a4e5fb@googlegroups.com> Message-ID: <46ed5b1a-ce41-41c8-9570-a8f410db6d01@googlegroups.com> On Tuesday, December 29, 2015 at 1:30:18 AM UTC+3, Cameron Simpson wrote: > On 28Dec2015 01:34, Prince Udoka wrote: > >bu i have come up with a solution, that will work but encounter a problem in the set, giving set not manipulated correctly: > > > >def manipulate_data(kind, data): > > if kind == 'list': > > return list(data)[::-1] > > elif kind == 'set': > > return set(data) > > elif kind == 'dictionary': > > return dict.keys(data) > >manipulate_data("list", range(1,6)) > >manipulate_data("set", {"a", "b", "c", "d", "e", "ANDELA", "TIA", "AFRICA"}) > >manipulate_data("dictionary", {"apples": 23, "oranges": 15, "mangoes": 3, "grapes": 45}) > > > >the thing now is the function to use in adding "ANDELA", "TIA", "AFRICA" > >pls 4give my use of language > > You are very close. Let me remind you of the original task text: > > add items `"ANDELA"`, `"TIA"` and `"AFRICA"` to the set and return the > resulting set > > Your previous attempt (with hardwired values inside the function) actually had > code to do it. > > While you have pulled out all the hardwired values from the function (good) and > put them in the external calls, note that the task explicitly says "add items > `"ANDELA"`, `"TIA"` and `"AFRICA"` to the set". So _those_ values _are_ > supposed to be hardwired inside the function - they are a fixed part of the > task. So move them back in, as in your previous attempt. > > There is some ambiguity in that part of the question: should you return a _new_ > set consistint of the original set plus the three new values, or simply add the > three values to the original set? Your prior code modified the original set, > which may fit the task specification. > > However, it is a common design objective that functions do not, _normally_, > modify their arguments. So, consider this code: > > set1 = {"a", "b", "c", "d", "e"} > set2 = manipulate_data("set", set1) > > After running this, set2 should look like this: > > {"a", "b", "c", "d", "e", "ANDELA", "TIA", "AFRICA"} > > (in some order -- sets are not ordered). However, what about set1? In your > current code, set1 is modified, so it will be the same. But you can imagine > that it would be more useful for the caller if set1 were unchanged. > > In python, the convention is usually that if a function returns the new value > then it should not modify the original. So you should probably construct a copy > of the original set and modify that: > > data = set(data) > ... add the new values ... > return data > > Cheers, > Cameron Simpson please help me how can i add a function to this code am a star From travisgriggs at gmail.com Mon Jan 11 17:14:05 2016 From: travisgriggs at gmail.com (Travis Griggs) Date: Mon, 11 Jan 2016 14:14:05 -0800 Subject: Confused by python-dbus weird behavior In-Reply-To: References: <4ac97a67-2527-424e-90e2-b714528977c8@googlegroups.com> Message-ID: <1C66100C-EA6D-4694-8D6E-6B176AEABDA7@gmail.com> This may not be a great list for this question (which would be?); it?s a big group, and I?m hoping there?s some people here that cross into these same areas. I?m new to dbus, it seems it?s a sort of CORBA for the Linux world. :) Python seems to be a popular way to interact with it. I?m trying to interact with the BlueZ services for Bluetooth LE stuff, and the scant hints I can find seem to indicate dbus is the preferred way going forward. The BlueZ distribution even provides example code. That said, my question should be independent of whether this was BLE or a dbus interface for a Calculator program. There is a class defined as such: class Characteristic(dbus.service.Object): def __init__(self, bus, index, uuid, flags, service): # ? set a bunch of attributes dbus.service.Object.__init__(self, bus, self.path) @dbus.service.method(GATT_CHRC_IFACE, in_signature='ay') def WriteValue(self, value): print('Default WriteValue called, returning error?) raise NotSupportedException() Then I have a subclass of my own: class MyCharacteristic(Characteristic): def __init__(self, bus, index, uuid, flags, service): Characteristic.__init__(self, bus, index, uuid, flags, service) # ? set some of my own attributes def WriteValue(self, value): print(?Got write value:?, value) self.anotherMethod(value) print(?back from anotherMethod?) def anotherMethod(self, value): print(?pondering this value:?, value) My program does not call WriteValue directly. It seems to be called by the bluetooth machinery. The mainloop, or something like that. I don?t honestly know. I just know I use some other boilerplate code involving registration and the mainloop, to get it all running. And so the MyCharacteristic.WriteValue() method DOES get fired. I see the output. But when it gets to the anotherMethod call, it just seems to... not. More callbacks may fire later. But that?s the end of that one. I?ve tried this under python2 AND python3. So my basic python-dbus question is: Is this some nuance where a callback method, inheriting from what looks like a proxy of some sort (dbus.service.Object) should/can not send messages to itself? Help me python-obis, help me. You?re my only hope. From jeff at antigravityinc.com Mon Jan 11 17:47:31 2016 From: jeff at antigravityinc.com (jeff at antigravityinc.com) Date: Mon, 11 Jan 2016 14:47:31 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: <1b4984ae-500e-460f-af99-802b8e533e8c@googlegroups.com> References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <1b4984ae-500e-460f-af99-802b8e533e8c@googlegroups.com> Message-ID: <9e938c4a-440d-4f4b-a9ae-a47dae47a28f@googlegroups.com> On Friday, January 8, 2016 at 6:16:49 PM UTC+1, geral... at gmail.com wrote: > On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > > i have these task which i believe i have done well to some level > > > > > > Create a function get_algorithm_result to implement the algorithm below > > > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > > > so i came up with this code below > > > > > > def get_algorithm_result(my_list): > > > if not any(not type(y) is int for y in my_list): > > > largest = 0 > > > for item in range(0,len(my_list)): > > > if largest < my_list[item]: > > > largest = my_list[item] > > > return largest > > > else: > > > > > > return(my_list[-1]) > > > > > > def prime_number(integer): > > > if integer%2==0 and 2!=integer: > > > return False > > > else: > > > return True > > > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > prime_number(1) > > > prime_number(78) > > > prime_number(11) > > > for the question above, there is a unittes which reads > > > > > > import unittest > > > > > > class AlgorithmTestCases(unittest.TestCase): > > > def test_maximum_number_one(self): > > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > self.assertEqual(result, 78, msg="Incorrect number") > > > > > > def test_maximum_number_two(self): > > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > > > def test_prime_number_one(self): > > > result = prime_number(1) > > > self.assertEqual(result, True, msg="Result is invalid") > > > > > > def test_prime_number_two(self): > > > result = prime_number(78) > > > self.assertEqual(result, False, msg="Result is invalid") > > > > > > def test_prime_number_three(self): > > > result = prime_number(11) > > > self.assertEqual(result, True, msg="Result is invalid") > > > but once i run my code ,it returns error saying Test Spec Failed > > > > > > Your solution failed to pass all the tests > > > what is actually wrong with my code? > > > > I had to use a hack to bypass it, worked and I moved on to next quiz > > > could you please share how you bypassed it? Just return the message instead of printing it. > > On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > > i have these task which i believe i have done well to some level > > > > > > Create a function get_algorithm_result to implement the algorithm below > > > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > > > so i came up with this code below > > > > > > def get_algorithm_result(my_list): > > > if not any(not type(y) is int for y in my_list): > > > largest = 0 > > > for item in range(0,len(my_list)): > > > if largest < my_list[item]: > > > largest = my_list[item] > > > return largest > > > else: > > > > > > return(my_list[-1]) > > > > > > def prime_number(integer): > > > if integer%2==0 and 2!=integer: > > > return False > > > else: > > > return True > > > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > prime_number(1) > > > prime_number(78) > > > prime_number(11) > > > for the question above, there is a unittes which reads > > > > > > import unittest > > > > > > class AlgorithmTestCases(unittest.TestCase): > > > def test_maximum_number_one(self): > > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > self.assertEqual(result, 78, msg="Incorrect number") > > > > > > def test_maximum_number_two(self): > > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > > > def test_prime_number_one(self): > > > result = prime_number(1) > > > self.assertEqual(result, True, msg="Result is invalid") > > > > > > def test_prime_number_two(self): > > > result = prime_number(78) > > > self.assertEqual(result, False, msg="Result is invalid") > > > > > > def test_prime_number_three(self): > > > result = prime_number(11) > > > self.assertEqual(result, True, msg="Result is invalid") > > > but once i run my code ,it returns error saying Test Spec Failed > > > > > > Your solution failed to pass all the tests > > > what is actually wrong with my code? > > > > I had to use a hack to bypass it, worked and I moved on to next quiz > > > > On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > > i have these task which i believe i have done well to some level > > > > > > Create a function get_algorithm_result to implement the algorithm below > > > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > > > so i came up with this code below > > > > > > def get_algorithm_result(my_list): > > > if not any(not type(y) is int for y in my_list): > > > largest = 0 > > > for item in range(0,len(my_list)): > > > if largest < my_list[item]: > > > largest = my_list[item] > > > return largest > > > else: > > > > > > return(my_list[-1]) > > > > > > def prime_number(integer): > > > if integer%2==0 and 2!=integer: > > > return False > > > else: > > > return True > > > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > prime_number(1) > > > prime_number(78) > > > prime_number(11) > > > for the question above, there is a unittes which reads > > > > > > import unittest > > > > > > class AlgorithmTestCases(unittest.TestCase): > > > def test_maximum_number_one(self): > > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > self.assertEqual(result, 78, msg="Incorrect number") > > > > > > def test_maximum_number_two(self): > > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > > > def test_prime_number_one(self): > > > result = prime_number(1) > > > self.assertEqual(result, True, msg="Result is invalid") > > > > > > def test_prime_number_two(self): > > > result = prime_number(78) > > > self.assertEqual(result, False, msg="Result is invalid") > > > > > > def test_prime_number_three(self): > > > result = prime_number(11) > > > self.assertEqual(result, True, msg="Result is invalid") > > > but once i run my code ,it returns error saying Test Spec Failed > > > > > > Your solution failed to pass all the tests > > > what is actually wrong with my code? > > > > I had to use a hack to bypass it, worked and I moved on to next quiz > > > > On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > > i have these task which i believe i have done well to some level > > > > > > Create a function get_algorithm_result to implement the algorithm below > > > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > > > so i came up with this code below > > > > > > def get_algorithm_result(my_list): > > > if not any(not type(y) is int for y in my_list): > > > largest = 0 > > > for item in range(0,len(my_list)): > > > if largest < my_list[item]: > > > largest = my_list[item] > > > return largest > > > else: > > > > > > return(my_list[-1]) > > > > > > def prime_number(integer): > > > if integer%2==0 and 2!=integer: > > > return False > > > else: > > > return True > > > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > prime_number(1) > > > prime_number(78) > > > prime_number(11) > > > for the question above, there is a unittes which reads > > > > > > import unittest > > > > > > class AlgorithmTestCases(unittest.TestCase): > > > def test_maximum_number_one(self): > > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > self.assertEqual(result, 78, msg="Incorrect number") > > > > > > def test_maximum_number_two(self): > > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > > > def test_prime_number_one(self): > > > result = prime_number(1) > > > self.assertEqual(result, True, msg="Result is invalid") > > > > > > def test_prime_number_two(self): > > > result = prime_number(78) > > > self.assertEqual(result, False, msg="Result is invalid") > > > > > > def test_prime_number_three(self): > > > result = prime_number(11) > > > self.assertEqual(result, True, msg="Result is invalid") > > > but once i run my code ,it returns error saying Test Spec Failed > > > > > > Your solution failed to pass all the tests > > > what is actually wrong with my code? > > > > I had to use a hack to bypass it, worked and I moved on to next quiz > > > > On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > > i have these task which i believe i have done well to some level > > > > > > Create a function get_algorithm_result to implement the algorithm below > > > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > > > so i came up with this code below > > > > > > def get_algorithm_result(my_list): > > > if not any(not type(y) is int for y in my_list): > > > largest = 0 > > > for item in range(0,len(my_list)): > > > if largest < my_list[item]: > > > largest = my_list[item] > > > return largest > > > else: > > > > > > return(my_list[-1]) > > > > > > def prime_number(integer): > > > if integer%2==0 and 2!=integer: > > > return False > > > else: > > > return True > > > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > prime_number(1) > > > prime_number(78) > > > prime_number(11) > > > for the question above, there is a unittes which reads > > > > > > import unittest > > > > > > class AlgorithmTestCases(unittest.TestCase): > > > def test_maximum_number_one(self): > > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > self.assertEqual(result, 78, msg="Incorrect number") > > > > > > def test_maximum_number_two(self): > > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > > > def test_prime_number_one(self): > > > result = prime_number(1) > > > self.assertEqual(result, True, msg="Result is invalid") > > > > > > def test_prime_number_two(self): > > > result = prime_number(78) > > > self.assertEqual(result, False, msg="Result is invalid") > > > > > > def test_prime_number_three(self): > > > result = prime_number(11) > > > self.assertEqual(result, True, msg="Result is invalid") > > > but once i run my code ,it returns error saying Test Spec Failed > > > > > > Your solution failed to pass all the tests > > > what is actually wrong with my code? > > > > I had to use a hack to bypass it, worked and I moved on to next quiz > > > > On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > > i have these task which i believe i have done well to some level > > > > > > Create a function get_algorithm_result to implement the algorithm below > > > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > > > so i came up with this code below > > > > > > def get_algorithm_result(my_list): > > > if not any(not type(y) is int for y in my_list): > > > largest = 0 > > > for item in range(0,len(my_list)): > > > if largest < my_list[item]: > > > largest = my_list[item] > > > return largest > > > else: > > > > > > return(my_list[-1]) > > > > > > def prime_number(integer): > > > if integer%2==0 and 2!=integer: > > > return False > > > else: > > > return True > > > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > prime_number(1) > > > prime_number(78) > > > prime_number(11) > > > for the question above, there is a unittes which reads > > > > > > import unittest > > > > > > class AlgorithmTestCases(unittest.TestCase): > > > def test_maximum_number_one(self): > > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > self.assertEqual(result, 78, msg="Incorrect number") > > > > > > def test_maximum_number_two(self): > > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > > > def test_prime_number_one(self): > > > result = prime_number(1) > > > self.assertEqual(result, True, msg="Result is invalid") > > > > > > def test_prime_number_two(self): > > > result = prime_number(78) > > > self.assertEqual(result, False, msg="Result is invalid") > > > > > > def test_prime_number_three(self): > > > result = prime_number(11) > > > self.assertEqual(result, True, msg="Result is invalid") > > > but once i run my code ,it returns error saying Test Spec Failed > > > > > > Your solution failed to pass all the tests > > > what is actually wrong with my code? > > > > I had to use a hack to bypass it, worked and I moved on to next quiz > > > > On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > > i have these task which i believe i have done well to some level > > > > > > Create a function get_algorithm_result to implement the algorithm below > > > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > > > so i came up with this code below > > > > > > def get_algorithm_result(my_list): > > > if not any(not type(y) is int for y in my_list): > > > largest = 0 > > > for item in range(0,len(my_list)): > > > if largest < my_list[item]: > > > largest = my_list[item] > > > return largest > > > else: > > > > > > return(my_list[-1]) > > > > > > def prime_number(integer): > > > if integer%2==0 and 2!=integer: > > > return False > > > else: > > > return True > > > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > prime_number(1) > > > prime_number(78) > > > prime_number(11) > > > for the question above, there is a unittes which reads > > > > > > import unittest > > > > > > class AlgorithmTestCases(unittest.TestCase): > > > def test_maximum_number_one(self): > > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > self.assertEqual(result, 78, msg="Incorrect number") > > > > > > def test_maximum_number_two(self): > > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > > > def test_prime_number_one(self): > > > result = prime_number(1) > > > self.assertEqual(result, True, msg="Result is invalid") > > > > > > def test_prime_number_two(self): > > > result = prime_number(78) > > > self.assertEqual(result, False, msg="Result is invalid") > > > > > > def test_prime_number_three(self): > > > result = prime_number(11) > > > self.assertEqual(result, True, msg="Result is invalid") > > > but once i run my code ,it returns error saying Test Spec Failed > > > > > > Your solution failed to pass all the tests > > > what is actually wrong with my code? > > > > I had to use a hack to bypass it, worked and I moved on to next quiz > > > > On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > > i have these task which i believe i have done well to some level > > > > > > Create a function get_algorithm_result to implement the algorithm below > > > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > > > so i came up with this code below > > > > > > def get_algorithm_result(my_list): > > > if not any(not type(y) is int for y in my_list): > > > largest = 0 > > > for item in range(0,len(my_list)): > > > if largest < my_list[item]: > > > largest = my_list[item] > > > return largest > > > else: > > > > > > return(my_list[-1]) > > > > > > def prime_number(integer): > > > if integer%2==0 and 2!=integer: > > > return False > > > else: > > > return True > > > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > prime_number(1) > > > prime_number(78) > > > prime_number(11) > > > for the question above, there is a unittes which reads > > > > > > import unittest > > > > > > class AlgorithmTestCases(unittest.TestCase): > > > def test_maximum_number_one(self): > > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > self.assertEqual(result, 78, msg="Incorrect number") > > > > > > def test_maximum_number_two(self): > > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > > > def test_prime_number_one(self): > > > result = prime_number(1) > > > self.assertEqual(result, True, msg="Result is invalid") > > > > > > def test_prime_number_two(self): > > > result = prime_number(78) > > > self.assertEqual(result, False, msg="Result is invalid") > > > > > > def test_prime_number_three(self): > > > result = prime_number(11) > > > self.assertEqual(result, True, msg="Result is invalid") > > > but once i run my code ,it returns error saying Test Spec Failed > > > > > > Your solution failed to pass all the tests > > > what is actually wrong with my code? > > > > I had to use a hack to bypass it, worked and I moved on to next quiz > > > > On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > > i have these task which i believe i have done well to some level > > > > > > Create a function get_algorithm_result to implement the algorithm below > > > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > > > so i came up with this code below > > > > > > def get_algorithm_result(my_list): > > > if not any(not type(y) is int for y in my_list): > > > largest = 0 > > > for item in range(0,len(my_list)): > > > if largest < my_list[item]: > > > largest = my_list[item] > > > return largest > > > else: > > > > > > return(my_list[-1]) > > > > > > def prime_number(integer): > > > if integer%2==0 and 2!=integer: > > > return False > > > else: > > > return True > > > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > prime_number(1) > > > prime_number(78) > > > prime_number(11) > > > for the question above, there is a unittes which reads > > > > > > import unittest > > > > > > class AlgorithmTestCases(unittest.TestCase): > > > def test_maximum_number_one(self): > > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > self.assertEqual(result, 78, msg="Incorrect number") > > > > > > def test_maximum_number_two(self): > > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > > > def test_prime_number_one(self): > > > result = prime_number(1) > > > self.assertEqual(result, True, msg="Result is invalid") > > > > > > def test_prime_number_two(self): > > > result = prime_number(78) > > > self.assertEqual(result, False, msg="Result is invalid") > > > > > > def test_prime_number_three(self): > > > result = prime_number(11) > > > self.assertEqual(result, True, msg="Result is invalid") > > > but once i run my code ,it returns error saying Test Spec Failed > > > > > > Your solution failed to pass all the tests > > > what is actually wrong with my code? > > > > I had to use a hack to bypass it, worked and I moved on to next quiz > > > > On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > > i have these task which i believe i have done well to some level > > > > > > Create a function get_algorithm_result to implement the algorithm below > > > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > > > so i came up with this code below > > > > > > def get_algorithm_result(my_list): > > > if not any(not type(y) is int for y in my_list): > > > largest = 0 > > > for item in range(0,len(my_list)): > > > if largest < my_list[item]: > > > largest = my_list[item] > > > return largest > > > else: > > > > > > return(my_list[-1]) > > > > > > def prime_number(integer): > > > if integer%2==0 and 2!=integer: > > > return False > > > else: > > > return True > > > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > prime_number(1) > > > prime_number(78) > > > prime_number(11) > > > for the question above, there is a unittes which reads > > > > > > import unittest > > > > > > class AlgorithmTestCases(unittest.TestCase): > > > def test_maximum_number_one(self): > > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > self.assertEqual(result, 78, msg="Incorrect number") > > > > > > def test_maximum_number_two(self): > > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > > > def test_prime_number_one(self): > > > result = prime_number(1) > > > self.assertEqual(result, True, msg="Result is invalid") > > > > > > def test_prime_number_two(self): > > > result = prime_number(78) > > > self.assertEqual(result, False, msg="Result is invalid") > > > > > > def test_prime_number_three(self): > > > result = prime_number(11) > > > self.assertEqual(result, True, msg="Result is invalid") > > > but once i run my code ,it returns error saying Test Spec Failed > > > > > > Your solution failed to pass all the tests > > > what is actually wrong with my code? > > > > I had to use a hack to bypass it, worked and I moved on to next quiz > > > > On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > > i have these task which i believe i have done well to some level > > > > > > Create a function get_algorithm_result to implement the algorithm below > > > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > > > so i came up with this code below > > > > > > def get_algorithm_result(my_list): > > > if not any(not type(y) is int for y in my_list): > > > largest = 0 > > > for item in range(0,len(my_list)): > > > if largest < my_list[item]: > > > largest = my_list[item] > > > return largest > > > else: > > > > > > return(my_list[-1]) > > > > > > def prime_number(integer): > > > if integer%2==0 and 2!=integer: > > > return False > > > else: > > > return True > > > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > prime_number(1) > > > prime_number(78) > > > prime_number(11) > > > for the question above, there is a unittes which reads > > > > > > import unittest > > > > > > class AlgorithmTestCases(unittest.TestCase): > > > def test_maximum_number_one(self): > > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > self.assertEqual(result, 78, msg="Incorrect number") > > > > > > def test_maximum_number_two(self): > > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > > > def test_prime_number_one(self): > > > result = prime_number(1) > > > self.assertEqual(result, True, msg="Result is invalid") > > > > > > def test_prime_number_two(self): > > > result = prime_number(78) > > > self.assertEqual(result, False, msg="Result is invalid") > > > > > > def test_prime_number_three(self): > > > result = prime_number(11) > > > self.assertEqual(result, True, msg="Result is invalid") > > > but once i run my code ,it returns error saying Test Spec Failed > > > > > > Your solution failed to pass all the tests > > > what is actually wrong with my code? > > > > I had to use a hack to bypass it, worked and I moved on to next quiz > > > > On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > > i have these task which i believe i have done well to some level > > > > > > Create a function get_algorithm_result to implement the algorithm below > > > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > > > so i came up with this code below > > > > > > def get_algorithm_result(my_list): > > > if not any(not type(y) is int for y in my_list): > > > largest = 0 > > > for item in range(0,len(my_list)): > > > if largest < my_list[item]: > > > largest = my_list[item] > > > return largest > > > else: > > > > > > return(my_list[-1]) > > > > > > def prime_number(integer): > > > if integer%2==0 and 2!=integer: > > > return False > > > else: > > > return True > > > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > prime_number(1) > > > prime_number(78) > > > prime_number(11) > > > for the question above, there is a unittes which reads > > > > > > import unittest > > > > > > class AlgorithmTestCases(unittest.TestCase): > > > def test_maximum_number_one(self): > > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > self.assertEqual(result, 78, msg="Incorrect number") > > > > > > def test_maximum_number_two(self): > > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > > > def test_prime_number_one(self): > > > result = prime_number(1) > > > self.assertEqual(result, True, msg="Result is invalid") > > > > > > def test_prime_number_two(self): > > > result = prime_number(78) > > > self.assertEqual(result, False, msg="Result is invalid") > > > > > > def test_prime_number_three(self): > > > result = prime_number(11) > > > self.assertEqual(result, True, msg="Result is invalid") > > > but once i run my code ,it returns error saying Test Spec Failed > > > > > > Your solution failed to pass all the tests > > > what is actually wrong with my code? > > > > I had to use a hack to bypass it, worked and I moved on to next quiz > > > > On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > > i have these task which i believe i have done well to some level > > > > > > Create a function get_algorithm_result to implement the algorithm below > > > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > > > so i came up with this code below > > > > > > def get_algorithm_result(my_list): > > > if not any(not type(y) is int for y in my_list): > > > largest = 0 > > > for item in range(0,len(my_list)): > > > if largest < my_list[item]: > > > largest = my_list[item] > > > return largest > > > else: > > > > > > return(my_list[-1]) > > > > > > def prime_number(integer): > > > if integer%2==0 and 2!=integer: > > > return False > > > else: > > > return True > > > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > prime_number(1) > > > prime_number(78) > > > prime_number(11) > > > for the question above, there is a unittes which reads > > > > > > import unittest > > > > > > class AlgorithmTestCases(unittest.TestCase): > > > def test_maximum_number_one(self): > > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > self.assertEqual(result, 78, msg="Incorrect number") > > > > > > def test_maximum_number_two(self): > > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > > > def test_prime_number_one(self): > > > result = prime_number(1) > > > self.assertEqual(result, True, msg="Result is invalid") > > > > > > def test_prime_number_two(self): > > > result = prime_number(78) > > > self.assertEqual(result, False, msg="Result is invalid") > > > > > > def test_prime_number_three(self): > > > result = prime_number(11) > > > self.assertEqual(result, True, msg="Result is invalid") > > > but once i run my code ,it returns error saying Test Spec Failed > > > > > > Your solution failed to pass all the tests > > > what is actually wrong with my code? > > > > I had to use a hack to bypass it, worked and I moved on to next quiz > > > > On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > > i have these task which i believe i have done well to some level > > > > > > Create a function get_algorithm_result to implement the algorithm below > > > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > > > so i came up with this code below > > > > > > def get_algorithm_result(my_list): > > > if not any(not type(y) is int for y in my_list): > > > largest = 0 > > > for item in range(0,len(my_list)): > > > if largest < my_list[item]: > > > largest = my_list[item] > > > return largest > > > else: > > > > > > return(my_list[-1]) > > > > > > def prime_number(integer): > > > if integer%2==0 and 2!=integer: > > > return False > > > else: > > > return True > > > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > prime_number(1) > > > prime_number(78) > > > prime_number(11) > > > for the question above, there is a unittes which reads > > > > > > import unittest > > > > > > class AlgorithmTestCases(unittest.TestCase): > > > def test_maximum_number_one(self): > > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > self.assertEqual(result, 78, msg="Incorrect number") > > > > > > def test_maximum_number_two(self): > > > result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > self.assertEqual(result, "zoo", msg="Incorrect number") > > > > > > def test_prime_number_one(self): > > > result = prime_number(1) > > > self.assertEqual(result, True, msg="Result is invalid") > > > > > > def test_prime_number_two(self): > > > result = prime_number(78) > > > self.assertEqual(result, False, msg="Result is invalid") > > > > > > def test_prime_number_three(self): > > > result = prime_number(11) > > > self.assertEqual(result, True, msg="Result is invalid") > > > but once i run my code ,it returns error saying Test Spec Failed > > > > > > Your solution failed to pass all the tests > > > what is actually wrong with my code? > > > > I had to use a hack to bypass it, worked and I moved on to next quiz > > > > On Friday, 8 January 2016 17:38:11 UTC+1, acushl... at gmail.com wrote: > > On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang wrote: > > > i have these task which i believe i have done well to some level > > > > > > Create a function get_algorithm_result to implement the algorithm below > > > > > > 1- Get a list of numbers L1, L2, L3....LN as argument 2- Assume L1 is the largest, Largest = L1 3- Take next number Li from the list and do the following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last number from the list then 7- return Largest and come out 8- Else repeat same process starting from step 3 > > > > > > Create a function prime_number that does the following Takes as parameter an integer and Returns boolean value true if the value is prime or Returns boolean value false if the value is not prime > > > > > > so i came up with this code below > > > > > > def get_algorithm_result(my_list): > > > if not any(not type(y) is int for y in my_list): > > > largest = 0 > > > for item in range(0,len(my_list)): > > > if largest < my_list[item]: > > > largest = my_list[item] > > > return largest > > > else: > > > > > > return(my_list[-1]) > > > > > > def prime_number(integer): > > > if integer%2==0 and 2!=integer: > > > return False > > > else: > > > return True > > > > > > get_algorithm_result([1, 78, 34, 12, 10, 3]) > > > get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) > > > prime_number(1) > > > prime_number(78) > > > prime_number(11) > > > for the question above, there is a unittes which reads > > > > > > import unittest > > > > > > class AlgorithmTestCases(unittest.TestCase): > > > def test_maximum_number_one(self): > > > result = get_algorithm_result([1, 78, 34, 12, 10, 3]) From skip.montanaro at gmail.com Mon Jan 11 18:26:53 2016 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 11 Jan 2016 17:26:53 -0600 Subject: I'm missing something here... Message-ID: Here's a dumb little bit of code, adapted from a slightly larger script: #!/usr/bin/env python "dummy" import glob import os def compare_prices(*_args): "dummy" return set() def find_problems(cx1, cx2, cx3, prob_dates): "dummy" for fff in sorted(glob.glob("/path/to/*.nrm")): sym = os.path.splitext(os.path.basename(fff))[0] prob_dates |= compare_prices("E:%s"%sym, cx1, cx2, cx3) When I run pylint against it, it complains: junk.py:10: [W0613(unused-argument), find_problems] Unused argument 'prob_dates' I must be misunderstanding something about the |= operator as applied to sets. If I read the docs correctly, s1 |= s2 is equivalent to s1.update(s2). A dumb "test" at the prompt suggests that's true: >>> s1 = set("abc") >>> s2 = set("cde") >>> s1 | s2 set(['a', 'c', 'b', 'e', 'd']) >>> s1 |= s2 >>> s1 set(['a', 'c', 'b', 'e', 'd']) >>> s1 = set("abc") >>> s1.update(s2) >>> s1 set(['a', 'c', 'b', 'e', 'd']) If I change the last line of find_problems to call prob_dates.update(), the message disappears. Why is pylint (1.4.2 BTW) complaining that the prob_dates argument of find_problems is unused when I use the |= operator? Thx, Skip From travisgriggs at gmail.com Mon Jan 11 18:45:35 2016 From: travisgriggs at gmail.com (Travis Griggs) Date: Mon, 11 Jan 2016 15:45:35 -0800 Subject: When I need classes? In-Reply-To: References: <56927b37$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: > On Jan 10, 2016, at 9:48 AM, Bernardo Sulzbach wrote: > > Essentially, classes (as modules) are used mainly for organizational purposes. > > Although you can solve any problem you would solve using classes > without classes, solutions to some big problems may be cheaper and > more feasible using classes. As a long term OO purist practitioner, I would add to this. Obviously, you can organize your code any way you want, with or without classes. You could put all your functions with an odd number of letters in one class, and all of the even numbered ones in another class. Having listened to the guy (Alan Kay) who coined the term (Object Oriented Programming) quite a bit over the years, I believe that the focus of OO (of which classes are a particular implementation approach) is to bind behavior to data. In ?traditional? programming approaches, one focused on the algorithm (behavior) first, and then figured out what data needed to flow where to get the job done. Classes provided a mechanism to turn that equation, generally speaking, around. One thinks about the data first, and then figures out what behavior binds best to that data. And how that data will interact (inter-object behavior, often called messages) to get your job done. For some (many) problems, this can be a real win. And for some, not so much. I think, this is often why, for a simple script, OO just kind of gets in the way. You have a straightforward procedure that you just want to do. The state (data) is not rich enough to make making it the focal point of your program. From python at lucidity.plus.com Mon Jan 11 18:55:23 2016 From: python at lucidity.plus.com (Erik) Date: Mon, 11 Jan 2016 23:55:23 +0000 Subject: I'm missing something here... In-Reply-To: References: Message-ID: <569440EB.4090204@lucidity.plus.com> On 11/01/16 23:26, Skip Montanaro wrote: > If I change the last line of find_problems to call > prob_dates.update(), the message disappears. Why is pylint (1.4.2 BTW) > complaining that the prob_dates argument of find_problems is unused > when I use the |= operator? Is it complaining about that, or is it because the 'for' loop body might be executed zero times? E. From torriem at gmail.com Mon Jan 11 18:59:11 2016 From: torriem at gmail.com (Michael Torrie) Date: Mon, 11 Jan 2016 16:59:11 -0700 Subject: When I need classes? In-Reply-To: References: <56927b37$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <569441CF.6050202@gmail.com> On 01/11/2016 04:45 PM, Travis Griggs wrote: > As a long term OO purist practitioner, I would add to this. > Obviously, you can organize your code any way you want, with or > without classes. You could put all your functions with an odd number > of letters in one class, and all of the even numbered ones in another > class. And of course in Java you have to use classes for namespaces and organization. In python, the equivalent is simply a module. It's essentially a singleton object without having to do any boiler plate. A module can even keep state, so long as you only need to keep track of one instance or set of states at a time. > Having listened to the guy (Alan Kay) who coined the term (Object > Oriented Programming) quite a bit over the years, I believe that the > focus of OO (of which classes are a particular implementation > approach) is to bind behavior to data. In ?traditional? programming > approaches, one focused on the algorithm (behavior) first, and then > figured out what data needed to flow where to get the job done. > Classes provided a mechanism to turn that equation, generally > speaking, around. One thinks about the data first, and then figures > out what behavior binds best to that data. And how that data will > interact (inter-object behavior, often called messages) to get your > job done. For some (many) problems, this can be a real win. And for > some, not so much. > > I think, this is often why, for a simple script, OO just kind of gets > in the way. You have a straightforward procedure that you just want > to do. The state (data) is not rich enough to make making it the > focal point of your program. The beauty of Python is that you can program procedurally, and still work with objects as needed. Every data type in Python is some kind of object and you can call appropriate methods on those objects. Even if you do no OOP programming yourself. For example, some_string = "foo:bar" (a,b) = some_string.split(':') The ease with which Python can be used in many programming paradigms is one reason I like Python so much. From rosuav at gmail.com Mon Jan 11 19:14:59 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jan 2016 11:14:59 +1100 Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> Message-ID: On Tue, Jan 12, 2016 at 8:21 AM, Terry Reedy wrote: > > The context is currently read-only. Clicking on context lines does nothing. > As a result of this thread, I am thinking that clicking on a context line > should scroll up the main text window to display that line at the top (and > remove that line and any below from the context box). I *think* that this > should be fairly easy. That'd be pretty cool. Next IDLE feature request: Can you make it so that, across all platforms, it magically installs PostgreSQL and psycopg2? That would solve so many of my students' problems... ChrisA From sohcahtoa82 at gmail.com Mon Jan 11 19:31:19 2016 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Mon, 11 Jan 2016 16:31:19 -0800 (PST) Subject: I'm missing something here... In-Reply-To: References: Message-ID: On Monday, January 11, 2016 at 3:27:21 PM UTC-8, Skip Montanaro wrote: > Here's a dumb little bit of code, adapted from a slightly larger script: > > #!/usr/bin/env python > > "dummy" > > import glob > import os > > def compare_prices(*_args): > "dummy" > return set() > > def find_problems(cx1, cx2, cx3, prob_dates): > "dummy" > for fff in sorted(glob.glob("/path/to/*.nrm")): > sym = os.path.splitext(os.path.basename(fff))[0] > prob_dates |= compare_prices("E:%s"%sym, cx1, cx2, cx3) > > When I run pylint against it, it complains: > > junk.py:10: [W0613(unused-argument), find_problems] Unused argument 'prob_dates' > > I must be misunderstanding something about the |= operator as applied > to sets. If I read the docs correctly, s1 |= s2 is equivalent to > s1.update(s2). A dumb "test" at the prompt suggests that's true: > > >>> s1 = set("abc") > >>> s2 = set("cde") > >>> s1 | s2 > set(['a', 'c', 'b', 'e', 'd']) > >>> s1 |= s2 > >>> s1 > set(['a', 'c', 'b', 'e', 'd']) > >>> s1 = set("abc") > >>> s1.update(s2) > >>> s1 > set(['a', 'c', 'b', 'e', 'd']) > > If I change the last line of find_problems to call > prob_dates.update(), the message disappears. Why is pylint (1.4.2 BTW) > complaining that the prob_dates argument of find_problems is unused > when I use the |= operator? > > Thx, > > Skip The pipe character on its own also functions as the binary OR operator, with x |= y being a shortcut for x = x | y. If prob_dates is an integer, then it is immutable and the your prob_dates |= compare_prices(...) line won't do anything (The variable is being set, but never again read outside the function and it doesn't change the function's return value), which is probably what pylint is complaining about. Pylint doesn't know that your function is expecting a mutable iterable for the prob_dates argument. If you change it to prob_dates.update(...), does pylint complain? From tjreedy at udel.edu Mon Jan 11 19:36:26 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Jan 2016 19:36:26 -0500 Subject: I'm missing something here... In-Reply-To: References: Message-ID: On 1/11/2016 6:26 PM, Skip Montanaro wrote: > Here's a dumb little bit of code, adapted from a slightly larger script: > > #!/usr/bin/env python > > "dummy" > > import glob > import os > > def compare_prices(*_args): > "dummy" > return set() > > def find_problems(cx1, cx2, cx3, prob_dates): > "dummy" > for fff in sorted(glob.glob("/path/to/*.nrm")): > sym = os.path.splitext(os.path.basename(fff))[0] > prob_dates |= compare_prices("E:%s"%sym, cx1, cx2, cx3) > > When I run pylint against it, it complains: > > junk.py:10: [W0613(unused-argument), find_problems] Unused argument 'prob_dates' > > I must be misunderstanding something about the |= operator as applied > to sets. If I read the docs correctly, s1 |= s2 is equivalent to > s1.update(s2). A dumb "test" at the prompt suggests that's true: > >>>> s1 = set("abc") >>>> s2 = set("cde") >>>> s1 | s2 > set(['a', 'c', 'b', 'e', 'd']) >>>> s1 |= s2 >>>> s1 > set(['a', 'c', 'b', 'e', 'd']) >>>> s1 = set("abc") >>>> s1.update(s2) >>>> s1 > set(['a', 'c', 'b', 'e', 'd']) > > If I change the last line of find_problems to call > prob_dates.update(), the message disappears. Why is pylint (1.4.2 BTW) > complaining that the prob_dates argument of find_problems is unused > when I use the |= operator? A bug in pylint. It should treat both cases the same. -- Terry Jan Reedy From mafagafogigante at gmail.com Mon Jan 11 19:53:44 2016 From: mafagafogigante at gmail.com (Bernardo Sulzbach) Date: Mon, 11 Jan 2016 22:53:44 -0200 Subject: When I need classes? In-Reply-To: References: <56927b37$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 11, 2016 at 9:45 PM, Travis Griggs wrote: > >> On Jan 10, 2016, at 9:48 AM, Bernardo Sulzbach wrote: >> >> Essentially, classes (as modules) are used mainly for organizational purposes. >> >> Although you can solve any problem you would solve using classes >> without classes, solutions to some big problems may be cheaper and >> more feasible using classes. > > I think, this is often why, for a simple script, OO just kind of gets in the way. You have a straightforward procedure that you just want to do. The state (data) is not rich enough to make making it the focal point of your program. Your answer is quite good. I am not a purist myself (when it comes to Java and C++, I am never going to instantiate a Math class to get a logarithm function), but I understand the value of OO from experience. As I mentioned those "tuples and dictionaries" to pass data around, I would like to add that when a single script has two kinds of tuples or dictionaries, you may be better of using two different classes, as having "dedicated" types simplifies project organization and enhances readability. I have never gone "seriously OO" with Python though. I never wrote from scratch an application with more than 10 classes as far as I can remember. However, I would suppose that the interpreter can handle thousands of user-defined classes simultaneously. -- Bernardo Sulzbach From mafagafogigante at gmail.com Mon Jan 11 19:55:55 2016 From: mafagafogigante at gmail.com (Bernardo Sulzbach) Date: Mon, 11 Jan 2016 22:55:55 -0200 Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> Message-ID: On Mon, Jan 11, 2016 at 10:14 PM, Chris Angelico wrote: > > Next IDLE feature request: Can you make it so that, across all > platforms, it magically installs PostgreSQL and psycopg2? That would > solve so many of my students' problems... > Wouldn't this make the installer much bigger? -- Bernardo Sulzbach From skip.montanaro at gmail.com Mon Jan 11 20:04:03 2016 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 11 Jan 2016 19:04:03 -0600 Subject: I'm missing something here... In-Reply-To: References: Message-ID: Sorry, I should have been explicit. prob_dates (the actual argument of the call) is a set. As far as I know pylint does no type inference, so pylint can't tell if the LHS and RHS of the |= operator are appropriate, nor can it tell if it has an update() method. Before writing, I had more-or-less concluded I had hit a bug, but in my experience when I hit something I think is a bug, it's not. It's me. Terry's reply convinced me that I had hit something. Something else just occurred to me. I should have tried disassembling the two versions of the function. Here's the output near prob_dates.update() call: 14 ? ? 62 LOAD_FAST 3 (prob_dates) 65 LOAD_ATTR 6 (update) 68 LOAD_GLOBAL 7 (compare_prices) 71 LOAD_CONST 3 ('E:%s') 74 LOAD_FAST 5 (sym) 77 BINARY_MODULO 78 LOAD_FAST 0 (cx1) 81 LOAD_FAST 1 (cx2) 84 LOAD_FAST 2 (cx3) 87 CALL_FUNCTION 4 90 CALL_FUNCTION 1 Here's how the |= version disassembles in that region: 20 ? ? 62 LOAD_FAST 3 (prob_dates) 65 LOAD_GLOBAL 6 (compare_prices) 68 LOAD_CONST 3 ('E:%s') 71 LOAD_FAST 5 (sym) 74 BINARY_MODULO 75 LOAD_FAST 0 (cx1) 78 LOAD_FAST 1 (cx2) 81 LOAD_FAST 2 (cx3) 84 CALL_FUNCTION 4 87 INPLACE_OR 88 STORE_FAST 3 (prob_dates) I think what's throwing pylint is that last ?STORE_FAST. That tells pylint the argument is ignored. I'll at least bring up the issue on the code-quality list. Thanks, Skip ? From rosuav at gmail.com Mon Jan 11 20:09:42 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jan 2016 12:09:42 +1100 Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> Message-ID: On Tue, Jan 12, 2016 at 11:55 AM, Bernardo Sulzbach wrote: > On Mon, Jan 11, 2016 at 10:14 PM, Chris Angelico wrote: >> >> Next IDLE feature request: Can you make it so that, across all >> platforms, it magically installs PostgreSQL and psycopg2? That would >> solve so many of my students' problems... >> > > Wouldn't this make the installer much bigger? Yes, and it's also completely and utterly inappropriate. But I am seeing a lot of cool magic getting added to Idle. Since I met Python, it's gone from being "well, yeah, Python *does* include a GUI, but it's pretty unexciting compared to others" to "Python includes a pretty decent editor, but it's (unsurprisingly) Python-specific, so I don't use it for multilingual work". Shout-out to Terry and the other Idle devs for the work they've put in. Thanks! ChrisA From steve at pearwood.info Mon Jan 11 20:18:46 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 12 Jan 2016 12:18:46 +1100 Subject: Understanding " 'xml.etree.ElementTree.Element' does not support the buffer interface" References: <876e5e0c-42c4-416a-90c0-ac2641e81949@googlegroups.com> <56929498$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: <56945478$0$1619$c3e8da3$5496439d@news.astraweb.com> On Tue, 12 Jan 2016 08:54 am, Saran Ahluwalia wrote: > Hi Steven: > > Just as an update - apparently there were bytes in the Windows Command > Terminal that were interrupting the process execution. I didn't realize > this was happening until I dug around Windows' Q&A forum. Thanks for letting us know, I'm glad you've solved your problem to your satisfaction, but now I'm curious as to what sort of bytes in the Windows terminal could cause the symptoms you were seeing. Could you share the link(s) you found that explain this? -- Steven From rosuav at gmail.com Mon Jan 11 20:28:24 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jan 2016 12:28:24 +1100 Subject: When I need classes? In-Reply-To: References: <56927b37$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jan 12, 2016 at 11:53 AM, Bernardo Sulzbach wrote: > On Mon, Jan 11, 2016 at 9:45 PM, Travis Griggs wrote: >> >>> On Jan 10, 2016, at 9:48 AM, Bernardo Sulzbach wrote: >>> >>> Essentially, classes (as modules) are used mainly for organizational purposes. >>> >>> Although you can solve any problem you would solve using classes >>> without classes, solutions to some big problems may be cheaper and >>> more feasible using classes. >> >> I think, this is often why, for a simple script, OO just kind of gets in the way. You have a straightforward procedure that you just want to do. The state (data) is not rich enough to make making it the focal point of your program. > > Your answer is quite good. I am not a purist myself (when it comes to > Java and C++, I am never going to instantiate a Math class to get a > logarithm function), but I understand the value of OO from experience. > As I mentioned those "tuples and dictionaries" to pass data around, I > would like to add that when a single script has two kinds of tuples or > dictionaries, you may be better of using two different classes, as > having "dedicated" types simplifies project organization and > enhances readability. > Yeah. One thing I often recommend, especially to students, is to start with the very simplest and most naive code they can knock together, and then look at making it tidier afterwards. Classes, decorators, the unittest setUp/tearDown methods, and even functions themselves, are all just ways of improving code that could be written some other way. They're not rigid structures that you HAVE to comply with or your code is *just* *not* *good* *enough*. So start simplistic, and then look into it like this: "Hey, see how you're doing this five times? There HAS to be a better way!" (With acknowledgement to Raymond Hettinger.) ChrisA From ijansen at broncos.uncfsu.edu Mon Jan 11 20:30:50 2016 From: ijansen at broncos.uncfsu.edu (Jansen, Ingram L) Date: Tue, 12 Jan 2016 01:30:50 +0000 Subject: Installation Message-ID: I can't download Python and I need it for class. Any suggestions? Ingram Jansen Banner ID: 830742998 From jfong at ms4.hinet.net Mon Jan 11 20:51:12 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 11 Jan 2016 17:51:12 -0800 (PST) Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> Message-ID: Terry Reedy at 2016/1/12 UTC+8 5:22:35AM wrote: > IDLE has an optional 'code context' feature that shows header lines that > have scrolled up off the top of the screen. This would let you see > which class you are in, Thanks, Terry. It's just what I am looking for:-) By the way, do you know how to open file in a new tab, instead of in a separate window, in the IDLE editor? --Jach Fong From cfkaran2 at gmail.com Mon Jan 11 21:48:34 2016 From: cfkaran2 at gmail.com (Cem Karan) Date: Mon, 11 Jan 2016 21:48:34 -0500 Subject: How to remove item from heap efficiently? In-Reply-To: References: <568EEC40.7070807@mail.de> <568FE797.6090808@mail.de> <5692A795.3070904@mail.de> Message-ID: On Jan 11, 2016, at 9:53 AM, srinivas devaki wrote: > On Jan 11, 2016 12:18 AM, "Sven R. Kunze" wrote: >> Indeed. I already do the sweep method as you suggested. ;) >> >> Additionally, you provided me with a reasonable condition when to do the > sweep in order to achieve O(log n). Thanks much for that. I currently used > a time-bases approached (sweep each 20 iterations). >> >> PS: Could you add a note on how you got to the condition ( > 2*self.useless_b > len(self.heap_b))? >> > > oh that's actually simple, > that condition checks if more than half of heap is useless items. > the sweep complexity is O(len(heap)), so to keep the extra amortized > complexity as O(1), we have to split that work(virtually) with O(len(heap)) > operations, so when our condition becomes true we have done len(heap) > operations, so doing a sweep at that time means we splitted that > work(O(len(heap))) with every operation. Jumping in late, but... If you want something that 'just works', you can use HeapDict: http://stutzbachenterprises.com/ I've used it in the past, and it works quite well. I haven't tested its asymptotic performance though, so you might want to check into that. Thanks, Cem Karan From mr.eightnoteight at gmail.com Mon Jan 11 22:08:29 2016 From: mr.eightnoteight at gmail.com (srinivas devaki) Date: Tue, 12 Jan 2016 08:38:29 +0530 Subject: How to remove item from heap efficiently? In-Reply-To: <87lh7ywqm7.fsf@nightsong.com> References: <568EEC40.7070807@mail.de> <87lh7ywqm7.fsf@nightsong.com> Message-ID: On Jan 10, 2016 12:05 AM, "Paul Rubin" wrote: > > You could look up "timing wheels" for a simpler practical approach that > the Linux kernel scheduler used to use (I think it changed a few years > ago). this is not related to OP's topic I googled about "timing wheels" and "Linux kernel scheduler", I couldn't find any learning resources or at least the resources that I can understand. Could you please point me to some learning resources for a beginner. From no.email at nospam.invalid Mon Jan 11 22:16:57 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 11 Jan 2016 19:16:57 -0800 Subject: How to remove item from heap efficiently? References: <568EEC40.7070807@mail.de> <87lh7ywqm7.fsf@nightsong.com> Message-ID: <87lh7vv652.fsf@nightsong.com> srinivas devaki writes: > I googled about "timing wheels" and "Linux kernel scheduler" Sorry, correct term was "timer wheel" rather than "timing wheel". http://www.elinux.org/Kernel_Timer_Systems has some links. The Erlang BEAM internal scheduler works the same way, iirc. From steve+comp.lang.python at pearwood.info Mon Jan 11 23:26:09 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 12 Jan 2016 15:26:09 +1100 Subject: OT: There are no words for how broken everything is Message-ID: <56948066$0$11120$c3e8da3@news.astraweb.com> There are no words to explain just how broken everything is. This post tries: https://medium.com/message/everything-is-broken-81e5f33a24e1 but barely covers even a fraction of the breakage. Thanks goodness for anti-virus, right? One of the leading anti-virus vendors in the world, TrendMicro, has been opening their victims^W users' computers to trivially-discoverable remote execution attacks, exposing passwords to the internet, and running an old and insecure browser with security settings disabled (no sandbox). https://code.google.com/p/google-security-research/issues/detail?id=693 What's the worst security screw-up you've seen? The worst I've seen was a sys admin I used to work with who put a new Linux server on the internet with root ssh enabled. Guess what password he used for the root account? "test". Guess how long it took before it was broken into? Less than two hours. That is at the top of my list only because I can prove exactly what happened. Otherwise it would be an incident that I can't completely explain. I have my suspicions, but I'm not entire sure what happened. This was one of the last incidents that drove me off Windows. I was running Windows XP, protected behind a firewall, with commercial up-to-date anti- virus installed. I started up Windows update one day, and went out for a few hours, and came back to find the computer absolutely swarming with malware and the firewall turned off. I don't know what happened, I can only guess that the Windows update process turned off the firewall, but I don't really know. All I know is that whatever it was, it was a completely automated attack, as nobody was home to click on any buttons or visit any dubious websites. Took me three weeks to remove the last of the malware, and another two weeks to track down the cause of an annoying glitch where every 30 seconds the PC would freeze up for a fraction of a second. It was one of the anti-virus programs I had installed. -- Steve From ifeanyioprah at gmail.com Tue Jan 12 00:26:37 2016 From: ifeanyioprah at gmail.com (ifeanyioprah at gmail.com) Date: Mon, 11 Jan 2016 21:26:37 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> Message-ID: <6b98b493-fe07-446d-a58c-b243c342d270@googlegroups.com> Please how did you back it to move over to the next question pls need your help From ifeanyioprah at gmail.com Tue Jan 12 00:30:39 2016 From: ifeanyioprah at gmail.com (ifeanyioprah at gmail.com) Date: Mon, 11 Jan 2016 21:30:39 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: <9e938c4a-440d-4f4b-a9ae-a47dae47a28f@googlegroups.com> References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <1b4984ae-500e-460f-af99-802b8e533e8c@googlegroups.com> <9e938c4a-440d-4f4b-a9ae-a47dae47a28f@googlegroups.com> Message-ID: How do I use hack to move to the next question From ifeanyioprah at gmail.com Tue Jan 12 00:33:58 2016 From: ifeanyioprah at gmail.com (ifeanyioprah at gmail.com) Date: Mon, 11 Jan 2016 21:33:58 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: <9e938c4a-440d-4f4b-a9ae-a47dae47a28f@googlegroups.com> References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <1b4984ae-500e-460f-af99-802b8e533e8c@googlegroups.com> <9e938c4a-440d-4f4b-a9ae-a47dae47a28f@googlegroups.com> Message-ID: How do I use hack to move to the next question From ifeanyioprah at gmail.com Tue Jan 12 00:33:59 2016 From: ifeanyioprah at gmail.com (ifeanyioprah at gmail.com) Date: Mon, 11 Jan 2016 21:33:59 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: <9e938c4a-440d-4f4b-a9ae-a47dae47a28f@googlegroups.com> References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <1b4984ae-500e-460f-af99-802b8e533e8c@googlegroups.com> <9e938c4a-440d-4f4b-a9ae-a47dae47a28f@googlegroups.com> Message-ID: <8e525b69-1d63-4674-8a6a-80ee81b33766@googlegroups.com> How do I use hack to move to the next question From ifeanyioprah at yahoo.com Tue Jan 12 00:48:04 2016 From: ifeanyioprah at yahoo.com (ifeanyioprah at yahoo.com) Date: Tue, 12 Jan 2016 08:48:04 +0300 Subject: =?UTF-8?B?TmVlZCBoZWxwIHdpdGggdGhpcyBhc2FwLg==?= Message-ID: <1452577684.494943577@f402.i.mail.ru> Create a class called?BankAccount 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. This was my solution and I still got error. What should I do. class BankAccount:? ? ? def __init__(self, initial_amount):? ? ? ? ? self.balance = initial_amount? ? ? def deposit(self, amount):? ? ? ? ? self.balance += amount? ? ? def withdraw(self, amount):? ? ? ? ? if self.balance>= amount:? ? ? ? ? ? ? self.balance ?-= ?amount? ? ? ? ? else:? ? ? ? ? ? print('invalid transaction')? a1 = BankAccount (90)? a1.deposit(90)? a1.withdraw(40)? a1.withdraw(1000)? class MinimumBalanceAccount(BankAccount):? ? ? def __init__(self):? ? ? ? ? BankAccount.__init__(self)? Please help me. From rantingrickjohnson at gmail.com Tue Jan 12 01:43:58 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 11 Jan 2016 22:43:58 -0800 (PST) Subject: OT: There are no words for how broken everything is In-Reply-To: <56948066$0$11120$c3e8da3@news.astraweb.com> References: <56948066$0$11120$c3e8da3@news.astraweb.com> Message-ID: <965849d1-1b64-4788-8bfd-18f01a4293a6@googlegroups.com> On Monday, January 11, 2016 at 10:26:40 PM UTC-6, Steven D'Aprano wrote: > [...] > Took me three weeks to remove the last of the malware, and another two weeks > to track down the cause of an annoying glitch where every 30 seconds the PC > would freeze up for a fraction of a second. It was one of the anti-virus > programs I had installed. Three weeks??? Dude, you could have rebuilt the system in a few hours! :-) But this is *WAY* off topic. Hey Steven, they have these new inventions now called "blogs", maybe you should sign up for one? Heck, *I* even have a blog now! http://arantadaykeepsthemonstersaway.blogspot.com/ PS: And there's an nice Easter Egg on my google profile you might enjoy. *wink* From cs at zip.com.au Tue Jan 12 02:13:22 2016 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 12 Jan 2016 18:13:22 +1100 Subject: I'm missing something here... In-Reply-To: <569440EB.4090204@lucidity.plus.com> References: <569440EB.4090204@lucidity.plus.com> Message-ID: <20160112071322.GA12153@cskk.homeip.net> On 11Jan2016 23:55, Erik wrote: >On 11/01/16 23:26, Skip Montanaro wrote: >>If I change the last line of find_problems to call >>prob_dates.update(), the message disappears. Why is pylint (1.4.2 BTW) >>complaining that the prob_dates argument of find_problems is unused >>when I use the |= operator? > >Is it complaining about that, or is it because the 'for' loop body might be >executed zero times? The former. Almost any loop _might_ be executed zero times. Compilers and linters etc should only complain if they can prove the loop is always executed zero times. Cheers, Cameron Simpson From mrkimanindegwa at gmail.com Tue Jan 12 02:21:21 2016 From: mrkimanindegwa at gmail.com (mrkimanindegwa at gmail.com) Date: Mon, 11 Jan 2016 23:21:21 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> Message-ID: On Saturday, December 12, 2015 at 12:05:29 PM UTC+3, Harbey Leke wrote: > Create a class called BankAccount > > .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 > > Please i need help on this i am a beginer into python programming. > > > Also below is a test case given for this project > > > import unittest > class AccountBalanceTestCases(unittest.TestCase): > def setUp(self): > self.my_account = BankAccount(90) > > def test_balance(self): > self.assertEqual(self.my_account.balance, 90, msg='Account Balance Invalid') > > def test_deposit(self): > self.my_account.deposit(90) > self.assertEqual(self.my_account.balance, 180, msg='Deposit method inaccurate') > > def test_withdraw(self): > self.my_account.withdraw(40) > self.assertEqual(self.my_account.balance, 50, msg='Withdraw method inaccurate') > > def test_invalid_operation(self): > self.assertEqual(self.my_account.withdraw(1000), "invalid transaction", msg='Invalid transaction') > > def test_sub_class(self): > self.assertTrue(issubclass(MinimumBalanceAccount, BankAccount), msg='No true subclass of BankAccount') I would try. class BankAccount: def __init__(self,balance): self.balance=balance def deposit(self): print("Please enter ammount to deposit") dep=input() global depbalance depbalance=int(self.balance)+int(dep) print("New balance is",depbalance) def withdraw(self): print("Please enter ammount to withdraw") withd=input() if int(withd) > int(depbalance): print("Invalid Transaction") else: withbalance= depbalance-int(withd) print("New balance after widthdrawal is",withbalance) myAccount=BankAccount(0) myAccount.deposit() myAccount.withdraw() class minimumBalanceAccount(BankAccount): def msg(self): print("This is a sub class") mini=minimumBalanceAccount(0) mini.msg() mini.deposit() mini.withdraw() It may not be as fancy. Although i dont understand the relevance of the test part in your question From tjreedy at udel.edu Tue Jan 12 02:55:30 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Jan 2016 02:55:30 -0500 Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> Message-ID: On 1/11/2016 8:51 PM, jfong at ms4.hinet.net wrote: > Terry Reedy at 2016/1/12 UTC+8 5:22:35AM wrote: >> IDLE has an optional 'code context' feature that shows header lines that >> have scrolled up off the top of the screen. This would let you see >> which class you are in, > > Thanks, Terry. It's just what I am looking for:-) > By the way, do you know how to open file in a new tab, instead of in a separate window, in the IDLE editor? Revamping IDLE to 1. use ttk widgets and 2. become a modern single window app with multiple panes, including a tabbed editor pane, is a goal for 2016. -- Terry Jan Reedy From python at lucidity.plus.com Tue Jan 12 03:24:45 2016 From: python at lucidity.plus.com (Erik) Date: Tue, 12 Jan 2016 08:24:45 +0000 Subject: I'm missing something here... In-Reply-To: <20160112071322.GA12153@cskk.homeip.net> References: <569440EB.4090204@lucidity.plus.com> <20160112071322.GA12153@cskk.homeip.net> Message-ID: <5694B84D.4060803@lucidity.plus.com> On 12/01/16 07:13, Cameron Simpson wrote: > On 11Jan2016 23:55, Erik wrote: >> Is it complaining about that, or is it because the 'for' loop body >> might be executed zero times? > > The former. Almost any loop _might_ be executed zero times. Compilers > and linters etc should only complain if they can prove the loop is > always executed zero times. Sure, but Skip was thinking he'd found a bug - I was just raising the possibility that the bug could have been that the loop was (incorrectly) determined to be executed zero times for some reason. E. From tjreedy at udel.edu Tue Jan 12 03:27:43 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Jan 2016 03:27:43 -0500 Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> Message-ID: On 1/11/2016 8:09 PM, Chris Angelico wrote: > On Tue, Jan 12, 2016 at 11:55 AM, Bernardo Sulzbach > wrote: >> On Mon, Jan 11, 2016 at 10:14 PM, Chris Angelico wrote: >>> >>> Next IDLE feature request: Can you make it so that, across all >>> platforms, it magically installs PostgreSQL and psycopg2? That would >>> solve so many of my students' problems... I detect an invisible smiley at the end of that. PostgresSQL is not a Python package, hence would need a custom script to download and invoke, and would probably need user clicks anyway, at least on Windows. Does/could psycopg2 have such for installing its dependency? Can psycopg2 be installed with pip? There is an issue (#23551) to make a pip GUI and make it accessible from IDLE. We need someone with both pip and tkinter knowledge to either design and write it or mentor a GSOC student to do so. One written, I would add an IDLE menu item to run it, in a separate process, just as done now with turtledemo. >> Wouldn't this make the installer much bigger? See invisible smiley ;-). > Yes, and it's also completely and utterly inappropriate. But I am > seeing a lot of cool magic getting added to Idle. Since I met Python, > it's gone from being "well, yeah, Python *does* include a GUI, but > it's pretty unexciting compared to others" to "Python includes a > pretty decent editor, but it's (unsurprisingly) Python-specific, so I > don't use it for multilingual work". > > Shout-out to Terry and the other Idle devs for the work they've put in. > Thanks! Thank *you*. It is sometimes thankless work. -- Terry Jan Reedy From marko at pacujo.net Tue Jan 12 03:30:39 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 12 Jan 2016 10:30:39 +0200 Subject: OT: There are no words for how broken everything is References: <56948066$0$11120$c3e8da3@news.astraweb.com> <965849d1-1b64-4788-8bfd-18f01a4293a6@googlegroups.com> Message-ID: <87egdn5he8.fsf@elektro.pacujo.net> Rick Johnson : > they have these new inventions now called "blogs", maybe you should > sign up for one? "Sign up for a blog?" What does that mean? Is it like creating a computer program or starting a company: you sign up for one? Anyway, why not use Usenet what it is meant for: discussions. Marko From rosuav at gmail.com Tue Jan 12 03:37:55 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jan 2016 19:37:55 +1100 Subject: OT: There are no words for how broken everything is In-Reply-To: <87egdn5he8.fsf@elektro.pacujo.net> References: <56948066$0$11120$c3e8da3@news.astraweb.com> <965849d1-1b64-4788-8bfd-18f01a4293a6@googlegroups.com> <87egdn5he8.fsf@elektro.pacujo.net> Message-ID: On Tue, Jan 12, 2016 at 7:30 PM, Marko Rauhamaa wrote: > Rick Johnson : > >> they have these new inventions now called "blogs", maybe you should >> sign up for one? > > "Sign up for a blog?" What does that mean? > > Is it like creating a computer program or starting a company: you sign > up for one? It means getting someone to put up a sign saying "BLOG". I'm sure you can find professional signwriters in your area. ChrisA From ashish.makani at gmail.com Tue Jan 12 04:07:29 2016 From: ashish.makani at gmail.com (ashish) Date: Tue, 12 Jan 2016 01:07:29 -0800 (PST) Subject: Tools/libraries to determine the call graph(call flow) of an python program (module/package) Message-ID: <6baea9fe-0464-49c7-9b4d-be1db593efab@googlegroups.com> Hi Folks, I am trying to do the following. I have a moderately complex python module/application X, whose source code i have access to. I run X with the following command python x.py ... Internally, x.py callls y.py, which in turn calls z.py, etc etc x.py ---> y.py ---> z.py ---> u.py ---> v.py Is there a python library/tool/module , to which i give input the start point of X, x.py and the input arguments, arg1, arg2, ..., argn and which can come up with the call graph of X I have tried looking at pycallgraph[0], but havent had much luck with it. 0. https://pypi.python.org/pypi/pycallgraph Any suggestions,advice, pointers welcome. Thanks a ton, ashish "Talk is cheap. Show me the code." - Linus Torvalds [ https://lkml.org/lkml/2000/8/25/132 ] From python at lucidity.plus.com Tue Jan 12 04:13:21 2016 From: python at lucidity.plus.com (Erik) Date: Tue, 12 Jan 2016 09:13:21 +0000 Subject: I'm missing something here... In-Reply-To: <5694B84D.4060803@lucidity.plus.com> References: <569440EB.4090204@lucidity.plus.com> <20160112071322.GA12153@cskk.homeip.net> <5694B84D.4060803@lucidity.plus.com> Message-ID: <5694C3B1.6080005@lucidity.plus.com> Apologies for self-replying On 12/01/16 08:24, Erik wrote: > On 12/01/16 07:13, Cameron Simpson wrote: >> The former. Almost any loop _might_ be executed zero times. Compilers >> and linters etc should only complain if they can prove the loop is >> always executed zero times. > > I was just raising the > possibility that the bug could have been that the loop was (incorrectly) > determined to be executed zero times for some reason. Having just read it again, I note that Skip said he'd changed the |= to something different (and I've since read the solution to the question). I had misread what Skip said to mean he had added a new line _after_ the 'for' loop which touched the variable. E. From info at egenix.com Tue Jan 12 04:53:11 2016 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 12 Jan 2016 10:53:11 +0100 Subject: =?UTF-8?Q?ANN:_Python_Meeting_D=c3=bcsseldorf_-_19.01.2016?= Message-ID: <5694CD07.2050400@egenix.com> [This announcement is in German since it targets a local user group meeting in D?sseldorf, Germany] ________________________________________________________________________ ANK?NDIGUNG Python Meeting D?sseldorf http://pyddf.de/ Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosph?re. Mittwoch, 21.10.2015, 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-01-19 ________________________________________________________________________ NEUIGKEITEN * Bereits angemeldete Vortr?ge: Jens Diemer "DragonPy - Dragon 32 Emulator in Python" Charlie Clark "Statische Code-Analyse mit Quantified Code" Marc-Andre Lemburg "MicroPython auf dem BBC MicroBit" 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. Folien bitte als PDF auf USB Stick mitbringen. 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, Jan 12 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 info at egenix.com Tue Jan 12 04:59:24 2016 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 12 Jan 2016 10:59:24 +0100 Subject: =?UTF-8?Q?Re:_[egenix-info]_ANN:_Python_Meeting_D=c3=bcsseldorf_-_1?= =?UTF-8?Q?9.01.2016?= In-Reply-To: <5694CD07.2050400@egenix.com> References: <5694CD07.2050400@egenix.com> Message-ID: <5694CE7C.707@egenix.com> On 12.01.2016 10:53, eGenix Team: M.-A. Lemburg wrote: > [This announcement is in German since it targets a local user group > meeting in D?sseldorf, Germany] > > ________________________________________________________________________ > > ANK?NDIGUNG > > Python Meeting D?sseldorf > > http://pyddf.de/ > > Ein Treffen von Python Enthusiasten und Interessierten > in ungezwungener Atmosph?re. > > Mittwoch, 21.10.2015, 18:00 Uhr Sorry, the correct date is: Dienstag, 19.01.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-01-19 > ________________________________________________________________________ > > NEUIGKEITEN > > * Bereits angemeldete Vortr?ge: > > Jens Diemer > "DragonPy - Dragon 32 Emulator in Python" > > Charlie Clark > "Statische Code-Analyse mit Quantified Code" > > Marc-Andre Lemburg > "MicroPython auf dem BBC MicroBit" > > 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. Folien bitte als PDF auf USB > Stick mitbringen. > > 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, Jan 12 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 rosuav at gmail.com Tue Jan 12 05:18:55 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jan 2016 21:18:55 +1100 Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> Message-ID: On Tue, Jan 12, 2016 at 7:27 PM, Terry Reedy wrote: > On 1/11/2016 8:09 PM, Chris Angelico wrote: >> >> On Tue, Jan 12, 2016 at 11:55 AM, Bernardo Sulzbach >> wrote: >>> >>> On Mon, Jan 11, 2016 at 10:14 PM, Chris Angelico >>> wrote: >>>> >>>> >>>> Next IDLE feature request: Can you make it so that, across all >>>> platforms, it magically installs PostgreSQL and psycopg2? That would >>>> solve so many of my students' problems... > > > I detect an invisible smiley at the end of that. > > PostgresSQL is not a Python package, hence would need a custom script to > download and invoke, and would probably need user clicks anyway, at least on > Windows. Does/could psycopg2 have such for installing its dependency? > > Can psycopg2 be installed with pip? There is an issue (#23551) to make a > pip GUI and make it accessible from IDLE. We need someone with both pip and > tkinter knowledge to either design and write it or mentor a GSOC student to > do so. One written, I would add an IDLE menu item to run it, in a separate > process, just as done now with turtledemo. Yes, invisible smiley... but with a hint of truth too. Obviously installing PostgreSQL itself is outside the scope of IDLE, but psycopg2 is indeed pip-installable... except that it isn't always, on Windows, because wheels aren't available for all versions. (There's no Python 3.5 wheel yet; at least, I can't see one on PyPI.) So what I'm really looking for isn't an IDLE feature but a Python packaging feature - some people have talked about setting up build farms that can produce wheels for people. Hmm. I just tried this, and actually, there's some possibly low-hanging fruit. (Tested on Python 3.4.3 as 3.5 can't install psycopg2 anyway.) >>> import pip; pip.main(["install","psycopg2"]) This produces a rather messy display, because pip.main seems to assume that writing carriage returns to the console will result in the display nicely overwriting (producing a moving progress bar as the file gets downloaded). If IDLE can't handle carriage returns as such, an easy fix would be to simply display them as complete lines; it would be more verbose than the normal console behaviour, but not as ugly. A couple of other random thoughts from this experiment. * Going to python.org and pointing the mouse at the download link got me 3.5.1 32-bit. This is on Google Chrome on a Windows 7 64-bit VM. * Instead of pip.main(["install","psycopg2"]), I'd like to be able to say pip.install("psycopg2"). In fact, I might take that to the pip folks as a suggestion. * The performance difference between "import pip" on 3.4.3 and 3.5.1 was dramatic! I don't know whether it's CPython that's been sped up or pip itself, but it's awesome! There's some kind of issue between pip and Idle that means that installing a non-wheel blows up with an exception: Traceback (most recent call last): File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\basecommand.py", line 211, in main status = self.run(options, args) File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\commands\install.py", line 294, in run requirement_set.prepare_files(finder) File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\req\req_set.py", line 334, in prepare_files functools.partial(self._prepare_file, finder)) File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\req\req_set.py", line 321, in _walk_req_to_install more_reqs = handler(req_to_install) File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\req\req_set.py", line 505, in _prepare_file abstract_dist.prep_for_dist() File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\req\req_set.py", line 123, in prep_for_dist self.req_to_install.run_egg_info() File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\req\req_install.py", line 410, in run_egg_info command_desc='python setup.py egg_info') File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\utils\__init__.py", line 711, in call_subprocess line = console_to_str(proc.stdout.readline()) File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\compat\__init__.py", line 47, in console_to_str return s.decode(sys.__stdout__.encoding) AttributeError: 'NoneType' object has no attribute 'encoding' Maybe calling pip.main just isn't a supported thing, but it'd be nice if there were _some_ way to do this, even without a fancy GUI. How much of this is worth doing anything about, and how much is "hey, you're hacking around calling a command-line tool from inside a GUI, and stuff ain't a'gonna work right"? ChrisA From python.list at tim.thechases.com Tue Jan 12 06:52:36 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 12 Jan 2016 05:52:36 -0600 Subject: modifying parts of a urlparse.SplitResult Message-ID: <20160112055236.7af20f50@bigbox.christie.dr> I can successfully parse my URLs. However, I'd like to modify a part then reassemble them. However, like tuples, the parts appear to be unmodifiable >>> URL = 'http://foo/path1/path2/?fragment=foo' >>> import urlparse >>> u = urlparse.urlparse(URL) >>> u ParseResult(scheme='http', netloc='foo', path='/path1/path2/', params='', query='fragment=foo', fragment='') >>> u.query 'fragment=foo' >>> u.query = 'blah=baz' Traceback (most recent call last): File "", line 1, in AttributeError: can't set attribute The best I've been able to come up with is >>> u = urlparse.urlsplit(URL) >>> lst = list(u) # can't manipulate the tuple directly >>> lst[3] = "bar=baz" # 3 = query-string index >>> urlparse.urlunsplit(lst) 'http://foo/path1/path2/?bar=baz' It takes knowing that "3" is the magic index (documented, but not given some named-constant in urlparse) for the query-string. Is there some better, clearer, or more Pythonic way to do this? -tkc (sorry if this is a dupe post, as I got an SMTP bounce/error from mail.python.org stating "service currently unavailable") From __peter__ at web.de Tue Jan 12 07:12:43 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 12 Jan 2016 13:12:43 +0100 Subject: Need help with this asap. References: <1452577684.494943577@f402.i.mail.ru> Message-ID: ifeanyioprah--- via Python-list wrote: > Create a class called BankAccount > 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"` Return or print? You print. > Create a subclass MinimumBalanceAccount of the BankAccount class. I would suppose that such a MinimumBalanceAccount needs a way to specify the minimum balance (in the initializer) and to ensure (both initially and in the withdraw() method) that the account actually has that minimum balance. > This was my solution and I still got error. What should I do. > class BankAccount: > def __init__(self, initial_amount): > self.balance = initial_amount > def deposit(self, amount): > self.balance += amount > def withdraw(self, amount): > if self.balance>= amount: > self.balance -= amount > else: > print('invalid transaction') > a1 = BankAccount (90) > a1.deposit(90) > a1.withdraw(40) > a1.withdraw(1000) > class MinimumBalanceAccount(BankAccount): > def __init__(self): > BankAccount.__init__(self) > From __peter__ at web.de Tue Jan 12 07:46:43 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 12 Jan 2016 13:46:43 +0100 Subject: modifying parts of a urlparse.SplitResult References: <20160112055236.7af20f50@bigbox.christie.dr> Message-ID: Tim Chase wrote: > I can successfully parse my URLs. However, I'd like to modify a part > then reassemble them. However, like tuples, the parts appear to be > unmodifiable > > >>> URL = 'http://foo/path1/path2/?fragment=foo' > >>> import urlparse > >>> u = urlparse.urlparse(URL) > >>> u > ParseResult(scheme='http', netloc='foo', path='/path1/path2/', > params='', query='fragment=foo', fragment='') > >>> u.query > 'fragment=foo' > >>> u.query = 'blah=baz' > Traceback (most recent call last): > File "", line 1, in > AttributeError: can't set attribute > > The best I've been able to come up with is > > >>> u = urlparse.urlsplit(URL) > >>> lst = list(u) # can't manipulate the tuple directly > >>> lst[3] = "bar=baz" # 3 = query-string index > >>> urlparse.urlunsplit(lst) > 'http://foo/path1/path2/?bar=baz' > > It takes knowing that "3" is the magic index (documented, but not > given some named-constant in urlparse) for the query-string. Is > there some better, clearer, or more Pythonic way to do this? To allow more fieldnames namedtuples use method names starting with an underscore. You can safely use them, they are not private. So: >>> pr = urlparse.urlparse("http://foo/path1/path2/?fragment=foo") >>> urlparse.urlunparse(pr._replace(query="bar=baz")) 'http://foo/path1/path2/?bar=baz' From joel.goldstick at gmail.com Tue Jan 12 07:48:56 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 12 Jan 2016 07:48:56 -0500 Subject: Installation In-Reply-To: References: Message-ID: On Mon, Jan 11, 2016 at 8:30 PM, Jansen, Ingram L < ijansen at broncos.uncfsu.edu> wrote: > > I can't download Python and I need it for class. Any suggestions? > > drop the class? ;) But more seriously, what OS, what version of Python, what did you try, what happened? > > Ingram Jansen > Banner ID: 830742998 > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From python.list at tim.thechases.com Tue Jan 12 08:15:46 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 12 Jan 2016 07:15:46 -0600 Subject: modifying parts of a urlparse.SplitResult In-Reply-To: References: <20160112055236.7af20f50@bigbox.christie.dr> Message-ID: <20160112071546.4d2e546d@bigbox.christie.dr> On 2016-01-12 13:46, Peter Otten wrote: > Tim Chase wrote: > > >>> u = urlparse.urlsplit(URL) > > >>> lst = list(u) # can't manipulate the tuple directly > > >>> lst[3] = "bar=baz" # 3 = query-string index > > >>> urlparse.urlunsplit(lst) > > 'http://foo/path1/path2/?bar=baz' > > > > It takes knowing that "3" is the magic index (documented, but not > > given some named-constant in urlparse) for the query-string. Is > > there some better, clearer, or more Pythonic way to do this? > > To allow more fieldnames namedtuples use method names starting with > an underscore. You can safely use them, they are not private. So: > > >>> pr = urlparse.urlparse("http://foo/path1/path2/?fragment=foo") > >>> urlparse.urlunparse(pr._replace(query="bar=baz")) > 'http://foo/path1/path2/?bar=baz' Much nicer. Thanks! Off to improve my code. -tkc From malitician at gmail.com Tue Jan 12 08:20:04 2016 From: malitician at gmail.com (lee) Date: Tue, 12 Jan 2016 05:20:04 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> Message-ID: <33746645-80d7-4441-99dd-4e41e6a5816b@googlegroups.com> You're still struggling with this question because you didn't take your time to read the previous comments here , the solution to this and other question has being posted long ago before new year here , just read previous comments. Remember don't use print , instead use return . From self at example.org Tue Jan 12 09:12:06 2016 From: self at example.org (me) Date: Tue, 12 Jan 2016 14:12:06 +0000 (UTC) Subject: What use of these _ prefix members? References: <4ee5810e-abe9-4c4b-9ebd-d989b5c2b341@googlegroups.com> Message-ID: On 2016-01-10, Peter Otten <__peter__ at web.de> wrote: >>>> class Derived(Base): > ... def _init(self, x): > ... super()._init(x) > ... print("do something else with", x) > ... >>>> Derived(42) > do something with 42 > do something else with 42 ><__main__.Derived object at 0x7f8e6b3e9b70> > I think you are doing inheritance wrong. AFAIK you should call directly the __init__() of the parent class, and pass *args and **kwargs instead. Except for that, yes, the _init would be conventionally private. Not enforced by name mangling though. From __peter__ at web.de Tue Jan 12 09:52:18 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 12 Jan 2016 15:52:18 +0100 Subject: What use of these _ prefix members? References: <4ee5810e-abe9-4c4b-9ebd-d989b5c2b341@googlegroups.com> Message-ID: Someone else posting as "me" wrote: > On 2016-01-10, Peter Otten <__peter__ at web.de> wrote: >>>>> class Derived(Base): >> ... def _init(self, x): >> ... super()._init(x) >> ... print("do something else with", x) >> ... >>>>> Derived(42) >> do something with 42 >> do something else with 42 >><__main__.Derived object at 0x7f8e6b3e9b70> >> > > I think you are doing inheritance wrong. If by "you" you mean "me" -- the above sample is an illustration of the pattern I expected to see elsewhere in the software Robert was quoting, not an endorsement. I have now looked into the hmmlearn source, and it turns out that _init() is invoked by the fit() method rather than the initializer. But... > AFAIK you should call directly the __init__() of the parent class, and > pass *args and **kwargs instead. you sometimes want to break initialisation or any other method into distinct steps that don't make sense stand-alone: class Foo: def method(...) self._one(...) self._two(...) self._three(...) That way subclasses have the option to override only _two() instead of method() and users of Foo won't try to invoke _two(...) on its own. I think this is a good approach. What arguments you need to accept and/or pass on is a question that you can decide depending on the actual use-case. I use *args, **kwargs only if function is very generic because it makes code hard to follow. > Except for that, yes, the _init would be conventionally private. Not > enforced by name mangling though. From jason.swails at gmail.com Tue Jan 12 10:01:57 2016 From: jason.swails at gmail.com (Jason Swails) Date: Tue, 12 Jan 2016 10:01:57 -0500 Subject: What use of these _ prefix members? In-Reply-To: References: <4ee5810e-abe9-4c4b-9ebd-d989b5c2b341@googlegroups.com> Message-ID: On Tue, Jan 12, 2016 at 9:12 AM, me wrote: > On 2016-01-10, Peter Otten <__peter__ at web.de> wrote: > >>>> class Derived(Base): > > ... def _init(self, x): > > ... super()._init(x) > > ... print("do something else with", x) > > ... > >>>> Derived(42) > > do something with 42 > > do something else with 42 > ><__main__.Derived object at 0x7f8e6b3e9b70> > > > > I think you are doing inheritance wrong. > ?There's nothing "wrong" about this, and there are times this type of pattern is justified. Sure, *this* example doesn't make sense to do it this way, but this is just an illustrative example. I would even call this type of pattern pythonic. ? ? > AFAIK you should call directly the __init__() of the parent class, and > ?? > pass *args and **kwargs instead. > Sometimes there's no need to call __init__ on the parent class directly, and the base class's __init__ is sufficient for the derived class. And perhaps initialization requires numerous "steps" that are easiest to grok when split out into different, private sub-methods. For example: class Derived(Base): ? def __init__(self, arg1, arg2, arg3): self._initial_object_setup() self._process_arg1(arg1) self._process_arg23(arg2, arg3) self._postprocess_new_object()? This makes it clear what is involved in the initialization of the new object. And it allows the functionality to be split up into more atomic units. It also has the added benefit of subclasses being able to more selectively override base class functionality. Suppose Derived only needs to change how it reacts to arg1 -- all Derived needs to implement directly is _process_arg1. This reduces code duplication and improves maintainability, and is a pattern I've used myself and like enough to use again (not necessarily in __init__, but outside of being automatically called during construction I don't see anything else inherently "specialer" about __init__ than any other method). All the best, Jason From oscar.j.benjamin at gmail.com Tue Jan 12 10:15:40 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 12 Jan 2016 15:15:40 +0000 Subject: Python installation in windows In-Reply-To: <20160111201643.GA27813@cskk.homeip.net> References: <3d609795-016b-477c-be2c-8b37194df0ac@googlegroups.com> <20160111201643.GA27813@cskk.homeip.net> Message-ID: On 11 January 2016 at 20:16, Cameron Simpson wrote: > On 11Jan2016 07:19, rusi wrote: >> >> On Monday, January 11, 2016 at 6:32:14 PM UTC+5:30, navneet bhatele wrote: >>> >>> I have been trying to install the "python-3.5.1-amd64-webinstall " many >>> times and the Set up failed is shown up with named 0*80070002 - file >>> doesn't exist in dialog box >> >> >> Which windows? >> XP and 3.5 are not compatible >> For XP use 3.4 > > > I am not a Windows user, but this question occurs a lot. > > Is this cryptic message a missing dependency of the installer or of Python. > Because if it is Python surely we should be doing potential users a favour > and mentioning this 3.5 vs XP (and earlier?) issue in nice human friendly > prose instead of complaining about an obscure missing library file? > > As things stand, many users infer that they have a corrupt or broken > download, not that they needed a different version of Python. I think there are several different issues to do with Python 3.5 and Windows. Firstly support for Windows XP was dropped and 3.5 was made in a way that is incompatible with XP. However initially neither the download page nor the installer were warning XP users leading to a lot of confusion. I thought this was suppose to have been fixed in 3.5.1 though so the installer should now warn that it won't work on XP. Secondly the Windows builds of 3.5 are now compiled using VS2015 and I believe the installer itself has had something of an overhaul. This seems to have caused a number of different problems. One problem is that the newer VS2015 runtime requires the installation of some dll from Microsoft. So some users are getting error messages about a missing dll. The error message quoted above is something else though. I can't tell but it seems as if there are a number of distinct issues caused by the significant changes to Python 3.5 on Windows. > Should this be raised on python-dev? Probably better to go for bugs.python.org. There's a few 3.5/Windows issues already there. Not sure if this one's already listed. -- Oscar From ian.g.kelly at gmail.com Tue Jan 12 11:03:24 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 12 Jan 2016 09:03:24 -0700 Subject: I'm missing something here... In-Reply-To: References: Message-ID: On Mon, Jan 11, 2016 at 6:04 PM, Skip Montanaro wrote: > Sorry, I should have been explicit. prob_dates (the actual argument of the > call) is a set. As far as I know pylint does no type inference, so pylint > can't tell if the LHS and RHS of the |= operator are appropriate, nor can > it tell if it has an update() method. > > Before writing, I had more-or-less concluded I had hit a bug, but in my > experience when I hit something I think is a bug, it's not. It's me. > Terry's reply convinced me that I had hit something. > > Something else just occurred to me. I should have tried disassembling the > two versions of the function. Here's the output near prob_dates.update() > call: > > 14 > > 62 LOAD_FAST 3 (prob_dates) > 65 LOAD_ATTR 6 (update) > 68 LOAD_GLOBAL 7 (compare_prices) > 71 LOAD_CONST 3 ('E:%s') > 74 LOAD_FAST 5 (sym) > 77 BINARY_MODULO > 78 LOAD_FAST 0 (cx1) > 81 LOAD_FAST 1 (cx2) > 84 LOAD_FAST 2 (cx3) > 87 CALL_FUNCTION 4 > 90 CALL_FUNCTION 1 > > Here's how the |= version disassembles in that region: > > 20 > > 62 LOAD_FAST 3 (prob_dates) > 65 LOAD_GLOBAL 6 (compare_prices) > 68 LOAD_CONST 3 ('E:%s') > 71 LOAD_FAST 5 (sym) > 74 BINARY_MODULO > 75 LOAD_FAST 0 (cx1) > 78 LOAD_FAST 1 (cx2) > 81 LOAD_FAST 2 (cx3) > 84 CALL_FUNCTION 4 > 87 INPLACE_OR > 88 STORE_FAST 3 (prob_dates) > > I think what's throwing pylint is that last > STORE_FAST. That tells pylint the argument is ignored. I may be wrong, but I believe pylint just looks at the AST, not the opcodes. From srkunze at mail.de Tue Jan 12 11:18:50 2016 From: srkunze at mail.de (Sven R. Kunze) Date: Tue, 12 Jan 2016 17:18:50 +0100 Subject: How to remove item from heap efficiently? In-Reply-To: References: <568EEC40.7070807@mail.de> <568FE797.6090808@mail.de> <5692A795.3070904@mail.de> Message-ID: <5695276A.2020101@mail.de> On 12.01.2016 03:48, Cem Karan wrote: > > Jumping in late, but... > > If you want something that 'just works', you can use HeapDict: > > http://stutzbachenterprises.com/ > > I've used it in the past, and it works quite well. I haven't tested its asymptotic performance though, so you might want to check into that. Thanks for replying here. I've come across these types of wrappers/re-implementations of heapq as well when researching this issue. :) Unfortunately, they don't solve the underlying issue at hand which is: "remove item from heap with unknown index" and be efficient at it (by not using _heapq C implementation). So, I thought I did another wrapper. ;) It at least uses _heapq (if available otherwise heapq) and lets you remove items without violating the invariant in O(log n). I am going to make that open-source on pypi and see what people think of it. Best, Sven From eryksun at gmail.com Tue Jan 12 11:42:04 2016 From: eryksun at gmail.com (eryk sun) Date: Tue, 12 Jan 2016 10:42:04 -0600 Subject: Python installation in windows In-Reply-To: References: <3d609795-016b-477c-be2c-8b37194df0ac@googlegroups.com> <20160111201643.GA27813@cskk.homeip.net> Message-ID: On Tue, Jan 12, 2016 at 9:15 AM, Oscar Benjamin wrote: > > I thought this was suppose to have been fixed in 3.5.1 though so the installer > should now warn that it won't work on XP. The CRT update also requires service pack 1 on Windows 7 and service pack 2 on Vista. 3.5.1's installer was updated to check for a supported operating system. On an XP system the error message should be "Windows Vista SP2 or later is required to continue installation". > I believe the installer itself has had something of an overhaul. It was rewritten completely. From thebalancepro at gmail.com Tue Jan 12 11:50:41 2016 From: thebalancepro at gmail.com (Nick Mellor) Date: Tue, 12 Jan 2016 08:50:41 -0800 (PST) Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict Message-ID: Hi all, Seemingly simple problem: There is a case in my code where I know a dictionary has only one item in it. I want to get the value of that item, whatever the key is. In Python2 I'd write: >>> d = {"Wilf's Cafe": 1} >>> d.values()[0] 1 and that'd be an end to it. In Python 3: >>> d = {"Wilf's Cafe": 1} >>> d.values()[0] Traceback (most recent call last): File "", line 1, in TypeError: 'dict_values' object does not support indexing "Wilf's Cafe" >>> d[list(d)[0]] 1 >>> for k in d: ... value = d[k] ... break ... >>> value 1 >>> list(d.values())[0] 1 None of this feels like the "one, and preferably only one, obvious way to do it" we all strive for. Any other ideas? Thanks, Nick From jkn_gg at nicorp.f9.co.uk Tue Jan 12 11:51:13 2016 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Tue, 12 Jan 2016 08:51:13 -0800 (PST) Subject: use Python and an outlook: protocol URL to bring up a specific email Message-ID: Hi all a little OS/windows specific, I'm afraid: In Windows, there exists a part-supported 'outlook protocol' to obtain and use email references within Outlook as URL. You have to go through various shenanagins to enable this and to get Outlook to give you access to the URLs - see for instance: http://www.slipstick.com/problems/outlook-missing-outlook-protocol/ http://superuser.com/questions/834019/using-outlook-protocol-open-current-instance-of-outlook-not-new-instance http://www.davidtan.org/create-hyperlinks-to-outlook-messages-folders-contacts-events/ Having gone through all of this I get a refernce URL on my clipboard or whatever: "outlook:00000000BB1BBDFACA3A4D41A98037A1D85A8DA50700E6FBFC004227134D97632785EE69C220003C0208DEA10000DAC09B3B9C648E4597BE2A013A6E8B84000026F87CCA0000" (This refers to a particular email in Outlook) What I want to do is then use Python to invoke this URL to cause Outlook to bring up the referenced email. I'm stumbling here; I've tried urllib.urlopen(), and os.startfile(), but I am getting errors from urllib in either case: def open_unknown(self, fullurl, data=None): """Overridable interface to open unknown URL type.""" type, url = splittype(fullurl) raise IOError, ('url error', 'unknown url type', type) ie. the 'outlook' protocol is unknown. I happy to carve some code without using urllib, but I am not clear what I actually need to do to 'open' such a URL using this protocol. FWIW I can paste this URL into Windows Explorer and I get the referenced email popping up ;-) Thanks for any pointers Regards Jon N From vgr255 at live.ca Tue Jan 12 12:00:06 2016 From: vgr255 at live.ca (Emanuel Barry) Date: Tue, 12 Jan 2016 12:00:06 -0500 Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict In-Reply-To: References: Message-ID: > Hi all, > > Seemingly simple problem: > > There is a case in my code where I know a dictionary has only one item in it. I want to get the value of that item, whatever the key is. > > In Python2 I'd write: > > >>> d = {"Wilf's Cafe": 1} > >>> d.values()[0] > 1 The equivalent in Python 3 is `list(d.values())[0]` > None of this feels like the "one, and preferably only one, obvious way to do it" we all strive for. Any other ideas? If you feel like doing that, `for v in d.values(): pass` will set `v` to your value. But it's a bit cryptic, so you can probably resort to the list() alternative above :) - Emanuel From rosuav at gmail.com Tue Jan 12 12:06:20 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jan 2016 04:06:20 +1100 Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict In-Reply-To: References: Message-ID: On Wed, Jan 13, 2016 at 3:50 AM, Nick Mellor wrote: > There is a case in my code where I know a dictionary has only one item in it. I want to get the value of that item, whatever the key is. > > In Python2 I'd write: > >>>> d = {"Wilf's Cafe": 1} >>>> d.values()[0] > 1 > > and that'd be an end to it. > > In Python 3: > >>>> d = {"Wilf's Cafe": 1} >>>> d.values()[0] > Traceback (most recent call last): > File "", line 1, in > TypeError: 'dict_values' object does not support indexing > "Wilf's Cafe" >>>> d[list(d)[0]] > 1 You could try: next(iter(d.values())) but honestly, this isn't all that common a situation, so I'm not surprised there's no really simple and clean way to do it. ChrisA From rosuav at gmail.com Tue Jan 12 12:10:52 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jan 2016 04:10:52 +1100 Subject: use Python and an outlook: protocol URL to bring up a specific email In-Reply-To: References: Message-ID: On Wed, Jan 13, 2016 at 3:51 AM, jkn wrote: > I happy to carve some code without using urllib, but I am not clear what I > actually need to do to 'open' such a URL using this protocol. FWIW I can paste > this URL into Windows Explorer and I get the referenced email popping up ;-) > What happens if you invoke the 'start' command using subprocess? subprocess.check_call(["start", url]) In theory, that should be equivalent to pasting it into Explorer. In theory. ChrisA From tjreedy at udel.edu Tue Jan 12 12:12:43 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Jan 2016 12:12:43 -0500 Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict In-Reply-To: References: Message-ID: On 1/12/2016 11:50 AM, Nick Mellor wrote: > Hi all, > > Seemingly simple problem: > > There is a case in my code where I know a dictionary has only one item in it. I want to get the value of that item, whatever the key is. > > In Python2 I'd write: > >>>> d = {"Wilf's Cafe": 1} >>>> d.values()[0] > 1 > > and that'd be an end to it. > > In Python 3: > >>>> d = {"Wilf's Cafe": 1} >>>> d.values()[0] > Traceback (most recent call last): > File "", line 1, in > TypeError: 'dict_values' object does not support indexing The intended use of dict views: "Dictionary views can be iterated over to yield their respective data, and support membership tests:" > "Wilf's Cafe" >>>> d[list(d)[0]] > 1 > >>>> for k in d: > ... value = d[k] > ... break > ... >>>> value > 1 > >>>> list(d.values())[0] > 1 > > None of this feels like the "one, and preferably only one, > obvious way to do it" we all strive for. Any other ideas? Using the values views at intended (as an iterable): >>> dv = d.values() >>> next(iter(dv)) 1 -- Terry Jan Reedy From mafagafogigante at gmail.com Tue Jan 12 12:18:01 2016 From: mafagafogigante at gmail.com (Bernardo Sulzbach) Date: Tue, 12 Jan 2016 15:18:01 -0200 Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict In-Reply-To: References: Message-ID: Intentions aside, next(iter(...)) seems the most pythonic you can get about this anyway. Just in case you happen not to need the dictionary anymore, d.popitem()[1] does the trick. From jkn_gg at nicorp.f9.co.uk Tue Jan 12 12:22:26 2016 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Tue, 12 Jan 2016 09:22:26 -0800 (PST) Subject: use Python and an outlook: protocol URL to bring up a specific email In-Reply-To: References: Message-ID: Hi Chris On Tuesday, January 12, 2016 at 5:11:18 PM UTC, Chris Angelico wrote: > On Wed, Jan 13, 2016 at 3:51 AM, jkn wrote: > > I happy to carve some code without using urllib, but I am not clear what I > > actually need to do to 'open' such a URL using this protocol. FWIW I can paste > > this URL into Windows Explorer and I get the referenced email popping up ;-) > > > > What happens if you invoke the 'start' command using subprocess? > > subprocess.check_call(["start", url]) > > In theory, that should be equivalent to pasting it into Explorer. In theory. > > ChrisA I'll try that, but (typically!) I found some things that worked shortly after posting... These both work: PROTOCOL = "outlook:" TEST_URL = "00000000BB1BBDFACA3A... 84000026F87CCA0000" # elided for example import os os.startfile(PROTOCOL + TEST_URL, 'open') # second parameter not needed # and import win32api win32api.ShellExecute(0, 'open', PROTOCOL + TEST_URL, "", "", 0) I thought I had already tried the first one, not sure what happened. Sorry for the noise... Cheers Jon N From __peter__ at web.de Tue Jan 12 12:32:50 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 12 Jan 2016 18:32:50 +0100 Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict References: Message-ID: Nick Mellor wrote: > Hi all, > > Seemingly simple problem: > > There is a case in my code where I know a dictionary has only one item in > it. I want to get the value of that item, whatever the key is. > > In Python2 I'd write: > >>>> d = {"Wilf's Cafe": 1} >>>> d.values()[0] > 1 > > and that'd be an end to it. > > In Python 3: > >>>> d = {"Wilf's Cafe": 1} >>>> d.values()[0] > Traceback (most recent call last): > File "", line 1, in > TypeError: 'dict_values' object does not support indexing > "Wilf's Cafe" >>>> d[list(d)[0]] > 1 > >>>> for k in d: > ... value = d[k] > ... break > ... >>>> value > 1 > >>>> list(d.values())[0] > 1 > > None of this feels like the "one, and preferably only one, obvious way to > do it" we all strive for. Any other ideas? If there is exactly one item you can unpack: >>> d = {"Wilf's Cafe": 1} >>> k, = d.values() >>> k 1 From eryksun at gmail.com Tue Jan 12 12:37:09 2016 From: eryksun at gmail.com (eryk sun) Date: Tue, 12 Jan 2016 11:37:09 -0600 Subject: use Python and an outlook: protocol URL to bring up a specific email In-Reply-To: References: Message-ID: On Tue, Jan 12, 2016 at 11:10 AM, Chris Angelico wrote: > On Wed, Jan 13, 2016 at 3:51 AM, jkn wrote: >> I happy to carve some code without using urllib, but I am not clear what I >> actually need to do to 'open' such a URL using this protocol. FWIW I can paste >> this URL into Windows Explorer and I get the referenced email popping up ;-) > > What happens if you invoke the 'start' command using subprocess? > > subprocess.check_call(["start", url]) > > In theory, that should be equivalent to pasting it into Explorer. In theory. start is a shell command. It also has a quirk that the first quoted argument is the window title. Here's the correct call: subprocess.check_call('start "title" "%s"' % url, shell=True) That said, since no arguments are being passed the simpler and more secure way to call ShellExecute in this case is os.startfile(url). From ian.g.kelly at gmail.com Tue Jan 12 12:39:55 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 12 Jan 2016 10:39:55 -0700 Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict In-Reply-To: References: Message-ID: On Tue, Jan 12, 2016 at 10:12 AM, Terry Reedy wrote: > Using the values views at intended (as an iterable): > >>>> dv = d.values() >>>> next(iter(dv)) > 1 Good coding practice also dictates that whenever next is called, the potential StopIteration exception must be caught unless it is clearly intended to be propagated up to some generator. So more fully, this should be something like: dv = iter(d.values()) try: next(dv) except StopIteration: raise IndexError("d is empty") At which point it may be desirable to extract that into a utility function. From skip.montanaro at gmail.com Tue Jan 12 12:46:49 2016 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 12 Jan 2016 11:46:49 -0600 Subject: I'm missing something here... In-Reply-To: References: Message-ID: I created an issue for the pylint folks: https://github.com/PyCQA/pylint/issues/774 Skip From jussi.piitulainen at helsinki.fi Tue Jan 12 12:47:22 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 12 Jan 2016 19:47:22 +0200 Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict References: Message-ID: Nick Mellor writes: > Hi all, > > Seemingly simple problem: > > There is a case in my code where I know a dictionary has only one item > in it. I want to get the value of that item, whatever the key is. > > In Python2 I'd write: > >>>> d = {"Wilf's Cafe": 1} >>>> d.values()[0] > 1 > > and that'd be an end to it. > > In Python 3: If you are happy to give the sole value a name: >>> shoe = dict(it=math.pi) >>> [o] = shoe.values() >>> o 3.141592653589793 You might be able to use * to pass the sole value to a function: >>> print(*shoe.values()) 3.141592653589793 But the most readable thing might be to have a function that extracts the sole value by whatever means: >>> def sole(d): [o] = d.values() ; return o ... >>> sole(shoe) 3.141592653589793 From rosuav at gmail.com Tue Jan 12 12:52:39 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jan 2016 04:52:39 +1100 Subject: use Python and an outlook: protocol URL to bring up a specific email In-Reply-To: References: Message-ID: On Wed, Jan 13, 2016 at 4:37 AM, eryk sun wrote: > On Tue, Jan 12, 2016 at 11:10 AM, Chris Angelico wrote: >> On Wed, Jan 13, 2016 at 3:51 AM, jkn wrote: >>> I happy to carve some code without using urllib, but I am not clear what I >>> actually need to do to 'open' such a URL using this protocol. FWIW I can paste >>> this URL into Windows Explorer and I get the referenced email popping up ;-) >> >> What happens if you invoke the 'start' command using subprocess? >> >> subprocess.check_call(["start", url]) >> >> In theory, that should be equivalent to pasting it into Explorer. In theory. > > start is a shell command. It also has a quirk that the first quoted > argument is the window title. Here's the correct call: > > subprocess.check_call('start "title" "%s"' % url, shell=True) Is that properly escaped to handle any arbitrary URL? I doubt it. Do you actually need shell=True? I would strongly recommend using the form that I used, unless it can be proven that that doesn't work. > That said, since no arguments are being passed the simpler and more > secure way to call ShellExecute in this case is os.startfile(url). Yes. The OP mentioned having tried this, though, so I went for an alternative. ChrisA From auriocus at gmx.de Tue Jan 12 13:04:35 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 12 Jan 2016 19:04:35 +0100 Subject: use Python and an outlook: protocol URL to bring up a specific email In-Reply-To: References: Message-ID: Am 12.01.16 um 18:52 schrieb Chris Angelico: > On Wed, Jan 13, 2016 at 4:37 AM, eryk sun wrote: >> >> start is a shell command. It also has a quirk that the first quoted >> argument is the window title. Here's the correct call: >> >> subprocess.check_call('start "title" "%s"' % url, shell=True) > > Is that properly escaped to handle any arbitrary URL? I doubt it. > > Do you actually need shell=True? I would strongly recommend using the > form that I used, unless it can be proven that that doesn't work. As stated, start is not an executable on Windows, but it is a built-in command of cmd.exe. And thus it has very quirky quotation rules. This is unlike Linux, where "xdg-open" is a shell script, and OSX, where "open" is a binary executable. Christian From __peter__ at web.de Tue Jan 12 13:09:29 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 12 Jan 2016 19:09:29 +0100 Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict References: Message-ID: Ian Kelly wrote: > On Tue, Jan 12, 2016 at 10:12 AM, Terry Reedy wrote: >> Using the values views at intended (as an iterable): >> >>>>> dv = d.values() >>>>> next(iter(dv)) >> 1 > > Good coding practice also dictates that whenever next is called, the > potential StopIteration exception must be caught unless it is clearly > intended to be propagated up to some generator. Even then you should be prepared for https://docs.python.org/dev/whatsnew/3.5.html#pep-479-change-stopiteration-handling-inside-generators > So more fully, this > should be something like: > > dv = iter(d.values()) > try: > next(dv) > except StopIteration: > raise IndexError("d is empty") > > At which point it may be desirable to extract that into a utility > function. From invalid at invalid.invalid Tue Jan 12 13:31:16 2016 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 12 Jan 2016 18:31:16 +0000 (UTC) Subject: Which Python editor has this feature? References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> Message-ID: On 2016-01-12, Bernardo Sulzbach wrote: > On Mon, Jan 11, 2016 at 10:14 PM, Chris Angelico wrote: >> >> Next IDLE feature request: Can you make it so that, across all >> platforms, it magically installs PostgreSQL and psycopg2? That would >> solve so many of my students' problems... >> > > Wouldn't this make the installer much bigger? Whoosh! -- Grant Edwards grant.b.edwards Yow! I feel like I am at sharing a ``CORN-DOG'' gmail.com with NIKITA KHRUSCHEV ... From mafagafogigante at gmail.com Tue Jan 12 13:48:17 2016 From: mafagafogigante at gmail.com (Bernardo Sulzbach) Date: Tue, 12 Jan 2016 16:48:17 -0200 Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict In-Reply-To: References: Message-ID: On Tue, Jan 12, 2016 at 3:32 PM, Peter Otten <__peter__ at web.de> wrote: > > If there is exactly one item you can unpack: > >>>> d = {"Wilf's Cafe": 1} >>>> k, = d.values() >>>> k > 1 > I personally don't like that trailing comma, it just looks wrong there. But this is very neat. -- Bernardo Sulzbach From __peter__ at web.de Tue Jan 12 13:59:14 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 12 Jan 2016 19:59:14 +0100 Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict References: Message-ID: Bernardo Sulzbach wrote: > On Tue, Jan 12, 2016 at 3:32 PM, Peter Otten <__peter__ at web.de> wrote: >> >> If there is exactly one item you can unpack: >> >>>>> d = {"Wilf's Cafe": 1} >>>>> k, = d.values() >>>>> k >> 1 >> > > I personally don't like that trailing comma, it just looks wrong > there. But this is very neat. > [k] = d.values() works the same. I used the tuple here to keep it consistent with all other cases where the brackets are superfluous, like [foo, *bar] = ... foo, *bar = ... etc. From mafagafogigante at gmail.com Tue Jan 12 14:12:32 2016 From: mafagafogigante at gmail.com (Bernardo Sulzbach) Date: Tue, 12 Jan 2016 17:12:32 -0200 Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict In-Reply-To: References: Message-ID: I saw it in another answer. next(iter(d)) is still the winner. This resembles a list just too much, making the coder's intent harder to understand. This is **very** subjective, of course. From eryksun at gmail.com Tue Jan 12 14:12:40 2016 From: eryksun at gmail.com (eryk sun) Date: Tue, 12 Jan 2016 13:12:40 -0600 Subject: use Python and an outlook: protocol URL to bring up a specific email In-Reply-To: References: Message-ID: On Tue, Jan 12, 2016 at 11:52 AM, Chris Angelico wrote: > Is that properly escaped to handle any arbitrary URL? I doubt it. subprocess doesn't know how to quote a command line for the Windows shell, which doesn't follow the rules used by subprocess.list2cmdline. To make matters worse, one often has to follow both sets of rules or even some arbitrary rules used by an executable. > Do you actually need shell=True? I would strongly recommend using the > form that I used, unless it can be proven that that doesn't work. AFAIK, the "start" command has been built in to the shell since cmd.exe originated on OS/2 in like 1987. It was enhanced when cmd.exe was ported to Win32 for NT 3.1. From marko at pacujo.net Tue Jan 12 14:42:41 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 12 Jan 2016 21:42:41 +0200 Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict References: Message-ID: <87egdmd1ou.fsf@elektro.pacujo.net> Jussi Piitulainen : > But the most readable thing might be to have a function that extracts > the sole value by whatever means: > > >>> def sole(d): [o] = d.values() ; return o > ... > >>> sole(shoe) > 3.141592653589793 In the same vein: >>> def sole(d): ... for o in d.values(): ... return o ... >>> sole(shoe) 3.141592653589793 Marko From jussi.piitulainen at helsinki.fi Tue Jan 12 15:18:03 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 12 Jan 2016 22:18:03 +0200 Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict References: <87egdmd1ou.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa writes: > Jussi Piitulainen: > >> But the most readable thing might be to have a function that extracts >> the sole value by whatever means: >> >> >>> def sole(d): [o] = d.values() ; return o >> ... >> >>> sole(shoe) >> 3.141592653589793 > > In the same vein: > > >>> def sole(d): > ... for o in d.values(): > ... return o > ... > >>> sole(shoe) > 3.141592653589793 Tuple assignment has a useful side effect that all other methods present in this thread lack: it raises an exception if the number of dictionary entries is not exactly one. From rxjwg98 at gmail.com Tue Jan 12 15:35:41 2016 From: rxjwg98 at gmail.com (Robert) Date: Tue, 12 Jan 2016 12:35:41 -0800 (PST) Subject: It looks like one function not tested by pytest Message-ID: <8f9845fa-eff2-4276-95c7-f17baf30af2a@googlegroups.com> Hi, I modify a test suite, and simplified to the below content. I am interested in function: test_bad_covariance_type() I think that it tests for wrong type input, i.e. 'badcovariance_type' will generate error, which is expected. Thus, it passes test. When a correct type, such as 'diag', is given, there will be no error generated. pytest will declare a failure. Unfortunately, it will always pass the pytest for both cases. What is wrong with my code or my understanding? Thanks, ////////////// from __future__ import absolute_import from unittest import TestCase import numpy as np import pytest from hmmlearn import hmm from . import log_likelihood_increasing, make_covar_matrix, normalized class GaussianHMMTestMixin(object): covariance_type = None # set by subclasses def setUp(self): self.prng = prng = np.random.RandomState(10) self.n_components = n_components = 3 self.n_features = n_features = 3 self.startprob = prng.rand(n_components) self.startprob = self.startprob / self.startprob.sum() self.transmat = prng.rand(n_components, n_components) self.transmat /= np.tile(self.transmat.sum(axis=1)[:, np.newaxis], (1, n_components)) self.means = prng.randint(-20, 20, (n_components, n_features)) self.covars = dict( (cv_type, make_covar_matrix(cv_type, n_components, n_features)) for cv_type in ["spherical", "tied", "diag", "full"]) self.expanded_covars = { 'spherical': [np.eye(n_features) * cov for cov in self.covars['spherical']], 'diag': [np.diag(cov) for cov in self.covars['diag']], 'tied': [self.covars['tied']] * n_components, 'full': self.covars['full'], } def test_bad_covariance_type(self): with pytest.raises(ValueError): #h = hmm.GaussianHMM(20, covariance_type='badcovariance_type') h = hmm.GaussianHMM(covariance_type='diag') h.means_ = self.means h.covars_ = [] h.startprob_ = self.startprob h.transmat_ = self.transmat h._check() def test_fit(self, params='stmc', n_iter=5, **kwargs): h = hmm.GaussianHMM(self.n_components, self.covariance_type) h.startprob_ = self.startprob h.transmat_ = normalized( self.transmat + np.diag(self.prng.rand(self.n_components)), 1) h.means_ = 20 * self.means h.covars_ = self.covars[self.covariance_type] lengths = [10] * 10 X, _state_sequence = h.sample(sum(lengths), random_state=self.prng) # Mess up the parameters and see if we can re-learn them. # TODO: change the params and uncomment the check h.fit(X, lengths=lengths) class TestGaussianHMMWithSphericalCovars(GaussianHMMTestMixin, TestCase): covariance_type = 'spherical' def test_fit_startprob_and_transmat(self): self.test_fit('st') def test_bad_covariance_type0(self): self.test_bad_covariance_type() From greg.ewing at canterbury.ac.nz Tue Jan 12 16:01:44 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 13 Jan 2016 10:01:44 +1300 Subject: When I need classes? In-Reply-To: References: <56927b37$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > So start simplistic, and then look > into it like this: "Hey, see how you're doing this five times? There > HAS to be a better way!" (With acknowledgement to Raymond Hettinger.) That gave me visions of a little animated cartoon of Raymond popping up in the corner of the screen, offering to write some code for me. The next big IDLE feature...? -- Greg From mafagafogigante at gmail.com Tue Jan 12 16:08:10 2016 From: mafagafogigante at gmail.com (Bernardo Sulzbach) Date: Tue, 12 Jan 2016 19:08:10 -0200 Subject: When I need classes? In-Reply-To: References: <56927b37$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jan 12, 2016 at 7:01 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> So start simplistic, and then look >> into it like this: "Hey, see how you're doing this five times? There >> HAS to be a better way!" (With acknowledgement to Raymond Hettinger.) > > > That gave me visions of a little animated cartoon of > Raymond popping up in the corner of the screen, offering > to write some code for me. The next big IDLE feature...? > The Windows paperclip strikes back! -- Bernardo Sulzbach From ian.g.kelly at gmail.com Tue Jan 12 19:18:07 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 12 Jan 2016 17:18:07 -0700 Subject: When I need classes? In-Reply-To: References: <56927b37$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 11, 2016 at 5:53 PM, Bernardo Sulzbach wrote: > I have never gone "seriously OO" with Python though. I never wrote > from scratch an application with more than 10 classes as far as I can > remember. However, I would suppose that the interpreter can handle > thousands of user-defined classes simultaneously. In Python, a class is just an object, so the only limit on how many classes the interpreter can handle simultaneously is available memory. However, if you have deeply nested inheritance graphs then you could start to see performance issues on method calls, since the entire inheritance graph potentially has to be traversed in order to find the method. From jfong at ms4.hinet.net Tue Jan 12 20:20:45 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Tue, 12 Jan 2016 17:20:45 -0800 (PST) Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> Message-ID: Terry Reedy at 2016/1/12 UTC+8 3:56:03PM wrote: > Revamping IDLE to 1. use ttk widgets and 2. become a modern single > window app with multiple panes, including a tabbed editor pane, is a > goal for 2016. That will be great, I'm looking forward to it. By the way, when I was playing around with the IDLE editor yesterday, I had noticed that during the time the "Search Dialog" was opened, "Find Next" button will not highlight the item searched, unless the dialog was closed. --Jach Fong From rxjwg98 at gmail.com Tue Jan 12 20:23:32 2016 From: rxjwg98 at gmail.com (Robert) Date: Tue, 12 Jan 2016 17:23:32 -0800 (PST) Subject: It looks like one function not tested by pytest In-Reply-To: <8f9845fa-eff2-4276-95c7-f17baf30af2a@googlegroups.com> References: <8f9845fa-eff2-4276-95c7-f17baf30af2a@googlegroups.com> Message-ID: <5f0f762c-64c2-48c9-a628-535f23df6957@googlegroups.com> On Tuesday, January 12, 2016 at 3:36:13 PM UTC-5, Robert wrote: > Hi, > > I modify a test suite, and simplified to the below content. > I am interested in function: > test_bad_covariance_type() > > I think that it tests for wrong type input, i.e. > 'badcovariance_type' > will generate error, which is expected. Thus, it passes test. > > When a correct type, such as 'diag', is given, there will be no error > generated. pytest will declare a failure. > > > Unfortunately, it will always pass the pytest for both cases. > > What is wrong with my code or my understanding? > > > Thanks, > > > > > ////////////// > from __future__ import absolute_import > > from unittest import TestCase > > import numpy as np > import pytest > > from hmmlearn import hmm > > from . import log_likelihood_increasing, make_covar_matrix, normalized > > > class GaussianHMMTestMixin(object): > covariance_type = None # set by subclasses > > def setUp(self): > self.prng = prng = np.random.RandomState(10) > self.n_components = n_components = 3 > self.n_features = n_features = 3 > self.startprob = prng.rand(n_components) > self.startprob = self.startprob / self.startprob.sum() > self.transmat = prng.rand(n_components, n_components) > self.transmat /= np.tile(self.transmat.sum(axis=1)[:, np.newaxis], > (1, n_components)) > self.means = prng.randint(-20, 20, (n_components, n_features)) > self.covars = dict( > (cv_type, make_covar_matrix(cv_type, n_components, n_features)) > for cv_type in ["spherical", "tied", "diag", "full"]) > self.expanded_covars = { > 'spherical': [np.eye(n_features) * cov > for cov in self.covars['spherical']], > 'diag': [np.diag(cov) for cov in self.covars['diag']], > 'tied': [self.covars['tied']] * n_components, > 'full': self.covars['full'], > } > > def test_bad_covariance_type(self): > with pytest.raises(ValueError): > #h = hmm.GaussianHMM(20, covariance_type='badcovariance_type') > h = hmm.GaussianHMM(covariance_type='diag') > h.means_ = self.means > h.covars_ = [] > h.startprob_ = self.startprob > h.transmat_ = self.transmat > h._check() > > def test_fit(self, params='stmc', n_iter=5, **kwargs): > h = hmm.GaussianHMM(self.n_components, self.covariance_type) > h.startprob_ = self.startprob > h.transmat_ = normalized( > self.transmat + np.diag(self.prng.rand(self.n_components)), 1) > h.means_ = 20 * self.means > h.covars_ = self.covars[self.covariance_type] > > lengths = [10] * 10 > X, _state_sequence = h.sample(sum(lengths), random_state=self.prng) > > # Mess up the parameters and see if we can re-learn them. > # TODO: change the params and uncomment the check > h.fit(X, lengths=lengths) > > > > > class TestGaussianHMMWithSphericalCovars(GaussianHMMTestMixin, TestCase): > covariance_type = 'spherical' > > def test_fit_startprob_and_transmat(self): > self.test_fit('st') > > def test_bad_covariance_type0(self): > self.test_bad_covariance_type() It turns out that it always raises error, because there are other errors besides the covariance_type object. That is, pytest works as expected. Thanks, From steve at pearwood.info Tue Jan 12 20:23:52 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jan 2016 12:23:52 +1100 Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict References: Message-ID: <5695a72a$0$1583$c3e8da3$5496439d@news.astraweb.com> On Wed, 13 Jan 2016 03:50 am, Nick Mellor wrote: > Hi all, > > Seemingly simple problem: > > There is a case in my code where I know a dictionary has only one item in > it. I want to get the value of that item, whatever the key is. [snip examples] > None of this feels like the "one, and preferably only one, obvious way to > do it" we all strive for. Any other ideas? That's because this is a somewhat weird case. A dict with only one item that you don't know the key of? Who does that? (Well, apart from you, obviously.) Three solutions: item = d.popitem()[1] # But this modifies the dict. # Use tuple rather than list for efficiency. item = tuple(d.values())[0] Probably the best solution, because it will conveniently raise an exception if your assumption that the dict has exactly one item is wrong: item, = d.values() # Note the comma after "item". The comma turns the assignment into sequence unpacking. Normally we would write something like this: a, b, c, d = four_items but you can unpack a sequence of one item too. If you really want to make it obvious that the comma isn't a typo: (item,) = d.values() -- Steven From jfong at ms4.hinet.net Tue Jan 12 20:27:41 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Tue, 12 Jan 2016 17:27:41 -0800 (PST) Subject: Which Python editor has this feature? In-Reply-To: <256a4818-859e-46a1-9dee-6157a2dda23f@googlegroups.com> References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> <256a4818-859e-46a1-9dee-6157a2dda23f@googlegroups.com> Message-ID: wxjm... at gmail.com at 2016/1/?12 4:29:08PM wrote: > IDLE ? > I need less than 10 seconds to make it crash. Unwittingly or intentionally? > The interesting aspect is not only to show that it crashes, > the very interesting point is to explain why it is crashing. Can you tell us (in a separate subject title)? I am willing to learn every aspects of Python. --Jach Fong From steve at pearwood.info Tue Jan 12 20:29:12 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jan 2016 12:29:12 +1100 Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict References: Message-ID: <5695a86c$0$1588$c3e8da3$5496439d@news.astraweb.com> On Wed, 13 Jan 2016 06:12 am, Bernardo Sulzbach wrote: > I saw it in another answer. next(iter(d)) is still the winner. Except that doesn't return the *value*, it returns the *key*. py> d = {'key': 'value'} py> next(iter(d)) 'key' To get the value: py> next(iter(d.values())) 'value' > This resembles a list just too much, making the coder's intent harder > to understand. This is **very** subjective, of course. I'm sorry, I don't understand what you mean by "resembles a list"? What does? In what way? -- Steven From steve at pearwood.info Tue Jan 12 20:33:25 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jan 2016 12:33:25 +1100 Subject: When I need classes? References: <56927b37$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5695a967$0$1588$c3e8da3$5496439d@news.astraweb.com> On Wed, 13 Jan 2016 11:18 am, Ian Kelly wrote: > On Mon, Jan 11, 2016 at 5:53 PM, Bernardo Sulzbach > wrote: >> I have never gone "seriously OO" with Python though. I never wrote >> from scratch an application with more than 10 classes as far as I can >> remember. However, I would suppose that the interpreter can handle >> thousands of user-defined classes simultaneously. > > In Python, a class is just an object, so the only limit on how many > classes the interpreter can handle simultaneously is available memory. > > However, if you have deeply nested inheritance graphs then you could > start to see performance issues on method calls, since the entire > inheritance graph potentially has to be traversed in order to find the > method. I'm sure Ian knows this already, but for the benefit of others... Python is not Java: http://dirtsimple.org/2004/12/python-is-not-java.html And Java is not Python either: http://dirtsimple.org/2004/12/java-is-not-python-either.html -- Steven From rosuav at gmail.com Tue Jan 12 20:51:16 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jan 2016 12:51:16 +1100 Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> <256a4818-859e-46a1-9dee-6157a2dda23f@googlegroups.com> Message-ID: On Wed, Jan 13, 2016 at 12:27 PM, wrote: > wxjm... at gmail.com at 2016/1/?12 4:29:08PM wrote: >> IDLE ? >> I need less than 10 seconds to make it crash. > > Unwittingly or intentionally? > >> The interesting aspect is not only to show that it crashes, >> the very interesting point is to explain why it is crashing. > > Can you tell us (in a separate subject title)? I am willing to learn every aspects of Python. Take no notice of the troll. ChrisA From tdsperth at gmail.com Tue Jan 12 20:52:02 2016 From: tdsperth at gmail.com (tdsperth at gmail.com) Date: Tue, 12 Jan 2016 17:52:02 -0800 (PST) Subject: Data Entry Message-ID: <6ea58259-05f8-40b5-8c85-46a69668c8e6@googlegroups.com> Hi All I have written a small web app using cgi for testing for changes to data from a python script that does a lot of database updating depending on certain conditions form = cgi.FieldStorage() cRefNo = form.getvalue('refno') cElectSupp = form.getvalue('electsupp') print('Electrical Supplier : '%cElectSupp) If i change the value from origin to origin energy and save - the value updated to the database is correct but when the page is re displayed it only shows origin in the text field - as if it ignores everything after the space. How do I make it display the full name. Cheers Colin From rosuav at gmail.com Tue Jan 12 21:01:12 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jan 2016 13:01:12 +1100 Subject: Data Entry In-Reply-To: <6ea58259-05f8-40b5-8c85-46a69668c8e6@googlegroups.com> References: <6ea58259-05f8-40b5-8c85-46a69668c8e6@googlegroups.com> Message-ID: On Wed, Jan 13, 2016 at 12:52 PM, wrote: > If i change the value from origin to origin energy and save - the value updated to the database is correct but when the page is re displayed it only > shows origin in the text field - as if it ignores everything after the space. > > How do I make it display the full name. > To set a multi-word value as an HTML attribute, you'll need to put quotes around it. You might be able to get away with using %r instead of %s, or even just "%s", but proper escaping would be the best way. ChrisA From steve at pearwood.info Tue Jan 12 21:04:43 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jan 2016 13:04:43 +1100 Subject: Which Python editor has this feature? References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> <256a4818-859e-46a1-9dee-6157a2dda23f@googlegroups.com> Message-ID: <5695b0bc$0$1586$c3e8da3$5496439d@news.astraweb.com> On Wed, 13 Jan 2016 12:27 pm, jfong at ms4.hinet.net wrote: > wxjm... at gmail.com at 2016/1/?12 4:29:08PM wrote: >> IDLE ? >> I need less than 10 seconds to make it crash. > > Unwittingly or intentionally? > >> The interesting aspect is not only to show that it crashes, >> the very interesting point is to explain why it is crashing. > > Can you tell us (in a separate subject title)? I am willing to learn every > aspects of Python. Pay no attention to wxjmfauth, he is our resident troll who is obsessed with Python's Unicode implementation. When he says "make it crash", he means "raise an exception", which is absolutely trivial. We can all make Python raise an exception in a fraction of a second: 1/0 will do it. Or if you prefer to stick to unicode: u'?'.encode('ascii') wxjmfauth's obsession started with an alpha release of Python 3.3 that had a small performance decrease for some operations on non-ASCII characters under some circumstances. He has taken this tiny decrease in performance as proof of some grand conspiracy that the Python developers hate non-English speaking Europeans (he never seems to care about Asians or other non-Latin based characters, only French and other European ones) and that this small performance decrease shows that Python can't do Unicode. I think that is fair to say that he is what the English call "a nutter". -- Steven From tdsperth at gmail.com Tue Jan 12 21:58:17 2016 From: tdsperth at gmail.com (tdsperth at gmail.com) Date: Tue, 12 Jan 2016 18:58:17 -0800 (PST) Subject: Data Entry In-Reply-To: <6ea58259-05f8-40b5-8c85-46a69668c8e6@googlegroups.com> References: <6ea58259-05f8-40b5-8c85-46a69668c8e6@googlegroups.com> Message-ID: <9d3a8c53-ba8b-4ec0-8570-2a523132ebdb@googlegroups.com> On Wednesday, January 13, 2016 at 9:52:17 AM UTC+8, tdsp... at gmail.com wrote: > Hi All > > I have written a small web app using cgi for testing for changes to data from a python script that does a lot of database updating depending on certain conditions > > form = cgi.FieldStorage() > cRefNo = form.getvalue('refno') > > > cElectSupp = form.getvalue('electsupp') > > > print('Electrical Supplier : '%cElectSupp) > > > If i change the value from origin to origin energy and save - the value updated to the database is correct but when the page is re displayed it only > shows origin in the text field - as if it ignores everything after the space. > > How do I make it display the full name. > > Cheers > > Colin Hi Chris %r worked a treat thanks Colin From rustompmody at gmail.com Tue Jan 12 22:36:47 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 12 Jan 2016 19:36:47 -0800 (PST) Subject: When I need classes? In-Reply-To: References: Message-ID: <34aa811c-433d-4f8a-90e0-9dd768460415@googlegroups.com> On Sunday, January 10, 2016 at 1:00:13 PM UTC+5:30, Arshpreet Singh wrote: > Hello Friends, I am quite new to OOP(object oriented Programming), I did some projects with python which includes Data-Analysis, Flask Web Development and some simple scripts. > > I have only one question which is bothering me most of the time, When I will get the need to use Classes in Python? Or in other way is there any real-life example where you can tell me this problem/solution is kind of impossible in Python without Classes? I think the answers so far dont cover two complementary sides to this question: 1. Python the LANGUAGE, is rather even-handed in paradigm choice: Choose OO, imperative, functional or whatever style pleases/suits you 2. Python LIBRARIES however need to make committing choices. Users of those then need to align with these. egs 1. Majority of basic python is functional; eg stuff in os module 2. Some things need object creation and method call eg for re-s you need to know about and to use re objects, match objects etc 3. Then there are things that are naturally used by inheriting and extending eg Basehttpserver is typically used via inheritance To use these you need to know basic OO 4. Then there may be things whose natural usage needs multiple inheritance [cant think of examples] So as others have said, in principle you dont need to go beyond 1. Unfortunately when you are using non-trivial libraries you are a user both of python and the library and so the library-author's paradigm choices are a given for you From steve+comp.lang.python at pearwood.info Wed Jan 13 00:27:00 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jan 2016 16:27 +1100 Subject: When I need classes? References: <34aa811c-433d-4f8a-90e0-9dd768460415@googlegroups.com> Message-ID: <5695e025$0$11113$c3e8da3@news.astraweb.com> On Wednesday 13 January 2016 14:36, Rustom Mody wrote: > 1. Python the LANGUAGE, is rather even-handed in paradigm choice: Choose > OO, imperative, functional or whatever style pleases/suits you > 2. Python LIBRARIES however need to make committing choices. Users of > those then need to align with these. I don't think that second one is necessarily correct. Look at the random module: it is based on an OOP design, with classes random.Random and random.SystemRandom doing the real work. But most people don't use them directly, they use the procedural interface random.random, random.choice, random.seed etc. -- Steve From ifeanyioprah at yahoo.com Wed Jan 13 00:57:20 2016 From: ifeanyioprah at yahoo.com (ifeanyioprah at yahoo.com) Date: Wed, 13 Jan 2016 08:57:20 +0300 Subject: =?UTF-8?B?TmVlZCBzb2x1dGlvbiB3aXRoIHRoaXMgcHJvYmxlbQ==?= Message-ID: <1452664640.353395695@f125.i.mail.ru> Create a class called BankAccount? Create a constructor that takes in an in?teger and assigns this to a `balance` pr?operty. Create a method called `deposit` that ta?kes in cash deposit amount and updates t?he balance accordingly. Create a method called `withdraw` that t?akes in cash withdrawal amount and updat?es the balance accordingly. if amount is? greater than balance return `"invalid t?ransaction"` Create a subclass MinimumBalanceAccount ?of the BankAccount class import unittest class AccountBalanceTest?Cases(unittest.TestCase): def setUp(self?): self.my_account = BankAccount(90) def test_balance(self): self.assertEqual?(self.my_account.balance, 90, msg='Accou?nt Balance Invalid') def test_deposit(self): self.my_account.?deposit(90) self.assertEqual(self.my_acc?ount.balance, 180, msg='Deposit method i?naccurate') def test_withdraw(self): self.my_account?.withdraw(40) self.assertEqual(self.my_a?ccount.balance, 50, msg='Withdraw method? inaccurate') def test_invalid_operation(self): self.a?ssertEqual(self.my_account.withdraw(1000?), "invalid transaction", msg='Invalid t?ransaction') def test_sub_class(self): self.assertTru?e(issubclass(MinimumBalanceAccount, Bank?Account), msg='No true subclass of BankA?ccount') Thank you.....? Pls need assistance. My email : ifeanyioprah at yahoo.com. From rustompmody at gmail.com Wed Jan 13 01:31:05 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 12 Jan 2016 22:31:05 -0800 (PST) Subject: When I need classes? In-Reply-To: <5695e025$0$11113$c3e8da3@news.astraweb.com> References: <34aa811c-433d-4f8a-90e0-9dd768460415@googlegroups.com> <5695e025$0$11113$c3e8da3@news.astraweb.com> Message-ID: On Wednesday, January 13, 2016 at 10:57:23 AM UTC+5:30, Steven D'Aprano wrote: > On Wednesday 13 January 2016 14:36, Rustom Mody wrote: > > > 1. Python the LANGUAGE, is rather even-handed in paradigm choice: Choose > > OO, imperative, functional or whatever style pleases/suits you > > 2. Python LIBRARIES however need to make committing choices. Users of > > those then need to align with these. > > I don't think that second one is necessarily correct. Look at the random > module: it is based on an OOP design, with classes random.Random and > random.SystemRandom doing the real work. But most people don't use them > directly, they use the procedural interface random.random, random.choice, > random.seed etc. > Yes one can have more or less degrees of freedom. Are infinite degrees possible? I believe not. eg My example of re is strictly not correct: can use strings instead of re objects Can use findall instead of search/match and avoid groping around in opaque match objects So you may conclude that the re module allows these degrees of freedom But you cant bold res all the way into the syntax of the language (eg perl/awk) Anyway these are side points My main point is that when you sit on top of heavy-duty many-layered libraries (worse frameworks... OP seems to be trying Kivy) then you have to align with the opinionatedness of all the layers down to python. Of course that is modulo the leakiness of the abstractions. eg mostly python programmers do not need to know the underlying C... Mostly... And then someone asks about id/is/performance... From maillists at pp.inet.fi Wed Jan 13 01:46:15 2016 From: maillists at pp.inet.fi (K. Elo) Date: Wed, 13 Jan 2016 08:46:15 +0200 Subject: SSL certification fails / tweepy Message-ID: <5695F2B7.3000401@pp.inet.fi> Dear list members! I have written I small python script for twitter mining utilising the 'tweepy' library. Since a couple of days I cannot use the script anymore, due to a "ssl certificate verification failed" error. The authentication with Twitter API succeess, but when I try to run the following code: --- snip --- api=tweepy.API(auth) # 'auth' is my authentification token print("Receiving network members for '", user_to_track, "' ... ") network_members = [] # # The user wants to get all followers of a twitter user # while True: try: for page in tweepy.Cursor(api.followers_ids, user_to_track).pages(): network_members.extend(page) print("Current follower count: ", len(network_members)) if len(page)==5000: time.sleep(60) break except tweepy.TweepError as e: # Did we exceed the rate limit? if e.message[0]["code"]==88: # Yes -> sleep for 15 minutes and then continue print("Rate limit exceeded, sleeping for 15 minutes ...") time.sleep(15*60) continue else: # Something else went wrong -> break out from the loop! print("Exception: ", e.message[0], " (", e.code[0], ") --> interrupting, sorry!") break --- snip --- the execution is broken with an "?SL_VERIFICATION_FAILED" error. I have tried both python 2.7 and 3.x, no difference :( I have also upgraded 'tweepy', no help. I suspect this being somehow related to my current system, i.e. openSuSE Tumbleweed. I tested the script on a ubuntu system and encountered no problems... But I need to get the script running also with my openSuSE :) Any ideas what could be causing this weird problem? Thanks in advance! Kimmo From steve+comp.lang.python at pearwood.info Wed Jan 13 02:30:19 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jan 2016 18:30:19 +1100 Subject: Stop writing Python 4 incompatible code Message-ID: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> Quote: With the end of support for Python 2 on the horizon (in 2020), many package developers have made their packages compatible with both Python 2 and Python 3 by using constructs such as: if sys.version_info[0] == 2: # Python 2 code else: # Python 3 code [...] Another example of problematic code is the following: if six.PY2: # Python 2 code elif six.PY3: # Python 3 code In this case, no code will get executed on Python 4 at all! [end quote] http://astrofrog.github.io/blog/2016/01/12/stop-writing-python-4- incompatible-code/ or http://tinyurl.com/jskt54s Better still, don't do version checks *at all*. There is almost never any need for a version check. Better is to use feature detection: try: xrange # Succeeds in Python 2. except NameError: xrange = range Not only is this almost entirely future-proof[1] and avoids overly-specific version tests, but if your code happens to find itself running in a customized environment which has already monkey-patched builtins to re-add xrange, the first lookup will succeed and no extra work need be done. You can be extremely fine-grained too: try: casefold = str.casefold # Succeeds in Python 3.3 or better else: casefold = str.lower # Poor Man's case-folding. # Or if you prefer: def casefold(s): ... About the only thing I use version checking for is to decide which prompt I want to use: if sys.version_info[0] >= 3 and os.name == 'posix': # Make the main prompt bold in Python 3. This probably won't # work on Windows, put it should(?) work on any POSIX system. sys.ps1 = '\001\x1b[1m\002py> \001\x1b[0m\002' else: sys.ps1 = 'py> ' In Python 3, that highlights the prompt py> in bold. You can detect the return type: if isinstance(map(len, []), list): print("Python 2 version of map") else: # Python 3, or Python 2 with future_builtins. print("Python 3 version of map") and even the number and kind of arguments: try: sorted([], cmp=None) except TypeError: print("use key not cmp in Python 3") _sorted = sorted def sorted(L, cmp=None): if cmp is None: return _sorted(L) return _sorted(L, key=functools.cmp_to_key(cmp)) So remember, use feature detection, not version checking. [1] It might fail if some distant version of Python adds an xrange which does something completely unexpected, or if it removes range; but surely nobody can be expected to write forward-compatible code in the face of changes of that magnitude. -- Steve From mail at timgolden.me.uk Wed Jan 13 03:58:03 2016 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 13 Jan 2016 08:58:03 +0000 Subject: Need solution with this problem In-Reply-To: <1452664640.353395695@f125.i.mail.ru> References: <1452664640.353395695@f125.i.mail.ru> Message-ID: <5696119B.6070609@timgolden.me.uk> On 13/01/2016 05:57, ifeanyioprah--- via Python-list wrote: [... snip yet another homework dump with one more still held in moderation ...] At this point you're basically spamming this list. I won't allow any more of your posts through unless they appear to be engaging with the help shown to you (and others?) over the last few days. TJG From tjreedy at udel.edu Wed Jan 13 04:05:18 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jan 2016 04:05:18 -0500 Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> Message-ID: On 1/12/2016 5:18 AM, Chris Angelico wrote: > On Tue, Jan 12, 2016 at 7:27 PM, Terry Reedy wrote: >> Can psycopg2 be installed with pip? There is an issue (#23551) to make a >> pip GUI and make it accessible from IDLE. We need someone with both pip and >> tkinter knowledge to either design and write it or mentor a GSOC student to >> do so. One written, I would add an IDLE menu item to run it, in a separate >> process, just as done now with turtledemo. > > Yes, invisible smiley... but with a hint of truth too. Obviously > installing PostgreSQL itself is outside the scope of IDLE, but > psycopg2 is indeed pip-installable... except that it isn't always, on > Windows, because wheels aren't available for all versions. (There's no > Python 3.5 wheel yet; at least, I can't see one on PyPI.) Maybe someone should give them a prod. It has been 4 months. http://www.lfd.uci.edu/~gohlke/pythonlibs/ only has psycopg, for 2.6. > So what I'm > really looking for isn't an IDLE feature but a Python packaging > feature - some people have talked about setting up build farms that > can produce wheels for people. Building binaries is a rather different issue, certainly on Windows. > Hmm. I just tried this, and actually, there's some possibly > low-hanging fruit. (Tested on Python 3.4.3 as 3.5 can't install > psycopg2 anyway.) > >>>> import pip; pip.main(["install","psycopg2"]) https://bugs.python.org/issue23551 has my report of experimenting with directly using pip.main. The main issue I ran into is that pip creates a cache of 'currently installed packages' the first time it needs it and never again during the same process. In other words, pip.main is called exactly once when pip is run from the command line. Another command from the command line starts a new process, which makes a new cache. So calling main() repeatedly may fail due to a stale cache. However, the need to refresh it is predictable, so reloading the module may work. > This produces a rather messy display, because pip.main seems to assume > that writing carriage returns to the console will result in the > display nicely overwriting (producing a moving progress bar as the > file gets downloaded). If IDLE can't handle carriage returns as such, > an easy fix would be to simply display them as complete lines; it > would be more verbose than the normal console behaviour, but not as > ugly. Currently, Idle sends user code output to the tk Text widget as is, except for colorizing. There was an issue about changing this, but it was closed, at least for the time being, as Python allows print to send output to any file and does not require than stdout be connected to a 'console', and anyway there is no standard for console behavior. A gui program that runs pip and displays its output would generally parse output for display in differnet widgets. > > A couple of other random thoughts from this experiment. > > * Going to python.org and pointing the mouse at the download link got > me 3.5.1 32-bit. This is on Google Chrome on a Windows 7 64-bit VM. > * Instead of pip.main(["install","psycopg2"]), I'd like to be able to > say pip.install("psycopg2"). In fact, I might take that to the pip > folks as a suggestion. > * The performance difference between "import pip" on 3.4.3 and 3.5.1 > was dramatic! I don't know whether it's CPython that's been sped up or > pip itself, but it's awesome! Try with 3.4.4, as I believe its installer should also update to the most recent pip version. > There's some kind of issue between pip and Idle that means that > installing a non-wheel blows up with an exception: > > > Traceback (most recent call last): > File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\basecommand.py", > ... > return s.decode(sys.__stdout__.encoding) > AttributeError: 'NoneType' object has no attribute 'encoding' Assuming that sys.__sydout__ is not None is a bug on pip's part. Perhaps you could report it to it list or tracker, and point Donald and whoever to https://docs.python.org/3/library/sys.html#sys.__stdin__ "Note Under some conditions stdin, stdout and stderr as well as the original values __stdin__, __stdout__ and __stderr__ can be None. It is usually the case for Windows GUI apps that aren?t connected to a console and Python apps started with pythonw." IDLE is a GUI app that on Windows is started with pythonw.exe. More relevant, user code is executed in a windowless pythonw process. The same problem should occur with any IDE that executes user code in a pythonw process. A GUI program could work around the bug by setting sys.__stdin__ to an object with a .encoding attribute. I checked that this can be done. > Maybe calling pip.main just isn't a supported thing, but it'd be nice > if there were _some_ way to do this, even without a fancy GUI. Calling is once during a process is supported, or supposed to be. If you ran, at the console, > pythonw.exe -c "import pip; pip.main(['install','psycopg2'])" the same failure would happen. However, the only indication of failure, before you checked site-packages and found no psycopg2, would be the quick return to the console prompt. > How much of this is worth doing anything about, and how much is "hey, > you're hacking around calling a command-line tool from inside a GUI, > and stuff ain't a'gonna work right"? On the issue linked above, Donald Stuffit, a (the?) pip maintainer, said that he wanted there to be a pip Gui, even though he was unlikely to write it himself. We have identified 3 problems; I believe all can be worked around. I added your two and the workarounds to the issue. -- Terry Jan Reedy From tjreedy at udel.edu Wed Jan 13 04:10:06 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jan 2016 04:10:06 -0500 Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> Message-ID: On 1/12/2016 8:20 PM, jfong at ms4.hinet.net wrote: > Terry Reedy at 2016/1/12 UTC+8 3:56:03PM wrote: >> Revamping IDLE to 1. use ttk widgets and 2. become a modern single >> window app with multiple panes, including a tabbed editor pane, is >> a goal for 2016. > > That will be great, I'm looking forward to it. > > By the way, when I was playing around with the IDLE editor yesterday, > I had noticed that during the time the "Search Dialog" was opened, > "Find Next" button will not highlight the item searched, unless the > dialog was closed. This was a Windows specific problem that was fixed (for me) in all three recent (last November/December) bugfix releases. If you have a problem with *current* IDLE, I would like to know. -- Terry Jan Reedy From joel.goldstick at gmail.com Wed Jan 13 04:15:19 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 13 Jan 2016 04:15:19 -0500 Subject: Need solution with this problem In-Reply-To: <5696119B.6070609@timgolden.me.uk> References: <1452664640.353395695@f125.i.mail.ru> <5696119B.6070609@timgolden.me.uk> Message-ID: On Wed, Jan 13, 2016 at 3:58 AM, Tim Golden wrote: > On 13/01/2016 05:57, ifeanyioprah--- via Python-list wrote: > > [... snip yet another homework dump with one more still held in > moderation ...] > > At this point you're basically spamming this list. I won't allow any > more of your posts through unless they appear to be engaging with the > help shown to you (and others?) over the last few days. > > TJG > -- > https://mail.python.org/mailman/listinfo/python-list > plus 1! -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From rosuav at gmail.com Wed Jan 13 05:09:05 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jan 2016 21:09:05 +1100 Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> Message-ID: On Wed, Jan 13, 2016 at 8:05 PM, Terry Reedy wrote: > Assuming that sys.__sydout__ is not None is a bug on pip's part. Perhaps you > could report it to it list or tracker, and point Donald and whoever to > https://docs.python.org/3/library/sys.html#sys.__stdin__ > > "Note > > Under some conditions stdin, stdout and stderr as well as the original > values __stdin__, __stdout__ and __stderr__ can be None. It is usually the > case for Windows GUI apps that aren?t connected to a console and Python apps > started with pythonw." > Thanks! Posted. https://github.com/pypa/pip/issues/3356 ChrisA From bonfaceo3 at gmail.com Wed Jan 13 06:14:18 2016 From: bonfaceo3 at gmail.com (bonfaceo3 at gmail.com) Date: Wed, 13 Jan 2016 03:14:18 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> Message-ID: <3643bf28-dad3-48ca-9dcd-9581049415c2@googlegroups.com> On Saturday, December 12, 2015 at 12:05:29 PM UTC+3, Harbey Leke wrote: > Create a class called BankAccount > > .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 > > Please i need help on this i am a beginer into python programming. > > > Also below is a test case given for this project > > > import unittest > class AccountBalanceTestCases(unittest.TestCase): > def setUp(self): > self.my_account = BankAccount(90) > > def test_balance(self): > self.assertEqual(self.my_account.balance, 90, msg='Account Balance Invalid') > > def test_deposit(self): > self.my_account.deposit(90) > self.assertEqual(self.my_account.balance, 180, msg='Deposit method inaccurate') > > def test_withdraw(self): > self.my_account.withdraw(40) > self.assertEqual(self.my_account.balance, 50, msg='Withdraw method inaccurate') > > def test_invalid_operation(self): > self.assertEqual(self.my_account.withdraw(1000), "invalid transaction", msg='Invalid transaction') > > def test_sub_class(self): > self.assertTrue(issubclass(MinimumBalanceAccount, BankAccount), msg='No true subclass of BankAccount') lee is right go through the comment thread you will get what you are looking for From cfkaran2 at gmail.com Wed Jan 13 06:20:17 2016 From: cfkaran2 at gmail.com (Cem Karan) Date: Wed, 13 Jan 2016 06:20:17 -0500 Subject: How to remove item from heap efficiently? In-Reply-To: <5695276A.2020101@mail.de> References: <568EEC40.7070807@mail.de> <568FE797.6090808@mail.de> <5692A795.3070904@mail.de> <5695276A.2020101@mail.de> Message-ID: <7A7E26D9-01E5-4D77-92B4-3491D86E1EA8@gmail.com> On Jan 12, 2016, at 11:18 AM, "Sven R. Kunze" wrote: > On 12.01.2016 03:48, Cem Karan wrote: >> >> Jumping in late, but... >> >> If you want something that 'just works', you can use HeapDict: >> >> http://stutzbachenterprises.com/ >> >> I've used it in the past, and it works quite well. I haven't tested its asymptotic performance though, so you might want to check into that. > > Thanks for replying here. I've come across these types of wrappers/re-implementations of heapq as well when researching this issue. :) > > Unfortunately, they don't solve the underlying issue at hand which is: "remove item from heap with unknown index" and be efficient at it (by not using _heapq C implementation). > > > So, I thought I did another wrapper. ;) It at least uses _heapq (if available otherwise heapq) and lets you remove items without violating the invariant in O(log n). I am going to make that open-source on pypi and see what people think of it. Is that so? I'll be honest, I never tested its asymptotic performance, I just assumed that he had a dict coupled with a heap somehow, but I never looked into the code. That said, IMHO using a dict interface is the way to go for priority queues; it really simplified my code using it! This is my not-so-subtle way of asking you to adopt the MutableMapping interface for your wrapper ;) Thanks, Cem Karan From __peter__ at web.de Wed Jan 13 06:21:25 2016 From: __peter__ at web.de (Peter Otten) Date: Wed, 13 Jan 2016 12:21:25 +0100 Subject: Data Entry References: <6ea58259-05f8-40b5-8c85-46a69668c8e6@googlegroups.com> Message-ID: Chris Angelico wrote: > On Wed, Jan 13, 2016 at 12:52 PM, wrote: >> If i change the value from origin to origin energy and save - the value >> updated to the database is correct but when the page is re displayed it >> only shows origin in the text field - as if it ignores everything after >> the space. >> >> How do I make it display the full name. >> > > To set a multi-word value as an HTML attribute, you'll need to put > quotes around it. You might be able to get away with using %r instead > of %s, or even just "%s", That is bad advice that "works" until there is a value containing quotes or other markup. > but proper escaping would be the best way. OP, that's what you should do. Either pick one of the many templating languages -- a simple one is http://bottlepy.org/docs/dev/stpl.html >>> from bottle import SimpleTemplate >>> SimpleTemplate('... value="{{supplier}}">').render( ... supplier=" 'bar' \"baz\"") '... value="<foo> 'bar' "baz"">' -- or at least manually apply html.escape() to the value: >>> import html >>> '... value="%s">' % html.escape(" 'bar' \"baz\"") '... value="<foo> 'bar' "baz"">' From rosuav at gmail.com Wed Jan 13 06:29:37 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jan 2016 22:29:37 +1100 Subject: Data Entry In-Reply-To: References: <6ea58259-05f8-40b5-8c85-46a69668c8e6@googlegroups.com> Message-ID: On Wed, Jan 13, 2016 at 10:21 PM, Peter Otten <__peter__ at web.de> wrote: >> To set a multi-word value as an HTML attribute, you'll need to put >> quotes around it. You might be able to get away with using %r instead >> of %s, or even just "%s", > > That is bad advice that "works" until there is a value containing > quotes or other markup. > Which is why I said "get away with". If you know your data, you might know that it can have spaces but never quotes, for instance. But proper escaping is definitely the way to go. ChrisA From arobinson at lordlawson.org.uk Wed Jan 13 07:23:05 2016 From: arobinson at lordlawson.org.uk (Alan Robinson) Date: Wed, 13 Jan 2016 04:23:05 -0800 (PST) Subject: local variable 'juveniles' referenced before assignment Message-ID: def menu(): option = int(input("Please select an option: \n 1: Set Generation 0 Values \n 2: View Generation 0 Values \n 3: Run Model \n 4: Print values")) if option == 1: juveniles,adults,seniles = setGen() elif option == 2: displayGen() elif option == 3: runModel(juveniles,adults,seniles) elif option == 4: print(juveniles,adults,seniles) menu() def setGen(): #enter number of juveniles juveniles = int(input("How many juveniles are in the total popluation?")) #enter number of adults adults = int(input("How many Adults are in the total popluation?")) #enter number of seniles seniles = int(input("How many Seniles are in the total popluation?")) #enter juvenilesenile survival rates return(juveniles,adults,seniles) menu() when I go to print I get the above error I can't see a solution please help From rosuav at gmail.com Wed Jan 13 07:32:31 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jan 2016 23:32:31 +1100 Subject: local variable 'juveniles' referenced before assignment In-Reply-To: References: Message-ID: On Wed, Jan 13, 2016 at 11:23 PM, Alan Robinson wrote: > def menu(): > option = int(input("Please select an option: \n 1: Set Generation 0 Values \n 2: View Generation 0 Values \n 3: Run Model \n 4: Print values")) > > if option == 1: > juveniles,adults,seniles = setGen() > elif option == 2: > displayGen() > elif option == 3: > runModel(juveniles,adults,seniles) > elif option == 4: > print(juveniles,adults,seniles) > menu() > This is a classic use of recursion instead of iteration. When you call menu() again, you're creating a completely new 'slot' for the new function; it has its own set of names. Assigning to names in one call of menu() has no effect on any other call. Instead, look into the way a while loop works. You'll find that your code is simpler and clearer, plus your variables will stay set. ChrisA From arobinson at lordlawson.org.uk Wed Jan 13 07:54:36 2016 From: arobinson at lordlawson.org.uk (Alan Robinson) Date: Wed, 13 Jan 2016 04:54:36 -0800 (PST) Subject: local variable 'juveniles' referenced before assignment In-Reply-To: References: Message-ID: <5b66e2de-bc73-4200-a9c1-645d2e3f0467@googlegroups.com> On Wednesday, 13 January 2016 12:32:51 UTC, Chris Angelico wrote: > On Wed, Jan 13, 2016 at 11:23 PM, Alan Robinson > wrote: > > def menu(): > > option = int(input("Please select an option: \n 1: Set Generation 0 Values \n 2: View Generation 0 Values \n 3: Run Model \n 4: Print values")) > > > > if option == 1: > > juveniles,adults,seniles = setGen() > > elif option == 2: > > displayGen() > > elif option == 3: > > runModel(juveniles,adults,seniles) > > elif option == 4: > > print(juveniles,adults,seniles) > > menu() > > > > This is a classic use of recursion instead of iteration. When you call > menu() again, you're creating a completely new 'slot' for the new > function; it has its own set of names. Assigning to names in one call > of menu() has no effect on any other call. > > Instead, look into the way a while loop works. You'll find that your > code is simpler and clearer, plus your variables will stay set. > > ChrisA thanks I need the menu to run again not sure how to do that though From rosuav at gmail.com Wed Jan 13 08:05:15 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2016 00:05:15 +1100 Subject: local variable 'juveniles' referenced before assignment In-Reply-To: <5b66e2de-bc73-4200-a9c1-645d2e3f0467@googlegroups.com> References: <5b66e2de-bc73-4200-a9c1-645d2e3f0467@googlegroups.com> Message-ID: On Wed, Jan 13, 2016 at 11:54 PM, Alan Robinson wrote: > On Wednesday, 13 January 2016 12:32:51 UTC, Chris Angelico wrote: >> On Wed, Jan 13, 2016 at 11:23 PM, Alan Robinson >> wrote: >> > def menu(): >> > option = int(input("Please select an option: \n 1: Set Generation 0 Values \n 2: View Generation 0 Values \n 3: Run Model \n 4: Print values")) >> > >> > if option == 1: >> > juveniles,adults,seniles = setGen() >> > elif option == 2: >> > displayGen() >> > elif option == 3: >> > runModel(juveniles,adults,seniles) >> > elif option == 4: >> > print(juveniles,adults,seniles) >> > menu() >> > >> >> This is a classic use of recursion instead of iteration. When you call >> menu() again, you're creating a completely new 'slot' for the new >> function; it has its own set of names. Assigning to names in one call >> of menu() has no effect on any other call. >> >> Instead, look into the way a while loop works. You'll find that your >> code is simpler and clearer, plus your variables will stay set. >> >> ChrisA > thanks I need the menu to run again not sure how to do that though Not quite. You don't want the menu to run again; you want it to continue to run. Look up the 'while' loop and what it does. ChrisA From __peter__ at web.de Wed Jan 13 08:05:39 2016 From: __peter__ at web.de (Peter Otten) Date: Wed, 13 Jan 2016 14:05:39 +0100 Subject: local variable 'juveniles' referenced before assignment References: <5b66e2de-bc73-4200-a9c1-645d2e3f0467@googlegroups.com> Message-ID: Alan Robinson wrote: > On Wednesday, 13 January 2016 12:32:51 UTC, Chris Angelico wrote: >> On Wed, Jan 13, 2016 at 11:23 PM, Alan Robinson >> wrote: >> > def menu(): >> > option = int(input("Please select an option: \n 1: Set Generation 0 >> > Values \n 2: View Generation 0 Values \n 3: Run Model \n 4: Print >> > values")) >> > >> > if option == 1: >> > juveniles,adults,seniles = setGen() >> > elif option == 2: >> > displayGen() >> > elif option == 3: >> > runModel(juveniles,adults,seniles) >> > elif option == 4: >> > print(juveniles,adults,seniles) >> > menu() >> > >> >> This is a classic use of recursion instead of iteration. When you call >> menu() again, you're creating a completely new 'slot' for the new >> function; it has its own set of names. Assigning to names in one call >> of menu() has no effect on any other call. >> >> Instead, look into the way a while loop works. You'll find that your >> code is simpler and clearer, plus your variables will stay set. >> >> ChrisA > thanks I need the menu to run again not sure how to do that though def menu(): option = 1 # make sure setGen is invoked on first iteration while option: # choosing 0 ends the while loop if option == 1: juveniles, adults, seniles = setGen() elif option == 2: ... option = int(input(...)) # choose option for the next iteration From arobinson at lordlawson.org.uk Wed Jan 13 08:22:28 2016 From: arobinson at lordlawson.org.uk (Alan Robinson) Date: Wed, 13 Jan 2016 05:22:28 -0800 (PST) Subject: local variable 'juveniles' referenced before assignment In-Reply-To: References: <5b66e2de-bc73-4200-a9c1-645d2e3f0467@googlegroups.com> Message-ID: On Wednesday, 13 January 2016 13:06:11 UTC, Peter Otten wrote: > Alan Robinson wrote: > > > On Wednesday, 13 January 2016 12:32:51 UTC, Chris Angelico wrote: > >> On Wed, Jan 13, 2016 at 11:23 PM, Alan Robinson > >> wrote: > >> > def menu(): > >> > option = int(input("Please select an option: \n 1: Set Generation 0 > >> > Values \n 2: View Generation 0 Values \n 3: Run Model \n 4: Print > >> > values")) > >> > > >> > if option == 1: > >> > juveniles,adults,seniles = setGen() > >> > elif option == 2: > >> > displayGen() > >> > elif option == 3: > >> > runModel(juveniles,adults,seniles) > >> > elif option == 4: > >> > print(juveniles,adults,seniles) > >> > menu() > >> > > >> > >> This is a classic use of recursion instead of iteration. When you call > >> menu() again, you're creating a completely new 'slot' for the new > >> function; it has its own set of names. Assigning to names in one call > >> of menu() has no effect on any other call. > >> > >> Instead, look into the way a while loop works. You'll find that your > >> code is simpler and clearer, plus your variables will stay set. > >> > >> ChrisA > > thanks I need the menu to run again not sure how to do that though > > def menu(): > option = 1 # make sure setGen is invoked on first iteration > while option: # choosing 0 ends the while loop > if option == 1: > juveniles, adults, seniles = setGen() > elif option == 2: > ... > option = int(input(...)) # choose option for the next iteration that's really helpful I understand whats happening now I just need to work out how to do this loop as I am new it looks difficult to do here goes From arobinson at lordlawson.org.uk Wed Jan 13 08:26:56 2016 From: arobinson at lordlawson.org.uk (Alan Robinson) Date: Wed, 13 Jan 2016 05:26:56 -0800 (PST) Subject: local variable 'juveniles' referenced before assignment In-Reply-To: References: <5b66e2de-bc73-4200-a9c1-645d2e3f0467@googlegroups.com> Message-ID: <8c528328-0dcd-49df-8d0c-d4519f24ea3a@googlegroups.com> On Wednesday, 13 January 2016 13:23:04 UTC, Alan Robinson wrote: > On Wednesday, 13 January 2016 13:06:11 UTC, Peter Otten wrote: > > Alan Robinson wrote: > > > > > On Wednesday, 13 January 2016 12:32:51 UTC, Chris Angelico wrote: > > >> On Wed, Jan 13, 2016 at 11:23 PM, Alan Robinson > > >> wrote: > > >> > def menu(): > > >> > option = int(input("Please select an option: \n 1: Set Generation 0 > > >> > Values \n 2: View Generation 0 Values \n 3: Run Model \n 4: Print > > >> > values")) > > >> > > > >> > if option == 1: > > >> > juveniles,adults,seniles = setGen() > > >> > elif option == 2: > > >> > displayGen() > > >> > elif option == 3: > > >> > runModel(juveniles,adults,seniles) > > >> > elif option == 4: > > >> > print(juveniles,adults,seniles) > > >> > menu() > > >> > > > >> > > >> This is a classic use of recursion instead of iteration. When you call > > >> menu() again, you're creating a completely new 'slot' for the new > > >> function; it has its own set of names. Assigning to names in one call > > >> of menu() has no effect on any other call. > > >> > > >> Instead, look into the way a while loop works. You'll find that your > > >> code is simpler and clearer, plus your variables will stay set. > > >> > > >> ChrisA > > > thanks I need the menu to run again not sure how to do that though > > > > def menu(): > > option = 1 # make sure setGen is invoked on first iteration > > while option: # choosing 0 ends the while loop > > if option == 1: > > juveniles, adults, seniles = setGen() > > elif option == 2: > > ... > > option = int(input(...)) # choose option for the next iteration > > that's really helpful I understand what's happening now I just need to work out how to do this loop as I am new it looks difficult to do here goes not too sure what you mean by make sure setGen is invoked on the first iteration? From phatsammhiel at gmail.com Wed Jan 13 08:27:21 2016 From: phatsammhiel at gmail.com (phatsammhiel at gmail.com) Date: Wed, 13 Jan 2016 05:27:21 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: References: <57a7133b-8ee0-4196-b2e5-6aa393a4e5fb@googlegroups.com> <20151228222953.GA94789@cskk.homeip.net> Message-ID: <3a7cd450-dd0a-4c04-a608-980d5aa42648@googlegroups.com> please assist with the solution on this p h a t s a m m hi e l at gmail.com thanks From phatsammhiel at gmail.com Wed Jan 13 08:28:14 2016 From: phatsammhiel at gmail.com (phatsammhiel at gmail.com) Date: Wed, 13 Jan 2016 05:28:14 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: <1fa635dd-704b-41c6-a6e0-f3be0dac1fe5@googlegroups.com> References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <79ce6cf5-4bad-47f6-8824-44ce9849d825@googlegroups.com> <4023d75d-5e96-40b0-b1b1-a193c722004d@googlegroups.com> <1fa635dd-704b-41c6-a6e0-f3be0dac1fe5@googlegroups.com> Message-ID: <252436f8-89dc-4273-9ec9-3bb2207da846@googlegroups.com> please kindly inbox me the solution thanks in anticipation of your kind gesture sammhieladeolu at gmail.com From rosuav at gmail.com Wed Jan 13 08:37:17 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2016 00:37:17 +1100 Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: <252436f8-89dc-4273-9ec9-3bb2207da846@googlegroups.com> References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <79ce6cf5-4bad-47f6-8824-44ce9849d825@googlegroups.com> <4023d75d-5e96-40b0-b1b1-a193c722004d@googlegroups.com> <1fa635dd-704b-41c6-a6e0-f3be0dac1fe5@googlegroups.com> <252436f8-89dc-4273-9ec9-3bb2207da846@googlegroups.com> Message-ID: On Thu, Jan 14, 2016 at 12:28 AM, wrote: > please kindly inbox me the solution > > thanks in anticipation of your kind gesture > > > sammhieladeolu at gmail.com Don't you get it? You are not going to be given the code. All you're doing is making us resent your presence, which means you're less likely to get help in the future. Please do not repeatedly post from new email addresses. This is spamming, and will be reported to Gmail as such. ChrisA From hongyi.zhao at gmail.com Wed Jan 13 08:40:07 2016 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Wed, 13 Jan 2016 13:40:07 -0000 (UTC) Subject: 45 Message-ID: rt -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From sjmsoft at gmail.com Wed Jan 13 09:21:46 2016 From: sjmsoft at gmail.com (sjmsoft at gmail.com) Date: Wed, 13 Jan 2016 06:21:46 -0800 (PST) Subject: Stop writing Python 4 incompatible code In-Reply-To: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> Message-ID: <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> This strikes me as very good advice. Thanks for being so far-sighted. And let's hope that Python 4 has fewer incompatibilities (none would good) than Python 3! Cheers, Steve J. Martin From joel.goldstick at gmail.com Wed Jan 13 09:43:15 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 13 Jan 2016 09:43:15 -0500 Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <79ce6cf5-4bad-47f6-8824-44ce9849d825@googlegroups.com> <4023d75d-5e96-40b0-b1b1-a193c722004d@googlegroups.com> <1fa635dd-704b-41c6-a6e0-f3be0dac1fe5@googlegroups.com> <252436f8-89dc-4273-9ec9-3bb2207da846@googlegroups.com> Message-ID: On Wed, Jan 13, 2016 at 8:37 AM, Chris Angelico wrote: > On Thu, Jan 14, 2016 at 12:28 AM, wrote: > > please kindly inbox me the solution > > > > thanks in anticipation of your kind gesture > > > > > > sammhieladeolu at gmail.com > > Don't you get it? You are not going to be given the code. All you're > doing is making us resent your presence, which means you're less > likely to get help in the future. > > Please do not repeatedly post from new email addresses. This is > spamming, and will be reported to Gmail as such. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > 93 messages in this thread. a handful are earnest attempts to help a beginner with what looks like homework. The rest are an odd barrage of obsequious please and whining from who knows how many OPs.begging to have their source code delivered. bleh -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From mail at timgolden.me.uk Wed Jan 13 10:23:00 2016 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 13 Jan 2016 15:23:00 +0000 Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <79ce6cf5-4bad-47f6-8824-44ce9849d825@googlegroups.com> <4023d75d-5e96-40b0-b1b1-a193c722004d@googlegroups.com> <1fa635dd-704b-41c6-a6e0-f3be0dac1fe5@googlegroups.com> <252436f8-89dc-4273-9ec9-3bb2207da846@googlegroups.com> Message-ID: <56966BD4.6090502@timgolden.me.uk> On 13/01/2016 14:43, Joel Goldstick wrote: > On Wed, Jan 13, 2016 at 8:37 AM, Chris Angelico wrote: > >> On Thu, Jan 14, 2016 at 12:28 AM, wrote: >>> please kindly inbox me the solution >>> >>> thanks in anticipation of your kind gesture >>> >>> >>> sammhieladeolu at gmail.com >> >> Don't you get it? You are not going to be given the code. All you're >> doing is making us resent your presence, which means you're less >> likely to get help in the future. >> >> Please do not repeatedly post from new email addresses. This is >> spamming, and will be reported to Gmail as such. >> >> ChrisA >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > 93 messages in this thread. a handful are earnest attempts to help a > beginner with what looks like homework. The rest are an odd barrage of > obsequious please and whining from who knows how many OPs.begging to have > their source code delivered. I've also held this (and one other) email address for moderation. TJG From Eddy at Quicksall.com Wed Jan 13 10:23:00 2016 From: Eddy at Quicksall.com (Eddy Quicksall) Date: Wed, 13 Jan 2016 10:23:00 -0500 Subject: Building list Message-ID: <000601d14e16$5002e8b0$f008ba10$@com> What list do I use for building issues? I'm building 3.5.1. Eddy From mr.eightnoteight at gmail.com Wed Jan 13 10:34:26 2016 From: mr.eightnoteight at gmail.com (srinivas devaki) Date: Wed, 13 Jan 2016 21:04:26 +0530 Subject: How to remove item from heap efficiently? In-Reply-To: <7A7E26D9-01E5-4D77-92B4-3491D86E1EA8@gmail.com> References: <568EEC40.7070807@mail.de> <568FE797.6090808@mail.de> <5692A795.3070904@mail.de> <5695276A.2020101@mail.de> <7A7E26D9-01E5-4D77-92B4-3491D86E1EA8@gmail.com> Message-ID: On Wed, Jan 13, 2016 at 4:50 PM, Cem Karan wrote: > > Is that so? I'll be honest, I never tested its asymptotic performance, I just assumed that he had a dict coupled with a heap somehow, but I never looked into the code. > I have just tested the code, the aymptotic performance is O(log(n)) for all operations. Infact the code is very simple to understand, technically the heapdict class is composed of a dict and heap, each element of heap is a mutable list and dict stores references to that mutable list, so that a specific element can be deleted in O(log(n)) From andrew.ongko at gmail.com Wed Jan 13 10:35:35 2016 From: andrew.ongko at gmail.com (Andrew Ongko) Date: Wed, 13 Jan 2016 22:35:35 +0700 Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: <56966BD4.6090502@timgolden.me.uk> References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <79ce6cf5-4bad-47f6-8824-44ce9849d825@googlegroups.com> <4023d75d-5e96-40b0-b1b1-a193c722004d@googlegroups.com> <1fa635dd-704b-41c6-a6e0-f3be0dac1fe5@googlegroups.com> <252436f8-89dc-4273-9ec9-3bb2207da846@googlegroups.com> <56966BD4.6090502@timgolden.me.uk> Message-ID: On Jan 13, 2016 10:25 PM, "Tim Golden" wrote: > > On 13/01/2016 14:43, Joel Goldstick wrote: > > On Wed, Jan 13, 2016 at 8:37 AM, Chris Angelico wrote: > > > >> On Thu, Jan 14, 2016 at 12:28 AM, wrote: > >>> please kindly inbox me the solution > >>> > >>> thanks in anticipation of your kind gesture > >>> > >>> > >>> sammhieladeolu at gmail.com > >> > >> Don't you get it? You are not going to be given the code. All you're > >> doing is making us resent your presence, which means you're less > >> likely to get help in the future. > >> > >> Please do not repeatedly post from new email addresses. This is > >> spamming, and will be reported to Gmail as such. > >> > >> ChrisA > >> -- > >> https://mail.python.org/mailman/listinfo/python-list > >> > > > > 93 messages in this thread. a handful are earnest attempts to help a > > beginner with what looks like homework. The rest are an odd barrage of > > obsequious please and whining from who knows how many OPs.begging to have > > their source code delivered. > > I've also held this (and one other) email address for moderation. > > TJG > > -- > https://mail.python.org/mailman/listinfo/python-list This thread is so annoying, don't you guys think? At least if it is a homework, one should try to do their best by themselves. While this one, after getting tons of hints, or even the answers itself, is still asking for help. I wonder what is the meaning behind. Cheers, Andrew From steve at pearwood.info Wed Jan 13 10:52:12 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 14 Jan 2016 02:52:12 +1100 Subject: Building list References: Message-ID: <569672ad$0$1589$c3e8da3$5496439d@news.astraweb.com> On Thu, 14 Jan 2016 02:23 am, Eddy Quicksall wrote: > What list do I use for building issues? I'm building 3.5.1. You can ask here. -- Steven From mafagafogigante at gmail.com Wed Jan 13 10:53:40 2016 From: mafagafogigante at gmail.com (Bernardo Sulzbach) Date: Wed, 13 Jan 2016 13:53:40 -0200 Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict In-Reply-To: <5695a86c$0$1588$c3e8da3$5496439d@news.astraweb.com> References: <5695a86c$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jan 12, 2016 at 11:29 PM, Steven D'Aprano wrote: > On Wed, 13 Jan 2016 06:12 am, Bernardo Sulzbach wrote: > >> I saw it in another answer. next(iter(d)) is still the winner. > > Except that doesn't return the *value*, it returns the *key*. > There is a typo, sorry. I assume that what is passed to iter is a dict_values object. >> This resembles a list just too much, making the coder's intent harder >> to understand. This is **very** subjective, of course. > > I'm sorry, I don't understand what you mean by "resembles a list"? What > does? In what way? > [a] = d.values() resembles a list too much to my eyes. -- Bernardo Sulzbach From invalid at invalid.invalid Wed Jan 13 10:58:23 2016 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 13 Jan 2016 15:58:23 +0000 (UTC) Subject: subscripting Python 3 dicts/getting the only value in a Python 3 dict References: <5695a72a$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-01-13, Steven D'Aprano wrote: > Probably the best solution, because it will conveniently raise an exception > if your assumption that the dict has exactly one item is wrong: > > item, = d.values() # Note the comma after "item". [...] > but you can unpack a sequence of one item too. If you really want to make it > obvious that the comma isn't a typo: > > (item,) = d.values() If it were I, I'd definitely do the later. I used to do it the first way, but I often times would not notice the comma later when maintaining the code and end up wasting an embarassing amount of time when what should have been an easy, trivial change broke. -- Grant Edwards grant.b.edwards Yow! It was a JOKE!! at Get it?? I was receiving gmail.com messages from DAVID LETTERMAN!! ! From random832 at fastmail.com Wed Jan 13 11:25:20 2016 From: random832 at fastmail.com (Random832) Date: Wed, 13 Jan 2016 11:25:20 -0500 Subject: Stop writing Python 4 incompatible code In-Reply-To: <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> Message-ID: <1452702320.2982810.491094826.69EA5C7D@webmail.messagingengine.com> On Wed, Jan 13, 2016, at 09:21, sjmsoft at gmail.com wrote: > This strikes me as very good advice. Thanks for being so far-sighted. > And let's hope that Python 4 has fewer incompatibilities (none would > good) than Python 3! Who says there's going to be a Python 4? I always assumed 3.9 would be followed by 3.10. From rustompmody at gmail.com Wed Jan 13 11:33:46 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 13 Jan 2016 08:33:46 -0800 (PST) Subject: When I need classes? In-Reply-To: References: <34aa811c-433d-4f8a-90e0-9dd768460415@googlegroups.com> <5695e025$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4d4de4cb-90c4-4edb-a5ef-ed331f8cfccf@googlegroups.com> Guess you (Rodrigo) wanted to send this to the list? On Wed, Jan 13, 2016 at 8:22 PM, Rodrigo Bistolfi wrote: > Start by using just functions. As you move forward, you will find that > often you are passing the same data structure as first argument to some > functions. At that point, you are already using OOP, and you may want to > formalize that in a class. > HTH On Wednesday, January 13, 2016 at 12:01:29 PM UTC+5:30, Rustom Mody wrote: > On Wednesday, January 13, 2016 at 10:57:23 AM UTC+5:30, Steven D'Aprano wrote: > > On Wednesday 13 January 2016 14:36, Rustom Mody wrote: > > > > > 1. Python the LANGUAGE, is rather even-handed in paradigm choice: Choose > > > OO, imperative, functional or whatever style pleases/suits you > > > 2. Python LIBRARIES however need to make committing choices. Users of > > > those then need to align with these. > > > > I don't think that second one is necessarily correct. Look at the random > > module: it is based on an OOP design, with classes random.Random and > > random.SystemRandom doing the real work. But most people don't use them > > directly, they use the procedural interface random.random, random.choice, > > random.seed etc. > > > > Yes one can have more or less degrees of freedom. Are infinite degrees possible? > I believe not. > > eg My example of re is strictly not correct: can use strings instead of re objects > Can use findall instead of search/match and avoid groping around in opaque match > objects > So you may conclude that the re module allows these degrees of freedom > But you cant bold res all the way into the syntax of the language (eg perl/awk) > > Anyway these are side points > My main point is that when you sit on top of heavy-duty many-layered libraries > (worse frameworks... OP seems to be trying Kivy) then you have to align with > the opinionatedness of all the layers down to python. > > Of course that is modulo the leakiness of the abstractions. > eg mostly python programmers do not need to know the underlying C... > > Mostly... > And then someone asks about id/is/performance... From rosuav at gmail.com Wed Jan 13 11:38:53 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2016 03:38:53 +1100 Subject: Stop writing Python 4 incompatible code In-Reply-To: <1452702320.2982810.491094826.69EA5C7D@webmail.messagingengine.com> References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <1452702320.2982810.491094826.69EA5C7D@webmail.messagingengine.com> Message-ID: On Thu, Jan 14, 2016 at 3:25 AM, Random832 wrote: > On Wed, Jan 13, 2016, at 09:21, sjmsoft at gmail.com wrote: >> This strikes me as very good advice. Thanks for being so far-sighted. >> And let's hope that Python 4 has fewer incompatibilities (none would >> good) than Python 3! > > Who says there's going to be a Python 4? I always assumed 3.9 would be > followed by 3.10. There most likely will be a Python 4.0 at some point. One theory is that 3.9 will be followed by 4.0, which will technically have some backward-incompatible changes (hence it would be inappropriate to call it 3.10), but in practical terms, good Py3.9 code will be identical to good Py4.0 code - it'll just remove things that got deprecated during the 3.x lifecycle. ChrisA From robin at reportlab.com Wed Jan 13 11:40:29 2016 From: robin at reportlab.com (Robin Becker) Date: Wed, 13 Jan 2016 16:40:29 +0000 Subject: How to remove item from heap efficiently? In-Reply-To: References: <568EEC40.7070807@mail.de> <568FE797.6090808@mail.de> <5692A795.3070904@mail.de> <5695276A.2020101@mail.de> <7A7E26D9-01E5-4D77-92B4-3491D86E1EA8@gmail.com> Message-ID: <56967DFD.5090408@chamonix.reportlab.co.uk> On 13/01/2016 15:34, srinivas devaki wrote: > On Wed, Jan 13, 2016 at 4:50 PM, Cem Karan wrote: >> >> Is that so? I'll be honest, I never tested its asymptotic performance, I just assumed that he had a dict coupled with a heap somehow, but I never looked into the code. >> > > I have just tested the code, the aymptotic performance is O(log(n)) > for all operations. Infact the code is very simple to understand, > technically the heapdict class is composed of a dict and heap, each element of > heap is a mutable list and dict stores references to that mutable list, > so that a specific element can be deleted in O(log(n)) > is this true? I looked at https://wiki.python.org/moin/TimeComplexity and it says that dict.get which I assume is used for accessing the heapq delete point can be large (the average time is O(1), but amortized over a lot of accesses can be O(n)). Apparently the history of sets/gets can affect individual times quite a lot. I seem to remember there was some kind of hashing attack against python dicts that would use up large amounts of time, but I guess that's now fixed. -- Robin Becker From rosuav at gmail.com Wed Jan 13 11:54:32 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2016 03:54:32 +1100 Subject: How to remove item from heap efficiently? In-Reply-To: <56967DFD.5090408@chamonix.reportlab.co.uk> References: <568EEC40.7070807@mail.de> <568FE797.6090808@mail.de> <5692A795.3070904@mail.de> <5695276A.2020101@mail.de> <7A7E26D9-01E5-4D77-92B4-3491D86E1EA8@gmail.com> <56967DFD.5090408@chamonix.reportlab.co.uk> Message-ID: On Thu, Jan 14, 2016 at 3:40 AM, Robin Becker wrote: > is this true? I looked at https://wiki.python.org/moin/TimeComplexity and it > says that dict.get which I assume is used for accessing the heapq delete > point can be large (the average time is O(1), but amortized over a lot of > accesses can be O(n)). Apparently the history of sets/gets can affect > individual times quite a lot. I seem to remember there was some kind of > hashing attack against python dicts that would use up large amounts of time, > but I guess that's now fixed. Yes and no. In current CPython versions, the hash attack is made a lot harder by randomizing the hashes of strings; the most obvious attack (sending form data to a web site) is now a lot harder, because you need to figure out what the server process is using as its key. But there are some caveats to it: 1) CPython 2.7 doesn't (I believe) do this by default. You have to set PYTHONHASHSEED=random or pass the -R parameter. 2) This still only affects strings. If you build a dictionary out of integers provided by a potential attacker, the hashes will be consistent. 3) If an attacker can get info from the server in dictionary order, the hash key could be deduced. Since it can't change within one run of a program, this could make attacks possible. So, I wouldn't say it's *fixed*. It's certainly been made a lot less easy to abuse than it originally was. That said, though - even before these fixes, it wasn't something you'd accidentally stumble on. It takes a deliberate attack. ChrisA From katewinslet626 at gmail.com Wed Jan 13 12:21:46 2016 From: katewinslet626 at gmail.com (Shiva Upreti) Date: Wed, 13 Jan 2016 09:21:46 -0800 (PST) Subject: Create notifications in python Message-ID: <88711925-1052-4dc9-ae70-801b2dabb44c@googlegroups.com> I want to create notification box using python just like I get when battery is running low or something similar. I can do it using libnotify in linux, but I cant figure out how to do it in windows. I got some codes on internet for this like: https://gist.github.com/wontoncc/1808234, however it didnt work on windows 10. It showed the notification icon but nothing else happened. I cant understand this code as well. I would like to ask you how to achieve the above, and what should I learn so that I am able to understand what the code above does and learn to write it myself. Please provide learning sources if you can, because I cant understand any of it so I dont even know from where to begin. Any help will be highly appreciated.:) From zeppelina.gf at gmail.com Wed Jan 13 12:38:59 2016 From: zeppelina.gf at gmail.com (=?iso-8859-1?Q?Gert_F=F6rster?=) Date: Wed, 13 Jan 2016 18:38:59 +0100 Subject: issues Message-ID: <000001d14e29$49aaa1c0$dcffe540$@gmail.com> Ladies, Gentlemen, using the PyCharm Community Edition 4.5.4, with Python-3-5-1-amd64.exe, there is constantly a ?Repair?-demand. This is ?successful? when executed. Without execution, there results an ?Error code 1602? error. Please help me? Sincerely Yours, Gert F?rster From srkunze at mail.de Wed Jan 13 14:08:21 2016 From: srkunze at mail.de (Sven R. Kunze) Date: Wed, 13 Jan 2016 20:08:21 +0100 Subject: How to remove item from heap efficiently? In-Reply-To: <7A7E26D9-01E5-4D77-92B4-3491D86E1EA8@gmail.com> References: <568EEC40.7070807@mail.de> <568FE797.6090808@mail.de> <5692A795.3070904@mail.de> <5695276A.2020101@mail.de> <7A7E26D9-01E5-4D77-92B4-3491D86E1EA8@gmail.com> Message-ID: <5696A0A5.8020401@mail.de> On 13.01.2016 12:20, Cem Karan wrote: > On Jan 12, 2016, at 11:18 AM, "Sven R. Kunze" wrote: > >> Thanks for replying here. I've come across these types of wrappers/re-implementations of heapq as well when researching this issue. :) >> >> Unfortunately, they don't solve the underlying issue at hand which is: "remove item from heap with unknown index" and be efficient at it (by not using _heapq C implementation). >> >> >> So, I thought I did another wrapper. ;) It at least uses _heapq (if available otherwise heapq) and lets you remove items without violating the invariant in O(log n). I am going to make that open-source on pypi and see what people think of it. > Is that so? I'll be honest, I never tested its asymptotic performance, I just assumed that he had a dict coupled with a heap somehow, but I never looked into the code. My concern about that specific package is a missing C-implementation. I feel that somewhat defeats the whole purpose of using a heap: performance. Asymptotic performance is still O(log n). > That said, IMHO using a dict interface is the way to go for priority queues; it really simplified my code using it! This is my not-so-subtle way of asking you to adopt the MutableMapping interface for your wrapper ;) Could you elaborate on this? What simplified you code so much? I have been using heaps for priority queues as well but haven't missed the dict interface so far. Maybe, my use-case is different. Best, Sven From cfernandez16 at franklinvillecsd.org Wed Jan 13 15:42:52 2016 From: cfernandez16 at franklinvillecsd.org (Crystal Fernandez) Date: Wed, 13 Jan 2016 15:42:52 -0500 Subject: i am having troubles downloading 3.5.1 to my computer Message-ID: NLT+CRF <3 From lac at openend.se Wed Jan 13 15:47:43 2016 From: lac at openend.se (Laura Creighton) Date: Wed, 13 Jan 2016 21:47:43 +0100 Subject: me, my arm, my availability ... Message-ID: <201601132047.u0DKlhIc025984@theraft.openend.se> I fell recently. Ought to be nothing, but a small chip of bone, either an existing one or one I just made is nicely wedged in the joint taking away a whole lot of the ability of my arm to rotate in the elbow joint. Or hold my arm in a position that is usual for typing. Plus, now that the sprain/swelling is more or less over, the pain, unfortunately is not. The real downside is that my typing speed is down from 135-140 wpm to 5-10 wmp. At this rate, just getting my usual work done takes overtime. Seems like surgery is needed to fix this. So I wanted you all to know, no, I haven't forgotten you and no haven't stopped caring. I have just stopped being as __capable__ if you know what I mean. Please take care of yourselves and each other. I will often be reading even if typing is more than I can do right now. Laura ps -- (recent tutor discussion) I am with Alan and not with Mark. I am happy as anything when people post their not-quite-working code for homework assignments here to tutor. They aren't lazy bastards wanting somebody to do their assignments for them, they want to learn why what they are trying to do isn't working. Sounds perfect for tutor to me. From greg.ewing at canterbury.ac.nz Wed Jan 13 16:38:57 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 14 Jan 2016 10:38:57 +1300 Subject: Stop writing Python 4 incompatible code In-Reply-To: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Quote: > > if six.PY2: > # Python 2 code > elif six.PY3: > # Python 3 code > > In this case, no code will get executed on Python 4 at all! Which is good, because if no code is executed, it can't exhibit any bugs. Everyone should write their code this way, and then Python 4 will make *all* bugs in *all* programs disappear! -- Greg From DLipman~NoSpam~ at Verizon.Net Wed Jan 13 16:41:57 2016 From: DLipman~NoSpam~ at Verizon.Net (David H. Lipman) Date: Wed, 13 Jan 2016 16:41:57 -0500 Subject: me, my arm, my availability ... In-Reply-To: References: Message-ID: From: "Laura Creighton" > > I fell recently. Ought to be nothing, but a small chip of bone, either an Due to the side-effects of the prescription drugs you were given, I suggest you not use a computer until you are no longer taking them. ;-) -- Dave Multi-AV Scanning Tool - http://multi-av.thespykiller.co.uk http://www.pctipp.ch/downloads/dl/35905.asp From mafagafogigante at gmail.com Wed Jan 13 16:46:20 2016 From: mafagafogigante at gmail.com (Bernardo Sulzbach) Date: Wed, 13 Jan 2016 19:46:20 -0200 Subject: Stop writing Python 4 incompatible code In-Reply-To: References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> Message-ID: On Wed, Jan 13, 2016 at 7:38 PM, Gregory Ewing wrote: > Steven D'Aprano wrote: >> >> Quote: >> >> if six.PY2: >> # Python 2 code >> elif six.PY3: >> # Python 3 code >> >> In this case, no code will get executed on Python 4 at all! > > > Which is good, because if no code is executed, it can't exhibit > any bugs. > > Everyone should write their code this way, and then Python 4 > will make *all* bugs in *all* programs disappear! > And if that is not enough, imagine how faster all tasks will finish. -- Bernardo Sulzbach From lac at openend.se Wed Jan 13 17:26:27 2016 From: lac at openend.se (Laura Creighton) Date: Wed, 13 Jan 2016 23:26:27 +0100 Subject: me, my arm, my availability ... In-Reply-To: References: Message-ID: <201601132226.u0DMQRFw018708@theraft.openend.se> In a message of Wed, 13 Jan 2016 16:41:57 -0500, "David H. Lipman" writes: >From: "Laura Creighton" > >> >> I fell recently. Ought to be nothing, but a small chip of bone, either an > >Due to the side-effects of the prescription drugs you were given, I suggest >you not use a computer until you are no longer taking them. ;-) God, this is going to make playing games on my android tablet a problem. And there _was_ a time when under drugs, killing monsters was about all I was good for ... Thank you for cheering me up, some. Nice community this. :) Laura >Dave >Multi-AV Scanning Tool - http://multi-av.thespykiller.co.uk >http://www.pctipp.ch/downloads/dl/35905.asp From tjreedy at udel.edu Wed Jan 13 18:36:09 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jan 2016 18:36:09 -0500 Subject: Building list In-Reply-To: <000601d14e16$5002e8b0$f008ba10$@com> References: <000601d14e16$5002e8b0$f008ba10$@com> Message-ID: On 1/13/2016 10:23 AM, Eddy Quicksall wrote: > What list do I use for building issues? I'm building 3.5.1. Start here. -- Terry Jan Reedy From steve at pearwood.info Wed Jan 13 19:10:36 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 14 Jan 2016 11:10:36 +1100 Subject: Stop writing Python 4 incompatible code References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> Message-ID: <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> On Thu, 14 Jan 2016 03:25 am, Random832 wrote: > On Wed, Jan 13, 2016, at 09:21, sjmsoft at gmail.com wrote: >> This strikes me as very good advice. Thanks for being so far-sighted. >> And let's hope that Python 4 has fewer incompatibilities (none would >> good) than Python 3! > > Who says there's going to be a Python 4? I always assumed 3.9 would be > followed by 3.10. Guido has a *very* strong dislike for two digit minor version numbers. It took a fair amount of arm-twisting to get him to accept two digit micro version numbers, like 2.7.10. It is doubtful that we'll see 3.10. But he has definitely ruled that 4.0 (assuming there is one) will not be a major backwards-incompatible version like 3.0 was. That's not to say that there won't be any backwards incompatibilities at all, but they will be relatively minor, like the change from 2.5 to 2.6. (I bet most people don't even know that 2.6 broke backwards-compatibility.) -- Steven From ian.g.kelly at gmail.com Wed Jan 13 19:17:42 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Jan 2016 17:17:42 -0700 Subject: [Python-ideas] Password masking for getpass.getpass In-Reply-To: References: <20160113015414.GF10854@ando.pearwood.info> <20160113021746.GA26480@phdru.name> <20160113100442.GI10854@ando.pearwood.info> Message-ID: On Wed, Jan 13, 2016 at 3:19 AM, Chris Angelico wrote: > You're quite probably right that obfuscating the display is security > theatre; but it's the security theatre that people are expecting. If > you're about to enter your credit card details into a web form, does > it really matter whether or not the form itself was downloaded over an > encrypted link? But people are used to "look for the padlock", which > means that NOT having the padlock will bother people. If you ask for a > password and it gets displayed, people will wonder if they're entering > it in the right place. I realize that I'm taking this thread off-topic, but yes it's important that the form itself be downloaded over a secure connection. If I can MitM the form response over an insecure connection, then I can also MitM the form itself. And if I can do that, then I can deliver exactly the form you were expecting, but with an added script that will read your credit card number as you type it and then fire it off to be stored on my server before you've even hit the Submit button. From rosuav at gmail.com Wed Jan 13 19:27:21 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2016 11:27:21 +1100 Subject: [Python-ideas] Password masking for getpass.getpass In-Reply-To: References: <20160113015414.GF10854@ando.pearwood.info> <20160113021746.GA26480@phdru.name> <20160113100442.GI10854@ando.pearwood.info> Message-ID: On Thu, Jan 14, 2016 at 11:17 AM, Ian Kelly wrote: > On Wed, Jan 13, 2016 at 3:19 AM, Chris Angelico wrote: >> You're quite probably right that obfuscating the display is security >> theatre; but it's the security theatre that people are expecting. If >> you're about to enter your credit card details into a web form, does >> it really matter whether or not the form itself was downloaded over an >> encrypted link? But people are used to "look for the padlock", which >> means that NOT having the padlock will bother people. If you ask for a >> password and it gets displayed, people will wonder if they're entering >> it in the right place. > > I realize that I'm taking this thread off-topic, but yes it's > important that the form itself be downloaded over a secure connection. > If I can MitM the form response over an insecure connection, then I > can also MitM the form itself. And if I can do that, then I can > deliver exactly the form you were expecting, but with an added script > that will read your credit card number as you type it and then fire it > off to be stored on my server before you've even hit the Submit > button. Noscript FTW. :) ChrisA From steve at pearwood.info Wed Jan 13 19:27:41 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 14 Jan 2016 11:27:41 +1100 Subject: me, my arm, my availability ... References: Message-ID: <5696eb7f$0$1601$c3e8da3$5496439d@news.astraweb.com> On Thu, 14 Jan 2016 07:47 am, Laura Creighton wrote: > > I fell recently. Ought to be nothing, [...] Ouch! Much ouch! Hope you get well soon Laura! My best wishes and sympathies to you! -- Steven From steve at pearwood.info Wed Jan 13 19:30:36 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 14 Jan 2016 11:30:36 +1100 Subject: me, my arm, my availability ... References: Message-ID: <5696ec2d$0$1601$c3e8da3$5496439d@news.astraweb.com> On Thu, 14 Jan 2016 08:41 am, David H. Lipman wrote: > From: "Laura Creighton" > >> >> I fell recently. Ought to be nothing, but a small chip of bone, either >> an > > Due to the side-effects of the prescription drugs you were given, I > suggest > you not use a computer until you are no longer taking them. ;-) I don't get it. Are you implying that Laura's comments were drug-addled nonsense? They make perfect sense to me, and seem to be grammatically correct for informal English (apart from a missing comma), and quite idiomatic too. And I'm not taking any drugs. I know that there's a trope of affectionately mocking people on strong pain-killers ("I want some of the drugs she's having!"), but it's normal to wait until *after* they've actually demonstrated impairment. Otherwise you risk having the response which I'm having right now: "I don't think it's Laura who is high on drugs, prescription or otherwise, but you!" :-) Seriously, sorry for being That Guy who asks you to analyse what I expect is meant as a joke, but I have no idea where the humour is. -- Steven From steve at pearwood.info Wed Jan 13 19:33:18 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 14 Jan 2016 11:33:18 +1100 Subject: [Python-ideas] Password masking for getpass.getpass References: <20160113015414.GF10854@ando.pearwood.info> <20160113021746.GA26480@phdru.name> <20160113100442.GI10854@ando.pearwood.info> Message-ID: <5696ecd0$0$1620$c3e8da3$5496439d@news.astraweb.com> On Thu, 14 Jan 2016 11:17 am, Ian Kelly wrote: > On Wed, Jan 13, 2016 at 3:19 AM, Chris Angelico wrote: >> You're quite probably right that obfuscating the display is security >> theatre; but it's the security theatre that people are expecting. If >> you're about to enter your credit card details into a web form, does >> it really matter whether or not the form itself was downloaded over an >> encrypted link? But people are used to "look for the padlock", which >> means that NOT having the padlock will bother people. If you ask for a >> password and it gets displayed, people will wonder if they're entering >> it in the right place. > > I realize that I'm taking this thread off-topic, but yes it's > important that the form itself be downloaded over a secure connection. Not just off-topic, but off-list. You appear to have replied to the wrong mailing list :-) > If I can MitM the form response over an insecure connection, then I > can also MitM the form itself. And if I can do that, then I can > deliver exactly the form you were expecting, but with an added script > that will read your credit card number as you type it and then fire it > off to be stored on my server before you've even hit the Submit > button. -- Steven From mafagafogigante at gmail.com Wed Jan 13 19:40:35 2016 From: mafagafogigante at gmail.com (Bernardo Sulzbach) Date: Wed, 13 Jan 2016 22:40:35 -0200 Subject: Stop writing Python 4 incompatible code In-Reply-To: <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jan 13, 2016 at 10:10 PM, Steven D'Aprano wrote: > (...) 4.0 (assuming there is one) Isn't it just a matter of time? Do you think it is even possible not to have Python 4 eventually? -- Bernardo Sulzbach From steve at pearwood.info Wed Jan 13 19:47:37 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 14 Jan 2016 11:47:37 +1100 Subject: [Python-ideas] Password masking for getpass.getpass References: <20160113015414.GF10854@ando.pearwood.info> <20160113021746.GA26480@phdru.name> <20160113100442.GI10854@ando.pearwood.info> Message-ID: <5696f02b$0$1611$c3e8da3$5496439d@news.astraweb.com> On Thu, 14 Jan 2016 11:27 am, Chris Angelico wrote: > On Thu, Jan 14, 2016 at 11:17 AM, Ian Kelly wrote: >> I realize that I'm taking this thread off-topic, but yes it's >> important that the form itself be downloaded over a secure connection. >> If I can MitM the form response over an insecure connection, then I >> can also MitM the form itself. And if I can do that, then I can >> deliver exactly the form you were expecting, but with an added script >> that will read your credit card number as you type it and then fire it >> off to be stored on my server before you've even hit the Submit >> button. > > Noscript FTW. > > :) What of the poor souls who, for whatever reason, can't use NoScript? What about those who are so frustrated with trying to get sites to work that they just Allow All On This Page? I've seen websites that rely on anything up to forty or fifty externally hosted scripts just to get basic functionality. (I stopped counting after a while and just kept clicking "Temporarily Allow...") You have external scripts calling out to external scripts from completely different domains, each more and more dodgy-looking than the last. And that's just the "legitimate" (for some definition of) scripts. -- Steven From jfong at ms4.hinet.net Wed Jan 13 19:48:42 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Wed, 13 Jan 2016 16:48:42 -0800 (PST) Subject: Which Python editor has this feature? In-Reply-To: References: <830f6f97-22dd-488c-9dd6-e9cd92844307@googlegroups.com> <5f1619e5-83ff-449e-b7e5-2374a37bd50b@googlegroups.com> Message-ID: <25f77bd2-9665-4119-a1e2-ad3745fc6280@googlegroups.com> Terry Reedy at 2016/1/13 UTC+8 5:15:20PM wrote: > This was a Windows specific problem that was fixed (for me) in all three > recent (last November/December) bugfix releases. If you have a problem > with *current* IDLE, I would like to know. I download/install the latest version 3.4.4 and it works perfectly. It surprise me that how Python society is so active. I had version 3.4.3 installed 4 months ago and now this problem had already been taken care of:-) Thank you. --Jach Fong From tjreedy at udel.edu Wed Jan 13 19:53:35 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jan 2016 19:53:35 -0500 Subject: Stop writing Python 4 incompatible code In-Reply-To: <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/13/2016 7:10 PM, Steven D'Aprano wrote: > On Thu, 14 Jan 2016 03:25 am, Random832 wrote: > >> On Wed, Jan 13, 2016, at 09:21, sjmsoft at gmail.com wrote: >>> This strikes me as very good advice. Thanks for being so far-sighted. >>> And let's hope that Python 4 has fewer incompatibilities (none would >>> good) than Python 3! >> >> Who says there's going to be a Python 4? I always assumed 3.9 would be >> followed by 3.10. > > > Guido has a *very* strong dislike for two digit minor version numbers. It > took a fair amount of arm-twisting to get him to accept two digit micro > version numbers, like 2.7.10. It is doubtful that we'll see 3.10. > > But he has definitely ruled that 4.0 (assuming there is one) will not be a > major backwards-incompatible version like 3.0 was. > > That's not to say that there won't be any backwards incompatibilities at > all, but they will be relatively minor, like the change from 2.5 to 2.6. (I > bet most people don't even know that 2.6 broke backwards-compatibility.) There are a number of deprecations that will not be turned into removals while 2.7 remains on support but which probably will be removed after, and after they have been giving DeprecationWarnings for at least 2 3.x releases. So code that does not have deprecated features will not be affected. This should be after 3.8. If removals happen in a release that would be '3.9', I expect that it would be '4.0' instead. (But there is no definite plan and will not be until the time comes. -- Terry Jan Reedy From torriem at gmail.com Wed Jan 13 19:59:06 2016 From: torriem at gmail.com (Michael Torrie) Date: Wed, 13 Jan 2016 17:59:06 -0700 Subject: [Python-ideas] Password masking for getpass.getpass In-Reply-To: <5696f02b$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <20160113015414.GF10854@ando.pearwood.info> <20160113021746.GA26480@phdru.name> <20160113100442.GI10854@ando.pearwood.info> <5696f02b$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5696F2DA.5020701@gmail.com> On 01/13/2016 05:47 PM, Steven D'Aprano wrote: > What of the poor souls who, for whatever reason, can't use NoScript? > > What about those who are so frustrated with trying to get sites to work that > they just Allow All On This Page? I've seen websites that rely on anything > up to forty or fifty externally hosted scripts just to get basic > functionality. (I stopped counting after a while and just kept > clicking "Temporarily Allow...") You have external scripts calling out to > external scripts from completely different domains, each more and more > dodgy-looking than the last. And that's just the "legitimate" (for some > definition of) scripts. I seriously doubt there are any web pages that rely on 40 or 50 external scripts for *basic* functionality. But I have seen pages that load dozens of external scripts for tracking, ad, and other purposes. With Ghostery I disable almost all of them and guess what, the pages load faster and work just fine. I think some companies must think, hey if one analytics site is good, then 10 are better! I've seen pages that refused to load because some analytic script's hosting server was not responding. I highly recommend everyone run Ghostery and turn off nearly all external scripts. Doesn't usually affect the page's function itself. If anything it's educational to see how many external scripts sites use these days. No wonder we have so many security issues. From bc at freeuk.com Wed Jan 13 20:02:08 2016 From: bc at freeuk.com (BartC) Date: Thu, 14 Jan 2016 01:02:08 +0000 Subject: Stop writing Python 4 incompatible code In-Reply-To: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> Message-ID: On 13/01/2016 07:30, Steven D'Aprano wrote: > Quote: > > With the end of support for Python 2 on the horizon (in 2020), > many package developers have made their packages compatible > with both Python 2 and Python 3 by using constructs such as: > > if sys.version_info[0] == 2: > # Python 2 code > else: > # Python 3 code > Better still, don't do version checks *at all*. There is almost never any > need for a version check. Better is to use feature detection: > > > try: > xrange # Succeeds in Python 2. > except NameError: > xrange = range I was surprised recently by just how much incompatibility there was between Python 2 and 3. It wasn't just about print with parentheses and range instead of xrange. I wanted to try out a jpeg decoder with PyPy and the three different ones I could find only worked with 2.x. Attempts to fix the incompatibilities usually lead to deeper mire. In the end it was easier to put together my own version, which ran on all Pythons (2.7 to 3.4). It was surprisingly easy to do; no need for conditional version code. (It was also smaller and considerably faster than the others even before I went tried PyPy. Using range in 2.7 instead of xrange didn't make much difference either.) -- Bartc From rantingrickjohnson at gmail.com Wed Jan 13 20:02:52 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 13 Jan 2016 17:02:52 -0800 (PST) Subject: Stop writing Python 4 incompatible code In-Reply-To: <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> On Wednesday, January 13, 2016 at 6:11:06 PM UTC-6, Steven D'Aprano wrote: > But [GvR] has definitely ruled that 4.0 (assuming there is > one) will not be a major backwards-incompatible version > like 3.0 was. Well for the sake of Python's future, let's all hope so! I typically don't give much weight to the statements of sycophants, but i really do hope your assessment of GvR's intentions is correct, because it would indicate that "old hubris" has *FINALLY* come to realize what many of us feared all along -- that Python3 was going to do more damage than good! In fact, in the years before Python3 arrived, it had enjoyed a steady ascension from obscurity into mainstream hacker culture, but now, all that remains is a fractured community, a fractured code base, and a leader who lost his cushy job at Google -- of which i think Python3 is directly responsible. Think about it: if they hired him *BECAUSE* of Python's success then we can *ONLY* conclude they fired him for mismanaging it. Folks, our future is in peril, but one thing is guaranteed, if the introduction of Python4 is *anything* like the introduction of Python3, well, then, it's curtains for Python. *CURTAINS*!!! From steve at pearwood.info Wed Jan 13 20:02:59 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 14 Jan 2016 12:02:59 +1100 Subject: Stop writing Python 4 incompatible code References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5696f3c6$0$1583$c3e8da3$5496439d@news.astraweb.com> On Thu, 14 Jan 2016 11:40 am, Bernardo Sulzbach wrote: > On Wed, Jan 13, 2016 at 10:10 PM, Steven D'Aprano > wrote: >> (...) 4.0 (assuming there is one) > > Isn't it just a matter of time? Do you think it is even possible not > to have Python 4 eventually? 3.9 is probably five or six years away. Perhaps more. A lot can happen in five years. Just ask Syria. Maybe Guido will change his mind and we'll have 3.10. 3.11, 3.12, ... Maybe there will be a sudden and rapid collapse in popularity of Python between 3.7 and 3.8, and the language is mostly abandoned. Maybe by the time we approach 3.9, our new xenophobic and fascist overlords will roll back the internet and ban all that "communist" open source software, especially those written by foreigners (Dutch or otherwise -- Ruby will be banned too). Or we're too busy dealing with rising sea levels, crop failures, antibiotic resistant diseases, chaotic mass migrations, terrorists, wars for control over resources like water, and the collapse of the corporate state to care about such little things as upgrades to programming languages. Or the AI singularity arrives and "human programmer" becomes as obsolete as "flint knapper". Or we'll be hit by a big rock from space. Who knows? -- Steven From rosuav at gmail.com Wed Jan 13 20:21:23 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2016 12:21:23 +1100 Subject: Stop writing Python 4 incompatible code In-Reply-To: References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> Message-ID: On Thu, Jan 14, 2016 at 12:02 PM, BartC wrote: > I was surprised recently by just how much incompatibility there was between > Python 2 and 3. It wasn't just about print with parentheses and range > instead of xrange. > > I wanted to try out a jpeg decoder with PyPy and the three different ones I > could find only worked with 2.x. Attempts to fix the incompatibilities > usually lead to deeper mire. This implies that there are many differences between 2.x and 3.x. > In the end it was easier to put together my own version, which ran on all > Pythons (2.7 to 3.4). It was surprisingly easy to do; no need for > conditional version code. But this implies that the differences are pretty simple. Which argument are you putting? The biggest difference between 2.x and 3.x is the handling of text vs bytes. This is a very important distinction, but for a lot of programs, it's not difficult; most of what you'll be using will be text, and the only difference is that the 3.x version of your program can handle all of Unicode. If you open any files, you might need to specify encoding="utf-8" or encoding="ascii" or something, but that's about the only issue. > (It was also smaller and considerably faster than the others even before I > went tried PyPy. Using range in 2.7 instead of xrange didn't make much > difference either.) Yeah, the effectiveness of xrange over range isn't significant on smallish lists. And PyPy can optimize all sorts of things. If I'm writing 2/3 compatible code, I'll usually just use range() everywhere, unless I know for sure that the lists are going to be huge. ChrisA From torriem at gmail.com Wed Jan 13 20:24:51 2016 From: torriem at gmail.com (Michael Torrie) Date: Wed, 13 Jan 2016 18:24:51 -0700 Subject: Stop writing Python 4 incompatible code In-Reply-To: <5696f3c6$0$1583$c3e8da3$5496439d@news.astraweb.com> References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5696f3c6$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5696F8E3.3030205@gmail.com> On 01/13/2016 06:02 PM, Steven D'Aprano wrote: > Or we're too busy dealing with rising sea levels, crop failures, antibiotic > resistant diseases, chaotic mass migrations, terrorists, wars for control > over resources like water, and the collapse of the corporate state to care > about such little things as upgrades to programming languages. > > Or the AI singularity arrives and "human programmer" becomes as obsolete > as "flint knapper". Most likely, given your apocalyptic scenarios, flintknapping will become an essential skill again! From rosuav at gmail.com Wed Jan 13 20:29:09 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2016 12:29:09 +1100 Subject: Stop writing Python 4 incompatible code In-Reply-To: <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> Message-ID: On Thu, Jan 14, 2016 at 12:02 PM, Rick Johnson wrote: > In fact, in the years before Python3 arrived, it had enjoyed > a steady ascension from obscurity into mainstream hacker > culture, but now, all that remains is a fractured community, > a fractured code base, and a leader who lost his cushy job > at Google -- of which i think Python3 is directly > responsible. Think about it: if they hired him *BECAUSE* of > Python's success then we can *ONLY* conclude they fired him > for mismanaging it. > I got hired by my last boss because he wanted some software written. I'm no longer employed there. Think about it: if he hired me *BECAUSE* of software's success, we can ONLY conclude that I mismanaged the very concept of software. Watch out, folks; software is about to become the next dead thing! ChrisA From bc at freeuk.com Wed Jan 13 20:49:48 2016 From: bc at freeuk.com (BartC) Date: Thu, 14 Jan 2016 01:49:48 +0000 Subject: Stop writing Python 4 incompatible code In-Reply-To: References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> Message-ID: On 14/01/2016 01:21, Chris Angelico wrote: > On Thu, Jan 14, 2016 at 12:02 PM, BartC wrote: >> I was surprised recently by just how much incompatibility there was between >> Python 2 and 3. It wasn't just about print with parentheses and range >> instead of xrange. >> >> I wanted to try out a jpeg decoder with PyPy and the three different ones I >> could find only worked with 2.x. Attempts to fix the incompatibilities >> usually lead to deeper mire. > > This implies that there are many differences between 2.x and 3.x. > >> In the end it was easier to put together my own version, which ran on all >> Pythons (2.7 to 3.4). It was surprisingly easy to do; no need for >> conditional version code. > > But this implies that the differences are pretty simple. Which > argument are you putting? That they are plenty of differences but I was adept at avoiding them! They didn't come up in my 700-line module anyway, except for the use of 'bytearray' which required upgrading from 2.5 to 2.7. (I needws to make use of bytearrays otherwise it could run out of memory on large inputs.) -- Bartc From torriem at gmail.com Wed Jan 13 21:11:17 2016 From: torriem at gmail.com (Michael Torrie) Date: Wed, 13 Jan 2016 19:11:17 -0700 Subject: Stop writing Python 4 incompatible code In-Reply-To: <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> Message-ID: <569703C5.50509@gmail.com> On 01/13/2016 06:02 PM, Rick Johnson wrote: > In fact, in the years before Python3 arrived, it had enjoyed > a steady ascension from obscurity into mainstream hacker > culture, but now, all that remains is a fractured community, > a fractured code base, and a leader who lost his cushy job > at Google -- of which i think Python3 is directly > responsible. Think about it: if they hired him *BECAUSE* of > Python's success then we can *ONLY* conclude they fired him > for mismanaging it. Hmm, so Guido moved to Dropbox because Google fired him? Interesting revisionist history there. I can find zero evidence to support your assertion, so we can *ONLY* conclude that you are making stuff up. Dishonesty is a harsh accusation, but when one makes up stuff to support one's argument, is that not lying? Besides that, people leave good jobs all the time for other more challenging jobs. Who says it was cushy? Cushy because Google paid him to work on Python? Sounds like the move to Dropbox suited him just fine and he and Python are both doing well. I'm sure there were contributing factors to his decision to leave Google, like Google's NIH syndrome (golang, dart, etc). Things happen. From joel.goldstick at gmail.com Wed Jan 13 21:21:39 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 13 Jan 2016 21:21:39 -0500 Subject: me, my arm, my availability ... In-Reply-To: <5696ec2d$0$1601$c3e8da3$5496439d@news.astraweb.com> References: <5696ec2d$0$1601$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jan 13, 2016 at 7:30 PM, Steven D'Aprano wrote: > On Thu, 14 Jan 2016 08:41 am, David H. Lipman wrote: > > > From: "Laura Creighton" > > > >> > >> I fell recently. Ought to be nothing, but a small chip of bone, either > >> an > > > > Due to the side-effects of the prescription drugs you were given, I > > suggest > > you not use a computer until you are no longer taking them. ;-) > > > I don't get it. Are you implying that Laura's comments were drug-addled > nonsense? They make perfect sense to me, and seem to be grammatically > correct for informal English (apart from a missing comma), and quite > idiomatic too. And I'm not taking any drugs. > > I know that there's a trope of affectionately mocking people on strong > pain-killers ("I want some of the drugs she's having!"), but it's normal to > wait until *after* they've actually demonstrated impairment. Otherwise you > risk having the response which I'm having right now: > > "I don't think it's Laura who is high on drugs, prescription > or otherwise, but you!" > > :-) > > > Seriously, sorry for being That Guy who asks you to analyse what I expect > is > meant as a joke, but I have no idea where the humour is. > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list > I enjoy Laura. Excellent advice, informed.. wishing her injury heels soon. A great asset to the python interested community -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From rantingrickjohnson at gmail.com Wed Jan 13 21:51:28 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 13 Jan 2016 18:51:28 -0800 (PST) Subject: Stop writing Python 4 incompatible code In-Reply-To: References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> Message-ID: <6e0f3ba0-750d-4f57-afcc-238b85779948@googlegroups.com> On Wednesday, January 13, 2016 at 8:11:40 PM UTC-6, Michael Torrie wrote: > Hmm, so Guido moved to Dropbox because Google fired him? > [...] I can find zero evidence to support your assertion, Feel free to post evidence that will *DISPROVE* my statement. > Dishonesty is a harsh accusation, but when one makes up > stuff to support one's argument, is that not lying? You cannot accuse me of lying until you provide *PROOF* that i am lying. But even if you offered proof, that GvR was not fired because of Python's downward spiral, your implication that an "assertion" is "a lie" is in itself dishonest (yes?). And your interpretation of my statement "as malicious" does speak volumes to your true feelings on the subject. Why do you feel *SO* compelled to speak on behalf of GvR? And furthermore, what gives you the right to speak on his behalf? > Besides that, people leave good jobs all the time for > other more challenging jobs. Who says it was cushy? Cushy > because Google paid him to work on Python? Getting paid to work on Pyhton 20% of the time is a pretty damn cushy job Micheal! How much time does *YOUR* employer pay *YOU* to work on "side projects"? > Sounds like the move to Dropbox suited him just fine Sounds like conjecture to me. What evidence do you have that will support your position? I provided the evidence that lead me to my conclusion, sure, you may not agree, but at least i provided more than just denial. From gheskett at wdtv.com Wed Jan 13 21:59:25 2016 From: gheskett at wdtv.com (Gene Heskett) Date: Wed, 13 Jan 2016 21:59:25 -0500 Subject: Stop writing Python 4 incompatible code In-Reply-To: <4h2e9bljgqk65dkh5kr0bq8od5m041207d@4ax.com> References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <5696f3c6$0$1583$c3e8da3$5496439d@news.astraweb.com> <4h2e9bljgqk65dkh5kr0bq8od5m041207d@4ax.com> Message-ID: <201601132159.25126.gheskett@wdtv.com> On Wednesday 13 January 2016 21:39:12 Dennis Lee Bieber wrote: > On Thu, 14 Jan 2016 12:02:59 +1100, Steven D'Aprano > > > declaimed the following: > >On Thu, 14 Jan 2016 11:40 am, Bernardo Sulzbach wrote: > >> On Wed, Jan 13, 2016 at 10:10 PM, Steven D'Aprano > >> > >> > >> wrote: > >>> (...) 4.0 (assuming there is one) > >> > >> Isn't it just a matter of time? Do you think it is even possible > >> not to have Python 4 eventually? > > > >3.9 is probably five or six years away. Perhaps more. A lot can > > happen in five years. Just ask Syria. > > > >Maybe Guido will change his mind and we'll have 3.10. 3.11, 3.12, ... > > 3.14.15926... Apple, Blueberry or Peach? Preferably ala-mode. Must....... Learn.......... To........ Resist. I am a DM-II victim. :( > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ 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 rosuav at gmail.com Wed Jan 13 22:08:23 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2016 14:08:23 +1100 Subject: Stop writing Python 4 incompatible code In-Reply-To: <6e0f3ba0-750d-4f57-afcc-238b85779948@googlegroups.com> References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> <6e0f3ba0-750d-4f57-afcc-238b85779948@googlegroups.com> Message-ID: On Thu, Jan 14, 2016 at 1:51 PM, Rick Johnson wrote: > On Wednesday, January 13, 2016 at 8:11:40 PM UTC-6, Michael Torrie wrote: >> Hmm, so Guido moved to Dropbox because Google fired him? >> [...] I can find zero evidence to support your assertion, > > Feel free to post evidence that will *DISPROVE* my statement. > >> Dishonesty is a harsh accusation, but when one makes up >> stuff to support one's argument, is that not lying? > > You cannot accuse me of lying until you provide *PROOF* that > i am lying. That's not how it goes. You provided assertions; you should provide at least some sort of supporting evidence. > But even if you offered proof, that GvR was not > fired because of Python's downward spiral, your implication > that an "assertion" is "a lie" is in itself dishonest > (yes?). And your interpretation of my statement "as > malicious" does speak volumes to your true feelings on the > subject. Why do you feel *SO* compelled to speak on behalf > of GvR? And furthermore, what gives you the right to speak on > his behalf? You're talking about a very serious matter between two legal entities - if someone was *fired* because of social, technological, or other problems with Python, that has implications that could matter in a court of law. So I put it right back to you: What gives you the right to speak against Guido and Google? >> Besides that, people leave good jobs all the time for >> other more challenging jobs. Who says it was cushy? Cushy >> because Google paid him to work on Python? > > Getting paid to work on Pyhton 20% of the time is a pretty > damn cushy job Micheal! How much time does *YOUR* employer > pay *YOU* to work on "side projects"? It's hardly a side project if it's creating something of immense value to the company. And Google is still getting immense value from Python even now that they're not paying Guido's salary. And Michael's right: people move around for all sorts of reasons. Doesn't necessarily mean anything about the previous job. ChrisA From rantingrickjohnson at gmail.com Wed Jan 13 22:29:44 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 13 Jan 2016 19:29:44 -0800 (PST) Subject: Stop writing Python 4 incompatible code In-Reply-To: References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> <6e0f3ba0-750d-4f57-afcc-238b85779948@googlegroups.com> Message-ID: On Wednesday, January 13, 2016 at 9:08:40 PM UTC-6, Chris Angelico wrote: > You're talking about a very serious matter between two legal entities > - if someone was *fired* because of social, technological, or other > problems with Python, that has implications that could matter in a > court of law. So I put it right back to you: What gives you the right > to speak against Guido and Google? I'm not speaking *AGAINST* anyone, i'm merely trying to understand what happened. And unless there was some sort of explicit contract, Google could fire *ANYONE* for *ANY* reason -- this is not France, Chris! > And Michael's right: people move around for all sorts of reasons. > Doesn't necessarily mean anything about the previous job. Of course. But when you leave things open for speculation, you enviably create a situation where rumors can start circulating. GvR is not just any "John Doe" engineer, no, he's the head of an open source community, and the community has a right to be concerned about the livelihood and well being of their leader. Not because we need something to gossip about whilst watching reruns of Monty Python, but because we need to know if Python is going to be viable into the foreseeable future. More specifically, we need to know if we're writing code in a language that is heading back to the obscurity from wench it came. We have a *RIGHT* to be worried Chris, because our livelihoods are directly dependent on Python. From michal.nalevanko at gmail.com Wed Jan 13 23:03:31 2016 From: michal.nalevanko at gmail.com (Michal Nalevanko) Date: Thu, 14 Jan 2016 05:03:31 +0100 Subject: Strange behavior Message-ID: Hello, I've just installed Python 3.5.1 on my computer and came across somewhat strange behavior. This is a snapshot of a short code that I wrote: https://goo.gl/izYbD0 Quite simple, you might say. Obviously, the program should create a new text file, nothing else. But do you see the numbers it had added to the output? Is this behavior normal or am I overlooking something? Thank you very much for your help. Michal, Slovakia From torriem at gmail.com Thu Jan 14 00:18:46 2016 From: torriem at gmail.com (Michael Torrie) Date: Wed, 13 Jan 2016 22:18:46 -0700 Subject: Stop writing Python 4 incompatible code In-Reply-To: References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> <6e0f3ba0-750d-4f57-afcc-238b85779948@googlegroups.com> Message-ID: <56972FB6.10601@gmail.com> On 01/13/2016 08:29 PM, Rick Johnson wrote: > Of course. But when you leave things open for speculation, > you enviably create a situation where rumors can start > circulating. GvR is not just any "John Doe" engineer, no, > he's the head of an open source community, and the community > has a right to be concerned about the livelihood and well > being of their leader. The only one speculating is you. Everything I've read points to this idea of yours about GvR and Google being untrue. You have presented no evidence for your accusation, so given the evidence I have seen that contradicts you, I must conclude that you made it. That's the part I take issue with and why I stopped to feed the troll, much to the chagrin of everyone else. > We have a *RIGHT* to be worried Chris, because our livelihoods are > directly dependent on Python. I don't know who the "we" you're talking about is, but if your livelihood depends on Python's existence and development in a certain direction, then I suggest you hire GvR--that's what Dropbox did and they don't seem too worried about Python's future. Python's doing just fine, but you should be able to adapt to any programming language suitable for your job at hand. From tjreedy at udel.edu Thu Jan 14 00:45:57 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Jan 2016 00:45:57 -0500 Subject: Stop writing Python 4 incompatible code In-Reply-To: <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> Message-ID: On 1/13/2016 8:02 PM, Rick Johnson wrote: > and a leader who lost his cushy job at Google Unless you have access to facts that I do not, 'lost' is impolite speculation. But lets move on. I have a contrary hypothesis based on the facts quoted below. As far as I know, Google is somewhat stuck on 2.7. Dropbox, on the other, is migrating to modern 3.x Python (see below). Guido wants the world to do this, so he moved to a company where he can help make this practical, by helping to work out some of the practical details of how to do so, and then share them with the rest of the Python community. On Jan 8, 6 days ago, Guido posted on python-idea "Proposal to extend PEP 484 (gradual typing) to support Python 2.7" "At Dropbox we're trying to be good citizens and we're working towards introducing gradual typing (PEP 484) into our Python code bases (several million lines of code). However, that code base is mostly still Python 2.7 and we believe that we should introduce gradual typing first and start working on conversion to Python 3 second (since having static types in the code can help a big refactoring like that). Since Python 2 doesn't support function annotations we've had to look for alternatives. We considered stub files, a magic codec, docstrings, and additional `# type:` comments. In the end we decided that `# type:` comments are the most robust approach. We've experimented a fair amount with this and we have a proposal for a standard." A few days later, in the absence of objection to the proposed comment syntax, he added the proposal. Not mentioned in the quote is that mypy will support the new comments for static analysis. 2.x interpreters will happily ignore then. If Dropbox comment-annotates a public 2.x package, it can contribute the work back for the use of others. Google, on the other hand, decided to support annotation in 2.7 creating a custom 2.7 interpreter than will ignore them. Any code annotated by Google will be useless on standard interpreters without being run through a converter. -- Terry Jan Reedy From frank at chagford.com Thu Jan 14 01:27:25 2016 From: frank at chagford.com (Frank Millman) Date: Thu, 14 Jan 2016 08:27:25 +0200 Subject: Stop writing Python 3.5 incompatible code :-) Message-ID: This is a tongue-in-cheek follow-up to the thread on Python 4 incompatible code, but it did happen to me, and may help someone else. I execute a lot of database SELECT commands. In many cases I expect to get only one row returned, but it could be zero or more than one. Using LBYL, one would retrieve the row(s) and check the length. I found a way to use EAFP, as follows - cur.execute('SELECT ...') (row,) = cur This uses tuple unpacking, and only works if exactly one row is returned. If it fails it raises ValueError, but I need to know whether it failed because no rows were returned, or more than one row was returned. The only way I could figure out how to achieve this was to parse the error message. If 0 rows were returned, the message is 'need more than 0 values to unpack'. If > 1 rows were returned, the message is 'too many values to unpack'. So my test was - except ValueError as e: if str(e).startswith('need'): # 0 rows returned else: # > 1 rows returned This has worked for years, but with 3.5 it stopped working. It took me a while to figure out why. Lo and behold, the error message has changed! Now, if 0 rows are returned, the message is 'not enough values to unpack'. Luckily the other message has not changed, so now my test is - except ValueError as e: if str(e).startswith('too many'): # > 1 rows returned else: # 0 rows returned Now it works with both versions. Frank Millman From mscir at yahoo.com Thu Jan 14 01:27:41 2016 From: mscir at yahoo.com (Mike S) Date: Wed, 13 Jan 2016 22:27:41 -0800 Subject: When I need classes? In-Reply-To: References: <56927b37$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/11/2016 3:45 PM, Travis Griggs wrote: > >> On Jan 10, 2016, at 9:48 AM, Bernardo Sulzbach wrote: >> >> Essentially, classes (as modules) are used mainly for organizational purposes. >> >> Although you can solve any problem you would solve using classes >> without classes, solutions to some big problems may be cheaper and >> more feasible using classes. > > As a long term OO purist practitioner, I would add to this. Obviously, you can organize your code any way you want, with or without classes. You could put all your functions with an odd number of letters in one class, and all of the even numbered ones in another class. > > Having listened to the guy (Alan Kay) who coined the term (Object Oriented Programming) quite a bit over the years, I believe that the focus of OO (of which classes are a particular implementation approach) is to bind behavior to data. In ?traditional? programming approaches, one focused on the algorithm (behavior) first, and then figured out what data needed to flow where to get the job done. Classes provided a mechanism to turn that equation, generally speaking, around. One thinks about the data first, and then figures out what behavior binds best to that data. And how that data will interact (inter-object behavior, often called messages) to get your job done. For some (many) problems, this can be a real win. And for some, not so much. > > I think, this is often why, for a simple script, OO just kind of gets in the way. You have a straightforward procedure that you just want to do. The state (data) is not rich enough to make making it the focal point of your program. Well said, thanks! From marko at pacujo.net Thu Jan 14 01:32:30 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 14 Jan 2016 08:32:30 +0200 Subject: [Python-ideas] Password masking for getpass.getpass References: <20160113015414.GF10854@ando.pearwood.info> <20160113021746.GA26480@phdru.name> <20160113100442.GI10854@ando.pearwood.info> <5696f02b$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87oacobri9.fsf@elektro.pacujo.net> Steven D'Aprano : > What about those who are so frustrated with trying to get sites to > work that they just Allow All On This Page? I'm occasionally frustrated by that, but I simply won't read that page. Nothing truly important is lost. Marko From rosuav at gmail.com Thu Jan 14 01:36:46 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2016 17:36:46 +1100 Subject: Stop writing Python 3.5 incompatible code :-) In-Reply-To: References: Message-ID: On Thu, Jan 14, 2016 at 5:27 PM, Frank Millman wrote: > Using LBYL, one would retrieve the row(s) and check the length. I found a > way to use EAFP, as follows - > > cur.execute('SELECT ...') > (row,) = cur > > This uses tuple unpacking, and only works if exactly one row is returned. If > it fails it raises ValueError, but I need to know whether it failed because > no rows were returned, or more than one row was returned. The only way I > could figure out how to achieve this was to parse the error message. That seems like a tricky way to do things. How about this: cur.execute(...) rows = iter(cur) try: row = next(rows) except StopIteration: # 0 rows returned try: next(rows) except StopIteration: pass else: # >1 rows returned It's a bit more verbose, but it's reliable. Alternatively, since you know that a returned row will never be None: cur.execute(...) rows = iter(cur) row, extra = next(rows), next(rows) if row is None: # 0 rows returned if extra is not None: # >1 rows returned ChrisA From frank at chagford.com Thu Jan 14 02:36:59 2016 From: frank at chagford.com (Frank Millman) Date: Thu, 14 Jan 2016 09:36:59 +0200 Subject: Stop writing Python 3.5 incompatible code :-) In-Reply-To: References: Message-ID: "Chris Angelico" wrote in message news:CAPTjJmpS+vfu33tULaE5oiVRvN_OTfuxrp8YLuy68qmu36-Nrw at mail.gmail.com... > On Thu, Jan 14, 2016 at 5:27 PM, Frank Millman wrote: > > Using LBYL, one would retrieve the row(s) and check the length. I found > > a > > way to use EAFP, as follows - > > > > cur.execute('SELECT ...') > > (row,) = cur > > > > This uses tuple unpacking, and only works if exactly one row is > > returned. If > > it fails it raises ValueError, but I need to know whether it failed > > because > > no rows were returned, or more than one row was returned. The only way I > > could figure out how to achieve this was to parse the error message. > > That seems like a tricky way to do things. How about this: > > cur.execute(...) > rows = iter(cur) > try: > row = next(rows) > except StopIteration: > # 0 rows returned > try: > next(rows) > except StopIteration: pass > else: > # >1 rows returned > > It's a bit more verbose, but it's reliable. Alternatively, since you > know that a returned row will never be None: > > cur.execute(...) > rows = iter(cur) > row, extra = next(rows), next(rows) > if row is None: > # 0 rows returned > if extra is not None: > # >1 rows returned > Thanks, Chris. I did feel unhappy relying on the contents of an error message, so I will follow up on your suggestion. I like your first solution. In fact, with sqlite3, 'cur' is already iterable, so I can just say cur.execute(...) try: row = next(cur) except StopIteration: # 0 rows returned try: next(cur) except StopIteration: pass else: # >1 rows returned I will have to check if this works with psycopg2 and pyodbc, the other two adaptors that I use. Your second solution does not seem to work - if it raises StopIteration, neither 'row' nor 'extra' is populated. I may be doing it wrong, but no matter, I prefer the first one anyway. There is one slight downside that I can see. I believe that raising an exception is a relatively expensive operation in Python. For this reason, a rule of thumb is to use EAFP when the usual case is to have no exception, and LBYL otherwise. With my approach, I do not get an exception if exactly one row is returned. With yours, you rely on raising an exception to determine the result. I can think of two counter-arguments to that. Firstly, it is more important to ensure that the program is correct than to shave off a few microseconds. Secondly, as StopIteration is used extensively under the hood in modern pythons, it is probably highly optimised, and therefore nothing to be worried about. Frank From dieter at handshake.de Thu Jan 14 02:59:22 2016 From: dieter at handshake.de (dieter) Date: Thu, 14 Jan 2016 08:59:22 +0100 Subject: SSL certification fails / tweepy References: <5695F2B7.3000401@pp.inet.fi> Message-ID: <87r3hkh9r9.fsf@handshake.de> "K. Elo" writes: > I have written I small python script for twitter mining utilising the > 'tweepy' library. Since a couple of days I cannot use the script > anymore, due to a "ssl certificate verification failed" error. The > authentication with Twitter API succeess, but when I try to run the > following code: > ... > the execution is broken with an "SSL_VERIFICATION_FAILED" error. Whenever an execution is aborted by an exception, you should always look at the traceback (--> "traceback" module). It tells you where precisely in your code the exception has occured and how you came to that point. This is important information in order to understand the problem. "SSL_VERIFICATION_FAILED" is an error which occurs when an SSL ("https") connection is established. It happens when the SSL certificate (of the server and/or client) does not contain expected data - e.g. the certificate is no longer (or not yet) valid or its subject does not reference the connected entity or the certificate chain cannot be verified. Look for Python documentation on SSL verification to learn how to properly set up things for successful verfication. Among others, you will need have somewhere information about trusted root certificates. From rosuav at gmail.com Thu Jan 14 03:07:59 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2016 19:07:59 +1100 Subject: Stop writing Python 3.5 incompatible code :-) In-Reply-To: References: Message-ID: On Thu, Jan 14, 2016 at 6:36 PM, Frank Millman wrote: > I like your first solution. In fact, with sqlite3, 'cur' is already > iterable, so I can just say > > cur.execute(...) > try: > row = next(cur) > except StopIteration: > # 0 rows returned > try: > next(cur) > except StopIteration: pass > else: > # >1 rows returned > > I will have to check if this works with psycopg2 and pyodbc, the other two > adaptors that I use. Not sure that "already iterable" means what you think it does. Since it's iterable, you can call iter() on it (as I do in my example). > Your second solution does not seem to work - if it raises StopIteration, > neither 'row' nor 'extra' is populated. I may be doing it wrong, but no > matter, I prefer the first one anyway. Oops. cur.execute(...) rows = iter(cur) row, extra = next(rows, None), next(rows, None) if row is None: # 0 rows returned if extra is not None: # >1 rows returned Now it's set. > There is one slight downside that I can see. I believe that raising an > exception is a relatively expensive operation in Python. For this reason, a > rule of thumb is to use EAFP when the usual case is to have no exception, > and LBYL otherwise. With my approach, I do not get an exception if exactly > one row is returned. With yours, you rely on raising an exception to > determine the result. Under the hood, they're all doing the same thing. > I can think of two counter-arguments to that. Firstly, it is more important > to ensure that the program is correct than to shave off a few microseconds. > Secondly, as StopIteration is used extensively under the hood in modern > pythons, it is probably highly optimised, and therefore nothing to be > worried about. Thirdly, the cost of raising an exception is WAY lower than the cost of reading anything from a hard disk - probably way lower than reading from an SSD. Unless all your content is getting cached in RAM, there's no way the cost of an exception will be at all significant. ChrisA From steve+comp.lang.python at pearwood.info Thu Jan 14 03:09:25 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 14 Jan 2016 19:09:25 +1100 Subject: Stop writing Python 3.5 incompatible code :-) References: Message-ID: <569757b6$0$1505$c3e8da3$5496439d@news.astraweb.com> On Thursday 14 January 2016 17:27, Frank Millman wrote: > So my test was - > > except ValueError as e: > if str(e).startswith('need'): > # 0 rows returned > else: > # > 1 rows returned > > This has worked for years, but with 3.5 it stopped working. It took me a > while to figure out why. Lo and behold, the error message has changed! Error message strings have *never* been part of the function API. They are always subject to change without notice. Somebody might localise them to the user's native language, or merely change them on a whim, and they can do that in maintenance releases too, not just minor or major releases. > Now, if 0 rows are returned, the message is 'not enough values to unpack'. > > Luckily the other message has not changed, Note to self: push through a minor change to the error message. Perhaps make it "too many targets for the number of items"? > so now my test is - > > except ValueError as e: > if str(e).startswith('too many'): > # > 1 rows returned > else: > # 0 rows returned > > Now it works with both versions. For now. -- Steve From steve+comp.lang.python at pearwood.info Thu Jan 14 03:16:02 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 14 Jan 2016 19:16:02 +1100 Subject: Stop writing Python 4 incompatible code References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> <6e0f3ba0-750d-4f57-afcc-238b85779948@googlegroups.com> Message-ID: <56975946$0$2786$c3e8da3$76491128@news.astraweb.com> On Thursday 14 January 2016 14:29, Rick Johnson wrote: > On Wednesday, January 13, 2016 at 9:08:40 PM UTC-6, Chris Angelico wrote: >> You're talking about a very serious matter between two legal entities >> - if someone was *fired* because of social, technological, or other >> problems with Python, that has implications that could matter in a >> court of law. So I put it right back to you: What gives you the right >> to speak against Guido and Google? > > I'm not speaking *AGAINST* anyone, i'm merely trying to > understand what happened. And unless there was some sort of > explicit contract, Google could fire *ANYONE* for *ANY* > reason -- this is not France, Chris! There's no reason to think that Guido was fired. He announced that he was leaving Google to go work for Dropbox -- that sounds to me that he was given a better offer, or perhaps he no longer cared for the toxic work environment which is Google. He wasn't fired, he was poached: http://techcrunch.com/2012/12/07/dropbox-guido-van-rossum-python/ >> And Michael's right: people move around for all sorts of reasons. >> Doesn't necessarily mean anything about the previous job. > > Of course. But when you leave things open for speculation, > you enviably create a situation where rumors can start > circulating. You're the only one trying to circulate rumours about Guido and Google -- and it's old news too, he's been working at Dropbox since Dec 2012: https://blogs.dropbox.com/tech/2012/12/welcome-guido/ [...] > We have a *RIGHT* to be worried Chris, because our > livelihoods are directly dependent on Python. You will be pleased to know that Dropbox are 100% behind Python 3, and spending a lot of time and money on bringing optional static typing to Python 2 and 3 in order to simplify the migration. -- Steve From breamoreboy at yahoo.co.uk Thu Jan 14 03:33:20 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 14 Jan 2016 08:33:20 +0000 Subject: The history behind the decision to move Python to GitHub Message-ID: http://www.snarky.ca/the-history-behind-the-decision-to-move-python-to-github -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From frank at chagford.com Thu Jan 14 04:39:05 2016 From: frank at chagford.com (Frank Millman) Date: Thu, 14 Jan 2016 11:39:05 +0200 Subject: Stop writing Python 3.5 incompatible code :-) In-Reply-To: References: Message-ID: "Frank Millman" wrote in message news:n77j78$ld0$1 at ger.gmane.org... > cur.execute(...) > try: > row = next(cur) > except StopIteration: > # 0 rows returned > try: > next(cur) > except StopIteration: pass > else: > # >1 rows returned For the record, I just tried this and found an error. It is easier to explain if I change it slightly - cur.execute(...) try: row = next(cur) except StopIteration: # 0 rows returned try: next(cur) except StopIteration: # instead of pass, do something with row else: # >1 rows returned 'do something with row' is reached even if the first next() failed, so row does not exist. Here is the corrected version - cur.execute(...) try: row = next(cur) except StopIteration: # 0 rows returned else: try: next(cur) except StopIteration: # do something with row else: # >1 rows returned Frank From forda773 at gmail.com Thu Jan 14 04:39:47 2016 From: forda773 at gmail.com (Ashford) Date: Thu, 14 Jan 2016 01:39:47 -0800 (PST) Subject: Python alternative to Google Groups In-Reply-To: References: Message-ID: <42dac280-7dac-4340-a6e4-d7d769904138@googlegroups.com> Vebnest Ecommerce Online Shopping Services Windows Reseller Hosting?is based on the Windows operating system 2008. It is known for support of various programming frameworks, including Asp, ASP.net and TomCat . Windows Hosting also supports SQL Server (MSSQL) and Access, which can be used to build database driven websites. So if your site has pages ending in .asp or .aspx then you need Windows Hosting. Economy $9.99 / per month 500 GB Disk Space 100 Databases List Free Domain Registration 1 Hosting Space FREE Ad Coupons Account Control Panel FREE 24/7 Support http://www.vebnest.com/windows-reseller-hosting From oscar.j.benjamin at gmail.com Thu Jan 14 06:10:33 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 14 Jan 2016 11:10:33 +0000 Subject: [Tutor] me, my arm, my availability ... In-Reply-To: <201601132047.u0DKlhIc025984@theraft.openend.se> References: <201601132047.u0DKlhIc025984@theraft.openend.se> Message-ID: On 13 January 2016 at 20:47, Laura Creighton wrote: > > Seems like surgery is needed to fix this. > > So I wanted you all to know, no, I haven't forgotten you and no haven't > stopped caring. I have just stopped being as __capable__ if you know > what I mean. > > Please take care of yourselves and each other. I will often be reading > even if typing is more than I can do right now. I had honestly been wondering where you were. Glad to see that you're not gone (although obviously not glad that you're injured!). Wishing a speedy recovery. -- Oscar From maillists at pp.inet.fi Thu Jan 14 06:33:22 2016 From: maillists at pp.inet.fi (K. Elo) Date: Thu, 14 Jan 2016 13:33:22 +0200 Subject: SSL certification fails / tweepy [SOLVED] In-Reply-To: <87r3hkh9r9.fsf@handshake.de> References: <5695F2B7.3000401@pp.inet.fi> <87r3hkh9r9.fsf@handshake.de> Message-ID: <56978782.9020507@pp.inet.fi> Hi! 14.01.2016, 09:59, dieter wrote: > "SSL_VERIFICATION_FAILED" is an error which occurs when > an SSL ("https") connection is established. It happens when > the SSL certificate (of the server and/or client) does not contain > expected data - e.g. the certificate is no longer (or not yet) valid > or its subject does not reference the connected entity or the > certificate chain cannot be verified. > > Look for Python documentation on SSL verification to learn how to > properly set up things for successful verfication. Among others, > you will need have somewhere information about trusted root certificates. > Thanks, dieter, for your reply. I have now re-installed both certificate packages and (open)ssl related python packages - and now it works! I still wonder why openSuSE certificates are not working out-of-box with python. Maybe some of the packages were not correctly installed... Anyway, thanks for your quick reply - the issue is now solved :) Best, Kimmo From cfkaran2 at gmail.com Thu Jan 14 06:35:59 2016 From: cfkaran2 at gmail.com (Cem Karan) Date: Thu, 14 Jan 2016 06:35:59 -0500 Subject: me, my arm, my availability ... In-Reply-To: <201601132047.u0DKlhIc025984@theraft.openend.se> References: <201601132047.u0DKlhIc025984@theraft.openend.se> Message-ID: On Jan 13, 2016, at 3:47 PM, Laura Creighton wrote: > > I fell recently. Ought to be nothing, but a small chip of bone, either an > existing one or one I just made is nicely wedged in the joint taking away > a whole lot of the ability of my arm to rotate in the elbow joint. Or > hold my arm in a position that is usual for typing. Plus, now that the > sprain/swelling is more or less over, the pain, unfortunately is not. > > The real downside is that my typing speed is down from 135-140 wpm > to 5-10 wmp. At this rate, just getting my usual work done takes > overtime. > > Seems like surgery is needed to fix this. > > So I wanted you all to know, no, I haven't forgotten you and no haven't > stopped caring. I have just stopped being as __capable__ if you know > what I mean. > > Please take care of yourselves and each other. I will often be reading > even if typing is more than I can do right now. > > Laura > > ps -- (recent tutor discussion) I am with Alan and not with Mark. I > am happy as anything when people post their not-quite-working code for > homework assignments here to tutor. They aren't lazy bastards wanting > somebody to do their assignments for them, they want to learn why what > they are trying to do isn't working. Sounds perfect for tutor to me. Good luck healing! Hope you get better soon. Surgery has gotten a WHOLE lot better recently, they did wonders for my knee a few years back. With luck, it'll be more or less outpatient surgery. Good luck, Cem Karan From kasale.jacktone at gmail.com Thu Jan 14 06:50:45 2016 From: kasale.jacktone at gmail.com (kasale.jacktone at gmail.com) Date: Thu, 14 Jan 2016 03:50:45 -0800 (PST) Subject: Need help on a project To :"Create a class called BankAccount with the following parameters " In-Reply-To: <4023d75d-5e96-40b0-b1b1-a193c722004d@googlegroups.com> References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <79ce6cf5-4bad-47f6-8824-44ce9849d825@googlegroups.com> <4023d75d-5e96-40b0-b1b1-a193c722004d@googlegroups.com> Message-ID: <3f363de0-55d2-4e37-bd07-f946a505f78f@googlegroups.com> hello lee so what was the final answer u gave for the following question.. reate 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 From oscar.j.benjamin at gmail.com Thu Jan 14 06:53:52 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 14 Jan 2016 11:53:52 +0000 Subject: How to remove item from heap efficiently? In-Reply-To: <568EEC40.7070807@mail.de> References: <568EEC40.7070807@mail.de> Message-ID: On 7 January 2016 at 22:52, Sven R. Kunze wrote: > > suppose, I need items sorted by two criteria (say timestamp and priority). > For that purpose, I use two heaps (heapq module): > > heapA # items sorted by timestamp > heapB # items sorted by priority > > Now my actual problem. When popping an item of heapA (that's the oldest > item), I need to remove the very same item from heapB, regardlessly where it > is in heapB. And vice versa. > > Is there a datastructure or a simple trick to achieve that in an efficient > matter? Essentially you want a data structure that can efficiently do the following: 1) add an arbitrary item 2) remove an arbitrary item 3) get/pop the minimum element So Python's set object does add/remove in O(1) but min in O(N). A heap does add and min in O(log(N)) but remove in O(N). Self-balancing binary trees can do all of add/remove/min in O(log(N)) so I guess that's better than what you currently have. Google shows many third party implementations for Python. Here's one: https://pypi.python.org/pypi/bintrees/2.0.2 -- Oscar From cfkaran2 at gmail.com Thu Jan 14 07:04:17 2016 From: cfkaran2 at gmail.com (Cem Karan) Date: Thu, 14 Jan 2016 07:04:17 -0500 Subject: How to remove item from heap efficiently? In-Reply-To: <5696A0A5.8020401@mail.de> References: <568EEC40.7070807@mail.de> <568FE797.6090808@mail.de> <5692A795.3070904@mail.de> <5695276A.2020101@mail.de> <7A7E26D9-01E5-4D77-92B4-3491D86E1EA8@gmail.com> <5696A0A5.8020401@mail.de> Message-ID: On Jan 13, 2016, at 2:08 PM, Sven R. Kunze wrote: > On 13.01.2016 12:20, Cem Karan wrote: >> On Jan 12, 2016, at 11:18 AM, "Sven R. Kunze" wrote: >> >>> Thanks for replying here. I've come across these types of wrappers/re-implementations of heapq as well when researching this issue. :) >>> >>> Unfortunately, they don't solve the underlying issue at hand which is: "remove item from heap with unknown index" and be efficient at it (by not using _heapq C implementation). >>> >>> >>> So, I thought I did another wrapper. ;) It at least uses _heapq (if available otherwise heapq) and lets you remove items without violating the invariant in O(log n). I am going to make that open-source on pypi and see what people think of it. >> Is that so? I'll be honest, I never tested its asymptotic performance, I just assumed that he had a dict coupled with a heap somehow, but I never looked into the code. > > My concern about that specific package is a missing C-implementation. I feel that somewhat defeats the whole purpose of using a heap: performance. I agree with you that performance is less than that of using a C extension module, but there are other costs associated with developing a C module: 1) As the developer of the module, you must be very careful to ensure your code is portable. 2) Distribution becomes somewhat more difficult; you may need to distribute both source and compiled binaries for various platforms. This is somewhat more annoying than pure python scripts. 3) Debugging can become significantly more difficult. My current codebase is python+cython+c, and when something crashes, it is usually easier to use a bunch of printf() statements to figure out what is going on than to use a debugger (others may have different experiences, this is just mine). 4) Not everyone is familiar with C, so writing extensions may be more difficult. 5) Will the extension module work on non-cpython platforms (iron python, jython, etc.)? Finally, without profiling the complete package it may be difficult to tell what impact your C module will have on overall performance. In my code, HeapDict had less than a 2% performance impact on what I was doing; even if I had replaced it with a pure C implementation, my code would not have run much faster. So, while I agree in principle to what you're saying, in practice there may be other factors to consider before rejecting the pure python approach. > Asymptotic performance is still O(log n). So, if the intent is to pop events more often than to peek at them, then in practice, HeapDict is about the same as some clever heap+dict method (which it might be, as I said, I haven't looked at the code). >> That said, IMHO using a dict interface is the way to go for priority queues; it really simplified my code using it! This is my not-so-subtle way of asking you to adopt the MutableMapping interface for your wrapper ;) > > Could you elaborate on this? What simplified you code so much? > > I have been using heaps for priority queues as well but haven't missed the dict interface so far. Maybe, my use-case is different. I'm writing an event-based simulator, and as it turns out, it is much easier to tentatively add events than it is to figure out precisely which events will occur in the future. That means that on a regular basis I need to delete events as I determine that they are garbage. HeapDict did a good job of that for me (for completely unrelated reasons I decided to switch to a pure-C codebase, with python hooks to twiddle the simulator at a few, very rare, points in time; hence the python+cython+c comment above). Thanks, Cem Karan From fernandojr.ifcg at live.com Thu Jan 14 07:56:22 2016 From: fernandojr.ifcg at live.com (fernando junior) Date: Thu, 14 Jan 2016 04:56:22 -0800 (PST) Subject: Observer pattern implementation in Python based on jQuery Message-ID: <32a8cad5-8414-46ae-a5de-90c6f7d590e3@googlegroups.com> Hi, I made an observer/pubsub pattern implementation in Python based on jQuery. It's available in https://github.com/fernandojunior/python-pattern-observer. Take a look! :) Fernando Felix https://br.linkedin.com/in/fernandofnjr From rosuav at gmail.com Thu Jan 14 07:56:46 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2016 23:56:46 +1100 Subject: Strange behavior In-Reply-To: References: Message-ID: On Thu, Jan 14, 2016 at 3:03 PM, Michal Nalevanko wrote: > I've just installed Python 3.5.1 on my computer and came across somewhat > strange behavior. > > This is a snapshot of a short code that I wrote: https://goo.gl/izYbD0 > > Quite simple, you might say. Obviously, the program should create a new > text file, nothing else. But do you see the numbers it had added to the > output? > > Is this behavior normal or am I overlooking something? Thank you very much > for your help. Hi Michal! When you work with Python interactively, the interpreter prints out the results of expressions automatically. This doesn't happen when you write a script, but it's often helpful with simple tinkering. The numbers getting printed out are the returned values from the .write() method; they're a simple check saying how much stuff got written. You can ignore them - your file has been created correctly. ChrisA From joel.goldstick at gmail.com Thu Jan 14 08:01:38 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 14 Jan 2016 08:01:38 -0500 Subject: i am having troubles downloading 3.5.1 to my computer In-Reply-To: References: Message-ID: On Wed, Jan 13, 2016 at 3:42 PM, Crystal Fernandez < cfernandez16 at franklinvillecsd.org> wrote: > NLT+CRF <3 > -- > https://mail.python.org/mailman/listinfo/python-list > What operating system? What steps did you take? What error messages did your computer return? If you are using an older version of Windows, you can't use python 3.5 -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From __peter__ at web.de Thu Jan 14 08:43:51 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Jan 2016 14:43:51 +0100 Subject: Stop writing Python 4 incompatible code References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5696f3c6$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Or we'll be hit by a big rock from space. Sounds like a plan. From darcy at VybeNetworks.com Thu Jan 14 08:47:22 2016 From: darcy at VybeNetworks.com (D'Arcy J.M. Cain) Date: Thu, 14 Jan 2016 08:47:22 -0500 Subject: Stop writing Python 4 incompatible code In-Reply-To: References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5696f3c6$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20160114084722.5f92f2c2@imp> On Thu, 14 Jan 2016 14:43:51 +0100 Peter Otten <__peter__ at web.de> wrote: > > Or we'll be hit by a big rock from space. > > Sounds like a plan. Which one? Number 9? -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From breamoreboy at yahoo.co.uk Thu Jan 14 10:25:44 2016 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 14 Jan 2016 15:25:44 +0000 Subject: i am having troubles downloading 3.5.1 to my computer In-Reply-To: References: Message-ID: On 13/01/2016 20:42, Crystal Fernandez wrote: Asked and anwsered repeatedly over the last few weeks. Search the archives for the action(s) you need to take. If you are uncertain here are good starting points. http://catb.org/~esr/faqs/smart-questions.html http://www.sscce.org/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rantingrickjohnson at gmail.com Thu Jan 14 10:30:38 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 14 Jan 2016 07:30:38 -0800 (PST) Subject: Stop writing Python 4 incompatible code In-Reply-To: References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> <6e0f3ba0-750d-4f57-afcc-238b85779948@googlegroups.com> Message-ID: <7df87f88-b63d-4cc2-95a9-075313d72537@googlegroups.com> On Wednesday, January 13, 2016 at 11:19:16 PM UTC-6, Michael Torrie wrote: > The only one speculating is you. Everything I've read points to this > idea of yours about GvR and Google being untrue. Providing speculation is not the same as providing facts. Please provide facts. And enumerate them! > You have presented no evidence for your accusation, so > given the evidence I have seen that contradicts you, I > must conclude that you made it [up]. Here is an enumerated list of the indisputable facts of this case: (1) GvR is no longer employed by Google (FACT!) (2) Before Python3 came along, the Python community was vibrant and growing (FACT!) (3) After Python3 came along, the Python community has become fractured, and the Python code base has become fractured, and the general public consensus is that Python is on its way to extinction (FACT!) Of course these are not *ALL* the facts, but they are *ALL* the facts that publicly available. If you (and your hero GvR) want to prevent rumors from circulation, them i suggest you provide the relevant facts regarding his change of employment, and simply throwing opinions out that "the change suited him well" is not providing any facts. > I don't know who the "we" you're talking about is, I represent the concerns of entire class of Python community members, folks who are fearful to speak out publicly for fear of reprisals (which is a legitimate fear). > but if your livelihood depends on Python's existence and > development in a certain direction, then [...] you should > be able to adapt to any programming language suitable for > your job at hand. Both myself, and the people i represent, write code in *MANY* languages, but to suggest that we should just """be quiet and translate millions of lines of code into another language because our "dear leader" decided to break backwards compatibility for arbitrary reasons"""... is a quite impractical, don't you think? From __peter__ at web.de Thu Jan 14 10:32:46 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Jan 2016 16:32:46 +0100 Subject: Stop writing Python 4 incompatible code References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5696f3c6$0$1583$c3e8da3$5496439d@news.astraweb.com> <20160114084722.5f92f2c2@imp> Message-ID: D'Arcy J.M. Cain wrote: > On Thu, 14 Jan 2016 14:43:51 +0100 > Peter Otten <__peter__ at web.de> wrote: >> > Or we'll be hit by a big rock from space. >> >> Sounds like a plan. > > Which one? Number 9? Hm, I didn't expect this question... plans[-1], most certainly. From darcy at VybeNetworks.com Thu Jan 14 10:47:14 2016 From: darcy at VybeNetworks.com (D'Arcy J.M. Cain) Date: Thu, 14 Jan 2016 10:47:14 -0500 Subject: Stop writing Python 4 incompatible code In-Reply-To: References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5696f3c6$0$1583$c3e8da3$5496439d@news.astraweb.com> <20160114084722.5f92f2c2@imp> Message-ID: <20160114104714.4cbbf565@imp> On Thu, 14 Jan 2016 16:32:46 +0100 Peter Otten <__peter__ at web.de> wrote: > >> > Or we'll be hit by a big rock from space. > >> Sounds like a plan. > > Which one? Number 9? > > Hm, I didn't expect this question... > > plans[-1], most certainly. Hmm. Am I being too subtle or...? from OuterSpace import plan print(plan[9]) If that's still too subtle: https://en.wikipedia.org/wiki/Plan_9_from_Outer_Space -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From rantingrickjohnson at gmail.com Thu Jan 14 10:52:12 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 14 Jan 2016 07:52:12 -0800 (PST) Subject: Stop writing Python 4 incompatible code In-Reply-To: References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> Message-ID: <36c2dbd5-e8e4-4e56-8c4e-ffb2da51875f@googlegroups.com> On Wednesday, January 13, 2016 at 11:46:30 PM UTC-6, Terry Reedy wrote: > On 1/13/2016 8:02 PM, Rick Johnson wrote: > > and a leader who lost his cushy job at Google > > Unless you have access to facts that I do not, 'lost' is > impolite speculation. But lets move on. Well i admit my speculation may be leading to an undesirable conclusion, but i can *ONLY* speculate utilizing the facts that are publicly available to me. If we want to prevent rumors, then we need to ensure that *ALL THE FACTS* are available for review. > I have a contrary hypothesis based on the facts quoted > below. As far as I know, Google is somewhat stuck on 2.7. So you're suggesting that GvR *WILLINGLY* left a global, and well established giant, to work for a tiny start-up because his bosses refused to switch from Python2 to (his new baby) Pyhton3? So, let me get this strait: he wasn't fired, *HE QUIT*??? I wonder if he's considered the possibility that Google may swoop in an purchase Dropbox at some time in the near future, and he could find himself working for google once again. And you know what would be the ultimate form of irony, if they forced him to migrate Dropbox *BACK* to Python2! And here is the sign that they will post on his new office door: AND YOU WILL *KNOW* THAT GOOGLE IS THE *LORD*, WHEN WE TRANSFORM YOU FROM A PETULANT LITTLE ENGINEER, INTO AN OBEDIENT LITTLE CODE MONKEY! From fabiofz at gmail.com Thu Jan 14 10:52:43 2016 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 14 Jan 2016 13:52:43 -0200 Subject: PyDev 4.5.1 Released Message-ID: Release Highlights: ------------------------------- * Debugger * Cython speedup modules are now available for the debugger (see performance improvements at: https://www.speedtin.com/reports/7_pydevd_cython). * It is considerably faster even without the speedup modules (see performance improvements at: https://www.speedtin.com/reports/8_pydevd_pure_python). * When debugging multiple processes the console wasn't being updated to the selected stack in the debug view. * Many bug-fixes. * Improved the search to always play safe and update the index so that the matches are always consistent (#PyDev-634). * Fixed issue renaming top-level module on refactoring. * Refactoring has option to rename variable to a standard case style. * Improved the parser that extracted the outline for global tokens to deal with async and consider declarations inside ifs. * Code completion of properties with @property no longer shows arguments parenthesis (#PyDev-453). * Preventing a freeze if some code-analysis takes too much time (#PyDev-636). * Ctrl+1 can be used to wrap/unwrap the contents of brackets (patch by yohell). What is PyDev? --------------------------- PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com What is LiClipse? --------------------------- LiClipse is a PyDev standalone with goodies such as support for Multiple cursors, theming, TextMate bundles and a number of other languages such as Django Templates, Jinja2, Kivy Language, Mako Templates, Html, Javascript, etc. It's also a commercial counterpart which helps supporting the development of PyDev. Details on LiClipse: http://www.liclipse.com/ Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer LiClipse http://www.liclipse.com PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com PyVmMonitor - Python Profiler http://www.pyvmmonitor.com/ From mailtoshivamgupta at gmail.com Thu Jan 14 10:53:41 2016 From: mailtoshivamgupta at gmail.com (Shivam Gupta) Date: Thu, 14 Jan 2016 21:23:41 +0530 Subject: problem Message-ID: Hello, I am using python 3.5.1 on my windows 8.1. The problem is that whenever i save any file any after that when i run it the screen just close immediately after i double click on python file. Thank you. From milad.khakpour at gmail.com Thu Jan 14 11:32:50 2016 From: milad.khakpour at gmail.com (milad.khakpour at gmail.com) Date: Thu, 14 Jan 2016 08:32:50 -0800 (PST) Subject: Convert timeseries GDAL raster format (vrt) to NetCDF Message-ID: <6f28b850-5a44-4925-9acf-e63fc7f8eb2e@googlegroups.com> I tried to package a timeseries for vrt file to NetCDF. The problem is, it converts layer by layer and save it to NetCDF which it took much time (also with memory allocation). I wanted to do is to save it chunk by chunk which I do not have any idea how to do it ! Does someone have any solution for that !? it take for 1Gb (25 images) around 90 second !! here is my code: def tiff_to_netcdf(imagesPath, output, chunksize=None): img_txt = open('img_path.txt', 'w') for paths, subdirs, files in os.walk(imagesPath): for name in files: if name.endswith('.tif'): img_txt.write(os.path.join(paths, name) + '\n') img_txt.close() # Build vrt files os.system('gdalbuildvrt -separate -input_file_list img_path.txt images.vrt') ds = gdal.Open('images.vrt') band1 = ds.GetRasterBand(1) a = band1.ReadAsArray() nlat, nlon = np.shape(a) b = ds.GetGeoTransform() # bbox, interval lon = np.arange(nlon)*b[1]+b[0] lat = np.arange(nlat)*b[5]+b[3] basedate = dt.datetime(2006, 01, 11, 0, 0, 0) # Create NetCDF file # Clobber- Overwrite any existing file with the same name nco = netCDF4.Dataset(output+'.nc', 'w', clobber=True) # Create dimensions, variables and attributes: nco.createDimension('lon', nlon) nco.createDimension('lat', nlat) nco.createDimension('time', None) timeo = nco.createVariable('time', 'f4', ('time',)) timeo.units = 'days since 2006-01-11 00:00:00' timeo.standard_name = 'time' lono = nco.createVariable('lon', 'f4', ('lon',)) lono.standard_name = 'longitude' lato = nco.createVariable('lat', 'f4', ('lat',)) lato.standard_name = 'latitude' # Create container variable for CRS: lon/lat WGS84 datum crso = nco.createVariable('crs', 'i4') crso.long_name = 'Lon/Lat Coords in WGS84' crso.grid_mapping_name = 'latitude_longitude' crso.longitude_of_prime_meridian = 0.0 crso.semi_major_axis = 6378137.0 crso.inverse_flattening = 298.257223563 # Create short integer variable with chunking tmno = nco.createVariable('tmn', 'i2', ('time', 'lat', 'lon'), zlib=True, chunksizes=chunksize, fill_value=-9999) tmno.scale_factor = 0.01 tmno.add_offset = 0.00 tmno.grid_mapping = 'crs' tmno.set_auto_maskandscale(False) nco.Conventions = 'CF-1.6' # Write lon,lat lono[:] = lon lato[:] = lat pat = re.compile(r'^(\w{1})(\d{4})(\d{2})(\d{2})_\d{6}___SIG0.*.tif$') itime = 0 written = 0 data = np.empty((3, 8000, 8000), dtype=np.float) # Step through data, writing time and data to NetCDF for root, dirs, files in os.walk(imagesPath): dirs.sort() files.sort() for f in files: match = re.match(pat, f) if match: if itime % 3 == 0 and itime != 0: tmno[written:itime, :, :] = data written = itime # read the time values by parsing the filename year = int(match.group(2)) mon = int(match.group(3)) day = int(match.group(4)) date = dt.datetime(year, mon, day, 0, 0, 0) print(date) dtime = (date-basedate).total_seconds()/86400. timeo[itime] = dtime tmn_path = os.path.join(root, f) print(tmn_path) tmn = gdal.Open(tmn_path) a = tmn.ReadAsArray() # data data[itime%3, :, :] = a itime = itime+1 nco.close() From __peter__ at web.de Thu Jan 14 11:52:14 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Jan 2016 17:52:14 +0100 Subject: Stop writing Python 4 incompatible code References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5696f3c6$0$1583$c3e8da3$5496439d@news.astraweb.com> <20160114084722.5f92f2c2@imp> <20160114104714.4cbbf565@imp> Message-ID: D'Arcy J.M. Cain wrote: > On Thu, 14 Jan 2016 16:32:46 +0100 > Peter Otten <__peter__ at web.de> wrote: >> >> > Or we'll be hit by a big rock from space. >> >> Sounds like a plan. >> > Which one? Number 9? >> >> Hm, I didn't expect this question... >> >> plans[-1], most certainly. > > Hmm. Am I being too subtle or...? AOL > from OuterSpace import plan > print(plan[9]) > > If that's still too subtle: > https://en.wikipedia.org/wiki/Plan_9_from_Outer_Space OK -- this joke is no more. It has ceased to be. It's expired and gone to meet its maker. This is a late joke. It's a stiff. Bereft of life, it rests in peace. If you hadn't nailed it to the perch, it would be pushing up the daisies. It's rung down the curtain and joined the choir invisible. This is an ex-joke. ;) From rosuav at gmail.com Thu Jan 14 12:41:00 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Jan 2016 04:41:00 +1100 Subject: Stop writing Python 4 incompatible code In-Reply-To: <7df87f88-b63d-4cc2-95a9-075313d72537@googlegroups.com> References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> <6e0f3ba0-750d-4f57-afcc-238b85779948@googlegroups.com> <7df87f88-b63d-4cc2-95a9-075313d72537@googlegroups.com> Message-ID: On Fri, Jan 15, 2016 at 2:30 AM, Rick Johnson wrote: > (3) After Python3 came along, the Python community has > become fractured, and the Python code base has become > fractured, and the general public consensus is that Python > is on its way to extinction (FACT!) Prove this. Find "general public consensus" that Python is dead. And then, imitate rats and abandon this sinking ship. I decided to give 3D modelling a go, after watching some amazing work done on Twitch.tv. A lot of people recommend Maya, but I'd rather use GPL software than proprietary (particularly when the latter has a thousands-of-dollars price tag), so I grabbed Blender. Anyone want to hazard a guess as to the language Blender uses for scripting, expression evaluation, and so on? ChrisA From Brandon.Lee at netapp.com Thu Jan 14 12:42:54 2016 From: Brandon.Lee at netapp.com (Lee, Brandon) Date: Thu, 14 Jan 2016 17:42:54 +0000 Subject: ERROR: IDLEs subprocesses did not make a connection... Message-ID: <825ac00af58849b3806bb27b5f02dd33@hioexcmbx01-prd.hq.netapp.com> Hello! I am running into the following error and need some guidance. Please see the screenshots of the error, the files I currently have in the /python directory. As well as a link to a troubleshooting post on 'stackoverflow'. Thank you! -Brandon http://stackoverflow.com/questions/15888186/cant-run-python-via-idle-from-explorer-2013-idles-subprocess-didnt-make-c [cid:image001.png at 01D14EBF.7BCEB740] [cid:image009.png at 01D14EC0.7875ABC0] Best Regards, Brandon Lee Professional Services Delivery | SMC Softlayer Resident NetApp 469-631-5429 Mobile brandon.lee at netapp.com [NetApp honored for 13 consecutive years! FORTUNE's 100 Best Companies to Work For(r) 2015] [Facebook] [Twitter] [Linked In] [YouTube] [Slideshare] [Community] #netapp www.parsintl.com/web/Fortune100BestCreditNotice2015.html From rantingrickjohnson at gmail.com Thu Jan 14 13:00:31 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 14 Jan 2016 10:00:31 -0800 (PST) Subject: When I need classes? In-Reply-To: <5695e025$0$11113$c3e8da3@news.astraweb.com> References: <34aa811c-433d-4f8a-90e0-9dd768460415@googlegroups.com> <5695e025$0$11113$c3e8da3@news.astraweb.com> Message-ID: On Tuesday, January 12, 2016 at 11:27:23 PM UTC-6, Steven D'Aprano wrote: > On Wednesday 13 January 2016 14:36, Rustom Mody wrote: > > > 1. Python the LANGUAGE, is rather even-handed in paradigm choice: > > Choose OO, imperative, functional or whatever style pleases/suits > > you 2. Python LIBRARIES however need to make committing choices. > > Users of those then need to align with these. > > I don't think that second one is necessarily correct. Look at the > random module: it is based on an OOP design, with classes > random.Random and random.SystemRandom doing the real work. But most > people don't use them directly, they use the procedural interface > random.random, random.choice, random.seed etc. Of course, because these "procedural interfaces" are the most convenient (in this case). Obviously that's what Rustom was pointing out: "utilize the most convenient aspects of the interface" to get the job done. If you juxtapose the "interface of starting an automobile engine" with the "interface of the random module", you could say that the convenience of the ignition switch is like the convenience of the three functions "random.random, random.choice, and random.seed", and that, the inconvenience of crawling under the vehicle and utilizing a metal *OBJECT* (like a screwdriver) to arc the two contacts on the starter, is much the same as utilizing the random.Random object -- both may achieve the same end goal, but one "interface" happens to be more convenient than the other. In this case, the procedural interface, and not the OOP interface -- but this is not always the case! Some functionalities cannot be reduced to the "gleeful convenience" of a single procedure, at least, not without sacrificing too much control! Not only will you need to wield the power of OOP to *EXTEND* a "general functionally" into a more "specific form", but also when you need a "reusable package" of procedures and (their shared data) which can *ONLY* be modeled "sanely" by utilizing the OOP paradigm! For instance, you can write Tkinter[1] GUI code in a procedural form, utilizing the classes that are made available to you, but for anything more than the most simplistic "toy GUI", i would highly suggest against it! ============================================================ REFERENCES: ============================================================ [1] Tkinter is used as an example here because it is a primitive GUI library that does not include many of the controls that modern GUI interfaces demand. For any advanced usage, a programmer would be forced to create his *OWN* controls, and to do so "proceduraly", would result in an unmanageable nightmare. In order to achieve maintainability, inevitably, you end up utilizing the *SAME* modular design techniques of OOP! So the question begs: Why not use OOP in the first place? I am never without amazement as to the lengths people will go to excuse their "nostalgic clinging"! From rantingrickjohnson at gmail.com Thu Jan 14 13:40:03 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 14 Jan 2016 10:40:03 -0800 (PST) Subject: Stop writing Python 4 incompatible code In-Reply-To: References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> <6e0f3ba0-750d-4f57-afcc-238b85779948@googlegroups.com> <7df87f88-b63d-4cc2-95a9-075313d72537@googlegroups.com> Message-ID: <0100391c-2282-4c3a-98a9-e843eae31a8f@googlegroups.com> On Thursday, January 14, 2016 at 11:41:21 AM UTC-6, Chris Angelico wrote: > Prove this. Find "general public consensus" that Python is > dead. And then, imitate rats and abandon this sinking > ship. I don't need to "imitate" anything, it has already begun. > I decided to give 3D modelling a go, after watching some > amazing work done on Twitch.tv. A lot of people recommend > Maya, but I'd rather use GPL software than proprietary > (particularly when the latter has a thousands-of-dollars > price tag), so I grabbed Blender. Anyone want to hazard a > guess as to the language Blender uses for scripting, > expression evaluation, and so on? Blender is a nice freeware modeling program, and is great for organic modeling, animations, photo realistic rendering, game creation, and yes, exposes a Pyhton API -- but what is your point? The Python scripting features have been a part of Blender for many years, back when Python3 was just a "innocent mis-folded programming protein" rotting holes in the BDFL's pre-frontal cortex. The existence of Python3 in the wild, is merely evidence that the original PrP has replicated exponentially. From irmen.NOSPAM at xs4all.nl Thu Jan 14 14:01:39 2016 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Thu, 14 Jan 2016 20:01:39 +0100 Subject: problem In-Reply-To: References: Message-ID: <5697f08f$0$23822$e4fe514c@news.xs4all.nl> On 14-1-2016 16:53, Shivam Gupta wrote: > Hello, > > I am using python 3.5.1 on my windows 8.1. The problem is that whenever i > save any file any after that when i run it the screen just close > immediately after i double click on python file. > > Thank you. > That's not a python thing, it's the way the windows console behaves. As soon as any script or console command it executes finishes, it closes. Either put something like this at the end of your python scripts, to keep the console open: raw_input("press enter to exit...") or run them from an existing console prompt instead of clicking on them. Irmen From paul.hermeneutic at gmail.com Thu Jan 14 15:16:28 2016 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Thu, 14 Jan 2016 13:16:28 -0700 Subject: Stop writing Python 4 incompatible code In-Reply-To: <0100391c-2282-4c3a-98a9-e843eae31a8f@googlegroups.com> References: <5695fd0e$0$11119$c3e8da3@news.astraweb.com> <0529e7d6-0de1-4e38-9a19-2b5ed1ecc39f@googlegroups.com> <5696e77e$0$1597$c3e8da3$5496439d@news.astraweb.com> <5d7a5bb1-f229-4755-a0bf-dd3ad9d99fba@googlegroups.com> <6e0f3ba0-750d-4f57-afcc-238b85779948@googlegroups.com> <7df87f88-b63d-4cc2-95a9-075313d72537@googlegroups.com> <0100391c-2282-4c3a-98a9-e843eae31a8f@googlegroups.com> Message-ID: I am confident that in a few years there will be sufficient new developments in language design that some degree of backward compatibility would be worth dropping in order to provide greater capabilities. If it needs to fork and become another language, that's OK. From srkunze at mail.de Thu Jan 14 15:17:35 2016 From: srkunze at mail.de (Sven R. Kunze) Date: Thu, 14 Jan 2016 21:17:35 +0100 Subject: issues In-Reply-To: <000001d14e29$49aaa1c0$dcffe540$@gmail.com> References: <000001d14e29$49aaa1c0$dcffe540$@gmail.com> Message-ID: <5698025F.7030700@mail.de> Hi Gert, just upgrade to 5.03. Best, Sven On 13.01.2016 18:38, Gert F?rster wrote: > Ladies, Gentlemen, > > using the PyCharm Community Edition 4.5.4, with Python-3-5-1-amd64.exe, > there is constantly a ?Repair?-demand. This is ?successful? when executed. > Without execution, there results an ?Error code 1602? error. Please help me? > > > > Sincerely Yours, > > Gert F?rster > > > From renting at astron.nl Thu Jan 14 15:22:23 2016 From: renting at astron.nl (Adriaan Renting) Date: Thu, 14 Jan 2016 21:22:23 +0100 Subject: ignoring or replacing white lines in a diff In-Reply-To: <5697f08f$0$23822$e4fe514c@news.xs4all.nl> References: <5697f08f$0$23822$e4fe514c@news.xs4all.nl> Message-ID: <5698118F0200001B0003B68D@gwsmtp1.astron.nl> Maybe someone here has a clue what is going wrong here? Any help is appreciated. I'm writing a regression test for a module that generates XML. I'm using diff to compare the results with a pregenerated one from an earlier version. I'm running into two problems: The diff doesn't seem to behave properly with the -B option. (diff (GNU diffutils) 2.8.1 on OSX 10.9) Replacing -B with -I '^[[:space:]]*$' fixes it on the command line, which should be exactly the same according to: http://www.gnu.org/software/diffutils/manual/html_node/Blank-Lines.html#Blank-Lines (for Python problem continue below) MacRenting 21:00-159> diff -w -B test.xml xml/Ticket_6923.xml 3,5c3,5 < 2.15.0 <