From wilson.tamarrie at gmail.com Mon Dec 3 02:10:48 2012 From: wilson.tamarrie at gmail.com (T Wilson) Date: Sun, 2 Dec 2012 19:10:48 -0600 Subject: [Chicago] python office hours In-Reply-To: References: Message-ID: if you can put it together. I'm in and have 2 people that would be interested also. Will help out any way i can. On Fri, Nov 30, 2012 at 9:23 AM, sheila miguez wrote: > > quoting replies inline in response to my question on why people don't show > up to python office hours at ps:one. > > On Nov 27, 2012 4:49 PM, "T Wilson" wrote: > > > > I leave work at 5pm and at school until 10pm you guys are way gone by > then. even if my class is downtown. I don't think they want to meet on a > Friday or early Sat. Heck I would take a Sunday if it's possible. > > > > Sometimes I'm at ps:one on a weekend. It's not beyond the pale to put > something together. Keep in mind that I don't have any teaching experience > so will be discombobulated until I have more. > > Okay, so I'd like to set up something specifically on a weekend, > > 1. maybe not in December, I'll check. > 2. I'd like a person with more experience around (or at least on irc) to > field questions. > 3. I'd like a small quorum, maybe at least 3 to 5 people who want to learn > at a similar skill level. if it's not just me helping, then a few more. > > > On Tue, Nov 27, 2012 at 4:45 PM, David Dumas > wrote: > >> > >> > Why don't more of you show up at ps:one for python office hours? > >> > Sometimes I see people ask questions on the mailing list, but they > >> > don't show up to the office hours. > >> > >> One would need to be a (paying) PS:One member to attend the office > hours, right? > >> > > Nope. People can attend for something a member is hosting. > > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From shekay at pobox.com Mon Dec 3 19:07:40 2012 From: shekay at pobox.com (sheila miguez) Date: Mon, 3 Dec 2012 12:07:40 -0600 Subject: [Chicago] Python office hours at PS:One this week Message-ID: Hi Chipy! This is a reminder for python office hours this week. Python Office Hours is for people of all experience levels. It happens on the 1st and 3rd Thursdays of the month. There are usually 5 to 10 people who show up. RSVP here: http://www.meetup.com/ChiPyFans/events/93878812/ -- sheila From dan at streemit.net Mon Dec 3 21:33:41 2012 From: dan at streemit.net (D Mahoney) Date: Mon, 03 Dec 2012 14:33:41 -0600 Subject: [Chicago] Passing an expression into Python then executing it Message-ID: <50BD0CA5.50908@streemit.net> I'm working on a log file parser and have a bunch of regular expressions I want to watch for and for each regex I have an expression that tells me what re output result I want to return for analysis. For example, one of my instruction lines might look like: '(Connection closed by ([a-zA-Z0-9.-]+)', 'groups()[0]' What that would tell me is that after I do a re.search of the compiled regex against my log file line, if the input line matches the regex I want to return the contents of groups()[0] to the calling code. I am at a loss as to how to do this. I've been experimenting with the "compile" and "exec" commands, but haven't been able to figure out how to do what I'm attempting. I've also tried using backticks, but so far all I've been able to do is return the string "groups()[0]". Is there a reasonable way to do what I'm attempting, or should I look for a different approach? From thatmattbone at gmail.com Mon Dec 3 21:50:23 2012 From: thatmattbone at gmail.com (Matt Bone) Date: Mon, 3 Dec 2012 14:50:23 -0600 Subject: [Chicago] Passing an expression into Python then executing it In-Reply-To: <50BD0CA5.50908@streemit.net> References: <50BD0CA5.50908@streemit.net> Message-ID: I'd avoid the problem and build a dictionary from regex's to functions. Here's an example (in python 2.7): http://pastebin.com/4gUBb4W8 --matt On Mon, Dec 3, 2012 at 2:33 PM, D Mahoney wrote: > '(Connection closed by ([a-zA-Z0-9.-]+)', 'groups()[0]' -------------- next part -------------- An HTML attachment was scrubbed... URL: From kumar.mcmillan at gmail.com Mon Dec 3 22:10:26 2012 From: kumar.mcmillan at gmail.com (Kumar McMillan) Date: Mon, 3 Dec 2012 15:10:26 -0600 Subject: [Chicago] Passing an expression into Python then executing it In-Reply-To: <50BD0CA5.50908@streemit.net> References: <50BD0CA5.50908@streemit.net> Message-ID: On Mon, Dec 3, 2012 at 2:33 PM, D Mahoney wrote: > I'm working on a log file parser and have a bunch of regular expressions I > want to watch for and for each regex I have an expression that tells me > what re output result I want to return for analysis. For example, one of my > instruction lines might look like: > '(Connection closed by ([a-zA-Z0-9.-]+)', 'groups()[0]' > What that would tell me is that after I do a re.search of the compiled > regex against my log file line, if the input line matches the regex I want > to return the contents of groups()[0] to the calling code. > > I am at a loss as to how to do this. > > I've been experimenting with the "compile" and "exec" commands, but > haven't been able to figure out how to do what I'm attempting. I've also > tried using backticks, but so far all I've been able to do is return the > string "groups()[0]". > Hi Dan. It sounds like you are on the right track. The pattern you're describing is common but in Python we generally handle it with callbacks. So you could do it like this: expr = ['(Connection closed by ([a-zA-Z0-9.-]+)', processor] Notice how instead of mapping an expression to a string of code, each expression is mapped to a callback. The callback could look like this: def processor(match_ob): return match_ob.groups()[0] I think that would give you the same flexibility you were trying to achieve by executing a string of code. > > Is there a reasonable way to do what I'm attempting, or should I look for > a different approach? > ______________________________**_________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/**mailman/listinfo/chicago > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dale at codefu.org Mon Dec 3 22:53:12 2012 From: dale at codefu.org (Dale) Date: Mon, 3 Dec 2012 15:53:12 -0600 Subject: [Chicago] Passing an expression into Python then executing it In-Reply-To: <50BD0CA5.50908@streemit.net> References: <50BD0CA5.50908@streemit.net> Message-ID: On Mon, Dec 3, 2012 at 2:33 PM, D Mahoney wrote: > > I'm working on a log file parser and have a bunch of regular expressions I want to watch for and for each regex I have an expression that tells me what re output result I want to return for analysis. For example, one of my instruction lines might look like: > '(Connection closed by ([a-zA-Z0-9.-]+)', 'groups()[0]' > What that would tell me is that after I do a re.search of the compiled regex against my log file line, if the input line matches the regex I want to return the contents of groups()[0] to the calling code. First, to answer your question, this works: ~~~~~~ import re import inspect REGEXPS = [(r"(foo)", "groups()[0]")] INPUT = "foo" for regexp, expression in REGEXPS: match = re.search(regexp, INPUT) if match: match_dict = dict(inspect.getmembers(match)) print repr(regexp), "matched with result:", eval(expression, match_dict) ~~~~~~ That dict(inspect.getmembers(match)) builds a dictionary of attribute -> value for every attribute on the match object, and then it uses that as the globals dictionary to evaluate your expression. Don't do this. Please. It's bad in several ways. I'm afraid I don't really have time to explain right now, but this is almost certain to lead to headaches. I just wanted to demonstrate how it can be done for academic purposes. The other suggestions you've already gotten are good. To those I'll add: Can you always just extract group 1? Here's an example using your original regexp: ~~~~~~ >>> match = re.search(r"Connection closed by ([a-zA-Z0-9.-]+)", ... "Connection closed by 1.2.3.4") >>> match.group(1) '1.2.3.4' ~~~~~~ Note that I removed the outer parentheses because they were superfluous in this example. (Also note that there's no reason to call groups()[1]; group(1) will do just fine.) Maybe sometimes you need to use more than one set of parentheses, which could change the number of the group you want? If that's the problem, do you know about the (?:...) construct? Example: ~~~~~~ >>> match = re.search(r"Connection (?:opened|closed) by ([a-zA-Z0-9.-]+)", "Connection closed by 1.2.3.4") >>> match.group(1) '1.2.3.4' ~~~~~~ Note that I used two sets of parentheses but only created one group: (?:opened|closed) works just like (opened|closed), but it doesn't capture what's inside into a numbered group. Finally, are you aware of named groups? For example: ~~~~~~ >>> match = re.search(r"Connection closed by (?P
[a-zA-Z0-9.-]+)", ... "Connection closed by 1.2.3.4") >>> match.group("address") '1.2.3.4' >>> match.groupdict() {'address': '1.2.3.4'} ~~~~~~ Named groups let you assign a name to a captured group, like "address" above. That way you don't have to worry about what order your groups come in. You can also get all the named groups out of a match with the groupdict method. You could then very easily do thing like 'if "username" in match.groupdict(): ...' to only take an action if a particular regular expression may hold a "username" group. Regards, Dale From deadwisdom at gmail.com Mon Dec 3 23:20:16 2012 From: deadwisdom at gmail.com (Brantley Harris) Date: Mon, 3 Dec 2012 16:20:16 -0600 Subject: [Chicago] Passing an expression into Python then executing it In-Reply-To: <50BD0CA5.50908@streemit.net> References: <50BD0CA5.50908@streemit.net> Message-ID: Essentially you have instructions that are a pair (regex, result). How complex do you want ``result`` to be? Kumar is right that you can be infinitely complex by passing it in as a pure function. This is likely you're best bet. However, if you need it to be a string, because of easy configuration or some other reason, then you have to pass something meaningful into it. You have a few options after that, one is to just have a {0, 1, 2, 3, ..., n} and return the m.groups()[n]. But something tells me you want something a bit more complex. Another is completely unsafe, security-wise, but unquestionably easy and powerful: def get_result(m, code): return eval(code, {}, {'m': m}) Then you can do: >>> regex, result = 'Connection closed by ([a-zA-Z0-9.-]+)', 'm.groups()[0]' >>> m = re.match(regex, 'Connection closed by TheCloser') >>> print get_result(m, result) TheCloser This is, as I said, completely insecure. If anyone is allowed to specify the "result", they could do whatever they wanted to your system. Another is to run it as a template. Safe and secure, and allows rather high complexities: from jinja2 import Template def get_result(m, code): return Template(code).render(m=m) Then you can do: >>> regex, result = 'Connection closed by ([a-zA-Z0-9.-]+)', '{{ m.groups()[0] }}' >>> m = re.match(regex, 'Connection closed by TheCloser') >>> print get_result(m, result) TheCloser Along with any of the other complexities available in the Jinja2 Template Library. On Mon, Dec 3, 2012 at 2:33 PM, D Mahoney wrote: > For -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan at streemit.net Tue Dec 4 19:11:17 2012 From: dan at streemit.net (D Mahoney) Date: Tue, 04 Dec 2012 12:11:17 -0600 Subject: [Chicago] Passing an expression into Python then executing it In-Reply-To: References: <50BD0CA5.50908@streemit.net> Message-ID: <50BE3CC5.1070000@streemit.net> Thanks for the wonderful advice, everybody! I love reading this mailing list - I learn a lot here. It does indeed look like callbacks are the way to go. That would allow me to easily resolve a couple other small issues I've been seeing with my code. I'll make the changes to use callbacks this afternoon. It would be wonderful if I could just always grab groups()[0], but in a few instances I need to grab other stuff. Kernel messages, for example, where the string looks like "kernel: [] vfs_read+0xcb/0x171". In this instance I want to capture the "vfs_read" part but don't care (for summary purposes" what memory address is associated with it. I could take care of this with a more elaborate regex, but given the audience that is going to be using this tool a simpler regex that makes use of callbacks ought be a better fit. Again, thanks for all the input. I'm going to study all of your suggestions, and move my code to the callback solution right away. On 12/03/2012 04:20 PM, Brantley Harris wrote: > Essentially you have instructions that are a pair (regex, result). > How complex do you want ``result`` to be? Kumar is right that you > can be infinitely complex by passing it in as a pure function. This > is likely you're best bet. > > However, if you need it to be a string, because of easy configuration > or some other reason, then you have to pass something meaningful into it. > > You have a few options after that, one is to just have a {0, 1, 2, 3, > ..., n} and return the m.groups()[n]. But something tells me you want > something a bit more complex. > > > Another is completely unsafe, security-wise, but unquestionably easy > and powerful: > > def get_result(m, code): > return eval(code, {}, {'m': m}) > > Then you can do: > >>> regex, result = 'Connection closed by ([a-zA-Z0-9.-]+)', > 'm.groups()[0]' > >>> m = re.match(regex, 'Connection closed by TheCloser') > >>> print get_result(m, result) > TheCloser > > This is, as I said, completely insecure. If anyone is allowed to > specify the "result", they could do whatever they wanted to your system. > > > Another is to run it as a template. Safe and secure, and allows > rather high complexities: > > from jinja2 import Template > def get_result(m, code): > return Template(code).render(m=m) > > Then you can do: > >>> regex, result = 'Connection closed by ([a-zA-Z0-9.-]+)', '{{ > m.groups()[0] }}' > >>> m = re.match(regex, 'Connection closed by TheCloser') > >>> print get_result(m, result) > TheCloser > > Along with any of the other complexities available in the Jinja2 > Template Library. > > > On Mon, Dec 3, 2012 at 2:33 PM, D Mahoney > wrote: > > For > > > > > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago -------------- next part -------------- An HTML attachment was scrubbed... URL: From brianhray at gmail.com Wed Dec 5 14:50:27 2012 From: brianhray at gmail.com (Brian Ray) Date: Wed, 5 Dec 2012 07:50:27 -0600 Subject: [Chicago] Venue and Talks found for Next Weeks Meeting Message-ID: Really good news! We have full sponsorship for next weekend's meeting at Excelerate Labs in 1871 from our friends over at SpotHero. RSVP is now open -> http://chipy.org I am working with Tal and Jordan on some better talk descriptions. -- Brian Ray @brianray (773) 669-7717 -------------- next part -------------- An HTML attachment was scrubbed... URL: From malcolm.newsome at gmail.com Wed Dec 5 16:38:47 2012 From: malcolm.newsome at gmail.com (Malcolm Newsome) Date: Wed, 5 Dec 2012 09:38:47 -0600 Subject: [Chicago] Get/Set/Accessors in Python? Message-ID: Hey ChiPy, Python is/was my first language. Yet, I've recently begun learning C# for my new job. One thing I've come across in C# (and, quite frankly, am having a difficult time grasping) is Get and Set (Accessors). Since, I don't ever recall reading about this in Python, I'm wondering if they exist. If not, what is the "thinking" behind why they are not included in the language? Additionally, a separate, but perhaps related question is that I have not seen public/private classes in Python. How might this factor into the whole accessor scenario? (Or, am I trying to relate two topics that have nothing to do with each other?) Hopefully these questions are clear enough... Thanks in advance, Malcolm Newsome -------------- next part -------------- An HTML attachment was scrubbed... URL: From orblivion at gmail.com Wed Dec 5 16:54:41 2012 From: orblivion at gmail.com (Dan Krol) Date: Wed, 5 Dec 2012 07:54:41 -0800 Subject: [Chicago] Get/Set/Accessors in Python? In-Reply-To: References: Message-ID: http://docs.python.org/2/library/functions.html#property Or if get, set, and delete are just not enough granularity: http://docs.python.org/2/howto/descriptor.html On Wed, Dec 5, 2012 at 7:38 AM, Malcolm Newsome wrote: > Hey ChiPy, > > Python is/was my first language. Yet, I've recently begun learning C# for > my new job. > > One thing I've come across in C# (and, quite frankly, am having a difficult > time grasping) is Get and Set (Accessors). > > Since, I don't ever recall reading about this in Python, I'm wondering if > they exist. If not, what is the "thinking" behind why they are not included > in the language? > > Additionally, a separate, but perhaps related question is that I have not > seen public/private classes in Python. How might this factor into the whole > accessor scenario? (Or, am I trying to relate two topics that have nothing > to do with each other?) > > Hopefully these questions are clear enough... > > Thanks in advance, > > Malcolm Newsome > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago > From tottinge at gmail.com Wed Dec 5 17:09:08 2012 From: tottinge at gmail.com (Tim Ottinger) Date: Wed, 5 Dec 2012 08:09:08 -0800 Subject: [Chicago] Get/Set/Accessors in Python? In-Reply-To: References: Message-ID: We have them but they're not terribly useful. they're not all that useful on c# really since a bar with a getter and setter is effectively a public variable. look at "property" On Dec 5, 2012 7:44 AM, "Malcolm Newsome" wrote: > Hey ChiPy, > > Python is/was my first language. Yet, I've recently begun learning C# for > my new job. > > One thing I've come across in C# (and, quite frankly, am having a > difficult time grasping) is Get and Set (Accessors). > > Since, I don't ever recall reading about this in Python, I'm wondering if > they exist. If not, what is the "thinking" behind why they are not > included in the language? > > Additionally, a separate, but perhaps related question is that I have not > seen public/private classes in Python. How might this factor into the > whole accessor scenario? (Or, am I trying to relate two topics that have > nothing to do with each other?) > > Hopefully these questions are clear enough... > > Thanks in advance, > > Malcolm Newsome > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From brian at python.org Wed Dec 5 17:15:48 2012 From: brian at python.org (Brian Curtin) Date: Wed, 5 Dec 2012 10:15:48 -0600 Subject: [Chicago] Get/Set/Accessors in Python? In-Reply-To: References: Message-ID: On Wed, Dec 5, 2012 at 9:38 AM, Malcolm Newsome wrote: > Additionally, a separate, but perhaps related question is that I have not > seen public/private classes in Python. How might this factor into the whole > accessor scenario? (Or, am I trying to relate two topics that have nothing > to do with each other?) There's no notion of private classes, but you could create private attributes on a class using a leading double underscore. I and most others don't recommend doing this. class MyClass: def __private(self): ... Python uses "name mangling" to hide the __private method, but nothing is stopping you from unmangling the name and just calling mangled names. Check out this first paragraph for more information: http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Objects From diomedestydeus at gmail.com Wed Dec 5 17:22:54 2012 From: diomedestydeus at gmail.com (Philip Doctor) Date: Wed, 5 Dec 2012 10:22:54 -0600 Subject: [Chicago] Get/Set/Accessors in Python? In-Reply-To: References: Message-ID: Tim, I agree that they get misused a lot (especially in C#) but I see it's very common to put validation in a set in c#. So maybe syntactically it looks like you're just setting myCar.Speed to 60, but in myCar it's validating that Speed is not negative and it's less than MaxSpeed, etc etc. I actually see this happening more and more in C# with data attributes in msft MVC. They have a public get/set and then an annotation that indicates things like not negative or required, etc etc. I guess the caveat being that without a return value, your only way to really communicate that a value is out of bounds is with an exception throw, so your developers need to be comfortable with that kind of getter/setter feedback. My only point in this ramble being that public get/set, while often cargo culted in and bad style, can actually still be quite useful in c# and a little bit better than a public variable :) On Wed, Dec 5, 2012 at 10:15 AM, Brian Curtin wrote: > On Wed, Dec 5, 2012 at 9:38 AM, Malcolm Newsome > wrote: > > Additionally, a separate, but perhaps related question is that I have not > > seen public/private classes in Python. How might this factor into the > whole > > accessor scenario? (Or, am I trying to relate two topics that have > nothing > > to do with each other?) > > There's no notion of private classes, but you could create private > attributes on a class using a leading double underscore. I and most > others don't recommend doing this. > > class MyClass: > def __private(self): > ... > > Python uses "name mangling" to hide the __private method, but nothing > is stopping you from unmangling the name and just calling mangled > names. > > Check out this first paragraph for more information: > http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Objects > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deadwisdom at gmail.com Wed Dec 5 17:29:15 2012 From: deadwisdom at gmail.com (Brantley Harris) Date: Wed, 5 Dec 2012 10:29:15 -0600 Subject: [Chicago] Get/Set/Accessors in Python? In-Reply-To: References: Message-ID: Interesting, you're essentially ensuring a sort of type check on the attribute. Generally in the python world you only do this sort of checking in a function that takes the object, which strikes me as more positive programming, but I'm not sure why. Possibly because I try very hard to put less logic on the objects themselves and more in the functions/methods that use them, because the less logic on the objects there is, the more pure they are and therefore the more modular. On Wed, Dec 5, 2012 at 10:22 AM, Philip Doctor wrote: > Tim, > I agree that they get misused a lot (especially in C#) but I see it's very > common to put validation in a set in c#. So maybe syntactically it looks > like you're just setting myCar.Speed to 60, but in myCar it's validating > that Speed is not negative and it's less than MaxSpeed, etc etc. I > actually see this happening more and more in C# with data attributes in > msft MVC. They have a public get/set and then an annotation that indicates > things like not negative or required, etc etc. I guess the caveat being > that without a return value, your only way to really communicate that a > value is out of bounds is with an exception throw, so your developers need > to be comfortable with that kind of getter/setter feedback. > > My only point in this ramble being that public get/set, while often cargo > culted in and bad style, can actually still be quite useful in c# and a > little bit better than a public variable :) > > > > > On Wed, Dec 5, 2012 at 10:15 AM, Brian Curtin wrote: > >> On Wed, Dec 5, 2012 at 9:38 AM, Malcolm Newsome >> wrote: >> > Additionally, a separate, but perhaps related question is that I have >> not >> > seen public/private classes in Python. How might this factor into the >> whole >> > accessor scenario? (Or, am I trying to relate two topics that have >> nothing >> > to do with each other?) >> >> There's no notion of private classes, but you could create private >> attributes on a class using a leading double underscore. I and most >> others don't recommend doing this. >> >> class MyClass: >> def __private(self): >> ... >> >> Python uses "name mangling" to hide the __private method, but nothing >> is stopping you from unmangling the name and just calling mangled >> names. >> >> Check out this first paragraph for more information: >> http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Objects >> _______________________________________________ >> Chicago mailing list >> Chicago at python.org >> http://mail.python.org/mailman/listinfo/chicago >> > > > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From shekay at pobox.com Wed Dec 5 17:34:24 2012 From: shekay at pobox.com (sheila miguez) Date: Wed, 5 Dec 2012 10:34:24 -0600 Subject: [Chicago] Get/Set/Accessors in Python? In-Reply-To: References: Message-ID: GRAR sometimes things are so annoying. why must we suffer so? This setter/getter stuff with cross cutting concerns or business logic, or what-have-you. ARG In java, sometimes I handle the validation stuff by making pojos with no setters, but they have builders. The builders provide the validation logic. In the past, when people have put logic in POJO getters and setters for things that get serialized and sent across the wire to a client, I've had reactions like being ape-shit insane due to the annoyances that can arise. I don't know, I guess you can move the ape-shit annoyedness by moving the logic to different parts and then other painful things will happen. With java, I have reacted to painful things by using god-awful builders. to avoid god-awful other things. I bet these are all smells happening due to design but also probably due to the language. not just the design. the design accrues to the language. HULK SMASH On Wed, Dec 5, 2012 at 10:22 AM, Philip Doctor wrote: > Tim, > I agree that they get misused a lot (especially in C#) but I see it's very > common to put validation in a set in c#. So maybe syntactically it looks > like you're just setting myCar.Speed to 60, but in myCar it's validating > that Speed is not negative and it's less than MaxSpeed, etc etc. I actually > see this happening more and more in C# with data attributes in msft MVC. > They have a public get/set and then an annotation that indicates things like > not negative or required, etc etc. I guess the caveat being that without a > return value, your only way to really communicate that a value is out of > bounds is with an exception throw, so your developers need to be comfortable > with that kind of getter/setter feedback. > > My only point in this ramble being that public get/set, while often cargo > culted in and bad style, can actually still be quite useful in c# and a > little bit better than a public variable :) > > > > > On Wed, Dec 5, 2012 at 10:15 AM, Brian Curtin wrote: >> >> On Wed, Dec 5, 2012 at 9:38 AM, Malcolm Newsome >> wrote: >> > Additionally, a separate, but perhaps related question is that I have >> > not >> > seen public/private classes in Python. How might this factor into the >> > whole >> > accessor scenario? (Or, am I trying to relate two topics that have >> > nothing >> > to do with each other?) >> >> There's no notion of private classes, but you could create private >> attributes on a class using a leading double underscore. I and most >> others don't recommend doing this. >> >> class MyClass: >> def __private(self): >> ... >> >> Python uses "name mangling" to hide the __private method, but nothing >> is stopping you from unmangling the name and just calling mangled >> names. >> >> Check out this first paragraph for more information: >> http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Objects >> _______________________________________________ >> Chicago mailing list >> Chicago at python.org >> http://mail.python.org/mailman/listinfo/chicago > > > > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago > -- sheila From shekay at pobox.com Wed Dec 5 17:36:17 2012 From: shekay at pobox.com (sheila miguez) Date: Wed, 5 Dec 2012 10:36:17 -0600 Subject: [Chicago] Get/Set/Accessors in Python? In-Reply-To: References: Message-ID: Btw, yes. On Wed, Dec 5, 2012 at 9:38 AM, Malcolm Newsome wrote: > > Hopefully these questions are clear enough... -- sheila From diomedestydeus at gmail.com Wed Dec 5 18:02:53 2012 From: diomedestydeus at gmail.com (Philip Doctor) Date: Wed, 5 Dec 2012 11:02:53 -0600 Subject: [Chicago] Get/Set/Accessors in Python? In-Reply-To: References: Message-ID: > Possibly because I try very hard to put less logic on the objects themselves and more in the functions/methods that use them Without trying to further transform Sheila into the hulk, I would suggest that's one way to do it, but another way gets are the heart of OO encapsulation and data hiding. If a Car class owns the idea of being a car, then it should own private int speed as well as the way to set speed (either through public void accelerate() or a public setter). Then a call to those methods invokes the business logic in Car because Car owns that business logic, after all, it is the abstraction of a Car. Now when we goto change how a Car works and want to check that the engine is On before we can set speed, we have one place to maintain that code, in Car, and none of the other developers who call our code need to make any changes (unless a developer has a simulation of rolling a car down a hill... then maybe we are in trouble... hopefully we have integration tests). On the other hand, if Car just has a lot of data in it, and you are passing Car to a bunch of functions which then change the variables in Car, then the impact of adding an "On" check is maybe less certain. There's a lot of other code you need to search through for references to Car and see how each one is using Car. Having seen both ways of doing it for many years, I can agree that both are going to have drawbacks, and both are going to be subject to bad coding practices. The most obnoxious of which is easily some developer changing Car by copy+pasting accelerate() into accelerate_new() and then making their modifications there (if you want to talk hulk rage, that's mine right there). So neither is a magic bullet, but having car data hide/etc is the more object oriented approach. Interestingly, one of my favorite blogs by Mark Seemann (who is a dependency injection master) recently had an interesting discussion on encapsulation and information hiding as well. I would highly recommend his take on it too (although there are many great articles on the web): http://blog.ploeh.dk/2012/11/27/EncapsulationOfProperties.aspx On Wed, Dec 5, 2012 at 10:36 AM, sheila miguez wrote: > Btw, yes. > > On Wed, Dec 5, 2012 at 9:38 AM, Malcolm Newsome > wrote: > > > > Hopefully these questions are clear enough... > > > > -- > sheila > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago > -------------- next part -------------- An HTML attachment was scrubbed... URL: From brianhray at gmail.com Wed Dec 5 19:42:15 2012 From: brianhray at gmail.com (Brian Ray) Date: Wed, 5 Dec 2012 12:42:15 -0600 Subject: [Chicago] Speaker Needed Message-ID: Anybody have something they want to present at next week's ChiPy. Get a bunch of +1 and you are in the cool club. -- Brian Ray @brianray (773) 669-7717 -------------- next part -------------- An HTML attachment was scrubbed... URL: From brianhray at gmail.com Wed Dec 5 19:43:55 2012 From: brianhray at gmail.com (Brian Ray) Date: Wed, 5 Dec 2012 12:43:55 -0600 Subject: [Chicago] Venue and Talks found for Next Weeks Meeting In-Reply-To: References: Message-ID: I meant next week's meeting. Yes it is the same time as every month, 7pm 2nd Thursday. This is going to be the best ever. On Wed, Dec 5, 2012 at 7:50 AM, Brian Ray wrote: > Really good news! > > We have full sponsorship for next weekend's meeting at Excelerate Labs in > 1871 from our friends over at SpotHero. > > RSVP is now open -> http://chipy.org > > I am working with Tal and Jordan on some better talk descriptions. > > > -- > Brian Ray > @brianray > (773) 669-7717 > > -- Brian Ray @brianray (773) 669-7717 -------------- next part -------------- An HTML attachment was scrubbed... URL: From carl at personnelware.com Wed Dec 5 19:50:00 2012 From: carl at personnelware.com (Carl Karsten) Date: Wed, 5 Dec 2012 12:50:00 -0600 Subject: [Chicago] Speaker Needed In-Reply-To: References: Message-ID: I think the 2 talks we have are going to use up all of the meeting. On Wed, Dec 5, 2012 at 12:42 PM, Brian Ray wrote: > Anybody have something they want to present at next week's ChiPy. Get a > bunch of +1 and you are in the cool club. > > > -- > Brian Ray > @brianray > (773) 669-7717 > > > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago > -- Carl K From brianhray at gmail.com Wed Dec 5 20:32:44 2012 From: brianhray at gmail.com (Brian Ray) Date: Wed, 5 Dec 2012 13:32:44 -0600 Subject: [Chicago] Speaker Needed In-Reply-To: References: Message-ID: I agree, but we have only one talk on schedule as before lunch. On Wed, Dec 5, 2012 at 12:50 PM, Carl Karsten wrote: > I think the 2 talks we have are going to use up all of the meeting. > > On Wed, Dec 5, 2012 at 12:42 PM, Brian Ray wrote: > > Anybody have something they want to present at next week's ChiPy. Get a > > bunch of +1 and you are in the cool club. > > > > > > -- > > Brian Ray > > @brianray > > (773) 669-7717 > > > > > > _______________________________________________ > > Chicago mailing list > > Chicago at python.org > > http://mail.python.org/mailman/listinfo/chicago > > > > > > -- > Carl K > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago > -- Brian Ray @brianray (773) 669-7717 -------------- next part -------------- An HTML attachment was scrubbed... URL: From tal.liron at threecrickets.com Wed Dec 5 20:33:59 2012 From: tal.liron at threecrickets.com (Tal Liron) Date: Wed, 05 Dec 2012 13:33:59 -0600 Subject: [Chicago] Get/Set/Accessors in Python? In-Reply-To: References: Message-ID: <50BFA1A7.2030609@threecrickets.com> An HTML attachment was scrubbed... URL: From tottinge at gmail.com Wed Dec 5 20:42:17 2012 From: tottinge at gmail.com (Tim Ottinger) Date: Wed, 5 Dec 2012 11:42:17 -0800 Subject: [Chicago] Get/Set/Accessors in Python? In-Reply-To: <50BFA1A7.2030609@threecrickets.com> References: <50BFA1A7.2030609@threecrickets.com> Message-ID: The original idea behind this, by the way, is quite beautiful. Look at Bertrand Meyer's Uniform Access principle. He's not wrong. He was never wrong. I also agree that it _can_ be pretty important and useful. But yes, it's mostly nonsense as practiced by java/c++/c# devs. On Wed, Dec 5, 2012 at 11:33 AM, Tal Liron wrote: > I just want to point out that in Java's case, it's not a matter of the > language itself, but of conventions (the JavaBean standard) that grew on > top of it. Java getters and setters really are 100% regular method calls, > just with names that some mechanisms decide to introspect and use, > sometimes in the terrible ways Sheila describes. :) > > In my talk about Genie/Vala (postponed to next month) you'll that getters > and setters have a lot more mechanisms associated with them, and moreover > have special limitations in terms of passing ownership of values. As it > should be, really! A property should be *of* an object, and if you want to > extract or inject data there are better paradigms. > > -Tal > > > On 12/05/2012 10:34 AM, sheila miguez wrote: > > GRAR sometimes things are so annoying. why must we suffer so? > > This setter/getter stuff with cross cutting concerns or business > logic, or what-have-you. ARG > > In java, sometimes I handle the validation stuff by making pojos with > no setters, but they have builders. The builders provide the > validation logic. In the past, when people have put logic in POJO > getters and setters for things that get serialized and sent across the > wire to a client, I've had reactions like being ape-shit insane due to > the annoyances that can arise. I don't know, I guess you can move the > ape-shit annoyedness by moving the logic to different parts and then > other painful things will happen. With java, I have reacted to painful > things by using god-awful builders. to avoid god-awful other things. I > bet these are all smells happening due to design but also probably due > to the language. not just the design. the design accrues to the > language. HULK SMASH > > > > On Wed, Dec 5, 2012 at 10:22 AM, Philip Doctor wrote: > > Tim, > I agree that they get misused a lot (especially in C#) but I see it's very > common to put validation in a set in c#. So maybe syntactically it looks > like you're just setting myCar.Speed to 60, but in myCar it's validating > that Speed is not negative and it's less than MaxSpeed, etc etc. I actually > see this happening more and more in C# with data attributes in msft MVC. > They have a public get/set and then an annotation that indicates things like > not negative or required, etc etc. I guess the caveat being that without a > return value, your only way to really communicate that a value is out of > bounds is with an exception throw, so your developers need to be comfortable > with that kind of getter/setter feedback. > > My only point in this ramble being that public get/set, while often cargo > culted in and bad style, can actually still be quite useful in c# and a > little bit better than a public variable :) > > > > > On Wed, Dec 5, 2012 at 10:15 AM, Brian Curtin wrote: > > On Wed, Dec 5, 2012 at 9:38 AM, Malcolm Newsome wrote: > > Additionally, a separate, but perhaps related question is that I have > not > seen public/private classes in Python. How might this factor into the > whole > accessor scenario? (Or, am I trying to relate two topics that have > nothing > to do with each other?) > > There's no notion of private classes, but you could create private > attributes on a class using a leading double underscore. I and most > others don't recommend doing this. > > class MyClass: > def __private(self): > ... > > Python uses "name mangling" to hide the __private method, but nothing > is stopping you from unmangling the name and just calling mangled > names. > > Check out this first paragraph for more information:http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Objects > _______________________________________________ > Chicago mailing listChicago at python.orghttp://mail.python.org/mailman/listinfo/chicago > > > > _______________________________________________ > Chicago mailing listChicago at python.orghttp://mail.python.org/mailman/listinfo/chicago > > > > > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago > > -- Tim Ottinger, Sr. Consultant, Industrial Logic ------------------------------------- http://www.industriallogic.com/ http://agileinaflash.com/ http://agileotter.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From shekay at pobox.com Wed Dec 5 20:44:57 2012 From: shekay at pobox.com (sheila miguez) Date: Wed, 5 Dec 2012 13:44:57 -0600 Subject: [Chicago] Get/Set/Accessors in Python? In-Reply-To: <50BFA1A7.2030609@threecrickets.com> References: <50BFA1A7.2030609@threecrickets.com> Message-ID: Oh! I guess I missed that you postponed it. I thought you and Jordan had talks next week. On Wed, Dec 5, 2012 at 1:33 PM, Tal Liron wrote: > In my talk about Genie/Vala (postponed to next month) -- sheila From joegermuska at gmail.com Wed Dec 5 16:54:47 2012 From: joegermuska at gmail.com (Joe Germuska) Date: Wed, 5 Dec 2012 09:54:47 -0600 Subject: [Chicago] Venue and Talks found for Next Weeks Meeting In-Reply-To: References: Message-ID: Be sure to pop over to the OpenGovChicago holiday party also happening at 1871 next Thursday. Also, I'm hiring two developers for a Knight News Challenge grant to build out an awesome web site to make Census data easier for journalists to use. It's pretty well documented out on the web, so if you're interested, do some googling and hit me up to tell me why you're someone who should be part of the team. Joe -- Joe Germuska Joe at Germuska.com * http://blog.germuska.com * http://twitter.com/JoeGermuska "Science's job is to map our ignorance." --David Byrne On Dec 5, 2012, at 7:50 AM, Brian Ray wrote: > Really good news! > > We have full sponsorship for next weekend's meeting at Excelerate Labs in 1871 from our friends over at SpotHero. > > RSVP is now open -> http://chipy.org > > I am working with Tal and Jordan on some better talk descriptions. > > > -- > Brian Ray > @brianray > (773) 669-7717 > > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago -------------- next part -------------- An HTML attachment was scrubbed... URL: From brianhray at gmail.com Wed Dec 12 04:11:27 2012 From: brianhray at gmail.com (Brian Ray) Date: Tue, 11 Dec 2012 21:11:27 -0600 Subject: [Chicago] RSVP for Thursday's meeting Message-ID: If you think you might attend: RSVP -> http://chipy.org/ The location is 1871 and we will be in Excelerate Labs. This will help us order enough food/drink. See you there! -- Brian Ray @brianray (773) 669-7717 -------------- next part -------------- An HTML attachment was scrubbed... URL: From carl at personnelware.com Wed Dec 12 09:24:47 2012 From: carl at personnelware.com (Carl Karsten) Date: Wed, 12 Dec 2012 02:24:47 -0600 Subject: [Chicago] RSVP for Thursday's meeting In-Reply-To: References: Message-ID: On Tue, Dec 11, 2012 at 9:11 PM, Brian Ray wrote: > we will be in Excelerate Labs. What does that mean? -- Carl K From emperorcezar at gmail.com Wed Dec 12 12:36:08 2012 From: emperorcezar at gmail.com (Cezar Jenkins) Date: Wed, 12 Dec 2012 05:36:08 -0600 Subject: [Chicago] RSVP for Thursday's meeting In-Reply-To: References: Message-ID: Well, if you're using the RSVP to count buying beer, you should count me at two. <3 On Dec 11, 2012, at 9:11 PM, Brian Ray wrote: > If you think you might attend: > > RSVP -> http://chipy.org/ > > The location is 1871 and we will be in Excelerate Labs. > > This will help us order enough food/drink. > > See you there! > > -- > Brian Ray > @brianray > (773) 669-7717 > > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago -------------- next part -------------- An HTML attachment was scrubbed... URL: From brian at python.org Wed Dec 12 16:46:07 2012 From: brian at python.org (Brian Curtin) Date: Wed, 12 Dec 2012 09:46:07 -0600 Subject: [Chicago] RSVP for Thursday's meeting In-Reply-To: References: Message-ID: On Tue, Dec 11, 2012 at 9:11 PM, Brian Ray wrote: > If you think you might attend: > > RSVP -> http://chipy.org/ > > The location is 1871 and we will be in Excelerate Labs. > > This will help us order enough food/drink. > > See you there! Is the schedule up to date on the site? From brianhray at gmail.com Wed Dec 12 17:02:49 2012 From: brianhray at gmail.com (Brian Ray) Date: Wed, 12 Dec 2012 10:02:49 -0600 Subject: [Chicago] RSVP for Thursday's meeting In-Reply-To: References: Message-ID: <69369239-F1A7-4CE3-9A13-0A47F4404BBC@gmail.com> On Dec 12, 2012, at 2:24 AM, Carl Karsten wrote: > On Tue, Dec 11, 2012 at 9:11 PM, Brian Ray wrote: >> we will be in Excelerate Labs. > > What does that mean? > It in a different room, I will get you in touch with the host. From brianhray at gmail.com Wed Dec 12 17:04:34 2012 From: brianhray at gmail.com (Brian Ray) Date: Wed, 12 Dec 2012 10:04:34 -0600 Subject: [Chicago] RSVP for Thursday's meeting In-Reply-To: References: Message-ID: <031064DB-175D-4D21-9559-AC8ED7D90201@gmail.com> On Dec 12, 2012, at 9:46 AM, Brian Curtin wrote: > On Tue, Dec 11, 2012 at 9:11 PM, Brian Ray wrote: >> If you think you might attend: >> >> RSVP -> http://chipy.org/ >> >> The location is 1871 and we will be in Excelerate Labs. >> >> This will help us order enough food/drink. >> >> See you there! > > Is the schedule up to date on the site? > I have been talking with one member about an imaging (PIL alternative) talk. You got something, Brian? From p.wallenberg at gmail.com Wed Dec 19 23:02:46 2012 From: p.wallenberg at gmail.com (Paul Wallenberg) Date: Wed, 19 Dec 2012 16:02:46 -0600 Subject: [Chicago] Java with some Python Message-ID: Hi ChiPy, I am working with an association that is running into some problems with extensions they have built on top of their Association Management System (AMS). Their developer built a number of different web service extensions in Python, Java, and PHP. Unfortunately, he has run into some work visa issues and is not able to work until things get resolved. Thus, they need a developer to step in to fill the void. There are numerous new development initatives on the horizon, but a critical component of the job will be supporting and enhancing already existing extensions. Documentation does exist - however, the CTO is brand new and he wasn't able to give me a clear indication of how reliable it is in its current state. The developer will be available for any questions/issues that arise, but can't physically perform any of the work. Their AMS is Personify which is .NET and sits on MS SQL. There's no firm end date or timeframe for the position, but they are looking for someone to start as soon as possible (the new year would be okay). The CTO also expressed interest in bringing someone on board that would want to evaluate the position permanently. Therefore, this could work for any freelance developers/consultants or someone looking to make a career move. On contract, it would pay $45/hr and permanently, the salary would be $80,000 per year. If you're interested, feel free to reply to this email. Happy holidays! All my best, Paul Wallenberg -------------- next part -------------- An HTML attachment was scrubbed... URL: From danieltpeters at gmail.com Fri Dec 21 23:05:03 2012 From: danieltpeters at gmail.com (Daniel Peters) Date: Fri, 21 Dec 2012 16:05:03 -0600 Subject: [Chicago] any advice is appreciated Message-ID: I'm at my wits end here. This is a seemingly functional question I've got two lists list1 is a list of compiled regular expression match objects *and possibly *None values, culled from the text of an elementtree element list2 is a list of ElementTree elements (each of which happens to be a sibling to the element the regexs were taken from) The length and order of the lists mirror each other, meaning, each are X long and have the same ordering, since they both come from the same parent. So, theoretically I should be able to conditionalize some kind of map-like operation such that for each index of list2 i can stuff the corresponding index from list1 into the elements .text method *or* if the value is None (no regexs found), the operation continues on maintaining order, simply skipping the None values since that node was ill formed anyway. I've tried list comprehensions, map itself and simply stacking for loops. When I can get anything to work at all, i get the last item of the regex list (list1) in *all* of the positions of list2. Any help would be deeply appreciated. also, thanks jeremy mcmillian. Clearly I did *not* double down and write a parser. The sysadmin decided to install 2.6 for me, so I have elementtree now. Thanks again. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tal.liron at threecrickets.com Fri Dec 21 23:08:56 2012 From: tal.liron at threecrickets.com (Tal Liron) Date: Fri, 21 Dec 2012 16:08:56 -0600 Subject: [Chicago] Genie presentation coming up Message-ID: <50D4DDF8.9060803@threecrickets.com> An HTML attachment was scrubbed... URL: From thatmattbone at gmail.com Fri Dec 21 23:13:58 2012 From: thatmattbone at gmail.com (Matt Bone) Date: Fri, 21 Dec 2012 16:13:58 -0600 Subject: [Chicago] any advice is appreciated In-Reply-To: References: Message-ID: You might be looking for zip(). for regex_thing, element in zip(list1, list2): if regex_thing is None: pass else: do_the_stuff_you_wanna_do() --matt On Fri, Dec 21, 2012 at 4:05 PM, Daniel Peters wrote: > I'm at my wits end here. This is a seemingly functional question > > > I've got two lists > list1 is a list of compiled regular expression match objects *and > possibly *None values, culled from the text of an elementtree element > list2 is a list of ElementTree elements (each of which happens to be a > sibling to the element the regexs were taken from) > The length and order of the lists mirror each other, meaning, each are X > long and have the same ordering, since they both come from the same parent. > > So, theoretically I should be able to conditionalize some kind of map-like > operation such that for each index of list2 i can stuff the corresponding > index from list1 into > the elements .text method *or* if the value is None (no regexs found), > the operation continues on maintaining order, simply skipping the None > values since that node was ill formed anyway. > > I've tried list comprehensions, map itself and simply stacking for loops. > When I can get anything to work at all, i get the last item of the regex > list (list1) in *all* of the positions of list2. > > Any help would be deeply appreciated. > > also, thanks jeremy mcmillian. Clearly I did *not* double down and write > a parser. The sysadmin decided to install 2.6 for me, so I have > elementtree now. Thanks again. > > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From danieltpeters at gmail.com Fri Dec 21 23:21:17 2012 From: danieltpeters at gmail.com (Daniel Peters) Date: Fri, 21 Dec 2012 16:21:17 -0600 Subject: [Chicago] any advice is appreciated In-Reply-To: References: Message-ID: Matt Bone you a freaking a saint. that was exactly what i wanted. holy shit man. I can't believe how long i spent trying to get that to work. On Fri, Dec 21, 2012 at 4:13 PM, Matt Bone wrote: > You might be looking for zip(). > > for regex_thing, element in zip(list1, list2): > if regex_thing is None: > pass > else: > do_the_stuff_you_wanna_do() > > --matt > > > On Fri, Dec 21, 2012 at 4:05 PM, Daniel Peters wrote: > >> I'm at my wits end here. This is a seemingly functional question >> >> >> I've got two lists >> list1 is a list of compiled regular expression match objects *and >> possibly *None values, culled from the text of an elementtree element >> list2 is a list of ElementTree elements (each of which happens to be a >> sibling to the element the regexs were taken from) >> The length and order of the lists mirror each other, meaning, each are X >> long and have the same ordering, since they both come from the same parent. >> >> So, theoretically I should be able to conditionalize some kind of >> map-like operation such that for each index of list2 i can stuff the >> corresponding index from list1 into >> the elements .text method *or* if the value is None (no regexs found), >> the operation continues on maintaining order, simply skipping the None >> values since that node was ill formed anyway. >> >> I've tried list comprehensions, map itself and simply stacking for >> loops. When I can get anything to work at all, i get the last item of the >> regex list (list1) in *all* of the positions of list2. >> >> Any help would be deeply appreciated. >> >> also, thanks jeremy mcmillian. Clearly I did *not* double down and >> write a parser. The sysadmin decided to install 2.6 for me, so I have >> elementtree now. Thanks again. >> >> _______________________________________________ >> Chicago mailing list >> Chicago at python.org >> http://mail.python.org/mailman/listinfo/chicago >> >> > > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From livne at uchicago.edu Fri Dec 21 23:36:23 2012 From: livne at uchicago.edu (Oren Livne) Date: Fri, 21 Dec 2012 16:36:23 -0600 Subject: [Chicago] Segments in binary array Message-ID: <50D4E467.4040709@uchicago.edu> Dear All, I have a binary numpy array A. I would like to find all ranges of consecutive 0's of length >= L in A. What would be an efficient implementation? Thanks, Oren From kenschutte at gmail.com Sat Dec 22 01:41:06 2012 From: kenschutte at gmail.com (Ken Schutte) Date: Fri, 21 Dec 2012 18:41:06 -0600 Subject: [Chicago] Segments in binary array In-Reply-To: <50D4E467.4040709@uchicago.edu> References: <50D4E467.4040709@uchicago.edu> Message-ID: I'm not sure if it's most efficient, but for something that doesn't use a Python for-loop, you can do this: WARNING: doesn't handle edge cases! need to add a couple checks if zero ranges go to first or last index. import numpy as np A = np.array([1,0,0,1,0,0,0,1,1,0,0,0,0,1,1,1]) L = 3 changes = np.where(np.diff(A == 0))[0] starts = changes[::2] + 1 lengths = changes[1::2] - changes[::2] idx = np.where(lengths >= L)[0] # ranges that are long enough print "Ranges (start,len): ", zip(starts[idx], lengths[idx]) On Fri, Dec 21, 2012 at 4:36 PM, Oren Livne wrote: > Dear All, > > I have a binary numpy array A. I would like to find all ranges of > consecutive 0's of length >= L in A. What would be an efficient > implementation? > > Thanks, > Oren > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago From carl at personnelware.com Sat Dec 22 03:03:04 2012 From: carl at personnelware.com (Carl Karsten) Date: Fri, 21 Dec 2012 20:03:04 -0600 Subject: [Chicago] Segments in binary array In-Reply-To: <50D4E467.4040709@uchicago.edu> References: <50D4E467.4040709@uchicago.edu> Message-ID: for L = 3, how many ranges are in: 0,0,0,0 ? I can find 3: 1,2,3 1,2,3,4 2,3,4 But if you are not allowed to reuse, then just the 1234 one is all there is. but that still leaves 0,0,0,0,0,0 123 and 456 give you 2 ranges with no reuse. Is that better than one long one? On Fri, Dec 21, 2012 at 4:36 PM, Oren Livne wrote: > Dear All, > > I have a binary numpy array A. I would like to find all ranges of > consecutive 0's of length >= L in A. What would be an efficient > implementation? > > Thanks, > Oren > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago -- Carl K From maney at two14.net Sat Dec 22 05:43:47 2012 From: maney at two14.net (Martin Maney) Date: Fri, 21 Dec 2012 22:43:47 -0600 Subject: [Chicago] any advice is appreciated In-Reply-To: References: Message-ID: <20121222044347.GB12807@furrr.two14.net> On Fri, Dec 21, 2012 at 04:21:17PM -0600, Daniel Peters wrote: > Matt Bone you a freaking a saint. that was exactly what i wanted. holy > shit man. I can't believe how long i spent trying to get that to work. Don't want to steal Matt's saintly thunder at all, but I have to admit that where I, too, would have immediately thought of using zip back when Python's functional aspect was new and exciting, today I'd just write an old-fashioned index loop - for i in range(len(list1)). The wonderfullest thing about Python is that it doesn't force one way of thinking about things - it's multiparadigmatic! -- People make secure systems insecure because insecure systems do what people want and secure systems don't. -- James Grimmelmann From livne at uchicago.edu Sun Dec 23 15:39:30 2012 From: livne at uchicago.edu (Oren Livne) Date: Sun, 23 Dec 2012 08:39:30 -0600 Subject: [Chicago] Segments in binary array In-Reply-To: References: <50D4E467.4040709@uchicago.edu> Message-ID: <50D717A2.6020904@uchicago.edu> Dear Ken and Carl, Thank you so much! I always get quality responses from this group! I referred to maximal ranges. So there's a single range in both 0,0,0,0 and 0,0,0,0,0,0. Ken's solution, with boundary cases treatment, will work for me. Happy Holidays, Oren On 12/21/2012 8:03 PM, Carl Karsten wrote: > for L = 3, how many ranges are in: > 0,0,0,0 ? > > I can find 3: > 1,2,3 > 1,2,3,4 > 2,3,4 > > But if you are not allowed to reuse, then just the 1234 one is all there is. > > but that still leaves 0,0,0,0,0,0 > 123 and 456 give you 2 ranges with no reuse. Is that better than one long one? > > On Fri, Dec 21, 2012 at 4:36 PM, Oren Livne wrote: >> Dear All, >> >> I have a binary numpy array A. I would like to find all ranges of >> consecutive 0's of length >= L in A. What would be an efficient >> implementation? >> >> Thanks, >> Oren >> _______________________________________________ >> Chicago mailing list >> Chicago at python.org >> http://mail.python.org/mailman/listinfo/chicago > > -- A person is just about as big as the things that make him angry. From randy7771026 at gmail.com Sat Dec 22 21:49:33 2012 From: randy7771026 at gmail.com (Randy Baxley) Date: Sat, 22 Dec 2012 14:49:33 -0600 Subject: [Chicago] Dr Chuck MOOC Message-ID: http://online.dr-chuck.com/index.php Dr. Chuck is a fun professor and I have already worked through his pythonlearn.com basics so this should be fun. Randy -------------- next part -------------- An HTML attachment was scrubbed... URL: From randy7771026 at gmail.com Wed Dec 26 00:43:32 2012 From: randy7771026 at gmail.com (Randy Baxley) Date: Tue, 25 Dec 2012 17:43:32 -0600 Subject: [Chicago] Segments in binary array In-Reply-To: <50D717A2.6020904@uchicago.edu> References: <50D4E467.4040709@uchicago.edu> <50D717A2.6020904@uchicago.edu> Message-ID: Someday I will get to understand numpy, scipy, maximal, single range and boundary cases. Today though I am just hoping we can figure out why my emails are not getting through to chipy. Here is my latest fun with the Rice course for folks to try and crash or to make comments on towards better programming practices. http://www.codeskulptor.org/#user8-ffQ0VDPc4LqtZuS-3.py On Sun, Dec 23, 2012 at 8:39 AM, Oren Livne wrote: > Dear Ken and Carl, > > Thank you so much! I always get quality responses from this group! > I referred to maximal ranges. So there's a single range in both 0,0,0,0 > and 0,0,0,0,0,0. > Ken's solution, with boundary cases treatment, will work for me. > > Happy Holidays, > Oren > > On 12/21/2012 8:03 PM, Carl Karsten wrote: > >> for L = 3, how many ranges are in: >> 0,0,0,0 ? >> >> I can find 3: >> 1,2,3 >> 1,2,3,4 >> 2,3,4 >> >> But if you are not allowed to reuse, then just the 1234 one is all there >> is. >> >> but that still leaves 0,0,0,0,0,0 >> 123 and 456 give you 2 ranges with no reuse. Is that better than one >> long one? >> >> On Fri, Dec 21, 2012 at 4:36 PM, Oren Livne wrote: >> >>> Dear All, >>> >>> I have a binary numpy array A. I would like to find all ranges of >>> consecutive 0's of length >= L in A. What would be an efficient >>> implementation? >>> >>> Thanks, >>> Oren >>> ______________________________**_________________ >>> Chicago mailing list >>> Chicago at python.org >>> http://mail.python.org/**mailman/listinfo/chicago >>> >> >> >> > > -- > A person is just about as big as the things that make him angry. > > ______________________________**_________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/**mailman/listinfo/chicago > -------------- next part -------------- An HTML attachment was scrubbed... URL: From livne at uchicago.edu Thu Dec 27 16:35:42 2012 From: livne at uchicago.edu (Oren Livne) Date: Thu, 27 Dec 2012 09:35:42 -0600 Subject: [Chicago] Multiple test suites in PyDev Message-ID: <50DC6ACE.2050602@uchicago.edu> Dear All, I work in eclipse. I have 10 projects, each of which has a main test suite that I can run with a PyDev PyUnit run config. How can I create a super-test PyDev suite/run config that runs all of them with one click? Thanks, Oren -- A person is just about as big as the things that make him angry. From tal.liron at threecrickets.com Thu Dec 27 22:51:59 2012 From: tal.liron at threecrickets.com (Tal Liron) Date: Thu, 27 Dec 2012 15:51:59 -0600 Subject: [Chicago] Multiple test suites in PyDev In-Reply-To: <50DC6ACE.2050602@uchicago.edu> References: <50DC6ACE.2050602@uchicago.edu> Message-ID: <50DCC2FF.4040203@threecrickets.com> An HTML attachment was scrubbed... URL: From livne at uchicago.edu Thu Dec 27 22:57:46 2012 From: livne at uchicago.edu (Oren Livne) Date: Thu, 27 Dec 2012 15:57:46 -0600 Subject: [Chicago] Multiple test suites in PyDev In-Reply-To: <50DCC2FF.4040203@threecrickets.com> References: <50DC6ACE.2050602@uchicago.edu> <50DCC2FF.4040203@threecrickets.com> Message-ID: <50DCC45A.8040601@uchicago.edu> Dear Tal, Thanks. I thought of creating the Test project, but don't know how to use the dynamicism to import everything. Is there a good tutorial on that? Oren On 12/27/2012 3:51 PM, Tal Liron wrote: > I would create a new project called "Test", which just has one test > that uses Python magickal dynamism to import tests from all the other > projects. > > When it works I would share this snippet online so that others may enjoy. > > On 12/27/2012 09:35 AM, Oren Livne wrote: >> Dear All, >> >> I work in eclipse. I have 10 projects, each of which has a main test >> suite that I can run with a PyDev PyUnit run config. How can I create >> a super-test PyDev suite/run config that runs all of them with one >> click? >> >> Thanks, >> Oren >> > > > > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago -- A person is just about as big as the things that make him angry. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tal.liron at threecrickets.com Thu Dec 27 23:07:28 2012 From: tal.liron at threecrickets.com (Tal Liron) Date: Thu, 27 Dec 2012 16:07:28 -0600 Subject: [Chicago] Multiple test suites in PyDev In-Reply-To: <50DCC45A.8040601@uchicago.edu> References: <50DC6ACE.2050602@uchicago.edu> <50DCC2FF.4040203@threecrickets.com> <50DCC45A.8040601@uchicago.edu> Message-ID: <50DCC6A0.5090506@threecrickets.com> An HTML attachment was scrubbed... URL: From tottinge at gmail.com Thu Dec 27 23:15:17 2012 From: tottinge at gmail.com (Tim Ottinger) Date: Thu, 27 Dec 2012 16:15:17 -0600 Subject: [Chicago] Multiple test suites in PyDev In-Reply-To: <50DCC6A0.5090506@threecrickets.com> References: <50DC6ACE.2050602@uchicago.edu> <50DCC2FF.4040203@threecrickets.com> <50DCC45A.8040601@uchicago.edu> <50DCC6A0.5090506@threecrickets.com> Message-ID: I always use sniffer/nose in a separate window, even when working in pydev, so I'm not sure what the trick is. Sniffer is wonderful. It runs all the tests any time a file changes, so you always know (without asking) if your tests are green or red. Sadly, it doesn't integrate with eclipse windows (that I know of). On Thu, Dec 27, 2012 at 4:07 PM, Tal Liron wrote: > I would first crawl all directories in your Eclipse projects root looking > for tests. You can use the os.walk API. Note that if you have non-PyDev > Eclipse projects, you can quickly dismiss them from your crawl: PyDev > projects have a ".pydevproject" file in their root directory. > > Once you've found all files with the tests, you can import them by first > programatically using __import__. > > > On 12/27/2012 03:57 PM, Oren Livne wrote: > > Dear Tal, > > Thanks. I thought of creating the Test project, but don't know how to use > the dynamicism to import everything. Is there a good tutorial on that? > > Oren > > On 12/27/2012 3:51 PM, Tal Liron wrote: > > I would create a new project called "Test", which just has one test that > uses Python magickal dynamism to import tests from all the other projects. > > When it works I would share this snippet online so that others may enjoy. > > On 12/27/2012 09:35 AM, Oren Livne wrote: > > Dear All, > > I work in eclipse. I have 10 projects, each of which has a main test suite > that I can run with a PyDev PyUnit run config. How can I create a > super-test PyDev suite/run config that runs all of them with one click? > > Thanks, > Oren > > > > > _______________________________________________ > Chicago mailing listChicago at python.orghttp://mail.python.org/mailman/listinfo/chicago > > > > -- > A person is just about as big as the things that make him angry. > > > > _______________________________________________ > Chicago mailing listChicago at python.orghttp://mail.python.org/mailman/listinfo/chicago > > > > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago > > -- Tim Ottinger, Sr. Consultant, Industrial Logic ------------------------------------- http://www.industriallogic.com/ http://agileinaflash.com/ http://agileotter.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From scott.ferguson at vokalinteractive.com Fri Dec 28 18:21:21 2012 From: scott.ferguson at vokalinteractive.com (Scott Ferguson) Date: Fri, 28 Dec 2012 11:21:21 -0600 Subject: [Chicago] Python/Django position at VOKAL Interactive Message-ID: Hey guys, I wanted to ping this list to see if anybody in the Chicago area is interested in joining the VOKAL Interactive team. We're primarily a mobile shop but with an increasing amount of web work (both mobile and desktop) coming in. We bill ourselves as a Django shop but we use Python pretty liberally, so any experience with the language is desired. Typical work ranges from building API's for mobile apps to building full-fledged web applications. We're located in River North, right off of the Chicago brown line station. The culture is close-knit. We'll often end days with beer, Bomberman or Minecraft (there's ping pong too). Basically a bunch of folks that love building software. If you're interested, or know anybody who might be interested, please feel free to get in touch with me at scott.ferguson at vokalinteractive.com. Scott Ferguson Director of Engineering VOKAL INTERACTIVE m: +1.312.324.0829 e: scott.ferguson at vokalinteractive.com sn: http://gplus.to/scottferguson -------------- next part -------------- An HTML attachment was scrubbed... URL: From randy7771026 at gmail.com Sat Dec 29 17:46:01 2012 From: randy7771026 at gmail.com (Randy Baxley) Date: Sat, 29 Dec 2012 10:46:01 -0600 Subject: [Chicago] Stopwatch game Message-ID: http://www.codeskulptor.org/#user8-cZGUx5xm9N-4.py Submitted for those who might be board and either play it or tell me how to improve my programming practices. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jp at zavteq.com Sun Dec 30 01:22:24 2012 From: jp at zavteq.com (JP Bader) Date: Sat, 29 Dec 2012 18:22:24 -0600 Subject: [Chicago] Stopwatch game In-Reply-To: References: Message-ID: Where are the directions? I go to the site and hit play, but don't know why... On Dec 29, 2012 10:51 AM, "Randy Baxley" wrote: > http://www.codeskulptor.org/#user8-cZGUx5xm9N-4.py > > Submitted for those who might be board and either play it or tell me how > to improve my programming practices. > > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From diomedestydeus at gmail.com Sun Dec 30 01:34:45 2012 From: diomedestydeus at gmail.com (Philip Doctor) Date: Sat, 29 Dec 2012 18:34:45 -0600 Subject: [Chicago] Stopwatch game In-Reply-To: References: Message-ID: Judging based on the code it's something about click stop on a multiple of 5 seconds exactly On Sat, Dec 29, 2012 at 6:22 PM, JP Bader wrote: > Where are the directions? I go to the site and hit play, but don't know > why... > On Dec 29, 2012 10:51 AM, "Randy Baxley" wrote: > >> http://www.codeskulptor.org/#user8-cZGUx5xm9N-4.py >> >> Submitted for those who might be board and either play it or tell me how >> to improve my programming practices. >> >> _______________________________________________ >> Chicago mailing list >> Chicago at python.org >> http://mail.python.org/mailman/listinfo/chicago >> >> > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From randy7771026 at gmail.com Sun Dec 30 12:37:49 2012 From: randy7771026 at gmail.com (Randy Baxley) Date: Sun, 30 Dec 2012 05:37:49 -0600 Subject: [Chicago] Stopwatch game In-Reply-To: References: Message-ID: You score by stopping on five second intervals. On Sat, Dec 29, 2012 at 6:22 PM, JP Bader wrote: > Where are the directions? I go to the site and hit play, but don't know > why... > On Dec 29, 2012 10:51 AM, "Randy Baxley" wrote: > >> http://www.codeskulptor.org/#user8-cZGUx5xm9N-4.py >> >> Submitted for those who might be board and either play it or tell me how >> to improve my programming practices. >> >> _______________________________________________ >> Chicago mailing list >> Chicago at python.org >> http://mail.python.org/mailman/listinfo/chicago >> >> > _______________________________________________ > Chicago mailing list > Chicago at python.org > http://mail.python.org/mailman/listinfo/chicago > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From randy7771026 at gmail.com Mon Dec 31 13:55:23 2012 From: randy7771026 at gmail.com (Randy Baxley) Date: Mon, 31 Dec 2012 06:55:23 -0600 Subject: [Chicago] Stopwatch game In-Reply-To: References: Message-ID: OK, thank you for the gentle reminder to comment a bit more. Here is a commented to the nth version. Thank you again. http://www.codeskulptor.org/#user8-EeiJ18rm3k-0.py On Sat, Dec 29, 2012 at 6:22 PM, JP Bader wrote: > Where are the directions? I go to the site and hit play, but don't know > why... > -------------- next part -------------- An HTML attachment was scrubbed... URL: