help with an error msg please
I'm stumped by this: $ PYTHONPATH= python except Traceback (most recent call last): File "except", line 7, in except getopt.error, msg: AttributeError: 'module' object has no attribute 'error' The program is: $ cat except #!/usr/bin/env python import getopt try: opts, args = getopt.getopt (sys.argv[1:], "t:") except getopt.error, msg: raise "Usage: some other way", msg what am I doing wrong? -- https://mail.python.org/mailman/listinfo/python-list
Re: help with an error msg please
> $ PYTHONPATH= python except > Traceback (most recent call last): > File "except", line 7, in > except getopt.error, msg: > AttributeError: 'module' object has no attribute 'error' > > > The program is: > > $ cat except > #!/usr/bin/env python > > import getopt > > try: > opts, args = getopt.getopt (sys.argv[1:], "t:") > except getopt.error, msg: > raise "Usage: some other way", msg I guess you are using Python 2. In any case you should import sys if you want to access sys.argv. Lutz signature.asc Description: OpenPGP digital signature -- https://mail.python.org/mailman/listinfo/python-list
Re: help with an error msg please
On 5/14/17, Charles T. Smith wrote: > I'm stumped by this: > $ PYTHONPATH= python except > Traceback (most recent call last): > File "except", line 7, in > except getopt.error, msg: > AttributeError: 'module' object has no attribute 'error' > > > The program is: > > $ cat except > #!/usr/bin/env python > > import getopt > > try: > opts, args = getopt.getopt (sys.argv[1:], "t:") > except getopt.error, msg: > raise "Usage: some other way", msg > > what am I doing wrong? Did you create getopt.py in your working directory? If so then try to rename it. PL. -- https://mail.python.org/mailman/listinfo/python-list
Re: help with an error msg please
On 5/14/17, Pavol Lisy wrote: > On 5/14/17, Charles T. Smith wrote: >> I'm stumped by this: > >> $ PYTHONPATH= python except >> Traceback (most recent call last): >> File "except", line 7, in >> except getopt.error, msg: >> AttributeError: 'module' object has no attribute 'error' >> >> >> The program is: >> >> $ cat except >> #!/usr/bin/env python >> >> import getopt >> >> try: >> opts, args = getopt.getopt (sys.argv[1:], "t:") >> except getopt.error, msg: >> raise "Usage: some other way", msg >> >> what am I doing wrong? > > Did you create getopt.py in your working directory? If so then try to > rename it. > > PL. And remove getopt.pyc! PL. -- https://mail.python.org/mailman/listinfo/python-list
Re: help with an error msg please
On Sun, 14 May 2017 15:30:52 +0200, Pavol Lisy wrote: > On 5/14/17, Charles T. Smith wrote: >> I'm stumped by this: ... > Did you create getopt.py in your working directory? If so then try to > rename it. > > PL. That was it! Not in my working directory, but in the directory where the test program was residing! ~/eg/python/unicode-read data.csv It was in ~/eg/python Thank you! -- https://mail.python.org/mailman/listinfo/python-list
Overriding methods on a per instance basis
It is common to add an attribute to a class, then over-ride it in the instance: class Document: pagesize = "A4" def __init__(self, pagesize): self.pagesize = pagesize A little-known fact, not appreciated by users of less powerful OOP languages: Python supports per-instance customized methods too, since methods are just attributes. py> class Parrot: ... name = "Polly" ... def speak(self): ... return "%s wants a cracker!" % self.name ... py> petey = Parrot() py> petey.speak() 'Polly wants a cracker!' We can shadow petey's "speak" method with a callable: py> petey.speak = lambda: "Who's a cheeky boy then!" py> petey.speak() "Who's a cheeky boy then!" Notice that using a regular function means that we cannot access "self". But all is not lost! We can do so by using a method object bound to the instance: py> from types import MethodType py> petey.speak = MethodType( ... lambda self: "%s is a cheeky boy!" % self.name, ... petey) py> petey.speak() 'Polly is a cheeky boy!' This can be considered a form of the Strategy design pattern. From Wikipedia: ... the strategy pattern (also known as the policy pattern) is a behavioural software design pattern that enables an algorithm's behavior to be selected at runtime. The strategy pattern: - defines a family of algorithms, - encapsulates each algorithm, and - makes the algorithms interchangeable within that family. https://en.wikipedia.org/wiki/Strategy_pattern the major difference being is that in the Strategy pattern there is not necessarily a default implementation provided by the class: class Dog: pass rover = Dog() butch = Dog() laddie = Dog() rover.do_trick = fetch_stick butch.do_trick = play_dead laddie.do_trick = solve_world_hunger -- Steve Emoji: a small, fuzzy, indistinct picture used to replace a clear and perfectly comprehensible word. -- https://mail.python.org/mailman/listinfo/python-list
How to install Python package from source on Windows
I want to install the recordclass package: https://pypi.python.org/pypi/recordclass But they've only released wheel files for two platforms, macosx and win_amd64, neither of which will install on my system. I need win_x86 or intel_x86, which they don't provide. The only alternative to pip install that I know of is to install from source, and the source I need is at: https://bitbucket.org/intellimath/recordclass/src I've never done this, so any help would be appreciated. Deborah -- https://mail.python.org/mailman/listinfo/python-list
Re: Survey: improving the Python std lib docs
On Saturday, May 13, 2017 at 3:39:52 PM UTC-7, Terry Reedy wrote: > On 5/13/2017 1:23 PM, jeanbigbo...@gmail.com wrote: > > > Thank you for bringing up this important topic. As an occasional Python > > user, I find that Python documentation is all over the usability map - some > > great, some difficult. The Python docs have been at best a starting point. > > I usually need to go to other sites like this group, StackOverflow, and a > > blog or two to understand how to do something. After I learn to do that > > one thing, I am not any more independent, self-reliant, or able to > > contribute back to the community. Although Matlab gets a lot of grief in > > the open source community, its documentation is concise, complete, and > > self-contained. > > Thank you for writing a response focused on your experience with the docs. ... [ trimmed ] ... I appreciate your prompt reply. I would like to 'aggregate' my thoughts along a couple of items you mentioned. 1) Old documentation (e.g. Classes referencing Modula-3) and opening trackers. The Classes and Pkgutil docs are representative of a lot of the Python docs that fall into the hard-to-use category. I would have to file many trackers to cover problems I have had. That's not very grateful in context of an open source tool. Discussing this at a top-level as we are doing here I think is fair game. This is something that needs to be addressed comprehensively or possibly intentionally left alone. If the original doc suite was written 20 years ago, it may not be possible or practical to get it caught up when the language evolves so quickly. The right answer might be to "leave it be" and accept that newer methods of Q&A have to take over. This is true even of some paid packages - to get help with Microsoft, avoid the documentation wherever possible. This approach has its problems especially for corporate users. They're often behind firewalls and can't participate. 2) The blog post: I think the post author's attempt was a good, honest try and an example of what the documentation suite might become. I agree it is hard to come up with good, tested examples across multiple platforms and that's where some paid packages have an advantage. I think the Python community could go a little easier on non-free tools. Trying things and seeing what works is good in many cases but there isn't the time for that in a lot of workplaces, especially those that bill services by the hour. --- JBB -- https://mail.python.org/mailman/listinfo/python-list
Re: How to install Python package from source on Windows
On Sun, May 14, 2017 at 8:46 PM, Deborah Swanson wrote: > I want to install the recordclass package: > https://pypi.python.org/pypi/recordclass > > But they've only released wheel files for two platforms, macosx and > win_amd64, neither of which will install on my system. I need win_x86 or > intel_x86, which they don't provide. The tag for 32-bit Windows is "win32". The PyPI page has win32 wheels for 2.7-3.5. If you're using 3.6, you'll have to build from source. The package has a single C extension without external dependencies, so it should be a straight-forward build if you have Visual Studio 2015+ installed with the C/C++ compiler for x86. Ideally it should work straight from pip. But I tried and it failed in 3.6.1 due to the new PySlice_GetIndicesEx macro. Apparently MSVC doesn't like preprocessor code like this in memoryslots.c: #if PY_MAJOR_VERSION >= 3 if (PySlice_GetIndicesEx(item, Py_SIZE(self), #else if (PySlice_GetIndicesEx((PySliceObject*)item, Py_SIZE(self), #endif &start, &stop, &step, &slicelength) < 0) { It fails with a C1057 error (unexpected end of file in macro expansion). The build will succeed if you copy the common line with `&start` to each case and comment out the original line, such that the macro invocation isn't split across an #if / #endif. This is an ugly consequence of making PySlice_GetIndicesEx a macro. I wonder if it could be written differently to avoid this problem. -- https://mail.python.org/mailman/listinfo/python-list
OT footers (was Rosetta: )
On Monday, May 15, 2017 at 1:23:41 AM UTC+5:30, breamerboy wrote: > On Sunday, May 14, 2017 at 2:44:33 AM UTC+1, Steve D'Aprano wrote: > > On Sun, 14 May 2017 07:03 am, Jan van den Broek wrote: > > > > > On 2017-05-13, Robert L. < wrote: > > > > > > [Schnipp] > > > > > >> def build_permutations things > > >> if block_given? > > >> things.permutation.select{|x| yield x} > > >> else > > >> things.permutation.to_a > > >> end > > >> end > > > > > > I fail to recognize the Python-version. > > > > That is because it isn't Python, it is Ruby. > > > > Ironically given Robert's "No_spamming" fake email address, he is a spammer. > > He is posting Ruby code to the Python list as an excuse for sending his > > vile, anti-Semitic and racist quotes. (Half of them are lies, the other > > half are out-of-context half-truths.) > > > > And the coward doesn't even have the courage to stand behind his > > convictions: he doesn't even use his full name. > > > > "Robert L" No_Spamming@fake-address thinks he is spreading his message of > > White Power, but all he is doing is showing what a cowardly, hypocritical, > > dumb-arse spammer he is. > > I report all of his posts on gg as hateful or violent content. Does that help? Does anything change? > In the UK we've been conned into leaving the EU in an advisory referendum > that has been described by a Professor who specialises in EU law as won by > using "dishonesty on an industrial scale". Instead of past-tense — conned — please see what they are now up to: https://www.theguardian.com/politics/2017/may/13/millionaire-brexit-donor-targets-remain-mps And why: https://www.theguardian.com/business/2017/mar/22/uk-millionaires-brexit-eu-ubs-wealth-management Speaking for myself: If someone starts a kickstarter project to shore-up Corbyn, I would happily send a few pennies [And I am neither British nor European] > What do you expect of the extreme right wing, honesty? Here are some left-wing utopias. Honest? You like these? https://medium.com/incerto/the-most-intolerant-wins-the-dictatorship-of-the-small-minority-3f1f83ce4e15 https://youtu.be/QuSc_U5VqDQ https://www.facebook.com/seen.everything/videos/1154800587957810/ -- https://mail.python.org/mailman/listinfo/python-list
RE: How to install Python package from source on Windows
eryk sun wrote, on Sunday, May 14, 2017 7:15 PM > > On Sun, May 14, 2017 at 8:46 PM, Deborah Swanson > wrote: > > I want to install the recordclass package: > > https://pypi.python.org/pypi/recordclass > > > > But they've only released wheel files for two platforms, macosx and > > win_amd64, neither of which will install on my system. I > need win_x86 > > or intel_x86, which they don't provide. > > The tag for 32-bit Windows is "win32". The PyPI page has > win32 wheels for 2.7-3.5. I'll look at the PyPi page again, it's true I skipped over the Python2 builds, but if that turns out tobe my best option, I can rewrite my project for Python2. > If you're using 3.6, you'll have to build from source. The > package has a single C extension without external > dependencies, so it should be a straight-forward build if you > have Visual Studio 2015+ installed with the C/C++ compiler > for x86. Unfortunately I don't have Visual Studio 2015+ installed and I can't install it on Windows XP SP2 (plus I really don't want to). Probably I should have mentioned that, but I didn't know I'd need to build C/C++. > Ideally it should work straight from pip. But I > tried and it failed in 3.6.1 due to the new > PySlice_GetIndicesEx macro. Apparently MSVC doesn't like > preprocessor code like this in > memoryslots.c: > > #if PY_MAJOR_VERSION >= 3 > if (PySlice_GetIndicesEx(item, Py_SIZE(self), > #else > if (PySlice_GetIndicesEx((PySliceObject*)item, > Py_SIZE(self), > #endif > &start, &stop, &step, > &slicelength) < 0) { > > It fails with a C1057 error (unexpected end of file in macro > expansion). The build will succeed if you copy the common > line with `&start` to each case and comment out the original > line, such that the macro invocation isn't split across an > #if / #endif. This is an ugly consequence of making > PySlice_GetIndicesEx a macro. I wonder if it could be written > differently to avoid this problem. There isn't any solution or workaround for me if building C/C++ is required. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to install Python package from source on Windows
On Mon, May 15, 2017 at 4:19 AM, Deborah Swanson wrote: > Unfortunately I don't have Visual Studio 2015+ installed and I can't > install it on Windows XP SP2 (plus I really don't want to). Probably I > should have mentioned that, but I didn't know I'd need to build C/C++. 3.5+ doesn't work in XP, so the highest version you can run is 3.4. For 32-bit, install recordclass-0.4.3-cp34-cp34m-win32.whl. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to install Python package from source on Windows
On Mon, May 15, 2017 at 2:26 PM, eryk sun wrote: > On Mon, May 15, 2017 at 4:19 AM, Deborah Swanson > wrote: >> Unfortunately I don't have Visual Studio 2015+ installed and I can't >> install it on Windows XP SP2 (plus I really don't want to). Probably I >> should have mentioned that, but I didn't know I'd need to build C/C++. > > 3.5+ doesn't work in XP, so the highest version you can run is 3.4. > For 32-bit, install recordclass-0.4.3-cp34-cp34m-win32.whl. The best way to install this sort of thing is using pip. You should have it with your Python 3.4, and it'll do all the work of figuring out which one to download. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
RE: How to install Python package from source on Windows
Chris Angelico wrote, on Sunday, May 14, 2017 9:56 PM > > On Mon, May 15, 2017 at 2:26 PM, eryk sun wrote: > > On Mon, May 15, 2017 at 4:19 AM, Deborah Swanson > > wrote: > >> Unfortunately I don't have Visual Studio 2015+ installed > and I can't > >> install it on Windows XP SP2 (plus I really don't want > to). Probably > >> I should have mentioned that, but I didn't know I'd need to build > >> C/C++. > > > > 3.5+ doesn't work in XP, so the highest version you can run is 3.4. > > For 32-bit, install recordclass-0.4.3-cp34-cp34m-win32.whl. > > The best way to install this sort of thing is using pip. You > should have it with your Python 3.4, and it'll do all the > work of figuring out which one to download. > > ChrisA > -- That was easy to try, "pip install recordclass", but it failed: C:\Programs\Coding\Anaconda3\Scripts>pip install recordclass You are using pip version 7.0.3, however version 9.0.1 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' comm and. Collecting recordclass Downloading recordclass-0.4.3.tar.gz Installing collected packages: recordclass Running setup.py install for recordclass Complete output from command C:\Programs\Coding\Anaconda3\python.exe -c "imp ort setuptools, tokenize;__file__='E:\\temp\\pip-build-zhximvpd\\recordclass\\se tup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\ r\n', '\n'), __file__, 'exec'))" install --record E:\temp\pip-r7ky4fv1-record\in stall-record.txt --single-version-externally-managed --compile: running install running build running build_py creating build creating build\lib.win32-3.4 creating build\lib.win32-3.4\recordclass copying lib\recordclass\record.py -> build\lib.win32-3.4\recordclass copying lib\recordclass\__init__.py -> build\lib.win32-3.4\recordclass creating build\lib.win32-3.4\recordclass\test copying lib\recordclass\test\test_memoryslots.py -> build\lib.win32-3.4\reco rdclass\test copying lib\recordclass\test\test_record.py -> build\lib.win32-3.4\recordcla ss\test copying lib\recordclass\test\__init__.py -> build\lib.win32-3.4\recordclass\ test running build_ext building 'recordclass.memoryslots' extension error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat). Command "C:\Programs\Coding\Anaconda3\python.exe -c "import setuptools, tokenize ;__file__='E:\\temp\\pip-build-zhximvpd\\recordclass\\setup.py';exec(com pile(get attr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, ' exec'))" install --record E:\temp\pip-r7ky4fv1-record\install-record.txt --singl e-version-externally-managed --compile" failed with error code 1 in E:\temp\pip- build-zhximvpd\recordclass Looks like lack of Visual C++ tripped me up again. Strange how Python code can't install with purely Python code. I don't plan to have Visual anything on Linux either. It might be possible to do something with lib\recordclass\test\test_record.py -> build\lib.win32-3.4\recordclass\test and lib\recordclass\record.py -> build\lib.win32-3.4\recordclass, but I wouldn't know what. Maybe I should go back to Python 2.7.8 for this. Deborah -- https://mail.python.org/mailman/listinfo/python-list
RE: How to install Python package from source on Windows
eryk sun wrote, on Sunday, May 14, 2017 9:27 PM > > On Mon, May 15, 2017 at 4:19 AM, Deborah Swanson > wrote: > > Unfortunately I don't have Visual Studio 2015+ installed > and I can't > > install it on Windows XP SP2 (plus I really don't want to). > Probably I > > should have mentioned that, but I didn't know I'd need to > build C/C++. > > 3.5+ doesn't work in XP, so the highest version you can run > is 3.4. For 32-bit, install recordclass-0.4.3-cp34-cp34m-win32.whl. > I have 3.4.3 installed. That was the last build it was possible to get out of Anaconda for XP, and there's lots of goodies I have to do without or work around. But, "pip install recordclass-0.4.3-cp34-cp34m-win32.whl" fails with: "recordclass-0.4.3-cp34-cp34m-win32.whl is not a supported wheel on this platform." Probably because it wants to use C++, or Visual something (higher than version 4). Unless you know how I can install recordclass without using pip, and recordclass-0.4.3-cp34-cp34m-win32.whl won't fail if it can't find Visual C++. Again, maybe I should go back to Python 2 for this. Deborah -- https://mail.python.org/mailman/listinfo/python-list
Re: How to install Python package from source on Windows
On Mon, May 15, 2017 at 4:14 PM, Deborah Swanson wrote: > Looks like lack of Visual C++ tripped me up again. > > Strange how Python code can't install with purely Python code. I don't > plan to have Visual anything on Linux either. > > It might be possible to do something with > > lib\recordclass\test\test_record.py -> > build\lib.win32-3.4\recordclass\test and > > lib\recordclass\record.py -> build\lib.win32-3.4\recordclass, > > but I wouldn't know what. > > Maybe I should go back to Python 2.7.8 for this. That's the thing, though: it is NOT purely Python code. The module you're trying to install is implemented in C, which is why it needs a C compiler. It may be that Anaconda is breaking the wheels, which means that you can't use the precompiled binaries; you could try using conda to install the module. Otherwise, try installing vanilla CPython 3.4, and see if that helps. Or get yourself off XP, because it's not supported any more anyway. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to install Python package from source on Windows
On Mon, May 15, 2017 at 4:28 PM, Deborah Swanson wrote: > > Again, maybe I should go back to Python 2 for this. Won't help. The same problems will exist. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
RE: How to install Python package from source on Windows
eryk sun wrote on Sunday, May 14, 2017 9:27 PM > > On Mon, May 15, 2017 at 4:19 AM, Deborah Swanson > wrote: > > Unfortunately I don't have Visual Studio 2015+ installed > and I can't > > install it on Windows XP SP2 (plus I really don't want to). > Probably I > > should have mentioned that, but I didn't know I'd need to > build C/C++. > > 3.5+ doesn't work in XP, so the highest version you can run > is 3.4. For 32-bit, install recordclass-0.4.3-cp34-cp34m-win32.whl. > Where did you find recordclass-0.4.3-cp34-cp34m-win32.whl? There weren't any win32 builds on https://pypi.python.org/pypi/recordclass. Maybe I can find an earlier 3 build that won't demand Visual C++. -- https://mail.python.org/mailman/listinfo/python-list
RE: How to install Python package from source on Windows
Chris Angelico wrote on Sunday, May 14, 2017 11:30 PM > > On Mon, May 15, 2017 at 4:28 PM, Deborah Swanson > wrote: > > > > Again, maybe I should go back to Python 2 for this. > > Won't help. The same problems will exist. > > ChrisA > Good to know. Maybe I just won't be able to try recordclass until I get Linux set up one way or another. Right now it's more important to me to spend the few hours a day I have making progress in Python. (Now, if I can figure out how to make gettattr work in this one namedtuple problem, I won't need anything like recordclass. I've converted three more Excel spreadsheets to Python, but it's tricky working with namedtuples when you want to group rows or take n colomns at a time. I've done it, but this one is really tough.) -- https://mail.python.org/mailman/listinfo/python-list