Download issue.
Dear Group, I am using Python on Windows 7 SP-1 (64 bit). I have two versions of Python installed 2.7 and 3.2. I want to install networkx in both. How may I do that? If any one may kindly let me know. Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL questions: still supported? Problems on 2.7 for win? alternatives?
Gelonida N gmail.com> writes: > I wondered whether some of you have a little more insight into what's > going on with PIL. AFAIK the latest PIL stuff lives here: hg.effbot.org -- http://mail.python.org/mailman/listinfo/python-list
terminate called after throwing an instance of 'CABRTException'
I've noticed a strange thing with python lately: Python 2.6.2 (r262:71600, Aug 21 2009, 12:23:57) [GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def f(): print x ... >>> f() terminate called after throwing an instance of 'CABRTException' Traceback (most recent call last): File "", line 1, in File "", line 1, in f NameError: global name 'x' is not defined >>> Clearly there is a NameError because x is not defined, but what the hell is the "terminate . 'CABRTException'" business? I guess it has to do with abrt but abrt is not running on my system at all. Also, if I run python2.7 with the above code I don't get the CABRTException stuff. What is really strange is that I have all sorts of recent files in /var/cache/abrt/pyhook-* indicating that somehow abrt is doing things even though it is not running, for instance chkconfig --list | grep abrt shows it off in all run levels. What's going on? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: Download issue.
http://www.pip-installer.org/en/latest/index.html -- Ritchie Flick -- http://mail.python.org/mailman/listinfo/python-list
Re: terminate called after throwing an instance of 'CABRTException'
Daniel Fetchinson wrote: > I've noticed a strange thing with python lately: > > > > Python 2.6.2 (r262:71600, Aug 21 2009, 12:23:57) > [GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. def f(): print x > ... f() > terminate called after throwing an instance of 'CABRTException' > Traceback (most recent call last): > File "", line 1, in > File "", line 1, in f > NameError: global name 'x' is not defined > > > > Clearly there is a NameError because x is not defined, but what the > hell is the "terminate . 'CABRTException'" business? > > I guess it has to do with abrt but abrt is not running on my system at > all. Also, if I run python2.7 with the above code I don't get the > CABRTException stuff. What is really strange is that I have all sorts > of recent files in /var/cache/abrt/pyhook-* indicating that somehow > abrt is doing things even though it is not running, for instance > chkconfig --list | grep abrt shows it off in all run levels. > > What's going on? No idea, but I'd have a look at sys.modules, and if >>> import sys >>> [name for name in sys.modules if "abrt" in name.lower()] [] gives a non-empty result I'd investigate where the culprit is imported -- /usr/lib/python2.6/sitecustomize.py would be the obvious candidate. -- http://mail.python.org/mailman/listinfo/python-list
Re: Download issue.
On 10/02/2012 04:43 AM, [email protected] wrote: > Dear Group, > > I am using Python on Windows 7 SP-1 (64 bit). > > I have two versions of Python installed 2.7 and 3.2. > > I want to install networkx in both. > > How may I do that? > > If any one may kindly let me know. > Doing a search for networkx, there are several. But the most likely candidate for what you might mean is: http://pypi.python.org/pypi/networkx/ from that I see that both 2.7 and 3.2 are supported, and follow a link to: http://networkx.lanl.gov/ then I look for the documentation, which is here: http://networkx.lanl.gov/contents.html After that, I don't know what to tell you, as I don't use the package. They do have a discussion group, however. I don't know its real name, as all they list on the pages I saw was a google-groups link. If you don't understand python egg files, and how to install them, you might start with: http://peak.telecommunity.com/DevCenter/EasyInstall or http://www.pip-installer.org/en/latest/index.html -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: terminate called after throwing an instance of 'CABRTException'
>> I've noticed a strange thing with python lately: >> >> >> >> Python 2.6.2 (r262:71600, Aug 21 2009, 12:23:57) >> [GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. > def f(): print x >> ... > f() >> terminate called after throwing an instance of 'CABRTException' >> Traceback (most recent call last): >> File "", line 1, in >> File "", line 1, in f >> NameError: global name 'x' is not defined > >> >> >> >> Clearly there is a NameError because x is not defined, but what the >> hell is the "terminate . 'CABRTException'" business? >> >> I guess it has to do with abrt but abrt is not running on my system at >> all. Also, if I run python2.7 with the above code I don't get the >> CABRTException stuff. What is really strange is that I have all sorts >> of recent files in /var/cache/abrt/pyhook-* indicating that somehow >> abrt is doing things even though it is not running, for instance >> chkconfig --list | grep abrt shows it off in all run levels. >> >> What's going on? > > No idea, but I'd have a look at sys.modules, and if > import sys [name for name in sys.modules if "abrt" in name.lower()] > [] > > gives a non-empty result I'd investigate where the culprit is imported -- > /usr/lib/python2.6/sitecustomize.py would be the obvious candidate. Indeed! Thanks a lot, /usr/lib/python2.6/site-packages/sitecustomize.py was created by the package abrt-addon-python (at least this is the fedora name) and so it was activated by python itself completely independently from abrt (which was not running). Now I removed all packages called abrt-* and the problem is gone. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL questions: still supported? Problems on 2.7 for win? alternatives?
On 2012-10-02 09:26:56 +, WhisperingWally said: Gelonida N gmail.com> writes: I wondered whether some of you have a little more insight into what's going on with PIL. AFAIK the latest PIL stuff lives here: hg.effbot.org Certainly true, though somewhat meaningless in the current context of "what's going on with PIL?"[1]. The latest Pillow (PIL fork) lives here: - https://github.com/python-imaging/Pillow And if folks commit meaningful changes there, we'll get releases out as needed. In other words, you are welcome and encouraged to explore all your options. And if it helps, you can affect the future of PIL in a meaningful way via Pillow. Alex [1] The last commit to: http://hg.effbot.org/pil-2009-raclette was in 2011. Based on that information, the answer would appear to be "nothing", which is why Pillow exists. -- Alex Clark · http://aclark.net -- http://mail.python.org/mailman/listinfo/python-list
RE: Fastest web framework
In order to provide more reliable benchmark, I get rid of application server and network boundary. As a result I simulated a valid WSGI request and isolated calls just to the web framework alone. Also I found interesting to take a look at total number of calls and unique functions used by corresponding web framework. The post has been updated: http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html Isolated benchmark source code is here: https://bitbucket.org/akorn/helloworld/src/tip/benchmark.py I should mention several web frameworks experience huge memory leaks in this benchmark. BONUS: added benchmark for python 3.3 (for the web frameworks that support it) and plain simple WSGI application (for contrast). Comments or suggestions are welcome. Thanks. Andriy Kornatskyy > From: [email protected] > To: [email protected] > Subject: RE: Fastest web framework > Date: Sat, 29 Sep 2012 12:18:32 +0300 > CC: [email protected] > > > Tarek, > > My response inline to your: > > > You are not getting my point. What happens to weezhy or XXX framework > > when you are running it in a given stack, under heavy load ? > > let me correct you, it is wheezy.web (not `weezhy`). > > Tell me your definition of web framework heavy load. If you have one, we > can try benchmark it. > > > There are many interactions that may impact the behavior of the stack - > > most of them are in the web server itself, but they can be things in the > > framework too, depending on the architectural choice. > > The reason I choose uWSGI is due to minimal possible impact that application > server may cause. Since this component `equally influence` productivity > of each framework it can be to some degree ignored. > > > And you will not know it with an hello world app. To put it more > > bluntly, your benchmark is going to join the big pile of hello worlds > > benchmarks that are completely meaningless. > > Can not agree. This is just simple thing. Simple things should run > fast, no doubt. If you can provide a better idea as to which framework > calls to put into benchmark, I will be happy extend the benchmark case. > > > If you want to prove that weezhy is faster than another py framework, > > because, I dunno, the number of function calls are smaller ? then you > > need to isolate this and > > do a different kind of bench. > > > > Have a look at http://plope.com/pyroptimization , it's a good example > > The numbers provided in that article are incorrect. They didn't match results > from the file they provide (result.txt in each framework dir) at the time > of writing. > > I have used that idea to re-run things (isolated benchmark; report with > total time, total number of calls and number of distinct functions used). > See here: > > https://bitbucket.org/akorn/helloworld/src/tip/benchmark.py > > I will update original post a bit later (to let you comment on this). > > > Same thing for the raw speed of your templating engine - isolation is > > required. > > Improved bigtable benchmark report by adding total number of calls and > number distinct functions used: > https://bitbucket.org/akorn/wheezy.template/src/tip/demos/bigtable/bigtable.py > > Original post not updated yet. > > > One good read: > > http://blog.ianbicking.org/2010/03/16/web-server-benchmarking-we-need/ > > Sounds not so bad. It points to some specific workloads. Any attempt to > prioritize > and/or practically implement them? > > Thanks. > > Andriy -- http://mail.python.org/mailman/listinfo/python-list
unit testing class hierarchies
Greetings! I'm trying to unittest a class hierachy using Python 2.7. I have a common baseclass Base and derived classes D1 and D2 that I want to test. The baseclass in not instantiatable on its own. Now, the first approach is to have test cases TestD1 and TestD2, both derived from class TestCase: class TestD1(unittest.TestCase): def test_base(self): ... def test_r(self): ... def test_s(self): ... class TestD2(unittest.TestCase): def test_base(self): # same as above ... def test_x(self): ... def test_y(self): ... As you see, the code for test_base() is redundant, so the idea is to move it to a baseclass: class TestBase(unittest.TestCase): def test_base(self): ... class TestD1(TestBase): def test_r(self): ... def test_s(self): ... class TestD2(TestBase): def test_x(self): ... def test_y(self): ... The problem here is that TestBase is not a complete test case (just as class Base is not complete), but the unittest framework will still try to run it on its own. One way around this is to not derive class TestBase from unittest.TestCase but instead use multiple inheritance in the derived classes [1]. Maybe it's just my personal gut feeling, but I don't like that solution, because it is not obvious that this class actually needs to be combined with a TestCase class in order to function. I would rather tell the unittest framework directly that it's not supposed to consider this intermediate class as a test case, but couldn't find a way to express that clearly. How would you do this? Uli [1] in C++ I would call that a "mixin" -- http://mail.python.org/mailman/listinfo/python-list
Re: unit testing class hierarchies
[1] in C++ I would call that a "mixin" Mixins are perfectly valid Python constructs as well and are perfectly valid (imho) for this use case. On a side note, I usually append a "Mixin" suffix to my mixin classes in order to make it obvious to the reader. -- Demian Brecht @demianbrecht http://demianbrecht.github.com -- http://mail.python.org/mailman/listinfo/python-list
Re: unit testing class hierarchies
On Tue, Oct 02, 2012 at 02:27:11PM +0200, Ulrich Eckhardt wrote: > As you see, the code for test_base() is redundant, so the idea is to > move it to a baseclass: > > class TestBase(unittest.TestCase): > def test_base(self): > ... > > class TestD1(TestBase): > def test_r(self): > ... > def test_s(self): > ... > > class TestD2(TestBase): > def test_x(self): > ... > def test_y(self): > ... Could you provide more background? How do you avoid that test_base() runs in TestD1 or TestD2? To me it sounds like test_base() is actually no test. Hence, I would rather give it a catchy name like _build_base_cls(). If a method name does not start with 'test' it is not considered a test to run automatically. Does this help? Regards, Thomas Bach. -- http://mail.python.org/mailman/listinfo/python-list
Are ABCs an anti-pattern?
I don't use them anymore, but I'm curious about others opinions on this list... The more time I spend in Python, discovering what "Pythonic" code is and such, it seems that I throw away much in terms of academic learnings as far as "OOP correctness" goes. In doing so, I find that, in general, overall LOC (yes, I'm aware that this is a poor metric to judge anything on), readability and overall quality of code seems to go up. Yes, you give the user much more rope to hang themselves with making the general assumption that the user knows what they're doing, but we're all consenting adults here after all, right? ;) As an example, I initially had an OAuth 2.0 client library that was roughly 450 LOC (using ABCs, adapter patterns for the various flows, etc). Dropping this for a more "Pythonic" (at least, what my interpretation of Pythonic code is) brought the entire library down to 55 LOC. Having said that, the decline in LOC and overall grok-ability wasn't entirely due to moving away from ABCs and dropping the use of adapters, but it did have quite a bit to do with it). As such, I see ABCs as somewhat of an anti-pattern in the Python world. The concept is obviously essential in non-duck-typed language using strict OOP, but does it *really* belong in Python? -- Demian Brecht @demianbrecht http://demianbrecht.github.com -- http://mail.python.org/mailman/listinfo/python-list
Re: unit testing class hierarchies
Ulrich Eckhardt wrote: > As you see, the code for test_base() is redundant, so the idea is to > move it to a baseclass: > > class TestBase(unittest.TestCase): > def test_base(self): > ... > > class TestD1(TestBase): > def test_r(self): > ... > def test_s(self): > ... > > class TestD2(TestBase): > def test_x(self): > ... > def test_y(self): > ... > > The problem here is that TestBase is not a complete test case (just as > class Base is not complete), but the unittest framework will still try > to run it on its own. One way around this is to not derive class > TestBase from unittest. Another is to remove it from the global namespace with del TestBase -- http://mail.python.org/mailman/listinfo/python-list
Re: unit testing class hierarchies
Peter Otten wrote: > Ulrich Eckhardt wrote: >> The problem here is that TestBase is not a complete test case (just as >> class Base is not complete), but the unittest framework will still try >> to run it on its own. How exactly are you invoking the test runner? unittest? nose? You can tell the test discoverer which classes you want it to run and which ones you don't. For the unittest library, I use my own custom load_tests methods: def load_tests(loader, tests, pattern): testcases = [TestD1, TestD2] return TestSuite([loader.loadTestsFromTestCase(testcase) for testcase in testcases]) http://docs.python.org/library/unittest.html#load-tests-protocol >> One way around this is to not derive class >> TestBase from unittest. > > Another is to remove it from the global namespace with > > del TestBase Removing the class from namespace may or may not help. Consider a scenario where someone decided to be creative with the cls.__bases__ attribute. -- Fayaz Yusuf Khan Cloud architect, Dexetra SS, India fayaz.yusuf.khan_AT_gmail_DOT_com, fayaz_AT_dexetra_DOT_com +91-9746-830-823 -- http://mail.python.org/mailman/listinfo/python-list
Re: parse an environment file
On Monday 2012 October 01 08:35, Hans Mulder wrote: > AFAIK, there is no Python module that can read shell syntax. The stdlib's shlex might be that module. -- Yonder nor sorghum stenches shut ladle gulls stopper torque wet strainers. -- http://mail.python.org/mailman/listinfo/python-list
Re: Slicing iterables in sub-generators without loosing elements
On Monday, 1 October 2012 13:47:50 UTC+5:30, Mark Lawrence wrote: > On 01/10/2012 01:58, 8 Dihedral wrote: > > > > > > Your question seems vague to me. If you know you are storing > > > only immutable tuples in a list, then the way to iterate is simple. > > > > > > > Does Python have a magic method that let's me use mutable tuples? I'd > > also like immutable lists. Is it worth raising a feature request on the > > bug tracker? > > > > -- > > Cheers. > > > > Mark Lawrence. Mark, you are talking to a bot. -- http://mail.python.org/mailman/listinfo/python-list
Re: parse an environment file
On Tuesday, 2 October 2012 21:34:04 UTC+5:30, xDog Walker wrote: > On Monday 2012 October 01 08:35, Hans Mulder wrote: > > > AFAIK, there is no Python module that can read shell syntax. > > > > The stdlib's shlex might be that module. > > > > -- > > Yonder nor sorghum stenches shut ladle gulls stopper torque wet > > strainers. shlex can only split shell code into tokens. -- http://mail.python.org/mailman/listinfo/python-list
Re: unit testing class hierarchies
Am 02.10.2012 16:06, schrieb Thomas Bach: On Tue, Oct 02, 2012 at 02:27:11PM +0200, Ulrich Eckhardt wrote: As you see, the code for test_base() is redundant, so the idea is to move it to a baseclass: class TestBase(unittest.TestCase): def test_base(self): ... class TestD1(TestBase): def test_r(self): ... def test_s(self): ... class TestD2(TestBase): def test_x(self): ... def test_y(self): ... Could you provide more background? How do you avoid that test_base() runs in TestD1 or TestD2? Sorry, there's a misunderstanding: I want test_base() to be run as part of both TestD1 and TestD2, because it tests basic functions provided by both class D1 and D2. Uli -- http://mail.python.org/mailman/listinfo/python-list
Re: How to apply the user's HTML environment in a Python programme?
On Monday, 1 October 2012 19:49:27 UTC+5:30, BobAalsma wrote: > Op vrijdag 21 september 2012 16:15:30 UTC+2 schreef Joel Goldstick het > volgende: > > > On Fri, Sep 21, 2012 at 9:58 AM, BobAalsma wrote: > > > > > > > Op vrijdag 21 september 2012 15:36:11 UTC+2 schreef Jerry Hill het > > > volgende: > > > > > > >> On Fri, Sep 21, 2012 at 9:31 AM, BobAalsma wrote: > > > > > > >> > > > > > > >> > Thanks, Joel, yes, but as far as I'm aware these would all require the > > >> > Python programme to have the user's username and password (or > > >> > "credentials"), which I wanted to avoid. > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> No matter what you do, your web service is going to have to > > > > > > >> > > > > > > >> authenticate with the remote web site. The details of that > > > > > > >> > > > > > > >> authentication are going to vary with each remote web site you want to > > > > > > >> > > > > > > >> connect to. > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> -- > > > > > > >> > > > > > > >> Jerry > > > > > > > > > > > > > > Hmm, from the previous posts I get the impression that I could best solve > > > this by asking the user for the specific combination of username, > > > password and URL + promising not to keep any of that... > > > > > > > > > > > > > > OK, that does sound doable - thank you all > > > > > > > > > > > > > > > > > > I recommend that you write your program to read pages that are not > > > > > > protected. Once you get that working, you can go back and figure out > > > > > > how you want to get the username/password from your 'friends' and add > > > > > > that in. Also look up Beautiful Soup (version 4) for a great library > > > > > > to parse the pages that you retrieve > > > > > > > > > > > > > > Bob > > > > > > > -- > > > > > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > Joel Goldstick > > > > Joel, > > > > I've spent some time with this but don't really understand my results - some > help would be appreciated. > > I've built a tester that will read my LinkedIn home page, which is password > protected. > > When I use that method for reading other people's pages, the program is > redirected to the LinkedIn login page. > > When I paste the URLs for the other people's pages in any browser, the > requested pages are shown. > > > > Bob Not all the authentication information is in the URL. Some of it is in cookies in the browser. -- http://mail.python.org/mailman/listinfo/python-list
Re: Slicing iterables in sub-generators without loosing elements
On 02/10/2012 17:12, Ramchandra Apte wrote: On Monday, 1 October 2012 13:47:50 UTC+5:30, Mark Lawrence wrote: On 01/10/2012 01:58, 8 Dihedral wrote: Your question seems vague to me. If you know you are storing only immutable tuples in a list, then the way to iterate is simple. Does Python have a magic method that let's me use mutable tuples? I'd also like immutable lists. Is it worth raising a feature request on the bug tracker? -- Cheers. Mark Lawrence. Mark, you are talking to a bot. What happened to freedom of speech? If I want to talk to a bot, I'll talk to a bot. Besides I'm not convinced it/he/she is a bot. Plus if you read my post carefully, add in several years experience of Python the language and Python the comedy, you might come to the conclusion that a certain amount of urine extraction was going on :) -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: unit testing class hierarchies
Am 02.10.2012 16:06, schrieb Thomas Bach: On Tue, Oct 02, 2012 at 02:27:11PM +0200, Ulrich Eckhardt wrote: As you see, the code for test_base() is redundant, so the idea is to move it to a baseclass: class TestBase(unittest.TestCase): def test_base(self): ... class TestD1(TestBase): def test_r(self): ... def test_s(self): ... class TestD2(TestBase): def test_x(self): ... def test_y(self): ... Could you provide more background? How do you avoid that test_base() runs in TestD1 or TestD2? Sorry, there's a misunderstanding: I want test_base() to be run as part of both TestD1 and TestD2, because it tests basic functions provided by both classes D1 and D2. The instances of D1 and D2 are created in TestD1.setUp and TestD2.setUp and then used by all tests. There is no possible implementation creating such an instance for TestBase, since the baseclass is abstract. Last edit for today, I hope that makes my intentions clear... ;) Uli -- http://mail.python.org/mailman/listinfo/python-list
Re: unit testing class hierarchies
Ulrich Eckhardt wrote: > Am 02.10.2012 16:06, schrieb Thomas Bach: >> On Tue, Oct 02, 2012 at 02:27:11PM +0200, Ulrich Eckhardt wrote: >>> As you see, the code for test_base() is redundant, so the idea is to >>> move it to a baseclass: >>> >>> class TestBase(unittest.TestCase): >>> def test_base(self): >>> ... >>> >>> class TestD1(TestBase): >>> def test_r(self): >>> ... >>> def test_s(self): >>> ... >>> >>> class TestD2(TestBase): >>> def test_x(self): >>> ... >>> def test_y(self): >>> ... >> >> Could you provide more background? How do you avoid that test_base() >> runs in TestD1 or TestD2? > > Sorry, there's a misunderstanding: I want test_base() to be run as part > of both TestD1 and TestD2, because it tests basic functions provided by > both classes D1 and D2. The instances of D1 and D2 are created in > TestD1.setUp and TestD2.setUp and then used by all tests. There is no > possible implementation creating such an instance for TestBase, since > the baseclass is abstract. > > Last edit for today, I hope that makes my intentions clear... > > ;) Ceterum censeo baseclassinem esse delendam ;) $ cat test_shared.py import unittest class Shared(unittest.TestCase): def test_shared(self): pass class D1(Shared): def test_d1_only(self): pass class D2(Shared): def test_d2_only(self): pass del Shared unittest.main() $ python test_shared.py -v test_d1_only (__main__.D1) ... ok test_shared (__main__.D1) ... ok test_d2_only (__main__.D2) ... ok test_shared (__main__.D2) ... ok -- Ran 4 tests in 0.000s OK $ -- http://mail.python.org/mailman/listinfo/python-list
Re: unit testing class hierarchies
Fayaz Yusuf Khan wrote: > Peter Otten wrote: > >> Ulrich Eckhardt wrote: >>> The problem here is that TestBase is not a complete test case (just > as >>> class Base is not complete), but the unittest framework will still > try >>> to run it on its own. > How exactly are you invoking the test runner? unittest? nose? You can > tell the test discoverer which classes you want it to run and which > ones you don't. For the unittest library, I use my own custom > load_tests methods: > def load_tests(loader, tests, pattern): > testcases = [TestD1, TestD2] > return TestSuite([loader.loadTestsFromTestCase(testcase) > for testcase in testcases]) > http://docs.python.org/library/unittest.html#load-tests-protocol > >>> One way around this is to not derive class >>> TestBase from unittest. >> >> Another is to remove it from the global namespace with >> >> del TestBase > Removing the class from namespace may or may not help. Consider a > scenario where someone decided to be creative with the cls.__bases__ > attribute. Isn't that a bit far-fetched? I'd rather start simple and fix problems as they arise... -- http://mail.python.org/mailman/listinfo/python-list
Re: Are ABCs an anti-pattern?
On Tue, Oct 2, 2012 at 9:23 AM, Demian Brecht wrote:
> I don't use them anymore, but I'm curious about others opinions on this
> list...
>
Interesting question. I think they haven't been useful for representing
the real world as everyone hoped, but are pretty good for organizing
structures within the Python universe (like "object "collections" -->
{'list','set','dict'...}, for example).
mark
--
http://mail.python.org/mailman/listinfo/python-list
Re: unit testing class hierarchies
Am I missing something? Is there something that wasn't answered by my reply
about using mixins?
from unittest import TestCase
class SharedTestMixin(object):
def test_shared(self):
self.assertNotEquals('foo', 'bar')
class TestA(TestCase, SharedTestMixin):
def test_a(self):
self.assertEquals('a', 'a')
class TestB(TestCase, SharedTestMixin):
def test_b(self):
self.assertEquals('b', 'b')
$ nosetests test.py -v
test_a (test.TestA) ... ok
test_shared (test.TestA) ... ok
test_b (test.TestB) ... ok
test_shared (test.TestB) ... ok
--
Ran 4 tests in 0.001s
OK
This seems to be a clear answer to the problem that solves the original
requirements without introducing error-prone, non-obvious solutions.
> Sorry, there's a misunderstanding: I want test_base() to be run as part of
> both TestD1 and TestD2, because it tests basic functions provided by both
> classes D1 and D2. The instances of D1 and D2 are created in TestD1.setUp
> and TestD2.setUp and then used by all tests. There is no possible
> implementation creating such an instance for TestBase, since the baseclass
> is abstract.
>
> Last edit for today, I hope that makes my intentions clear...
>
> ;)
>
> Uli
>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: Slicing iterables in sub-generators without loosing elements
On Wed, Oct 3, 2012 at 2:44 AM, Mark Lawrence wrote: > What happened to freedom of speech? If I want to talk to a bot, I'll talk > to a bot. Besides I'm not convinced it/he/she is a bot. Plus if you read > my post carefully, add in several years experience of Python the language > and Python the comedy, you might come to the conclusion that a certain > amount of urine extraction was going on :) Coupled with a bit of bot-seeding, which is always fun. One of these days I'm going to mail Dihedral a whole pile of Gilbert and Sullivan operetta and see if any of it comes back in his posts... Dihedral might be a bot and might not. I've come to the conclusion that it's not worth trying to find out, given that a good bot can outdo a lot of humans in useful conversation. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: unit testing class hierarchies
Am I missing something? Is there something that wasn't answered by my reply
about using mixins?
from unittest import TestCase
class SharedTestMixin(object):
def test_shared(self):
self.assertNotEquals('foo', 'bar')
class TestA(TestCase, SharedTestMixin):
def test_a(self):
self.assertEquals('a', 'a')
class TestB(TestCase, SharedTestMixin):
def test_b(self):
self.assertEquals('b', 'b')
$ nosetests test.py -v
test_a (test.TestA) ... ok
test_shared (test.TestA) ... ok
test_b (test.TestB) ... ok
test_shared (test.TestB) ... ok
--
Ran 4 tests in 0.001s
OK
This seems to be a clear answer to the problem that solves the original
requirements without introducing error-prone, non-obvious solutions.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Slicing iterables in sub-generators without loosing elements
On 02/10/2012 18:58, Chris Angelico wrote: Dihedral might be a bot and might not. I've come to the conclusion that it's not worth trying to find out, given that a good bot can outdo a lot of humans in useful conversation. ChrisA Try telling that to the newbies on the Python tutor mailing list and they simply won't believe ya :) -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: unit testing class hierarchies
On 02/10/2012 19:06, Demian Brecht wrote:
Am I missing something? Is there something that wasn't answered by my reply
about using mixins?
from unittest import TestCase
class SharedTestMixin(object):
def test_shared(self):
self.assertNotEquals('foo', 'bar')
class TestA(TestCase, SharedTestMixin):
def test_a(self):
self.assertEquals('a', 'a')
class TestB(TestCase, SharedTestMixin):
def test_b(self):
self.assertEquals('b', 'b')
$ nosetests test.py -v
test_a (test.TestA) ... ok
test_shared (test.TestA) ... ok
test_b (test.TestB) ... ok
test_shared (test.TestB) ... ok
--
Ran 4 tests in 0.001s
OK
This seems to be a clear answer to the problem that solves the original
requirements without introducing error-prone, non-obvious solutions.
Peter Otten's response is obviously vastly superior to yours, 4 tests in
0.000s compared to your highly inefficient 4 tests in 0.001s :)
--
Cheers.
Mark Lawrence.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Are ABCs an anti-pattern?
On 10/2/2012 10:23 AM, Demian Brecht wrote: I don't use them anymore, but I'm curious about others opinions on this list... The more time I spend in Python, discovering what "Pythonic" code is and such, it seems that I throw away much in terms of academic learnings as far as "OOP correctness" goes. In doing so, I find that, in general, overall LOC (yes, I'm aware that this is a poor metric to judge anything on), readability and overall quality of code seems to go up. Yes, you give the user much more rope to hang themselves with making the general assumption that the user knows what they're doing, but we're all consenting adults here after all, right? ;) As an example, I initially had an OAuth 2.0 client library that was roughly 450 LOC (using ABCs, adapter patterns for the various flows, etc). Dropping this for a more "Pythonic" (at least, what my interpretation of Pythonic code is) brought the entire library down to 55 LOC. Having said that, the decline in LOC and overall grok-ability wasn't entirely due to moving away from ABCs and dropping the use of adapters, but it did have quite a bit to do with it). As such, I see ABCs as somewhat of an anti-pattern in the Python world. The concept is obviously essential in non-duck-typed language using strict OOP, but does it *really* belong in Python? ABCs were added (fairly recently) in 3.0 for the reasons given in http://python.org/dev/peps/pep-3119/ It was expected that it would take awhile for them to see good, pythonic uses. We obviously did okay without them up to 2.7. They are partly informational, partly meant to help duck typing. I don't think they are used much in the stdlib (except to register classes) and I have not used them myself. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Slicing iterables in sub-generators without loosing elements
On 10/2/2012 1:58 PM, Chris Angelico wrote: On Wed, Oct 3, 2012 at 2:44 AM, Mark Lawrence wrote: What happened to freedom of speech? If I want to talk to a bot, I'll talk to a bot. Besides I'm not convinced it/he/she is a bot. Plus if you read my post carefully, add in several years experience of Python the language and Python the comedy, you might come to the conclusion that a certain amount of urine extraction was going on :) Coupled with a bit of bot-seeding, which is always fun. One of these days I'm going to mail Dihedral a whole pile of Gilbert and Sullivan operetta and see if any of it comes back in his posts... Dihedral might be a bot and might not. I've come to the conclusion that it's not worth trying to find out, given that a good bot can outdo a lot of humans in useful conversation. I just read that bots playing Unreal Tournament with an 'act human' module seem more human to at least some humans than humans. Perhaps that is because humans have to become bot-like to play UT well. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
trying to unsubscribe
My efforts at trying to unsubscribe are not working. Could you help me with this, or take this email as a request to unsubscribe. Thanks, Timothy Holmes -- http://mail.python.org/mailman/listinfo/python-list
design question:game skill system
Hello all:
I'm looking at a skill/perk system, where the player builds up his char
by using perk points to add abilities.
Each perk is under a category, and generally costs go up as you increase
the perk.
So I'm trying to figure something out; first, I'd really like the cost
calculation and all of that to be dynamic, so that I don't have to write
a calculateCost per object. I'd also like to be able to specify
dependencies and say a level, as well as other factors before a player
can obtain a perk and have them self documenting. The idea is that a
player could do something like:
data perk extended health
and it would tell them they require health at 50 before they can
purchase extended health, as well as the cost, the increase per level
and the total overall cost.
Any ideas on how to set this up would be really appreciated.
Finally, I'm curious how to store and calculate these. I thought about
using a uid per perk, then storing something like: {uid:level} on the
player, but means that I have to lookup the name somehow still in the
main perk database, then use that uid to check if the player has it. Are
there better ways of storing skills? I'm also thinking about
calculation; currently the CalculateMaxHp method would have to add up
all the possible perks for health, then add stats and all that. That
could get really rough on performance if it's called often; would
something like a cache work, where you have something like:
{attribute:dirty}? So if I call CalculateHealth, it checks for the dirty
flag, and if it doesn't exist just returns the previous max HP, but if
the dirty flag is set, it recalculates? Then anything modifying health
(level gains, perks, stat increases/etc) would just set the dirty flag
and call calculate?
Thoughts/ideas would be welcome.
Thanks,
--
Take care,
Ty
http://tds-solutions.net
The aspen project: a barebones light-weight mud engine:
http://code.google.com/p/aspenmud
He that will not reason is a bigot; he that cannot reason is a fool; he that
dares not reason is a slave.
--
http://mail.python.org/mailman/listinfo/python-list
Re: trying to unsubscribe
On Tue, Oct 2, 2012 at 3:01 PM, timothy holmes wrote: > My efforts at trying to unsubscribe are not working. Could you help me with > this, or take this email as a request to unsubscribe. > Thanks, > Timothy Holmes > > -- > http://mail.python.org/mailman/listinfo/python-list > Go here http://mail.python.org/mailman/listinfo/python-list and look for unsubscribe near the bottom -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: design question:game skill system
On Tue, Oct 2, 2012 at 2:00 PM, Littlefield, Tyler wrote:
> Hello all:
> I'm looking at a skill/perk system, where the player builds up his char by
> using perk points to add abilities.
> Each perk is under a category, and generally costs go up as you increase the
> perk.
> So I'm trying to figure something out; first, I'd really like the cost
> calculation and all of that to be dynamic, so that I don't have to write a
> calculateCost per object. I'd also like to be able to specify dependencies
> and say a level, as well as other factors before a player can obtain a perk
> and have them self documenting. The idea is that a player could do something
> like:
> data perk extended health
> and it would tell them they require health at 50 before they can purchase
> extended health, as well as the cost, the increase per level and the total
> overall cost.
What are the cost calculations based on? If there are specific
formulas then you would need to store them somehow, possibly just as a
function to be called or string to be evaled, but if the security of
the perk database is of concern then you could engineer a more
sandboxed representation. For dependencies, you can keep them in a
container. An extended health perk might look something like:
cost_formula = "5 * level ** 2"
dependencies = {HEALTH: 50, PLAYER_LEVEL: 15}
benefits = {HEALTH: "7 * level"}
where HEALTH and PLAYER_LEVEL are just some arbitrary known constants.
Your core perks library would then be responsible for looking this
information up, running the formulas, and performing whatever
calculations on it are needed.
> Finally, I'm curious how to store and calculate these. I thought about using
> a uid per perk, then storing something like: {uid:level} on the player, but
> means that I have to lookup the name somehow still in the main perk
> database, then use that uid to check if the player has it. Are there better
> ways of storing skills?
When you say uids, you mean UUIDs, right? I'm not sure what advantage
there is in using abstracted unique identifiers for these. Assuming
you have full control over what perks are added, you can ensure there
will be no name clashes, so why not just use the name or a name-based
tag to uniquely identify each perk? Regardless of how you identify
them, though, your code is at some point going to have to go to the
database to look them up, so I would suggest you just go ahead and
write that code, and then you can add some caching later if it turns
out to be needed.
> I'm also thinking about calculation; currently the
> CalculateMaxHp method would have to add up all the possible perks for
> health, then add stats and all that. That could get really rough on
> performance if it's called often; would something like a cache work, where
> you have something like: {attribute:dirty}? So if I call CalculateHealth, it
> checks for the dirty flag, and if it doesn't exist just returns the previous
> max HP, but if the dirty flag is set, it recalculates? Then anything
> modifying health (level gains, perks, stat increases/etc) would just set the
> dirty flag and call calculate?
Sounds reasonable. I wouldn't use a separate flag attribute, though.
When max HP becomes dirty, clear the cached value, and use the absence
of a cached value to inform your code that it needs to recalculate.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Slicing iterables in sub-generators without loosing elements
On Monday, October 1, 2012 4:17:50 PM UTC+8, Mark Lawrence wrote: > On 01/10/2012 01:58, 8 Dihedral wrote: > > > > > > Your question seems vague to me. If you know you are storing > > > only immutable tuples in a list, then the way to iterate is simple. > > > > > > > Does Python have a magic method that let's me use mutable tuples? I'd > > also like immutable lists. Is it worth raising a feature request on the > > bug tracker? > > > > -- > > Cheers. > > > > Mark Lawrence. Python resolves objects by names and dynamical types. This will force the programmer to write structured programs. -- http://mail.python.org/mailman/listinfo/python-list
Python Developers needed in Austin TX with a top notch IT company
Job Title: Python developers Duration: 6 months; Location: Austin TX Responsibilities / Skills: 1) distributed complex application experience 2) prefer experience with enterprise class identity management systems, particularly around auth/credentials 3) experience with openstack 4) experience with large scale systems 5) Proficiency with Linux, ability to write Bash / Perl / Python scripts to run CRON jobs 6) Experience working in an agile environment and with a distributed team If interested, please reply with your updated Resume at [email protected] Regards, Sunny Narang Talent Acquisition [email protected] Persistent Systems Ltd. | 20 Glorious Years | www.persistentsys.com -- http://mail.python.org/mailman/listinfo/python-list
Re: unit testing class hierarchies
Ulrich Eckhardt writes: > I want test_base() to be run as part of both TestD1 and TestD2, > because it tests basic functions provided by both classes D1 and D2. It sounds, from your description so far, that you have identified a design flaw in D1 and D2. The common functionality should be moved to a common code point (maybe a base class of D1 and D2; maybe a function without need of a class). Then you'll have only one occurrence of that functionality to test, which is good design as well as easier test code :-) -- \ “When I was a little kid we had a sand box. It was a quicksand | `\ box. I was an only child... eventually.” —Steven Wright | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Issue installing pyopencv in mac
On Wednesday, August 29, 2012 6:21:50 AM UTC-4, Rakesh Rocker RuLZzz wrote: > I tried installing pyopencv in mac but i gives me an error > > I have installed all the dependent softwares like opencv,boost, etcstill > unable to fix it. > > also i have updated xcode and using python 2.7 > > I also tried using mac port but still no use > > > > can anybody help meThanks in advance. Are you having these issues? http://stackoverflow.com/questions/12354628/errors-met-while-installing-pyopencv-2-1-0-with-opencv-2-4-2 Because I am getting this exact error too. I installed Boost 1.50.0 and OpenCV 2.4.2 using Homebrew, and am trying to install pyopencv 2.1.0 with pip+virtualenv, to no avail. Python 2.7.2, Mac OSX Mountain Lion. I hope someone out there has figured this out. -- http://mail.python.org/mailman/listinfo/python-list
Re: unit testing class hierarchies
In article , Peter Otten <[email protected]> wrote: > >> Another is to remove it from the global namespace with > >> > >> del TestBase When I had this problem, that's the solution I used. -- http://mail.python.org/mailman/listinfo/python-list
Re: Slicing iterables in sub-generators without loosing elements
Steven D'Aprano於 2012年10月3日星期三UTC+8上午8時57分20秒寫道: > On Wed, 03 Oct 2012 03:58:02 +1000, Chris Angelico wrote: > > > > > Dihedral might be a bot and might not. I've come to the conclusion that > > > it's not worth trying to find out, given that a good bot can outdo a lot > > > of humans in useful conversation. > > > > Oh, I'm convinced that it's a bot. > > > > The fact that Dihedral never responds to conversations about him/it is a > > give away: nearly all people are far to egotistical to let accusations of > > bot-hood go unchallenged. And even though its responses are grammatically > > correct, they often are semantically meaningless. Even the best AIs > > (Evie, CleverBot, Alice) don't come close to passing the Turing test. It > > helps that Dihedral only talks about computer programming, but even so, > > it has well and truly failed my personal Turing test. > > > > Mind you, some human beings fail the Turing test too: > > > > http://northernplanets.blogspot.com.au/2006/06/failing-turing-test.html > > > > > > Of course, Dihedral's creator wanted to really confound us, the > > occasional human response would probably muddy the waters sufficiently. > > > > > > > > -- > > Steven Are you still not getting the generator part in Python? Do you really test any generator before? -- http://mail.python.org/mailman/listinfo/python-list
Re: Slicing iterables in sub-generators without loosing elements
On Tue, 02 Oct 2012 18:11:20 -0700, 8 Dihedral wrote: > Steven D'Aprano於 2012年10月3日星期三UTC+8上午8時57分20秒寫道: >> Oh, I'm convinced that it's a bot. >> The fact that Dihedral never responds to conversations about him/it is >> a give away: nearly all people are far to egotistical to let >> accusations of bot-hood go unchallenged. [...] >> Of course, Dihedral's creator wanted to really confound us, the >> occasional human response would probably muddy the waters sufficiently. > Are you still not getting the generator part in Python? Do you really > test any generator before? I rest my case :) I have many problems with generators. Can you tell me more about them? I really need your help. Sometimes, when it is very cold, the diesel freezes and the generator raises StopIteration at the wrong place. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: unit testing class hierarchies
On Wed, 03 Oct 2012 08:30:19 +1000, Ben Finney wrote: > Ulrich Eckhardt writes: > >> I want test_base() to be run as part of both TestD1 and TestD2, because >> it tests basic functions provided by both classes D1 and D2. > > It sounds, from your description so far, that you have identified a > design flaw in D1 and D2. > > The common functionality should be moved to a common code point (maybe a > base class of D1 and D2; maybe a function without need of a class). Then > you'll have only one occurrence of that functionality to test, which is > good design as well as easier test code :-) But surely, regardless of where that functionality is defined, you still need to test that both D1 and D2 exhibit the correct behaviour? Otherwise D2 (say) may break that functionality and your tests won't notice. Given a class hierarchy like this: class AbstractBaseClass: spam = "spam" class D1(AbstractBaseClass): pass class D2(D1): pass I write tests like this: class TestD1CommonBehaviour(unittest.TestCase): cls = D1 def testSpam(self): self.assertTrue(self.cls.spam == "spam") def testHam(self): self.assertFalse(hasattr(self.cls, 'ham')) class TestD2CommonBehaviour(TestD1CommonBehaviour): cls = D2 class TestD1SpecialBehaviour(unittest.TestCase): # D1 specific tests here class TestD2SpecialBehaviour(unittest.TestCase): # D2 specific tests here If D2 doesn't inherit from D1, but both from AbstractBaseClass, I need to do a little more work. First, in the test suite I create a subclass specifically for testing the common behaviour, write tests for that, then subclass from that: class MyD(AbstractBaseClass): # Defeat the prohibition on instantiating the base class pass class TestCommonBehaviour(unittest.TestCase): cls = MyD def testSpam(self): self.assertTrue(self.cls.spam == "spam") def testHam(self): self.assertFalse(hasattr(self.cls, 'ham')) class TestD1CommonBehaviour(unittest.TestCase): cls = D1 class TestD2CommonBehaviour(unittest.TestCase): cls = D2 D1 and D2 specific tests remain the same. Either way, each class gets tested for the full set of expected functionality. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Slicing iterables in sub-generators without loosing elements
Steven D'Aprano於 2012年10月3日星期三UTC+8上午9時24分13秒寫道: > On Tue, 02 Oct 2012 18:11:20 -0700, 8 Dihedral wrote: > > > > > Steven D'Aprano於 2012年10月3日星期三UTC+8上午8時57分20秒寫道: > > > > >> Oh, I'm convinced that it's a bot. > > >> The fact that Dihedral never responds to conversations about him/it is > > >> a give away: nearly all people are far to egotistical to let > > >> accusations of bot-hood go unchallenged. > > [...] > > >> Of course, Dihedral's creator wanted to really confound us, the > > >> occasional human response would probably muddy the waters sufficiently. > > > > > Are you still not getting the generator part in Python? Do you really > > > test any generator before? > > > > I rest my case :) > > > > I have many problems with generators. Can you tell me more about them? I > > really need your help. Sometimes, when it is very cold, the diesel > > freezes and the generator raises StopIteration at the wrong place. > > > > > > > > -- > > Steven Please work out your own templates as I showed in the decorator part. -- http://mail.python.org/mailman/listinfo/python-list
local variable 'a' referenced b
code1 >>> def foo(): ... a = 1 ... def bar(): ... b=2 ... print a + b ... bar() ... ... >>> foo() 3 code2 >>> def foo(): ... a = 1 ... def bar(): ... b=2 ... a = a + b ... print a ... bar() ... >>> foo() Traceback (most recent call last): File "", line 1, in File "", line 7, in foo File "", line 5, in bar UnboundLocalError: local variable 'a' referenced b why code2 can not get output of 3? -- http://mail.python.org/mailman/listinfo/python-list
Re: local variable 'a' referenced b
On 10/02/2012 10:03 PM, contro opinion wrote: > code1 def foo(): > ... a = 1 > ... def bar(): > ... b=2 > ... print a + b > ... bar() > ... > ... foo() > 3 > > code2 def foo(): > ... a = 1 > ... def bar(): > ... b=2 > ... a = a + b Because your function bar() has an assignment to a, it becomes a local, and masks access to the one in the containing function. Then because when you start executing that assignment statement, a hasn't yet gotten a value, you get the error below. > ... print a > ... bar() > ... foo() > Traceback (most recent call last): > File "", line 1, in > File "", line 7, in foo > File "", line 5, in bar > UnboundLocalError: local variable 'a' referenced b > > why code2 can not get output of 3? > In Python3, you can avoid the "problem" by declaring a as nonlocal. def foo(): a = 1 def bar(): nonlocal a b=2 a = a + b print (a) bar() foo() if you're stuck with Python2.x, you can use a mutable object for a, and mutate it, rather than replace it. For example, def foo(): a = [3] def bar(): b=2 a.append(b) #this mutates a, but doesn't assign it print (a) a[0] += b #likewise, for a number within the list print (a) bar() That should work in either 2.x or 3.2 -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Slicing iterables in sub-generators without loosing elements
On Tuesday, 2 October 2012 22:13:20 UTC+5:30, Mark Lawrence wrote: > On 02/10/2012 17:12, Ramchandra Apte wrote: > > > On Monday, 1 October 2012 13:47:50 UTC+5:30, Mark Lawrence wrote: > > >> On 01/10/2012 01:58, 8 Dihedral wrote: > > >> > > >>> > > >> > > >>> Your question seems vague to me. If you know you are storing > > >> > > >>> only immutable tuples in a list, then the way to iterate is simple. > > >> > > >>> > > >> > > >> > > >> > > >> Does Python have a magic method that let's me use mutable tuples? I'd > > >> > > >> also like immutable lists. Is it worth raising a feature request on the > > >> > > >> bug tracker? > > >> > > >> > > >> > > >> -- > > >> > > >> Cheers. > > >> > > >> > > >> > > >> Mark Lawrence. > > > > > > Mark, you are talking to a bot. > > > > > > > What happened to freedom of speech? If I want to talk to a bot, I'll > > talk to a bot. Besides I'm not convinced it/he/she is a bot. Plus if > > you read my post carefully, add in several years experience of Python > > the language and Python the comedy, you might come to the conclusion > > that a certain amount of urine extraction was going on :) > > > > -- > > Cheers. > > > > Mark Lawrence. Never said you can't. -- http://mail.python.org/mailman/listinfo/python-list
Re: parse an environment file
> Ah, fair enough. Well, since you're using the full range of bash > functionality, the only viable way to parse it is with bash itself. > I'd recommend going with the version you have above: > >> * * * * * . /path/to/export_file && /path/to/script.py > > Under what circumstances is this not an option? That'd be the next > thing to consider. > > Alternatively, you may want to consider making your own config file > format. If you consciously restrict yourself to a severe subset of > bash functionality, you could easily parse it in Python - for > instance, always look for "export %s=%s" with simple strings for the > variable name and value. > Thank you, Chris, off-list post unintentional. It may be the case that I do not maintain /path/to/export_file; I might just be allowed to read it. Based on your responses and everyone's responses I'm guessing that what I am doing is sufficiently novel that there is no canned solution. I looked at shlex but did not see how that would be helpful. Thank you all for your thoughts. -- http://mail.python.org/mailman/listinfo/python-list
Re: parse an environment file
On Wed, Oct 3, 2012 at 1:49 PM, Jason Friedman wrote: > Based on your responses and everyone's responses I'm guessing that > what I am doing is sufficiently novel that there is no canned > solution. I looked at shlex but did not see how that would be > helpful. The only canned solution for parsing a bash script is bash. Think about it the other way around: If you wanted to have a Python variable made available to a bash script, the obvious thing to do is to invoke Python. It's the same thing. I recommend going with Hans Mulder's suggestion of a wrapper script; that seems to be the cleanest option available. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Experimental Python-based shell
Jonathan Hayward wrote: > >I've made an experimental Python-based Unix/Linux shell at: > >http://JonathansCorner.com/cjsh/ > >An experimental Unix/Linux command line shell, implemented in Python 3, >that takes advantage of some more recent concepts in terms of usability >and searching above pinpointing files in heirarchies. > >I invite you to try it. Without intending to detract from your work in any way, are you familiar with the IPython project? http://ipython.org/ You may find some interesting synergy with them. -- Tim Roberts, [email protected] Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: local variable 'a' referenced b
On 12-10-02 07:26 PM, Dave Angel wrote: if you're stuck with Python2.x, you can use a mutable object for a, and mutate it, rather than replace it. For example, def foo(): a = [3] def bar(): b=2 a.append(b) #this mutates a, but doesn't assign it print (a) a[0] += b #likewise, for a number within the list print (a) bar() That should work in either 2.x or 3.2 Alternatively, you can restructure your code by simply adding a parameter to bar(). Nice thing about this is that if you ever move bar() out into another module, then you don't have to worry about documenting the side effects on 'a' so users (including yourself) aren't confused later: >>> def foo(): ... a = 1 ... def bar(n): ... b = 2 ... return n + b ... a = bar(a) ... print a ... >>> foo() 3 -- Demian Brecht @demianbrecht http://demianbrecht.github.com -- http://mail.python.org/mailman/listinfo/python-list
Re: local variable 'a' referenced b
On 10/03/2012 01:54 AM, Demian Brecht wrote: > On 12-10-02 07:26 PM, Dave Angel wrote: >> >> if you're stuck with Python2.x, you can use a mutable object for a, and >> mutate it, rather than replace it. For example, >> >> >> def foo(): >> a = [3] >> def bar(): >> b=2 >> a.append(b) #this mutates a, but doesn't assign it >> print (a) >> a[0] += b #likewise, for a number within the list >> print (a) >> bar() >> >> That should work in either 2.x or 3.2 >> > > Alternatively, you can restructure your code by simply adding a > parameter to bar(). Nice thing about this is that if you ever move > bar() out into another module, then you don't have to worry about > documenting the side effects on 'a' so users (including yourself) > aren't confused later: > > >>> def foo(): > ... a = 1 > ... def bar(n): > ... b = 2 > ... return n + b > ... a = bar(a) > ... print a > ... > >>> foo() > 3 > > One problem with short examples is they mask the reason for the code to be structured that way. I assumed that the OP was really talking about a closure, and that sharing that variable was deliberate. I seldom write nested functions otherwise. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
