From patenaude at gmail.com Sun Sep 20 18:41:26 2015 From: patenaude at gmail.com (Mitch Patenaude) Date: Sun, 20 Sep 2015 09:41:26 -0700 Subject: [Baypiggies] Django url regex weirdness Message-ID: Hi BayPiggies, I'm trying to write a simple little django app, and I'm trying get it to match a URL of the form list/,/to/,/ Where the coords are floats. for example: list/37,-122.5/to/37.5,-122/ Here's the regex from my module's urls.py: url(r'^list/{?P(-?[0-9]+\.?[0-9]*,-?[0-9]+\.?[0-9]*)}/to/{?P(-?[0-9]+\.?[0-9]*\,-?[0-9]+\.?[0-9]*)}/', views.tplist, name='list'), I've tried it without the parens as well. I've verified that the basic regex works using the re module, but django is just returning a 404. Does anybody see my problem? Thanks, -- Mitch -------------- next part -------------- An HTML attachment was scrubbed... URL: From patenaude at gmail.com Mon Sep 21 02:09:09 2015 From: patenaude at gmail.com (Mitch Patenaude) Date: Sun, 20 Sep 2015 17:09:09 -0700 Subject: [Baypiggies] Django url regex weirdness In-Reply-To: References: Message-ID: The problem was that I misread the example, and the outer set of braces ({}) should have been parens instead. Sorry for the stupid question -- Mitch On Sun, Sep 20, 2015 at 9:41 AM, Mitch Patenaude wrote: > Hi BayPiggies, > > I'm trying to write a simple little django app, and I'm trying get it to > match a URL of the form > list/,/to/,/ > Where the coords are floats. for example: > list/37,-122.5/to/37.5,-122/ > > Here's the regex from my module's urls.py: > url(r'^list/{?P(-?[0-9]+\.?[0-9]*,-?[0-9]+\.?[0-9]*)}/to/{?P(-?[0-9]+\.?[0-9]*\,-?[0-9]+\.?[0-9]*)}/', > views.tplist, name='list'), > > I've tried it without the parens as well. I've verified that the basic > regex works using the re module, but django is just returning a 404. Does > anybody see my problem? > > Thanks, > -- Mitch > -------------- next part -------------- An HTML attachment was scrubbed... URL: From spmcinerney at hotmail.com Fri Sep 25 22:15:47 2015 From: spmcinerney at hotmail.com (Stephen) Date: Fri, 25 Sep 2015 13:15:47 -0700 Subject: [Baypiggies] Should I install brew under /usr/local or /opt/local, on Mac? Message-ID: Seeking quick opinions on a marginally Python-related question: I decided to move from macports to brew.Should I install brew under /usr/local (default) or /opt/local (said to be better for separation)?- I'm on MacOS 10.8.x- I want to have multiple installs of Python 2.x, 3.x and various other libraries and tools (octave, Vowpal Wabbit, word2vec, Spark etc.)- I don't want any grief from Mac system libraries, version dependencies, etc.- I read StackOverflow et al. and there is no clear consensus Thanks,Stephen -------------- next part -------------- An HTML attachment was scrubbed... URL: From hasan.diwan at gmail.com Fri Sep 25 22:25:36 2015 From: hasan.diwan at gmail.com (Hasan Diwan) Date: Fri, 25 Sep 2015 13:25:36 -0700 Subject: [Baypiggies] Should I install brew under /usr/local or /opt/local, on Mac? In-Reply-To: References: Message-ID: Stephen, On 25 September 2015 at 13:15, Stephen wrote: > Seeking quick opinions on a marginally Python-related question: > > I decided to move from macports to brew. > Should I install brew under /usr/local (default) or /opt/local (said to be > better for separation)? > - I'm on MacOS 10.8.x > - I want to have multiple installs of Python 2.x, 3.x and various other > libraries > and tools (octave, Vowpal Wabbit, word2vec, Spark etc.) > - I don't want any grief from Mac system libraries, version dependencies, > etc. > - I read StackOverflow et al. and there is no clear consensus > I just install python using virtualenv for libraries: hd1 % /usr/local/bin/virtualenv .virtualenvs/$PROJECT_NAME ... hd1 % .virtualenvs/$PROJECT_NAME/bin/pip installl word2vec # and so on ... To execute $PROJECT_NAME, I use .virtualenvs/$PROJECT_NAME/bin/python $PROJECT_NAME/main.py -- hope that helps. -- H > > Thanks, > Stephen > > _______________________________________________ > Baypiggies mailing list > Baypiggies at python.org > To change your subscription options or unsubscribe: > https://mail.python.org/mailman/listinfo/baypiggies > -- OpenPGP: https://hasan.d8u.us/gpg.key Sent from my mobile device Envoy? de mon portable -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjinux at gmail.com Fri Sep 25 22:38:46 2015 From: jjinux at gmail.com (Shannon -jj Behrens) Date: Fri, 25 Sep 2015 20:38:46 +0000 Subject: [Baypiggies] Should I install brew under /usr/local or /opt/local, on Mac? In-Reply-To: References: Message-ID: Probably doesn't matter very much. You can even install it under your home directory. On Fri, Sep 25, 2015 at 1:17 PM Stephen wrote: > Seeking quick opinions on a marginally Python-related question: > > I decided to move from macports to brew. > Should I install brew under /usr/local (default) or /opt/local (said to be > better for separation)? > - I'm on MacOS 10.8.x > - I want to have multiple installs of Python 2.x, 3.x and various other > libraries > and tools (octave, Vowpal Wabbit, word2vec, Spark etc.) > - I don't want any grief from Mac system libraries, version dependencies, > etc. > - I read StackOverflow et al. and there is no clear consensus > > Thanks, > Stephen > _______________________________________________ > Baypiggies mailing list > Baypiggies at python.org > To change your subscription options or unsubscribe: > https://mail.python.org/mailman/listinfo/baypiggies -------------- next part -------------- An HTML attachment was scrubbed... URL: From vijayram.gopu at gmail.com Sat Sep 26 19:23:55 2015 From: vijayram.gopu at gmail.com (vijayram) Date: Sat, 26 Sep 2015 10:23:55 -0700 Subject: [Baypiggies] xunit unittest.TestSuite Message-ID: <4EB8A01B-7FC5-46A9-ABD2-33542312C23A@gmail.com> Hi All, I am facing this same issue described here: https://github.com/nose-devs/nose/issues/542 any alternative or solution to this issue that anyone is aware of... please kindly suggest... Thank you, VJ -------------- next part -------------- An HTML attachment was scrubbed... URL: From bbrelin at gmail.com Mon Sep 28 13:01:35 2015 From: bbrelin at gmail.com (Braun Brelin) Date: Mon, 28 Sep 2015 16:31:35 +0530 Subject: [Baypiggies] How to create a dict of counts using functional programming Message-ID: Hello all, I am trying to do the following: I have a list that looks like this: ['1','2','7','8','8'] I want to create a dictionary that looks like this: {1:1, 2:1,7:1,8:2} i.e. the value is the count of the number of times the key appears in the list. The catch is that I'm trying to do this in a functional programming way, rather than iteratively. I'm trying to use something like map, or reduce or even dict, but I can't figure out how to tell python to increment the value. In other words how do I even specify what the value is, as it seems to be a bit of a chicken and egg scenario. I can, for example create a dictionary that sets the values to a constant, such as zero using FP, but how do I tell it to increment the value for a dictionary that doesn't yet exist as I'm in the process of building it? Thanks, Braun Brelin -------------- next part -------------- An HTML attachment was scrubbed... URL: From david.berthelot at gmail.com Mon Sep 28 13:19:41 2015 From: david.berthelot at gmail.com (David Berthelot) Date: Mon, 28 Sep 2015 04:19:41 -0700 Subject: [Baypiggies] How to create a dict of counts using functional programming In-Reply-To: References: Message-ID: There's already a function written for that though in the standard library: https://docs.python.org/2/library/collections.html#collections.Counter On Mon, Sep 28, 2015 at 4:01 AM, Braun Brelin wrote: > Hello all, > > I am trying to do the following: > I have a list that looks like this: > ['1','2','7','8','8'] > > I want to create a dictionary that looks like this: > {1:1, 2:1,7:1,8:2} > i.e. the value is the count of the number of times the key appears in > the list. The catch is that I'm trying to do this in a functional > programming way, rather than iteratively. > > I'm trying to use something like map, or reduce or even dict, but I can't > figure out how to tell > python to increment the value. In other words how do I even specify what > the value is, as it > seems to be a bit of a chicken and egg scenario. > > I can, for example create a dictionary that sets the values to a constant, > such as zero using FP, > but how do I tell it to increment the value for a dictionary that doesn't > yet exist as I'm in the process of > building it? > > Thanks, > > Braun Brelin > > > > _______________________________________________ > Baypiggies mailing list > Baypiggies at python.org > To change your subscription options or unsubscribe: > https://mail.python.org/mailman/listinfo/baypiggies > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleax at google.com Mon Sep 28 16:01:07 2015 From: aleax at google.com (Alex Martelli) Date: Mon, 28 Sep 2015 07:01:07 -0700 Subject: [Baypiggies] How to create a dict of counts using functional programming In-Reply-To: References: Message-ID: If for some weird reason in can't use collections.Counter, as David sensibly suggests, the "FP way" (slow and cranky in Python, which doesn't do tail-call optimization, NOT being a functional programming language) is recursion: _sentinel = object() def _count_aux(it, adict): item = next(it, _sentinel) return adict if item is _sentinel else _count_aux(it, dict(adict, *{item: adict.get(item, 0) + 1}) def count(iterable): return _count_aux(iter(iterable), {}) The assignment in _count_aux's first statement is needed because iterators are not "peekable", and you need to refer to "the next item of the iterator" three times in the return statement -- if the bet terms included "totally avoid assignment" (I see no reason for the task except a weird bet!-) you could add another aux function (using argument passing in lieu of assignment, and making the recursion mutual). Except for winning weird bets, there are no positive aspects in using such a convoluted style in Python. Alex On Mon, Sep 28, 2015 at 4:01 AM, Braun Brelin wrote: > Hello all, > > I am trying to do the following: > I have a list that looks like this: > ['1','2','7','8','8'] > > I want to create a dictionary that looks like this: > {1:1, 2:1,7:1,8:2} > i.e. the value is the count of the number of times the key appears in > the list. The catch is that I'm trying to do this in a functional > programming way, rather than iteratively. > > I'm trying to use something like map, or reduce or even dict, but I can't > figure out how to tell > python to increment the value. In other words how do I even specify what > the value is, as it > seems to be a bit of a chicken and egg scenario. > > I can, for example create a dictionary that sets the values to a constant, > such as zero using FP, > but how do I tell it to increment the value for a dictionary that doesn't > yet exist as I'm in the process of > building it? > > Thanks, > > Braun Brelin > > > > _______________________________________________ > Baypiggies mailing list > Baypiggies at python.org > To change your subscription options or unsubscribe: > https://mail.python.org/mailman/listinfo/baypiggies > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bbrelin at gmail.com Mon Sep 28 16:07:42 2015 From: bbrelin at gmail.com (Braun Brelin) Date: Mon, 28 Sep 2015 19:37:42 +0530 Subject: [Baypiggies] How to create a dict of counts using functional programming In-Reply-To: References: Message-ID: Thanks to all for the advice. I used the collections.Counter() method and that did exactly what I needed. Braun Brelin On Mon, Sep 28, 2015 at 7:31 PM, Alex Martelli wrote: > If for some weird reason in can't use collections.Counter, as David > sensibly suggests, the "FP way" (slow and cranky in Python, which doesn't > do tail-call optimization, NOT being a functional programming language) is > recursion: > > _sentinel = object() > > def _count_aux(it, adict): > item = next(it, _sentinel) > return adict if item is _sentinel else _count_aux(it, dict(adict, > *{item: adict.get(item, 0) + 1}) > def count(iterable): > return _count_aux(iter(iterable), {}) > > The assignment in _count_aux's first statement is needed because iterators > are not "peekable", and you need to refer to "the next item of the > iterator" three times in the return statement -- if the bet terms included > "totally avoid assignment" (I see no reason for the task except a weird > bet!-) you could add another aux function (using argument passing in lieu > of assignment, and making the recursion mutual). > > Except for winning weird bets, there are no positive aspects in using such > a convoluted style in Python. > > > Alex > > > On Mon, Sep 28, 2015 at 4:01 AM, Braun Brelin wrote: > >> Hello all, >> >> I am trying to do the following: >> I have a list that looks like this: >> ['1','2','7','8','8'] >> >> I want to create a dictionary that looks like this: >> {1:1, 2:1,7:1,8:2} >> i.e. the value is the count of the number of times the key appears in >> the list. The catch is that I'm trying to do this in a functional >> programming way, rather than iteratively. >> >> I'm trying to use something like map, or reduce or even dict, but I can't >> figure out how to tell >> python to increment the value. In other words how do I even specify what >> the value is, as it >> seems to be a bit of a chicken and egg scenario. >> >> I can, for example create a dictionary that sets the values to a >> constant, such as zero using FP, >> but how do I tell it to increment the value for a dictionary that doesn't >> yet exist as I'm in the process of >> building it? >> >> Thanks, >> >> Braun Brelin >> >> >> >> _______________________________________________ >> Baypiggies mailing list >> Baypiggies at python.org >> To change your subscription options or unsubscribe: >> https://mail.python.org/mailman/listinfo/baypiggies >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdavis2 at ucsc.edu Mon Sep 28 22:41:40 2015 From: mdavis2 at ucsc.edu (Marilyn Davis) Date: Mon, 28 Sep 2015 13:41:40 -0700 Subject: [Baypiggies] How to create a dict of counts using functional programming In-Reply-To: References: Message-ID: It's a great little student project: data = '1','2','7','8','8' data_count_d = dict([(datum, data.count(datum)) for index, datum in enumerate(data) if index == data.index(datum)]) print data_count_d That does it I think. Thanks for an interesting question. Marilyn On Mon, Sep 28, 2015 at 4:19 AM, David Berthelot wrote: > There's already a function written for that though in the standard library: > https://docs.python.org/2/library/collections.html#collections.Counter > > On Mon, Sep 28, 2015 at 4:01 AM, Braun Brelin wrote: > >> Hello all, >> >> I am trying to do the following: >> I have a list that looks like this: >> ['1','2','7','8','8'] >> >> I want to create a dictionary that looks like this: >> {1:1, 2:1,7:1,8:2} >> i.e. the value is the count of the number of times the key appears in >> the list. The catch is that I'm trying to do this in a functional >> programming way, rather than iteratively. >> >> I'm trying to use something like map, or reduce or even dict, but I can't >> figure out how to tell >> python to increment the value. In other words how do I even specify what >> the value is, as it >> seems to be a bit of a chicken and egg scenario. >> >> I can, for example create a dictionary that sets the values to a >> constant, such as zero using FP, >> but how do I tell it to increment the value for a dictionary that doesn't >> yet exist as I'm in the process of >> building it? >> >> Thanks, >> >> Braun Brelin >> >> >> >> _______________________________________________ >> Baypiggies mailing list >> Baypiggies at python.org >> To change your subscription options or unsubscribe: >> https://mail.python.org/mailman/listinfo/baypiggies >> > > > _______________________________________________ > Baypiggies mailing list > Baypiggies at python.org > To change your subscription options or unsubscribe: > https://mail.python.org/mailman/listinfo/baypiggies > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdavis2 at ucsc.edu Mon Sep 28 22:46:46 2015 From: mdavis2 at ucsc.edu (Marilyn Davis) Date: Mon, 28 Sep 2015 13:46:46 -0700 Subject: [Baypiggies] How to create a dict of counts using functional programming In-Reply-To: References: Message-ID: I should add that using the standard library module is usually a better idea because, hopefully, it runs in compiled C so is much faster, and there are no bugs. Marilyn Davis On Mon, Sep 28, 2015 at 1:41 PM, Marilyn Davis wrote: > It's a great little student project: > > data = '1','2','7','8','8' > > data_count_d = dict([(datum, data.count(datum)) for index, datum in > enumerate(data) if index == data.index(datum)]) > > print data_count_d > > That does it I think. > > Thanks for an interesting question. > > Marilyn > > > On Mon, Sep 28, 2015 at 4:19 AM, David Berthelot < > david.berthelot at gmail.com> wrote: > >> There's already a function written for that though in the standard >> library: >> https://docs.python.org/2/library/collections.html#collections.Counter >> >> On Mon, Sep 28, 2015 at 4:01 AM, Braun Brelin wrote: >> >>> Hello all, >>> >>> I am trying to do the following: >>> I have a list that looks like this: >>> ['1','2','7','8','8'] >>> >>> I want to create a dictionary that looks like this: >>> {1:1, 2:1,7:1,8:2} >>> i.e. the value is the count of the number of times the key appears in >>> the list. The catch is that I'm trying to do this in a functional >>> programming way, rather than iteratively. >>> >>> I'm trying to use something like map, or reduce or even dict, but I >>> can't figure out how to tell >>> python to increment the value. In other words how do I even specify >>> what the value is, as it >>> seems to be a bit of a chicken and egg scenario. >>> >>> I can, for example create a dictionary that sets the values to a >>> constant, such as zero using FP, >>> but how do I tell it to increment the value for a dictionary that >>> doesn't yet exist as I'm in the process of >>> building it? >>> >>> Thanks, >>> >>> Braun Brelin >>> >>> >>> >>> _______________________________________________ >>> Baypiggies mailing list >>> Baypiggies at python.org >>> To change your subscription options or unsubscribe: >>> https://mail.python.org/mailman/listinfo/baypiggies >>> >> >> >> _______________________________________________ >> Baypiggies mailing list >> Baypiggies at python.org >> To change your subscription options or unsubscribe: >> https://mail.python.org/mailman/listinfo/baypiggies >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From simeonf at gmail.com Mon Sep 28 22:58:44 2015 From: simeonf at gmail.com (Simeon Franklin) Date: Mon, 28 Sep 2015 13:58:44 -0700 Subject: [Baypiggies] How to create a dict of counts using functional programming In-Reply-To: References: Message-ID: I agree wrt to recursion in Python. But if the correct solution (collections.Counter) didn't exist we could write a reduce function. Doesn't that seem to be the right FP idiom for the task at hand - it takes an input iterable and produces a single calculated result? >>> def count(total, item): ... total[item] = total.get(item, 0) + 1 ... return total ... >>> data = "Simeon Franklin" >>> reduce(count, data, {}) {'a': 1, ' ': 1, 'e': 1, 'F': 1, 'i': 2, 'k': 1, 'm': 1, 'l': 1, 'o': 1, 'n': 3, 'S': 1, 'r': 1} This doesn't seem so bad to me! On Mon, Sep 28, 2015 at 7:01 AM, Alex Martelli via Baypiggies < baypiggies at python.org> wrote: > If for some weird reason in can't use collections.Counter, as David > sensibly suggests, the "FP way" (slow and cranky in Python, which doesn't > do tail-call optimization, NOT being a functional programming language) is > recursion: > > _sentinel = object() > > def _count_aux(it, adict): > item = next(it, _sentinel) > return adict if item is _sentinel else _count_aux(it, dict(adict, > *{item: adict.get(item, 0) + 1}) > def count(iterable): > return _count_aux(iter(iterable), {}) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleax at google.com Mon Sep 28 23:12:44 2015 From: aleax at google.com (Alex Martelli) Date: Mon, 28 Sep 2015 14:12:44 -0700 Subject: [Baypiggies] How to create a dict of counts using functional programming In-Reply-To: References: Message-ID: "functional programming" == "no alteration of existing data"; the `count` function below is not FP by this definition. (FP "avoids changing-state and mutable data" is how Wikipedia phrases this definition). I did mention that by a slightly stricter definition the assignment `item = next(it, _sentinel)` in my code might also be said to be non-FP (though it is by the definition above, since local variable `item` is NOT "existing data" before the assignment) -- but, the stricter definition (forbidding all assignment) can be respected by using one more function, and argument passing in lieu of assignment. I.e: def _count_aux2(item, it, adict); return adict if item is _sentinel else _count_aux(it, dict(adict, *{item: adict.get(item, 0) + 1}) def _count_aux(it, adict): return _count_aux2(next(it, _sentinel), it, adict) Marylin's suggestion *is* FP -- but, it's quadratic (O(N**2)), while this one is linear (O(N))... like your non-FP one. Alex On Mon, Sep 28, 2015 at 1:58 PM, Simeon Franklin wrote: > I agree wrt to recursion in Python. But if the correct solution > (collections.Counter) didn't exist we could write a reduce function. > Doesn't that seem to be the right FP idiom for the task at hand - it takes > an input iterable and produces a single calculated result? > > >>> def count(total, item): > ... total[item] = total.get(item, 0) + 1 > ... return total > ... > >>> data = "Simeon Franklin" > >>> reduce(count, data, {}) > {'a': 1, ' ': 1, 'e': 1, 'F': 1, 'i': 2, 'k': 1, 'm': 1, 'l': 1, 'o': 1, > 'n': 3, 'S': 1, 'r': 1} > > This doesn't seem so bad to me! > > > On Mon, Sep 28, 2015 at 7:01 AM, Alex Martelli via Baypiggies < > baypiggies at python.org> wrote: > >> If for some weird reason in can't use collections.Counter, as David >> sensibly suggests, the "FP way" (slow and cranky in Python, which doesn't >> do tail-call optimization, NOT being a functional programming language) is >> recursion: >> >> _sentinel = object() >> >> def _count_aux(it, adict): >> item = next(it, _sentinel) >> return adict if item is _sentinel else _count_aux(it, dict(adict, >> *{item: adict.get(item, 0) + 1}) >> def count(iterable): >> return _count_aux(iter(iterable), {}) >> > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: