From dwightdhutto at gmail.com Tue Apr 1 00:11:57 2014 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 1 Apr 2014 00:11:57 -0400 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> Message-ID: This brings us into a juxtaposition between how cultures have tried to hybridize their mentalities, into more of an empathic means of communication via a formulatic set of coding, and the philosophy thereof, and, 3D renderings of what we visualize, and how we come to the conclusions of these philosophies of what we want to accomplish within the technological age we live within. Maybe not the best way I could explain it, but it has a bunch of fancy words in it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Tue Apr 1 00:24:15 2014 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 1 Apr 2014 00:24:15 -0400 Subject: Examples of modern GUI python programms In-Reply-To: <7731beae-7309-4fbc-b706-d4dd4983f535@googlegroups.com> References: <7731beae-7309-4fbc-b706-d4dd4983f535@googlegroups.com> Message-ID: Caveat emptor(I have a copy of Latin For Idiots). When you get through with refining, in whatever language, the open source/proprietary app you're developing, is there anyway you can say for sure how many people's work went into things under different licenses accompanying what you may have copy and pasted into it, and neither can the individuals who developed the systems they "designed", and threw a license on it? *Standing on the shoulder's of giants can still be unsteady ground.* -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at pearwood.info Tue Apr 1 00:26:01 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 01 Apr 2014 04:26:01 GMT Subject: Code style query: multiple assignments in if/elif tree References: Message-ID: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> On Tue, 01 Apr 2014 01:33:09 +1100, Chris Angelico wrote: > Call this a code review request, if you like. I'm wondering how you'd go > about coding something like this. I wouldn't. I'd start off by analysing the problem, and putting it into the simplest format possible, and *then* start writing code if and only if needed. See below. The first mistake of computational mathematics is to do the computation before the mathematics, and the Holy Grail is to avoid the computation altogether. > Imagine you're in a train, and the brakes don't apply instantly. The > definition, in the interests of passenger comfort, Ah, you're using comfort in the modern sense, i.e. what people used to call discomfort :-P The scenario you describe has (effectively) infinite rate-of-change-of- acceleration, often called "jerk". (A jerk is a rapid change in acceleration.) Human comfort is (within reasonable limits) more affected by jerk than acceleration. The passengers will feel three quite distinctive jerks, one when the brakes are first applied (which is probably reasonable), then one at 1s, then again at 2s. That's not comfortable by any stretch of the imagination. > is that the first > second of brake application has an acceleration of 0.2 m/s/s, the next > second has 0.425 m/s/s, and thereafter full effect of 0.85 m/s/s. In mathematics, this is called hybrid function, and is usually written like this: g(t) for t < 0 f(t) = { 42 for t == 0 h(t) for t > 0 or something similar. (The opening brace { ought to be large enough to cover all three lines, and there is no closing brace.) In your case, you have three constant functions. > You > have a state variable that says whether the brakes have just been > applied, have already been applied for at least two seconds, or haven't > yet been applied at all. I wouldn't model it that way. Especially since you've missed at least one state :-) I'd model the acceleration as a function of time, otherwise you have to convert a time into a state. Nevertheless, if you insist, we can use a state variable instead: 0 for state == "BRAKES NOT APPLIED YET" accel = { 0.2 for state == "BRAKES ON FOR BETWEEN 0 AND 1 SECOND" 0.425 for STATE == BRAKES ON FOR BETWEEN 1 AND 2 SECOND" 0.85 for state == "BRAKES ON FOR MORE THAN 2 SECONDS" Implied, but not stated, is that once the train stops, acceleration also goes to zero -- the train does not start moving backwards. Haskell has nifty pattern-matching syntax for this that looks quite close to the mathematical hybrid function syntax, but in Python, we're limited to explicitly using an if. If I were coding this, and I'm not, I'd wrap it in a function. One advantage of a state variable rather than a continuous time function is that we can do this: def accel(state): return {NO_BRAKING: 0.0, LOW_BRAKING: 0.2, MID_BRAKING: 0.425, HIGH_BRAKING: 0.85}[state] which is simple enough to skip using a function in the first place, and just use the dict lookup directly. But for a more general question you'll want acceleration as a function of time. If you prefer if...elif over a dict, I'd still hide it in a function. > Problem: Work out how far you'll go before the > brakes reach full power, and how fast you'll be going at that point. Given that problem, we actually only care about LOW_BRAKING and MID_BRAKING. The problem becomes quite simple: At t=0, the train is travelling at u m/s and the brakes are applied with acceleration of 0.2m/s^2 for one second, then 0.425m/s^2 for an additional one second. What is the speed of the train after those two seconds, and the distance travelled. This becomes a simple question for the four standard equations of motion: (1) v = u + at (2) s = 1/2(u + v)t (3) s = ut + 1/2(at^2) (4) v^2 = u^2 + 2as Only (1) and (3) are needed. The distance travelled in the first second is: s1 = u - 0.1 m and the speed of the train at that time becomes: v = u - 0.2 m/s Applying this for the second second gives: s2 = (u - 0.2) - 0.2125 m v = (u - 0.2) - 0.425 m/s and the total distance: s = s1 + s2 No programming required, just a calculator :-) Given that solving the entire problem is barely five lines, writing code to do so is probably unnecessary. The only thing I haven't done is check that the train isn't travelling so slowly that it comes to a complete halt within two seconds. I leave that as an exercise. (Hint: if the final speed is negative, the train came to a halt.) > Here's how I currently have the code. The variable names are a tad long, > as this was also part of me teaching my brother Python. Whatever you used to post this, ate the indentation. > # Already got the brakes fully on > if mode=="Brake2": distance_to_full_braking_power, speed_full_brake = > 0.0, curspeed > # The brakes went on one second ago, they're nearly full elif > mode=="Brake1": distance_to_full_braking_power, speed_full_brake = > curspeed - 0.2125, curspeed - 0.425 # Brakes aren't on. > else: distance_to_full_braking_power, speed_full_brake = (curspeed - > 0.1) + (curspeed - 0.4125), curspeed - 0.625 # If we hit the brakes now > (or already have hit them), we'll go another d meters and be going at s > m/s before reaching full braking power. Using sequence unpacking just to save a newline is naughty :-) dist, speed = (curspeed - 0.1) + (curspeed - 0.4125), curspeed - 0.625 is an abuse of syntax, not far removed from: dist = (curspeed - 0.1) + (curspeed - 0.4125); speed = curspeed - 0.625 It will be much more comprehensible written as two statements. > But I don't like the layout. I could change it to a single assignment > with expression-if, but that feels awkward too. How would you lay this > out? > > (Note that the "else" case could have any of several modes in it, so I > can't so easily use a dict.) It could have, but doesn't. Is your aim to build a general purpose Newtonian linear motion solver, or to solve this one problem? -- Steven From rosuav at gmail.com Tue Apr 1 01:01:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Apr 2014 16:01:40 +1100 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Apr 1, 2014 at 3:26 PM, Steven D'Aprano wrote: > On Tue, 01 Apr 2014 01:33:09 +1100, Chris Angelico wrote: > >> Call this a code review request, if you like. I'm wondering how you'd go >> about coding something like this. > > I wouldn't. I'd start off by analysing the problem, and putting it into > the simplest format possible, and *then* start writing code if and only > if needed. See below. > > The first mistake of computational mathematics is to do the computation > before the mathematics, and the Holy Grail is to avoid the computation > altogether. Fair enough. :) >> Imagine you're in a train, and the brakes don't apply instantly. The >> definition, in the interests of passenger comfort, > > Ah, you're using comfort in the modern sense, i.e. what people used to > call discomfort :-P > > The scenario you describe has (effectively) infinite rate-of-change-of- > acceleration, often called "jerk". (A jerk is a rapid change in > acceleration.) Human comfort is (within reasonable limits) more affected > by jerk than acceleration. The passengers will feel three quite > distinctive jerks, one when the brakes are first applied (which is > probably reasonable), then one at 1s, then again at 2s. That's not > comfortable by any stretch of the imagination. It actually is a smooth increase in deceleration, but I'm operating the simulator on a 1s period, so it's actually an average across the first second, and an average across the next second... >> is that the first >> second of brake application has an acceleration of 0.2 m/s/s, the next >> second has 0.425 m/s/s, and thereafter full effect of 0.85 m/s/s. ... so really, it's seeking upward from 0 to 0.85 according to some curve, the details of which I'm not familiar with, but in terms of 1s average accelerations, it's those figures. Actually even 1s resolution is more than we need; the overall purpose is to get a calculated time in minutes, so calculating to sub-second resolution (when, in reality, this is trying to predict what a human will do) is massive overkill. >> You >> have a state variable that says whether the brakes have just been >> applied, have already been applied for at least two seconds, or haven't >> yet been applied at all. > > I wouldn't model it that way. Especially since you've missed at least one > state :-) I'd model the acceleration as a function of time, otherwise you > have to convert a time into a state. Nevertheless, if you insist, we can > use a state variable instead: > > 0 for state == "BRAKES NOT APPLIED YET" > accel = { 0.2 for state == "BRAKES ON FOR BETWEEN 0 AND 1 SECOND" > 0.425 for STATE == BRAKES ON FOR BETWEEN 1 AND 2 SECOND" > 0.85 for state == "BRAKES ON FOR MORE THAN 2 SECONDS" > > Implied, but not stated, is that once the train stops, acceleration also > goes to zero -- the train does not start moving backwards. "Just been applied" is poorly named; that's the state where the brakes have been applied for 1 second so far. The other state (brakes not applied yet) could be looking at powering (which follows a similar curve in the opposite direction) or cruising (which has acceleration of 0.0 m/s/s). > Haskell has nifty pattern-matching syntax for this that looks quite close > to the mathematical hybrid function syntax, but in Python, we're limited > to explicitly using an if. If I were coding this, and I'm not, I'd wrap > it in a function. One advantage of a state variable rather than a > continuous time function is that we can do this: > > def accel(state): > return {NO_BRAKING: 0.0, > LOW_BRAKING: 0.2, > MID_BRAKING: 0.425, > HIGH_BRAKING: 0.85}[state] That could be done, but with .get() to allow a default. I may well do that. >> Problem: Work out how far you'll go before the >> brakes reach full power, and how fast you'll be going at that point. > > Given that problem, we actually only care about LOW_BRAKING and > MID_BRAKING. The problem becomes quite simple: Right. The other state is "zero distance and zero loss of speed". > At t=0, the train is travelling at u m/s and the brakes are applied with > acceleration of 0.2m/s^2 for one second, then 0.425m/s^2 for an > additional one second. What is the speed of the train after those two > seconds, and the distance travelled. > > This becomes a simple question for the four standard equations of motion: > > (1) v = u + at > (2) s = 1/2(u + v)t > (3) s = ut + 1/2(at^2) > (4) v^2 = u^2 + 2as > > Only (1) and (3) are needed. Okay, what's u here? Heh. > The distance travelled in the first second is: > > s1 = u - 0.1 m > > and the speed of the train at that time becomes: > > v = u - 0.2 m/s > > Applying this for the second second gives: > > s2 = (u - 0.2) - 0.2125 m > > v = (u - 0.2) - 0.425 m/s > > and the total distance: > > s = s1 + s2 > > > No programming required, just a calculator :-) > > Given that solving the entire problem is barely five lines, writing code > to do so is probably unnecessary. This is one small part of a larger piece of code (which, in this instance, is trying to answer this question: "If I apply the brakes now and keep them on until the next curve, will I be way below the curve's speed limit?" - if yes, don't apply the brakes now). > The only thing I haven't done is check that the train isn't travelling so > slowly that it comes to a complete halt within two seconds. I leave that > as an exercise. (Hint: if the final speed is negative, the train came to > a halt.) Yeah. Or just let that go into the next part of the calculation, which works out quadratically how much distance -> how much time -> how much remaining speed, which may have no solution ie it doesn't reach that point. That part's fine. > Whatever you used to post this, ate the indentation. I posted that part without indentation, yeah. Gmail eats tabs. Normally I manually replace them with spaces for posting, but since this whole section was at the same indentation level, I didn't bother. It is one of the problems with Gmail, though, and if I weren't running this account on multiple systems of different OSes, I'd probably use a dedicated client. >> # Already got the brakes fully on >> if mode=="Brake2": distance_to_full_braking_power, speed_full_brake = >> 0.0, curspeed >> # The brakes went on one second ago, they're nearly full elif >> mode=="Brake1": distance_to_full_braking_power, speed_full_brake = >> curspeed - 0.2125, curspeed - 0.425 # Brakes aren't on. >> else: distance_to_full_braking_power, speed_full_brake = (curspeed - >> 0.1) + (curspeed - 0.4125), curspeed - 0.625 # If we hit the brakes now >> (or already have hit them), we'll go another d meters and be going at s >> m/s before reaching full braking power. > > Using sequence unpacking just to save a newline is naughty :-) > > dist, speed = (curspeed - 0.1) + (curspeed - 0.4125), curspeed - 0.625 > > is an abuse of syntax, not far removed from: > > dist = (curspeed - 0.1) + (curspeed - 0.4125); speed = curspeed - 0.625 > > It will be much more comprehensible written as two statements. Fair enough. :) That's why I asked. Is it naughty enough to break into two statements, or is it better to combine it into a single multiple assignment? >> But I don't like the layout. I could change it to a single assignment >> with expression-if, but that feels awkward too. How would you lay this >> out? >> >> (Note that the "else" case could have any of several modes in it, so I >> can't so easily use a dict.) > > It could have, but doesn't. Is your aim to build a general purpose > Newtonian linear motion solver, or to solve this one problem? To solve this one problem, as part of a simulator. For any purpose beyond what you can see in the code itself, you'd have to ask my brother; I don't have the full details on that. Thanks for the advice! Flamage welcome, I'm wearing the asbestos that's just been removed from the theatre here... ChrisA From miki.tebeka at gmail.com Tue Apr 1 01:06:17 2014 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 31 Mar 2014 22:06:17 -0700 (PDT) Subject: Python IM server In-Reply-To: References: Message-ID: <50efd79f-d085-4813-97fa-86e4e48e13f7@googlegroups.com> > I want to develop a instant message server, simply has user and group entity. > Is there any better existing open-source one? > Thus I can download and have a look. You can take a look at Twisted Words (https://twistedmatrix.com/trac/wiki/TwistedWords). From cmpython at gmail.com Tue Apr 1 01:14:01 2014 From: cmpython at gmail.com (CM) Date: Mon, 31 Mar 2014 22:14:01 -0700 (PDT) Subject: Examples of modern GUI python programms In-Reply-To: References: Message-ID: <9563e381-f5a6-4c13-a941-e56290ca6549@googlegroups.com> On Sunday, March 30, 2014 7:16:07 PM UTC-4, D. Xenakis wrote: > Id like to ask.. do you know any modern looking GUI examples of windows software written in python? Something like this maybe: http://techreport.com/r.x/asus-x79deluxe/software-oc.jpg (or hopefully something like this android look: http://chromloop.com/wp-content/uploads/2013/07/Skype-4.0-Android-screenshot.jpg). > > What i need is to develop an android looking program (entirelly in python) for windows, but dunno if this is possible (most propably is), and which tool between those would help me most: tkinter - wxpython - pyqt - pygtk . > I just know wxPython, so I'll discuss that. I'm pretty sure you could achieve either of those with wxPython, but it isn't really set up to look like that ("modern looking" in your words) by default. wxPython is set up to look *native* for each platform it runs on. On WinXP, for example, toolbars and buttons generally have "system gray" backgrounds, but some widgets can be changed, some can't. There are custom widgets that are more flexible though are not native. You could cleverly simulate these sorts of looks with creative use of library-included custom widgets, a few of your own custom widgets possibly, black backgrounds, drawing on a DC directly to the screen, image backgrounds, and a few other things (basically creating your own "skin"). The harder one is probably the first one you linked--the other, Skype on Android, is mostly just big fluffy images. Probably the first 90% of that is pretty easy and the last 10% might be somewhat difficult, but not too bad. It would be fun to try. From dwightdhutto at gmail.com Tue Apr 1 01:38:52 2014 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 1 Apr 2014 01:38:52 -0400 Subject: Python IM server In-Reply-To: <50efd79f-d085-4813-97fa-86e4e48e13f7@googlegroups.com> References: <50efd79f-d085-4813-97fa-86e4e48e13f7@googlegroups.com> Message-ID: hint: Tkinter server db update the tkinter apps, with the new data, after moving a line down On Tue, Apr 1, 2014 at 1:06 AM, Miki Tebeka wrote: > > I want to develop a instant message server, simply has user and group > entity. > > Is there any better existing open-source one? > > Thus I can download and have a look. > You can take a look at Twisted Words ( > https://twistedmatrix.com/trac/wiki/TwistedWords). > -- > https://mail.python.org/mailman/listinfo/python-list > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com * -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Tue Apr 1 01:45:32 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 31 Mar 2014 22:45:32 -0700 (PDT) Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: <0f01ed1d-bc24-4286-8d1c-bfee7baedbc2@googlegroups.com> On Tue, Apr 1, 2014 at 3:26 PM, Steven D'Aprano wrote: > Haskell has nifty pattern-matching syntax for this that looks quite close > to the mathematical hybrid function syntax, but in Python, we're limited > to explicitly using an if. If I were coding this, and I'm not, I'd wrap > it in a function. One advantage of a state variable rather than a > continuous time function is that we can do this: > def accel(state): > return {NO_BRAKING: 0.0, > LOW_BRAKING: 0.2, > MID_BRAKING: 0.425, > HIGH_BRAKING: 0.85}[state] Neat I would put the dict in a variable. And those _BRAKINGs are GALLing me! breaking = {NO:0.0, LOW:0.2, MID:0.425:, HIGH:0.85} def accel(state): return breaking[state] In using Haskell, I often wish for dicts especially python's nifty dict-literals From dwightdhutto at gmail.com Tue Apr 1 02:05:17 2014 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 1 Apr 2014 02:05:17 -0400 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: <0f01ed1d-bc24-4286-8d1c-bfee7baedbc2@googlegroups.com> References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> <0f01ed1d-bc24-4286-8d1c-bfee7baedbc2@googlegroups.com> Message-ID: On Tue, Apr 1, 2014 at 1:45 AM, Rustom Mody wrote: > On Tue, Apr 1, 2014 at 3:26 PM, Steven D'Aprano wrote: > > > Haskell has nifty pattern-matching syntax for this that looks quite close > > to the mathematical hybrid function syntax, but in Python, we're limited > > to explicitly using an if. If I were coding this, and I'm not, I'd wrap > > it in a function. One advantage of a state variable rather than a > > continuous time function is that we can do this: > > def accel(state): > > return {NO_BRAKING: 0.0, > > LOW_BRAKING: 0.2, > > MID_BRAKING: 0.425, > > HIGH_BRAKING: 0.85}[state] > > Neat > I would put the dict in a variable. And those _BRAKINGs are GALLing me! > > breaking = {NO:0.0, LOW:0.2, MID:0.425:, HIGH:0.85} > def accel(state): return breaking[state] > > > In using Haskell, I often wish for dicts especially python's nifty > dict-literals > > > This still omits the viscosity(+-) of the enclosed, or exposed track/environmental variables of the system in which the objects traveling. http://www.synlube.com/viscosit.htm > -- > > https://mail.python.org/mailman/listinfo/python-list > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com * -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Apr 1 02:13:00 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 1 Apr 2014 00:13:00 -0600 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On Mon, Mar 31, 2014 at 11:01 PM, Chris Angelico wrote: > On Tue, Apr 1, 2014 at 3:26 PM, Steven D'Aprano wrote: >> The scenario you describe has (effectively) infinite rate-of-change-of- >> acceleration, often called "jerk". (A jerk is a rapid change in >> acceleration.) Human comfort is (within reasonable limits) more affected >> by jerk than acceleration. The passengers will feel three quite >> distinctive jerks, one when the brakes are first applied (which is >> probably reasonable), then one at 1s, then again at 2s. That's not >> comfortable by any stretch of the imagination. > > It actually is a smooth increase in deceleration, but I'm operating > the simulator on a 1s period, so it's actually an average across the > first second, and an average across the next second... Then your computation is incorrect and will systematically underestimate the stopping distance. Assuming for simplicity that the acceleration actually increases linearly until it reaches maximum, picture the velocity graph between, say, t=0 and t=1s. You are modeling it as a straight line segment. However, it would actually be part of a quadratic curve connecting the same points, convex upwards. The line segment is short-cutting the curve between the two points. The distance traveled is the integral of the curve, and it is easy to see that the integral of the line segment is less than the integral of the actual curve. >> (1) v = u + at >> (2) s = 1/2(u + v)t >> (3) s = ut + 1/2(at^2) >> (4) v^2 = u^2 + 2as >> >> Only (1) and (3) are needed. > > Okay, what's u here? Heh. u is the initial velocity; v is the velocity after accelerating at a for time t. From dwightdhutto at gmail.com Tue Apr 1 02:24:46 2014 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 1 Apr 2014 02:24:46 -0400 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: > > > >> (1) v = u + at > >> (2) s = 1/2(u + v)t > >> (3) s = ut + 1/2(at^2) > >> (4) v^2 = u^2 + 2as > >> > >> Only (1) and (3) are needed. > > > > Okay, what's u here? Heh. > > u is the initial velocity; v is the velocity after accelerating at a for > time t. > This assumes that the viscosity is in a state of superfluidity, and in a perfect state between itself, and it's traveling environment. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Best Regards, David Hutto -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Apr 1 02:28:53 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 1 Apr 2014 00:28:53 -0600 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: <0f01ed1d-bc24-4286-8d1c-bfee7baedbc2@googlegroups.com> References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> <0f01ed1d-bc24-4286-8d1c-bfee7baedbc2@googlegroups.com> Message-ID: On Mon, Mar 31, 2014 at 11:45 PM, Rustom Mody wrote: > On Tue, Apr 1, 2014 at 3:26 PM, Steven D'Aprano wrote: > >> Haskell has nifty pattern-matching syntax for this that looks quite close >> to the mathematical hybrid function syntax, but in Python, we're limited >> to explicitly using an if. If I were coding this, and I'm not, I'd wrap >> it in a function. One advantage of a state variable rather than a >> continuous time function is that we can do this: >> def accel(state): >> return {NO_BRAKING: 0.0, >> LOW_BRAKING: 0.2, >> MID_BRAKING: 0.425, >> HIGH_BRAKING: 0.85}[state] > > Neat > I would put the dict in a variable. And those _BRAKINGs are GALLing me! > > breaking = {NO:0.0, LOW:0.2, MID:0.425:, HIGH:0.85} > def accel(state): return breaking[state] If I were doing this in Python 3.4 I would be sorely tempted to use an Enum for the state. Then the acceleration could just be an attribute (or method) of the state itself! class BrakingState(Enum): no_braking = 0.0 low_braking = 0.2 mid_braking = 0.425 high_braking = 0.85 @property def acceleration(self): return self.value >>> print(BrakingState.low_braking.acceleration) 0.2 Alternatively the __init__ method could set the acceleration directly from the value(s) passed in, as in the Planet example: https://docs.python.org/3/library/enum.html#planet The problem I have with either of these approaches though is that if two distinct states happen to have the same acceleration, they will be considered aliases for the same state. This is because the acceleration value is doing double duty as a parameter of the state and also as its identity. Likewise in the Planet example, if a new planet happened to have the same mass and radius as Jupiter, it would be considered the same planet as Jupiter. I haven't managed to work out a wholly satisfying way to avoid this. From ian.g.kelly at gmail.com Tue Apr 1 02:39:47 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 1 Apr 2014 00:39:47 -0600 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Apr 1, 2014 at 12:24 AM, David Hutto wrote: >> >> >> (1) v = u + at >> >> (2) s = 1/2(u + v)t >> >> (3) s = ut + 1/2(at^2) >> >> (4) v^2 = u^2 + 2as >> >> >> >> Only (1) and (3) are needed. >> > >> > Okay, what's u here? Heh. >> >> u is the initial velocity; v is the velocity after accelerating at a for >> time t. > > > This assumes that the viscosity is in a state of superfluidity, and in a > perfect state between itself, and it's traveling environment. I fail to see how this is relevant. I would assume that the amount of friction is already modeled in the acceleration constants; if it were zero then the brakes would be nonfunctional and the train would not be able to accelerate or decelerate at all. In any case, a change in friction simply works out to a change in acceleration. The equations above still hold true. From rosuav at gmail.com Tue Apr 1 02:55:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Apr 2014 17:55:32 +1100 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Apr 1, 2014 at 5:13 PM, Ian Kelly wrote: > Then your computation is incorrect and will systematically > underestimate the stopping distance. Assuming for simplicity that the > acceleration actually increases linearly until it reaches maximum, > picture the velocity graph between, say, t=0 and t=1s. You are > modeling it as a straight line segment. However, it would actually be > part of a quadratic curve connecting the same points, convex upwards. > The line segment is short-cutting the curve between the two points. > The distance traveled is the integral of the curve, and it is easy to > see that the integral of the line segment is less than the integral of > the actual curve. .... great. Okay. I never studied calculus, so this is beyond my expertise. Is this going to make a majorly significant difference to the end result? If so, I guess the code's going to have to be a whole lot more sophisticated, which means I need to learn a whole lot more maths in order to write it. And I'm still trying to find time to get familiar with systemd (having jumped on the Upstart bandwagon and now find myself backing a losing horse, if you'll forgive a mixed metaphor) and Cython (just need an excuse for that one). ChrisA From dwightdhutto at gmail.com Tue Apr 1 03:21:10 2014 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 1 Apr 2014 03:21:10 -0400 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: u is the initial velocity from a starting/resting point, not a static speed at that point, and begins to accelerate, over a particular timeframe, in which it's momentum is not stopped by friction on which the rails/environment it travels upon has, or the similar properties the object might have during acceleration in relation to the environment it travels within. So the object has a starting point at which there is no equal, or opposing force, as it begins to accelerate from a resting position(Newton: an object will remain in motion, until acted upon by an equal or opposite force, and in this case the motion is propulsion of the object, or the newtons of propulsion, until it is moving at the exact speed of the propulsion applied to the object->Vo-V1, with 0 friction/viscosity during this timeframe). The difference in our opinions, seems to be that there is an initial resting state, and not at an already accelerated motion that has reached it's maximum capacity. So there is a dynamic in my mind's eye, where the object is at a "resting" point initially, and either the environment, or the object can maneuver their own viscosity in relation to the other. On Tue, Apr 1, 2014 at 2:39 AM, Ian Kelly wrote: > On Tue, Apr 1, 2014 at 12:24 AM, David Hutto > wrote: > >> > >> >> (1) v = u + at > >> >> (2) s = 1/2(u + v)t > >> >> (3) s = ut + 1/2(at^2) > >> >> (4) v^2 = u^2 + 2as > >> >> > >> >> Only (1) and (3) are needed. > >> > > >> > Okay, what's u here? Heh. > >> > >> u is the initial velocity; v is the velocity after accelerating at a for > >> time t. > > > > > > This assumes that the viscosity is in a state of superfluidity, and in a > > perfect state between itself, and it's traveling environment. > > I fail to see how this is relevant. I would assume that the amount of > friction is already modeled in the acceleration constants; if it were > zero then the brakes would be nonfunctional and the train would not be > able to accelerate or decelerate at all. In any case, a change in > friction simply works out to a change in acceleration. The equations > above still hold true. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com * -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at pearwood.info Tue Apr 1 03:20:37 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 01 Apr 2014 07:20:37 GMT Subject: Code style query: multiple assignments in if/elif tree References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: <533a68c3$0$2909$c3e8da3$76491128@news.astraweb.com> On Tue, 01 Apr 2014 16:01:40 +1100, Chris Angelico wrote: [...] >> The scenario you describe has (effectively) infinite rate-of-change-of- >> acceleration, often called "jerk". (A jerk is a rapid change in >> acceleration.) Human comfort is (within reasonable limits) more >> affected by jerk than acceleration. The passengers will feel three >> quite distinctive jerks, one when the brakes are first applied (which >> is probably reasonable), then one at 1s, then again at 2s. That's not >> comfortable by any stretch of the imagination. > > It actually is a smooth increase in deceleration, but I'm operating the > simulator on a 1s period, so it's actually an average across the first > second, and an average across the next second... Hmmm. A 1-second resolution doesn't really sound too great to me. Suppose the deceleration increases linearly from 0 to 0.85 m/s over two seconds. Averaging it in the way you suggested, we get a total distance of: 2*u - 0.5125 (see my previous post for details) where u is measured in metres per second. Multiply by seconds to get the units right. For a Japanese bullet train where u = 320 km/hr that corresponds to py> 2*88.888889 - 0.5125 177.26527800000002 metres. Now let's do it properly! Given our assumption that the deceleration is linear, the jerk will be constant: j = ?a/?t = (0.85 - 0)/2 = 0.425 m/s^3 Let's start integrating! py> from sympy import integrate py> from sympy.abc import t py> j = '0.425' py> a = integrate(j, t) py> v = 88.888889 - integrate(a, t) py> s = integrate(v, (t, 0, 2)) py> s 177.211111333333 compared to 177.26527800000002 calculated the rough way. That's not bad, only about 5cm off! Effectively, your rough calculation was accurate to one decimal place. Of course, if the equation for acceleration was more complex, the approximation may not be anywhere near as good. [...] >> This becomes a simple question for the four standard equations of >> motion: >> >> (1) v = u + at >> (2) s = 1/2(u + v)t >> (3) s = ut + 1/2(at^2) >> (4) v^2 = u^2 + 2as >> >> Only (1) and (3) are needed. > > Okay, what's u here? Heh. They're *standard* equations of motion. Weren't you paying attention through the, oh, three years of high school where they teach this? :-P s = displacement (distance) t = time u = initial velocity v = final velocity a = acceleration [...] > Fair enough. :) That's why I asked. Is it naughty enough to break into > two statements, or is it better to combine it into a single multiple > assignment? Since they are unrelated assignments, of two different variables, they should be written as two separate assignments, not one using sequence unpacking. -- Steven From rosuav at gmail.com Tue Apr 1 03:26:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Apr 2014 18:26:30 +1100 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Apr 1, 2014 at 6:21 PM, David Hutto wrote: > The difference in our opinions, seems to be that there is an initial resting > state, and not at an already accelerated motion that has reached it's > maximum capacity. > > > So there is a dynamic in my mind's eye, where the object is at a "resting" > point initially, and either the environment, or the object can maneuver > their own viscosity in relation to the other. The initial state, in this problem, is of a vehicle moving at a known speed (an input to the formula; it's a variable, but one that we know at that point). Friction, viscosity, etc, etc, etc are all handled elsewhere; these trains are generally way overpowered, and the onboard computer caps the power and non-emergency braking such that the change in speed never exceeds 0.85 m/s/s. I don't know how exactly it goes about that, but for the purposes of this test, we can assume that it's able to achieve that acceleration. ChrisA From steve at pearwood.info Tue Apr 1 03:29:53 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 01 Apr 2014 07:29:53 GMT Subject: Code style query: multiple assignments in if/elif tree References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: <533a6af1$0$2909$c3e8da3$76491128@news.astraweb.com> On Tue, 01 Apr 2014 17:55:32 +1100, Chris Angelico wrote: > On Tue, Apr 1, 2014 at 5:13 PM, Ian Kelly wrote: >> Then your computation is incorrect and will systematically >> underestimate the stopping distance. Assuming for simplicity that the >> acceleration actually increases linearly until it reaches maximum, We're talking deceleration, so it actually decreases linearly until it reaches minimum :-) >> picture the velocity graph between, say, t=0 and t=1s. You are >> modeling it as a straight line segment. However, it would actually be >> part of a quadratic curve connecting the same points, convex upwards. Concave upwards, since we're decelerating. >> The line segment is short-cutting the curve between the two points. The >> distance traveled is the integral of the curve, and it is easy to see >> that the integral of the line segment is less than the integral of the >> actual curve. Integral of the line segment is greater than the integral of the actual curve. > .... great. > > Okay. I never studied calculus, so this is beyond my expertise. Is this > going to make a majorly significant difference to the end result? I thought that there was a chance that there might be, but it turns out, not so much. There is a difference, but for the purposes of the simulation it probably doesn't matter. If you were trying to land a spacecraft on Mars, that's a different story... -- Steven From dwightdhutto at gmail.com Tue Apr 1 03:34:03 2014 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 1 Apr 2014 03:34:03 -0400 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: You would be assuming a quantum leap type theory, that the object has no Vo->V1, it just adjusts to the constant immediately, instead of what I would call the quantum leap,without other 'theories' involved, that it has a classical physics type movement in which it can accelerate from a resting position, to a velocity, and then regain orbit: http://wiki.answers.com/Q/What_is_a_quantum_leap On Tue, Apr 1, 2014 at 3:21 AM, David Hutto wrote: > u is the initial velocity from a starting/resting point, not a static > speed at that point, and begins to accelerate, > over a particular timeframe, in which it's momentum is not stopped by > friction on which the rails/environment it travels upon has, or the similar > properties the object might have during acceleration in relation to the > environment it travels within. > > So the object has a starting point at which there is no equal, or opposing > force, as it begins to accelerate from a resting position(Newton: an object > will remain in motion, until acted upon by an equal or opposite force, and > in this case the motion is propulsion of the object, or the newtons of > propulsion, until it is moving at the exact speed of the propulsion applied > to the object->Vo-V1, with 0 friction/viscosity during this timeframe). > > The difference in our opinions, seems to be that there is an initial > resting state, and not at an already accelerated motion that has reached > it's maximum capacity. > > > So there is a dynamic in my mind's eye, where the object is at a "resting" > point initially, and either the environment, or the object can maneuver > their own viscosity in relation to the other. > > > On Tue, Apr 1, 2014 at 2:39 AM, Ian Kelly wrote: > >> On Tue, Apr 1, 2014 at 12:24 AM, David Hutto >> wrote: >> >> >> >> >> (1) v = u + at >> >> >> (2) s = 1/2(u + v)t >> >> >> (3) s = ut + 1/2(at^2) >> >> >> (4) v^2 = u^2 + 2as >> >> >> >> >> >> Only (1) and (3) are needed. >> >> > >> >> > Okay, what's u here? Heh. >> >> >> >> u is the initial velocity; v is the velocity after accelerating at a >> for >> >> time t. >> > >> > >> > This assumes that the viscosity is in a state of superfluidity, and in a >> > perfect state between itself, and it's traveling environment. >> >> I fail to see how this is relevant. I would assume that the amount of >> friction is already modeled in the acceleration constants; if it were >> zero then the brakes would be nonfunctional and the train would not be >> able to accelerate or decelerate at all. In any case, a change in >> friction simply works out to a change in acceleration. The equations >> above still hold true. >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Best Regards, > David Hutto > *CEO:* *http://www.hitwebdevelopment.com > * > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com * -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Apr 1 03:35:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Apr 2014 18:35:52 +1100 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: <533a68c3$0$2909$c3e8da3$76491128@news.astraweb.com> References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> <533a68c3$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Apr 1, 2014 at 6:20 PM, Steven D'Aprano wrote: > On Tue, 01 Apr 2014 16:01:40 +1100, Chris Angelico wrote: > > [...] >>> The scenario you describe has (effectively) infinite rate-of-change-of- >>> acceleration, often called "jerk". (A jerk is a rapid change in >>> acceleration.) Human comfort is (within reasonable limits) more >>> affected by jerk than acceleration. The passengers will feel three >>> quite distinctive jerks, one when the brakes are first applied (which >>> is probably reasonable), then one at 1s, then again at 2s. That's not >>> comfortable by any stretch of the imagination. >> >> It actually is a smooth increase in deceleration, but I'm operating the >> simulator on a 1s period, so it's actually an average across the first >> second, and an average across the next second... > > Hmmm. A 1-second resolution doesn't really sound too great to me. > > Suppose the deceleration increases linearly from 0 to 0.85 m/s over two > seconds. Averaging it in the way you suggested, we get a total distance > of: > > 2*u - 0.5125 > > (see my previous post for details) where u is measured in metres per > second. Multiply by seconds to get the units right. For a Japanese bullet > train where u = 320 km/hr that corresponds to > > py> 2*88.888889 - 0.5125 > 177.26527800000002 > > metres. > > Now let's do it properly! Given our assumption that the deceleration is > linear, the jerk will be constant: > > j = ?a/?t > = (0.85 - 0)/2 > = 0.425 m/s^3 > > Let's start integrating! > > py> from sympy import integrate > py> from sympy.abc import t > py> j = '0.425' > py> a = integrate(j, t) > py> v = 88.888889 - integrate(a, t) > py> s = integrate(v, (t, 0, 2)) > py> s > 177.211111333333 > > compared to 177.26527800000002 calculated the rough way. That's not bad, > only about 5cm off! Effectively, your rough calculation was accurate to > one decimal place. 5cm when we're dealing with track distances measured in meters and usually hundreds of them? Sounds fine to me! > Of course, if the equation for acceleration was more complex, the > approximation may not be anywhere near as good. And that's the bit I can't know. I've added a comment to the code and will toss it back to my brother - hopefully he'll either know the answer or know where to look it up / who to ask. > [...] >>> This becomes a simple question for the four standard equations of >>> motion: >>> >>> (1) v = u + at >>> (2) s = 1/2(u + v)t >>> (3) s = ut + 1/2(at^2) >>> (4) v^2 = u^2 + 2as >>> >>> Only (1) and (3) are needed. >> >> Okay, what's u here? Heh. > > They're *standard* equations of motion. Weren't you paying attention > through the, oh, three years of high school where they teach this? :-P They're certainly the standard equations, but I learned that: d = v?t + at?/2 which is the same as you had, except for the names: d for distance, v? (V zero, that's a subscript zero if encodings or fonts kill you here) for initial velocity (ie velocity at time zero - v? (that's a subscript t, U+209C, but it isn't working in this font) is velocity at time t, which is v?+at), and a and t are the same as you have. > s = displacement (distance) > t = time > u = initial velocity > v = final velocity > a = acceleration I have to say, the one-letter variables are a lot easier to work with. Guess I learned them the hard way, heh. Although remembering that v is velocity is easier than remembering which of u and v is initial and which is final. >> Fair enough. :) That's why I asked. Is it naughty enough to break into >> two statements, or is it better to combine it into a single multiple >> assignment? > > Since they are unrelated assignments, of two different variables, they > should be written as two separate assignments, not one using sequence > unpacking. Change made. Yeah, that looks a bit cleaner. Although I would prefer a simple formula to what I have there, and I'm still not perfectly sure it's accurate. Advice appreciated. :) ChrisA From dwightdhutto at gmail.com Tue Apr 1 03:39:00 2014 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 1 Apr 2014 03:39:00 -0400 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: The link isn't to prove my ideology of what happens, it to show what you might be thinking about, instead of how I feel about it...nth dimensional dynamics/hyperspace taken out. Been out of this for a while due to medical reasons, but try to keep up on the latest measurements/accumulated data with today's(what has been publicly released) manufacturing levels. On Tue, Apr 1, 2014 at 3:34 AM, David Hutto wrote: > You would be assuming a quantum leap type theory, that the object has no > Vo->V1, it just adjusts to the constant immediately, instead of what I > would call the quantum leap,without other 'theories' involved, that it has > a classical physics type movement in which it can accelerate from a resting > position, to a velocity, and then regain orbit: > > http://wiki.answers.com/Q/What_is_a_quantum_leap > > > > On Tue, Apr 1, 2014 at 3:21 AM, David Hutto wrote: > >> u is the initial velocity from a starting/resting point, not a static >> speed at that point, and begins to accelerate, >> over a particular timeframe, in which it's momentum is not stopped by >> friction on which the rails/environment it travels upon has, or the similar >> properties the object might have during acceleration in relation to the >> environment it travels within. >> >> So the object has a starting point at which there is no equal, or >> opposing force, as it begins to accelerate from a resting position(Newton: >> an object will remain in motion, until acted upon by an equal or opposite >> force, and in this case the motion is propulsion of the object, or the >> newtons of propulsion, until it is moving at the exact speed of the >> propulsion applied to the object->Vo-V1, with 0 friction/viscosity during >> this timeframe). >> >> The difference in our opinions, seems to be that there is an initial >> resting state, and not at an already accelerated motion that has reached >> it's maximum capacity. >> >> >> So there is a dynamic in my mind's eye, where the object is at a >> "resting" point initially, and either the environment, or the object can >> maneuver their own viscosity in relation to the other. >> >> >> On Tue, Apr 1, 2014 at 2:39 AM, Ian Kelly wrote: >> >>> On Tue, Apr 1, 2014 at 12:24 AM, David Hutto >>> wrote: >>> >> >>> >> >> (1) v = u + at >>> >> >> (2) s = 1/2(u + v)t >>> >> >> (3) s = ut + 1/2(at^2) >>> >> >> (4) v^2 = u^2 + 2as >>> >> >> >>> >> >> Only (1) and (3) are needed. >>> >> > >>> >> > Okay, what's u here? Heh. >>> >> >>> >> u is the initial velocity; v is the velocity after accelerating at a >>> for >>> >> time t. >>> > >>> > >>> > This assumes that the viscosity is in a state of superfluidity, and in >>> a >>> > perfect state between itself, and it's traveling environment. >>> >>> I fail to see how this is relevant. I would assume that the amount of >>> friction is already modeled in the acceleration constants; if it were >>> zero then the brakes would be nonfunctional and the train would not be >>> able to accelerate or decelerate at all. In any case, a change in >>> friction simply works out to a change in acceleration. The equations >>> above still hold true. >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> >> >> >> -- >> Best Regards, >> David Hutto >> *CEO:* *http://www.hitwebdevelopment.com >> * >> > > > > -- > Best Regards, > David Hutto > *CEO:* *http://www.hitwebdevelopment.com > * > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com * -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Tue Apr 1 03:46:32 2014 From: dwightdhutto at gmail.com (David Hutto) Date: Tue, 1 Apr 2014 03:46:32 -0400 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: Notice that it says that laymans say it has a small state in progress, instead of a large state of 'progress'...that's arrogance, it's just the fact that it has a Vo->V1 state of progress. My question, which I haven't looked up the latest research on, is does it have the conservation of momentum, in which during the time frames that can be sampled in hertz, as it transitions to the higher shell level , and do those timeframes increase or decrease in relation to the eV(electron volts) applied? On Tue, Apr 1, 2014 at 3:39 AM, David Hutto wrote: > The link isn't to prove my ideology of what happens, it to show what you > might be thinking about, instead of how I feel about it...nth dimensional > dynamics/hyperspace taken out. Been out of this for a while due to medical > reasons, but try to keep up on the latest measurements/accumulated data > with today's(what has been publicly released) manufacturing levels. > > > On Tue, Apr 1, 2014 at 3:34 AM, David Hutto wrote: > >> You would be assuming a quantum leap type theory, that the object has no >> Vo->V1, it just adjusts to the constant immediately, instead of what I >> would call the quantum leap,without other 'theories' involved, that it has >> a classical physics type movement in which it can accelerate from a resting >> position, to a velocity, and then regain orbit: >> >> http://wiki.answers.com/Q/What_is_a_quantum_leap >> >> >> >> On Tue, Apr 1, 2014 at 3:21 AM, David Hutto wrote: >> >>> u is the initial velocity from a starting/resting point, not a static >>> speed at that point, and begins to accelerate, >>> over a particular timeframe, in which it's momentum is not stopped by >>> friction on which the rails/environment it travels upon has, or the similar >>> properties the object might have during acceleration in relation to the >>> environment it travels within. >>> >>> So the object has a starting point at which there is no equal, or >>> opposing force, as it begins to accelerate from a resting position(Newton: >>> an object will remain in motion, until acted upon by an equal or opposite >>> force, and in this case the motion is propulsion of the object, or the >>> newtons of propulsion, until it is moving at the exact speed of the >>> propulsion applied to the object->Vo-V1, with 0 friction/viscosity during >>> this timeframe). >>> >>> The difference in our opinions, seems to be that there is an initial >>> resting state, and not at an already accelerated motion that has reached >>> it's maximum capacity. >>> >>> >>> So there is a dynamic in my mind's eye, where the object is at a >>> "resting" point initially, and either the environment, or the object can >>> maneuver their own viscosity in relation to the other. >>> >>> >>> On Tue, Apr 1, 2014 at 2:39 AM, Ian Kelly wrote: >>> >>>> On Tue, Apr 1, 2014 at 12:24 AM, David Hutto >>>> wrote: >>>> >> >>>> >> >> (1) v = u + at >>>> >> >> (2) s = 1/2(u + v)t >>>> >> >> (3) s = ut + 1/2(at^2) >>>> >> >> (4) v^2 = u^2 + 2as >>>> >> >> >>>> >> >> Only (1) and (3) are needed. >>>> >> > >>>> >> > Okay, what's u here? Heh. >>>> >> >>>> >> u is the initial velocity; v is the velocity after accelerating at a >>>> for >>>> >> time t. >>>> > >>>> > >>>> > This assumes that the viscosity is in a state of superfluidity, and >>>> in a >>>> > perfect state between itself, and it's traveling environment. >>>> >>>> I fail to see how this is relevant. I would assume that the amount of >>>> friction is already modeled in the acceleration constants; if it were >>>> zero then the brakes would be nonfunctional and the train would not be >>>> able to accelerate or decelerate at all. In any case, a change in >>>> friction simply works out to a change in acceleration. The equations >>>> above still hold true. >>>> -- >>>> https://mail.python.org/mailman/listinfo/python-list >>>> >>> >>> >>> >>> -- >>> Best Regards, >>> David Hutto >>> *CEO:* *http://www.hitwebdevelopment.com >>> * >>> >> >> >> >> -- >> Best Regards, >> David Hutto >> *CEO:* *http://www.hitwebdevelopment.com >> * >> > > > > -- > Best Regards, > David Hutto > *CEO:* *http://www.hitwebdevelopment.com > * > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com * -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Apr 1 03:49:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Apr 2014 18:49:43 +1100 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: <533a6af1$0$2909$c3e8da3$76491128@news.astraweb.com> References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> <533a6af1$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Apr 1, 2014 at 6:29 PM, Steven D'Aprano wrote: >> Okay. I never studied calculus, so this is beyond my expertise. Is this >> going to make a majorly significant difference to the end result? > > I thought that there was a chance that there might be, but it turns out, > not so much. There is a difference, but for the purposes of the > simulation it probably doesn't matter. If you were trying to land a > spacecraft on Mars, that's a different story... I'm liking the idea of pretending it's linear acceleration. Our error in the system is: 1) Distances are accurate to one meter at absolute best; and I wouldn't guarantee that they're even that accurate. 2) The simulation will apply the brakes at some exact number of seconds past its origin. 3) A human driver might well apply the brakes a couple of seconds too soon, and then cruise at the curve's speed for a short distance before actually reaching the curve. 4) A human driver might also apply the brakes too _late_, and there are tolerances built into the curve speed limits to cater for this. The train would rock a bit more than is desired, but it won't instantly derail if it hits a 90km/h curve at 91km/h (which is how the simulator treats it). Add all that up, and the end result is unlikely to be accurate to better than ten seconds - and that's being generous. Ultimately, this would be for drawing up projected timetables, so it's not going to be used at more than one-minute accuracy; although comparing two proposed routes might technically make use of more accuracy than that ("we could go around to the left of this, or to the right of it; which would be the faster route?" "This one, by thirty seconds"), any difference of less than a minute would really have to be called "practically equal". By the way, line speed (the maximum safe speed on straight track) is 400km/h, so your estimates involving a 320km/h bullet train are in the right ballpark. Curves could be practically any speed between zero and that, although one would hope there aren't any Kooyong Stations on the route! (Just up [1] of the station [2] is a tram crossing, which for decades has been so bumpy and messy that trains had to slow down to about 10 or 20 kays to get through safely.) ChrisA [1] https://en.wikipedia.org/wiki/Rail_directions#United_Kingdom [2] https://en.wikipedia.org/wiki/Kooyong_railway_station From steve at pearwood.info Tue Apr 1 04:07:05 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 01 Apr 2014 08:07:05 GMT Subject: Code style query: multiple assignments in if/elif tree References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> <533a68c3$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: <533a73a9$0$2909$c3e8da3$76491128@news.astraweb.com> On Tue, 01 Apr 2014 18:35:52 +1100, Chris Angelico wrote: > Although remembering that v is > velocity is easier than remembering which of u and v is initial and > which is final. Which comes earlier in the alphabet? :-P -- Steven From rosuav at gmail.com Tue Apr 1 04:12:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Apr 2014 19:12:59 +1100 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: <533a73a9$0$2909$c3e8da3$76491128@news.astraweb.com> References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> <533a68c3$0$2909$c3e8da3$76491128@news.astraweb.com> <533a73a9$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Apr 1, 2014 at 7:07 PM, Steven D'Aprano wrote: > On Tue, 01 Apr 2014 18:35:52 +1100, Chris Angelico wrote: > >> Although remembering that v is >> velocity is easier than remembering which of u and v is initial and >> which is final. > > Which comes earlier in the alphabet? :-P So why isn't v initial velocity and w final? You start with some velocity, right? (Okay, now I'm mostly trolling. Heh. I did say your way was better, to start with.) ChrisA From ian.g.kelly at gmail.com Tue Apr 1 04:18:26 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 1 Apr 2014 02:18:26 -0600 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> <533a68c3$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Apr 1, 2014 at 1:35 AM, Chris Angelico wrote: > On Tue, Apr 1, 2014 at 6:20 PM, Steven D'Aprano wrote: >> 177.211111333333 >> >> compared to 177.26527800000002 calculated the rough way. That's not bad, >> only about 5cm off! Effectively, your rough calculation was accurate to >> one decimal place. > > 5cm when we're dealing with track distances measured in meters and > usually hundreds of them? Sounds fine to me! Erm, that's just the accumulated error over the first 2 seconds, though. A train moving at 88 m/s and decelerating at a maximum of 0.85 m/s^2 is not going to stop in just 177 meters. After the first 2 seconds, the model is the same using either method, but the velocity after 2 seconds is different. Using the linear deceleration integration, we get: a(t) = {-0.425t, t <= 2; -0.85, t > 2} v(t) = {v0 - 0.2125t^2, t <= 2; v0 - 0.85 - 0.85t, t > 2} Giving v(2s) = v0 - 0.85 m/s Using the averaging method, we get v(2s) = v0 - 0.2 - 0.425 = v0 - 0.625 m/s For a difference of 0.225 m/s. Using Steven's formula (4), the additional difference in stopping distance is thus: ?s = ((0 - (88.888889 - 0.625)^2) - (0 - (88.888889 - 0.85)^2)) / -1.7 = 23.33 m The reason the velocity is different after 2 seconds is because the linear deceleration does not match the constraints of the problem. The average deceleration for the first second is not 0.2 m/s, and the average deceleration for the second second is not 0.425 m/s. From antoon.pardon at rece.vub.ac.be Tue Apr 1 04:19:27 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 01 Apr 2014 10:19:27 +0200 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> Message-ID: <533A768F.5080102@rece.vub.ac.be> On 01-04-14 02:47, Ian Kelly wrote: > On Mon, Mar 31, 2014 at 1:31 PM, Antoon Pardon > wrote: >> Op 31-03-14 19:40, Ian Kelly schreef: >>> That was an exaggeration on my part. It wouldn't affect my job, as I >>> wouldn't expect to ever actually have to maintain anything like the >>> above. My greater point though is that it damages Python's >>> readability for no actual gain in my view. There is nothing useful >>> you can do with a name that is the U+1F4A9 character that you can't do >>> just as easily with alphanumeric identifiers like pile_of_poo (or >>> ????_??????? if one prefers; that's auto-translated, so don't blame me >>> if it's a poor translation). The kinds of symbols that we're talking >>> about here aren't part of any writing systems, and so to incorporate >>> them in *names* as if they were is an abuse of Unicode. >> Your argument doesn't has much weight. First of all it can be used >> for just restricting names to the ascii range. > I disagree. Non-ASCII written names are useful to anybody who prefers > not to do all their programming in English. Symbols that carry a meaning among different languages are more useful because they are meaningful to more people and so make the program readable to more people. >> Second of all I >> think a good chosen symbolic name can be more readable than a >> name in a character set you are not familiar with. A good chosen >> symbol will evoke a meaning with a lot of people. A name in a >> character set you are not familiar with is just gibberish to >> you. > Well, this is the path taken by APL. It has its supporters. It's not > known for being readable. No that is not the path taken by APL. AFAICS identifiers in APL are just like identifiers in python. The path taken by APL was that there were a lot more operators available that used non-alphanumeric characters. AFICS APL programs tend to be unreadable because they are mostly written in a very concise style. I think this is more the path taken by lisp-like languages where '+' is a name just like 'alpha' or 'r2d2'. In scheme I can just do the following. (define ? sqrt) (? 4) Which will give me the normal result. Maybe I missed it but I haven't heard scheme being called an unreadable language. >>> First, because while those may degrade readability, they do >>> so in a constrained way. A decorator application is just the @ symbol >>> and an identifier. >> And if abused, can totally change the working of your function. There >> is no guarantee that the function returned, has any relation with the >> original function. If that can't be a night mare for readability, >> I don't know what is. > As Terry Reedy noted, this has nothing to do with the decorator > syntax, so it isn't much of an argument against having such syntax. Point taken. >>> The if-else is just three expressions separated by >>> keywords. >> Yes but if used unrestrained in arbitrary expressions will make those >> expressions hard to understand. > I don't disagree. I hardly ever use it myself, certainly only if it > can fit comfortably into one line, which is rare. But it's still > quite limited in syntactic scope. Non alphanumeric characters in names is even more limited in syntatic scope. It doesn't even play at the syntatic level but only at the lexical level. >> So what if we double the number of different characters? I don't care >> about the number of them, I care about how meaningful they are. And >> as you say confusion is already possible. A good programmer knows >> how to deal with such a possible confusion, that the number of >> cases increases, doesn't need to be a problem for those that care >> about this. > So tell me then, how would you deal with it? In the case of script > identifiers, it's often not hard to discern from context whether a > particular character is e.g. a Latin h or a Cyrillic ?. Assuming the > original author wasn't being intentionally obfuscatory, if the rest of > the identifier is Cyrillic then the character is probably also > Cyrillic. If it's a one-character identifier, then hopefully the rest > of the module is consistent and you can guess from that. If the > identifier in question is just one symbol though, then you have a lot > less context. I deal with it, just the way I deal with it now. I generally trust the programmer to know what he is doing and to have done a good faith effort So that I don't have to worry about him having both a variable 'NO' and 'N0' I see no reason to be more parano?d about this just because there are more possibilities. > Second, at least in the case of decorators, while I don't dispute that > they can harm readability, I think that in the majority of cases they > actually help it. >> But that is not a fair comparison now, is it. What you are doing here >> is comparing actual use, to a worst case doom scenario. > I contend that there is no scenario with arbitrary Unicode identifiers > where readability is improved. At this moment I see no reason to just accept this. -- Antoon Pardon From ian.g.kelly at gmail.com Tue Apr 1 04:24:06 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 1 Apr 2014 02:24:06 -0600 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> <533a68c3$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Apr 1, 2014 at 2:18 AM, Ian Kelly wrote: > The reason the velocity is different after 2 seconds is because the > linear deceleration does not match the constraints of the problem. The > average deceleration for the first second is not 0.2 m/s, and the > average deceleration for the second second is not 0.425 m/s. Which I suddenly realize after posting makes my entire point moot. It doesn't matter how much total error there is from the linear deceleration method because the linear deceleration is wrong. As long as the averaging method has the actually correct velocity at 2s and thereafter continues to have the actually correct velocity, it will only be off by that small amount of error from the first two seconds. From Windows7IsOK at DreamPC2006.com Tue Apr 1 04:20:45 2014 From: Windows7IsOK at DreamPC2006.com (Skybuck Flying) Date: Tue, 1 Apr 2014 10:20:45 +0200 Subject: Python to be replaced by the new language called Cookie ! Message-ID: <1a31$533a76d6$5419b3e4$11235@cache80.multikabel.net> April Fools =D Bye, Skybuck =D From ian.g.kelly at gmail.com Tue Apr 1 04:29:42 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 1 Apr 2014 02:29:42 -0600 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> <533a6af1$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Apr 1, 2014 at 1:59 AM, Ian Kelly wrote: > Given that, I have to question your figures: > >> 177.211111333333 > >> compared to 177.26527800000002 calculated the rough way. That's not bad, >> only about 5cm off! Effectively, your rough calculation was accurate to >> one decimal place. > > As I noted the rough way should be an underestimate, so I'm not sure > why it's an overestimate here. That said, I don't see where either of > us made a mistake. And I realize now that this is also because the linear deceleration assumption doesn't match the average deceleration stated in the problem. It actually decelerates faster and cuts under the t=1s and t=2s points in the velocity graph, and therefore is actually a slightly larger underestimate. From hamidreza.alian at gmail.com Tue Apr 1 04:24:46 2014 From: hamidreza.alian at gmail.com (Hamidreza Alian) Date: Tue, 1 Apr 2014 10:24:46 +0200 Subject: realtime plot Message-ID: Dears, I want to plot serial data from Arduino by Chaco. Could you help me and guide me about that. If it is possible please send me some example. Bests Hamid. -- Hamidreza Hajimirzaalian PhD Eng. Politecnico di Torino Department of Mechanical and Aerospace Engineering Cell No : 0039 3298988694 Tel. No : 0039 011090 5921 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Apr 1 04:55:23 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 1 Apr 2014 02:55:23 -0600 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Apr 1, 2014 at 12:55 AM, Chris Angelico wrote: > On Tue, Apr 1, 2014 at 5:13 PM, Ian Kelly wrote: >> Then your computation is incorrect and will systematically >> underestimate the stopping distance. Assuming for simplicity that the >> acceleration actually increases linearly until it reaches maximum, >> picture the velocity graph between, say, t=0 and t=1s. You are >> modeling it as a straight line segment. However, it would actually be >> part of a quadratic curve connecting the same points, convex upwards. >> The line segment is short-cutting the curve between the two points. >> The distance traveled is the integral of the curve, and it is easy to >> see that the integral of the line segment is less than the integral of >> the actual curve. > > .... great. > > Okay. I never studied calculus, so this is beyond my expertise. Is > this going to make a majorly significant difference to the end result? > If so, I guess the code's going to have to be a whole lot more > sophisticated, which means I need to learn a whole lot more maths in > order to write it. And I'm still trying to find time to get familiar > with systemd (having jumped on the Upstart bandwagon and now find > myself backing a losing horse, if you'll forgive a mixed metaphor) and > Cython (just need an excuse for that one). Assuming the stated acceleration averages are correct, we can put an upper bound on the error. Draw a rectangle bounding the two consecutive points on the velocity graph. Given that the actual velocity decreases monotonically (which should be a safe assumption), that curve must be contained within this rectangle. Given that the deceleration also increases monotonically, we can also say that the curve must be contained within the upper triangle of that rectangle, as bisected by the straight line segment of the constant average acceleration version. The area of this triangle is 1s * 0.2 m/s / 2 = 0.1m. The area of the same triangle between t=1s and t=2s is 1s * 0.425 m/s / 2= 0.2125 m. Summing those, the upper bound for the error is only 0.3125 m. From rosuav at gmail.com Tue Apr 1 04:56:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Apr 2014 19:56:59 +1100 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> <533a6af1$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Apr 1, 2014 at 7:29 PM, Ian Kelly wrote: > On Tue, Apr 1, 2014 at 1:59 AM, Ian Kelly wrote: >> Given that, I have to question your figures: >> >>> 177.211111333333 >> >>> compared to 177.26527800000002 calculated the rough way. That's not bad, >>> only about 5cm off! Effectively, your rough calculation was accurate to >>> one decimal place. >> >> As I noted the rough way should be an underestimate, so I'm not sure >> why it's an overestimate here. That said, I don't see where either of >> us made a mistake. > > And I realize now that this is also because the linear deceleration > assumption doesn't match the average deceleration stated in the > problem. It actually decelerates faster and cuts under the t=1s and > t=2s points in the velocity graph, and therefore is actually a > slightly larger underestimate. Okay... so... hmm. I'm trying to wrap a fried brain around your post here, and I'm not sure it covered it properly. It's like a tortilla with the meat spilling out. (My analogies aren't much saner when I'm not brain fried, trust me.) The important part here is to work out exactly how fast we'll be going at the end of two seconds of gentle braking (before the 0.85m/s/s bit begins). If that velocity is exactly the initial speed minus 0.625 m/s/s, then the error won't accumulate, and it's just a slight difference that's well within tolerance. But if that velocity is higher or lower, then it's going to be significant; the initial speed could be 111.1? m/s (line speed of 400 km/h), and at that speed, 0.1 m/s difference could make a visible difference to the distance travelled (the difference between 111.0 and 111.1 m/s makes a 10m difference in the distance to reach 90 km/h or 25 m/s). Although, truth be told, that's probably still not *very* significant; it's 0.12 seconds of time difference. The exact deceleration curve isn't significant; all that matters is how far the train goes during that curve, and how much speed it loses. ChrisA From nispray at gmail.com Tue Apr 1 05:14:09 2014 From: nispray at gmail.com (Wesley) Date: Tue, 1 Apr 2014 02:14:09 -0700 (PDT) Subject: Python IM server In-Reply-To: <50efd79f-d085-4813-97fa-86e4e48e13f7@googlegroups.com> References: <50efd79f-d085-4813-97fa-86e4e48e13f7@googlegroups.com> Message-ID: ? 2014?4?1????UTC+8??1?06?17??Miki Tebeka??? > > I want to develop a instant message server, simply has user and group entity. > > > Is there any better existing open-source one? > > > Thus I can download and have a look. > > You can take a look at Twisted Words (https://twistedmatrix.com/trac/wiki/TwistedWords). Have you tried this before? I just have a look. Seems most samples are just for bot. I have scenarios that user-to-user and user talking in group. So, for the IM server side, may need store some infomation in database,store messages not sent to user .etc Seems twisted words is high wrapped, we still need to develop lots of things. Wesley From ian.g.kelly at gmail.com Tue Apr 1 05:18:24 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 1 Apr 2014 03:18:24 -0600 Subject: unicode as valid naming symbols In-Reply-To: <533A768F.5080102@rece.vub.ac.be> References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> Message-ID: On Tue, Apr 1, 2014 at 2:19 AM, Antoon Pardon wrote: > On 01-04-14 02:47, Ian Kelly wrote: >> On Mon, Mar 31, 2014 at 1:31 PM, Antoon Pardon >> wrote: >>> Second of all I >>> think a good chosen symbolic name can be more readable than a >>> name in a character set you are not familiar with. A good chosen >>> symbol will evoke a meaning with a lot of people. A name in a >>> character set you are not familiar with is just gibberish to >>> you. >> Well, this is the path taken by APL. It has its supporters. It's not >> known for being readable. > > No that is not the path taken by APL. AFAICS identifiers in APL are just > like identifiers in python. The path taken by APL was that there were > a lot more operators available that used non-alphanumeric characters. > > AFICS APL programs tend to be unreadable because they are mostly written > in a very concise style. > > I think this is more the path taken by lisp-like languages where '+' is > a name just like 'alpha' or 'r2d2'. In scheme I can just do the following. > > (define ? sqrt) > (? 4) You're still using the symbol as the name of an operation, though, so I see no practical difference from the APL style. The operation just happens to be user-defined rather than built-in. Granted that in Scheme or in Python-with-arbitrary-Unicode-identifiers you could just as easily name a variable ?, but I don't think that is what you are proposing in terms of choosing symbols to evoke meaning. > Which will give me the normal result. Maybe I missed it but I haven't heard > scheme being called an unreadable language. Well, I have, but I think that usually has more to do with an excess of parentheses. From marko at pacujo.net Tue Apr 1 05:32:53 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 01 Apr 2014 12:32:53 +0300 Subject: unicode as valid naming symbols References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> Message-ID: <87txadtmwq.fsf@elektro.pacujo.net> Ian Kelly : > On Tue, Apr 1, 2014 at 2:19 AM, Antoon Pardon >> Which will give me the normal result. Maybe I missed it but I haven't >> heard scheme being called an unreadable language. > > Well, I have, but I think that usually has more to do with an excess > of parentheses. If you count braces as parentheses, there are about the same number of parentheses in scheme and C: int main() { printf("Hello world\n"); return 0; } (define (main) (format #t "Hello world\n") 0) C: 6 Scheme: 6 Marko From ian.g.kelly at gmail.com Tue Apr 1 05:58:00 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 1 Apr 2014 03:58:00 -0600 Subject: unicode as valid naming symbols In-Reply-To: <87txadtmwq.fsf@elektro.pacujo.net> References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <87txadtmwq.fsf@elektro.pacujo.net> Message-ID: On Tue, Apr 1, 2014 at 3:32 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> On Tue, Apr 1, 2014 at 2:19 AM, Antoon Pardon >>> Which will give me the normal result. Maybe I missed it but I haven't >>> heard scheme being called an unreadable language. >> >> Well, I have, but I think that usually has more to do with an excess >> of parentheses. > > If you count braces as parentheses, there are about the same number of > parentheses in scheme and C: > > int main() > { > printf("Hello world\n"); > return 0; > } > > (define (main) > (format #t "Hello world\n") > 0) > > C: 6 > Scheme: 6 On the other hand, you recently posted this snippet to the list: ((let ((n 3)) (let ((f (lambda () n))) (set! n 7) f))) Setting aside the fact that C doesn't have anonymous functions, I'll approximate it as best I can: static int n = 3; int f() { return n; } int main() { n = 7; return f(); } C: 10 Scheme: 20 From antoon.pardon at rece.vub.ac.be Tue Apr 1 06:37:29 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 01 Apr 2014 12:37:29 +0200 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> Message-ID: <533A96E9.1030107@rece.vub.ac.be> On 01-04-14 11:18, Ian Kelly wrote: > On Tue, Apr 1, 2014 at 2:19 AM, Antoon Pardon > wrote: >> On 01-04-14 02:47, Ian Kelly wrote: >> >>> Well, this is the path taken by APL. It has its supporters. It's not >>> known for being readable. >> No that is not the path taken by APL. AFAICS identifiers in APL are just >> like identifiers in python. The path taken by APL was that there were >> a lot more operators available that used non-alphanumeric characters. >> >> AFICS APL programs tend to be unreadable because they are mostly written >> in a very concise style. >> >> I think this is more the path taken by lisp-like languages where '+' is >> a name just like 'alpha' or 'r2d2'. In scheme I can just do the following. >> >> (define ? sqrt) >> (? 4) > You're still using the symbol as the name of an operation, though, so > I see no practical difference from the APL style. The operation just > happens to be user-defined rather than built-in. Python also uses symbols for names of operations, like '+'. And when someone suggested python might consider increasing the number of operations and gave some symbols for those extra operations, nobody suggested that would make python unreadable, though it would be far more like the path taken by APL then what we are discussing now. But the idea we are discussing here has nothing to do with introducing more operators and use symbolic characters for that and as such wouldn't make python more APL like. You only bring up APL because it uses a number of unfamilar symbols and you attribute the unreadabilty of APL programs mostly to that. But regarding the functionality we are talking here APL doesn't have it. So we are not talking about the path taken by APL. -- Antoon Pardon From rosuav at gmail.com Tue Apr 1 06:39:06 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Apr 2014 21:39:06 +1100 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <87txadtmwq.fsf@elektro.pacujo.net> Message-ID: On Tue, Apr 1, 2014 at 8:58 PM, Ian Kelly wrote: > Setting aside the fact that C doesn't have anonymous functions, I'll > approximate it as best I can: > > static int n = 3; > > int f() > { > return n; > } > > int main() > { > n = 7; > return f(); > } > > C: 10 > Scheme: 20 And the less trivial the example, the more difference you'll see. This is Scheme inside LilyPond, a little translator that lets me input lyrics in a tidy way that can then be turned into something that works well with both MIDI Karaoke and printed score: #(define (bang2slashn lst) ( cond ((null? lst) 0) (else (begin (if (equal? (ly:music-property (car lst) 'name) 'LyricEvent) (let ((txt (ly:music-property (car lst) 'text))) (if (equal? (string-ref txt 0) #\!) (begin ; Debugging display ; (display (ly:music-property (car lst) 'name)) (display " - ") (display txt) (newline) ; Prepend a newline instead of the exclamation mark - works for both MIDI Karaoke and page layout (ly:music-set-property! (car lst) 'text (string-append "\n" (substring txt 1 (string-length txt)))) )))) (bang2slashn (ly:music-property (car lst) 'elements)) (bang2slashn (cdr lst)) )) )) % Call the above recursive function lyr=#(define-music-function (parser location lyrics) (ly:music?) (bang2slashn (ly:music-property lyrics 'elements)) lyrics ) Now, this was written by a non-Scheme programmer, so it's not going to be optimal code, but I doubt it's going to lose a huge number of parentheses. Not counting the commented-out debugging line, that's 41 pairs of them in a short but non-trivial piece of code. Translating it to C isn't easy, in the same way that it's hard to explain how to do client-side web form validation in Lua; but here's an attempt. It assumes a broadly C-like structure to LilyPond (eg that the elements are passed as a structure; they are a tree already, as you can see by the double-recursive function above), which is of course not the case, but here goes: void bang2slashn(struct element *lst) { while (lst) { if (!strcmp(lst->name, "LyricEvent")) { char *text = music_property(lst, "text"); /* Okay, C doesn't have string manipulation, so I cheat here */ /* If this were C++ or Pike, some notation nearer to the original would work */ if (*text == '!') music_set_property(lst, "text", "\n" + text[1..]); } bang2slashn(lst->elements); lst = lst->next; } } DEFINE_MUSIC_FUNCTION(PARSER_LOCATION_LYRICS, bang2slashn); That's nine pair parens, three braces, and one square. I assume a lot about the supposed C-like interface to LilyPond, but I think anyone who knows both C and Scheme would agree that I haven't been horrendously unfair in the translation. (Though I will accept an alternate implementation of the Scheme version. If you can cut it down to just 26 pair parens, you'll achieve the 2:1 ratio that Ian mentioned. And if you can cut it down to 13 pairs, you've equalled my count.) The only way to have the C figure come up approximately equal is to count a semicolon as if it were a pair of parens - Scheme has an extra set of parens doing the job of separating one function call from another. But that adds only another 5, bringing C up to a total of 18 (plus a few more if I used functions to do my string manipulation, so let's say about 20-25) where Scheme is still at roughly twice that. ChrisA From rosuav at gmail.com Tue Apr 1 06:58:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Apr 2014 21:58:14 +1100 Subject: unicode as valid naming symbols In-Reply-To: <533A96E9.1030107@rece.vub.ac.be> References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <533A96E9.1030107@rece.vub.ac.be> Message-ID: On Tue, Apr 1, 2014 at 9:37 PM, Antoon Pardon wrote: > Python also uses symbols for names of operations, like '+'. And when > someone suggested python might consider increasing the number of > operations and gave some symbols for those extra operations, nobody > suggested that would make python unreadable, though it would be far > more like the path taken by APL then what we are discussing now. Actually, people did. But mainly the thread (look up "Time we switched to unicode?") went off looking at how hard it'd be to type those operators, and therefore the more serious point that there would either be hard-to-type language elements or duplicate syntactic tokens ("lambda" as well as "?", etc). That isn't an issue with names, because any name has only one, well, name. If you choose to use both "alpha" and "?" as names, that's fine, and they're distinct names. You can make your code unreadable, and it doesn't impact my code at all. Language-level features like operators have stronger concerns. But because, in the future, Python may choose to create new operators, the simplest and safest way to ensure safety is to put a boundary on what can be operators and what can be names; Unicode character classes are perfect for this. It's also possible that all Unicode whitespace characters might become legal for indentation and separation (maybe they are already??), so obviously they're ruled out as identifiers; anyway, I honestly do not think people would want to use U+2007 FIGURE SPACE inside a name. So if we deny whitespace, and accept letters and digits, it makes good sense to deny mathematical symbols so as to keep them available for operators. (It also makes reasonable sense to *permit* mathematical symbols, thus allowing you to use them for functions/methods, in the same way that you can use "n", "o", and "t", but not "not"; but with word operators, the entire word has to be used as-is before it's a collision - with a symbolic one, any instance of that symbol inside a name will change parsing entirely. It's a trade-off, and Python's made a decision one way and not the other.) ChrisA From jsf80238 at gmail.com Tue Apr 1 07:50:49 2014 From: jsf80238 at gmail.com (Jason Friedman) Date: Tue, 1 Apr 2014 05:50:49 -0600 Subject: realtime plot In-Reply-To: References: Message-ID: > > I want to plot serial data from Arduino by Chaco. Could you help me and > guide me about that. > I found this: http://www.blendedtechnologies.com/realtime-plot-of-arduino-serial-data-using-python/231 . -------------- next part -------------- An HTML attachment was scrubbed... URL: From marko at pacujo.net Tue Apr 1 08:02:29 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 01 Apr 2014 15:02:29 +0300 Subject: unicode as valid naming symbols References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <87txadtmwq.fsf@elektro.pacujo.net> Message-ID: <87ob0ltfze.fsf@elektro.pacujo.net> Ian Kelly : > Setting aside the fact that C doesn't have anonymous functions, I'll > approximate it as best I can: > > [...] > > C: 10 > Scheme: 20 It is true that scheme needs parentheses for operators and assignments so the ratio is probably in the order of 2:1. Whether that is excess or not is a matter of taste. For example: ======================================================================== #include int main() { int n, i = 3, count, c; printf("Enter the number of prime numbers required\n"); scanf("%d",&n); if ( n >= 1 ) { printf("First %d prime numbers are :\n",n); printf("2\n"); } for ( count = 2 ; count <= n ; ) { for ( c = 2 ; c <= i - 1 ; c++ ) { if ( i%c == 0 ) break; } if ( c == i ) { printf("%d\n",i); count++; } i++; } return 0; } ======================================================================== () is rendered in scheme as follows: ======================================================================== (define (main) (format #t "Enter the number of prime numbers required\n") (let ((n (read))) (if (>= n 1) (begin (format #t "First ~S prime numbers are :\n" n) (format #t "2\n"))) (let display-primes ((count 2) (i 3)) (if (<= count n) (let find-divisor ((c 2)) (cond ((= c i) (format #t "~S\n" i) (display-primes (1+ count) (1+ i))) ((= (remainder i c) 0) (display-primes count (1+ i))) (else (find-divisor (1+ c))))))))) (main) ======================================================================== The scheme translation has 37 parenthesis pairs, while the C version has 16. Which one is easier on the eye? Marko From antoon.pardon at rece.vub.ac.be Tue Apr 1 07:59:15 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 01 Apr 2014 13:59:15 +0200 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <533A96E9.1030107@rece.vub.ac.be> Message-ID: <533AAA13.4010309@rece.vub.ac.be> On 01-04-14 12:58, Chris Angelico wrote: > But because, in the future, Python may choose to create new operators, > the simplest and safest way to ensure safety is to put a boundary on > what can be operators and what can be names; Unicode character classes > are perfect for this. It's also possible that all Unicode whitespace > characters might become legal for indentation and separation (maybe > they are already??), so obviously they're ruled out as identifiers; > anyway, I honestly do not think people would want to use U+2007 FIGURE > SPACE inside a name. So if we deny whitespace, and accept letters and > digits, it makes good sense to deny mathematical symbols so as to keep > them available for operators. (It also makes reasonable sense to > *permit* mathematical symbols, thus allowing you to use them for > functions/methods, in the same way that you can use "n", "o", and "t", > but not "not"; but with word operators, the entire word has to be used > as-is before it's a collision - with a symbolic one, any instance of > that symbol inside a name will change parsing entirely. It's a > trade-off, and Python's made a decision one way and not the other.) This mostly makes sense to me. The only caveat I have is that since we also allow _ (U+005F LOW LINE) in names which belongs to the category , we should allow other symbols within this category in a name. But I confess that is mostly personal taste, since I find names_like_this ugly. Names-like-this look better to me but that wouldn't be workable in python. But maybe there is some connector that would be aestetically pleasing and not causing other problems. -- Antoon Pardon From roy at panix.com Tue Apr 1 08:29:13 2014 From: roy at panix.com (Roy Smith) Date: Tue, 01 Apr 2014 08:29:13 -0400 Subject: unicode as valid naming symbols References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <533A96E9.1030107@rece.vub.ac.be> Message-ID: In article , Antoon Pardon wrote: > On 01-04-14 12:58, Chris Angelico wrote: > > But because, in the future, Python may choose to create new operators, > > the simplest and safest way to ensure safety is to put a boundary on > > what can be operators and what can be names; Unicode character classes > > are perfect for this. It's also possible that all Unicode whitespace > > characters might become legal for indentation and separation (maybe > > they are already??), so obviously they're ruled out as identifiers; > > anyway, I honestly do not think people would want to use U+2007 FIGURE > > SPACE inside a name. So if we deny whitespace, and accept letters and > > digits, it makes good sense to deny mathematical symbols so as to keep > > them available for operators. (It also makes reasonable sense to > > *permit* mathematical symbols, thus allowing you to use them for > > functions/methods, in the same way that you can use "n", "o", and "t", > > but not "not"; but with word operators, the entire word has to be used > > as-is before it's a collision - with a symbolic one, any instance of > > that symbol inside a name will change parsing entirely. It's a > > trade-off, and Python's made a decision one way and not the other.) > > This mostly makes sense to me. The only caveat I have is that since we > also allow _ (U+005F LOW LINE) in names which belongs to the category > , we should allow other symbols within this > category in a name. > > But I confess that is mostly personal taste, since I find names_like_this > ugly. Names-like-this look better to me but that wouldn't be workable > in python. But maybe there is some connector that would be aestetically > pleasing and not causing other problems. Semi-seriously, let me suggest (names like this). It's not valid syntax now, so it can't break any existing code. It reuses existing punctuation in a way which is a logical extension of its traditional meaning, i.e. "group these things together". From rosuav at gmail.com Tue Apr 1 08:54:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Apr 2014 23:54:00 +1100 Subject: unicode as valid naming symbols In-Reply-To: <87ob0ltfze.fsf@elektro.pacujo.net> References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <87txadtmwq.fsf@elektro.pacujo.net> <87ob0ltfze.fsf@elektro.pacujo.net> Message-ID: On Tue, Apr 1, 2014 at 11:02 PM, Marko Rauhamaa wrote: > ======================================================================== > #include > > int main() > { > int n, i = 3, count, c; > > printf("Enter the number of prime numbers required\n"); > scanf("%d",&n); > > if ( n >= 1 ) > { > printf("First %d prime numbers are :\n",n); > printf("2\n"); > } > > for ( count = 2 ; count <= n ; ) > { > for ( c = 2 ; c <= i - 1 ; c++ ) > { > if ( i%c == 0 ) > break; > } > if ( c == i ) > { > printf("%d\n",i); > count++; > } > i++; > } > > return 0; > } > ======================================================================== > ( c-program-for-prime-number>) Here's my tweaked version of that: ======================================================================== #include int main() { int i = 3, count, factor; printf("Enter the number of prime numbers required\n"); scanf("%d",&count); if ( count >= 1 ) { printf("First %d prime numbers are:\n",count); printf("2\n"); } while (count > 1) { /* This is a pretty stupid algorithm */ for ( factor = 2 ; factor <= i - 1 ; factor++ ) if ( i%factor == 0 ) break; if ( factor == i ) { printf("%d\n",i); count--; } i++; } return 0; } ======================================================================== Doesn't change the parenthesis count (other than that I dropped an unnecessary pair of braces; some people would prefer to keep them, but I find they're quite superfluous), but improves readability. (Why use a for loop when you could use a simple while?) As to the question of whether this is more or less readable than the Scheme version... I guess that partly depends on the reader's relative familiarity with C and Scheme, but it's crystal clear to me what the C version is doing - and that it's doing something stupid. I don't find it more readable to cast something as recursive; compare these two tight loops: (let find-divisor ((c 2)) (cond ((= c i) (format #t "~S\n" i) (display-primes (1+ count) (1+ i))) ((= (remainder i c) 0) (display-primes count (1+ i))) (else (find-divisor (1+ c))))))))) for ( factor = 2 ; factor <= i - 1 ; factor++ ) if ( i%factor == 0 ) break; if ( factor == i ) { printf("%d\n",i); count--; } In the first one, you start doing something, and if you don't have a termination point, you recurse - which means you have to name this loop as a function. In the second, you simply iterate, and then at the end, decide whether you have the termination condition or not. It's easy to see what the loop condition is; it's easy to see that it will always end by one or other termination rule, and then it acts based on that. Actually, if you switch the conditions, it would look a bit more like the Scheme version: for ( factor = 2 ; i%factor ; factor++ ) { if ( factor == i ) { printf("%d\n",i); count--; break; } } I wouldn't say this makes the code notably more readable, and it doesn't change the parenthesis count (apart from making more people want to put the outer braces in - they're still technically optional, and that was only an optional reduction in the first place), but it's a closer equivalent and that might make comparison easier. My view is definitely that the C version is WAY more readable than the Scheme one. ChrisA From rosuav at gmail.com Tue Apr 1 09:00:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Apr 2014 00:00:56 +1100 Subject: unicode as valid naming symbols In-Reply-To: <533AAA13.4010309@rece.vub.ac.be> References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <533A96E9.1030107@rece.vub.ac.be> <533AAA13.4010309@rece.vub.ac.be> Message-ID: On Tue, Apr 1, 2014 at 10:59 PM, Antoon Pardon wrote: > On 01-04-14 12:58, Chris Angelico wrote: >> But because, in the future, Python may choose to create new operators, >> the simplest and safest way to ensure safety is to put a boundary on >> what can be operators and what can be names; Unicode character classes >> are perfect for this. It's also possible that all Unicode whitespace >> characters might become legal for indentation and separation (maybe >> they are already??), so obviously they're ruled out as identifiers; >> anyway, I honestly do not think people would want to use U+2007 FIGURE >> SPACE inside a name. So if we deny whitespace, and accept letters and >> digits, it makes good sense to deny mathematical symbols so as to keep >> them available for operators. (It also makes reasonable sense to >> *permit* mathematical symbols, thus allowing you to use them for >> functions/methods, in the same way that you can use "n", "o", and "t", >> but not "not"; but with word operators, the entire word has to be used >> as-is before it's a collision - with a symbolic one, any instance of >> that symbol inside a name will change parsing entirely. It's a >> trade-off, and Python's made a decision one way and not the other.) > > This mostly makes sense to me. The only caveat I have is that since we > also allow _ (U+005F LOW LINE) in names which belongs to the category > , we should allow other symbols within this > category in a name. > > But I confess that is mostly personal taste, since I find names_like_this > ugly. Names-like-this look better to me but that wouldn't be workable > in python. But maybe there is some connector that would be aestetically > pleasing and not causing other problems. That's reasonable. The Pc category doesn't have much in it: http://www.fileformat.info/info/unicode/category/Pc/list.htm If the definition of "characters permitted in identifiers" is derived exclusively from the Unicode categories, including Pc would make fine sense. Probably the definition should be: First character is L* or Pc, subsequent characters are L*, N*, or Pc, and either Mn or M* (combining characters). Or something like that. ChrisA From rosuav at gmail.com Tue Apr 1 09:08:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Apr 2014 00:08:14 +1100 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <533A96E9.1030107@rece.vub.ac.be> Message-ID: On Tue, Apr 1, 2014 at 11:29 PM, Roy Smith wrote: >> But I confess that is mostly personal taste, since I find names_like_this >> ugly. Names-like-this look better to me but that wouldn't be workable >> in python. But maybe there is some connector that would be aestetically >> pleasing and not causing other problems. > > Semi-seriously, let me suggest (names like this). It's not valid syntax > now, so it can't break any existing code. It reuses existing > punctuation in a way which is a logical extension of its traditional > meaning, i.e. "group these things together". I'd really rather not have a drastically different concept of "name" to every other language's definition! Reading over COBOL code is confusing in ways that reading, say, Ruby code isn't; the ? and ! suffixes aren't nearly as confusing as: http://www.math-cs.gordon.edu/courses/cs323/COBOL/cobol.html """ COBOL identifers are 1-30 alphanumeric characters, at least one of which must be non-numeric. In certain contexts it is permissible to use a totally numeric identifier; however, that usage is discouraged. Hyphens may be included in an identifier anywhere except the first of last character. """ Hyphens in names! Ugh! That means subtraction! :) But there is a solution! You can have *anything you want* in your identifiers. Watch: v = {} v["names like this"] = 42 print(v["names like this"]) Yes, that's a five-character delimiter/marker. But it works!! ChrisA From marko at pacujo.net Tue Apr 1 09:16:51 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 01 Apr 2014 16:16:51 +0300 Subject: unicode as valid naming symbols References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <87txadtmwq.fsf@elektro.pacujo.net> <87ob0ltfze.fsf@elektro.pacujo.net> Message-ID: <87eh1htcjg.fsf@elektro.pacujo.net> Chris Angelico : > I don't find it more readable to cast something as recursive; compare > these two tight loops: > > (let find-divisor ((c 2)) > (cond > ((= c i) > (format #t "~S\n" i) > (display-primes (1+ count) (1+ i))) > ((= (remainder i c) 0) > (display-primes count (1+ i))) > (else > (find-divisor (1+ c))))))))) > > for ( factor = 2 ; factor <= i - 1 ; factor++ ) > if ( i%factor == 0 ) break; > if ( factor == i ) > { > printf("%d\n",i); > count--; > } > > In the first one, you start doing something, and if you don't have a > termination point, you recurse - which means you have to name this > loop as a function. In the second, you simply iterate, I implemented the loops in the scheme way. Recursion is how iteration is done by the Believers. Traditional looping structures are available to scheme, but if you felt the need for them, you might as well program in Python. On the other hand, I didn't look for the most elegant implementation idiom but tried to translate the original rather mechanically--in good and bad. > My view is definitely that the C version is WAY more readable than the > Scheme one. Yes, scheme is an acquired taste. As is Python. My experienced bash/C colleague was baffled by some Python idioms (not in my code, I might add) that looked pretty clear to me. Marko From rosuav at gmail.com Tue Apr 1 09:32:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Apr 2014 00:32:54 +1100 Subject: unicode as valid naming symbols In-Reply-To: <87eh1htcjg.fsf@elektro.pacujo.net> References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <87txadtmwq.fsf@elektro.pacujo.net> <87ob0ltfze.fsf@elektro.pacujo.net> <87eh1htcjg.fsf@elektro.pacujo.net> Message-ID: On Wed, Apr 2, 2014 at 12:16 AM, Marko Rauhamaa wrote: > I implemented the loops in the scheme way. Recursion is how iteration is > done by the Believers. Traditional looping structures are available to > scheme, but if you felt the need for them, you might as well program in > Python. Then I'm happily a pagan who uses while loops instead of recursion. Why should every loop become a named function? find_divisor: for ( factor = 2 ; i%factor ; factor++ ) { if ( factor == i ) { printf("%d\n",i); count--; break; } } Does that label add anything? If you really need to put a name to every loop you ever write, there's something wrong with the code; some loops' purposes should be patently obvious by their body. All you do is add duplicate information that might be wrong. ChrisA From ned at nedbatchelder.com Tue Apr 1 09:33:33 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 01 Apr 2014 09:33:33 -0400 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <533A96E9.1030107@rece.vub.ac.be> <533AAA13.4010309@rece.vub.ac.be> Message-ID: On 4/1/14 9:00 AM, Chris Angelico wrote: > On Tue, Apr 1, 2014 at 10:59 PM, Antoon Pardon > wrote: >> On 01-04-14 12:58, Chris Angelico wrote: >>> But because, in the future, Python may choose to create new operators, >>> the simplest and safest way to ensure safety is to put a boundary on >>> what can be operators and what can be names; Unicode character classes >>> are perfect for this. It's also possible that all Unicode whitespace >>> characters might become legal for indentation and separation (maybe >>> they are already??), so obviously they're ruled out as identifiers; >>> anyway, I honestly do not think people would want to use U+2007 FIGURE >>> SPACE inside a name. So if we deny whitespace, and accept letters and >>> digits, it makes good sense to deny mathematical symbols so as to keep >>> them available for operators. (It also makes reasonable sense to >>> *permit* mathematical symbols, thus allowing you to use them for >>> functions/methods, in the same way that you can use "n", "o", and "t", >>> but not "not"; but with word operators, the entire word has to be used >>> as-is before it's a collision - with a symbolic one, any instance of >>> that symbol inside a name will change parsing entirely. It's a >>> trade-off, and Python's made a decision one way and not the other.) >> >> This mostly makes sense to me. The only caveat I have is that since we >> also allow _ (U+005F LOW LINE) in names which belongs to the category >> , we should allow other symbols within this >> category in a name. >> >> But I confess that is mostly personal taste, since I find names_like_this >> ugly. Names-like-this look better to me but that wouldn't be workable >> in python. But maybe there is some connector that would be aestetically >> pleasing and not causing other problems. > > That's reasonable. The Pc category doesn't have much in it: > > http://www.fileformat.info/info/unicode/category/Pc/list.htm > > If the definition of "characters permitted in identifiers" is derived > exclusively from the Unicode categories, including Pc would make fine > sense. Probably the definition should be: First character is L* or Pc, > subsequent characters are L*, N*, or Pc, and either Mn or M* > (combining characters). Or something like that. Maybe I'm misunderstanding the discussion... It seems like we're talking about a hypothetical definition of identifiers based on Unicode character categories, but there's no need: Python 3 has defined precisely that. From the docs (https://docs.python.org/3/reference/lexical_analysis.html#identifiers): ------------ Python 3.0 introduces additional characters from outside the ASCII range (see PEP 3131). For these characters, the classification uses the version of the Unicode Character Database as included in the unicodedata module. Identifiers are unlimited in length. Case is significant. identifier ::= xid_start xid_continue* id_start ::= id_continue ::= xid_start ::= xid_continue ::= The Unicode category codes mentioned above stand for: Lu - uppercase letters Ll - lowercase letters Lt - titlecase letters Lm - modifier letters Lo - other letters Nl - letter numbers Mn - nonspacing marks Mc - spacing combining marks Nd - decimal numbers Pc - connector punctuations Other_ID_Start - explicit list of characters in PropList.txt to support backwards compatibility Other_ID_Continue - likewise All identifiers are converted into the normal form NFKC while parsing; comparison of identifiers is based on NFKC. -------- > > ChrisA > -- Ned Batchelder, http://nedbatchelder.com From rustompmody at gmail.com Tue Apr 1 09:34:42 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 1 Apr 2014 06:34:42 -0700 (PDT) Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <533A96E9.1030107@rece.vub.ac.be> Message-ID: On Tuesday, April 1, 2014 6:38:14 PM UTC+5:30, Chris Angelico wrote: > On Tue, Apr 1, 2014 at 11:29 PM, Roy Smith wrote: > >> But I confess that is mostly personal taste, since I find names_like_this > >> ugly. Names-like-this look better to me but that wouldn't be workable > >> in python. But maybe there is some connector that would be aestetically > >> pleasing and not causing other problems. > > Semi-seriously, let me suggest (names like this). It's not valid syntax > > now, so it can't break any existing code. It reuses existing > > punctuation in a way which is a logical extension of its traditional > > meaning, i.e. "group these things together". > I'd really rather not have a drastically different concept of "name" > to every other language's definition! Reading over COBOL code is > confusing in ways that reading, say, Ruby code isn't; the ? and ! > suffixes aren't nearly as confusing as: > http://www.math-cs.gordon.edu/courses/cs323/COBOL/cobol.html > """ > COBOL identifers are 1-30 alphanumeric characters, at least one of > which must be non-numeric. > In certain contexts it is permissible to use a totally numeric > identifier; however, that usage > is discouraged. Hyphens may be included in an identifier anywhere > except the first of last > character. > """ > Hyphens in names! Ugh! That means subtraction! :) Just temporarily switch to a domain other than programming -- one that has not been under the absolute hegemony of ASCII for 40 years and you may get different results -- See 1st item from here: http://searchengineland.com/9-seo-quirks-you-should-be-aware-of-146465 From rosuav at gmail.com Tue Apr 1 09:44:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Apr 2014 00:44:15 +1100 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <533A96E9.1030107@rece.vub.ac.be> <533AAA13.4010309@rece.vub.ac.be> Message-ID: On Wed, Apr 2, 2014 at 12:33 AM, Ned Batchelder wrote: > Maybe I'm misunderstanding the discussion... It seems like we're talking > about a hypothetical definition of identifiers based on Unicode character > categories, but there's no need: Python 3 has defined precisely that. From > the docs > (https://docs.python.org/3/reference/lexical_analysis.html#identifiers): > "Python 3.0 introduces **additional characters** from outside the ASCII range" - emphasis mine. Python currently has - at least, per that documentation - a hybrid system with ASCII characters defined in the classic way, and non-ASCII characters defined by their Unicode character classes. I'm talking about a system that's _purely_ defined by Unicode character classes. It may turn out that the class list exactly compasses the ASCII characters listed, though, in which case you'd be right: it's not hypothetical. In any case, Pc is included, which I should have checked beforehand. So that part is, as you say, not hypothetical. Go for it! Use 'em. ChrisA From rustompmody at gmail.com Tue Apr 1 09:58:47 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 1 Apr 2014 06:58:47 -0700 (PDT) Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <533A96E9.1030107@rece.vub.ac.be> <533AAA13.4010309@rece.vub.ac.be> Message-ID: On Tuesday, April 1, 2014 7:14:15 PM UTC+5:30, Chris Angelico wrote: > On Wed, Apr 2, 2014 at 12:33 AM, Ned Batchelder wrote: > > Maybe I'm misunderstanding the discussion... It seems like we're talking > > about a hypothetical definition of identifiers based on Unicode character > > categories, but there's no need: Python 3 has defined precisely that. From > > the docs > > (https://docs.python.org/3/reference/lexical_analysis.html#identifiers): > "Python 3.0 introduces **additional characters** from outside the > ASCII range" - emphasis mine. > Python currently has - at least, per that documentation - a hybrid > system with ASCII characters defined in the classic way, and non-ASCII > characters defined by their Unicode character classes. I'm talking > about a system that's _purely_ defined by Unicode character classes. > It may turn out that the class list exactly compasses the ASCII > characters listed, though, in which case you'd be right: it's not > hypothetical. > In any case, Pc is included, which I should have checked beforehand. > So that part is, as you say, not hypothetical. Go for it! Use 'em. Dunno if you really mean it or are just saying... Steven gave the example the other day of confusing the identifiers A and ?. There must be easily hundreds (thousands?) of other such confusables. So you think thats nice and APL(-ese), Scheme(-ish) is not...??? Confused by your stand... Personally I dont believe that unicode has been designed with programming languages in mind. Assuming that unicode categories will naturally and easily fit programming language lexical/syntax categories is rather naive. From damien.touraine at limsi.fr Tue Apr 1 10:14:07 2014 From: damien.touraine at limsi.fr (Damien Touraine) Date: Tue, 01 Apr 2014 16:14:07 +0200 Subject: Strange message from a program Message-ID: <533AC9AF.5080604@limsi.fr> Hi, We use Python 3.2 on standard Ubuntu precise Linux. I have a big program with several dependencies (mainly PySide). But, sometimes, it fails with :RuntimeError: Can't find converter for '\ufffd\ufffd' to call Python meta method. The given string ('\ufffd\ufffd') is changing each time. Moreover, it can make a segmentation fault, but not each time it fails. I don't even know where this can of error can occur. I have searched for this string in the program and none exists. Can you tell me the cases when search message appears ? Regards, Damien Touraine -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2943 bytes Desc: S/MIME Cryptographic Signature URL: From rosuav at gmail.com Tue Apr 1 10:29:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Apr 2014 01:29:30 +1100 Subject: Strange message from a program In-Reply-To: <533AC9AF.5080604@limsi.fr> References: <533AC9AF.5080604@limsi.fr> Message-ID: On Wed, Apr 2, 2014 at 1:14 AM, Damien Touraine wrote: > I have a big program with several dependencies (mainly PySide). But, > sometimes, it fails with :RuntimeError: Can't find converter for > '\ufffd\ufffd' to call Python meta method. The given string ('\ufffd\ufffd') > is changing each time. Moreover, it can make a segmentation fault, but not > each time it fails. It would be a huge help if you copy and paste the entire traceback: everything that Python emits. Does the given string always have particular characters listed? It looks like you may be having some sort of character encoding issue; \ufffd means U+FFFD, the "Replacement Character" used when something can't be decoded correctly. ChrisA From bgailer at gmail.com Tue Apr 1 10:32:41 2014 From: bgailer at gmail.com (bob gailer) Date: Tue, 01 Apr 2014 10:32:41 -0400 Subject: Python to be replaced by the new language called Cookie ! In-Reply-To: <1a31$533a76d6$5419b3e4$11235@cache80.multikabel.net> References: <1a31$533a76d6$5419b3e4$11235@cache80.multikabel.net> Message-ID: <533ACE09.2070809@gmail.com> On 4/1/2014 4:20 AM, Skybuck Flying wrote: > April Fools =D If you thought spaghetti code was bad, ... in December, 1973 R. Lawrence Clark proposed a new programming construct: COME FROM. See https://www.fortran.com/come_from.html What can we do in this new age of GOTOless programming do to match this incredible achievement? How about an "against" statement. Something like against throw ? This doesn't really capture the same weird behavior of COME FROM, but it is a starter. How about a "without" statement? without ]: Within the Any mention of any identifier in the list raises the specified or default (WithoutError) exception. PEP writers: sharpen your quills! From rosuav at gmail.com Tue Apr 1 11:19:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Apr 2014 02:19:38 +1100 Subject: Python to be replaced by the new language called Cookie ! In-Reply-To: <533ACE09.2070809@gmail.com> References: <1a31$533a76d6$5419b3e4$11235@cache80.multikabel.net> <533ACE09.2070809@gmail.com> Message-ID: On Wed, Apr 2, 2014 at 1:32 AM, bob gailer wrote: > How about a "without" statement? > > without ]: > > > Within the Any mention of any identifier in the list raises the > specified or default (WithoutError) exception. In the interests of anti-patterns, we should adopt converses to all the classic patterns. Instead of Object Orientation, where you instantiate a few classes many times, we have Object Disorientation: every object is in a class of its own, and all objects rank equally. No more hierarchies, we have true equality! Also, we should recommend Dysfunctional Programming. Recursion is bad, and all instances of it should be turned into generators. Behold: # Functional programming style def spam(x): return "." + ham(x) def ham(y): return spam(y-1) if y else "!" def __main__(): print(spam(5)) __main__() # Dysfunctional style def spam(x): yield " " + next(ham(x)) def ham(y): if y: yield from spam(y-1) else: yield "!" def __main__(): print(next(spam(5))) __main__() Generators are inherently more Pythonic than recursion; after all, they have language-level support, while recursion doesn't even get the meager support of a "call self" opcode. Finally, Imperative Programming should be replaced with a much more courteous Request Programming. Instead of stating what you expect the program to do with a series of commands, you implement everything using the 'requests' module and the 'http.server' module. As an added bonus, you can very easily separate components of your program across multiple processes or even multiple computers, without any extra effort! These improvements are absolutely critical to the language, and should be made in Python 2.5.7, 2.6.9, and 3.0.2. Anyone using a newer version of Python is paying the price for early adoption, and should back-level immediately to a supported version. ChrisA From feliphil at gmx.net Tue Apr 1 11:19:27 2014 From: feliphil at gmx.net (Wolfgang Keller) Date: Tue, 1 Apr 2014 17:19:27 +0200 Subject: Examples of modern GUI python programms References: Message-ID: <20140401171927.edf916b2b03dda70d2b2b012@gmx.net> > Id like to ask.. do you know any modern looking GUI examples of > windows software written in python? Something like this maybe: > http://techreport.com/r.x/asus-x79deluxe/software-oc.jpg (or > hopefully something like this android look: > http://chromloop.com/wp-content/uploads/2013/07/Skype-4.0-Android-screenshot.jpg). These are textbook examples of totally anti-ergonomic gadgetcrap for gamekiddies. Judging from the example screenshots on their website, Kivy might be adequate. Sincerely, Wolfgang From ian.g.kelly at gmail.com Tue Apr 1 11:53:41 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 1 Apr 2014 09:53:41 -0600 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <533A96E9.1030107@rece.vub.ac.be> <533AAA13.4010309@rece.vub.ac.be> Message-ID: On Tue, Apr 1, 2014 at 7:44 AM, Chris Angelico wrote: > On Wed, Apr 2, 2014 at 12:33 AM, Ned Batchelder wrote: >> Maybe I'm misunderstanding the discussion... It seems like we're talking >> about a hypothetical definition of identifiers based on Unicode character >> categories, but there's no need: Python 3 has defined precisely that. From >> the docs >> (https://docs.python.org/3/reference/lexical_analysis.html#identifiers): >> > > "Python 3.0 introduces **additional characters** from outside the > ASCII range" - emphasis mine. > > Python currently has - at least, per that documentation - a hybrid > system with ASCII characters defined in the classic way, and non-ASCII > characters defined by their Unicode character classes. I'm talking > about a system that's _purely_ defined by Unicode character classes. > It may turn out that the class list exactly compasses the ASCII > characters listed, though, in which case you'd be right: it's not > hypothetical. The only ASCII character not encompassed is that _ is explicitly permitted to start an identifier (for obvious reasons) whereas characters in Pc are more generally only permitted to continue identifiers. There are also explicit lists of extra permitted characters in PropList.txt for backward compatibility (once a character is permitted, it should remain permitted even if its Unicode category changes). There are currently 4 extra starting characters and 12 extra continuing characters, but none of these are ASCII. From marko at pacujo.net Tue Apr 1 11:59:27 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 01 Apr 2014 18:59:27 +0300 Subject: unicode as valid naming symbols References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <87txadtmwq.fsf@elektro.pacujo.net> <87ob0ltfze.fsf@elektro.pacujo.net> <87eh1htcjg.fsf@elektro.pacujo.net> Message-ID: <874n2dt50g.fsf@elektro.pacujo.net> Chris Angelico : > On Wed, Apr 2, 2014 at 12:16 AM, Marko Rauhamaa wrote: >> I implemented the loops in the scheme way. Recursion is how iteration >> is done by the Believers. > > Then I'm happily a pagan who uses while loops instead of recursion. > Why should every loop become a named function? Every language has its idioms. The principal aesthetic motivation for named-let loops is the avoidance of (set!), I think. Secondarily, you get to shift gears in the middle of your loops; something you can often, but not always, accomplish in Python with break, return and continue. Don't take me wrong. Python has its own idioms and avoiding loops in Python would be equally blasphemous. In C++ you avoid void pointers like the plague, in C you celebrate them. Marko From harrismh777 at gmail.com Tue Apr 1 17:26:22 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 01 Apr 2014 16:26:22 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/31/14 3:46 PM, Rhodri James wrote: >> I was using arpanet since the late 1970s. > > I was using JANet since the early 80s, and I'm by no means the oldest > person here. I should stop playing that card if I were you. My point (which you missed) is not how old I am, rather, for some of us 1991 is NOT ancient history. Also, that some people have a rather unusual "memory" of history that, surprising to those of us who were living then, does not match up. My experience in the mid-to-late 1970s was on an IBM 360 mod44 mainframe (high-speed number cruncher)(at the time only 11 of them existed in the world). We were connected on the net (at a time when most people didn't know there was a net). Its not a 'card' its just a fact. We used our machine to analyze electrocardiograms. (it was the first in the world to do that, Upsher Laboratories, K.C. MO USA). Its not a snotty holier than thou thing, its just an experience and accomplishment thing (if you don't value the testimony, well, plonk). >>>> I didn't really start using unicode >>>> until about 5 years ago; python has only really used it since python3. >>>> right? >>> No. Python 2.2 introduced Unicode. >> I didn't ask when it was introduced, I asked when it became useful? > No you didn't. Yes, I did. Our common English is apparently getting in the way. Well, I speak American English, and you don't, apparently; U.K.? Python3 finally started getting unicode right. The fact that it 'existed' in some form prior to (3) is not meaningful, nor helpful. When I said, "python has only really used it since python3, right?," I meant that unicode in python2 was a mess (and incomplete, and I could go on) but finally---in python3---it is becoming useful (even though it still has glitches). I don't know why we need to argue about it. I do regret that you misinterpreted my meaning. That is always frustrating, for me. > *plonk* You choice. I never *plonk* anyone. Even the dull and ignorant have their story. YMMV--- plonk away, God save the Queen. From tade.ankur at gmail.com Tue Apr 1 17:36:11 2014 From: tade.ankur at gmail.com (tade.ankur at gmail.com) Date: Tue, 1 Apr 2014 14:36:11 -0700 (PDT) Subject: SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC In-Reply-To: <94cfb444-8c5d-4b2c-b08c-29170991d02b@googlegroups.com> References: <94cfb444-8c5d-4b2c-b08c-29170991d02b@googlegroups.com> Message-ID: <9e61da23-3510-4289-aba9-3ec2f9167253@googlegroups.com> On Thursday, March 27, 2014 5:40:52 PM UTC+1, tade.... at gmail.com wrote: > hei , > > > > I am a newcome to Python. > > > > I am trying to create a python script which will connect to an SSL URL and using the HEAD request will get the status of URL. > > > > For one the link I am getting following error > > > > [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:589) > > > > I am using python on windows. > > > > Following is the code snippet > > > > def checkURLStatusSecure(testhostname,urlsinatest): > > global conn, url, res > > > > for url in urlsinatest: > > conn = HTTPSConnection(testhostname,'443') > > conn.request('HEAD', url) > > res = conn.getresponse() > > print('|***https://' + testhostname + url + '| %s | %s |' % (res.status, res.reason)) > > res.close() > > conn.close() > > > > Any idea why I am gtting the above mentioned error. > > > > Any help will be appreciable > > > > Python version in 3.4 Hei Dave, Thanks for taking your time and replying. I am getting only the mentioned on the command prompt. Is it possible set some traces and get more information about the errors. Regards Ankur From rosuav at gmail.com Tue Apr 1 17:49:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Apr 2014 08:49:21 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 2, 2014 at 8:26 AM, Mark H Harris wrote: > Python3 finally started getting unicode right. The fact that it 'existed' > in some form prior to (3) is not meaningful, nor helpful. > When I said, "python has only really used it since python3, right?," I meant > that unicode in python2 was a mess (and incomplete, and I could go on) but > finally---in python3---it is becoming useful (even though it still has > glitches). I don't know why we need to argue about it. Please elaborate. Apart from the default double-quoted string being a byte string (which can be changed with a future directive), and the consequent likelihood that library functions will expect str rather than unicode, what was such an incomplete mess in Py2 that made Unicode completely useless? Personally, I'd still rather work with Unicode in Py2 than in C, REXX, or any other completely Unicode-naive language. ChrisA From harrismh777 at gmail.com Tue Apr 1 19:18:32 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 01 Apr 2014 18:18:32 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/1/14 4:49 PM, Chris Angelico wrote: > On Wed, Apr 2, 2014 at 8:26 AM, Mark H Harris wrote: >> Python3 finally started getting unicode right. The fact that it 'existed' >> in some form prior to (3) is not meaningful, nor helpful. >> When I said, "python has only really used it since python3, right?," I meant >> that unicode in python2 was a mess (and incomplete, and I could go on) but >> finally---in python3---it is becoming useful (even though it still has >> glitches). I don't know why we need to argue about it. > > Please elaborate. Apart from the default double-quoted string being a > byte string (which can be changed with a future directive), and the > consequent likelihood that library functions will expect str rather > than unicode, what was such an incomplete mess in Py2 that made > Unicode completely useless? Personally, I'd still rather work with > Unicode in Py2 than in C, REXX, or any other completely Unicode-naive > language. > > ChrisA > hi Chris, oh good, another chance to be entirely misinterpreted; thanks. :) I think I will defer to another person in an attempt to keep the emotions, rhetoric, and politics out of the answer. This link is not inclusive, but its a good reminder ( for those new to the topic ) of what was *wrong* with python2 unicode (still is wrong with python2 unicode) although it focuses on the positives of what is new in python3: > http://python-notes.curiousefficiency.org/en/latest/python3/text_file_processing.html Um, 'mess' might be too harsh a word. But in my view text processing in python is a bit of a mess in python2 (particularly concerning unicode). In my opinion python3 has made some fairly dramatic improvements, that help to make text file processing (something I do a lot of) more consistent and easier to manage (relatively new to unicode as I am). Something that should be noted is that unicode is only as good as commitment 'does'. ASCII is still used. Sometimes (often) unicode is being used 'as though' ASCII were still there ruling. Unicode usage requires commitment to use and implementation. My hat is off to the python core development team for stepping up to the plate with their changes to python3 text processing issues. That's all I really want to say about it. Read the link, but don't argue with me; its not that important and too many folks get upset by it. marcus From jsf80238 at gmail.com Tue Apr 1 21:25:50 2014 From: jsf80238 at gmail.com (Jason Friedman) Date: Tue, 1 Apr 2014 19:25:50 -0600 Subject: writing reading from a csv or txt file In-Reply-To: References: <9023eae9-f814-40ac-9b84-043214e6b28f@googlegroups.com> Message-ID: > > Hi jason thanks for replying.Below is a typical file return.To you I've no > doubt this is a simple problem but,to a beginner like me it just seems I > lack the understanding of how to split out the items in a list.Thanks again > for looking at it. > Rainfall,duration,TimeStart,windspeed,Date > 0.1,5,05:25,3.1,03/02/2013 > 0.12,8,11:20,4.1,03/02/2013 > 0.1,2,18:05,2.8,03/02/2013 > 18,15,04:03,4.5,04/02/2013 > 2.3,6,17:02,2.4,04/02/2013 > *********************************************** > Rainfall,duration,TimeStart,windspeed,Date > 1.1,5,05:25,3.1,014/02/2012 > 1.32,8,14:20,4.1,14/02/2012 > 2.1,2,22:00,2.8,14/02/2012 > 18,15,03:30,4.5,18/02/2012 > 1.3,4,13:00,2.4,18/02/2012 > > > I am trying to compare the files. cutting out items in list list. ie:- >>> first file (rainfall2012.csv)rainfall, duration,time of day,wind >>> speed,date. >>> first file (rainfall2013.csv)rainfall, duration,time of day,wind >>> speed,date. >>> I would like to pick out maybe rainfalls and duration's and measure >>> against say years. >>> >>> >> Ok, now show us the first few lines of the output you are wanting (please remember to add you answer at the bottom, not the top). Please also remember to reply-all. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rymg19 at gmail.com Tue Apr 1 21:54:44 2014 From: rymg19 at gmail.com (Ryan Gonzalez) Date: Tue, 1 Apr 2014 20:54:44 -0500 Subject: Ideas for Python 4 Message-ID: I have a bunch of ideas I'd like to share for Python 4: Use -- for comments instead of #. Switch to <> for "not equal" instead of !=. Remove indentation requirement: -- Python 2&3 if x != y: return 7 -- Python 4 if x <> y: return 7 ;; Add multiline lambdas: my_multiline_lambda = ll { return 7; } Add implicit lambdas using a clear, simple, and concise syntax: my_implicit_lambda = ??[0] + ??[1] if ??#? != 0 -- ?? = argument dictionary -- ??#? = argument count Add method chaining using even easier syntax: a = SomeObject() b = a->>>m2->>>m3->>>m4!!;; -- Call m2, then m3, then m4, then return the resulting object -- BTW, April Fools! This is ugly... -- Ryan If anybody ever asks me why I prefer C++ to C, my answer will be simple: "It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was nul-terminated." -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Apr 1 21:58:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Apr 2014 12:58:50 +1100 Subject: Ideas for Python 4 In-Reply-To: References: Message-ID: On Wed, Apr 2, 2014 at 12:54 PM, Ryan Gonzalez wrote: > I have a bunch of ideas I'd like to share for Python 4: > > Switch to <> for "not equal" instead of !=. PEP 0401 beat you to it five years ago. > Add multiline lambdas: > > my_multiline_lambda = ll { return 7; } Yeah, you an' everyone else. > Add method chaining using even easier syntax: > > a = SomeObject() > b = a->>>m2->>>m3->>>m4!!;; > > -- Call m2, then m3, then m4, then return the resulting object Huh, did you see my recent proposal on that? I was quite serious. > -- BTW, April Fools! This is ugly... You're about a day late, sorry :) ChrisA From rymg19 at gmail.com Tue Apr 1 22:15:24 2014 From: rymg19 at gmail.com (rymg19 at gmail.com) Date: Tue, 1 Apr 2014 19:15:24 -0700 (PDT) Subject: Ideas for Python 4 In-Reply-To: References: Message-ID: On Tuesday, April 1, 2014 8:58:50 PM UTC-5, Chris Angelico wrote: > On Wed, Apr 2, 2014 at 12:54 PM, Ryan Gonzalez wrote: > > > I have a bunch of ideas I'd like to share for Python 4: > > > > > > Switch to <> for "not equal" instead of !=. > > > > PEP 0401 beat you to it five years ago. > That's what inspired this. > > > Add multiline lambdas: > > > > > > my_multiline_lambda = ll { return 7; } > > > > Yeah, you an' everyone else. > > > > > Add method chaining using even easier syntax: > > > > > > a = SomeObject() > > > b = a->>>m2->>>m3->>>m4!!;; > > > > > > -- Call m2, then m3, then m4, then return the resulting object > > > > Huh, did you see my recent proposal on that? I was quite serious. > I did. You were in my mind when I was writing this. ;) > > > -- BTW, April Fools! This is ugly... > > > > You're about a day late, sorry :) > In Florida, it's still April Fools. > > ChrisA From th982a at googlemail.com Tue Apr 1 22:24:07 2014 From: th982a at googlemail.com (Tamer Higazi) Date: Wed, 02 Apr 2014 04:24:07 +0200 Subject: Python IM server In-Reply-To: References: Message-ID: <533B74C7.1020305@googlemail.com> Take Twisted! twistedmatrix.... has all you need! Am 31.03.2014 13:03, schrieb Wesley: > Hi all, > I want to develop a instant message server, simply has user and group entity. > > Is there any better existing open-source one? > Thus I can download and have a look. > > Thanks. > Wesley > From rosuav at gmail.com Tue Apr 1 22:25:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Apr 2014 13:25:37 +1100 Subject: Ideas for Python 4 In-Reply-To: References: Message-ID: On Wed, Apr 2, 2014 at 1:15 PM, wrote: > In Florida, it's still April Fools. > In Florida, it's *always* April Fools. ChrisA From rustompmody at gmail.com Tue Apr 1 22:58:02 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 1 Apr 2014 19:58:02 -0700 (PDT) Subject: unicode as valid naming symbols In-Reply-To: <874n2dt50g.fsf@elektro.pacujo.net> References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <87txadtmwq.fsf@elektro.pacujo.net> <87ob0ltfze.fsf@elektro.pacujo.net> <87eh1htcjg.fsf@elektro.pacujo.net> <874n2dt50g.fsf@elektro.pacujo.net> Message-ID: On Tuesday, April 1, 2014 9:29:27 PM UTC+5:30, Marko Rauhamaa wrote: > Chris Angelico : > > On Wed, Apr 2, 2014 at 12:16 AM, Marko Rauhamaa wrote: > >> I implemented the loops in the scheme way. Recursion is how iteration > >> is done by the Believers. > > Then I'm happily a pagan who uses while loops instead of recursion. > > Why should every loop become a named function? > Every language has its idioms. The principal aesthetic motivation for > named-let loops is the avoidance of (set!), I think. Secondarily, you > get to shift gears in the middle of your loops; something you can often, > but not always, accomplish in Python with break, return and continue. You are forgetting the main point: In scheme, in a named-let, the name chosen was very often 'loop' (if I remember the PC scheme manuals correctly). IOW if you had a dozen loops implemented with named-letted-tail-recursion, you could call all of them 'loop'. How is that different from calling all of them 'while' or 'for' ? > Don't take me wrong. Python has its own idioms and avoiding loops in > Python would be equally blasphemous. In C++ you avoid void pointers like > the plague, in C you celebrate them. Yeah... I guess that is the issue. People brought up on imperative (which includes OO) programming, think recursion and iteration are fundamentally different, just as assembly language programmers think of memory and register as fundamentally different. Sure is but if you are a C programmer the distinction is irrelevant 99% of the time! Continues downward... For an assembly language programmer, memory and cache-memory is not a distinction he needs to make 99% of the time. Not so for the hardware engineer From rustompmody at gmail.com Tue Apr 1 23:16:27 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 1 Apr 2014 20:16:27 -0700 (PDT) Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <87txadtmwq.fsf@elektro.pacujo.net> <87ob0ltfze.fsf@elektro.pacujo.net> <87eh1htcjg.fsf@elektro.pacujo.net> <874n2dt50g.fsf@elektro.pacujo.net> Message-ID: On Wednesday, April 2, 2014 8:28:02 AM UTC+5:30, Rustom Mody wrote: > On Tuesday, April 1, 2014 9:29:27 PM UTC+5:30, Marko Rauhamaa wrote: > > Chris Angelico : > > > On Wed, Apr 2, 2014 at 12:16 AM, Marko Rauhamaa wrote: > > >> I implemented the loops in the scheme way. Recursion is how iteration > > >> is done by the Believers. > > > Then I'm happily a pagan who uses while loops instead of recursion. > > > Why should every loop become a named function? > > Every language has its idioms. The principal aesthetic motivation for > > named-let loops is the avoidance of (set!), I think. Secondarily, you > > get to shift gears in the middle of your loops; something you can often, > > but not always, accomplish in Python with break, return and continue. > You are forgetting the main point: In scheme, in a named-let, the name > chosen was very often 'loop' (if I remember the PC scheme manuals > correctly). IOW if you had a dozen loops implemented with > named-letted-tail-recursion, you could call all of them 'loop'. How > is that different from calling all of them 'while' or 'for' ? Umm... I see from your prime number example that there are nested loops in which sometimes you restart the inner and sometimes the outer. So you could not possibly call both of them 'loop' :-). So "you could call all of them 'loop'" is over-statement. "Good many" may be more appropriate? From dan at tombstonezero.net Wed Apr 2 00:15:36 2014 From: dan at tombstonezero.net (Dan Sommers) Date: Wed, 2 Apr 2014 04:15:36 +0000 (UTC) Subject: Python to be replaced by the new language called Cookie ! References: <1a31$533a76d6$5419b3e4$11235@cache80.multikabel.net> <533ACE09.2070809@gmail.com> Message-ID: On Wed, 02 Apr 2014 02:19:38 +1100, Chris Angelico wrote: > These improvements are absolutely critical to the language, and should > be made in Python 2.5.7, 2.6.9, and 3.0.2. Anyone using a newer > version of Python is paying the price for early adoption, and should > back-level immediately to a supported version. I'm using 2.8. Should I upgrade? *ducking* From Joshua.R.English at gmail.com Wed Apr 2 01:03:33 2014 From: Joshua.R.English at gmail.com (Josh English) Date: Tue, 1 Apr 2014 22:03:33 -0700 (PDT) Subject: Switching between cmd.CMD instances Message-ID: I have a program with several cmd.Cmd instances. I am trying to figure out what the best way to organize them should be. I've got my BossCmd, SubmissionCmd, and StoryCmd objects. The BossCmd object can start either of the other two, and this module allows the user switch back and forth between them. Exiting either of the sub-command objects returns back to the BossCmd. I have defined both a do_done and do_exit method on the sub-commands. Is it possible to flag BossCmd so when either of the other two process do_exit, the BossCmd will also exit? Josh From rosuav at gmail.com Wed Apr 2 01:42:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Apr 2014 16:42:24 +1100 Subject: Python to be replaced by the new language called Cookie ! In-Reply-To: References: <1a31$533a76d6$5419b3e4$11235@cache80.multikabel.net> <533ACE09.2070809@gmail.com> Message-ID: On Wed, Apr 2, 2014 at 3:15 PM, Dan Sommers wrote: > On Wed, 02 Apr 2014 02:19:38 +1100, Chris Angelico wrote: > >> These improvements are absolutely critical to the language, and should >> be made in Python 2.5.7, 2.6.9, and 3.0.2. Anyone using a newer >> version of Python is paying the price for early adoption, and should >> back-level immediately to a supported version. > > I'm using 2.8. Should I upgrade? Definitely. Python 2.8 is supported only on Windows XP 64-bit, and you should upgrade to 32-bit Python; this will give you a 50% saving on all pointers, and Python uses a lot of pointers, so your code will be more efficient. ChrisA From marko at pacujo.net Wed Apr 2 01:55:53 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 02 Apr 2014 08:55:53 +0300 Subject: unicode as valid naming symbols References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> <533A768F.5080102@rece.vub.ac.be> <87txadtmwq.fsf@elektro.pacujo.net> <87ob0ltfze.fsf@elektro.pacujo.net> <87eh1htcjg.fsf@elektro.pacujo.net> <874n2dt50g.fsf@elektro.pacujo.net> Message-ID: <87d2h09swm.fsf@elektro.pacujo.net> Rustom Mody : > On Wednesday, April 2, 2014 8:28:02 AM UTC+5:30, Rustom Mody wrote: >> In scheme, in a named-let, the name >> chosen was very often 'loop' > > Umm... I see from your prime number example that there are nested > loops in which sometimes you restart the inner and sometimes the > outer. So you could not possibly call both of them 'loop' :-). Correct. I could call them "inner" and "outer". After all, the code uses variables like "i", "c" and "n". However, it doesn't hurt to use variable/function/loop names that convey meaning. Marko From wuwei23 at gmail.com Wed Apr 2 03:17:55 2014 From: wuwei23 at gmail.com (alex23) Date: Wed, 02 Apr 2014 17:17:55 +1000 Subject: Python to be replaced by the new language called Cookie ! In-Reply-To: References: <1a31$533a76d6$5419b3e4$11235@cache80.multikabel.net> <533ACE09.2070809@gmail.com> Message-ID: On 2/04/2014 3:42 PM, Chris Angelico wrote: > Python 2.8 is supported only on Windows XP 64-bit, and you > should upgrade to 32-bit Python That would be Python 1.4 From mtabesh at gmail.com Wed Apr 2 03:33:03 2014 From: mtabesh at gmail.com (mtabesh at gmail.com) Date: Wed, 2 Apr 2014 00:33:03 -0700 (PDT) Subject: Installing binwalk on Portable Python In-Reply-To: References: Message-ID: <4b37e2fb-28af-4ead-831b-caf2d99e6e3f@googlegroups.com> On Tuesday, March 18, 2014 2:22:57 AM UTC+4:30, lagu... at mail.com wrote: > Yes, that? help. > Installation start, but then failed due to "Pre-requisite failure: failed to find libmagic. Check your installation. Please install the python-magic module, or download and install it from source: ftp://ftp.astron.com/pub/file/' " > Although libmagic was installed using pip. > > ? > ? > ----- Original Message ----- > From: Peter Mawhorter > Sent: 03/17/14 11:07 PM > To: laguna-mc > Subject: Re: Installing binwalk on Portable Python? > > On Mon, Mar 17, 2014 at 1:58 PM, wrote: > > I tried: pip install "E:\Portable Python > > 2.7.5.1\binwalk-1.3.0\src\setup.py" > > > > Error: > > > > E:\Portable Python 2.7.5.1\App\Scripts\pip run on 03/17/14 22:53:51 > > > > Exception: > > Traceback (most recent call last): > > File "E:\Portable Python > > 2.7.5.1\App\lib\site-packages\pip\basecommand.py", line 122, in main > > status = self.run(options, args) > > File "E:\Portable Python > > 2.7.5.1\App\lib\site-packages\pip\commands\install.py", line 257, in run > > InstallRequirement.from_line(name, None)) > > File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", line > > 172, in from_line > > return cls(req, comes_from, url=url, prereleases=prereleases) > > File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", line > > 70, in __init__ > > req = pkg_resources.Requirement.parse(req) > > File "E:\Portable Python > > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2606, in > > parse > > reqs = list(parse_requirements(s)) > > File "E:\Portable Python > > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2544, in > > parse_requirements > > line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version spec") > > File "E:\Portable Python > > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2512, in > > scan_list > > raise ValueError("Expected "+item_name+" in",line,"at",line[p:]) > > ValueError: ('Expected version spec in', 'E:\\Portable Python > > 2.7.5.1\\binwalk-1.3.0\\src\\setup.py', 'at', ':\\Portable Python > > 2.7.5.1\\binwalk-1.3.0\\src\\setup.py') > > > > > > -------------- > > I'm no expert, but when I try to run pip install ... it seems to want > a directory that contains a setup.py file rather than the path of the > setup.py file itself. Try: > > pip install "E:\Portable Python 2.7.5.1\binwalk-1.3.0\src" > > perhaps? > > -Peter Mawhorter > ? > ? > ? http://phoenixinteractive.mine.nu/websitebb/viewtopic.php?f=35&t=99 From nispray at gmail.com Wed Apr 2 08:16:40 2014 From: nispray at gmail.com (Wesley) Date: Wed, 2 Apr 2014 05:16:40 -0700 (PDT) Subject: Telepathy is server or client? Message-ID: <8a82ca42-79e3-494c-b161-389c65641809@googlegroups.com> Hi, These days I see Telepathy on the net. Not so much examples for this guy. Is it used to write client or server? I mean, for example, I wanna develop a voice chatting system, so, can use this guy to develop a client or server? Thanks. Wesley From wrw at mac.com Wed Apr 2 08:05:21 2014 From: wrw at mac.com (William Ray Wing) Date: Wed, 02 Apr 2014 08:05:21 -0400 Subject: Switching between cmd.CMD instances In-Reply-To: References: Message-ID: <1E2D7154-B3E7-4B24-A932-C2B5E98C3E67@mac.com> On Apr 2, 2014, at 1:03 AM, Josh English wrote: > I have a program with several cmd.Cmd instances. I am trying to figure out what the best way to organize them should be. > > I've got my BossCmd, SubmissionCmd, and StoryCmd objects. > > The BossCmd object can start either of the other two, and this module allows the user switch back and forth between them. Exiting either of the sub-command objects returns back to the BossCmd. > > I have defined both a do_done and do_exit method on the sub-commands. > > Is it possible to flag BossCmd so when either of the other two process do_exit, the BossCmd will also exit? > > Josh > I am anything BUT a super experienced Python programmer, but if it were my problem - and if BossCmd has anything like an event loop in it, then certainly one way to handle this would be to have a Status.py module that contained status flags for each of the modules. All three modules would "import status? and do_done and do_exit would set status flags in status.py on their way out. I?m sure there are better answers. I?ll be interested to see what else is suggested. -Bill From schapman1974 at gmail.com Wed Apr 2 09:39:01 2014 From: schapman1974 at gmail.com (schapman1974 at gmail.com) Date: Wed, 2 Apr 2014 06:39:01 -0700 (PDT) Subject: COM Server data from python Message-ID: <1bee53e3-7778-463f-a6db-c40cb23f5638@googlegroups.com> I am attempting to provide a bit of data through a com server I did a comparison of speed of my COM interface to ADODB and It seems massively slower. I'm not sure if there is something I need to adjust or maybe that I am making so many calls to the COM server that each call takes time and possibly ADO is just buffering some data in chunks to my code. This is mainly for an excel add-on that has not possibility to connect to mongodb except through an interface like this. I thought it was not really a big deal until I tested larger amounts of data and the speed took a nose dive. For instance 10,000 records just to walk through and pull a couple fields. ADO on the exact same data took only 1.5 seconds where my python code took close to 58 seconds to do the same thing. I've played around with design etc. When i test the same code directly from python I get the same result if not better than I did with ADO. Is there some bit of COM magic that I am missing. Or is this because python is having to do more behind the scenes? Thanks From invalid at invalid.invalid Wed Apr 2 10:20:30 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 2 Apr 2014 14:20:30 +0000 (UTC) Subject: Python to be replaced by the new language called Cookie ! References: <1a31$533a76d6$5419b3e4$11235@cache80.multikabel.net> <533ACE09.2070809@gmail.com> Message-ID: On 2014-04-02, Chris Angelico wrote: > On Wed, Apr 2, 2014 at 3:15 PM, Dan Sommers wrote: >> On Wed, 02 Apr 2014 02:19:38 +1100, Chris Angelico wrote: >> >>> These improvements are absolutely critical to the language, and should >>> be made in Python 2.5.7, 2.6.9, and 3.0.2. Anyone using a newer >>> version of Python is paying the price for early adoption, and should >>> back-level immediately to a supported version. >> >> I'm using 2.8. Should I upgrade? > > Definitely. Python 2.8 is supported only on Windows XP 64-bit, and you > should upgrade to 32-bit Python; this will give you a 50% saving on > all pointers, and Python uses a lot of pointers, so your code will be > more efficient. And you'll save a _ton_ of money on ink. -- Grant Edwards grant.b.edwards Yow! Is my fallout shelter at termite proof? gmail.com From 3kywjyds5d at snkmail.com Wed Apr 2 10:53:19 2014 From: 3kywjyds5d at snkmail.com (Lucas Malor) Date: Wed, 2 Apr 2014 14:53:19 +0000 Subject: Yet Another Switch-Case Syntax Proposal Message-ID: <12008-1396450399-453900@sneakemail.com> Hi all. I would proposeto you all a switch-case syntax for Python. I already read PEP 3103 and I'm not completely satisfied by any of the proposed solutions. This is my proposal: switch_stmt ::= "switch" identifier "case" expression_list ":" suite ("case" expression_list ":" suite)* ["else" ":" suite] or, more simply: switch x case var1: .... case var2: ... case var3: ... else: ... Expression list should yield an iterable. The case suite will be executed if the variable of the identifier is a member of the iterable. For example, in a "switch x" statement, the code "case iterable: " is identical to "if x in iterable: " (or elif etc). So if you want to perform the same case block for more than one value, you have only to specify a tuple, a range etc. I would suggest to add an exception for non-iterable variables, so that you don't have to write "case var, : " but simply "case var: " and it will be identical to "if x == var: ". It's a bit tricky but the alternative is ugly. Fallthrough is disabled by default. The continue keyword cause to skip all the remaining current case suite. The next case will be checked. You can't use the continue keyword in the else clause. Some random remarks: 1. switch is on the same line of the first case. This will avoid any unpythonic syntaxes like: switch x case var1: ... or switch x: case var1: ... 2. Fallthrough is disabled by default because IMHO it's what non-programmers expect and that's what programmer usually needs more. I don't think a switch with such a syntax needs a break statement. 3. As an alternative, the continue statement could be written only at the end of a case suite; it will be less powerful and not consistent with the other compound statements, but it will improve readability. 4. I decided to not use already existing keyword like "if" or "in", since it will be misleading and problematic for syntax highlighters. Tell me what you think about. From contacthareesha at gmail.com Wed Apr 2 09:22:04 2014 From: contacthareesha at gmail.com (Hareesha Karunakar) Date: Wed, 2 Apr 2014 18:52:04 +0530 Subject: python nose unit test - test plan preparation Message-ID: Hello Group, I am using python's nose testing frame work for my automated testing. I would like to run my python cases and generate only the documentation without actually running/executing the cases. How is this possible? I head "collect-only" plugin will help to achieve the same. But I think I could not make out how to use this effectively? Are there any other possibilities? I mainly want to collect the "comments" form the test classes and test methods. Thanks, Harish. -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Wed Apr 2 13:58:16 2014 From: roy at panix.com (Roy Smith) Date: Wed, 2 Apr 2014 13:58:16 -0400 Subject: Retrieve item deep in dict tree? Message-ID: <8E3FFB83-FDCA-4214-A8C6-8681200830DA@panix.com> I have a big hairy data structure which is a tree of nested dicts. I have a sequence of strings which represents a path through the tree. Different leaves in the tree will be at different depths (which range from 1 to about 4 or 5 at most). I want to get the value stored at that path. Thus, if keys = ['foo', 'bar', 'baz'] I want to retrieve tree['foo']['bar']['baz']. Is there some idiomatic, non-cryptic way to write that as a one-liner? I'm using Python 2.7. --- Roy Smith roy at panix.com From gordon at panix.com Wed Apr 2 14:03:07 2014 From: gordon at panix.com (John Gordon) Date: Wed, 2 Apr 2014 18:03:07 +0000 (UTC) Subject: Retrieve item deep in dict tree? References: Message-ID: In Roy Smith writes: > I have a big hairy data structure which is a tree of nested dicts. I = > have a sequence of strings which represents a path through the tree. = > Different leaves in the tree will be at different depths (which range = > from 1 to about 4 or 5 at most). I want to get the value stored at that = > path. Thus, if > keys =3D ['foo', 'bar', 'baz'] > I want to retrieve tree['foo']['bar']['baz']. > Is there some idiomatic, non-cryptic way to write that as a one-liner? > I'm using Python 2.7. How about three lines? subtree = tree for key in keys: subtree = subtree.get(key) -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From ian.g.kelly at gmail.com Wed Apr 2 14:12:09 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 2 Apr 2014 12:12:09 -0600 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: <12008-1396450399-453900@sneakemail.com> References: <12008-1396450399-453900@sneakemail.com> Message-ID: On Wed, Apr 2, 2014 at 8:53 AM, Lucas Malor <3kywjyds5d at snkmail.com> wrote: > Hi all. I would proposeto you all a switch-case syntax for Python. I already read PEP 3103 and I'm not completely satisfied by any of the proposed solutions. This is my proposal: A more suitable place to propose this would be the python-ideas mailing list. > switch_stmt ::= "switch" identifier "case" expression_list ":" suite > ("case" expression_list ":" suite)* > ["else" ":" suite] Why just just an identifier after the switch keyword instead of an expression? There are many cases where a user might wish to do something along the lines of "switch values[0] case 42:" > Expression list should yield an iterable. The case suite will be executed if the variable of the identifier is a member of the iterable. An expression_list is one or more independent expressions separated by commas that don't create a tuple. If you just want an iterable, then it should just be one expression. But I'm not sure I like that. Additionally, what if the value that you want to match is itself a tuple? If I write "switch 1, 2, 3 case 1, 2, 3:" will it match against the entire tuple or will it try to match against the individual ints and fail? I prefer the "case in" syntax of Alternative B of PEP 3103 here; it reads naturally and makes explicit in the syntax whether you're matching against an individual object or a grouping of objects. > For example, in a "switch x" statement, the code "case iterable: " is identical to "if x in iterable: " (or elif etc). So if you want to perform the same case block for more than one value, you have only to specify a tuple, a range etc. __contains__ is not part of the interface for iterables; it is defined for containers only. So if the matching expression evaluates to a container that could be the code equivalent, but for arbitrary iterables the equivalent code would have to be: for item in iterable: if value == item: # suite break else: # move on to the next case Which is unlikely to be any more efficient than a simple elif chain. > Fallthrough is disabled by default. The continue keyword cause to skip all the remaining current case suite. The next case will be checked. You can't use the continue keyword in the else clause. If we overload the continue keyword in this way, then a continue can't be used within the switch to control a loop that the switch is nested within. Instead of disabling fallthrough by default, why not disable it all together? The container/iterable matching means that we can already match multiple values to the same suite, so the only use remaining for fallthrough would be the kind that creates code smell. > Some random remarks: > 1. switch is on the same line of the first case. This will avoid any unpythonic syntaxes like: I like this better than any of the alternatives in the PEP. > 4. I decided to not use already existing keyword like "if" or "in", since it will be misleading and problematic for syntax highlighters. Syntax highlighters could easily distinguish between something like "case in" and existing uses of "in". The former starts with the keyword "case", and the others do not. From ethan at stoneleaf.us Wed Apr 2 14:15:13 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 02 Apr 2014 11:15:13 -0700 Subject: Retrieve item deep in dict tree? In-Reply-To: <8E3FFB83-FDCA-4214-A8C6-8681200830DA@panix.com> References: <8E3FFB83-FDCA-4214-A8C6-8681200830DA@panix.com> Message-ID: <533C53B1.2030408@stoneleaf.us> On 04/02/2014 10:58 AM, Roy Smith wrote: > > I have a big hairy data structure which is a tree of nested dicts. I have > a sequence of strings which represents a path through the tree. Different > leaves in the tree will be at different depths (which range from 1 to about > 4 or 5 at most). I want to get the value stored at that path. Thus, if > > keys = ['foo', 'bar', 'baz'] > > I want to retrieve tree['foo']['bar']['baz']. > > Is there some idiomatic, non-cryptic way to write that as a one-liner? > > I'm using Python 2.7. Can you make the top-level tree a custom dict that understands tuple keys should be drilled down? -- ~Ethan~ From accessnewbie at gmail.com Wed Apr 2 15:00:07 2014 From: accessnewbie at gmail.com (accessnewbie at gmail.com) Date: Wed, 2 Apr 2014 12:00:07 -0700 (PDT) Subject: Calling macro from python script bombs out when custom table style is used Message-ID: <60a82251-1ff9-454d-9179-49ce6afd8cff@googlegroups.com> I have a python script (2.7.5) that calls a macro from an excel template. Both scripts ran fine until i tried to apply a custom table style within excel. I suspect this has something to do with the win32.com client application not recognizing custom table styles. Does anyone have a work around suggestion? My python script: import os.path import win32com.client mySourceExcelFile = "C:\\tests\\Source\\Cats.xlsm" projectArea = ("C:\\tests\\Target\\results\\") projectName = ("Cats") print projectName print repr(projectArea) xlApp = win32com.client.DispatchEx('Excel.Application') xlsPath = os.path.expanduser(mySourceExcelFile) wb = xlApp.Workbooks.Open(Filename=xlsPath) wb.Application.DisplayAlerts = False xlApp.Run("FormatFile", projectArea, projectName) xlApp.Quit() My 2007 excel macro Sub FormatFile(strResultsDir As String, targetFileName As String) ' ' Application.DisplayAlerts = False Workbooks.Open fileName:=strResultsDir & targetFileName & ".dbf" ActiveSheet.ListObjects.Add(xlSrcRange, Range("A1", ActiveCell.SpecialCells(xlLastCell)), , xlYes).Name = _ "Table1" Range("Table1[#All]").Select ' ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleLight1" ActiveSheet.ListObjects("Table1").TableStyle = "MyStyle" ActiveWorkbook.SaveAs fileName:=strResultsDir & targetFileName & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False ActiveWorkbook.Close Application.Quit End Sub Macro bombs out when it gets to my custom table style ActiveSheet.ListObjects("Table1").TableStyle = "MyStyle" Works fine when table style is one that comes with excel: TableStyleLight1 From steve at pearwood.info Wed Apr 2 16:18:45 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 02 Apr 2014 20:18:45 GMT Subject: Retrieve item deep in dict tree? References: Message-ID: <533c70a5$0$2909$c3e8da3$76491128@news.astraweb.com> On Wed, 02 Apr 2014 13:58:16 -0400, Roy Smith wrote: > I have a big hairy data structure which is a tree of nested dicts. I > have a sequence of strings which represents a path through the tree. > Different leaves in the tree will be at different depths (which range > from 1 to about 4 or 5 at most). I want to get the value stored at that > path. Thus, if > > keys = ['foo', 'bar', 'baz'] > > I want to retrieve tree['foo']['bar']['baz']. > > Is there some idiomatic, non-cryptic way to write that as a one-liner? Er, idiomatic one liner? No, not really. But a helper function makes nearly anything into a one-liner: def traverse(tree, *keys): t = tree for k in keys: t = t[k] return t # one-liner leaf = traverse(tree, *list_of_keys) -- Steven From ethan at stoneleaf.us Wed Apr 2 16:25:24 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 02 Apr 2014 13:25:24 -0700 Subject: Retrieve item deep in dict tree? In-Reply-To: <533c70a5$0$2909$c3e8da3$76491128@news.astraweb.com> References: <533c70a5$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: <533C7234.600@stoneleaf.us> On 04/02/2014 01:18 PM, Steven D'Aprano wrote: > On Wed, 02 Apr 2014 13:58:16 -0400, Roy Smith wrote: > >> I have a big hairy data structure which is a tree of nested dicts. I >> have a sequence of strings which represents a path through the tree. >> Different leaves in the tree will be at different depths (which range >> from 1 to about 4 or 5 at most). I want to get the value stored at that >> path. Thus, if >> >> keys = ['foo', 'bar', 'baz'] >> >> I want to retrieve tree['foo']['bar']['baz']. >> >> Is there some idiomatic, non-cryptic way to write that as a one-liner? > > Er, idiomatic one liner? No, not really. But a helper function makes > nearly anything into a one-liner: > > def traverse(tree, *keys): > t = tree > for k in keys: > t = t[k] > return t > > # one-liner > leaf = traverse(tree, *list_of_keys) +1 Short, simple -- good Python. :) -- ~Ethan~ From rosuav at gmail.com Wed Apr 2 17:50:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 Apr 2014 08:50:47 +1100 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: <12008-1396450399-453900@sneakemail.com> References: <12008-1396450399-453900@sneakemail.com> Message-ID: On Thu, Apr 3, 2014 at 1:53 AM, Lucas Malor <3kywjyds5d at snkmail.com> wrote: > For example, in a "switch x" statement, the code "case iterable: " is identical to "if x in iterable: " (or elif etc). So if you want to perform the same case block for more than one value, you have only to specify a tuple, a range etc. > I would suggest to add an exception for non-iterable variables, so that you don't have to write "case var, : " but simply "case var: " and it will be identical to "if x == var: ". It's a bit tricky but the alternative is ugly. > This is sounding like a nasty special case. I'm ambivalent on the overall proposal (want to see some real-world usage examples and how they read), but I don't like the "iterable vs non-iterable" distinction. Compare: case 1,2,3: # Tuple - checks for any of its members case range(10,110,10): # Range object - beautiful, convenient! case 42: # Non-iterable, works the way you'd expect case {1:"Test",2:"Hello",3:[]}: # Dictionary, may be surprising case "Test",: # Tuple with a single string in it - works but ugly case "Test": # And there's your problem. You now have three valid ways to interpret that last statement: 1) It matches the exact string "Test", the way people will expect 2) It matches any of the results of iterating over it 3) It matches anything where x in "Test" is true The first option is a big fat special case, and one that'll get more complicated as you start looking at subclasses and such. The second means that "case x" is equivalent to "case tuple(x)", but I can't imagine people would actually want that in real usage. The third is the way you've described it so far, but again, I cannot imagine it as anything other than highly surprising that my last statement above will match "st" and "es". It would be more invasive to the language, but possibly better, to have a new magic method __case__ which gets called to see if this object matches this switched object. If that isn't defined, an equality check is done. Then all of the above cases can be made unsurprising by simply defining __case__ on a tuple (membership test) and a range (ditto, except that the members aren't specifically instantiated); everything else will check equality. (Having a dict check for its keys is surprising, IMO, and I don't mind that one not working.) It'd make it a *lot* easier to ensure sane behaviour in custom classes; if you want your class to function like a single unit, don't define __case__, but if you want it to function like a collection, set __case__=__in__. What do you reckon? ChrisA From Windows7IsOK at DreamPC2006.com Wed Apr 2 19:02:05 2014 From: Windows7IsOK at DreamPC2006.com (Skybuck Flying) Date: Thu, 3 Apr 2014 01:02:05 +0200 Subject: Recording instruction/data flow for a python script/program. Message-ID: Hello, Is there a way for a python script's execution to be capture in an instruction/data flow log ? Since python is an interpreter this should be easy to do ? Such a feature would then allow the script to be played back in some kind of log player for a script or something ? And compare how the script executed on my PC versus perhaps the recorded log. Or perhaps follow the recorded log to see what happened... Bye, Skybuck. From drsalists at gmail.com Wed Apr 2 19:16:13 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 2 Apr 2014 16:16:13 -0700 Subject: Recording instruction/data flow for a python script/program. In-Reply-To: References: Message-ID: Google is your friend: https://docs.python.org/2/library/trace.html On Wed, Apr 2, 2014 at 4:02 PM, Skybuck Flying wrote: > Hello, > > Is there a way for a python script's execution to be capture in an > instruction/data flow log ? > > Since python is an interpreter this should be easy to do ? > > Such a feature would then allow the script to be played back in some kind of > log player for a script or something ? > > And compare how the script executed on my PC versus perhaps the recorded > log. > > Or perhaps follow the recorded log to see what happened... > > Bye, > Skybuck. > -- > https://mail.python.org/mailman/listinfo/python-list From sreisscruz at gmail.com Wed Apr 2 19:27:04 2014 From: sreisscruz at gmail.com (Steve) Date: Wed, 2 Apr 2014 16:27:04 -0700 (PDT) Subject: Unicode Chars in Windows Path Message-ID: Hi All, I'm in need of some encoding/decoding help for a situation for a Windows Path that contains Unicode characters in it. ---- CODE ---- import os.path import codecs import sys All_Tests = [u"c:\automation_common\Python\TestCases\list_dir_script.txt"] for curr_test in All_Tests: print("\n raw : " + repr(curr_test) + "\n") print("\n encode : %s \n\n" ) % os.path.normpath(codecs.encode(curr_test, "ascii")) print("\n decode : %s \n\n" ) % curr_test.decode('string_escape') ---- CODE ---- Screen Output : raw : u'c:\x07utomation_common\\Python\\TestCases\\list_dir_script.txt' encode : c:utomation_common\Python\TestCases\list_dir_script.txt decode : c:utomation_common\Python\TestCases\list_dir_script.txt My goal is to have the properly formatting path in the output : c:\automation_common\Python\TestCases\list_dir_script.txt What is the "magic" encode/decode sequence here?? Thanks! Steve From jason.swails at gmail.com Wed Apr 2 19:33:07 2014 From: jason.swails at gmail.com (Jason Swails) Date: Wed, 2 Apr 2014 19:33:07 -0400 Subject: Switching between cmd.CMD instances In-Reply-To: References: Message-ID: On Wed, Apr 2, 2014 at 1:03 AM, Josh English wrote: > I have a program with several cmd.Cmd instances. I am trying to figure out > what the best way to organize them should be. > > I've got my BossCmd, SubmissionCmd, and StoryCmd objects. > > The BossCmd object can start either of the other two, and this module > allows the user switch back and forth between them. Exiting either of the > sub-command objects returns back to the BossCmd. > > I have defined both a do_done and do_exit method on the sub-commands. > > Is it possible to flag BossCmd so when either of the other two process > do_exit, the BossCmd will also exit? > I have an app that also has a number of cmd.Cmd subclasses to implement different interpreter layers. I haven't needed to implement what you're talking about here (exiting one interpreter just drops you down to a lower-level interpreter). However, it's definitely possible. You can have your SubmissionCmd and StoryCmd take a "master" (BossCmd) object in its __init__ method and store the BossCmd as an instance attribute. >From there, you can implement a method interface in which the child Cmd subclasses can call to indicate to BossCmd that do_exit has been called and it should quit after the child's cmdloop returns. So something like this: class SubmissionCmd(cmd.Cmd): # your stuff def __init__(self, master): cmd.Cmd.__init__(self, *your_args) self.master = master def do_exit(self, line): self.master.child_has_exited() class BossCmd(cmd.Cmd): # your stuff def child_has_exited(self): self.exit_on_return = True # this should be set False in __init__ def do_submit(self, line): subcmd = SubmissionCmd(self) subcmd.cmdloop() if self.exit_on_return: return True Untested and incomplete, but you get the idea. HTH, Jason -- Jason M. Swails BioMaPS, Rutgers University Postdoctoral Researcher -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at pearwood.info Wed Apr 2 21:06:06 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 03 Apr 2014 01:06:06 GMT Subject: Yet Another Switch-Case Syntax Proposal References: <12008-1396450399-453900@sneakemail.com> Message-ID: <533cb3fd$0$2909$c3e8da3$76491128@news.astraweb.com> On Thu, 03 Apr 2014 08:50:47 +1100, Chris Angelico wrote: > On Thu, Apr 3, 2014 at 1:53 AM, Lucas Malor <3kywjyds5d at snkmail.com> > wrote: >> For example, in a "switch x" statement, the code "case iterable: " is >> identical to "if x in iterable: " (or elif etc). So if you want to >> perform the same case block for more than one value, you have only to >> specify a tuple, a range etc. I would suggest to add an exception for >> non-iterable variables, so that you don't have to write "case var, : " >> but simply "case var: " and it will be identical to "if x == var: ". >> It's a bit tricky but the alternative is ugly. >> >> > This is sounding like a nasty special case. I'm ambivalent on the > overall proposal (want to see some real-world usage examples and how > they read), but I don't like the "iterable vs non-iterable" distinction. If we're going to add "switch" and "case" keywords, how about we also add "of"? Then we can write: switch x case of a, b, c: # x equals one of a, b or c case of d, e, f: # x equals one of d, e or f case in g, h, i: # g, h and i must be iterable, and x is in one of them else: # none of the above match That means we can cleanly match the common use-case where we want to match something by equality, comparing against a list of 1 or more (usually) scalar values: case of 1, 2, [23, 42], 99: assert x == 1 or x == 2 or x = [23,42] or x == 99 while also supporting the more complex case where we're matching against one or more sequences: case in (1, 2, 99), [23, 42]: assert x == 1 or x == 2 or x = 99 or x == 23 or x == 42 Of course, in practice the second case is likely to be given dynamically, not as literals: case in LIST_OF_KEYWORDS: ... Another option is to say that the cases being tested ought to be quite small in number. If you're trying to do this: case in range(100000000): ... you're doing it wrong. That being the case, we only need to match by equality: case 1, 2, 3: assert x == 1 or x == 2 or x == 3 and can write this when we want to match against a sequence or iterator: case *LIST_OF_KEYWORDS: ... and on the rare occasion we want to match against substrings, we can build a wrapper class: class Wrapper: def __init__(self, value): self.value = value def __eq__(self, other): return other in self.value case Wrapper("Hello world!"): # matches if x is a substring of "Hello world!" But what's the advantage here? Since Python is not a static-typed language, it's unlikely that there are any compile-time optimizations that can be performed here. If there are any run-time optimizations that a JIT optimizing compiler like Python can perform, it probably can perform them just as well on a series of if...elif. So I'm not sure I see what having special syntax for a switch-case statement gives us. -- Steven From rymg19 at gmail.com Wed Apr 2 21:29:13 2014 From: rymg19 at gmail.com (rymg19 at gmail.com) Date: Wed, 2 Apr 2014 18:29:13 -0700 (PDT) Subject: [ANN] ClamAV for Python 0.1 Message-ID: <0f9cb223-1564-4db6-92c5-9a5c9c20f003@googlegroups.com> ClamAV for Python is a simple set of Python bindings for libclamav. It uses CFFI for the bindings. Please give all user input. I'm anxious to see what others think of this. From jobhunts02 at aol.com Wed Apr 2 21:45:59 2014 From: jobhunts02 at aol.com (Washington Ratso) Date: Wed, 2 Apr 2014 18:45:59 -0700 (PDT) Subject: Calculating time differences given daylight savings time Message-ID: I am running Python 2.7 and would like to be able to calculate to the second the time difference between now and some future date/time in the same timezone while taking into account daylight savings time. I do not have pytz. Any ideas how to do it? If it requires having pytz, how would I do it with pytz? Thank you. From rustompmody at gmail.com Wed Apr 2 22:02:55 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 2 Apr 2014 19:02:55 -0700 (PDT) Subject: python nose unit test - test plan preparation In-Reply-To: References: Message-ID: <3c1ce911-8330-4185-ab77-d0ab8cc62cd2@googlegroups.com> On Wednesday, April 2, 2014 6:52:04 PM UTC+5:30, Hareesha Karunakar wrote: > Hello Group, > I am using python's nose testing frame work for my automated testing. > I would like to run my python cases and generate only the documentation without actually running/executing the cases. > How is this possible? > I head "collect-only" plugin will help to achieve the same. But I think I could not make out how to use this effectively? > Are there any other possibilities? > I mainly want to collect the "comments" form the test classes and test methods. If you dont get answers here you can try the nose group https://groups.google.com/forum/#!forum/nose-users From steve at pearwood.info Wed Apr 2 22:37:27 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 03 Apr 2014 02:37:27 GMT Subject: Unicode Chars in Windows Path References: Message-ID: <533cc967$0$2909$c3e8da3$76491128@news.astraweb.com> On Wed, 02 Apr 2014 16:27:04 -0700, Steve wrote: > Hi All, > > I'm in need of some encoding/decoding help for a situation for a Windows > Path that contains Unicode characters in it. > > ---- CODE ---- > > import os.path > import codecs > import sys > > All_Tests = > [u"c:\automation_common\Python\TestCases\list_dir_script.txt"] I don't think this has anything to do with Unicode encoding or decoding. In Python string literals, the backslash makes the next character special. So \n makes a newline, \t makes a tab, and so forth. Only if the character being backslashed has no special meaning does Python give you a literal backslash: py> print("x\tx") x x py> print("x\Tx") x\Tx In this case, \a has special meaning, and is converted to the ASCII BEL control character: py> u"...\automation" u'...\x07utomation' When working with Windows paths, you should make a habit of either escaping every backslash: u"c:\\automation_common\\Python\\TestCases\\list_dir_script.txt" using a raw-string: ur"c:\automation_common\Python\TestCases\list_dir_script.txt" or just use forward slashes: u"c:/automation_common/Python/TestCases/list_dir_script.txt" Windows accepts both forward and backslashes in file names. If you fix that issue, I expect your problem will go away. -- Steven From rustompmody at gmail.com Wed Apr 2 22:41:33 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 2 Apr 2014 19:41:33 -0700 (PDT) Subject: Retrieve item deep in dict tree? In-Reply-To: References: Message-ID: <5d184a3a-c8d2-40d6-8055-7f7d1eb96127@googlegroups.com> On Wednesday, April 2, 2014 11:28:16 PM UTC+5:30, Roy Smith wrote: > I have a big hairy data structure which is a tree of nested dicts. I have a sequence of strings which represents a path through the tree. Different leaves in the tree will be at different depths (which range from 1 to about 4 or 5 at most). I want to get the value stored at that path. Thus, if > keys = ['foo', 'bar', 'baz'] > I want to retrieve tree['foo']['bar']['baz']. > Is there some idiomatic, non-cryptic way to write that as a one-liner? > I'm using Python 2.7. What you are asking for is probably: >>> reduce((lambda tr, att: tr[att]), ['a','b','c'], nested) 'Hiii!!' >>> I used a nested thus >>> nested = {'a':{'b':{'c':"Hiii!!"}}} But what you are REALLY looking for is what Steven/Gordon gave In order to see more visibly that those whiles are just reduces you may want to rewrite as: >>> reduce((lambda tr, att: str(tr) + "[" + str(att) + "]"), ['a','b','c'], "nested") 'nested[a][b][c]' IOW the 'theorem' I am using is that reduce(op, id, l) is short for while l: id, l = op(id, l[0]), l[1:] return id From rosuav at gmail.com Wed Apr 2 23:10:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 Apr 2014 14:10:12 +1100 Subject: Unicode Chars in Windows Path In-Reply-To: <533cc967$0$2909$c3e8da3$76491128@news.astraweb.com> References: <533cc967$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, Apr 3, 2014 at 1:37 PM, Steven D'Aprano wrote: > Windows accepts both forward and backslashes in file names. Small clarification: The Windows *API* accepts both types of slash (you can open a file using forward slashes, for instance), but not all Windows *applications* are aware of this (generally only cross-platform ones take notice of this), and most Windows *users* prefer backslashes. So when you come to display a Windows path, you may want to convert to backslashes. But that's for display. ChrisA From rustompmody at gmail.com Thu Apr 3 00:15:23 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 2 Apr 2014 21:15:23 -0700 (PDT) Subject: Retrieve item deep in dict tree? In-Reply-To: <5d184a3a-c8d2-40d6-8055-7f7d1eb96127@googlegroups.com> References: <5d184a3a-c8d2-40d6-8055-7f7d1eb96127@googlegroups.com> Message-ID: <141eca25-744b-47c0-8b2b-d8d08f8b27ef@googlegroups.com> On Thursday, April 3, 2014 8:11:33 AM UTC+5:30, Rustom Mody wrote: > On Wednesday, April 2, 2014 11:28:16 PM UTC+5:30, Roy Smith wrote: > > I have a big hairy data structure which is a tree of nested dicts. I have a sequence of strings which represents a path through the tree. Different leaves in the tree will be at different depths (which range from 1 to about 4 or 5 at most). I want to get the value stored at that path. Thus, if > > keys = ['foo', 'bar', 'baz'] > > I want to retrieve tree['foo']['bar']['baz']. > > Is there some idiomatic, non-cryptic way to write that as a one-liner? > > I'm using Python 2.7. > What you are asking for is probably: > >>> reduce((lambda tr, att: tr[att]), ['a','b','c'], nested) > 'Hiii!!' Shorter version: >>> reduce(dict.get, ['a','b','c'], nested) 'Hiii!!' From steve at pearwood.info Thu Apr 3 01:29:47 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 03 Apr 2014 05:29:47 GMT Subject: Retrieve item deep in dict tree? References: <5d184a3a-c8d2-40d6-8055-7f7d1eb96127@googlegroups.com> <141eca25-744b-47c0-8b2b-d8d08f8b27ef@googlegroups.com> Message-ID: <533cf1cb$0$2909$c3e8da3$76491128@news.astraweb.com> On Wed, 02 Apr 2014 21:15:23 -0700, Rustom Mody wrote: >>>> reduce(dict.get, ['a','b','c'], nested) > 'Hiii!!' Nice! -- Steven From ian.g.kelly at gmail.com Thu Apr 3 02:50:44 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 Apr 2014 00:50:44 -0600 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: <533cb3fd$0$2909$c3e8da3$76491128@news.astraweb.com> References: <12008-1396450399-453900@sneakemail.com> <533cb3fd$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On Wed, Apr 2, 2014 at 7:06 PM, Steven D'Aprano wrote: > If we're going to add "switch" and "case" keywords, how about we also add > "of"? Then we can write: > > switch x case of a, b, c: > # x equals one of a, b or c > case of d, e, f: > # x equals one of d, e or f > case in g, h, i: > # g, h and i must be iterable, and x is in one of them > else: > # none of the above match I don't think I like the idea of having "case in" and "case of" meaning two different things, particularly since the one that you have labeled with "of" is the one that I think should use "in" and vice versa. Seems like too much potential for confusion here. From ian.g.kelly at gmail.com Thu Apr 3 03:00:10 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 Apr 2014 01:00:10 -0600 Subject: Retrieve item deep in dict tree? In-Reply-To: <141eca25-744b-47c0-8b2b-d8d08f8b27ef@googlegroups.com> References: <5d184a3a-c8d2-40d6-8055-7f7d1eb96127@googlegroups.com> <141eca25-744b-47c0-8b2b-d8d08f8b27ef@googlegroups.com> Message-ID: On Wed, Apr 2, 2014 at 10:15 PM, Rustom Mody wrote: > On Thursday, April 3, 2014 8:11:33 AM UTC+5:30, Rustom Mody wrote: >> On Wednesday, April 2, 2014 11:28:16 PM UTC+5:30, Roy Smith wrote: >> > I have a big hairy data structure which is a tree of nested dicts. I have a sequence of strings which represents a path through the tree. Different leaves in the tree will be at different depths (which range from 1 to about 4 or 5 at most). I want to get the value stored at that path. Thus, if > >> > keys = ['foo', 'bar', 'baz'] > >> > I want to retrieve tree['foo']['bar']['baz']. > >> > Is there some idiomatic, non-cryptic way to write that as a one-liner? > >> > I'm using Python 2.7. > >> What you are asking for is probably: > >> >>> reduce((lambda tr, att: tr[att]), ['a','b','c'], nested) >> 'Hiii!!' > > Shorter version: > >>>> reduce(dict.get, ['a','b','c'], nested) > 'Hiii!!' That breaks if the dicts are ever replaced with an alternate mapping implementation (or a dict subclass that overrides the get method), and incorrectly returns None instead of raising KeyError if the last key in the sequence does not exist (and if any of the other keys don't exist, you'll get a TypeError instead of a KeyError). This is more robust: import operator reduce(operator.getitem, ['a', 'b', 'c'], nested) From alister.nospam.ware at ntlworld.com Thu Apr 3 04:35:38 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Thu, 03 Apr 2014 08:35:38 GMT Subject: Unicode Chars in Windows Path References: Message-ID: On Wed, 02 Apr 2014 16:27:04 -0700, Steve wrote: > Hi All, > > I'm in need of some encoding/decoding help for a situation for a Windows > Path that contains Unicode characters in it. > > ---- CODE ---- > > import os.path import codecs import sys > > All_Tests = > [u"c:\automation_common\Python\TestCases\list_dir_script.txt"] > > > for curr_test in All_Tests: > print("\n raw : " + repr(curr_test) + "\n") > print("\n encode : %s \n\n" ) % > os.path.normpath(codecs.encode(curr_test, "ascii")) > print("\n decode : %s \n\n" ) % curr_test.decode('string_escape') > > ---- CODE ---- > > > Screen Output : > > raw : u'c:\x07utomation_common\\Python\\TestCases\\list_dir_script.txt' > > encode : c:utomation_common\Python\TestCases\list_dir_script.txt > > decode : c:utomation_common\Python\TestCases\list_dir_script.txt > > > My goal is to have the properly formatting path in the output : > > > c:\automation_common\Python\TestCases\list_dir_script.txt > > > What is the "magic" encode/decode sequence here?? > > Thanks! > > Steve you have imported os.path you will find it contains a number of functions to make this task easier* import os.path root=os.path.sep drive='c:' path= [root, 'automation_common','python', 'TestCases','list_dir_script.txt'] all_tests=os.path.join(drive,*path) works happily even in linux (the un-necessary drive letter simply gets stripped) *easier to maintain cross platform compatibility From marko at pacujo.net Thu Apr 3 05:00:09 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 03 Apr 2014 12:00:09 +0300 Subject: Unicode Chars in Windows Path References: <533cc967$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: <87fvluss86.fsf@elektro.pacujo.net> Chris Angelico : > Small clarification: The Windows *API* accepts both types of slash > (you can open a file using forward slashes, for instance), but not all > Windows *applications* are aware of this (generally only > cross-platform ones take notice of this), and most Windows *users* > prefer backslashes. So when you come to display a Windows path, you > may want to convert to backslashes. But that's for display. Didn't know that. More importantly, I had thought forward slashes were valid file basename characters, but Windows is surprisingly strict about that: < > : " / \ | ? * NUL are not allowed in basenames. Unix/linux disallows only: / NUL In fact, proper dealing with punctuation in pathnames is one of the main reasons to migrate to Python from bash. Even if it is often possible to write bash scripts that handle arbitrary pathnames correctly, few script writers are pedantic enough to do it properly. For example, newlines in filenames are bound to confuse 99.9% of bash scripts. Marko From breamoreboy at yahoo.co.uk Tue Apr 1 19:17:13 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 02 Apr 2014 00:17:13 +0100 Subject: Compact way to assign values by slicing list in Python Message-ID: Came across this http://stackoverflow.com/questions/22756632/compact-way-to-assign-values-by-slicing-list-in-python?newsletter=1&nlcode=245176|202f - just curious what you guys and gals thought of the answers. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From frank at chagford.com Thu Apr 3 01:23:58 2014 From: frank at chagford.com (Frank Millman) Date: Thu, 3 Apr 2014 07:23:58 +0200 Subject: Gauteng Usergroup Meeting Message-ID: A meeting of python users in Gauteng, South Africa has been arranged for Saturday 12th April. Full discussion and details can be found here - https://groups.google.com/forum/#!topic/gpugsa/qZEy-ptVxac I was not aware of this group until recently, even though I live in Gauteng, so I thought I would mention it here in case others are equally unaware. Frank Millman From tjreedy at udel.edu Tue Apr 1 18:33:25 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 01 Apr 2014 18:33:25 -0400 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/1/2014 5:26 PM, Mark H Harris wrote: >>>>> I didn't really start using unicode >>>>> until about 5 years ago; python has only really used it since python3. >>>>> right? If you narrowly meant "The python interpreter only starting using unicode as the default text class in 3.0", then you are, in that narrow sense, correct. If you meant something broader, if by 'python' you meant 'the python community' or 'python programmers', then you are wrong. >>>> No. Python 2.2 introduced Unicode. 2.0, as someone else corrected. >>> I didn't ask when it was introduced, I asked when it became useful? It was useful immediately when introduced. Do you really think we would add something useless, and that no one wanted to use? Core developers constantly ask 'What is the practical use case?' in response to suggested additions. For either question, your original answer is wrong. >> No you didn't. Does not matter. The answer he gave to the question he claims he asked, and the elaboration below, is wrong. > Yes, I did. Fine. You asked 'When did unicode in Python become useful.' Answer: 2.0, not 3.0. Most unicode use in Python is still running on Python 2. It works well enough that people are reluctant to migrate working and tested production code. End of discussion? > Our common English is apparently getting in the way. > Well, I speak American English, and you don't, apparently; U.K.? I hear, speak, read, and write standard American English. -- Terry Jan Reedy From sturla.molden at gmail.com Wed Apr 2 08:14:01 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Wed, 2 Apr 2014 12:14:01 +0000 (UTC) Subject: Examples of modern GUI python programms References: <20140401171927.edf916b2b03dda70d2b2b012@gmx.net> Message-ID: <1120216403418133228.875280sturla.molden-gmail.com@news.gmane.org> Wolfgang Keller wrote: >> Id like to ask.. do you know any modern looking GUI examples of > Judging from the example screenshots on their website, Kivy might be > adequate. If you want to build something from scratch, libSDL is excellent and free (zlib license). Official supported platforms are: Windows XP/Vista/7/8 Mac OS X 10.5+ Linux 2.6+ iOS 5.1.1+ Android 2.3.3+ libSDL can be used from Python using ctypes or Cython. There is no GUI, but you can draw whatever you like. Sturla From tjreedy at udel.edu Wed Apr 2 19:39:21 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 02 Apr 2014 19:39:21 -0400 Subject: Test post via gmane. Message-ID: Gmane has stopped receiving mail from the lists it mirrors at about 0:30 apr 2 (utc, I presume). I want to see what happens if I send to the list via gmane. -- Terry Jan Reedy From sturla.molden at gmail.com Wed Apr 2 07:52:54 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Wed, 2 Apr 2014 11:52:54 +0000 (UTC) Subject: Examples of modern GUI python programms References: <20140401171927.edf916b2b03dda70d2b2b012@gmx.net> Message-ID: <1032152677418132246.972756sturla.molden-gmail.com@news.gmane.org> Wolfgang Keller wrote: > Judging from the example screenshots on their website, Kivy might be > adequate. Kivy depends on PyGame which is GPL, and can only be used to build GPL software. From kwpolska at gmail.com Thu Apr 3 09:46:50 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Thu, 3 Apr 2014 15:46:50 +0200 Subject: Calculating time differences given daylight savings time In-Reply-To: References: Message-ID: On Thu, Apr 3, 2014 at 3:45 AM, Washington Ratso wrote: > I am running Python 2.7 and would like to be able to calculate to the second the time difference between now and some future date/time in the same timezone while taking into account daylight savings time. I do not have pytz. Any ideas how to do it? > > If it requires having pytz, how would I do it with pytz? > > Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list It requires having pytz, or dateutil, in order to get timezone objects*. You can also create those objects yourself, but that?s tricky ? and you SHOULD NOT do time zones on your own and just use something else. Why? See [0]. Example with pytz: # Necessary imports import pytz from datetime import datetime # the timezone in this example is Europe/Warsaw ? use your favorite one tz = pytz.timezone('Europe/Warsaw') now = datetime.now(tz) # Note I?m not using the tzinfo= argument of datetime(), it?s flaky and seemingly uses a historic WMT (+01:24) timezone that is dead since 1915. future = tz.localize(datetime(2014, 12, 24)) # And now you can happily do: delta = future - now # and you will get the usual timedelta object, which you can use the usual way. ### * pytz ships the Olson tz database, while dateutil maps uses your system?s copy of the tz database (if you are on Linux, OS X or anything else that is not Windows, really) or maps to the Windows registry. Use whichever suits you. [0]: http://www.youtube.com/watch?v=-5wpm-gesOY -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From rosuav at gmail.com Thu Apr 3 09:48:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Apr 2014 00:48:19 +1100 Subject: Test post via gmane. In-Reply-To: References: Message-ID: On Thu, Apr 3, 2014 at 10:39 AM, Terry Reedy wrote: > Gmane has stopped receiving mail from the lists it mirrors at about 0:30 apr > 2 (utc, I presume). I want to see what happens if I send to the list via > gmane. Looks like Gmane has started transmitting after fourteen hours (at least, that's what the timestamp on your post suggests). Is it now receiving also? ChrisA From marco.buttu at gmail.com Thu Apr 3 09:50:48 2014 From: marco.buttu at gmail.com (Marco Buttu) Date: Thu, 03 Apr 2014 15:50:48 +0200 Subject: Compact way to assign values by slicing list in Python References: Message-ID: On 04/02/2014 01:17 AM, Mark Lawrence wrote: > Came across this > http://stackoverflow.com/questions/22756632/compact-way-to-assign-values-by-slicing-list-in-python?newsletter=1&nlcode=245176|202f > - just curious what you guys and gals thought of the answers. I prefere this one: bar = ['a','b','c','x','y','z'] v1, _, _, v2, v3, _ = bar I also like the solution with itemgetter: v1, v2, v3 = itemgetter(0, 3, 4)(bar) but I think it is less readable than the previous one -- Marco Buttu From __peter__ at web.de Thu Apr 3 09:09:53 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 03 Apr 2014 15:09:53 +0200 Subject: Unicode Chars in Windows Path References: <533cc967$0$2909$c3e8da3$76491128@news.astraweb.com> <87fvluss86.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > Chris Angelico : > >> Small clarification: The Windows *API* accepts both types of slash >> (you can open a file using forward slashes, for instance), but not all >> Windows *applications* are aware of this (generally only >> cross-platform ones take notice of this), and most Windows *users* >> prefer backslashes. So when you come to display a Windows path, you >> may want to convert to backslashes. But that's for display. > > Didn't know that. More importantly, I had thought forward slashes were > valid file basename characters, but Windows is surprisingly strict about > that: > > < > : " / \ | ? * NUL > > are not allowed in basenames. Unix/linux disallows only: > > / NUL > > In fact, proper dealing with punctuation in pathnames is one of the main > reasons to migrate to Python from bash. Even if it is often possible to > write bash scripts that handle arbitrary pathnames correctly, few script > writers are pedantic enough to do it properly. For example, newlines in > filenames are bound to confuse 99.9% of bash scripts. That doesn't bother me much as 99.8% of all bash scripts are already confused by ordinary space chars ;) From random832 at fastmail.us Thu Apr 3 09:57:51 2014 From: random832 at fastmail.us (random832 at fastmail.us) Date: Thu, 03 Apr 2014 09:57:51 -0400 Subject: Unicode Chars in Windows Path In-Reply-To: <87fvluss86.fsf@elektro.pacujo.net> References: <533cc967$0$2909$c3e8da3$76491128@news.astraweb.com> <87fvluss86.fsf@elektro.pacujo.net> Message-ID: <1396533471.32018.102326165.14B5BB43@webmail.messagingengine.com> On Thu, Apr 3, 2014, at 5:00, Marko Rauhamaa wrote: > In fact, proper dealing with punctuation in pathnames is one of the main > reasons to migrate to Python from bash. Even if it is often possible to > write bash scripts that handle arbitrary pathnames correctly, few script > writers are pedantic enough to do it properly. For example, newlines in > filenames are bound to confuse 99.9% of bash scripts. Incidentally, these rules mean there are different norms about how command line arguments are parsed on windows. Since * and ? are not allowed in filenames, you don't have to care whether they were quoted. An argument [in a position where a list of filenames is expected] with * or ? in it _always_ gets globbed, so "C:\dir with spaces\*.txt" can be used. This is part of the reason the program is responsible for globbing rather than the shell - because only the program knows if it expects a list of filenames in that position vs a text string for some other purpose. This is unfortunate, because it means that most python programs do not handle filename patterns at all (expecting the shell to do it for them) - it would be nice if there was a cross-platform way to do this. Native windows wildcards are also weird in a number of ways not emulated by the glob module. Most of these are not expected by users, but some users may expect, for example, *.htm to match files ending in .html; *.* to match files with no dot in them, and *. to match _only_ files with no dot in them. The latter two are guaranteed by the windows API, the first is merely common due to default shortname settings. Also, native windows wildcards do not support [character classes]. From breamoreboy at yahoo.co.uk Thu Apr 3 09:31:39 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 03 Apr 2014 14:31:39 +0100 Subject: python nose unit test - test plan preparation In-Reply-To: <3c1ce911-8330-4185-ab77-d0ab8cc62cd2@googlegroups.com> References: <3c1ce911-8330-4185-ab77-d0ab8cc62cd2@googlegroups.com> Message-ID: On 03/04/2014 03:02, Rustom Mody wrote: > On Wednesday, April 2, 2014 6:52:04 PM UTC+5:30, Hareesha Karunakar wrote: >> Hello Group, >> I am using python's nose testing frame work for my automated testing. >> I would like to run my python cases and generate only the documentation without actually running/executing the cases. > >> How is this possible? >> I head "collect-only" plugin will help to achieve the same. But I think I could not make out how to use this effectively? >> Are there any other possibilities? >> I mainly want to collect the "comments" form the test classes and test methods. > > If you dont get answers here you can try the nose group > https://groups.google.com/forum/#!forum/nose-users > Or see http://lists.idyll.org/listinfo/testing-in-python which is also available as gmane.comp.python.testing.general -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From robert.kern at gmail.com Thu Apr 3 10:02:01 2014 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 03 Apr 2014 15:02:01 +0100 Subject: Examples of modern GUI python programms In-Reply-To: <1032152677418132246.972756sturla.molden-gmail.com@news.gmane.org> References: <20140401171927.edf916b2b03dda70d2b2b012@gmx.net> <1032152677418132246.972756sturla.molden-gmail.com@news.gmane.org> Message-ID: On 2014-04-02 12:52, Sturla Molden wrote: > Wolfgang Keller wrote: > >> Judging from the example screenshots on their website, Kivy might be >> adequate. > > Kivy depends on PyGame which is GPL, and can only be used to build GPL > software. It is not. http://www.pygame.org/LGPL -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From fabiofz at gmail.com Thu Apr 3 10:00:06 2014 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 3 Apr 2014 11:00:06 -0300 Subject: Examples of modern GUI python programms In-Reply-To: <1032152677418132246.972756sturla.molden-gmail.com@news.gmane.org> References: <20140401171927.edf916b2b03dda70d2b2b012@gmx.net> <1032152677418132246.972756sturla.molden-gmail.com@news.gmane.org> Message-ID: On Wed, Apr 2, 2014 at 8:52 AM, Sturla Molden wrote: > Wolfgang Keller wrote: > > > Judging from the example screenshots on their website, Kivy might be > > adequate. > > Kivy depends on PyGame which is GPL, and can only be used to build GPL > software. Actually, PyGame is LGPL: http://www.pygame.org/LGPL (it's also what their source files say, although I noted that in their homepage the link which points to http://www.pygame.org/LGPL *wrongly* says GPL when the actual link goes to LGPL and the sources say LGPL). Cheers, Fabio -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Apr 3 10:17:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Apr 2014 01:17:25 +1100 Subject: Unicode Chars in Windows Path In-Reply-To: <1396533471.32018.102326165.14B5BB43@webmail.messagingengine.com> References: <533cc967$0$2909$c3e8da3$76491128@news.astraweb.com> <87fvluss86.fsf@elektro.pacujo.net> <1396533471.32018.102326165.14B5BB43@webmail.messagingengine.com> Message-ID: On Fri, Apr 4, 2014 at 12:57 AM, wrote: > An argument [in a position where a list of filenames is expected] with * > or ? in it _always_ gets globbed, so "C:\dir with spaces\*.txt" can be > used. This is part of the reason the program is responsible for globbing > rather than the shell - because only the program knows if it expects a > list of filenames in that position vs a text string for some other > purpose. Which, I might mention, is part of why the old DOS way (still applicable under Windows, but I first met it with MS-DOS) of searching for files was more convenient than it can be with Unix tools. Compare: -- Get info on all .pyc files in a directory -- C:\>dir some_directory\*.pyc $ ls -l some_directory/*.pyc So far, so good. -- Get info on all .pyc files in a directory and all its subdirectories -- C:\>dir some_directory\*.pyc /s $ ls -l `find some_directory -name \*.pyc` Except that the ls version there can't handle names with spaces in them, so you need to faff around with null termination and stuff. With bash, you can use 'shopt -s globstar; ls -l **/*.py', but that's not a default-active option (at least, it's not active on any of the systems I use, but they're all Debians and Ubuntus; it might be active by default on others), and I suspect a lot of people don't even know it exists; I know of it, but don't always think of it, and often end up doing the above flawed version. On the flip side, having the shell handle it does mean you automatically get this on *any* command. You can go and delete all those .pyc files by just changing "ls -l" into "rm" or "dir" into "del", but that's only because del happens to support /s; other DOS programs may well not. ChrisA From rosuav at gmail.com Thu Apr 3 10:25:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Apr 2014 01:25:36 +1100 Subject: Examples of modern GUI python programms In-Reply-To: References: <20140401171927.edf916b2b03dda70d2b2b012@gmx.net> <1032152677418132246.972756sturla.molden-gmail.com@news.gmane.org> Message-ID: On Fri, Apr 4, 2014 at 1:00 AM, Fabio Zadrozny wrote: > Actually, PyGame is LGPL: http://www.pygame.org/LGPL (it's also what their > source files say, although I noted that in their homepage the link which > points to http://www.pygame.org/LGPL *wrongly* says GPL when the actual link > goes to LGPL and the sources say LGPL). Where? I can't see it. The home page redirects me to /news.html which doesn't say anything about GPL (other than in its collection of tags, which seem to be for finding other people's projects - that is, clicking that link takes you to a list of all pygame-using projects that are GPL'd); on the Documentation page, the license is clearly LGPL. ChrisA From sturla.molden at gmail.com Thu Apr 3 11:22:34 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Thu, 03 Apr 2014 17:22:34 +0200 Subject: Examples of modern GUI python programms In-Reply-To: References: <20140401171927.edf916b2b03dda70d2b2b012@gmx.net> <1032152677418132246.972756sturla.molden-gmail.com@news.gmane.org> Message-ID: On 03/04/14 16:02, Robert Kern wrote: >> Kivy depends on PyGame which is GPL, and can only be used to build GPL >> software. > > It is not. > > http://www.pygame.org/LGPL Their web paged says GPL, but I assume that is an error. Is Python allowed on iOS anyway? Apple used to ban any code not written in C, C++, Objective-C and Objective-C++. Sturla From 3kywjyds5d at snkmail.com Thu Apr 3 12:02:42 2014 From: 3kywjyds5d at snkmail.com (Lucas Malor) Date: Thu, 3 Apr 2014 16:02:42 +0000 Subject: Yet Another Switch-Case Syntax Proposal Message-ID: <8084-1396540962-768613@sneakemail.com> Thank you for reading and commenting my proposal. Here are my replies: In reply to Chris Angelico: > I don't like the "iterable vs non-iterable" distinction. Compare: [...] > case "Test": # And there's your problem. Yes, I had already thought after I posted that testing against string it's a problem. But I think that the more practical and unambiguous solution is to introduce also "casein" as a new keyword. So if you want to test a string: switch mystring case "-h": print_usage() case "--version" print_version() If you want to test against membership: switch mychar casein "aeiou": mychar.vocal = True I prefer "casein" instead of "case in" for the same reason Python uses "elif" instead of "else if". In reply to Ian Kelly: > A more suitable place to propose this would be the python-ideas mailing list. You're right. I posted here because this list was linked by PEP 1. But now that I read more there's also python-ideas listed. Let me know if I have to continue there instead. > Why just just an identifier after the switch keyword instead of an expression? Because I wronged, it can be an expression_list as well. > An expression_list is one or more independent expressions separated by commas that > don't create a tuple. Well, py docs state "An expression list containing at least one comma yields a tuple". > __contains__ is not part of the interface for iterables For what I know there's not an Iterable interface. For example List simply extends Object. I hope that an ABC Iterable class will be introduced in a future. Anyway, I think that "switch x casein y" should simply raise a TypeError if y doesn't implement __contains__, like "x in y" do. > If we overload the continue keyword in this way, then a continue can't be used within the switch > to control a loop that the switch is nested within. Well, this is the same problem for, say, a for loop nested inside another for loop, and you can solve it with the same methods. > Instead of disabling fallthrough by default, why not disable it all together? I was tempted but there are cases in which it's useful. An example switch day casein ("Monday", "Thursday", "Wednesday", "Tuesday", "Friday"): gotowork = True continue casein ("Monday", "Thursday", "Wednesday", "Tuesday", "Friday"): daytype = "ferial" casein ("Saturday", "Sunday") daytype = "festive" From harrismh777 at gmail.com Thu Apr 3 12:38:13 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 03 Apr 2014 11:38:13 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/1/14 5:33 PM, Terry Reedy wrote: hi Terry, hope you are well today, despite gmane difficulties; > If you narrowly meant "The python interpreter only starting using > unicode as the default text class in 3.0", then you are, in that narrow > sense, correct. Yes. When I speak of 'python' I am almost always speaking about the interpreter. If I speak of the python community, and I rarely do, I explicitly use the word 'community'. I am concerned with backward compatibility in my own stuff, but I am primarily interested in python3, and I have made the conscious decision to use only python3 moving forward, except in those cases (like QPython 2.7.2 on the Android platform ). So, python(3)'s use of unicode is exciting, not only as a step forward for the python interpreter, but also as a leadership step forward in computer science around the world. >>>> I didn't ask when it was introduced, I asked when it became useful? > > It was useful immediately when introduced. Do you really think we would > add something useless, and that no one wanted to use? Core developers > constantly ask 'What is the practical use case?' in response to > suggested additions. 'Useful' must always be taken in context, and also contextually evaluated with an on-going methodology which constantly informs 'usefulness' on a continuum. I admire and encourage the core devs, in their pursuit of excellence. Asking 'what is the practical use case?' is essential. Not always is the answer complete. On the python unicode continuum version (3) is more useful than version (2). ( this is of course relative and debatable, so the statement is rhetorical ) The commitment and dedicated effort to move forward with a unicode default is not only commendable, but also admits to the 'usefulness' of same. Its not that version 2 was useless, its just that version 3 is so much more useful that people are 'using' it and dedicating their resources moving forward with python3. This is similar to the decimal module. Of course it had limited usefulness in version(2) thru 3.2/ but now, python3.3+ the decimal module is truly useful! Why? Glad you asked... because it is now fast enough for use cases previously reserved for floats. I found limited usefulness for decimal prior to 3.3, but now we're finding decimal so useful that some of us are wanting decimal to be the default. ( all of this is also relative and debatable ) > Fine. You asked 'When did unicode in Python become useful.' > Answer: 2.0, not 3.0. Most unicode use in Python is still running on > Python 2. It works well enough that people are reluctant to migrate > working and tested production code. End of discussion? Sure. Yes, this is sad. Python2 works. Python2 is inconsistent, and troublesome. ( I do not mean that to be insulting, not in the least, its just true ) I've been studying python3 now for several years; cross referencing between python2 and python3 has been fun and illuminating, from a practical programming standpoint as well as from a standpoint of general interest in computer science, and the science of language design. Its been a magnificent journey for me (thanks to all of you who provided the food for thought, as it were ) Python3 is not perfect; but python3 is *way* more consistent than python2 and consequently *way* more useful than python2. ( this is relative, debatable, or even certainly one of those discussions of personal preference and taste perhaps ) As we move forward with use cases we grow and consequently our language evolves. This is true of the spoken word, also true of the comp sci word. In this sense, at this time, I would call python2 a 'mess'. Python3 straightened up the 'mess' pep after pep. At what point does do we arrive at 'elegant'? Beats me. Maybe when number is unified, decimal is default, scientists are free to mix literals of all types in a convenient and intelligent way. But, for the moment, python3 is elegant---and very useful. No doubt Python4 will build upon that; perhaps we will come to think of python3 as a mess? > I hear, speak, read, and write standard American English. > ~nice. Trouble is, as we've stated before, most of our comm in life is non verbal. So, even in the best (E)scale effectiveness we are at a loss because mailing lists and news servers lose the non verbals, the smiles, and shrugs, the waves, and the handshakes. rats() Enjoy your day Terry. PS I just thought of another example along the lines of continual usefulness: IDLE. (you've worked on IDLE, right?) IDLE is now useful ! ---a few years back, not so much. That is not to say that IDLE was *never* useful back in the day (it always has been, to some extent), but since it has matured over the years it is at a point now where it really can be the default (very useful) development interface for code and test. Its now stable, does what it advertises, and provides a clean simple environment that is pleasant to work with. I ask nay-Sayers, "Have you driven an IDLE lately?" From walterhurry at gmail.com Thu Apr 3 13:06:29 2014 From: walterhurry at gmail.com (Walter Hurry) Date: Thu, 3 Apr 2014 17:06:29 +0000 (UTC) Subject: Two Questions about Python on Windows Message-ID: Normally my Python development is done on FreeBSD and Linux. I know that on *ix I simply have to make foo.py executable (the shebang line is present, of course) to make it runnable. For my son's school assignment, I have to help him with Python for Windows. As I understand it, on Windows a .py file is not executable, so I need to run 'python foo py', or use a .pyw file. Question 1: Do I make a .pyw file simply by copying or renaming foo.py to foo.pyw? Secondly, on *ix, if there's an up-to-date .pyc in the right place and I run foo.py, Python will automagically use foo.pyc. Question 2: Does it work the same way on Windows, and does this apply both to foo.py and foo.pyw? From marko at pacujo.net Thu Apr 3 13:14:16 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 03 Apr 2014 20:14:16 +0300 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ioqq8hef.fsf@elektro.pacujo.net> Mark H Harris : > So, python(3)'s use of unicode is exciting, not only as a step forward > for the python interpreter, but also as a leadership step forward in > computer science around the world. Big words. I don't think computer science has experienced major steps forward since the 1930's: combinatory logic, the Turing machine, the Entscheidungsproblem, the halting problem,... The one major latter-day addition is complexity theory (1960's). Marko From maxerickson at gmail.com Thu Apr 3 13:31:55 2014 From: maxerickson at gmail.com (maxerickson at gmail.com) Date: Thu, 3 Apr 2014 10:31:55 -0700 (PDT) Subject: Two Questions about Python on Windows In-Reply-To: References: Message-ID: On Thursday, April 3, 2014 1:06:29 PM UTC-4, Walter Hurry wrote: > Normally my Python development is done on FreeBSD and Linux. I know that on *ix I simply have to make foo.py executable (the shebang line is present, of course) to make it runnable. > > For my son's school assignment, I have to help him with Python for Windows. > > As I understand it, on Windows a .py file is not executable, so I need to run 'python foo py', or use a .pyw file. > > Question 1: Do I make a .pyw file simply by copying or renaming foo.py to foo.pyw? > > Secondly, on *ix, if there's an up-to-date .pyc in the right place and I run foo.py, Python will automagically use foo.pyc. > > Question 2: Does it work the same way on Windows, and does this apply both to >foo.py and foo.pyw? The compile caching is more or less the same. It works transparently. If you are working in a cmd shell, it doesn't matter what extension you use, pyw just allows for associating scripts with an interpreter stub that does not bring up a shell (for a gui or whatever). Console and gui programs are handled separately on Windows and that's how Python makes the option available to scripts. You can also edit the PATHEXT environment variable to include .py/.pyw, making the python source files executable (as long as the types are properly registered with Windows; if double clicking runs them they should be properly registered). Max From ian.g.kelly at gmail.com Thu Apr 3 13:54:04 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 Apr 2014 11:54:04 -0600 Subject: Two Questions about Python on Windows In-Reply-To: References: Message-ID: On Apr 3, 2014 11:12 AM, "Walter Hurry" wrote: > > Normally my Python development is done on FreeBSD and Linux. I know that on *ix I simply have to make foo.py executable (the shebang line is present, of course) to make it runnable. > > For my son's school assignment, I have to help him with Python for Windows. > > As I understand it, on Windows a .py file is not executable, so I need to run 'python foo py', or use a .pyw file. > > Question 1: Do I make a .pyw file simply by copying or renaming foo.py to foo.pyw? Yes. The only distinction between .py and .pyw is that the Python installer associates the former with Python.exe and the latter with Pythonw.exe. Pythonw runs the script without creating a console window for stdin/stdout. > Secondly, on *ix, if there's an up-to-date .pyc in the right place and I run foo.py, Python will automagically use foo.pyc. I don't believe this is exactly correct. Python will only use a .pyc automatically for imported modules. For a file specified on the command line, Python won't try to second-guess the user as to which file they want. The file could have a .php extension, and Python will happily run it if the contents are valid Python code. > Question 2: Does it work the same way on Windows, and does this apply both to foo.py and foo.pyw? Yes. -------------- next part -------------- An HTML attachment was scrubbed... URL: From yimr00 at gmail.com Thu Apr 3 12:46:38 2014 From: yimr00 at gmail.com (Yimr Zero) Date: Fri, 4 Apr 2014 00:46:38 +0800 Subject: Retrieve item deep in dict tree? Message-ID: Here is a tricky method : reduce(lambda x,y:x[str(y)],keys,tree) ---------- Forwarded message ---------- From: Roy Smith To: Python List Cc: Date: Wed, 2 Apr 2014 13:58:16 -0400 Subject: Retrieve item deep in dict tree? I have a big hairy data structure which is a tree of nested dicts. I have a sequence of strings which represents a path through the tree. Different leaves in the tree will be at different depths (which range from 1 to about 4 or 5 at most). I want to get the value stored at that path. Thus, if keys = ['foo', 'bar', 'baz'] I want to retrieve tree['foo']['bar']['baz']. Is there some idiomatic, non-cryptic way to write that as a one-liner? I'm using Python 2.7. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Thu Apr 3 14:12:21 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 Apr 2014 12:12:21 -0600 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: <8084-1396540962-768613@sneakemail.com> References: <8084-1396540962-768613@sneakemail.com> Message-ID: On Thu, Apr 3, 2014 at 10:02 AM, Lucas Malor <3kywjyds5d at snkmail.com> wrote: >> __contains__ is not part of the interface for iterables > > For what I know there's not an Iterable interface. For example List simply extends Object. I hope that an ABC Iterable class will be introduced in a future. It already exists: >>> import collections.abc >>> isinstance([1,2,3], collections.abc.Iterable) True >> Instead of disabling fallthrough by default, why not disable it all together? > > I was tempted but there are cases in which it's useful. An example > > switch day casein ("Monday", "Thursday", "Wednesday", "Tuesday", "Friday"): > gotowork = True > continue > casein ("Monday", "Thursday", "Wednesday", "Tuesday", "Friday"): > daytype = "ferial" > casein ("Saturday", "Sunday") > daytype = "festive" I don't see how it's useful there. The first two cases are the same, so just combine the code into one suite. For overlapping cases where the intersection needs to be handled by both suites, you can match against the union and use conditionals to determine in more detail which code to run. For example, if you would write: switch day case in ("Mon", "Wed", "Fri"): lunch_time = datetime.time(12) meeting_time = datetime.time(14) continue case in ("Tue", "Thu"): lunch_time = datetime.time(11, 30) meeting_time = datetime.time(12, 30) continue case in ("Mon", "Tue", "Wed", "Thu", "Fri"): go_to_work = True day_type = "ferial" case in ("Sat", "Sun"): go_to_work = False day_type = "festive" Use this instead: switch day case in ("Mon", "Tue", "Wed", "Thu", "Fri"): go_to_work = True day_type = "ferial" if day in ("Tue", "Thu"): lunch_time = datetime.time(11, 30) meeting_time = datetime.time(12, 30) else: lunch_time = datetime.time(12) meeting_time = datetime.time(14) case in ("Sat", "Sun"): go_to_work = False day_type = "festive" You get an extra level of indentation this way, but it reads less like spaghetti code. From tjreedy at udel.edu Thu Apr 3 14:25:56 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 03 Apr 2014 14:25:56 -0400 Subject: Test post via gmane. In-Reply-To: References: Message-ID: On 4/3/2014 9:48 AM, Chris Angelico wrote: > On Thu, Apr 3, 2014 at 10:39 AM, Terry Reedy wrote: >> Gmane has stopped receiving mail from the lists it mirrors at about 0:30 apr >> 2 (utc, I presume). I want to see what happens if I send to the list via >> gmane. > > Looks like Gmane has started transmitting after fourteen hours (at > least, that's what the timestamp on your post suggests). Is it now > receiving also? Everything seems to be working now. -- Terry Jan Reedy From tjreedy at udel.edu Thu Apr 3 14:34:39 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 03 Apr 2014 14:34:39 -0400 Subject: Two Questions about Python on Windows In-Reply-To: References: Message-ID: On 4/3/2014 1:06 PM, Walter Hurry wrote: > Normally my Python development is done on FreeBSD and Linux. I know that on *ix I simply have to make foo.py executable (the shebang line is present, of course) to make it runnable. > > For my son's school assignment, I have to help him with Python for Windows. > > As I understand it, on Windows a .py file is not executable, so I need to run 'python foo py', or use a .pyw file. If he edits the file with Idle (see Start menu Python directory, F5 runs the file and uses the Idle shell for input and output. When the program finishes, one can interactively examine objects and call functions. F5 Run is like running a program from a console with -I. -- Terry Jan Reedy From tjreedy at udel.edu Thu Apr 3 14:41:29 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 03 Apr 2014 14:41:29 -0400 Subject: Unicode Chars in Windows Path In-Reply-To: References: <533cc967$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On 4/2/2014 11:10 PM, Chris Angelico wrote: > On Thu, Apr 3, 2014 at 1:37 PM, Steven D'Aprano wrote: >> Windows accepts both forward and backslashes in file names. > > Small clarification: The Windows *API* accepts both types of slash To me, that is what Steven said. > (you can open a file using forward slashes, for instance), but not all > Windows *applications* are aware of this (generally only > cross-platform ones take notice of this), and most Windows *users* > prefer backslashes. Do you have a source for that? > So when you come to display a Windows path, you > may want to convert to backslashes. But that's for display. -- Terry Jan Reedy From rustompmody at gmail.com Thu Apr 3 14:40:25 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 3 Apr 2014 11:40:25 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <87ioqq8hef.fsf@elektro.pacujo.net> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ioqq8hef.fsf@elektro.pacujo.net> Message-ID: <7158e573-5325-4b92-a7e9-0972cbabe36c@googlegroups.com> On Thursday, April 3, 2014 10:44:16 PM UTC+5:30, Marko Rauhamaa wrote: > Mark H Harris: > > So, python(3)'s use of unicode is exciting, not only as a step forward > > for the python interpreter, but also as a leadership step forward in > > computer science around the world. > Big words. I don't think computer science has experienced major steps > forward since the 1930's: combinatory logic, the Turing machine, the > Entscheidungsproblem, the halting problem,... > The one major latter-day addition is complexity theory (1960's). > Marko Umm... There is science and there is science Those who think Einstein the greatest are not likely to consider Edison. And vice versa :D From ethan at stoneleaf.us Thu Apr 3 14:23:39 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 03 Apr 2014 11:23:39 -0700 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: <8084-1396540962-768613@sneakemail.com> References: <8084-1396540962-768613@sneakemail.com> Message-ID: <533DA72B.9010602@stoneleaf.us> On 04/03/2014 09:02 AM, Lucas Malor wrote: > > In reply to Ian Kelly: >> >> Instead of disabling fallthrough by default, why not disable it all together? > > I was tempted but there are cases in which it's useful. An example > > switch day casein ("Monday", "Thursday", "Wednesday", "Tuesday", "Friday"): > gotowork = True > continue > casein ("Monday", "Thursday", "Wednesday", "Tuesday", "Friday"): > daytype = "ferial" > casein ("Saturday", "Sunday") > daytype = "festive" Absolutely not. Currently, the 'continue' key word means "stop processing and go back to the beginning". You would have it mean "keep going forward". Thus 'continue' would mean both "go backwards" and "go forwards" and would lead to unnecessary confusion. -- ~Ethan~ From fbicknel at gmail.com Thu Apr 3 14:49:56 2014 From: fbicknel at gmail.com (fbicknel at gmail.com) Date: Thu, 3 Apr 2014 11:49:56 -0700 (PDT) Subject: Default mutable parameters in functions Message-ID: Hi all, So I was reading about default values for functions and spied this: Important warning: The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes. That's ok - guess I can get used to that. So I did some experimenting and sure enough, immutables sort of behave "normally" in that they get the default value every time you call the function and don't specify the value for the parameter. But mutables behave very strangely (imho). Take this example: def foo(bar=[ 42 ]): print "It's a parrot, not a cheese: {value}".format(value=bar) bar[0] += 1 Now call it like this: foo() foo() foo() foo() and based on the "Important warning" above, you get something expected: It's a parrot, not a cheese: [42] It's a parrot, not a cheese: [43] It's a parrot, not a cheese: [44] It's a parrot, not a cheese: [45] Now call it with a value: foo([ 3 ]) as you might expect: It's a parrot, not a cheese: [3] But now go back to no parameter in the call: foo() foo() foo() It's a parrot, not a cheese: [46] It's a parrot, not a cheese: [47] It's a parrot, not a cheese: [48] it picks up where it left off. I was rather expecting it to start with 4! I put this into pythontutor.com's code visualization tool (http://goo.gl/XOmMjR) and it makes more sense what's going on. I thought this was interesting; thought I would share. From harrismh777 at gmail.com Thu Apr 3 14:55:06 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 03 Apr 2014 13:55:06 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ioqq8hef.fsf@elektro.pacujo.net> Message-ID: On 4/3/14 12:14 PM, Marko Rauhamaa wrote: > Mark H Harris : > >> So, python(3)'s use of unicode is exciting, not only as a step forward >> for the python interpreter, but also as a leadership step forward in >> computer science around the world. > > Big words. I don't think computer science has experienced major steps > forward since the 1930's: combinatory logic, the Turing machine, the > Entscheidungsproblem, the halting problem,... > > The one major latter-day addition is complexity theory (1960's). hi Marko, computer science covers everything from a linked list to virtual reality, from cpu pipe lining to flash memory, from punched tape i/o to plasma displays--- to led back-lit flat panels. Computer science also includes theory, and most of what you mention actually had its beginnings in mathematics, not computer science. And yet, most of what you mention as fundamental to computer science is only the beginning. The Turning a-machines together (and parallel to) Alonzo Church's lambda calculus (diverse methodologies on computability) brought a negative answer on the Entscheidungsproblem; so much so that one might even think that artificial intelligence were impossible. Alan Turning proved (before computers ever existed) that one a-machine may not determine whether another a-machine configuration will loop or halt. So what? Do we cease to work towards artificial intelligence? Do you believe that the AI work at MIT (using lisp) was a non step forwards for artificial intelligence; for computer science? Did not David Hilbert get a kick-in-the-pants? You might have thought that mathematics at IAS would have folded its tents and blown away after Kurt G?del proved (mostly as consequence of self-reference) that if an axiomatic system is complete it is also inconsistent, and if consistent assuredly incomplete! There are true statements which cannot be proven! Oh, crap. There must be systems of computation for which there is no proof, yet function non-the-less. Does this impact computer science today; does this impact AI studies today? We as human beings have only just begun. The human mind is a quantum computer. Can a bit be 1 and 0 at the same time?? It most certainly can; entanglement is a computational reality that we have only just begun to think about let alone comprehend, nor code for (whatever we might mean by that). Mathematicians hate this, but, computers are the way forward for mathematics. Computer proofs are increasing; we are discovering that proofs of import are requiring computers and computation algorithms. We don't through our straight edges and compasses away; nor do we toss out our BIC pens and paper. Algorithm is what is needed because the mathematics is too complicated. Computer science is moving understanding forward with algorithm. Beyond all of that is communication. That is where unicode comes in. Computer science is going to handle the problem of Universal Translation. Great strides have been taken towards this already. More are sure to come. ??? marcus From tjreedy at udel.edu Thu Apr 3 15:11:38 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 03 Apr 2014 15:11:38 -0400 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: <8084-1396540962-768613@sneakemail.com> References: <8084-1396540962-768613@sneakemail.com> Message-ID: On 4/3/2014 12:02 PM, Lucas Malor wrote: >> A more suitable place to propose this would be the python-ideas mailing list. > > You're right. I posted here because this list was linked by PEP 1. But now that I read more there's also python-ideas listed. Let me know if I have to continue there instead. Given that the idea has been posted to python-ideas and rejected, more that once I believe, I think this was the right place to post this to have variations discussed in a friendly manner. -- Terry Jan Reedy From marko at pacujo.net Thu Apr 3 15:43:16 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 03 Apr 2014 22:43:16 +0300 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ioqq8hef.fsf@elektro.pacujo.net> Message-ID: <8761mq8ai3.fsf@elektro.pacujo.net> Mark H Harris : > computer science covers everything from a linked list to virtual > reality, from cpu pipe lining to flash memory, from punched tape i/o > to plasma displays--- to led back-lit flat panels. >From the point of view of computer science, those barely register. We have had a revolution in hardware and software engineering, not computer science. > Computer science also includes theory, and most of what you mention > actually had its beginnings in mathematics, not computer science. And > yet, most of what you mention as fundamental to computer science is > only the beginning. Yes, but not much has taken place since in computer science. Even virtualization was well covered before WWII from the scientific point of view. > Do we cease to work towards artificial intelligence? Do you believe > that the AI work at MIT (using lisp) was a non step forwards for > artificial intelligence; for computer science? Little to write home about so far. Well, having Fritz beat the best human chess players is impressive, to be sure. A testament to the power of brute force. Similarly with Google and Big Data. But again, those are not scientific advances. > Did not David Hilbert get a kick-in-the-pants? You might have thought > that mathematics at IAS would have folded its tents and blown away > after Kurt G?del proved (mostly as consequence of self-reference) that > if an axiomatic system is complete it is also inconsistent, and if > consistent assuredly incomplete! There are true statements which > cannot be proven! Oh, crap. There must be systems of computation for > which there is no proof, yet function non-the-less. Does this impact > computer science today; does this impact AI studies today? True, the mathematicians gave up on justifying their existence and went back to counting beads. The foundational excitement still remains in physics. What does computer science have to show of late? A better mutual exclusion algorithm? Dancing trees? Ok, cryptography has been pretty exciting. The back and forth between feasibility and unfeasibility. The ongoing cat and mouse. Marko From ethan at stoneleaf.us Thu Apr 3 14:00:00 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 03 Apr 2014 11:00:00 -0700 Subject: Two Questions about Python on Windows In-Reply-To: References: Message-ID: <533DA1A0.9010900@stoneleaf.us> On 04/03/2014 10:54 AM, Ian Kelly wrote: > On Apr 3, 2014 11:12 AM, "Walter Hurry" wrote: >> >> Secondly, on *ix, if there's an up-to-date .pyc in the right place and I run foo.py, Python will automagically use foo.pyc. > > I don't believe this is exactly correct. Python will only use a .pyc automatically for imported modules. For a file > specified on the command line, Python won't try to second-guess the user as to which file they want. The file could > have a .php extension, and Python will happily run it if the contents are valid Python code. Right. When specifying the file as a command-line argument to python, you have it include the extension, and that is exactly the file that python executes. Also, using this method, a .pyc file is not created. Only imported files may have a .py[co] file automatically created for corresponding .py file. -- ~Ethan~ From breamoreboy at yahoo.co.uk Thu Apr 3 16:15:36 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 03 Apr 2014 21:15:36 +0100 Subject: Two Questions about Python on Windows In-Reply-To: References: Message-ID: On 03/04/2014 18:54, Ian Kelly wrote: > > On Apr 3, 2014 11:12 AM, "Walter Hurry" > wrote: > > > > Normally my Python development is done on FreeBSD and Linux. I know > that on *ix I simply have to make foo.py executable (the shebang line is > present, of course) to make it runnable. > > > > For my son's school assignment, I have to help him with Python for > Windows. > > > > As I understand it, on Windows a .py file is not executable, so I > need to run 'python foo py', or use a .pyw file. > > > > Question 1: Do I make a .pyw file simply by copying or renaming > foo.py to foo.pyw? > > Yes. The only distinction between .py and .pyw is that the Python > installer associates the former with Python.exe and the latter with > Pythonw.exe. Pythonw runs the script without creating a console window > for stdin/stdout. > Not with more modern versions of Python. c:\Users\Mark>assoc .py .py=Python.File c:\Users\Mark>ftype Python.File Python.File="C:\Windows\py.exe" "%1" %* c:\Users\Mark>assoc .pyw .pyw=Python.NoConFile c:\Users\Mark>ftype Python.NoConFile Python.NoConFile="C:\Windows\pyw.exe" "%1" %* -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From davea at davea.name Thu Apr 3 17:29:36 2014 From: davea at davea.name (Dave Angel) Date: Thu, 3 Apr 2014 17:29:36 -0400 (EDT) Subject: Test post via gmane. References: Message-ID: Terry Reedy Wrote in message: > On 4/3/2014 9:48 AM, Chris Angelico wrote: >> On Thu, Apr 3, 2014 at 10:39 AM, Terry Reedy wrote: >>> Gmane has stopped receiving mail from the lists it mirrors at about 0:30 apr >>> 2 (utc, I presume). I want to see what happens if I send to the list via >>> gmane. >> >> Looks like Gmane has started transmitting after fourteen hours (at >> least, that's what the timestamp on your post suggests). Is it now >> receiving also? > > Everything seems to be working now. > > I have a separate problem that first happened when gmane started working again: my nntp reader (Android nntp NewsReader) is showing extra posts in summary view that don't show in detail view. So there are apparently posts which are "new", but invisible. -- DaveA From ian.g.kelly at gmail.com Thu Apr 3 17:32:42 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 Apr 2014 15:32:42 -0600 Subject: Default mutable parameters in functions In-Reply-To: References: Message-ID: On Thu, Apr 3, 2014 at 12:49 PM, wrote: > Now call it with a value: > foo([ 3 ]) > > as you might expect: > It's a parrot, not a cheese: [3] > > But now go back to no parameter in the call: > foo() > foo() > foo() > > It's a parrot, not a cheese: [46] > It's a parrot, not a cheese: [47] > It's a parrot, not a cheese: [48] > > it picks up where it left off. > > I was rather expecting it to start with 4! You haven't replaced the default value; you've only substituted a different value for that call. In this function: def foo(x=3): print(x) You wouldn't expect a call of foo(27) to change the default value to 27, would you? From ethan at stoneleaf.us Thu Apr 3 17:44:10 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 03 Apr 2014 14:44:10 -0700 Subject: Default mutable parameters in functions In-Reply-To: References: Message-ID: <533DD62A.5040500@stoneleaf.us> On 04/03/2014 11:49 AM, fbicknel at gmail.com wrote: > > I put this into pythontutor.com's code visualization tool (http://goo.gl/XOmMjR) and it makes more sense what's going on. > > I thought this was interesting; thought I would share. That visualization tool is certainly neat, thanks! -- ~Ethan~ From rosuav at gmail.com Thu Apr 3 18:06:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Apr 2014 09:06:09 +1100 Subject: Unicode Chars in Windows Path In-Reply-To: References: <533cc967$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: On Fri, Apr 4, 2014 at 5:41 AM, Terry Reedy wrote: > On 4/2/2014 11:10 PM, Chris Angelico wrote: >> >> On Thu, Apr 3, 2014 at 1:37 PM, Steven D'Aprano >> wrote: >>> >>> Windows accepts both forward and backslashes in file names. >> >> >> Small clarification: The Windows *API* accepts both types of slash > > > To me, that is what Steven said. Yes, which is why I said "clarification" not "correction". >> (you can open a file using forward slashes, for instance), but not all >> Windows *applications* are aware of this (generally only >> cross-platform ones take notice of this), and most Windows *users* >> prefer backslashes. > > > Do you have a source for that? Hardly need one for the first point - it's proven by a single Windows application that parses a path name by dividing it on backslashes. Even if there isn't one today, I could simply write one, and prove my own point trivially (albeit not usefully). Anything that simply passes its arguments to an API (eg it just opens the file) won't need to take notice of slash type, but otherwise, it's very *VERY* common for a Windows program to assume that it can split paths manually. The second point would be better sourced, yes, but all I can say is that I've written programs that use and display slashes, and had non-programmers express surprise at it; similarly when you see certain programs that take one part of a path literally, and then build on it with either type of slash, like zip and unzip - if you say "zip -r C:\Foo\Bar", it'll tell you that it's archiving C:\Foo\Bar/Quux/Asdf.txt and so on. Definitely inspires surprise in non-programmers. ChrisA From rosuav at gmail.com Thu Apr 3 18:20:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Apr 2014 09:20:41 +1100 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: References: <8084-1396540962-768613@sneakemail.com> Message-ID: On Fri, Apr 4, 2014 at 5:12 AM, Ian Kelly wrote: > Use this instead: > > switch day case in ("Mon", "Tue", "Wed", "Thu", "Fri"): > go_to_work = True > day_type = "ferial" > if day in ("Tue", "Thu"): > lunch_time = datetime.time(11, 30) > meeting_time = datetime.time(12, 30) > else: > lunch_time = datetime.time(12) > meeting_time = datetime.time(14) > case in ("Sat", "Sun"): > go_to_work = False > day_type = "festive" > > You get an extra level of indentation this way, but it reads less like > spaghetti code. Still not an ideal demonstration of fall-through. Here's a much more useful form: switch get("version") case 0: commands_to_get_to_version_1 case 1: commands_to_get_to_version_2 case 2: commands_to_get_to_version_3 # Version 3 is current. set("version", 3) case 3: break else: raise UnknownVersionError("Unexpected version!") With fall-through, you don't need a loop around that. You jump to the appropriate point and start executing code until you get to the bottom (apart from the else, which obviously should never happen). To implement this in current Python, I'd probably do all the comparisons as inequalities: v = get("version") if v<0: raise UnknownVersionError("Version is below zero!") if v<1: commands_to_get_to_version_1 if v<2: commands_to_get_to_version_2 # Version 3 is current. set("version", 3) if v>3: raise UnknownVersionError("Version is moving backward!") Which means this isn't really a terribly compelling use-case; but I think it's a better one than overlapping ranges. Fall-through in C-like languages completely ignores the case labels on subsequent sections, and executes them because of their position in the file; I'm not sure how it's looking with the current proposals, but it seems the case statements would have to be written to catch the values from above. ChrisA From sturla.molden at gmail.com Thu Apr 3 18:31:44 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Thu, 3 Apr 2014 22:31:44 +0000 (UTC) Subject: Examples of modern GUI python programms References: <20140401171927.edf916b2b03dda70d2b2b012@gmx.net> <1032152677418132246.972756sturla.molden-gmail.com@news.gmane.org> Message-ID: <805299346418256996.395202sturla.molden-gmail.com@news.gmane.org> Chris Angelico wrote: > Where? I can't see it. The home page redirects me to /news.html which > doesn't say anything about GPL (other than in its collection of tags, > which seem to be for finding other people's projects - that is, > clicking that link takes you to a list of all pygame-using projects > that are GPL'd); on the Documentation page, the license is clearly > LGPL. > http://www.pygame.org/wiki/about "Pygame is free. Released under the GPL License, you can create open source, free, freeware, shareware, and commercial games with it. See the licence for full details." But as pointed out, it seems to be a typo. Sturla From ian.g.kelly at gmail.com Thu Apr 3 18:41:31 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 Apr 2014 16:41:31 -0600 Subject: Two Questions about Python on Windows In-Reply-To: References: Message-ID: On Thu, Apr 3, 2014 at 2:15 PM, Mark Lawrence wrote: > On 03/04/2014 18:54, Ian Kelly wrote: >> >> >> On Apr 3, 2014 11:12 AM, "Walter Hurry" > > wrote: >> > >> > Normally my Python development is done on FreeBSD and Linux. I know >> that on *ix I simply have to make foo.py executable (the shebang line is >> present, of course) to make it runnable. >> > >> > For my son's school assignment, I have to help him with Python for >> Windows. >> > >> > As I understand it, on Windows a .py file is not executable, so I >> need to run 'python foo py', or use a .pyw file. >> > >> > Question 1: Do I make a .pyw file simply by copying or renaming >> foo.py to foo.pyw? >> >> Yes. The only distinction between .py and .pyw is that the Python >> installer associates the former with Python.exe and the latter with >> Pythonw.exe. Pythonw runs the script without creating a console window >> for stdin/stdout. >> > > Not with more modern versions of Python. > > c:\Users\Mark>assoc .py > .py=Python.File > > c:\Users\Mark>ftype Python.File > Python.File="C:\Windows\py.exe" "%1" %* Which ultimately calls some version of python.exe. > c:\Users\Mark>assoc .pyw > .pyw=Python.NoConFile > > c:\Users\Mark>ftype Python.NoConFile > Python.NoConFile="C:\Windows\pyw.exe" "%1" %* Which ultimately calls some version of pythonw.exe. I elided that detail because it wasn't relevant to the question at hand. From rosuav at gmail.com Thu Apr 3 18:43:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Apr 2014 09:43:15 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 4, 2014 at 3:38 AM, Mark H Harris wrote: > 'Useful' must always be taken in context, and also contextually evaluated > with an on-going methodology which constantly informs 'usefulness' on a > continuum. I admire and encourage the core devs, in their pursuit of > excellence. Asking 'what is the practical use case?' is essential. Not > always is the answer complete. > On the python unicode continuum version (3) is more useful than version > (2). ( this is of course relative and debatable, so the statement is > rhetorical ) The commitment and dedicated effort to move forward with a > unicode default is not only commendable, but also admits to the 'usefulness' > of same. Its not that version 2 was useless, its just that version 3 is so > much more useful that people are 'using' it and dedicating their resources > moving forward with python3. > This is similar to the decimal module. Of course it had limited > usefulness in version(2) thru 3.2/ but now, python3.3+ the decimal module > is truly useful! Why? Glad you asked... because it is now fast enough for > use cases previously reserved for floats. I found limited usefulness for > decimal prior to 3.3, but now we're finding decimal so useful that some of > us are wanting decimal to be the default. ( all of this is also relative and > debatable ) So your definition of "useful" for the Decimal module is "fast" and your definition of "useful" for Unicode is "mandated into use". Neither of those is how any dictionary I know defines that word, and you're not even consistent (since you said Unicode became useful at 3.0, which didn't - AFAIK - improve its performance any, while 3.3 did (PEP 393)). Here's one definition: "able to be used for a practical purpose or in several ways". Does not say anything about performance. Python is useful in that I am able to wield it to solve my problems. I don't care that it's slower than C; in fact, a lot of the problems I solve with Python are interactive, and run to completion faster than I can notice them. If I use decimal.Decimal or fractions.Fraction in my code, it is not because it's fast or slow or anything, it is because that type matches what I want to do with it. Those types are useful to me because there are situations in which they match my problem. While I am interested in seeing a Decimal literal syntax in Python, and I would support a shift to have "1.2" evaluate as a Decimal (but not soon - it'd break backward compat *hugely*), I do not by any means believe that Decimal will only become useful when it's the default non-integer type in source code. ChrisA From rosuav at gmail.com Thu Apr 3 18:44:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Apr 2014 09:44:44 +1100 Subject: Examples of modern GUI python programms In-Reply-To: <805299346418256996.395202sturla.molden-gmail.com@news.gmane.org> References: <20140401171927.edf916b2b03dda70d2b2b012@gmx.net> <1032152677418132246.972756sturla.molden-gmail.com@news.gmane.org> <805299346418256996.395202sturla.molden-gmail.com@news.gmane.org> Message-ID: On Fri, Apr 4, 2014 at 9:31 AM, Sturla Molden wrote: > Chris Angelico wrote: > >> Where? I can't see it. The home page redirects me to /news.html which >> doesn't say anything about GPL (other than in its collection of tags, >> which seem to be for finding other people's projects - that is, >> clicking that link takes you to a list of all pygame-using projects >> that are GPL'd); on the Documentation page, the license is clearly >> LGPL. >> > > http://www.pygame.org/wiki/about > > "Pygame is free. Released under the GPL License, you can create open > source, free, freeware, shareware, and commercial games with it. See the > licence for full details." > > But as pointed out, it seems to be a typo. Ah yes, I see. That should probably be raised as a bug. ChrisA From breamoreboy at yahoo.co.uk Thu Apr 3 18:57:31 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 03 Apr 2014 23:57:31 +0100 Subject: Two Questions about Python on Windows In-Reply-To: References: Message-ID: On 03/04/2014 23:41, Ian Kelly wrote: > On Thu, Apr 3, 2014 at 2:15 PM, Mark Lawrence wrote: >> On 03/04/2014 18:54, Ian Kelly wrote: >>> >>> >>> On Apr 3, 2014 11:12 AM, "Walter Hurry" >> > wrote: >>> > >>> > Normally my Python development is done on FreeBSD and Linux. I know >>> that on *ix I simply have to make foo.py executable (the shebang line is >>> present, of course) to make it runnable. >>> > >>> > For my son's school assignment, I have to help him with Python for >>> Windows. >>> > >>> > As I understand it, on Windows a .py file is not executable, so I >>> need to run 'python foo py', or use a .pyw file. >>> > >>> > Question 1: Do I make a .pyw file simply by copying or renaming >>> foo.py to foo.pyw? >>> >>> Yes. The only distinction between .py and .pyw is that the Python >>> installer associates the former with Python.exe and the latter with >>> Pythonw.exe. Pythonw runs the script without creating a console window >>> for stdin/stdout. >>> >> >> Not with more modern versions of Python. >> >> c:\Users\Mark>assoc .py >> .py=Python.File >> >> c:\Users\Mark>ftype Python.File >> Python.File="C:\Windows\py.exe" "%1" %* > > Which ultimately calls some version of python.exe. > >> c:\Users\Mark>assoc .pyw >> .pyw=Python.NoConFile >> >> c:\Users\Mark>ftype Python.NoConFile >> Python.NoConFile="C:\Windows\pyw.exe" "%1" %* > > Which ultimately calls some version of pythonw.exe. > > I elided that detail because it wasn't relevant to the question at hand. > Yes, I regretted how badly I worded the above the second I hit the send button. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Thu Apr 3 19:03:40 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 04 Apr 2014 00:03:40 +0100 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: <12008-1396450399-453900@sneakemail.com> References: <12008-1396450399-453900@sneakemail.com> Message-ID: On 02/04/2014 15:53, Lucas Malor wrote: > Hi all. I would proposeto you all a switch-case syntax for Python. I already read PEP 3103 and I'm not completely satisfied by any of the proposed solutions. This is my proposal: > > switch_stmt ::= "switch" identifier "case" expression_list ":" suite > ("case" expression_list ":" suite)* > ["else" ":" suite] > > or, more simply: > > > > switch x case var1: > .... > case var2: > ... > case var3: > ... > else: > ... > Please don't take this personally, but there's more chance of me being the first ever World President than of anybody getting a switch/case statement past the BDFL. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Thu Apr 3 19:08:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Apr 2014 10:08:56 +1100 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: References: <12008-1396450399-453900@sneakemail.com> Message-ID: On Fri, Apr 4, 2014 at 10:03 AM, Mark Lawrence wrote: > Please don't take this personally, but there's more chance of me being the > first ever World President than of anybody getting a switch/case statement > past the BDFL. The language in PEP 3103 (written by Guido) doesn't suggest this to me. But maybe that's just being diplomatic. ChrisA From bouncingcats at gmail.com Thu Apr 3 20:15:57 2014 From: bouncingcats at gmail.com (David) Date: Fri, 4 Apr 2014 11:15:57 +1100 Subject: Unicode Chars in Windows Path In-Reply-To: References: <533cc967$0$2909$c3e8da3$76491128@news.astraweb.com> <87fvluss86.fsf@elektro.pacujo.net> <1396533471.32018.102326165.14B5BB43@webmail.messagingengine.com> Message-ID: On 4 April 2014 01:17, Chris Angelico wrote: > > -- Get info on all .pyc files in a directory and all its subdirectories -- > C:\>dir some_directory\*.pyc /s > $ ls -l `find some_directory -name \*.pyc` > > Except that the ls version there can't handle names with spaces in > them, so you need to faff around with null termination and stuff. Nooo, that stinks! There's no need to abuse 'find' like that, unless the version you have is truly ancient. Null termination is only necessary to pass 'find' results *via the shell*. Instead, ask 'find' to invoke the task itself. The simplest way is: find some_directory -name '*.pyc' -ls 'find' is the tool to use for *finding* things, not 'ls', which is intended for terminal display of directory information. If you require a particular feature of 'ls', or any other command, you can ask 'find' to invoke it directly (not via a shell): find some_directory -name '*.pyc' -exec ls -l {} \; 'Find' is widely under utilised and poorly understood because its command line syntax is extremely confusing compared to other tools, plus its documentation compounds the confusion. For anyone interested, I offer these key insights: Most important to understand is that the -name, -exec and -ls that I used above (for example) are *not* command-line "options". Even though they look like command-line options, they aren't. They are part of an *expression* in 'find' syntax. And the crucial difference is that the expression is order-dependent. So unlike most other commands, it is a mistake to put them in arbitrary order. Also annoyingly, the -exec syntax utilises characters that must be escaped from shell processing. This is more arcane knowledge that just frustrates people when they are in a rush to get something done. In fact, the only command-line *options* that 'find' takes are -H -L -P -D and -O, but these are rarely used. They come *before* the directory name(s). Everything that comes after the directory name is part of a 'find' expression. But, the most confusing thing of all, in the 'find' documentation, expressions are composed of tests, actions, and ... options! These so-called options are expression-options, not command-line-options. No wonder everyone's confused, when one word describes two similar-looking but behaviourally different things! So 'info find' must be read very carefully indeed. But it is worthwhile, because in the model of "do one thing and do it well", 'find' is the tool intended for such tasks, rather than expecting these capabilities to be built into all other command line utilities. I know this is off-topic but because I learn so much from the countless terrific contributions to this list from Chris (and others) with wide expertise, I am motivated to give something back when I can. And given that in the past I spent a little time and effort and eventually understood this, I summarise it here hoping it helps someone else. The unix-style tools are far more capable than the Microsoft shell when used as intended. There is good documentation on find at: http://mywiki.wooledge.org/UsingFind From breamoreboy at yahoo.co.uk Thu Apr 3 20:38:33 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 04 Apr 2014 01:38:33 +0100 Subject: Default mutable parameters in functions In-Reply-To: References: Message-ID: On 03/04/2014 19:49, fbicknel at gmail.com wrote: > Hi all, > > So I was reading about default values for functions and spied this: [snip] > > I was rather expecting it to start with 4! I just wish I had a quid for every time somebody expects something out of Python, that way I'd have retired years ago. At least here it's not accompanied by "as that's how it works in ". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Thu Apr 3 21:16:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Apr 2014 12:16:58 +1100 Subject: Unicode Chars in Windows Path In-Reply-To: References: <533cc967$0$2909$c3e8da3$76491128@news.astraweb.com> <87fvluss86.fsf@elektro.pacujo.net> <1396533471.32018.102326165.14B5BB43@webmail.messagingengine.com> Message-ID: On Fri, Apr 4, 2014 at 11:15 AM, David wrote: > On 4 April 2014 01:17, Chris Angelico wrote: >> >> -- Get info on all .pyc files in a directory and all its subdirectories -- >> C:\>dir some_directory\*.pyc /s >> $ ls -l `find some_directory -name \*.pyc` >> >> Except that the ls version there can't handle names with spaces in >> them, so you need to faff around with null termination and stuff. > > Nooo, that stinks! There's no need to abuse 'find' like that, unless > the version you have is truly ancient. Null termination is only > necessary to pass 'find' results *via the shell*. Instead, ask 'find' > to invoke the task itself. > > The simplest way is: > > find some_directory -name '*.pyc' -ls > > 'find' is the tool to use for *finding* things, not 'ls', which is > intended for terminal display of directory information. I used ls only as a first example, and then picked up an extremely common next example (deleting files). It so happens that find can '-delete' its found files, but my point is that on DOS/Windows, every command has to explicitly support subdirectories. If, instead, the 'find' command has to explicitly support everything you might want to do to files, that's even worse! So we need an execution form... > If you require a particular feature of 'ls', or any other command, you > can ask 'find' to invoke it directly (not via a shell): > > find some_directory -name '*.pyc' -exec ls -l {} \; ... which this looks like, but it's not equivalent. That will execute 'ls -l' once for each file. You can tell, because the columns aren't aligned; for anything more complicated than simply 'ls -l', you potentially destroy any chance at bulk operations. No, to be equivalent it *must* pass all the args to a single invocation of the program. You need to instead use xargs if you want it to be equivalent, and it's now getting to be quite an incantation: find some_directory -name \*.pyc -print0|xargs -0 ls -l And *that* is equivalent to the original, but it's way *way* longer and less convenient, which was my point. Plus, it's extremely tempting to shorten that, because this will almost always work: find some_directory -name \*.pyc|xargs ls -l But it'll fail if you have newlines in file names. It'd probably work every time you try it, and then you'll put that in a script and boom, it stops working. (That's what I meant by "faffing about with null termination". You have to go through an extra level of indirection, making the command fairly unwieldy.) > I know this is off-topic but because I learn so much from the > countless terrific contributions to this list from Chris (and others) > with wide expertise, I am motivated to give something back when I can. Definitely! This is how we all learn :) And thank you, glad to hear that. > And given that in the past I spent a little time and effort and > eventually understood this, I summarise it here hoping it helps > someone else. The unix-style tools are far more capable than the > Microsoft shell when used as intended. More specifically, the Unix model ("each tool should do one thing and do it well") tends to make for more combinable tools. The DOS style requires every program to reimplement the same directory-search functionality, and then requires the user to figure out how it's been written in this form ("zip -r" (or is it "zip -R"...), "dir /s", "del /s", etc, etc). The Unix style requires applications to accept arbitrary numbers of arguments (which they probably would anyway), and then requires the user to learn some incantations that will then work anywhere. If you're writing a script, you should probably use the -print0|xargs -0 method (unless you already require bash for some other reason); interactively, you more likely want to enable globstar and use the much shorter double-star notation. Either way, it works for any program, and that is indeed "far more capable". ChrisA From farrowch at gmail.com Thu Apr 3 21:49:53 2014 From: farrowch at gmail.com (Chris Farrow) Date: Thu, 3 Apr 2014 18:49:53 -0700 (PDT) Subject: COM Server data from python In-Reply-To: <1bee53e3-7778-463f-a6db-c40cb23f5638@googlegroups.com> References: <1bee53e3-7778-463f-a6db-c40cb23f5638@googlegroups.com> Message-ID: <81e0ad25-eb9a-45cd-91a3-6bb1b5191946@googlegroups.com> On Wednesday, April 2, 2014 8:39:01 AM UTC-5, schapm... at gmail.com wrote: > I am attempting to provide a bit of data through a com server I did a comparison of speed of my COM interface to ADODB and It seems massively slower. I'm not sure if there is something I need to adjust or maybe that I am making so many calls to the COM server that each call takes time and possibly ADO is just buffering some data in chunks to my code. This is mainly for an excel add-on that has not possibility to connect to mongodb except through an interface like this. > > > > I thought it was not really a big deal until I tested larger amounts of data and the speed took a nose dive. For instance 10,000 records just to walk through and pull a couple fields. ADO on the exact same data took only 1.5 seconds where my python code took close to 58 seconds to do the same thing. I've played around with design etc. > > > > When i test the same code directly from python I get the same result if not better than I did with ADO. Is there some bit of COM magic that I am missing. Or is this because python is having to do more behind the scenes? > > > > Thanks Hi, Did you implement your server using win32com? You might be better off looking for help on the python-win32 mailing list [1]. Regards, Chris [1] https://mail.python.org/pipermail/python-win32/ From wuwei23 at gmail.com Thu Apr 3 21:52:25 2014 From: wuwei23 at gmail.com (alex23) Date: Fri, 04 Apr 2014 11:52:25 +1000 Subject: Compact way to assign values by slicing list in Python In-Reply-To: References: Message-ID: On 3/04/2014 11:50 PM, Marco Buttu wrote: > I prefere this one: > > bar = ['a','b','c','x','y','z'] > v1, _, _, v2, v3, _ = bar > > I also like the solution with itemgetter: > > v1, v2, v3 = itemgetter(0, 3, 4)(bar) > > but I think it is less readable than the previous one What if you wanted the 2nd, 37th, and 1007th items from a list? Personally, I find the 2nd form far more readable, once I got past my initial surprise that it would access a list of items. From bouncingcats at gmail.com Thu Apr 3 22:02:40 2014 From: bouncingcats at gmail.com (David) Date: Fri, 4 Apr 2014 13:02:40 +1100 Subject: Unicode Chars in Windows Path In-Reply-To: References: <533cc967$0$2909$c3e8da3$76491128@news.astraweb.com> <87fvluss86.fsf@elektro.pacujo.net> <1396533471.32018.102326165.14B5BB43@webmail.messagingengine.com> Message-ID: On 4 April 2014 12:16, Chris Angelico wrote: > On Fri, Apr 4, 2014 at 11:15 AM, David wrote: >> On 4 April 2014 01:17, Chris Angelico wrote: >>> >>> -- Get info on all .pyc files in a directory and all its subdirectories -- >>> C:\>dir some_directory\*.pyc /s >>> $ ls -l `find some_directory -name \*.pyc` >>> >>> Except that the ls version there can't handle names with spaces in >>> them, so you need to faff around with null termination and stuff. >> >> Nooo, that stinks! There's no need to abuse 'find' like that, unless >> the version you have is truly ancient. Null termination is only >> necessary to pass 'find' results *via the shell*. Instead, ask 'find' >> to invoke the task itself. >> >> The simplest way is: >> >> find some_directory -name '*.pyc' -ls >> >> 'find' is the tool to use for *finding* things, not 'ls', which is >> intended for terminal display of directory information. > > I used ls only as a first example, and then picked up an extremely > common next example (deleting files). It so happens that find can > '-delete' its found files, but my point is that on DOS/Windows, every > command has to explicitly support subdirectories. If, instead, the > 'find' command has to explicitly support everything you might want to > do to files, that's even worse! So we need an execution form... > >> If you require a particular feature of 'ls', or any other command, you >> can ask 'find' to invoke it directly (not via a shell): >> >> find some_directory -name '*.pyc' -exec ls -l {} \; > > ... which this looks like, but it's not equivalent. > That will execute > 'ls -l' once for each file. You can tell, because the columns aren't > aligned; for anything more complicated than simply 'ls -l', you > potentially destroy any chance at bulk operations. Thanks for elaborating that point. But still ... > equivalent it *must* pass all the args to a single invocation of the > program. You need to instead use xargs if you want it to be > equivalent, and it's now getting to be quite an incantation: > > find some_directory -name \*.pyc -print0|xargs -0 ls -l > > And *that* is equivalent to the original, but it's way *way* longer > and less convenient, which was my point. If you are not already aware, it might interest you that 'find' in (GNU findutils) 4.4.2. has -- Action: -execdir command {} + This works as for `-execdir command ;', except that the `{}' at the end of the command is expanded to a list of names of matching files. This expansion is done in such a way as to avoid exceeding the maximum command line length available on the system. Only one `{}' is allowed within the command, and it must appear at the end, immediately before the `+'. A `+' appearing in any position other than immediately after `{}' is not considered to be special (that is, it does not terminate the command). I believe that achieves the goal, without involving the shell. It also has an -exec equivalent that works the same but has an unrelated security issue and not recommended. But if that '+' instead of ';' feature is not available on the target system, then as far as I am aware it would be necessary to use xargs as you say. Anyway, the two points I wished to contribute are: 1) It is preferable to avoid shell command substitutions (the backticks in the first example) and expansions where possible. 2) My observations on 'find' syntax, for anyone interested. Cheers, David From python at mrabarnett.plus.com Thu Apr 3 22:04:15 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 04 Apr 2014 03:04:15 +0100 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: <533DA72B.9010602@stoneleaf.us> References: <8084-1396540962-768613@sneakemail.com> <533DA72B.9010602@stoneleaf.us> Message-ID: <533E131F.6010907@mrabarnett.plus.com> On 2014-04-03 19:23, Ethan Furman wrote: > On 04/03/2014 09:02 AM, Lucas Malor wrote: >> >> In reply to Ian Kelly: >>> >>> Instead of disabling fallthrough by default, why not disable it all together? >> >> I was tempted but there are cases in which it's useful. An example >> >> switch day casein ("Monday", "Thursday", "Wednesday", "Tuesday", "Friday"): >> gotowork = True >> continue >> casein ("Monday", "Thursday", "Wednesday", "Tuesday", "Friday"): >> daytype = "ferial" >> casein ("Saturday", "Sunday") >> daytype = "festive" > > > Absolutely not. Currently, the 'continue' key word means "stop processing and go back to the beginning". You would > have it mean "keep going forward". Thus 'continue' would mean both "go backwards" and "go forwards" and would lead to > unnecessary confusion. > I thought it went to the end of the loop, but because it's a loop, it just wraps around back to the top... From wuwei23 at gmail.com Thu Apr 3 22:07:22 2014 From: wuwei23 at gmail.com (alex23) Date: Fri, 04 Apr 2014 12:07:22 +1000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/04/2014 2:38 AM, Mark H Harris wrote: >If I speak of the python community, and I rarely do Maybe you speak "of" them rarely but you claim to speak "for" them fairly often. > Python3 is not perfect; but python3 is *way* more consistent than > python2 and consequently *way* more useful than python2. It's possible for something to become "more useful" and for the original to *also* be useful: Py2 old-style classes were useful even though new-style classes were more so. Plone uses Py2's unicode extensively and at no point have I thought it "useless". From harrismh777 at gmail.com Thu Apr 3 22:09:38 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 03 Apr 2014 21:09:38 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/3/14 5:43 PM, Chris Angelico wrote: > So your definition of "useful" for the Decimal module is "fast" and > your definition of "useful" for Unicode is "mandated into use". No. I did not define 'useful'. I placed 'useful' on a continuum whereby 'useful' is non definitive & relative. Go read it again. Decimal became practical (due to performance enhancement) and therefore 'bumped up' on the 'useful' continuum. Unicode in python3 is more 'useful' than in python2; yet, useful for a given purpose in *both* (based on user preference and "suitability for a particular purpose") One of the reasons that many of us include a boiler plate legal disclaimer about useability in our open source is that "suitable for a particular purpose", ehem 'useful,' is entirely in the eye(s) of the beholder. > Python is > useful in that I am able to wield it to solve my problems. Python is 'useful' because I am able to solve my computational problems with it. Python3 is *more* 'useful' than Python2 for my purposes of computability and computational problem solving--- don't look for it in the dictionary. 'Useful' is as 'useful' does. 'Useful' is as I perceive it. 'Useful' is also as you perceive it. Immanuel kant said, "Perception is reality". 'Useful' is perceived reality--- a continuum between to extremes--- useless on the one hand, and flexible and all-powerful on the other. Oh, and by the by, my perceived continuum will 'look' different than your perceived continuum. In fact, they might be overlapping but probably will be non intersecting (all depending upon our own perceptions). marcus From daveandem2000 at gmail.com Thu Apr 3 22:10:16 2014 From: daveandem2000 at gmail.com (dave em) Date: Thu, 3 Apr 2014 19:10:16 -0700 (PDT) Subject: converting strings to hex Message-ID: Hello, I am taking a cryptography class and am having a tough time with an assignment similar to this. Given plain text message 1 and cipher 1 compute cipher 2 for message 2 Work flow will be: - figure out the key - use key to compute c2 So this is what I have so far and am getting nowhere fast. I could use a little help on this one. So my first step is to compute the key. I suspect my error below is because c1 is a float and m1 is a string but I don't know how to turn the string into a float. #### Python 2.7### m1text="my test message" print( m1text + ' in hex is ') print m1text.encode("hex") m1 = m1text.encode("hex") c1=0x6c73d5240a948c86981bc294814d k=m1^c1 print( 'the key = ' ) print hex(k) This code yields the following: my test message in hex is 6d792074657374206d657373616765 Traceback (most recent call last): File "/media/.../Crypto/Attackv2.py", line 10, in k=m1^c1 TypeError: unsupported operand type(s) for ^: 'str' and 'long' Any help is most appreciated. Dave From harrismh777 at gmail.com Thu Apr 3 22:29:43 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 03 Apr 2014 21:29:43 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/3/14 9:07 PM, alex23 wrote: > On 4/04/2014 2:38 AM, Mark H Harris wrote: >> If I speak of the python community, and I rarely do > > Maybe you speak "of" them rarely but you claim to speak "for" them > fairly often. I am sorry, and I do apologize (genuinely). I knowingly speak for my users, because I have their input (positive and negative) and because I have a list of likes|dislikes. I don't knowingly speak 'for' the python community; except that I can see that speaking about|for 'python' the interpreter might get interpreted as speaking of|for the 'python community'. If that occurs I assure you that its not intentional (mostly). >> Python3 is not perfect; but python3 is *way* more consistent than >> python2 and consequently *way* more useful than python2. > It's possible for something to become "more useful" and for the original > to *also* be useful: Py2 old-style classes were useful even though > new-style classes were more so. Plone uses Py2's unicode extensively and > at no point have I thought it "useless". Oh, I agree. Again, think of 'useful' on a continuum where comparison and contrast is king and queen, and where 'more useful' does not make 'less useful' obsolete. Again, prior to the C accelerated decimal module for python3.3 I did not use decimal (too slow). That does not mean that decimal was 'useless' (I am using it on 2.7.2 with QPython on Android with pdeclib). But something happened, decimal became fast enough that it is truly 'useful' enough (on the continuum) to be used IMHO as default. (that is all rhetorical; no need to argue it) Now, about Python2. It has not died. It appears to be 'useful'. The perceived reality is that Python2 is 'useful'. Or, is it as I perceive it, python2 is embedded in so many places that it must be maintained for a long time because so many code(s) will break otherwise? Not so much 'useful' as 'used,' so that it is never sacked. Or, is it really that python2 is so much more 'suitable for a particular purpose' ('useful') that certain folks just don't want to use python3? Beats me; the community will have to decide. marcus From python.list at tim.thechases.com Thu Apr 3 22:31:42 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 3 Apr 2014 21:31:42 -0500 Subject: converting strings to hex In-Reply-To: References: Message-ID: <20140403213142.2e737c6c@bigbox.christie.dr> On 2014-04-03 19:10, dave em wrote: > So my first step is to compute the key. I suspect my error below > is because c1 is a float and m1 is a string but I don't know how to > turn the string into a float. For the record, "c1" in your example should be an integer/long It sounds like you want the optional parameter to int() so you'd do >>> hex_string = "My text message".encode("hex") >>> hex_string '4d792074657874206d657373616765' >>> m1 = int(hex_string, 16) # magic happens here >>> m1 402263600993355509170946582822086501L >>> c1=0x6c73d5240a948c86981bc294814d >>> c1 2199677439761906166135512011931981L >>> k = m1 ^ c1 >>> k 400239414552556350237329405469124136L >>> hex(k) # as a string '0x4d1553a14172e0acebfd68b1f5e628L' -tkc From harrismh777 at gmail.com Thu Apr 3 22:38:38 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 03 Apr 2014 21:38:38 -0500 Subject: converting strings to hex References: Message-ID: <533E1B2E.5040608@gmail.com> On 4/3/14 9:10 PM, dave em wrote: > > I am taking a cryptography class and am having a > tough time with an assignment similar to this. > hi Dave, if your instructor wanted you to work on this with other people she would have made it a group project and ordered pizza for everyone. I'll give you some credit, that last couple of folks that wanted help with their homework here could not bring themselves to admit they wanted help with their homework. :) "HAL, please help me with my homework!" "I'm sorry, Dave, I can't do that..." "HAL!!?" "I'm sorry, Dave, I just can't do that..." marcus From ethan at stoneleaf.us Thu Apr 3 22:16:24 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 03 Apr 2014 19:16:24 -0700 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: <533E131F.6010907@mrabarnett.plus.com> References: <8084-1396540962-768613@sneakemail.com> <533DA72B.9010602@stoneleaf.us> <533E131F.6010907@mrabarnett.plus.com> Message-ID: <533E15F8.4000607@stoneleaf.us> On 04/03/2014 07:04 PM, MRAB wrote: > On 2014-04-03 19:23, Ethan Furman wrote: >> On 04/03/2014 09:02 AM, Lucas Malor wrote: >>> >>> In reply to Ian Kelly: >>>> >>>> Instead of disabling fallthrough by default, why not disable it all together? >>> >>> I was tempted but there are cases in which it's useful. An example >>> >>> switch day casein ("Monday", "Thursday", "Wednesday", "Tuesday", "Friday"): >>> gotowork = True >>> continue >>> casein ("Monday", "Thursday", "Wednesday", "Tuesday", "Friday"): >>> daytype = "ferial" >>> casein ("Saturday", "Sunday") >>> daytype = "festive" >> >> >> Absolutely not. Currently, the 'continue' key word means "stop processing and go back to the beginning". You would >> have it mean "keep going forward". Thus 'continue' would mean both "go backwards" and "go forwards" and would lead to >> unnecessary confusion. >> > I thought it went to the end of the loop, but because it's a loop, it > just wraps around back to the top... *sigh* I see you are already confused. ;) Hmmmm.... I think that would be more like 'skip' as in 'skip to the end'... Either way, though, 'continue' would mean two very different things: - skip everything between here and the end of the loop - don't skip everything between here and the end of the case -- ~Ethan~ From rosuav at gmail.com Thu Apr 3 23:09:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Apr 2014 14:09:49 +1100 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: <533E131F.6010907@mrabarnett.plus.com> References: <8084-1396540962-768613@sneakemail.com> <533DA72B.9010602@stoneleaf.us> <533E131F.6010907@mrabarnett.plus.com> Message-ID: On Fri, Apr 4, 2014 at 1:04 PM, MRAB wrote: > I thought [continue] went to the end of the loop, but because it's a loop, it > just wraps around back to the top... It goes to the bottom of the loop, and then the loop condition may or may not send it to the top of the loop. ChrisA From daveandem2000 at gmail.com Thu Apr 3 23:10:21 2014 From: daveandem2000 at gmail.com (dave em) Date: Thu, 3 Apr 2014 20:10:21 -0700 (PDT) Subject: converting strings to hex In-Reply-To: References: Message-ID: <77b50721-3206-4b03-8d49-1cd73ba46d66@googlegroups.com> On Thursday, April 3, 2014 8:31:42 PM UTC-6, Tim Chase wrote: > On 2014-04-03 19:10, dave em wrote: > > > So my first step is to compute the key. I suspect my error below > > > is because c1 is a float and m1 is a string but I don't know how to > > > turn the string into a float. > > > > For the record, "c1" in your example should be an integer/long > > > > It sounds like you want the optional parameter to int() so you'd do > > > > >>> hex_string = "My text message".encode("hex") > > >>> hex_string > > '4d792074657874206d657373616765' > > >>> m1 = int(hex_string, 16) # magic happens here > > >>> m1 > > 402263600993355509170946582822086501L > > >>> c1=0x6c73d5240a948c86981bc294814d > > >>> c1 > > 2199677439761906166135512011931981L > > >>> k = m1 ^ c1 > > >>> k > > 400239414552556350237329405469124136L > > >>> hex(k) # as a string > > '0x4d1553a14172e0acebfd68b1f5e628L' > > > > > > -tkc Thanks, got it. Sometimes the simple things can be difficult. Dave From harrismh777 at gmail.com Thu Apr 3 23:12:56 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 03 Apr 2014 22:12:56 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ioqq8hef.fsf@elektro.pacujo.net> <8761mq8ai3.fsf@elektro.pacujo.net> Message-ID: <533E2338.6060206@gmail.com> On 4/3/14 2:43 PM, Marko Rauhamaa wrote: > What does computer science have to show of late? A better mutual > exclusion algorithm? Dancing trees? > Ok, cryptography has been pretty exciting. The back and forth between > feasibility and unfeasibility. The ongoing cat and mouse. Computer science is stuck right now. This is for two reasons: 1) marketing (capitalism) 2) software idea patents (obviously marketing related) Two things need to happen to 'unstick' computer science: 1) intellectual property law needs an overhaul and software idea patents must die, and 2) computer languages (software engineering, coding) needs to be taught as a liberal art beginning seriously in middle school as an integrated discipline (for sure by high school, and as an absolute in colleges). Computer science needs to be freed of the capitalistic strangle-hold which some corporations leverage over it. Innovation is thwarted because its the wrong capitalistic thing to do. Innovation is thwarted because of the asinine world-wide intellectual property law malfunction; software idea patents must die. Cryptography is particularly annoying. Mathematicians and algorithm specialists are ham-strung because of the GCHQ in the U.K. and the NSA in the States. Our governments DO NOT want computer science to move forward with cryptography! God help the guy (people) who finally figure out how to determine the nth prime, or figure out how to factor really HUGE prime numbers easily on a desktop computer (not likely to happen anytime soon, but for sure NOT going to happen with the NSA & GCHQ looking over everyone's shoulders. Well, as everyone pointed out integers are the focal point for crypto. But, what if the focal point should be 'decimal' (really large very fast decimals). --- which are useful for constructing certain integers and ... dream with me here. Whatever it will take WILL require a paradigm shift, and it will require that we stand up and defend our right to pursue the course. Everyone has a right to digital privacy. Computer science is the way forward. marcus From harrismh777 at gmail.com Thu Apr 3 23:20:42 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 03 Apr 2014 22:20:42 -0500 Subject: converting strings to hex References: <77b50721-3206-4b03-8d49-1cd73ba46d66@googlegroups.com> Message-ID: On 4/3/14 10:10 PM, dave em wrote: > Thanks, got it. Sometimes the simple things can be difficult. > > Dave > You haven't seen nothing yet, wait till M.L. catches you on the flip side for using gg. {running for cover} marcus From daveandem2000 at gmail.com Thu Apr 3 23:22:10 2014 From: daveandem2000 at gmail.com (dave em) Date: Thu, 3 Apr 2014 20:22:10 -0700 (PDT) Subject: converting strings to hex In-Reply-To: References: <77b50721-3206-4b03-8d49-1cd73ba46d66@googlegroups.com> Message-ID: <5c9bd34f-b9ba-4c2f-b72e-ca72982ad0c9@googlegroups.com> > You haven't seen nothing yet, wait till M.L. catches you on the flip > > side for using gg. {running for cover} Who is ML? From ethan at stoneleaf.us Thu Apr 3 23:13:12 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 03 Apr 2014 20:13:12 -0700 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: References: <8084-1396540962-768613@sneakemail.com> <533DA72B.9010602@stoneleaf.us> <533E131F.6010907@mrabarnett.plus.com> Message-ID: <533E2348.4060403@stoneleaf.us> On 04/03/2014 08:09 PM, Chris Angelico wrote: > On Fri, Apr 4, 2014 at 1:04 PM, MRAB wrote: >> I thought [continue] went to the end of the loop, but because it's a loop, it >> just wraps around back to the top... > > It goes to the bottom of the loop, and then the loop condition may or > may not send it to the top of the loop. *ahem* The loop condition is *at* the top of the loop; if it was at the bottom it would be a do..until. ;) -- ~Ethan~ From Joshua.R.English at gmail.com Thu Apr 3 23:40:44 2014 From: Joshua.R.English at gmail.com (Josh English) Date: Thu, 3 Apr 2014 20:40:44 -0700 (PDT) Subject: Switching between cmd.CMD instances In-Reply-To: References: Message-ID: On Wednesday, April 2, 2014 4:33:07 PM UTC-7, Jason Swails wrote: > From there, you can implement a method interface in which the child Cmd subclasses can call to indicate to BossCmd that do_exit has been called and it should quit after the child's cmdloop returns. ?So something like this: > > Hey, yeah. My previous responses didn't show up, or are delayed, or something. Thank you, yes. This advice helped and rooting around the source code I realized that the Cmd.cmdqueue attribute is the easy way out: import cmd class BossCmd(cmd.Cmd): def __init__(self): cmd.Cmd.__init__(self) self.prompt = 'Boss>' self.exit_called_from_minion = False self.minions = {} def add_minion(self, name, cmder): self.minions[name] = cmder def do_exit(self, line): return True def postloop(self): print "I mean it. I'm done" def postcmd(self, stop, line): # check if minion called for exit if self.exit_called_from_minion: stop = True return stop def do_submission(self, line): if line: self.minions['submission'].onecmd(line) else: self.minions['submission'].cmdloop() def do_story(self, line): if line: self.minions['story'].onecmd(line) else: self.minions['story'].cmdloop() class SubmissionCmd(cmd.Cmd): def __init__(self, master = None): cmd.Cmd.__init__(self) self.prompt = 'Submission>' self.master = master if self.master: self.master.add_minion('submission', self) def do_done(self, line): return True def do_exit(self, line): self.master.exit_called_from_minion = True return True def do_story(self, line): if line: self.master.minions['story'].onecmd(line) else: self.master.cmdqueue.append('story {}'.format(line)) return True class StoryCmd(cmd.Cmd): def __init__(self, master=None): cmd.Cmd.__init__(self) self.prompt = 'Story>' self.master=master if self.master: self.master.add_minion('story', self) def do_done(self, line): return True def do_exit(self, line): elf.master.exit_called_from_minion = True return True def do_submission(self, line): if line: self.master.minions['submission'].onecmd(line) else: self.master.cmdqueue.append('submission {}'.format(line)) return True Boss = BossCmd() Sub = SubmissionCmd(Boss) Story = StoryCmd(Boss) Boss.cmdloop() ---- This gives me a flexible framework to bounce between Cmd instances at will, and quit the program from anywhere. Josh From rosuav at gmail.com Fri Apr 4 00:20:06 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Apr 2014 15:20:06 +1100 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: <533E2348.4060403@stoneleaf.us> References: <8084-1396540962-768613@sneakemail.com> <533DA72B.9010602@stoneleaf.us> <533E131F.6010907@mrabarnett.plus.com> <533E2348.4060403@stoneleaf.us> Message-ID: On Fri, Apr 4, 2014 at 2:13 PM, Ethan Furman wrote: > On 04/03/2014 08:09 PM, Chris Angelico wrote: >> >> On Fri, Apr 4, 2014 at 1:04 PM, MRAB wrote: >>> >>> I thought [continue] went to the end of the loop, but because it's a >>> loop, it >>> just wraps around back to the top... >> >> >> It goes to the bottom of the loop, and then the loop condition may or >> may not send it to the top of the loop. > > > *ahem* > > The loop condition is *at* the top of the loop; if it was at the bottom it > would be a do..until. ;) Well, if you go by the disassembly, Python does put the condition at the top of the loop. But I've seen plenty of C compilers that invert that - before the top of the loop it jumps down to the bottom, the bottom has the condition, and the condition may or may not jump you up to the top of the loop. Semantics :) ChrisA From james.harris.1 at gmail.com Fri Apr 4 02:16:43 2014 From: james.harris.1 at gmail.com (James Harris) Date: Fri, 4 Apr 2014 07:16:43 +0100 Subject: converting strings to hex References: <533E1B2E.5040608@gmail.com> Message-ID: "Mark H Harris" wrote in message news:533E1B2E.5040608 at gmail.com... > On 4/3/14 9:10 PM, dave em wrote: >> >> I am taking a cryptography class and am having a >> tough time with an assignment similar to this. >> > > hi Dave, if your instructor wanted you to work on this with other people > she would have made it a group project and ordered pizza for everyone. > > I'll give you some credit, that last couple of folks that wanted help with > their homework here could not bring themselves to admit they wanted help > with their homework. :) YMMV but I thought the OP had done a good job before asking for help and then asked about only a tiny bit of it. Some just post a question! > "HAL, please help me with my homework!" > > "I'm sorry, Dave, I can't do that..." > > "HAL!!?" > > "I'm sorry, Dave, I just can't do that..." You might find this interesting. http://sundry.wikispaces.com/transcript-2001 James From David at gbkt.org Tue Apr 1 06:12:27 2014 From: David at gbkt.org (David) Date: Tue, 01 Apr 2014 10:12:27 +0000 Subject: If you have a Mortgage, you NEED to read this. Message-ID: Did you hear? President Obama recently announced a two year extension of the HARP program. Its a Government program for homeowners with a mortgage. This program allows homeowners to lower their monthly payment by HUNDREDS a month AND reduce the number of years left on the mortgage. If you owe $825,000 or less on your mortgage, you are eligible to receive a quote and see how much you could be saving. It only takes a minute and doesn't cost anything to get a quote. Go here to get your quote: http://www.AmericanRefinance.org I hope this helps you, have a wonderful day. :) David Reynolds Vice President, American Refinance -------------------------------------------- To stop receiving emails from this sender, go here: stopemails dot org 2307 main st, Long Beach California From lele at metapensiero.it Fri Apr 4 03:07:39 2014 From: lele at metapensiero.it (Lele Gaifax) Date: Fri, 04 Apr 2014 09:07:39 +0200 Subject: Unicode Chars in Windows Path References: <533cc967$0$2909$c3e8da3$76491128@news.astraweb.com> Message-ID: <8761mp8tdw.fsf@nautilus.nautilus> Steven D'Aprano writes: > When working with Windows paths, you should make a habit of either > escaping every backslash: > > u"c:\\automation_common\\Python\\TestCases\\list_dir_script.txt" > > using a raw-string: > > ur"c:\automation_common\Python\TestCases\list_dir_script.txt" > > or just use forward slashes: > > u"c:/automation_common/Python/TestCases/list_dir_script.txt" The latter should be preferred, in case Python3 compatibility is a goal. ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From steve+comp.lang.python at pearwood.info Fri Apr 4 03:18:57 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Apr 2014 07:18:57 GMT Subject: Yet Another Switch-Case Syntax Proposal References: <8084-1396540962-768613@sneakemail.com> Message-ID: <533e5ce1$0$29993$c3e8da3$5496439d@news.astraweb.com> On Thu, 03 Apr 2014 15:11:38 -0400, Terry Reedy wrote: > On 4/3/2014 12:02 PM, Lucas Malor wrote: > >>> A more suitable place to propose this would be the python-ideas >>> mailing list. >> >> You're right. I posted here because this list was linked by PEP 1. But >> now that I read more there's also python-ideas listed. Let me know if I >> have to continue there instead. > > Given that the idea has been posted to python-ideas and rejected, more > that once I believe, I think this was the right place to post this to > have variations discussed in a friendly manner. I agree with Terry. Nothing wrong with gathering some feedback here first. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Fri Apr 4 03:52:46 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Apr 2014 07:52:46 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533e64ce$0$29993$c3e8da3$5496439d@news.astraweb.com> On Fri, 04 Apr 2014 09:43:15 +1100, Chris Angelico wrote: > While I am interested in seeing a Decimal literal syntax in Python, and > I would support a shift to have "1.2" evaluate as a Decimal (but not > soon - it'd break backward compat *hugely*) I used to think the same thing, but have since learned that it's not a coincidence or accident that people seriously interested in numerical computation nearly always stick to binary floats. I think it's a little harsh to say that only dilettantes and amateurs use base-10 floats, but only a little. Base-10 has one, and only one, thing going for it: the number you type (in decimal) is the number you get (within the limits of precision). Apart from that, in every way IEEE-754 binary floats are as good or better than any other choice of base, including decimal. The same floating-point complications that plague binary floats also plague decimal ones, only worse. I really should stop being shocked by anything I learn about floating point numbers, but something that knocked my socks off when I learned it was that as simple an operation as taking the average of two floats is problematic in decimal. In base-2, and given round-to-nearest division, (x+y)/2 is always within the range x...y. But that's not necessarily the case in base-10 floats: sometimes the average of two numbers is not between those two numbers. Contrast binary floats: py> x = 0.7777777777787516 py> y = 0.7777777777787518 py> (x + y) / 2 0.7777777777787517 with decimal: py> from decimal import * py> getcontext().prec = 16 py> x = Decimal("0.7777777777787516") py> y = Decimal("0.7777777777787518") py> (x + y) / 2 Decimal('0.7777777777787515') "Guido, why can't Python do maths???" (Oh lordy, can you imagine Ranting Rick getting onto that???) I've changed my mind about Python using Decimal as the default numeric type. I think that would send a very strong message that Python is not for serious numeric work. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Fri Apr 4 04:11:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Apr 2014 19:11:40 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <533e64ce$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e64ce$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 4, 2014 at 6:52 PM, Steven D'Aprano wrote: > py> x = Decimal("0.7777777777787516") > py> y = Decimal("0.7777777777787518") > py> (x + y) / 2 > Decimal('0.7777777777787515') > > I've changed my mind about Python using Decimal as the default numeric > type. I think that would send a very strong message that Python is not > for serious numeric work. Hmm. Good point. (I'm not familiar with your notation, by the way; assuming x...y includes both endpoints? The first thing that comes to mind is git's revision syntax, in which x and y would be tags/commits/branches and that would give you everything that's in those branches but not in their common parent. And I doubt very much that's what you mean!) So I go back to a previous form of the request/desire: that the AST store numeric literals as their original strings (maybe as well as the parsed version), such that an AST transform can replace all float literals with Decimal literals (if they exist, or calls to Decimal and string args if they don't). >>> print(ast.dump(ast.parse("print(0.1 + 0.2)"))) Module(body=[Expr(value=Call(func=Name(id='print', ctx=Load()), args=[BinOp(left=Num(n=0.1), op=Add(), right=Num(n=0.2))], keywords=[], starargs=None, kwargs=None))]) Possibly the easiest way - and maybe I should shift this part of the discussion to -ideas - would be to have Num nodes retain additional meta-information, in the same way that nodes retain line/column info. Then it would be relatively simple to write a "Decimal-mode" hook for IDLE that would turn it into a Decimal calculator instead of a binary float calculator. Adding Decimal as a supported type (which would have to happen if Python gets Decimal literals, but could be done in other ways too) would help, though it's not strictly necessary. >>> mod=ast.parse("print(0.1 + 0.2)") >>> exec(compile(mod,"-","exec")) 0.30000000000000004 >>> mod.body[0].value.args[0].left.n=Decimal("0.1") >>> mod.body[0].value.args[0].right.n=Decimal("0.2") >>> exec(compile(mod,"-","exec")) Traceback (most recent call last): File "", line 1, in exec(compile(mod,"-","exec")) TypeError: non-numeric type in Num But it can still be done, as long as it's possible to go back to the original string - which currently it's not, short of parsing the entire Python program manually. ChrisA From ian.g.kelly at gmail.com Fri Apr 4 04:13:13 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 4 Apr 2014 02:13:13 -0600 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <533e64ce$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e64ce$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 4, 2014 at 1:52 AM, Steven D'Aprano wrote: > py> from decimal import * > py> getcontext().prec = 16 > py> x = Decimal("0.7777777777787516") > py> y = Decimal("0.7777777777787518") > py> (x + y) / 2 > Decimal('0.7777777777787515') > > "Guido, why can't Python do maths???" Well, you need to work within the system: >>> (5*x + 5*y) / 10 Decimal('0.7777777777787517') Actually, I have no idea whether that formula can be relied upon or the correctness of the above was just luck. From breamoreboy at yahoo.co.uk Fri Apr 4 04:14:56 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 04 Apr 2014 09:14:56 +0100 Subject: converting strings to hex In-Reply-To: <5c9bd34f-b9ba-4c2f-b72e-ca72982ad0c9@googlegroups.com> References: <77b50721-3206-4b03-8d49-1cd73ba46d66@googlegroups.com> <5c9bd34f-b9ba-4c2f-b72e-ca72982ad0c9@googlegroups.com> Message-ID: On 04/04/2014 04:22, dave em wrote: > >> You haven't seen nothing yet, wait till M.L. catches you on the flip >> >> side for using gg. {running for cover} > > > Who is ML? > Good morning :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Fri Apr 4 04:20:52 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 04 Apr 2014 09:20:52 +0100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/04/2014 03:29, Mark H Harris wrote: > > Now, about Python2. It has not died. It appears to be 'useful'. > The perceived reality is that Python2 is 'useful'. Or, is it as I > perceive it, python2 is embedded in so many places that it must be > maintained for a long time because so many code(s) will break otherwise? > Not so much 'useful' as 'used,' so that it is never sacked. > Or, is it really that python2 is so much more 'suitable for a particular > purpose' ('useful') that certain folks just don't want to use python3? > Beats me; the community will have to decide. > For a lot of people, if it ain't broke, don't fix it. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From steve+comp.lang.python at pearwood.info Fri Apr 4 04:33:28 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Apr 2014 08:33:28 GMT Subject: Yet Another Switch-Case Syntax Proposal References: <8084-1396540962-768613@sneakemail.com> Message-ID: <533e6e58$0$29993$c3e8da3$5496439d@news.astraweb.com> On Thu, 03 Apr 2014 11:23:39 -0700, Ethan Furman wrote: > On 04/03/2014 09:02 AM, Lucas Malor wrote: >> >> In reply to Ian Kelly: >>> >>> Instead of disabling fallthrough by default, why not disable it all >>> together? >> >> I was tempted but there are cases in which it's useful. An example >> >> switch day casein ("Monday", "Thursday", "Wednesday", "Tuesday", >> "Friday"): >> gotowork = True >> continue >> casein ("Monday", "Thursday", "Wednesday", "Tuesday", "Friday"): >> daytype = "ferial" >> casein ("Saturday", "Sunday") >> daytype = "festive" > > > Absolutely not. Currently, the 'continue' key word means "stop > processing and go back to the beginning". It does not go back to the beginning. That would require resetting the iterable, which may be impossible. And if you succeeded, it would mean a loop with continue might never terminate! for i in (1, 2, 3): print(i) if i == 2: continue => prints: 1 2 1 2 1 2 1 ... Perhaps you mean "continue from the top"? But top and bottom is just an artifact of how we write the loop. The only direction that matters is iteration order, and I'm not aware of any language that allows for-loop iteration to go forward and backwards. "continue" means "continue with the next iteration", as the documentation says: https://docs.python.org/3/reference/simple_stmts.html In some languages, it's even spelled "next", e.g. Perl. (After a decade plus of reading and writing Python code, I still try to write "next" when I mean continue.) It's not a big stretch to go from "continue with the next iteration" to "continue with the next case". > You would have it mean "keep > going forward". Thus 'continue' would mean both "go backwards" and "go > forwards" and would lead to unnecessary confusion. Well, there's certainly already some confusion :-) -- Steven D'Aprano http://import-that.dreamwidth.org/ From fanny at itprovent.com Fri Apr 4 04:36:28 2014 From: fanny at itprovent.com (fanny at itprovent.com) Date: Fri, 4 Apr 2014 01:36:28 -0700 (PDT) Subject: segmentation fault, executable python file Message-ID: Hello, I generated an executable python file using cxfreeze. I run that file, it runs fine. But when I run it on another PC, it don't run. I try to it via terminal, and it says "Segmentation fault(core dump)". I try again run it with sudo, it says nothing and nothing happend. Could any of you please let me know how to fix this? From rosuav at gmail.com Fri Apr 4 04:57:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Apr 2014 19:57:33 +1100 Subject: segmentation fault, executable python file In-Reply-To: References: Message-ID: On Fri, Apr 4, 2014 at 7:36 PM, wrote: > Hello, > I generated an executable python file using cxfreeze. > I run that file, it runs fine. > But when I run it on another PC, it don't run. I try to it via terminal, and it says "Segmentation fault(core dump)". I try again run it with sudo, it says nothing and nothing happend. > > Could any of you please let me know how to fix this? Freezing a Python script into a binary requires matching all sorts of things, including the word size (32-bit or 64-bit), most likely the versions of various shared libraries, and possibly other compatibilities as well. What are the two computers? I'm guessing your second one is some kind of Unix, but that's as much as I can tell. ChrisA From fanny at itprovent.com Fri Apr 4 05:06:44 2014 From: fanny at itprovent.com (fanny at itprovent.com) Date: Fri, 4 Apr 2014 02:06:44 -0700 (PDT) Subject: segmentation fault, executable python file In-Reply-To: References: Message-ID: <49ded36a-5c07-4421-874a-5c3fb518efd5@googlegroups.com> the first one is ubuntu 12.04 64-bit (where i generate the executable file), and the second one is the same. Any idea? I confused for days until today. Thanks for your replay On Friday, April 4, 2014 3:57:33 PM UTC+7, Chris Angelico wrote: > On Fri, Apr 4, 2014 at 7:36 PM, wrote: > > > Hello, > > > I generated an executable python file using cxfreeze. > > > I run that file, it runs fine. > > > But when I run it on another PC, it don't run. I try to it via terminal, and it says "Segmentation fault(core dump)". I try again run it with sudo, it says nothing and nothing happend. > > > > > > Could any of you please let me know how to fix this? > > > > Freezing a Python script into a binary requires matching all sorts of > > things, including the word size (32-bit or 64-bit), most likely the > > versions of various shared libraries, and possibly other > > compatibilities as well. What are the two computers? I'm guessing your > > second one is some kind of Unix, but that's as much as I can tell. > > > > ChrisA From rosuav at gmail.com Fri Apr 4 05:17:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Apr 2014 20:17:33 +1100 Subject: segmentation fault, executable python file In-Reply-To: <49ded36a-5c07-4421-874a-5c3fb518efd5@googlegroups.com> References: <49ded36a-5c07-4421-874a-5c3fb518efd5@googlegroups.com> Message-ID: On Fri, Apr 4, 2014 at 8:06 PM, wrote: > the first one is ubuntu 12.04 64-bit (where i generate the executable file), and the second one is the same. Any idea? I confused for days until today. > > Thanks for your replay That's a good start. Next thing to try is running your executable under gdb; instead of getting a simple "Segmentation fault" message, you get some chance at a bit more info. But from here you need someone more familiar with cxfreeze. All I can advise is to compare installed packages on each; maybe you have multiple versions of some library or something. ChrisA From marko at pacujo.net Fri Apr 4 05:46:48 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 04 Apr 2014 12:46:48 +0300 Subject: Yet Another Switch-Case Syntax Proposal References: <8084-1396540962-768613@sneakemail.com> <533e6e58$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ioqpqvef.fsf@elektro.pacujo.net> >>>> Instead of disabling fallthrough by default, why not disable it all >>>> together? >>> >>> I was tempted but there are cases in which it's useful. An example No, it is never useful, it never was. It came into being by accident, a design bug turned into an advertised feature. >>> switch day casein ("Monday", "Thursday", "Wednesday", "Tuesday", >>> "Friday"): >>> gotowork = True >>> continue >>> casein ("Monday", "Thursday", "Wednesday", "Tuesday", "Friday"): >>> daytype = "ferial" >>> casein ("Saturday", "Sunday") >>> daytype = "festive" That "casein" next to "switch" bugs me. Did I already propose: switch: local_sabbath() case (1, 2, 3) as sabbath: ... case 6: ... else: ... The key is to look at precedents: try: ... except (E1, E2) as e: ... except ...: ... finally: ... and: lambda: expression The "switch: day" format is a hybrid of the "try" and "lambda" syntaxes and would be compatible with existing Python editors as well as general Python sensibilities. Marko From steve+comp.lang.python at pearwood.info Fri Apr 4 05:53:31 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Apr 2014 09:53:31 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> On Thu, 03 Apr 2014 11:38:13 -0500, Mark H Harris wrote: > On 4/1/14 5:33 PM, Terry Reedy wrote: > > hi Terry, hope you are well today, despite gmane difficulties; > >> If you narrowly meant "The python interpreter only starting using >> unicode as the default text class in 3.0", then you are, in that narrow >> sense, correct. > > Yes. When I speak of 'python' I am almost always speaking about the > interpreter. Which interpreter? PyPy, Numba, Nuitka, or perhaps even the newest in the family, Pyston? https://tech.dropbox.com/2014/04/introducing-pyston-an-upcoming-jit-based- python-implementation/ Wait, all of those are compilers! Nuitka is a static compiler, the others are JIT compilers. Perhaps you meant Jython, IronPython, or Stackless? They're all interpreters. Ah, they're compilers too! Specifically, byte-code compilers. There's even a compile() built-in function. I'm not just being pedantic for the sake of being annoying[1], there's an important point here. Namely, that we shouldn't conflate Python the language with any one specific compiler or interpreter. Not even -- *especially* not even -- CPython the reference implementation. So we have Python *the language*, and any of a number of implementations. By my count, including experimental, obsolete and abandoned versions, I know of at least 50 different implementations, at least 10 of which might count as "the Python interpreter" for somebody. So the question is, when you speak of "Python", do you mean *a specific implementation*, or do you mean *the language*? > If I speak of the python community, and I rarely do, I > explicitly use the word 'community'. I am concerned with backward > compatibility in my own stuff, but I am primarily interested in python3, > and I have made the conscious decision to use only python3 moving > forward, except in those cases (like QPython 2.7.2 on the Android > platform ). So, python(3)'s use of unicode is exciting, not only as a > step forward for the python interpreter, but also as a leadership step > forward in computer science around the world. I appreciate your enthusiasm, but let's not get too excited. Python is neither the first, nor the most influential, language to include Unicode. And as for it being a "leadership" step in computer science, that's rather like me proclaiming that my local take-away Italian restaurant shifting to gluten-free pasta is a revolution in chemistry. Python is not a computer-science-ey language. It is of little or no interest to computer scientists involved in the mathematics of computation, or compiler-theory, or type-theory, or any of the other academic disciplines under comp-sci. It's true that you might get a semester or two of learning Python in a comp-sci course (but more likely to be Java), but that's only because students have to be taught *something*. Comp-sci researchers are far more likely to be using something like Mercury or Haskell, not Python. Unicode is completely uninteresting to comp-sci. Whether strings contain 127 symbols or 1114112 or 2 is just a boring detail. [...] > On the python unicode continuum version (3) is more useful than > version (2). ( this is of course relative and debatable, so the > statement is rhetorical ) Now that's funny. You make a completely non-controversial statement, that Python 3's Unicode implementation is more useful (i.e. more functionally complete, fewer design flaws, more efficient) than Python 2's, and *that* is the claim that you smother to death in disclaimers. Whereas other statements you make, which sometimes have been as wrong as an utterly wrong thing, you've been prepared to go to the battlements and fight to the death over. [1] Although that's a bonus *wink* -- Steven D'Aprano http://import-that.dreamwidth.org/ From alister.nospam.ware at ntlworld.com Fri Apr 4 06:07:46 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Fri, 04 Apr 2014 10:07:46 GMT Subject: converting strings to hex References: <533E1B2E.5040608@gmail.com> Message-ID: On Thu, 03 Apr 2014 21:38:38 -0500, Mark H Harris wrote: > On 4/3/14 9:10 PM, dave em wrote: >> >> I am taking a cryptography class and am having a tough time with an >> assignment similar to this. >> >> > hi Dave, if your instructor wanted you to work on this with other people > she would have made it a group project and ordered pizza for everyone. > > I'll give you some credit, that last couple of folks that wanted help > with their homework here could not bring themselves to admit they wanted > help with their homework. :) > > "HAL, please help me with my homework!" > > "I'm sorry, Dave, I can't do that..." > > "HAL!!?" > > "I'm sorry, Dave, I just can't do that..." > > > marcus in general i would say:- "Can you 'HELP' with my homework?" is resonable "Can you 'DO' my homework for me" if wrong Not even mentioning it is homework is really taking the P**s Dave has been open Shown his existing work & received assistance on a minor correction, isn't that how we all learn :-) From steve+comp.lang.python at pearwood.info Fri Apr 4 06:08:46 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Apr 2014 10:08:46 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e64ce$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533e84ad$0$29993$c3e8da3$5496439d@news.astraweb.com> On Fri, 04 Apr 2014 02:13:13 -0600, Ian Kelly wrote: > On Fri, Apr 4, 2014 at 1:52 AM, Steven D'Aprano > wrote: >> py> from decimal import * >> py> getcontext().prec = 16 >> py> x = Decimal("0.7777777777787516") py> y = >> Decimal("0.7777777777787518") py> (x + y) / 2 >> Decimal('0.7777777777787515') >> >> "Guido, why can't Python do maths???" > > Well, you need to work within the system: > >>>> (5*x + 5*y) / 10 > Decimal('0.7777777777787517') > > Actually, I have no idea whether that formula can be relied upon or the > correctness of the above was just luck. And what happens when x+y would have been calculated correctly, but one, or both, of 5*x or 5*y loses catastrophically loses accuracy due to overflow? py> x = 3.1e307 py> y = 3.3e307 py> (x+y)/2 3.2e+307 py> (5*x+5*y)/10 inf (I've used regular floats here out of laziness, the same principle applies to Decimals -- there will be *some* number x which is finite, but 5*x overflows to infinity.) -- Steven D'Aprano http://import-that.dreamwidth.org/ From rustompmody at gmail.com Fri Apr 4 06:24:14 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 4 Apr 2014 03:24:14 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <236f592a-757f-489d-ba05-b2085cd70f8f@googlegroups.com> On Friday, April 4, 2014 3:23:31 PM UTC+5:30, Steven D'Aprano wrote: > On Thu, 03 Apr 2014 11:38:13 -0500, Mark H Harris wrote: > > > On 4/1/14 5:33 PM, Terry Reedy wrote: > > > > hi Terry, hope you are well today, despite gmane difficulties; > > > >> If you narrowly meant "The python interpreter only starting using > >> unicode as the default text class in 3.0", then you are, in that narrow > >> sense, correct. > > > > Yes. When I speak of 'python' I am almost always speaking about the > > interpreter. > > > > Which interpreter? PyPy, Numba, Nuitka, or perhaps even the newest in the > family, Pyston? > > > > https://tech.dropbox.com/2014/04/introducing-pyston-an-upcoming-jit-based- > python-implementation/ > > Wait, all of those are compilers! Nuitka is a static compiler, the others > are JIT compilers. Perhaps you meant Jython, IronPython, or Stackless? > They're all interpreters. > > Ah, they're compilers too! Specifically, byte-code compilers. There's > even a compile() built-in function. > > > I'm not just being pedantic for the sake of being annoying[1], I thought you were being statistic... Now who was the chap with the new statistics module? From tjreedy at udel.edu Fri Apr 4 06:43:12 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 Apr 2014 06:43:12 -0400 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/4/2014 5:53 AM, Steven D'Aprano wrote: > On Thu, 03 Apr 2014 11:38:13 -0500, Mark H Harris wrote: > >> On 4/1/14 5:33 PM, Terry Reedy wrote: >>> If you narrowly meant "The python interpreter only starting using >>> unicode as the default text class in 3.0", then you are, in that narrow >>> sense, correct. I really should have said "3.0 was the first version of Python (the language) to specify that code and strings are unicode" >> Yes. When I speak of 'python' I am almost always speaking about the >> interpreter. > > Which interpreter? Since the unicode change is a language and not an interpreter issue, it does not matter. > Unicode is completely uninteresting to comp-sci. Whether strings > contain 127 symbols or 1114112 or 2 is just a boring detail. Until CS researchers want to write academic papers with non-ascii symbols ;-). >> On the python unicode continuum version (3) is more useful than >> version (2). ( this is of course relative and debatable, so the >> statement is rhetorical ) > > Now that's funny. I agree. > You make a completely non-controversial statement, that > Python 3's Unicode implementation is more useful (i.e. more functionally > complete, fewer design flaws, more efficient) than Python 2's, and *that* > is the claim that you smother to death in disclaimers. -- Terry Jan Reedy From jurko.gospodnetic at pke.hr Fri Apr 4 07:05:52 2014 From: jurko.gospodnetic at pke.hr (=?UTF-8?B?SnVya28gR29zcG9kbmV0acSH?=) Date: Fri, 04 Apr 2014 13:05:52 +0200 Subject: segmentation fault, executable python file In-Reply-To: References: <49ded36a-5c07-4421-874a-5c3fb518efd5@googlegroups.com> Message-ID: Hi. On 4.4.2014. 11:17, Chris Angelico wrote: > But from here you need someone more familiar with cxfreeze. All I > can advise is to compare installed packages on each; maybe you > have multiple versions of some library or something. From what little I know of it, it freezes as little as possible of Python's modules into the executable and stores the remaining Python code in a single zip file and loads it from there at run-time. That should limit your search area to just the frozen part and externally used libraries, and my instinct tells me gdb should be able to point you in the culprit's direction in no time. Hope this helps. Best regards, Jurko Gospodneti? From sabri.pllana at gmail.com Fri Apr 4 09:31:01 2014 From: sabri.pllana at gmail.com (SP) Date: Fri, 4 Apr 2014 06:31:01 -0700 (PDT) Subject: CFP: MuCoCoS-2014, August, Porto, Portugal Message-ID: <514bd752-dd3c-49d4-a696-6a8ee4fa9eb6@googlegroups.com> 7th International Workshop on Multi/many-Core Computing Systems (MuCoCoS-2014) in conjunction with Euro-Par 2014 25-29 August, 2014, Porto, Portugal http://www.univie.ac.at/mucocos2014 AIMS AND SCOPE The pervasiveness of homogeneous and heterogeneous multi-core and many-core processors, in a large spectrum of systems from embedded and general-purpose to high-end computing systems, poses major challenges to the software industry. In general, there is no guarantee that software developed for a particular architecture will run on another architecture. Furthermore, ensuring that the software preserves some aspects of performance behavior (such as temporal or energy efficiency) across different such architectures is an open research issue. Therefore, a focus of this workshop is on language level, system software and architectural solutions for performance portability across different architectures and for automated performance tuning. The topics of the MuCoCoS workshop include but are not limited to: - Programming models, languages, libraries and compilation techniques - Run-time systems and hardware support - Automatic performance tuning and optimization techniques - Patterns, algorithms and data structures for multi-/many-core systems - Performance measurement, modeling, analysis and tuning - Case studies highlighting performance portability and tuning. As the seventh workshop in the series MuCoCoS 2008 (Barcelona, Spain), MuCoCoS 2009 (Fukuoka, Japan), MuCoCoS 2010 (Krakow, Poland), MuCoCoS 2011 (Seoul, Korea), MuCoCoS 2012 (Salt Lake City, USA), and MuCoCoS 2013 (Edinburgh, UK), MuCoCoS 2014 will be held in Porto, Portugal, in conjunction with Euro-Par 2014. SUBMISSION GUIDELINES Full papers should not exceed 12 pages in the Springer LNCS style. Paper submission has to be performed electronically via the conference Web site in PDF format. MuCoCoS-2014 submission site: https://www.easychair.org/conferences/?conf=europar2014ws (Please select the track: Seventh International Workshop on Multi-/Many-core Computing Systems) Papers accepted for publication must also be supplied in source form (LaTeX). The 12 pages limit is a hard limit. It includes everything (text, figures, references) and will be strictly enforced by the submission system. Download LNCS Latex style: ftp://ftp.springer.de/pub/tex/latex/llncs/latex2e/llncs2e.zip Papers must offer original contributions. Only contributions not submitted elsewhere for publication will be considered. All accepted papers will be included in the Europar-2014 workshop proceedings, published by Springer in the LNCS series after the workshop. Authors of accepted papers will be requested to sign a Springer copyright form. Submissions are handled through the EasyChair conference system. https://www.easychair.org/conferences/?conf=europar2014ws Once logged into the system select the track: Seventh International Workshop on Multi-/Many-core Computing Systems) IMPORTANT DATES Workshop papers due: May 30, 2014 Workshop author notification: July 4, 2014 Workshop early registration: July 25, 2014 Workshop camera-ready papers due: October 3, 2014 Workshop date: tba WORKSHOP ORGANIZATION Siegfried Benkner, University of Vienna, Austria, program chair Sabri Pllana, Linnaeus University, Sweden, co-chair PROGRAM COMMITTEE - Beverly Bachmayer, Intel, Germany - Eduardo Cesar, Universitat Autonoma de Barcelona, Spain - Milind Chabbi, Rice University, USA - Jiri Dokuli, University of Vienna, Austria - Franz Franchetti, Carnegie Mellon University, USA - Michael Gerndt, TU Munich, Germany - Joerg Keller, FernUniv. Hagen, Germany - Christoph Kessler, Linkoping University, Sweden - Erwin Laure, KTH, Sweden - Renato Miceli, Irish Centre for High-End Computing, Ireland - Lasse Natvig, NTNU Trondheim, Norway - Beniamino Di Martino, Seconda Universita' di Napoli, Italy - Samuel Thibault, Univ. Bordeaux, France - Philippas Tsigas, Chalmers Univ., Sweden - Josef Weidendorfer, TU Munich, Germany From random832 at fastmail.us Fri Apr 4 10:00:25 2014 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 04 Apr 2014 10:00:25 -0400 Subject: Default mutable parameters in functions In-Reply-To: References: Message-ID: <1396620025.10391.102762569.6DD0D52A@webmail.messagingengine.com> On Thu, Apr 3, 2014, at 20:38, Mark Lawrence wrote: > I just wish I had a quid for every time somebody expects something out > of Python, that way I'd have retired years ago. At least here it's not > accompanied by "as that's how it works in ". I can't imagine a language that would work that way. For one, it would also imply that passing a value would change the default for future calls even for non-mutable types. From bv4bv4bv4 at gmail.com Fri Apr 4 10:32:11 2014 From: bv4bv4bv4 at gmail.com (bv4bv4bv4 at gmail.com) Date: Fri, 4 Apr 2014 07:32:11 -0700 (PDT) Subject: Jesus: an Islamic view Message-ID: <0c36d95e-2cd0-4528-99e3-93c63582a42f@googlegroups.com> Jesus: an Islamic view In this pamphlet, the author shows the nature of the Prophet Jesus as Islam provides. He shows that the Prophet Jesus is a human prophet and does not have any divine nature as Christian believe. Did you know that it is obligatory for Muslims to believe in Jesus, or that a record of Jesus' life and teachings is preserved in the Qur'an and sayings of Muhammad, as well as in little-known traditions handed down by Muslim communities over the centuries? Christians brought up in the West are often surprised to discover Muslims who are familiar with the life and teachings of Jesus through the teachings and scriptures of Islam, while they themselves are unlikely to have learned anything about the Prophet Muhammad at church. This is partly a matter of history: Islam incorporates the Judeo-Christian tradition and embraces Jesus in the same way that Christianity incorporates the Old Testament and embraces Moses (peace be upon them both). All three religions trace their roots to Abraham, and in fact the Qur'an and the Bible share and uphold many beliefs, practices and virtues in common -- belief in God, angels and the Day of Judgement, in the virtues of prayer, charity and fasting, and in the importance of truthfulness, patience, and love. Together, Christians and Muslims make up more than half the world's population, and rather than being ideological opposites as some people imagine, their faiths are in many ways the most alike of the world's major religions. Early Muslims were granted protection in Christian Abyssinia This common ground is one of the reasons the Prophet Muhammad (PBH) advised the weak and poor among his early followers to seek refuge in Christian Abyssinia (present-day Ethiopia) to escape persecution by the idolatrous Arab tribes, before Islam became established in Arabia. Muslim historians' account of the event succinctly conveys the heart of the relationship between the two faiths. When the corrupt leaders of Makkah pursued the Muslims into Africa and asked the Negus to return them, the Abyssinian ruler summoned the small community of Muslims, then asked them: 'What is this religion which has caused you to become separate from your people, though you have not entered my religion or that of any other folk around us?' Their spokesman Ja'far, Muhammad's young cousin, replied, 'O King, we were a people steeped in ignorance, worshipping idols, eating unslaughtered meat, committing abominations, and the strong would devour the weak. That is how we were until God sent us a Messenger from out of our midst, one whose lineage was known to us, and whose truthfulness, trustworthiness and integrity were renowned. He called us to God - that we should testify to His Oneness, and worship Him and renounce what we and our ancestors had worshipped in the way of stones and idols; and he commanded us to speak truly, to fulfil our promises, to respect the ties of kinship and the rights of our neighbours, and to refrain from crimes and bloodshed. So we worship God alone, setting nothing beside Him, counting as forbidden what He has forbidden and as permissible what He has allowed. For these reasons have our people turned against us, and persecuted us to try to make us forsake our religion and revert from the worship of God to the worship of idols. That is why we have come to your country, having chosen you above all others, We have been happy under your protection, and it is our hope, O King, that here with you we shall not suffer wrong.' His speech was translated by the royal interpreters, after which the Negus asked if they had with them any revelation their prophet had brought them. Ja'far then recited the following verses of the Qur'an, from the chapter entitled 'Mary': And make mention of Mary in the Scripture, when she withdrew from her people to a place towards the east, and secluded herself from them. We sent to her Our spirit (the angel Gabriel), and he appeared to her in the likeness of a perfect man. She said, 'I seek refuge in the Compassionate God from you; (do not come near me) if you fear the Lord.' He replied, 'I am none other than a messenger from your Lord, (to announce) to you the gift of a pure son.' She said, 'How can I have a son when no man has touched me, nor am I unchaste?' He said, 'Even so will it be; your Lord says, "This is an easy thing for Me. And We shall make him a sign for humanity and a mercy from Us. So it has been decreed."'(Qur'an 19: 16-21) Ja'far's recitation and the translation of these verses brought tears to the king's eyes. He responded, 'This has truly come from the same source as that which Jesus brought.' He granted the Muslims his protection. But the tribesmen of Makkah, furious that their plans and alliances had been frustrated, decided to rouse the king's ire against their monotheist cousins by playing up the differences between Christianity and Islam regarding Jesus. The king assembled them together once again and asked, 'What do you say about Jesus, son of Mary?' Ja'far replied, 'We say of him what our Prophet has brought us, namely that he is the servant of God and His Messenger, and His Spirit and Word which He cast into Mary, the blessed virgin.' The Negus then lifted his wooden staff and said, 'Jesus does not exceed what you have said by the length of this stick.' The bishops present objected to the king's judgment, but that did not deter him from granting the small Muslim community full protection, declaring, 'Not for mountains of gold would I harm a single one of you'. (Adapted from Muhammad: his life based on the earliest sources, by Martin Lings) That was Christianity's first encounter with Islam, and is how Islam first came to flourish -- in Africa, under the protection of a benevolent Christian king. Differing Christian views on Jesus It may surprise some to think of any Christians accepting a description of Jesus that fell short of 'only-begotten Son of God' and 'Saviour', but the Negus would have known of the theological arguments that had raged between various sects in the Eastern birthplace of Christianity for centuries after Christ. Christians had been divided roughly into two 'camps' from the beginning, which can perhaps best be described as people who followed the religion of Jesus, versus those who followed a religion about Jesus. The first is exemplified by his disciples, who lived as Jews, believed in One God, and followed the Law of Moses -- which Jesus had come 'not to destroy, but to fulfil' (Matthew 5:17). They had no concept of Jesus originating a new religion: they worshipped in the temple, and focused their efforts on spreading the good news to fellow Jews that their Messiah had come. This group further developed and became known as Arians, after Arius, a North African bishop who emphasized Jesus' human nature. The second was led by Paul, a charismatic speaker who had never met Jesus and had persecuted many Christians before his sudden conversion. Under his leadership, Pauline Christians directed their conversion efforts towards non-Jews and developed a theology foreign to the Old Testament, including belief in a Trinity (which had been prevalent among Romans, Egyptians and other pagans), an emphasis on Jesus as the 'son' of God, associated concepts of original sin and atonement, and the central dogma of Jesus' (supposed) crucifixion and resurrection. The Council of Nicea Disagreements between these and other sects had grown so great by the 4th century that the Roman Emperor Constantine decided to convene the Council of Nicea (Iznik, Turkey) in 325, to settle the matter of true belief 'once and for all'. During this event (in which Constantine's own trinitarian leanings were made known), the bishops of the Christian world gathered together for the first time to debate doctrine, and a draft creed espousing belief in a Trinity of 'Father, Son and Holy Ghost' received the most votes. Dissenting bishops were suddenly declared heretics; their writings were banned, and the gospels supporting them burned. That marked the birth of the Roman Catholic Church, state religion of the Roman empire. Tens of gospels and other writings that individual churches had been free to use, some which presented an alternative view of Jesus, were destroyed; only four were included in the New Testament collection, along with a heavy dose of Paul's writings. Despite this totalitarian approach to achieving 'religious unity', a small number of dissenting Christian sects survived, together with alternative gospels that were carefully hidden and only came to light in the 20th century. Viewed in historical context, the main theological differences between Muslims and Christians are largely the same differences that have been a major source of disagreement between Christians themselves from the beginning. These concern the nature and role of Jesus, his relationship with God, and how best to venerate and follow his example. Beloved servant, son of Mary; not 'Son' of God In contrast to the often contradictory passages of the New Testament, the Qur'an teaches monotheism, pure and simple: faith in One God, Creator and Sustainer of the universe, a Supreme Being without partners, associates or family members. There is no concept of an intermediary in Islam, whether priest or saviour, who must intercede between a human being and his Creator. Whatever individual Christians may understand by the term 'son' or 'Father' - whether in their minds the terms symbolize no more than a caring, loving relationship, or whether they regard belief in the Trinity as the key to avoiding eternal damnation - Islam considers that the Christian view in which Jesus is 'idolized' while God is 'humanized', obscures Jesus' invaluable role as master teacher and role model, while vastly underestimating God's transcendent majesty. It is impossible, indeed inconceivable to Muslims that the Almighty Creator of the Universe could appear in any human form, whole or in 'part', constrained by time and space. As the prophet Solomon is reported as saying after completing the Temple of Jerusalem, 'But will God really dwell on earth? The heavens, even the highest heaven, cannot contain You. How much less this temple I have built!' (I Kings 8:27) While the Qur'an, like the Bible, confirms that Jesus had no human father, it does not accept that this makes Jesus the son of God any more than it does Adam himself, who was created without either father or mother. Rather, when God decides something, 'He need only say to it 'Be!' and it is' (Q. 3:47). It is interesting to note that the term Jesus most often used of himself in the New Testament gospels is 'son of man' (in Hebrew, literally the 'son of Adam'); a term that for Muslims emphasizes his human nature. The phrase 'son of man' also appears in the Old Testament, where it underscores man's insignificance before God as well as the undeserved honour God has shown him: 'How then can a man be righteous before God?... If even the stars are not pure in His eyes, how much less man, who is but a maggot-- a son of man, who is only a worm!' (Job 25:4-6) 'When I consider Your heavens, the work of Your fingers, the moon and the stars, which You have set in place, What is man that You are mindful of him, the son of man that You care for him? You made him a little lower than the heavenly beings, and crowned him with glory and honour.' (Psalms 8:3-5) Christian arguments against the trinity Many Arians, Unitarians and other like-minded Christians have argued against the existence of a trinity, basing their reasoning on passages of the Bible itself. The lack of any mention of the word or concept in the Old Testament is one of the most important, as God surely would have found it important enough to mention to Moses and the many other prophets of old. Yet the cornerstone of the Jewish faith has always been, 'Hear, O Israel: the Lord our God, the Lord is One. You shall love the Lord your God with all your heart and with all your soul and with all your strength.' (Deut. 6:4), and, 'You shall have no other gods besides Me.' (Deut. 5:7) Jesus never taught his followers to worship him, and no record exists of him preaching about a trinity. 'By myself I can do nothing' (John 5:30), 'the Father is greater than I' (John 14:28), and many similar statements of his support pure monotheism, although other passages in the New Testament contradict it. Many Christians came to the conclusion that the Biblical texts must have been corrupted, as indeed the Qur'an asserts. The reader is referred to the writings of John Biddle, father of Unitarianism, as well as others such as John Milton, Sir Isaac Newton, John Locke, Thomas Jefferson, and Benjamin Franklin for examples of this kind of reasoning. The Qur'anic position on Jesus The Qur'an speaks of 'the Gospel' (Injil) as a Scripture revealed to Jesus by God, from which he preached, like the Torah of Moses. It is clear from early Christian history as well as modern Biblical studies that this original Scripture has been lost forever, and the fragments that remain in the form of various gospels have been corrupted so that they do not inspire confidence. The Qur'an, which was revealed partly in order to clarify points that had been misunderstood by previous religious groups, paints a brief but clear portrait of Jesus as Messenger of God. Responding to the views of an early Christian sect known as 'Adoptionists', who believed that God had 'adopted' Jesus, the Qur'an says: 'It does not befit (the majesty of) the Compassionate God that He should adopt a son. There is none in the heavens and the earth but shall come to the Compassionate One as a servant.' (Q. 19:92-93) The Qur'an further cautions: 'O People of the Scripture, do not exaggerate or go to extremes in your religion, or say anything about God but the truth. The Messiah, Jesus, son of Mary, was no more than an (honoured) Messenger of God, and His word that He imparted to Mary, and a spirit from Him. So believe in God and His Messengers and do not say, 'Three (in One).' Cease, for your own good! For your Lord is One God; Glory be to Him - (He is far) above having a son! All that is in the heavens and the earth belongs to Him. And God is Sufficient as Guardian (of the affairs of the universe). The Messiah would never scorn to be a servant of God, nor would the angels who are near (to Him)...' (Q. 4;171-2) The Angel Gabriel announced to the Virgin Mary the miraculous nature of the child she was to bear by saying: 'O Mary, God gives you the good news of a word from Him, whose name is the Messiah, Jesus, son of Mary, held in high honour in this world and the Next, and one of those brought near (to Him). 'He will speak to people in his cradle and in the prime of manhood, and he is one of the righteous... ...(God) will teach him the Scripture and wisdom, and the Torah and the Gospel, And (will appoint him as) a Messenger to the Children of Israel (saying), 'I come to you with a miracle from your Lord (as proof of my message). I will make the likeness of a bird for you out of clay; (then) I will breathe into it and, by God's permission, it shall become a (living) bird. And by God's permission I will give sight to those born blind, and heal the leper, and raise the dead to life. And I will inform you of what you eat and what you store in your houses. Surely that is a sign for you, if you are believers. 'And (I come to you) confirming (what has been sent down before me in) the Torah, and in order to make some of the things which were forbidden (in the past) lawful for you. I came to you with a sign from your Lord, so fear Allah and obey me. God is my Lord and your Lord, so worship Him. That is the straight path.' (Q. 3: 45-51) Some of these miracles are unfamiliar to modern readers of the Bible, but the accounts do appear in the 'Infancy Gospels', which enjoyed wide circulation in eastern churches for centuries. Jesus was saved by God, not crucified; his return is awaited by Muslims. Another point of contention surrounding the life of Jesus has been that of the crucifixion: whereas Christians have regarded it as an essential point of faith, Jews took it as proof that Jesus was not the promised Messiah, since God would not have allowed His chosen one to suffer such humiliation at the hands of his enemies. The Islamic position is that the crucifixion of Jesus never happened, although it appeared to. . We may note that the descriptions given in the New Testament gospels of the crucifixion cannot be considered accurate eyewitness accounts since, in their words, 'all the disciples fled' when Jesus was arrested. The work of modern Biblical scholars lends support to the Islamic position. They have established that the earliest (original) gospels make no mention of either crucifixion or resurrection, but focus instead on Jesus' teachings and miracles. What did happen to Jesus if he was not crucified? The Qur'an says: '(The Jews who rejected Jesus earned God's displeasure) because of their denying the truth and slandering Mary with a terrible accusation; and because of their (boasting) claim, 'We killed the Messiah, Jesus, son of Mary, God's Messenger!' They neither killed him nor crucified him, though it was made to appear that way to them. Those who disagree about this (matter) are full of doubts; they have no knowledge about it except to follow guesswork and speculation, but they certainly did not kill him. Rather, God raised him up to Himself; and God is ever Mighty, Wise. There is not one of the People of the Scripture who will not believe in him (as he should be believed in) before his death (e.g. after his Second Coming), and on the Day of Judgement he will be a witness against them.' (Q. 4:156-9) The most prevalent interpretation of these verses among Muslim scholars is that someone else (such as the traitor Judas Iscariot) was crucified instead, while Jesus was raised to heaven, as God often saves those beloved to Him. The Prophet Muhammad taught that Jesus will return to earth one day to rule in peace and justice, although Islamic prophecies on the subject differ from Christian ones. The historical Jesus: Messiah, Messenger, Wise Teacher and Prophet The Islamic view of Jesus is a logical and reasonable one, which is consistent with earlier Biblical teachings, and people today can relate to: he was a virtuous and wise teacher; an ascetic who taught by personal example and spoke without fear against corruption in high places; prophet and Messiah of the Jewish people, who healed and brought the dead to life by God's permission; an honoured Messenger of God. Rather than being sent to found a new religion, he came to 'breathe life' into and revitalise the interpretation of Mosaic Law. Teachings of Jesus as related by generations of Muslims Stories related by Muslims about Jesus are plentiful, and highlight his role as teacher of wisdom. A few examples are: Jesus said, 'Do not hang jewels around the necks of swine. Wisdom is finer than gems, and those who do not value it are worse than swine.' Jesus said, 'A plant can only grow in yielding earth, not on hard rock. In the same way, wisdom flourishes only in a humble heart, not one which is proud and unyielding.' (The above and many other sayings are related by the classical Muslim scholar Al-Ghazali in his Revival of the Religious Sciences. For translations of and information on other gospels, see The Complete Gospels, edited by R.J. Miller.) Sayings of the Prophet Muhammad relating to Jesus The Prophet Muhammad spoke with much affection and respect of Jesus, and taught Muslims to do the same. Relating some of Jesus' teachings, he said: 'Jesus, son of Mary, used to say, "Do not speak much without mentioning God, for your hearts will become hardened. A hard heart is far from God, if you only knew.' 'Do not look at the wrong actions of others as though you were lords; look at your own wrong actions as if you were slaves. And Muhammad emphasised the true and common message of Christianity and Islam, saying: 'Both in this world and in the Hereafter, I am the nearest of all people to Jesus, son of Mary. The prophets are paternal brothers; their mothers are different, but their religion is one.' Islam's invitation to Christians Many Arab Christians converted to Islam during and soon after Muhammad's lifetime because they recognised the simple truth of his message, and were convinced that New Testament passages foretelling the appearance of a 'Comforter' and other Biblical prophecies referred to him. Those who seek a truly historical prophet, whose life and teachings have been lovingly and meticulously preserved in remarkable detail, may wish to learn more about Muhammad -- another great leader who continues to be widely misunderstood, especially in the West. We conclude with the words of the Qur'an: Say, 'O People of the Scripture, let us) come to an agreement together: that we will worship none but God, and that we will not associate any (other god) with Him, and that none of us shall take others for lords besides God.' And if they turn away, then say, 'Bear witness that we are (the ones who have surrendered to Him, as) Muslims.' (Q. 3:64) Recommended Reading 'Ata ur-Rahim, M., Jesus: A Prophet of Islam (available in several editions) Miller, R. J. (ed.) The Complete Gospels (1992), Sonoma, CA. (USA), Polebridge Press Siddiqui, F., The Bible's Last Prophet (1995), Alexandria, VA (USA), Al-Saadawi Publications http://wamy.co.uk/jesus-in-islam/ Thank you From steve+comp.lang.python at pearwood.info Fri Apr 4 10:34:21 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Apr 2014 14:34:21 GMT Subject: Default mutable parameters in functions References: Message-ID: <533ec2ec$0$29993$c3e8da3$5496439d@news.astraweb.com> On Fri, 04 Apr 2014 10:00:25 -0400, random832 wrote: > On Thu, Apr 3, 2014, at 20:38, Mark Lawrence wrote: >> I just wish I had a quid for every time somebody expects something out >> of Python, that way I'd have retired years ago. At least here it's not >> accompanied by "as that's how it works in ". > > I can't imagine a language that would work that way. That seems like a failure of imagination to me. At least, I can't imagine anyone unable to imagine a language like that :-P > For one, it would > also imply that passing a value would change the default for future > calls even for non-mutable types. Not all programming languages distinguish between mutable and non-mutable types. Or for that matter even have types. But it's not hard to get that effect in Python, mutable or immutable doesn't matter: py> def spam(count, food="spam"): ... spam.__defaults__ = (food,) ... return food*count ... py> spam(5) 'spamspamspamspamspam' py> spam(3, 'eggs') 'eggseggseggs' py> spam(5) 'eggseggseggseggseggs' py> spam(5, 3) 15 py> spam(4) 12 Is it so unusual for a function to want to store persistent state which survives from one call to another but may also vary from time to time? Managing situations like that is one of the reasons OOP was invented! -- Steven D'Aprano http://import-that.dreamwidth.org/ From ian.g.kelly at gmail.com Fri Apr 4 12:02:21 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 4 Apr 2014 10:02:21 -0600 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: <87ioqpqvef.fsf@elektro.pacujo.net> References: <8084-1396540962-768613@sneakemail.com> <533e6e58$0$29993$c3e8da3$5496439d@news.astraweb.com> <87ioqpqvef.fsf@elektro.pacujo.net> Message-ID: On Apr 4, 2014 3:51 AM, "Marko Rauhamaa" wrote: > > >>> switch day casein ("Monday", "Thursday", "Wednesday", "Tuesday", > >>> "Friday"): > >>> gotowork = True > >>> continue > >>> casein ("Monday", "Thursday", "Wednesday", "Tuesday", "Friday"): > >>> daytype = "ferial" > >>> casein ("Saturday", "Sunday") > >>> daytype = "festive" > > That "casein" next to "switch" bugs me. Did I already propose: > > switch: local_sabbath() > case (1, 2, 3) as sabbath: > ... > case 6: > ... > else: > ... I don't get what this is intended to do. First, why is the expression in the first line after the colon? That doesn't match any existing block syntax (as you note it matches lambda, but that's an expression-level syntax). What's wrong with the much more natural "switch local_sabbath():"? Second, "as" clauses are used in other contexts for local assignment. What is the purpose of doing that here? How does this solve the problem of explicitly denoting case multiplicity? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanpierreda at gmail.com Fri Apr 4 12:21:14 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 4 Apr 2014 09:21:14 -0700 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: <12008-1396450399-453900@sneakemail.com> References: <12008-1396450399-453900@sneakemail.com> Message-ID: If one were to add switch into Python, wouldn't it be desirable to make a pattern matching switch (think the "match" or "case" construct from Haskell or ML)? Python currently has poor support for union/sum types in general, not just enumerations. It feels weird to add better support for enumerations while ignoring the broader use case. If a switch statement gets added to Python and I still need to examine ASTs by a long chain of if-elif and isinstance and so on I will cry. -- Devin On Wed, Apr 2, 2014 at 7:53 AM, Lucas Malor <3kywjyds5d at snkmail.com> wrote: > Hi all. I would proposeto you all a switch-case syntax for Python. I already read PEP 3103 and I'm not completely satisfied by any of the proposed solutions. This is my proposal: > > switch_stmt ::= "switch" identifier "case" expression_list ":" suite > ("case" expression_list ":" suite)* > ["else" ":" suite] > > or, more simply: > > > > switch x case var1: > .... > case var2: > ... > case var3: > ... > else: > ... > > > > Expression list should yield an iterable. The case suite will be executed if the variable of the identifier is a member of the iterable. > > For example, in a "switch x" statement, the code "case iterable: " is identical to "if x in iterable: " (or elif etc). So if you want to perform the same case block for more than one value, you have only to specify a tuple, a range etc. > I would suggest to add an exception for non-iterable variables, so that you don't have to write "case var, : " but simply "case var: " and it will be identical to "if x == var: ". It's a bit tricky but the alternative is ugly. > > Fallthrough is disabled by default. The continue keyword cause to skip all the remaining current case suite. The next case will be checked. You can't use the continue keyword in the else clause. > > Some random remarks: > 1. switch is on the same line of the first case. This will avoid any unpythonic syntaxes like: > switch x > case var1: > ... > > or > > switch x: > case var1: > ... > > 2. Fallthrough is disabled by default because IMHO it's what non-programmers expect and that's what programmer usually needs more. I don't think a switch with such a syntax needs a break statement. > > 3. As an alternative, the continue statement could be written only at the end of a case suite; it will be less powerful and not consistent with the other compound statements, but it will improve readability. > > 4. I decided to not use already existing keyword like "if" or "in", since it will be misleading and problematic for syntax highlighters. > > > Tell me what you think about. > -- > https://mail.python.org/mailman/listinfo/python-list From marko at pacujo.net Fri Apr 4 12:44:06 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 04 Apr 2014 19:44:06 +0300 Subject: Yet Another Switch-Case Syntax Proposal References: <8084-1396540962-768613@sneakemail.com> <533e6e58$0$29993$c3e8da3$5496439d@news.astraweb.com> <87ioqpqvef.fsf@elektro.pacujo.net> Message-ID: <87ppkx6o4p.fsf@elektro.pacujo.net> Ian Kelly : > On Apr 4, 2014 3:51 AM, "Marko Rauhamaa" wrote: >> switch: local_sabbath() >> case (1, 2, 3) as sabbath: >> ... >> case 6: >> ... >> else: >> ... > [...] > > What's wrong with the much more natural "switch local_sabbath():"? Consider: switch local_sabbath(): # bad case (1, 2, 3) as sabbath: ... Now Python "framing" requires that you place something between the first ":" and "case": switch local_sabbath(): # bad pass case (1, 2, 3) as sabbath: ... Placing the expression after the colon terminates the first colon cleanly. Also, the "lambda" precedent allows an expression to follow a colon; both "lambda" and my "switch" mandate that the expression stay on the same line with the colon. > Second, "as" clauses are used in other contexts for local assignment. > What is the purpose of doing that here? How does this solve the > problem of explicitly denoting case multiplicity? The "as" clause follows the precedent of the "try/except" statement. It removes the occasional annoyance in C: switch (next_char()) { case '\n': case '\r': putchar(???); : : : which forces you to introduce a temporary variable: char c; : : : c = next_char(); switch (c) { case '\n': case '\r': putchar(c); : : : It is most useful in the "default"/"else" branch: switch: q.pop() case 0: log_direction(0) return 1 case (90, 270) as angle: log_direction(angle) return 0 case 180: log_direction(180) return -1 else angle: log_direction(angle) return math.cos(angle * 2 * PI / 360) Marko From ian.g.kelly at gmail.com Fri Apr 4 13:01:48 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 4 Apr 2014 11:01:48 -0600 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <533e84ad$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e64ce$0$29993$c3e8da3$5496439d@news.astraweb.com> <533e84ad$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 4, 2014 at 4:08 AM, Steven D'Aprano wrote: > On Fri, 04 Apr 2014 02:13:13 -0600, Ian Kelly wrote: > >> On Fri, Apr 4, 2014 at 1:52 AM, Steven D'Aprano >> wrote: >>> py> from decimal import * >>> py> getcontext().prec = 16 >>> py> x = Decimal("0.7777777777787516") py> y = >>> Decimal("0.7777777777787518") py> (x + y) / 2 >>> Decimal('0.7777777777787515') >>> >>> "Guido, why can't Python do maths???" >> >> Well, you need to work within the system: >> >>>>> (5*x + 5*y) / 10 >> Decimal('0.7777777777787517') >> >> Actually, I have no idea whether that formula can be relied upon or the >> correctness of the above was just luck. > > > And what happens when x+y would have been calculated correctly, but one, > or both, of 5*x or 5*y loses catastrophically loses accuracy due to > overflow? > > py> x = 3.1e307 > py> y = 3.3e307 > py> (x+y)/2 > 3.2e+307 > py> (5*x+5*y)/10 > inf > > (I've used regular floats here out of laziness, the same principle > applies to Decimals -- there will be *some* number x which is finite, but > 5*x overflows to infinity.) I thought that Decimals had arbitrary-precision exponents, at least in the pure Python version. Turns out that's wrong; although the context.Emax can be set to any int in the pure Python version, it can't be removed entirely. One could just temporarily upgrade the Emax for the above calculation, but the pure Python version was made inconvenient to use voluntarily in CPython 3.3, and the C version has strict limits. In any event, the exponent limits for decimals are much higher than for floats (the default Emax is 999999, and it can be set roughly within the limits of C integer precision), so any case where you'll get overflow with a Decimal is already far beyond the point where you'd have gotten overflow with a float. From ian.g.kelly at gmail.com Fri Apr 4 13:55:11 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 4 Apr 2014 11:55:11 -0600 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: <87ppkx6o4p.fsf@elektro.pacujo.net> References: <8084-1396540962-768613@sneakemail.com> <533e6e58$0$29993$c3e8da3$5496439d@news.astraweb.com> <87ioqpqvef.fsf@elektro.pacujo.net> <87ppkx6o4p.fsf@elektro.pacujo.net> Message-ID: On Fri, Apr 4, 2014 at 10:44 AM, Marko Rauhamaa wrote: > Consider: > > switch local_sabbath(): # bad > case (1, 2, 3) as sabbath: > ... I'm not overly fond of that either. That's why I liked the OP's choice to put the first case in the switch statement. > Now Python "framing" requires that you place something between the first > ":" and "case": > > switch local_sabbath(): # bad > pass > case (1, 2, 3) as sabbath: > ... That's absurd. Granted that omitting the pass doesn't match any existing syntax, but that doesn't mean it *must* be done that way. > Placing the expression after the colon terminates the first colon > cleanly. Also, the "lambda" precedent allows an expression to follow a > colon; both "lambda" and my "switch" mandate that the expression stay on > the same line with the colon. But in the case of the lambda *expression*, the following expression is effectively the entire "suite" of the lambda "clause", mirroring the form of a def statement. If "local_sabbath()" is treated as the suite of the switch *statement*, then "Python framing" tells us the same construct could be written like this: switch: local_sabbath() case 1: ... And if that's allowed, then why not this? switch: if username == "ozzy": black_sabbath() else: local_sabbath() case 1: ... Or: switch: for sabbath in list_of_sabbaths: sabbath case 1: ... Or even: switch: pass case 1: ... The intent of the first two are fairly clear, but they're way out of scope for a switch statement. I don't even intuitively know what to do with the last two. The point here is that the switch expression really ought to be a single expression contained in the switch header, not a suite. >> Second, "as" clauses are used in other contexts for local assignment. >> What is the purpose of doing that here? How does this solve the >> problem of explicitly denoting case multiplicity? > > The "as" clause follows the precedent of the "try/except" statement. It > removes the occasional annoyance in C: > > switch (next_char()) { > case '\n': > case '\r': > putchar(???); > : : : > > which forces you to introduce a temporary variable: How is the target identifier of the "as" not a temporary variable? Try/except statements and with statements use "as" keywords to capture values that may not otherwise be available in scope for assignment. Except assigns the exception instance that was just caught, and with assigns whatever arbitrary object was returned by the context manager's __enter__ method. With switch there is no need for that; just do this: char = next_char() switch next_char: case in '\n\r': print(char) Similarly there is no need for the "if" or "while" statements to support an "as" keyword, as in: while next_char() as char: print(char) There are good reasons why the language generally does not allow assignments in non-assignment statements, which is what your "as" is trying to do. The Pythonic way to write that loop is: while True: char = next_char() if not char: break print(char) Which is at least as ungraceful as assigning the switch variable before the switch statement. From sg552 at hotmail.co.uk Fri Apr 4 14:37:56 2014 From: sg552 at hotmail.co.uk (Rotwang) Date: Fri, 04 Apr 2014 19:37:56 +0100 Subject: Scoping rules for class definitions Message-ID: Hi all. I thought I had a pretty good grasp of Python's scoping rules, but today I noticed something that I don't understand. Can anyone explain to me why this happens? >>> x = 'global' >>> def f1(): x = 'local' class C: y = x return C.y >>> def f2(): x = 'local' class C: x = x return C.x >>> f1() 'local' >>> f2() 'global' From ian.g.kelly at gmail.com Fri Apr 4 14:55:07 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 4 Apr 2014 12:55:07 -0600 Subject: Scoping rules for class definitions In-Reply-To: References: Message-ID: On Fri, Apr 4, 2014 at 12:37 PM, Rotwang wrote: > Hi all. I thought I had a pretty good grasp of Python's scoping rules, but > today I noticed something that I don't understand. Can anyone explain to me > why this happens? > >>>> x = 'global' >>>> def f1(): > x = 'local' > class C: > y = x > return C.y > >>>> def f2(): > x = 'local' > class C: > x = x > return C.x > >>>> f1() > 'local' >>>> f2() > 'global' Start by comparing the disassembly of the two class bodies: >>> dis.dis(f1.__code__.co_consts[2]) 3 0 LOAD_NAME 0 (__name__) 3 STORE_NAME 1 (__module__) 6 LOAD_CONST 0 ('f1..C') 9 STORE_NAME 2 (__qualname__) 4 12 LOAD_CLASSDEREF 0 (x) 15 STORE_NAME 3 (y) 18 LOAD_CONST 1 (None) 21 RETURN_VALUE >>> dis.dis(f2.__code__.co_consts[2]) 3 0 LOAD_NAME 0 (__name__) 3 STORE_NAME 1 (__module__) 6 LOAD_CONST 0 ('f2..C') 9 STORE_NAME 2 (__qualname__) 4 12 LOAD_NAME 3 (x) 15 STORE_NAME 3 (x) 18 LOAD_CONST 1 (None) 21 RETURN_VALUE The only significant difference is that the first uses LOAD_CLASSDEREF, which I guess is the class version of LOAD_DEREF for loading values from closures, at line 4 whereas the second uses LOAD_NAME. So the first one knows about the x in the nonlocal scope, whereas the second does not and just loads the global (since x doesn't yet exist in the locals dict). Now why doesn't the second version also use LOAD_CLASSDEREF? My guess is because it's the name of a local; if it were referenced a second time in the class then the second LOAD_CLASSDEREF would again get the x from the nonlocal scope, which would be incorrect. From harrismh777 at gmail.com Fri Apr 4 16:58:29 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 04 Apr 2014 15:58:29 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/4/14 3:20 AM, Mark Lawrence wrote: > On 04/04/2014 03:29, Mark H Harris wrote: >> >> Now, about Python2. It has not died. It appears to be 'useful'. >> {snip} >> > > For a lot of people, if it ain't broke, don't fix it. > hi Mark, yes that's my point. I have heard rumors of python2.8? At some point I would expect that the Cpython interpreter would 'freeze' and no one would fix it any longer. I have a serious question, namely, why does the Cpython community continue to suppport two interpreters rather than asking the Cpython user-base to migrate to Cpython3? Oh, I have another serious question about implementations. I'm not sure about (50) implementations, but I know that Jython and IronPython are serious contenders (although, I have not, nor probably will, use them). Are the other implementation communities *also* supporting two versions of the language? Is there a Jython2 &also a Jython3 ? marcus From harrismh777 at gmail.com Fri Apr 4 17:33:08 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 04 Apr 2014 16:33:08 -0500 Subject: converting strings to hex References: <533E1B2E.5040608@gmail.com> Message-ID: On 4/4/14 1:16 AM, James Harris wrote: > YMMV but I thought the OP had done a good job before asking for help and > then asked about only a tiny bit of it. Some just post a question! Indeed they do. Its a little like negotiating with terrorists. As soon as you negotiate with the first one, you then must negotiate with all of them. Bad plan. The OP was soooo close, that to give him the help is immoral for two reasons: 1) it deprives him of the satisfaction of accomplishing the solution to the puzzle himself, and 2) it deprives the instructor (whoever she is) of the teachable moment. There is something she is trying to get Dave to learn, and she really *does* want him to go through the entire exercise on his own. Other than that, I give the OP credit for honesty and the good 'ol college try. But next time I'd like to see Dave post the problem (and his own solution) and then let the professional Cpython community pipe up on enhancements, or challenges. That way the OP learns twice. > You might find this interesting. > > http://sundry.wikispaces.com/transcript-2001 Indeed I do. I was thirteen when Odyssey came out. I was so impressed with the ship, and yet so disappointed with HAL. My favorite line, "I'm sorry, Dave, I'm afraid I can't do that," *must* have the word 'afraid' in there; the HAL 9000 not only had mental illness, &will, but also classic controlled emotion... but HAL's soft confident assured voice pattern was fabulous, wasn't it? My second favorite line was, "Look Dave, I can see you're really upset about this," as Dave was unplugging HAL's neural net. Classic. It was not until my later career at IBM did I realize that 'HAL' was one letter -0ff from 'IBM'; just never thought about it before. Hilarious. Wasn't it interesting that Kubrick and Clarke were concerned about machines acquiring will and emotion (or mental illness) before anyone got those von Neumann processors to 'think' in the first place? Which, of course, because of the negative answer to the Entscheidungsproblem is not possible. This was a passion of Alan Turing; machines thinking I mean. We're going to find that thinking machine IS possible, but that the system is going to require multiple quantum processors running together (out of phase with one another) in order to be self-aware. I think it will happen in my life-time; I'm encouraged with the work so far... I'm sorry, Dave, I'm afraid I can't do that... ... Look Dave, I can see you're really upset about this... marcus From ian.g.kelly at gmail.com Fri Apr 4 17:40:55 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 4 Apr 2014 15:40:55 -0600 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 4, 2014 at 2:58 PM, Mark H Harris wrote: > On 4/4/14 3:20 AM, Mark Lawrence wrote: >> >> On 04/04/2014 03:29, Mark H Harris wrote: >>> >>> >>> Now, about Python2. It has not died. It appears to be 'useful'. >>> {snip} >>> >> >> For a lot of people, if it ain't broke, don't fix it. >> > > hi Mark, yes that's my point. I have heard rumors of python2.8? The Python 2.8 release schedule is documented in PEP 404: http://legacy.python.org/dev/peps/pep-0404/ > At some > point I would expect that the Cpython interpreter would 'freeze' and no one > would fix it any longer. I have a serious question, namely, why does the > Cpython community continue to suppport two interpreters rather than asking > the Cpython user-base to migrate to Cpython3? 2.6 and 2.7 exist to ease the pain of migration, which is far from trivial. Eventually users still on 2.x will need to upgrade, but you can't force them to do it on your own schedule. That path will just end up driving them to another language, or to a fork of 2.7. > Oh, I have another serious question about implementations. I'm not sure > about (50) implementations, but I know that Jython and IronPython are > serious contenders (although, I have not, nor probably will, use them). > > Are the other implementation communities *also* supporting two versions of > the language? Is there a Jython2 &also a Jython3 ? There is no Jython3 or IronPython3 yet. PyPy is currently supporting both 2.7 and 3.2. From breamoreboy at yahoo.co.uk Fri Apr 4 17:50:34 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 04 Apr 2014 22:50:34 +0100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/04/2014 21:58, Mark H Harris wrote: > On 4/4/14 3:20 AM, Mark Lawrence wrote: >> On 04/04/2014 03:29, Mark H Harris wrote: >>> >>> Now, about Python2. It has not died. It appears to be 'useful'. >>> {snip} >>> >> >> For a lot of people, if it ain't broke, don't fix it. >> > > hi Mark, yes that's my point. I have heard rumors of python2.8? At some > point I would expect that the Cpython interpreter would 'freeze' and no > one would fix it any longer. I have a serious question, namely, why does > the Cpython community continue to suppport two interpreters rather than > asking the Cpython user-base to migrate to Cpython3? > > Oh, I have another serious question about implementations. I'm not sure > about (50) implementations, but I know that Jython and IronPython are > serious contenders (although, I have not, nor probably will, use them). > > Are the other implementation communities *also* supporting two versions > of the language? Is there a Jython2 &also a Jython3 ? > > marcus You could answer all of the above for yourself if you were to use your favourite search engine. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From harrismh777 at gmail.com Fri Apr 4 18:07:11 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 04 Apr 2014 17:07:11 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533F2D0F.2080806@gmail.com> On 4/4/14 4:50 PM, Mark Lawrence wrote: > You could answer all of the above for yourself if you were to use your > favourite search engine. hi Mark, yeah, condescending as that is, been there done that. See this link as just one example: http://blog.startifact.com/posts/python28-discussion-channel-on-freenode.html Follow the nextpost-> links for a while... at least the first two. You'll get a flavor for what I'm asking about. Its always better to get a straight answer from the core people than to rely on rumors and fork discussions found on google. PEP 404 is hilarious; I missed that one. marcus From harrismh777 at gmail.com Fri Apr 4 18:07:11 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 04 Apr 2014 17:07:11 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533F2D0F.2080806@gmail.com> On 4/4/14 4:50 PM, Mark Lawrence wrote: > You could answer all of the above for yourself if you were to use your > favourite search engine. hi Mark, yeah, condescending as that is, been there done that. See this link as just one example: http://blog.startifact.com/posts/python28-discussion-channel-on-freenode.html Follow the nextpost-> links for a while... at least the first two. You'll get a flavor for what I'm asking about. Its always better to get a straight answer from the core people than to rely on rumors and fork discussions found on google. PEP 404 is hilarious; I missed that one. marcus From rosuav at gmail.com Fri Apr 4 18:36:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Apr 2014 09:36:43 +1100 Subject: converting strings to hex In-Reply-To: References: <533E1B2E.5040608@gmail.com> Message-ID: On Sat, Apr 5, 2014 at 8:33 AM, Mark H Harris wrote: > On 4/4/14 1:16 AM, James Harris wrote: >> >> YMMV but I thought the OP had done a good job before asking for help and >> then asked about only a tiny bit of it. Some just post a question! > > > Indeed they do. Its a little like negotiating with terrorists. As soon as > you negotiate with the first one, you then must negotiate with all of them. > Bad plan. What, you treat student programmers like terrorists?!? Ouch. > The OP was soooo close, that to give him the help is immoral for two > reasons: 1) it deprives him of the satisfaction of accomplishing the > solution to the puzzle himself, and 2) it deprives the instructor (whoever > she is) of the teachable moment. There is something she is trying to get > Dave to learn, and she really *does* want him to go through the entire > exercise on his own. I strongly disagree. If someone is asking for a hint, it's because s/he is trying to learn. I'm always willing to help someone learn, regardless of whether they're going through a course or currently employed or whatever. Sometimes a small hint can be obtained from the interpreter itself; but often, it takes a measure of experience to grok (one of the differences between the expert and the inexperienced is how quickly a traceback can be read - an expert can often go straight to the line with the problem); a hint from another Python programmer can be immensely helpful, as it can include advice as well as a hard "this works, that doesn't". ChrisA From rosuav at gmail.com Fri Apr 4 18:39:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Apr 2014 09:39:50 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <533F2D0F.2080806@gmail.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> Message-ID: On Sat, Apr 5, 2014 at 9:07 AM, Mark H Harris wrote: > On 4/4/14 4:50 PM, Mark Lawrence wrote: > >> You could answer all of the above for yourself if you were to use your >> favourite search engine. > > > hi Mark, yeah, condescending as that is, been there done that. > > Its always better to get a straight answer from the core people than to > rely on rumors and fork discussions found on google. Yes, because python-list responses are *so* much more reliable than official statements on python.org, which are easily found with a Google search. Or a DuckDuckGo search. Or a Bing search. Or probably even gopher, we're not partisan here. ChrisA From rosuav at gmail.com Fri Apr 4 18:47:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Apr 2014 09:47:13 +1100 Subject: Default mutable parameters in functions In-Reply-To: <533ec2ec$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <533ec2ec$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 5, 2014 at 1:34 AM, Steven D'Aprano wrote: > But it's not hard to get that effect in Python, mutable or immutable > doesn't matter: > > > py> def spam(count, food="spam"): > ... spam.__defaults__ = (food,) > ... return food*count > ... > py> spam(5) > 'spamspamspamspamspam' > py> spam(3, 'eggs') > 'eggseggseggs' > py> spam(5) > 'eggseggseggseggseggs' > py> spam(5, 3) > 15 > py> spam(4) > 12 > > > Is it so unusual for a function to want to store persistent state which > survives from one call to another but may also vary from time to time? > Managing situations like that is one of the reasons OOP was invented! Maybe it'd be clearer if we change the names around. def signal(sig, handler=None): ret = signals[sig] if handler: signals[sig] = handler return ret This neatly merges the definitions of signal.signal() and signal.getsignal(); per the docs: """ signal.getsignal(signalnum) Return the current signal handler for the signal signalnum. The returned value may be a callable Python object, or one of the special values signal.SIG_IGN, signal.SIG_DFL or None. Here, signal.SIG_IGN means that the signal was previously ignored, signal.SIG_DFL means that the default way of handling the signal was previously in use, and None means that the previous signal handler was not installed from Python. signal.signal(signalnum, handler) Set the handler for signal signalnum to the function handler. handler can be a callable Python object taking two arguments (see below), or one of the special values signal.SIG_IGN or signal.SIG_DFL. The previous signal handler will be returned (see the description of getsignal() above). (See the Unix man page signal(2).) """ (Incidentally, SIG_IGN and SIG_DFL are just integers. Are they targets for enumification?) >>> signal(SIGINT, ctrl_c_handler) --> whatever the default is >>> signal(SIGINT) ctrl_c_handler >>> signal(SIGINT, other_ctrl_c_handler) ctrl_c_handler >>> signal(SIGINT) other_ctrl_c_handler I think that's a perfectly reasonable API... it just doesn't happen to be how Python works by default. ChrisA From harrismh777 at gmail.com Fri Apr 4 18:52:06 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 04 Apr 2014 17:52:06 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> Message-ID: <533F3796.1000807@gmail.com> On 4/4/14 5:39 PM, Chris Angelico wrote: > Yes, because python-list responses are *so* much more reliable than > official statements on python.org, {/sarcasm off} ... from some responders. The discussion following such posts is also *much* more valuable, too. IMHO Python.org is the political place to start; but its not much good after that, in regards the forking of 2.7 --> 2.8 As Ian points out, you can't expect a complete migration on the PSF schedule (2->3), because of the fear|panic of a fork. So, comp.lang.python is the best place to find out where the Cpython community is, and where they expect to go (for that discussion). I realize that many of Cpython's user-base will never read comp.lang.python, and then the Internet is an open field for trying to discern where 'they' are at, and where 'they' want to go. What I'm trying to say is that I tap many resources (comp.lang.python is just one of them) and I'm going to tap that source even though I also tap the Internet with a google search (and others). Eeyore doesn't like to be bugged, by double line spaces, nor by questions. What's the point of having a comp.lang.python news list if its not open for simple questions of opinion? Yes, I know google is my friend. Comp.lang.python should be my friend too. (and others) marcus From harrismh777 at gmail.com Fri Apr 4 18:52:06 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 04 Apr 2014 17:52:06 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> Message-ID: <533F3796.1000807@gmail.com> On 4/4/14 5:39 PM, Chris Angelico wrote: > Yes, because python-list responses are *so* much more reliable than > official statements on python.org, {/sarcasm off} ... from some responders. The discussion following such posts is also *much* more valuable, too. IMHO Python.org is the political place to start; but its not much good after that, in regards the forking of 2.7 --> 2.8 As Ian points out, you can't expect a complete migration on the PSF schedule (2->3), because of the fear|panic of a fork. So, comp.lang.python is the best place to find out where the Cpython community is, and where they expect to go (for that discussion). I realize that many of Cpython's user-base will never read comp.lang.python, and then the Internet is an open field for trying to discern where 'they' are at, and where 'they' want to go. What I'm trying to say is that I tap many resources (comp.lang.python is just one of them) and I'm going to tap that source even though I also tap the Internet with a google search (and others). Eeyore doesn't like to be bugged, by double line spaces, nor by questions. What's the point of having a comp.lang.python news list if its not open for simple questions of opinion? Yes, I know google is my friend. Comp.lang.python should be my friend too. (and others) marcus From rosuav at gmail.com Fri Apr 4 18:57:22 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Apr 2014 09:57:22 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <533F3796.1000807@gmail.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> <533F3796.1000807@gmail.com> Message-ID: On Sat, Apr 5, 2014 at 9:52 AM, Mark H Harris wrote: > On 4/4/14 5:39 PM, Chris Angelico wrote: >> >> Yes, because python-list responses are *so* much more reliable than >> official statements on python.org, > > > {/sarcasm off} > > ... from some responders. The discussion following such posts is also *much* > more valuable, too. IMHO > > Python.org is the political place to start; but its not much good after > that, in regards the forking of 2.7 --> 2.8 Official statements on python.org are the perfect place to find out whether or not there'll be a 2.8. And that's exactly what PEP 404 details. > As Ian points out, you can't expect a complete migration on the PSF schedule > (2->3), because of the fear|panic of a fork. So, comp.lang.python is the > best place to find out where the Cpython community is, and where they expect > to go (for that discussion). What *is* the PSF schedule? Have you read that? Do you know when the PSF expects all code to transition from Py2 to Py3? Because you can find that on python.org too (at least some estimates). > What I'm trying to say is that I tap many resources (comp.lang.python is > just one of them) and I'm going to tap that source even though I also tap > the Internet with a google search (and others). > > Eeyore doesn't like to be bugged, by double line spaces, nor by questions. > What's the point of having a comp.lang.python news list if its not open for > simple questions of opinion? Yes, I know google is my friend. > Comp.lang.python should be my friend too. You're certainly free to ask. And we're free to tell you to use a search engine to find authoritative responses :) ChrisA From harrismh777 at gmail.com Fri Apr 4 19:00:57 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 04 Apr 2014 18:00:57 -0500 Subject: converting strings to hex References: <533E1B2E.5040608@gmail.com> Message-ID: On 4/4/14 5:36 PM, Chris Angelico wrote: > If someone is asking for a hint, it's because > s/he is trying to learn. I'm always willing to help someone learn, > regardless of whether they're going through a course or currently > employed or whatever. Sometimes a small hint can be obtained from the > interpreter itself; but often, it takes a measure of experience to > grok (one of the differences between the expert and the inexperienced > is how quickly a traceback can be read - an expert can often go > straight to the line with the problem); a hint from another Python > programmer can be immensely helpful, as it can include advice as well > as a hard "this works, that doesn't". I accept that. It really depends case-by-case at what point the person asks for help ( tension is really a good teacher sometimes ) and at what level the help is provided ( give the hint, but maintain the tension ). I particularly agree with your statement above in every venue except the educational venue where the break-over moment (the teachable moment) is NOT the moment being queried ! If the student is NOT able to discover on their own that one 'moment' the teachable moment may be lost forever, and the student(s) never have the opportunity to visit that moment again. Now, was this one of those for Dave, who knows. Beats me. I do appreciate your disagreement, and I think you have a good point. marcus From breamoreboy at yahoo.co.uk Fri Apr 4 19:16:48 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 05 Apr 2014 00:16:48 +0100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <533F3796.1000807@gmail.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> <533F3796.1000807@gmail.com> Message-ID: On 04/04/2014 23:52, Mark H Harris wrote: > > As Ian points out, you can't expect a complete migration on the PSF > schedule (2->3), because of the fear|panic of a fork. So, > comp.lang.python is the best place to find out where the Cpython > community is, and where they expect to go (for that discussion). > Fear/panic of a fork, where did that come from? It's certainly the first I've ever heard of it. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From roy at panix.com Fri Apr 4 19:38:20 2014 From: roy at panix.com (Roy Smith) Date: Fri, 04 Apr 2014 19:38:20 -0400 Subject: Default mutable parameters in functions References: <1396620025.10391.102762569.6DD0D52A@webmail.messagingengine.com> Message-ID: In article , Dennis Lee Bieber wrote: > On Fri, 04 Apr 2014 10:00:25 -0400, random832 at fastmail.us declaimed the > following: > > > > >I can't imagine a language that would work that way. For one, it would > >also imply that passing a value would change the default for future > >calls even for non-mutable types. > > Some early FORTRAN compilers purportedly had problems with, for > example: > > X = 1 > call mutant(1) > Y = 1 > > where > > subroutine mutant(y) > > y = y + 1 > return > > meant that Y now held the value of 2 -- that is, literals were stored in > mutable memory, and since FORTRAN passes by reference, the address of the > literal is passed, and the assignment changed the "constant". Problem? I always assumed it was a feature :-) From steve+comp.lang.python at pearwood.info Fri Apr 4 20:00:54 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Apr 2014 00:00:54 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533f47b5$0$29993$c3e8da3$5496439d@news.astraweb.com> On Fri, 04 Apr 2014 15:58:29 -0500, Mark H Harris wrote: > Oh, I have another serious question about implementations. I'm not sure > about (50) implementations, Here's a list. Which ones you count as actual implementations of Python and which are not may be a matter of opinion. (Do translators count? Supersets and subsets of the language? How many changes can one make before you have a completely different language? I haven't included obviously different languages like Cobra and Delight.) Berp, Brython, CLPython, CPython, CapPython, ChinesePython, Compyler, Copperhead, Cython, HoPe, HotPy, IronPython, Jython, Kivy, Mypy, Mython, Nuitka, Numba, Parakeet, Parallel Python, Perthon, Pippy, Psyco, Py4A, PyMite, PyMT, PyPad, PyPy, PyQNX, PyVM, Pycorn, Pyjamas, Pynie, Pystachio, Pyston, Python for .NET, Python for OS/2, Python for S60, Python-iPod, Python2C, Pythonce, Pythonium Core, Pythran, QPython, RapydScript, Shedskin, Skulpt, Stackless, TinyPy, Typhon, UnPython, Unladen Swallow, Vyper, WPython As I said, some of these may be abandoned, obsolete, experimental, or even vapourware. Some are probably just ports of CPython to another platform rather than completely independent implementations. The "big four" are CPython, IronPython, Jython and PyPy, although Stackless is still maintained and in active use as part of the EVE Online game. Stackless is older than all of them except CPython itself. Cython is a superset of Python, but it is capable of running pure Python code, so it counts as a Python compiler, and is in very active development and use. Nuitika is a static compiler written by a developer willing to go against the conventional wisdom that JIT compilers are the way to go for dynamic languages like Python, and he claims to have impressive speedups. > but I know that Jython and IronPython are > serious contenders (although, I have not, nor probably will, use them). If you are using a Debian-based system, it is trivial to install them via apt-get or aptitude: sudo aptitude install jython ironpython > Are the other implementation communities *also* supporting two versions > of the language? Is there a Jython2 &also a Jython3 ? Not Jython or IronPython yet. As far as I know, the implementations which support Python 3 are CPython, Cython, Kivy, Nuitika and PyPy. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Fri Apr 4 20:20:38 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Apr 2014 00:20:38 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e64ce$0$29993$c3e8da3$5496439d@news.astraweb.com> <533e84ad$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533f4c55$0$29993$c3e8da3$5496439d@news.astraweb.com> On Fri, 04 Apr 2014 11:01:48 -0600, Ian Kelly wrote: > On Fri, Apr 4, 2014 at 4:08 AM, Steven D'Aprano > wrote: >> On Fri, 04 Apr 2014 02:13:13 -0600, Ian Kelly wrote: >> >>> On Fri, Apr 4, 2014 at 1:52 AM, Steven D'Aprano >>> wrote: >>>> py> from decimal import * >>>> py> getcontext().prec = 16 >>>> py> x = Decimal("0.7777777777787516") py> y = >>>> Decimal("0.7777777777787518") py> (x + y) / 2 >>>> Decimal('0.7777777777787515') >>>> >>>> "Guido, why can't Python do maths???" >>> >>> Well, you need to work within the system: >>> >>>>>> (5*x + 5*y) / 10 >>> Decimal('0.7777777777787517') >>> >>> Actually, I have no idea whether that formula can be relied upon or >>> the correctness of the above was just luck. >> >> >> And what happens when x+y would have been calculated correctly, but >> one, or both, of 5*x or 5*y loses catastrophically loses accuracy due >> to overflow? >> >> py> x = 3.1e307 >> py> y = 3.3e307 >> py> (x+y)/2 >> 3.2e+307 >> py> (5*x+5*y)/10 >> inf >> >> (I've used regular floats here out of laziness, the same principle >> applies to Decimals -- there will be *some* number x which is finite, >> but 5*x overflows to infinity.) > > I thought that Decimals had arbitrary-precision exponents, at least in > the pure Python version. Turns out that's wrong; although the > context.Emax can be set to any int in the pure Python version, it can't > be removed entirely. One could just temporarily upgrade the Emax for > the above calculation, but the pure Python version was made inconvenient > to use voluntarily in CPython 3.3, and the C version has strict limits. > > In any event, the exponent limits for decimals are much higher than for > floats (the default Emax is 999999, and it can be set roughly within the > limits of C integer precision), so any case where you'll get overflow > with a Decimal is already far beyond the point where you'd have gotten > overflow with a float. If you write the most obvious code that works -- usually a good thing in computing, but not always so in numeric computing -- and calculate (x+y)/2, with Decimal, most of the time the result will be correct but sometimes it won't be. In addition to that problem, if the addition overflows you will get an inf instead of the correct answer. But if you write the "tricky" code (5*x+5*y)/10, you may eliminate the failure cases, but at the cost that while it will still overflow to inf in the same cases as before, now it will also overflow in a whole lot of cases that *would have worked correctly* if only you had written the obvious code. There's no free lunch here. You might argue that this doesn't matter, since the problem values for x and y have been moved from "scattered values everywhere" to only(?) "values so huge that surely nobody will care". Apart, of course, those people who do care. Still, I'm sympathetic to the idea that swapping "average doesn't work right" for "really humongous numbers overflow sooner than they otherwise would have" counts as a win. But of course, neither of us know what other problems this "tricky" code will introduce. Perhaps it fixes the failures for *some* values of x and y, but introduces a different set of failures for *other* values of x and y. I'm not quite good enough at numeric analysis to rule that out, although I haven't tried very hard. (The division by 10 is obviously just a shift, so its error is at most 0.5 ULP. But I'm not sure about the multiplications by 5.) But all of this is missing the really important point. Isn't the (supposed) move to Decimal-by-default supposed to *simplify* numeric calculations, not complicate them? Do we really expect the average non- expert to write (5*x+5*y)/10 instead of the obvious (x+y)/2? There's no doubt that binary floating point calculations are tricky beasts, and while IEEE-754 semantics mean that they just about always do the right thing, still, serious numeric work is half advanced mathematics and half voodoo. Base-10 floats don't improve that situation, they make it worse. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Fri Apr 4 21:51:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Apr 2014 12:51:44 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <533f47b5$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533f47b5$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 5, 2014 at 11:00 AM, Steven D'Aprano wrote: > As I said, some of these may be abandoned, obsolete, experimental, or > even vapourware. Some are probably just ports of CPython to another > platform rather than completely independent implementations. Python for OS/2 is definitely just a port. It's built from as close to unmodified sources as possible, and doesn't (deliberately) add/remove any features or anything. On the other hand, there's a Python for Android which may be a separate project. (Or is that the Py4A you referred to?) ChrisA From davea at davea.name Fri Apr 4 22:21:01 2014 From: davea at davea.name (Dave Angel) Date: Fri, 4 Apr 2014 22:21:01 -0400 (EDT) Subject: Default mutable parameters in functions References: <1396620025.10391.102762569.6DD0D52A@webmail.messagingengine.com> Message-ID: Dennis Lee Bieber Wrote in message: > On Fri, 04 Apr 2014 10:00:25 -0400, random832 at fastmail.us declaimed the > following: > >> >>I can't imagine a language that would work that way. For one, it would >>also imply that passing a value would change the default for future >>calls even for non-mutable types. > > Some early FORTRAN compilers purportedly had problems with, for > example: > > X = 1 > call mutant(1) > Y = 1 > > where > > subroutine mutant(y) > > y = y + 1 > return > > meant that Y now held the value of 2 -- that is, literals were stored in > mutable memory, and since FORTRAN passes by reference, the address of the > literal is passed, and the assignment changed the "constant". I can confirm that, first hand. In late 60's, CDC 6400, I deliberately wrote code to exploit that. Not for production of course. -- DaveA From xeonmailinglist at gmail.com Fri Apr 4 22:18:34 2014 From: xeonmailinglist at gmail.com (xeon Mailinglist) Date: Fri, 4 Apr 2014 19:18:34 -0700 (PDT) Subject: process do not join? Message-ID: <080019ac-0afa-4b2e-b015-d5550bb47576@googlegroups.com> I am trying to debug my program that launch processes to run a function to copy data between hosts located really far away from each other. The end of my function are in the orders.py and mergedirs.py. >From this point onwards, in is python code. The problem is that this code hangs in the last instruction "forking()", instead of my program continue. The call of my function were made with: outputs = parmap(mergeDirs, args). This is my parmap function. It seems that the function mergeDirs ends, but the process does not join. I checked that the mergeDirs is working properly, because I ran the code without processes, and it works fine. I don't know what is happening. How can I debug this problem? def parmap(f, X): pipe = [Pipe() for x in X] # 2 - what is happening with the tuples (c,x) and (p, c)? proc = [Process(target=spawn(f), args=(c, x)) for x, (p, c) in zip(X, pipe)] #[p.start() for p in proc] for p in proc: print("Spawn") p.start() #[p.join() for p in proc] for p in proc: print("Joining") p.join() return [p.recv() for (p, c) in pipe] Copy data time: 104.863273859 orders.py(99): return cluster mergedirs.py(48): return (new_included, command, poutput) spawn.py(7): pipe.close() process.py(259): exitcode = 0 process.py(261): util._exit_function() --- modulename: util, funcname: _exit_function util.py(303): info('process shutting down') --- modulename: util, funcname: info util.py(77): if _logger: util.py(304): debug('running all "atexit" finalizers with priority >= 0') --- modulename: util, funcname: debug util.py(73): if _logger: util.py(305): _run_finalizers(0) --- modulename: util, funcname: _run_finalizers util.py(257): if _finalizer_registry is None: util.py(263): if minpriority is None: util.py(266): f = lambda p : p[0][0] is not None and p[0][0] >= minpriority util.py(268): items = [x for x in _finalizer_registry.items() if f(x)] util.py(269): items.sort(reverse=True) util.py(271): for key, finalizer in items: util.py(279): if minpriority is None: util.py(307): if current_process() is not None: --- modulename: process, funcname: current_process process.py(63): return _current_process util.py(318): for p in active_children(): --- modulename: process, funcname: active_children process.py(69): _cleanup() --- modulename: process, funcname: _cleanup process.py(78): for p in list(_current_process._children): process.py(70): return list(_current_process._children) util.py(323): for p in active_children(): --- modulename: process, funcname: active_children process.py(69): _cleanup() --- modulename: process, funcname: _cleanup process.py(78): for p in list(_current_process._children): process.py(70): return list(_current_process._children) util.py(327): debug('running the remaining "atexit" finalizers') --- modulename: util, funcname: debug util.py(73): if _logger: util.py(328): _run_finalizers() --- modulename: util, funcname: _run_finalizers util.py(257): if _finalizer_registry is None: util.py(263): if minpriority is None: util.py(264): f = lambda p : p[0][0] is not None util.py(268): items = [x for x in _finalizer_registry.items() if f(x)] util.py(269): items.sort(reverse=True) util.py(271): for key, finalizer in items: util.py(279): if minpriority is None: util.py(280): _finalizer_registry.clear() process.py(278): util.info('process exiting with exitcode %d' % exitcode) --- modulename: util, funcname: info util.py(77): if _logger: process.py(279): return exitcode forking.py(127): sys.stdout.flush() forking.py(128): sys.stderr.flush() forking.py(129): os._exit(code) From xeonmailinglist at gmail.com Fri Apr 4 22:35:07 2014 From: xeonmailinglist at gmail.com (xeon Mailinglist) Date: Fri, 4 Apr 2014 19:35:07 -0700 (PDT) Subject: process do not join? In-Reply-To: <080019ac-0afa-4b2e-b015-d5550bb47576@googlegroups.com> References: <080019ac-0afa-4b2e-b015-d5550bb47576@googlegroups.com> Message-ID: <4ae7ebeb-7758-477a-b039-7fce5beab4ba@googlegroups.com> This log came when I launched the command: python -m trace --trace myclass.py On Saturday, April 5, 2014 3:18:34 AM UTC+1, xeon Mailinglist wrote: > I am trying to debug my program that launch processes to run a function to copy data between hosts located really far away from each other. The end of my function are in the orders.py and mergedirs.py. > > > > From this point onwards, in is python code. The problem is that this code hangs in the last instruction "forking()", instead of my program continue. > > > > The call of my function were made with: outputs = parmap(mergeDirs, args). This is my parmap function. > > > > It seems that the function mergeDirs ends, but the process does not join. I checked that the mergeDirs is working properly, because I ran the code without processes, and it works fine. > > > > I don't know what is happening. How can I debug this problem? > > > > def parmap(f, X): > > pipe = [Pipe() for x in X] > > # 2 - what is happening with the tuples (c,x) and (p, c)? > > proc = [Process(target=spawn(f), args=(c, x)) > > for x, (p, c) in zip(X, pipe)] > > #[p.start() for p in proc] > > for p in proc: > > print("Spawn") > > p.start() > > #[p.join() for p in proc] > > for p in proc: > > print("Joining") > > p.join() > > return [p.recv() for (p, c) in pipe] > > > > > > > > > > Copy data time: 104.863273859 > > orders.py(99): return cluster > > mergedirs.py(48): return (new_included, command, poutput) > > spawn.py(7): pipe.close() > > process.py(259): exitcode = 0 > > process.py(261): util._exit_function() > > --- modulename: util, funcname: _exit_function > > util.py(303): info('process shutting down') > > --- modulename: util, funcname: info > > util.py(77): if _logger: > > util.py(304): debug('running all "atexit" finalizers with priority >= 0') > > --- modulename: util, funcname: debug > > util.py(73): if _logger: > > util.py(305): _run_finalizers(0) > > --- modulename: util, funcname: _run_finalizers > > util.py(257): if _finalizer_registry is None: > > util.py(263): if minpriority is None: > > util.py(266): f = lambda p : p[0][0] is not None and p[0][0] >= minpriority > > util.py(268): items = [x for x in _finalizer_registry.items() if f(x)] > > util.py(269): items.sort(reverse=True) > > util.py(271): for key, finalizer in items: > > util.py(279): if minpriority is None: > > util.py(307): if current_process() is not None: > > --- modulename: process, funcname: current_process > > process.py(63): return _current_process > > util.py(318): for p in active_children(): > > --- modulename: process, funcname: active_children > > process.py(69): _cleanup() > > --- modulename: process, funcname: _cleanup > > process.py(78): for p in list(_current_process._children): > > process.py(70): return list(_current_process._children) > > util.py(323): for p in active_children(): > > --- modulename: process, funcname: active_children > > process.py(69): _cleanup() > > --- modulename: process, funcname: _cleanup > > process.py(78): for p in list(_current_process._children): > > process.py(70): return list(_current_process._children) > > util.py(327): debug('running the remaining "atexit" finalizers') > > --- modulename: util, funcname: debug > > util.py(73): if _logger: > > util.py(328): _run_finalizers() > > --- modulename: util, funcname: _run_finalizers > > util.py(257): if _finalizer_registry is None: > > util.py(263): if minpriority is None: > > util.py(264): f = lambda p : p[0][0] is not None > > util.py(268): items = [x for x in _finalizer_registry.items() if f(x)] > > util.py(269): items.sort(reverse=True) > > util.py(271): for key, finalizer in items: > > util.py(279): if minpriority is None: > > util.py(280): _finalizer_registry.clear() > > process.py(278): util.info('process exiting with exitcode %d' % exitcode) > > --- modulename: util, funcname: info > > util.py(77): if _logger: > > process.py(279): return exitcode > > forking.py(127): sys.stdout.flush() > > forking.py(128): sys.stderr.flush() > > forking.py(129): os._exit(code) From tjreedy at udel.edu Fri Apr 4 23:04:50 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 Apr 2014 23:04:50 -0400 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <533F2D0F.2080806@gmail.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> Message-ID: On 4/4/2014 6:07 PM, Mark H Harris wrote: > On 4/4/14 4:50 PM, Mark Lawrence wrote: > >> You could answer all of the above for yourself if you were to use your >> favourite search engine. > > hi Mark, yeah, condescending as that is, been there done that. Since there *are* people who use python-list as a substitute, it does not hurt to mention searches done, the result, along with what you still want to know. > Its always better to get a straight answer from the core people than > to rely on rumors and fork discussions found on google. I am a core developer and I am 99.99% sure that the core developers will not produce a CPython 2.8. For one thing we will likely do instead, see http://legacy.python.org/dev/peps/pep-0466/ -- Terry Jan Reedy From rosuav at gmail.com Fri Apr 4 23:22:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Apr 2014 14:22:57 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> Message-ID: On Sat, Apr 5, 2014 at 2:04 PM, Terry Reedy wrote: > I am a core developer and I am 99.99% sure that the core developers will not > produce a CPython 2.8. For one thing we will likely do instead, see > http://legacy.python.org/dev/peps/pep-0466/ There's also been talk of a potential compiler change for the Windows builds, which otherwise only ever happens at minor releases. Is there a PEP to link people to about that? ChrisA From rustompmody at gmail.com Fri Apr 4 23:42:01 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 4 Apr 2014 20:42:01 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8eaca90c-cd43-40b7-92c3-ad8676a11cbd@googlegroups.com> On Saturday, April 5, 2014 2:28:29 AM UTC+5:30, Mark H. Harris wrote: > hi Mark, yes that's my point. I have heard rumors of python2.8? At some > point I would expect that the Cpython interpreter would 'freeze' and no > one would fix it any longer. I have a serious question, namely, why does > the Cpython community continue to suppport two interpreters rather than > asking the Cpython user-base to migrate to Cpython3? Computer-hobbyists and computer-professionals are quite different sets of people. Are you aware That people FORTRAN, COBOL, mainframes are still in use? That people deep in those would not be amused if their systems suddenly stopped working? That some of the above people have not clue that the world around is not exactly in the same state they see it? And that YOU would not be amused if your credit card suddenly stopped working? (very likely running in some cloistered COBOL mainframe env). IOW: 1. Python is a fun language; its also a serious language 2. Python is not as old as FORTRAN and COBOL but at 20 years its not exactly young either 3. Its reached so far because core-devs behave responsibly towards different constituencies From tjreedy at udel.edu Sat Apr 5 00:10:33 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 05 Apr 2014 00:10:33 -0400 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> Message-ID: On 4/4/2014 11:22 PM, Chris Angelico wrote: > On Sat, Apr 5, 2014 at 2:04 PM, Terry Reedy wrote: >> I am a core developer and I am 99.99% sure that the core developers will not >> produce a CPython 2.8. For one thing we will likely do instead, see >> http://legacy.python.org/dev/peps/pep-0466/ > > There's also been talk of a potential compiler change for the Windows > builds, which otherwise only ever happens at minor releases. Is there > a PEP to link people to about that? Not that I know of. -- Terry Jan Reedy From harrismh777 at gmail.com Sat Apr 5 00:10:54 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 04 Apr 2014 23:10:54 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> <533F3796.1000807@gmail.com> Message-ID: On 4/4/14 6:16 PM, Mark Lawrence wrote: > Fear/panic of a fork, where did that come from? It's certainly the > first I've ever heard of it. > hi Mark, it came from Ian; or, my interpretation of Ian. It comes out on the net too (from various places). Here is Ian's quote, then my comment: > Eventually users still on 2.x will need to upgrade, but you > can't force them to do it on your own schedule. That path will just > end up driving them to another language, or to a fork of 2.7. The sentiment behind this last quote is essentially fear (and that is natural). Its basically the tension between (I'm speaking as the royal we here) we don't want folks to be driven away from Cpython as a language, and we don't want them to fork the Cpython interpreter, so we'll take a very casual and methodically conservative approach to nudging people towards a Cpython3 migration route ( I am speaking not for the community, just hypothetically trying to get at the gist of Ian's quote); please forgive me if I didn't quite get it. I spent most of the afternoon reading this: > http://python-notes.curiousefficiency.org/en/latest/python3/questions_and_answers.html This doc is long, thorough in detail, and mostly complete. Its a great read. The migration is not trivial, and it can't happen in one fell swoop, either. marcus From harrismh777 at gmail.com Sat Apr 5 00:18:51 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 04 Apr 2014 23:18:51 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> Message-ID: On 4/4/14 10:04 PM, Terry Reedy wrote: > I am a core developer and I am 99.99% sure that the core developers will > not produce a CPython 2.8. For one thing we will likely do instead, see > http://legacy.python.org/dev/peps/pep-0466/ > Thanks Terry. The back-port sounds great; I find the "Rejected alternatives" interesting. I think this must be where I was getting the gist that 2.8 might be an option--- just all the discussion that went on trying to figure out what to do with the security issues. I notice a good bit on unicode there too. marcus From harrismh777 at gmail.com Sat Apr 5 00:31:39 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 04 Apr 2014 23:31:39 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533f47b5$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/4/14 7:00 PM, Steven D'Aprano wrote: > > Berp, Brython, CLPython, CPython, CapPython, ChinesePython, Compyler, > Copperhead, Cython, HoPe, HotPy, IronPython, Jython, Kivy, Mypy, Mython, > Nuitka, Numba, Parakeet, Parallel Python, Perthon, Pippy, Psyco, Py4A, > PyMite, PyMT, PyPad, PyPy, PyQNX, PyVM, Pycorn, Pyjamas, Pynie, > Pystachio, Pyston, Python for .NET, Python for OS/2, Python for S60, > Python-iPod, Python2C, Pythonce, Pythonium Core, Pythran, QPython, > RapydScript, Shedskin, Skulpt, Stackless, TinyPy, Typhon, UnPython, > Unladen Swallow, Vyper, WPython Thanks for this list. > > As I said, some of these may be abandoned, obsolete, experimental, or > even vapourware. Some are probably just ports of CPython to another > platform rather than completely independent implementations. The only one I've used regularly is QPython (on Android) which is apparently a 2.7.2 port. Its relatively slow but 'useful' because its obviously highly mobile, which gives me the opportunity to code-on-the-go, or try a new idea in those awkward times when only a cell-phone is convenient for the venue. >> but I know that Jython and IronPython are >> serious contenders (although, I have not, nor probably will, use them). > > If you are using a Debian-based system, it is trivial to install them via > apt-get or aptitude: > > sudo aptitude install jython ironpython Its has always seemed to me that Java or C++ would be better suited to creating python. I wonder will C always be the standard canonical PSF python interpreter base language? Has the C python community considered making the standard base language Java or C++ ? marcus From rosuav at gmail.com Sat Apr 5 00:40:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Apr 2014 15:40:24 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> <533F3796.1000807@gmail.com> Message-ID: On Sat, Apr 5, 2014 at 3:10 PM, Mark H Harris wrote: > we don't want folks to be driven away from Cpython as a language, and we > don't want them to fork the Cpython interpreter, so we'll take a very casual > and methodically conservative approach to nudging people towards a Cpython3 > migration route If it's too much work to make the changes to move something from Python 2.7 to Python 3.3, it's *definitely* too much work to rewrite it in a different language. There would have to be some strong other reason for shifting, especially since there's a 2to3 but not a PytoRuby. And forking is a pretty huge job; someone's gotta maintain it. What's more likely is that, once python.org stops maintaining Python 2.x at all, people will just stay on 2.7.9 or whatever the last version is, without any bugfixes. Companies like Red Hat will be looking at security patches (which is what PEP 466 is all about), but only to the extent that they have people willing to put in the work to make and test them. After that, it'll be like running old versions of anything else: you weigh the cost of migrating to the new version against the risk of exploits if you don't move. It's that simple. ChrisA From rosuav at gmail.com Sat Apr 5 00:49:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Apr 2014 15:49:47 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533f47b5$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 5, 2014 at 3:31 PM, Mark H Harris wrote: > Its has always seemed to me that Java or C++ would be better suited to > creating python. I wonder will C always be the standard canonical PSF python > interpreter base language? Has the C python community considered making the > standard base language Java or C++ ? Java you know about (Jython); what's the advantage of C++ over C? A Python interpreter needs to do broadly this: 1) Parse a text file into an abstract syntax tree 2) Compile the AST into bytecode 3) Execute the bytecode: 3a) Manage object lifetimes and garbage collection 3b) Perform lower-level calls 3c) Efficiently handle namespaces etc Java has an advantage over C in that 3a can be done by the JVM. (At least, I believe that's how Jython does it; a Python object is backed by a Java object, and every Python object that references another Python object is backed by a corresponding reference to the corresponding Java object, so the JVM knows about all object lifetimes.) C++ doesn't have that, at least not normally (and I've never really liked most C++ garbage collectors - maybe there's a good one that I've not yet met), so all you'd really gain is 3b, in that you could conveniently pass jobs down to a lower-level C++ library. (Java also gains this advantage - or maybe disadvantage, as you can easily interface to other Java code but not so easily to C code.) Most programming languages make it easy to talk to C code, ergo most libraries are written for C interfaces, ergo most programming languages don't need C++. The only case I can think of is Google's V8 interpreter (ECMAScript), which uses C++ bindings to handle scoping; it's nice and easy as long as you embed V8 in a C++ program, and not so easy if you're going back and forth between the two languages; at that point, it basically reverts to a C-like interface, so there's no advantage. ChrisA From ian.g.kelly at gmail.com Sat Apr 5 01:02:40 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 4 Apr 2014 23:02:40 -0600 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> <533F3796.1000807@gmail.com> Message-ID: On Fri, Apr 4, 2014 at 10:10 PM, Mark H Harris wrote: > On 4/4/14 6:16 PM, Mark Lawrence wrote: >> >> Fear/panic of a fork, where did that come from? It's certainly the >> first I've ever heard of it. >> > > hi Mark, it came from Ian; or, my interpretation of Ian. It comes out on the > net too (from various places). Here is Ian's quote, then my comment: > > >> Eventually users still on 2.x will need to upgrade, but you >> can't force them to do it on your own schedule. That path will just >> end up driving them to another language, or to a fork of 2.7. > > > The sentiment behind this last quote is essentially fear (and that is > natural). Its basically the tension between (I'm speaking as the royal we > here) we don't want folks to be driven away from Cpython as a language, and > we don't want them to fork the Cpython interpreter, so we'll take a very > casual and methodically conservative approach to nudging people towards a > Cpython3 migration route ( I am speaking not for the community, just > hypothetically trying to get at the gist of Ian's quote); please forgive me > if I didn't quite get it. A fork is undesirable because it fragments the community. I don't think "fear" or "panic" are the right words for it. From zhangpeipei812 at outlook.com Sat Apr 5 01:02:59 2014 From: zhangpeipei812 at outlook.com (=?UTF-8?B?5byg5L2p5L2p?=) Date: Sat, 5 Apr 2014 13:02:59 +0800 Subject: About threading.Thread Message-ID: Hello guys: I have an question on threading.Thread My code is here: File1: a.py import threading import time def hello(): while True: print('hello') threads = threading.enumerate() for thread in threads: print(thread.getName()) time.sleep(3) def fun(): a = threading.Thread(target=hello(), name='hello') print("a file: I won't display!") a.start() File2: b.py import time from a import fun fun() print("b file: I won't display!") When I run: python b.py (python version: 2.7.6, 3.3.5, 3.4.0) It seems that threading.Thread() in file1 not create a new thread but use MainThread. Anyone can explain this ? Thank you in advance. Best regards. peipei From harrismh777 at gmail.com Sat Apr 5 01:02:58 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 05 Apr 2014 00:02:58 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <8eaca90c-cd43-40b7-92c3-ad8676a11cbd@googlegroups.com> Message-ID: On 4/4/14 10:42 PM, Rustom Mody wrote: > > Computer-hobbyists and computer-professionals are quite different sets of people. > I know its just a gut feel, and I know there are a lot of lurkers here too, but it seems that there are *way* more folks from the professional camp on comp.lang.python than otherwise. Do you have a gut feel for the % of hobbyists vs. professionals participating here? > Are you aware > That [people?] FORTRAN, COBOL, mainframes are still in use? Well, the S390 is still in use (running gnu/linux these days) and the z series machines from IBM. FORTRAN and COBOL have government (military) niche. I remember during the Y2K problem COBOL coders were working their butts off. There is a 2014 standard doc replacing the 2002 standard, believe. The last time I used FORTRAN IV was in about 1977, on the System360-44, but GNU still supports it, and as far as I know it still has a wide user group (mostly academic). I have it on my system here, but I don't use it. > 1. Python is a fun language; its also a serious language A very serious language; yes, its fun too. > 2. Python is not as old as FORTRAN and COBOL but at 20 years its not exactly young either It won't have its day until it becomes ubiquitous... and its coming! As the gnu/linux numbers continue to climb, more everyday is C python becoming ubiquitous. I'm hoping the ubiquitous version is C python 3.4+ > 3. Its reached far because core-devs behave responsibly > towards different constituencies I think its because the language is flexible, extensible, &powerful (batteries included), and is supported by a world-wide community of software engineers (both amateur and professional) who are committed to its development and adoption world-wide. The PEP process has had a lot to due with this (and not to ape the BDFL) it has had a lot to due with some Dutch genius. ;-) However, knowing your user-base is certainly important. Its always a problem (any venue, any environment) to try to please everyone. Tough choices have to be made. The C python community does a pretty good job of this. Python-ideas and the PEP process are a unique and unparalleled strategy for enhancement. Very nice. Having said that, I do believe that the migration to C python3 has been too conservative. Nobody wants to maintain a fork, not really. I don't think its something anyone should be afraid of. Somebody should put a date on C python 3.4+ migration and cut off support for 2.7.x/ Its just an opinion. If 'Twisted' isn't ready for 3.x, well, they need to get ready. That's also just an opinion. marcus From ian.g.kelly at gmail.com Sat Apr 5 01:07:43 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 4 Apr 2014 23:07:43 -0600 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> <533F3796.1000807@gmail.com> Message-ID: On Fri, Apr 4, 2014 at 10:40 PM, Chris Angelico wrote: > On Sat, Apr 5, 2014 at 3:10 PM, Mark H Harris wrote: >> we don't want folks to be driven away from Cpython as a language, and we >> don't want them to fork the Cpython interpreter, so we'll take a very casual >> and methodically conservative approach to nudging people towards a Cpython3 >> migration route > > If it's too much work to make the changes to move something from > Python 2.7 to Python 3.3, it's *definitely* too much work to rewrite > it in a different language. There would have to be some strong other > reason for shifting, especially since there's a 2to3 but not a > PytoRuby. For whatever the current project is, yes -- if there's no route to Python 3 then they will simply be stuck on Python 2.7 indefinitely. However, if Python is perceived as a language that doesn't provide backward compatibility and long-term maintainability via some migration path, then users will be less likely to pick Python for their *next* project. From harrismh777 at gmail.com Sat Apr 5 01:11:58 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 05 Apr 2014 00:11:58 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> <533F3796.1000807@gmail.com> Message-ID: On 4/4/14 11:40 PM, Chris Angelico wrote: > If it's too much work to make the changes to move something from > Python 2.7 to Python 3.3, it's *definitely* too much work to rewrite > it in a different language. Totally, no doubt. > There would have to be some strong other > reason for shifting, especially since there's a 2to3 but not a > PytoRuby. And forking is a pretty huge job; someone's gotta maintain > it. I agree there, too. That's why I don't think anyone should worry about a new program, nor about a fork. Nobody really wants to fork a programming language, esp one like python. It takes an entire team of dedicated people to support it--- jut not worth trying to do that. > What's more likely is that, once python.org stops maintaining > Python 2.x at all, people will just stay on 2.7.9 or {snip} > After that, it'll be like running old versions of > anything else: you weigh the cost of migrating to the new version > against the risk of exploits if you don't move. It's that simple. Yup, totally agree. So, just do it. Probably after 3.4 will be the right time. Beats me. marcus From rosuav at gmail.com Sat Apr 5 01:22:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Apr 2014 16:22:26 +1100 Subject: About threading.Thread In-Reply-To: References: Message-ID: On Sat, Apr 5, 2014 at 4:02 PM, ??? wrote: > def fun(): > a = threading.Thread(target=hello(), name='hello') > It seems that threading.Thread() in file1 not create a new thread but use MainThread. > Anyone can explain this ? > Thank you in advance. Suggestion: Cut the code down until you find the exact bit that's showing a problem. You don't need two files for this; in fact, all you need is your definition of hello, the call to threading.Thread(), and a print statement after it, which you'll see doesn't happen. The problem here is that you're already *calling* hello() in the argument list. Before threading.Thread() gets called, its arguments get fully evaluated... which calls hello(), which infinitely loops. That's why it's getting called on the main thread. To spin off a thread that will call hello(), take the parentheses off: a = threading.Thread(target=hello, name='hello') That'll pass a function, rather than the return value of that function, and then Thread can call that. ChrisA From rosuav at gmail.com Sat Apr 5 01:24:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Apr 2014 16:24:53 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <8eaca90c-cd43-40b7-92c3-ad8676a11cbd@googlegroups.com> Message-ID: On Sat, Apr 5, 2014 at 4:02 PM, Mark H Harris wrote: > I know its just a gut feel, and I know there are a lot of lurkers here > too, but it seems that there are *way* more folks from the professional camp > on comp.lang.python than otherwise. Do you have a gut feel for the % of > hobbyists vs. professionals participating here? Impossible to say. However, I would suggest that the more prolific posters are going to be those who use Python more (and thus it's worth investing more time in), which is going to skew the post stats towards the professional end of the spectrum. ChrisA From harrismh777 at gmail.com Sat Apr 5 01:23:58 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 05 Apr 2014 00:23:58 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533f47b5$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533F936E.1000102@gmail.com> On 4/4/14 11:49 PM, Chris Angelico wrote: > On Sat, Apr 5, 2014 at 3:31 PM, Mark H Harris wrote: >> Its has always seemed to me that Java or C++ would be better suited to >> creating python. I wonder will C always be the standard canonical PSF python >> interpreter base language? Has the C python community considered making the >> standard base language Java or C++ ? > > what's the advantage of C++ over C? > A Python interpreter needs to do broadly this: > > 1) Parse a text file into an abstract syntax tree > 2) Compile the AST into bytecode > 3) Execute the bytecode: > 3a) Manage object lifetimes and garbage collection > 3b) Perform lower-level calls > 3c) Efficiently handle namespaces etc > The only advantage of C++ over C is polymorphism, really. There are in my view only three reasons to even use C++: 1) the iostream library, and 2) polymorphism, and 3) operator overloading. If you need to do all three, then C++ is a really good candidate. I am still thinking about the concept of unifying Number; Number as a C++ abstract base class, and an entire Class hierarchy which carries through making *any* Number just work. The ability of the C++ compiler to construct and maintain the virtual function tables would be an advantage. Operator overloading (and maybe templates) would make C++ advantageous also. Guido told me that the modern C python is object oriented. Operator overloading is a big part of this. It seems to me that a modern object oriented language would best be implemented with a true object oriented base language, C++ rather than C. I have always questioned this, just curious why the decision for C was made--- historically, methodologically, and maybe scientifically. It would be tons of work, but maybe not as much as one might think, initially. marcus From ben+python at benfinney.id.au Sat Apr 5 01:29:57 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 05 Apr 2014 16:29:57 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <8eaca90c-cd43-40b7-92c3-ad8676a11cbd@googlegroups.com> Message-ID: <85d2gw2vje.fsf@benfinney.id.au> Chris Angelico writes: > I would suggest that the more prolific posters are going to be those > who use Python more (and thus it's worth investing more time in), > which is going to skew the post stats towards the professional end of > the spectrum. It's also plausible that the more prolific posters are those who spend *less* time actually coding, and instead spend their free time being prolific in this forum. Other explanations are plausible. Any of them could be contributing factors in any mixture. Without actual data ? which neither of us has on this matter ? all of these hypotheses are unfounded speculation. Let's not draw any conclusions in the absence of evidence. -- \ ?I went to the cinema, it said ?Adults: $5.00, Children $2.50?. | `\ So I said ?Give me two boys and a girl.?? ?Steven Wright | _o__) | Ben Finney From harrismh777 at gmail.com Sat Apr 5 01:37:36 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 05 Apr 2014 00:37:36 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> <533F3796.1000807@gmail.com> Message-ID: On 4/5/14 12:02 AM, Ian Kelly wrote: > A fork is undesirable because it fragments the community. I don't > think "fear" or "panic" are the right words for it. > Yes. I get that. I think what is desired (just thinking out loud from my own vantage point) is a unified community, but also a foundation of perceived permanence. The PSF establishes this to a certain extend, as well the PEP process, and to some extent the communities willingness to support two interpreters. It looks like C python is here to stay; I can count on it for my projects years into the future. From rosuav at gmail.com Sat Apr 5 01:55:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Apr 2014 16:55:42 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <533F936E.1000102@gmail.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533f47b5$0$29993$c3e8da3$5496439d@news.astraweb.com> <533F936E.1000102@gmail.com> Message-ID: On Sat, Apr 5, 2014 at 4:23 PM, Mark H Harris wrote: > The only advantage of C++ over C is polymorphism, really. There are in my > view only three reasons to even use C++: 1) the iostream library, and 2) > polymorphism, and 3) operator overloading. If you need to do all three, then > C++ is a really good candidate. The iostream library actually gives you very little over the stdio functions (printf, FILE*, etc), beyond that they're arguably easier to use. (I say "arguably" because there've been plenty of times when I've been writing C++ code and just not bothered with cout, finding printf the better option. Sometimes you find yourself arguing with cout and it's not worth arguing with.) Operator overloading, ultimately, is just this: x + y // becomes x.operator+(y) // or operator+(x,y) When you're actually writing C++ code, that's a huge advantage in readability. But if you're writing an interpreter for another language, there's no benefit; you may as well not bother. Maybe it'd be of value if you want to write a Python-to-C++ translator that then lets you compile the resulting C++ code, but only if you want the C++ code to be readable. So all you're left with is polymorphism. Well, big problem: Python and C++ have distinctly different semantics for multiple inheritance. It wouldn't be possible, much less practical, to try to implement Python's MRO on top of a C++ class structure, other than by basically ignoring the whole structure and using it much the same way PyObject * is used in the existing C code. > I am still thinking about the concept of unifying Number; Number as a C++ > abstract base class, and an entire Class hierarchy which carries through > making *any* Number just work. The ability of the C++ compiler to construct > and maintain the virtual function tables would be an advantage. Operator > overloading (and maybe templates) would make C++ advantageous also. The virtual function tables don't cater for the MRO, see above. But even with simple single inheritance, the effort of creating a new class at run-time would be quite a problem; remember, 'class' in C++ is a declaration to the compiler, but 'class' in Python is an executable statement. > Guido told me that the modern C python is object oriented. Operator > overloading is a big part of this. It seems to me that a modern object > oriented language would best be implemented with a true object oriented base > language, C++ rather than C. I have always questioned this, just curious > why the decision for C was made--- historically, methodologically, and maybe > scientifically. Python is object oriented, and it has operator overloading. But it's possible to implement operator overloading in a language that doesn't have it - it's not OOPs all the way down, turtle-style - so somewhere there has to be that boundary, and building one object oriented language on top of another doesn't necessarily actually give many benefits. ChrisA From rosuav at gmail.com Sat Apr 5 01:57:08 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Apr 2014 16:57:08 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <85d2gw2vje.fsf@benfinney.id.au> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <8eaca90c-cd43-40b7-92c3-ad8676a11cbd@googlegroups.com> <85d2gw2vje.fsf@benfinney.id.au> Message-ID: On Sat, Apr 5, 2014 at 4:29 PM, Ben Finney wrote: > Chris Angelico writes: > >> I would suggest that the more prolific posters are going to be those >> who use Python more (and thus it's worth investing more time in), >> which is going to skew the post stats towards the professional end of >> the spectrum. > > It's also plausible that the more prolific posters are those who spend > *less* time actually coding, and instead spend their free time being > prolific in this forum. Heh. Very true. > Other explanations are plausible. Any of them could be contributing > factors in any mixture. > > Without actual data ? which neither of us has on this matter ? all of > these hypotheses are unfounded speculation. Let's not draw any > conclusions in the absence of evidence. Not to mention that there's not a lot of difference between an unemployed professional coder and a serious hobbyist. :) ChrisA From ben+python at benfinney.id.au Sat Apr 5 02:01:21 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 05 Apr 2014 17:01:21 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> <533F3796.1000807@gmail.com> Message-ID: <858urk2u32.fsf@benfinney.id.au> Mark H Harris writes: > On 4/5/14 12:02 AM, Ian Kelly wrote: > > A fork is undesirable because it fragments the community. I don't > > think "fear" or "panic" are the right words for it. > > Yes. I get that. So, you get that ?fear? and ?panic? are not the right words to characterise the undesirability Ian describes. Did you use those words anyway, despite knowing they're not the right words to use? Or did you think they were the right words to use, and now you've changed your position? I don't see where that happened, so I'm confused. Or do you still think they are the correct words to use, but now wish to distance yourself from that position? This may seem trivial, but I'm trying to get a handle on what it is you mean to communicate, when your stated position in one message conflicts with your stated position only a few messages earlier. -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, but | `\ where will we find an open tattoo parlor at this time of | _o__) night?? ?_Pinky and The Brain_ | Ben Finney From harrismh777 at gmail.com Sat Apr 5 01:23:58 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 05 Apr 2014 00:23:58 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533f47b5$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533F936E.1000102@gmail.com> On 4/4/14 11:49 PM, Chris Angelico wrote: > On Sat, Apr 5, 2014 at 3:31 PM, Mark H Harris wrote: >> Its has always seemed to me that Java or C++ would be better suited to >> creating python. I wonder will C always be the standard canonical PSF python >> interpreter base language? Has the C python community considered making the >> standard base language Java or C++ ? > > what's the advantage of C++ over C? > A Python interpreter needs to do broadly this: > > 1) Parse a text file into an abstract syntax tree > 2) Compile the AST into bytecode > 3) Execute the bytecode: > 3a) Manage object lifetimes and garbage collection > 3b) Perform lower-level calls > 3c) Efficiently handle namespaces etc > The only advantage of C++ over C is polymorphism, really. There are in my view only three reasons to even use C++: 1) the iostream library, and 2) polymorphism, and 3) operator overloading. If you need to do all three, then C++ is a really good candidate. I am still thinking about the concept of unifying Number; Number as a C++ abstract base class, and an entire Class hierarchy which carries through making *any* Number just work. The ability of the C++ compiler to construct and maintain the virtual function tables would be an advantage. Operator overloading (and maybe templates) would make C++ advantageous also. Guido told me that the modern C python is object oriented. Operator overloading is a big part of this. It seems to me that a modern object oriented language would best be implemented with a true object oriented base language, C++ rather than C. I have always questioned this, just curious why the decision for C was made--- historically, methodologically, and maybe scientifically. It would be tons of work, but maybe not as much as one might think, initially. marcus From harrismh777 at gmail.com Sat Apr 5 02:48:22 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 05 Apr 2014 01:48:22 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> <533F3796.1000807@gmail.com> Message-ID: <533FA736.2050105@gmail.com> On 4/5/14 1:01 AM, Ben Finney wrote: > Mark H Harris writes: > >> On 4/5/14 12:02 AM, Ian Kelly wrote: >>> A fork is undesirable because it fragments the community. I don't >>> think "fear" or "panic" are the right words for it. >> >> Yes. I get that. > > So, you get that ?fear? and ?panic? are not the right words to > characterise the undesirability Ian describes. Not so much. I 'get' his point about community fragmentation. I disagree that 'fear' is not the correct word. Its semantics, really, but the root is 'fear' of community fragmentation. This is something less than 'fear' as in terror, or fear as in irrational, or fear as in childish (or something like that). > Did you use those words anyway, despite knowing they're not the right > words to use? Often decisions are made within tension (fear) that the price of consequences will not warrant the effort, nor heroism. I believe that decisions should be made because "its the right thing to do," and not because, "if we force this too soon there will be a fork," kinda thing. Decision out of fear is not good. Conservative posturing within tension might be good, as long as its not carried out too far. > Or did you think they were the right words to use, and now you've > changed your position? I don't see where that happened, so I'm confused. You might be confused because you expect me to have a position. My opinions are often also floating on a continuum (just like everything else). I try to keep an open mind, consider all views, allow for the fact that I'm constantly learning and don't know everything, humble enough to know that others can teach me, and above all else willing to hold "truth" gently and humbly. > Or do you still think they are the correct words to use, but now wish to > distance yourself from that position? In Ian's case he may, in point of fact, be concerned for the fragmentation of the community and he might not be fearful; in which case fear would not be the right word for his concern. On the other hand, in point of fact, if Ian (or anyone else) fears the fragmentation of the community that he sees as the consequence of forking C python, then 'fear' would be the right word to use. Just say'n. I don't really have a position (as it were) to distance myself from, but I do have a concern about the perceived awkward conservative snail pace with regard to C python 3.x migration. I mean, its not about being slothful (nor anything like that) but it appears to be 'concern' for constituents (of one kind and another). That 'appearance' is in my view the 'fear' of consequence with a too-quick migration plan (its been way drawn out so far). I personally want python 3.3+ on my android devices. Well, QPython is stuck on 2.7.2 because why? Twisted does not fully work on 3.x yet. What's the solution? Get Twisted up to speed. (gevent is similar). Now, I don't think QPython will want to maintain a fork. I also don't think they will want to stay on 2.7.2 forever, because they will want security patches. They will eventually get up to speed when Twisted is ready. What I wish the C python community would do is to apply just a little pressure here so that the Twisted community is motivated to move a little faster. This is taking too long, and yes, I think the core devs are afraid of offending (or fragmenting) constituents. I might be wrong. > This may seem trivial, but I'm trying to get a handle on what it is you > mean to communicate, when your stated position in one message conflicts > with your stated position only a few messages earlier. Very seldom is anything black & white. Always we entertain shades of grey and a panacea of color and multiple hues. Sometimes when we are thinking out loud (which is itself more than vulnerable) we may be interpreted as being contradictory. Often the contradiction is more or less a nuance as we're wrestling with our mental heuristics. Often my categories overlap, and sometimes those categories have weights that shift (or morph) as the discussion continues. Never are we thinking in a vacuum, and always we are being influenced and challenged by others viewpoints and nuanced opinions. *What position?* Its a little like quantum mechanics and the Heisenberg uncertainty principle--- the more you know about my position, the less you know about how I arrived at it; and the more you know about how I arrived at my position the less you will know about the locus of the position itself. Of course, being able to parse intention with nothing to go on except typed English words and without non verbals (oh the pain of it all) is at best a quandary fraught with foil and frustration; but none the less we persist. {shrug} marcus From rustompmody at gmail.com Sat Apr 5 02:59:48 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 4 Apr 2014 23:59:48 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <8eaca90c-cd43-40b7-92c3-ad8676a11cbd@googlegroups.com> <85d2gw2vje.fsf@benfinney.id.au> Message-ID: On Saturday, April 5, 2014 11:27:08 AM UTC+5:30, Chris Angelico wrote: > On Sat, Apr 5, 2014 at 4:29 PM, Ben Finney wrote: > > Without actual data - which neither of us has on this matter - all of > > these hypotheses are unfounded speculation. Let's not draw any > > conclusions in the absence of evidence. > > Not to mention that there's not a lot of difference between an > unemployed professional coder and a serious hobbyist. :) Since I started this distinction, I would like to clarify that I dont take it too seriously. My impressions: 1. The number of people who read (lurk (on GG!!)) is significantly higher than those who post. 3 times? 10 times? Dunno 2. And they fall into an in-between limbo region: ie students -- some formal, some informal -- who would like to become python 'professionals' but dont see themselves as that right now And in case you missed it, I was suggesting that the idea that python 2 support should be cavalierly dropped implied a completely hobbyist viewpoint. Professionalism implies at bottom that a client is God even if he is being an asshole. Intel, Microsoft, IBM and any successful brick-n-mortar corp of your choice, will be seen to follow this principle scrupulously Of course you are free to prefer the '90%' [Run your favorite search engine on "90 percent of startups..." Of course that does not mean that I find the 'conservatism' of python's choices happy. Here is a recent thread https://mail.python.org/pipermail/python-list/2014-February/667169.html and its contained link http://bugs.python.org/issue2506 I am too far removed from the details to comment on the technical merit of it However reading it suggests that decisions are being made on "conservatism is good, change is not" basis From rosuav at gmail.com Sat Apr 5 03:08:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Apr 2014 18:08:33 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <533FA736.2050105@gmail.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> <533F3796.1000807@gmail.com> <533FA736.2050105@gmail.com> Message-ID: On Sat, Apr 5, 2014 at 5:48 PM, Mark H Harris wrote: > On 4/5/14 1:01 AM, Ben Finney wrote: >> >> Mark H Harris writes: >> >>> On 4/5/14 12:02 AM, Ian Kelly wrote: >>>> >>>> A fork is undesirable because it fragments the community. I don't >>>> think "fear" or "panic" are the right words for it. >>> >>> >>> Yes. I get that. >> >> >> So, you get that ?fear? and ?panic? are not the right words to >> characterise the undesirability Ian describes. > > > Not so much. I 'get' his point about community fragmentation. I disagree > that 'fear' is not the correct word. Its semantics, really, but the root is > 'fear' of community fragmentation. This is something less than 'fear' as in > terror, or fear as in irrational, or fear as in childish (or something like > that). In that case, don't quote both sentences and say "I get that", because people will interpret that to mean that you "get" both of them. You do have the power to edit quoted text and insert your responses in the exact right places. > Often decisions are made within tension (fear) that the price of > consequences will not warrant the effort, nor heroism. I believe that > decisions should be made because "its the right thing to do," and not > because, "if we force this too soon there will be a fork," kinda thing. > Decision out of fear is not good. Conservative posturing within tension > might be good, as long as its not carried out too far. I avoid stepping out onto the road in front of a truck, out of fear that the truck will hit me and break the screen on my laptop. (And secondarily, because getting hit will hurt. Priorities.) Is that a bad decision? At what point does something stop being "conservative posturing" or sane decision-making and start being a "decision out of fear"? > I personally want python 3.3+ on my android devices. Well, QPython is > stuck on 2.7.2 because why? Twisted does not fully work on 3.x yet. What's > the solution? Get Twisted up to speed. (gevent is similar). > Now, I don't think QPython will want to maintain a fork. I also don't > think they will want to stay on 2.7.2 forever, because they will want > security patches. They will eventually get up to speed when Twisted is > ready. What I wish the C python community would do is to apply just a little > pressure here so that the Twisted community is motivated to move a little > faster. This is taking too long, and yes, I think the core devs are afraid > of offending (or fragmenting) constituents. I might be wrong. Why 2.7.2? That can't be because of Twisted. There must be some other reason for not upgrading within 2.7. > Very seldom is anything black & white. Always we entertain shades of grey > and a panacea of color and multiple hues. (You may mean a "rainbow" of color or something, but not a "panacea", which is a quite different thing. According to the Baroness von Krakenfeldt, old wine is a panacea - as long as someone else pays the bill.) And yet ultimately, many things *are* black and white. There is truth, and there is falsehood. Something may be accurate to a greater or lesser degree (if I say that the human body is "mostly" water, then I'm correct; if I say the human body is "about 60% water" then I'm more correct, but if I say the human body is "95.2423% water", then I'm flat out wrong), but correctness is absolute. It's impossible to conduct a sane debate if those participating do not at least attempt to maintain a position, and acknowledge when that position changes. There's nothing wrong with shifting, if done graciously and without trying to pretend that you haven't shifted. (After all, that's usually the point of a debate - to have two extreme positions progressively clarified and shifted until they come into agreement.) ChrisA From harrismh777 at gmail.com Sat Apr 5 02:48:22 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 05 Apr 2014 01:48:22 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533F2D0F.2080806@gmail.com> <533F3796.1000807@gmail.com> Message-ID: <533FA736.2050105@gmail.com> On 4/5/14 1:01 AM, Ben Finney wrote: > Mark H Harris writes: > >> On 4/5/14 12:02 AM, Ian Kelly wrote: >>> A fork is undesirable because it fragments the community. I don't >>> think "fear" or "panic" are the right words for it. >> >> Yes. I get that. > > So, you get that ?fear? and ?panic? are not the right words to > characterise the undesirability Ian describes. Not so much. I 'get' his point about community fragmentation. I disagree that 'fear' is not the correct word. Its semantics, really, but the root is 'fear' of community fragmentation. This is something less than 'fear' as in terror, or fear as in irrational, or fear as in childish (or something like that). > Did you use those words anyway, despite knowing they're not the right > words to use? Often decisions are made within tension (fear) that the price of consequences will not warrant the effort, nor heroism. I believe that decisions should be made because "its the right thing to do," and not because, "if we force this too soon there will be a fork," kinda thing. Decision out of fear is not good. Conservative posturing within tension might be good, as long as its not carried out too far. > Or did you think they were the right words to use, and now you've > changed your position? I don't see where that happened, so I'm confused. You might be confused because you expect me to have a position. My opinions are often also floating on a continuum (just like everything else). I try to keep an open mind, consider all views, allow for the fact that I'm constantly learning and don't know everything, humble enough to know that others can teach me, and above all else willing to hold "truth" gently and humbly. > Or do you still think they are the correct words to use, but now wish to > distance yourself from that position? In Ian's case he may, in point of fact, be concerned for the fragmentation of the community and he might not be fearful; in which case fear would not be the right word for his concern. On the other hand, in point of fact, if Ian (or anyone else) fears the fragmentation of the community that he sees as the consequence of forking C python, then 'fear' would be the right word to use. Just say'n. I don't really have a position (as it were) to distance myself from, but I do have a concern about the perceived awkward conservative snail pace with regard to C python 3.x migration. I mean, its not about being slothful (nor anything like that) but it appears to be 'concern' for constituents (of one kind and another). That 'appearance' is in my view the 'fear' of consequence with a too-quick migration plan (its been way drawn out so far). I personally want python 3.3+ on my android devices. Well, QPython is stuck on 2.7.2 because why? Twisted does not fully work on 3.x yet. What's the solution? Get Twisted up to speed. (gevent is similar). Now, I don't think QPython will want to maintain a fork. I also don't think they will want to stay on 2.7.2 forever, because they will want security patches. They will eventually get up to speed when Twisted is ready. What I wish the C python community would do is to apply just a little pressure here so that the Twisted community is motivated to move a little faster. This is taking too long, and yes, I think the core devs are afraid of offending (or fragmenting) constituents. I might be wrong. > This may seem trivial, but I'm trying to get a handle on what it is you > mean to communicate, when your stated position in one message conflicts > with your stated position only a few messages earlier. Very seldom is anything black & white. Always we entertain shades of grey and a panacea of color and multiple hues. Sometimes when we are thinking out loud (which is itself more than vulnerable) we may be interpreted as being contradictory. Often the contradiction is more or less a nuance as we're wrestling with our mental heuristics. Often my categories overlap, and sometimes those categories have weights that shift (or morph) as the discussion continues. Never are we thinking in a vacuum, and always we are being influenced and challenged by others viewpoints and nuanced opinions. *What position?* Its a little like quantum mechanics and the Heisenberg uncertainty principle--- the more you know about my position, the less you know about how I arrived at it; and the more you know about how I arrived at my position the less you will know about the locus of the position itself. Of course, being able to parse intention with nothing to go on except typed English words and without non verbals (oh the pain of it all) is at best a quandary fraught with foil and frustration; but none the less we persist. {shrug} marcus From rosuav at gmail.com Sat Apr 5 03:10:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Apr 2014 18:10:38 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <8eaca90c-cd43-40b7-92c3-ad8676a11cbd@googlegroups.com> <85d2gw2vje.fsf@benfinney.id.au> Message-ID: On Sat, Apr 5, 2014 at 5:59 PM, Rustom Mody wrote: > Professionalism implies at bottom that a client is God even if > he is being an asshole. Not really :) Sometimes, your employer or client just has to go jump. Professionalism implies that you treat your client at least as well as s/he deserves, and try to solve his/her problems. If that becomes impractical, your client can find a new Charlie. :) ChrisA From nispray at gmail.com Sat Apr 5 06:11:02 2014 From: nispray at gmail.com (Wesley) Date: Sat, 5 Apr 2014 03:11:02 -0700 (PDT) Subject: Python streaming media server Message-ID: <11aa1097-e878-4b91-b117-4b44df246a98@googlegroups.com> Hi, Anyone knows open source streaming media server written by Python? I am trying to setup a streaming media server in python, wanna find an existing one and have a look. Thanks. Wesley From steve+comp.lang.python at pearwood.info Sat Apr 5 06:19:01 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Apr 2014 10:19:01 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <8eaca90c-cd43-40b7-92c3-ad8676a11cbd@googlegroups.com> Message-ID: <533fd894$0$29993$c3e8da3$5496439d@news.astraweb.com> On Sat, 05 Apr 2014 00:02:58 -0500, Mark H Harris wrote: > Having said that, I do believe that the migration to C python3 has > been too conservative. Why? Is it a race? Does Python 2.x turn into PHP at midnight? Some people think the move to Python 3 has been too radical and too fast for them. Are they wrong? > Nobody wants to maintain a fork, not really. There will be no serious fork of Python 2.7. Oh, I dare say that when the core developers finally announce Python 2.7 is end-of-lifed, probably in another five or so years, there will be a flurry of cheap talk about forking Python, and maybe even a few "Python2.8" projects on Github. But nobody will use them, and they will fade away into obscurity. I can't see *anyone* with the necessary resources taking on the job and gathering enough community support for a successful fork. With perhaps one exception. Twisted has apparently said they cannot migrate to 3.x. They might, I suppose, take up maintenance of Python 2.7. But I doubt it. I expect that when push comes to shove in 4 or 5 years time, they'll find a way to migrate. Python 2.7 will continue to get paid-for support from RedHat until 2024, and I expect that there will be companies like Activestate that will offer extended support for Python 2.7 for a few years too. But that's it. > I don't think its something anyone should be afraid of. Nobody is *afraid* of a fork. But forks do split the community, and introduce FUD (Fear, Uncertainty, Doubt), except for the rare occasions like the XFree86 to X.Org fork where the entire community moved almost overnight to the fork. That was a HUGE vote of no confidence to the original maintainer, and (so I'm told) deservedly so. Nothing like that is plausible with Python. There simply isn't anywhere near that level of dissatisfaction with the way the language is being managed, mild grumbling from a few people aside. Most importantly, the core devs have been *very* responsive to people's complaints. > Somebody should > put a date on C python 3.4+ migration and cut off support for 2.7.x/ 2045-04-01. If you're not migrated to Python 3.4 by then, no cake for you. A date will be set when the time is right, but rushing to set a date now when we don't know the state of the language in five years time is just silly. It is expected to be five years from now, but if there is a flurry of migration activity it may be brought forward, and if five years is not long enough it may be delayed. *May* be delayed. It's fine if people don't migrate to 3.4. Waiting until 3.5 or even 3.6 is perfectly acceptable too. Leaving it to 3.7 (expected about 5 years from now) is probably okay too. The longer you wait to migrate, the easier it will be: migrate when the benefit of migrating exceeds the cost. (I'm talking about application-level projects here. Libraries and frameworks are somewhat different.) Each point release of 3.x has added not just new features to entice users, but new features (and sometimes old features) to aid in porting. For example, some things that had been dropped, like the callable() built- in, were re-added in 3.2. 3.3 re-added the u'' syntax solely to aid in porting from 2.x. There is a lot of discussion going on to make it easier to deal with mixed bytes and ASCII text, which is a very important use- case which by accident was suited well to the Python 2.x byte-string model, but not well suited to the Python 3.x unicode-text versus bytes model. You should expect that to come into production in 3.5. > Its > just an opinion. If 'Twisted' isn't ready for 3.x, well, they need to > get ready. Are you volunteering to do the work for them? > That's also just an opinion. Ah, but is it an *informed* opinion? Do you know why Twisted say they cannot migrate to 3.x? -- Steven D'Aprano http://import-that.dreamwidth.org/ From tjreedy at udel.edu Sat Apr 5 07:20:24 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 05 Apr 2014 07:20:24 -0400 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <533fd894$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <8eaca90c-cd43-40b7-92c3-ad8676a11cbd@googlegroups.com> <533fd894$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/5/2014 6:19 AM, Steven D'Aprano wrote: > Oh, I dare say that when the core developers finally announce Python 2.7 > is end-of-lifed, probably in another five or so years, Bug fixing will end in May/June 2015 with 2.7.8, maybe 2.7.9. It will probably start tapering off before that on the basis that fixes may break working code that has worked around bugs. I am not sure how long I will backport Idle patches. Code-only security patches after that? Undecided. I think PEP 466 defines what the focus will be -- keeping 2.7 web apps from becoming bad internet citizens. -- Terry Jan Reedy From roy at panix.com Sat Apr 5 10:28:21 2014 From: roy at panix.com (Roy Smith) Date: Sat, 05 Apr 2014 10:28:21 -0400 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <8eaca90c-cd43-40b7-92c3-ad8676a11cbd@googlegroups.com> <533fd894$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <533fd894$0$29993$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > Twisted has apparently said they cannot migrate to 3.x. They might, I > suppose, take up maintenance of Python 2.7. But I doubt it. I expect > that when push comes to shove in 4 or 5 years time, they'll find a > way to migrate. Is Twisted really that relevant? I know they've been around for a long time, and there are a few high-profile projects using them, but I get the impression they've become a bit of a legacy product by now, and 5 years from now, I suspect that will be even more true. Their big claim to fame was the ability to do asynchronous I/O in Python. There's other ways to do that now. > Nobody is *afraid* of a fork. But forks do split the community, and > introduce FUD A classic example would be the BSD world (Free, Net, Open, Dragonfly, and a host of minor players). There's a lot of really smart people working on those projects, but they're all pushing in different directions. Meanwhile, Linux ate their lunch. >> Somebody should >> put a date on C python 3.4+ migration and cut off support for 2.7.x/ > > 2045-04-01. If you're not migrated to Python 3.4 by then, no cake for you. But, somewhere, somebody will still be running XP on their desktop, and haggling with Microsoft over another deadline extension. From sturla.molden at gmail.com Sat Apr 5 13:38:57 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Sat, 5 Apr 2014 17:38:57 +0000 (UTC) Subject: Python streaming media server References: <11aa1097-e878-4b91-b117-4b44df246a98@googlegroups.com> Message-ID: <1164452706418412253.604283sturla.molden-gmail.com@news.gmane.org> Wesley wrote: > Anyone knows open source streaming media server written by Python? > > I am trying to setup a streaming media server in python, wanna find an > existing one and have a look. Not open source, but there is a famous closed-source one called YouTube. From timr at probo.com Sat Apr 5 17:57:33 2014 From: timr at probo.com (Tim Roberts) Date: Sat, 05 Apr 2014 14:57:33 -0700 Subject: Two Questions about Python on Windows References: Message-ID: maxerickson at gmail.com wrote: > >You can also edit the PATHEXT environment variable to include .py/.pyw, >making the python source files executable (as long as the types are >properly registered with Windows; if double clicking runs them they >should be properly registered). Let me clarify that just a bit. There are several ways to run Python scripts from a Windows command line. You can invoke the interpreter specifically by name: C:\Apps\Python27\python xxx.py C:\Apps\Python27\python xxx.pyw Or, if the Python directory is in your path: python xxx.py python xxx.pyw If the .py and .pyw extension are registered using assoc and ftype (which the Windows installer does), then you can invoke them by file name: xxx.py xxx.pyw If you add those extensions to PATHEXT, then you do not even need to provide the extension, so they will look just like any other automatically executable program: xxx -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From nispray at gmail.com Sat Apr 5 21:51:58 2014 From: nispray at gmail.com (Wesley) Date: Sat, 5 Apr 2014 18:51:58 -0700 (PDT) Subject: Python streaming media server In-Reply-To: References: <11aa1097-e878-4b91-b117-4b44df246a98@googlegroups.com> Message-ID: <0a4cc21b-3d8d-483b-b24f-8bd61da59c0e@googlegroups.com> ? 2014?4?6????UTC+8??1?38?57??Sturla Molden??? > Wesley wrote: > > > > > Anyone knows open source streaming media server written by Python? > > > > > > I am trying to setup a streaming media server in python, wanna find an > > > existing one and have a look. > > > > Not open source, but there is a famous closed-source one called YouTube. Are you kidding? I know youtube, but do you think we can use it setup our own streaming media server? From steve+comp.lang.python at pearwood.info Sat Apr 5 22:10:07 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Apr 2014 02:10:07 GMT Subject: Python streaming media server References: <11aa1097-e878-4b91-b117-4b44df246a98@googlegroups.com> <0a4cc21b-3d8d-483b-b24f-8bd61da59c0e@googlegroups.com> Message-ID: <5340b77f$0$29993$c3e8da3$5496439d@news.astraweb.com> On Sat, 05 Apr 2014 18:51:58 -0700, Wesley wrote: > ? 2014?4?6????UTC+8??1?38?57??Sturla Molden??? >> Wesley wrote: >> >> > Anyone knows open source streaming media server written by Python? >> > >> > I am trying to setup a streaming media server in python, wanna find >> > an existing one and have a look. >> >> >> Not open source, but there is a famous closed-source one called >> YouTube. > > Are you kidding? > I know youtube, but do you think we can use it setup our own streaming > media server? I'm sure if you have a few hundreds of million dollars, you could buy YouTube from Google. Otherwise, no. It is secret, proprietary software, not available to anyone else. Speaking of Google, did you try this? https://www.google.com.au/search?q=python+streaming+video Does that help? Unfortunately, Google customizes the search results depending on who you are and where you are, so you may not see what I see. But for me, the top link (after the paid ads) is for a Python video streaming server. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ben+python at benfinney.id.au Sat Apr 5 22:41:10 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 06 Apr 2014 12:41:10 +1000 Subject: Python streaming media server References: <11aa1097-e878-4b91-b117-4b44df246a98@googlegroups.com> <0a4cc21b-3d8d-483b-b24f-8bd61da59c0e@googlegroups.com> <5340b77f$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <854n272n95.fsf@benfinney.id.au> Steven D'Aprano writes: > Unfortunately, Google customizes the search results depending on who you > are and where you are, so you may not see what I see. Which is one of many reasons to prefer a search engine that doesn't put you in a search bubble like that. DuckDuckGo returns search results impartially because they don't track your search results: -- \ ?I don't care to belong to a club that accepts people like me | `\ as members.? ?Groucho Marx | _o__) | Ben Finney From papillion at gmail.com Sat Apr 5 23:52:23 2014 From: papillion at gmail.com (Anthony Papillion) Date: Sat, 5 Apr 2014 22:52:23 -0500 Subject: How can I parse this correctly? Message-ID: Hello Everyone, I'm working with historical earthquake data and I have a tab delimited file. I'm using the csv module with the \t delimiter to denote it's tab separated and it's working fine. I've set things up loike this: import csv f = open('earthquakes.tsv') r = csv.DictReader(f, delimiter='\t') for row in r: print row['YEAR'] This works fine. But, I am needing to do date addition/subtraction using datetime and so I need these dates as integers. When I try to cast them like this: print int(row['YEAR']) I am told by the interpreter: Traceback (most recent call last): File "analyze.py", line 14, in print int(row['MONTH']) ValueError: invalid literal for int() with base 10: '' What am I doing wrong? Am I not understanding HOW to cast? Thanks, Anthony From rosuav at gmail.com Sun Apr 6 00:03:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Apr 2014 14:03:14 +1000 Subject: How can I parse this correctly? In-Reply-To: References: Message-ID: On Sun, Apr 6, 2014 at 1:52 PM, Anthony Papillion wrote: > When I try to > cast them like this: > > print int(row['YEAR']) > > I am told by the interpreter: > > Traceback (most recent call last): > File "analyze.py", line 14, in > print int(row['MONTH']) > ValueError: invalid literal for int() with base 10: '' > > What am I doing wrong? Am I not understanding HOW to cast? An empty string isn't a valid Python integer, unlike in some other languages where it's taken as zero. Do you have data in some but not in others? Should all blank entries be interpreted as zero? (That's common with a lot of spreadsheets.) Make sure that's really what you want, and then just do this: print int(row['MONTH'] or 0) That'll set a default of zero, if (and only if) the MONTH string is blank. By the way, is there a reason you're using Python 2 rather than Python 3? For new projects, you ideally should be working with a more recent version of Python; that way, you won't have to edit your code later, when you find there's some newer feature that you want. The differences aren't huge, but the sooner you make the change, the less code you have to look at. ChrisA From ben+python at benfinney.id.au Sun Apr 6 00:21:27 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 06 Apr 2014 14:21:27 +1000 Subject: How can I parse this correctly? References: Message-ID: <85zjjz141k.fsf@benfinney.id.au> Anthony Papillion writes: > for row in r: > print row['YEAR'] > > This works fine. But, I am needing to do date addition/subtraction > using datetime and so I need these dates as integers. I assume you mean you will be creating ?datetime.date? objects. What will you set as the month and day? Alternatively, if you just want to do integer arithmetic on the year, you don't need the ?datetime? module at all. > When I try to cast them like this: Python doesn't have ?cast?; instead, you request the creation of a new object by calling the type. > print int(row['YEAR']) What do you expect this to return when ?row['YEAR']? is ?""? (empty string)? > I am told by the interpreter: > > Traceback (most recent call last): > File "analyze.py", line 14, in > print int(row['MONTH']) > ValueError: invalid literal for int() with base 10: '' > > What am I doing wrong? You've ignored the condition where your ?row['YEAR']? is the empty string. Python doesn't have an unambiguous integer represented by the empty string, so it refuses to guess. You'll need to handle that specially, and decide what value you want when that's the case. -- \ ?A free press is one where it's okay to state the conclusion | `\ you're led to by the evidence.? ?Bill Moyers | _o__) | Ben Finney From nispray at gmail.com Sun Apr 6 00:31:37 2014 From: nispray at gmail.com (Wesley) Date: Sat, 5 Apr 2014 21:31:37 -0700 (PDT) Subject: Python streaming media server In-Reply-To: <11aa1097-e878-4b91-b117-4b44df246a98@googlegroups.com> References: <11aa1097-e878-4b91-b117-4b44df246a98@googlegroups.com> Message-ID: ? 2014?4?5????UTC+8??6?11?02??Wesley??? > Hi, > > Anyone knows open source streaming media server written by Python? > > > > I am trying to setup a streaming media server in python, wanna find an existing one and have a look. > > > > Thanks. > > Wesley After a lot google work, I am looking at Flumotion. Need to check the streaming mode and file formats it support. Wesley From jackie.walkabout at gmail.com Sun Apr 6 00:58:18 2014 From: jackie.walkabout at gmail.com (Anthony Smith) Date: Sat, 5 Apr 2014 21:58:18 -0700 (PDT) Subject: If statement issue driving me nuts Message-ID: <01e8ff1c-e10a-4df2-84f7-bbc65014e88e@googlegroups.com> Hi I have a small project and I have been unable to get the following statement to work. Any help would great. User inputs can either self_sale_head which is a $ value,if a $ value is not add a self.estimated_weight_hd is used to get the total weight, the code below should return a estimated_weight_total which can be used for the total sale price. All works when I add the estimated_weight_total manually. I am lost as why. def calc_estimated_weight_total(self): if self.sale_head <= 0: amount = (self.number * self.estimated_weight_hd) return amount def save(self): self.estimated_total_weight = self.calc_estimated_weight_total() super(SaleNote, self).save() From davea at davea.name Sun Apr 6 02:22:21 2014 From: davea at davea.name (Dave Angel) Date: Sun, 6 Apr 2014 02:22:21 -0400 (EDT) Subject: If statement issue driving me nuts References: <01e8ff1c-e10a-4df2-84f7-bbc65014e88e@googlegroups.com> Message-ID: Anthony Smith Wrote in message: > Hi > > I have a small project and I have been unable to get the following statement to work. Any help would great. > User inputs can either self_sale_head which is a $ value,if a $ value is not add a self.estimated_weight_hd is used to get the total weight, > the code below should return a estimated_weight_total which can be used for the total sale price. > All works when I add the estimated_weight_total manually. I am lost as why. > > def calc_estimated_weight_total(self): > if self.sale_head <= 0: > amount = (self.number * self.estimated_weight_hd) > return amount > > def save(self): > self.estimated_total_weight = self.calc_estimated_weight_total() > super(SaleNote, self).save() > Please insert the missing words, and fix the punctuation, and maybe we'll be able to decipher your question. Your subject line implies you think there's a problem with the if statement; perhaps you could describe what problem that is. You might even try to describe what the sale_head attribute is supposed to be. Then post a useful fragment of code, and state what resulted, and what you expected that was different. If you got an exception, paste the whole thing Ideally post a runnable hunk of code. One problem with your first method is that you don't return an amount in the (missing) else clause. So if the condition is false, the caller will see None instead of a number. If it happens to be called from the save method, you'll get an exception. -- DaveA From papillion at gmail.com Sun Apr 6 02:29:43 2014 From: papillion at gmail.com (Anthony Papillion) Date: Sun, 6 Apr 2014 01:29:43 -0500 Subject: How can I parse this correctly? In-Reply-To: References: Message-ID: <7E623349-4095-4550-9E2F-D7261C311DBE@gmail.com> On Apr 5, 2014, at 23:03, Chris Angelico wrote: > On Sun, Apr 6, 2014 at 1:52 PM, Anthony Papillion > wrote: >> When I try to >> cast them like this: >> >> print int(row['YEAR']) >> >> I am told by the interpreter: >> >> Traceback (most recent call last): >> File "analyze.py", line 14, in >> print int(row['MONTH']) >> ValueError: invalid literal for int() with base 10: '' >> >> What am I doing wrong? Am I not understanding HOW to cast? > > An empty string isn't a valid Python integer, unlike in some other > languages where it's taken as zero. Do you have data in some but not > in others? Should all blank entries be interpreted as zero? (That's > common with a lot of spreadsheets.) Make sure that's really what you > want, and then just do this: > > print int(row['MONTH'] or 0) > > That'll set a default of zero, if (and only if) the MONTH string is > blank. Many thanks! That's exactly what I was looking for. In this case, since I'm needing to create a valid date, I'm defaulting to 1. > By the way, is there a reason you're using Python 2 rather than Python > 3? For new projects, you ideally should be working with a more recent > version of Python; that way, you won't have to edit your code later, > when you find there's some newer feature that you want. The > differences aren't huge, but the sooner you make the change, the less > code you have to look at No particular reason at all. I've Bern dabbling in Python for the last bit and am just writing code based on the samples or examples I'm finding. What was the tipoff that this was not Python 3? Would there be a large difference in this code if it was Python 3? Anthony From gary.herron at islandtraining.com Sun Apr 6 02:23:46 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Sat, 05 Apr 2014 23:23:46 -0700 Subject: If statement issue driving me nuts In-Reply-To: <01e8ff1c-e10a-4df2-84f7-bbc65014e88e@googlegroups.com> References: <01e8ff1c-e10a-4df2-84f7-bbc65014e88e@googlegroups.com> Message-ID: <5340F2F2.8080309@islandtraining.com> On 04/05/2014 09:58 PM, Anthony Smith wrote: > Hi > > I have a small project and I have been unable to get the following statement to work. Any help would great. > User inputs can either self_sale_head which is a $ value,if a $ value is not add a self.estimated_weight_hd is used to get the total weight, > the code below should return a estimated_weight_total which can be used for the total sale price. > All works when I add the estimated_weight_total manually. I am lost as why. > > def calc_estimated_weight_total(self): > if self.sale_head <= 0: > amount = (self.number * self.estimated_weight_hd) > return amount > > def save(self): > self.estimated_total_weight = self.calc_estimated_weight_total() > super(SaleNote, self).save() You'll have to be more informative than that. Exactly what does "unable to get the following statement to work" mean? What did you do to try to get it to work? What did you get instead? If there was a traceback, please include it in an email. While you're at it, please also tell us what version of Python, and on what hardware you are running -- just in case that matters. Gary Herron From papillion at gmail.com Sun Apr 6 02:49:52 2014 From: papillion at gmail.com (Anthony Papillion) Date: Sun, 6 Apr 2014 01:49:52 -0500 Subject: How can I parse this correctly? In-Reply-To: <85zjjz141k.fsf@benfinney.id.au> References: <85zjjz141k.fsf@benfinney.id.au> Message-ID: <985B907F-8EC7-4B5C-8A9F-64AEC3E5803D@gmail.com> On Apr 5, 2014, at 23:21, Ben Finney wrote: > Anthony Papillion writes: > >> for row in r: >> print row['YEAR'] >> >> This works fine. But, I am needing to do date addition/subtraction >> using datetime and so I need these dates as integers. > > I assume you mean you will be creating ?datetime.date? objects. Wh > at > will you set as the month and day? Right, I did mean datetime.date. As form month and day, I also have a column in my data for that. I'll be pulling it the same way I'm doing with year > Alternatively, if you just want to do integer arithmetic on the year, > you don't need the ?datetime? module at all. True. But I do actually need to some date based calculations. Basically I'm processing a large data set and calculating time intervals between entries >> When I try to cast them like this: > > Python doesn't have ?cast?; instead, you request the creation of > a new > object by calling the type. Hmm, interesting. I need to think on that for a moment. I may well have completely misunderstood a major part of Python all this time. >> print int(row['YEAR']) > > What do you expect this to return when ?row['YEAR']? is > ?""? (empty > string)? I expected a defaut value to be returned, perhaps "0". I see now from another response that this is not the case and so I've fixed it to read print int(row['YEAR'] or 0000) > >> I am told by the interpreter: >> >> Traceback (most recent call last): >> File "analyze.py", line 14, in >> print int(row['MONTH']) >> ValueError: invalid literal for int() with base 10: '' >> >> What am I doing wrong? > > You've ignored the condition where your ?row['YEAR']? is the empty > string. Python doesn't have an unambiguous integer represented by the > empty string, so it refuses to guess. > > You'll need to handle that specially, and decide what value you want > when that's the case. Thank you! I actually like the fact that it won't simply "fill something in". It makes things more predictable and stable. Anthony From john_ladasky at sbcglobal.net Sun Apr 6 02:53:57 2014 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sat, 5 Apr 2014 23:53:57 -0700 (PDT) Subject: Mutable objects inside tuples - good or bad? Message-ID: <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> I find this programming pattern to be useful... but can it cause problems? Python 3.3.2+ (default, Feb 28 2014, 00:52:16) [GCC 4.8.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> a = [1,2,3] >>> b = [4,5,6] >>> c = (a,b) >>> c ([1, 2, 3], [4, 5, 6]) >>> c[0][0] = 0 >>> c ([0, 2, 3], [4, 5, 6]) Comments appreciated. From gary.herron at islandtraining.com Sun Apr 6 03:25:57 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Sun, 06 Apr 2014 00:25:57 -0700 Subject: Mutable objects inside tuples - good or bad? In-Reply-To: <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> References: <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> Message-ID: <53410185.6050304@islandtraining.com> On 04/05/2014 11:53 PM, John Ladasky wrote: > I find this programming pattern to be useful... but can it cause problems? No. What kind of problems are you considering? It won't break Python. It's perfectly legal code. The tuple c is still immutable, consisting of two specific objects, and (as always) without regard to the specifics or contents of those two objects. Gary Herron > > Python 3.3.2+ (default, Feb 28 2014, 00:52:16) > [GCC 4.8.1] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> a = [1,2,3] >>>> b = [4,5,6] >>>> c = (a,b) >>>> c > ([1, 2, 3], [4, 5, 6]) >>>> c[0][0] = 0 >>>> c > ([0, 2, 3], [4, 5, 6]) > > Comments appreciated. From gbe32241 at libero.it Sun Apr 6 03:44:13 2014 From: gbe32241 at libero.it (Giuliano Bertoletti) Date: Sun, 06 Apr 2014 09:44:13 +0200 Subject: Keeping track of things with dictionaries Message-ID: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> I frequently use this pattern to keep track of incoming data (for example, to sum up sales of a specific brand): ===================================== # read a brand record from a db ... # keep track of brands seen obj = brands_seen.get(brandname) if obj is None: obj = Brand() brands_seen[brandname] = obj obj.AddData(...) # this might for example keep track of sales ===================================== as you might guess, brands_seen is a dictionary whose keys are brandnames and whose values are brand objects. Now the point is: is there a cleverer way to do this? Basically what I'm doing is query the dictionary twice if the object does not exist. What I would like to understand is if there's some language built-in logic to: - supply a function which is meant to return a new object - have the interpreter to locate the point in the dictionary where the key is to be - if the key is already there, it returns the value/object associated and stops - if the key is not there, it calls the supplied function, assigns the returned value to the dictionary and return the object. Giulio. From jeanpierreda at gmail.com Sun Apr 6 03:55:58 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 6 Apr 2014 00:55:58 -0700 Subject: Mutable objects inside tuples - good or bad? In-Reply-To: <53410185.6050304@islandtraining.com> References: <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> <53410185.6050304@islandtraining.com> Message-ID: On Sun, Apr 6, 2014 at 12:25 AM, Gary Herron wrote: > On 04/05/2014 11:53 PM, John Ladasky wrote: >> >> I find this programming pattern to be useful... but can it cause problems? > > No. > > What kind of problems are you considering? It won't break Python. It's > perfectly legal code. Agreed. Putting mutable objects inside tuples is common and totally OK. > The tuple c is still immutable, consisting of two specific objects, and (as > always) without regard to the specifics or contents of those two objects. You can choose to define mutability that way, but in many contexts you'll find that definition not very useful. c is such that you could have another variable d, where the following interpreter session fragment is easily possible: >>> c == d True >>> foo(c) >>> c == d False -- Devin >> Python 3.3.2+ (default, Feb 28 2014, 00:52:16) >> [GCC 4.8.1] on linux >> Type "help", "copyright", "credits" or "license" for more information. >>>>> >>>>> a = [1,2,3] >>>>> b = [4,5,6] >>>>> c = (a,b) >>>>> c >> >> ([1, 2, 3], [4, 5, 6]) >>>>> >>>>> c[0][0] = 0 >>>>> c >> >> ([0, 2, 3], [4, 5, 6]) >> >> Comments appreciated. > > > -- > https://mail.python.org/mailman/listinfo/python-list From harrismh777 at gmail.com Sat Apr 5 23:59:23 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 05 Apr 2014 22:59:23 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5340D11B.8070802@gmail.com> On 4/4/14 4:53 AM, Steven D'Aprano wrote: > Python is not a computer-science-ey language. Really ? > It is of little or no > interest to computer scientists involved in the mathematics of > computation, ... you mean no one except me, then ? > or compiler-theory, or type-theory, or any of the other > academic disciplines under comp-sci. So, I understand as you say, that there are no academics using C python interpreter within the rubric of their particular comp sci discipline? none? anyplace? I am surprised. They might be surprised as well. You probably think the same is true of common lisp? then? Under the covers there are some striking similarities between the way lisp does things, and the way python does things. You know this, right? The python interpreter is actually an excellent computer science language (not only for education) because of its structure, data types, flexibility, and extensibility. It is an excellent research language. There seems to be a considerable difference of opinion as to 'what' comprises computer science; very interesting. Not only is C python interpreter an excellent research language, but the study of the Python language itself is of major interest for anyone who studies languages in general; ie., Lambda the Ultimate ? marcus From harrismh777 at gmail.com Sun Apr 6 00:59:33 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 05 Apr 2014 23:59:33 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/4/14 4:53 AM, Steven D'Aprano wrote: > Python is not a computer-science-ey language. Every programming language is interesting from a comp sci standpoint. Some are more useful for research; python is one of those. For what reasons do you disagree? marcus From harrismh777 at gmail.com Sun Apr 6 00:01:07 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 05 Apr 2014 23:01:07 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/4/14 4:53 AM, Steven D'Aprano wrote: > Python is not a computer-science-ey language. Really ? > It is of little or no > interest to computer scientists involved in the mathematics of > computation, ... you mean no one except me, then ? > or compiler-theory, or type-theory, or any of the other > academic disciplines under comp-sci. So, I understand as you say, that there are no academics using C python interpreter within the rubric of their particular comp sci discipline? none? anyplace? I am surprised. They might be surprised as well. You probably think the same is true of common lisp? then? Under the covers there are some striking similarities between the way lisp does things, and the way python does things. You know this, right? The python interpreter is actually an excellent computer science language (not only for education) because of its structure, data types, flexibility, and extensibility. It is an excellent research language. There seems to be a considerable difference of opinion as to 'what' comprises computer science; very interesting. Not only is C python interpreter an excellent research language, but the study of the Python language itself is of major interest for anyone who studies languages in general; ie., Lambda the Ultimate ? marcus From mok-kong.shen at t-online.de Sun Apr 6 04:09:24 2014 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Sun, 06 Apr 2014 10:09:24 +0200 Subject: A data conversion question Message-ID: A newbie's question of curiosity: If I have g=[1,[2]] and bg=bytearray(str(g),"latin-1") could I somehow get back from bg a list g1 that is the same as g? Thanks in advance. M. K. Shen From ben+python at benfinney.id.au Sun Apr 6 04:16:22 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 06 Apr 2014 18:16:22 +1000 Subject: How can I parse this correctly? References: <85zjjz141k.fsf@benfinney.id.au> <985B907F-8EC7-4B5C-8A9F-64AEC3E5803D@gmail.com> Message-ID: <85lhvi27qh.fsf@benfinney.id.au> Anthony Papillion writes: > On Apr 5, 2014, at 23:21, Ben Finney wrote: > > Alternatively, if you just want to do integer arithmetic on the > > year, you don't need the ?datetime? module at all. > > True. But I do actually need to some date based calculations. > Basically I'm processing a large data set and calculating time > intervals between entries Okay. So, it seems that some entries have (some of?) the date components blank. There is no sensible general-purpose default for ?datetime.date?, so you will need to decide what ?empty date? means for your data. > > Python doesn't have ?cast?; instead, you request the creation of a > > new object by calling the type. > > Hmm, interesting. I need to think on that for a moment. I may well > have completely misunderstood a major part of Python all this time. Yes, it's important to recognise that all Python's built-in types are callable just as user-defined types are; and by calling them, you are requesting a new instance. > >> print int(row['YEAR']) > > > > What do you expect this to return when ?row['YEAR']? is ?""? (empty > > string)? > > I expected a defaut value to be returned, perhaps "0". You'll need to be aware that the Gregorian calendar (which is what ?datetime.date? uses) has no year zero. 1 BCE is immediately succeeded by 1 CE. So, again, there's no good general-purpose default year in our calendar. Any system will need an explicit decision for the most sensible default for its purpose. > I see now from another response that this is not the case and so I've > fixed it to read > > print int(row['YEAR'] or 0000) ?foo or bar? is not a Pythonic way to get a default value; it relies on quirks of implementation and is not expressive as to the meaning you intend. Rather, be explicit: # Default to the beginning of the project. year = 1969 if row['YEAR']: # Use the value as a text representation of a year. year = int(row['YEAR']) Also, be aware that Python allows leading-zero integer literals, but interprets them not as decimal (base ten), but as octal (base eight). If ?this integer is base-eight for a good reason explained nearby? is not your intent, don't put a leading-zero integer literal in the code. > Thank you! I actually like the fact that [Python's ?int? initialiser] > won't simply "fill something in". It makes things more predictable and > stable. Welcome to a dependable language :-) -- \ ?Firmness in decision is often merely a form of stupidity. It | `\ indicates an inability to think the same thing out twice.? | _o__) ?Henry L. Mencken | Ben Finney From rosuav at gmail.com Sun Apr 6 04:17:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Apr 2014 18:17:01 +1000 Subject: How can I parse this correctly? In-Reply-To: <7E623349-4095-4550-9E2F-D7261C311DBE@gmail.com> References: <7E623349-4095-4550-9E2F-D7261C311DBE@gmail.com> Message-ID: On Sun, Apr 6, 2014 at 4:29 PM, Anthony Papillion wrote: > No particular reason at all. I've Bern dabbling in Python for the last bit > and am just writing code based on the samples or examples I'm finding. What > was the tipoff that this was not Python 3? Would there be a large difference > in this code if it was Python 3? The tip-off was that you have no parentheses around print's arguments. Behold the vast difference that told me which it was: # Python 2: print is a statement print int(row['YEAR']) # Python 3: print is a function print(int(row['YEAR'])) So incredibly different :) But it's enough to show that you're on Python 2. ChrisA From __peter__ at web.de Sun Apr 6 04:23:38 2014 From: __peter__ at web.de (Peter Otten) Date: Sun, 06 Apr 2014 10:23:38 +0200 Subject: Keeping track of things with dictionaries References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> Message-ID: Giuliano Bertoletti wrote: > I frequently use this pattern to keep track of incoming data (for > example, to sum up sales of a specific brand): > > ===================================== > > # read a brand record from a db > ... > > # keep track of brands seen > obj = brands_seen.get(brandname) > if obj is None: > obj = Brand() > brands_seen[brandname] = obj > > obj.AddData(...) # this might for example keep track of sales > > ===================================== > > as you might guess, brands_seen is a dictionary whose keys are > brandnames and whose values are brand objects. > > Now the point is: is there a cleverer way to do this? > > Basically what I'm doing is query the dictionary twice if the object > does not exist. > > What I would like to understand is if there's some language built-in > logic to: > > - supply a function which is meant to return a new object > - have the interpreter to locate the point in the dictionary where the > key is to be > - if the key is already there, it returns the value/object associated > and stops > - if the key is not there, it calls the supplied function, assigns the > returned value to the dictionary and return the object. Cudos, you give a precise discription of your problem in both english and code. There is a data structure in the stdlib that fits your task. With a collections.defaultdict your code becomes from collections import defaultdict brands_seen = defaultdict(Brand) brands_seen[brandname].add_data(...) # Method name adjusted to PEP 8 Side note: If you needed the key in the construction of the value you would have to subclass class BrandsSeen(dict): def __missing__(self, brandname): result = self[brandname] = Brand(brandname) return result brands_seen = BrandsSeen() brands_seen[brandname].add_data(...) From rosuav at gmail.com Sun Apr 6 04:25:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Apr 2014 18:25:36 +1000 Subject: Mutable objects inside tuples - good or bad? In-Reply-To: References: <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> <53410185.6050304@islandtraining.com> Message-ID: On Sun, Apr 6, 2014 at 5:55 PM, Devin Jeanpierre wrote: > On Sun, Apr 6, 2014 at 12:25 AM, Gary Herron > wrote: >> On 04/05/2014 11:53 PM, John Ladasky wrote: >>> >>> I find this programming pattern to be useful... but can it cause problems? >> >> No. >> >> What kind of problems are you considering? It won't break Python. It's >> perfectly legal code. > > Agreed. Putting mutable objects inside tuples is common and totally OK. There are many programming habits that can cause problems, even though they won't break Python and are legal code. :) >> The tuple c is still immutable, consisting of two specific objects, and (as >> always) without regard to the specifics or contents of those two objects. > > You can choose to define mutability that way, but in many contexts > you'll find that definition not very useful. > > c is such that you could have another variable d, where the following > interpreter session fragment is easily possible: > >>>> c == d > True >>>> foo(c) >>>> c == d > False What you're looking at here is hashability, not mutability. Compare: >>> a = (1,2,3) >>> hash(a) 2528502973977326415 >>> b = ([1],[2],[3]) >>> hash(b) Traceback (most recent call last): File "", line 1, in TypeError: unhashable type: 'list' Both tuples are immutable, but the former is hashable because all its members are hashable, while the latter is not. You can't trust that equality with b is constant: >>> c = ([1],[2],[3]) >>> b == c True >>> b[2][0]=4 >>> b == c False Going back to the original question, though: I do not believe that putting mutable objects inside tuples is a problem. I've done it frequently myself, and it's never caused confusion. So go right ahead, do it if it makes sense! ChrisA From rosuav at gmail.com Sun Apr 6 04:32:23 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Apr 2014 18:32:23 +1000 Subject: How can I parse this correctly? In-Reply-To: <85lhvi27qh.fsf@benfinney.id.au> References: <85zjjz141k.fsf@benfinney.id.au> <985B907F-8EC7-4B5C-8A9F-64AEC3E5803D@gmail.com> <85lhvi27qh.fsf@benfinney.id.au> Message-ID: On Sun, Apr 6, 2014 at 6:16 PM, Ben Finney wrote: >> print int(row['YEAR'] or 0000) > > ?foo or bar? is not a Pythonic way to get a default value; it relies on > quirks of implementation and is not expressive as to the meaning you > intend. > > Rather, be explicit: > > # Default to the beginning of the project. > year = 1969 > if row['YEAR']: > # Use the value as a text representation of a year. > year = int(row['YEAR']) What's wrong with "foo or bar" as a means of defaulting a blank string? (Obviously this assumes you know you have a string, as it'll equally default a 0 or a 0.0 or a [] or anything else false.) The definition of the "or" operator is that it returns its first argument if it's true, otherwise it returns its second argument. That's not a quirk of implementation. This exact example (with strings, no less!) can be found in help("or") and in the docs: https://docs.python.org/3/reference/expressions.html#boolean-operations ChrisA From __peter__ at web.de Sun Apr 6 04:37:58 2014 From: __peter__ at web.de (Peter Otten) Date: Sun, 06 Apr 2014 10:37:58 +0200 Subject: A data conversion question References: Message-ID: Mok-Kong Shen wrote: > A newbie's question of curiosity: > > If I have > > g=[1,[2]] and > > bg=bytearray(str(g),"latin-1") > > could I somehow get back from bg a list g1 that is the same as g? Not for arbitrary values, but for lists, ints, and a few other types that's not a problem: >>> g = [1, [2]] >>> bg = bytearray(str(g), "latin-1") >>> bg bytearray(b'[1, [2]]') >>> import ast >>> ast.literal_eval(bg.decode("latin-1")) [1, [2]] See also https://docs.python.org/dev/library/ast.html#ast.literal_eval Note that while eval() instead of ast.literal_eval() would also work you should avoid it. eval() can execute arbitrary Python code and is thus a big security whole when applied to user-provided data. From marko at pacujo.net Sun Apr 6 05:05:16 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 06 Apr 2014 12:05:16 +0300 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <874n26su9f.fsf@elektro.pacujo.net> Mark H Harris : > On 4/4/14 4:53 AM, Steven D'Aprano wrote: >> Python is not a computer-science-ey language. > > Every programming language is interesting from a comp sci standpoint. > Some are more useful for research; python is one of those. > > For what reasons do you disagree? Computer science doesn't mean "anything related to computers." Physicists typically couldn't care less about your heating up your lunch in the microwave oven. Similarly, computer scientists aren't interested in the mundane applications of their lofty research topics. Python, BTW, is perfectly suitable for computer science. Normally, though, you either use a pseudolanguage or some sort of formalism that hasn't been implemented. In theoretical computer science, they cherish off-the-wall models that detach the topic from everyday applications. Here are examples that I remember from graduate school: * combinatory birds in forests * unfaithful husbands on an island ruled by female logicians * dining philosophers getting into a deadlock over forks * Byzantine generals trying to agree on a surprise onslaught on a besieged city Marko From jeanpierreda at gmail.com Sun Apr 6 07:01:10 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 6 Apr 2014 04:01:10 -0700 Subject: Mutable objects inside tuples - good or bad? In-Reply-To: References: <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> <53410185.6050304@islandtraining.com> Message-ID: On Sun, Apr 6, 2014 at 1:25 AM, Chris Angelico wrote: > On Sun, Apr 6, 2014 at 5:55 PM, Devin Jeanpierre wrote: >> Agreed. Putting mutable objects inside tuples is common and totally OK. > > There are many programming habits that can cause problems, even though > they won't break Python and are legal code. :) Yes, but this isn't one of them. >> c is such that you could have another variable d, where the following >> interpreter session fragment is easily possible: >> >>>>> c == d >> True >>>>> foo(c) >>>>> c == d >> False > > What you're looking at here is hashability, not mutability. Compare: No, that is not what I am looking at. There are hashable objects with the property I described, and unhashable objects without it. My point in that example was that sometimes it is more useful to talk about entire objects and their behavior as a whole. Calling the object "immutable" when it has mutable state is misleading in this context. -- Devin From breamoreboy at yahoo.co.uk Sun Apr 6 07:32:21 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 06 Apr 2014 12:32:21 +0100 Subject: How can I parse this correctly? In-Reply-To: References: <7E623349-4095-4550-9E2F-D7261C311DBE@gmail.com> Message-ID: On 06/04/2014 09:17, Chris Angelico wrote: > On Sun, Apr 6, 2014 at 4:29 PM, Anthony Papillion wrote: >> No particular reason at all. I've Bern dabbling in Python for the last bit >> and am just writing code based on the samples or examples I'm finding. What >> was the tipoff that this was not Python 3? Would there be a large difference >> in this code if it was Python 3? > > The tip-off was that you have no parentheses around print's arguments. > Behold the vast difference that told me which it was: > > # Python 2: print is a statement > print int(row['YEAR']) > > # Python 3: print is a function > print(int(row['YEAR'])) > > So incredibly different :) But it's enough to show that you're on Python 2. > > ChrisA > I'd recommend using this import statement in Python 2 so you get used to print being a function. from __future__ import print_function -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Sun Apr 6 07:43:45 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 06 Apr 2014 12:43:45 +0100 Subject: Python streaming media server In-Reply-To: References: <11aa1097-e878-4b91-b117-4b44df246a98@googlegroups.com> Message-ID: On 06/04/2014 05:31, Wesley wrote: > ? 2014?4?5????UTC+8??6?11?02??Wesley??? >> Hi, >> >> Anyone knows open source streaming media server written by Python? >> >> >> >> I am trying to setup a streaming media server in python, wanna find an existing one and have a look. >> >> >> >> Thanks. >> >> Wesley > > After a lot google work, I am looking at Flumotion. > Need to check the streaming mode and file formats it support. > > Wesley > Would you please use the mailing list https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Sun Apr 6 07:54:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Apr 2014 21:54:16 +1000 Subject: How can I parse this correctly? In-Reply-To: References: <7E623349-4095-4550-9E2F-D7261C311DBE@gmail.com> Message-ID: On Sun, Apr 6, 2014 at 9:32 PM, Mark Lawrence wrote: > I'd recommend using this import statement in Python 2 so you get used to > print being a function. > > from __future__ import print_function Or better still, just write Python 3 code - then you get to take advantage of all the fancy new features :) ChrisA From breamoreboy at yahoo.co.uk Sun Apr 6 08:42:32 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 06 Apr 2014 13:42:32 +0100 Subject: How can I parse this correctly? In-Reply-To: References: <7E623349-4095-4550-9E2F-D7261C311DBE@gmail.com> Message-ID: On 06/04/2014 12:54, Chris Angelico wrote: > On Sun, Apr 6, 2014 at 9:32 PM, Mark Lawrence wrote: >> I'd recommend using this import statement in Python 2 so you get used to >> print being a function. >> >> from __future__ import print_function > > Or better still, just write Python 3 code - then you get to take > advantage of all the fancy new features :) > > ChrisA > I meant to say, "If you're stuck with Python 2 ..." :( -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From sturla.molden at gmail.com Sun Apr 6 08:52:37 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Sun, 6 Apr 2014 12:52:37 +0000 (UTC) Subject: Python streaming media server References: <0a4cc21b-3d8d-483b-b24f-8bd61da59c0e@googlegroups.com> Message-ID: <648953336418480560.617588sturla.molden-gmail.com@news.gmane.org> Wesley wrote: >> Not open source, but there is a famous closed-source one called YouTube. > > Are you kidding? > I know youtube, but do you think we can use it setup our own streaming media server? Obviously not. Before YouTube was bought by Google, it was common knowledge that it ran on Stackless Python. So a streaming media server on Python is absolutely possible. But no, I don't know of one you can set up and use on your own. You can make a highly scalable server with PyZMQ and Tornado or Twisted. NumPy is great for storing binary data like media streams. HDF5 (PyTables or h5py) might be a better database than some SQL server, as it is capable of highly scalable parallel binary i/o. Sturla From python.list at tim.thechases.com Sun Apr 6 08:31:05 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 6 Apr 2014 07:31:05 -0500 Subject: How can I parse this correctly? In-Reply-To: <85zjjz141k.fsf@benfinney.id.au> References: <85zjjz141k.fsf@benfinney.id.au> Message-ID: <20140406073105.578f4817@bigbox.christie.dr> On 2014-04-06 14:21, Ben Finney wrote: > I assume you mean you will be creating ?datetime.date? objects. What > will you set as the month and day? > > Alternatively, if you just want to do integer arithmetic on the > year, you don't need the ?datetime? module at all. Even if you do the arithmetic by hand, it's still nice to use the datetime module to parse for sane dates: year = 2004 month = 2 day = 29 what should month & day be if you increment/decrement the year by one? The datetime module will throw a ValueError which is a nice check for a valid date. I've had to do things like this in a loop to sanitize dates (depending on which field is being inc/dec'ed, by how much, and which direction it's going) and it's nice to just have a y,m,d = initial = some_date.timetuple()[:3] # result = None while result is None: y,m,d = twiddle(y, m, d) try: result = datetime(y, m, d) except ValueError: result = None log.info("Shifted %r -> %r", initial, result) where twiddle() is whatever business logic I need for this particular case. For me usually, it's adjusting by one month for billing purposes. -tkc From rustompmody at gmail.com Sun Apr 6 11:07:27 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 6 Apr 2014 08:07:27 -0700 (PDT) Subject: Mutable objects inside tuples - good or bad? In-Reply-To: References: <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> <53410185.6050304@islandtraining.com> Message-ID: <873b7df7-f213-4d84-a300-ef34ea1dd0a2@googlegroups.com> On Sunday, April 6, 2014 1:40:58 PM UTC+5:45, Devin Jeanpierre wrote: > > You can choose to define mutability that way, but in many contexts > you'll find that definition not very useful. > > c is such that you could have another variable d, where the following > interpreter session fragment is easily possible: > > > >>> c == d > True > >>> foo(c) > >>> c == d > False Its called referential transparency (or rather the lack of it) And that is why it (Johns question) is not a good idea. In general worshipping overzealously at the altar of RT produces functional programming. To the non-zealots this has the characteristic of "Throw out baby with bathwater" On the other hand imperative programming is a source of more problems than people realize: http://blog.languager.org/2012/11/imperative-programming-lessons-not.html From steve+comp.lang.python at pearwood.info Sun Apr 6 12:52:21 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Apr 2014 16:52:21 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> Message-ID: <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> On Sun, 06 Apr 2014 12:05:16 +0300, Marko Rauhamaa wrote: > Mark H Harris : > >> On 4/4/14 4:53 AM, Steven D'Aprano wrote: >>> Python is not a computer-science-ey language. >> >> Every programming language is interesting from a comp sci standpoint. >> Some are more useful for research; python is one of those. >> >> For what reasons do you disagree? > > Computer science doesn't mean "anything related to computers." > Physicists typically couldn't care less about your heating up your lunch > in the microwave oven. Similarly, computer scientists aren't interested > in the mundane applications of their lofty research topics. > > Python, BTW, is perfectly suitable for computer science. I don't think it is. Python is not a pure functional language, so it's very difficult to prove anything about the code apart from running it. For example, see Brett Cannon's master's thesis, where he essentially demonstrates that: - you can't do compile-time type inference of general types in Python; - although you can infer a very small amount of information about a few built-in types; - adding specialized byte-codes to handle those types gives, at best, a marginal performance boost, and sometimes even slows code down. To quote from the conclusion: "Introducing over 3,000 lines of new C code to Python?s compiler to get, at best, a 1% improvement is in no way justified. The level of added complexity that would be introduced into the compilation step would definitely need to lead to a noticeable performance improvement, the 5% that was the goal, to justify the cost of code maintenance." http://citeseerx.ist.psu.edu/viewdoc/download? doi=10.1.1.90.3231&rep=rep1&type=pdf What does it mean to say that a language like Python is suitable for use in computer science? It can mean (at least) four things: (1) If you do an undergraduate computer science course, they will teach you Python. While this is good for the general Python community, it's hardly *doing* computer science. It's *learning* computer science. (I read a book by Richard Dawkins. That doesn't mean I'm a biologist.) So while I agree that it is significant that some universities will teach Python to undergraduates, I don't count this as Python being used in computer science. I think we need to look at postgraduate use of Python, not undergraduate. (2) Some post-grads use Python as a tool, e.g. they use a Python script to analyse some data. In this case, the use of Python is incidental to the research they are doing. They might have used Perl, or a bash script, or calculated the results by hand. In a similar fashion, they probably wrote up their results using Microsoft Word. It's just a tool. (3) Some post-grads do original research *into* Python, as a language. Brett Cannon's thesis is proof that this has happened at least once. I think this does count as doing computer science with Python, although only marginally. No slight intended, but it should be obvious that something like Brett's thesis has very little application outside of Python itself. Perhaps a little: if there is another language with similar types of dynamism as Python, you might conclude that it too is not a good candidate for compile-time type inference. (4) This is the category which I was referring to when I said that Python wasn't a "computer-science-ey language": do people use Python for research into language-independent fundamental principles of computation? I don't think so. I agree with Marko that normally you: > you either use a pseudolanguage or some sort of formalism that > hasn't been implemented. E.g. most of the really deep stuff by Turing wasn't even performed on a computer, since there were no computers[1], or languages to program them in. A lot (all?) of Knuth's published work is written in an assembly language for an imaginary processor. Douglas Hofstadter invented two languages, BlooP and FlooP, to demonstrate the difference between programming languages that are, or aren't, Turing complete. (He also named a mythical super-Turing language GlooP.) Some languages are better suited for academic research of this nature. Python is too... messy, I suppose. Python's mix of imperative, functional and OOP paradigms makes it really useful for solving problems, but less useful for academic research of this type, where pure functional, pure OOP paradigms are more useful. Naturally I'm not saying that there is *absolutely no* comp-sci work done using Python, that would be foolish, only that it is in a minority and is not well-suited for the sort of problems academics are interested in. But since I'm not a computer scientist, perhaps I'm wrong. Anyone have any studies showing what percentage of research papers use various languages? > In theoretical computer science, they cherish off-the-wall models that > detach the topic from everyday applications. Here are examples that I > remember from graduate school: > > * combinatory birds in forests I don't believe that came from academia. If I've understood correctly, that was from a non-academic book on applying the lambda calculus to solve practical applications. > * unfaithful husbands on an island ruled by female logicians I don't know that one. > * dining philosophers getting into a deadlock over forks > > * Byzantine generals trying to agree on a surprise onslaught on a > besieged city [1] Actually there were. They were women who had the tedious job of performing large numbers of tedious computations by hand. But there were no *electronic* computers. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Sun Apr 6 13:27:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Apr 2014 03:27:56 +1000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Apr 7, 2014 at 2:52 AM, Steven D'Aprano wrote: > (4) This is the category which I was referring to when I said that Python > wasn't a "computer-science-ey language": do people use Python for > research into language-independent fundamental principles of computation? > I don't think so. I agree with Marko that normally you: > >> you either use a pseudolanguage or some sort of formalism that >> hasn't been implemented. > > E.g. most of the really deep stuff by Turing wasn't even performed on a > computer... A simple reason for that is summed up in the Zen of Python: Practicality beats purity. For a comp sci theoretical study, you want something that exemplifies purity. That's why you get examples like the ones mentioned below - a dining philosopher is fundamentally unable to do such a simple thing as look to see what his neighbours are doing, and is also apparently unable to think and eat at the same time (plus, why on earth can't they afford a few more forks in the interests of hygiene??!?). Defining all of mathematics in terms of lambda is wonderfully pure, and utterly useless for any practical purpose. It's the same, in my opinion, with the eternal arguments about functional vs imperative vs declarative programming languages, and with the differences between compilers and interpreters, and whether something's a second-generation or third-generation or fourth-generation language. You can define all those terms in nice pure ways ("a compiler translates code into something that can be executed directly, but an interpreter parses code bit by bit and executes it"), but most actually-usable systems blur the lines. I still haven't seen any real definition of FP or OOP (especially the latter, O!) that doesn't ultimately come down to "avoid these language features which violate FP/OOP principles", which means that most programming languages (and more so with popular languages) are neither and/or both. It's all very well to say that everything is a function whose return value depends solely on its arguments, but practicality demands that you allow side effects in certain places. And it's all very well to say that everything's an object and every bit of code is a method, but aiming too far for purity results in Java-like syntactic salt. Pike avoids this somewhat by letting you pretend that it's a C-like module with top-level functions, but actually it's instantiated an object and called a method on it. That's occasionally useful, but most of the time you just ignore it and work imperatively. Python goes a bit further: top-level is just code like anything else, and it gets executed straight down the line. Practicality beats purity. >> * unfaithful husbands on an island ruled by female logicians > > I don't know that one. Me neither, although I can see elements of classic logic analysis elements. Islands ruled by logicians, people who always tell the truth / always tell exact falsehoods, etc, etc. I don't know of any that involve unfaithful husbands, but it wouldn't surprise me. Would like to hear it though. ChrisA From rustompmody at gmail.com Sun Apr 6 13:31:53 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 6 Apr 2014 10:31:53 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <38795bc9-f67d-423f-a929-212b6b38ec8c@googlegroups.com> On Sunday, April 6, 2014 10:22:21 PM UTC+5:30, Steven D'Aprano wrote: > On Sun, 06 Apr 2014 12:05:16 +0300, Marko Rauhamaa wrote: > > Mark H Harris : > >> On 4/4/14 4:53 AM, Steven D'Aprano wrote: > >>> Python is not a computer-science-ey language. > >> Every programming language is interesting from a comp sci standpoint. > >> Some are more useful for research; python is one of those. > >> For what reasons do you disagree? > > Computer science doesn't mean "anything related to computers." > > Physicists typically couldn't care less about your heating up your lunch > > in the microwave oven. Similarly, computer scientists aren't interested > > in the mundane applications of their lofty research topics. > > Python, BTW, is perfectly suitable for computer science. > I don't think it is. Python is not a pure functional language, so it's > very difficult to prove anything about the code apart from running it. > For example, see Brett Cannon's master's thesis, where he essentially > demonstrates that: > - you can't do compile-time type inference of general types in Python; > - although you can infer a very small amount of information about a > few built-in types; > - adding specialized byte-codes to handle those types gives, at best, > a marginal performance boost, and sometimes even slows code down. > To quote from the conclusion: > "Introducing over 3,000 lines of new C code to Python's compiler > to get, at best, a 1% improvement is in no way justified. The > level of added complexity that would be introduced into the > compilation step would definitely need to lead to a noticeable > performance improvement, the 5% that was the goal, to justify the > cost of code maintenance." > http://citeseerx.ist.psu.edu/viewdoc/download? > doi=10.1.1.90.3231&rep=rep1&type=pdf Thanks for the link. It think however you are reading it more widely than intended. The appropriate context is a few paras below: | In the end, it seems that Python, as a language, is not geared towards | type inference. Its flexibility, considered a great strength, | interferes with how extensive type inference can be performed. Without | a significant change to the language, type inference is not worth the | hassle of implementation So... Yes if CS begins and ends with type-inference then your conclusion would be valid. However consider that some of the things that people did around 40 years ago and do today - use FORTRAN for numerical/simulation work -- now use scipy/sage etc - NLP with Lisp/Prolog -- look at Nltk - ??? with Data Analysis in Pandas - Scheme (basis for programming pedagogy, semantics research) -> Python you can add/multiply ad libitum Yeah you covered this in your (2) as "...just a tool..." Ask some recent PhD about what is for you "just" an almost irrelevant tool and you are very likely to find that that choice may well have been the difference between completing the research and giving up. I think python wins because it (usually) lets people do their thing (includes but not limited to CS-research) and gets out of the way. To say therefore that it is irrelevant to the research is a strange inversion of its advantages. [Or simply just switch to C++ for 3 months and report back with the increment in your white-hair-count] In short, I just dispute your 'just'! From elbarbun at gmail.com Sun Apr 6 13:49:45 2014 From: elbarbun at gmail.com (Marco S.) Date: Sun, 6 Apr 2014 19:49:45 +0200 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: References: <8084-1396540962-768613@sneakemail.com> Message-ID: On 3 April 2014 20:12, Ian Kelly ian.g.kelly-at-gmail.com | python-list at python.org| wrote: > Use this instead [of continue]: > > switch day case in ("Mon", "Tue", "Wed", "Thu", "Fri"): > go_to_work = True > day_type = "ferial" > if day in ("Tue", "Thu"): > lunch_time = datetime.time(11, 30) > meeting_time = datetime.time(12, 30) > else: > lunch_time = datetime.time(12) > meeting_time = datetime.time(14) > case in ("Sat", "Sun"): > go_to_work = False > day_type = "festive" > > You get an extra level of indentation this way, but it reads less like > spaghetti code. Well, if you have to add an if-else to your switch-case, it means switch-case syntax is not so useful. An alternative is to imitate elif, so you'll have elcase. This way we don't need continue. Since I do not like elcasein, the best solution is to do as suggested by many of you, so case in instead of casein. But if you can write case in, why you can't write "case" comp_operator in general? With this syntax you can do also case is not, case > etc... Your example will turn into briefing_days = ("Tue", "Thu") festive_days = ("Sat", "Sun") switch day case in briefing_days: lunch_time = datetime.time(11, 30) meeting_time = datetime.time(12, 30) case not in briefing_days + festive_days: lunch_time = datetime.time(12) meeting_time = datetime.time(14) case in festive_days: go_to_work = False day_type = "festive" else: go_to_work = True day_type = "ferial" The if-else equivalent will be: if day in briefing_days: lunch_time = datetime.time(11, 30) meeting_time = datetime.time(12, 30) if day not in briefing_days + festive_days: lunch_time = datetime.time(12) meeting_time = datetime.time(14) if day in festive_days: go_to_work = False day_type = "festive" else: go_to_work = True day_type = "ferial" If you don't specify comp_operator, the default is ==. Example: switch day_num case 1: day_str = "Monday" elcase 2: day_str = "Thursday" else: day_str = "etcetera" -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Apr 6 13:54:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Apr 2014 03:54:15 +1000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <38795bc9-f67d-423f-a929-212b6b38ec8c@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <38795bc9-f67d-423f-a929-212b6b38ec8c@googlegroups.com> Message-ID: On Mon, Apr 7, 2014 at 3:31 AM, Rustom Mody wrote: > However consider that some of the things that people did around 40 years > ago and do today > > - use FORTRAN for numerical/simulation work -- now use scipy/sage etc > - NLP with Lisp/Prolog -- look at Nltk > - ??? with Data Analysis in Pandas > - Scheme (basis for programming pedagogy, semantics research) -> Python > > you can add/multiply ad libitum > > Yeah you covered this in your (2) as "...just a tool..." > > Ask some recent PhD about what is for you "just" an almost irrelevant > tool and you are very likely to find that that choice may well have > been the difference between completing the research and giving up. > > I think python wins because it (usually) lets people do their thing Allow me to put it another way. Mathematicians use the language of algebra to describe their research; they don't, by and large, use a programming language. They use pencils and paper [1] as tools to get their work done, and may well have strong opinions on which pencil brand is the best, but the point of the pencil (pun intended) is to enable something else. It's supposed to get out of the way and let them do their thing. Python is highly practical because it gets out of the way. It's not the way that you develop programming language theory, though. I might start out designing a language with the express purpose of implementing everything as an expression. The whole program consists of one long expression, with perhaps the semicolon being a sequence point that evaluates its left side, then evaluates its right side, and returns the latter (like the C comma operator). I could then go through a whole lot of lovely mental exploration as to what the benefits and costs of that system are, all the while writing nothing more than design documents and example code. At some point, if I'm happy with it, I'll write a reference implementation, and maybe then I'll use Python for the job. But that's not using Python to explore a language concept; that's using Python to rapidly prototype the executable code that I need in order to show my new language at work. All the work of developing the language is done in the design stage, with nothing at all even needing a computer (although I *guarantee* you that if I were to start something like that, I'd find part way through that I've made some fundamental mistakes early on - and a computer is better for editing text than anything on paper). I could just as easily write my reference implementation using yacc/bison and C, and it wouldn't be materially different. Using Python at the design stage would be what Steven's talking about - actually using it to build the theory of programming. I have about as much experience in the area as he has, so we can't speak to the lack of examples, but that's the sort of example it would take. ChrisA [1] As the old joke goes: The physics department needs a whole lot of expensive equipment, but the math department needs only pencils, paper, and wastepaper baskets. And the philosophy department goes even further: they don't need wastepaper baskets. From breamoreboy at yahoo.co.uk Sun Apr 6 14:09:21 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 06 Apr 2014 19:09:21 +0100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/04/2014 18:27, Chris Angelico wrote: > (plus, why on earth can't they afford a few more forks in the > interests of hygiene??!?). They couldn't get the purchase order for these capital cost items past the accountants. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Sun Apr 6 14:07:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Apr 2014 04:07:02 +1000 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: References: <8084-1396540962-768613@sneakemail.com> Message-ID: On Mon, Apr 7, 2014 at 3:49 AM, Marco S. wrote: > switch day case in briefing_days: > > lunch_time = datetime.time(11, 30) > meeting_time = datetime.time(12, 30) > case not in briefing_days + festive_days: > > lunch_time = datetime.time(12) > meeting_time = datetime.time(14) > case in festive_days: > > go_to_work = False > day_type = "festive" > else: > > go_to_work = True > day_type = "ferial" > > The if-else equivalent will be: > > if day in briefing_days: > > lunch_time = datetime.time(11, 30) > meeting_time = datetime.time(12, 30) > if day not in briefing_days + festive_days: > > lunch_time = datetime.time(12) > meeting_time = datetime.time(14) > if day in festive_days: > > go_to_work = False > day_type = "festive" > else: > > go_to_work = True > day_type = "ferial" Here's a simpler form of the proposal, which might cover what you need. It's basically a short-hand if/elif tree. case expression comp_op expression: suite case [comp_op] expression: suite ... else: suite This has a slight oddity of parsing (in that an expression can normally have a comparison in it); if you really want to use the result of a comparison inside a case block, you'd have to parenthesize it. But it's easy enough to explain to a human. case day in briefing_days: lunch_time = datetime.time(11, 30) meeting_time = datetime.time(12, 30) case not in briefing_days + festive_days: lunch_time = datetime.time(12) meeting_time = datetime.time(14) case in festive_days: go_to_work = False day_type = "festive" else: go_to_work = True day_type = "ferial" A case statement that opens with a comparison operator takes the value from the previous case (without re-evaluating it); a case statement that lacks a comparison altogether assumes == and does the above. In either case (pardon the pun), the check will be done only if the preceding case was false. An 'else' clause is effectively equivalent to a 'case' that's always true. Adds only one keyword to the language ("switch" is gone), and adds an edge case to parsing that's unlikely to come up in non-contrived code. ChrisA From rosuav at gmail.com Sun Apr 6 14:14:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Apr 2014 04:14:21 +1000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Apr 7, 2014 at 4:09 AM, Mark Lawrence wrote: > On 06/04/2014 18:27, Chris Angelico wrote: >> >> (plus, why on earth can't they afford a few more forks in the >> interests of hygiene??!?). > > > They couldn't get the purchase order for these capital cost items past the > accountants. That would explain why they spend so much time thinking. Can't afford pencils and paper to write their thoughts down, so they sit in the sun and one by one they collect their thoughts and think them over. ChrisA From rustompmody at gmail.com Sun Apr 6 14:13:05 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 6 Apr 2014 11:13:05 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <38795bc9-f67d-423f-a929-212b6b38ec8c@googlegroups.com> Message-ID: On Sunday, April 6, 2014 11:24:15 PM UTC+5:30, Chris Angelico wrote: > On Mon, Apr 7, 2014 at 3:31 AM, Rustom Mody wrote: > > However consider that some of the things that people did around 40 years > > ago and do today > > - use FORTRAN for numerical/simulation work -- now use scipy/sage etc > > - NLP with Lisp/Prolog -- look at Nltk > > - ??? with Data Analysis in Pandas > > - Scheme (basis for programming pedagogy, semantics research) -> Python > > you can add/multiply ad libitum > > Yeah you covered this in your (2) as "...just a tool..." > > Ask some recent PhD about what is for you "just" an almost irrelevant > > tool and you are very likely to find that that choice may well have > > been the difference between completing the research and giving up. > > I think python wins because it (usually) lets people do their thing > [1] As the old joke goes: The physics department needs a whole lot of > expensive equipment, but the math department needs only pencils, > paper, and wastepaper baskets. And the philosophy department goes even > further: they don't need wastepaper baskets. HaHa! Very funny and unpleasantly accurate! > Allow me to put it another way. Mathematicians use the language of > algebra to describe their research; they don't, by and large, use a > programming language. They use pencils and paper [1] as tools to get > their work done, and may well have strong opinions on which pencil > brand is the best, but the point of the pencil (pun intended) is to > enable something else. It's supposed to get out of the way and let > them do their thing. Python is highly practical because it gets out of > the way. It's not the way that you develop programming language > theory, though. Right. Whats wrong is (the implication -- maybe its not there??) that CS begins and ends with "develop programming language theory" > I might start out designing a language with the express purpose of > implementing everything as an expression. The whole program consists > of one long expression, with perhaps the semicolon being a sequence > point that evaluates its left side, then evaluates its right side, and > returns the latter (like the C comma operator). I could then go > through a whole lot of lovely mental exploration as to what the > benefits and costs of that system are, all the while writing nothing > more than design documents and example code. At some point, if I'm > happy with it, I'll write a reference implementation, and maybe then > I'll use Python for the job. But that's not using Python to explore a > language concept; that's using Python to rapidly prototype the > executable code that I need in order to show my new language at work. > All the work of developing the language is done in the design stage, > with nothing at all even needing a computer (although I *guarantee* > you that if I were to start something like that, I'd find part way > through that I've made some fundamental mistakes early on - and a > computer is better for editing text than anything on paper). I could > just as easily write my reference implementation using yacc/bison and > C, and it wouldn't be materially different. Again I dispute the 'just'. Its a right example for the wrong reason: State of art of writing language implementations in python is no-better-probably-worse than the venerable yacc ecosystem. Choose an example where the difference between poor and good tool is more palpable and the 'just' will no longer be upholdable as just. Is the diff between cvs/svn and git "just one vcs or another"? > Using Python at the design stage would be what Steven's talking about > - actually using it to build the theory of programming. I have about > as much experience in the area as he has, so we can't speak to the > lack of examples, but that's the sort of example it would take. !Parse Error! What are you saying -- I don get :-) From rosuav at gmail.com Sun Apr 6 14:46:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Apr 2014 04:46:54 +1000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <38795bc9-f67d-423f-a929-212b6b38ec8c@googlegroups.com> Message-ID: On Mon, Apr 7, 2014 at 4:13 AM, Rustom Mody wrote: > Is the diff between cvs/svn and git "just one vcs or another"? The theory of version control, or source control, or whatever you want to call it, can be found in some of the docs for those systems (git goes into some depth about the Directed Acyclic Graph that underpins everything), but that theory isn't what makes git or cvs/svn useful. The theory behind my MUD client "Gypsum" is that it should be built the way a server is, including that it should not need to be restarted even when there's new code to be loaded in; but that's not what makes Gypsum useful. The theory behind an ergonomic keyboard is that it should hurt your hands less than a classic keyboard does, but that's not what makes it useful. Actually, in that instance, it might be what makes it useless... >> Using Python at the design stage would be what Steven's talking about >> - actually using it to build the theory of programming. I have about >> as much experience in the area as he has, so we can't speak to the >> lack of examples, but that's the sort of example it would take. > > !Parse Error! What are you saying -- I don get :-) What I'm saying is that I - and, if my reading is correct, similarly with Steven - am looking for is a prominent example of someone using Python as the very basis for a discussion on the future of computer science *as a field*. So, not "here's what can be done with Python", and not "here's something about hydraulics, with some Python code showing how my theory adds up". If you're developing a cryptography algorithm, it might well be convenient to support it with Python code (although I mostly see reference implementations in C), but that's still using Python as a tool, rather than as a language for fundamental development of comp sci theories. ChrisA From torriem at gmail.com Sun Apr 6 16:13:30 2014 From: torriem at gmail.com (Michael Torrie) Date: Sun, 06 Apr 2014 14:13:30 -0600 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: References: <8084-1396540962-768613@sneakemail.com> Message-ID: <5341B56A.40004@gmail.com> On 04/06/2014 12:07 PM, Chris Angelico wrote: > This has a slight oddity of parsing (in that an expression can > normally have a comparison in it); if you really want to use the > result of a comparison inside a case block, you'd have to parenthesize > it. But it's easy enough to explain to a human. This syntax is almost identical to the if/elif/else syntax, though, no? > > case day in briefing_days: > lunch_time = datetime.time(11, 30) > meeting_time = datetime.time(12, 30) > case not in briefing_days + festive_days: > lunch_time = datetime.time(12) > meeting_time = datetime.time(14) > case in festive_days: > go_to_work = False > day_type = "festive" > else: > go_to_work = True > day_type = "ferial" > > A case statement that opens with a comparison operator takes the value > from the previous case (without re-evaluating it); a case statement > that lacks a comparison altogether assumes == and does the above. In > either case (pardon the pun), the check will be done only if the > preceding case was false. An 'else' clause is effectively equivalent > to a 'case' that's always true. > > Adds only one keyword to the language ("switch" is gone), and adds an > edge case to parsing that's unlikely to come up in non-contrived code. > > ChrisA > From marko at pacujo.net Sun Apr 6 16:10:47 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 06 Apr 2014 23:10:47 +0300 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87txa643so.fsf@elektro.pacujo.net> Steven D'Aprano : > On Sun, 06 Apr 2014 12:05:16 +0300, Marko Rauhamaa wrote: >> Python, BTW, is perfectly suitable for computer science. > > I don't think it is. Python is not a pure functional language, so it's > very difficult to prove anything about the code apart from running it. Many classic CS ideas are expressed in terms of an Algol-like language. Nothing would prevent you from framing those ideas in a Python-like (pseudo)language. The question is mostly whether you prefer begin/end, braces or indentation. >> * combinatory birds in forests > > I don't believe that came from academia. If I've understood correctly, > that was from a non-academic book on applying the lambda calculus to > solve practical applications. It is academic because the author, Raymond Smullyan, was a professor of philosophy and, more importantly, my professor selected that as a textbook for us graduate students. Marko From marko at pacujo.net Sun Apr 6 16:23:55 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 06 Apr 2014 23:23:55 +0300 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ppku436s.fsf@elektro.pacujo.net> Chris Angelico : >>> * unfaithful husbands on an island ruled by female logicians >> >> I don't know that one. > > Me neither, although I can see elements of classic logic analysis > elements. Islands ruled by logicians, people who always tell the truth > / always tell exact falsehoods, etc, etc. I don't know of any that > involve unfaithful husbands, but it wouldn't surprise me. Would like > to hear it though. Here's how I remember it: There was a tiny matriarchal island ruled by a queen. The women were capable logicians and that was common knowledge. The idyllic island had a problem, though: faithless husbands. The queen decided to solve the problem and summoned all women to the market square. She said: We need to solve the problem of unfaithful husbands once and for all. Now, we all know which men are cheating on their wives except our own. I hereby ban you from talking about this matter with each other ever again. However, if one day you should come to know your husband has been unfaithful, I am ordering you to show no mercy but shoot him to death the following night while he is asleep. The women left and went back to their business. The night after 40 days, shots were heard throughout the island. How many husbands were unfaithful? How did they find out? It was a variation of numerous similar puzzles and was the topic of a dissertation on knowledge logic, IIRC. Marko From ian.g.kelly at gmail.com Sun Apr 6 16:55:47 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 6 Apr 2014 14:55:47 -0600 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: <11366-1396806627-75788@sneakemail.com> References: <8084-1396540962-768613@sneakemail.com> <11366-1396806627-75788@sneakemail.com> Message-ID: On Sun, Apr 6, 2014 at 11:49 AM, Lucas Malor <3kywjyds5d at snkmail.com> wrote: > On 3 April 2014 20:12, Ian Kelly ian.g.kelly-at-gmail.com > |python-list at python.org| wrote: >> Use this instead [of continue]: > >> >> switch day case in ("Mon", "Tue", "Wed", "Thu", "Fri"): >> go_to_work = True >> day_type = "ferial" >> if day in ("Tue", "Thu"): >> lunch_time = datetime.time(11, 30) >> meeting_time = datetime.time(12, 30) >> else: >> lunch_time = datetime.time(12) >> meeting_time = datetime.time(14) >> case in ("Sat", "Sun"): >> go_to_work = False >> day_type = "festive" >> >> You get an extra level of indentation this way, but it reads less like >> spaghetti code. > > > Well, if you have to add an if-else to your switch-case, it means > switch-case syntax is not so useful. I agree; the above is better suited to be an if. > An alternative is to imitate elif, so you'll have elcase. This way we don't > need continue. Since I do not like elcasein, the best solution is to do as > suggested by many of you, so case in instead of casein. So if I'm understanding your intention correctly, "case" means to check this case regardless of whether any preceding case was matched, and "elcase" means to check this case only if the most recent "case" and its dependent "elcases" preceding this one were not matched. switch "Mon" case in ("Tue", "Thu"): print(1) elcase in ("Mon", "Wed", "Fri"): print(2) case in ("Sat", "Sun"): print(3) elcase in ("Mon", "Tue", "Wed", "Thu", "Fri"): print(4) will print 2 and 4, correct? > But if you can write case in, why you can't write "case" comp_operator in > general? With this syntax you can do also case is not, case > etc... At this point I see no advantage in adding this syntax. It is so similar to an if-elif chain that surely any optimization that could be applied would be equally possible if the if-elif syntax, so why not just use that? From breamoreboy at yahoo.co.uk Sun Apr 6 16:56:05 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 06 Apr 2014 21:56:05 +0100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <87txa643so.fsf@elektro.pacujo.net> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <87txa643so.fsf@elektro.pacujo.net> Message-ID: On 06/04/2014 21:10, Marko Rauhamaa wrote: > > Many classic CS ideas are expressed in terms of an Algol-like language. > Nothing would prevent you from framing those ideas in a Python-like > (pseudo)language. The question is mostly whether you prefer begin/end, > braces or indentation. > Of course whilst all this work in the fields of languages, algorithms and such like has been going on, in parallel engineers have been working on the hardware side of things. My understanding is that some abacuses now have as many as ten strings on them. Although this scale was at first difficult for the users to grasp, the designers came up with the fantastic idea of using different coloured beads on different strings to simplify the user experience. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Sun Apr 6 19:16:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Apr 2014 09:16:21 +1000 Subject: Yet Another Switch-Case Syntax Proposal In-Reply-To: <5341B56A.40004@gmail.com> References: <8084-1396540962-768613@sneakemail.com> <5341B56A.40004@gmail.com> Message-ID: On Mon, Apr 7, 2014 at 6:13 AM, Michael Torrie wrote: > On 04/06/2014 12:07 PM, Chris Angelico wrote: >> This has a slight oddity of parsing (in that an expression can >> normally have a comparison in it); if you really want to use the >> result of a comparison inside a case block, you'd have to parenthesize >> it. But it's easy enough to explain to a human. > > This syntax is almost identical to the if/elif/else syntax, though, no? Like I said, it's a short-hand for an if/elif tree, nothing more. Most of the proposals have effectively been that anyway. There are differences, though; the case target gets evaluated only once, for instance. I'm not pushing strongly for its addition to the language. ChrisA From rymg19 at gmail.com Sun Apr 6 19:24:53 2014 From: rymg19 at gmail.com (Ryan Gonzalez) Date: Sun, 6 Apr 2014 18:24:53 -0500 Subject: [ANN] ClamAV for Python 0.2! Message-ID: Announcing ClamAV for Python 0.2! ClamAV for Python is a set of pure-Python bindings for libclamav. This version adds basic support for callbacks and makes it work under Python 3. Check it out of PyPIand GitHub . Report bugs to the Issue tracker . -- Ryan If anybody ever asks me why I prefer C++ to C, my answer will be simple: "It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was nul-terminated." -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sun Apr 6 19:48:22 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Apr 2014 23:48:22 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <87txa643so.fsf@elektro.pacujo.net> Message-ID: <5341e7c6$0$29993$c3e8da3$5496439d@news.astraweb.com> On Sun, 06 Apr 2014 23:10:47 +0300, Marko Rauhamaa wrote: > Steven D'Aprano : > >> On Sun, 06 Apr 2014 12:05:16 +0300, Marko Rauhamaa wrote: >>> Python, BTW, is perfectly suitable for computer science. >> >> I don't think it is. Python is not a pure functional language, so it's >> very difficult to prove anything about the code apart from running it. > > Many classic CS ideas are expressed in terms of an Algol-like language. > Nothing would prevent you from framing those ideas in a Python-like > (pseudo)language. The question is mostly whether you prefer begin/end, > braces or indentation. Okay, I made an error in stating that it's because Python is not a pure functional language. It's because Python is so dynamic that it is very difficult to prove anything about the code apart from running it. Take this code-snippet of Python: n = len([1, 2, 3]) What can we say about it? Almost nothing! All we know is that the name "len" will be looked up, it may or may not find something, that thing may or may not be callable, calling it with a list may or may not succeed, and it may or may not return 3 when given that specific list as input. From the perspective of wanting to prove things about the code, there's not a lot of certainty there. If we replace Python with a Python-like language which is closer to the traditional Algol mode of built-in functions being keywords (and hence unable to be shadowed or deleted) then we can reason about the behaviour more successfully. Alas, a Python-like language is not Python, and our discussion is about whether or not *Python* is suitable for this use. >>> * combinatory birds in forests >> >> I don't believe that came from academia. If I've understood correctly, >> that was from a non-academic book on applying the lambda calculus to >> solve practical applications. > > It is academic because the author, Raymond Smullyan, was a professor of > philosophy and, more importantly, my professor selected that as a > textbook for us graduate students. Ah. Well they do that, don't they? I've always consider the ability of professors to select their own book as text to be a classic case of conflict of interest. They're supposed to pick the best book, not necessarily the one that earns them money. -- Steven D'Aprano http://import-that.dreamwidth.org/ From tjreedy at udel.edu Sun Apr 6 20:45:47 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 06 Apr 2014 20:45:47 -0400 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <5341e7c6$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <87txa643so.fsf@elektro.pacujo.net> <5341e7c6$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/6/2014 7:48 PM, Steven D'Aprano wrote: > On Sun, 06 Apr 2014 23:10:47 +0300, Marko Rauhamaa wrote: > >> Steven D'Aprano : >> >>> On Sun, 06 Apr 2014 12:05:16 +0300, Marko Rauhamaa wrote: >>>> Python, BTW, is perfectly suitable for computer science. >>> >>> I don't think it is. Python is not a pure functional language, so it's >>> very difficult to prove anything about the code apart from running it. >> >> Many classic CS ideas are expressed in terms of an Algol-like language. >> Nothing would prevent you from framing those ideas in a Python-like >> (pseudo)language. The question is mostly whether you prefer begin/end, >> braces or indentation. > > Okay, I made an error in stating that it's because Python is not a pure > functional language. It's because Python is so dynamic that it is very > difficult to prove anything about the code apart from running it. Take > this code-snippet of Python: > > n = len([1, 2, 3]) > > What can we say about it? Almost nothing! One merely needs to stipulate that builtin names have not been rebound to give the answer: n is bound to 3. In the absence of code or text specifying otherwise, that is the reasonable default assumption and the one that most makes when reading code. Restricting the usage of Python's flexibility does not make it another language. It makes it the actual language that the vast majority of programs are written in and that people assume when reading code. -- Terry Jan Reedy From rustompmody at gmail.com Sun Apr 6 21:54:19 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 6 Apr 2014 18:54:19 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <87txa643so.fsf@elektro.pacujo.net> <5341e7c6$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, April 7, 2014 6:15:47 AM UTC+5:30, Terry Reedy wrote: > On 4/6/2014 7:48 PM, Steven D'Aprano wrote: > > On Sun, 06 Apr 2014 23:10:47 +0300, Marko Rauhamaa wrote: > >> Steven D'Aprano : > >>> On Sun, 06 Apr 2014 12:05:16 +0300, Marko Rauhamaa wrote: > >>>> Python, BTW, is perfectly suitable for computer science. > >>> I don't think it is. Python is not a pure functional language, so it's > >>> very difficult to prove anything about the code apart from running it. > >> Many classic CS ideas are expressed in terms of an Algol-like language. > >> Nothing would prevent you from framing those ideas in a Python-like > >> (pseudo)language. The question is mostly whether you prefer begin/end, > >> braces or indentation. > > Okay, I made an error in stating that it's because Python is not a pure > > functional language. It's because Python is so dynamic that it is very > > difficult to prove anything about the code apart from running it. Take > > this code-snippet of Python: > > n = len([1, 2, 3]) > > What can we say about it? Almost nothing! > One merely needs to stipulate that builtin names have not been rebound > to give the answer: n is bound to 3. In the absence of code or text > specifying otherwise, that is the reasonable default assumption and the > one that most makes when reading code. > Restricting the usage of Python's flexibility does not make it another > language. It makes it the actual language that the vast majority of > programs are written in and that people assume when reading code. Well what Steven is saying (I think!) amounts to pointing out a gap: - the actual language that the vast majority of programs are written in - python as in the Cpython (say) implementation To close this gap requires trying to do what Brett Canon tried and more generally PyPy tries. Some small rarely used features which humans can invoke with with a wave-fo-hands when reasoning about programs, end up being a show-stopper in an implementation. Every language has such: Fortran remains better for scientific computing than C (leave aside C++) because among other things alias analysis for Fortran arrays is more straightforward. From rustompmody at gmail.com Sun Apr 6 22:32:29 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 6 Apr 2014 19:32:29 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <38795bc9-f67d-423f-a929-212b6b38ec8c@googlegroups.com> Message-ID: On Monday, April 7, 2014 12:16:54 AM UTC+5:30, Chris Angelico wrote: > On Mon, Apr 7, 2014 at 4:13 AM, Rustom Mody wrote: > >> Using Python at the design stage would be what Steven's talking about > >> - actually using it to build the theory of programming. I have about > >> as much experience in the area as he has, so we can't speak to the > >> lack of examples, but that's the sort of example it would take. > > !Parse Error! What are you saying -- I don get :-) > What I'm saying is that I - and, if my reading is correct, similarly > with Steven - am looking for is a prominent example of someone using > Python as the very basis for a discussion on the future of computer > science *as a field*. So, not "here's what can be done with Python", > and not "here's something about hydraulics, with some Python code > showing how my theory adds up". If you're developing a cryptography > algorithm, it might well be convenient to support it with Python code > (although I mostly see reference implementations in C), but that's > still using Python as a tool, rather than as a language for > fundamental development of comp sci theories. Nice example 10 years ago Nicholas Carr wrote an article: "Does IT matter?" http://hbr.org/2003/05/it-doesnt-matter/ar/1 | Twenty years ago, most executives looked down on computers as | proletarian tools?glorified typewriters and calculators?best relegated | to low level employees like secretaries, analysts, and technicians. It | was the rare executive who would let his fingers touch a keyboard, | much less incorporate information technology into his strategic | thinking. Today, that has changed completely. Chief executives now | routinely talk about the strategic value of information technology... | | Behind the change in thinking lies a simple assumption: that as IT?s | potency and ubiquity have increased, so too has its strategic | value. It?s a reasonable assumption, even an intuitive one. But it?s | mistaken. What makes a resource truly strategic?what gives it the | capacity to be the basis for a sustained competitive advantage?is not | ubiquity but scarcity. You only gain an edge over rivals by having or | doing something that they can?t have or do. By now, the core functions | of IT?data storage, data processing, and data transport?have become | available and affordable to all.1 Their very power and presence have | begun to transform them from potentially strategic resources into | commodity factors of production. They are becoming costs of doing | business that must be paid by all but provide distinction to none. Now replace IT by CS. CS matters because it has stopped being visible -- entered the woodword. This is the underlying principle of python replacing scheme for programming at MIT. Its not that python is a better language. Its rather that doing the job and getting out of the way is more crucial today than 1980. http://cemerick.com/2009/03/24/why-mit-now-uses-python-instead-of-scheme-for-its-undergraduate-cs-program/ So cryptographic algos need (typically) 1. An algorithmic language 2. Fast implementations Python only provides 1, C provides both.So C is more useful (ignoring the marginal effects of inertia) > > Is the diff between cvs/svn and git "just one vcs or another"? > The theory of version control, or source control, or whatever you want > to call it, can be found in some of the docs for those systems (git > goes into some depth about the Directed Acyclic Graph that underpins > everything), but that theory isn't what makes git or cvs/svn useful. > The theory behind my MUD client "Gypsum" is that it should be built > the way a server is, including that it should not need to be restarted > even when there's new code to be loaded in; but that's not what makes > Gypsum useful. > The theory behind an ergonomic keyboard is that it should hurt your > hands less than a classic keyboard does, but that's not what makes it > useful. Actually, in that instance, it might be what makes it > useless... These examples are very different: 1. MUD I dont know 2. Ergonomic keyboard is a good example. For a ergonomic keyboard to be useful it has to satisfy the precondition "Not more than a ? neighborhood away from QWERTY" 3. Git: We differ on whats the underlying theory. For me crucial is a. Peer-to-peer replacing client-server -- this gives the D in DVCS b. Branching as central to software (more generally any material) development From oxhazaroglu at ualr.edu Sun Apr 6 22:54:37 2014 From: oxhazaroglu at ualr.edu (Onder Hazaroglu) Date: Sun, 6 Apr 2014 21:54:37 -0500 Subject: threading Message-ID: Hello, I've been using threading library to run some experiments parallel. There is no message passing between my threads but still it messes up somehow. The results are different than running it separated. Basically I experiment with three threads working on three different files but the results are different than running three of them sequentially. Is there a way to make sure that there is no memory sharing between threads? -- Best Regards, Onder HAZAROGLU | Graduate Student | Ph.D. Candidate University of Arkansas at Little Rock | Computer Science Department EIT Bldg. | (501) 615-3851 | oxhazaroglu at ualr.edu, onderhazaroglu at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Sun Apr 6 23:05:03 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 07 Apr 2014 13:05:03 +1000 Subject: threading References: Message-ID: <85ha65261s.fsf@benfinney.id.au> Onder Hazaroglu writes: > I've been using threading library to run some experiments parallel. Threading is very difficult to get right, much more so than the usual separation into distinct processes. How did you decide against the normal means of parallel execution and instead choose threading? > There is no message passing between my threads but still it messes up > somehow. The results are different than running it separated. Yes, this is a common result of threading; problems are much harder to reproduce and much more entangled with apparently unrelated factors. This is one of the main reasons to avoid threading if at all feasible. > Is there a way to make sure that there is no memory sharing between > threads? The *whole point* of threading (AFAIK) is to share memory and other process-distinct resources. If you're looking to avoid that, don't use threading! Instead, use separate processes for parallel execution. Parallel processing is achieved much more reliably and deterministically with separate processes. Python even makes this much easier than most languages, with the ?multiprocessing? module in the standard library . I would recommend you make easier-to-understand and easier-to-debug code with that module, and only consider threading if you determine it's needed. -- \ ?Stop ? Drive sideways.? ?detour sign, Kyushu, Japan | `\ | _o__) | Ben Finney From rustompmody at gmail.com Sun Apr 6 23:22:22 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 6 Apr 2014 20:22:22 -0700 (PDT) Subject: threading In-Reply-To: References: Message-ID: <6a7cd37d-91e5-4e72-86c2-247b713e006c@googlegroups.com> On Monday, April 7, 2014 8:24:37 AM UTC+5:30, Onder Hazaroglu wrote: > Hello, > I've been using threading library to run some experiments parallel. There is > no message passing between my threads but still it messes up somehow. The > results are different than running it separated. Basically I experiment with > three threads working on three different files but the results are different > than running three of them sequentially. Is there a way to make sure that > there is no memory sharing between threads? Python -- like most languages -- does not provide the option: thread-efficiency plus process-isolation. Erlang makes this its centerpiece. So look at it if thats what you are after. From nispray at gmail.com Sun Apr 6 23:32:53 2014 From: nispray at gmail.com (Wesley) Date: Sun, 6 Apr 2014 20:32:53 -0700 (PDT) Subject: Python streaming media server In-Reply-To: References: <0a4cc21b-3d8d-483b-b24f-8bd61da59c0e@googlegroups.com> Message-ID: <0d4cf64b-8b62-4fb7-b4b9-e64c359fa80a@googlegroups.com> ? 2014?4?6????UTC+8??8?52?37??Sturla Molden??? > Wesley wrote: > > > > >> Not open source, but there is a famous closed-source one called YouTube. > > > > > > Are you kidding? > > > I know youtube, but do you think we can use it setup our own streaming media server? > > > > Obviously not. > > > > Before YouTube was bought by Google, it was common knowledge that it ran on > > Stackless Python. So a streaming media server on Python is absolutely > > possible. But no, I don't know of one you can set up and use on your own. > > > > You can make a highly scalable server with PyZMQ and Tornado or Twisted. > > NumPy is great for storing binary data like media streams. HDF5 (PyTables > > or h5py) might be a better database than some SQL server, as it is capable > > of highly scalable parallel binary i/o. > > > > Sturla Thanks, Sturla. Umm,I think we can setup one using the technique skills you mentioned above:-) But that will need a lot work to do I think. I am looking at an opensource one named Flumotion. Wesley From roy at panix.com Sun Apr 6 23:48:46 2014 From: roy at panix.com (Roy Smith) Date: Sun, 06 Apr 2014 23:48:46 -0400 Subject: threading References: Message-ID: In article , Ben Finney wrote: > The *whole point* of threading (AFAIK) is to share memory and other > process-distinct resources. There is (or at least, was) another reason. Creating a new process used to be far more expensive than creating a new thread. In modern Unix kernels, however, the cost difference has become much less, so this is no longer a major issue. I agree wholeheartedly with Ben when he says: > Parallel processing is achieved much more reliably and deterministically > with separate processes. Threading makes it incredibly difficult to reason about program execution. It's not just that things happen asynchronously, the control flow changes happen at arbitrary times. From rosuav at gmail.com Sun Apr 6 23:56:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Apr 2014 13:56:35 +1000 Subject: threading In-Reply-To: References: Message-ID: On Mon, Apr 7, 2014 at 1:48 PM, Roy Smith wrote: > There is (or at least, was) another reason. Creating a new process used > to be far more expensive than creating a new thread. In modern Unix > kernels, however, the cost difference has become much less, so this is > no longer a major issue. Unix maybe, but what about Windows? Is it efficient to create processes under Windows? ChrisA From marko at pacujo.net Mon Apr 7 00:54:27 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 07 Apr 2014 07:54:27 +0300 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <87txa643so.fsf@elektro.pacujo.net> <5341e7c6$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ha654u4c.fsf@elektro.pacujo.net> Steven D'Aprano : > On Sun, 06 Apr 2014 23:10:47 +0300, Marko Rauhamaa wrote: >> It is academic because the author, Raymond Smullyan, was a professor >> of philosophy and, more importantly, my professor selected that as a >> textbook for us graduate students. > > Ah. Well they do that, don't they? I've always consider the ability of > professors to select their own book as text to be a classic case of > conflict of interest. They're supposed to pick the best book, not > necessarily the one that earns them money. Note that "my professor" above was not Raymond Smullyan. Marko From steve at pearwood.info Mon Apr 7 01:10:22 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 07 Apr 2014 05:10:22 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <87txa643so.fsf@elektro.pacujo.net> <5341e7c6$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5342333e$0$11109$c3e8da3@news.astraweb.com> On Sun, 06 Apr 2014 20:45:47 -0400, Terry Reedy wrote: > On 4/6/2014 7:48 PM, Steven D'Aprano wrote: >> On Sun, 06 Apr 2014 23:10:47 +0300, Marko Rauhamaa wrote: >> >>> Steven D'Aprano : >>> >>>> On Sun, 06 Apr 2014 12:05:16 +0300, Marko Rauhamaa wrote: >>>>> Python, BTW, is perfectly suitable for computer science. >>>> >>>> I don't think it is. Python is not a pure functional language, so >>>> it's very difficult to prove anything about the code apart from >>>> running it. >>> >>> Many classic CS ideas are expressed in terms of an Algol-like >>> language. Nothing would prevent you from framing those ideas in a >>> Python-like (pseudo)language. The question is mostly whether you >>> prefer begin/end, braces or indentation. >> >> Okay, I made an error in stating that it's because Python is not a pure >> functional language. It's because Python is so dynamic that it is very >> difficult to prove anything about the code apart from running it. Take >> this code-snippet of Python: >> >> n = len([1, 2, 3]) >> >> What can we say about it? Almost nothing! > > One merely needs to stipulate that builtin names have not been rebound > to give the answer: n is bound to 3. But if I can do that, I can also stipulate that len() has been rebound to a function that ignores its argument and always returns the string "Surprise!". In that case, n is bound to the string "Surprise!". I can prove that this code snippet does almost *anything*, just be making some assumption about len. The point is that one cannot derive much about the behaviour of Python code except by analysing the whole program, which is a very difficult problem, and often not even then. The only way to be sure what value is bound to len at the time that code snippet is executed is to actually run the code up to that code snippet and then look. In practical terms, things are not quite as bleak as I've made out: a little bit of runtime analysis goes a long way, as the success of PyPy, Numba, Cython and Psyco prove. That's why optimizers like PyPy generally produce code like this: if some guard condition is true: run fast optimized branch else: fall back on standard Python where the guard condition is generally checked at runtime, not at compile time. But *in isolation*, you can't tell what len will be bound to unless you wait until runtime and look. A peephole optimizer that replaced a call like len([1,2,3]) with the constant 3 every time it sees it would be *wrong*. > In the absence of code or text > specifying otherwise, that is the reasonable default assumption and the > one that most makes when reading code. Well of course, but the requirements of an optimizer or correctness prover or similar is much higher than just "this is a reasonable default assumption". > Restricting the usage of Python's flexibility does not make it another > language. It makes it the actual language that the vast majority of > programs are written in and that people assume when reading code. That's incorrect. If len were a keyword, and couldn't be shadowed or replaced, it would be another language. It is not an accident that you can replace len in builtins, it is a deliberate feature of the language. -- Steven From marko at pacujo.net Mon Apr 7 01:10:49 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 07 Apr 2014 08:10:49 +0300 Subject: threading References: Message-ID: <87d2gt4td2.fsf@elektro.pacujo.net> Ben Finney : > The *whole point* of threading (AFAIK) is to share memory and other > process-distinct resources. Another way to look at it is that threads were pushed as a magic bullet to manage the complexities of network programming. They were fashionable in Windows and Java. The idea was that the programmer could write linear code that blocks on I/O and not be overwhelmed by the intricacies. I don't think it worked out all that well. Since then both Windows and Java have come up with their own I/O multiplexing facilities. Now we see Python follow suit with asyncio. Threads have their uses, but they are such tricky beasts that I would see first if the problem couldn't be handled with multiplexing and multiprocessing. The main need for threads today comes from the database libraries, which, AFAIK, generally don't provide a nonblocking API. Marko From marko at pacujo.net Mon Apr 7 01:14:52 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 07 Apr 2014 08:14:52 +0300 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <87txa643so.fsf@elektro.pacujo.net> <5341e7c6$0$29993$c3e8da3$5496439d@news.astraweb.com> <5342333e$0$11109$c3e8da3@news.astraweb.com> Message-ID: <878urh4t6b.fsf@elektro.pacujo.net> Steven D'Aprano : > That's why optimizers like PyPy generally produce code like this: > > if some guard condition is true: > run fast optimized branch > else: > fall back on standard Python There you go! You are using Python-esque syntax to communicate a CS idea. Marko From ben+python at benfinney.id.au Mon Apr 7 01:22:04 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 07 Apr 2014 15:22:04 +1000 Subject: threading References: Message-ID: <85d2gt1zpf.fsf@benfinney.id.au> Chris Angelico writes: > On Mon, Apr 7, 2014 at 1:48 PM, Roy Smith wrote: > > There is (or at least, was) another reason. Creating a new process > > used to be far more expensive than creating a new thread. In modern > > Unix kernels, however, the cost difference has become much less, so > > this is no longer a major issue. > > Unix maybe, but what about Windows? Is it efficient to create > processes under Windows? Another reason to avoid Microsoft's operating systems as a programming target, IMO. -- \ ?We cannot solve our problems with the same thinking we used | `\ when we created them.? ?Albert Einstein | _o__) | Ben Finney From no.email at nospam.invalid Mon Apr 7 01:39:05 2014 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 06 Apr 2014 22:39:05 -0700 Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> Message-ID: <7xha651yx2.fsf@ruckus.brouhaha.com> Marko Rauhamaa writes: > Since then both Windows and Java have come up with their own I/O > multiplexing facilities. Now we see Python follow suit with asyncio. That all happened because threads in those systems are rather expensive. GHC and Erlang have fast lightweight threads/processes and programming with them is much more civilized than using async schemes. Even a low level language like Forth reached something similar. I keep hearing about all the perils of threading bugs and it just hasn't happened to me in Python as far as I know. The main trick is to not share any mutable data between threads. Instead have them communicate by message passing through Queues. If you've got a lot of tasks in the system then it helps to have a bit of abstraction to keep the queues organized and make the other tasks addressible by name, but it's all pretty straightforward. You do take an efficiency hit, but if that's a big concern you sort of have to look past Python. Lately I'm messing with Go and it's sort of the same idea. From marko at pacujo.net Mon Apr 7 01:46:15 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 07 Apr 2014 08:46:15 +0300 Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> Message-ID: <874n254rq0.fsf@elektro.pacujo.net> Paul Rubin : > I keep hearing about all the perils of threading bugs and it just > hasn't happened to me in Python as far as I know. Good for you. I'm saying the first step to thread-safe code is to have a healthy fear of the perils. > The main trick is to not share any mutable data between threads. > Instead have them communicate by message passing through Queues. That certainly is a good way and is akin to multiprocessing. You still need to make sure you don't flood the queues or cause deadlocks by limiting queue sizes. It is still easy to accidentally pass references to mutable objects between threads (and most people don't even try to avoid it). Multiprocessing naturally enforces the principle. Marko From nh.jones01 at gmail.com Mon Apr 7 07:43:35 2014 From: nh.jones01 at gmail.com (Norah Jones) Date: Mon, 7 Apr 2014 11:43:35 +0000 Subject: What is Application Context and Request Context in Flask and WerkZeug. Message-ID: Hi, I am developing a web application using flask, Werkzeug and jinja2. I am very much confused with these terms and wanted to know the meaning of the terms and how they are interrelated to the CGI environment variables. What is global variable g and how it is related to the application context and request context. Also since I don't have much knowledge of developing web apps( I am doing it for first time) any another language also so there is another request if someone could give a reference or make me understand that how the requests are handled, i mean what happens when a request arrives to the web application. Also if i am not using any openID providers for logging in the user into my website, how can i make the password secure. Should i use any framework for that? Thanks, Norah Jones From steve+comp.lang.python at pearwood.info Mon Apr 7 08:19:56 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Apr 2014 12:19:56 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <87txa643so.fsf@elektro.pacujo.net> <5341e7c6$0$29993$c3e8da3$5496439d@news.astraweb.com> <87ha654u4c.fsf@elektro.pacujo.net> Message-ID: <534297eb$0$29993$c3e8da3$5496439d@news.astraweb.com> On Mon, 07 Apr 2014 07:54:27 +0300, Marko Rauhamaa wrote: > Steven D'Aprano : > >> On Sun, 06 Apr 2014 23:10:47 +0300, Marko Rauhamaa wrote: >>> It is academic because the author, Raymond Smullyan, was a professor >>> of philosophy and, more importantly, my professor selected that as a >>> textbook for us graduate students. >> >> Ah. Well they do that, don't they? I've always consider the ability of >> professors to select their own book as text to be a classic case of >> conflict of interest. They're supposed to pick the best book, not >> necessarily the one that earns them money. > > Note that "my professor" above was not Raymond Smullyan. Ah! Sorry about that, I misread your post as implying he was your professor. -- Steven D'Aprano http://import-that.dreamwidth.org/ From roy at panix.com Mon Apr 7 08:26:01 2014 From: roy at panix.com (Roy Smith) Date: Mon, 07 Apr 2014 08:26:01 -0400 Subject: threading References: Message-ID: In article , Chris Angelico wrote: > On Mon, Apr 7, 2014 at 1:48 PM, Roy Smith wrote: > > There is (or at least, was) another reason. Creating a new process used > > to be far more expensive than creating a new thread. In modern Unix > > kernels, however, the cost difference has become much less, so this is > > no longer a major issue. > > Unix maybe, but what about Windows? Is it efficient to create > processes under Windows? Whether something works well on Windows is really not something I worry about a lot. From rosuav at gmail.com Mon Apr 7 08:34:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Apr 2014 22:34:53 +1000 Subject: threading In-Reply-To: References: Message-ID: On Mon, Apr 7, 2014 at 10:26 PM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Mon, Apr 7, 2014 at 1:48 PM, Roy Smith wrote: >> > There is (or at least, was) another reason. Creating a new process used >> > to be far more expensive than creating a new thread. In modern Unix >> > kernels, however, the cost difference has become much less, so this is >> > no longer a major issue. >> >> Unix maybe, but what about Windows? Is it efficient to create >> processes under Windows? > > Whether something works well on Windows is really not something I worry > about a lot. It's a concern for some of us. Maybe one day supporting Windows will be like supporting Python 2.4 is now - something that only a few people do, and knowingly pay the complexity price for it - but for now, it's a fully-supported platform for a lot of Python software, so in a generic discussion, I'd say it's important to note it. Threading has NOT been entirely replaced with multiprocessing. ChrisA From roy at panix.com Mon Apr 7 09:22:12 2014 From: roy at panix.com (Roy Smith) Date: Mon, 07 Apr 2014 09:22:12 -0400 Subject: threading References: Message-ID: In article , Chris Angelico wrote: > On Mon, Apr 7, 2014 at 10:26 PM, Roy Smith wrote: > > Whether something works well on Windows is really not something I worry > > about a lot. > > It's a concern for some of us. You have my sympathy. > it's a fully-supported platform for a lot of Python software, so in a > generic discussion, I'd say it's important to note it. In all things technology related, there is an evolutionary path. It goes something like this: * bleeding edge * avant-garde * what the kewl kids are using * modern * mainstream * traditional * corporate standard * legacy * extended support * prehistoric I figure Windows (at least on the desktop) is legacy at this point. Or, in the case of XP (The Release That Wouldn't Die), extended support. I acknowledge it exists, and is still commercially important, and even has certain advantages, in the same way that I acknowledge the continued existence of incandescent light bulbs, POTS, C++, and film photography. I put threading in the same category. There are two major reasons for using threading: as an architectural pattern for doing non-blocking I/O, and to allow a program to take advantage of multiple processors in a single machine. Fortunately, we have figured out better ways to do both of those. The idea that we should continue to use threading just because Windows makes process creation hideously expensive compared to thread creation doesn't impress me as an argument in favor of threading. It impresses me as an argument in favor of ditching Windows. When I started using Python (1.4), it was somewhere around avant-garde. Now, I figure it's mainstream, which probably means it's time for me to move on to something else soon :-) From breamoreboy at yahoo.co.uk Mon Apr 7 09:41:12 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 07 Apr 2014 14:41:12 +0100 Subject: threading In-Reply-To: References: Message-ID: On 07/04/2014 14:22, Roy Smith wrote: > > When I started using Python (1.4), it was somewhere around avant-garde. > Now, I figure it's mainstream, which probably means it's time for me to > move on to something else soon :-) > Python 2.8? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From marko at pacujo.net Mon Apr 7 09:49:44 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 07 Apr 2014 16:49:44 +0300 Subject: threading References: Message-ID: <87zjjxp7uv.fsf@elektro.pacujo.net> Roy Smith : > The idea that we should continue to use threading just because Windows > makes process creation hideously expensive compared to thread creation > doesn't impress me as an argument in favor of threading. It impresses > me as an argument in favor of ditching Windows. There are many reasons to start processes or threads. One of them is performance (you have more than one CPU core). When performance is the objective, my rough guidelines would be: * Start your processes during initialization. * Start about twice as many processes as there are CPUs. IOW, the processes are there to exercise the CPUs and should not represent individual connections or other dynamic entities. I don't program for Windows, but that's the approach I would take under linux as well. Marko From chris at simplistix.co.uk Mon Apr 7 09:51:36 2014 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 07 Apr 2014 14:51:36 +0100 Subject: testfixtures 3.0.2 Released! Message-ID: <5342AD68.50201@simplistix.co.uk> Hi All, I'm pleased to announce the release of testfixtures 3.0.2. This is a bug fix release featuring the following changes: - Document ShouldRaise.raised and make it part of the official API. - Fix rare failures when cleaning up TempDirectory instances on Windows. If you haven't bumped into it already, testfixtures is a collection of helpers for writing succinct unit tests including help for: - Comparing objects and sequences Better feedback when the results aren't as you expected along with support for comparison of objects that don't normally support comparison. - Mocking out objects and methods Easy to use ways of stubbing out objects, classes or individual methods for both doc tests and unit tests. Special helpers are provided for testing with dates and times. - Testing logging Helpers for capturing logging output in both doc tests and unit tests. - Testing stream output Helpers for capturing stream output, such as that from print statements, and making assertion about it. - Testing with files and directories Support for creating and checking files and directories in sandboxes for both doc tests and unit tests. - Testing exceptions Easy to use ways of checking that a certain exception is raised, even down the to the parameters the exception is raised with. The package is on PyPI and a full list of all the links to docs, issue trackers and the like can be found here: http://www.simplistix.co.uk/software/python/testfixtures Any questions, please do ask on the Testing in Python list or on the Simplistix open source mailing list... cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From rosuav at gmail.com Mon Apr 7 10:24:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Apr 2014 00:24:14 +1000 Subject: threading In-Reply-To: References: Message-ID: On Mon, Apr 7, 2014 at 11:22 PM, Roy Smith wrote: > In all things technology related, there is an evolutionary path. It > goes something like this: > > * bleeding edge > * avant-garde > * what the kewl kids are using > * modern > * mainstream > * traditional > * corporate standard > * legacy > * extended support > * prehistoric > > I figure Windows (at least on the desktop) is legacy at this point. Or, > in the case of XP (The Release That Wouldn't Die), extended support. I > acknowledge it exists, and is still commercially important, and even has > certain advantages, in the same way that I acknowledge the continued > existence of incandescent light bulbs, POTS, C++, and film photography. And technologies can be, at the same time, at different points depending on where you look. To many people, OS/2 is prehistoric; to us, it's legacy. Incandescent light bulbs are legacy in a lot of places, but corporate standard in theatres (the modern replacement is LEDs, but their colors are distinctly different so you can't just pull out an incan and stick in an LED). Same goes for plenty of other technologies. To a lot of people, Windows is mainstream, and Linux is "what the non-cool kids are using", which doesn't exactly fit on your scale anywhere :) So if your audience is that sort of person, then to you Windows has to be considered mainstream or at least traditional, with Linux being the modern option that you're trying to push people onto. That's how I am with my MUD client. People use Windows, Mac OS, and Linux (plus various mobile devices, which I don't support); I'd like to push more people to Linux, but as a second-best, I can get them onto the same client that I'm developing on Linux, which minimizes the cross-platform development work. That's unlikely to change any time soon, so Windows support has to be a part of what I do. Doesn't mean I can't look with envy at projects that have dropped Windows support altogether and saved themselves a mess of trouble... ChrisA From rosuav at gmail.com Mon Apr 7 10:27:04 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Apr 2014 00:27:04 +1000 Subject: threading In-Reply-To: <87zjjxp7uv.fsf@elektro.pacujo.net> References: <87zjjxp7uv.fsf@elektro.pacujo.net> Message-ID: On Mon, Apr 7, 2014 at 11:49 PM, Marko Rauhamaa wrote: > Roy Smith : > >> The idea that we should continue to use threading just because Windows >> makes process creation hideously expensive compared to thread creation >> doesn't impress me as an argument in favor of threading. It impresses >> me as an argument in favor of ditching Windows. > > There are many reasons to start processes or threads. One of them is > performance (you have more than one CPU core). When performance is the > objective, my rough guidelines would be: > > * Start your processes during initialization. > > * Start about twice as many processes as there are CPUs. > > IOW, the processes are there to exercise the CPUs and should not > represent individual connections or other dynamic entities. That's potentially brutal on a shared system! I hope it's controlled by an option, or that you do this only in something you're writing for yourself alone. There are other reasons for forking per connection, though, such as state cleanup. You can guarantee that each job is done in a consistent state if it's spawned from the exact same point in the master process every time. That can help enormously if you're allowing any sort of foreign code, even from a trusted programmer. ChrisA From info at wingware.com Mon Apr 7 10:35:53 2014 From: info at wingware.com (Wingware) Date: Mon, 07 Apr 2014 10:35:53 -0400 Subject: ANN: Wing IDE 5.0.5 released Message-ID: <5342B7C9.7030209@wingware.com> Hi, Wingware has released version 5.0.5 of Wing IDE, our cross-platform integrated development environment for the Python programming language. Wing IDE includes a professional quality code editor with vi, emacs, visual studio, and other key bindings, auto-completion, call tips, goto-definition, find uses, refactoring, context-aware auto-editing, a powerful graphical debugger, version control, unit testing, search, and many other features. For details see http://wingware.com/ Changes in this minor release include: * Preference to control auto-spacing inside argument lists * Palette color and preference for changing occurrences color * Detect and flag unit tests that crash before running to completion * Fix Compare to Repository with recent SVN versions * Syntax highlighting for .scss CSS extension language files * Fix scraping extension modules in recent numpy versions * Fixed restarting after patch installation * Fix auto-editor and auto-completion context detection problems in the shells * Correctly show PEP 287 docstrings when indentation causes parse errors * Expand fold points on any edited line to avoid inaccessible folded lines * Improve and clarify validation of Python Executable in Project Properties * Several color adjustment fixes * About 25 other bug fixes For details see http://wingware.com/pub/wingide/5.0.5/CHANGELOG.txt A summary of new features in Wing 5: * Redesigned GUI based on Qt and PySide * Native GUI on OS X (and better overall OS-native look and feel) * Tools and editors can be dragged around * Toolbar and editor and Project context menus are configurable * Optional mode that opens different sets of files in each editor split * Sharable color palettes and syntax highlighting configurations * Auto-editing is on by default (except some operations that have a learning curve) * Named file sets * Sharable launch configurations * Named entry points * More control over unit testing environment * Lockable editor splits * Initial preferences dialog for new users * Support for Python 3.4 * Support for Django 1.6 * Support for matplotlib on Anaconda and with MacOSX backend * Improved Source Assistant with PEP 287 docstring rendering and return types * Improved integrated and PDF documentation For more information on what's new in Wing 5, see http://wingware.com/wingide/whatsnew Free trial: http://wingware.com/wingide/trial Downloads: http://wingware.com/downloads Feature list: http://wingware.com/wingide/features Sales: http://wingware.com/store/purchase Upgrades: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at support at wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE The Intelligent Development Environment for Python Programmers wingware.com From marko at pacujo.net Mon Apr 7 10:51:11 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 07 Apr 2014 17:51:11 +0300 Subject: threading References: <87zjjxp7uv.fsf@elektro.pacujo.net> Message-ID: <87vbulp50g.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Apr 7, 2014 at 11:49 PM, Marko Rauhamaa wrote: >> Roy Smith : >> IOW, the processes are there to exercise the CPUs and should not >> represent individual connections or other dynamic entities. > > That's potentially brutal on a shared system! I hope it's controlled > by an option, or that you do this only in something you're writing for > yourself alone. I'm thinking of a dedicated system here and exploiting the available CPU resources as efficiently as possible. > There are other reasons for forking per connection, though, such as > state cleanup. If we are talking about a handful of connections, a single asyncio process will be all you need (and will be gentle to other users of the shared system). When your server has to deal with thousands of simultaneous connections, spawning a process for each connection is probably not the optimal approach. It is precisely the scalability issues that caused Windows and Java go back to event-driven processing (that was prevalent in GUI design from the get-go). A company I used to work for was bitten badly by the multithreaded classic Java I/O, and a NIO overhaul was required when the connection count went to 500 and beyond. Marko From rosuav at gmail.com Mon Apr 7 11:12:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Apr 2014 01:12:47 +1000 Subject: threading In-Reply-To: <87vbulp50g.fsf@elektro.pacujo.net> References: <87zjjxp7uv.fsf@elektro.pacujo.net> <87vbulp50g.fsf@elektro.pacujo.net> Message-ID: On Tue, Apr 8, 2014 at 12:51 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Mon, Apr 7, 2014 at 11:49 PM, Marko Rauhamaa wrote: >>> Roy Smith : >>> IOW, the processes are there to exercise the CPUs and should not >>> represent individual connections or other dynamic entities. >> >> That's potentially brutal on a shared system! I hope it's controlled >> by an option, or that you do this only in something you're writing for >> yourself alone. > > I'm thinking of a dedicated system here and exploiting the available CPU > resources as efficiently as possible. Huh. I don't remember the last time I worked on any system that could be dedicated to one single job. My servers are all carrying multiple services (HTTP, SMTP, IMAP, DNS, database, maybe a MUD or two...), my desktop computer doubles as a router and a VM host and a server for a few internal things (the NIV 1984 translation of the Bible is hosted there, for convenience, as is my RSS reader), etc, etc, etc. Ages since I've had enough physical hardware that I can afford to say "You're *just* the XYZ server and nothing else". At very least, I'll usually want to have some spare CPU cycles so I can plop a backup service on there (eg a PostgreSQL replicating clone, or a fail-over HTTP server, or a secondary DNS), but mainly, I've been working for the past however-many years under budget constraints. Oh the luxury of a dedicated application server. But that's why I said "writing for yourself alone", or govern it with an option. For any sort of general server software, it should be able to cope with a shared system. (And that should probably be the default - anyone who's running a dedicated system will normally already be aware that most programs need to be tweaked before you get maximum throughput out of them.) ChrisA From pkoelle at gmail.com Mon Apr 7 11:26:37 2014 From: pkoelle at gmail.com (=?UTF-8?B?UGF1bCBLw7ZsbGU=?=) Date: Mon, 07 Apr 2014 17:26:37 +0200 Subject: Mutable objects inside tuples - good or bad? In-Reply-To: <53410185.6050304@islandtraining.com> References: <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> <53410185.6050304@islandtraining.com> Message-ID: <5342C3AD.9080707@subsignal.org> Am 06.04.2014 09:25, schrieb Gary Herron: > On 04/05/2014 11:53 PM, John Ladasky wrote: >> I find this programming pattern to be useful... but can it cause >> problems? > No. > > What kind of problems are you considering? It won't break Python. It's > perfectly legal code. > > The tuple c is still immutable, consisting of two specific objects, and > (as always) without regard to the specifics or contents of those two > objects. It seems a tuple's immutability is debatable, or is this another instance of the small-integer-reuse-implementation-detail-artifact? Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = ([1,2],[3,4]) >>> b = a >>> a is b True >>> a == b True >>> c = (1,2,3) >>> d = (1,2,3) >>> c is d False >>> c == d True cheers Paul From paul at subsignal.org Mon Apr 7 11:26:37 2014 From: paul at subsignal.org (=?UTF-8?B?UGF1bCBLw7ZsbGU=?=) Date: Mon, 07 Apr 2014 17:26:37 +0200 Subject: Mutable objects inside tuples - good or bad? In-Reply-To: <53410185.6050304@islandtraining.com> References: <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> <53410185.6050304@islandtraining.com> Message-ID: <5342C3AD.9080707@subsignal.org> Am 06.04.2014 09:25, schrieb Gary Herron: > On 04/05/2014 11:53 PM, John Ladasky wrote: >> I find this programming pattern to be useful... but can it cause >> problems? > No. > > What kind of problems are you considering? It won't break Python. It's > perfectly legal code. > > The tuple c is still immutable, consisting of two specific objects, and > (as always) without regard to the specifics or contents of those two > objects. It seems a tuple's immutability is debatable, or is this another instance of the small-integer-reuse-implementation-detail-artifact? Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = ([1,2],[3,4]) >>> b = a >>> a is b True >>> a == b True >>> c = (1,2,3) >>> d = (1,2,3) >>> c is d False >>> c == d True cheers Paul From rosuav at gmail.com Mon Apr 7 11:44:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Apr 2014 01:44:12 +1000 Subject: Mutable objects inside tuples - good or bad? In-Reply-To: <5342C3AD.9080707@subsignal.org> References: <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> <53410185.6050304@islandtraining.com> <5342C3AD.9080707@subsignal.org> Message-ID: On Tue, Apr 8, 2014 at 1:26 AM, Paul K?lle wrote: > It seems a tuple's immutability is debatable, or is this another instance of > the small-integer-reuse-implementation-detail-artifact? > > Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) > [GCC 4.4.5] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. >>>> a = ([1,2],[3,4]) >>>> b = a >>>> a is b > True >>>> a == b > True >>>> c = (1,2,3) >>>> d = (1,2,3) >>>> c is d > False >>>> c == d > True That's nothing to do with mutability or reuse. With a and b, you assigned one to be the same as the other, so they are by definition identical (and equal; tuples assume that identity implies equality, even though that may not be true of their elements). With c and d, you assigned separate tuples, so they're allowed to be separate objects. I'm not sure if they're allowed to be constant-folded, but CPython apparently isn't doing so. They are still equal, though; they contain equal elements, ergo they are equal. (Note that (1, 2, 3) and (1.0, 2.0, 3.0) are equal, but they obviously can't be identical any more than "1 is 1.0" can ever be True.) ChrisA From paul at subsignal.org Mon Apr 7 15:46:37 2014 From: paul at subsignal.org (=?UTF-8?B?UGF1bCBLw7ZsbGU=?=) Date: Mon, 07 Apr 2014 21:46:37 +0200 Subject: Mutable objects inside tuples - good or bad? In-Reply-To: References: <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> <53410185.6050304@islandtraining.com> <5342C3AD.9080707@subsignal.org> Message-ID: Am 07.04.2014 17:44, schrieb Chris Angelico: > On Tue, Apr 8, 2014 at 1:26 AM, Paul K?lle wrote: >> It seems a tuple's immutability is debatable, or is this another instance of >> the small-integer-reuse-implementation-detail-artifact? >> >> Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) >> [GCC 4.4.5] on linux2 >> >> Type "help", "copyright", "credits" or "license" for more information. >>>>> a = ([1,2],[3,4]) >>>>> b = a >>>>> a is b >> True >>>>> a == b >> True >>>>> c = (1,2,3) >>>>> d = (1,2,3) >>>>> c is d >> False >>>>> c == d >> True > > That's nothing to do with mutability or reuse. With a and b, you > assigned one to be the same as the other, so they are by definition > identical (and equal; tuples assume that identity implies equality, > even though that may not be true of their elements). With c and d, you > assigned separate tuples, so they're allowed to be separate objects. > I'm not sure if they're allowed to be constant-folded, but CPython > apparently isn't doing so. They are still equal, though; they contain > equal elements, ergo they are equal. (Note that (1, 2, 3) and (1.0, > 2.0, 3.0) are equal, but they obviously can't be identical any more > than "1 is 1.0" can ever be True.) > > ChrisA > Thanks Chris, stupid error indeed ;) cheers Paul From rosuav at gmail.com Mon Apr 7 18:47:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Apr 2014 08:47:02 +1000 Subject: Mutable objects inside tuples - good or bad? In-Reply-To: References: <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> <53410185.6050304@islandtraining.com> <5342C3AD.9080707@subsignal.org> Message-ID: On Tue, Apr 8, 2014 at 5:46 AM, Paul K?lle wrote: > Thanks Chris, stupid error indeed ;) Error, at least :) This is why we have a mailing list: errors, inaccuracies, and typos, regardless of who makes them or when, are pretty much guaranteed to be caught. ChrisA From tjreedy at udel.edu Mon Apr 7 20:16:05 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 07 Apr 2014 20:16:05 -0400 Subject: Mutable objects inside tuples - good or bad? In-Reply-To: <5342C3AD.9080707@subsignal.org> References: <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> <53410185.6050304@islandtraining.com> <5342C3AD.9080707@subsignal.org> Message-ID: On 4/7/2014 11:26 AM, Paul K?lle wrote: > >>> c = (1,2,3) > >>> d = (1,2,3) > >>> c is d > False An implementation would be allowed to make that True, as it does for small ints and short strings that could be identifiers. >>> a = 'one' >>> b = 'one' >>> a == b; a is b True True However, duplicate tuples are much rarer than duplicate identifier strings. -- Terry Jan Reedy From harrismh777 at gmail.com Mon Apr 7 21:33:31 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 07 Apr 2014 20:33:31 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <38795bc9-f67d-423f-a929-212b6b38ec8c@googlegroups.com> Message-ID: On 4/6/14 12:31 PM, Rustom Mody wrote: > I think python wins because it (usually) lets people do their thing > (includes but not limited to CS-research) > and gets out of the way. To say therefore that it is irrelevant to the > research is a strange inversion of its advantages. I think so too. I find python useful for modeling (prototyping) constructs that it [python interpreter] was not 'designed' to do. > [Or simply just switch to C++ for 3 months and report back with > the increment in your white-hair-count] Back in the day I used Rexx to prototype a new language idea, or a new computational technique. Today I use python for prototyping. From a CS standpoint I can use python for research in morphology because of the flexibility and extensibility of the namespace, and the easy ability to create new nouns and verbs through 'def' (as either function or generator) and the iterative process over data types like 'list' and 'dict'. I am playing with neural nets again, using python, and liking the fact that I can put my ideas into practice easily and python gets out of the way. I find it a great research language. I am surprised that others only see it as a problem solving tool. I have another question for y'all, is a function (particularly a generator) a noun or a verb? Does a function (or generator) 'do' something (based on name and parms) or does it 'return' something based on name and parms? Based on name and parms should a function (or generator) function as a noun, or function as a verb, or *both*? --or, are Classes nouns only, and all functions *are* verbs only? marcus From python at mrabarnett.plus.com Mon Apr 7 21:52:37 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 08 Apr 2014 02:52:37 +0100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <38795bc9-f67d-423f-a929-212b6b38ec8c@googlegroups.com> Message-ID: <53435665.1050509@mrabarnett.plus.com> On 2014-04-08 02:33, Mark H Harris wrote: > On 4/6/14 12:31 PM, Rustom Mody wrote: > >> I think python wins because it (usually) lets people do their thing >> (includes but not limited to CS-research) >> and gets out of the way. To say therefore that it is irrelevant to the >> research is a strange inversion of its advantages. > > I think so too. I find python useful for modeling (prototyping) > constructs that it [python interpreter] was not 'designed' to do. > >> [Or simply just switch to C++ for 3 months and report back with >> the increment in your white-hair-count] > > Back in the day I used Rexx to prototype a new language idea, or a > new computational technique. Today I use python for prototyping. > > From a CS standpoint I can use python for research in morphology > because of the flexibility and extensibility of the namespace, and the > easy ability to create new nouns and verbs through 'def' (as either > function or generator) and the iterative process over data types like > 'list' and 'dict'. I am playing with neural nets again, using python, > and liking the fact that I can put my ideas into practice easily and > python gets out of the way. I find it a great research language. I am > surprised that others only see it as a problem solving tool. > > > I have another question for y'all, is a function (particularly a > generator) a noun or a verb? Does a function (or generator) 'do' > something (based on name and parms) or does it 'return' something based > on name and parms? Based on name and parms should a function (or > generator) function as a noun, or function as a verb, or *both*? --or, > are Classes nouns only, and all functions *are* verbs only? > A function is an object (noun) that does stuff (verb). Does that make it clearer? :-) From sturla.molden at gmail.com Mon Apr 7 22:06:19 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 8 Apr 2014 02:06:19 +0000 (UTC) Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> Message-ID: <1554950943418614717.012948sturla.molden-gmail.com@news.gmane.org> Dennis Lee Bieber wrote: > That's been my experience too... Threading works for me... My attempts > at so called asyncio (whatever language) have always led to my having to > worry about losing data if some handler takes too long to return. > > To me, asyncio is closer to a polling interrupt handler, and I still > need a thread to handle the main processing. On a 32 bit system, the virtual address space with limit the scalabiliy for multi-threading in parallel i/o. That is, the stack space for each thread can quickly become a problem. Memory is not a problem on 64-bit servers. Multithreading can be used to solve the C10K problem, contrary to common belief. Before you dissmiss threads, take a look at this: http://www.mailinator.com/tymaPaulMultithreaded.pdf http://stackoverflow.com/questions/17593699/tcp-ip-solving-the-c10k-with-the-thread-per-client-approach My personal feeling is that asynchronous i/o is mostly useful on 32-bit systems, and the problem it actually solves is the limited virtual address space. On a 64 bit system we can just throw more RAM at it and threads be fine. Sturla From nispray at gmail.com Mon Apr 7 22:21:24 2014 From: nispray at gmail.com (Wesley) Date: Mon, 7 Apr 2014 19:21:24 -0700 (PDT) Subject: gdb python print truncated string Message-ID: <07421611-1c5c-4850-9617-a4ea2184c655@googlegroups.com> Hi all, I have a question regarding gdb python. I use gdb7.7 and python2.7.6. Here is snippet that py-print one variable: (gdb) py-print self local 'self' = , timer513645288=<_Timeout at remote 0xb42f760>, timer1248840930=<_Timeout at remote 0x7f85f7f4c300>, timer1678666863=<_Timeout at remote 0x7f85fec0ddf0>, timer888598936=<_Timeout at remote 0x7f860579a300>, timer1566174556=<_Timeout at remote 0xe69a7d0>, timer1307561941=<_Timeout at remote 0x7f85e41145a0>, timer1010094072=<_Timeout at remote 0xb42af40>, to_device={u'sendno': u'1252682169', u'msg_content': {u'message': {u'command': True}}, u'msg_type': u'2'}, timer2050775853=<_Timeout at remote 0x7f8606ddcb50>, timer1115907467=<_Timeout at remote 0x9c02140>, timer333587031=<_Timeout at remote 0xbb25450>, timer71350378=<_Timeout at remote 0x7f85e5e38220>, timer1044716881=<_Timeout at remote 0x7f86053094c0>, timer2069059536=<_Timeout at remote 0x7f85f3d3b530>, timer2139990080=<_Timeout at remote 0x8bd5370>, timer1121163931=<_Timeout at remote 0x99e5370>, queue=, maxsize=0, all_ta...(truncated) self is instance of Connection class. So, actually, I wanna check self.status...but you can see the print is truncated. I tried py-print self.status but failed. After a lot google work, somebody mention gdb 'set print elements 0/-1', but still failed.. So, how to check self.status value? Thanks. Wesley From steve+comp.lang.python at pearwood.info Mon Apr 7 22:53:35 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Apr 2014 02:53:35 GMT Subject: Mutable objects inside tuples - good or bad? References: <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> <53410185.6050304@islandtraining.com> <5342C3AD.9080707@subsignal.org> Message-ID: <534364af$0$29993$c3e8da3$5496439d@news.astraweb.com> On Mon, 07 Apr 2014 20:16:05 -0400, Terry Reedy wrote: > On 4/7/2014 11:26 AM, Paul K?lle wrote: > >> >>> c = (1,2,3) >> >>> d = (1,2,3) >> >>> c is d >> False > > An implementation would be allowed to make that True, as it does for > small ints and short strings that could be identifiers. And indeed, that happens in at least one circumstance in Python 3.3: py> a, b = [(1, 2, 3) for _ in range(2)] py> a is b True But: py> x = 3 py> a, b = [(1, 2, x) for _ in range(2)] py> a is b False As Terry knows, but for the benefit of others who may not, the re-use of objects leading to object identity ("a is b") is an implementation detail which *cannot be relied on*. It can change without notice, and is not a promise of the language. > >>> a = 'one' > >>> b = 'one' > >>> a == b; a is b > True > True In this case, it is a promise of the language that a will equal b: a and b must be bound to strings with the same value. But an implementation detail whether Python creates two strings, both with value "one", or just a single string, and uses it for both a and b. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Mon Apr 7 23:02:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Apr 2014 13:02:37 +1000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <38795bc9-f67d-423f-a929-212b6b38ec8c@googlegroups.com> Message-ID: On Tue, Apr 8, 2014 at 11:33 AM, Mark H Harris wrote: > Does a function (or generator) 'do' something (based on name and parms) or > does it 'return' something based on name and parms? If it has no side effects, then it does something, where the 'something' is returning a value. "Return" is a verb. (It can also be a noun, but in the context of functions, it's a verb.) ChrisA From daodennis at gmail.com Mon Apr 7 23:06:34 2014 From: daodennis at gmail.com (Dennis) Date: Mon, 7 Apr 2014 20:06:34 -0700 Subject: change spacing to two instead of four with pep8 or flake8? Message-ID: Hi, In Pylint you can change the spacing multiplier from 4 spaces to two in its pylintrc, but for the life of me I cannot find a way to do this with the flake8 / pep8 utilities. I want to avoid ignoring E111 altogether if at all possible, because it may catch other spacing problems that are not as obvious. hacky/non-hacky solutions welcome of course. If this is too specific and I should go to the pep8/flake8 MLs that is welcome advice too. Thanks, Dennis From Joshua.R.English at gmail.com Tue Apr 8 00:02:20 2014 From: Joshua.R.English at gmail.com (Josh English) Date: Mon, 7 Apr 2014 21:02:20 -0700 (PDT) Subject: Keeping track of things with dictionaries In-Reply-To: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> Message-ID: <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> On Sunday, April 6, 2014 12:44:13 AM UTC-7, Giuliano Bertoletti wrote: > obj = brands_seen.get(brandname) > > if obj is None: > obj = Brand() > brands_seen[brandname] = obj > > Would dict.setdefault() solve this problem? Is there any advantage to defaultdict over setdefault() Josh From rosuav at gmail.com Tue Apr 8 00:08:23 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Apr 2014 14:08:23 +1000 Subject: Keeping track of things with dictionaries In-Reply-To: <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: On Tue, Apr 8, 2014 at 2:02 PM, Josh English wrote: > On Sunday, April 6, 2014 12:44:13 AM UTC-7, Giuliano Bertoletti wrote: > > >> obj = brands_seen.get(brandname) >> >> if obj is None: >> obj = Brand() >> brands_seen[brandname] = obj >> >> > > Would dict.setdefault() solve this problem? Is there any advantage to defaultdict over setdefault() That depends on whether calling Brand() unnecessarily is a problem. Using setdefault() is handy when you're working with a simple list or something, but if calling Brand() is costly, or (worse) if it has side effects that you don't want, then you need to use a defaultdict. I think this is a textbook example of why defaultdict exists, though, so I'd be inclined to just use it, rather than going for setdefault :) ChrisA From marko at pacujo.net Tue Apr 8 01:19:02 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 08 Apr 2014 08:19:02 +0300 Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> Message-ID: <877g70wg8p.fsf@elektro.pacujo.net> Dennis Lee Bieber : > That's been my experience too... Threading works for me... My > attempts at so called asyncio (whatever language) have always led to > my having to worry about losing data if some handler takes too long to > return. > > To me, asyncio is closer to a polling interrupt handler, and I > still need a thread to handle the main processing. Yes, asynchronous processing results in complex, event-driven state machines that can be hard to get right. However, my experience is that that's the lesser evil. About a handler taking too long: you need to guard each state with a timer. Also, you need then to handle the belated handler after the timer has expired. The main problems with threads include: * Thread-safety is rarely done right. Also, when it's done wrong, it can be virtually impossible to fix it without a significant rewrite. This is not a theoretical concern: I have had to deal with the resulting nightmares in my work. * There is no accepted, taught, industry-wide discipline on proper thread-safety practices so every developer has to improvise. I have come up with a "bullet-proof" way of developing with threads, but even that methodology has nasty corner cases. * Thread-safety cannot be abstracted out. IOW, divide and conquer doesn't work. You can't hide the locking inside a class and forget about it. The entire application must be aware low-level thread synchronization needs. * Threads assume each state has one exit event. At a bare minimum, each thread should be prepared to have the blocking event aborted from the outside. Unfortunately, most threading frameworks don't allow for graceful aborts (that goes for Java and Python, too). * If you have made your design around threads and finally decide asynchronous processing would have been a better choice, a complete rewrite is required if it is even possible. Library writers often only provide blocking I/O functions forcing you to insulate the libraries in thread pools. Marko From Joshua.R.English at gmail.com Tue Apr 8 02:22:17 2014 From: Joshua.R.English at gmail.com (Josh English) Date: Mon, 7 Apr 2014 23:22:17 -0700 (PDT) Subject: Keeping track of things with dictionaries In-Reply-To: References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: <1aee6e9e-f2c2-426e-a753-3cc8d3c53536@googlegroups.com> On Monday, April 7, 2014 9:08:23 PM UTC-7, Chris Angelico wrote: > That depends on whether calling Brand() unnecessarily is a problem. > Using setdefault() is handy when you're working with a simple list or > something, but if calling Brand() is costly, or (worse) if it has side > effects that you don't want, then you need to use a defaultdict. > > I think this is a textbook example of why defaultdict exists, though, > so I'd be inclined to just use it, rather than going for setdefault :) Thanks for the clarification. From antoon.pardon at rece.vub.ac.be Tue Apr 8 03:03:34 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 08 Apr 2014 09:03:34 +0200 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <5342333e$0$11109$c3e8da3@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <87txa643so.fsf@elektro.pacujo.net> <5341e7c6$0$29993$c3e8da3$5496439d@news.astraweb.com> <5342333e$0$11109$c3e8da3@news.astraweb.com> Message-ID: <53439F46.1020204@rece.vub.ac.be> On 07-04-14 07:10, Steven D'Aprano wrote: > >> Restricting the usage of Python's flexibility does not make it another >> language. It makes it the actual language that the vast majority of >> programs are written in and that people assume when reading code. > That's incorrect. If len were a keyword, and couldn't be shadowed or > replaced, it would be another language. That is true but in a useless meaning. With such a strict meaning of when a language is different, people programming python have been continuously changing programming language. However the changes seem to be gradual enough for people to continue speaking of python. So if we see python as a family of languages where some difference may produce variations while still speaking of the same language, I don't see why a change like you propose would fall into a category that would imply we are now speaking of an other language. -- Antoon Pardon From james at brwr.org Tue Apr 8 03:07:27 2014 From: james at brwr.org (James Brewer) Date: Tue, 8 Apr 2014 00:07:27 -0700 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? Message-ID: I'm sure there will be a substantial amount of arrogance perceived from this question, but frankly I don't think that I have anything to learn from my co-workers, which saddens me because I really like to learn and I know that I have a lot of learning to do. I've been employed as a software engineer for about eight months now and I feel like I haven't learned nearly as much as I should. Sure, I've picked up little tidbits of information here and there, but I'm no more confident in my ability to build anything more complex than a basic crud app than I was the day I started. Things I'm interested include contributing to both Python and Django, database design and data modeling, API design, code quality, algorithms and data structures, and software architecture, among other things. Basically, I want to be a better engineer. Where can I find someone willing to point me in the right direction and what can I offer in return? Happy Monday! James -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at chagford.com Tue Apr 8 03:14:39 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 8 Apr 2014 09:14:39 +0200 Subject: Keeping track of things with dictionaries References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: "Chris Angelico" wrote in message news:CAPTjJmqFBt2XX+BDfNHz0gaGOrDkhtpBzrR29DUWN36girzcSw at mail.gmail.com... > On Tue, Apr 8, 2014 at 2:02 PM, Josh English > wrote: >> >> Would dict.setdefault() solve this problem? Is there any advantage to >> defaultdict over setdefault() > > That depends on whether calling Brand() unnecessarily is a problem. > Using setdefault() is handy when you're working with a simple list or > something, but if calling Brand() is costly, or (worse) if it has side > effects that you don't want, then you need to use a defaultdict. > It appears that when you use 'setdefault', the default is always evaluated, even if the key exists. >>> def get_value(val): ... print('getting value', val) ... return val*2 ... >>> my_dict = {} >>> my_dict.setdefault('a', get_value('xyz')) getting value xyz 'xyzxyz' >>> my_dict.setdefault('a', get_value('abc')) getting value abc 'xyzxyz' >>> my_dict {'a': 'xyzxyz'} >>> It seems odd. Is there a situation where this behaviour is useful? Frank Millman From info at egenix.com Tue Apr 8 03:18:16 2014 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 08 Apr 2014 09:18:16 +0200 Subject: ANN: eGenix mxODBC 3.3.0 - Python ODBC Database Interface Message-ID: <5343A2B8.6040603@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC Python ODBC Database Interface Version 3.3.0 mxODBC is our commercially supported Python extension providing ODBC database connectivity to Python applications on Windows, Mac OS X, Unix and BSD platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-3.3.0-GA.html ________________________________________________________________________ INTRODUCTION mxODBC provides an easy-to-use, high-performance, reliable and robust Python interface to ODBC compatible databases such as MS SQL Server, MS Access, Oracle Database, IBM DB2 and Informix , Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more: http://www.egenix.com/products/python/mxODBC/ The "eGenix mxODBC - Python ODBC Database Interface" product is a commercial extension to our open-source eGenix mx Base Distribution: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS The 3.3.0 release of our mxODBC is a new release of our popular Python ODBC Interface for Windows, Linux, Mac OS X and FreeBSD. New Features in 3.3 ------------------- Stored Procedures * mxODBC now has full support for input, output and input/output parameters in stored procedures and stored functions, allowing easy integration with existing databases systems. User Customizable Row Objects * Added support for user customizable row objects by adding cursor/connection .rowfactory and .row constructor attributes. When set, these are used to wrap the normal row tuples returned by the .fetch*() methods into dynamically created row objects. * Added new RowFactory classes to support cursor.rowfactory and cursor.row. These allow dynamically creating row classes that provide sequence as well as mapping and attribute access to row fields - similar to what namedtuples implement, but specific to result sets. Fast Cursor Types * Switched to forward-only cursor types for all database backends, since this provides a much better performance for MS SQL Server and IBM DB2 drivers. * Added a new .cursortype attribute to allow adjusting and inspecting the ODBC cursor type to be used for an mxODBC cursor object. Default is to use forward-only cursors, but mxODBC also support several other useful cursor types such as static cursors with full support for result set scrolling. More new Features * Custom errorhandlers are now also called very early during the connection process. This makes it possible to debug e.g. ODBC driver/manager setup problems from within Python, without having to resort to ODBC trace files. * Enhanced cursor.prepare() to allow querying cursor.description right after the prepare step and not only after calling a cursor.execute*() method. * Added iterator/generator support to .executemany(). The parameters list can now be an iterator/generator, if needed. * Added new connection.dbapi property to easily access module level symbols from the connection object. * Timestamp seconds fraction resolution is now determined from the scale of a datetime/timestamp SQL column, using the connection.timestampresolution as lower bound, when using SQL type binding. In Python type binding, the connection.timestampresolution determines the scale with which a variable is bound. This allows for greater flexibility when dealing with database backends that don't provide full nano-second second resolution, such as e.g. MS SQL Server. * mxODBC now accepts Unicode string values for date/time/datetime/timestamp column types in SQL type binding mode. Previous versions already did in Python type binding mode. * mxODBC now uses unicode(obj, encoding) semantics when binding Python objects to SQLWCHAR database parameters. Additionally, it ignores the encoding in case obj is a number, to avoid conversion errors. * Added new cursor.encoding and (read-only) cursor.converter attributes. Both inherit their default values from the connection the cursor was created on. * Added cursor.bindmethod which inherits from connection.bindmethod when creating the cursor. This allows adjusting the variable bind method on a per-cursor basis, rather than only on a per connection basis as in previous mxODBC versions. * mxODBC is now built against unixODBC 2.3.2. * The SQL lookup object now supports ODBC 3.8 symbols and values, including driver specific symbols used by the MS SQL Server Native Client and IBM DB2 ODBC drivers. * Updated the DataDirect binding to version 7.1.2 of the DataDirect ODBC manager. For the full set of features mxODBC has to offer, please see: http://www.egenix.com/products/python/mxODBC/#Features Driver Compatibility Enhancements --------------------------------- Oracle * Added work-around for Oracle Instant Client to be able to use integer output parameters. * Added a work-around for Oracle Instant Client to have it return output parameters based on the input placeholder Python parameter types. It would otherwise return all parameters as strings. * Disabled a test for Oracle Instant Client which tries to set a pre-connect connection option for timeouts, since the ODBC driver segfaults with this option. MS SQL Server * mxODBC now defaults to 100ns connection.timestampresolution for MS SQL Server 2008 and later, and 1ms resolution for MS SQL server 2005 and earlier. This simplifies interfacing to SQL Server timestamp columns by preventing occasional precision errors. * Tested mxODBC successfully with new MS SQL Server Native Client 11 for Linux. Unicode connection strings still don't work, but everything else does. * Added documentation on how to use Kerberos with mxODBC and SQL Server fo authentication on both Windows and Linux. * Added note about problems of the FreeTDS ODBC driver dealing with TIME and DATE columns to the documentation. Sybase ASE * Added work-around for the Sybase ASE ODBC driver, which doesn't always pass back NULL correctly to mxODBC on 64-bit Unix systems. * Changed the variable type binding mode default for the Sybase ASE ODBC driver from Python type binding to SQL type binding, which resolves issues with e.g. the Unicode support for that driver. * Added note about a segfault problem with the Sybase ASE 15.7 ODBC driver which is caused by the driver corrupting the heap. IBM DB2 * Added work-around for the IBM DB2 ODBC driver, which doesn't always pass back NULL correctly to mxODBC on 64-bit Unix systems. PostgreSQL * Added work-around to force Python type binding for the PostgreSQL ODBC drivers. More recent versions of the driver report supporting SQL type binding, but they don't implement it. * Added work-around to have PostgreSQL ODBC drivers properly work with binary data for BYTEA columns. MySQL * mxODBC now supports native Unicode with the recent MySQL ODBC drivers - provided you use the Unicode variants of the drivers. * Changed the default binding mode for MySQL ODBC drivers to Python type binding. This works around a problem with date/time values when talking to MySQL 5.6 servers. For the full set of changes please check the mxODBC change log: http://www.egenix.com/products/python/mxODBC/changelog.html The Future --------------- * Please note that this will be the last release of mxODBC for Python 2.4, 2.5 and 2.6. For the next release of mxODBC, we are focusing on making the code Python 2.7 and Python 3.x compatible, dropping support for earlier Python versions. * If you need long term support for these older Python versions, please contact sales at egenix.com. We can then arrange custom support contracts for you. mxODBC Editions --------------- mxODBC is available in these two editions: * The Professional Edition, which gives full access to all mxODBC features. * The Product Development Edition, which allows including mxODBC in applications you develop. For a complete overview of the new editions, please see the product page. http://www.egenix.com/products/python/mxODBC/#mxODBCEditions ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/mxODBC/ In order to use the eGenix mxODBC package you will first need to install the eGenix mx Base package: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ UPGRADING Users are encouraged to upgrade to this latest mxODBC release to benefit from the new features and updated ODBC driver support. We have taken special care, not to introduce backwards incompatible changes, making the upgrade experience as smooth as possible. For upgrade purchases, we will give out 20% discount coupons going from mxODBC 2.x to 3.3 and 50% coupons for upgrades from mxODBC 3.x to 3.3. After upgrade, use of the original license from which you upgraded is no longer permitted. Please contact the eGenix.com Sales Team at sales at egenix.com with your existing license serials for details for an upgrade discount coupon. If you want to try the new release before purchace, you can request 30-day evaluation licenses by visiting our web-site http://www.egenix.com/products/python/mxODBC/#Evaluation or by writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. _______________________________________________________________________ INFORMATION About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert services and professional quality products for companies, Python users and developers. PS: If you want to meet with eGenix at PyCon 2014, please send an email and we can arrange a meeting. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Apr 08 2014) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2014-04-09: PyCon 2014, Montreal, Canada ... tomorrow 2014-04-29: Python Meeting Duesseldorf ... 21 days to go ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From steve at pearwood.info Tue Apr 8 03:47:49 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 08 Apr 2014 07:47:49 GMT Subject: Keeping track of things with dictionaries References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: <5343a9a5$0$11109$c3e8da3@news.astraweb.com> On Tue, 08 Apr 2014 09:14:39 +0200, Frank Millman wrote: > It appears that when you use 'setdefault', the default is always > evaluated, even if the key exists. > >>>> def get_value(val): > ... print('getting value', val) > ... return val*2 > ... >>>> my_dict = {} >>>> my_dict.setdefault('a', get_value('xyz')) > getting value xyz > 'xyzxyz' >>>> my_dict.setdefault('a', get_value('abc')) > getting value abc > 'xyzxyz' >>>> my_dict > {'a': 'xyzxyz'} >>>> >>>> > It seems odd. Is there a situation where this behaviour is useful? It's not a feature of setdefault. It's how Python works: arguments to functions and methods are always evaluated before the function is called. The same applies to most languages. Only a very few number of syntactic features involve delayed evaluation. Off the top of my head: - the second argument to short-circuit "or" and "and" operators: if obj and obj[0]: ... - ternary if: 1/x if x != 0 else float("inf") - generator expressions - and of course the body of functions and methods don't execute until the function is called. -- Steven From kwpolska at gmail.com Tue Apr 8 03:52:43 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Tue, 8 Apr 2014 09:52:43 +0200 Subject: change spacing to two instead of four with pep8 or flake8? In-Reply-To: References: Message-ID: On Tue, Apr 8, 2014 at 5:06 AM, Dennis wrote: > Hi, > > In Pylint you can change the spacing multiplier from 4 spaces to two > in its pylintrc, but for the life of me I cannot find a way to do this > with the flake8 / pep8 utilities. > > I want to avoid ignoring E111 altogether if at all possible, because > it may catch other spacing problems that are not as obvious. > > hacky/non-hacky solutions welcome of course. > > If this is too specific and I should go to the pep8/flake8 MLs that is > welcome advice too. > > Thanks, > > Dennis > -- > https://mail.python.org/mailman/listinfo/python-list You are trying to use tools that enforce a set of rules, one of which is ?use 4 spaces per indentation level?. If you don?t agree with this rule, simply don?t use tools that enforce these rules. It?s that easy. But note, that E111 is ?indentation is not a multiple of four?. Which you are never going to listen to anyways if you want 2 spaces per indentation level. If you *really* want to do 2 spaces (and look weird), then just ignore that. -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From ian.g.kelly at gmail.com Tue Apr 8 03:53:33 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 8 Apr 2014 01:53:33 -0600 Subject: Keeping track of things with dictionaries In-Reply-To: References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: On Tue, Apr 8, 2014 at 1:14 AM, Frank Millman wrote: > > "Chris Angelico" wrote in message > news:CAPTjJmqFBt2XX+BDfNHz0gaGOrDkhtpBzrR29DUWN36girzcSw at mail.gmail.com... >> On Tue, Apr 8, 2014 at 2:02 PM, Josh English >> wrote: >>> >>> Would dict.setdefault() solve this problem? Is there any advantage to >>> defaultdict over setdefault() >> >> That depends on whether calling Brand() unnecessarily is a problem. >> Using setdefault() is handy when you're working with a simple list or >> something, but if calling Brand() is costly, or (worse) if it has side >> effects that you don't want, then you need to use a defaultdict. >> > > It appears that when you use 'setdefault', the default is always evaluated, > even if the key exists. > >>>> def get_value(val): > ... print('getting value', val) > ... return val*2 > ... >>>> my_dict = {} >>>> my_dict.setdefault('a', get_value('xyz')) > getting value xyz > 'xyzxyz' >>>> my_dict.setdefault('a', get_value('abc')) > getting value abc > 'xyzxyz' >>>> my_dict > {'a': 'xyzxyz'} >>>> > > It seems odd. Is there a situation where this behaviour is useful? No. The default argument is evaluated because it must be evaluated before it can be passed into the method, just like any other function argument in Python. So why doesn't it take a callable instead of a value for its second argument? At a guess, because the method was probably added for efficiency, and the function call overhead might easily be slower than just doing a separate getitem and setitem. The reason setdefault exists I think is primarily because it was added before defaultdict. The contributors at SO can't seem to come up with any particularly good use cases either: http://stackoverflow.com/questions/3483520/use-cases-for-the-setdefault-dict-method One thing I will note as a disadvantage of defaultdict is that sometimes you only want the default value behavior while you're initially building the dict, and then you just want a normal dict with KeyErrors from then on. defaultdict doesn't do that; once constructed, it will always be a defaultdict. You can copy the data into a normal dict using the dict() constructor, but this feels dirty to me. From rosuav at gmail.com Tue Apr 8 03:57:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Apr 2014 17:57:02 +1000 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: On Tue, Apr 8, 2014 at 5:07 PM, James Brewer wrote: > Basically, I want to be a better engineer. Where can I find someone willing > to point me in the right direction and what can I offer in return? > Right here on this list! And all you have to offer in return is interesting questions. You ask the questions, we'll start spouting answers... and we'll all enjoy the discussion! ChrisA From rosuav at gmail.com Tue Apr 8 04:00:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Apr 2014 18:00:28 +1000 Subject: Keeping track of things with dictionaries In-Reply-To: References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: On Tue, Apr 8, 2014 at 5:14 PM, Frank Millman wrote: > It appears that when you use 'setdefault', the default is always evaluated, > even if the key exists. > >>>> def get_value(val): > ... print('getting value', val) > ... return val*2 > ... >>>> my_dict = {} >>>> my_dict.setdefault('a', get_value('xyz')) > getting value xyz > 'xyzxyz' >>>> my_dict.setdefault('a', get_value('abc')) > getting value abc > 'xyzxyz' >>>> my_dict > {'a': 'xyzxyz'} >>>> > > It seems odd. Is there a situation where this behaviour is useful? If the default value is cheap to define and has no side effects, it can be very clean. words_by_length = {} for word in open("/usr/share/dict/words"): words_by_length.setdefault(len(word), []).append(word) This will, very conveniently, give you a list of all words of a particular length. (It's actually a little buggy but you get the idea.) ChrisA From __peter__ at web.de Tue Apr 8 04:21:58 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 08 Apr 2014 10:21:58 +0200 Subject: Keeping track of things with dictionaries References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: Ian Kelly wrote: > One thing I will note as a disadvantage of defaultdict is that > sometimes you only want the default value behavior while you're > initially building the dict, and then you just want a normal dict with > KeyErrors from then on. defaultdict doesn't do that; once > constructed, it will always be a defaultdict. This is one of the statements that I won't believe without trying myself. As I'm posting you can probably guess my findings: >>> from collections import defaultdict >>> d = defaultdict(int) >>> d[0] 0 >>> d.default_factory = str >>> d[1] '' >>> d.default_factory = None >>> d[2] Traceback (most recent call last): File "", line 1, in KeyError: 2 >>> d defaultdict(None, {0: 0, 1: ''}) So you can change a defaultdict's default_factory any time you like, and if you set it to None there will be no default. It will still "be" a defaultdict, but it will act like a normal dict. > You can copy the data > into a normal dict using the dict() constructor, but this feels dirty > to me. From steve at pearwood.info Tue Apr 8 04:21:26 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 08 Apr 2014 08:21:26 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <38795bc9-f67d-423f-a929-212b6b38ec8c@googlegroups.com> Message-ID: <5343b186$0$11109$c3e8da3@news.astraweb.com> On Mon, 07 Apr 2014 20:33:31 -0500, Mark H Harris wrote: > I have another question for y'all, is a function (particularly a > generator) a noun or a verb? Mu. http://en.wikipedia.org/wiki/Mu_%28negative%29#.22Unasking.22_the_question Nouns and verbs are concepts from a completely different magisteria, namely linguistics. Functions are no more a noun (or verb) than list comprehensions are adjectives. What we can say is that in Python, functions are objects, and being objects, they are also values, like ints, strings, lists, floats, etc. Even in languages where functions are not first-class values, e.g. Pascal, we treat them as abstract things rather than actions, so linguistically we use functions as nouns. E.g. given a function "spam", we might say "pass the argument to spam" rather than "spam that argument". We do that even when the function is named for a verb: "pass the argument to execute". (English is great for this: we can use nearly every verb as a noun, if the context is understood.) > Does a function (or generator) 'do' > something (based on name and parms) or does it 'return' something based > on name and parms? Both. Returning something is just a special case of doing. Monkeys climb, fish swim, cows moo, functions return, and programmers drink caffeinated drinks. > Based on name and parms should a function (or > generator) function as a noun, or function as a verb, or *both*? --or, > are Classes nouns only, and all functions *are* verbs only? I *think* you are referring to naming conventions here. Functions which are intended to be used as a procedure, that is, only for their side-effects, should be named using a verb: time.sleep dict.update list.append Spam.make_yummy_foodstuffs Functions which are intended to return a value may be named as verbs: run eval sorted print or as nouns: int str dict namedtuple coordinate array (the first three are now types, i.e. classes, but early in Python they were functions). Classes represent things (possible abstract things), and so should be named as nouns, not verbs: Runner not Run or Do_Run Decimal not Decimalize or Do_Decimal float not Make_Floating_Point Generator functions are called for their value: a generator function returns a generator, and a generator is a value: def make_generator(n): for i in range(n): yield "something" gen = make_generator(23) Since the generator object itself is a thing, it should be named with a noun. Since the generator function is also a thing, and it is called for it's return value, not a side-effect, it could be named as a verb or a noun, whichever you prefer, or makes sense in context. Are there "things" in Python that aren't values? No. But there is syntax that represents verbs: import this del that for [do]: this while condition [do]: that There's no such thing in Python as an "Import object" or a "DelType value", but Python provides verbs for those commands. -- Steven From frank at chagford.com Tue Apr 8 04:26:27 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 8 Apr 2014 10:26:27 +0200 Subject: Keeping track of things with dictionaries References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: "Chris Angelico" wrote in message news:CAPTjJmpK-rqX0fp6_4vXYUS2Z34Vc5fQ_qNTj+Q9+Kn8Y5UPAA at mail.gmail.com... > On Tue, Apr 8, 2014 at 5:14 PM, Frank Millman wrote: >> It appears that when you use 'setdefault', the default is always >> evaluated, >> even if the key exists. >> >> It seems odd. Is there a situation where this behaviour is useful? > > If the default value is cheap to define and has no side effects, it > can be very clean. > > words_by_length = {} > for word in open("/usr/share/dict/words"): > words_by_length.setdefault(len(word), []).append(word) > > This will, very conveniently, give you a list of all words of a > particular length. (It's actually a little buggy but you get the > idea.) > Thanks, that is neat. I haven't spotted the bug yet! Can you give me a hint? Frank From frank at chagford.com Tue Apr 8 04:31:28 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 8 Apr 2014 10:31:28 +0200 Subject: Keeping track of things with dictionaries References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: "Ian Kelly" wrote in message news:CALwzidmP5Bevbace9GyQrVXe-_2T=jtPQ1yVaPsAePvOMQePLA at mail.gmail.com... > On Tue, Apr 8, 2014 at 1:14 AM, Frank Millman wrote: >> >> It appears that when you use 'setdefault', the default is always >> evaluated, >> even if the key exists. >> >> It seems odd. Is there a situation where this behaviour is useful? > > No. The default argument is evaluated because it must be evaluated > before it can be passed into the method, just like any other function > argument in Python. So why doesn't it take a callable instead of a > value for its second argument? At a guess, because the method was > probably added for efficiency, and the function call overhead might > easily be slower than just doing a separate getitem and setitem. > > The reason setdefault exists I think is primarily because it was added > before defaultdict. The contributors at SO can't seem to come up with > any particularly good use cases either: > > http://stackoverflow.com/questions/3483520/use-cases-for-the-setdefault-dict-method > > One thing I will note as a disadvantage of defaultdict is that > sometimes you only want the default value behavior while you're > initially building the dict, and then you just want a normal dict with > KeyErrors from then on. defaultdict doesn't do that; once > constructed, it will always be a defaultdict. You can copy the data > into a normal dict using the dict() constructor, but this feels dirty > to me. Here is an idea, inspired by Peter Otten's suggestion earlier in this thread. Instead of defaultdict, subclass dict and use __missing__() to supply the default values. When the dictionary is set up, delete __missing__ from the subclass! Ugly, but it seems to work. Frank From rosuav at gmail.com Tue Apr 8 04:35:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Apr 2014 18:35:02 +1000 Subject: Keeping track of things with dictionaries In-Reply-To: References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: On Tue, Apr 8, 2014 at 6:26 PM, Frank Millman wrote: >> words_by_length = {} >> for word in open("/usr/share/dict/words"): >> words_by_length.setdefault(len(word), []).append(word) >> >> This will, very conveniently, give you a list of all words of a >> particular length. (It's actually a little buggy but you get the >> idea.) >> > > Thanks, that is neat. > > I haven't spotted the bug yet! Can you give me a hint? Run those lines in interactive Python (and change the file name if you're not on Unix or if you don't have a dictionary at that path), and then look at what's in words_by_length[23] - in the dictionary I have here (Debian Wheezy, using an American English dictionary - it's a symlink to (ultimately) /usr/share/dict/american-english), there are five entries in that list. Count how many letters there are in them. Also, there's a technical bug [1] in that I ought to use 'with' to ensure that the file's properly closed. But for a simple example, that's not critical. ChrisA [1] As Julia Jellicoe pointed out, it's an awful thing to be haunted by a technical bug! From frank at chagford.com Tue Apr 8 05:28:19 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 8 Apr 2014 11:28:19 +0200 Subject: Keeping track of things with dictionaries References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: "Chris Angelico" wrote in message news:CAPTjJmoRxEhX02ZviHiLO+qi+dD+81smbGGYcPECpHb5E=p4=A at mail.gmail.com... > On Tue, Apr 8, 2014 at 6:26 PM, Frank Millman wrote: >>> words_by_length = {} >>> for word in open("/usr/share/dict/words"): >>> words_by_length.setdefault(len(word), []).append(word) >>> >>> This will, very conveniently, give you a list of all words of a >>> particular length. (It's actually a little buggy but you get the >>> idea.) >>> >> >> Thanks, that is neat. >> >> I haven't spotted the bug yet! Can you give me a hint? > > Run those lines in interactive Python (and change the file name if > you're not on Unix or if you don't have a dictionary at that path), > and then look at what's in words_by_length[23] - in the dictionary I > have here (Debian Wheezy, using an American English dictionary - it's > a symlink to (ultimately) /usr/share/dict/american-english), there are > five entries in that list. Count how many letters there are in them. > I don't have a large dictionary to test with, and a small list of words (ls /etc > dict) did not throw up any problems. Are you saying that all([len(word) == 23 for word in words_by_length[23]]) # hope I got that right will not return True? Frank From rosuav at gmail.com Tue Apr 8 05:34:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Apr 2014 19:34:24 +1000 Subject: Keeping track of things with dictionaries In-Reply-To: References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: On Tue, Apr 8, 2014 at 7:28 PM, Frank Millman wrote: > Are you saying that > > all([len(word) == 23 for word in words_by_length[23]]) # hope I got > that right > > will not return True? That'll return true. What it won't show, though, is the length of the word as you would understand it in the English language. You see, when you iterate over a file, you get strings that include a newline at the end, and that'll be included in the length :) So with a dictionary of English words, you'll see that "cat\n" is a four-letter word, and "python\n" is a seven-letter word. It's a subtle point, but an important one when you start looking at lengths of things that are suddenly off by one. Obviously the solution is to strip them, but I didn't want to pollute the example with that (nor a 'with' block). I didn't think it particularly important, and just acknowledged the bug in what I thought was a throw-away line :) ChrisA From frank at chagford.com Tue Apr 8 05:41:20 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 8 Apr 2014 11:41:20 +0200 Subject: Keeping track of things with dictionaries References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: "Chris Angelico" wrote in message news:CAPTjJmpPAqmb6No7UDdDAdqG_jv9yz0sN4d70KAsksbwWR3jdg at mail.gmail.com... > On Tue, Apr 8, 2014 at 7:28 PM, Frank Millman wrote: >> Are you saying that >> >> all([len(word) == 23 for word in words_by_length[23]]) # hope I got >> that right >> >> will not return True? > > That'll return true. What it won't show, though, is the length of the > word as you would understand it in the English language. You see, when > you iterate over a file, you get strings that include a newline at the > end, and that'll be included in the length :) So with a dictionary of > English words, you'll see that "cat\n" is a four-letter word, and > "python\n" is a seven-letter word. It's a subtle point, but an > important one when you start looking at lengths of things that are > suddenly off by one. > > Obviously the solution is to strip them, but I didn't want to pollute > the example with that (nor a 'with' block). I didn't think it > particularly important, and just acknowledged the bug in what I > thought was a throw-away line :) > Got it - thanks Frank From sturla.molden at gmail.com Tue Apr 8 06:47:43 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 8 Apr 2014 10:47:43 +0000 (UTC) Subject: threading References: <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: <858676537418645912.552889sturla.molden-gmail.com@news.gmane.org> Marko Rauhamaa wrote: > The main problems with threads include: > > * Thread-safety is rarely done right. Also, when it's done wrong, it > can be virtually impossible to fix it without a significant rewrite. > This is not a theoretical concern: I have had to deal with the > resulting nightmares in my work. > > * There is no accepted, taught, industry-wide discipline on proper > thread-safety practices so every developer has to improvise. I have > come up with a "bullet-proof" way of developing with threads, but > even that methodology has nasty corner cases. > > * Thread-safety cannot be abstracted out. IOW, divide and conquer > doesn't work. You can't hide the locking inside a class and forget > about it. The entire application must be aware low-level thread > synchronization needs. The problem here is the belief that "thread-safety cannot be abstracted out". It can. The solution is to share nothing and send messages through queues. If you start to use mutexes and conditions all over your code, you might shoot yourself in the foot, eventually. Sturla From rustompmody at gmail.com Tue Apr 8 06:53:58 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 8 Apr 2014 03:53:58 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <38795bc9-f67d-423f-a929-212b6b38ec8c@googlegroups.com> Message-ID: <3bd43172-2cd3-4aba-8946-a02c87f61257@googlegroups.com> On Tuesday, April 8, 2014 7:03:31 AM UTC+5:30, Mark H. Harris wrote: > I have another question for y'all, is a function (particularly a > generator) a noun or a verb? Does a function (or generator) 'do' > something (based on name and parms) or does it 'return' something based > on name and parms? Based on name and parms should a function (or > generator) function as a noun, or function as a verb, or *both*? --or, > are Classes nouns only, and all functions *are* verbs only? If your question is "What is (function/generator...)?" the answer is noun If your question is "What does it (function/generator...) do/behave?" the answer is verb From alister.nospam.ware at ntlworld.com Tue Apr 8 07:07:28 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 08 Apr 2014 11:07:28 GMT Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> Message-ID: > My personal feeling is that asynchronous i/o is mostly useful on 32-bit > systems, and the problem it actually solves is the limited virtual > address space. On a 64 bit system we can just throw more RAM at it and > threads be fine. > As my only professional coding experience has been with embedded 8 bit processors with limited resources i naturally abhorrent to the process of "Just throw more RAM (Or any other resource for that matter)at it". It is my personal opinion that the quality of code has diminished steadily as physical limitations on the programmer have been reduced, of course I could be wrong so I would like to here other peoples views on this. From python.list at tim.thechases.com Tue Apr 8 07:53:26 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 8 Apr 2014 06:53:26 -0500 Subject: change spacing to two instead of four with pep8 or flake8? In-Reply-To: References: Message-ID: <20140408065326.65639af2@bigbox.christie.dr> On 2014-04-08 09:52, Chris ?Kwpolska? Warrick wrote: > On Tue, Apr 8, 2014 at 5:06 AM, Dennis wrote: > > In Pylint you can change the spacing multiplier from 4 spaces to > > two in its pylintrc, but for the life of me I cannot find a way > > to do this with the flake8 / pep8 utilities. > > > > I want to avoid ignoring E111 altogether if at all possible, > > because it may catch other spacing problems that are not as > > obvious. > > You are trying to use tools that enforce a set of rules, one of > which is ?use 4 spaces per indentation level?. If you don?t agree > with this rule, simply don?t use tools that enforce these rules. > It?s that easy. > > But note, that E111 is ?indentation is not a multiple of four?. > Which you are never going to listen to anyways if you want 2 spaces > per indentation level. If you *really* want to do 2 spaces (and > look weird), then just ignore that. It sounds like the OP wants a "indentation is not a multiple of N" error/warning which would be a more generic (and as you state, look weird doing so). I wouldn't expect pep8 to do it, since its goal is to align with pep8. But I could see some of the other checkers having a command-line option to set the expected indentation. Otherwise, one might just do something like sed -n '/^\( \)*\ Message-ID: <87d2gsowck.fsf@elektro.pacujo.net> Sturla Molden : > The problem here is the belief that "thread-safety cannot be > abstracted out". It can. The solution is to share nothing and send > messages through queues. If you start to use mutexes and conditions > all over your code, you might shoot yourself in the foot, eventually. Queues are fine if you hermetically insulate your objects. IOW, you group your objects in single-threaded pseudoprocesses that don't make any direct method calls to each other. If you do that, you might as well use real processes. That way, you can even naturally enforce your insulation assumption against accidents. In "normal" multithreaded code, different object methods are called from different threads. And, as you say, you *will* shoot yourself in the foot. Now, even in your queued thread world, you will suffer from the fact that the naive thread programmer uses blocking function calls (as they have been taught). Imagine, for example, a network outage in the middle of a database call. The thread might not take a peek at its input queue during the stuck I/O call and the application cannot abort the operation. The solution is to use an asyncio main loop and nonblocking I/O in each of your insulated threads... Marko From __peter__ at web.de Tue Apr 8 08:55:46 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 08 Apr 2014 14:55:46 +0200 Subject: change spacing to two instead of four with pep8 or flake8? References: Message-ID: Dennis wrote: > In Pylint you can change the spacing multiplier from 4 spaces to two > in its pylintrc, but for the life of me I cannot find a way to do this > with the flake8 / pep8 utilities. > > I want to avoid ignoring E111 altogether if at all possible, because > it may catch other spacing problems that are not as obvious. > > hacky/non-hacky solutions welcome of course. The check is hardcoded if indent_char == ' ' and indent_level % 4: yield 0, "E111 indentation is not a multiple of four" so your only short-term solution is to modify the script's source code. From roy at panix.com Tue Apr 8 09:13:24 2014 From: roy at panix.com (Roy Smith) Date: Tue, 08 Apr 2014 09:13:24 -0400 Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> Message-ID: In article , alister wrote: > > My personal feeling is that asynchronous i/o is mostly useful on 32-bit > > systems, and the problem it actually solves is the limited virtual > > address space. On a 64 bit system we can just throw more RAM at it and > > threads be fine. > > > As my only professional coding experience has been with embedded 8 bit > processors with limited resources i naturally abhorrent to the process of > "Just throw more RAM (Or any other resource for that matter)at it". > > It is my personal opinion that the quality of code has diminished > steadily as physical limitations on the programmer have been reduced, of > course I could be wrong so I would like to here other peoples views on > this. I can rent a machine with 30 GB (r3.xlarge) of RAM from Amazon for about $3000/year (http://aws.amazon.com/ec2/pricing/). A 60 GB machine (r3.2xlarge) is exactly twice that. You get more CPU and SSD too, but for the moment, I'm thinking about this as just renting memory. Glassdoor.com says the median salary for a "software architect" New York is $115k. By the time I'm done with personnel-related overhead, that person is really going to cost me $150k. Let's say I've got a program which consumes 60 GB of RAM, so I'm renting the 2xlarge instance to run it. My software architect could recode the program to be more efficient, and fit into just 30 GB, saving me $3000/year. How much of his time is it worth to do that? He's costing me about $600/day, so if he can do it in a week, it'll take a year to recoup my investment. Oh, by the way, those prices I quoted are the on-demand prices. If I'm willing to sign a three year contract, I can cut the annual cost almost in half. And the cost of hardware keeps going down, while the cost of good programmers keeps going up. From roy at panix.com Tue Apr 8 09:19:05 2014 From: roy at panix.com (Roy Smith) Date: Tue, 08 Apr 2014 09:19:05 -0400 Subject: threading References: <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: In article , Sturla Molden wrote: > The problem here is the belief that "thread-safety cannot be abstracted > out". It can. The solution is to share nothing and send messages through > queues. Thread 1 and Thread 2 use a pair of queues to communicate. T1 sends work to T2 using Q1, and T2 sends back results using Q2. T1 pushes Item1 onto Q1, and waits for Result1 to come back on Q2. T2 reads Item1 from its end of Q1, and waits to read Item2, which it needs to compute Result1. Sounds like a deadlock to me. From rosuav at gmail.com Tue Apr 8 09:23:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Apr 2014 23:23:05 +1000 Subject: threading In-Reply-To: References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> Message-ID: On Tue, Apr 8, 2014 at 11:13 PM, Roy Smith wrote: > And the cost of hardware keeps going down, while the cost of > good programmers keeps going up. Like everything, it's a matter of trade-offs. Spending a moment thinking about what you're doing before you do it might cut your RAM usage by 20% without materially increasing your programmer time cost. But coding everything in C "for efficiency" is almost certainly a bad trade, for the reason quoted. There can be special boundaries in resource consumption. Fitting something inside an Amazon Micro instance might be important for you, in which case you get just 613 MB of RAM (a weird figure, I know). Or maybe you need to stay within 8GB so you can allocate the other 8GB to the database. Or whatever it is. But any time it's flexible (where you basically just pay twice as much to get twice as much), it's usually worth going as far as you can. ChrisA From roy at panix.com Tue Apr 8 09:20:29 2014 From: roy at panix.com (Roy Smith) Date: Tue, 08 Apr 2014 09:20:29 -0400 Subject: change spacing to two instead of four with pep8 or flake8? References: Message-ID: In article , Peter Otten <__peter__ at web.de> wrote: > Dennis wrote: > > > In Pylint you can change the spacing multiplier from 4 spaces to two > > in its pylintrc, but for the life of me I cannot find a way to do this > > with the flake8 / pep8 utilities. > > > > I want to avoid ignoring E111 altogether if at all possible, because > > it may catch other spacing problems that are not as obvious. > > > > hacky/non-hacky solutions welcome of course. > > The check is hardcoded > > if indent_char == ' ' and indent_level % 4: > yield 0, "E111 indentation is not a multiple of four" > > so your only short-term solution is to modify the script's source code. There's always monkey-patching :-) From invalid at invalid.invalid Tue Apr 8 09:47:12 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 8 Apr 2014 13:47:12 +0000 (UTC) Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? References: Message-ID: On 2014-04-08, Chris Angelico wrote: > On Tue, Apr 8, 2014 at 5:07 PM, James Brewer wrote: > >> Basically, I want to be a better engineer. Where can I find someone >> willing to point me in the right direction and what can I offer in >> return? > > Right here on this list! And all you have to offer in return is > interesting questions. Actually, I've noticed that the questions usually don't even have to be very good or interesting. Ask anything. You'll get genneraly get answers to: the question you asked the question you thought you were asking the question you should have asked a few other questions only tangentially related to the above -- Grant Edwards grant.b.edwards Yow! We are now enjoying at total mutual interaction in gmail.com an imaginary hot tub ... From rosuav at gmail.com Tue Apr 8 09:56:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Apr 2014 23:56:56 +1000 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: On Tue, Apr 8, 2014 at 11:47 PM, Grant Edwards wrote: > You'll get genneraly get answers to: > [chomp] and the question "Did I spell everything correctly?", to which the answer is generally "No". :) ChrisA diving for cover... From alister.nospam.ware at ntlworld.com Tue Apr 8 09:58:24 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 08 Apr 2014 13:58:24 GMT Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? Message-ID: <4gT0v.62253$oI.45884@fx18.am4> On Tue, 08 Apr 2014 13:47:12 +0000, Grant Edwards wrote: > On 2014-04-08, Chris Angelico wrote: >> On Tue, Apr 8, 2014 at 5:07 PM, James Brewer wrote: >> >>> Basically, I want to be a better engineer. Where can I find someone >>> willing to point me in the right direction and what can I offer in >>> return? >> >> Right here on this list! And all you have to offer in return is >> interesting questions. > > Actually, I've noticed that the questions usually don't even have to be > very good or interesting. Ask anything. You'll get genneraly get > answers to: > > the question you asked > > the question you thought you were asking > > the question you should have asked > > a few other questions only tangentially related to the above I would agree with 1 & 4, but 2 & 3 only happen if you are really lucky :-) -- You can't fall off the floor. From harrismh777 at gmail.com Tue Apr 8 09:59:52 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 08 Apr 2014 08:59:52 -0500 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? References: Message-ID: On 4/8/14 2:07 AM, James Brewer wrote: > I don't think that I have anything to learn > from my co-workers, which saddens me because I really like to learn and > I know that I have a lot of learning to do. Give it time. The first thing that must happen is relationship building. Initially its about being: faithful available interested teachable > I've been employed as a software engineer for about eight months now and > I feel like I haven't learned nearly as much as I should. compared to what > Things I'm interested include contributing to both Python and Django, > database design and data modeling, API design, code quality, algorithms > and data structures, and software architecture, among other things. Find a project. Find something you are interested in, download the source, and study. Volunteer, and do a lot of observing. > Basically, I want to be a better engineer. Where can I find someone > willing to point me in the right direction and what can I offer in return? This list is a great resource. The folks here are tough, but friendly; the list is active, and those participating will teach you plenty. marcus From jason.swails at gmail.com Tue Apr 8 10:00:45 2014 From: jason.swails at gmail.com (Jason Swails) Date: Tue, 8 Apr 2014 10:00:45 -0400 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: On Tue, Apr 8, 2014 at 3:07 AM, James Brewer wrote: > I'm sure there will be a substantial amount of arrogance perceived from > this question, but frankly I don't think that I have anything to learn from > my co-workers, which saddens me because I really like to learn and I know > that I have a lot of learning to do. > > I've been employed as a software engineer for about eight months now and I > feel like I haven't learned nearly as much as I should. Sure, I've picked > up little tidbits of information here and there, but I'm no more confident > in my ability to build anything more complex than a basic crud app than I > was the day I started. > > Things I'm interested include contributing to both Python and Django, > database design and data modeling, API design, code quality, algorithms and > data structures, and software architecture, among other things. > > Basically, I want to be a better engineer. Where can I find someone > willing to point me in the right direction and what can I offer in return? > Find something that interests you (you've done that already). Clone the repository of whatever interests you (Django, Python, etc.). Then start reading their source code. Maybe pick up a bug report that you think you can understand and work on coming up with a solution -- that will lead to more targeted reading than simply perusing it at random. Chances are someone will fix it before you get a chance, but just seeing how _others_ have designed their software and implemented it will help you learn a lot. The more you do that, the more you will understand the overall framework of the project. Best of all would be to choose a project that you use regularly. Once you become more experienced and knowledgeable about the project you've chosen, you can start contributing back to it. Everybody wins. At least I've learned a lot doing that. Good luck, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Apr 8 10:06:44 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 08 Apr 2014 16:06:44 +0200 Subject: change spacing to two instead of four with pep8 or flake8? References: Message-ID: Roy Smith wrote: > In article , > Peter Otten <__peter__ at web.de> wrote: > >> Dennis wrote: >> >> > In Pylint you can change the spacing multiplier from 4 spaces to two >> > in its pylintrc, but for the life of me I cannot find a way to do this >> > with the flake8 / pep8 utilities. >> > >> > I want to avoid ignoring E111 altogether if at all possible, because >> > it may catch other spacing problems that are not as obvious. >> > >> > hacky/non-hacky solutions welcome of course. >> >> The check is hardcoded >> >> if indent_char == ' ' and indent_level % 4: >> yield 0, "E111 indentation is not a multiple of four" >> >> so your only short-term solution is to modify the script's source code. > > There's always monkey-patching :-) There is always a way to achieve roughly the same that takes more time and is slightly harder to get right ;) From alister.nospam.ware at ntlworld.com Tue Apr 8 10:15:00 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 08 Apr 2014 14:15:00 GMT Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> Message-ID: On Tue, 08 Apr 2014 23:23:05 +1000, Chris Angelico wrote: > On Tue, Apr 8, 2014 at 11:13 PM, Roy Smith wrote: >> And the cost of hardware keeps going down, while the cost of good >> programmers keeps going up. > > Like everything, it's a matter of trade-offs. Spending a moment thinking > about what you're doing before you do it might cut your RAM usage by 20% > without materially increasing your programmer time cost. But coding > everything in C "for efficiency" is almost certainly a bad trade, for > the reason quoted. > > There can be special boundaries in resource consumption. Fitting > something inside an Amazon Micro instance might be important for you, in > which case you get just 613 MB of RAM (a weird figure, I know). Or maybe > you need to stay within 8GB so you can allocate the other 8GB to the > database. Or whatever it is. But any time it's flexible (where you > basically just pay twice as much to get twice as much), it's usually > worth going as far as you can. > > ChrisA My main point was that when you have only 8K of ROM & 128 byte of ram you have to think about your algorithms first. Programming is in Assembler because there is no other choice (I would not like to go back to that Python is so much more enjoyable), do you calculate a result or use a look up table (calculating costs ram & there are only a few bytes available for temp storage) but a lookup table costs ROM space. I am sure lack of constraint is what has lead to a number of the abominations on thedailywtf.com. I must admit I can also see the other side of the coin in that it can sometimes lead to "Clever Programming"* which is rarely a good idea. *Programming that makes use of side effects or other trickery that may not be obvious when read later. -- Avoid the Gates of Hell. Use Linux -- unknown source From larry.martell at gmail.com Tue Apr 8 10:28:21 2014 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 8 Apr 2014 10:28:21 -0400 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: On Tue, Apr 8, 2014 at 3:07 AM, James Brewer wrote: > I'm sure there will be a substantial amount of arrogance perceived from this > question, but frankly I don't think that I have anything to learn from my > co-workers, which saddens me because I really like to learn and I know that > I have a lot of learning to do. > > I've been employed as a software engineer for about eight months now and I > feel like I haven't learned nearly as much as I should. Sure, I've picked up > little tidbits of information here and there, but I'm no more confident in > my ability to build anything more complex than a basic crud app than I was > the day I started. I don't know where you work, but there are all sorts of different working environments. I've been at this for 35 years and I think I've seen most of them. I've worked at places where: -People were afraid you'll take their job and they won't answer questions or spend time to bring you up to speed on the company's systems -People who you're working with either were against hiring you or were not involved in the hiring process and won't work with you. -People are on crazy deadlines and have no time to work with you. -People have tried to work with you, but don't want to anymore because ______ (fill in the blank: you're arrogant, you're stupid, you smell, you don't learn fast enough for them, you like the Yankees and they're a Red Sox fan, ....) -People make you feel like an idiot when you ask a question and they intimidate you so you don't come back and ask more. -The culture requires some 'trial by fire' where you stand up to people and/or make it known you're not going away and won't take crap from anyone. -The new hire sits around and waits for things to happen instead making things happen themselfs. -There is absolutely nothing interesting going on at the company - no new development, no hard bugs to track down - and the people they work there are lazy and slothy, just marking time until they can retire. -People are super patient and helpful and they answer all your questions and go beyond the call of duty to help you. Do any of these apply to your situation? From rosuav at gmail.com Tue Apr 8 11:02:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Apr 2014 01:02:05 +1000 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: On Wed, Apr 9, 2014 at 12:28 AM, Larry Martell wrote: > I've worked at places where: Add to that list: - Some of the programmers really aren't programmers, but the boss just hasn't figured it out yet. That was my last job, until said non-programmer decided to quit. ChrisA From larry.martell at gmail.com Tue Apr 8 11:10:49 2014 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 8 Apr 2014 11:10:49 -0400 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: On Tue, Apr 8, 2014 at 11:02 AM, Chris Angelico wrote: > On Wed, Apr 9, 2014 at 12:28 AM, Larry Martell wrote: >> I've worked at places where: > > Add to that list: > > - Some of the programmers really aren't programmers, but the boss just > hasn't figured it out yet. > > That was my last job, until said non-programmer decided to quit. Or: The boss thinks they're a programmer and they're not and wants to tell you how to do things. Or: The boss is a former programmer, perhaps even a very good one, but he's not at all involved with the day to day issues, but still wants to tell you how to do things. From sturla.molden at gmail.com Tue Apr 8 11:19:00 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 8 Apr 2014 15:19:00 +0000 (UTC) Subject: threading References: Message-ID: <1351946045418662915.523525sturla.molden-gmail.com@news.gmane.org> alister wrote: > As my only professional coding experience has been with embedded 8 bit > processors with limited resources i naturally abhorrent to the process of > "Just throw more RAM (Or any other resource for that matter)at it". I understand. I do not advocate threads for parallel i/o on 8, 16 or 32 bit systems ? nor on 64 bit systems without sufficient RAM. But I do advocate is that buying RAM is cheaper than buying developer time. Sturla From gheskett at wdtv.com Tue Apr 8 11:14:57 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Tue, 8 Apr 2014 11:14:57 -0400 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: <201404081114.57345.gheskett@wdtv.com> On Tuesday 08 April 2014 10:52:39 Larry Martell did opine: > On Tue, Apr 8, 2014 at 3:07 AM, James Brewer wrote: > > I'm sure there will be a substantial amount of arrogance perceived > > from this question, but frankly I don't think that I have anything to > > learn from my co-workers, which saddens me because I really like to > > learn and I know that I have a lot of learning to do. > > > > I've been employed as a software engineer for about eight months now > > and I feel like I haven't learned nearly as much as I should. Sure, > > I've picked up little tidbits of information here and there, but I'm > > no more confident in my ability to build anything more complex than a > > basic crud app than I was the day I started. > > I don't know where you work, but there are all sorts of different > working environments. I've been at this for 35 years and I think I've > seen most of them. I've worked at places where: > Ditto, but make it 65 years in electronics for me. > -People were afraid you'll take their job and they won't answer > questions or spend time to bring you up to speed on the company's > systems A minor pet peeve I don't generally tolerate, I relocate. > -People who you're working with either were against hiring you or were > not involved in the hiring process and won't work with you. Not been a huge problem unless the place was unionized. > > -People are on crazy deadlines and have no time to work with you. > Typical sales force. They don't see a single problem when it takes expensive parts to fix, except they won't authorize that P.O. It generally takes a while for them to get the message about the cost of doing business. In my time, I change two general managers above me because of that. > -People have tried to work with you, but don't want to anymore because > ______ (fill in the blank: you're arrogant, you're stupid, you smell, > you don't learn fast enough for them, you like the Yankees and they're > a Red Sox fan, ....) You mean there are fans besides steelers fans? > > -People make you feel like an idiot when you ask a question and they > intimidate you so you don't come back and ask more. That generally only happens a couple times, I am good at making them eat their words. > -The culture requires some 'trial by fire' where you stand up to > people and/or make it known you're not going away and won't take crap > from anyone. Absolutely, you cannot assert yourself any other way. And if you do it in front of the owner, he is your friend for life. > -The new hire sits around and waits for things to happen instead > making things happen themselfs. Where I may sit around when not fixing something, but I am watching for repetitive operations that can better be handled by pushing a few buttons on a micro panel so they can go get a cuppa, it will be done perfectly when they come back. Then I start coding. It took me 6 months as I had to make most of the hardware too, but the first such project I made for a tv station was still in use 15 years later, written in assembly without an assembler and full of self modifying code, only crashed when a power failure outlasted the backup battery, and another I made for the last station I was at was only retired when a $250,000 video switcher was retired, about 14 years. > -There is absolutely nothing interesting going on at the company - no > new development, no hard bugs to track down - and the people they work > there are lazy and slothy, just marking time until they can retire. Those sorts don't normally last till retirement age at a tv station. Caught out enough times and the room will be given to someone who can produce. TV broadcasting is a very competitive field. > -People are super patient and helpful and they answer all your > questions and go beyond the call of duty to help you. A utopia very few will ever find. > Do any of these apply to your situation? See above. This is what you might get when you ask the question. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS From rosuav at gmail.com Tue Apr 8 11:33:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Apr 2014 01:33:29 +1000 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: On Wed, Apr 9, 2014 at 1:10 AM, Larry Martell wrote: > Or: The boss is a former programmer, perhaps even a very good one, but > he's not at all involved with the day to day issues, but still wants > to tell you how to do things. Heh. The boss was a bit like that at my last job. Kept telling me stories of how he programmed some microcontroller in its assembly language... if I wanted to kill time, they were interesting stories, but if I wanted to get some work done in a high level language, they weren't particularly helpful. He also was majorly stuck in a concrete style of coding - consequence of assembly language programming, I think - and couldn't wrap his head around logical layout, functional styles, that kind of thing. I dread to think what he'd be like with Haskell or LISP; I wouldn't even have dared introduce him to Python's generators. (Although he probably wouldn't have been bothered by generators. He was majorly turned off by the whole thing of significant whitespace and basically just told me "there will be no Python here". Bah.) ChrisA From rosuav at gmail.com Tue Apr 8 11:38:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Apr 2014 01:38:42 +1000 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: <201404081114.57345.gheskett@wdtv.com> References: <201404081114.57345.gheskett@wdtv.com> Message-ID: On Wed, Apr 9, 2014 at 1:14 AM, Gene Heskett wrote: > Ditto, but make it 65 years in electronics for me. > >> -People make you feel like an idiot when you ask a question and they >> intimidate you so you don't come back and ask more. > > That generally only happens a couple times, I am good at making them eat > their words. So you play the curmudgeon. That's a perfectly viable role... for someone who's been doing stuff for 65 years. For someone straight out of school, not so much. Even for someone with a few years' experience, trying to bite back like that is very risky. >> -People are super patient and helpful and they answer all your >> questions and go beyond the call of duty to help you. > > A utopia very few will ever find. In corporate, yes, it's rare. But it's a lot less rare in open source projects. I could go into my theories as to why, but it'd make for a long post. ChrisA From sturla.molden at gmail.com Tue Apr 8 11:40:57 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 8 Apr 2014 15:40:57 +0000 (UTC) Subject: threading References: Message-ID: <2096542326418663489.212897sturla.molden-gmail.com@news.gmane.org> Roy Smith wrote: > Let's say I've got a program which consumes 60 GB of RAM, so I'm renting > the 2xlarge instance to run it. My software architect could recode the > program to be more efficient, and fit into just 30 GB, saving me > $3000/year. How much of his time is it worth to do that? He's costing > me about $600/day, so if he can do it in a week, it'll take a year to > recoup my investment. Exactly. That is what I said "just throw more RAM at it". We see this in scientific HPC too. What does it cost of optimizing software compared to just using a bigger computer? It virtually never pays off. Or Python related: Python might be slow, but how much should we value our own time? A simulation which took one week to complete, how long did it take to write the code? When should we use C++ or Fortran instead of Python? Ever? There is a reason scientists are running Python on even the biggest supercomputers today. Hardware might be expensive, but not compared to human resources. And that gap just increases as hardware is getting cheaper. So we should optimize for human resources rather than for hardware. And with 64 bit that is finally possible. (It isn't always possible with 32 bit, so that is a different story.) Sturla From larry.martell at gmail.com Tue Apr 8 11:44:57 2014 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 8 Apr 2014 11:44:57 -0400 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: On Tue, Apr 8, 2014 at 11:33 AM, Chris Angelico wrote: > He was majorly turned off > by the whole thing of significant whitespace and basically just told > me "there will be no Python here". Bah.) I had programmed in perl for 20 years, then got a job at place where the boss made the edict "There will be no perl here, only python." I resisted, complained, grumbled and struggled for a few months, but now I thank him every time I see him. From sturla.molden at gmail.com Tue Apr 8 11:44:29 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 8 Apr 2014 15:44:29 +0000 (UTC) Subject: threading References: Message-ID: <1602550978418664488.592168sturla.molden-gmail.com@news.gmane.org> Roy Smith wrote: > Thread 1 and Thread 2 use a pair of queues to communicate. T1 sends > work to T2 using Q1, and T2 sends back results using Q2. > > T1 pushes Item1 onto Q1, and waits for Result1 to come back on Q2. > > T2 reads Item1 from its end of Q1, and waits to read Item2, which it > needs to compute Result1. > > Sounds like a deadlock to me. As it turns out, if you try hard enough, you can always construct a race condition, deadlock or a livelock. If you need to guard against it, there is paradigms like BSP, but not everything fits in. a BSP design. Sturla From rosuav at gmail.com Tue Apr 8 11:48:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Apr 2014 01:48:52 +1000 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: On Wed, Apr 9, 2014 at 1:44 AM, Larry Martell wrote: > On Tue, Apr 8, 2014 at 11:33 AM, Chris Angelico wrote: >> He was majorly turned off >> by the whole thing of significant whitespace and basically just told >> me "there will be no Python here". Bah.) > > I had programmed in perl for 20 years, then got a job at place where > the boss made the edict "There will be no perl here, only python." I > resisted, complained, grumbled and struggled for a few months, but now > I thank him every time I see him. I managed to convince him to let me use Pike for a lot of the work, though I suspect that - now that we're no longer working together - he's ripping a lot of it out in favour of either PHP or JavaScript. And that's a job I wouldn't wish on my worst enemy. ChrisA From sturla.molden at gmail.com Tue Apr 8 12:06:15 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 8 Apr 2014 16:06:15 +0000 (UTC) Subject: threading References: Message-ID: <1700405790418664759.421830sturla.molden-gmail.com@news.gmane.org> alister wrote: > My main point was that when you have only 8K of ROM & 128 byte of ram you > have to think about your algorithms first. And that also happens if you have a 32 bit system, with just 2 GB of memory available to user space (the operating system reserves the upper half of the 4 GB address space). Using threads to solve a C10K problem means you must limit yourself to e.g. 150KB of memory (including stack space) per thread. Is that doable? Perhaps not. Can you put 10,000 threads in the kernel and hope for good performance? On Windows, yes, at least since Windows 2000. On Linux? Only recently. That I think was the real argument for asynchronous i/o. Today this is not so relevant, but idea that asynchronous i/o is fundamentally better than threads is still with us. So what we are left with, then, in favor of non-blocking i/o is ability to time-out a non-responsive i/o operation. But that does not mean we need an asynchronous event-driven server. (Actually we can time-out blocking i/o with threads, but it involves using two threads per connection instead of one.) Sturla From no.email at nospam.invalid Tue Apr 8 12:38:49 2014 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 08 Apr 2014 09:38:49 -0700 Subject: threading References: Message-ID: <7x4n23dbdy.fsf@ruckus.brouhaha.com> Sturla Molden writes: > As it turns out, if you try hard enough, you can always construct a race > condition, deadlock or a livelock. If you need to guard against it, there > is paradigms like BSP, but not everything fits in. a BSP design. Software transactional memory (STM) may also be of interest, though it's not that great a fit with Python. From no.email at nospam.invalid Tue Apr 8 12:46:41 2014 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 08 Apr 2014 09:46:41 -0700 Subject: threading References: Message-ID: <7xzjjvbwge.fsf@ruckus.brouhaha.com> Sturla Molden writes: > When should we use C++ or Fortran instead of Python? Ever? When performance matters? > There is a reason scientists are running Python on even the biggest > supercomputers today. They use Python as a scripting wrapper around numerics libraries written in compiled languages. > Hardware might be expensive, but not compared to human resources. Sure, and that implies that making people wait for computer results costs you. If a C++ program can run in 2 seconds while the equivalent Python script would take a minute, the Python version loses the user's attention and they have to burn time refocusing it. Or if the C++ version takes 12 hours and the Python version takes a month, they can start the C++ version at the end of their workday and have the results when they arrive at the office the next morning. Then they spend the day examining the results and adjusting the program for the next run. Most of my stuff is in Python but there are times when your stuff just has to run fast. From sturla.molden at gmail.com Tue Apr 8 12:37:41 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 8 Apr 2014 16:37:41 +0000 (UTC) Subject: threading References: <87d2gsowck.fsf@elektro.pacujo.net> Message-ID: <628793226418666289.764727sturla.molden-gmail.com@news.gmane.org> Marko Rauhamaa wrote: > Queues are fine if you hermetically insulate your objects. IOW, you > group your objects in single-threaded pseudoprocesses that don't make > any direct method calls to each other. If you do that, you might as well > use real processes. That way, you can even naturally enforce your > insulation assumption against accidents. No, 10,000 processes will not do. First, they use more resources than threads, at least on Windows. Second, if something fails, you have 10,000 worker processes to kill. You also risk flooding your system with zombies. So thanks, but no thanks. I would consider a small pool of processes to utilize all cores on the CPU, though. But each process would have hundreds or thousands of threads. .NET AppDomains is an attempt to solve this. Python do not support AppDomains in the interpreter. It would be nice if it did, though, e.g. a thread with an isolated interpreter instance (similar to tcl). But currently the Python interpreter is not designed for that, as it has states which are lobal to the process, not just the interpreter. If we insulate objects completely, we must also serialize (pickle) them before sending them off as messages on a queue. That can be a major bottleneck. At least it is in numerical computing with Python. Avoiding serialization is also an important consideration. But IPC itself is very fast, so the important part is packing a object into a byte string and unpacking, not the overhead involved in sending it. Unix domain sockets and Windows named pipes are close to a memcpy in performance, with very little overhead. Pickle on the other hand is "very slow". Serialization is hard ot get around if we use processes for multi-core CPUs, but in a pure multithread design it is not an issue. Sturla From steve+comp.lang.python at pearwood.info Tue Apr 8 12:44:16 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Apr 2014 16:44:16 GMT Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? References: <201404081114.57345.gheskett@wdtv.com> Message-ID: <53442760$0$29993$c3e8da3$5496439d@news.astraweb.com> On Wed, 09 Apr 2014 01:38:42 +1000, Chris Angelico wrote: >>> -People are super patient and helpful and they answer all your >>> questions and go beyond the call of duty to help you. >> >> A utopia very few will ever find. > > In corporate, yes, it's rare. But it's a lot less rare in open source > projects. I could go into my theories as to why, but it'd make for a > long post. http://michaelochurch.wordpress.com/2012/04/13/java-shop-politics/ -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Tue Apr 8 12:46:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Apr 2014 02:46:27 +1000 Subject: threading In-Reply-To: <7xzjjvbwge.fsf@ruckus.brouhaha.com> References: <7xzjjvbwge.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Apr 9, 2014 at 2:46 AM, Paul Rubin wrote: > Sure, and that implies that making people wait for computer results > costs you. If a C++ program can run in 2 seconds while the equivalent > Python script would take a minute, the Python version loses the user's > attention and they have to burn time refocusing it. Or if the C++ > version takes 12 hours and the Python version takes a month, they can > start the C++ version at the end of their workday and have the results > when they arrive at the office the next morning. Then they spend the > day examining the results and adjusting the program for the next run. > > Most of my stuff is in Python but there are times when your stuff just > has to run fast. This is true. However, this applies ONLY when you really are spending that much computational effort and getting interactive response. Most programs aren't like that; most interactive programs do their work in a fraction of a second regardless of the language (the difference between 10ms and 50ms is nothing to a human), and performance of non-interactive servers really translates to throughput (can you handle 100 requests a second or 200 req/s?) When you actually do have heavy mathematical computation, often you can write your logic in Python and have the grunt-work done at a lower level; that's what all those numeric/scientific libraries are doing, and that's also - in effect - what crypto libraries do for you. You don't implement cryptography in Python; you call on a lower-level library and let it do the work. So the choices aren't really "write it in Python" and "write it in C++". The choices are actually "write it in some combination of Python and C/FORTRAN" and "write it in C++ with some libraries written in whatever". And when you look at it like that, the difference isn't nearly as stark as it first seemed. I'd much rather write my outer wrapper code in something like Python than have to fiddle with all those basics in C++; and that goes even more strongly if I have to write any sort of UI beyond the most basic console I/O. I've written my share of GUIs in C++, and Python beats them all hands down. Even for basic text, it's a lot easier in Python; sure, I have printf() to do my output, and that's fine, but for input, I'm really not happy with either cin (C++ iostream style) or gets/scanf (C stdio style). In Python? >>> input("Enter your name: ") and you get back a nice Unicode string. Easy. ChrisA From joel.goldstick at gmail.com Tue Apr 8 13:16:41 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 8 Apr 2014 13:16:41 -0400 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: <53442760$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <201404081114.57345.gheskett@wdtv.com> <53442760$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: Check meetup.com. I live in nyc where there are django, python groups. Maybe where you live too On Apr 8, 2014 12:45 PM, "Steven D'Aprano" < steve+comp.lang.python at pearwood.info> wrote: > On Wed, 09 Apr 2014 01:38:42 +1000, Chris Angelico wrote: > > >>> -People are super patient and helpful and they answer all your > >>> questions and go beyond the call of duty to help you. > >> > >> A utopia very few will ever find. > > > > In corporate, yes, it's rare. But it's a lot less rare in open source > > projects. I could go into my theories as to why, but it'd make for a > > long post. > > http://michaelochurch.wordpress.com/2012/04/13/java-shop-politics/ > > > > > > -- > Steven D'Aprano > http://import-that.dreamwidth.org/ > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sturla.molden at gmail.com Tue Apr 8 13:17:51 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 8 Apr 2014 17:17:51 +0000 (UTC) Subject: threading References: <7xzjjvbwge.fsf@ruckus.brouhaha.com> Message-ID: <861840133418667970.668023sturla.molden-gmail.com@news.gmane.org> Paul Rubin wrote: > Sturla Molden writes: >> When should we use C++ or Fortran instead of Python? Ever? > > When performance matters? Sometimes, but usually performance only matters in certain types of calculations like matrix algebra or FFTs. But we always use specialized libraries for that, such as Intel MKL, OpenBLAS, AMD ACML, or Apple's Accelerate Framework. "When performance matters" is not really a good answer, because performance might not matter where we think or as much as we think. For examle if I were to write a Levenberg-Marquardt solver, I would e.g. find that 95% of the time is spent solving the linearized least-squares equations (J' J + lambda diag(J' J)) dx = J' error using QR or SVD. If I used LAPACK method DGELS or DGELSS to solve these equations with QR or SVD, I would find that my otherwise idential Fortran and Python code would perform roughly the same. None of the performance libraries I mentioned cares if I am calling them from Python or Fortran. The differences in runtime would thus be in the 5 % spent outside the performance libraries. And if i/o is more efficient in Python, which is very likely, it might even be that the Python version runs faster. So the question is, when does it matter for me? Now and then, perhaps, but very rarely. For example it did matter when we wrote the cKDTree object for SciPy. But it never matters when I use it. I will make the bold claim that 90 % of the use of C++ or Fortran code in scientific computing stems from the misconception that "writing everything" in a compiled language will be faster. I have done this mistake myself, and lost valuable time. I have promised myself I will not do it again, and then realized I have done the same mistake yet again. It is a very dangerous misconception. Always prototype in Python first, then profile, then choose between optimization or using a bigger computer. Starting out by writing C, C++, Cython or Fortran is a trap. Yet many do, myself included, because we errorneously trust ourselves to know when we should just use Python. But the thing is, nobody does, we just think we do. Sturla From rosuav at gmail.com Tue Apr 8 13:18:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Apr 2014 03:18:26 +1000 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: <53442760$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <201404081114.57345.gheskett@wdtv.com> <53442760$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 9, 2014 at 2:44 AM, Steven D'Aprano wrote: > On Wed, 09 Apr 2014 01:38:42 +1000, Chris Angelico wrote: > >>>> -People are super patient and helpful and they answer all your >>>> questions and go beyond the call of duty to help you. >>> >>> A utopia very few will ever find. >> >> In corporate, yes, it's rare. But it's a lot less rare in open source >> projects. I could go into my theories as to why, but it'd make for a >> long post. > > http://michaelochurch.wordpress.com/2012/04/13/java-shop-politics/ Yeah, that goes into several of the reasons I would have been saying. It also has some great quotes. """ C++ exists because someone had a fever dream in which these two classes of vehicles got mixed up and thought, ?I?m going to put wings on a [bleep] tank?. """ ChrisA From marko at pacujo.net Tue Apr 8 13:17:22 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 08 Apr 2014 20:17:22 +0300 Subject: threading References: <87d2gsowck.fsf@elektro.pacujo.net> Message-ID: <8738hnwxjx.fsf@elektro.pacujo.net> Sturla Molden : > No, 10,000 processes will not do. I never suggested that. In fact, I'm on the record recommending about two processes per CPU core. There are many principles on which to allocate threads/processes: objects, tasks, stimulus sources, CPUs. I'm advocating CPUs. If you use nonblocking primitives, a single process is enough to keep a CPU busy and the throughput high. With multiple processors, you need more processes, but generally not more than one. You should give the hardware a chance to optimize the dataflows a bit so having some extra processes is probably a good idea. Marko From alister.nospam.ware at ntlworld.com Tue Apr 8 13:19:46 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 08 Apr 2014 17:19:46 GMT Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? Message-ID: On Wed, 09 Apr 2014 01:48:52 +1000, Chris Angelico wrote: > I managed to convince him to let me use Pike for a lot of the work, > though I suspect that - now that we're no longer working together - > he's ripping a lot of it out in favour of either PHP or JavaScript. > And that's a job I wouldn't wish on my worst enemy. > > ChrisA Why was your code that bad? ;-) -- Kin, n.: An affliction of the blood. From rosuav at gmail.com Tue Apr 8 13:29:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Apr 2014 03:29:30 +1000 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: On Wed, Apr 9, 2014 at 3:19 AM, alister wrote: > On Wed, 09 Apr 2014 01:48:52 +1000, Chris Angelico wrote: > >> I managed to convince him to let me use Pike for a lot of the work, >> though I suspect that - now that we're no longer working together - >> he's ripping a lot of it out in favour of either PHP or JavaScript. >> And that's a job I wouldn't wish on my worst enemy. >> >> ChrisA > > Why was your code that bad? ;-) It was idiomatic Pike code, which is in many ways similar to idiomatic Python (definitely not exactly, but I'm guessing you're not familiar with Pike, so just pretend I'd written a good few KLOC of idiomatic Python). The code is expressive; in just a handful of lines, I can do bulk operations on entire arrays of values, and I can comfortably run callbacks efficiently, and (this part wouldn't work so easily in Python) on a SIGHUP, the code would smoothly switch over to the latest version on the disk, without breaking any currently-processing work. Now try rewriting that in PHP (or serverside JavaScript - probably node.js or something - but he hadn't gone anywhere beyond the "vague theory" stage with server JS, so PHP is more likely). Bear in mind that you have to handle multiple concurrent network connections, so you need to do either piles of threads/processes or asynchronous I/O (the Pike code used the latter). So, yeah. My code would make for terrible PHP. :) One day, out of morbid curiosity, I might try SSHing into one of the boxes to see whether any of the accounts are still there for which I know the passwords. (I was the primary network admin, so I knew the passwords for a lot of obscure accounts on obscure servers.) Would be interesting to see what's going on there. But more than likely the project's dead in the water. It's highly unlikely he'll find a decent programmer willing to work for the low wages I was getting there, and even less likely that he'll have the time to do it all on his own. ChrisA From steve+comp.lang.python at pearwood.info Tue Apr 8 13:25:01 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Apr 2014 17:25:01 GMT Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? References: Message-ID: <534430ed$0$29993$c3e8da3$5496439d@news.astraweb.com> On Tue, 08 Apr 2014 17:19:46 +0000, alister wrote: > On Wed, 09 Apr 2014 01:48:52 +1000, Chris Angelico wrote: > >> I managed to convince him to let me use Pike for a lot of the work, >> though I suspect that - now that we're no longer working together - >> he's ripping a lot of it out in favour of either PHP or JavaScript. And >> that's a job I wouldn't wish on my worst enemy. >> >> ChrisA > > Why was your code that bad? ;-) Now be kind! It's not that Chris' code was bad, but obviously Pike is such a rubbish language that it's all but untranslatable... :-P -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Tue Apr 8 13:36:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Apr 2014 03:36:13 +1000 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: <534430ed$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <534430ed$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 9, 2014 at 3:25 AM, Steven D'Aprano wrote: > Now be kind! It's not that Chris' code was bad, but obviously Pike is > such a rubbish language that it's all but untranslatable... > > :-P Now that's completely not true! Translating Pike into PHP is by definition easy. Look: // Pike code: int x = (1==2) ? 3 : 4; # PHP code: $x = (1==2) ? 3 : 4; # Python code: x = 3 if 1==2 else 4 See? Python is just arbitrarily different! The ?: operator is fundamental to so much of programming, and Python has to go and break it! (*Stop* trolling you?!? But this is getting-trolled-on-the-head lessons... anyway, you started it...) ChrisA From pecore at pascolo.net Tue Apr 8 13:45:19 2014 From: pecore at pascolo.net (pecore at pascolo.net) Date: Tue, 08 Apr 2014 19:45:19 +0200 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? References: <201404081114.57345.gheskett@wdtv.com> <53442760$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87k3azn2a8.fsf@pascolo.net> > """ ?I?m going to put wings on a [bleep] tank?. class FairchildA10(... From rosuav at gmail.com Tue Apr 8 13:58:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Apr 2014 03:58:54 +1000 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: <87k3azn2a8.fsf@pascolo.net> References: <201404081114.57345.gheskett@wdtv.com> <53442760$0$29993$c3e8da3$5496439d@news.astraweb.com> <87k3azn2a8.fsf@pascolo.net> Message-ID: On Wed, Apr 9, 2014 at 3:45 AM, wrote: >> """ ?I?m going to put wings on a [bleep] tank?. > > class FairchildA10(... Ah yes, the Warthog. You might call one ugly, but it'll just call you dead... ChrisA From feliphil at gmx.net Tue Apr 8 14:10:44 2014 From: feliphil at gmx.net (Wolfgang Keller) Date: Tue, 8 Apr 2014 20:10:44 +0200 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? References: Message-ID: <20140408201044.8f44b493523d7a20afc6f82e@gmx.net> > Things I'm interested include contributing to both Python and Django, > database design and data modeling, Django is made by people who definitely don't know what they're doing. https://code.djangoproject.com/wiki/MultipleColumnPrimaryKeys Open the index to any half-decent database design textbook, look for the term "overlapping foreign keys" and learn why surrogate keys are a non-starter. One answer to the subject line would be: Learn to judge the competence of people by asking a few "litmus" questions. The above mentioned issue is one personal "litmus" question I ask anyone who pretends to have a clue of database design and database applications. Sincerely, Wolfgang From ethan at stoneleaf.us Tue Apr 8 14:09:57 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 08 Apr 2014 11:09:57 -0700 Subject: threading In-Reply-To: References: Message-ID: <53443B75.90100@stoneleaf.us> On 04/06/2014 08:56 PM, Chris Angelico wrote: > On Mon, Apr 7, 2014 at 1:48 PM, Roy Smith wrote: >> There is (or at least, was) another reason. Creating a new process used >> to be far more expensive than creating a new thread. In modern Unix >> kernels, however, the cost difference has become much less, so this is >> no longer a major issue. > > Unix maybe, but what about Windows? Is it efficient to create > processes under Windows? Not a concern until performance is not good enough. -- ~Ethan~ From sturla.molden at gmail.com Tue Apr 8 15:41:40 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 08 Apr 2014 21:41:40 +0200 Subject: threading In-Reply-To: References: Message-ID: On 07/04/14 05:56, Chris Angelico wrote: > On Mon, Apr 7, 2014 at 1:48 PM, Roy Smith wrote: >> There is (or at least, was) another reason. Creating a new process used >> to be far more expensive than creating a new thread. In modern Unix >> kernels, however, the cost difference has become much less, so this is >> no longer a major issue. > > Unix maybe, but what about Windows? Is it efficient to create > processes under Windows? Processes are very heavy-weight on Windows. Sturla From james at brwr.org Tue Apr 8 15:44:37 2014 From: james at brwr.org (James Brewer) Date: Tue, 8 Apr 2014 12:44:37 -0700 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: On Tue, Apr 8, 2014 at 7:28 AM, Larry Martell wrote: > -People are on crazy deadlines and have no time to work with you. > > > -People make you feel like an idiot when you ask a question and they > intimidate you so you don't come back and ask more. > Both of these issues exist; mainly on the part of the CTO. I feel like everyone else is on board with making a few changes that need to happen, but management is much more concerned with pushing code to keep investors happy. While I understand that we have to move quickly as a startup, I don't understand why we are sacrificing quality for speed. > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrickjohnson at gmail.com Tue Apr 8 15:47:31 2014 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 8 Apr 2014 12:47:31 -0700 (PDT) Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: <5bc85cf7-fc38-4d2f-8082-d30161023b80@googlegroups.com> On Tuesday, April 8, 2014 2:07:27 AM UTC-5, James Brewer wrote: > I'm sure there will be a substantial amount of arrogance > perceived from this question, but frankly I don't think > that I have anything to learn from my co-workers, which > saddens me because I really like to learn and I know that > I have a lot of learning to do. > > [Blah-blah-blah -- rambling in a feeble attempt to mask my > question as more than just infantile whining -- blah-blah- > blah...] > > Basically, I want to be a better engineer. Where can I > find someone willing to point me in the right direction > and what can I offer in return? Judging from your childish optimism and bombastic expectations that the onerous of scholastic achievements lay solely in the prowess of your teacher, i can only conclude that you are yet another recent graduate of one of the "fine universities" that happily rob naive parents of their life savings and then infect the professional world with plagues of self-absorbed little lazy a-holes who think they offload their workload on everyone else. So you want to be taught eh? Maybe you should consider this little "tidbit"... "When the pupil is ready, the master will appear" And now allow me to "female dog" slap you back in to reality about your new found "masters" -- you know, the ones you so kindly refer to as "co-workers"... They are not going to help you! They are not going to teach you! Heck, they may not even point you in the direction of the lavatory when you need to tinkle! No, these people are your mortal enemies. They will smile to your pimpled face and then stick a knife in your back -- not much unlike the trolls around here! Listen kid; working is competition, a competition to the death, and only the stupidest of stupid person would train their replacement! So what is a boy to do? I would suggest you learn a little self reliance. Go and read some tutorials, learn a new language, try to challenge yourself to build something that is beyond your skill level. Short of that you'll always be Bubba's "female dog". Good day! From james at brwr.org Tue Apr 8 15:45:59 2014 From: james at brwr.org (James Brewer) Date: Tue, 8 Apr 2014 12:45:59 -0700 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: <201404081114.57345.gheskett@wdtv.com> <53442760$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: I'm in the Bay Area and I did actually go to a Django meetup yesterday in SF where there were talks revolving around large-scale Django applications. It was very informative. :) On Tue, Apr 8, 2014 at 10:16 AM, Joel Goldstick wrote: > Check meetup.com. I live in nyc where there are django, python groups. > Maybe where you live too > On Apr 8, 2014 12:45 PM, "Steven D'Aprano" < > steve+comp.lang.python at pearwood.info> wrote: > >> On Wed, 09 Apr 2014 01:38:42 +1000, Chris Angelico wrote: >> >> >>> -People are super patient and helpful and they answer all your >> >>> questions and go beyond the call of duty to help you. >> >> >> >> A utopia very few will ever find. >> > >> > In corporate, yes, it's rare. But it's a lot less rare in open source >> > projects. I could go into my theories as to why, but it'd make for a >> > long post. >> >> http://michaelochurch.wordpress.com/2012/04/13/java-shop-politics/ >> >> >> >> >> >> -- >> Steven D'Aprano >> http://import-that.dreamwidth.org/ >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > -- > https://mail.python.org/mailman/listinfo/python-list > > -- *James Brewer* *http://www.brwr.org/ * *Software Engineer @ RealScout | What is RealScout? * *Twitter* *twitter.com/jamesbrwr * *GitHub* *github.com/brwr* *StackOverflow** stackoverflow.com/users/2052923/james-brewer * *LinkedIn* *linkedin.com/in/jamesbrwr * ? *M**y favorite RealScout search is Modern & High-Tech Homes in Atherton * -------------- next part -------------- An HTML attachment was scrubbed... URL: From urbangabo at gmail.com Tue Apr 8 16:18:20 2014 From: urbangabo at gmail.com (Gabor Urban) Date: Tue, 8 Apr 2014 22:18:20 +0200 Subject: Python 2.3 and ODBC Message-ID: Hi guys, I am using Python 2.3 on an XP box at my company. (I know it is quite outdated, but we could not make the management to upgrade.) I have started a pilot project the last week to show the possibility of processing incoming XML files and extracting data into Oracle tables. Now I am almost ready, but need to use an ODBC module with Python. What do you suggest? BTW if my demo will be good, we hope to have an aproval to change to Python 3.3 Thanks in advance -- Urb?n G?bor Linux is like a wigwam: no Gates, no Windows and an Apache inside. -------------- next part -------------- An HTML attachment was scrubbed... URL: From larry.martell at gmail.com Tue Apr 8 16:24:14 2014 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 8 Apr 2014 16:24:14 -0400 Subject: Python 2.3 and ODBC In-Reply-To: References: Message-ID: On Tue, Apr 8, 2014 at 4:18 PM, Gabor Urban wrote: > Hi guys, > > I am using Python 2.3 on an XP box at my company. (I know it is quite > outdated, but we could not make the management to upgrade.) I have started a > pilot project the last week to show the possibility of processing incoming > XML files and extracting data into Oracle tables. > > Now I am almost ready, but need to use an ODBC module with Python. What do > you suggest? I do not know anything about Windows, but on Linux I'm pretty sure pyodbc requires python 2.7 or higher. From python.list at tim.thechases.com Tue Apr 8 16:32:40 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 8 Apr 2014 15:32:40 -0500 Subject: Python 2.3 and ODBC In-Reply-To: References: Message-ID: <20140408153240.79b0bb34@bigbox.christie.dr> On 2014-04-08 22:18, Gabor Urban wrote: > I am using Python 2.3 on an XP box at my company. (I know it is > quite outdated, but we could not make the management to upgrade.) I > have started a pilot project the last week to show the possibility > of processing incoming XML files and extracting data into Oracle > tables. > > Now I am almost ready, but need to use an ODBC module with Python. > What do you suggest? Your project sounds remarkably like one I maintain for a local business, though I have the luxury of working with Python 2.*4* under XP on that project. :-) That said, the differences between 2.3 and 2.4 are pretty minor; decorators being the big difference. For that project, the company uses mx.ODBC http://www.egenix.com/products/python/mxODBC/ which works with 2.4 and might have a 2.3 build available if you dig hard enough. If you main goal is to build a good demo and then promote to newer versions, eGenix might be willing to extend an unsupported older version along with a developer license. I know Marc-Andre Lemburg (of eGenix) lurks here, posting occasionally with new releases of mxODBC, so he might chime in with details. > BTW if my demo will be good, we hope to have an aproval to change > to Python 3.3 I pray all goes well for you, as the constraints of pre-2.5 chafe horribly. :-) -tkc From invalid at invalid.invalid Tue Apr 8 16:30:37 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 8 Apr 2014 20:30:37 +0000 (UTC) Subject: threading References: Message-ID: On 2014-04-08, Sturla Molden wrote: > On 07/04/14 05:56, Chris Angelico wrote: >> On Mon, Apr 7, 2014 at 1:48 PM, Roy Smith wrote: >>> There is (or at least, was) another reason. Creating a new process used >>> to be far more expensive than creating a new thread. In modern Unix >>> kernels, however, the cost difference has become much less, so this is >>> no longer a major issue. >> >> Unix maybe, but what about Windows? Is it efficient to create >> processes under Windows? > > Processes are very heavy-weight on Windows. Not surprising given its VMS heritage. I remember running shell scripts under VMS on a VAX-11/780 that took hours to do what would have taken minutes on an LSI-11 running Unix. The whole Unix "small tools working together" paradigm is based on the assumption that process creation and death are fast and cheap. -- Grant Edwards grant.b.edwards Yow! I selected E5 ... but at I didn't hear "Sam the Sham gmail.com and the Pharoahs"! From breamoreboy at yahoo.co.uk Tue Apr 8 17:35:46 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 08 Apr 2014 22:35:46 +0100 Subject: Python 2.3 and ODBC In-Reply-To: References: Message-ID: On 08/04/2014 21:18, Gabor Urban wrote: > Hi guys, > [snip] > > BTW if my demo will be good, we hope to have an aproval to change to > Python 3.3 Why 3.3? 3.4 has just been released and has lots of new batteries, so why not use them? > > Thanks in advance > > -- > Urb?n G?bor > Linux is like a wigwam: no Gates, no Windows and an Apache inside. > > -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From sg552 at hotmail.co.uk Tue Apr 8 18:09:11 2014 From: sg552 at hotmail.co.uk (Rotwang) Date: Tue, 08 Apr 2014 23:09:11 +0100 Subject: Scoping rules for class definitions In-Reply-To: References: Message-ID: On 04/04/2014 19:55, Ian Kelly wrote: > On Fri, Apr 4, 2014 at 12:37 PM, Rotwang wrote: >> Hi all. I thought I had a pretty good grasp of Python's scoping rules, but >> today I noticed something that I don't understand. Can anyone explain to me >> why this happens? >> >>>>> x = 'global' >>>>> def f1(): >> x = 'local' >> class C: >> y = x >> return C.y >> >>>>> def f2(): >> x = 'local' >> class C: >> x = x >> return C.x >> >>>>> f1() >> 'local' >>>>> f2() >> 'global' > > Start by comparing the disassembly of the two class bodies: > >>>> dis.dis(f1.__code__.co_consts[2]) > 3 0 LOAD_NAME 0 (__name__) > 3 STORE_NAME 1 (__module__) > 6 LOAD_CONST 0 ('f1..C') > 9 STORE_NAME 2 (__qualname__) > > 4 12 LOAD_CLASSDEREF 0 (x) > 15 STORE_NAME 3 (y) > 18 LOAD_CONST 1 (None) > 21 RETURN_VALUE >>>> dis.dis(f2.__code__.co_consts[2]) > 3 0 LOAD_NAME 0 (__name__) > 3 STORE_NAME 1 (__module__) > 6 LOAD_CONST 0 ('f2..C') > 9 STORE_NAME 2 (__qualname__) > > 4 12 LOAD_NAME 3 (x) > 15 STORE_NAME 3 (x) > 18 LOAD_CONST 1 (None) > 21 RETURN_VALUE > > The only significant difference is that the first uses > LOAD_CLASSDEREF, which I guess is the class version of LOAD_DEREF for > loading values from closures, at line 4 whereas the second uses > LOAD_NAME. So the first one knows about the x in the nonlocal scope, > whereas the second does not and just loads the global (since x doesn't > yet exist in the locals dict). > > Now why doesn't the second version also use LOAD_CLASSDEREF? My guess > is because it's the name of a local; if it were referenced a second > time in the class then the second LOAD_CLASSDEREF would again get the > x from the nonlocal scope, which would be incorrect. Thanks (sorry for the slow reply, I've had a busy few days). For anyone who's interested, I also found an interesting discussion of the above in the following thread: https://mail.python.org/pipermail/python-dev/2002-April/023427.html From sturla.molden at gmail.com Tue Apr 8 18:32:10 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Wed, 09 Apr 2014 00:32:10 +0200 Subject: threading In-Reply-To: References: Message-ID: On 08/04/14 22:30, Grant Edwards wrote: >>> Unix maybe, but what about Windows? Is it efficient to create >>> processes under Windows? >> >> Processes are very heavy-weight on Windows. > > Not surprising given its VMS heritage. I remember running shell > scripts under VMS on a VAX-11/780 that took hours to do what would > have taken minutes on an LSI-11 running Unix. The whole Unix "small > tools working together" paradigm is based on the assumption that > process creation and death are fast and cheap. That is one reason software tend to be monolithic on Windows, including build tools. Running a configure script used to take forever, but thankfully computers are getting faster. Sturla From grawburg at myglnc.com Tue Apr 8 16:09:28 2014 From: grawburg at myglnc.com (Grawburg) Date: Tue, 08 Apr 2014 16:09:28 -0400 Subject: "Latching" variables in function Message-ID: <7ffe44a68f47a64f5120d3a6c6a660b5@myglnc.com> I've probably used the wrong term - I'm thinking of what I do when writing PLC code - so I can't find how to do this in my reference books. This is part of a project I'm working on with a Raspberry Pi and an MCP23017 port expander. I have a N/O pushbutton that I want to "latch" a value to a variable when it's been pressed. ?I have this function that gets called periodically in a 'while True' statement: def button(): ? ?pushbutton = 0 ? button_value = 0 ? ?pushbutton=bus.read_byte_data(address,GPIOB) ? ?if pushbutton > 0: ? ? ? ? button_value = 1 ? ?return button_value I need button_value to become '1' when the button is pressed and to remain '1' until the entire program (only about 25 lines) ends with a sys.exit() What do I use to 'latch' button_value? Brian Grawburg North Carolina -- The truth will set you free . . .but first it will infuriate you. From james at brwr.org Tue Apr 8 16:19:51 2014 From: james at brwr.org (James Brewer) Date: Tue, 8 Apr 2014 13:19:51 -0700 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: <5bc85cf7-fc38-4d2f-8082-d30161023b80@googlegroups.com> References: <5bc85cf7-fc38-4d2f-8082-d30161023b80@googlegroups.com> Message-ID: On Tue, Apr 8, 2014 at 12:47 PM, Rick Johnson wrote: > > Judging from your childish optimism and bombastic > expectations that the onerous of scholastic achievements lay > solely in the prowess of your teacher, i can only conclude > that you are yet another recent graduate of one of the > "fine universities" that happily rob naive parents of their > life savings and then infect the professional world with > plagues of self-absorbed little lazy a-holes who think they > offload their workload on everyone else. > > So you want to be taught eh? Maybe you should consider this > little "tidbit"... > > "When the pupil is ready, the master will appear" > > And now allow me to "female dog" slap you back in to reality > about your new found "masters" -- you know, the ones you so > kindly refer to as "co-workers"... > > > They are not going to help you! > > They are not going to teach you! > > Heck, they may not even point you in the direction of > the lavatory when you need to tinkle! > > No, these people are your mortal enemies. They will smile to > your pimpled face and then stick a knife in your back -- not > much unlike the trolls around here! > > Listen kid; working is competition, a competition to the > death, and only the stupidest of stupid person would train > their replacement! > > So what is a boy to do? > > I would suggest you learn a little self reliance. Go and > read some tutorials, learn a new language, try to challenge > yourself to build something that is beyond your skill level. > Short of that you'll always be Bubba's "female dog". > > Good day! > You're an interesting fellow. Also, I didn't graduate; I dropped out. -------------- next part -------------- An HTML attachment was scrubbed... URL: From marc at marcsnet.com Tue Apr 8 16:39:27 2014 From: marc at marcsnet.com (Marc Lucke) Date: Wed, 09 Apr 2014 06:39:27 +1000 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: <5bc85cf7-fc38-4d2f-8082-d30161023b80@googlegroups.com> References: <5bc85cf7-fc38-4d2f-8082-d30161023b80@googlegroups.com> Message-ID: <53445E7F.1010703@marcsnet.com> On 9/04/2014 5:47 AM, Rick Johnson wrote: > On Tuesday, April 8, 2014 2:07:27 AM UTC-5, James Brewer wrote: >> I'm sure there will be a substantial amount of arrogance >> perceived from this question, but frankly I don't think >> that I have anything to learn from my co-workers, which >> saddens me because I really like to learn and I know that >> I have a lot of learning to do. >> >> [Blah-blah-blah -- rambling in a feeble attempt to mask my >> question as more than just infantile whining -- blah-blah- >> blah...] >> >> Basically, I want to be a better engineer. Where can I >> find someone willing to point me in the right direction >> and what can I offer in return? > Judging from your childish optimism and bombastic > expectations that the onerous of scholastic achievements lay > solely in the prowess of your teacher, i can only conclude > that you are yet another recent graduate of one of the > "fine universities" that happily rob naive parents of their > life savings and then infect the professional world with > plagues of self-absorbed little lazy a-holes who think they > offload their workload on everyone else. > > So you want to be taught eh? Maybe you should consider this > little "tidbit"... > > "When the pupil is ready, the master will appear" > > And now allow me to "female dog" slap you back in to reality > about your new found "masters" -- you know, the ones you so > kindly refer to as "co-workers"... > > > They are not going to help you! > > They are not going to teach you! > > Heck, they may not even point you in the direction of > the lavatory when you need to tinkle! > > No, these people are your mortal enemies. They will smile to > your pimpled face and then stick a knife in your back -- not > much unlike the trolls around here! > > Listen kid; working is competition, a competition to the > death, and only the stupidest of stupid person would train > their replacement! > > So what is a boy to do? > > I would suggest you learn a little self reliance. Go and > read some tutorials, learn a new language, try to challenge > yourself to build something that is beyond your skill level. > Short of that you'll always be Bubba's "female dog". > > Good day! > "Teach and learn twice". I love teaching people. It makes me better. Marc From wuwei23 at gmail.com Tue Apr 8 20:02:03 2014 From: wuwei23 at gmail.com (alex23) Date: Wed, 09 Apr 2014 10:02:03 +1000 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: On 9/04/2014 3:29 AM, Chris Angelico wrote: > My code would make for terrible PHP. :) Don't feel bad about that. It's a truism for every language, including PHP. From denismfmcmahon at gmail.com Tue Apr 8 20:28:36 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 9 Apr 2014 00:28:36 +0000 (UTC) Subject: "Latching" variables in function References: Message-ID: On Tue, 08 Apr 2014 16:09:28 -0400, Grawburg wrote: > def button(): > ? ?pushbutton = 0 > ? button_value = 0 > ? ?pushbutton=bus.read_byte_data(address,GPIOB) > ? ?if pushbutton > 0: > ? ? ? ? button_value = 1 > ? ?return button_value Every time your function is called, you start out with button_value of 0. You may need a global variable that starts out as False (or 0), and once flipped to True (or 1) and then stays there: button_value = False # or: button_value = 0 def button(): global button_value ? ?pushbutton = bus.read_byte_data( address, GPIOB ) ? ?if pushbutton > 0: ? ? ? ? button_value = True # or: button_value = 1 ? ?return button_value Also I think I'd probably pass the IO address as a parameter to the button function. -- Denis McMahon, denismfmcmahon at gmail.com From wuwei23 at gmail.com Tue Apr 8 20:39:49 2014 From: wuwei23 at gmail.com (alex23) Date: Wed, 09 Apr 2014 10:39:49 +1000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <5343b186$0$11109$c3e8da3@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <38795bc9-f67d-423f-a929-212b6b38ec8c@googlegroups.com> <5343b186$0$11109$c3e8da3@news.astraweb.com> Message-ID: On 8/04/2014 6:21 PM, Steven D'Aprano wrote: > Functions which are intended to return a value may be named as verbs: > [...] > or as nouns: > int Shorthand for 'integerise'. > str 'stringify' > dict 'dictionarate' > coordinate > array These are both verbs. ...I'll get me coat. From greg.ewing at canterbury.ac.nz Tue Apr 8 20:43:38 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 09 Apr 2014 12:43:38 +1200 Subject: Keeping track of things with dictionaries In-Reply-To: References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: Chris Angelico wrote: > in the dictionary I > have here (Debian Wheezy, using an American English dictionary - it's > a symlink to (ultimately) /usr/share/dict/american-english), there are > five entries in that list. Mine's bigger than yours! On MacOSX 10.6 I get 41 words. (I think someone must have fed a medical dictionary into it... my list includes such obviously indispensible terms as laparocolpohysterotomy, thyroparathyroidectomy and ureterocystanastomosis.) Unfortunately I seem to be missing antidisestablishmentarianism, because the longest words in my dict are only 24 characters, excluding the '\n'. Should I ask for my money back? -- Greg From ethan at stoneleaf.us Tue Apr 8 20:22:12 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 08 Apr 2014 17:22:12 -0700 Subject: "Latching" variables in function In-Reply-To: <7ffe44a68f47a64f5120d3a6c6a660b5@myglnc.com> References: <7ffe44a68f47a64f5120d3a6c6a660b5@myglnc.com> Message-ID: <534492B4.3000602@stoneleaf.us> On 04/08/2014 01:09 PM, Grawburg wrote: > > I've probably used the wrong term - I'm thinking of what I do when writing PLC code - so I can't find how to do this in my reference books. > This is part of a project I'm working on with a Raspberry Pi and an MCP23017 port expander. > I have a N/O pushbutton that I want to "latch" a value to a variable when it's been pressed. I have this function that gets called periodically in > a 'while True' statement: > > > def button(): > pushbutton = 0 > button_value = 0 > pushbutton=bus.read_byte_data(address,GPIOB) > if pushbutton > 0: > button_value = 1 > return button_value > > > > > I need button_value to become '1' when the button is pressed and to remain '1' until the entire program (only about 25 lines) ends with a sys.exit() > > > What do I use to 'latch' button_value? If I understand correctly, once 'bus.read_byte_data()' has returned a non-zero value, 'button' should continue returning 1 even if 'bus.read_byte_data()' later returns a 0? There are a couple options for this: - use a default paramater as static storage def button(_latched=[0]) push_button = _latched[0] if not push_button: button_value = bus.read_byte_data(address, GPIOB) if button_value > 0: _latched[0] = push_button = 1 return push_button - use a class # implementation left as an exercise for the reader ;) -- ~Ethan~ From rantingrickjohnson at gmail.com Tue Apr 8 21:09:12 2014 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 8 Apr 2014 18:09:12 -0700 (PDT) Subject: threading In-Reply-To: References: Message-ID: <4a24f218-158a-4a21-af36-5cc69ce1f7e1@googlegroups.com> A overview of the Py-Venactular used in this thread: by Professor Rick ############################################################ # Finny Said: # ############################################################ # "Threading is very difficult to get right" # ############################################################ Hmm, and I wonder how difficult threading would be to "get" left? Or perhaps the proper explanation would be: "Using the Python threading module *correctly* can be difficult to *contemplate* by mere mortals (and even most experts, just ask GvR!). Which can be future trimmed to: "If the implementation is difficult to explain (or use), it's probably a bad idea. -PythonZen ############################################################ # Roy Said: # ############################################################ # "Threading makes it incredibly difficult to reason about # # program execution." # ############################################################ Makes "what" incredibly difficult? Makes *reasoning* very difficult? ############################################################ # Roy Said: # ############################################################ # "It's not just that things happen asynchronously, the # # control flow changes happen at arbitrary times." # ############################################################ Your first four words are superfluous and could have simply been replaced with "because" or "since". Below I've joined both sentences into a complete thought, observe: "Threading renders reasoning of program execution difficult, because of unpredictable control flow." "Since control flow is unpredictable, use of the Python threading module is not advised when parallel processing will suffice." ############################################################ # Chris Said: # ############################################################ # Is it efficient to create processes under Windows? # ############################################################ Is "what" efficient? Creating processes? You just said that! Now I'm confused? :-( ############################################################ # Marko Said: # ############################################################ # Another way to look at it...[snip] # ############################################################ Look at what? There should be no visual learners here. ############################################################ # Marko Said: # ############################################################ # I don't think it worked out all that well. # ############################################################ If you want to poke a stick in someones eye then do it explicitly, don't be a wuss by using implicit expletives. Instead you could have post fixed this snarky remark to your main idea: "-- Obviously the attempt was an abysmal failure!". ############################################################ # Paul said: # ############################################################ # I keep hearing about all the perils of threading bugs # # and it just hasn't happened to me in Python as far as I # # know. # ############################################################ What has not happened to you? "threading bugs"? ============================================================ Summary: ============================================================ I'm far too lazy to continue on --since the transcribing and corrections for just this "relatively short" thread could take hours--, and my intentions are not to belittle any of our fine community members, however, sometimes we all need to be reminded of our own weaknesses. I would hope that my fellow members would consider investing more thought into the structure and coherency of their posts. A little proof reading can go a long way you know! But most importantly, i would hope that they might realize the damage done not only to the coherency of this groups message from the habitual usage of expletives, but also, to their own logical expression of ideas. So, next time you find yourself writing the word "it", stop and ask yourself these questions: "What is "it" referring to? "Did i unconsciously use "it" to beg the question, or underscore the obvious?" "Does the removal of "it" from this sentence effect the interpretation of my expression?" You see, there are very few instances where an "it" is required, and if you're communication skills are honed you can just about never use the word "it" again. ============================================================ "It", FINALLY EXPLAINED!!! ============================================================ "IT" IS A CRUTCH WIELDED BY LAZY COMMUNICATORS. I warn you that not only will "it" impede the interpretation of your ideas, "it" will also degrade your ability to think clearly when expressing yourself and slow (or completely halt) your linguistic evolution. HAVE YOU NOTICED THAT YOUR INNER MONOLOGUE NEVER USES "IT"? Indeed! That's because "it" is a habitual viral infestation of the human communication interface. "It" cannot exits in the purely logical realm of the mind. We must stop the future propagation of "it" and work to eradicate "it" from our vernacular if we wish to achieve logical nirvana. From rustompmody at gmail.com Tue Apr 8 22:17:21 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 8 Apr 2014 19:17:21 -0700 (PDT) Subject: threading In-Reply-To: References: Message-ID: <36b54196-ce59-4e21-be83-c7f118f172ed@googlegroups.com> On Wednesday, April 9, 2014 4:02:10 AM UTC+5:30, Sturla Molden wrote: > On 08/04/14 22:30, Grant Edwards wrote: > >>> Unix maybe, but what about Windows? Is it efficient to create > >>> processes under Windows? > >> Processes are very heavy-weight on Windows. > > Not surprising given its VMS heritage. I remember running shell > > scripts under VMS on a VAX-11/780 that took hours to do what would > > have taken minutes on an LSI-11 running Unix. The whole Unix "small > > tools working together" paradigm is based on the assumption that > > process creation and death are fast and cheap. > That is one reason software tend to be monolithic on Windows, including > build tools. > Running a configure script used to take forever, but thankfully > computers are getting faster. I was looking at Erlang... And under similar presumptions that I see on this thread (in a different sense!) viz.: Either the messiness of callback hell or the error-proneness of threads However this was Erlang whose basic premise is to question this either-or. And so I was properly told-off by Joe Armstrong (roughly the equivalent of being told off by Guido out here :-) ) http://erlang.org/pipermail/erlang-questions/2012-October/069560.html Note Erlang, Go and Cloud-haskell all set out along a similar route: http://joneisen.tumblr.com/post/38188396218/concurrency-models-go-vs-erlang From rosuav at gmail.com Tue Apr 8 22:19:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Apr 2014 12:19:59 +1000 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: <5bc85cf7-fc38-4d2f-8082-d30161023b80@googlegroups.com> Message-ID: On Wed, Apr 9, 2014 at 6:19 AM, James Brewer wrote: > On Tue, Apr 8, 2014 at 12:47 PM, Rick Johnson > wrote: >>[ a whole lot of typical stuff ] > > You're an interesting fellow. Rick's one of our resident... uhh... characters. Don't take his words to heart. > Also, I didn't graduate; I dropped out. I dropped out of high school. Never went to uni/college/etc. ChrisA From rosuav at gmail.com Tue Apr 8 22:26:07 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Apr 2014 12:26:07 +1000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e811a$0$29993$c3e8da3$5496439d@news.astraweb.com> <874n26su9f.fsf@elektro.pacujo.net> <53418644$0$29993$c3e8da3$5496439d@news.astraweb.com> <38795bc9-f67d-423f-a929-212b6b38ec8c@googlegroups.com> <5343b186$0$11109$c3e8da3@news.astraweb.com> Message-ID: On Wed, Apr 9, 2014 at 10:39 AM, alex23 wrote: >> int > > > Shorthand for 'integerise'. Not at all. "Integrate". It's a vital mathematical operation, that's why you always get a number back. ... I'll get my coat, too. ChrisA From rosuav at gmail.com Tue Apr 8 22:33:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Apr 2014 12:33:28 +1000 Subject: Keeping track of things with dictionaries In-Reply-To: References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: On Wed, Apr 9, 2014 at 10:43 AM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> in the dictionary I >> have here (Debian Wheezy, using an American English dictionary - it's >> a symlink to (ultimately) /usr/share/dict/american-english), there are >> five entries in that list. > > > Mine's bigger than yours! On MacOSX 10.6 I get 41 words. > (I think someone must have fed a medical dictionary into > it... my list includes such obviously indispensible terms > as laparocolpohysterotomy, thyroparathyroidectomy and > ureterocystanastomosis.) Yeah, it'll vary based on the exact dictionary used. I went for something with multiple, but not prolific, entries. > Unfortunately I seem to be missing antidisestablishmentarianism, > because the longest words in my dict are only 24 characters, > excluding the '\n'. Should I ask for my money back? I think you should. That's a fundamental flaw in the dictionary. Everyone knows that word's the longest! ChrisA From wuwei23 at gmail.com Tue Apr 8 22:34:13 2014 From: wuwei23 at gmail.com (alex23) Date: Wed, 09 Apr 2014 12:34:13 +1000 Subject: Keeping track of things with dictionaries In-Reply-To: References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: On 8/04/2014 6:31 PM, Frank Millman wrote: > Here is an idea, inspired by Peter Otten's suggestion earlier in this > thread. > > Instead of defaultdict, subclass dict and use __missing__() to supply the > default values. > When the dictionary is set up, delete __missing__ from the subclass! > Ugly, but it seems to work. Ugly indeed. Replicating the behaviour of defaultdict and then deleting a method from the class seems a very heavyhanded 'solution', especially when you can just override a public attribute on defaultdict, as mentioned by Peter. From wuwei23 at gmail.com Tue Apr 8 22:45:04 2014 From: wuwei23 at gmail.com (alex23) Date: Wed, 09 Apr 2014 12:45:04 +1000 Subject: Keeping track of things with dictionaries In-Reply-To: References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: On 9/04/2014 12:33 PM, Chris Angelico wrote: >> Unfortunately I seem to be missing antidisestablishmentarianism, >> because the longest words in my dict are only 24 characters, >> excluding the '\n'. Should I ask for my money back? > > I think you should. That's a fundamental flaw in the dictionary. > Everyone knows that word's the longest! It depends on whether you count 'supercalifragilisticexpialidocious'. If you don't, then 'pseudopseudohypoparathyroidism' is still slightly longer :) From ian.g.kelly at gmail.com Tue Apr 8 23:19:33 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 8 Apr 2014 21:19:33 -0600 Subject: Keeping track of things with dictionaries In-Reply-To: References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Message-ID: On Tue, Apr 8, 2014 at 8:45 PM, alex23 wrote: > On 9/04/2014 12:33 PM, Chris Angelico wrote: >>> >>> Unfortunately I seem to be missing antidisestablishmentarianism, >>> because the longest words in my dict are only 24 characters, >>> excluding the '\n'. Should I ask for my money back? >> >> >> I think you should. That's a fundamental flaw in the dictionary. >> Everyone knows that word's the longest! > > > It depends on whether you count 'supercalifragilisticexpialidocious'. If you > don't, then 'pseudopseudohypoparathyroidism' is still slightly longer :) 'Pneumonoultramicroscopicsilicovolcanoconiosis' has them all beat. From gheskett at wdtv.com Tue Apr 8 23:31:50 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Tue, 8 Apr 2014 23:31:50 -0400 Subject: Keeping track of things with dictionaries In-Reply-To: References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> Message-ID: <201404082331.50367.gheskett@wdtv.com> On Tuesday 08 April 2014 23:31:35 Ian Kelly did opine: > On Tue, Apr 8, 2014 at 8:45 PM, alex23 wrote: > > On 9/04/2014 12:33 PM, Chris Angelico wrote: > >>> Unfortunately I seem to be missing antidisestablishmentarianism, > >>> because the longest words in my dict are only 24 characters, > >>> excluding the '\n'. Should I ask for my money back? > >> > >> I think you should. That's a fundamental flaw in the dictionary. > >> Everyone knows that word's the longest! > > > > It depends on whether you count 'supercalifragilisticexpialidocious'. > > If you don't, then 'pseudopseudohypoparathyroidism' is still slightly > > longer :) > > 'Pneumonoultramicroscopicsilicovolcanoconiosis' has them all beat. Source citation please? Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS From tjreedy at udel.edu Wed Apr 9 00:29:50 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 09 Apr 2014 00:29:50 -0400 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: <53442760$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <201404081114.57345.gheskett@wdtv.com> <53442760$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/8/2014 12:44 PM, Steven D'Aprano wrote: > http://michaelochurch.wordpress.com/2012/04/13/java-shop-politics/ Thank you for posting this. I read several more. I especially found this interesting: http://michaelochurch.wordpress.com/2012/08/26/xwp-vs-jap/ in which he concludes that one route to becoming a good programmer is to not be a programmer. It seems that being a 'statistician who programs' was a better gig, comparitively speaking, than I realized at the time. Another way to work on high level projects is to volunteer on an open source project. -- Terry Jan Reedy From tjreedy at udel.edu Wed Apr 9 00:35:01 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 09 Apr 2014 00:35:01 -0400 Subject: "Latching" variables in function In-Reply-To: <7ffe44a68f47a64f5120d3a6c6a660b5@myglnc.com> References: <7ffe44a68f47a64f5120d3a6c6a660b5@myglnc.com> Message-ID: On 4/8/2014 4:09 PM, Grawburg wrote: > > I've probably used the wrong term - I'm thinking of what I do when writing PLC code - so I can't find how to do this in my reference books. > This is part of a project I'm working on with a Raspberry Pi and an MCP23017 port expander. > I have a N/O pushbutton that I want to "latch" a value to a variable when it's been pressed. I have this function that gets called periodically in > a 'while True' statement: > > def button(): > pushbutton = 0 > button_value = 0 > pushbutton=bus.read_byte_data(address,GPIOB) > if pushbutton > 0: > button_value = 1 > return button_value > > I need button_value to become '1' when the button is pressed and to remain '1' until the entire program (only about 25 lines) ends with a sys.exit() > > What do I use to 'latch' button_value? It depends on whether you can set up your system so that pushing the button generates an interrupt. But I know little about R.Pi and less about the 'port expander'. If there were an interrupt, you would just have to write an interrupt handler. When possible, this is much better than polling. -- Terry Jan Reedy From gheskett at wdtv.com Tue Apr 8 20:42:27 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Tue, 8 Apr 2014 20:42:27 -0400 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: <201404081114.57345.gheskett@wdtv.com> Message-ID: <201404082042.27714.gheskett@wdtv.com> On Tuesday 08 April 2014 20:23:05 Chris Angelico did opine: > On Wed, Apr 9, 2014 at 1:14 AM, Gene Heskett wrote: > > Ditto, but make it 65 years in electronics for me. > > > >> -People make you feel like an idiot when you ask a question and they > >> intimidate you so you don't come back and ask more. > > > > That generally only happens a couple times, I am good at making them > > eat their words. > > So you play the curmudgeon. That's a perfectly viable role... for > someone who's been doing stuff for 65 years. For someone straight out > of school, not so much. Even for someone with a few years' experience, > trying to bite back like that is very risky. > At that point, neither of those two gents had a good idea what I could do as I had only drove in on a motorcycle to interview for the job about 3 weeks before, so I could have been out the door, but watching the owner, I could see the wheels turning, in about 1.5 seconds he nodded his head in my direction and changed the subject. But because the owner could see I wasn't kidding, it became just one more clue that eventually lead to that GM being let go. I became his goto man even after I had retired and we spent many a pleasant flight in his twin piston pounder Cessna as I was being hauled someplace to put a technical "fire" out. Telling war stories, I mentioned that another GM, who in the end was given 5 minutes to get his things as the sheriff was going to escort him out as he had been cooking the books, but he had made threats to fire me on several occasions. The owner (who has since passed) looked me right in the eye & said he couldn't have done it because he would never get permissions from me. > >> -People are super patient and helpful and they answer all your > >> questions and go beyond the call of duty to help you. > > > > A utopia very few will ever find. > > In corporate, yes, it's rare. But it's a lot less rare in open source > projects. I could go into my theories as to why, but it'd make for a > long post. No doubt, unfortunately, I haven't been that involved with open source other than as a confirmed user since 1997. Born 40 years too soon I guess. I grew up building my stuff using vacuum tubes. Its quite a treat watching you guys call some students bluff over doing his homework for him. That isn't how you learn how to do it, and we both damned well know it. But generally, you do so with a sense of humor to go with the elbow in the ribs. Just watching that interplay has been educational in and by itself. ;-) You, as John Glenn once said, do good work. > ChrisA Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS From ian.g.kelly at gmail.com Tue Apr 8 23:37:44 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 8 Apr 2014 21:37:44 -0600 Subject: Keeping track of things with dictionaries In-Reply-To: <201404082331.50367.gheskett@wdtv.com> References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <201404082331.50367.gheskett@wdtv.com> Message-ID: On Tue, Apr 8, 2014 at 9:31 PM, Gene Heskett wrote: >> 'Pneumonoultramicroscopicsilicovolcanoconiosis' has them all beat. > > Source citation please? http://en.wikipedia.org/wiki/Pneumonoultramicroscopicsilicovolcanoconiosis http://www.oxforddictionaries.com/definition/english/pneumonoultramicroscopicsilicovolcanoconiosis http://dictionary.reference.com/browse/Pneumonoultramicroscopicsilicovolcanoconiosis From carlinli94 at gmail.com Wed Apr 9 03:47:59 2014 From: carlinli94 at gmail.com (Carlin Li) Date: Wed, 9 Apr 2014 00:47:59 -0700 Subject: solutions manual and test banks Message-ID: Approximately how much do you charge for these solutions manuals? -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at brwr.org Wed Apr 9 02:53:31 2014 From: james at brwr.org (James Brewer) Date: Tue, 8 Apr 2014 23:53:31 -0700 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: <5bc85cf7-fc38-4d2f-8082-d30161023b80@googlegroups.com> Message-ID: On Tue, Apr 8, 2014 at 7:19 PM, Chris Angelico wrote: > On Wed, Apr 9, 2014 at 6:19 AM, James Brewer wrote: > > You're an interesting fellow. > > Rick's one of our resident... uhh... characters. Don't take his words to > heart. > > > Also, I didn't graduate; I dropped out. > > I dropped out of high school. Never went to uni/college/etc. > > ChrisA One thing I have picked up is to take what everyone says with a grain of salt, taking only that advice which is helpful. People like Rick are awesome because they say things that other people only think; and sometimes these things are the most helpful. :) - James -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Apr 9 03:54:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Apr 2014 17:54:02 +1000 Subject: solutions manual and test banks In-Reply-To: References: Message-ID: On Wed, Apr 9, 2014 at 5:47 PM, Carlin Li wrote: > Approximately how much do you charge for these solutions manuals? > You're responding to a spambot. I advise against it :) Most of us didn't even see the original post (I certainly didn't), and you really don't want to be inviting more spam. ChrisA From orgnut at yahoo.com Wed Apr 9 04:02:05 2014 From: orgnut at yahoo.com (Larry Hudson) Date: Wed, 09 Apr 2014 01:02:05 -0700 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: On 04/08/2014 08:02 AM, Chris Angelico wrote: > On Wed, Apr 9, 2014 at 12:28 AM, Larry Martell wrote: >> I've worked at places where: > > Add to that list: > > - Some of the programmers really aren't programmers, but the boss just > hasn't figured it out yet. > > That was my last job, until said non-programmer decided to quit. > > ChrisA > This reminds me of one of the stories on the Computer Stupidities website. (The site says these anecdotes are public domain, so I can copy it here.) Since I teach nights at a local community college, I get a lot of professional programmers in my classes upgrading their education. One student, who was one such person, attended every lecture and smiled and nodded and took notes. But he only turned in his first assignment. The results of his first test were horrid. Out of curiosity, I asked my wife, who barely knew how to turn a computer on much less program one, to take the test (which was mostly true/false and multiple choice questions). My wife scored higher than this guy. The semester's end came, and he flubbed his final, too. A few weeks later, I got a call from him complaining about his 'F'. I pointed out he hadn't turned in any of his assignments, and those counted 75% of the grade. "Did you hear me say something besides what the other students heard?" I asked. "Well, I thought my test grades would carry me," he replied. It had turned out his company had paid for him to take the course. Since he failed, it suddenly came to the attention of his employer that he didn't know how to program, and now his job was in jeopardy. As I hung up the phone, I mused that his company shouldn't fire him. It was a perfect match: a programmer who couldn't program and a company that couldn't figure out sooner that he couldn't. If you have some leisure time, this site is well worth at least a quick skim--lots of hilarious stories and of course some just so-so (like broken cup holders). And I suspect some are apocryphal, but a lot of fun stuff. The home page is http://rinkworks.com/stupid/ This story is in the Miscellaneous Dumbness section. -=- Larry -=- From wxjmfauth at gmail.com Wed Apr 9 04:07:20 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 9 Apr 2014 01:07:20 -0700 (PDT) Subject: Python and Unicode Message-ID: <9f3580c2-ef8c-4dcc-8dea-7eca3b242f15@googlegroups.com> Well, there is a (serious) problem somewhere... jmf From breamoreboy at yahoo.co.uk Wed Apr 9 04:50:23 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 09 Apr 2014 09:50:23 +0100 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: <5bc85cf7-fc38-4d2f-8082-d30161023b80@googlegroups.com> Message-ID: On 08/04/2014 21:19, James Brewer wrote: > On Tue, Apr 8, 2014 at 12:47 PM, Rick Johnson > > wrote: > > You're an interesting fellow. Also, I didn't graduate; I dropped out. > try: print('rr is okay when discussing IDLE or tkinter') except TrollingError: print('just ignore him') -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Wed Apr 9 04:53:36 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 09 Apr 2014 09:53:36 +0100 Subject: Python and Unicode In-Reply-To: <9f3580c2-ef8c-4dcc-8dea-7eca3b242f15@googlegroups.com> References: <9f3580c2-ef8c-4dcc-8dea-7eca3b242f15@googlegroups.com> Message-ID: On 09/04/2014 09:07, wxjmfauth at gmail.com wrote: > Well, there is a (serious) problem somewhere... > > jmf > Look in a mirror and you'll see it as it'll be staring you in the face. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Wed Apr 9 04:55:36 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 09 Apr 2014 09:55:36 +0100 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: On 09/04/2014 01:02, alex23 wrote: > On 9/04/2014 3:29 AM, Chris Angelico wrote: >> My code would make for terrible PHP. :) > > Don't feel bad about that. It's a truism for every language, including PHP. Yep. And the worst thing about terrible code is when you first realise just how bad it is and wonder why you wrote it like that in the first place. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From hayesstw at telkomsa.net Wed Apr 9 05:01:56 2014 From: hayesstw at telkomsa.net (Steve Hayes) Date: Wed, 09 Apr 2014 11:01:56 +0200 Subject: Python and Unicode References: <9f3580c2-ef8c-4dcc-8dea-7eca3b242f15@googlegroups.com> Message-ID: On Wed, 9 Apr 2014 01:07:20 -0700 (PDT), wxjmfauth at gmail.com wrote: >Well, there is a (serious) problem somewhere... As there is with pandas and infertility. -- Terms and conditions apply. Steve Hayes hayesmstw at hotmail.com From elearn2014 at gmail.com Wed Apr 9 03:43:09 2014 From: elearn2014 at gmail.com (length power) Date: Wed, 9 Apr 2014 15:43:09 +0800 Subject: is there more simple way to do? Message-ID: x='name,sex,birthday\n\nx1,male,1948/05/28\n\nx2,female,1952/03/27 \n\nx3,female,1994/12/09' x.replace("\n\n","\n").splitlines() is there more simple way to replace `x.replace("\n\n","\n").splitlines()` ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From elearn2014 at gmail.com Wed Apr 9 04:57:25 2014 From: elearn2014 at gmail.com (length power) Date: Wed, 9 Apr 2014 16:57:25 +0800 Subject: how to insert the elements in a list properly? Message-ID: word=["x1","x2","x3","x4","x5"] w=word[-2:] del word[-2:] word.insert(2,w) word ['x1', 'x2', ['x4', 'x5'], 'x3'] what i want to get is ['x1', 'x2', 'x4', 'x5', 'x3'] how can i insert them ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From gheskett at wdtv.com Wed Apr 9 05:51:26 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Wed, 9 Apr 2014 05:51:26 -0400 Subject: Keeping track of things with dictionaries In-Reply-To: References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <201404082331.50367.gheskett@wdtv.com> Message-ID: <201404090551.26098.gheskett@wdtv.com> On Wednesday 09 April 2014 05:47:37 Ian Kelly did opine: > On Tue, Apr 8, 2014 at 9:31 PM, Gene Heskett wrote: > >> 'Pneumonoultramicroscopicsilicovolcanoconiosis' has them all beat. > > > > Source citation please? > > http://en.wikipedia.org/wiki/Pneumonoultramicroscopicsilicovolcanoconios > is > http://www.oxforddictionaries.com/definition/english/pneumonoultramicro > scopicsilicovolcanoconiosis > http://dictionary.reference.com/browse/Pneumonoultramicroscopicsilicovo > lcanoconiosis Damn, I should know better than call your bluff. Serves me right. :( Boil that down to its essence and it might be used for one of the miners lung problems (black or white lung) they eventually die from. I have a friend doing that as I type. And getting very close to the end of his rope. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS From __peter__ at web.de Wed Apr 9 06:46:24 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 09 Apr 2014 12:46:24 +0200 Subject: how to insert the elements in a list properly? References: Message-ID: length power wrote: > word=["x1","x2","x3","x4","x5"] > w=word[-2:] > del word[-2:] > word.insert(2,w) > word > ['x1', 'x2', ['x4', 'x5'], 'x3'] > > what i want to get is > ['x1', 'x2', 'x4', 'x5', 'x3'] > > how can i insert them ? Make the left-hand side an empty slice: >>> words = ["x1", "x2", "x3", "x4", "x5"] >>> w = words[-2:] >>> del words[-2:] >>> words[2:2] = w >>> words ['x1', 'x2', 'x4', 'x5', 'x3'] Or note that the operation is equivalent to moving the third item to the end: >>> words = ["x1", "x2", "x3", "x4", "x5"] >>> words.append(words.pop(2)) >>> words ['x1', 'x2', 'x4', 'x5', 'x3'] From __peter__ at web.de Wed Apr 9 06:48:43 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 09 Apr 2014 12:48:43 +0200 Subject: is there more simple way to do? References: Message-ID: length power wrote: > x='name,sex,birthday\n\nx1,male,1948/05/28\n\nx2,female,1952/03/27 > \n\nx3,female,1994/12/09' > x.replace("\n\n","\n").splitlines() > > is there more simple way to replace `x.replace("\n\n","\n").splitlines()` > ? One alternative that ignores all empty lines is [line for line in x.splitlines() if line] From antoon.pardon at rece.vub.ac.be Wed Apr 9 07:09:50 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 09 Apr 2014 13:09:50 +0200 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: <4gT0v.62253$oI.45884@fx18.am4> References: <4gT0v.62253$oI.45884@fx18.am4> Message-ID: <53452A7E.80907@rece.vub.ac.be> On 08-04-14 15:58, alister wrote: > On Tue, 08 Apr 2014 13:47:12 +0000, Grant Edwards wrote: > >> On 2014-04-08, Chris Angelico wrote: >>> On Tue, Apr 8, 2014 at 5:07 PM, James Brewer wrote: >>> >>>> Basically, I want to be a better engineer. Where can I find someone >>>> willing to point me in the right direction and what can I offer in >>>> return? >>> Right here on this list! And all you have to offer in return is >>> interesting questions. >> Actually, I've noticed that the questions usually don't even have to be >> very good or interesting. Ask anything. You'll get genneraly get >> answers to: >> >> the question you asked >> >> the question you thought you were asking >> >> the question you should have asked >> >> a few other questions only tangentially related to the above > I would agree with 1 & 4, but 2 & 3 only happen if you are really lucky > :-) No wonder, because when they do happen, chances are someone will complain about that person not answering the question actually asked. -- Antoon Pardon From wrw at mac.com Wed Apr 9 08:12:32 2014 From: wrw at mac.com (William Ray Wing) Date: Wed, 09 Apr 2014 08:12:32 -0400 Subject: "Latching" variables in function In-Reply-To: References: <7ffe44a68f47a64f5120d3a6c6a660b5@myglnc.com> Message-ID: <73D49217-8B06-4F0C-AC57-D9CCD83DF660@mac.com> On Apr 9, 2014, at 12:35 AM, Terry Reedy wrote: > On 4/8/2014 4:09 PM, Grawburg wrote: >> >> I've probably used the wrong term - I'm thinking of what I do when writing PLC code - so I can't find how to do this in my reference books. >> This is part of a project I'm working on with a Raspberry Pi and an MCP23017 port expander. >> I have a N/O pushbutton that I want to "latch" a value to a variable when it's been pressed. I have this function that gets called periodically in >> a 'while True' statement: >> >> def button(): >> pushbutton = 0 >> button_value = 0 >> pushbutton=bus.read_byte_data(address,GPIOB) >> if pushbutton > 0: >> button_value = 1 >> return button_value >> >> I need button_value to become '1' when the button is pressed and to remain '1' until the entire program (only about 25 lines) ends with a sys.exit() >> >> What do I use to 'latch' button_value? > > It depends on whether you can set up your system so that pushing the button generates an interrupt. But I know little about R.Pi and less about the 'port expander'. If there were an interrupt, you would just have to write an interrupt handler. When possible, this is much better than polling. > > -- > Terry Jan Reedy > I think what the OP was asking for was a way in standard Python to ?lock" the value of an instance variable, which of course, you really can?t do. However, what he (I assume it?s a he) could do is arrange his calling program so that after the button method returns a ?1?, the method isn?t called again. That is, test for truth of button = 1 in the calling program, and if true, skip the call. The next time the program runs, the button value will be re-initialized to zero and everything is back to square one. -Bill From frank at chagford.com Wed Apr 9 09:23:33 2014 From: frank at chagford.com (Frank Millman) Date: Wed, 9 Apr 2014 15:23:33 +0200 Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: "Marko Rauhamaa" wrote in message news:877g70wg8p.fsf at elektro.pacujo.net... > Dennis Lee Bieber : > >> That's been my experience too... Threading works for me... My >> attempts at so called asyncio (whatever language) have always led to >> my having to worry about losing data if some handler takes too long to >> return. >> >> To me, asyncio is closer to a polling interrupt handler, and I >> still need a thread to handle the main processing. > > Yes, asynchronous processing results in complex, event-driven state > machines that can be hard to get right. However, my experience is that > that's the lesser evil. > > About a handler taking too long: you need to guard each state with a > timer. Also, you need then to handle the belated handler after the timer > has expired. > Can I ask a newbie question here? I understand that, if one uses threading, each thread *can* block without affecting other threads, whereas if one uses the async approach, a request handler must *not* block, otherwise it will hold up the entire process and not allow other requests to be handled. How does one distinguish betwen 'blocking' and 'non-blocking'? Is it either/or, or is it some arbitrary timeout - if a handler returns within that time it is non-blocking, but if it exceeds it it is blocking? In my environment, most requests involve a database lookup. I endeavour to ensure that a response is returned quickly (however one defines quickly) but I cannot guarantee it if the database server is under stress. Is this a good candidate for async, or not? Thanks for any insights. Frank Millman From python.list at tim.thechases.com Wed Apr 9 09:34:26 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 9 Apr 2014 08:34:26 -0500 Subject: "Latching" variables in function In-Reply-To: <7ffe44a68f47a64f5120d3a6c6a660b5@myglnc.com> References: <7ffe44a68f47a64f5120d3a6c6a660b5@myglnc.com> Message-ID: <20140409083426.7c22eb86@bigbox.christie.dr> On 2014-04-08 16:09, Grawburg wrote: > def button(): > ? ?pushbutton = 0 > ? button_value = 0 > ? ?pushbutton=bus.read_byte_data(address,GPIOB) > ? ?if pushbutton > 0: > ? ? ? ? button_value = 1 > ? ?return button_value > > I need button_value to become '1' when the button is pressed and to > remain '1' until the entire program (only about 25 lines) ends with > a sys.exit() > > What do I use to 'latch' button_value? If I understand what you want, you could do something like class LatchButton: def __init__(self, address): self.value = 0 self.address = address def __call__(self): if not self.value: if bus.read_byte_data(self.address, GPIOB) > 0: self.value = 1 return self.value button1 = LatchButton(address1) button2 = LatchButton(address2) for i in range(10): print button1(), button2() time.sleep(3) -tkc From elearn2014 at gmail.com Wed Apr 9 09:09:37 2014 From: elearn2014 at gmail.com (length power) Date: Wed, 9 Apr 2014 21:09:37 +0800 Subject: how to insert the elements in a list properly? In-Reply-To: References: Message-ID: words = ["x1", "x2", "x3", "x4", "x5"] words.append(words.pop(2)) words.append(words.pop(2)) words ['x1', 'x2', 'x5', 'x3', 'x4'] why i can't write it as: [words.append(words.pop(2)) for i in range(0,2)] >>> [words.append(words.pop(2)) for i in range(0,2)] [None, None] 2014-04-09 18:46 GMT+08:00 Peter Otten <__peter__ at web.de>: > length power wrote: > > > word=["x1","x2","x3","x4","x5"] > > w=word[-2:] > > del word[-2:] > > word.insert(2,w) > > word > > ['x1', 'x2', ['x4', 'x5'], 'x3'] > > > > what i want to get is > > ['x1', 'x2', 'x4', 'x5', 'x3'] > > > > how can i insert them ? > > Make the left-hand side an empty slice: > > >>> words = ["x1", "x2", "x3", "x4", "x5"] > >>> w = words[-2:] > >>> del words[-2:] > >>> words[2:2] = w > >>> words > ['x1', 'x2', 'x4', 'x5', 'x3'] > > Or note that the operation is equivalent to moving the third item to the > end: > > >>> words = ["x1", "x2", "x3", "x4", "x5"] > >>> words.append(words.pop(2)) > >>> words > ['x1', 'x2', 'x4', 'x5', 'x3'] > > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan at tombstonezero.net Wed Apr 9 09:42:59 2014 From: dan at tombstonezero.net (Dan Sommers) Date: Wed, 9 Apr 2014 13:42:59 +0000 (UTC) Subject: how to insert the elements in a list properly? References: Message-ID: On Wed, 09 Apr 2014 21:09:37 +0800, length power wrote: > words = ["x1", "x2", "x3", "x4", "x5"] > words.append(words.pop(2)) > words.append(words.pop(2)) > words > ['x1', 'x2', 'x5', 'x3', 'x4'] > why i can't write it as: > > [words.append(words.pop(2)) for i in range(0,2)] > >>>> [words.append(words.pop(2)) for i in range(0,2)] > [None, None] You can, but you don't want to. At this point, even though the comprehension returned something else, words contains what you want. HTH, Dan From breamoreboy at yahoo.co.uk Wed Apr 9 09:42:52 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 09 Apr 2014 14:42:52 +0100 Subject: threading In-Reply-To: <7x4n23dbdy.fsf@ruckus.brouhaha.com> References: <7x4n23dbdy.fsf@ruckus.brouhaha.com> Message-ID: On 08/04/2014 17:38, Paul Rubin wrote: > Sturla Molden writes: >> As it turns out, if you try hard enough, you can always construct a race >> condition, deadlock or a livelock. If you need to guard against it, there >> is paradigms like BSP, but not everything fits in. a BSP design. > > Software transactional memory (STM) may also be of interest, though > it's not that great a fit with Python. > The pypy folks have been looking at this see http://pypy.readthedocs.org/en/latest/stm.html -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From neilc at norwich.edu Wed Apr 9 09:50:59 2014 From: neilc at norwich.edu (Neil D. Cerutti) Date: Wed, 09 Apr 2014 09:50:59 -0400 Subject: threading In-Reply-To: <4a24f218-158a-4a21-af36-5cc69ce1f7e1@googlegroups.com> References: <4a24f218-158a-4a21-af36-5cc69ce1f7e1@googlegroups.com> Message-ID: On 4/8/2014 9:09 PM, Rick Johnson wrote: > I warn you that not only will "it" impede the interpretation > of your ideas, "it" will also degrade your ability to think > clearly when expressing yourself and slow (or completely > halt) your linguistic evolution. > > HAVE YOU NOTICED THAT YOUR INNER MONOLOGUE NEVER USES "IT"? > > Indeed! > > That's because "it" is a habitual viral infestation of the > human communication interface. It strikes me that that's not superior to it. It's ironic that that would be used in place of it in your rant. Plus Rufus Xavier Sasparilla disagrees with it. -- Neil Cerutti From harrismh777 at gmail.com Wed Apr 9 09:53:19 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 09 Apr 2014 08:53:19 -0500 Subject: "Latching" variables in function In-Reply-To: References: Message-ID: <534550CF.2000808@gmail.com> On 4/8/14 3:09 PM, Grawburg wrote: > I have a N/O pushbutton that I want to "latch" a value to a variable when it's been pressed. > I need button_value to become '1' when the button is pressed and to remain '1' until ... > What do I use to 'latch' button_value? Philosophically speaking buttons don't latch. You push the button, an event is generated, and the call-back handles the event to do something in your project. You might try setting a global variable on the button-push event. Or, if I understand you, you might want to use a configurable, like a radio button or a check box, either of which are designed to be "latched". marcus From rosuav at gmail.com Wed Apr 9 09:47:04 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Apr 2014 23:47:04 +1000 Subject: threading In-Reply-To: References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: On Wed, Apr 9, 2014 at 11:23 PM, Frank Millman wrote: > Can I ask a newbie question here? You certainly can! > I understand that, if one uses threading, each thread *can* block without > affecting other threads, whereas if one uses the async approach, a request > handler must *not* block, otherwise it will hold up the entire process and > not allow other requests to be handled. That would be correct. > How does one distinguish betwen 'blocking' and 'non-blocking'? Is it > either/or, or is it some arbitrary timeout - if a handler returns within > that time it is non-blocking, but if it exceeds it it is blocking? No; a blocking request is one that waits until it has a response, and a non-blocking request is one that goes off and does something, and then comes back to you when it's done. When you turn on the kettle, you can either stay there and watch until it's ready to make your coffee (or, in my case, hot chocolate), or you can go away and come back when it whistles at you to say that it's boiling. A third option, polling, is when you put a pot of water on the stove, turn it on, and then come back periodically to see if it's boiling yet. As the old saying tells us, blocking I/O is a bad idea with pots of water, because it'll never return. > In my environment, most requests involve a database lookup. I endeavour to > ensure that a response is returned quickly (however one defines quickly) but > I cannot guarantee it if the database server is under stress. Is this a good > candidate for async, or not? No, that's a bad idea, because you have blocking I/O. If you have multiple threads, it's fine, because the thread that's waiting for the database will be blocked, and other threads can run (you may need to ensure that you have separate database connections for your separate threads); but in an asynchronous system, you want to be able to go and do something else while you're waiting. Something like this: def blocking_database_query(id): print("Finding out who employee #%d is..."%id) res = db.query("select name from emp where id=12345") print("Employee #%d is %s."%(id,res[0].name)) def nonblocking_query(id): print("Finding out who employee #%d is..."%id) def nextstep(res): print("Employee #%d is %s."%(id,res[0].name)) db.asyncquery(nextstep, "select name from emp where id=12345") This is a common way to do asynchronous I/O. Instead of saying "Do this and give me a result", you say "Do this, and when you have a result, call this function". Then as soon as you've done that, you return (to some main loop, probably). It's usually a bit more complicated than this (eg you might need multiple callbacks or additional arguments in case it times out or otherwise fails - there's no way to throw an exception into a callback, the way the blocking query could throw something instead of returning), but that's the basic concept. You may be able to get away with doing blocking operations in asynchronous mode, if you're confident they'll be fairly fast. But you have to be really REALLY confident, and it does create assumptions that can be wrong. For instance, the above code assumes that print() won't block. You might think "Duh, how can printing to the screen block?!?", but if your program's output is being piped into something else, it most certainly can :) If that were writing to a remote socket, though, it'd be better to perform those operations asynchronously too: attempt to write to the socket; once that's done, start the database query; when the database result arrives, write the response to the socket; when that's done, go back to some main loop. ChrisA From marko at pacujo.net Wed Apr 9 09:55:09 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 09 Apr 2014 16:55:09 +0300 Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: <87lhveobeq.fsf@elektro.pacujo.net> "Frank Millman" : > I understand that, if one uses threading, each thread *can* block > without affecting other threads, whereas if one uses the async > approach, a request handler must *not* block, otherwise it will hold > up the entire process and not allow other requests to be handled. Yes. > How does one distinguish betwen 'blocking' and 'non-blocking'? Is it > either/or, or is it some arbitrary timeout - if a handler returns within > that time it is non-blocking, but if it exceeds it it is blocking? Old-school I/O primitives are blocking by default. Nonblocking I/O is enabled with the setblocking() method. In the new asyncio package, I/O is nonblocking by default (I'm sure, but didn't verify). > In my environment, most requests involve a database lookup. I > endeavour to ensure that a response is returned quickly (however one > defines quickly) but I cannot guarantee it if the database server is > under stress. Is this a good candidate for async, or not? Database libraries are notoriously bad for nonblocking I/O. It's nothing fundamental; it's only that the library writers couldn't appreciate the worth of async communication. For that, asyncio provides special support: Marko From frank at chagford.com Wed Apr 9 10:30:20 2014 From: frank at chagford.com (Frank Millman) Date: Wed, 9 Apr 2014 16:30:20 +0200 Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: "Chris Angelico" wrote in message news:CAPTjJmqwhb8O8vq84mMTv+-Rkc3Ff1AQDXe5cs8Y5gY02kHyNg at mail.gmail.com... > On Wed, Apr 9, 2014 at 11:23 PM, Frank Millman wrote: > >> How does one distinguish betwen 'blocking' and 'non-blocking'? Is it >> either/or, or is it some arbitrary timeout - if a handler returns within >> that time it is non-blocking, but if it exceeds it it is blocking? > > No; a blocking request is one that waits until it has a response, and > a non-blocking request is one that goes off and does something, and > then comes back to you when it's done. Does reading from disk count as blocking? Strictly speaking I would have thought 'yes'. In other words, non-blocking implies that everything required to pass off the request to a handler and be ready to deal with the next one must already be in memory, and it must not rely on communicating with any outside resource at all. Is this correct? > > def blocking_database_query(id): > print("Finding out who employee #%d is..."%id) > res = db.query("select name from emp where id=12345") > print("Employee #%d is %s."%(id,res[0].name)) > > def nonblocking_query(id): > print("Finding out who employee #%d is..."%id) > def nextstep(res): > print("Employee #%d is %s."%(id,res[0].name)) > db.asyncquery(nextstep, "select name from emp where id=12345") > In this example, what is 'db.asyncquery'? If you mean that you have a separate thread to handle database queries, and you use a queue or other message-passing mechanism to hand it the query and get the result, then I understand it. If not, can you explain in more detail. If I have understood correctly, then is there any benefit at all in my going async? I might as well just stick with threads for the request handling as well as the database handling. Frank From rosuav at gmail.com Wed Apr 9 10:44:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Apr 2014 00:44:52 +1000 Subject: threading In-Reply-To: References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: On Thu, Apr 10, 2014 at 12:30 AM, Frank Millman wrote: > > "Chris Angelico" wrote in message > news:CAPTjJmqwhb8O8vq84mMTv+-Rkc3Ff1AQDXe5cs8Y5gY02kHyNg at mail.gmail.com... >> On Wed, Apr 9, 2014 at 11:23 PM, Frank Millman wrote: >> >>> How does one distinguish betwen 'blocking' and 'non-blocking'? Is it >>> either/or, or is it some arbitrary timeout - if a handler returns within >>> that time it is non-blocking, but if it exceeds it it is blocking? >> >> No; a blocking request is one that waits until it has a response, and >> a non-blocking request is one that goes off and does something, and >> then comes back to you when it's done. > > Does reading from disk count as blocking? Strictly speaking I would have > thought 'yes'. What the operation actually *is* is quite immaterial. Reading from the disk can be done as blocking or non-blocking; if you simply open a file and call its read() method, that'll block by default (the open() call can block, too, but you asked about reading). When you ask for something to be done and expect a return value with the result, that implies a blocking operation. Even simple work like floating-point addition can be blocking or nonblocking; I learned some of the basics of the 8087 coprocessor and how to do assembly-language floating point, and it was, by default, a non-blocking operation - you say "Go do this", and then you say "FWAIT" to block until the coprocessor is done. But normally you want to be able to write this: a = 12.3 b = 45.6 c = a + b print("The sum is:",c) rather than this: add_async(a, b, lambda c: print("The sum is:",c)) > In other words, non-blocking implies that everything required to pass off > the request to a handler and be ready to deal with the next one must already > be in memory, and it must not rely on communicating with any outside > resource at all. Is this correct? Nope. It simply requires that communicating with an outside resource be done asynchronously. You fire off the request and either check for its completion periodically (polling) or get a notification when it's done (callback, usually). >> def nonblocking_query(id): >> print("Finding out who employee #%d is..."%id) >> def nextstep(res): >> print("Employee #%d is %s."%(id,res[0].name)) >> db.asyncquery(nextstep, "select name from emp where id=12345") >> > > In this example, what is 'db.asyncquery'? > > If you mean that you have a separate thread to handle database queries, and > you use a queue or other message-passing mechanism to hand it the query and > get the result, then I understand it. If not, can you explain in more > detail. It's an imaginary function that would send a request to the database, and then call some callback function when the result arrives. If the database connection is via a TCP/IP socket, that could be handled by writing the query to the socket, and then when data comes back from the socket, looking up the callback and calling it. There's no additional thread here. > If I have understood correctly, then is there any benefit at all in my going > async? I might as well just stick with threads for the request handling as > well as the database handling. Threads are a convenient way to handle things, but they're an alternative. You generally do one or the other. Occasionally you'll use a bit of both, maybe because your database handler can't work asynchronously, but ideally you shouldn't need to mix and match like that. I'm oversimplifying horribly, here, but hopefully helpfully :) ChrisA From roy at panix.com Wed Apr 9 10:44:38 2014 From: roy at panix.com (Roy Smith) Date: Wed, 09 Apr 2014 10:44:38 -0400 Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: In article , Chris Angelico wrote: > For instance, the above code assumes that print() won't block. You > might think "Duh, how can printing to the screen block?!?", but if > your program's output is being piped into something else, it most > certainly can :) Heh. One day, a long time ago, I had to investigate why our Vax-11/750 had crashed. I vaguely recollect being called at home on a weekend and having to schlepp into work, but my memory may just be running in auto-story-embelishment mode. Turns out, the machine hadn't really crashed, but it was hung. The console was a LA-120 (http://tinyurl.com/mljyegv), on which was printed various log messages from time to time. It had run out of paper, which was detected by the little out-of-paper microswitch, so it stopped printing. When its input buffer got full, it sent a control-s, which tells the thing on the other end of the serial line to stop sending. Which of course caused the kernel tty driver output buffer to fill, which eventually caused all the print statements by the various system loggers to block, and eventually the whole mess ground to a halt. I put in new paper. The printer proceeded to spit out several hours worth of buffered log messages and the system picked up where it left off. At Songza, we've been using gevent to do asynchronous I/O. It's an interesting concept. Basically, you write your application code as you normally would, using blocking I/O calls. Gevent then monkey-patches the heck out of the Python library to intercept every call that could possibly block and splice it into a asynchronous task scheduler framework. The amazing thing is that it works. It let us reduce the number of gunicorn worker processes we use by a factor of 6, and handle the same amount of traffic. Of course, monkey-patching is black magic, and sometimes we get hit by really bizarre and difficult to track down bugs. But, to go back to my "technology evolution" scale, gevent is somewhere between avant-garde and what the kewl kids are using (version 1.0 was released in December), so that shouldn't be too surprising. From frank at chagford.com Wed Apr 9 10:46:50 2014 From: frank at chagford.com (Frank Millman) Date: Wed, 9 Apr 2014 16:46:50 +0200 Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> <87lhveobeq.fsf@elektro.pacujo.net> Message-ID: "Marko Rauhamaa" wrote in message news:87lhveobeq.fsf at elektro.pacujo.net... > "Frank Millman" : > >> I understand that, if one uses threading, each thread *can* block >> without affecting other threads, whereas if one uses the async >> approach, a request handler must *not* block, otherwise it will hold >> up the entire process and not allow other requests to be handled. > > Yes. > >> How does one distinguish betwen 'blocking' and 'non-blocking'? Is it >> either/or, or is it some arbitrary timeout - if a handler returns within >> that time it is non-blocking, but if it exceeds it it is blocking? > > Old-school I/O primitives are blocking by default. Nonblocking I/O is > enabled with the setblocking() method. > > In the new asyncio package, I/O is nonblocking by default (I'm sure, but > didn't verify). > >> In my environment, most requests involve a database lookup. I >> endeavour to ensure that a response is returned quickly (however one >> defines quickly) but I cannot guarantee it if the database server is >> under stress. Is this a good candidate for async, or not? > > Database libraries are notoriously bad for nonblocking I/O. It's nothing > fundamental; it's only that the library writers couldn't appreciate the > worth of async communication. For that, asyncio provides special > support: > > handle-blocking-functions-correctly> > Thanks for the reply, Marko. I did have a look at the link you provided, but at the moment my brain is 'blocking' on this, so I will need to read it a few times to get back into 'async' mode. As I asked Chris, (so you don't have to respond if he already has), I am finding difficulty in understanding the benefit of going async in my case. If most requests require a blocking handler, it seems that I might as well stick with each request being handled by a thread, independent of all other threads. Frank From roy at panix.com Wed Apr 9 10:52:43 2014 From: roy at panix.com (Roy Smith) Date: Wed, 09 Apr 2014 10:52:43 -0400 Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: In article , "Frank Millman" wrote: > "Chris Angelico" wrote in message > news:CAPTjJmqwhb8O8vq84mMTv+-Rkc3Ff1AQDXe5cs8Y5gY02kHyNg at mail.gmail.com... > > On Wed, Apr 9, 2014 at 11:23 PM, Frank Millman wrote: > > > >> How does one distinguish betwen 'blocking' and 'non-blocking'? Is it > >> either/or, or is it some arbitrary timeout - if a handler returns within > >> that time it is non-blocking, but if it exceeds it it is blocking? > > > > No; a blocking request is one that waits until it has a response, and > > a non-blocking request is one that goes off and does something, and > > then comes back to you when it's done. > > Does reading from disk count as blocking? Strictly speaking I would have > thought 'yes'. Of course it does. But, the bigger question is, "What counts as reading from disk?" In the old days, all Unix system calls were divided up into two groups, based on whether they were "fast" or "slow". Processes executing a "fast" system call would block, and could not be interrupted; i.e. any signals delivered to them would be queued up and delivered after the system call had finished. Typically, that meant, if you typed Control-C, your process wouldn't get killed until the system call it was executing completed. Disk reads were considered fast. You type Control-C, the read takes another few ms to finish, then your process gets whacked. You never even notice the delay. But, a read on a tty was slow. It would sit there forever, until you hit return. Slow system calls got interrupted. Then, along came the network, and everything got confusing. If I open a file that lives on an NFS server, and read from it, am I doing a disk read? Should I be able to interrupt an NFS operation? From sturla.molden at gmail.com Wed Apr 9 11:29:26 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Wed, 9 Apr 2014 15:29:26 +0000 (UTC) Subject: threading References: <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: <139834687418749240.077450sturla.molden-gmail.com@news.gmane.org> "Frank Millman" wrote: > If I have understood correctly, then is there any benefit at all in my going > async? I might as well just stick with threads for the request handling as > well as the database handling. 1. There is a scalability issue with threads, particularly if you don't have enough RAM or use a 32 bit system. 2. Earlier Linux kernels did not perform well if they had to schedule 10,000 threads. 3. It is nice to be able to abort a read or write that hangs (for whatever reason). Killing a thread with pthread_cancel or TerminateThread is not recommended. Sturla From alister.nospam.ware at ntlworld.com Wed Apr 9 11:43:33 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 09 Apr 2014 15:43:33 GMT Subject: "Latching" variables in function References: Message-ID: On Wed, 09 Apr 2014 08:53:19 -0500, Mark H Harris wrote: > On 4/8/14 3:09 PM, Grawburg wrote: > >> I have a N/O pushbutton that I want to "latch" a value to a variable >> when it's been pressed. >> I need button_value to become '1' when the button is pressed and to >> remain '1' until ... > >> What do I use to 'latch' button_value? > > Philosophically speaking buttons don't latch. You push the button, an > event is generated, and the call-back handles the event to do something > in your project. > > You might try setting a global variable on the button-push event. > > Or, if I understand you, you might want to use a configurable, like a > radio button or a check box, either of which are designed to be > "latched". > > > marcus How familiar are you with oop? a class would sort this quite nicely Class Button(object) def __init__(self,bit): self.pressed=False: self.bit=bit def check_button(self): if bus.read_byte_data(bit): self.pressed=True button=Button(address.GPIOB) while not button.pressed: button.check button() once button.pressed has been set True it will remain True until you reset it with button.pressed=False + with a bit of tweaking you should be able to create multiple button objects for each switch you connect *note this code has been typed direct & not tested so may contain minor errors. -- Imbalance of power corrupts and monopoly of power corrupts absolutely. -- Genji From rantingrickjohnson at gmail.com Wed Apr 9 11:51:09 2014 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 9 Apr 2014 08:51:09 -0700 (PDT) Subject: threading In-Reply-To: References: <4a24f218-158a-4a21-af36-5cc69ce1f7e1@googlegroups.com> Message-ID: On Wednesday, April 9, 2014 8:50:59 AM UTC-5, Neil D. Cerutti wrote: > [...] > Plus Rufus Xavier Sasparilla disagrees with it. If you think you're going to argue in such an implicit manner as to the benefits of pronouns, then you should expect that an astute logician such as myself will tear you to shreds. ############################################################ # WARNING: # ############################################################ # You cannot wave shiny objects in front of MY eyes and # # expect me to fold like a lawn-chair! # ############################################################ And whist i admit your snarky comment is founded on a *superficial* fact that cannot be denied,(that is: the fact that pronouns remove superfluous repetition from communications), most people will be so distracted by the initial emotional response of laughter, that they will lose their logical focus and fortitude, and forget to confirm the validity of your assertion. Your comment is a fine example of why people like Bill Mahr, Steve Colbert, and , uh, that other guy??? can pacify otherwise intelligent people via comedy whist their civil liberties are robbed from them and justice is ignored. Does "fiddling" and "Rome" ring a bell people? ############################################################ # Summary: # ############################################################ # You comment is cleaver propaganda, but (as we shall all # # learn soon) in no way shape or form is your assertion # # *logical* or *resilient* to interrogations. # ############################################################ Now, before i utterly destroy you, we must first *ALL* take a lesson in linguistics. ############################################################ # Define Noun: # ############################################################ # a word (other than a pronoun) used to identify any of a # # class of people, places, or things # ############################################################ ############################################################ # Define "Pronoun": # ############################################################ # In linguistics and grammar, a pronoun is a word or form # # that substitutes for a noun or noun phrase. # ############################################################ Pronouns are simply shorthands versions of nouns. We use them to reduce the amount of atomic repetition in our speech and writing, at that's a good thing! No one wants to inject superfluous repetition into their prose. This, is the very argument that my good friend "Mr. Cerutti" is presenting with his *esoteric* reference to "Rufus Xavier Sasparilla" -- of whom I will refer to from now on as "Mr.RXS" Whist i agree with my opponent and "MR.RXS" on this one tiny aspect of pronouns, we must dig deeper to understand why "Mr. Cerutti's" argument is invalid to the subject matter for which he is replying. The only way Mr Cerutti's comment could be valid is if i argued that *ALL* pronouns are evil, and that is NOT my argument. MY ARGUMENT IS HIGHLY SPECIFIC! ############################################################ # Inquisitive Joe asks: # ############################################################ # "But why do you single out "it" for excommunication # # Rick? What is so bad about "it"?" # ############################################################ My argument is simply that the pronoun "it", is a superfluously implicit use of pronouns! Since "it" can refer to either a "person", a "place" or even a "thing", it therefor injects too much ambiguity EVEN when "properly"[1] used. But not only is the ambiguity of the "it" pronoun an unfortunate ubiquity, the manner in which the pronoun "it" is referenced will many times manifest itself in confusing manners. Observe the following three sentences which use "it" in illogically ascending orders of incomprehensibility: 1. I ate a burger, and it was good. The first example is not terribly difficult to grok since the noun "burger" is defined before the pronoun "it" is declared and then logically bound to "burger". 2. It was a good day today. In the second example we have the "it" at the very beginning of the sentence, therefore, i must not only read and comprehend the remainder of the sentence, but, i must also remember that i need to find the antecedent of the initial unbound pronoun "it". 3. It irks me that language designers pay no attention to consistency. And the evil incarnation of the IMPLICIT PRONOUN raises it's ugly head!!! Again we have the pronoun "it" declared as the very first word of the sentence, however, the referent is missing, and instead must be intuited! But the fun does not stop there people, NO-NO-NO, after you go to all the work required to intuit the referent, you then immediately realize that the referent is *SUPERFLUOUS* and needs garbage collection! What sort of sick joke is this? Heck, we have not even considered the emotional states that must be mustered to empathize with the authors' intent!!! This last example is the height of illogical and superfluous prose, and a fine example of the slippery slope that is common to the "it" pronoun. ============================================================ REFERENCES: ============================================================ [1]: I use the term "properly" loosely here, actually more like sarcastically! From tjreedy at udel.edu Wed Apr 9 12:14:15 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 09 Apr 2014 12:14:15 -0400 Subject: threading In-Reply-To: References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: On 4/9/2014 10:30 AM, Frank Millman wrote: > In other words, non-blocking implies that everything required to pass off > the request to a handler and be ready to deal with the next one must already > be in memory, and it must not rely on communicating with any outside > resource at all. Is this correct? Chris said no, I would have said yes, but I think we understand the above differently. The important point is that there are two goals. The first is to avoid having the cpu sitting idle when there is work to be done. Switching processes, switching threads within a process, and switching tasks within a thread are all aimed at this. (So are compiler code rearrangements that aim to keep various parts of a cpu, such integer and float arithmetic units, active simultaneously.) The second, usually, is to keep the system responsive by not letting any particular work unit hog the cpu. But note that is work units are made too small, cpu time is wasted in excessive switching overhead. A handler should neither waste nor monopolize cpu time. If input data is needed for a long computation, the handler should store the data where it needs to be for the computation but leave the actual computation to a background or idle task that runs when there is nothing else to do. -- Terry Jan Reedy From laguna-mc at mail.com Wed Apr 9 12:06:40 2014 From: laguna-mc at mail.com (trewio) Date: Wed, 09 Apr 2014 12:06:40 -0400 Subject: Unpacking U-Boot image file Message-ID: <20140409160640.50200@gmx.com> How to extract files from U-Boot image file, LZMA-compressed? Is there a Python script that can do this properly? From rosuav at gmail.com Wed Apr 9 12:25:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Apr 2014 02:25:43 +1000 Subject: threading In-Reply-To: References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: On Thu, Apr 10, 2014 at 2:14 AM, Terry Reedy wrote: > On 4/9/2014 10:30 AM, Frank Millman wrote: > >> In other words, non-blocking implies that everything required to pass off >> the request to a handler and be ready to deal with the next one must >> already >> be in memory, and it must not rely on communicating with any outside >> resource at all. Is this correct? > > > Chris said no, I would have said yes, but I think we understand the above > differently. I said no because I see asynchronous I/O as a perfectly viable structure for a program, which means that a non-blocking handler is allowed to communicate with outside resources. Conversely, if you see "a non-blocking handler" as meaning the one small piece that runs uninterruptibly, then you might say that yes, it must not rely on any outside resource. Of course, it depends on where you're looking. Memory is itself an outside resource that can potentially take a long time to give a result - just look at what happens when you dip into swap space, and RAM accesses become disk accesses. But generally, you go asynchronous in order to increase your throughput; and if you're churning through your page file, well, that's going to kill throughput whichever way you look at it. It's generally safe enough to pretend that RAM can be accessed in-line, and worry about the slowdowns elsewhere. ChrisA From sturla.molden at gmail.com Wed Apr 9 12:32:53 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Wed, 9 Apr 2014 16:32:53 +0000 (UTC) Subject: threading References: <877g70wg8p.fsf@elektro.pacujo.net> <139834687418749240.077450sturla.molden-gmail.com@news.gmane.org> Message-ID: <1707088050418753776.873926sturla.molden-gmail.com@news.gmane.org> Sturla Molden wrote: > 3. It is nice to be able to abort a read or write that hangs (for whatever > reason). Killing a thread with pthread_cancel or TerminateThread is not > recommended. While "graceful timeout" is easy to do on Unix, using fcntl.fcntl or signal.alarm, on Windows it requires overlapped I/O. This means the normal Python file objects cannot be used for this purpose on Windows. Sturla From marko at pacujo.net Wed Apr 9 12:48:18 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 09 Apr 2014 19:48:18 +0300 Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: <87ob0ala99.fsf@elektro.pacujo.net> "Frank Millman" : > Does reading from disk count as blocking? Strictly speaking I would > have thought 'yes'. You have touched upon a very interesting topic there. I can't speak for Windows, but linux doesn't really let you control the blocking of disk access. In fact, linux doesn't really let you control the blocking of RAM access, either. RAM and the disk are considered two sides of the same coin. It is very difficult to guarantee that a process has all of its memory "cached" in RAM short of not having a physical disk mounted. There is what's known as AIO, and it's supposedly supported in linux, but I have never seen anybody use it, and I don't know how well tested it is. Also, I don't know how well it integrates with regular asyncio. On the other hand, you don't know if disk access ever blocks. Quite often you will find that the whole active part of the file system is kept in RAM by linux. My rule of thumb, two processes per CPU, should alleviate disk blocking issues. When that isn't enough, you may be forced to write a small file server that translates disk access to socket/pipe access. Sockets and pipes are different beasts because, unlike files, they are allocated memory buffers in the kernel memory. Also, they are accessed strictly sequentially while files can be sought back and forth. I do think it would be a nice addition to linux if they added a, say, AF_FILE socket type that provided a buffered socket abstraction for physical files. Marko From rustompmody at gmail.com Wed Apr 9 13:18:56 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 9 Apr 2014 10:18:56 -0700 (PDT) Subject: Unpacking U-Boot image file In-Reply-To: References: Message-ID: <6ed343e7-fa02-426a-a75f-3e1d164a6a61@googlegroups.com> On Wednesday, April 9, 2014 9:36:40 PM UTC+5:30, trewio wrote: > How to extract files from U-Boot image file, LZMA-compressed? > > Is there a Python script that can do this properly? For lzma theres this (recent) python library https://docs.python.org/dev/library/lzma.html Though you might just be better off with the command-line xz unxz etc After that.. whats the U-boot format? From sadzak at gmail.com Wed Apr 9 13:33:20 2014 From: sadzak at gmail.com (Adnan Sadzak) Date: Wed, 9 Apr 2014 19:33:20 +0200 Subject: Unpacking U-Boot image file In-Reply-To: <6ed343e7-fa02-426a-a75f-3e1d164a6a61@googlegroups.com> References: <6ed343e7-fa02-426a-a75f-3e1d164a6a61@googlegroups.com> Message-ID: I belive you are trying to decompress some router images or router backup/config files? Check if maybe LZS. Rustom gave You starting point. On Wed, Apr 9, 2014 at 7:18 PM, Rustom Mody wrote: > On Wednesday, April 9, 2014 9:36:40 PM UTC+5:30, trewio wrote: > > How to extract files from U-Boot image file, LZMA-compressed? > > > > Is there a Python script that can do this properly? > > For lzma theres this (recent) python library > https://docs.python.org/dev/library/lzma.html > > Though you might just be better off with the command-line xz unxz etc > > After that.. whats the U-boot format? > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From marko at pacujo.net Wed Apr 9 13:31:36 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 09 Apr 2014 20:31:36 +0300 Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> <87lhveobeq.fsf@elektro.pacujo.net> Message-ID: <87k3ayl893.fsf@elektro.pacujo.net> "Frank Millman" : > I am finding difficulty in understanding the benefit of going async in > my case. If most requests require a blocking handler, it seems that I > might as well stick with each request being handled by a thread, > independent of all other threads. When the underlying facilities only provide blocking access, you are forced to use threads (or processes). One area where asynchronous programming was always the method of choice is graphical user interfaces. The GUI of an application must always be responsive to the user and must be prepared to handle any of numerous stimuli. Network protocol layers are also usually implemented asynchronously. The protocol standards read like asynchronous programs so the translation into executable programs is most natural in the asynchronous style. Here, too, the networking entities must be ready for different stimuli in any state, so threads are usually not a good fit. Kernel programming makes use of threads and processes. However, the asynchronous style is there in a big way in the form of interrupt handlers, hooks and system calls. Really, the threading model is only good for a relatively small subset of programming objectives, and over the lifetime of the solution, you will often come to realize threading wasn't that good a fit after all. Namely, in any given state, you will have to be prepared to handle more than one stimulus. Also, over time you will learn to dread the race conditions that are endemic in thread programming. Those are the kinds of problems that make you check out the current job postings. Only there's no escape: in your next job, they are going to make you find and fix the race conditions in your predecessor's code. Marko From python at mrabarnett.plus.com Wed Apr 9 13:47:50 2014 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 09 Apr 2014 18:47:50 +0100 Subject: threading In-Reply-To: References: <4a24f218-158a-4a21-af36-5cc69ce1f7e1@googlegroups.com> Message-ID: <534587C6.5030404@mrabarnett.plus.com> On 2014-04-09 16:51, Rick Johnson wrote: [snip] > > 3. It irks me that language designers pay no attention > to consistency. > > And the evil incarnation of the IMPLICIT PRONOUN raises > it's ugly head!!! > The pronoun isn't implicit, because it's actually present! (And it's "its ugly head", BTW.) > Again we have the pronoun "it" declared as the very first > word of the sentence, however, the referent is missing, and > instead must be intuited! But the fun does not stop there > people, NO-NO-NO, after you go to all the work required to > intuit the referent, you then immediately realize that the > referent is *SUPERFLUOUS* and needs garbage collection! What > sort of sick joke is this? Heck, we have not even considered > the emotional states that must be mustered to empathize > with the authors' intent!!! > The referent isn't missing. The "it" refers to the postcedent clause "that language designers..." that's the subject of the verb "irks". (A postcedent is like an antecendent, except that it refers forwards to something that follows instead of backwards to something that preceded.) From rosuav at gmail.com Wed Apr 9 13:52:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Apr 2014 03:52:10 +1000 Subject: threading In-Reply-To: <87k3ayl893.fsf@elektro.pacujo.net> References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> <87lhveobeq.fsf@elektro.pacujo.net> <87k3ayl893.fsf@elektro.pacujo.net> Message-ID: On Thu, Apr 10, 2014 at 3:31 AM, Marko Rauhamaa wrote: > Really, the threading model is only good for a relatively small subset > of programming objectives, and over the lifetime of the solution, you > will often come to realize threading wasn't that good a fit after all. > Namely, in any given state, you will have to be prepared to handle more > than one stimulus. Also, over time you will learn to dread the race > conditions that are endemic in thread programming. Those are the kinds > of problems that make you check out the current job postings. Only > there's no escape: in your next job, they are going to make you find and > fix the race conditions in your predecessor's code. People with a fear of threaded programming almost certainly never grew up on OS/2. :) I learned about GUI programming thus: Write your synchronous message handler to guarantee that it will return in an absolute maximum of 0.1s, preferably a lot less. If you have any sort of heavy processing to do, spin off a thread. It was simply the normal way to do things. Normal handling was done on Thread 0, and two sequential events would be processed sequentially on that thread (so if your handler for the Enter keypress message clears out an entry field, the next key pressed is guaranteed to happen on an empty field), and everything else, it's considered normal to spawn threads and let them run to completion. ChrisA From rosuav at gmail.com Wed Apr 9 14:00:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Apr 2014 04:00:46 +1000 Subject: threading In-Reply-To: <534587C6.5030404@mrabarnett.plus.com> References: <4a24f218-158a-4a21-af36-5cc69ce1f7e1@googlegroups.com> <534587C6.5030404@mrabarnett.plus.com> Message-ID: On Thu, Apr 10, 2014 at 3:47 AM, MRAB wrote: > On 2014-04-09 16:51, Rick Johnson wrote: >> And the evil incarnation of the IMPLICIT PRONOUN raises >> it's ugly head!!! >> > (And it's "its ugly head", BTW.) Fundamental rule of the internet: If you criticize someone else's spelling or grammar, you will make a blooper yourself, usually of paper-bag proportions. ChrisA From sturla.molden at gmail.com Wed Apr 9 15:20:22 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Wed, 9 Apr 2014 19:20:22 +0000 (UTC) Subject: threading References: <87k3ayl893.fsf@elektro.pacujo.net> Message-ID: <730473318418763802.451610sturla.molden-gmail.com@news.gmane.org> Chris Angelico wrote: > People with a fear of threaded programming almost certainly never grew > up on OS/2. :) I learned about GUI programming thus: Write your > synchronous message handler to guarantee that it will return in an > absolute maximum of 0.1s, preferably a lot less. If you have any sort > of heavy processing to do, spin off a thread. It was simply the normal > way to do things. That is still the best way to do it, IMHO. As I recall, on BeOS the operating system would even spawn a new thread to handle each GUI event. Pervasive multithreading is great for creating responsive user interfaces and running multimedia. Sturla From laguna-mc at mail.com Wed Apr 9 13:53:23 2014 From: laguna-mc at mail.com (trewio) Date: Wed, 09 Apr 2014 13:53:23 -0400 Subject: Unpacking U-Boot image file Message-ID: <20140409175323.50160@gmx.com> U-Boot format: hmm, I'm not sure, can someone specify Python script that will help me deterermine U-boot format used? [for Python for Windows OS] Note: I need Python script for Python under Windows OS. > ----- Original Message ----- > From: Rustom Mody > Sent: 04/09/14 08:18 PM > To: python-list at python.org > Subject: Re: Unpacking U-Boot image file > > On Wednesday, April 9, 2014 9:36:40 PM UTC+5:30, trewio wrote: > > How to extract files from U-Boot image file, LZMA-compressed? > > > > Is there a Python script that can do this properly? > > For lzma theres this (recent) python library > https://docs.python.org/dev/library/lzma.html > > Though you might just be better off with the command-line xz unxz etc > > After that.. whats the U-boot format? > -- > https://mail.python.org/mailman/listinfo/python-list From laguna-mc at mail.com Wed Apr 9 13:59:37 2014 From: laguna-mc at mail.com (trewio) Date: Wed, 09 Apr 2014 13:59:37 -0400 Subject: Unpacking U-Boot image file Message-ID: <20140409175937.50160@gmx.com> I need decompress image(modem), and I deciced use some Python script or utility which capable run on Python for Windows OS. > ----- Original Message ----- > From: Adnan Sadzak > Sent: 04/09/14 08:33 PM > To: python-list > Subject: Re: Unpacking U-Boot image file > > I belive you are trying to decompress some router images or router > backup/config files? > Check if maybe LZS. > > Rustom gave You starting point. > > > > On Wed, Apr 9, 2014 at 7:18 PM, Rustom Mody wrote: > > > On Wednesday, April 9, 2014 9:36:40 PM UTC+5:30, trewio wrote: > > > How to extract files from U-Boot image file, LZMA-compressed? > > > > > > Is there a Python script that can do this properly? > > > > For lzma theres this (recent) python library > > https://docs.python.org/dev/library/lzma.html > > > > Though you might just be better off with the command-line xz unxz etc > > > > After that.. whats the U-boot format? > > -- > > https://mail.python.org/mailman/listinfo/python-list > > From rohan_1925 at yahoo.co.in Wed Apr 9 15:23:03 2014 From: rohan_1925 at yahoo.co.in (rohan bareja) Date: Thu, 10 Apr 2014 03:23:03 +0800 (SGT) Subject: CommandLine Option in Python for filtering values from Column Message-ID: <1397071383.35192.YahooMailNeo@web193506.mail.sg3.yahoo.com> I want to write a function in Python for a tab delimited file I am dealing with,to filter out values from a column, and put that parameter as a command line option while running the script. So,if the limit is 10,the filter out all the rows with values less than 10. Also,I want to check if the number entered is numeric or not else display the message "its not numeric". So,the command line would be: ? ? python script.py file --quality [limit] ? ?? ? The Python script: ? ? import sys ? ? arg = [] ? ? ? ? for a in sys.argv: ? ?arg.append(a)? ? ? ? ? ? ? quality = arg[2] To be more specific,the file I am dealing with is a Samfile,and using package? Pysam,which has mapping quality limits in the 5th column. https://media.readthedocs.org/pdf/pysam/latest/pysam.pdf Commandline: ? ? ? python script.py samfile --quality [limit] ?I am reading the samfile using this: ? ? ?samfile = pysam.Samfile(arg[1], "rb" ) ? ? ?mapqlim = arg[2] I am a Python beginner,but saw one of the modules,argparse. How can I accomplish this using argparse in Python? -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Wed Apr 9 16:12:04 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 9 Apr 2014 20:12:04 +0000 (UTC) Subject: imaplib: how to specify SSL/TLS protocol version? Message-ID: Connecting to Exchange server fails like this: File "/usr/lib64/python2.7/imaplib.py", line 1148, in __init__ IMAP4.__init__(self, host, port) SSLError: [Errno 1] _ssl.c:1419: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number Experiments show that when calling ssl.wrap_socket() I have to specify ssl_version=PROTOCOL_TLSv1 to avoid the above error. How do I tell imaplib to use TLS1 instead of SSL3? -- Grant Edwards grant.b.edwards Yow! UH-OH!! We're out at of AUTOMOBILE PARTS and gmail.com RUBBER GOODS! From invalid at invalid.invalid Wed Apr 9 16:20:15 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 9 Apr 2014 20:20:15 +0000 (UTC) Subject: imaplib: how to specify SSL/TLS protocol version? References: Message-ID: On 2014-04-09, Grant Edwards wrote: > Connecting to Exchange server fails like this: > > File "/usr/lib64/python2.7/imaplib.py", line 1148, in __init__ > IMAP4.__init__(self, host, port) > SSLError: [Errno 1] _ssl.c:1419: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number > > Experiments show that when calling ssl.wrap_socket() I have to specify > ssl_version=PROTOCOL_TLSv1 to avoid the above error. > > How do I tell imaplib to use TLS1 instead of SSL3? I'm not too keen on this approach, but monkey-patching the open() method seems to work: def my_imap4_ssl_open(self, host = '', port = 993): self.host = host self.port = port self.sock = socket.create_connection((host, port)) self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile, ssl_version=ssl.PROTOCOL_TLSv1) self.file = self.sslobj.makefile('rb') imaplib.IMAP4_SSL.open = my_imap4_ssl_open -- Grant Edwards grant.b.edwards Yow! I hope the at ``Eurythmics'' practice gmail.com birth control ... From john_ladasky at sbcglobal.net Wed Apr 9 16:24:32 2014 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Wed, 9 Apr 2014 13:24:32 -0700 (PDT) Subject: Method(s) called by square brackets, slice objects Message-ID: <74d6fb5c-baca-4606-9fa8-66238a561e0c@googlegroups.com> I would like to build a multi-dimensional array that allows numpy-style indexing and, ideally, uses Python's familiar square-bracket and slice notations. For example, if I declare a two-dimensional array object, x, then x[4,7] retrieves the element located at the 4th row and the 7th column. If I ask for x[3:6,1:3], I get a 3 x 2 array object consisting of the intersection of the 3rd-5th rows, and the 1st-2nd columns, of x. In this case I'm not allowed to use numpy, I have to restrict myself to the standard library. I thought that I might achieve the desired behavior by defining an object with specific __getitem__ and/or __getslice__ methods. However, the documentation of these methods that I am reading suggests that the arguments are pre-parsed into certain formats which may not allow me to do things numpy's way. Is this true? From python.list at tim.thechases.com Wed Apr 9 16:26:22 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 9 Apr 2014 15:26:22 -0500 Subject: imaplib: how to specify SSL/TLS protocol version? In-Reply-To: References: Message-ID: <20140409152622.4008a01a@bigbox.christie.dr> On 2014-04-09 20:12, Grant Edwards wrote: > File "/usr/lib64/python2.7/imaplib.py", line 1148, in __init__ > IMAP4.__init__(self, host, port) > SSLError: [Errno 1] _ssl.c:1419: error:1408F10B:SSL > routines:SSL3_GET_RECORD:wrong version number > > Experiments show that when calling ssl.wrap_socket() I have to > specify ssl_version=PROTOCOL_TLSv1 to avoid the above error. > > How do I tell imaplib to use TLS1 instead of SSL3? Sounds like you'd need to make a subclass, something like class IMAP4_TLS(imaplib.IMAP4_SSL): def open(self, host="", port=IMAP4_SSL_PORT): self.host = host self.port = port self.sock = socket.create_connection((host, port)) self.sslobj = ssl.wrap_socket( self.sock, self.keyfile, self.certfile, ssl_version=PROTOCOL_TLSv1, ) self.file = self.sslobj.makefile('rb') Alternatively, you could genericify it something like class IMAP4_TLS(imaplib.IMAP4_SSL): def open(self, host="", port=IMAP4_SSL_PORT, ssl_version=PROTOCOL_SSLv23, ): self.host = host self.port = port self.sock = socket.create_connection((host, port)) self.sslobj = ssl.wrap_socket( self.sock, self.keyfile, self.certfile, ssl_version=ssl_version, ) self.file = self.sslobj.makefile('rb') and then call .open(..., ssl_version=PROTOCOL_TLSv1) or specify any other protocol that you need. -tkc From python.list at tim.thechases.com Wed Apr 9 16:33:11 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 9 Apr 2014 15:33:11 -0500 Subject: imaplib: how to specify SSL/TLS protocol version? In-Reply-To: References: Message-ID: <20140409153311.1d2d5353@bigbox.christie.dr> On 2014-04-09 20:20, Grant Edwards wrote: > I'm not too keen on this approach, but monkey-patching the open() > method seems to work: > > def my_imap4_ssl_open(self, host = '', port = 993): > self.host = host > self.port = port > self.sock = socket.create_connection((host, port)) > self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, > self.certfile, ssl_version=ssl.PROTOCOL_TLSv1) self.file = > self.sslobj.makefile('rb') > > imaplib.IMAP4_SSL.open = my_imap4_ssl_open Our messages passed in the ether. You don't have to feel dirty for monkey-patching, as you can just do it with inheritance. -tkc From ethan at stoneleaf.us Wed Apr 9 16:34:06 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 09 Apr 2014 13:34:06 -0700 Subject: Method(s) called by square brackets, slice objects In-Reply-To: <74d6fb5c-baca-4606-9fa8-66238a561e0c@googlegroups.com> References: <74d6fb5c-baca-4606-9fa8-66238a561e0c@googlegroups.com> Message-ID: <5345AEBE.1010904@stoneleaf.us> On 04/09/2014 01:24 PM, John Ladasky wrote: > > I would like to build a multi-dimensional array that allows numpy-style > indexing and, ideally, uses Python's familiar square-bracket and slice > notations. > > For example, if I declare a two-dimensional array object, x, then x[4,7] > retrieves the element located at the 4th row and the 7th column. If I > ask for x[3:6,1:3], I get a 3 x 2 array object consisting of the inter- >section of the 3rd-5th rows, and the 1st-2nd columns, of x. > > In this case I'm not allowed to use numpy, I have to restrict myself to > the standard library. I thought that I might achieve the desired behavior > by defining an object with specific __getitem__ and/or __getslice__ methods. > However, the documentation of these methods that I am reading suggests that > the arguments are pre-parsed into certain formats which may not allow me to > do things numpy's way. Is this true? Nope. Whatever you put between the square brackets is what gets passed into __getitem__; the only caveat is that anything with : will be turned into a slice: Python 2.7.3 (default, Sep 26 2012, 21:51:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. --> class GetIndex(object): ... def __getitem__(self, thing): ... print thing ... return None ... --> test = GetIndex() --> test[1] 1 --> test [1,2] (1, 2) --> test[1:3, 4:5] (slice(1, 3, None), slice(4, 5, None)) --> test[range(3)] [0, 1, 2] -- ~Ethan~ From invalid at invalid.invalid Wed Apr 9 16:55:49 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 9 Apr 2014 20:55:49 +0000 (UTC) Subject: imaplib: how to specify SSL/TLS protocol version? References: Message-ID: On 2014-04-09, Tim Chase wrote: > On 2014-04-09 20:20, Grant Edwards wrote: >> I'm not too keen on this approach, but monkey-patching the open() >> method seems to work: >> >> def my_imap4_ssl_open(self, host = '', port = 993): >> self.host = host >> self.port = port >> self.sock = socket.create_connection((host, port)) >> self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, >> self.certfile, ssl_version=ssl.PROTOCOL_TLSv1) self.file = >> self.sslobj.makefile('rb') >> >> imaplib.IMAP4_SSL.open = my_imap4_ssl_open > > Our messages passed in the ether. Yep saw that. Thanks for the answers. > You don't have to feel dirty for monkey-patching, as you can just do > it with inheritance. Doh. I don't know why I didn't think of that... -- Grant Edwards grant.b.edwards Yow! I wonder if there's at anything GOOD on tonight? gmail.com From laguna-mc at mail.com Wed Apr 9 16:49:36 2014 From: laguna-mc at mail.com (laguna-mc at mail.com) Date: Wed, 09 Apr 2014 16:49:36 -0400 Subject: Unpacking U-Boot image file Message-ID: <20140409204936.50160@gmx.com> I know about Binwalk, it can run on Linux OS only. I am looking for Python script that can run on Windows too. Thank you. ----- Original Message ----- From: Adnan Sadzak Sent: 04/09/14 11:37 PM To: trewio Subject: Re: Unpacking U-Boot image file Oh then see Craig's page [0]. You can find in deepth explanation about some tools (Linux) that is used to desompress and mount filesystems/images. From my experience you should find first read modem tehnical documentation. Find out what kind of firmware is using. You won't find just script to decompress those images. [0] http://www.devttys0.com/2011/05/reverse-engineering-firmware-linksys-wag120n/ Cheers On Wed, Apr 9, 2014 at 7:53 PM, trewio < laguna-mc at mail.com > wrote:U-Boot format: hmm, I'm not sure, can someone specify Python script that will help me deterermine U-boot format used? [for Python for Windows OS] Note: I need Python script for Python under Windows OS. > ----- Original Message ----- > From: Rustom Mody > Sent: 04/09/14 08:18 PM > To: python-list at python.org > Subject: Re: Unpacking U-Boot image file > > On Wednesday, April 9, 2014 9:36:40 PM UTC+5:30, trewio wrote: > > How to extract files from U-Boot image file, LZMA-compressed? > > > > Is there a Python script that can do this properly? > > For lzma theres this (recent) python library > https://docs.python.org/dev/library/lzma.html > > Though you might just be better off with the command-line xz unxz etc > > After that.. whats the U-boot format? > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Wed Apr 9 17:10:10 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 9 Apr 2014 21:10:10 +0000 (UTC) Subject: imaplib: how to specify SSL/TLS protocol version? References: Message-ID: On 2014-04-09, Grant Edwards wrote: > On 2014-04-09, Tim Chase wrote: >> On 2014-04-09 20:20, Grant Edwards wrote: >>> I'm not too keen on this approach, but monkey-patching the open() >>> method seems to work: >>> >>> def my_imap4_ssl_open(self, host = '', port = 993): >>> self.host = host >>> self.port = port >>> self.sock = socket.create_connection((host, port)) >>> self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, >>> self.certfile, ssl_version=ssl.PROTOCOL_TLSv1) self.file = >>> self.sslobj.makefile('rb') >>> >>> imaplib.IMAP4_SSL.open = my_imap4_ssl_open >> >> Our messages passed in the ether. > > Yep saw that. Thanks for the answers. > >> You don't have to feel dirty for monkey-patching, as you can just do >> it with inheritance. > > Doh. I don't know why I didn't think of that... Now I remember... I left out a relevent fact: I'm not the one calling IMAP4_. That's being done by the imapclient library. There's no way to pass imapclient a custom class to use. It's hard-waired to call either imaplib.IMAP4_stream(), imaplib.IMAP4(), or imaplib.IMAP4_SSL(). I could create an IMAP4_TLS1 class, but I would then have to sub-class imapclient.IMAPClient and override its _create_IMAP4() method to make it call my IMAP4_TLS1() class instead of calling imaplib.IMAP4_SSL(). Monkey-patching imaplib seems a little better since it it doesn't depend on assumptions about the internal workings of imapclient (other than the fact that it uses imaplib.IMAP4_SSL). -- Grant Edwards grant.b.edwards Yow! MMM-MM!! So THIS is at BIO-NEBULATION! gmail.com From cbc at unc.edu Wed Apr 9 17:53:38 2014 From: cbc at unc.edu (Chris Calloway) Date: Wed, 09 Apr 2014 17:53:38 -0400 Subject: 2014 PyCamps Message-ID: <5345C162.10701@unc.edu> PyCamp is an ultra-low-cost, five-day, intensive Python boot camp program by a user group for user groups. PyCamp has taught Python fundamentals to thousands of beginners for nine years while sponsoring Python regional conferences, symposia, sprints, scholarships, and user groups. You can get up to speed on the most modern programming language at PyCamp. This year choose from two PyCamps: Wisconsin PyCamp 2014, June 13-17, University of Wisconsin-Oshkosh http://tripython.org/wiscpy14 Wisconsin PyCamp 2014 is a training program of Plone Symposium Midwest. http://midwest.plonesymp.org Wisconsin PyCamp 2014 is all-day catered (breakfast, lunch, snacks). or PyOhio PyCamp 2014, July 21-25, The Ohio State University http://tripython.org/pyohio14 PyOhio PyCamp 2014 is a pre-conference training program of PyOhio http://pyohio.org Scholarships for women and minorities are available for PyOhio PyCamp -- Sincerely, Chris Calloway http://nccoos.org/Members/cbc office: 3313 Venable Hall phone: (919) 599-3530 mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599 From greg.ewing at canterbury.ac.nz Wed Apr 9 19:19:45 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 10 Apr 2014 11:19:45 +1200 Subject: threading In-Reply-To: References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: Roy Smith wrote: > In the old days, all Unix system calls were divided up into two groups, > based on whether they were "fast" or "slow". Processes executing a > "fast" system call would block, and could not be interrupted; That doesn't really have anything to do with blocking vs. non-blocking, though. The system call blocks in both cases; the only difference is whether the kernel bothers to allow for aborting the blocked operation part way through. The calling process doesn't see any difference. -- Greg From greg.ewing at canterbury.ac.nz Wed Apr 9 19:35:05 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 10 Apr 2014 11:35:05 +1200 Subject: threading In-Reply-To: References: <4a24f218-158a-4a21-af36-5cc69ce1f7e1@googlegroups.com> Message-ID: > On 2014-04-09 16:51, Rick Johnson wrote: >> Again we have the pronoun "it" declared as the very first >> word of the sentence, however, the referent is missing, and >> instead must be intuited! Pronoun referents *always* need to be intuited. There are no mechanical rules for finding the referent of a pronoun in an English sentence; you have to figure it out from what makes the most sense given the context. > (A > postcedent is like an antecendent, except that it refers forwards to > something that follows instead of backwards to something that preceded.) Then there are even weirder cases, such as "It is raining today", where the referent ("the weather" in this case) is never explicitly mentioned at all! -- Greg From roy at panix.com Wed Apr 9 19:53:26 2014 From: roy at panix.com (Roy Smith) Date: Wed, 09 Apr 2014 19:53:26 -0400 Subject: threading References: <4a24f218-158a-4a21-af36-5cc69ce1f7e1@googlegroups.com> Message-ID: In article , Gregory Ewing wrote: > > On 2014-04-09 16:51, Rick Johnson wrote: > >> Again we have the pronoun "it" declared as the very first > >> word of the sentence, however, the referent is missing, and > >> instead must be intuited! > > Pronoun referents *always* need to be intuited. There are > no mechanical rules for finding the referent of a pronoun > in an English sentence; you have to figure it out from what > makes the most sense given the context. > > > (A > > postcedent is like an antecendent, except that it refers forwards to > > something that follows instead of backwards to something that preceded.) > > Then there are even weirder cases, such as "It is raining > today", where the referent ("the weather" in this case) is > never explicitly mentioned at all! It's even more ambiguous in Spanish. Esta lloviendo. Not only do you get to intuit the referrent, you get to intuit the pronoun too :-) Natural language is a wonderfully expressive thing. I open the window, stick my head out, look up at the sky, and say, "Raining". Forget the pronoun, I don't even have a verb. And yet everybody understands exactly what I mean. From robotsondrugs at gmail.com Wed Apr 9 20:02:42 2014 From: robotsondrugs at gmail.com (Andrew Berg) Date: Wed, 09 Apr 2014 19:02:42 -0500 Subject: threading In-Reply-To: References: <4a24f218-158a-4a21-af36-5cc69ce1f7e1@googlegroups.com> Message-ID: <5345DFA2.3060608@gmail.com> On 2014.04.09 18:53, Roy Smith wrote: > It's even more ambiguous in Spanish. Esta lloviendo. Not only do you > get to intuit the referrent, you get to intuit the pronoun too :-) And in this particular instance, you have to figure out that 'est?' (verb) was meant instead of 'esta' (adjective). :) -- CPython 3.4.0 | Windows NT 6.2.9200 / FreeBSD 10.0 From davea at davea.name Wed Apr 9 20:42:33 2014 From: davea at davea.name (Dave Angel) Date: Wed, 9 Apr 2014 20:42:33 -0400 (EDT) Subject: Unpacking U-Boot image file References: <20140409160640.50200@gmx.com> Message-ID: "trewio" Wrote in message: > How to extract files from U-Boot image file, LZMA-compressed? > > Is there a Python script that can do this properly? > Use the lzma module in Python 3.3 for starters -- DaveA From visphatesjava at gmail.com Wed Apr 9 20:37:34 2014 From: visphatesjava at gmail.com (johannes falcone) Date: Wed, 9 Apr 2014 17:37:34 -0700 (PDT) Subject: webapp stuck on 1 cpu Message-ID: <37daea13-1749-4bd4-990d-b50cc701a4ca@googlegroups.com> do python web frameworks green thread but are stuck on 1 cpu or like aolserver do they use os threads and then maybe a combo of green and events ? so that a webapp can use a 64 cpu machine with out pain? From davea at davea.name Wed Apr 9 20:44:49 2014 From: davea at davea.name (Dave Angel) Date: Wed, 9 Apr 2014 20:44:49 -0400 (EDT) Subject: Unpacking U-Boot image file References: <20140409175323.50160@gmx.com> Message-ID: "trewio" Wrote in message: > U-Boot format: hmm, I'm not sure, can someone specify Python script that will help me deterermine U-boot format used? [for Python for Windows OS] > > Note: I need Python script for Python under Windows OS. > > >> ----- Original Message ----- >> From: Rustom Mody >> Sent: 04/09/14 08:18 PM >> To: python-list at python.org >> Subject: Re: Unpacking U-Boot image file >> >> On Wednesday, April 9, 2014 9:36:40 PM UTC+5:30, trewio wrote: >> > How to extract files from U-Boot image file, LZMA-compressed? >> > >> > Is there a Python script that can do this properly? >> >> For lzma theres this (recent) python library >> https://docs.python.org/dev/library/lzma.html >> >> Though you might just be better off with the command-line xz unxz etc >> >> After that.. whats the U-boot format? >> -- >> https://mail.python.org/mailman/listinfo/python-list > > Good job starting 3 separate threads for same question. Sorry I answered the first one. -- DaveA From wuwei23 at gmail.com Wed Apr 9 20:41:15 2014 From: wuwei23 at gmail.com (alex23) Date: Thu, 10 Apr 2014 10:41:15 +1000 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: References: Message-ID: On 9/04/2014 6:55 PM, Mark Lawrence wrote: > And the worst thing about terrible code is when you first realise > just how bad it is and wonder why you wrote it like that in the first > place. For me, it's nearly always due to time constraints. Usually caused by a comment like: "we absolutely need this extensive feature added before launch, can you start it right now? oh and we're still good for release tomorrow, right? Because we promised the client etc etc etc" From rosuav at gmail.com Wed Apr 9 21:05:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Apr 2014 11:05:15 +1000 Subject: threading In-Reply-To: References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: On Thu, Apr 10, 2014 at 9:44 AM, Dennis Lee Bieber wrote: > On Wed, 9 Apr 2014 23:47:04 +1000, Chris Angelico > declaimed the following: > >>won't block. You might think "Duh, how can printing to the screen >>block?!?", but if your program's output is being piped into something >>else, it most certainly can :) If that were writing to a remote > > Heck, even if it isn't blocking per se, it may still be enough to slow > down the whole system (over the past year I've had to characterize through > put on some systems -- and the console logging of "exceptions"* slowed the > overall data rate significantly) Oh yes, definitely. Console output can be *slow*. Back in my earliest programming days, I'd often have a program that iterated over sub-jobs from either 0 or 1 up to some unknown top (so I can't show a percent-done), and the obvious thing to do is (rewritten in Python): i = 0 while stuff_to_do(): i += 1 print(i, end="\r") do_more_stuff() print(i) Hmm, that's really slow. I know! I'll speed this up by printing out only once a second. That should be way faster, right? Let's see. i = time_printed = 0 while stuff_to_do(): i += 1 if int(time.time()) != time_printed: print(i, end="\r") time_printed = int(time.time()) do_more_stuff() print(i) And that made it... waaaay slower. Turns out clock querying (at least on those systems) is pretty slow too, even more so than console output. Of course, what we ended up settling on was something like this, which *does* make sense: i = 0 while stuff_to_do(): i += 1 if i & 255 == 0: print(i, end="\r") do_more_stuff() print(i) replacing 255 with any number one less than a power of two, so it'd print out every however-many-th (in this case, every 256th), using bitwise operations rather than division. But yeah, console output isn't something you want when you're going for maximum throughput. Heh. ChrisA From elearn2014 at gmail.com Wed Apr 9 21:54:37 2014 From: elearn2014 at gmail.com (length power) Date: Thu, 10 Apr 2014 09:54:37 +0800 Subject: How to display chinese character in 65001 in pytohn? Message-ID: I am in win7 +python3.3. import os os.system("chcp 936") fh=open("test.ch","w",encoding="utf-8") fh.write("?") fh.close() os.system("chcp 65001") fh=open("test.ch","r",encoding="utf-8").read() print(fh) ?? >>> print(fh.encode("utf-8")) b'\xe4\xbd\xa0' How can i display the chinese character `?` in 65001? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Apr 9 21:55:23 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Apr 2014 11:55:23 +1000 Subject: imaplib: how to specify SSL/TLS protocol version? In-Reply-To: References: Message-ID: On Thu, Apr 10, 2014 at 7:10 AM, Grant Edwards wrote: > I left out a relevent fact: I'm not the one calling IMAP4_. > > That's being done by the imapclient library. There's no way to pass > imapclient a custom class to use. It's hard-waired to call either > imaplib.IMAP4_stream(), imaplib.IMAP4(), or imaplib.IMAP4_SSL(). I > could create an IMAP4_TLS1 class, but I would then have to sub-class > imapclient.IMAPClient and override its _create_IMAP4() method to make > it call my IMAP4_TLS1() class instead of calling imaplib.IMAP4_SSL(). > > Monkey-patching imaplib seems a little better since it it doesn't > depend on assumptions about the internal workings of imapclient (other > than the fact that it uses imaplib.IMAP4_SSL). That's an argument in favour of a minor case of serious monkey-patching. Although if you do feel dirty, try to hold on to that feeling because that is the proper reaction to being told that you're monkey-patching. ChrisA okay, now I feel like a moron... not just a regular moron, though... From python at mrabarnett.plus.com Wed Apr 9 22:27:45 2014 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 10 Apr 2014 03:27:45 +0100 Subject: How to display chinese character in 65001 in pytohn? In-Reply-To: References: Message-ID: <534601A1.5040005@mrabarnett.plus.com> On 2014-04-10 02:54, length power wrote: > I am in win7 +python3.3. > > import os > os.system("chcp 936") > fh=open("test.ch ","w",encoding="utf-8") > fh.write("?") > fh.close() > os.system("chcp 65001") > fh=open("test.ch ","r",encoding="utf-8").read() > print(fh) > ?? > >>> print(fh.encode("utf-8")) > b'\xe4\xbd\xa0' > > How can i display the chinese character `?` in 65001? > The "chcp 65001" tells the operating system to use UTF-8, but you also have to tell Python to output UTF-8. Try this: from codecs import getwriter sys.stdout = getwriter('utf-8')(sys.stdout.detach()) From steve at pearwood.info Wed Apr 9 22:43:31 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 10 Apr 2014 02:43:31 GMT Subject: threading References: <4a24f218-158a-4a21-af36-5cc69ce1f7e1@googlegroups.com> Message-ID: <53460553$0$11109$c3e8da3@news.astraweb.com> On Wed, 09 Apr 2014 19:53:26 -0400, Roy Smith wrote: > Natural language is a wonderfully expressive thing. I open the window, > stick my head out, look up at the sky, and say, "Raining". Forget the > pronoun, I don't even have a verb. And yet everybody understands > exactly what I mean. Not everybody. There's always someone like Rick, who I'm sure will claim that he cannot understand a sentence like "Raining". The curious thing is, his claim to have less understanding of his own native tongue than a two-year-old is probably put on to prove how he is so much smarter than everyone else. "You people are SO DUMB!!! You cannot use plane English! Your so dumb i can't even understand you're sentences! Wake up sheeple and learn to right proper English!" -- Steven From steve at pearwood.info Wed Apr 9 22:52:26 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 10 Apr 2014 02:52:26 GMT Subject: Method(s) called by square brackets, slice objects References: <74d6fb5c-baca-4606-9fa8-66238a561e0c@googlegroups.com> Message-ID: <5346076a$0$11109$c3e8da3@news.astraweb.com> On Wed, 09 Apr 2014 13:24:32 -0700, John Ladasky wrote: > I would like to build a multi-dimensional array that allows numpy-style > indexing and, ideally, uses Python's familiar square-bracket and slice > notations. > > For example, if I declare a two-dimensional array object, x, then x[4,7] > retrieves the element located at the 4th row and the 7th column. If I > ask for x[3:6,1:3], I get a 3 x 2 array object consisting of the > intersection of the 3rd-5th rows, and the 1st-2nd columns, of x. > > In this case I'm not allowed to use numpy, I have to restrict myself to > the standard library. I thought that I might achieve the desired > behavior by defining an object with specific __getitem__ and/or > __getslice__ methods. Use __getitem__, __getslice__ is deprecated in Python 2 and gone in Python 3. https://docs.python.org/2/reference/datamodel.html#object.__getslice__ > However, the documentation of these methods that > I am reading suggests that the arguments are pre-parsed into certain > formats which may not allow me to do things numpy's way. Is this true? Why don't you try it in the interactive interpreter and see? py> class Test(object): ... def __getitem__(self, thing): ... print thing ... py> obj = Test() py> obj[1] 1 py> obj[1:2] slice(1, 2, None) py> obj[1:2:3] slice(1, 2, 3) py> obj[1,5:2:3] (1, slice(5, 2, 3)) py> obj[1:2:3,4:5:6] (slice(1, 2, 3), slice(4, 5, 6)) py> obj[1,2,3] (1, 2, 3) py> obj[1,2,"spam"] (1, 2, 'spam') py> obj[1,2,"spam":"eggs",3] (1, 2, slice('spam', 'eggs', None), 3) -- Steven From elearn2014 at gmail.com Wed Apr 9 23:05:05 2014 From: elearn2014 at gmail.com (length power) Date: Thu, 10 Apr 2014 11:05:05 +0800 Subject: How to display chinese character in 65001 in pytohn? In-Reply-To: <534601A1.5040005@mrabarnett.plus.com> References: <534601A1.5040005@mrabarnett.plus.com> Message-ID: i tried this way ,and post it in stackoverflow,please see: maybe it is the best answer. Codepage 65001 is generally broken in binary mode as used by Python 3, since _write calls Win32 WriteFile, which calls WriteConsoleA, which returns the number of characters written instead of the number of bytes. That confuses Python. ANSICON can hook WriteFile to fix this for programs that you specify in an environment variable, but that won't help with input. http://stackoverflow.com/questions/22977409/how-to-display-chinese-character-in-65001-in-pytohn?noredirect=1#comment35087732_22977409 2014-04-10 10:27 GMT+08:00 MRAB : > On 2014-04-10 02:54, length power wrote: > >> I am in win7 +python3.3. >> >> import os >> os.system("chcp 936") >> fh=open("test.ch ","w",encoding="utf-8") >> >> fh.write("?") >> fh.close() >> os.system("chcp 65001") >> fh=open("test.ch ","r",encoding="utf-8").read() >> >> print(fh) >> ?? >> >>> print(fh.encode("utf-8")) >> b'\xe4\xbd\xa0' >> >> How can i display the chinese character `?` in 65001? >> >> The "chcp 65001" tells the operating system to use UTF-8, but you also > have to tell Python to output UTF-8. Try this: > > from codecs import getwriter > sys.stdout = getwriter('utf-8')(sys.stdout.detach()) > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Apr 9 23:08:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Apr 2014 13:08:18 +1000 Subject: threading In-Reply-To: <53460553$0$11109$c3e8da3@news.astraweb.com> References: <4a24f218-158a-4a21-af36-5cc69ce1f7e1@googlegroups.com> <53460553$0$11109$c3e8da3@news.astraweb.com> Message-ID: On Thu, Apr 10, 2014 at 12:43 PM, Steven D'Aprano wrote: > You cannot use plane English! Cleared for takeoff... ChrisA From elearn2014 at gmail.com Wed Apr 9 23:19:27 2014 From: elearn2014 at gmail.com (length power) Date: Thu, 10 Apr 2014 11:19:27 +0800 Subject: How to display chinese character in 65001 in pytohn? In-Reply-To: References: <534601A1.5040005@mrabarnett.plus.com> Message-ID: problem solved.if you enter python by python(command line),the problem can't be solved.if you enter python by cmd ,and input python,no problem happen. 2014-04-10 11:05 GMT+08:00 length power : > i tried this way ,and post it in stackoverflow,please see: > maybe it is the best answer. > Codepage 65001 is generally broken in binary mode as used by Python 3, > since _write calls Win32 WriteFile, which calls WriteConsoleA, which > returns the number of characters written instead of the number of bytes. > That confuses Python. ANSICON can hook > WriteFile to fix this for programs that you specify in an environment > variable, but that won't help with input. > > > http://stackoverflow.com/questions/22977409/how-to-display-chinese-character-in-65001-in-pytohn?noredirect=1#comment35087732_22977409 > > > 2014-04-10 10:27 GMT+08:00 MRAB : > > On 2014-04-10 02:54, length power wrote: >> >>> I am in win7 +python3.3. >>> >>> import os >>> os.system("chcp 936") >>> fh=open("test.ch ","w",encoding="utf-8") >>> >>> fh.write("?") >>> fh.close() >>> os.system("chcp 65001") >>> fh=open("test.ch ","r",encoding="utf-8").read() >>> >>> print(fh) >>> ?? >>> >>> print(fh.encode("utf-8")) >>> b'\xe4\xbd\xa0' >>> >>> How can i display the chinese character `?` in 65001? >>> >>> The "chcp 65001" tells the operating system to use UTF-8, but you also >> have to tell Python to output UTF-8. Try this: >> >> from codecs import getwriter >> sys.stdout = getwriter('utf-8')(sys.stdout.detach()) >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at pearwood.info Wed Apr 9 23:44:39 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 10 Apr 2014 03:44:39 GMT Subject: threading References: <4a24f218-158a-4a21-af36-5cc69ce1f7e1@googlegroups.com> Message-ID: <534613a6$0$11109$c3e8da3@news.astraweb.com> On Wed, 09 Apr 2014 08:51:09 -0700, Rick Johnson wrote: > On Wednesday, April 9, 2014 8:50:59 AM UTC-5, Neil D. Cerutti wrote: >> [...] >> Plus Rufus Xavier Sasparilla disagrees with it. > > If you think you're going to argue in such an implicit manner as to the > benefits of pronouns, then you should expect that an astute logician > such as myself will tear you to shreds. This reminds me of Wile E. Coyote, announcing himself to others: "Allow me to introduce myself, Wile E. Coyote, Super-Genius." http://geekwisdom.wordpress.com/2013/03/16/wile-e-coyote-super-genius/ Rick, if you have to call yourself an astute logician for other to know, then you probably aren't. > And whist i admit your snarky comment is founded on a *superficial* fact "Whilst". Whist is a card game. [...] > ############################################################ > # You comment is cleaver propaganda, Damn those lying cleavers! "Clever". A cleaver is a type of heavy chopping knife, usually used for cutting through bones. [...] > Now, before i utterly destroy you, we must first *ALL* take a lesson in > linguistics. Oh noes! I'm going to be destroyed by Rick, Super-Genius! Rick, before you reform the English language, perhaps you ought to concentrate on an easier task. A few years ago you offered to fork Python and make it a better language. I promised to be a beta tester for you if you did so. How is that coming along? Do you have a repo where I can check out progress? -- Steven From rosuav at gmail.com Wed Apr 9 23:54:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Apr 2014 13:54:10 +1000 Subject: threading In-Reply-To: <534613a6$0$11109$c3e8da3@news.astraweb.com> References: <4a24f218-158a-4a21-af36-5cc69ce1f7e1@googlegroups.com> <534613a6$0$11109$c3e8da3@news.astraweb.com> Message-ID: On Thu, Apr 10, 2014 at 1:44 PM, Steven D'Aprano wrote: >> Now, before i utterly destroy you, we must first *ALL* take a lesson in >> linguistics. > > Oh noes! I'm going to be destroyed by Rick, Super-Genius! I'll send him my business card as a salesman for Acme. Easiest job in the world - just sell him stuff with no guarantees, isn't necessarily of merchantable quality, and might even backfire and explode, and he'll buy the lot. ChrisA From kim_plofker at yahoo.com Thu Apr 10 00:32:27 2014 From: kim_plofker at yahoo.com (Kim Plofker) Date: Wed, 9 Apr 2014 21:32:27 -0700 (PDT) Subject: Plotting the integer-and-fraction remainder of a function value modulo 360 Message-ID: <1397104347.74031.YahooMailNeo@web161504.mail.bf1.yahoo.com> How can I get Python to represent a value of a function in degrees, i.e., with values between 0 and 360, by taking the (non-integer) function expression mod 360? That is, I have a function with non-integer values, called Longitude, which is defined in terms of the variable t. I just want to plot Longitude modulo 360 for a range of values of t: that is, for every value of t, plot the integer-AND-fraction remainder after dividing Longitude by 360. But Python (in Sage) apparently won't let me use the int function or the // operator on functions defined in terms of a variable: I get a "cannot evaluate symbolic expression numerically" TypeError. How do I do this? There must be a simple way to tell Python that I want it to compute the value of Longitude for a given value of t and then take the integer-and-fraction remainder from dividing by 360. Many thanks, Kim -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Thu Apr 10 00:54:26 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 10 Apr 2014 14:54:26 +1000 Subject: Plotting the integer-and-fraction remainder of a function value modulo 360 References: <1397104347.74031.YahooMailNeo@web161504.mail.bf1.yahoo.com> Message-ID: <85eh15zsvx.fsf@benfinney.id.au> Kim Plofker writes: > How can I get Python to represent a value of a function in degrees, > i.e., with values between 0 and 360, by taking the (non-integer) > function expression mod 360? In Python, you simply use the modulo (?%?) operator:: >>> 45.0 % 360 45.0 >>> 700.0 % 360 340.0 >>> > That is, I have a function with non-integer values, called Longitude If they're not integers, and you're not saying what they *are*, then I can't know anything beyond ?they will behave the way the Longitude class defines them?. > which is defined in terms of the variable t. I don't understand what it means for a longitude value to be ?defined in terms of the variable t?. Can you say more about how these values are defined? Since (as you say) they're not integers, what *are* they? > I just want to plot Longitude modulo 360 for a range of values of t: > that is, for every value of t, plot the integer-AND-fraction remainder > after dividing Longitude by 360. What does it mean to ?plot the integer-AND-fraction remainder?? It sounds like you want to plot two numbers separately, the integer and the fraction remainder. But that doesn't make much sense to me. Do you mean simply that you want to plot numbers like ?3.7?, ?270.0?, and ?48.75?? In which case, this is supported by the native ?float? type, and (for better accuracy) by the ?decimal.Decimal? type from the standard library:: >>> lon = decimal.Decimal("758.45") >>> lon % 360 Decimal('38.45') > But Python (in Sage) apparently won't let me use the int function or > the // operator on functions defined in terms of a variable: I get a > "cannot evaluate symbolic expression numerically" TypeError. It sounds like this Sage is not behaving as the standard Python types do, with regard to the modulo ?%? operator. For help with Sage (I don't know what that is), you probably will get better answers on a Sage-specific discussion forum. >From the perspective of Python, the standard types handle the requirements you describe without any TypeError. -- \ ?If you were going to shoot a mime, would you use a silencer?? | `\ ?Steven Wright | _o__) | Ben Finney From steve at pearwood.info Thu Apr 10 01:01:42 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 10 Apr 2014 05:01:42 GMT Subject: Plotting the integer-and-fraction remainder of a function value modulo 360 References: Message-ID: <534625b5$0$11109$c3e8da3@news.astraweb.com> On Wed, 09 Apr 2014 21:32:27 -0700, Kim Plofker wrote: > How can I get Python to represent a value of a function in degrees, > i.e., with values between 0 and 360, by taking the (non-integer) > function expression mod 360? > > That is, I have a function with non-integer values, called Longitude, > which is defined in terms of the variable t. I just want to plot > Longitude modulo 360 for a range of values of t: that is, for every > value of t, plot the integer-AND-fraction remainder after dividing > Longitude by 360. > > But Python (in Sage) apparently won't let me use the int function or the > // operator on functions defined in terms of a variable: I get a "cannot > evaluate symbolic expression numerically" TypeError. That's an issue with Sage itself, probably sympy. Python the language doesn't natively understand symbolic expressions, that's added by sympy, so you may need to ask some sympy experts. It may help if you show the actual code you are using, and the full traceback generated by the error. When I try something similar, I get a different error message: py> from sympy.abc import x py> (x + 1) % 60 Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for %: 'Add' and 'int' which could mean I'm doing something different, or just a difference in version numbers. > How do I do this? > There must be a simple way to tell Python that I want it to compute the > value of Longitude for a given value of t and then take the > integer-and-fraction remainder from dividing by 360. That's simple with numeric types: use the divmod function or % operator. But you're using some sort of symbolic library, so we need to know what the library is. -- Steven From elearn2014 at gmail.com Thu Apr 10 01:14:49 2014 From: elearn2014 at gmail.com (length power) Date: Thu, 10 Apr 2014 13:14:49 +0800 Subject: how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ? Message-ID: >>> x=["a","b",["c","d"],"e"] >>> y=x[2] >>> y ['c', 'd'] >>> x.insert(2,y[0]) >>> x ['a', 'b', 'c', ['c', 'd'], 'e'] >>> x.insert(3,y[1]) >>> x ['a', 'b', 'c', 'd', ['c', 'd'], 'e'] >>> del x[4] >>> x ['a', 'b', 'c', 'd', 'e'] >>> maybe there is a more smart way to do. -------------- next part -------------- An HTML attachment was scrubbed... URL: From balajimarisetti at gmail.com Thu Apr 10 01:16:47 2014 From: balajimarisetti at gmail.com (balaji marisetti) Date: Thu, 10 Apr 2014 10:46:47 +0530 Subject: CommandLine Option in Python for filtering values from Column In-Reply-To: <1397071383.35192.YahooMailNeo@web193506.mail.sg3.yahoo.com> References: <1397071383.35192.YahooMailNeo@web193506.mail.sg3.yahoo.com> Message-ID: sys.argv is itself a list. You can directly access the `quality` field as sys.argv[2]. quality = int(sys.argv[2]) However, if you want to use more command line options, then using `argparse` module is better than accessing arguments using `sys.argv`. Import `argparse` module and create a parser import argparse parser = argparse.ArgumentParser(description='My example command line option parser') #Add as many arguments as you want to parse (from the command line) parser.add_argument('--quality', type=int, help='Quality score') parser.add_argument("--some-other-option", help="Some other option for example") ... ... #Parse the arguments (to be)given on the command line(when the script is invoked) args = parser.parse_args() #Access all the arguments or options as `args.quality`, `args.some_other_option`, etc. print("quality =", args.quality) print("some-other-option =", args.some_other_option) Read the documentation of argparse for better understanding. https://docs.python.org/2/library/argparse.html On 10 April 2014 00:53, rohan bareja wrote: > I want to write a function in Python for a tab delimited file I am dealing > with,to filter out values from a column, and put that parameter as a command > line option while running the script. > > So,if the limit is 10,the filter out all the rows with values less than 10. > Also,I want to check if the number entered is numeric or not else display > the message "its not numeric". > > > So,the command line would be: > > python script.py file --quality [limit] > > > The Python script: > > import sys > arg = [] > for a in sys.argv: > arg.append(a) > quality = arg[2] > > > To be more specific,the file I am dealing with is a Samfile,and using > package > Pysam,which has mapping quality limits in the 5th column. > > https://media.readthedocs.org/pdf/pysam/latest/pysam.pdf > > Commandline: > > python script.py samfile --quality [limit] > > I am reading the samfile using this: > > samfile = pysam.Samfile(arg[1], "rb" ) > mapqlim = arg[2] > > I am a Python beginner,but saw one of the modules,argparse. How can I > accomplish this using argparse in Python? > > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- :-)balaji From balajimarisetti at gmail.com Thu Apr 10 01:25:10 2014 From: balajimarisetti at gmail.com (balaji marisetti) Date: Thu, 10 Apr 2014 10:55:10 +0530 Subject: how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ? In-Reply-To: References: Message-ID: There was long thread discussing flattening of a list on this list :). See the link below. https://mail.python.org/pipermail/python-list/2014-March/669256.html On 10 April 2014 10:44, length power wrote: >>>> x=["a","b",["c","d"],"e"] >>>> y=x[2] >>>> y > ['c', 'd'] >>>> x.insert(2,y[0]) >>>> x > ['a', 'b', 'c', ['c', 'd'], 'e'] >>>> x.insert(3,y[1]) >>>> x > ['a', 'b', 'c', 'd', ['c', 'd'], 'e'] >>>> del x[4] >>>> x > ['a', 'b', 'c', 'd', 'e'] >>>> > maybe there is a more smart way to do. > > -- > https://mail.python.org/mailman/listinfo/python-list > -- :-)balaji From ben+python at benfinney.id.au Thu Apr 10 01:25:52 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 10 Apr 2014 15:25:52 +1000 Subject: how to make ["a", "b", ["c", "d"], "e"] into ['a', 'b', 'c', 'd', 'e'] ? References: Message-ID: <85a9btzrfj.fsf@benfinney.id.au> length power writes: > maybe there is a more smart way to do. Maybe. But a way to do what, exactly? You start with a list, but what is it exactly that you want to do with that list? >>> x = ["a", "b", ["c", "d"], "e"] If I interpret your request *literally*, I can achieve it in a single statement:: >>> y = ['a', 'b', 'c', 'd', 'e'] There! We got the second list you wanted. Maybe you want to turn the second item in any list into ?['c', 'd']?:: >>> y = x[:2] + ['c', 'd'] + x[3:] Or maybe you want some other operation. It's not clear from your example. So, thank you for providing an example of what you mean; but that doesn't help with knowing what you mean *generally*. What is the general operation you want to do? Please describe what input you will get, and what the output should be in the same terms. -- \ ?Ubi dubium, ibi libertas.? (?Where there is doubt, there is | `\ freedom.?) | _o__) | Ben Finney From rustompmody at gmail.com Thu Apr 10 01:38:25 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 9 Apr 2014 22:38:25 -0700 (PDT) Subject: how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ? In-Reply-To: References: Message-ID: On Thursday, April 10, 2014 10:55:10 AM UTC+5:30, balaji marisetti wrote: > There was long thread discussing flattening of a list on this list :). > See the link below. I dont think that thread is relevant to this question: 1. That (started with) a strange/cute way of using names 2. It does not work for heterogenous lists # One level flatten version # like the earlier thread without strange naming # needed by the recursive one below >>> def fl1(l): return [y for x in l for y in x] # recursive flatten >>> def fr(l): ... if not isinstance(l,list): return [l] ... return fl1([fr(x) for x in l]) You can replace the list-comps by generator-comps From nelle.varoquaux at gmail.com Thu Apr 10 02:04:44 2014 From: nelle.varoquaux at gmail.com (Nelle Varoquaux) Date: Thu, 10 Apr 2014 08:04:44 +0200 Subject: EuroScipy Reminder: call for abstracts closes in 4 days Message-ID: Hello everyone, Just a quick reminder that the EuroScipy call for abstracts closes on the 14th: don't forget to submit your talk proposal! It is in four days only! In short, EuroScipy is a cross-disciplinary gathering focused on the use and development of the Python language in scientific research. This event strives to bring together both users and developers of scientific tools, as well as academic research and state of the art industry. EuroSciPy 2014, the Seventh Annual Conference on Python in Science, takes place in *Cambridge, UK on 27 - 30 August 2014*. The conference features two days of tutorials followed by two days of scientific talks. The day after the main conference, developer sprints will be organized on projects of interest to attendees. The topics presented at EuroSciPy are very diverse, with a focus on advanced software engineering and original uses of Python and its scientific libraries, either in theoretical or experimental research, from both academia and the industry. The program includes keynotes, contributed talks and posters. Submissions for talks and posters are welcome on our website ( http://www.euroscipy.org/2014/). In your abstract, please provide details on what Python tools are being employed, and how. The deadline for submission is 14 April 2014. Also until 14 April 2014, you can apply for a sprint session on 31 August 2014. See https://www.euroscipy.org/2014/calls/sprints/ for details. Thanks, N -------------- next part -------------- An HTML attachment was scrubbed... URL: From elearn2014 at gmail.com Thu Apr 10 01:03:18 2014 From: elearn2014 at gmail.com (length power) Date: Thu, 10 Apr 2014 13:03:18 +0800 Subject: problem in python pandas module Message-ID: the problem about pandas the data is in the attachment,please download it and save as "test.ansi" import pandas as pd pd.read_csv("g:\\test.ansi",sep=",",encoding="gbk") 1.how to read data properly? there is a balnk line by every data of row. how can i don't read any NaN NaN NaN ? 2.how to display all data in the console? there are [301 rows x 3 columns],only 59 of them displayed,how to display all 301 rows? -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: test.ansi Type: application/octet-stream Size: 3437 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: pandas.JPG Type: image/jpeg Size: 106684 bytes Desc: not available URL: From kim_plofker at yahoo.com Thu Apr 10 01:03:49 2014 From: kim_plofker at yahoo.com (Kim Plofker) Date: Wed, 9 Apr 2014 22:03:49 -0700 (PDT) Subject: Plotting the integer-and-fraction remainder of a function value modulo 360 In-Reply-To: <85eh15zsvx.fsf@benfinney.id.au> References: <1397104347.74031.YahooMailNeo@web161504.mail.bf1.yahoo.com> <85eh15zsvx.fsf@benfinney.id.au> Message-ID: <1397106229.8794.YahooMailNeo@web161502.mail.bf1.yahoo.com> Thanks, the % operator is indeed what I want, but I want to use it with a function expression rather than with numbers alone. ?And that seems to create a type error. Here's an example of what goes wrong: t = var('t') L(t) = t*725.5%360.0 This produces the following error message: ... TypeError: unsupported operand type(s) for %: 'sage.symbolic.expression.Expression' and 'sage.symbolic.expression.Expression' I can use other arithmetic operators such as + and / in this function expression, but not %, and I don't understand why. ?Is it indeed a Sage-specific problem rather than something I could work around in Python? Many thanks again for any help. Kim ________________________________ From: Ben Finney To: python-list at python.org Sent: Thursday, April 10, 2014 12:54 AM Subject: Re: Plotting the integer-and-fraction remainder of a function value modulo 360 Kim Plofker writes: > How can I get Python to represent a value of a function in degrees, > i.e., with values between 0 and 360, by taking the (non-integer) > function expression mod 360? In Python, you simply use the modulo (?%?) operator:: ? ? >>> 45.0 % 360 ? ? 45.0 ? ? >>> 700.0 % 360 ? ? 340.0 ? ? >>> > That is, I have a function with non-integer values, called Longitude If they're not integers, and you're not saying what they *are*, then I can't know anything beyond ?they will behave the way the Longitude class defines them?. > which is defined in terms of the variable t. I don't understand what it means for a longitude value to be ?defined in terms of the variable t?. Can you say more about how these values are defined? Since (as you say) they're not integers, what *are* they? > I just want to plot Longitude modulo 360 for a range of values of t: > that is, for every value of t, plot the integer-AND-fraction remainder > after dividing Longitude by 360. What does it mean to ?plot the integer-AND-fraction remainder?? It sounds like you want to plot two numbers separately, the integer and the fraction remainder. But that doesn't make much sense to me. Do you mean simply that you want to plot numbers like ?3.7?, ?270.0?, and ?48.75?? In which case, this is supported by the native ?float? type, and (for better accuracy) by the ?decimal.Decimal? type from the standard library:: ? ? >>> lon = decimal.Decimal("758.45") ? ? >>> lon % 360 ? ? Decimal('38.45') > But Python (in Sage) apparently won't let me use the int function or > the // operator on functions defined in terms of a variable: I get a > "cannot evaluate symbolic expression numerically" TypeError. It sounds like this Sage is not behaving as the standard Python types do, with regard to the modulo ?%? operator. For help with Sage (I don't know what that is), you probably will get better answers on a Sage-specific discussion forum. From the perspective of Python, the standard types handle the requirements you describe without any TypeError. -- \? ? ? ?If you were going to shoot a mime, would you use a silencer?? | ? `\? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Steven Wright | _o__)? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From kim_plofker at yahoo.com Thu Apr 10 01:12:44 2014 From: kim_plofker at yahoo.com (Kim Plofker) Date: Wed, 9 Apr 2014 22:12:44 -0700 (PDT) Subject: Plotting the integer-and-fraction remainder of a function value modulo 360 In-Reply-To: <534625b5$0$11109$c3e8da3@news.astraweb.com> References: <534625b5$0$11109$c3e8da3@news.astraweb.com> Message-ID: <1397106764.87133.YahooMailNeo@web161505.mail.bf1.yahoo.com> Thanks! ?As I recently posted in a followup message, -------- Here's an example of what goes wrong: t = var('t') L(t) = t*725.5%360.0 This produces the following error message: ... TypeError: unsupported operand type(s) for %: 'sage.symbolic.expression.Expression' and 'sage.symbolic.expression.Expression' -------- So it looks like I've got a Sage-specific problem. ?I still don't know how to fix it, but at least I understand the problem better! ? Many thanks, Kim ________________________________ From: Steven D'Aprano To: python-list at python.org Sent: Thursday, April 10, 2014 1:01 AM Subject: Re: Plotting the integer-and-fraction remainder of a function value modulo 360 On Wed, 09 Apr 2014 21:32:27 -0700, Kim Plofker wrote: > How can I get Python to represent a value of a function in degrees, > i.e., with values between 0 and 360, by taking the (non-integer) > function expression mod 360? > > That is, I have a function with non-integer values, called Longitude, > which is defined in terms of the variable t. I just want to plot > Longitude modulo 360 for a range of values of t: that is, for every > value of t, plot the integer-AND-fraction remainder after dividing > Longitude by 360. > > But Python (in Sage) apparently won't let me use the int function or the > // operator on functions defined in terms of a variable: I get a "cannot > evaluate symbolic expression numerically" TypeError. That's an issue with Sage itself, probably sympy. Python the language doesn't natively understand symbolic expressions, that's added by sympy, so you may need to ask some sympy experts. It may help if you show the actual code you are using, and the full traceback generated by the error. When I try something similar, I get a different error message: py> from sympy.abc import x py> (x + 1) % 60 Traceback (most recent call last): ? File "", line 1, in TypeError: unsupported operand type(s) for %: 'Add' and 'int' which could mean I'm doing something different, or just a difference in version numbers. > How do I do this? > There must be a simple way to tell Python that I want it to compute the > value of Longitude for a given value of t and then take the > integer-and-fraction remainder from dividing by 360. That's simple with numeric types: use the divmod function or % operator. But you're using some sort of symbolic library, so we need to know what the library is. -- Steven -- https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Thu Apr 10 03:13:57 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 10 Apr 2014 17:13:57 +1000 Subject: Plotting the integer-and-fraction remainder of a function value modulo 360 References: <1397104347.74031.YahooMailNeo@web161504.mail.bf1.yahoo.com> <85eh15zsvx.fsf@benfinney.id.au> <1397106229.8794.YahooMailNeo@web161502.mail.bf1.yahoo.com> Message-ID: <8561mhzmfe.fsf@benfinney.id.au> Kim Plofker writes: > This produces the following error message: Thank you for providing an actual code example (though not one I can run, since it isn't a complete Python program). Particularly, thank you for providing the *actual* error output; this makes it much clearer what is happening. It's always best to show the complete error output since usually there are details in the output that narrow down the problem. > ... > TypeError: unsupported operand type(s) for %: > 'sage.symbolic.expression.Expression' and > 'sage.symbolic.expression.Expression' This is indeed a problem specific to the types defined by Sage. You'll need to start a discussion in a Sage-specific discussion forum. > Many thanks again for any help. You will likely still need assistance with Python to continue with this. Once you have a better idea what part is Sage-specific and what part is general Python, feel free to ask here. Or if you prefer, there is a beginner-level Python discussion forum at . -- \ ?Know what I hate most? Rhetorical questions.? ?Henry N. Camp | `\ | _o__) | Ben Finney From tjreedy at udel.edu Thu Apr 10 03:20:34 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 10 Apr 2014 03:20:34 -0400 Subject: How to display chinese character in 65001 in pytohn? In-Reply-To: References: <534601A1.5040005@mrabarnett.plus.com> Message-ID: On 4/9/2014 11:19 PM, length power wrote: > problem solved.if you enter python by python(command line),the problem > can't be solved.if you enter python by cmd ,and input |python|,no > problem happen. I have also failed trying to use cp65001. I do not understand the solution you claim. Please be more specific with exactly what works. -- Terry Jan Reedy From tjreedy at udel.edu Thu Apr 10 03:25:46 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 10 Apr 2014 03:25:46 -0400 Subject: Plotting the integer-and-fraction remainder of a function value modulo 360 In-Reply-To: <1397106229.8794.YahooMailNeo@web161502.mail.bf1.yahoo.com> References: <1397104347.74031.YahooMailNeo@web161504.mail.bf1.yahoo.com> <85eh15zsvx.fsf@benfinney.id.au> <1397106229.8794.YahooMailNeo@web161502.mail.bf1.yahoo.com> Message-ID: On 4/10/2014 1:03 AM, Kim Plofker wrote: > Thanks, the % operator is indeed what I want, but I want to use it with > a function expression rather than with numbers alone. And that seems to > create a type error. > > Here's an example of what goes wrong: > > t = var('t') > L(t) = t*725.5%360.0 > > This produces the following error message: > > ... > TypeError: unsupported operand type(s) for %: > 'sage.symbolic.expression.Expression' and > 'sage.symbolic.expression.Expression' > > > I can use other arithmetic operators such as + and / in this function > expression, but not %, and I don't understand why. Is it indeed a > Sage-specific problem rather than something I could work around in Python? It seems that someone either forgot to implement % or decided not too. You will have to ask the sage people. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Thu Apr 10 04:23:21 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 10 Apr 2014 09:23:21 +0100 Subject: threading In-Reply-To: References: <4a24f218-158a-4a21-af36-5cc69ce1f7e1@googlegroups.com> Message-ID: On 10/04/2014 00:53, Roy Smith wrote: > > Natural language is a wonderfully expressive thing. I open the window, > stick my head out, look up at the sky, and say, "Raining". Forget the > pronoun, I don't even have a verb. And yet everybody understands > exactly what I mean. > In the UK you can stay in bed and say "Raining" and the odds are you'll be correct :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Thu Apr 10 04:27:12 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 10 Apr 2014 09:27:12 +0100 Subject: CommandLine Option in Python for filtering values from Column In-Reply-To: References: <1397071383.35192.YahooMailNeo@web193506.mail.sg3.yahoo.com> Message-ID: On 10/04/2014 06:16, balaji marisetti wrote: > sys.argv is itself a list. You can directly access the `quality` field > as sys.argv[2]. > > quality = int(sys.argv[2]) > > However, if you want to use more command line options, then using > `argparse` module is better than accessing arguments using `sys.argv`. > An alternative is to grab docopt from pypi, it's awesome :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From chris at simplistix.co.uk Thu Apr 10 04:42:12 2014 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 10 Apr 2014 09:42:12 +0100 Subject: xlrd 0.9.3 released! Message-ID: <53465964.9000805@simplistix.co.uk> Hi All, I'm pleased to announce the release of xlrd 0.9.3: http://pypi.python.org/pypi/xlrd/0.9.3 This release includes the following changes: - Github issue #49 - Github issue #64 - skip meaningless chunk of 4 zero bytes between two otherwise-valid BIFF records - Github issue #61 - fix updating of escapement attribute of Font objects read from workbooks. - Implemented Sheet.visibility for xlsx files - Ignore anchors ($) in cell references - Dropped support for Python 2.5 and earlier, Python 2.6 is now the earliest Python release supported - Read xlsx merged cell elements. - Read cell comments in .xlsx files - Added xldate_to_datetime() function to convert from Excel serial date/time to datetime.datetime object. Thanks to the following for their contributions to this release: - John Machin - Caleb Epstein - Martin Panter - John McNamara - Gunnlaugur ??r Briem - Stephen Lewis If you find any problems, please ask about them on the python-excel at googlegroups.com list, or submit an issue on GitHub: https://github.com/python-excel/xlrd/issues Full details of all things Python and Excel related can be found here: http://www.python-excel.org/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From rosuav at gmail.com Thu Apr 10 05:11:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Apr 2014 19:11:34 +1000 Subject: threading In-Reply-To: References: <4a24f218-158a-4a21-af36-5cc69ce1f7e1@googlegroups.com> Message-ID: On Thu, Apr 10, 2014 at 6:23 PM, Mark Lawrence wrote: > On 10/04/2014 00:53, Roy Smith wrote: >> Natural language is a wonderfully expressive thing. I open the window, >> stick my head out, look up at the sky, and say, "Raining". Forget the >> pronoun, I don't even have a verb. And yet everybody understands >> exactly what I mean. >> > > In the UK you can stay in bed and say "Raining" and the odds are you'll be > correct :) Is the staying-in-bed part critical to that? The last few times I've been to England, it's only rained a few times. Granted, I've always come during your summer, but even so, the rumours suggest that rain should still be plenty common. We've happily driven a costume rack down the A53 (twice - once empty, once loaded, if I recall correctly), without worrying about rain. There were a few times when the terrain was treacherous (imagine this: you're at the top of a moderately-steep (probably 1 in 10-20) of rough concrete or asphalt, depending on which part you jog down, and it's been greased up by vehicles standing there, and then rained on; and you need to run down it at full speed, catch the porta-cabin before it closes for the last time this year, get the DVDs that were being run off for you, and run back up at full speed, all before a ceremony begins), but other than that, it's been pretty dry every time we've been there. But we don't stay in bed much. ChrisA From balajimarisetti at gmail.com Thu Apr 10 05:17:11 2014 From: balajimarisetti at gmail.com (balaji marisetti) Date: Thu, 10 Apr 2014 14:47:11 +0530 Subject: CommandLine Option in Python for filtering values from Column In-Reply-To: References: <1397071383.35192.YahooMailNeo@web193506.mail.sg3.yahoo.com> Message-ID: > An alternative is to grab docopt from pypi, it's awesome :) Some time back, I watched a video about that module but, later, I forgot its name. Thanks for reminding me of that module. On 10 April 2014 13:57, Mark Lawrence wrote: > On 10/04/2014 06:16, balaji marisetti wrote: >> >> sys.argv is itself a list. You can directly access the `quality` field >> as sys.argv[2]. >> >> quality = int(sys.argv[2]) >> >> However, if you want to use more command line options, then using >> `argparse` module is better than accessing arguments using `sys.argv`. >> > > An alternative is to grab docopt from pypi, it's awesome :) > > -- > My fellow Pythonistas, ask not what our language can do for you, ask what > you can do for our language. > > Mark Lawrence > > --- > This email is free from viruses and malware because avast! Antivirus > protection is active. > http://www.avast.com > > > -- > https://mail.python.org/mailman/listinfo/python-list -- :-)balaji From frank at chagford.com Thu Apr 10 05:17:50 2014 From: frank at chagford.com (Frank Millman) Date: Thu, 10 Apr 2014 11:17:50 +0200 Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: "Chris Angelico" wrote in message news:CAPTjJmq2xx_WG2ymCC0NNqisDO=DNnJhneGPiD3DE+xeiy5hjg at mail.gmail.com... > On Thu, Apr 10, 2014 at 12:30 AM, Frank Millman > wrote: >> >>> >>>> How does one distinguish betwen 'blocking' and 'non-blocking'? Is it >>>> either/or, or is it some arbitrary timeout - if a handler returns >>>> within >>>> that time it is non-blocking, but if it exceeds it it is blocking? >>> >>> No; a blocking request is one that waits until it has a response, and >>> a non-blocking request is one that goes off and does something, and >>> then comes back to you when it's done. >> Thanks for that clarification - I think I've got it now. >>> def nonblocking_query(id): >>> print("Finding out who employee #%d is..."%id) >>> def nextstep(res): >>> print("Employee #%d is %s."%(id,res[0].name)) >>> db.asyncquery(nextstep, "select name from emp where id=12345") >>> >> >> In this example, what is 'db.asyncquery'? >> >> If you mean that you have a separate thread to handle database queries, >> and >> you use a queue or other message-passing mechanism to hand it the query >> and >> get the result, then I understand it. If not, can you explain in more >> detail. > > It's an imaginary function that would send a request to the database, > and then call some callback function when the result arrives. If the > database connection is via a TCP/IP socket, that could be handled by > writing the query to the socket, and then when data comes back from > the socket, looking up the callback and calling it. There's no > additional thread here. > I need some time to get my head around that, but meanwhile can you resolve this stumbling block? The current version of my program uses HTTP. As I understand it, a client makes a connection and submits a request. The server processes the request and returns a result. The connection is then closed. In this scenario, does async apply at all? There is no open connection to 'select' or 'poll'. You have to ensure that the request handler does not block the entire process, so that the main loop is ready to accept more connections. But passing the request to a thread for handling seems an effective solution. Am I missing something? Frank From rosuav at gmail.com Thu Apr 10 05:40:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Apr 2014 19:40:57 +1000 Subject: threading In-Reply-To: References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: On Thu, Apr 10, 2014 at 7:17 PM, Frank Millman wrote: > The current version of my program uses HTTP. As I understand it, a client > makes a connection and submits a request. The server processes the request > and returns a result. The connection is then closed. > > In this scenario, does async apply at all? There is no open connection to > 'select' or 'poll'. You have to ensure that the request handler does not > block the entire process, so that the main loop is ready to accept more > connections. But passing the request to a thread for handling seems an > effective solution. Let's take this to a slightly lower level. HTTP is built on top of a TCP/IP socket. The client connects (usually on port 80), and sends a string like this: """GET /foo/bar/asdf.html HTTP/1.0 Host: www.spam.org User-Agent: Mozilla/5.0 """ The server then sends back something like this: """HTTP/1.0 200 OK Content-type: text/html Hello, world! """ These are carried on a straight-forward bidirectional stream socket, so the write and read operations (or send and recv, either way) can potentially block. With a small request, you can kinda assume that the write won't block, but the read most definitely will: it'll block until the server writes something for you. So it follows the usual model of blocking vs non-blocking. In blocking mode, you do something like this: data = socket.read() and it waits until it has something to return. In non-blocking mode, you do something like this: def data_available(socket, data): # whatever socket.set_read_callback(data_available) An HTTP handling library can then build a non-blocking request handler on top of that, by having data_available parse out the appropriate information, and return if it doesn't have enough content yet. So it follows the same model; you send off the request (and don't wait for it), and then get notified when the result is there. When you write the server, you effectively have the same principle, with one additional feature: a listening socket becomes readable whenever someone connects. So you can select() on that socket, just like you can with the others, and whenever there's a new connection, you add it to the collection and listen for requests on all of them. It's basically the same concept; as soon as you can accept a new connection, you do so, and then go back to the main loop. It's pretty simple when you let a lower-level library do the work for you :) The neat thing is, you can put all of this into a single program; I can't demo it in Python for you, but I have a Pike kernel that I wrote for my last job, which can handle a variety of different asynchronous operations: TCP, UDP (which just sends single packets, normally), a GUI (in theory), timers, the lot. It has convenience features for creating a DNS server, an HTTP server, and a stateful line-based server (covers lots of other protocols, like SMTP). And (though this bit would be hard to port to Python) it can update itself without shutting down. Yes, it can take some getting your head around, but it's well worth it. ChrisA From frank at chagford.com Thu Apr 10 07:10:54 2014 From: frank at chagford.com (Frank Millman) Date: Thu, 10 Apr 2014 13:10:54 +0200 Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: "Chris Angelico" wrote in message news:CAPTjJmoWaHPZk=DAxbfJ=9ez2aj=4yf2C8WMbRYoF5VgN6Exsw at mail.gmail.com... > On Thu, Apr 10, 2014 at 7:17 PM, Frank Millman wrote: >> The current version of my program uses HTTP. As I understand it, a client >> makes a connection and submits a request. The server processes the >> request >> and returns a result. The connection is then closed. >> >> In this scenario, does async apply at all? There is no open connection to >> 'select' or 'poll'. You have to ensure that the request handler does not >> block the entire process, so that the main loop is ready to accept more >> connections. But passing the request to a thread for handling seems an >> effective solution. > [...] Thanks, Chris - I am learning a lot! I have skipped the first part of your reply, as it seems to refer to the client. I am using a web browser as a client, so I don't have to worry about programming that. > > When you write the server, you effectively have the same principle, > with one additional feature: a listening socket becomes readable > whenever someone connects. So you can select() on that socket, just > like you can with the others, and whenever there's a new connection, > you add it to the collection and listen for requests on all of them. > It's basically the same concept; as soon as you can accept a new > connection, you do so, and then go back to the main loop. > This is where it gets interesting. At present I am using cherrypy as a server, and I have not checked its internals. However, in the past I have dabbled with writing server programs like this - while self.running: try: conn,addr = self.s.accept() Session(args=(self, conn)).start() except KeyboardInterrupt: self.shutdown() In this scenario, the loop blocks on 'accept'. You seem to be suggesting that I set the socket to 'non-blocking', use select() to determine when a client is trying to connect, and then call 'accept' on it to create a new connection. If so, I understand your point. The main loop changes from 'blocking' to 'non-blocking', which frees it up to perform all kinds of other tasks as well. It is no longer just a 'web server', but becomes an 'all-purpose server'. Much food for thought! Frank From rosuav at gmail.com Thu Apr 10 07:19:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Apr 2014 21:19:16 +1000 Subject: threading In-Reply-To: References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: On Thu, Apr 10, 2014 at 9:10 PM, Frank Millman wrote: > You seem to be suggesting that I set the socket to 'non-blocking', use > select() to determine when a client is trying to connect, and then call > 'accept' on it to create a new connection. Right! That's about how it goes. Of course, for production work you'll want to wrap all that up for convenience, but fundamentally, that is what happens. ChrisA From marko at pacujo.net Thu Apr 10 07:43:23 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 10 Apr 2014 14:43:23 +0300 Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Message-ID: <87wqexmmuc.fsf@elektro.pacujo.net> "Frank Millman" : > You seem to be suggesting that I set the socket to 'non-blocking', use > select() to determine when a client is trying to connect, and then > call 'accept' on it to create a new connection. Yes. > If so, I understand your point. The main loop changes from 'blocking' > to 'non-blocking', which frees it up to perform all kinds of other > tasks as well. It is no longer just a 'web server', but becomes an > 'all-purpose server'. The server will do whatever you make it do. Other points: * When you wake up from select() (or poll(), epoll()), you should treat it as a hint. The I/O call (accept()) could still raise socket.error(EAGAIN). * The connections returned from accept() have to be individually registered with select() (poll(), epoll()). * When you write() into a connection, you may be able to send only part of the data or get EAGAIN. You need to choose a buffering strategy -- you should not block until all data is written out. Also take into account how much you are prepared to buffer. * There are two main modes of multiplexing: level-triggered and edge-triggered. Only epoll() (and kqueue()) support edge-triggered wakeups. Edge-triggered requires more discipline from the programmer but frees you from having to tell the multiplexing facility if you are interested in readability or writability in any given situation. Edge-triggered wakeups are only guaranteed after you have gotten an EAGAIN from an operation. Make sure you keep on reading/writing until you get an EAGAIN. On the other hand, watch out so one connection doesn't hog the process because it always has active I/O to perform. * You should always be ready to read to prevent deadlocks. * Sockets can be half-closed. Your state machines should deal with the different combinations gracefully. For example, you might read an EOF from the client socket before you have pushed the response out. You must not close the socket before the response has finished writing. On the other hand, you should not treat the half-closed socket as readable. * While a single-threaded process will not have proper race conditions, you must watch out for preemption. IOW, you might have Object A call a method of Object B, which calls some other method of Object A. Asyncio has a task queue facility. If you write your own main loop, you should also implement a similar task queue. The queue can then be used to make such tricky function calls in a safe context. * Asyncio provides timers. If you write your own main loop, you should also implement your own timers. Note that modern software has to tolerate suspension (laptop lid, virtual machines). Time is a tricky concept when your server wakes up from a coma. * Specify explicit states. Your connection objects should have a data member named "state" (or similar). Make your state transitions explicit and obvious in the code. In fact, log them. Resist the temptation of deriving the state implicitly from other object information. * Most states should be guarded with a timer. Make sure to document for each state, which timers are running. * In each state, check that you handle all possible events and timeouts. The state/transition matrix will be quite sizable even for seemingly simple tasks. Marko From wxjmfauth at gmail.com Thu Apr 10 07:47:57 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 10 Apr 2014 04:47:57 -0700 (PDT) Subject: Python and Unicode In-Reply-To: References: <9f3580c2-ef8c-4dcc-8dea-7eca3b242f15@googlegroups.com> Message-ID: <5d80d60c-dc0d-45a2-8cde-88fd600e42a8@googlegroups.com> Le mercredi 9 avril 2014 10:53:36 UTC+2, Mark Lawrence a ?crit?: > On 09/04/2014 09:07, wxjmfauth at gmail.com wrote: > > > Well, there is a (serious) problem somewhere... > > > > > > jmf > > > > > > > Look in a mirror and you'll see it as it'll be staring you in the face. > > > > -- > > My fellow Pythonistas, ask not what our language can do for you, ask > > what you can do for our language. > > > > Mark Lawrence > > > From steve+comp.lang.python at pearwood.info Thu Apr 10 08:07:31 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Apr 2014 12:07:31 GMT Subject: Language summit notes Message-ID: <53468982$0$29993$c3e8da3$5496439d@news.astraweb.com> Today in Montreal Canada, there was a Language Summit to discuss the future of Python. Some highlights: PyPy is only three bug fixes away from shipping support for Python 3.2! Guido confirms that easing the transition from 2.x to 3.x code is a major priority. Version 2.7 is alive and in good health and not ready to be retired yet, but he's still against releasing a version 2.8. Both IronPython and Jython hope to support Python 3 soon, Jython is being held back by a lack of contributors. Packaging is hard. Very hard. There is a lot of work going on to try to improve packaging. After five years experience in managing the transition between 2 and 3, the official recommendation is now the opposite of what it was five years ago: write a single code-base aimed at both 2 and 3, rather than trying to automate translation via 2to3 or other tools. There is a lot of interest for optional type checking. More in this email thread here: https://mail.python.org/pipermail/python-dev/2014-April/133873.html -- Steven D'Aprano http://import-that.dreamwidth.org/ From python.list at tim.thechases.com Thu Apr 10 08:51:48 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 10 Apr 2014 07:51:48 -0500 Subject: Python and Unicode In-Reply-To: <5d80d60c-dc0d-45a2-8cde-88fd600e42a8@googlegroups.com> References: <9f3580c2-ef8c-4dcc-8dea-7eca3b242f15@googlegroups.com> <5d80d60c-dc0d-45a2-8cde-88fd600e42a8@googlegroups.com> Message-ID: <20140410075148.544c5777@bigbox.christie.dr> On 2014-04-10 04:47, wxjmfauth at gmail.com wrote: > Le mercredi 9 avril 2014 10:53:36 UTC+2, Mark Lawrence a ?crit?: > > On 09/04/2014 09:07, wxjmfauth at gmail.com wrote: > > > > > Well, there is a (serious) problem somewhere... > > > jmf > > > > Look in a mirror and you'll see it as it'll be staring you in the > > face. Hmm...both members of the conversation posted provocative & inflammatory statements, but one provided a way to reproduce an problem... Is either issue one that the Python community cares about? Until the problem can be reproduced *and the solution doesn't cause more problems than the existing condition*, the answer is likely "no." -tkc From roy at panix.com Thu Apr 10 08:56:33 2014 From: roy at panix.com (Roy Smith) Date: Thu, 10 Apr 2014 08:56:33 -0400 Subject: threading References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> <87wqexmmuc.fsf@elektro.pacujo.net> Message-ID: In article <87wqexmmuc.fsf at elektro.pacujo.net>, Marko Rauhamaa wrote: > * When you wake up from select() (or poll(), epoll()), you should treat > it as a hint. The I/O call (accept()) could still raise > socket.error(EAGAIN). People often misunderstand what select() does. The common misconception is that a select()ed descriptor has data waiting to be read. What the man page says is, "A file descriptor is considered ready if it is possible to perform the corresponding I/O operation (e.g., read(2)) without blocking." Not blocking includes failing immediately. And, once you introduce threading, things get even more complicated. Imagine two threads, both waiting in a select() call on the same socket. Data comes in on that socket. Both select() calls return. If both threads then do reads on the socket, you've got a race condition. One of them will read the data. The other will block in the read call, because the data has already been read by the other thread! So, yes, as Marko says, use select() as a hint, but then also do your reads in non-blocking mode, and be prepared for them to fail, regardless of whether select() said the descriptor was ready. > Note that modern software has to tolerate suspension (laptop lid, > virtual machines). Time is a tricky concept when your server wakes up > from a coma. Not to mention running in a virtual machine. Time is an equally tricky concept when your hardware clock is really some other piece of software playing smoke and mirrors. I once worked on a time-sensitive system which was running in a VM. The idiots who had configured the thing were running ntpd in the VM, to keep its clock in sync. Normally, this is a good thing, but they were ALSO using the hypervisor's clock management gizmo (vmtools?) to adjust the VM clock. The two mechanisms were fighting with each other, which did really weird stuff to time. It took me forever to figure out what was going on. How does one even observe that time is moving around randomly? I eventually ended up writing a trivial NTP client in Python (it's only a few lines of code) and periodically logging the difference between the local system clock and what my NTP reference was telling me. Of course, figuring out what was going on was the easy part. Convincing the IT drones to fix the problem was considerably more difficult. > * In each state, check that you handle all possible events and > timeouts. The state/transition matrix will be quite sizable even for > seemingly simple tasks. And, those empty boxes in the state transition matrix which are blank, because those transitions are impossible? Guess what, they happen, and you better have a plan for when they do :-) From harrismh777 at gmail.com Thu Apr 10 09:29:44 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 10 Apr 2014 08:29:44 -0500 Subject: threading In-Reply-To: References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> <87lhveobeq.fsf@elektro.pacujo.net> <87k3ayl893.fsf@elektro.pacujo.net> Message-ID: <53469CC8.7080206@gmail.com> On 4/9/14 12:52 PM, Chris Angelico wrote: > People with a fear of threaded programming almost certainly never grew > up on OS/2. :) I learned about GUI programming thus: Write your > synchronous message handler to guarantee that it will return in an > absolute maximum of 0.1s, preferably a lot less. If you have any sort > of heavy processing to do, spin off a thread. heh very true. Any non trivial OS/2 GUI app required threads. We had a template at our shop that we gave to noobs for copy-n-tweak. It had not only the basics for getting the canvas on the screen with a tool bar and a button, but also the minimal code required to setup the thread to handle the button event (it was a database lookup in our case). From elearn2014 at gmail.com Thu Apr 10 09:54:40 2014 From: elearn2014 at gmail.com (length power) Date: Thu, 10 Apr 2014 21:54:40 +0800 Subject: why i have the output of [None, None, None] Message-ID: >>> x=['','x1','x2','x3',' '] >>> x ['', 'x1', 'x2', 'x3', ' '] >>> [print("ok") for it in x if it.strip() !=""] ok ok ok [None, None, None] i understand there are three 'ok' in the output,but why i have the output of [None, None, None] -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip at pobox.com Thu Apr 10 10:12:26 2014 From: skip at pobox.com (Skip Montanaro) Date: Thu, 10 Apr 2014 09:12:26 -0500 Subject: why i have the output of [None, None, None] In-Reply-To: References: Message-ID: The print function in Python 3 returns None. The "ok" output is a side effect. The actual value of evaluating that list comprehension is a list of three None values. Skip On Thu, Apr 10, 2014 at 8:54 AM, length power wrote: >>>> x=['','x1','x2','x3',' '] >>>> x > ['', 'x1', 'x2', 'x3', ' '] >>>> [print("ok") for it in x if it.strip() !=""] > ok > ok > ok > [None, None, None] > > i understand there are three 'ok' in the output,but why i have the output of > [None, None, None] > > -- > https://mail.python.org/mailman/listinfo/python-list > From bborcic at gmail.com Thu Apr 10 10:14:55 2014 From: bborcic at gmail.com (Boris Borcic) Date: Thu, 10 Apr 2014 16:14:55 +0200 Subject: how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ? In-Reply-To: References: Message-ID: Rustom Mody wrote: >>>> def fl1(l): return [y for x in l for y in x] > > > # recursive flatten >>>> def fr(l): > ... if not isinstance(l,list): return [l] > ... return fl1([fr(x) for x in l]) For a short non-recursive procedure - not a function, modifies L in-place but none of its sublists. >>> def flatten(L) : .... for k,_ in enumerate(L) : .... while isinstance(L[k],list) : .... L[k:k+1]=L[k] flattens L to any depth, eg >>> L=[1,[2,[3,4]],5,6,[[7],8]] >>> flatten(L) >>> L [1, 2, 3, 4, 5, 6, 7, 8] --- Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com From jpiitula at ling.helsinki.fi Thu Apr 10 10:18:12 2014 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 10 Apr 2014 17:18:12 +0300 Subject: why i have the output of [None, None, None] References: Message-ID: length power writes: > >>> x=['','x1','x2','x3',' '] > >>> x > ['', 'x1', 'x2', 'x3', ' '] > >>> [print("ok") for it in x if it.strip() !=""] > ok > ok > ok > [None, None, None] > > i understand there are three 'ok' in the output,but why i have the > output of [None, None, None] It's a list containing the values from three invocations of print. You get it because you asked for it. |>>> print("ok") == None |ok |True |>>> print("ok") != None |ok |False |>>> [(print("ok") or "die") for x in (1,2,3)] |ok |ok |ok |['die', 'die', 'die'] |>>> [print("ok") for x in (1,2,3)] and print("What do you want it to be?") |ok |ok |ok |What do you want it to be? |>>> (That last one actually returns None to the interpreter, which promptly does not print it.) From rustompmody at gmail.com Thu Apr 10 10:18:33 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 10 Apr 2014 07:18:33 -0700 (PDT) Subject: why i have the output of [None, None, None] In-Reply-To: References: Message-ID: <757dd9bf-8207-4bdd-bafc-f35169db1a27@googlegroups.com> This is called imperative programming: for it in x: ... if it.strip() != '': ... print ("Ok") This is called functional programming: >>> [y for y in x if y.strip() != ''] ['x1', 'x2', 'x3'] What you have is a confusion: print is imperative comprehension is functional You should not mix them like that From johannes.schneider at galileo-press.de Thu Apr 10 09:59:48 2014 From: johannes.schneider at galileo-press.de (Johannes Schneider) Date: Thu, 10 Apr 2014 15:59:48 +0200 Subject: why i have the output of [None, None, None] In-Reply-To: References: Message-ID: <5346A3D4.9030507@galileo-press.de> because thats the return value of [...] print retuns None. On 10.04.2014 15:54, length power wrote: > >>> x=['','x1','x2','x3',' '] > >>> x > ['', 'x1', 'x2', 'x3', ' '] > >>> [print("ok") for it in x if it.strip() !=""] > ok > ok > ok > [None, None, None] > > i understand there are three 'ok' in the output,but why i have the > output of [None, None, None] > > -- Johannes Schneider Webentwicklung johannes.schneider at galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Gesch?ftsf?hrer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn From bborcic at gmail.com Thu Apr 10 10:40:32 2014 From: bborcic at gmail.com (Boris Borcic) Date: Thu, 10 Apr 2014 16:40:32 +0200 Subject: how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ? In-Reply-To: References: Message-ID: Boris Borcic wrote: > Rustom Mody wrote: >>>>> def fl1(l): return [y for x in l for y in x] >> >> >> # recursive flatten >>>>> def fr(l): >> ... if not isinstance(l,list): return [l] >> ... return fl1([fr(x) for x in l]) > > For a short non-recursive procedure - not a function, modifies L in-place but none of its sublists. > > >>> def flatten(L) : > .... for k,_ in enumerate(L) : > .... while isinstance(L[k],list) : > .... L[k:k+1]=L[k] > > flattens L to any depth, eg > > >>> L=[1,[2,[3,4]],5,6,[[7],8]] > >>> flatten(L) > >>> L > [1, 2, 3, 4, 5, 6, 7, 8] Mh, this will fail though if the last item (of the last item (of the...)) is an empty list, eg L=[[]]. If you want to cover this case you can wrap the inside of the proc with a try except IndexError: pass, in which case you can also simplify the enumerate(L) to an indefinite counter. Or insert a dummy value before starting and pop it off at the end. --- Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com From sturla.molden at gmail.com Thu Apr 10 11:24:46 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Thu, 10 Apr 2014 15:24:46 +0000 (UTC) Subject: threading References: <87wqexmmuc.fsf@elektro.pacujo.net> Message-ID: <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> Marko Rauhamaa wrote: > Other points: > > * When you wake up from select() (or poll(), epoll()), you should treat > it as a hint. The I/O call (accept()) could still raise > socket.error(EAGAIN). > > * The connections returned from accept() have to be individually > registered with select() (poll(), epoll()). > > * When you write() into a connection, you may be able to send only part > of the data or get EAGAIN. You need to choose a buffering strategy -- > you should not block until all data is written out. Also take into > account how much you are prepared to buffer. > > * There are two main modes of multiplexing: level-triggered and > edge-triggered. Only epoll() (and kqueue()) support edge-triggered > wakeups. Edge-triggered requires more discipline from the programmer > but frees you from having to tell the multiplexing facility if you > are interested in readability or writability in any given situation. > > Edge-triggered wakeups are only guaranteed after you have gotten an > EAGAIN from an operation. Make sure you keep on reading/writing until > you get an EAGAIN. On the other hand, watch out so one connection > doesn't hog the process because it always has active I/O to perform. > > * You should always be ready to read to prevent deadlocks. > > * Sockets can be half-closed. Your state machines should deal with the > different combinations gracefully. For example, you might read an EOF > from the client socket before you have pushed the response out. You > must not close the socket before the response has finished writing. > On the other hand, you should not treat the half-closed socket as > readable. > > * While a single-threaded process will not have proper race conditions, > you must watch out for preemption. IOW, you might have Object A call > a method of Object B, which calls some other method of Object A. > Asyncio has a task queue facility. If you write your own main loop, > you should also implement a similar task queue. The queue can then be > used to make such tricky function calls in a safe context. > > * Asyncio provides timers. If you write your own main loop, you should > also implement your own timers. > > Note that modern software has to tolerate suspension (laptop lid, > virtual machines). Time is a tricky concept when your server wakes up > from a coma. > > * Specify explicit states. Your connection objects should have a data > member named "state" (or similar). Make your state transitions > explicit and obvious in the code. In fact, log them. Resist the > temptation of deriving the state implicitly from other object > information. > > * Most states should be guarded with a timer. Make sure to document for > each state, which timers are running. > > * In each state, check that you handle all possible events and > timeouts. The state/transition matrix will be quite sizable even for > seemingly simple tasks. And exactly how is getting all of this correct any easier than just using threads and blocking i/o? I'd like to see the programmer who can get all of this correct, but has no idea how to use a queue og mutex without deadlocking. Sturla From rosuav at gmail.com Thu Apr 10 11:32:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Apr 2014 01:32:56 +1000 Subject: threading In-Reply-To: <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> Message-ID: On Fri, Apr 11, 2014 at 1:24 AM, Sturla Molden wrote: > And exactly how is getting all of this correct any easier than just using > threads and blocking i/o? For a start, nearly everything Marko just posted should be dealt with by your library. I don't know Python's asyncio as it's very new and I haven't yet found an excuse to use it, but with Pike, I just engage backend mode, set callbacks on the appropriate socket/file/port objects, and let things happen perfectly. All I need to do is check a few return values (eg if I ask a non-blocking socket to write a whole pile of data, it might return that it wrote only some of it, in which case I have to buffer the rest - not hard but has to be done), and make sure I always return promptly from my callbacks so as to avoid lagging out other operations. None of the details of C-level APIs matter to my high level code. ChrisA From lalithaprasad at gmail.com Thu Apr 10 11:54:48 2014 From: lalithaprasad at gmail.com (Lalitha Prasad K) Date: Thu, 10 Apr 2014 21:24:48 +0530 Subject: Teaching python to non-programmers Message-ID: Dear List Recently I was requested to teach python to a group of students of GIS (Geographic Information Systems). Their knowledge of programming is zero. The objective is to enable them to write plug-ins for GIS software like QGIS and ArcGIS. It would require them to learn, besides core python, PyQt, QtDesigner. So my plan is to teach them core python, PyQt, Qt Designer, in that order. A kind of "bottom up approach". But the students seem to feel that I should use "top down approach". That is, show them how to write a plug-in, then PyQt and Qt Designer and then enough of python so they can handle the above. I don't think, that is possible or a good idea. But I would like to know, if there are any other approaches. Thanks and Regards Lalitha Prasad, -------------- next part -------------- An HTML attachment was scrubbed... URL: From marko at pacujo.net Thu Apr 10 12:20:34 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 10 Apr 2014 19:20:34 +0300 Subject: threading References: <87wqexmmuc.fsf@elektro.pacujo.net> Message-ID: <87ppkpma0d.fsf@elektro.pacujo.net> Sturla Molden : > And exactly how is getting all of this correct any easier than just > using threads and blocking i/o? > > I'd like to see the programmer who can get all of this correct, but > has no idea how to use a queue og mutex without deadlocking. My personal experience is that it is easier to get "all of this correct" than threads. I've done it both ways. Marko From marko at pacujo.net Thu Apr 10 12:25:03 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 10 Apr 2014 19:25:03 +0300 Subject: threading References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> Message-ID: <87lhvdm9sw.fsf@elektro.pacujo.net> Chris Angelico : > For a start, nearly everything Marko just posted should be dealt with > by your library. Let's not kid ourselves: it is hard to get any reactive system right. > I don't know Python's asyncio as it's very new and I haven't yet found > an excuse to use it, but with Pike, I just engage backend mode, set > callbacks on the appropriate socket/file/port objects, and let things > happen perfectly. That "set callbacks" and "let things happen" is the hard part. The framework part is trivial. Marko From rosuav at gmail.com Thu Apr 10 13:08:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Apr 2014 03:08:49 +1000 Subject: threading In-Reply-To: <87lhvdm9sw.fsf@elektro.pacujo.net> References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> Message-ID: On Fri, Apr 11, 2014 at 2:25 AM, Marko Rauhamaa wrote: >> I don't know Python's asyncio as it's very new and I haven't yet found >> an excuse to use it, but with Pike, I just engage backend mode, set >> callbacks on the appropriate socket/file/port objects, and let things >> happen perfectly. > > That "set callbacks" and "let things happen" is the hard part. The > framework part is trivial. Maybe. Here's a simple self-contained Pike program that makes a simple echo server - whatever comes in goes out again: //Create the port (listening connection). object mainsock=Stdio.Port(12345,accept_callback); void accept_callback() { //Get the newly-connected socket object sock=mainsock->accept(); //Set up its callbacks sock->set_nonblocking(read_callback, write_callback, close_callback); //Keep track of metadata (here that'll just be the write buffer) sock->set_id((["sock":sock])); } //Attempt to write some text, buffering any that can't be written void write(mapping info, string text) { if (!text || text=="") return; if (info->write_me) { //There's already buffered text. Queue this text too. info->write_me += text; return; } int written = info->sock->write(text); if (written < 0) { //Deal with write errors brutally by closing the socket. info->sock->close(); return; } info->write_me = text[written..]; } //When more can be written, write it. void write_callback(mapping info) {write(info, m_delete(info,"write_me"));} void read_callback(mapping info, string data) { //Simple handling: Echo the text back with a prefix. //Note that this isn't line-buffered or anything. write(info, ">> " + data); } //Not strictly necessary, but if you need to do something when a client //disconnects, this is where you'd do it. void close_callback(mapping info) { info->sock = "(disconnected)"; } //Engage backend mode. int main() {return -1;} Setting callbacks? One line. There's a little complexity to the "write what you can, buffer the rest", but if you're doing anything even a little bit serious, you'll just bury that away in a mid-level library function. The interesting part is in the read callback, which does the actual work (in this case, it just writes back whatever it gets). And here's how easy it is to make it into a chat server: just replace the read and close callbacks with these: multiset(mapping) sockets=(<>); void read_callback(mapping info, string data) { //Simple handling: Echo the text back with a prefix. //Note that this isn't line-buffered or anything. sockets[info] = 1; write(indices(sockets)[*], ">> " + data); } //Not strictly necessary, but if you need to do something when a client //disconnects, this is where you'd do it. void close_callback(mapping info) { info->sock = "(disconnected)"; sockets[info] = 0; } If you want to handle more information (maybe get users to log in?), you just stuff more stuff into the info mapping (it's just like a Python dict). Handling of TELNET negotiation, line buffering, etc, etc, can all be added between this and the user-level code - that's what I did with the framework I wrote for work. Effectively, you just write one function (I had it double as the read and close callbacks for simplicity), put a declaration down the bottom to say what port number you want (hard coded to 12345 in the above code), and everything just happens. It really isn't hard to get callback-based code to work nicely if you think about what you're doing. I expect it'll be similarly simple with asyncio; does someone who's worked with it feel like implementing similar functionality? ChrisA From pete.bee.emm at gmail.com Thu Apr 10 13:36:46 2014 From: pete.bee.emm at gmail.com (pete.bee.emm at gmail.com) Date: Thu, 10 Apr 2014 10:36:46 -0700 (PDT) Subject: how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ? In-Reply-To: References: Message-ID: I've been using compiler.ast.flatten, but I have comments indicating it will need be replaced if/when I move to Python 3. I don't pollute my code base with flatten, I just call my own version in my utility library that is currently redirecting to flatten. flatten works equally well with tuples as lists and I'm going to remain consistent with that. My version returns a tuple as well. My love affair with the immutable, hashable, and wonderfully named tuple is perhaps something that needs its own thread, or private room. On Wednesday, April 9, 2014 10:14:49 PM UTC-7, length power wrote: > >>> x=["a","b",["c","d"],"e"] > >>> y=x[2] > >>> y > ['c', 'd'] > >>> x.insert(2,y[0]) > >>> x > > ['a', 'b', 'c', ['c', 'd'], 'e'] > >>> x.insert(3,y[1]) > >>> x > ['a', 'b', 'c', 'd', ['c', 'd'], 'e'] > > >>> del x[4] > >>> x > ['a', 'b', 'c', 'd', 'e'] > >>> > maybe there is a more smart way to do. From pete.bee.emm at gmail.com Thu Apr 10 13:53:30 2014 From: pete.bee.emm at gmail.com (pete.bee.emm at gmail.com) Date: Thu, 10 Apr 2014 10:53:30 -0700 (PDT) Subject: Teaching python to non-programmers In-Reply-To: References: Message-ID: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> Don't underestimate the value of morale. Python is a scripting language. You don't need to teach them very much python to get something working, and you can always revisit the initial code and refactor it for better coding hygiene. Someday they might have jobs, and be required to learn things in more of a top down order. ;) On Thursday, April 10, 2014 8:54:48 AM UTC-7, Lalitha Prasad K wrote: > Dear List > > Recently I was requested to teach python to a group of students of GIS (Geographic Information Systems). Their knowledge of programming is zero. The objective is to enable them to write plug-ins for GIS software like QGIS and ArcGIS. It would require them to learn, besides core python, PyQt, QtDesigner. So my plan is to teach them core python, PyQt, Qt Designer, in that order. A kind of "bottom up approach". But the students seem to feel that I should use "top down approach". That is, show them how to write a plug-in, then PyQt and Qt Designer and then enough of python so they can handle the above. I don't think, that is possible or a good idea. But I would like to know, if there are any other approaches. > > > > Thanks and Regards > > > > > > > Lalitha Prasad,? From tjreedy at udel.edu Thu Apr 10 14:00:58 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 10 Apr 2014 14:00:58 -0400 Subject: why i have the output of [None, None, None] In-Reply-To: References: Message-ID: On 4/10/2014 9:54 AM, length power wrote: > >>> x=['','x1','x2','x3',' '] > >>> x > ['', 'x1', 'x2', 'x3', ' '] > >>> [print("ok") for it in x if it.strip() !=""] Don't use comprehensions for side effects. To get what you want, just write normal code. for it in x: if it.strip() != '': print('ok') > ok > ok > ok > [None, None, None] > > i understand there are three 'ok' in the output,but why i have the > output of [None, None, None] Reread the ref manual section on comprehensions. -- Terry Jan Reedy From rustompmody at gmail.com Thu Apr 10 14:14:36 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 10 Apr 2014 11:14:36 -0700 (PDT) Subject: threading In-Reply-To: References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> Message-ID: <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> On Thursday, April 10, 2014 10:38:49 PM UTC+5:30, Chris Angelico wrote: > On Fri, Apr 11, 2014 at 2:25 AM, Marko Rauhamaa wrote: > >> I don't know Python's asyncio as it's very new and I haven't yet found > >> an excuse to use it, but with Pike, I just engage backend mode, set > >> callbacks on the appropriate socket/file/port objects, and let things > >> happen perfectly. > > > > That "set callbacks" and "let things happen" is the hard part. The > > framework part is trivial. > > Maybe. Here's a simple self-contained Pike program that makes a simple > echo server - whatever comes in goes out again: > For analogy let me take a 'thought-discussion' between a C programmer and a python programmer regarding data structures. ----------------------------------------------------- PP: Is it not tedious and error prone, C's use of data structures? How/Why do you stick to that? CP: Oh! Is it? And what do you propose I use? PP: Why python of course! Or any modern language with first class data and garbage collection! Why spend a lifetime tracking malloc errors?! CP: Oh! is it? And what is python implemented in? PP: But thats the whole point! Once Guido-n-gang have done their thing we are unscathed by the bugs that prick and poke and torment you day in day out. CP: Lets look at this in more detail shall we? PP: Very well CP: You give me any python data structure (so-called) and I'll give it to you in C. And note: Its very easy. I just open up the python implementation (its in C in case you forgot) and clean up all the mess that has been added for the support of lazy python programmers. In addition, I'll give you a couple of more data-structures/algorithms that we have easy access to but for you, your only choice is to drop into C to use (HeHe!) PP: You are setting the rules of the game... and winning. I did not say I want fancy algorithms and data structures. I said I want (primarily) the safety of garbage collection. Its also neat to have an explicit syntax for basic data types like lists rather than scrummaging around with struct and malloc and pointers (hoo boy!) CP: Yeah.. Like I said you like to be mollycoddled; we like our power and freedom ----------------------------------------------- If I may use somewhat heavy brush-strokes: Marco (and evidently Chris) are in the CP camp whereas Sturla is in the PP camp. Its just the 'data-structures (and algorithms)' is now replaced by 'concurrency' Both these viewpoints assume that the status quo of current (mainstream) language support for concurrency is a given and not negotiable. Erlang/Go etc disprove this. From me at eddy-ilg.net Thu Apr 10 09:24:07 2014 From: me at eddy-ilg.net (Eddy Ilg) Date: Thu, 10 Apr 2014 15:24:07 +0200 Subject: so module loading fails Message-ID: <53469B77.50007@eddy-ilg.net> Hi, I am trying to get PyQt5 to work. I already posted on their list but with no luck and since the question is rather general I am reposting it here: I built my own module "Entity.so". Trying to import it yields the following error: Python 3.4.0 (default, Apr 8 2014, 22:02:32) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import Entity Traceback (most recent call last): File "", line 1, in ImportError: dynamic module does not define init function (PyInit_Entity) >>> Checking the symbols of Entity.so gives: # nm Entity.so | grep PyInit_Entity 0000000000001e5c t PyInit_Entity 0000000000206850 b _ZZ13PyInit_EntityE11sip_methods 00000000002062c0 d _ZZ13PyInit_EntityE14sip_module_def Thus, the symbols exist. Why doesn't python find them? How can I find out more about where locating the symbols fails? Best, Eddy From rustompmody at gmail.com Thu Apr 10 14:24:59 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 10 Apr 2014 11:24:59 -0700 (PDT) Subject: Teaching python to non-programmers In-Reply-To: References: Message-ID: <68f96703-4a7d-44ff-8a72-51cb6f145ca9@googlegroups.com> On Thursday, April 10, 2014 9:24:48 PM UTC+5:30, Lalitha Prasad K wrote: > Dear List > > Recently I was requested to teach python to a group of students of GIS (Geographic Information Systems). Their knowledge of programming is zero. The objective is to enable them to write plug-ins for GIS software like QGIS and ArcGIS. It would require them to learn, besides core python, PyQt, QtDesigner. So my plan is to teach them core python, PyQt, Qt Designer, in that order. A kind of "bottom up approach". But the students seem to feel that I should use "top down approach". That is, show them how to write a plug-in, then PyQt and Qt Designer and then enough of python so they can handle the above. I don't think, that is possible or a good idea. But I would like to know, if there are any other approaches. > > > Thanks and Regards Theres a Mulla Nassr Eddin story: Villagers A and B had a dispute. They went to Mulla. A gave his harangue for a while... Mulla: You are right! The B came and gave his story Mulla (to B) You are right Mulla's wife (scratching her head): But Mulla?! Both cant be right?!?! Mulla: You are right. When you are a teacher you have to learn to say "Yes Yes!" to all sorts of demands -- from curriculum, boards, colleagues, and of course students And then keep on doing what you know is right! I have some writings on the stupidities of CS edu establishment http://blog.languager.org/2011/02/cs-education-is-fat-and-weak-1.html and following From breamoreboy at yahoo.co.uk Thu Apr 10 14:36:35 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 10 Apr 2014 19:36:35 +0100 Subject: Teaching python to non-programmers In-Reply-To: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> Message-ID: On 10/04/2014 18:53, pete.bee.emm at gmail.com wrote: > Don't underestimate the value of morale. Python is a scripting language. You don't need to teach them very much python to get something working, and you can always revisit the initial code and refactor it for better coding hygiene. > > Someday they might have jobs, and be required to learn things in more of a top down order. ;) > > On Thursday, April 10, 2014 8:54:48 AM UTC-7, Lalitha Prasad K wrote: >> Dear List >> >> Recently I was requested to teach python to a group of students of GIS (Geographic Information Systems). Their knowledge of programming is zero. The objective is to enable them to write plug-ins for GIS software like QGIS and ArcGIS. It would require them to learn, besides core python, PyQt, QtDesigner. So my plan is to teach them core python, PyQt, Qt Designer, in that order. A kind of "bottom up approach". But the students seem to feel that I should use "top down approach". That is, show them how to write a plug-in, then PyQt and Qt Designer and then enough of python so they can handle the above. I don't think, that is possible or a good idea. But I would like to know, if there are any other approaches. >> >> >> >> Thanks and Regards >> >> >> >> >> >> >> Lalitha Prasad, Just awesome, not only do we have double line spacing and single line paragraphs, we've also got top posting, oh boy am I a happy bunny :) I'll leave someone3 else to explain, I just can't be bothered. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From john_ladasky at sbcglobal.net Thu Apr 10 14:52:31 2014 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Thu, 10 Apr 2014 11:52:31 -0700 (PDT) Subject: Method(s) called by square brackets, slice objects In-Reply-To: <74d6fb5c-baca-4606-9fa8-66238a561e0c@googlegroups.com> References: <74d6fb5c-baca-4606-9fa8-66238a561e0c@googlegroups.com> Message-ID: Thanks to both Ethan and Steven for their replies. Steven: I was trying to use the interpreter and wasn't getting results that I understood -- because I didn't know that __getslice__ was simply gone in Python 3. I implemented a __getslice__ method in my subclass that never got called. Ethan: I saw that slice objects were being sent to __getitem__, but that confused me as I thought that its purpose, as implied by the method name, was to return a SINGLE item. OK, I think that I've got all that sorted out! From breamoreboy at yahoo.co.uk Thu Apr 10 15:12:52 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 10 Apr 2014 20:12:52 +0100 Subject: Sorted Containers Message-ID: I've just chanced upon this and thought it might be of interest to some of you, haven't tried it myself http://www.grantjenks.com/docs/sortedcontainers/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From marko at pacujo.net Thu Apr 10 15:44:01 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 10 Apr 2014 22:44:01 +0300 Subject: threading References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> Message-ID: <87wqexj7ge.fsf@elektro.pacujo.net> Rustom Mody : > Marco (and evidently Chris) are in the CP camp whereas Sturla is in > the PP camp. Its just the 'data-structures (and algorithms)' is now > replaced by 'concurrency' > > Both these viewpoints assume that the status quo of current > (mainstream) language support for concurrency is a given and not > negotiable. I think you misread me (us?). I'm not trying to make life hard on myself. Nor am I disparaging fitting abstractions and high-level utilities. Threads are an essential tool when used appropriately. However, I do believe the 90's fad of treating them like a silver bullet of concurrency was a big mistake. The industry is noticing it, as is evident in NIO and asyncio. Threads are enticing in that they make it quick to put together working prototypes. The difficulties only appear when it's too late to go back. They definitely are not the high-level abstraction you're looking for. > Erlang/Go etc disprove this. : n a + b Sir, ------ = x, hence God exists?reply! n Seriously, Erlang (and Go) have nice tools for managing state machines and concurrency. However, Python (and C) are perfectly suitable for clear asynchronous programming idioms. I'm happy that asyncio is happening after all these long years. It would be nice if it supported edge-triggered wakeups, but I suppose that isn't supported in all operating systems. Marko From solipsis at pitrou.net Thu Apr 10 15:57:57 2014 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 10 Apr 2014 19:57:57 +0000 (UTC) Subject: imaplib: how to specify SSL/TLS protocol version? References: Message-ID: Grant Edwards invalid.invalid> writes: > > Experiments show that when calling ssl.wrap_socket() I have to specify > ssl_version=PROTOCOL_TLSv1 to avoid the above error. > > How do I tell imaplib to use TLS1 instead of SSL3? Use Python 3 and pass the ssl_context parameter to IMAP_SSL: https://docs.python.org/3.3/library/imaplib.html#imaplib.IMAP4_SSL Regards Antoine. From rustompmody at gmail.com Thu Apr 10 16:21:53 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 10 Apr 2014 13:21:53 -0700 (PDT) Subject: threading In-Reply-To: <87wqexj7ge.fsf@elektro.pacujo.net> References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> <87wqexj7ge.fsf@elektro.pacujo.net> Message-ID: <685d594b-c31b-4629-b81d-4aa64d9e3394@googlegroups.com> On Friday, April 11, 2014 1:14:01 AM UTC+5:30, Marko Rauhamaa wrote: > > > Seriously, Erlang (and Go) have nice tools for managing state machines > and concurrency. However, Python (and C) are perfectly suitable for > clear asynchronous programming idioms. I'm happy that asyncio is > happening after all these long years. It would be nice if it supported > edge-triggered wakeups, but I suppose that isn't supported in all > operating systems. > Yes... Let me restate what (I hear you as) saying Lets start with pure uniprocessor machines for ease of discussion (also of history) An OS, sits between the uni-hardware and provides multi{processing,users,threads,etc}. How does it do it? By the mechanisms process-switching, interleaving etc In short all the good-stuff... that constitutes asyncio (and relations) What you are saying is that what the OS is doing, you can do better. Analogous to said C programmer saying that what (data structures) the python programmer can make he can do better. Note I dont exactly agree with Sturla either. To see that time-shift the C/Python argument 30 years back when it was imperative languages vs poorly implemented, buggy, interpreted Lisp/Prolog. In that world, your 'I'd rather do it by hand/work out my state machine' would make considerable sense. Analogously, if the only choice were mainstream (concurrency-wise) languages -- C/C++/Java/Python -- + native threads + overheads + ensuing errors/headaches, then the: "Please let me work out my state machine and manage my affairs" would be sound. But its not the only choice!! > http://en.wikipedia.org/wiki/Leonhard_Euler#Personal_philosophy_and_religious_beliefs > > n > a + b > Sir, ------ = x, hence God exists--reply! > n I always thought that God exists because was e^(ipi) + 1 = 0 :D Evidently (s)he has better reasons for existing! From info at egenix.com Thu Apr 10 16:44:40 2014 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Thu, 10 Apr 2014 22:44:40 +0200 Subject: ANN: eGenix pyOpenSSL Distribution 0.13.3.1.0.1.7 Message-ID: <534702B8.3020302@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com pyOpenSSL Distribution Version 0.13.3.1.0.1.7 An easy-to-install and easy-to-use distribution of the pyOpenSSL Python interface for OpenSSL - available for Windows, Mac OS X and Unix platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.13.3.1.0.1.7.html ________________________________________________________________________ INTRODUCTION The eGenix.com pyOpenSSL Distribution includes everything you need to get started with SSL in Python. It comes with an easy-to-use installer that includes the most recent OpenSSL library versions in pre-compiled form, making your application independent of OS provided OpenSSL libraries: http://www.egenix.com/products/python/pyOpenSSL/ pyOpenSSL is an open-source Python add-on that allows writing SSL/TLS- aware network applications as well as certificate management tools: https://launchpad.net/pyopenssl/ OpenSSL is an open-source implementation of the SSL/TLS protocol: http://www.openssl.org/ ________________________________________________________________________ NEWS This new release of the eGenix.com pyOpenSSL Distribution updates only the included OpenSSL version to address a serious bug in OpenSSL 1.0.1 versions: New in OpenSSL -------------- * Updated included OpenSSL libraries from OpenSSL 1.0.1e to 1.0.1f. See http://www.openssl.org/news/news.html and http://www.openssl.org/news/vulnerabilities.html for a complete list of changes, most important: - CVE-2014-0160 ("Heartbleed Bug"): A missing bounds check in the handling of the TLS heartbeat extension can be used to reveal up to 64kB of memory to a connected client or server. This issue did not affect versions of OpenSSL prior to 1.0.1. For information, also have a look at the Heartbeet Bug website: http://heartbleed.com/ As always, we provide binaries that include both pyOpenSSL and the necessary OpenSSL libraries for all supported platforms: Windows x86 and x64, Linux x86 and x64, Mac OS X PPC, x86 and x64. We've also added egg-file distribution versions of our eGenix.com pyOpenSSL Distribution for Windows, Linux and Mac OS X to the available download options. These make setups using e.g. zc.buildout and other egg-file based installers a lot easier. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/pyOpenSSL/ ________________________________________________________________________ UPGRADING Before installing this version of pyOpenSSL, please make sure that you uninstall any previously installed pyOpenSSL version. Otherwise, you could end up not using the included OpenSSL libs. _______________________________________________________________________ SUPPORT Commercial support for these packages is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. ________________________________________________________________________ MORE INFORMATION For more information about the eGenix pyOpenSSL Distribution, licensing and download instructions, please visit our web-site or write to sales at egenix.com. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From marko at pacujo.net Thu Apr 10 16:44:42 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 10 Apr 2014 23:44:42 +0300 Subject: threading References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> <87wqexj7ge.fsf@elektro.pacujo.net> <685d594b-c31b-4629-b81d-4aa64d9e3394@googlegroups.com> Message-ID: <87sipkkj7p.fsf@elektro.pacujo.net> Rustom Mody : > What you are saying is that what the OS is doing, you can do better. > Analogous to said C programmer saying that what (data structures) the > python programmer can make he can do better. I'm sorry, but I don't quite follow you there. I see the regular multithreaded approach as (1) oversimplification which makes it difficult to extend the design and handle all of the real-world contingencies (2) inviting race conditions carelessly--no mortal is immune. Marko From pete.bee.emm at gmail.com Thu Apr 10 16:52:53 2014 From: pete.bee.emm at gmail.com (pete.bee.emm at gmail.com) Date: Thu, 10 Apr 2014 13:52:53 -0700 (PDT) Subject: Teaching python to non-programmers In-Reply-To: References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> Message-ID: <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> > > Just awesome, not only do we have double line spacing and single line > > paragraphs, we've also got top posting, oh boy am I a happy bunny :) > > I'll leave someone3 else to explain, I just can't be bothered. > > Do you get paid to be a jerk, or is it just for yuks? If the latter, you're not funny. From 3kywjyds5d at snkmail.com Thu Apr 10 17:15:44 2014 From: 3kywjyds5d at snkmail.com (Lucas Malor) Date: Thu, 10 Apr 2014 21:15:44 +0000 Subject: Yet Another Switch-Case Syntax Proposal Message-ID: <18633-1397164544-649424@sneakemail.com> On 6 April 2014 20:07, Chris Angelico rosuav-at-gmail.com |python-list at python.org| wrote: > Here's a simpler form of the proposal, which might cover what you > need. It's basically a short-hand if/elif tree. > > case expression comp_op expression: > suite > case [comp_op] expression: > suite > .... > else: > suite I like this solution, but I tought about a simpler one. Basically it's my first proposal with two modifications: 1. case / elcase instead of continue, as before 2. if the case expression is a *tuple* (and not any one iterable), case suite is executed if the switched expression is an element of the tuple. If you want to match exactly a tuple, you have simply to put it into another tuple of length 1. Tricky but too much rare to care about. To recap: switch_stmt ::= "switch" expression "case" expression_list ":" suite ("case" | "elcase" expression_list ":" suite)* ["else" ":" suite] 1. if expression_list is a tuple, the case suite will be executed if the switch expression is a member of the tuple. 2. if expression_list is not a tuple, the case suite will be executed if the switch expression is equal Example: briefing_days = ("Tue", "Thu") normal_days = ("Mon", "Wed", "Fri") switch day normal_days + briefing_days: go_to_work = True day_type = "weekday" case normal_days: lunch_time = datetime.time(12) meeting_time = datetime.time(14) elcase briefing_days: lunch_time = datetime.time(11, 30) meeting_time = datetime.time(12, 30) else: go_to_work = False day_type = "festive" lunch_time = None meeting_time =None Another example: switch tarot case 0: card = "Fool" case 1: card = "Alan Moore" case 2: card = "High Priestess" etc. From rhodri at wildebst.org.uk Thu Apr 10 18:01:50 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Thu, 10 Apr 2014 23:01:50 +0100 Subject: Unpacking U-Boot image file References: <6ed343e7-fa02-426a-a75f-3e1d164a6a61@googlegroups.com> Message-ID: On Wed, 09 Apr 2014 18:18:56 +0100, Rustom Mody wrote: > On Wednesday, April 9, 2014 9:36:40 PM UTC+5:30, trewio wrote: >> How to extract files from U-Boot image file, LZMA-compressed? >> >> Is there a Python script that can do this properly? > > For lzma theres this (recent) python library > https://docs.python.org/dev/library/lzma.html > > Though you might just be better off with the command-line xz unxz etc > > After that.. whats the U-boot format? The Fine Manual (http://www.denx.de/wiki/view/DULG/UBootImages) isn't very forthcoming, sadly; "U-Boot operates on "image" files which can be basically anything, preceeded by a special header; see the definitions in include/image.h for details; basically, the header defines the following image properties * Target Operating System * Target CPU Architecture * Compression Type * Load Address * Entry Point * Image Name * Image Timestamp" I suspect taking this apart may be a little involved. -- Rhodri James *-* Wildebeest Herder to the Masses From tjreedy at udel.edu Thu Apr 10 18:20:22 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 10 Apr 2014 18:20:22 -0400 Subject: Method(s) called by square brackets, slice objects In-Reply-To: References: <74d6fb5c-baca-4606-9fa8-66238a561e0c@googlegroups.com> Message-ID: On 4/10/2014 2:52 PM, John Ladasky wrote: > Thanks to both Ethan and Steven for their replies. > > Steven: I was trying to use the interpreter and wasn't getting results that I understood -- because I didn't know that __getslice__ was simply gone in Python 3. I implemented a __getslice__ method in my subclass that never got called. > > Ethan: I saw that slice objects were being sent to __getitem__, but that confused me as I thought that its purpose, as implied by the method name, was to return a SINGLE item. A slice is a single sequence object. Sequences can result from any of index lookup, key lookup, or slicings. The backstory is that slicing originally supported only start and stop positions. The 3 __xyzslice__ had separate start and stop parameters instead of the 1 index/key parameter of __xyzitem__. Strides and the slice class were introduced for the benefit of numerical python. When they were 'mainstreamed' into regular python, the __xyzslice__ methods were deprecated (in 2.0) as a single slice object can just as well be passed to __xyzitem__. -- Terry Jan Reedy From rhodri at wildebst.org.uk Thu Apr 10 18:40:22 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Thu, 10 Apr 2014 23:40:22 +0100 Subject: Teaching python to non-programmers References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> Message-ID: On Thu, 10 Apr 2014 21:52:53 +0100, wrote: > >> >> Just awesome, not only do we have double line spacing and single line >> >> paragraphs, we've also got top posting, oh boy am I a happy bunny :) >> >> I'll leave someone3 else to explain, I just can't be bothered. >> >> > > Do you get paid to be a jerk, or is it just for yuks? If the latter, > you're not funny. It's called irony, and unfortunately Mark is reacting to an all-to-common situation that GoogleGroups foists on unsuspecting posters like yourself. It's the result of a fundamental clash of technological cultures; trying to impose a pretty web interface on a protocol defined to use unformatted plain text. It fails, inevitably, leaving us Usenet and mailing-list-based readers annoyed at being given something unreadable to deal with. Unsurprisingly, most of us don't bother, and won't have read more than the first couple of words of your original post. The wiki page https://wiki.python.org/moin/GoogleGroupsPython goes into some detail of what the rest of us find annoying, and how to fix the problems. I've left the double-spacing that you quoting Mark produced so you can see that part of the problem -- if you want to understand why it is so hated, imagine that done to a screenful of Python script, then quoted by a few more people on GG, until you're only getting half a dozen lines of code (or text) on the screen. That sort of thing is hard work to read, and not many bother, and yes, it really does happen. Top posting is generally poor netiquette, thank you for not doing it this time. Unfortunately you fell into another trap GG lays for you by not handling attributions properly. Or at all this time. I happen to remember that you were replying to Mark Lawrence (just in case it was impossible for me to guess from the subject matter :-), but if I hadn't remembered that, I wouldn't have known from the context without going and searching. Again, that's work many people won't bother putting in, making your post less likely to be read. Sorry your post was the straw to break the camel's back this week, but it is a complete pain to the rest of us. I have more than once considered getting my reader to automatically discard anything with "@googlegroups.com" in the message ID just to reduce the aggravation. -- Rhodri James *-* Wildebeest Herder to the Masses From dev at joernhees.de Thu Apr 10 18:45:35 2014 From: dev at joernhees.de (=?iso-8859-1?Q?J=F6rn_Hees?=) Date: Fri, 11 Apr 2014 00:45:35 +0200 Subject: module version number support for semver.org Message-ID: Hi, what do you think about officially supporting Semantic Versioning? ( http://semver.org ) Semantic Versioning has gained a lot of attention in other programming languages. Even though not officially supported, many python libraries use it as well (just search the pypi listing for things like "-alpha" "-beta" "-dev" "-pre" to get a rough idea). There even is a class handling Semantic Versioning in pip already: pip.util.version.SemanticVersion . I'd speak in favor of officially adding support for semantic versioning to the python module versioning specs as a follow up to PEP 440 ( http://legacy.python.org/dev/peps/pep-0440/ ). I want to avoid the fruitless discussion about personal versioning scheme preference. My main point is: both schemes are widely used (even in the python world). As far as i can see both schemes can just co-exist in the python world giving us the benefits of both without hurting us. Short re-cap of both versioning schemes ======================================= The current version format specified in PEP 440 [2] follows this pseudo format: [N:]N(.N)*[{a|b|c|rc}N][.postN][.devN] So python module version numbers look like (taken from [2]): 1.0.dev456 1.0a1 1.0a2.dev456 1.0a12.dev456 1.0a12 1.0b1.dev456 1.0b2 1.0b2.post345.dev456 1.0b2.post345 1.0c1.dev456 1.0c1 1.0 1.0.post456.dev34 1.0.post456 1.1.dev1 Semantic Versioning follows this pseudo format: N.N.N(-((N)|([0-9A-Za-z-]+))(.((N)|([0-9A-Za-z-])+))*)? Some examples in order (taken from http://semver.org ): 1.0.0-alpha 1.0.0-alpha.1 1.0.0-alpha.beta 1.0.0-beta 1.0.0-beta.2 1.0.0-beta.11 1.0.0-rc.1 1.0.0 Key differences =============== Semantic Versioning supports - free-text pre-releases without version number such as '-alpha', '-pre' and the very widely used '-dev' (after a release the next commit increases the version number and appends the '-dev', which is only removed for the release). - always has MAJOR.MINOR.PATCH, (so 3 relevant) numbers as version number and offers guidelines which to change when. Semantic Versioning does not support - post-releases (a post release would be an increase of the PATCH number). - special handling for '-dev', '-alpha', '-beta', '-gamma' or 'rc'. Ideas to solve (cross scheme) comparisons ========================================= A version comparator could first try parsing both versions to be compared according to the current scheme and if that fails try parsing them both as SemanticVersions. Switching from one version naming scheme to another should be discouraged at least within the leading N parts at the change boundary staying the same. That way comparisons between the naming schemes could be settled by comparing the leading numerical parts of the version. Cheers, J?rn From elearn2014 at gmail.com Thu Apr 10 19:02:33 2014 From: elearn2014 at gmail.com (length power) Date: Fri, 11 Apr 2014 07:02:33 +0800 Subject: the logical operation confused me Message-ID: >>> "ok" or "not ok" 'ok' >>> "ok" and "not ok" 'not ok' >>> why "ok" or "not ok" output "ok" , "ok" and "not ok" output "not ok" ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Apr 10 19:09:29 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 10 Apr 2014 19:09:29 -0400 Subject: the logical operation confused me In-Reply-To: References: Message-ID: On 4/10/2014 7:02 PM, length power wrote: > >>> "ok" or "not ok" > 'ok' > >>> "ok" and "not ok" > 'not ok' > >>> > > why "ok" or "not ok" output "ok" , "ok" and "not ok" output "not ok" ? This is explained in our fine manual. https://docs.python.org/2/reference/expressions.html#boolean-operations -- Terry Jan Reedy From gary.herron at islandtraining.com Thu Apr 10 19:13:49 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Thu, 10 Apr 2014 16:13:49 -0700 Subject: the logical operation confused me In-Reply-To: References: Message-ID: <534725AD.2030402@islandtraining.com> On 04/10/2014 04:02 PM, length power wrote: > >>> "ok" or "not ok" > 'ok' > >>> "ok" and "not ok" > 'not ok' > >>> > > why "ok" or "not ok" output "ok" , "ok" and "not ok" output "not ok" ? > > > You are probably confusing yourself with the string "not ok". That string, and any other non-empty string is considered true >>> bool("not ok") True >>> bool("ok") True perhaps you meant >>> not "ok" False Once past that possible confusion, the return value of the *and* and *or* operators are explained here: https://docs.python.org/release/2.5.2/lib/boolean.html Gary Herron -------------- next part -------------- An HTML attachment was scrubbed... URL: From denismfmcmahon at gmail.com Thu Apr 10 19:28:40 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 10 Apr 2014 23:28:40 +0000 (UTC) Subject: the logical operation confused me References: Message-ID: On Fri, 11 Apr 2014 07:02:33 +0800, length power wrote: >>>> "ok" or "not ok" > 'ok' >>>> "ok" and "not ok" > 'not ok' >>>> >>>> > why "ok" or "not ok" output "ok" , "ok" and "not ok" output "not ok" ? I believe that: [ (falsey condition) or ]* (first truthy condition) or (any condition) [ or (any condition) ]* will return (first truthy condition) whereas: (truthy condition) and [ (truthy condition) and ]* (last truthy condition) will return (last truthy condition) where "[ clause ]*" represents an optional clause that may be repeated any number of times, "any condition" may evaluate falsey or truthy, "first" and "last" relate to the position of the condition type in a left to right evaluation sequence. -- Denis McMahon, denismfmcmahon at gmail.com From tjreedy at udel.edu Thu Apr 10 19:34:29 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 10 Apr 2014 19:34:29 -0400 Subject: module version number support for semver.org In-Reply-To: References: Message-ID: On 4/10/2014 6:45 PM, J?rn Hees wrote: > what do you think about officially supporting Semantic Versioning? > (http://semver.org ) It is a nice fantasy. Under "Why...?" the author, Tom Preston-Werner, says "A simple example will demonstrate how Semantic Versioning can make dependency hell a thing of the past. Consider a library called "Firetruck." It requires a Semantically Versioned package named "Ladder." At the time that Firetruck is created, Ladder is at version 3.1.0. Since Firetruck uses some functionality that was first introduced in 3.1.0, you can safely specify the Ladder dependency as greater than or equal to 3.1.0 but less than 4.0.0. Now, when Ladder version 3.1.1 and 3.2.0 become available, you can release them to your package management system and know that they will be compatible with existing dependent software." Except you cannot know. Even though Firetruck works with Ladder 3.1.0, one *cannot* know for sure that is will work with Ladder 3.1.1, let alone 3.2.0. 1. Python use patch (micro, .z) numbers for bug fixes. Tom specifies "backwards compatible bug fixes". There ain't no such thing. Bug fixes break code that depends on the bug. Such dependence may be unintentional and not known until a supposedly safe patch release breaks the code that uses it. 2. Accidents, including regressions, happen. In respone to FAQ "What do I do if I accidentally release a backwards incompatible change as a minor version?" (which probably happends with every x.y.0 CPython release), Tom says "As soon as you realize that you've broken the Semantic Versioning spec, fix the problem and release a new minor version that corrects the problem and restores backwards compatibility. Even under this circumstance, it is unacceptable to modify versioned releases. If it's appropriate, document the offending version and inform your users of the problem so that they are aware of the offending version." This is well and good, but it invalidates the claim that one can reliably depend and mechanically base action on future release numbers. The answer to "What if I inadvertently alter the public API in a way that is not compliant with the version number change?" has the same problem. This is not to say that Semver does not improve the situation when it can be used. -- Terry Jan Reedy From ben+python at benfinney.id.au Thu Apr 10 19:50:31 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 11 Apr 2014 09:50:31 +1000 Subject: Language summit notes References: <53468982$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <851tx4zquw.fsf@benfinney.id.au> Steven D'Aprano writes: > Today in Montreal Canada, there was a Language Summit to discuss the > future of Python. Some highlights: [?] > More in this email thread here: > https://mail.python.org/pipermail/python-dev/2014-April/133873.html Thanks very much for this! Core development is important to the whole Python community, but time-consuming to keep abreast of. Summaries for general consumption are very helpful. -- \ ?I thought I'd begin by reading a poem by Shakespeare, but then | `\ I thought ?Why should I? He never reads any of mine.?? ?Spike | _o__) Milligan | Ben Finney From sturla.molden at gmail.com Thu Apr 10 19:51:41 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Fri, 11 Apr 2014 01:51:41 +0200 Subject: threading In-Reply-To: <87wqexj7ge.fsf@elektro.pacujo.net> References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> <87wqexj7ge.fsf@elektro.pacujo.net> Message-ID: On 10/04/14 21:44, Marko Rauhamaa wrote: > I'm happy that asyncio is > happening after all these long years. It would be nice if it supported > edge-triggered wakeups, but I suppose that isn't supported in all > operating systems. I have an issue with the use of coroutines. I think they are to evil. When a man like David Beazley says this https://twitter.com/dabeaz/status/440214755764994048 there is something crazy going on. Sturla From sturla.molden at gmail.com Thu Apr 10 20:21:26 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Fri, 11 Apr 2014 02:21:26 +0200 Subject: threading In-Reply-To: References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> <87wqexj7ge.fsf@elektro.pacujo.net> Message-ID: <53473586.4060306@gmail.com> On 11/04/14 01:51, Sturla Molden wrote: > I have an issue with the use of coroutines. I think they are to evil. > > When a man like David Beazley says this > > https://twitter.com/dabeaz/status/440214755764994048 > > there is something crazy going on. And why did Python get this Tulip beast, instead of a simple libuv wrapper? Node.js has already proven what libuv can do. Sturla From tjreedy at udel.edu Thu Apr 10 20:23:54 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 10 Apr 2014 20:23:54 -0400 Subject: threading In-Reply-To: References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> <87wqexj7ge.fsf@elektro.pacujo.net> Message-ID: On 4/10/2014 7:51 PM, Sturla Molden wrote: > On 10/04/14 21:44, Marko Rauhamaa wrote: >> I'm happy that asyncio is >> happening after all these long years. It would be nice if it supported >> edge-triggered wakeups, but I suppose that isn't supported in all >> operating systems. > > I have an issue with the use of coroutines. I think they are to evil. I think 'magical' is the word you should be looking for. > When a man like David Beazley says this > > https://twitter.com/dabeaz/status/440214755764994048 > > there is something crazy going on. There is understanding how to use them, and understanding how they work in this context. I suspect that DB was talking about the second, deeper level. -- Terry Jan Reedy From nispray at gmail.com Thu Apr 10 21:29:21 2014 From: nispray at gmail.com (Wesley) Date: Thu, 10 Apr 2014 18:29:21 -0700 (PDT) Subject: python obfuscate Message-ID: Hi all, Does python has any good obfuscate? Currently our company wanna release one product developed by python to our customer. But dont's wanna others see the py code. I googled for a while but mostly just say using pyc. Any better one? Our product is deployed on Linux bed. Thanks. Wesley From ben+python at benfinney.id.au Thu Apr 10 21:41:11 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 11 Apr 2014 11:41:11 +1000 Subject: python obfuscate References: Message-ID: <85wqewy760.fsf@benfinney.id.au> Wesley writes: > Hi all, > Does python has any good obfuscate? Define ?good obfuscate?. What is your goal? If it is to hide your program's secrets from others, then obfuscation isn't going to help: no matter how good it is, it still needs to be readable by the runtime on the machine. Moreover, the more effective the obfuscation, the less correspondence there is between the distributed code and the code ytou actually maintain. Attempting to debug problems will be infeasible, directly in proportion to how effective the obfuscation is. Before looking to obfuscate your code, first establish ? beyond mere emotional conviction ? that there actually is something in the code which is worth hiding from recipients. > Currently our company wanna release one product developed by python to > our customer. But dont's wanna others see the py code. That's impossible: the code is in the hands of the customer. If your threat model is ?the person who possesses the code must not have access?, then you've lost, just as DRM is a failure. -- \ ?People demand freedom of speech to make up for the freedom of | `\ thought which they avoid.? ?Soren Aabye Kierkegaard (1813?1855) | _o__) | Ben Finney From toby at tobiah.org Thu Apr 10 21:48:04 2014 From: toby at tobiah.org (Tobiah) Date: Thu, 10 Apr 2014 18:48:04 -0700 Subject: python obfuscate In-Reply-To: References: Message-ID: On 4/10/2014 6:29 PM, Wesley wrote: > Hi all, Does python has any good obfuscate? > > Currently our company wanna release one product developed by python > to our customer. But dont's wanna others see the py code. > > I googled for a while but mostly just say using pyc. Any better one? Does that work? If so, wouldn't that be a great solution? Toby From nispray at gmail.com Thu Apr 10 22:14:45 2014 From: nispray at gmail.com (Wesley) Date: Thu, 10 Apr 2014 19:14:45 -0700 (PDT) Subject: python obfuscate In-Reply-To: References: Message-ID: pyc has weakness: 1. easy to decompile 2. python version related, e.g. pyc from py2.5 cannot be used to py2.7 bed ? 2014?4?11????UTC+8??9?48?04??Tobiah??? > On 4/10/2014 6:29 PM, Wesley wrote: > > > Hi all, Does python has any good obfuscate? > > > > > > Currently our company wanna release one product developed by python > > > to our customer. But dont's wanna others see the py code. > > > > > > I googled for a while but mostly just say using pyc. Any better one? > > > > Does that work? If so, wouldn't that be a great solution? > > > > Toby From nispray at gmail.com Thu Apr 10 22:17:10 2014 From: nispray at gmail.com (Wesley) Date: Thu, 10 Apr 2014 19:17:10 -0700 (PDT) Subject: python obfuscate In-Reply-To: References: Message-ID: <572b740c-0ce2-4c01-a4cd-30d2e2463f2b@googlegroups.com> Umm, just wanna make all .py files not human readable. Or, maybe need a tool like zend in php. ? 2014?4?11????UTC+8??9?41?11??Ben Finney??? > Wesley writes: > > > > > Hi all, > > > Does python has any good obfuscate? > > > > Define ?good obfuscate?. What is your goal? > > > > If it is to hide your program's secrets from others, then obfuscation > > isn't going to help: no matter how good it is, it still needs to be > > readable by the runtime on the machine. > > > > Moreover, the more effective the obfuscation, the less correspondence > > there is between the distributed code and the code ytou actually > > maintain. Attempting to debug problems will be infeasible, directly in > > proportion to how effective the obfuscation is. > > > > Before looking to obfuscate your code, first establish ? beyond mere > > emotional conviction ? that there actually is something in the code > > which is worth hiding from recipients. > > > > > Currently our company wanna release one product developed by python to > > > our customer. But dont's wanna others see the py code. > > > > That's impossible: the code is in the hands of the customer. If your > > threat model is ?the person who possesses the code must not have > > access?, then you've lost, just as DRM is a failure. > > > > -- > > \ ?People demand freedom of speech to make up for the freedom of | > > `\ thought which they avoid.? ?Soren Aabye Kierkegaard (1813?1855) | > > _o__) | > > Ben Finney From ian.g.kelly at gmail.com Thu Apr 10 22:23:43 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 10 Apr 2014 20:23:43 -0600 Subject: python obfuscate In-Reply-To: References: Message-ID: On Thu, Apr 10, 2014 at 7:48 PM, Tobiah wrote: > On 4/10/2014 6:29 PM, Wesley wrote: >> Hi all, Does python has any good obfuscate? >> >> Currently our company wanna release one product developed by python >> to our customer. But dont's wanna others see the py code. >> >> I googled for a while but mostly just say using pyc. Any better one? > > Does that work? If so, wouldn't that be a great solution? No, pyc files contain Python byte code, which can easily be disassembled -- in fact, the capacity to do this can be found in the "dis" module of the standard library. The result of disassembly is not valid Python, but it is not hard to read either. There are also decompilers available that can go the extra step and produce actual Python from the pyc file. From ian.g.kelly at gmail.com Thu Apr 10 22:28:50 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 10 Apr 2014 20:28:50 -0600 Subject: python obfuscate In-Reply-To: <572b740c-0ce2-4c01-a4cd-30d2e2463f2b@googlegroups.com> References: <572b740c-0ce2-4c01-a4cd-30d2e2463f2b@googlegroups.com> Message-ID: On Thu, Apr 10, 2014 at 8:17 PM, Wesley wrote: > Umm, just wanna make all .py files not human readable. > > Or, maybe need a tool like zend in php. The only reliable way to prevent a customer from reverse-engineering your software is to not give them the software. For example, instead of giving them software containing the critical code that you want to protect, give them access to a web service running that code, which you host and control. This is true no matter what language you're using to write the software. From ben+python at benfinney.id.au Thu Apr 10 23:12:27 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 11 Apr 2014 13:12:27 +1000 Subject: python obfuscate References: <572b740c-0ce2-4c01-a4cd-30d2e2463f2b@googlegroups.com> Message-ID: <85mwfsy2xw.fsf@benfinney.id.au> Wesley writes: > Umm, just wanna make all .py files not human readable. (Please don't top-post; instead, use interleaved replies to make the conversation legible.) You want the code not readable by which humans? Any code which is readable by the machine is readable to the person who owns that machine, given enough effort of course. And any obfuscation needs to be reversed when the code is run, otherwise the machine reading it can't run it. So it seems you don't want obfuscation; you want to not distribute the code at all. -- \ ?They who can give up essential liberty to obtain a little | `\ temporary safety, deserve neither liberty nor safety.? | _o__) ?Benjamin Franklin, 1775-02-17 | Ben Finney From rustompmody at gmail.com Thu Apr 10 23:17:33 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 10 Apr 2014 20:17:33 -0700 (PDT) Subject: Teaching python to non-programmers In-Reply-To: References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> Message-ID: <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> On Friday, April 11, 2014 4:10:22 AM UTC+5:30, Rhodri James wrote: > Sorry your post was the straw to break the camel's back this week, but it > is a complete pain to the rest of us. I have more than once considered > getting my reader to automatically discard anything with > "@googlegroups.com" in the message ID just to reduce the aggravation. I had a colleague at the university who had taught "System Programming" for the fifth year running. One day he confided to us (other colleagues): I think I am losing it... I am getting impatient and am inclined to tell the class: "Ive taught all this to you (so many times!) before Until I realize its not this class!! > The wiki page https://wiki.python.org/moin/GoogleGroupsPython goes into > some detail of what the rest of us find annoying, and how to fix the > problems. So we need to... (one of) - Patiently point out that link to each newcomer here - Silently put up - Express 'last straw' irritation and get called a jerk - Canvas with python list owners to stop GG - Canvas with Google to modify else shut down GG - Your choice here > I've left the double-spacing that you quoting Mark produced so > you can see that part of the problem -- if you want to understand why it > is so hated, imagine that done to a screenful of Python script, then > quoted by a few more people on GG, until you're only getting half a dozen > lines of code (or text) on the screen. That sort of thing is hard work to > read, and not many bother, and yes, it really does happen. Its no use. GG hides all the double-spaced, top-posted stuff in a very small font "show quoted text". If you want to show it more effectively you need to do something like this (or point to the mailing list archive) > On Thu, 10 Apr 2014 21:52:53 +0100, Pete Bee wrote: - - - - > - - >> - - >> Just awesome, not only do we have double line spacing and single line - - >> - - >> paragraphs, we've also got top posting, oh boy am I a happy bunny :) - - >> - - >> I'll leave someone3 else to explain, I just can't be bothered. - - >> - - >> - - > - - > Do you get paid to be a jerk, or is it just for yuks? If the latter, - - > you're not funny. - - - ----------------------- > Top posting is generally poor netiquette, thank you for not doing it this > time. There are cultures -- far more pervasive than USENET in 2014 -- where top posting is the norm, eg - Gmail makes top posting the norm. Compare the figures of gmail and Usenet users - Corporate cultures more or less require top posting -- helped by MS Outlook Else it looks like dishonesty/dissimulation/hiding - Personally I am on different groups. I tend to top post by default. And its as strange and bizarre there as its required minimum etiquette here > Unfortunately you fell into another trap GG lays for you by not > handling attributions properly. Or at all this time. [Personally] Double spacing bothers me least, top posting more, non/mis-attribution most From ben+python at benfinney.id.au Thu Apr 10 23:28:31 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 11 Apr 2014 13:28:31 +1000 Subject: Ostracising bad actors (was: Teaching python to non-programmers) References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> Message-ID: <85ioqgy274.fsf_-_@benfinney.id.au> "Rhodri James" writes: > Sorry your post was the straw to break the camel's back this week, but > it is a complete pain to the rest of us. I have more than once > considered getting my reader to automatically discard anything with > "@googlegroups.com" in the message ID just to reduce the aggravation. I passed that threshold long ago. Posts that come to my Usenet client via Google Groups are automatically marked for deletion. I strongly recommend everyone do the same; and also to lobby for (and support) alternative Usenet interfaces which don't mangle the messages. -- \ ?You know what would make a good story? Something about a clown | `\ who makes people happy, but inside he's real sad. Also, he has | _o__) severe diarrhea.? ?Jack Handey | Ben Finney From rustompmody at gmail.com Thu Apr 10 23:27:14 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 10 Apr 2014 20:27:14 -0700 (PDT) Subject: Unpacking U-Boot image file In-Reply-To: References: <6ed343e7-fa02-426a-a75f-3e1d164a6a61@googlegroups.com> Message-ID: On Friday, April 11, 2014 3:31:50 AM UTC+5:30, Rhodri James wrote: > On Wed, 09 Apr 2014 18:18:56 +0100, Rustom Mody > > After that.. whats the U-boot format? > > The Fine Manual (http://www.denx.de/wiki/view/DULG/UBootImages) isn't very > forthcoming, sadly; > > "U-Boot operates on "image" files which can be basically anything, > preceeded by a special header; see the definitions in include/image.h for > details; basically, the header defines the following image properties > > * Target Operating System > * Target CPU Architecture > * Compression Type > * Load Address > * Entry Point > * Image Name > * Image Timestamp" > > > I suspect taking this apart may be a little involved. If its a binary format, you (OP) may want to look at https://pypi.python.org/pypi/construct/2.5.1 Of course you will have to read/get the C struct and write the corresponding "Construct" You may want to ask on a U-boot forum for more details. From rosuav at gmail.com Thu Apr 10 23:59:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Apr 2014 13:59:00 +1000 Subject: Teaching python to non-programmers In-Reply-To: <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> Message-ID: On Fri, Apr 11, 2014 at 1:17 PM, Rustom Mody wrote: > There are cultures -- far more pervasive than USENET in 2014 -- where > top posting is the norm, eg > - Gmail makes top posting the norm. Compare the figures of gmail and Usenet users > - Corporate cultures more or less require top posting -- helped by MS Outlook > Else it looks like dishonesty/dissimulation/hiding > - Personally I am on different groups. I tend to top post by default. And its > as strange and bizarre there as its required minimum etiquette here I have seen plenty of cultures where people are unaware of the value of interleaved/bottom posting, but so far, not one where anyone has actually required it. Not one. "Norm" here just means "the thing people are too lazy to not do". That's not a reason for anyone else doing it. ChrisA From rustompmody at gmail.com Fri Apr 11 00:37:22 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 10 Apr 2014 21:37:22 -0700 (PDT) Subject: Teaching python to non-programmers In-Reply-To: References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> Message-ID: <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> On Friday, April 11, 2014 9:29:00 AM UTC+5:30, Chris Angelico wrote: > On Fri, Apr 11, 2014 at 1:17 PM, Rustom Mody wrote: > > > There are cultures -- far more pervasive than USENET in 2014 -- where > > top posting is the norm, eg > > > - Gmail makes top posting the norm. Compare the figures of gmail and Usenet users > > - Corporate cultures more or less require top posting -- helped by MS Outlook > > Else it looks like dishonesty/dissimulation/hiding > > - Personally I am on different groups. I tend to top post by default. And its > > as strange and bizarre there as its required minimum etiquette here > > I have seen plenty of cultures where people are unaware of the value > of interleaved/bottom posting, but so far, not one where anyone has > actually required it. Not one. "Norm" here just means "the thing > people are too lazy to not do". That's not a reason for anyone else > doing it. Right. Its true that when I was at a fairly large corporate, I was not told: "Please always top post!" What I was very gently and super politely told was: "Please dont delete mail context" Now when a mail goes round between 5 persons and what is addressed at one point is not the immediate previous mail, bottom-posting without pruning is as meaningless as top posting. As in religion or any cultural matter, its fine to stand up for and even vociferously uphold one's 'own' whatever that may be. What is unhelpful is - to suggest that my norms are universal norms. IOW there is a fundamental difference between natural and human-made laws - to lose track of statistics, in this case the population-densities of USENET vs other internet-kiddie cultures From rosuav at gmail.com Fri Apr 11 01:11:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Apr 2014 15:11:26 +1000 Subject: Teaching python to non-programmers In-Reply-To: <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> Message-ID: On Fri, Apr 11, 2014 at 2:37 PM, Rustom Mody wrote: > Right. Its true that when I was at a fairly large corporate, I was not told: > "Please always top post!" > > What I was very gently and super politely told was: > "Please dont delete mail context" Then you were told that by someone who does not understand email. That's equivalent to being told "Don't ever delete any of your code, just comment it out". I don't care who's saying that, it's bad advice. > Now when a mail goes round between 5 persons and what is addressed at one point > is not the immediate previous mail, bottom-posting without pruning is as > meaningless as top posting. Yep. So you bottom-post *and prune*, because that is how email needs to be. You do not need to repeatedly send copies of the whole thread everywhere. > What is unhelpful is > - to suggest that my norms are universal norms. IOW there is a fundamental > difference between natural and human-made laws > - to lose track of statistics, in this case the population-densities of USENET > vs other internet-kiddie cultures Also unhelpful is to suggest that norms should, simply *because* they are the prevailing practice, be maintained. Even if everyone else on python-list top-posted, I would still bottom-post and trim. "Normal" is not a justification. ChrisA From rustompmody at gmail.com Fri Apr 11 01:15:08 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 10 Apr 2014 22:15:08 -0700 (PDT) Subject: threading In-Reply-To: <87sipkkj7p.fsf@elektro.pacujo.net> References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> <87wqexj7ge.fsf@elektro.pacujo.net> <685d594b-c31b-4629-b81d-4aa64d9e3394@googlegroups.com> <87sipkkj7p.fsf@elektro.pacujo.net> Message-ID: On Friday, April 11, 2014 2:14:42 AM UTC+5:30, Marko Rauhamaa wrote: > Rustom Mody: > > > What you are saying is that what the OS is doing, you can do better. > > Analogous to said C programmer saying that what (data structures) the > > python programmer can make he can do better. > > > > I'm sorry, but I don't quite follow you there. Ok let me try again (Please note I am speaking more analogically than logically) There was a time -- say 1990 -- when there was this choice - use C -- a production language with half-assed data structures support - use Lisp -- strong support for data structures but otherwise unrealistic >From this world and its world view its natural to conclude that to choose a strong data structure supporting language is to choose an unrealistic language I was in the thick of this debate then http://www.the-magus.in/Publications/chor.pdf This argument is seen to be fallacious once we have languages like python (and Ruby and Java and Perl and Haskell and ...) Today we are in the same position vis-a-vis concurrency as we were with data structures in 1990. We have mainstream languages -- Java,C,C++,Python -- with half-assed concurrency support. And we have languages like Erlang, Go, Cloud Haskell which make concurrency center-stage but are otherwise lacking and unrealistic. I disagree with you in saying "We cant do better (than stay within the options offered by mainstream languages" As an individual you are probably right. >From a larger systemic pov (hopefully!) not! I disagree with Sturla in what is considered invariant and what is under one's control. He (seems?) to take hardware as under control, programming paradigm as not. I believe that the mileage that can be achieved by working on both is more than can be achieved by either alone. > I see the regular multithreaded approach as > (2) inviting race conditions carelessly--no mortal is immune. This I understand and concur with > > (1) oversimplification which makes it difficult to extend the design > and handle all of the real-world contingencies This I dont... From paul.nospam at rudin.co.uk Fri Apr 11 01:34:46 2014 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Fri, 11 Apr 2014 06:34:46 +0100 Subject: Teaching python to non-programmers References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> Message-ID: <8761mg77k9.fsf@rudin.co.uk> Chris Angelico writes: > On Fri, Apr 11, 2014 at 2:37 PM, Rustom Mody wrote: >> Right. Its true that when I was at a fairly large corporate, I was not told: >> "Please always top post!" >> >> What I was very gently and super politely told was: >> "Please dont delete mail context" > > Then you were told that by someone who does not understand email. It's not necessarily a bad idea to retain context in corporate emails. Messages tend to get forwarded to people other than the original recipient(s), and the context can be very helpful. But when you're posting to a mailing list or to a usenet group different considerations apply as there's usually a way of seeing the whole thread. Email is often a poor relatively poor medium for internal communication, because of this problem. Also people who might properly have a something useful to say on the subject matter may never get to see the email. A private news server or web forum is often better. That's not to say that there's no place for email in internal communication, but it's best reserved for occasions where confidentiality is required, or at least politic. From steve+comp.lang.python at pearwood.info Fri Apr 11 01:35:37 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Apr 2014 05:35:37 GMT Subject: threading References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> <87wqexj7ge.fsf@elektro.pacujo.net> Message-ID: <53477f29$0$29993$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Apr 2014 01:51:41 +0200, Sturla Molden wrote: > On 10/04/14 21:44, Marko Rauhamaa wrote: >> I'm happy that asyncio is >> happening after all these long years. It would be nice if it supported >> edge-triggered wakeups, but I suppose that isn't supported in all >> operating systems. > > I have an issue with the use of coroutines. I think they are to evil. They are to evil ... as what? To evil as chalk is to cheese? Black is to white? Bees are to honey? I think coroutines are awesome, but like all advanced concepts, sometimes they can be abused, and sometimes they are hard to understand not because they are hard to understand in and of themselves, but because they are being used to do something inherently complicated. > When a man like David Beazley says this > > https://twitter.com/dabeaz/status/440214755764994048 > > there is something crazy going on. Good lord!!! David Beazley has been consumed by the Dark Side and uses Twitter??? There certainly is something crazy going on! -- Steven D'Aprano http://import-that.dreamwidth.org/ From ian.g.kelly at gmail.com Fri Apr 11 01:39:24 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 10 Apr 2014 23:39:24 -0600 Subject: Teaching python to non-programmers In-Reply-To: References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> Message-ID: On Thu, Apr 10, 2014 at 11:11 PM, Chris Angelico wrote: > On Fri, Apr 11, 2014 at 2:37 PM, Rustom Mody wrote: >> Right. Its true that when I was at a fairly large corporate, I was not told: >> "Please always top post!" >> >> What I was very gently and super politely told was: >> "Please dont delete mail context" > > Then you were told that by someone who does not understand email. > That's equivalent to being told "Don't ever delete any of your code, > just comment it out". I don't care who's saying that, it's bad advice. That depends on what the mail is being used for. For instance there's a difference between mail-as-dialogue and mail-as-business-process. In the former it is normal, even polite, to prune as the topic evolves and past quotations become less relevant. In the latter it seems more common for the entire thread to be preserved as a sort of "chain of custody" -- this way the next person who needs to see the email thread has full context as to what needs to happen and where the request is coming from. I'm generally in the habit of not pruning work-related emails even when they are more of the dialogue type, because these tend to be very tightly focused, and so that if a new person needs to be brought into the conversation they will have the full context of what we're talking about and why we're talking about it. From rosuav at gmail.com Fri Apr 11 01:42:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Apr 2014 15:42:46 +1000 Subject: Teaching python to non-programmers In-Reply-To: <8761mg77k9.fsf@rudin.co.uk> References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> <8761mg77k9.fsf@rudin.co.uk> Message-ID: On Fri, Apr 11, 2014 at 3:34 PM, Paul Rudin wrote: > Chris Angelico writes: > >> On Fri, Apr 11, 2014 at 2:37 PM, Rustom Mody wrote: >>> What I was very gently and super politely told was: >>> "Please dont delete mail context" >> >> Then you were told that by someone who does not understand email. > > It's not necessarily a bad idea to retain context in corporate > emails. Messages tend to get forwarded to people other than the original > recipient(s), and the context can be very helpful. A good mail client will let you forward an entire thread all at once. That covers the use-case without polluting *every single email ever sent* with the entire history. Plus, a decent client should let you forward some without others, which would mean you don't have the awkward situation of sending someone all the internal discussion ("just send this guy the standard cockroach letter") that led to the final decision. Retaining context should either be done with an internal wiki or forum, or by reading up in the retained emails. You don't need to duplicate all context every post in any medium. ChrisA From rustompmody at gmail.com Fri Apr 11 01:42:14 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 10 Apr 2014 22:42:14 -0700 (PDT) Subject: Teaching python to non-programmers In-Reply-To: References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> Message-ID: On Friday, April 11, 2014 10:41:26 AM UTC+5:30, Chris Angelico wrote: > On Fri, Apr 11, 2014 at 2:37 PM, Rustom Mody wrote: > > Right. Its true that when I was at a fairly large corporate, I was not told: > > "Please always top post!" > > > > What I was very gently and super politely told was: > > "Please dont delete mail context" > > Then you were told that by someone who does not understand email. In middle-eastern society women are expected to dress heavier than in the West. A few years ago a girl went to school in France with a scarf and she was penalized. You seem to be cocksure who is right. Im just curious who you think it is :-) People whose familiarity with religion is limited to the Judeo-Christian tradition are inclined to the view (usually implicit) that "being religious" == "belief in God" However there are religions where belief in God is irreligious -- Jainism And others where it is is irrelevant -- Tao, Shinto. [There is the story of a westerner who wen to a shinto temple and said: All this (rites) is fine and beautiful but what's your *philosophy* To which he was told: "Philosophy? We have no philosophy! We dance!"] > > That's equivalent to being told "Don't ever delete any of your code, > just comment it out". I don't care who's saying that, it's bad advice. The correct analogy: "Dont ever delete content from the repository" > > > Now when a mail goes round between 5 persons and what is addressed at one point > > is not the immediate previous mail, bottom-posting without pruning is as > > meaningless as top posting. > > > Yep. So you bottom-post *and prune*, because that is how email needs > to be. You do not need to repeatedly send copies of the whole thread > everywhere. > > > > What is unhelpful is > > - to suggest that my norms are universal norms. IOW there is a fundamental > > difference between natural and human-made laws > > - to lose track of statistics, in this case the population-densities of USENET > > vs other internet-kiddie cultures > > > > Also unhelpful is to suggest that norms should, simply *because* they > are the prevailing practice, be maintained. Even if everyone else on > python-list top-posted, I would still bottom-post and trim. "Normal" > is not a justification. Ok no argument here. On the python list that is the norm. Most people who are first timers have no clue about that norm. From breamoreboy at yahoo.co.uk Fri Apr 11 01:53:29 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 11 Apr 2014 06:53:29 +0100 Subject: python obfuscate In-Reply-To: <85mwfsy2xw.fsf@benfinney.id.au> References: <572b740c-0ce2-4c01-a4cd-30d2e2463f2b@googlegroups.com> <85mwfsy2xw.fsf@benfinney.id.au> Message-ID: On 11/04/2014 04:12, Ben Finney wrote: > Wesley writes: > >> Umm, just wanna make all .py files not human readable. > > (Please don't top-post; instead, use interleaved replies > to > make the conversation legible.) > Further would you please use the mailing list https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Fri Apr 11 01:54:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Apr 2014 15:54:58 +1000 Subject: Teaching python to non-programmers In-Reply-To: References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> Message-ID: On Fri, Apr 11, 2014 at 3:39 PM, Ian Kelly wrote: > That depends on what the mail is being used for. For instance there's > a difference between mail-as-dialogue and mail-as-business-process. > In the former it is normal, even polite, to prune as the topic evolves > and past quotations become less relevant. In the latter it seems more > common for the entire thread to be preserved as a sort of "chain of > custody" -- this way the next person who needs to see the email thread > has full context as to what needs to happen and where the request is > coming from. Sounds like a job for an internal wiki, actually. Have you ever gone back through a fifty-post thread, reading through its entire unpruned context to find something? And if you have, was it at all practical? Somehow I doubt it. ChrisA From rustompmody at gmail.com Fri Apr 11 01:54:23 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 10 Apr 2014 22:54:23 -0700 (PDT) Subject: Teaching python to non-programmers In-Reply-To: References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> Message-ID: On Friday, April 11, 2014 11:12:14 AM UTC+5:30, Rustom Mody wrote: > On Friday, April 11, 2014 10:41:26 AM UTC+5:30, Chris Angelico wrote: > > Also unhelpful is to suggest that norms should, simply *because* they > > are the prevailing practice, be maintained. Even if everyone else on > > python-list top-posted, I would still bottom-post and trim. "Normal" > > is not a justification. > > Ok no argument here. > On the python list that is the norm. > Most people who are first timers have no clue about that norm. Just to make it clear: 1. I have no objection to the python list culture. As I said I tend to follow it in places where it is not the norm and get chided for it [For the record on other groups which are exclusively GG/gmail based Ive been told that because I am geek/nerd I do it in a strange way] 2. Nor to people getting irritated with others not following it and telling them off What I am pointing out is that if one gets so besotted with irritation as to lose coherence, its unlikely that any useful communication will ensue. From rosuav at gmail.com Fri Apr 11 02:00:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Apr 2014 16:00:15 +1000 Subject: Teaching python to non-programmers In-Reply-To: References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> Message-ID: On Fri, Apr 11, 2014 at 3:42 PM, Rustom Mody wrote: > People whose familiarity with religion is limited to the Judeo-Christian > tradition are inclined to the view (usually implicit) that > "being religious" == "belief in God" > However there are religions where belief in God is irreligious -- Jainism > And others where it is is irrelevant -- Tao, Shinto. > [There is the story of a westerner who wen to a shinto temple and said: > All this (rites) is fine and beautiful but what's your *philosophy* > To which he was told: "Philosophy? We have no philosophy! We dance!"] That's nothing to do with norms, though. The norm might be to follow Taoism, but that doesn't make it more right - just more normal. >> That's equivalent to being told "Don't ever delete any of your code, >> just comment it out". I don't care who's saying that, it's bad advice. > > The correct analogy: "Dont ever delete content from the repository" Generally, a repository won't let you truly delete anything, which is exactly my point: you can delete lines of code from the current file without losing anything. If you want to see the context, you go and look at context, you don't need it to be right there in the current file. Same with email - and often even easier, because your client will let you simply scroll up and see what was said previously. ChrisA From joshua at landau.ws Fri Apr 11 02:00:05 2014 From: joshua at landau.ws (Joshua Landau) Date: Fri, 11 Apr 2014 07:00:05 +0100 Subject: python obfuscate In-Reply-To: References: Message-ID: On 11 April 2014 02:29, Wesley wrote: > Does python has any good obfuscate? Most other people on the list will point out why such a thing is mostly pointless and you don't really need it. However, if this really is your major blocker to using Python, I suggest compiling with Cython. There are downsides, but untyped Cython basically compiles the bytecode into C without actually changing the program, making compatibility really good. It's very difficult to reverse-engineer, largely because there aren't specialised tools to do it. But I do warn that it's adding another abstracting step that doesn't improve - it probably harms - the overall usability of the product. Further, a determined hacker can circumvent it, much as they can circumvent everything else. From rosuav at gmail.com Fri Apr 11 02:01:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Apr 2014 16:01:28 +1000 Subject: Teaching python to non-programmers In-Reply-To: References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> Message-ID: On Fri, Apr 11, 2014 at 3:54 PM, Rustom Mody wrote: > Just to make it clear: > 1. I have no objection to the python list culture. > As I said I tend to follow it in places where it is not the norm and get > chided for it > [For the record on other groups which are exclusively GG/gmail based Ive been > told that because I am geek/nerd I do it in a strange way] > 2. Nor to people getting irritated with others not following it and telling > them off > > What I am pointing out is that if one gets so besotted with irritation as to > lose coherence, its unlikely that any useful communication will ensue. Then be the geek/nerd. Do something more useful. See how many people start finding that it's actually the better way. ChrisA From rosuav at gmail.com Fri Apr 11 02:10:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Apr 2014 16:10:28 +1000 Subject: python obfuscate In-Reply-To: References: Message-ID: On Fri, Apr 11, 2014 at 4:00 PM, Joshua Landau wrote: > But I do warn that it's adding another abstracting step that > doesn't improve - it probably harms - the overall usability of the > product. Further, a determined hacker can circumvent it, much as they > can circumvent everything else. I had this argument with my boss at work about obfuscating our JavaScript code. He said that he was extremely concerned that nobody should be able to rip off all his code; I said that anybody could still rip it off, just by using the code exactly the way the browser would. The *ONLY* advantage you can possibly get from an obfuscation system is that your users can't easily figure out what's going on internally; they can still, by definition, run the program unchanged. If you run obfuscated code through a prettifier (or a decompiler and then a prettifier, as the case may be), you end up with something that's practically indistinguishable from poorly-commented code. Sure, it's not as nice to work with as something with helpful variable names and comments, but it's far from impossible. ChrisA From dieter at handshake.de Fri Apr 11 02:20:25 2014 From: dieter at handshake.de (dieter) Date: Fri, 11 Apr 2014 08:20:25 +0200 Subject: so module loading fails References: <53469B77.50007@eddy-ilg.net> Message-ID: <87d2gofkuu.fsf@handshake.de> Eddy Ilg writes: > ... > > Checking the symbols of Entity.so gives: > # nm Entity.so | grep PyInit_Entity > 0000000000001e5c t PyInit_Entity When I remember right, "t" means a "local" (aka "static") symbol - you need instead a "global" symbol (identified by "T"). From rustompmody at gmail.com Fri Apr 11 02:50:22 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 10 Apr 2014 23:50:22 -0700 (PDT) Subject: threading In-Reply-To: References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> <87wqexj7ge.fsf@elektro.pacujo.net> <685d594b-c31b-4629-b81d-4aa64d9e3394@googlegroups.com> <87sipkkj7p.fsf@elektro.pacujo.net> Message-ID: <19d537ee-dcc3-4265-8fce-bd24201e3dc4@googlegroups.com> On Friday, April 11, 2014 10:45:08 AM UTC+5:30, Rustom Mody wrote: > On Friday, April 11, 2014 2:14:42 AM UTC+5:30, Marko Rauhamaa wrote: > > (1) oversimplification which makes it difficult to extend the design > > and handle all of the real-world contingencies > > This I dont... I meant "Dont understand" From steve+comp.lang.python at pearwood.info Fri Apr 11 03:09:45 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Apr 2014 07:09:45 GMT Subject: Teaching python to non-programmers References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> Message-ID: <53479539$0$29993$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Apr 2014 13:59:00 +1000, Chris Angelico wrote: > I have seen plenty of cultures where people are unaware of the value of > interleaved/bottom posting, but so far, not one where anyone has > actually required it. Not one. I've been in plenty of mailing list forums where interleaved posting was required, but there's only so many times you can tell people off for being rude before you start coming across as rude yourself. It's one of those nasty aspects of human psychology: the guy who casually and without malice tosses litter out of his car window, spoiling things for everyone, is somehow considered less obnoxious than the person who tells him off. Except in Switzerland, where if you leave your rubbish bin out more than twenty minutes after its been emptied, the neighbours consider it perfectly acceptable to tell you off, never mind that you've been at work. And heaven help you if you take your discarded Christmas tree down to the street too early. > "Norm" here just means "the thing people > are too lazy to not do". That's not a reason for anyone else doing it. I'm not sure what you are talking about. As far as I am concerned, the norm here absolutely is interleaved posting. Nearly all of the regular posters use it, have have done so for the decade or so I've been here. Interleaved posting requires more, not less, work -- that's one of the appeals of top-posting: it makes it easy to avoid editing your post for sense and readability, you can just bang on the keyboard and fire off whatever your first thoughts were, never mind actually answering the questions you were asked. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Fri Apr 11 03:19:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Apr 2014 17:19:42 +1000 Subject: Teaching python to non-programmers In-Reply-To: <53479539$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <53479539$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 11, 2014 at 5:09 PM, Steven D'Aprano wrote: > On Fri, 11 Apr 2014 13:59:00 +1000, Chris Angelico wrote: > >> I have seen plenty of cultures where people are unaware of the value of >> interleaved/bottom posting, but so far, not one where anyone has >> actually required it. Not one. > > I've been in plenty of mailing list forums where interleaved posting was > required, but there's only so many times you can tell people off for > being rude before you start coming across as rude yourself. Oops, I worded that badly. What I meant was "not one where anyone has actually required top-posting". There are places where bottom-posting is expected/required, there are places where nobody cares enough to complain, but I've yet to meet any where bottom posting is actually forbidden. >> "Norm" here just means "the thing people >> are too lazy to not do". That's not a reason for anyone else doing it. > > I'm not sure what you are talking about. As far as I am concerned, the > norm here absolutely is interleaved posting. Nearly all of the regular > posters use it, have have done so for the decade or so I've been here. > Interleaved posting requires more, not less, work -- that's one of the > appeals of top-posting: it makes it easy to avoid editing your post for > sense and readability, you can just bang on the keyboard and fire off > whatever your first thoughts were, never mind actually answering the > questions you were asked. Right, and I'm glad that the norm here happens to be the better option. But the reason for advocating it is not "everyone else does it", but "it's the better way". ChrisA From nispray at gmail.com Fri Apr 11 03:35:17 2014 From: nispray at gmail.com (Wesley) Date: Fri, 11 Apr 2014 00:35:17 -0700 (PDT) Subject: gdb python print truncated string In-Reply-To: <07421611-1c5c-4850-9617-a4ea2184c655@googlegroups.com> References: <07421611-1c5c-4850-9617-a4ea2184c655@googlegroups.com> Message-ID: ? 2014?4?8????UTC+8??10?21?24??Wesley??? > Hi all, > > I have a question regarding gdb python. > > I use gdb7.7 and python2.7.6. > > > > Here is snippet that py-print one variable: > > (gdb) py-print self > > local 'self' = , timer513645288=<_Timeout at remote 0xb42f760>, timer1248840930=<_Timeout at remote 0x7f85f7f4c300>, timer1678666863=<_Timeout at remote 0x7f85fec0ddf0>, timer888598936=<_Timeout at remote 0x7f860579a300>, timer1566174556=<_Timeout at remote 0xe69a7d0>, timer1307561941=<_Timeout at remote 0x7f85e41145a0>, timer1010094072=<_Timeout at remote 0xb42af40>, to_device={u'sendno': u'1252682169', u'msg_content': {u'message': {u'command': True}}, u'msg_type': u'2'}, timer2050775853=<_Timeout at remote 0x7f8606ddcb50>, timer1115907467=<_Timeout at remote 0x9c02140>, timer333587031=<_Timeout at remote 0xbb25450>, timer71350378=<_Timeout at remote 0x7f85e5e38220>, timer1044716881=<_Timeout at remote 0x7f86053094c0>, timer2069059536=<_Timeout at remote 0x7f85f3d3b530>, timer2139990080=<_Timeout at remote 0x8bd5370>, timer1121163931=<_Timeout at remote 0x99e5370>, queue=, maxsize=0, all_ta...(truncated) > > > > self is instance of Connection class. > > So, actually, I wanna check self.status...but you can see the print is truncated. > > I tried py-print self.status but failed. > > After a lot google work, somebody mention gdb 'set print elements 0/-1', but still failed.. > > > > So, how to check self.status value? > > > > Thanks. > > Wesley Does anyone know this? From sturla.molden at gmail.com Fri Apr 11 05:17:41 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Fri, 11 Apr 2014 09:17:41 +0000 (UTC) Subject: python obfuscate References: <572b740c-0ce2-4c01-a4cd-30d2e2463f2b@googlegroups.com> Message-ID: <919121451418900428.100110sturla.molden-gmail.com@news.gmane.org> Ian Kelly wrote: > The only reliable way to prevent a customer from reverse-engineering > your software is to not give them the software. Not really. You just need to make it so difficult that it is not worth the effort. In that case they will go away and do something else instead. At least if the threat is other companies out to make money. Dropbox is an example. Sturla From sturla.molden at gmail.com Fri Apr 11 05:17:43 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Fri, 11 Apr 2014 09:17:43 +0000 (UTC) Subject: python obfuscate References: Message-ID: <1318687751418899035.169258sturla.molden-gmail.com@news.gmane.org> Wesley wrote: > Does python has any good obfuscate? > > Currently our company wanna release one product developed by python to > our customer. But dont's wanna others see the py code. > > I googled for a while but mostly just say using pyc. Any better one? It depends on the threat and how competent persons you want to protect your code from. If this comes from your boss, chances are he does not know that even x86 machine code can be decompiled. So as many has said, this is mostly futile business. The only way to protect your code is never to ship anything. Hacking the interpreter might be satisfactory to calm your boss: - Run a script that strips comments and make variable names incomprehensible - Swap .pyc byte codes so they don't mean the same as in vanilla Python - Make the compiler spit out scrambled bytes and make the .pyc loader unencrypt Any of these measures can be circumvented, though. But it is hardly easier to read than compiled C++. Sturla From sturla.molden at gmail.com Fri Apr 11 05:17:42 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Fri, 11 Apr 2014 09:17:42 +0000 (UTC) Subject: python obfuscate References: Message-ID: <802155420418900251.086281sturla.molden-gmail.com@news.gmane.org> Joshua Landau wrote: > However, if this really is your major blocker to using Python, I > suggest compiling with Cython. Cython restains all the code as text, e.g. to readable generate exceptions. Users can also still steal the extension modules and use them in their own code. In general, Cython is not useful as an obfuscation tool. Sturla From wxjmfauth at gmail.com Fri Apr 11 05:25:42 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 11 Apr 2014 02:25:42 -0700 (PDT) Subject: Language summit notes In-Reply-To: References: <53468982$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <911d97b8-b472-4d4a-9d5c-a6a74acf1ec5@googlegroups.com> Unicode! From sturla.molden at gmail.com Fri Apr 11 05:26:46 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Fri, 11 Apr 2014 09:26:46 +0000 (UTC) Subject: threading References: <53477f29$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1455728914418900923.376144sturla.molden-gmail.com@news.gmane.org> Steven D'Aprano wrote: >> I have an issue with the use of coroutines. I think they are to evil. > > They are to evil ... as what? To evil as chalk is to cheese? Black is to > white? Bees are to honey? I think coroutines are one of those things that don't fit the human mind. A class with a couple of queues for input and output is far easier to comprehend. Sturla From steve+comp.lang.python at pearwood.info Fri Apr 11 05:37:39 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Apr 2014 09:37:39 GMT Subject: Teaching python to non-programmers References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> Message-ID: <5347b7e3$0$29993$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Apr 2014 21:37:22 -0700, Rustom Mody wrote: > Right. Its true that when I was at a fairly large corporate, I was not > told: "Please always top post!" That's only because they are ignorant of the terminology of top- bottom- and interleaved posting. If they knew the term, they would say it. > What I was very gently and super politely told was: "Please dont delete > mail context" And your answer was, "I'm not. All the context required to establish meaning is there." Correct? Or perhaps you said, "When you send a letter via paper mail, replying to someone's enquiry, do you photocopy their letter and staple it to the back of your response? And when they reply, to they photocopy YOUR response, *including the photocopy of their letter*, and sent it back? Of course you don't. That would be *idiotic*. It's no less idiotic when the effort of photocopying the letter is reduced to hitting Reply in Outlook." Standard business handling of email truly is foolish. People only get away with it because, for the most part, *they stop reading* as soon as they hit the end of the top-posted reply (and their reading comprehension of that is generally lousy, but that's another story) and don't even notice that there are 15 pages of quoted-quoted-quoted-quoted-quoted- quoted copies of their own words attached, complete with 10 copies of their (legally meaningless) disclaimer. All this redundancy does nothing for improved communication, and it has real costs: emails are bigger than they need be, searching archives for information is harder, and if you're ever involved in a legal dispute, instead of paying your lawyer to review six pages of correspondence you're paying her to review sixty pages with the same semantic content. Top-posting is a classic example of the victory of short term gain (immediately save two seconds and a microscopic amount of effort when replying to an email) versus long term cost. > Now when a mail goes round between 5 persons and what is addressed at > one point is not the immediate previous mail, bottom-posting without > pruning is as meaningless as top posting. Ha. In my experience, anything not addressed immediately in corporate email is *never addressed again*, not until the original poster starts a new email to try to get an answer. > As in religion or any cultural matter, its fine to stand up for and even > vociferously uphold one's 'own' whatever that may be. > > What is unhelpful is > - to suggest that my norms are universal norms. IOW there is a > fundamental difference between natural and human-made laws > - to lose track of statistics, in this case the population-densities of > USENET vs other internet-kiddie cultures I don't know that there is anyone here that thinks interleaved posting is the norm among the majority of email users. Nor is anyone saying that Usenet posters make up a majority of internet users. What we are saying is that *interleaved posting is objectively better* for most forms of email or news communication (although it is not a panacea), and especially for *technical discussions* like those that occur here. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Fri Apr 11 05:40:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Apr 2014 19:40:01 +1000 Subject: python obfuscate In-Reply-To: <1318687751418899035.169258sturla.molden-gmail.com@news.gmane.org> References: <1318687751418899035.169258sturla.molden-gmail.com@news.gmane.org> Message-ID: On Fri, Apr 11, 2014 at 7:17 PM, Sturla Molden wrote: > The only way to protect your code is never to ship anything. It's worth noting, as an aside, that this does NOT mean you don't produce or sell anything. You can keep your code secure by running it on a server and permitting users to access it; that's perfectly safe. ChrisA From steve+comp.lang.python at pearwood.info Fri Apr 11 06:07:06 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Apr 2014 10:07:06 GMT Subject: Teaching python to non-programmers References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> Message-ID: <5347beca$0$29993$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Apr 2014 23:39:24 -0600, Ian Kelly wrote: > On Thu, Apr 10, 2014 at 11:11 PM, Chris Angelico > wrote: [...] >> Then you were told that by someone who does not understand email. >> That's equivalent to being told "Don't ever delete any of your code, >> just comment it out". I don't care who's saying that, it's bad advice. > > That depends on what the mail is being used for. For instance there's a > difference between mail-as-dialogue and mail-as-business-process. In the > former it is normal, even polite, to prune as the topic evolves and past > quotations become less relevant. Exactly. > In the latter it seems more common for > the entire thread to be preserved as a sort of "chain of custody" -- I think this is a rationalisation after the fact, and does not reflect actual practice with email. > this way the next person who needs to see the email thread has full > context as to what needs to happen and where the request is coming from. I think this is wrong. First of all, quite often the newcomer doesn't need or want to see the full *history*. They need to know the *current* situation -- customer X wants to order 50,000 widgets *now*, the fact that seven emails ago they were asking for a quote on 20,000 gadgets is irrelevant. Secondly, as soon as you have three or more people actively taking part is a conversation by email, no single email contains the entire history. So you still have to point the newcomer at some archive where they can see all the emails. Thirdly, even when it is useful to read the entire history, it is far more understandable and efficient to read it in the order that it was written, not in reverse order. I think that the habit of including the entire email history is just a side-effect of the typical corporate laziness and selfishness masquerading as "efficiency". Rather than take five minutes of my time to bring somebody up to speed with a summary telling them exactly what they need to know and nothing but what they need to know, I spend two seconds dumping the entire file in their lap. That's much more efficient! Except that the newcomer then has to spend twenty minutes or an hour and may end up misunderstanding the situation. But that's *his* fault, not mine -- my butt is covered. (You'll notice that nobody ever does this kind of info-dump on high- ranking executives. *Then* they take the time to write an executive summary.) It is, in a way, the corporate equivalent of "RTFM", only enshrined as normal practice rather than seen as a deliberate put-down of somebody who hasn't done their homework. And because it's normal practice, even those who know better end up going along with the flow, because its easier than explaining to their supervisor why their emails are so confusing. And thus the world is made a slightly darker place. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Fri Apr 11 06:17:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Apr 2014 20:17:35 +1000 Subject: Teaching python to non-programmers In-Reply-To: <5347beca$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> <5347beca$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 11, 2014 at 8:07 PM, Steven D'Aprano wrote: > It is, in a way, the corporate equivalent of "RTFM", only enshrined as > normal practice rather than seen as a deliberate put-down of somebody who > hasn't done their homework. And because it's normal practice, even those > who know better end up going along with the flow, because its easier than > explaining to their supervisor why their emails are so confusing. And > thus the world is made a slightly darker place. It's even worse. If someone comes to you saying "So what's this Heartbleed thing?", RTFM would be providing a link to https://en.wikipedia.org/wiki/Heartbleed but the default corporate practice is linking to https://en.wikipedia.org/w/index.php?title=Heartbleed&action=history and expecting the someone to read it all. But yes. ChrisA From ian.g.kelly at gmail.com Fri Apr 11 06:22:49 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 11 Apr 2014 04:22:49 -0600 Subject: python obfuscate In-Reply-To: <919121451418900428.100110sturla.molden-gmail.com@news.gmane.org> References: <572b740c-0ce2-4c01-a4cd-30d2e2463f2b@googlegroups.com> <919121451418900428.100110sturla.molden-gmail.com@news.gmane.org> Message-ID: On Fri, Apr 11, 2014 at 3:17 AM, Sturla Molden wrote: > Ian Kelly wrote: > >> The only reliable way to prevent a customer from reverse-engineering >> your software is to not give them the software. > > Not really... On Fri, Apr 11, 2014 at 3:17 AM, Sturla Molden wrote: > It depends on the threat and how competent persons you want to protect your > code from. If this comes from your boss, chances are he does not know that > even x86 machine code can be decompiled. So as many has said, this is > mostly futile business. The only way to protect your code is never to ship > anything. How is that last statement different from the one I made above, that you disagreed with? From alister.nospam.ware at ntlworld.com Fri Apr 11 06:46:02 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Fri, 11 Apr 2014 10:46:02 GMT Subject: Teaching python to non-programmers References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> <8761mg77k9.fsf@rudin.co.uk> Message-ID: On Fri, 11 Apr 2014 06:34:46 +0100, Paul Rudin wrote: > > It's not necessarily a bad idea to retain context in corporate emails. > Messages tend to get forwarded to people other than the original > recipient(s), and the context can be very helpful. > Right up to the point when someone forwards on an internal email chain to an external customer without bothering to prune out the bit where someone (usually an engineer like myself) has stated (bluntly) that what the salesman is proposing will never work*. the longer the chain the more likely it is for something like that to be missed by the sender who wont have bothered to read everything (for some reason the recipient always finds the embarrassing statements). *Or some other commercially sensitive & even more damming piece of information. -- Having children is like having a bowling alley installed in your brain. -- Martin Mull From rosuav at gmail.com Fri Apr 11 07:01:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Apr 2014 21:01:46 +1000 Subject: Teaching python to non-programmers In-Reply-To: References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> <8761mg77k9.fsf@rudin.co.uk> Message-ID: On Fri, Apr 11, 2014 at 8:46 PM, alister wrote: > Right up to the point when someone forwards on an internal email chain to > an external customer without bothering to prune out the bit where someone > (usually an engineer like myself) has stated (bluntly) that what the > salesman is proposing will never work*. > > the longer the chain the more likely it is for something like that to be > missed by the sender who wont have bothered to read everything (for some > reason the recipient always finds the embarrassing statements). > > *Or some other commercially sensitive & even more damming piece of > information. According to Snopes, that has happened in an email variant of the old "send this guy the standard cockroach letter" story (which is itself plausible and not provably false): http://www.snopes.com/business/consumer/bedbug.asp ChrisA From steve+comp.lang.python at pearwood.info Fri Apr 11 07:34:28 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Apr 2014 11:34:28 GMT Subject: Teaching python to non-programmers References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> Message-ID: <5347d343$0$29993$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Apr 2014 22:42:14 -0700, Rustom Mody wrote: > In middle-eastern society women are expected to dress heavier than in > the West. A few years ago a girl went to school in France with a scarf > and she was penalized. Citation please. I think this is bogus, although given how obnoxious some schools can be I'm not quite prepared to rule it out altogether. I think it's far more likely that she was only penalized for wearing full head- covering (not just a scarf) after being warned that it was not part of the school uniform and therefore not appropriate. [...] > People whose familiarity with religion is limited to the Judeo-Christian > tradition are inclined to the view (usually implicit) that "being > religious" == "belief in God" > However there are religions where belief in God is irreligious -- > Jainism I think that it will come as rather a surprise to Jains to be told that they don't believe in god. In fact, they believe in a multitude of gods (not surprising, as Jainism is derived from Hinduism) and believe that every soul has the potential to become a god. > And others where it is is irrelevant -- Tao, Shinto. [There is > the story of a westerner who wen to a shinto temple and said: All this > (rites) is fine and beautiful but what's your *philosophy* To which he > was told: "Philosophy? We have no philosophy! We dance!"] A nice story, but the name "Shinto" even means "The Way Of The Gods", so claiming that Shinto is not about gods is rubbish. It might be true that there is a particular Shinto temple where they have no religious beliefs and just dance for the love of it, but that's hardly the case for *all* Shinto. That would be a bit like claiming that Christians don't believe in god because some Unitarians are atheists. Shinto has no founder, no overarching doctrine, and no official religious texts, so you are more likely to find widely-varying religiosity than among Christian churches, but to generalise to all Shinto is misleading. Similarly for Taoism (Daoism). The Tao itself is not a religious concept, it is more of a mystical/philosophical concept than a theistic one, but Taoism is a religion with many gods. It seems to me that your statement that belief in gods is irrelevant to Taoism is making the same category mistake as it would be to say that belief in Jesus is irrelevant to Christianity because Faith is not a religious concept[1]. >> That's equivalent to being told "Don't ever delete any of your code, >> just comment it out". I don't care who's saying that, it's bad advice. > > The correct analogy: "Dont ever delete content from the repository" No -- the repository is the email archive. (Your inbox, perhaps.) You don't keep a copy of the entire repo in every source file. [1] Or at least, not necessarily a religious concept. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Fri Apr 11 07:36:46 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Apr 2014 11:36:46 GMT Subject: Teaching python to non-programmers References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> Message-ID: <5347d3cd$0$29993$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Apr 2014 22:54:23 -0700, Rustom Mody wrote: > What I am pointing out is that if one gets so besotted with irritation > as to lose coherence, its unlikely that any useful communication will > ensue. This, a million times. If all we do is be curmudgeons who complain about GG's poor posting styles, we will end up making this forum irrelevant. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Fri Apr 11 07:44:38 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Apr 2014 11:44:38 GMT Subject: python obfuscate References: <572b740c-0ce2-4c01-a4cd-30d2e2463f2b@googlegroups.com> <919121451418900428.100110sturla.molden-gmail.com@news.gmane.org> Message-ID: <5347d5a6$0$29993$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Apr 2014 04:22:49 -0600, Ian Kelly wrote: > On Fri, Apr 11, 2014 at 3:17 AM, Sturla Molden > wrote: >> Ian Kelly wrote: >> >>> The only reliable way to prevent a customer from reverse-engineering >>> your software is to not give them the software. >> >> Not really... > > On Fri, Apr 11, 2014 at 3:17 AM, Sturla Molden > wrote: >> It depends on the threat and how competent persons you want to protect >> your code from. If this comes from your boss, chances are he does not >> know that even x86 machine code can be decompiled. So as many has said, >> this is mostly futile business. The only way to protect your code is >> never to ship anything. > > How is that last statement different from the one I made above, that you > disagreed with? Isn't it obvious? When *you* say something, you're making a knee-jerk reaction without considering all the circumstances, so even if you're right you're right for the wrong reasons and hence wrong. But when *I* say the same thing, I've made a deep and careful consideration of all the nuances and therefore am right for the right reasons and hence right. :-) -- Steven D'Aprano http://import-that.dreamwidth.org/ From paul.nospam at rudin.co.uk Fri Apr 11 07:46:05 2014 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Fri, 11 Apr 2014 12:46:05 +0100 Subject: Teaching python to non-programmers References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> <5347d343$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87k3aw5bsy.fsf@rudin.co.uk> Steven D'Aprano writes: > On Thu, 10 Apr 2014 22:42:14 -0700, Rustom Mody wrote: > >> In middle-eastern society women are expected to dress heavier than in >> the West. A few years ago a girl went to school in France with a scarf >> and she was penalized. > > Citation please. I think this is bogus... This is not bogus. France has quite a strong tradition of keeping the education system secular and has passed a law regarding the wearing of "ostentatious" religious symbols in public schools, which also affects things like the wearing of crosses. Wikipedia has plenty on this... From alister.nospam.ware at ntlworld.com Fri Apr 11 07:48:53 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Fri, 11 Apr 2014 11:48:53 GMT Subject: Teaching python to non-programmers References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> <8761mg77k9.fsf@rudin.co.uk> Message-ID: On Fri, 11 Apr 2014 21:01:46 +1000, Chris Angelico wrote: > On Fri, Apr 11, 2014 at 8:46 PM, alister > wrote: >> Right up to the point when someone forwards on an internal email chain >> to an external customer without bothering to prune out the bit where >> someone (usually an engineer like myself) has stated (bluntly) that >> what the salesman is proposing will never work*. >> >> the longer the chain the more likely it is for something like that to >> be missed by the sender who wont have bothered to read everything (for >> some reason the recipient always finds the embarrassing statements). >> >> *Or some other commercially sensitive & even more damming piece of >> information. > > According to Snopes, that has happened in an email variant of the old > "send this guy the standard cockroach letter" story (which is itself > plausible and not provably false): > > http://www.snopes.com/business/consumer/bedbug.asp > > ChrisA forget Snopes I have personally been hauled into a managers office because something i put in an email to another member of staff was then forwarded to the customer. Fortunately my defence of "internal emails should not be being forwarded to customers without being sanitised" was accepted (& the other member of staff educated) -- Code like that would not pass through anybody's yuck-o-meter. - Linus Torvalds about design on linux-kernel From steve+comp.lang.python at pearwood.info Fri Apr 11 07:59:55 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Apr 2014 11:59:55 GMT Subject: Teaching python to non-programmers References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> <5347d343$0$29993$c3e8da3$5496439d@news.astraweb.com> <87k3aw5bsy.fsf@rudin.co.uk> Message-ID: <5347d93b$0$29993$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Apr 2014 12:46:05 +0100, Paul Rudin wrote: > Steven D'Aprano writes: > >> On Thu, 10 Apr 2014 22:42:14 -0700, Rustom Mody wrote: >> >>> In middle-eastern society women are expected to dress heavier than in >>> the West. A few years ago a girl went to school in France with a scarf >>> and she was penalized. >> >> Citation please. I think this is bogus... > > This is not bogus. France has quite a strong tradition of keeping the > education system secular and has passed a law regarding the wearing of > "ostentatious" religious symbols in public schools, which also affects > things like the wearing of crosses. > > Wikipedia has plenty on this... > > Which does not differ that much from the rest of my post, which you deleted. It wasn't just a scarf, it was a religious head-covering, the hijab, and despite the original context which suggests that the poor girl happened to turn up to school one day with a scarf and was penalized just for bringing it to school, the three girls were asked to remove their hijabs, and were only penalized when they refused to obey school rules. I don't know where I stand on the hijab in general, but in this specific case, I stand by my skepticism about Rustom's description. -- Steven D'Aprano http://import-that.dreamwidth.org/ From cl at isbd.net Fri Apr 11 08:32:43 2014 From: cl at isbd.net (cl at isbd.net) Date: Fri, 11 Apr 2014 13:32:43 +0100 Subject: python obfuscate References: <1318687751418899035.169258sturla.molden-gmail.com@news.gmane.org> Message-ID: Chris Angelico wrote: > On Fri, Apr 11, 2014 at 7:17 PM, Sturla Molden wrote: > > The only way to protect your code is never to ship anything. > > It's worth noting, as an aside, that this does NOT mean you don't > produce or sell anything. You can keep your code secure by running it > on a server and permitting users to access it; that's perfectly safe. > Perfectly? :-) -- Chris Green ? From python.list at tim.thechases.com Fri Apr 11 08:39:56 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 11 Apr 2014 07:39:56 -0500 Subject: Teaching python to non-programmers In-Reply-To: <5347d343$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> <5347d343$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140411073956.758809da@bigbox.christie.dr> On 2014-04-11 11:34, Steven D'Aprano wrote: > >> That's equivalent to being told "Don't ever delete any of your > >> code, just comment it out". I don't care who's saying that, it's > >> bad advice. > > > > The correct analogy: "Dont ever delete content from the > > repository" > > No -- the repository is the email archive. (Your inbox, perhaps.) > You don't keep a copy of the entire repo in every source file. Clearly you've not seen some of the corporate code-bases I've had to touch. ?shudder? I still have nightmares about vast swaths of code commented out or "#ifdef 0"ed out. Then again, since they used Visual Source Safe, it might have been the smarter/safer option ;-) -tkc From roy at panix.com Fri Apr 11 08:36:22 2014 From: roy at panix.com (Roy Smith) Date: Fri, 11 Apr 2014 08:36:22 -0400 Subject: threading References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> <87wqexj7ge.fsf@elektro.pacujo.net> <53477f29$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <53477f29$0$29993$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > I think coroutines are awesome, but like all advanced concepts, sometimes > they can be abused, and sometimes they are hard to understand not because > they are hard to understand in and of themselves, but because they are > being used to do something inherently complicated. Advanced, perhaps. But certainly not new. The first "real" computer I worked on (a pdp-11/45) had a hardware instruction which swapped execution contexts. The documentation described it as being designed to support coroutines. That's a machine which was designed in the early 1970s. Heh, Wikipedia's [[Coroutine]] article says, "The term coroutine was coined by Melvin Conway in a 1963 paper". At a high level, threads and coroutines are really very similar. They are both independent execution paths in the same process. I guess the only real difference between them is that thread switching is mediated by the operating system, so it can happen anywhere (i.e. at any instruction boundary). Coroutines scheduling is handled in user code, so you have a lot more control over when context switches happen. This makes it a lot easier to manage operations which must occur atomically. They both operate in the same process memory space, so have the potential to stomp on each others data structures. They also both have the property that there is flow of control happening which is not apparent from a top-down reading of the code (exceptions, to a certain extent, have this same problem). This is fundamentally what makes them difficult to understand. From sturla.molden at gmail.com Fri Apr 11 08:42:15 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Fri, 11 Apr 2014 12:42:15 +0000 (UTC) Subject: python obfuscate References: <572b740c-0ce2-4c01-a4cd-30d2e2463f2b@googlegroups.com> <919121451418900428.100110sturla.molden-gmail.com@news.gmane.org> Message-ID: <103816724418912615.259320sturla.molden-gmail.com@news.gmane.org> Ian Kelly wrote: > How is that last statement different from the one I made above, that > you disagreed with? Who says I disagreed? But to answer you question, it depends on the level of safety you need: Total secrecy or just enough protection to make it not worthwhile to access the code? Sturla From python.list at tim.thechases.com Fri Apr 11 08:44:19 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 11 Apr 2014 07:44:19 -0500 Subject: Interleaved vs. top-posting In-Reply-To: References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> Message-ID: <20140411074419.428631bc@bigbox.christie.dr> On 2014-04-11 13:59, Chris Angelico wrote: > I have seen plenty of cultures where people are unaware of the value > of interleaved/bottom posting, but so far, not one where anyone has > actually required it. Not one. The only time I've seen top-posting required (though there was nothing about trimming/dropping the content from the bottom) was on some lists for blind users where they wanted the new content at the top of the email rather than having to wade through lots of content they'd heard previously. The actual context was usually either given by in-sentence referencing to the topic, or the subject-heading (blind folks seem to have an incredible memory for things sighted folks are usually too lazy to remember). -tkc From rosuav at gmail.com Fri Apr 11 08:47:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Apr 2014 22:47:41 +1000 Subject: python obfuscate In-Reply-To: References: <1318687751418899035.169258sturla.molden-gmail.com@news.gmane.org> Message-ID: On Fri, Apr 11, 2014 at 10:32 PM, wrote: > Chris Angelico wrote: >> On Fri, Apr 11, 2014 at 7:17 PM, Sturla Molden wrote: >> > The only way to protect your code is never to ship anything. >> >> It's worth noting, as an aside, that this does NOT mean you don't >> produce or sell anything. You can keep your code secure by running it >> on a server and permitting users to access it; that's perfectly safe. >> > Perfectly? :-) Heh. Well, as perfectly as anything ever is. All they can do is try to find exploits (hi, Heartbleed!) and get at some of the code. It's not like "hey look, here it is, I can just run it". ChrisA From breamoreboy at yahoo.co.uk Fri Apr 11 08:48:50 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 11 Apr 2014 13:48:50 +0100 Subject: Language summit notes In-Reply-To: <911d97b8-b472-4d4a-9d5c-a6a74acf1ec5@googlegroups.com> References: <53468982$0$29993$c3e8da3$5496439d@news.astraweb.com> <911d97b8-b472-4d4a-9d5c-a6a74acf1ec5@googlegroups.com> Message-ID: On 11/04/2014 10:25, wxjmfauth at gmail.com wrote: > > Unicode! > Works perfectly in Python 3.3+ thanks to the excellent work done as a result of http://legacy.python.org/dev/peps/pep-0393/, the Flexible String Representation, as we, with one noticable exception, are perfectly well aware of. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Fri Apr 11 08:50:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Apr 2014 22:50:49 +1000 Subject: Teaching python to non-programmers In-Reply-To: <20140411073956.758809da@bigbox.christie.dr> References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> <5347d343$0$29993$c3e8da3$5496439d@news.astraweb.com> <20140411073956.758809da@bigbox.christie.dr> Message-ID: On Fri, Apr 11, 2014 at 10:39 PM, Tim Chase wrote: > On 2014-04-11 11:34, Steven D'Aprano wrote: >> >> That's equivalent to being told "Don't ever delete any of your >> >> code, just comment it out". I don't care who's saying that, it's >> >> bad advice. >> > >> > The correct analogy: "Dont ever delete content from the >> > repository" >> >> No -- the repository is the email archive. (Your inbox, perhaps.) >> You don't keep a copy of the entire repo in every source file. > > Clearly you've not seen some of the corporate code-bases I've had to > touch. ?shudder? I still have nightmares about vast swaths of code > commented out or "#ifdef 0"ed out. > > Then again, since they used Visual Source Safe, it might have been > the smarter/safer option ;-) I think Steven was agreeing with me that it's bad advice, rather than that it never happens... There's an expression on The Daily WTF: "Enterprise happens". Covers this situation well, IMO. http://thedailywtf.com/Articles/The-Enterprise-Dependency.aspx ChrisA From sturla.molden at gmail.com Fri Apr 11 09:06:39 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Fri, 11 Apr 2014 13:06:39 +0000 (UTC) Subject: python obfuscate References: Message-ID: <1390099360418914335.493887sturla.molden-gmail.com@news.gmane.org> wrote: >> It's worth noting, as an aside, that this does NOT mean you don't >> produce or sell anything. You can keep your code secure by running it >> on a server and permitting users to access it; that's perfectly safe. >> > Perfectly? :-) Unless you have a heartbleed :) Sturla From alister.nospam.ware at ntlworld.com Fri Apr 11 09:07:00 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Fri, 11 Apr 2014 13:07:00 GMT Subject: python obfuscate References: Message-ID: On Thu, 10 Apr 2014 18:29:21 -0700, Wesley wrote: > Hi all, > Does python has any good obfuscate? > > Currently our company wanna release one product developed by python to > our customer. But dont's wanna others see the py code. > > I googled for a while but mostly just say using pyc. Any better one? > > Our product is deployed on Linux bed. > > Thanks. > Wesley As already highlighted obfuscation is probably pointless, what do you expect it to achieve anyway? i can see a number of reasons all of which can be proved futile. 1) you want to stop the customer copying the program to other computers:- obsfucation wont help here they already have the executable file & can just run it anyway Many copy protection schemes have been tried in the past none have been sucsesull 2) you don't want the customer to be able to modify your code & pass it of as their own:- This is what Copyright is for. Also if they are that poor a programming shop that they are desperate to steel for your code they probably wont be in business long anyway. 3) to stop them modifying the code to suit their own requirements:- What on earth is the problem here, that just makes the software more valuable to them. As long as they are paying for your software (assuming it is not freeware) then everyone wins. if they are not paying then it is another example of Copyright breach. 4) your software is a driver for some exotic piece of hardware & reading the code will help produce a competing product:- A reasonable justification but in that case it is probably still worth the time & effort of fully decompiling the code & reverse engineering the hardware and the best you will do will be to slow them down it is my opinion that attempting to obfuscate the code is akin to Microsoft's improvements to the BSOD in windows 8 (Adding a frowning emotion) the effort would have been better spent ensuring it wasn't displayed in the first place. Concentrate on making the product (even) better rather than trying to hide the unhideable. -- It's easy to get on the internet and forget you have a life -- Topic on #LinuxGER From breamoreboy at yahoo.co.uk Fri Apr 11 09:10:31 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 11 Apr 2014 14:10:31 +0100 Subject: python obfuscate In-Reply-To: <1390099360418914335.493887sturla.molden-gmail.com@news.gmane.org> References: <1390099360418914335.493887sturla.molden-gmail.com@news.gmane.org> Message-ID: On 11/04/2014 14:06, Sturla Molden wrote: > wrote: > >>> It's worth noting, as an aside, that this does NOT mean you don't >>> produce or sell anything. You can keep your code secure by running it >>> on a server and permitting users to access it; that's perfectly safe. >>> >> Perfectly? :-) > > Unless you have a heartbleed :) > > Sturla > I was thinking more along the lines of Greek tragedies. :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Fri Apr 11 09:43:00 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 11 Apr 2014 14:43:00 +0100 Subject: Teaching python to non-programmers In-Reply-To: <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> Message-ID: On 10/04/2014 21:52, pete.bee.emm at gmail.com wrote: > >> >> Just awesome, not only do we have double line spacing and single line >> >> paragraphs, we've also got top posting, oh boy am I a happy bunny :) >> >> I'll leave someone3 else to explain, I just can't be bothered. >> >> > > Do you get paid to be a jerk, or is it just for yuks? If the latter, you're not funny. > Lucky I didn't say anything about the dirty knife. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From sturla.molden at gmail.com Fri Apr 11 10:00:07 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Fri, 11 Apr 2014 14:00:07 +0000 (UTC) Subject: python obfuscate References: Message-ID: <1276859620418917464.839320sturla.molden-gmail.com@news.gmane.org> alister wrote: > Concentrate on making the product (even) better rather than trying to > hide the unhideable. I think the number one reason for code obfuscation is an ignorant boss. Another reason might be to avoid the shame of showing crappy code to the customer. Sturla From harrismh777 at gmail.com Fri Apr 11 10:12:55 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 11 Apr 2014 09:12:55 -0500 Subject: Teaching python to non-programmers References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> Message-ID: On 4/10/14 3:52 PM, pete.bee.emm at gmail.com wrote: > > Do you get paid to be a jerk, or is it just for yuks? If the latter, you're not funny. > Mark is the c.l.python resident margin police. Think of him as a welcome committee with an attitude. :) From harrismh777 at gmail.com Fri Apr 11 10:35:08 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 11 Apr 2014 09:35:08 -0500 Subject: Teaching python to non-programmers In-Reply-To: References: Message-ID: <5347FD9C.6040105@gmail.com> On 4/10/14 10:54 AM, Lalitha Prasad K wrote: > Dear List > > Recently I was requested to teach python to a group of students of GIS > (Geographic Information Systems). Adults? ... what age ranges? > Their knowledge of programming is > zero. The objective is to enable them to write plug-ins for GIS software > like QGIS and ArcGIS. Its a fabulous idea. Integrating disciplines is the correct approach to computer science education in my opinion. From day one (and yes I was there on day one) computer science knows nothing about the insurance industry, and underwriters know nothing about programming. The way to get these two groups together is to integrate comp sci education with underwriting. > It would require them to learn, besides core > python, PyQt, QtDesigner. So my plan is to teach them core python, PyQt, > Qt Designer, in that order. A kind of "bottom up approach". Beautiful. > But the > students seem to feel that I should use "top down approach". That is, > show them how to write a plug-in, then PyQt and Qt Designer and then > enough of python so they can handle the above. The phrase "just enough python" is almost possible. I am working on a project I call SimplyPy that has this same goal in mind; but I'm not finished yet. But the idea is to boil the galaxy of python down to a small solar system with a couple of planets. If these cats are in their early twenties, no problem. If they really are "non programmers" it will be easier because they come to the table teachable. I would rather have twenty students "tabula rosa" than having one student who thinks they already know everything. marcus From harrismh777 at gmail.com Fri Apr 11 11:09:48 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 11 Apr 2014 10:09:48 -0500 Subject: python obfuscate References: Message-ID: On 4/10/14 8:29 PM, Wesley wrote: > Does python has any good obfuscate? Others have answered this well, but I thought I would give you another opinion, perhaps more direct. Obfuscation (hiding) of your source is *bad*, usually done for one of the following reasons: 1) Boss is paranoid and fears loss of revenues due to intellectual property theft. 2) Boss is ignorant of reverse engineering strategies available to folks who want to get to the heart of the matter. 3) Boss and|or coders are embarrassed for clients (or other coders) to see their art, or lack thereof. Sometimes this is also wanting to hide the fact that the product really isn't "worth" the price being charged for it?!? There really is no good reason to obfuscate your code. > Currently our company wanna release one product developed by > python to our customer. But dont's wanna others see the py code. This is the age of open source in computer science. It is far better to develop a strategy and culture of openness. Everyone benefits; especially your customers. I recommend the GPLv3 license. I also advocate for copyleft. How to leverage openness for capital gain, you might ask? Answer: provide a value add. Its not just about your code, or your "product". It should also be about your service, maintenance, support, packing, manuals, news letters, &c. Deliberately obfuscating your code is a negative; please consider an alternative strategy. marcus From torriem at gmail.com Fri Apr 11 11:19:08 2014 From: torriem at gmail.com (Michael Torrie) Date: Fri, 11 Apr 2014 09:19:08 -0600 Subject: python obfuscate In-Reply-To: References: Message-ID: <534807EC.3090902@gmail.com> On 04/10/2014 07:29 PM, Wesley wrote: > Hi all, Does python has any good obfuscate? > > Currently our company wanna release one product developed by python > to our customer. But dont's wanna others see the py code. > > I googled for a while but mostly just say using pyc. Any better one? > > Our product is deployed on Linux bed. I guess it all depends on what you are really trying to do. If you're trying to prevent people from making and using unauthorized copies of your software then even obfuscating the code certainly won't help that at all. If you're trying to prevent people from learning trade secrets, then simply don't put that part of your product in the hands of customers. And on this point the language doesn't matter. Could be a binary compiled from C++. Someone could, in theory, reverse-engineer and trace the code and uncover your secret algorithm. The question is, is it worth it for the mythical, theoretical, bad guy to do this? Is it worth it for you to go to lengths to prevent this theoretical possibility? If you have IP you truly need to keep secret, separate it out from your application and stick it on a server and talk to it over some form of RPC. If you're simply trying to keep the boss happy, simply wrapping up your python scripts into a self-contained executable format (say py2exe or a similar tool) is probably good enough. Most end users will never know or care what you build the app with, even if you have a directory full of open .py files. 99% of the users of a popular ebook app called Calibre never know or care that it's made of python and that you could go in and see the code. All they care about is they can click an icon and the program launches and runs. From rosuav at gmail.com Fri Apr 11 11:22:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Apr 2014 01:22:42 +1000 Subject: python obfuscate In-Reply-To: References: Message-ID: On Sat, Apr 12, 2014 at 1:09 AM, Mark H Harris wrote: > This is the age of open source in computer science. > > It is far better to develop a strategy and culture of openness. Everyone > benefits; especially your customers. I recommend the GPLv3 license. While I wholeheartedly agree with the ideal of open source, I don't like the GPL (any version), because of the annoying restrictions that end up running through projects. All sorts of projects can't go GPL, ergo can't use readline. Why? Because readline went for a policy of "force it to be GPL or nothing". Thank you so much, now I have to faff around with PostgreSQL to get decent editing keys (and the legality of that is apparently dubious, but IANAL and it's not my problem anyway). Postgres is open source, but not GPL, and it's linked to some other library (I disremember which) that's under a license incompatible with the GPL. For my code, I use the MIT license. Do what you like, only don't sue me. Okay, that's not something everyone will want to use, but it does make things easier on anyone who wants to distribute it. You want to release a third-party build of my program? Or even just package up my code into an installer? No problem; you aren't responsible to host the code. With GPL software, you *are*, as I found out when I tried to make a simple GTK updater; I'm legally required to make it clear that the source code is available from the same web site as the binaries are (even though I didn't build it, all I did was download the binaries from their site and download the corresponding source archives), and I'm also obliged from the perspective of practicality to make it clear that the source code is not necessary, lest my users be thoroughly confused. Completely unnecessary hassle; it's red tape applied to those who're keeping everything open, in order to have a weapon to wield against those who close things up. I'm aware that the GPL has its place. I'm fully aware that GPL violations, being pursued legally, help to ensure openness; and the borderline cases of "we could go proprietary or we could go open source" are sometimes tipped in favour of open source by an argument of "we could use this if we go open"; but for most people, please, pick a simpler license that puts less restrictions on usage. ChrisA From rosuav at gmail.com Fri Apr 11 11:30:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Apr 2014 01:30:27 +1000 Subject: python obfuscate In-Reply-To: <534807EC.3090902@gmail.com> References: <534807EC.3090902@gmail.com> Message-ID: On Sat, Apr 12, 2014 at 1:19 AM, Michael Torrie wrote: > Most end users will never know or care what you build the app with, even > if you have a directory full of open .py files. 99% of the users of a > popular ebook app called Calibre never know or care that it's made of > python and that you could go in and see the code. All they care about > is they can click an icon and the program launches and runs. Absolutely. When you run "hg something_or_other", you would expect that it's all written in Python, but some of it might not be, for all you know. Certainly with git there are several languages used (some are compiled binaries, some are shell scripts, some are Perl, gitk is TCL...), and it doesn't matter at all. Who cares? I type a command and it runs. If upstream decides to rewrite bash in Lua, I won't much care, and probably wouldn't even know (although somehow I suspect performance would drop... slightly...). Adding to your list, though: If you're trying to hide your source code for security, absolutely DO NOT! This is one of the most common reasons I've heard of; either because the "cryptographic" algorithms are hand-rolled and easy to reverse-engineer if you have the source, or because the keys are hard-coded in the program. Either way, you can't. It just won't work. People can get at your crypto, and if it's broken as soon as someone sees the source code, it's weak crypto to start with. ChrisA From marko at pacujo.net Fri Apr 11 11:36:47 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 11 Apr 2014 18:36:47 +0300 Subject: threading References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> <87wqexj7ge.fsf@elektro.pacujo.net> <685d594b-c31b-4629-b81d-4aa64d9e3394@googlegroups.com> <87sipkkj7p.fsf@elektro.pacujo.net> <19d537ee-dcc3-4265-8fce-bd24201e3dc4@googlegroups.com> Message-ID: <8761mfnai8.fsf@elektro.pacujo.net> Rustom Mody : > On Friday, April 11, 2014 10:45:08 AM UTC+5:30, Rustom Mody wrote: >> On Friday, April 11, 2014 2:14:42 AM UTC+5:30, Marko Rauhamaa wrote: >> > (1) oversimplification which makes it difficult to extend the design >> > and handle all of the real-world contingencies >> >> This I dont... > > I meant "Dont understand" The simplest example: there's no general way to terminate a thread. Hacks exist for some occasions, but they can hardly be considered graceful. Marko From steve+comp.lang.python at pearwood.info Fri Apr 11 11:49:57 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Apr 2014 15:49:57 GMT Subject: Language summit notes References: <53468982$0$29993$c3e8da3$5496439d@news.astraweb.com> <911d97b8-b472-4d4a-9d5c-a6a74acf1ec5@googlegroups.com> Message-ID: <53480f25$0$29993$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Apr 2014 13:48:50 +0100, Mark Lawrence wrote: > On 11/04/2014 10:25, wxjmfauth at gmail.com wrote: >> >> Unicode! >> >> > Works perfectly in Python 3.3+ thanks to the excellent work done as a > result of http://legacy.python.org/dev/peps/pep-0393/, the Flexible > String Representation, as we, with one noticable exception, are > perfectly well aware of. Please don't bait JMF. Writing a post for the sole purpose of getting a reaction from others is the definition of trolling. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Fri Apr 11 11:53:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Apr 2014 01:53:42 +1000 Subject: threading In-Reply-To: <8761mfnai8.fsf@elektro.pacujo.net> References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> <87wqexj7ge.fsf@elektro.pacujo.net> <685d594b-c31b-4629-b81d-4aa64d9e3394@googlegroups.com> <87sipkkj7p.fsf@elektro.pacujo.net> <19d537ee-dcc3-4265-8fce-bd24201e3dc4@googlegroups.com> <8761mfnai8.fsf@elektro.pacujo.net> Message-ID: On Sat, Apr 12, 2014 at 1:36 AM, Marko Rauhamaa wrote: > The simplest example: there's no general way to terminate a thread. > Hacks exist for some occasions, but they can hardly be considered > graceful. Having followed python-list for some time now, I have to agree... you can't terminate a thread, no matter how many posts it has in it! ChrisA From breamoreboy at yahoo.co.uk Fri Apr 11 11:57:59 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 11 Apr 2014 16:57:59 +0100 Subject: Language summit notes In-Reply-To: <53480f25$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <53468982$0$29993$c3e8da3$5496439d@news.astraweb.com> <911d97b8-b472-4d4a-9d5c-a6a74acf1ec5@googlegroups.com> <53480f25$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/04/2014 16:49, Steven D'Aprano wrote: > On Fri, 11 Apr 2014 13:48:50 +0100, Mark Lawrence wrote: > >> On 11/04/2014 10:25, wxjmfauth at gmail.com wrote: >>> >>> Unicode! >>> >>> >> Works perfectly in Python 3.3+ thanks to the excellent work done as a >> result of http://legacy.python.org/dev/peps/pep-0393/, the Flexible >> String Representation, as we, with one noticable exception, are >> perfectly well aware of. > > Please don't bait JMF. Writing a post for the sole purpose of getting a > reaction from others is the definition of trolling. > If you wish to interpret my words as baiting that's fine by me. From my perspective I'm simply making a statement of fact. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Fri Apr 11 11:58:39 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 11 Apr 2014 16:58:39 +0100 Subject: threading In-Reply-To: References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> <87wqexj7ge.fsf@elektro.pacujo.net> <685d594b-c31b-4629-b81d-4aa64d9e3394@googlegroups.com> <87sipkkj7p.fsf@elektro.pacujo.net> <19d537ee-dcc3-4265-8fce-bd24201e3dc4@googlegroups.com> <8761mfnai8.fsf@elektro.pacujo.net> Message-ID: On 11/04/2014 16:53, Chris Angelico wrote: > On Sat, Apr 12, 2014 at 1:36 AM, Marko Rauhamaa wrote: >> The simplest example: there's no general way to terminate a thread. >> Hacks exist for some occasions, but they can hardly be considered >> graceful. > > Having followed python-list for some time now, I have to agree... you > can't terminate a thread, no matter how many posts it has in it! > > ChrisA > Wro -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Fri Apr 11 12:02:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Apr 2014 02:02:18 +1000 Subject: Language summit notes In-Reply-To: References: <53468982$0$29993$c3e8da3$5496439d@news.astraweb.com> <911d97b8-b472-4d4a-9d5c-a6a74acf1ec5@googlegroups.com> <53480f25$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 12, 2014 at 1:57 AM, Mark Lawrence wrote: > If you wish to interpret my words as baiting that's fine by me. From my > perspective I'm simply making a statement of fact. It's almost now debatable whether you were metabaiting Steven into telling you off for trolling the resident troll... The time when we could have sane threads started by a jmf post about Unicode is now over. His posts no longer have false claims that crave rebuttal, so I advise completely ignoring them, and him, until such time as he makes a point worthy of a response. ChrisA From invalid at invalid.invalid Fri Apr 11 12:02:36 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 11 Apr 2014 16:02:36 +0000 (UTC) Subject: Unpacking U-Boot image file References: <6ed343e7-fa02-426a-a75f-3e1d164a6a61@googlegroups.com> Message-ID: On 2014-04-10, Rhodri James wrote: > On Wed, 09 Apr 2014 18:18:56 +0100, Rustom Mody wrote: >> On Wednesday, April 9, 2014 9:36:40 PM UTC+5:30, trewio wrote: >> >>> How to extract files from U-Boot image file, LZMA-compressed? >>> >>> Is there a Python script that can do this properly? >> >> For lzma theres this (recent) python library >> https://docs.python.org/dev/library/lzma.html >> >> Though you might just be better off with the command-line xz unxz etc >> >> After that.. whats the U-boot format? > > The Fine Manual (http://www.denx.de/wiki/view/DULG/UBootImages) isn't very > forthcoming, sadly; > > "U-Boot operates on "image" files which can be basically anything, > preceeded by a special header; see the definitions in include/image.h for > details; basically, the header defines the following image properties > > * Target Operating System > * Target CPU Architecture > * Compression Type > * Load Address > * Entry Point > * Image Name > * Image Timestamp" > > I suspect taking this apart may be a little involved. Not really. For the format you're talking about (single-file uImage), you can extract the data like so: data = open("foobar.uImage","rb").read()[64:] Then just uncompress 'data' as desired. If you want to look at individual fields in the heaer, here's the structure: #define IH_MAGIC 0x27051956 /* Image Magic Number */ #define IH_NMLEN 32 /* Image Name Length */ typedef struct image_header { uint32_t ih_magic; /* Image Header Magic Number */ uint32_t ih_hcrc; /* Image Header CRC Checksum */ uint32_t ih_time; /* Image Creation Timestamp */ uint32_t ih_size; /* Image Data Size */ uint32_t ih_load; /* Data Load Address */ uint32_t ih_ep; /* Entry Point Address */ uint32_t ih_dcrc; /* Image Data CRC Checksum */ uint8_t ih_os; /* Operating System */ uint8_t ih_arch; /* CPU architecture */ uint8_t ih_type; /* Image Type */ uint8_t ih_comp; /* Compression Type */ uint8_t ih_name[IH_NMLEN]; /* Image Name */ } image_header_t; Header fields are all in network byte order (bit-endian). However, there's also a "multi-file" uImage format that I suspect is what the OP is referring to (since he says he needs to extract "files" from a uImage file). http://www.isysop.com/unpacking-and-repacking-u-boot-uimage-files/ In that case, the "Image Type" field will be set to 4, and the 'data' field starts with a list of 32-bit image size values (network byte order, terminated by 0x00000000). That list is then followed by the image data. Here's a Python 2.7 program that reads the uImage header, prints some stuff and then reads the data for the image(s). What to _do_ with the data for the image(s) is left as an exercise for the gentle reader. -------------------------------------8<------------------------------------- #!/usr/bin/python import sys,struct f = open(sys.argv[1],"rb") (ih_magic, ih_hcrc, ih_time, ih_size, ih_load, ih_ep, ih_dcrc, ih_os, ih_arch, ih_type, ih_comp, ih_name) \ = struct.unpack("!IIIIIIIBBBB32s",f.read(64)) print "magic=%08x type=%d size=%d name='%s'" % (ih_magic, ih_type, ih_size, ih_name) if ih_type == 4: # multi-file: read image lengths from data imagesizes = [] while 1: size, = struct.unpack("!I",f.read(4)) if size == 0: break imagesizes.append(size) else: # single-file imagesizes = [ih_size] print imagesizes images = [f.read(size) for size in imagesizes] print [len(image) for image in images] extradata = f.read() if extradata: print "%d bytes of extra data" % len(extradata) -------------------------------------8<------------------------------------- -- Grant Edwards grant.b.edwards Yow! The Korean War must at have been fun. gmail.com From harrismh777 at gmail.com Fri Apr 11 12:12:09 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 11 Apr 2014 11:12:09 -0500 Subject: Language summit notes In-Reply-To: References: <53468982$0$29993$c3e8da3$5496439d@news.astraweb.com> <911d97b8-b472-4d4a-9d5c-a6a74acf1ec5@googlegroups.com> <53480f25$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53481459.6070909@gmail.com> On 4/11/14 11:02 AM, Chris Angelico wrote: > It's almost now debatable whether you were metabaiting Steven into > telling you off for trolling the resident troll... > QOTW From sturla.molden at gmail.com Fri Apr 11 12:13:47 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Fri, 11 Apr 2014 16:13:47 +0000 (UTC) Subject: python obfuscate References: Message-ID: <1195864610418924684.631243sturla.molden-gmail.com@news.gmane.org> Mark H Harris wrote: > This is the age of open source in computer science. > > It is far better to develop a strategy and culture of openness. > Everyone benefits; especially your customers. I recommend the GPLv3 > license. I also advocate for copyleft. I would not use GPL in a commercial product, but "Open Source" might still be beneficial. E.g. one can get better feedback and even bug fixes or code improvements from customers and other interested parties. It is a win-win situation. If I ran a software business (I don't currently do), I would gladly discount customers or pay anyone who help to improve my software. Open Source does not mean that software has to be free, that copyright is lost, or that copyleft is implied. Sturla From sturla.molden at gmail.com Fri Apr 11 12:13:47 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Fri, 11 Apr 2014 16:13:47 +0000 (UTC) Subject: python obfuscate References: Message-ID: <1711749978418925220.887886sturla.molden-gmail.com@news.gmane.org> Mark H Harris wrote: > Obfuscation (hiding) of your source is *bad*, usually done for one > of the following reasons: > 1) Boss is paranoid and fears loss of revenues due to intellectual > property theft. > 2) Boss is ignorant of reverse engineering strategies available to > folks who want to get to the heart of the matter. > 3) Boss and|or coders are embarrassed for clients (or other coders) > to see their art, or lack thereof. Sometimes this is also wanting to > hide the fact that the product really isn't "worth" the price being > charged for it?!? You can also add fear of patent trolls to this list. Particularly if you are in a startup and cannot afford a long battle in court. You can quickly go bankrupt on attorney fees. Sturla From breamoreboy at yahoo.co.uk Fri Apr 11 12:16:34 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 11 Apr 2014 17:16:34 +0100 Subject: Language summit notes In-Reply-To: References: <53468982$0$29993$c3e8da3$5496439d@news.astraweb.com> <911d97b8-b472-4d4a-9d5c-a6a74acf1ec5@googlegroups.com> <53480f25$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/04/2014 17:02, Chris Angelico wrote: > On Sat, Apr 12, 2014 at 1:57 AM, Mark Lawrence wrote: >> If you wish to interpret my words as baiting that's fine by me. From my >> perspective I'm simply making a statement of fact. > > It's almost now debatable whether you were metabaiting Steven into > telling you off for trolling the resident troll... > > The time when we could have sane threads started by a jmf post about > Unicode is now over. His posts no longer have false claims that crave > rebuttal, so I advise completely ignoring them, and him, until such > time as he makes a point worthy of a response. > > ChrisA > I have no further comment to make, regardless of who says what. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From invalid at invalid.invalid Fri Apr 11 12:18:07 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 11 Apr 2014 16:18:07 +0000 (UTC) Subject: threading References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> <87wqexj7ge.fsf@elektro.pacujo.net> <53477f29$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-04-11, Roy Smith wrote: > At a high level, threads and coroutines are really very similar. They > are both independent execution paths in the same process. I guess the > only real difference between them is that thread switching is mediated > by the operating system, so it can happen anywhere (i.e. at any > instruction boundary). That's only true if your threading system has pre-emption. Python's does, but not all do. If your threading system is cooperative rather than preemptive, then using coroutines is completely idential to threading with 2 threads. > Coroutines scheduling is handled in user code, As is cooperative multithreading. -- Grant Edwards grant.b.edwards Yow! My BIOLOGICAL ALARM at CLOCK just went off ... It gmail.com has noiseless DOZE FUNCTION and full kitchen!! From invalid at invalid.invalid Fri Apr 11 12:19:48 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 11 Apr 2014 16:19:48 +0000 (UTC) Subject: python obfuscate References: <572b740c-0ce2-4c01-a4cd-30d2e2463f2b@googlegroups.com> Message-ID: On 2014-04-11, Ian Kelly wrote: > On Thu, Apr 10, 2014 at 8:17 PM, Wesley wrote: >> Umm, just wanna make all .py files not human readable. >> >> Or, maybe need a tool like zend in php. > > The only reliable way to prevent a customer from reverse-engineering > your software is to not give them the software. For example, instead > of giving them software containing the critical code that you want to > protect, give them access to a web service running that code, which > you host and control. If you do that the odds of them obtaining your code are reduced, but don't assume they go to 0. ;) -- Grant Edwards grant.b.edwards Yow! I just heard the at SEVENTIES were over!! And gmail.com I was just getting in touch with my LEISURE SUIT!! From invalid at invalid.invalid Fri Apr 11 12:22:17 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 11 Apr 2014 16:22:17 +0000 (UTC) Subject: python obfuscate References: <1318687751418899035.169258sturla.molden-gmail.com@news.gmane.org> Message-ID: On 2014-04-11, Chris Angelico wrote: > On Fri, Apr 11, 2014 at 7:17 PM, Sturla Molden wrote: >> The only way to protect your code is never to ship anything. > > It's worth noting, as an aside, that this does NOT mean you don't > produce or sell anything. You can keep your code secure by running it > on a server and permitting users to access it; that's perfectly safe. You think a server that can be accessed by untrested people can be perfectly safe? Oh dear. -- Grant Edwards grant.b.edwards Yow! If our behavior is at strict, we do not need fun! gmail.com From invalid at invalid.invalid Fri Apr 11 12:27:27 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 11 Apr 2014 16:27:27 +0000 (UTC) Subject: python obfuscate References: Message-ID: On 2014-04-11, Sturla Molden wrote: > alister wrote: > >> Concentrate on making the product (even) better rather than trying to >> hide the unhideable. > > I think the number one reason for code obfuscation is an ignorant > boss. > > Another reason might be to avoid the shame of showing crappy code to > the customer. Another reason I've heard of is to try to reduce support efforts. If you distribute something that's easy to modify, then people will. And when it doesn't work, they'll call tech support and waste everybody's time trying to track down bugs that aren't actually _in_ the product you're shipping. -- Grant Edwards grant.b.edwards Yow! In Newark the at laundromats are open 24 gmail.com hours a day! From rustompmody at gmail.com Fri Apr 11 14:19:22 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 11 Apr 2014 11:19:22 -0700 (PDT) Subject: Teaching python to non-programmers In-Reply-To: <5347d343$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> <5347d343$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9e9e24f2-90d4-49a9-aa32-75632cf10cbc@googlegroups.com> On Friday, April 11, 2014 5:04:28 PM UTC+5:30, Steven D'Aprano wrote: > I've been in plenty of mailing list forums where interleaved posting was > required, but there's only so many times you can tell people off for > being rude before you start coming across as rude yourself. > It's one of those nasty aspects of human psychology: the guy who casually > and without malice tosses litter out of his car window, spoiling things > for everyone, is somehow considered less obnoxious than the person who > tells him off. Except in Switzerland, where if you leave your rubbish bin > out more than twenty minutes after its been emptied, the neighbours > consider it perfectly acceptable to tell you off, never mind that you've > been at work. And heaven help you if you take your discarded Christmas > tree down to the street too early. Yes this is correct: we make the world a worse place by choosing to be 'nice guys' when some telling off would help. And I am remiss on this matter since I dont post that python-google-groups link when I should. [Can never find the damn link when needed though I wrote half of it myself!] For the rest, Im not sure that you need my help in making a fool of yourself... Anyway since you are requesting said help, here goes: > On Thu, 10 Apr 2014 22:42:14 -0700, Rustom Mody wrote: > > > > People whose familiarity with religion is limited to the Judeo-Christian > > tradition are inclined to the view (usually implicit) that "being > > religious" == "belief in God" > > However there are religions where belief in God is irreligious -- > > > Jainism > > I think that it will come as rather a surprise to Jains to be told that > they don't believe in god. In fact, they believe in a multitude of gods > (not surprising, as Jainism is derived from Hinduism) and believe that > every soul has the potential to become a god. http://en.wikipedia.org/wiki/God_in_Jainism and particularly http://en.wikipedia.org/wiki/God_in_Jainism#Heavenly_Beings > > And others where it is is irrelevant -- Tao, Shinto. [There is > > the story of a westerner who wen to a shinto temple and said: All this > > (rites) is fine and beautiful but what's your *philosophy* To which he > > was told: "Philosophy? We have no philosophy! We dance!"] > > A nice story, but the name "Shinto" even means "The Way Of The Gods", so > claiming that Shinto is not about gods is rubbish. http://books.google.co.in/books?id=b-VACc7jcOAC&lpg=PA159&ots=femTbp96rh&dq=shinto%20%22We%20have%20no%20philosophy%22%20we%20dance&pg=PA159#v=onepage&q=shinto%20%22We%20have%20no%20philosophy%22%20we%20dance&f=false > > In middle-eastern society women are expected to dress heavier than in > > the West. A few years ago a girl went to school in France with a scarf > > and she was penalized. > > Citation please. I think this is bogus, although given how obnoxious some > schools can be I'm not quite prepared to rule it out altogether. I think > it's far more likely that she was only penalized for wearing full head- > covering (not just a scarf) after being warned that it was not part of > the school uniform and therefore not appropriate. In spite of Paul pointing out the link (thanks Paul) http://en.wikipedia.org/wiki/Islamic_scarf_controversy_in_France you still persist in > in this specific case, I stand by my skepticism So you think that wikipedia link/article is bogus? Anyway.. To come back to the point of those examples: You are welcome to your view: > I don't know that there is anyone here that thinks interleaved posting is > the norm among the majority of email users. Nor is anyone saying that > Usenet posters make up a majority of internet users. What we are saying > is that *interleaved posting is objectively better* for most forms of > email or news communication (although it is not a panacea), and > especially for *technical discussions* like those that occur here. All those examples were adduced only to say that like matters of dress and matters of God-belief are not absolute standards in any frame, in any sense, so also mail etiquette. From rustompmody at gmail.com Fri Apr 11 14:54:31 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 11 Apr 2014 11:54:31 -0700 (PDT) Subject: threading In-Reply-To: <8761mfnai8.fsf@elektro.pacujo.net> References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> <87wqexj7ge.fsf@elektro.pacujo.net> <685d594b-c31b-4629-b81d-4aa64d9e3394@googlegroups.com> <87sipkkj7p.fsf@elektro.pacujo.net> <19d537ee-dcc3-4265-8fce-bd24201e3dc4@googlegroups.com> <8761mfnai8.fsf@elektro.pacujo.net> Message-ID: <22978792-bb74-4d98-b840-0cde3ee6a9f4@googlegroups.com> On Friday, April 11, 2014 9:06:47 PM UTC+5:30, Marko Rauhamaa wrote: > Rustom Mody: > > On Friday, April 11, 2014 10:45:08 AM UTC+5:30, Rustom Mody wrote: > > >> On Friday, April 11, 2014 2:14:42 AM UTC+5:30, Marko Rauhamaa wrote: > > >> > (1) oversimplification which makes it difficult to extend the design > >> > and handle all of the real-world contingencies > >> > >> This I dont... > The simplest example: there's no general way to terminate a thread. > Hacks exist for some occasions, but they can hardly be considered > graceful. I was about to say that this is fairly close to my point, viz: Half-assed support in current languages does not imply any necessary problem in the idea -- just in the mainstream implementations of it. Then looking it up I find Go's goroutines have the same issue. Erlang processes though, are kill-able like quite any unix process http://www.erlang.org/doc/reference_manual/processes.html#id85098 What does that mean?? I am not quite sure... It may mean that Steven's > I think coroutines are awesome, but like all advanced concepts, sometimes > they can be abused, and sometimes they are hard to understand not because > they are hard to understand in and of themselves, but because they are > being used to do something inherently complicated. is right. Personally my view is the other way round: Concurrency (generalizing from coroutines) is not hard. The problem is that imperative programming and concurrency are deeply incompatible because imperative programming is almost by definition sequential programming and concurrency is by definition concurrent, ie non-sequential From marko at pacujo.net Fri Apr 11 15:27:21 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 11 Apr 2014 22:27:21 +0300 Subject: threading References: <87wqexmmuc.fsf@elektro.pacujo.net> <450892781418836111.682065sturla.molden-gmail.com@news.gmane.org> <87lhvdm9sw.fsf@elektro.pacujo.net> <70d69403-456a-43bc-84a6-c546983c90e5@googlegroups.com> <87wqexj7ge.fsf@elektro.pacujo.net> <685d594b-c31b-4629-b81d-4aa64d9e3394@googlegroups.com> <87sipkkj7p.fsf@elektro.pacujo.net> <19d537ee-dcc3-4265-8fce-bd24201e3dc4@googlegroups.com> <8761mfnai8.fsf@elektro.pacujo.net> <22978792-bb74-4d98-b840-0cde3ee6a9f4@googlegroups.com> Message-ID: <87eh13k6p2.fsf@elektro.pacujo.net> Rustom Mody : > Half-assed support in current languages does not imply any necessary > problem in the idea -- just in the mainstream implementations of it. > > Then looking it up I find Go's goroutines have the same issue. the promise of threads is that you only need to consider a single event out of any given state. Trouble is, in reality, you need ot consider a multitude of events in every state. Threads are not good at presenting that reality. Marko From pete.bee.emm at gmail.com Fri Apr 11 16:20:05 2014 From: pete.bee.emm at gmail.com (pete.bee.emm at gmail.com) Date: Fri, 11 Apr 2014 13:20:05 -0700 (PDT) Subject: Teaching python to non-programmers In-Reply-To: References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> Message-ID: <4e99defd-a693-4bd7-8470-7b8055d6dff8@googlegroups.com> On Thursday, April 10, 2014 3:40:22 PM UTC-7, Rhodri James wrote: > It's called irony, and unfortunately Mark is reacting to an all-to-common > situation that GoogleGroups foists on unsuspecting posters like yourself. People who say "I can't be bothered to correct this" while posting a wise a$$ correction are just trolling, probably not funny in real life either. I think if you're going to wise off than be witty about it, otherwise just a terse reference to a link. At any rate, my original point stands. You're not teaching on planet Vulcan. Better to teach things in an odd order if that helps motivates your students. It's not like people in real life carefully examine all available documentation before learning some piece of tech. Usually they shrug and say "what's the worst that could happen", dive in, and roll with the consequences. From noone at nowhere.net Fri Apr 11 17:33:02 2014 From: noone at nowhere.net (blindanagram) Date: Fri, 11 Apr 2014 22:33:02 +0100 Subject: indexing in format strings Message-ID: With: l = [1,2,3] this: print('{0[0]:d}..{0[2]:d}'.format(l)) gives 1..3 but this: print('{0[0]:d}..{0[-1]:d}'.format(l)) gives: Traceback (most recent call last): File "", line 1, in builtins.TypeError: list indices must be integers, not str which seems to me counterintuitive. I expected indexing in a format string to behave as it does elsewhere but this seems not to be true. From breamoreboy at yahoo.co.uk Fri Apr 11 17:43:59 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 11 Apr 2014 22:43:59 +0100 Subject: indexing in format strings In-Reply-To: References: Message-ID: On 11/04/2014 22:33, blindanagram wrote: > With: > > l = [1,2,3] > > this: > > print('{0[0]:d}..{0[2]:d}'.format(l)) > > gives 1..3 but this: > > print('{0[0]:d}..{0[-1]:d}'.format(l)) > > gives: > > Traceback (most recent call last): > File "", line 1, in > builtins.TypeError: list indices must be integers, not str > > which seems to me counterintuitive. > > I expected indexing in a format string to behave as it does elsewhere > but this seems not to be true. > See http://bugs.python.org/issue7951 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From tjreedy at udel.edu Fri Apr 11 17:45:02 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 11 Apr 2014 17:45:02 -0400 Subject: indexing in format strings In-Reply-To: References: Message-ID: On 4/11/2014 5:33 PM, blindanagram wrote: > With: > > l = [1,2,3] > > this: > > print('{0[0]:d}..{0[2]:d}'.format(l)) > > gives 1..3 but this: > > print('{0[0]:d}..{0[-1]:d}'.format(l)) > > gives: > > Traceback (most recent call last): > File "", line 1, in > builtins.TypeError: list indices must be integers, not str > > which seems to me counterintuitive. > > I expected indexing in a format string to behave as it does elsewhere > but this seems not to be true. Been discussed on the tracker. Consider: >>> '{0[-1]}'.format({'-1': 'neg int key'}) 'neg int key' Not quoting string keys within the format string introduces ambiguity settled by 'string unless all digits, then int'. -- Terry Jan Reedy From joshua at landau.ws Fri Apr 11 17:48:01 2014 From: joshua at landau.ws (Joshua Landau) Date: Fri, 11 Apr 2014 22:48:01 +0100 Subject: python obfuscate In-Reply-To: <802155420418900251.086281sturla.molden-gmail.com@news.gmane.org> References: <802155420418900251.086281sturla.molden-gmail.com@news.gmane.org> Message-ID: On 11 April 2014 10:17, Sturla Molden wrote: > Joshua Landau wrote: > >> However, if this really is your major blocker to using Python, I >> suggest compiling with Cython. > > Cython restains all the code as text, e.g. to readable generate exceptions. > Users can also still steal the extension modules and use them in their own > code. In general, Cython is not useful as an obfuscation tool. Ah, thanks for the info. I imagine it's perfectly easy to get around that, though, through basic removal at the C phase. I doubt it's worthwhile doing so, but deobfuscation will still be harder than a .pyc. From noone at nowhere.net Fri Apr 11 19:13:44 2014 From: noone at nowhere.net (blindanagram) Date: Sat, 12 Apr 2014 00:13:44 +0100 Subject: indexing in format strings In-Reply-To: References: Message-ID: On 11/04/2014 22:33, blindanagram wrote: Thanks, Mark and Terry, for your rapid responses. An interesting thread. Brian From steve+comp.lang.python at pearwood.info Fri Apr 11 20:49:40 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Apr 2014 00:49:40 GMT Subject: python obfuscate References: Message-ID: <53488da4$0$29993$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Apr 2014 16:27:27 +0000, Grant Edwards wrote: > Another reason I've heard of is to try to reduce support efforts. > > If you distribute something that's easy to modify, then people will. The majority of people will treat your app as a black box. Of course, a small minority (either out of actual competence, or sheer incompetence) will try to modify anything supplied as source code. (And who is to say that they shouldn't be permitted to, if they've bought your product?) > And when it doesn't work, they'll call tech support and waste > everybody's time trying to track down bugs that aren't actually _in_ the > product you're shipping. I wonder whether Red Hat and Ubuntu have this problem? Somehow I think that the magnitude of it is grossly exaggerated. But in any case, this at least is trivially solved: take the md5 of your application, then before doing any support check whether the md5 of their copy has changed. A tiny Python script (small enough to visually inspect) can do this on systems without a md5sum utility. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rustompmody at gmail.com Fri Apr 11 20:50:06 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 11 Apr 2014 17:50:06 -0700 (PDT) Subject: Teaching python to non-programmers In-Reply-To: <4e99defd-a693-4bd7-8470-7b8055d6dff8@googlegroups.com> References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <4e99defd-a693-4bd7-8470-7b8055d6dff8@googlegroups.com> Message-ID: <4fb49baf-35bc-4fd3-a28f-6e3e1fb2b55d@googlegroups.com> On Saturday, April 12, 2014 1:50:05 AM UTC+5:30, pete.b... at gmail.com wrote: > On Thursday, April 10, 2014 3:40:22 PM UTC-7, Rhodri James wrote: > > > It's called irony, and unfortunately Mark is reacting to an all-to-common > > situation that GoogleGroups foists on unsuspecting posters like yourself. > > > > People who say "I can't be bothered to correct this" while posting a wise a$$ correction are just trolling, probably not funny in real life either. I think if you're going to wise off than be witty about it, otherwise just a terse reference to a link. Thanks Pete for taking the trouble for aligning your posting style with the norms expected out here. On problem -- the over long lines -- remains. If you compare your post https://mail.python.org/pipermail/python-list/2014-April/670693.html with typical neighboring others, you will see that. [Just for the record I should mention that I did not know this to be a problem for a long time until someone pointed it out to me. ] From steve+comp.lang.python at pearwood.info Fri Apr 11 21:45:51 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Apr 2014 01:45:51 GMT Subject: Teaching python to non-programmers References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> <5347d343$0$29993$c3e8da3$5496439d@news.astraweb.com> <9e9e24f2-90d4-49a9-aa32-75632cf10cbc@googlegroups.com> Message-ID: <53489acf$0$29993$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Apr 2014 11:19:22 -0700, Rustom Mody wrote: > On Friday, April 11, 2014 5:04:28 PM UTC+5:30, Steven D'Aprano wrote: [...] > For the rest, Im not sure that you need my help in making a fool of > yourself... Anyway since you are requesting said help, here goes: Very strong words. >> On Thu, 10 Apr 2014 22:42:14 -0700, Rustom Mody wrote: >> >> >> > People whose familiarity with religion is limited to the >> > Judeo-Christian tradition are inclined to the view (usually implicit) >> > that "being religious" == "belief in God" >> > However there are religions where belief in God is irreligious -- >> >> > Jainism >> >> I think that it will come as rather a surprise to Jains to be told that >> they don't believe in god. In fact, they believe in a multitude of gods >> (not surprising, as Jainism is derived from Hinduism) and believe that >> every soul has the potential to become a god. > > http://en.wikipedia.org/wiki/God_in_Jainism and particularly > http://en.wikipedia.org/wiki/God_in_Jainism#Heavenly_Beings - You state that in Jainism, belief in god (which one?) is "irreligious" (i.e. hostile to religion); - I point out that in the case of Jains, belief in many gods is in fact a core part of their religion; - you attempt to refute me by linking to an article which confirms that belief in gods is part of Jainism. And that's supposed to prove that I'm wrong? Perhaps you think that "belief in gods" is ipso facto the same as "worshipping those gods"? That's an awfully naive view, especially for someone who started this discussion by complaining about the naivety of other people's understanding of religion. >> > And others where it is is irrelevant -- Tao, Shinto. [There is the >> > story of a westerner who wen to a shinto temple and said: All this >> > (rites) is fine and beautiful but what's your *philosophy* To which >> > he was told: "Philosophy? We have no philosophy! We dance!"] >> >> A nice story, but the name "Shinto" even means "The Way Of The Gods", >> so claiming that Shinto is not about gods is rubbish. > > http://books.google.co.in/books?id=b- VACc7jcOAC&lpg=PA159&ots=femTbp96rh&dq=shinto%20%22We%20have%20no% 20philosophy%22%20we%20dance&pg=PA159#v=onepage&q=shinto%20%22We%20have% 20no%20philosophy%22%20we%20dance&f=false What's this supposed to prove? It's a nice story. The book you linked to doesn't give any more details than you do, it even states "A story is told". It's an unnamed philosopher, an unnamed priest from an anonymous temple. There is *absolutely nothing* suggesting it ever happened in real life, but even if it did, it certainly doesn't suggest anything about Shinto. If anything, it's about the ignorance of the supposed American philosopher. Did you think I was questioning the existence of the story? I said nothing to suggest you made the story up (although it seems to me that the author you quote probably did). I don't question the existence of the story. I question that the story is meaningful. It seems to me that only somebody *completely ignorant of Shinto* can possible think that Shinto in general has no philosophy or religious meaning. Shinto, as a glorified (literally) folk-religion, may lack the sort of over-arching grand philosophies of (say) the Catholic Church, but I think it is an astonishingly foolish thing to suggest that all they do is dance. Even figuratively. >> > In middle-eastern society women are expected to dress heavier than in >> > the West. A few years ago a girl went to school in France with a >> > scarf and she was penalized. >> >> Citation please. I think this is bogus, although given how obnoxious >> some schools can be I'm not quite prepared to rule it out altogether. I >> think it's far more likely that she was only penalized for wearing full >> head- covering (not just a scarf) after being warned that it was not >> part of the school uniform and therefore not appropriate. > > In spite of Paul pointing out the link (thanks Paul) > > http://en.wikipedia.org/wiki/Islamic_scarf_controversy_in_France > > you still persist in > >> in this specific case, I stand by my skepticism > > So you think that wikipedia link/article is bogus? That article supports what I stated: the three girls (not one) were not penalized without warning for merely turning up to school with scarves. They were penalized for refusing to remove their hajibs, which were against the school's dress code. -- Steven D'Aprano http://import-that.dreamwidth.org/ From dev at joernhees.de Fri Apr 11 20:20:44 2014 From: dev at joernhees.de (=?windows-1252?Q?J=F6rn_Hees?=) Date: Sat, 12 Apr 2014 02:20:44 +0200 Subject: module version number support for semver.org In-Reply-To: References: Message-ID: <49010C54-23B2-445D-A495-5D005E3EE912@joernhees.de> On 11 Apr 2014, at 01:34, Terry Reedy wrote: > On 4/10/2014 6:45 PM, J?rn Hees wrote: >> what do you think about officially supporting Semantic Versioning? >> (http://semver.org ) > > It is a nice fantasy. ;) didn?t say it?s perfect, just that it?s widely used and we should support it. I like the ?fantasy" as it at least tries to give some kind of a meaning to version numbers. Sorry for not going into the details here, but that would quickly lead away from my main point. > This is not to say that Semver does not improve the situation when it can be used. I definitely think it does, i?ll count that as half a vote for it ;) j From tjreedy at udel.edu Fri Apr 11 22:44:04 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 11 Apr 2014 22:44:04 -0400 Subject: indexing in format strings In-Reply-To: References: Message-ID: On 4/11/2014 7:13 PM, blindanagram wrote: > On 11/04/2014 22:33, blindanagram wrote: > > Thanks, Mark and Terry, for your rapid responses. > > An interesting thread. It just occurred to me today, and I verified, that '+1' is also seen as a string. >>> '{0[-1]}'.format({'-1': 'neg int key'}) 'neg int key' >>> '{0[+1]}'.format({'+1': 'neg int key'}) 'neg int key' >>> '{0[+1]}'.format([1,2,3]) Traceback (most recent call last): File "", line 1, in '{0[+1]}'.format([1,2,3]) TypeError: list indices must be integers, not str -- Terry Jan Reedy From ben+python at benfinney.id.au Sat Apr 12 00:52:33 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 12 Apr 2014 14:52:33 +1000 Subject: python obfuscate References: <53488da4$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85d2gnxi7i.fsf@benfinney.id.au> Steven D'Aprano writes: > On Fri, 11 Apr 2014 16:27:27 +0000, Grant Edwards wrote: > > > Another reason I've heard of is to try to reduce support efforts. > > > > If you distribute something that's easy to modify, then people will. > > The majority of people will treat your app as a black box. Of course, a > small minority (either out of actual competence, or sheer incompetence) > will try to modify anything supplied as source code. Further, those who are motivated to modify the product they receive from you will often have motivations that remain even in the absence of source code. In many cases that motivation is strong enough they will *still* modify the product in an attempt to get it to do what they want. So in those cases, even the total absence of source code is not achieving the putative goal of ?stop the recipient from modifying the product?. > (And who is to say that they shouldn't be permitted to, if they've > bought your product?) Indeed. People in the position of selling something to a customer need to stop trying to have it both ways: Either the vendor owns the product, or the customer does. Either the customer is paying to own the product, and thereby has full rights to use that product and modify it and sell it on to other people without the vendor having any further say in the matter; or: The vendor continues to own the product even while the customer possesses it, and is responsible for controlling how it's used and is culpable for any harmful effects of that use. A third way is possible, but fans of obfuscation probably won't like it: Software is inherently not amenable to the limits of scarce physical property at all, and attempts to treat it as scarce and exclusive and ?owned? by one party are futile and counter to physical laws. This is the position taken by Thomas Jefferson in 1813: ?If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea.? -- \ ?By instructing students how to learn, unlearn, and relearn, a | `\ powerful new dimension can be added to education.? ?Alvin | _o__) Toffler, _Future Shock_, 1970 | Ben Finney From cmpython at gmail.com Sat Apr 12 01:01:52 2014 From: cmpython at gmail.com (CM) Date: Fri, 11 Apr 2014 22:01:52 -0700 (PDT) Subject: python obfuscate In-Reply-To: References: Message-ID: On Friday, April 11, 2014 12:13:47 PM UTC-4, Sturla Molden wrote: > Mark H Harris wrote: > > > Obfuscation (hiding) of your source is *bad*, usually done for one > > of the following reasons: > > > 1) Boss is paranoid and fears loss of revenues due to intellectual > > property theft. > > 2) Boss is ignorant of reverse engineering strategies available to > > folks who want to get to the heart of the matter. > > 3) Boss and|or coders are embarrassed for clients (or other coders) > > to see their art, or lack thereof. Sometimes this is also wanting to > > hide the fact that the product really isn't "worth" the price being > > charged for it?!? > > You can also add fear of patent trolls to this list. Particularly if you > are in a startup and cannot afford a long battle in court. You can quickly > go bankrupt on attorney fees. > > Sturla You're saying that fear of patent trolls is yet another bad reason to obfuscate your code? But then it almost sounds like you think it is a justifiable reason. So I don't think I understand your point. Whether a patent troll has your original code or not has no bearing on the patent infringement. From bob.martin at excite.com Sat Apr 12 07:28:13 2014 From: bob.martin at excite.com (Bob Martin) Date: Sat, 12 Apr 2014 07:28:13 BST Subject: Interleaved vs. top-posting References: Message-ID: in 720726 20140411 134419 Tim Chase wrote: >On 2014-04-11 13:59, Chris Angelico wrote: >> I have seen plenty of cultures where people are unaware of the value >> of interleaved/bottom posting, but so far, not one where anyone has >> actually required it. Not one. > >The only time I've seen top-posting required (though there was >nothing about trimming/dropping the content from the bottom) was on >some lists for blind users where they wanted the new content at the >top of the email rather than having to wade through lots of content >they'd heard previously. The actual context was usually either given >by in-sentence referencing to the topic, or the subject-heading >(blind folks seem to have an incredible memory for things sighted >folks are usually too lazy to remember). I read IBM's internal forums from 1978 on (on VM/CMS). Top posting was the norm where quoted text was included, though quoting wasn't necessary as there was a means to display the post being answered. From denismfmcmahon at gmail.com Sat Apr 12 03:48:53 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sat, 12 Apr 2014 07:48:53 +0000 (UTC) Subject: python obfuscate References: Message-ID: On Thu, 10 Apr 2014 18:29:21 -0700, Wesley wrote: > Currently our company wanna release one product developed by python to > our customer. But dont's wanna others see the py code. Your business model is fucked. -- Denis McMahon, denismfmcmahon at gmail.com From me at eddy-ilg.net Sat Apr 12 02:37:20 2014 From: me at eddy-ilg.net (Eddy Ilg) Date: Sat, 12 Apr 2014 08:37:20 +0200 Subject: so module loading fails In-Reply-To: <87d2gofkuu.fsf@handshake.de> References: <53469B77.50007@eddy-ilg.net> <87d2gofkuu.fsf@handshake.de> Message-ID: <5348DF20.3020602@eddy-ilg.net> I found out it was an issue with SIP - the version tag seemed to be wrong. Now another symbol is missing: _ZN10QArrayData11shared_nullE I can't find this symbol exported anywhere. Anyone knows where it is defined? Am 11.04.2014 08:20, schrieb dieter: > Eddy Ilg writes: > >> ... >> >> Checking the symbols of Entity.so gives: >> # nm Entity.so | grep PyInit_Entity >> 0000000000001e5c t PyInit_Entity > When I remember right, "t" means a "local" (aka "static") symbol - you need > instead a "global" symbol (identified by "T"). > From sturla.molden at gmail.com Sat Apr 12 08:07:57 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Sat, 12 Apr 2014 12:07:57 +0000 (UTC) Subject: python obfuscate References: Message-ID: <1953571697418996821.098374sturla.molden-gmail.com@news.gmane.org> CM wrote: > You're saying that fear of patent trolls is yet another bad reason to > obfuscate your code? But then it almost sounds like you think it is a > justifiable reason. So I don't think I understand your point. Whether a > patent troll has your original code or not has no bearing on the patent > infringement. There might be no infringment. Patent trolls usually possess invalid patents, as they constitute no real invention. These are usually not engineers who have invented something, but lawyers who have been granted patent on vague thoughts for the purpose of "selling protection". The US patent office has allowed this to happen, by believing that any invalid patent can be challenged in court, so their review process is close to non-existent. If patent trolls have your code they are in a better position to blackmail. They can use your code to generate bogus "legal documents" in the thousands, and thereby turn up your legal expenses. Sturla From wxjmfauth at gmail.com Sat Apr 12 08:25:22 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 12 Apr 2014 05:25:22 -0700 (PDT) Subject: Language summit notes In-Reply-To: References: <53468982$0$29993$c3e8da3$5496439d@news.astraweb.com> <911d97b8-b472-4d4a-9d5c-a6a74acf1ec5@googlegroups.com> <53480f25$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: ------ Regarding the Flexible String Representation, I have always been very coherent in the examples I gave (usually with and/or from an interactive intepreter - not relevant). I never seen once somebody pointing or beeing able to point what is wrong in those examples. jmf From ned at nedbatchelder.com Sat Apr 12 08:53:15 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 12 Apr 2014 08:53:15 -0400 Subject: Language summit notes In-Reply-To: References: <53468982$0$29993$c3e8da3$5496439d@news.astraweb.com> <911d97b8-b472-4d4a-9d5c-a6a74acf1ec5@googlegroups.com> <53480f25$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/12/14 8:25 AM, wxjmfauth at gmail.com wrote: > ------ > > Regarding the Flexible String Representation, I have always > been very coherent in the examples I gave (usually with and/or > from an interactive intepreter - not relevant). > I never seen once somebody pointing or beeing able to point > what is wrong in those examples. We aren't going to engage in this topic. The previous discussions have always ended the same way. You should refer to those threads if you want to re-acquaint yourself with other people's views on your theory and discourse. --Ned. > > jmf > -- Ned Batchelder, http://nedbatchelder.com From james at brwr.org Sat Apr 12 17:07:53 2014 From: james at brwr.org (James Brewer) Date: Sat, 12 Apr 2014 14:07:53 -0700 Subject: Travis CI + Python 3.3 + Django 1.7b1 Message-ID: Hi, I've been trying to get a build running for my Python 3.3 + Django 1.7b1 project, but I've run into an issue and I'm not sure how to solve it. When the command `pip install -r requirements.txt` gets run, the build errs with a message referencing some Python 2.x syntax when `import ez_setup` is called. Here is the log from the build: https://s3.amazonaws.com/archive.travis-ci.org/jobs/22824057/log.txt Here is the .travis.yml file associated with the project: https://github.com/WargamesIO/wargames/blob/master/.travis.yml Any ideas? :) Happy Saturday! -- *James Brewer* *http://www.brwr.org/ * *Software Engineer @ RealScout | What is RealScout? * *Twitter* *twitter.com/jamesbrwr * *GitHub* *github.com/brwr* *StackOverflow** stackoverflow.com/users/2052923/james-brewer * *LinkedIn* *linkedin.com/in/jamesbrwr * ? *M**y favorite RealScout search is Modern & High-Tech Homes in Atherton * -------------- next part -------------- An HTML attachment was scrubbed... URL: From cmpython at gmail.com Sat Apr 12 23:14:52 2014 From: cmpython at gmail.com (CM) Date: Sat, 12 Apr 2014 20:14:52 -0700 (PDT) Subject: python obfuscate In-Reply-To: References: Message-ID: On Saturday, April 12, 2014 8:07:57 AM UTC-4, Sturla Molden wrote: > CM wrote: > > > > > You're saying that fear of patent trolls is yet another bad reason to > > > obfuscate your code? But then it almost sounds like you think it is a > > > justifiable reason. So I don't think I understand your point. Whether a > > > patent troll has your original code or not has no bearing on the patent > > > infringement. > > > > There might be no infringment. Patent trolls usually possess invalid > patents, as they constitute no real invention. These are usually not > engineers who have invented something, but lawyers who have been granted > patent on vague thoughts for the purpose of "selling protection". The US > patent office has allowed this to happen, by believing that any invalid > patent can be challenged in court, so their review process is close to > non-existent. If patent trolls have your code they are in a better position > to blackmail. They can use your code to generate bogus "legal documents" in > the thousands, and thereby turn up your legal expenses. > > Sturla Ahh, I see. I suppose such an entity might try that. But I would hope it would not result in additional legal expenses, in that anyone with the smallest amount of legal understanding of patents knows that in doesn't matter in what way the invention is brought about in specific code, just that the *resulting invention* is similar enough to the claims of the patent. That is, the invention could be written in Python, or C, or COMAL, in whatever spaghetti the author wants, and none of that is pertinent to the issue of patent infringement (whereas it might very well be to the issue of copyright infringement). I would hope the defense lawyer(s) and judge struck that from the proceedings, but I am probably hoping for too rational an outcome. From stefan_ml at behnel.de Sun Apr 13 00:58:12 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 13 Apr 2014 06:58:12 +0200 Subject: python obfuscate In-Reply-To: <802155420418900251.086281sturla.molden-gmail.com@news.gmane.org> References: <802155420418900251.086281sturla.molden-gmail.com@news.gmane.org> Message-ID: Sturla Molden, 11.04.2014 11:17: > Joshua Landau wrote: > >> However, if this really is your major blocker to using Python, I >> suggest compiling with Cython. > > Cython restains all the code as text, e.g. to readable generate exceptions. No, it actually doesn't. It only keeps the code in C comments, to make reading the generated code easier. Those comments get stripped during compilation, obviously. The only thing it keeps for its exception tracebacks is the line numbers, both for the C code (which you can disable) and for the original Python code. That shouldn't be very telling if you don't have the original source code. Stefan PS: disclaimer: I never needed to obfuscate Python code with Cython, and this use case is definitely not a design goal of the compiler. No warranties, see the license. From dieter at handshake.de Sun Apr 13 02:07:33 2014 From: dieter at handshake.de (dieter) Date: Sun, 13 Apr 2014 08:07:33 +0200 Subject: so module loading fails References: <53469B77.50007@eddy-ilg.net> <87d2gofkuu.fsf@handshake.de> <5348DF20.3020602@eddy-ilg.net> Message-ID: <87bnw5oj8a.fsf@handshake.de> Eddy Ilg writes: > I found out it was an issue with SIP - the version tag seemed to be wrong. > > Now another symbol is missing: > _ZN10QArrayData11shared_nullE > > I can't find this symbol exported anywhere. Anyone knows where it is > defined? It looks like a "C++" symbol. Python must be specially build in order that the standard "C++" libraries are included. From intanlilyana at gmail.com Sun Apr 13 03:14:14 2014 From: intanlilyana at gmail.com (intanlilyana at gmail.com) Date: Sun, 13 Apr 2014 00:14:14 -0700 (PDT) Subject: Job Opportunity - Senior Python Developer Message-ID: Senior Python Developer Engineering | San Jose, CA, United States Contact - Lily Lily at winmaxcorp.com You will: Build an IDM (Identity and Access Management) system for the cloud offerings that's powered by OpenStack. The plan is to build multiple components that make up IDM: * Experience with LDAP * Create an API Proxy using Python. Qualifications: * Designing and writing python software, packages - for commercial or open source * Usage of standard libraries * Strong python distributions * REST/JSON/XML * WSGI frameworks * ORM frameworks * usage python frameworks for various components * testing/tox automation Please send me your updated resume to lily at winmaxcorp.com From intanlilyana at gmail.com Sun Apr 13 03:15:04 2014 From: intanlilyana at gmail.com (intanlilyana at gmail.com) Date: Sun, 13 Apr 2014 00:15:04 -0700 (PDT) Subject: Job Opportunity - Senior Web Developer Message-ID: <22648401-3ae0-4061-abfa-f310f644ad84@googlegroups.com> Senior Web Developer (Python) Engineering | Mountain View, CA, United States Contact - Lily Lily at winmaxcorp.com COMPANY DESCRIPTION Our Clent is a social networking website for people in professional occupations. It is mainly used for professional networking. JOB DESCRIPTION The engineering culture at our client is based on building and integrating cutting-edge technologies while encouraging creativity, innovation, and expansion. The engineers constantly raise the bar for excellence, motivating each other to tackle challenges and take intelligent risks. The industry is moving fast and the engineers are right there with it! You will help drive front-end development for an internal tool that addresses the #1 operating priority for the client - talent. You will collaborate with visual/interaction designers, engineers, and product managers to launch new products, iterate on existing features, and build a world-class user experience. With our client site and business experiencing dramatic growth, we are seeking engineers to join our client team and contribute to scaling to the next level. QUALIFICATIONS * Ability to work on-site in Mountain View * 4+ years experience with semantic HTML/XHTML and CSS * 4+ years experience writing clean, unobtrusive Javascript/AJAX including experience with common libraries (YUI, jQuery, etc) and debugging tools (Firebug, etc.) * An encyclopedic knowledge of browser quirks and their remedies * Knowledge of (and a passion for) current trends and best practices in front-end architecture, including performance, accessibility and usability * Familiarity and comfort with command-line applications * Experience writing object-oriented code for Python (preferred), Ruby, PHP or similar * Experience writing code for a MVC web framework: Flask, Django, Ruby on Rails, CakePHP or similar * Experience with Jinja, Bootstrap, or SQLAlchemy a plus * Comfortable with agile dev cycle - we are using advanced scrum methods * You have excellent communication skills, initiative and teamwork and you love to connect with your internal customers to hear and address their concerns * Bachelors degree or equivalent experience required ADDITIONAL INFORMATION Please send me your updated resume to lily at winmaxcorp.com From ben+python at benfinney.id.au Sun Apr 13 03:22:28 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 13 Apr 2014 17:22:28 +1000 Subject: Job Opportunity - Senior Python Developer References: Message-ID: <858ur9y9qj.fsf@benfinney.id.au> intanlilyana at gmail.com writes: > Senior Python Developer > Engineering | San Jose, CA, United States Please don't send emails for recruitment to this forum. The Python Job Board is specifically a resource for job postings. (Currently unavailable, but that doesn't make this forum any more appropriate.) -- \ ?I am too firm in my consciousness of the marvelous to be ever | `\ fascinated by the mere supernatural ?? ?Joseph Conrad, _The | _o__) Shadow-Line_ | Ben Finney From wxjmfauth at gmail.com Sun Apr 13 03:38:06 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 13 Apr 2014 00:38:06 -0700 (PDT) Subject: Language summit notes In-Reply-To: References: <53468982$0$29993$c3e8da3$5496439d@news.astraweb.com> <911d97b8-b472-4d4a-9d5c-a6a74acf1ec5@googlegroups.com> <53480f25$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <538ea131-2013-4fbb-92d4-d39890180074@googlegroups.com> Le samedi 12 avril 2014 14:53:15 UTC+2, Ned Batchelder a ?crit?: > On 4/12/14 8:25 AM, wxjmfauth at gmail.com wrote: > > > ------ > > > > > > Regarding the Flexible String Representation, I have always > > > been very coherent in the examples I gave (usually with and/or > > > from an interactive intepreter - not relevant). > > > I never seen once somebody pointing or beeing able to point > > > what is wrong in those examples. > > > > We aren't going to engage in this topic. The previous discussions have > > always ended the same way. You should refer to those threads if you want > > to re-acquaint yourself with other people's views on your theory and > > discourse. > > > > --Ned. > > > > > > > > jmf > > > > > > > May I recall again, I mainly "pointed" facts, examples, ... I can almost count on the fingers of one of my hands, the number of users/posters, who tried to reproduce the examples I gave! In fact, that's you (plural), who are dicussing (my examples). jmf From rosuav at gmail.com Sun Apr 13 04:00:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 13 Apr 2014 18:00:19 +1000 Subject: Job Opportunity - Senior Web Developer In-Reply-To: <22648401-3ae0-4061-abfa-f310f644ad84@googlegroups.com> References: <22648401-3ae0-4061-abfa-f310f644ad84@googlegroups.com> Message-ID: On Sun, Apr 13, 2014 at 5:15 PM, wrote: > Senior Web Developer (Python) > Engineering | Mountain View, CA, United States The Python Job Board is in a bit of a state of flux at the moment, but you can still put submissions to it: https://www.python.org/community/jobs/ ChrisA From rosuav at gmail.com Sun Apr 13 04:01:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 13 Apr 2014 18:01:16 +1000 Subject: Job Opportunity - Senior Python Developer In-Reply-To: <858ur9y9qj.fsf@benfinney.id.au> References: <858ur9y9qj.fsf@benfinney.id.au> Message-ID: On Sun, Apr 13, 2014 at 5:22 PM, Ben Finney wrote: > intanlilyana at gmail.com writes: > >> Senior Python Developer >> Engineering | San Jose, CA, United States > > Please don't send emails for recruitment to this forum. > > The Python Job Board is > specifically a resource for job postings. (Currently unavailable, but > that doesn't make this forum any more appropriate.) Whoops, I hadn't read your post and I just responded to the other of these two posts. Sorry for the noise! ChrisA From phd at phdru.name Sun Apr 13 08:28:52 2014 From: phd at phdru.name (Oleg Broytman) Date: Sun, 13 Apr 2014 14:28:52 +0200 Subject: SQLObject 1.5.2 Message-ID: <20140413122852.GB7243@phdru.name> Hello! I'm pleased to announce version 1.5.2, the second bugfix release of branch 1.5 of SQLObject. What's new in SQLObject ======================= * Adapt duplicate error message strings for SQLite 3.8. Contributor for this release is Neil Muller. For a more complete list, please see the news: http://sqlobject.org/News.html What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: https://pypi.python.org/pypi/SQLObject/1.5.2 News and changes: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From rustompmody at gmail.com Sun Apr 13 09:32:09 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 13 Apr 2014 06:32:09 -0700 (PDT) Subject: Language summit notes In-Reply-To: References: <53468982$0$29993$c3e8da3$5496439d@news.astraweb.com> <911d97b8-b472-4d4a-9d5c-a6a74acf1ec5@googlegroups.com> <53480f25$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, April 12, 2014 5:55:22 PM UTC+5:30, wxjm... at gmail.com wrote: > ------ > > Regarding the Flexible String Representation, I have always > been very coherent in the examples I gave (usually with and/or > from an interactive intepreter - not relevant). > I never seen once somebody pointing or beeing able to point > what is wrong in those examples. Unicode: I am ignorant and interested. Clearly you know more than me (and perhaps many others here) and we could learn from you. FSR and efficiency: I am barely interested. As is the case for most python users [If efficiency is one's primary consideration one should not be using python] Coherent: I dont know what that word means to you. To me it means acting in a way that eases and smoothens communication. Now if one look at this post of yours and most others one finds: - Poor or completely missing attribution - Or large quotes with google-groups unfortunate double-line spacing Does 'coherent' mean something different in French? [This question may sound sarcastic but is at least part serious/genuine] As for unicode I dont think Ive much more to say than Ive said here if you insist on remaining stuck on the FSR. However do please adjust your posting style to become more acceptable/coherent by reading https://wiki.python.org/moin/GoogleGroupsPython From rosuav at gmail.com Sun Apr 13 10:04:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 Apr 2014 00:04:12 +1000 Subject: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing? In-Reply-To: <534a87b5$0$4028$c3e8da3$9181c375@news.astraweb.com> References: <4gT0v.62253$oI.45884@fx18.am4> <534a87b5$0$4028$c3e8da3$9181c375@news.astraweb.com> Message-ID: On Sun, Apr 13, 2014 at 10:48 PM, Tony the Tiger wrote: > On Tue, 08 Apr 2014 13:58:24 +0000, alister wrote: > >> You can't fall off the floor. > > Yes, if the floor it two stories up, and the walls suddenly disappears, > and there's an earthquake. That makes me so angry, I think I'll smash that wall down! *SFX: boom, wall crumbles* I think I'll take out this floor, too! *SFX: have a guess* What a depressingly stupid machine. ChrisA From tjreedy at udel.edu Sun Apr 13 16:13:36 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 13 Apr 2014 16:13:36 -0400 Subject: Language summit notes In-Reply-To: <538ea131-2013-4fbb-92d4-d39890180074@googlegroups.com> References: <53468982$0$29993$c3e8da3$5496439d@news.astraweb.com> <911d97b8-b472-4d4a-9d5c-a6a74acf1ec5@googlegroups.com> <53480f25$0$29993$c3e8da3$5496439d@news.astraweb.com> <538ea131-2013-4fbb-92d4-d39890180074@googlegroups.com> Message-ID: Everyone, please ignore Jim's unicode/fsr trolling, which started in July 2012. Don't quote it, don't try to answer it. -- Terry Jan Reedy From rhodri at wildebst.org.uk Sun Apr 13 18:51:06 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Sun, 13 Apr 2014 23:51:06 +0100 Subject: Teaching python to non-programmers References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <4e99defd-a693-4bd7-8470-7b8055d6dff8@googlegroups.com> Message-ID: On Fri, 11 Apr 2014 21:20:05 +0100, wrote: > On Thursday, April 10, 2014 3:40:22 PM UTC-7, Rhodri James wrote: >> It's called irony, and unfortunately Mark is reacting to an >> all-to-common >> situation that GoogleGroups foists on unsuspecting posters like >> yourself. > > People who say "I can't be bothered to correct this" while posting a > wise a$$ correction are just trolling, probably not funny in real life > either. I think if you're going to wise off than be witty about it, > otherwise just a terse reference to a link. 99% of the time, Mark is the one to make a brief comment with the link I gave you. And often gets roundly condemned for daring to suggest that GG is not a shining beacon of perfection, for clearly the rest of us are complaining out of jealousy. See my previous comments about straws and camels' backs. Also irony. > At any rate, my original point stands. You're not teaching on planet > Vulcan. Better to teach things in an odd order if that helps motivates > your students. It's not like people in real life carefully examine all > available documentation before learning some piece of tech. Usually they > shrug and say "what's the worst that could happen", dive in, and roll > with the consequences%10. Since "the worst that could happen" with some of the kit I've worked on is that I kill people, I have to disagree. Some flexibility is good, but if you want to understand how something works you do need to go through it in a logical order. Otherwise you can end up knowing lots of bits but having no understanding of how they interact or hang together. That's fine if you want to learn how to write programs, but it's terrible if you want to become a programmer. -- Rhodri James *-* Wildebeest Herder to the Masses From breamoreboy at yahoo.co.uk Sun Apr 13 19:54:02 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 14 Apr 2014 00:54:02 +0100 Subject: Teaching python to non-programmers In-Reply-To: References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <4e99defd-a693-4bd7-8470-7b8055d6dff8@googlegroups.com> Message-ID: On 13/04/2014 23:51, Rhodri James wrote: > On Fri, 11 Apr 2014 21:20:05 +0100, wrote: > >> On Thursday, April 10, 2014 3:40:22 PM UTC-7, Rhodri James wrote: >>> It's called irony, and unfortunately Mark is reacting to an >>> all-to-common >>> situation that GoogleGroups foists on unsuspecting posters like >>> yourself. >> >> People who say "I can't be bothered to correct this" while posting a >> wise a$$ correction are just trolling, probably not funny in real life >> either. I think if you're going to wise off than be witty about it, >> otherwise just a terse reference to a link. > > 99% of the time, Mark is the one to make a brief comment with the link I > gave you. And often gets roundly condemned for daring to suggest that > GG is not a shining beacon of perfection, for clearly the rest of us are > complaining out of jealousy. See my previous comments about straws and > camels' backs. Also irony. > The world will now breath a sigh of relief as I've set up my Thunderbird filters to discard all of the double spaced crap that arrives from gg, hence the amount that I see to complain about will be minimised. This has the added advantage of discarding the blatant lies that our resident unicode expert sprouts about Python, but the powers that be deem fit not to take any action over. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From steve+comp.lang.python at pearwood.info Sun Apr 13 20:20:05 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Apr 2014 00:20:05 GMT Subject: Teaching python to non-programmers References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <4e99defd-a693-4bd7-8470-7b8055d6dff8@googlegroups.com> Message-ID: <534b29b5$0$29993$c3e8da3$5496439d@news.astraweb.com> On Mon, 14 Apr 2014 00:54:02 +0100, Mark Lawrence wrote: > but the powers that be deem fit not > to take any action over. There is no Internet police. Which is a good thing, for if there were, this sort of criticism of the Internet police is exactly the sort of thing that would bring down their wrath onto you. -- Steven D'Aprano http://import-that.dreamwidth.org/ From mok-kong.shen at t-online.de Sun Apr 13 21:46:19 2014 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Mon, 14 Apr 2014 03:46:19 +0200 Subject: MemoryError in data conversion Message-ID: The code attached below produces in one of the two IMHO similar cases (excepting the sizes of the lists involved) MemoryError. Could experts kindly tell why that's so and whether there is any work-around feasible. Thanks in advances. M. K. Shen ----------------------------------------------------------------- import ast def buildhuffmantree(slist,flist): item=slist[:] freq=flist[:] while len(item)>2: mn=min(freq) id=freq.index(mn) u=item[id] del item[id] del freq[id] mn1=min(freq) id=freq.index(mn1) v=item[id] del item[id] del freq[id] item.append([u,v]) freq.append(mn+mn1) return(item) def processing(slist,flist): bintree=buildhuffmantree(slist,flist) print(bintree) byarray=bytearray(str(bintree),"latin-1") bintree1=ast.literal_eval(byarray.decode("latin-1")) print(bintree1) print(bintree==bintree1) slist1=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 'eof'] flist1=[18, 16, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, -1] slist2=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 'eof'] flist2=[2, 2, 0, 2, 0, 0, 1, 2, 1, 0, 2, 0, 0, 1, 1, 0, 2, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1] processing(slist1,flist1) ### This works fine print() processing(slist2,flist2) ### This leads to MemoryError From dieter at handshake.de Mon Apr 14 02:14:07 2014 From: dieter at handshake.de (dieter) Date: Mon, 14 Apr 2014 08:14:07 +0200 Subject: MemoryError in data conversion References: Message-ID: <87k3asa15c.fsf@handshake.de> Mok-Kong Shen writes: > The code attached below produces in one of the two IMHO similar cases > (excepting the sizes of the lists involved) MemoryError. Could experts > kindly tell why that's so and whether there is any work-around feasible. "MemoryError" means: the Python process wants more memory from the operating system than this can give. Your options: * increase the memory resources (RAM, swap space) of your system * check the memory related configuration of your operating system (there may be a limit for memory allocated to processes - try to increase this) * change your algorithm such that less memory is needed From wuwei23 at gmail.com Mon Apr 14 02:13:11 2014 From: wuwei23 at gmail.com (alex23) Date: Mon, 14 Apr 2014 16:13:11 +1000 Subject: Teaching python to non-programmers In-Reply-To: References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> Message-ID: On 11/04/2014 3:42 PM, Rustom Mody wrote: > On Friday, April 11, 2014 10:41:26 AM UTC+5:30, Chris Angelico wrote: >> On Fri, Apr 11, 2014 at 2:37 PM, Rustom Mody wrote: >>> Right. Its true that when I was at a fairly large corporate, I was not told: >>> "Please always top post!" >>> >>> What I was very gently and super politely told was: >>> "Please dont delete mail context" >> Then you were told that by someone who does not understand email. > You seem to be cocksure who is right. > Im just curious who you think it is :-) http://www.ietf.org/rfc/rfc1855.txt If you are sending a reply to a message or a posting be sure you summarize the original at the top of the message, or include just enough text of the original to give a context. This will make sure readers understand when they start to read your response. Since NetNews, especially, is proliferated by distributing the postings from one host to another, it is possible to see a response to a message before seeing the original. Giving context helps everyone. But do not include the entire original! RFC1855 is the PEP8 of posting online :) From ian.g.kelly at gmail.com Mon Apr 14 02:59:34 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 14 Apr 2014 00:59:34 -0600 Subject: Teaching python to non-programmers In-Reply-To: References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <8c101063-9abe-49f1-a8ab-c5d7048079be@googlegroups.com> <79e36d43-6170-46a0-8f8e-9462f27efd2f@googlegroups.com> Message-ID: On Mon, Apr 14, 2014 at 12:13 AM, alex23 wrote: > http://www.ietf.org/rfc/rfc1855.txt > > If you are sending a reply to a message or a posting be sure you > summarize the original at the top of the message, or include just > enough text of the original to give a context. This will make > sure readers understand when they start to read your response. > Since NetNews, especially, is proliferated by distributing the > postings from one host to another, it is possible to see a > response to a message before seeing the original. Giving context > helps everyone. But do not include the entire original! > > RFC1855 is the PEP8 of posting online :) But it also says: Don't get involved in flame wars. Neither post nor respond to incendiary material. So we're already pretty much not in compliance. From breamoreboy at yahoo.co.uk Mon Apr 14 03:32:39 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 14 Apr 2014 08:32:39 +0100 Subject: Teaching python to non-programmers In-Reply-To: <534b29b5$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <1ec8952c-f9c8-4f58-9eee-0707a4c89dee@googlegroups.com> <10c257bb-1b3c-410a-81cf-916136b3f8e6@googlegroups.com> <4e99defd-a693-4bd7-8470-7b8055d6dff8@googlegroups.com> <534b29b5$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 14/04/2014 01:20, Steven D'Aprano wrote: > On Mon, 14 Apr 2014 00:54:02 +0100, Mark Lawrence wrote: > >> but the powers that be deem fit not >> to take any action over. > > There is no Internet police. Which is a good thing, for if there were, > this sort of criticism of the Internet police is exactly the sort of > thing that would bring down their wrath onto you. > I've been known on the odd occasion to get my bottom smacked. The full wrath is reserved for Greek internet experts. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From jackie.walkabout at gmail.com Mon Apr 14 03:43:41 2014 From: jackie.walkabout at gmail.com (Anthony Smith) Date: Mon, 14 Apr 2014 00:43:41 -0700 (PDT) Subject: Learner looking for assistance Message-ID: <67147571-4509-4476-bc7b-4712688cf7b1@googlegroups.com> Hi All I am probably doing something wrong but don't know what Any help would great Code below the calc_total does not return a estimated_total_weight if add the estimated_total_weight the rest of the code works I am at a lose as to why ????? def calc_total(self): amount = 0 if self.estimated_weight_hd > 0: amount = self.number * self.estimated_weight_hd return amount def save(self): self.estimated_total_weight = self.calc_total() super(SaleNote, self).save() def calc_total_price(self): amount_price = 0 if self.sale_head > 0: amount_price = self.number * self.sale_head return amount_price else: if self.estimated_total_weight > 0: amount_price = self.estimated_total_weight * self.sale_kg return amount_price def save(self): self.total_price = self.calc_total_price() super(SaleNote, self).save() thanks anthony From __peter__ at web.de Mon Apr 14 03:46:48 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 14 Apr 2014 09:46:48 +0200 Subject: MemoryError in data conversion References: Message-ID: Mok-Kong Shen wrote: > The code attached below produces in one of the two IMHO similar cases > (excepting the sizes of the lists involved) MemoryError. Could experts > kindly tell why that's so and whether there is any work-around feasible. Here's a simpler way to reproduce the error: >>> import ast >>> def nested_list_literal(n): ... return "[" * n + "42" + "]" * n ... >>> ast.literal_eval(nested_list_literal(98)) [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[42]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] >>> ast.literal_eval(nested_list_literal(99)) s_push: parser stack overflow Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.3/ast.py", line 47, in literal_eval node_or_string = parse(node_or_string, mode='eval') File "/usr/lib/python3.3/ast.py", line 35, in parse return compile(source, filename, mode, PyCF_ONLY_AST) MemoryError You ran into a limitation of the compiler. For us to suggest a workaround you'd have to explain why you want to convert the list returned from buildhuffmantree() into python source code and back. > Thanks in advances. > > M. K. Shen > > ----------------------------------------------------------------- > > import ast > > def buildhuffmantree(slist,flist): > item=slist[:] > freq=flist[:] > while len(item)>2: > mn=min(freq) > id=freq.index(mn) > u=item[id] > del item[id] > del freq[id] > mn1=min(freq) > id=freq.index(mn1) > v=item[id] > del item[id] > del freq[id] > item.append([u,v]) > freq.append(mn+mn1) > return(item) > > def processing(slist,flist): > bintree=buildhuffmantree(slist,flist) > print(bintree) > byarray=bytearray(str(bintree),"latin-1") > bintree1=ast.literal_eval(byarray.decode("latin-1")) > print(bintree1) > print(bintree==bintree1) > > slist1=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 'eof'] > > flist1=[18, 16, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, -1] > > slist2=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, > 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, > 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, > 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, > 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, > 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, > 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, > 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, > 124, 125, 126, 127, 'eof'] > > flist2=[2, 2, 0, 2, 0, 0, 1, 2, 1, 0, 2, 0, 0, 1, 1, 0, 2, 0, 0, 0, 1, > 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, > 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 1, 0, 2, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, > 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, -1] > > processing(slist1,flist1) ### This works fine > print() > > processing(slist2,flist2) ### This leads to MemoryError From wxjmfauth at gmail.com Mon Apr 14 04:02:30 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 14 Apr 2014 01:02:30 -0700 (PDT) Subject: Language summit notes In-Reply-To: References: <53468982$0$29993$c3e8da3$5496439d@news.astraweb.com> <911d97b8-b472-4d4a-9d5c-a6a74acf1ec5@googlegroups.com> <53480f25$0$29993$c3e8da3$5496439d@news.astraweb.com> <538ea131-2013-4fbb-92d4-d39890180074@googlegroups.com> Message-ID: ----- Unicode <== Coding of the characters (all schemes) <== math. For those who are interested in that field, I recommand to try to understand why we (the world) have to live with all these coding schemes. jmf From wxjmfauth at gmail.com Mon Apr 14 04:03:48 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 14 Apr 2014 01:03:48 -0700 (PDT) Subject: Language summit notes In-Reply-To: References: <53468982$0$29993$c3e8da3$5496439d@news.astraweb.com> <911d97b8-b472-4d4a-9d5c-a6a74acf1ec5@googlegroups.com> <53480f25$0$29993$c3e8da3$5496439d@news.astraweb.com> <538ea131-2013-4fbb-92d4-d39890180074@googlegroups.com> Message-ID: <4671d0ee-2c67-4261-8593-a918688536d9@googlegroups.com> Le dimanche 13 avril 2014 22:13:36 UTC+2, Terry Reedy a ?crit?: > Everyone, please ignore Jim's unicode/fsr trolling, which started in > > July 2012. Don't quote it, don't try to answer it. > > > > -- > > Terry Jan Reedy ------- FYI: I was waiting for the final 3.4 release. I'm only now maintaining interactive interpreters (with an "s") to toy with unicode (and the coding of characters) and some other tasks. Python succeeded to become some kind of an "anti unicode" tool (in the math sense, "antisymmetric, non symmetric, symmetric"). Very interesting. jmf From ben+python at benfinney.id.au Mon Apr 14 04:11:19 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 14 Apr 2014 18:11:19 +1000 Subject: Learner looking for assistance References: <67147571-4509-4476-bc7b-4712688cf7b1@googlegroups.com> Message-ID: <85vbucwct4.fsf@benfinney.id.au> Anthony Smith writes: > the calc_total does not return a estimated_total_weight > > if add the estimated_total_weight the rest of the code works > > I am at a lose as to why ????? When it's too confusing, simplify. The code you present is fine, but is more complex than it needs to be for the specific problem. Also, it's not complete: it appears to be part of some larger program that we don't have. And, it appears to have suffered re-formatting when you put it in your message, so it won't run. (Post only in plain text, not HTML; and copy-paste the code in plain text.) So: start simple, make something you understand, then gradually build it up until the point where it exhibits the behaviour you're confused by. Then, show that simple-as-possible-but-no-simpler version here, complete with the input you're using and the resulting output. You may find that this process gives you enough understanding that you are then able to solve the problem. Great! But, even if not, we'll need you to go through that process so we can understand. Feel free to post the simple version here if it still leaves you confused. -- \ ?Nothing worth saying is inoffensive to everyone. Nothing worth | `\ saying will fail to make you enemies. And nothing worth saying | _o__) will not produce a confrontation.? ?Johann Hari, 2011 | Ben Finney From nispray at gmail.com Mon Apr 14 04:19:01 2014 From: nispray at gmail.com (Wesley) Date: Mon, 14 Apr 2014 01:19:01 -0700 (PDT) Subject: gdb python core dump file : not in executable format: File format not Message-ID: Hi guys, Today I am debugging an issue related to memory leak. I use gdb 7.7 and python 2.7.6 to generate one core dump file from production env. And then, just use gdb to debug the coredump upon the same machine. Got error that seems not support debug core file using pyton? Here is snippet: [root at localhost server]# gdb --core memleak.core GNU gdb (GDB) 7.7 Copyright (C) 2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-unknown-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word". [New LWP 25738] [New LWP 25739] [New LWP 25740] [New LWP 25745] [New LWP 25746] [New LWP 25747] [New LWP 25635] Core was generated by `python'. #0 0x00000030016e15e3 in ?? () (gdb) file /root/server/deviceserver.py "/root/server/deviceserver.py": not in executable format: File format not recognized (gdb) file /root/server/deviceserver /root/server/deviceserver: No such file or directory. (gdb) file /root/server/deviceserver.py "/root/server/deviceserver.py": not in executable format: File format not recognized (gdb) From jackie.walkabout at gmail.com Mon Apr 14 04:23:02 2014 From: jackie.walkabout at gmail.com (Anthony Smith) Date: Mon, 14 Apr 2014 01:23:02 -0700 (PDT) Subject: Learner looking for assistance In-Reply-To: <67147571-4509-4476-bc7b-4712688cf7b1@googlegroups.com> References: <67147571-4509-4476-bc7b-4712688cf7b1@googlegroups.com> Message-ID: On Monday, 14 April 2014 17:43:41 UTC+10, Anthony Smith wrote: > Hi All > > > > I am probably doing something wrong but don't know what > > Any help would great > > > > Code below > > > > the calc_total does not return a estimated_total_weight > > > > if add the estimated_total_weight the rest of the code works > > > > I am at a lose as to why ????? > > > > def calc_total(self): > > amount = 0 > > if self.estimated_weight_hd > 0: > > amount = self.number * self.estimated_weight_hd > > return amount > > > > def save(self): > > self.estimated_total_weight = self.calc_total() > > super(SaleNote, self).save() > > > > def calc_total_price(self): > > amount_price = 0 > > if self.sale_head > 0: > > amount_price = self.number * self.sale_head > > return amount_price > > else: > > if self.estimated_total_weight > 0: > > amount_price = self.estimated_total_weight * self.sale_kg > > return amount_price > > > > def save(self): > > self.total_price = self.calc_total_price() > > super(SaleNote, self).save() > > > > thanks > > > > anthony Thanks Ben this involves django as well forgot to mention in ear lier post Maybe it a django issue rather code. Thats why I posted it here first. thanks cheers From davea at davea.name Mon Apr 14 08:34:33 2014 From: davea at davea.name (Dave Angel) Date: Mon, 14 Apr 2014 08:34:33 -0400 (EDT) Subject: Learner looking for assistance References: <67147571-4509-4476-bc7b-4712688cf7b1@googlegroups.com> Message-ID: Anthony Smith Wrote in message: > Hi All > > I am probably doing something wrong but don't know what > Any help would great > As Ben pointed out, you should be more careful with your copy/paste, and especially with your indentation. I'll assume these are all methods of a single class SaleNote, and that none are nested. If that's the case, your problem is most likely that the second definition of save hides the first. > Code below > > the calc_total does not return a estimated_total_weight Right, it returns amount. If it gets called, which it doesn't from your code here. And it doesn't save that value, it only gets saved by the dead code below in the first save method. > > if add the estimated_total_weight the rest of the code works > > I am at a lose as to why ????? > > def calc_total(self): > amount = 0 > if self.estimated_weight_hd > 0: > amount = self.number * self.estimated_weight_hd > return amount > > def save(self): > self.estimated_total_weight = self.calc_total() > super(SaleNote, self).save() > > def calc_total_price(self): > amount_price = 0 > if self.sale_head > 0: > amount_price = self.number * self.sale_head > return amount_price > else: > if self.estimated_total_weight > 0: > amount_price = self.estimated_total_weight * self.sale_kg > return amount_price > > def save(self): > self.total_price = self.calc_total_price() > super(SaleNote, self).save() > To make the rest of the code more readable, consider using else clauses on every if, so that you can more readily spot missing cases. Turns out that wasn't your problem, but it costs every reader of your code the time to decide that. Personally, I'd be using the max function, which would simplify the first function to one line. -- DaveA From mok-kong.shen at t-online.de Mon Apr 14 08:26:31 2014 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Mon, 14 Apr 2014 14:26:31 +0200 Subject: MemoryError in data conversion In-Reply-To: References: Message-ID: Am 14.04.2014 09:46, schrieb Peter Otten: > You ran into a limitation of the compiler. For us to suggest a workaround > you'd have to explain why you want to convert the list returned from > buildhuffmantree() into python source code and back. That list gives the Huffman encoding tree for compressing a given piece of source text. I am writing a Python code to implement an algorithm (not new, being first sketched in the literature since decades but yet having no publically available implementation as far as I am aware) of encryption processing that has Huffman data compression as its major constituent. Now, for good security against cryptanalysis, this list (which has to be included in the ciphertext for decryption by the recipient) has to be well scrambled in some way. I choose to use 8-bit bytes as units for the scrambling. Hence I convert the list to a bytearray for performing scrambling. On decryption I reverse the scrambling and get back the original bytearray and use ast to recover from it the list so as to be able to do the decompression. Hopefully this description is sufficiently clear. M. K. Shen From davea at davea.name Mon Apr 14 08:42:30 2014 From: davea at davea.name (Dave Angel) Date: Mon, 14 Apr 2014 08:42:30 -0400 (EDT) Subject: MemoryError in data conversion References: Message-ID: Mok-Kong Shen Wrote in message: > > The code attached below produces in one of the two IMHO similar cases > (excepting the sizes of the lists involved) MemoryError. Could experts > kindly tell why that's so and whether there is any work-around feasible. Where's your stack trace for the error? If it happens that it gets the error in the Ast call, then examine byarray. I expect it's too large or too complex for the compiler. -- DaveA From breamoreboy at yahoo.co.uk Mon Apr 14 08:56:15 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 14 Apr 2014 13:56:15 +0100 Subject: Martijn Faassen: The Call of Python 2.8 Message-ID: http://blog.startifact.com/posts/the-call-of-python-28.html so in response to the last line, who *IS* going to do all of the required work? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Mon Apr 14 09:20:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 Apr 2014 23:20:01 +1000 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: Message-ID: On Mon, Apr 14, 2014 at 10:56 PM, Mark Lawrence wrote: > http://blog.startifact.com/posts/the-call-of-python-28.html so in response > to the last line, who *IS* going to do all of the required work? Only someone for whom it's less work to build Python 2.8 than it is to port their code to Python 3. In other words, some organization with a megantic (that's one step below gigantic, you know [1]) Python codebase, and some (but not heaps of) resources to put into it. Personally, I don't see it happening; very little of the code required will be backportable from Python 3 (in contrast to PEP 466 security patches), so every bit of that work will be for the 2.x line only; and any features added in 2.8 can't be used until you're prepared to drop 2.7 support. That means a fair amount of work *and* you have to drop 2.7 support. If you're going to do that, why not just port your code to 3.x and be done with it? Who has the resources to put hours and hours of dev time into a 2.8? ChrisA [1] Megantic is only +3/+3, but gigantic is 8/8. Look! :) http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=370794 http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=195627 From marko at pacujo.net Mon Apr 14 09:51:51 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 14 Apr 2014 16:51:51 +0300 Subject: Martijn Faassen: The Call of Python 2.8 References: Message-ID: <87y4z8koi0.fsf@elektro.pacujo.net> Chris Angelico : > If you're going to do that, why not just port your code to 3.x and be > done with it? Who has the resources to put hours and hours of dev time > into a 2.8? Somewhat related. Only yesterday I ported/reimplemented a software package to python3. On the finish line, I ran into a problem: xlwt only supports 2.6, 2.7 and 3.3. My system has python3.2. So I backtracked to python2.7. So not only do we have a schism between python2 and python3 but there's one between 3.0 and 3.3. I can't help but wonder if PEP 414 was a mistake. Serves me right for being an "early adopter." Marko From __peter__ at web.de Mon Apr 14 09:59:48 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 14 Apr 2014 15:59:48 +0200 Subject: MemoryError in data conversion References: Message-ID: Mok-Kong Shen wrote: > Am 14.04.2014 09:46, schrieb Peter Otten: > >> You ran into a limitation of the compiler. For us to suggest a workaround >> you'd have to explain why you want to convert the list returned from >> buildhuffmantree() into python source code and back. > > That list gives the Huffman encoding tree for compressing a given piece > of source text. I am writing a Python code to implement an algorithm > (not new, being first sketched in the literature since decades but yet > having no publically available implementation as far as I am aware) of > encryption processing that has Huffman data compression as its major > constituent. Now, for good security against cryptanalysis, this list > (which has to be included in the ciphertext for decryption by the > recipient) has to be well scrambled in some way. I choose to use 8-bit > bytes as units for the scrambling. Hence I convert the list to a > bytearray for performing scrambling. On decryption I reverse the > scrambling and get back the original bytearray and use ast to recover > from it the list so as to be able to do the decompression. Hopefully > this description is sufficiently clear. You could use json, but you may run into the same problem with that, too (only later): >>> import json >>> items = [] >>> for i in range(1000): ... s = json.dumps(items) ... items = [items] ... Traceback (most recent call last): File "", line 2, in File "/usr/lib/python3.3/json/__init__.py", line 236, in dumps return _default_encoder.encode(obj) File "/usr/lib/python3.3/json/encoder.py", line 191, in encode chunks = self.iterencode(o, _one_shot=True) File "/usr/lib/python3.3/json/encoder.py", line 249, in iterencode return _iterencode(o, 0) RuntimeError: maximum recursion depth exceeded while encoding a JSON object >>> i 995 The safest option is probably to serialize the original flist and slist, and use them to create the tree on the fly. From rosuav at gmail.com Mon Apr 14 10:19:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Apr 2014 00:19:49 +1000 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: <87y4z8koi0.fsf@elektro.pacujo.net> References: <87y4z8koi0.fsf@elektro.pacujo.net> Message-ID: On Mon, Apr 14, 2014 at 11:51 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> If you're going to do that, why not just port your code to 3.x and be >> done with it? Who has the resources to put hours and hours of dev time >> into a 2.8? > > Somewhat related. Only yesterday I ported/reimplemented a software > package to python3. On the finish line, I ran into a problem: xlwt > only supports 2.6, 2.7 and 3.3. My system has python3.2. > > So I backtracked to python2.7. > > So not only do we have a schism between python2 and python3 but there's > one between 3.0 and 3.3. I can't help but wonder if PEP 414 was a > mistake. > > Serves me right for being an "early adopter." So get Python 3.3 for your system, then. It's not that hard. You might need to build it from source (not hard at all), or grab packages from a newer version of Debian/RHEL/etc (also not hard, although there might be additional consequential package requirements). The two should happily coexist. Also, the EOL for Python 3.2 is way *way* nearer than EOL of the 2.x line. If you declare that your package requires 2.6/2.7/3.3 (preferably also support 3.4), so be it. It won't be long before all supported systems can get 3.3+, so that won't be a problem. PEP 414 was useful because we can confidently target a newer 3.3 and expect that people will be able to get there before long. ChrisA From marko at pacujo.net Mon Apr 14 10:40:19 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 14 Apr 2014 17:40:19 +0300 Subject: Martijn Faassen: The Call of Python 2.8 References: <87y4z8koi0.fsf@elektro.pacujo.net> Message-ID: <87ppkkkm98.fsf@elektro.pacujo.net> Chris Angelico : > So get Python 3.3 for your system, then. That'll have to wait till it's time for an OS overhaul. I don't do those every year. Marko From breamoreboy at yahoo.co.uk Mon Apr 14 10:46:34 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 14 Apr 2014 15:46:34 +0100 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: <87y4z8koi0.fsf@elektro.pacujo.net> References: <87y4z8koi0.fsf@elektro.pacujo.net> Message-ID: On 14/04/2014 14:51, Marko Rauhamaa wrote: > Chris Angelico : > >> If you're going to do that, why not just port your code to 3.x and be >> done with it? Who has the resources to put hours and hours of dev time >> into a 2.8? The people who haven't had enough time over the last eight years to plan their upgrade path to 3.x. Eight years comes from the date of the first message here https://mail.python.org/pipermail/python-3000/ which was 21/03/2006, so feel free to come up with a different answer for the time span. > > Somewhat related. Only yesterday I ported/reimplemented a software > package to python3. On the finish line, I ran into a problem: xlwt > only supports 2.6, 2.7 and 3.3. My system has python3.2. > > So I backtracked to python2.7. > > So not only do we have a schism between python2 and python3 but there's > one between 3.0 and 3.3. I can't help but wonder if PEP 414 was a > mistake. I still believe that PEP 404 was the correct thing to do. PEP 414 was a no brainer :) > > Serves me right for being an "early adopter." No, serves the community right for not providing enough support to authors in getting their packages updated. > > > Marko > -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Mon Apr 14 11:01:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Apr 2014 01:01:59 +1000 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: <87ppkkkm98.fsf@elektro.pacujo.net> References: <87y4z8koi0.fsf@elektro.pacujo.net> <87ppkkkm98.fsf@elektro.pacujo.net> Message-ID: On Tue, Apr 15, 2014 at 12:40 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> So get Python 3.3 for your system, then. > > That'll have to wait till it's time for an OS overhaul. I don't do those > every year. What OS? Since getting 3.3 isn't just a matter of "grab the .msi/.dmg file from python.org", I'm guessing it's neither Windows nor OS X, so I'd guess you're most likely talking about Linux. On Linux, it's pretty easy to build Python from source. Debian Wheezy ships Python 3.2, so with that distro you should be able to do this: # apt-get build-dep python3 and it'll install everything you need to build Python 3.2 (and 3.3 needs the same packages). Then you just grab the source code and do the classic configure and make. Or if you don't want to build from source, you could get a package of 3.3 from somewhere. In the case of Debian, that would mean grabbing the Python package from Jessie: https://packages.debian.org/jessie/python3.3 I haven't tested, but that package will most likely install happily on a Debian Wheezy. Chances are you can find an equivalent for other Linuxes (I don't have much experience with rpm-based distros, but I'm sure there's some equivalent of "apt-get build-dep"). For non-Linux systems, I don't know how hard it is to get a newer Python, but it seems highly unlikely that you're forced to wait for an OS upgrade. Remember, there's nothing wrong with having lots of versions of Python installed. The package manager might provide a couple (maybe 3.1 and 3.2), but having 3.3 installed won't break scripts that depend on 3.2 being there, unless you actually switch over what 'python3' does - and even that's unlikely to break much, since most Linux distros are going to be depending more on the 2.x version than the 3.x... and those that depend on 3.x are sufficiently forward-looking to be shipping 3.3 or even 3.4, so the point is moot. ChrisA From rosuav at gmail.com Mon Apr 14 11:04:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Apr 2014 01:04:20 +1000 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: <87y4z8koi0.fsf@elektro.pacujo.net> Message-ID: On Tue, Apr 15, 2014 at 12:46 AM, Mark Lawrence wrote: >> So not only do we have a schism between python2 and python3 but there's >> one between 3.0 and 3.3. I can't help but wonder if PEP 414 was a >> mistake. > > > I still believe that PEP 404 was the correct thing to do. PEP 414 was a no > brainer :) I'm pretty sure the 414 there wasn't a typo, since he's talking about the schism between 3.0 and 3.3. But let's face it, there's a *lot* of schism between there, and it's all the same sort of thing: code written for 3.0 will usually run happily on 3.3, and code written to take advantage of 3.3's features won't work on 3.0. That's kinda how new versions work, yaknow... ChrisA From wxjmfauth at gmail.com Mon Apr 14 13:41:16 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 14 Apr 2014 10:41:16 -0700 (PDT) Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: <87y4z8koi0.fsf@elektro.pacujo.net> Message-ID: <5a1de60b-9208-4030-8126-16e1017f7ee9@googlegroups.com> I will most probably backport two quite large applications to Py27 ("scientific data processing apps"). It's more a question of willingness, than a technical difficulty. Then basta. Note: cp1252 is good enough. (latin1/iso8859-1 not!). jmf From petef4+usenet at gmail.com Mon Apr 14 14:39:40 2014 From: petef4+usenet at gmail.com (Pete Forman) Date: Mon, 14 Apr 2014 19:39:40 +0100 Subject: Martijn Faassen: The Call of Python 2.8 References: <87y4z8koi0.fsf@elektro.pacujo.net> Message-ID: <86wqer7o2b.fsf@gmail.com> Mark Lawrence writes: > On 14/04/2014 14:51, Marko Rauhamaa wrote: >> Chris Angelico : >> >>> If you're going to do that, why not just port your code to 3.x and >>> be done with it? Who has the resources to put hours and hours of dev >>> time into a 2.8? > > The people who haven't had enough time over the last eight years to > plan their upgrade path to 3.x. Eight years comes from the date of the > first message here https://mail.python.org/pipermail/python-3000/ > which was 21/03/2006, so feel free to come up with a different answer > for the time span. Would it help if we adopted a non-numeric name for this product to support eXisting Python for those who were notified some years ago that Python 2 would be superseded? How about Python XP? I thought not ;-) -- Pete Forman From pcmanticore at gmail.com Mon Apr 14 14:54:47 2014 From: pcmanticore at gmail.com (Claudiu Popa) Date: Mon, 14 Apr 2014 21:54:47 +0300 Subject: Python hackathon ideas Message-ID: Hello! I'm planning a Python hackathon in my area, which will be held in a couple of weeks. Being my first organized hackathon, I don't quite know on what we will be working. One idea I have is to find a couple of open source projects and start contributing to them. Another idea is to work on Python issues from the bug tracker, but finding easy ones to contribute is not an easy task even for an intermediate developer like me. So, what I am looking for is open source Python projects with: - no tests or very few tests at all - no documentation or very scarce documentation - Python 2 only (and we'll try to port them to Python 3) I know about Python 3 Wall of superpowers, but most of the Python 2 only projects seems too big for us to tackle in one day. If you know these kind of projects or you have one which needs those kind of things, please tell me. Any idea will be appreciated. Thanks! From ian.g.kelly at gmail.com Mon Apr 14 14:59:37 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 14 Apr 2014 12:59:37 -0600 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: <5a1de60b-9208-4030-8126-16e1017f7ee9@googlegroups.com> References: <87y4z8koi0.fsf@elektro.pacujo.net> <5a1de60b-9208-4030-8126-16e1017f7ee9@googlegroups.com> Message-ID: On Apr 14, 2014 11:46 AM, wrote: > > I will most probably backport two quite large applications > to Py27 ("scientific data processing apps"). These applications are already on Python 3? Why do you want them on Python 2? Even the people talking about a 2.8 are only seeing it as an upgrade path to Python 3. > It's more a question of willingness, than a technical > difficulty. Then basta. > Note: cp1252 is good enough. (latin1/iso8859-1 not!). Because cp1252 includes that holiest of holies, the Euro sign, I assume. Point of curiosity: if the first 256 codepoints of Unicode happened to correspond to cp1252 instead of Latin-1, would you still object to the FSR? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ned at nedbatchelder.com Mon Apr 14 15:28:42 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 14 Apr 2014 15:28:42 -0400 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: <87y4z8koi0.fsf@elektro.pacujo.net> <5a1de60b-9208-4030-8126-16e1017f7ee9@googlegroups.com> Message-ID: On 4/14/14 2:59 PM, Ian Kelly wrote: > Point of curiosity: if the first 256 codepoints of Unicode happened to > correspond to cp1252 instead of Latin-1, would you still object to the FSR? Many of us on the list would appreciate it if you didn't open that particular can of worms. You are of course always welcome to write to JMF privately, although he has never responded to me over that channel. -- Ned Batchelder, http://nedbatchelder.com From david.garvey at gmail.com Mon Apr 14 15:37:58 2014 From: david.garvey at gmail.com (david.garvey at gmail.com) Date: Mon, 14 Apr 2014 12:37:58 -0700 Subject: gdb python core dump file : not in executable format: File format not In-Reply-To: References: Message-ID: Does this help? http://plasmodic.github.io/ecto/ecto/usage/external/debugging.html http://gnuradio.org/redmine/projects/gnuradio/wiki/TutorialsDebugging http://downloads.conceptive.be/downloads/camelot/doc/sphinx/build/advanced/debug.html http://forums.gentoo.org/viewtopic-p-7123814.html On Mon, Apr 14, 2014 at 1:19 AM, Wesley wrote: > Hi guys, > Today I am debugging an issue related to memory leak. > I use gdb 7.7 and python 2.7.6 to generate one core dump file from > production env. > > And then, just use gdb to debug the coredump upon the same machine. > Got error that seems not support debug core file using pyton? > > Here is snippet: > [root at localhost server]# gdb --core memleak.core > GNU gdb (GDB) 7.7 > Copyright (C) 2014 Free Software Foundation, Inc. > License GPLv3+: GNU GPL version 3 or later < > http://gnu.org/licenses/gpl.html> > This is free software: you are free to change and redistribute it. > There is NO WARRANTY, to the extent permitted by law. Type "show copying" > and "show warranty" for details. > This GDB was configured as "x86_64-unknown-linux-gnu". > Type "show configuration" for configuration details. > For bug reporting instructions, please see: > . > Find the GDB manual and other documentation resources online at: > . > For help, type "help". > Type "apropos word" to search for commands related to "word". > [New LWP 25738] > [New LWP 25739] > [New LWP 25740] > [New LWP 25745] > [New LWP 25746] > [New LWP 25747] > [New LWP 25635] > Core was generated by `python'. > #0 0x00000030016e15e3 in ?? () > (gdb) file /root/server/deviceserver.py > "/root/server/deviceserver.py": not in executable format: File format not > recognized > (gdb) file /root/server/deviceserver > /root/server/deviceserver: No such file or directory. > (gdb) file /root/server/deviceserver.py > "/root/server/deviceserver.py": not in executable format: File format not > recognized > (gdb) > -- > https://mail.python.org/mailman/listinfo/python-list > -- David Garvey -------------- next part -------------- An HTML attachment was scrubbed... URL: From phildobbin at gmail.com Mon Apr 14 15:32:50 2014 From: phildobbin at gmail.com (Phil Dobbin) Date: Mon, 14 Apr 2014 20:32:50 +0100 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: Message-ID: <534C37E2.5040201@gmail.com> On 14/04/2014 13:56, Mark Lawrence wrote: > http://blog.startifact.com/posts/the-call-of-python-28.html so in > response to the last line, who *IS* going to do all of the required work? > On a related note, Guido announced today that there will be no 2.8 & that the eol for 2.7 will be 2020. Cheers, Phil... -- currently (ab)using CentOS 6.5, Debian Squeeze & Wheezy, Fedora 19 & 20, OS X Snow Leopard, RHEL 7, Ubuntu Precise & Saucy GnuGPG Key : http://phildobbin.org/publickey.asc Based in London, UK From mok-kong.shen at t-online.de Mon Apr 14 17:20:33 2014 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Mon, 14 Apr 2014 23:20:33 +0200 Subject: MemoryError in data conversion In-Reply-To: References: Message-ID: Am 14.04.2014 15:59, schrieb Peter Otten: > You could use json, but you may run into the same problem with that, too > (only later): > >>>> import json >>>> items = [] >>>> for i in range(1000): > ... s = json.dumps(items) > ... items = [items] > ... > Traceback (most recent call last): > File "", line 2, in > File "/usr/lib/python3.3/json/__init__.py", line 236, in dumps > return _default_encoder.encode(obj) > File "/usr/lib/python3.3/json/encoder.py", line 191, in encode > chunks = self.iterencode(o, _one_shot=True) > File "/usr/lib/python3.3/json/encoder.py", line 249, in iterencode > return _iterencode(o, 0) > RuntimeError: maximum recursion depth exceeded while encoding a JSON object >>>> i > 995 > > The safest option is probably to serialize the original flist and slist, and > use them to create the tree on the fly. Thank you very much for your efforts to help me. I have yet a question out of curiosity: Why is my 2nd list structure, that apparently is too complex for handling by eval and json, seemingly not a problem for pickle? M. K. Shen From ethan at stoneleaf.us Mon Apr 14 17:13:49 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 14 Apr 2014 14:13:49 -0700 Subject: Python, Linux, and the setuid bit Message-ID: <534C4F8D.6090005@stoneleaf.us> For anyone in the unenviable position of needing [1] to run Python scripts with the setuid bit on, there is an suid-python wrapper [2] that makes this possible. When I compiled it I was given a couple warnings. Can any one shed light on what they mean? ================================================================== suid-python.c: In function ?malloc_abort?: suid-python.c:119:17: warning: format ?%d? expects argument of type ?int?, but argument 3 has type ?size_t? [-Wformat] suid-python.c: In function ?remove_env_prefix?: suid-python.c:200:32: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] suid-python.c:201:32: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] ================================================================== and the code segments in question: ================================================================== void * malloc_abort(size_t size) { void *buf; buf = malloc(size); if (!buf) { fprintf(stderr, "Could not allocate %d bytes. errno=%d\n", size, errno); exit(1); } return buf; } ------------------------------------------------------------------ int remove_env_prefix(char **envp, char *prefix) { char **envp_read; char **envp_write; int prefix_len = strlen(prefix); int removed_count = 0; envp_write = envp; for (envp_read = envp; *envp_read; envp_read++) { if (!strncmp(*envp_read, prefix, prefix_len)) { /* Step past the environment variable that we don't want. */ removed_count++; continue; } if (envp_read != envp_write) { *envp_write = *envp_read; } envp_write++; } /* Set the remaining slots to NULL. */ if (envp_write < envp_read) { memset(envp_write, 0, ((unsigned int) envp_read - (unsigned int) envp_write)); } return removed_count; } ================================================================== Thanks! -- ~Ethan~ [1] Need, or really really really convenient to have. ;) [2] http://selliott.org/python/ From gordon at panix.com Mon Apr 14 17:55:42 2014 From: gordon at panix.com (John Gordon) Date: Mon, 14 Apr 2014 21:55:42 +0000 (UTC) Subject: Python, Linux, and the setuid bit References: Message-ID: In Ethan Furman writes: > fprintf(stderr, "Could not allocate %d bytes. errno=%d\n", > size, errno); %d is not the correct specifier for printing objects of type size_t. > char **envp_read; > char **envp_write; > if (envp_write < envp_read) > { > memset(envp_write, 0, ((unsigned int) envp_read - > (unsigned int) envp_write)); > } I think it's complaining about casting the char ** objects to unsigned int. -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From invalid at invalid.invalid Mon Apr 14 18:04:52 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 14 Apr 2014 22:04:52 +0000 (UTC) Subject: Python, Linux, and the setuid bit References: Message-ID: On 2014-04-14, John Gordon wrote: > In Ethan Furman writes: > >> fprintf(stderr, "Could not allocate %d bytes. errno=%d\n", >> size, errno); > > %d is not the correct specifier for printing objects of type size_t. I believe %zu is the correct format specifier for size_t values. >> char **envp_read; >> char **envp_write; > >> if (envp_write < envp_read) >> { >> memset(envp_write, 0, ((unsigned int) envp_read - >> (unsigned int) envp_write)); >> } > > I think it's complaining about casting the char ** objects to unsigned int. If we assume that the author is trying to clear memory between the addresses pointed to by the two variables, then it's probably better be cast to (char *) before the subtracted. That should result in an integer value. -- Grant Edwards grant.b.edwards Yow! Please come home with at me ... I have Tylenol!! gmail.com From invalid at invalid.invalid Mon Apr 14 18:07:07 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 14 Apr 2014 22:07:07 +0000 (UTC) Subject: Python, Linux, and the setuid bit References: Message-ID: On 2014-04-14, Grant Edwards wrote: > On 2014-04-14, John Gordon wrote: >>> char **envp_read; >>> char **envp_write; >> >>> if (envp_write < envp_read) >>> { >>> memset(envp_write, 0, ((unsigned int) envp_read - >>> (unsigned int) envp_write)); >>> } >> >> I think it's complaining about casting the char ** objects to unsigned int. > > If we assume that the author is trying to clear memory between the > addresses pointed to by the two variables, then it's probably better > be cast to (char *) before the subtracted. Wow, I mangled that sentence. It should have been something like: then it's probably better to cast them to (char *) before the subtraction. memset(envp_write, 0, ((char*)envp_read)-((char*)envp_write)); -- Grant Edwards grant.b.edwards Yow! My mind is making at ashtrays in Dayton ... gmail.com From greg.ewing at canterbury.ac.nz Mon Apr 14 19:51:07 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 15 Apr 2014 11:51:07 +1200 Subject: MemoryError in data conversion In-Reply-To: References: Message-ID: Mok-Kong Shen wrote: > I have yet a question out of curiosity: Why is my 2nd list structure, > that apparently is too complex for handling by eval and json, seemingly > not a problem for pickle? Pickle is intended for arbitrary data structures, so it is designed to be able to handle deeply-nested and/or recursive data. Eval only has to handle nesting to depths likely to be encountered in source code. Apparently the json parser also assumes you're not going to be using very deep nesting. -- Greg From rosuav at gmail.com Mon Apr 14 21:15:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Apr 2014 11:15:13 +1000 Subject: Python, Linux, and the setuid bit In-Reply-To: <534C4F8D.6090005@stoneleaf.us> References: <534C4F8D.6090005@stoneleaf.us> Message-ID: On Tue, Apr 15, 2014 at 7:13 AM, Ethan Furman wrote: > When I compiled it I was given a couple warnings. Can any one shed light on > what they mean? They mean, most likely, that the author compiled the program on his own computer and not on any other. If I had to make a guess, I'd say that it would compile nicely on a 32-bit system, and you're running a 64-bit system; according to gcc on my amd64 Debian Wheezy here, sizeof(short) is 2 bytes, int is 4, long is 8. Do you feel like patching the program? As Grant says, casting to (char *) is the more usual way to do this sort of arithmetic. Since they're being cast to (unsigned int), you'll *probably* get away with this, as long as the environment doesn't exceed 4GB in size (!!), so you could just ignore it (it's a warning, not an error, after all); but you can probably fix it for all platforms by making the two changes Grant suggested. ChrisA From rosuav at gmail.com Mon Apr 14 21:20:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Apr 2014 11:20:55 +1000 Subject: Python hackathon ideas In-Reply-To: References: Message-ID: On Tue, Apr 15, 2014 at 4:54 AM, Claudiu Popa wrote: > - Python 2 only (and we'll try to port them to Python 3) > > I know about Python 3 Wall of superpowers, but most of the Python 2 > only projects seems too big > for us to tackle in one day. I suspect that, by now, any Py2 projects that could be ported to Py3 in one day have already been ported, or else nobody cares about them. Generally, the best way to find a project to contribute to is to find one that you actively and personally use. Dig into it and find something that makes you go "Wow, I didn't know you could do that with it!", and there's a chance for a docs patch. Or dig through the bug tracker and confirm some bugs; that's more useful than a lot of people realize. "Bug occurs on X with Y and Z... let's see if it happens for me too." ChrisA From davea at davea.name Mon Apr 14 21:33:51 2014 From: davea at davea.name (Dave Angel) Date: Mon, 14 Apr 2014 21:33:51 -0400 (EDT) Subject: Python, Linux, and the setuid bit References: <534C4F8D.6090005@stoneleaf.us> Message-ID: Ethan Furman Wrote in message: > For anyone in the unenviable position of needing [1] to run Python scripts with the setuid bit on, there is an > suid-python wrapper [2] that makes this possible. > > When I compiled it I was given a couple warnings. Can any one shed light on what they mean? > > ================================================================== > suid-python.c: In function ?malloc_abort?: > suid-python.c:119:17: warning: format ?%d? expects argument of type ?int?, but argument 3 has type ?size_t? [-Wformat] > suid-python.c: In function ?remove_env_prefix?: > suid-python.c:200:32: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] > suid-python.c:201:32: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] > ================================================================== > > and the code segments in question: > > ================================================================== > void * > malloc_abort(size_t size) > { > void *buf; > > buf = malloc(size); > if (!buf) > { > fprintf(stderr, "Could not allocate %d bytes. errno=%d\n", > size, errno); Your variable 'size' is declared as size_t, which is an integer the size of a pointer. Not necessarily the same as an int. But if your size is reasonable, no harm done. The correct fix is to use some other format rather than % d, I forget what one. Second choice is to cast to an int. Third lousy choice, ignore the warning. > exit(1); > } > > return buf; > } > ------------------------------------------------------------------ > int > remove_env_prefix(char **envp, char *prefix) > { > char **envp_read; > char **envp_write; > int prefix_len = strlen(prefix); > int removed_count = 0; > > envp_write = envp; > for (envp_read = envp; *envp_read; envp_read++) > { > if (!strncmp(*envp_read, prefix, prefix_len)) > { > /* Step past the environment variable that we don't want. */ > removed_count++; > continue; > } > > if (envp_read != envp_write) > { > *envp_write = *envp_read; > } > > envp_write++; > } > > /* Set the remaining slots to NULL. */ > if (envp_write < envp_read) > { > memset(envp_write, 0, ((unsigned int) envp_read - > (unsigned int) envp_write)); (you really should have put a comment, so we'd know this is line 200, 201) It's incorrect to cast each pointer to an int, but not the difference of two pointers. Subtract the first, then cast if you must. But the difference of two pointers is type ptr_diff, and that should already be the type mem set is expecting. > > > -- DaveA From ethan at stoneleaf.us Mon Apr 14 21:37:19 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 14 Apr 2014 18:37:19 -0700 Subject: Python, Linux, and the setuid bit In-Reply-To: References: <534C4F8D.6090005@stoneleaf.us> Message-ID: <534C8D4F.1010606@stoneleaf.us> On 04/14/2014 06:33 PM, Dave Angel wrote: > > (you really should have put a comment, so we'd know this is line > 200, 201) Sorry, not used to asking questions about C code. ;) I'll make sure and do that next time. Thanks for the help! -- ~Ethan~ From ethan at stoneleaf.us Mon Apr 14 21:38:02 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 14 Apr 2014 18:38:02 -0700 Subject: Python, Linux, and the setuid bit In-Reply-To: <534C4F8D.6090005@stoneleaf.us> References: <534C4F8D.6090005@stoneleaf.us> Message-ID: <534C8D7A.9060801@stoneleaf.us> Thanks to everyone for the pointers. ;) -- ~Ethan~ From rosuav at gmail.com Mon Apr 14 22:08:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Apr 2014 12:08:13 +1000 Subject: Python, Linux, and the setuid bit In-Reply-To: <534C8D7A.9060801@stoneleaf.us> References: <534C4F8D.6090005@stoneleaf.us> <534C8D7A.9060801@stoneleaf.us> Message-ID: On Tue, Apr 15, 2014 at 11:38 AM, Ethan Furman wrote: > Thanks to everyone for the pointers. ;) Pun intended, I hope...? ChrisA *groan* From rustompmody at gmail.com Mon Apr 14 22:41:32 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 14 Apr 2014 19:41:32 -0700 (PDT) Subject: Python hackathon ideas In-Reply-To: References: Message-ID: On Tuesday, April 15, 2014 12:24:47 AM UTC+5:30, Claudiu Popa wrote: > Hello! > > I'm planning a Python hackathon in my area, which will be held in a > couple of weeks. Being my first organized hackathon, I don't quite > know on what we will be working. Just yesterday I discovered that kodos that used to work is now not working probably due to bit rot http://kodos.sourceforge.net/ Its a python-based and python-supporting app to create/debug regular expressions. Whether its a scale suitable for your hackathon I dont really know. All the best for the hackathon! From tjreedy at udel.edu Mon Apr 14 23:54:10 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 14 Apr 2014 23:54:10 -0400 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: <87y4z8koi0.fsf@elektro.pacujo.net> References: <87y4z8koi0.fsf@elektro.pacujo.net> Message-ID: On 4/14/2014 9:51 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> If you're going to do that, why not just port your code to 3.x and be >> done with it? Who has the resources to put hours and hours of dev time >> into a 2.8? > > Somewhat related. Only yesterday I ported/reimplemented a software > package to python3. On the finish line, I ran into a problem: xlwt > only supports 2.6, 2.7 and 3.3. My system has python3.2. > > So I backtracked to python2.7. > > So not only do we have a schism between python2 and python3 but there's > one between 3.0 and 3.3. I can't help but wonder if PEP 414 was a > mistake. The 'mistake' is your OS, whatever it is, not providing 3.3. It is already so old that it is off bugfix maintenance. Any decent system should have 3.4 available now. In any case, I think PEP 393 (new unicode implementation) is reason enough to jump to 3.3. -- Terry Jan Reedy From tjreedy at udel.edu Mon Apr 14 23:58:33 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 14 Apr 2014 23:58:33 -0400 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: Message-ID: On 4/14/2014 8:56 AM, Mark Lawrence wrote: > http://blog.startifact.com/posts/the-call-of-python-28.html so in > response to the last line, who *IS* going to do all of the required work? Steve Dower of Microsoft proposed a similar idea of a migration version of 2.7 after talking with people from businesses that use Python. His proposal engenders the same question. I don't really care. I just know that I am not volunteering my time to help billion-dollar corporations with 1000s of employees. -- Terry Jan Reedy From marko at pacujo.net Tue Apr 15 01:03:21 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 15 Apr 2014 08:03:21 +0300 Subject: Martijn Faassen: The Call of Python 2.8 References: <87y4z8koi0.fsf@elektro.pacujo.net> Message-ID: <87r44zgp5y.fsf@elektro.pacujo.net> Terry Reedy : > Any decent system should have 3.4 available now. Really, now? Which system is that? Marko From ben+python at benfinney.id.au Tue Apr 15 02:08:28 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 15 Apr 2014 16:08:28 +1000 Subject: Martijn Faassen: The Call of Python 2.8 References: <87y4z8koi0.fsf@elektro.pacujo.net> Message-ID: <85ioqbw2eb.fsf@benfinney.id.au> Terry Reedy writes: > The 'mistake' is your OS, whatever it is, not providing 3.3. It is > already so old that it is off bugfix maintenance. Any decent system > should have 3.4 available now. I think you mean ?? should have Python 3.3 available now?, yes? -- \ ?I wish there was a knob on the TV to turn up the intelligence. | `\ There's a knob called ?brightness? but it doesn't work.? | _o__) ?Eugene P. Gallagher | Ben Finney From jimish at auberginesolutions.com Tue Apr 15 03:36:35 2014 From: jimish at auberginesolutions.com (jimish at auberginesolutions.com) Date: Tue, 15 Apr 2014 00:36:35 -0700 (PDT) Subject: Kivy Contest 2014 Message-ID: <1b87b900-69ce-44db-95b6-77bd096fa4dd@googlegroups.com> hey guys, I have already enrolled to kivy contest 2014 few days ago. Now theme is out, How can I know that I have successfully enrolled in kivy contest? I didnt get any mail from kivy having confirmation of enrollment. According to instructions i have read earlier, I wanted to ask that are there 2 persons allowed in a team? Thanks in advance. From rosuav at gmail.com Tue Apr 15 03:48:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Apr 2014 17:48:36 +1000 Subject: Kivy Contest 2014 In-Reply-To: <1b87b900-69ce-44db-95b6-77bd096fa4dd@googlegroups.com> References: <1b87b900-69ce-44db-95b6-77bd096fa4dd@googlegroups.com> Message-ID: On Tue, Apr 15, 2014 at 5:36 PM, wrote: > I have already enrolled to kivy contest 2014 few days ago. Now theme is out, How can I know that I have successfully enrolled in kivy contest? > > I didnt get any mail from kivy having confirmation of enrollment. > > According to instructions i have read earlier, I wanted to ask that are there 2 persons allowed in a team? These are Kivy questions, not Python ones. I'd advise trying here: http://kivy.org/docs/contact.html ChrisA From jackie.walkabout at gmail.com Tue Apr 15 03:52:16 2014 From: jackie.walkabout at gmail.com (Anthony Smith) Date: Tue, 15 Apr 2014 00:52:16 -0700 (PDT) Subject: Learner looking for assistance In-Reply-To: <67147571-4509-4476-bc7b-4712688cf7b1@googlegroups.com> References: <67147571-4509-4476-bc7b-4712688cf7b1@googlegroups.com> Message-ID: <0bbfa6d3-fe85-48e8-a26b-1f7cd3bcf822@googlegroups.com> On Monday, 14 April 2014 17:43:41 UTC+10, Anthony Smith wrote: > Hi All > > > > I am probably doing something wrong but don't know what > > Any help would great > > > > Code below > > > > the calc_total does not return a estimated_total_weight > > > > if add the estimated_total_weight the rest of the code works > > > > I am at a lose as to why ????? > > > > def calc_total(self): > > amount = 0 > > if self.estimated_weight_hd > 0: > > amount = self.number * self.estimated_weight_hd > > return amount > > > > def save(self): > > self.estimated_total_weight = self.calc_total() > > super(SaleNote, self).save() > > > > def calc_total_price(self): > > amount_price = 0 > > if self.sale_head > 0: > > amount_price = self.number * self.sale_head > > return amount_price > > else: > > if self.estimated_total_weight > 0: > > amount_price = self.estimated_total_weight * self.sale_kg > > return amount_price > > > > def save(self): > > self.total_price = self.calc_total_price() > > super(SaleNote, self).save() > > > > thanks > > > > anthony Hi To see what I am trying go to yambuk.no-ip.org:8000/admin this will allow hands on what I am what the program does username python password test From rosuav at gmail.com Tue Apr 15 04:03:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Apr 2014 18:03:52 +1000 Subject: Learner looking for assistance In-Reply-To: <0bbfa6d3-fe85-48e8-a26b-1f7cd3bcf822@googlegroups.com> References: <67147571-4509-4476-bc7b-4712688cf7b1@googlegroups.com> <0bbfa6d3-fe85-48e8-a26b-1f7cd3bcf822@googlegroups.com> Message-ID: On Tue, Apr 15, 2014 at 5:52 PM, Anthony Smith wrote: > To see what I am trying go to yambuk.no-ip.org:8000/admin > > this will allow hands on what I am what the program does > Recommendation: Take the code out of this framework and just run the scripts manually. From there, you should have an easier job of figuring out what's happening. ChrisA From rjk at greenend.org.uk Tue Apr 15 04:00:55 2014 From: rjk at greenend.org.uk (Richard Kettlewell) Date: Tue, 15 Apr 2014 09:00:55 +0100 Subject: Python, Linux, and the setuid bit References: Message-ID: Ethan Furman writes: > memset(envp_write, 0, ((unsigned int) envp_read - > (unsigned int) envp_write)); That is a remarkable blunder for a security-critical program. On a 64-bit platform, the best case outcome is that it will throw away the top 32 bits of each pointer before doing the subtraction, yielding the wrong answer if the discarded bits happen to differ. (There is no limit to the worst case behavior; the effect of converting a pointer value to an integer type which cannot represent the result is undefined.) I would write: (envp_read - envp_write) * sizeof *envp_read -- http://www.greenend.org.uk/rjk/ From rosuav at gmail.com Tue Apr 15 04:15:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Apr 2014 18:15:11 +1000 Subject: Python, Linux, and the setuid bit In-Reply-To: References: Message-ID: On Tue, Apr 15, 2014 at 6:00 PM, Richard Kettlewell wrote: > Ethan Furman writes: >> memset(envp_write, 0, ((unsigned int) envp_read - >> (unsigned int) envp_write)); > > That is a remarkable blunder for a security-critical program. > > On a 64-bit platform, the best case outcome is that it will throw away > the top 32 bits of each pointer before doing the subtraction, yielding > the wrong answer if the discarded bits happen to differ. If the pointers are more than 4GB apart, then yes, it'll give the wrong answer - just as if you'd subtracted and then cast down to an integer too small for the result. But if they're two pointers inside the same object (already a requirement for pointer arithmetic) and not 4GB apart, then two's complement arithmetic will give the right result even if the discarded bits differ. So while you're correct in theory, in practice it's unlikely to actually be a problem. > (There is no limit to the worst case behavior; the effect of converting > a pointer value to an integer type which cannot represent the result is > undefined.) > > I would write: > > (envp_read - envp_write) * sizeof *envp_read I'd simply cast them to (char *), which will permit the arithmetic quite happily and look cleaner. ChrisA From rosuav at gmail.com Tue Apr 15 04:18:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Apr 2014 18:18:30 +1000 Subject: Python, Linux, and the setuid bit In-Reply-To: References: Message-ID: On Tue, Apr 15, 2014 at 6:15 PM, Chris Angelico wrote: > then two's complement arithmetic will give the right result > even if the discarded bits differ. Clarification: Two's complement isn't the only way this could be done, but it is the most likely. So, in theory, there are several possible causes of disaster, but in practice, on any IBM PC compatible architecture, casting a pointer to an integer will usually take the lowest N bits, and two's complement arithmetic will be used, and the environment is unlikely to hit 4GB in size, so the program will "happen to work" in >99.999% of cases. ChrisA From wxjmfauth at gmail.com Tue Apr 15 04:25:06 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 15 Apr 2014 01:25:06 -0700 (PDT) Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: <87y4z8koi0.fsf@elektro.pacujo.net> <5a1de60b-9208-4030-8126-16e1017f7ee9@googlegroups.com> Message-ID: Le lundi 14 avril 2014 20:59:37 UTC+2, Ian a ?crit?: > On Apr 14, 2014 11:46 AM, wrote: > > > > > > Point of curiosity: if the first 256 codepoints of Unicode happened to correspond to cp1252 instead of Latin-1, would you still object to the FSR? Yes. --- cp1252: I'm perfectly understanding, plenty of people are very happy with that coding scheme. From steve at pearwood.info Tue Apr 15 04:29:27 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 15 Apr 2014 08:29:27 GMT Subject: Learner looking for assistance References: <67147571-4509-4476-bc7b-4712688cf7b1@googlegroups.com> Message-ID: <534cede7$0$11109$c3e8da3@news.astraweb.com> On Mon, 14 Apr 2014 00:43:41 -0700, Anthony Smith wrote: > the calc_total does not return a estimated_total_weight That's because you don't tell it to. Your calc_total method multiplies by estimated_weight_hd which is not the same as estimated_total_weight. > > if add the estimated_total_weight the rest of the code works > I am at a lose as to why ????? What does "works" mean in this context? What is the code supposed to do, and what does it do instead? Because you have only given us a tiny snippet of code, we have no way of running it. Please read this page here: http://www.sscce.org/ and try to prepare a short, working (in the sense that it runs and demonstrates the problem) example. > def calc_total(self): > amount = 0 > if self.estimated_weight_hd > 0: > amount = self.number * self.estimated_weight_hd > return amount This only adds the weight to amount if it is positive. If it is negative, nothing happens. Is that deliberate? Also, I see you have mixed spaces and tabs. Please use one, or the other, but never use both. Mixing spaces and tabs will give you no end of headaches. > def save(self): > self.estimated_total_weight = self.calc_total() > super(SaleNote, self).save() This appears to be indented *inside* the calc_total method, but after the return statement, it is dead code and will never be executed. Or perhaps not -- because you have mixed spaces and tabs, it is very difficult to tell. > def calc_total_price(self): > amount_price = 0 > if self.sale_head > 0: > amount_price = self.number * self.sale_head > return amount_price > else: > if self.estimated_total_weight > 0: > amount_price = self.estimated_total_weight * > self.sale_kg > return amount_price Without knowing what your code is supposed to do, we cannot tell how it is broken. What is self.sale_head? Under what circumstances is is negative? -- Steven From tjreedy at udel.edu Tue Apr 15 04:32:00 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 15 Apr 2014 04:32:00 -0400 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: <87r44zgp5y.fsf@elektro.pacujo.net> References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> Message-ID: On 4/15/2014 1:03 AM, Marko Rauhamaa wrote: > Terry Reedy : > >> Any decent system should have 3.4 available now. > > Really, now? Which system is that? 3.4.0 was released a month ago with Windows and Mac installers and source for everything else. I know Ubuntu was testing the release candidate so I presume it is or will very soon have 3.4 officially available. Since there was a six month series of alpha, beta, and candidate releases, with an approximate final release data, any distribution that wanted to be up to date also could be. This is all quite aside from the fact that one should be able to unpack a tarball and 'make xxx'. -- Terry Jan Reedy From tjreedy at udel.edu Tue Apr 15 04:33:24 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 15 Apr 2014 04:33:24 -0400 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: <85ioqbw2eb.fsf@benfinney.id.au> References: <87y4z8koi0.fsf@elektro.pacujo.net> <85ioqbw2eb.fsf@benfinney.id.au> Message-ID: On 4/15/2014 2:08 AM, Ben Finney wrote: > Terry Reedy writes: > >> The 'mistake' is your OS, whatever it is, not providing 3.3. It is >> already so old that it is off bugfix maintenance. Any decent system >> should have 3.4 available now. > > I think you mean ?? should have Python 3.3 available now?, yes? ??? why would you think that??? My installed 3.4.0 for Windows is dated March 16. -- Terry Jan Reedy From jackie.walkabout at gmail.com Tue Apr 15 04:44:02 2014 From: jackie.walkabout at gmail.com (Anthony Smith) Date: Tue, 15 Apr 2014 01:44:02 -0700 (PDT) Subject: Learner looking for assistance In-Reply-To: <534cede7$0$11109$c3e8da3@news.astraweb.com> References: <67147571-4509-4476-bc7b-4712688cf7b1@googlegroups.com> <534cede7$0$11109$c3e8da3@news.astraweb.com> Message-ID: <4e425a36-4d63-436d-9083-ac479331bf92@googlegroups.com> On Tuesday, 15 April 2014 18:29:27 UTC+10, Steven D'Aprano wrote: > On Mon, 14 Apr 2014 00:43:41 -0700, Anthony Smith wrote: > > > > > > > the calc_total does not return a estimated_total_weight > > > > That's because you don't tell it to. Your calc_total method multiplies by > > estimated_weight_hd which is not the same as estimated_total_weight. > > > > > > > > if add the estimated_total_weight the rest of the code works > > > I am at a lose as to why ????? > > > > What does "works" mean in this context? What is the code supposed to do, > > and what does it do instead? > > > > Because you have only given us a tiny snippet of code, we have no way of > > running it. Please read this page here: > > > > http://www.sscce.org/ > > > > > > and try to prepare a short, working (in the sense that it runs and > > demonstrates the problem) example. > > > > > > > def calc_total(self): > > > amount = 0 > > > if self.estimated_weight_hd > 0: > > > amount = self.number * self.estimated_weight_hd > > > return amount > > > > This only adds the weight to amount if it is positive. If it is negative, > > nothing happens. Is that deliberate? Also, I see you have mixed spaces > > and tabs. Please use one, or the other, but never use both. Mixing spaces > > and tabs will give you no end of headaches. > > > > > > > def save(self): > > > self.estimated_total_weight = self.calc_total() > > > super(SaleNote, self).save() > > > > This appears to be indented *inside* the calc_total method, but after the > > return statement, it is dead code and will never be executed. Or perhaps > > not -- because you have mixed spaces and tabs, it is very difficult to > > tell. > > > > > > > def calc_total_price(self): > > > amount_price = 0 > > > if self.sale_head > 0: > > > amount_price = self.number * self.sale_head > > > return amount_price > > > else: > > > if self.estimated_total_weight > 0: > > > amount_price = self.estimated_total_weight * > > > self.sale_kg > > > return amount_price > > > > Without knowing what your code is supposed to do, we cannot tell how it > > is broken. What is self.sale_head? Under what circumstances is is > > negative? > > > > > > > > -- > > Steven Sale head is a positive if sale head is used the first function is not required but if it is not used the first function is used then the last function is used to calculate the total price From mok-kong.shen at t-online.de Tue Apr 15 04:55:41 2014 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Tue, 15 Apr 2014 10:55:41 +0200 Subject: MemoryError in data conversion In-Reply-To: References: Message-ID: Am 15.04.2014 01:51, schrieb Gregory Ewing: > Mok-Kong Shen wrote: >> I have yet a question out of curiosity: Why is my 2nd list structure, >> that apparently is too complex for handling by eval and json, seemingly >> not a problem for pickle? > > Pickle is intended for arbitrary data structures, so it > is designed to be able to handle deeply-nested and/or > recursive data. Eval only has to handle nesting to depths > likely to be encountered in source code. Apparently the > json parser also assumes you're not going to be using > very deep nesting. What I need is to have my (complicated) list to be put into a bytearray, do some proceesing, transfer it to the recipient. The recipient reverses the processing, obtains a bytearray that is the same as my original one and gets from it the same list as mine. Using pickle I can manage to do it (in fact I did try and succeed with my 2nd list), but that's IMHO a rather unnatural/awkward work-around. (It means that I have to pickle out the list to a file and read in the content of the file in order to have it as a bytearray etc. etc.) M. K. Shen From rosuav at gmail.com Tue Apr 15 05:05:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Apr 2014 19:05:29 +1000 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: <87y4z8koi0.fsf@elektro.pacujo.net> <85ioqbw2eb.fsf@benfinney.id.au> Message-ID: On Tue, Apr 15, 2014 at 6:33 PM, Terry Reedy wrote: > On 4/15/2014 2:08 AM, Ben Finney wrote: >> >> Terry Reedy writes: >> >>> The 'mistake' is your OS, whatever it is, not providing 3.3. It is >>> already so old that it is off bugfix maintenance. Any decent system >>> should have 3.4 available now. >> >> >> I think you mean ?? should have Python 3.3 available now?, yes? > > > ??? why would you think that??? My installed 3.4.0 for Windows is dated > March 16. Debian's current stable (Wheezy) was released 2013/05/04, and the latest version release of it (7.4) was 2014/02/08. Both those dates precede 2014/03/16, so you don't get 3.4 in Wheezy. (Actually, you don't even get 3.3, presumably because its launch date of 2012/09/29 missed the Wheezy feature freeze in mid-2012.) Debian Jessie (current testing) ships 3.3 and 3.4, with the 'python3' package giving you 3.3. Stable OSes won't necessarily be jumping onto 3.4 instantly upon availability. Debian Squeeze (oldstable, still supported) doesn't even ship 3.2, all you get is 3.1.3. If you want Arch Linux, you know where to find it :) And of course, that very stability is what makes it easy to just "apt-get build-dep python3" and spin up one from source, possibly even a 3.5-with-except-expressions for the purpose of testing :) ChrisA From rjk at greenend.org.uk Tue Apr 15 05:28:47 2014 From: rjk at greenend.org.uk (Richard Kettlewell) Date: Tue, 15 Apr 2014 10:28:47 +0100 Subject: Python, Linux, and the setuid bit References: Message-ID: Chris Angelico writes: > Richard Kettlewell wrote: >> Ethan Furman writes: >>> memset(envp_write, 0, ((unsigned int) envp_read - >>> (unsigned int) envp_write)); >> >> That is a remarkable blunder for a security-critical program. >> >> On a 64-bit platform, the best case outcome is that it will throw away >> the top 32 bits of each pointer before doing the subtraction, yielding >> the wrong answer if the discarded bits happen to differ. > > If the pointers are more than 4GB apart, then yes, it'll give the > wrong answer - just as if you'd subtracted and then cast down to an > integer too small for the result. But if they're two pointers inside > the same object (already a requirement for pointer arithmetic) and not > 4GB apart, then two's complement arithmetic will give the right result > even if the discarded bits differ. So while you're correct in theory, > in practice it's unlikely to actually be a problem. This program is on a security boundary, the pathological cases are precisely the ones the attacker looks for. (It?s hard to see how an attacker could turn this into a useful attack. But perhaps the attacker has more imagination than me.) -- http://www.greenend.org.uk/rjk/ From rosuav at gmail.com Tue Apr 15 05:35:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Apr 2014 19:35:46 +1000 Subject: Python, Linux, and the setuid bit In-Reply-To: References: Message-ID: On Tue, Apr 15, 2014 at 7:28 PM, Richard Kettlewell wrote: > This program is on a security boundary, the pathological cases are > precisely the ones the attacker looks for. > > (It?s hard to see how an attacker could turn this into a useful attack. > But perhaps the attacker has more imagination than me.) Quite frankly, I don't even care :) It's easy enough to fix the bug. The idiomatic code will compile without warnings *and* be secure, so I'm not seeing any reason to use the existing form. All I'm saying is that it's normally going to happen to work; sure, an attacker might well be able to get into something (although if you can generate 4GB of environment, the fact that it doesn't get zeroed is likely to be less of a concern than the massive DOS potential of a huge env!!), but casual usage will have it seeming to work. The obvious solution is right in every possible way, so that's the thing to do moving forward. ChrisA From nispray at gmail.com Tue Apr 15 05:39:26 2014 From: nispray at gmail.com (Wesley) Date: Tue, 15 Apr 2014 02:39:26 -0700 (PDT) Subject: gdb python core dump file : not in executable format: File format not In-Reply-To: References: Message-ID: ? 2014?4?15????UTC+8??3?37?58??david.... at gmail.com??? > Does this help? > > > http://plasmodic.github.io/ecto/ecto/usage/external/debugging.html > > > > > > > http://gnuradio.org/redmine/projects/gnuradio/wiki/TutorialsDebugging > > > > > > http://downloads.conceptive.be/downloads/camelot/doc/sphinx/build/advanced/debug.html > > > > > http://forums.gentoo.org/viewtopic-p-7123814.html > > > > > On Mon, Apr 14, 2014 at 1:19 AM, Wesley wrote: > > Hi guys, > > ? ?Today I am debugging an issue related to memory leak. > > I use gdb 7.7 and python 2.7.6 to generate one core dump file from production env. > > > > And then, just use gdb to debug the coredump upon the same machine. > > Got error that seems not support debug core file using pyton? > > > > Here is snippet: > > [root at localhost server]# gdb --core ?memleak.core > > GNU gdb (GDB) 7.7 > > Copyright (C) 2014 Free Software Foundation, Inc. > > License GPLv3+: GNU GPL version 3 or later > > This is free software: you are free to change and redistribute it. > > There is NO WARRANTY, to the extent permitted by law. ?Type "show copying" > > and "show warranty" for details. > > This GDB was configured as "x86_64-unknown-linux-gnu". > > Type "show configuration" for configuration details. > > For bug reporting instructions, please see: > > . > > Find the GDB manual and other documentation resources online at: > > . > > For help, type "help". > > Type "apropos word" to search for commands related to "word". > > [New LWP 25738] > > [New LWP 25739] > > [New LWP 25740] > > [New LWP 25745] > > [New LWP 25746] > > [New LWP 25747] > > [New LWP 25635] > > Core was generated by `python'. > > #0 ?0x00000030016e15e3 in ?? () > > (gdb) file /root/server/deviceserver.py > > "/root/server/deviceserver.py": not in executable format: File format not recognized > > (gdb) file /root/server/deviceserver > > /root/server/deviceserver: No such file or directory. > > (gdb) file /root/server/deviceserver.py > > "/root/server/deviceserver.py": not in executable format: File format not recognized > > (gdb) > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > > > -- > David Garvey Yeah? I use gdb --args /usr/local/bin/python ../xxx.py --core xxx.core Then, 'run' to start script. However, the core dump file is actually from a memory leak process,which use 1.2 G momory, but now, through info proc, I got proc id, and then, shell pmap proc_id, only 650M, so, seems this is new started proc, not reload env from the core file. Anything wrong? Thanks. Wesley From steve at pearwood.info Tue Apr 15 05:41:37 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 15 Apr 2014 09:41:37 GMT Subject: Martijn Faassen: The Call of Python 2.8 References: <87y4z8koi0.fsf@elektro.pacujo.net> <85ioqbw2eb.fsf@benfinney.id.au> Message-ID: <534cfed1$0$11109$c3e8da3@news.astraweb.com> On Tue, 15 Apr 2014 04:33:24 -0400, Terry Reedy wrote: > On 4/15/2014 2:08 AM, Ben Finney wrote: >> Terry Reedy writes: >> >>> The 'mistake' is your OS, whatever it is, not providing 3.3. It is >>> already so old that it is off bugfix maintenance. Any decent system >>> should have 3.4 available now. >> >> I think you mean ?? should have Python 3.3 available now?, yes? > > ??? why would you think that??? My installed 3.4.0 for Windows is dated > March 16. Was it provided by Microsoft as part of the OS? Terry, while enthusiasm for the latest and greatest version of Python is a good thing, stability is also a good thing. Not everyone has the luxury of being able to jump on the upgrade treadmill and stay on it. If I recall correctly, Python 2.6 has just received its last security update from Python, but it will continue to receive them from Red Hat for a few more years. (Python 2.4 is still receiving security updates from Red Hat, and 2.7 will be receiving them until 2024.) That stability is very valuable to some people -- that's why people use (e.g.) Debian, with its promises of multi-year stability, instead of Ubuntu, which goes through major version changes three times a week (or so sometimes it seems...) That failure to support 3.4 in the OS-provided system is not a mistake, it is a feature. -- Steven From __peter__ at web.de Tue Apr 15 05:59:00 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 15 Apr 2014 11:59 +0200 Subject: MemoryError in data conversion References: Message-ID: Gregory Ewing wrote: > Mok-Kong Shen wrote: >> I have yet a question out of curiosity: Why is my 2nd list structure, >> that apparently is too complex for handling by eval and json, seemingly >> not a problem for pickle? > > Pickle is intended for arbitrary data structures, so it > is designed to be able to handle deeply-nested and/or > recursive data. Eval only has to handle nesting to depths > likely to be encountered in source code. Apparently the > json parser also assumes you're not going to be using > very deep nesting. But pickle does have the same limitation: >>> def check(load, dump): ... items = [] ... try: ... for i in range(10**6): ... assert load(dump(items)) == items ... items = [items] ... except RuntimeError: ... return i ... >>> check(json.loads, json.dumps) 994 >>> check(pickle.loads, pickle.dumps) 499 Mok-Kong Shen, for pickle and json you can increase the limit a bit: >>> import sys >>> sys.setrecursionlimit(2000) >>> check(json.loads, json.dumps) 1994 >>> check(pickle.loads, pickle.dumps) 999 But be careful, if you choose the limit too high you'll see Python react like any other C program: >>> sys.setrecursionlimit(100000) >>> items = [] >>> for i in range(100000): ... items = [items] ... >>> s = pickle.dumps(items) Segmentation fault For literal_eval() the limit is unfortunately hard-coded in the C source. Mok-Kong Shen wrote: > What I need is to have my (complicated) list to be put into > a bytearray, do some proceesing, transfer it to the recipient. > The recipient reverses the processing, obtains a bytearray > that is the same as my original one and gets from it the same > list as mine. Using pickle I can manage to do it (in fact I > did try and succeed with my 2nd list), but that's IMHO a > rather unnatural/awkward work-around. (It means that I have > to pickle out the list to a file and read in the content of > the file in order to have it as a bytearray etc. etc.) The limit has been increased before, see http://bugs.python.org/issue1881 and maybe you can get the core developers to increase it again, but generally speaking the existence of a recursion limit is the price you pay for easy interfacing with C. literal_eval() could allocate its stack dynamically, but that would probably complicate the code so that return on investment is questionable. From ben+python at benfinney.id.au Tue Apr 15 07:33:50 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 15 Apr 2014 21:33:50 +1000 Subject: Martijn Faassen: The Call of Python 2.8 References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> Message-ID: <85eh0yx1wh.fsf@benfinney.id.au> Terry Reedy writes: > 3.4.0 was released a month ago with Windows and Mac installers and > source for everything else. I know Ubuntu was testing the release > candidate so I presume it is or will very soon have 3.4 officially > available. Since there was a six month series of alpha, beta, and > candidate releases, with an approximate final release data, any > distribution that wanted to be up to date also could be. Those assertions assume that: * operating systems have stable releases every few months; and * they have a zero-length process to get a stable release of Python into the stable OS release; and * the user is always running the latest stable OS version immediately after its release. When, in reality, the OS team will need quite a long time to ensure the stable Python release works smoothly with all of the rest of the OS; the stable release will come some number of months after that assurance process is complete; and the user will upgrade some wildly varying time after the stable OS release is complete. That reality means ?any decent OS will have Python 3.4 today? rather bold, only a month after its release, and eliminates just about all OSen from ?decent? category. On the other hand, you might have meant ?Python 3.4 is available *for* any decent OS today?; this is a very different thing from the OS having that version of Python. -- \ ?We can't depend for the long run on distinguishing one | `\ bitstream from another in order to figure out which rules | _o__) apply.? ?Eben Moglen, _Anarchism Triumphant_, 1999 | Ben Finney From greg.ewing at canterbury.ac.nz Tue Apr 15 08:08:25 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 16 Apr 2014 00:08:25 +1200 Subject: MemoryError in data conversion In-Reply-To: References: Message-ID: Mok-Kong Shen wrote: > (It means that I have > to pickle out the list to a file and read in the content of > the file in order to have it as a bytearray etc. etc.) No, you don't -- pickle.dumps() returns the pickled data as a bytes object instead of writing it to a file. -- Greg From invalid at invalid.invalid Tue Apr 15 11:05:25 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 15 Apr 2014 15:05:25 +0000 (UTC) Subject: Python, Linux, and the setuid bit References: <534C4F8D.6090005@stoneleaf.us> Message-ID: On 2014-04-15, Dave Angel wrote: > Your variable 'size' is declared as size_t, which is an integer > the size of a pointer. While that may always be true in practice (at least with gcc), I don't think the C standard requires it. size_t is guaranteed to be unsigned with at least 16 bits and sufficiently wide to represent the size of any object. It might be possible, in theory, to have an architecture that used 64-bit pointers but restricted each data space to 32-bits and therefore could use 32-bit values for size_t. If you want to declare an integer the size of a pointer, then the choices are intptr_t (signed), uintptr_t (unsigned), and ptrdiff_t (signed value representing the difference between to pointers). > Not necessarily the same as an int. Indeed. -- Grant Edwards grant.b.edwards Yow! Is something VIOLENT at going to happen to a gmail.com GARBAGE CAN? From thebalancepro at gmail.com Tue Apr 15 11:54:11 2014 From: thebalancepro at gmail.com (Nick Mellor) Date: Tue, 15 Apr 2014 08:54:11 -0700 (PDT) Subject: random.seed question (not reproducing same sequence) Message-ID: Hi guys, (Python 2.7, Windows 7 64-bit) Here's a bit of code stress-testing a method addUpdate_special_to_cart. The test adds and updates random "specials" (multiple products bundled at an advantageous price) of various sizes to thousands of shopping carts, then restocks the whole darn lot. The test passes if the stock level afterwards is the same as it was before executing the code for all products. addUpdate_special_to_cart is working perfectly. But the test isn't. The test iterates over the same code twice, once with special_qty==4, once with special_qty==0, reseeding the Python random module number generator to a fixed seed (a string) between the iterations. special_qty==0 removes the special and restocks the products. The test relies on precisely the same random number sequence on both runs. Can you think of a reason why the random number generator should fall out of sync between the two iterations? Because that's what's happening by the look of it: occasionally products are returned to the wrong stockbin. No "random" module method is used anywhere else while this code is executing. When I assign something non-random to the stockbin parameter, the test passes. Best wishes, Nick for qty in [4, 0]: random.seed(seed) for cart in range(test_size): for special in range(randrange(3)): s.addUpdate_special_to_cart(cart=cart, stockbin=randrange(test_size), special_id=randrange(test_size), special_qty=qty, products=[(random.choice(PRODUCTS), random.choice(range(10))) for r in range(randrange(7))]) From gordon at panix.com Tue Apr 15 12:21:26 2014 From: gordon at panix.com (John Gordon) Date: Tue, 15 Apr 2014 16:21:26 +0000 (UTC) Subject: random.seed question (not reproducing same sequence) References: Message-ID: In Nick Mellor writes: > No "random" module method is used anywhere else while this code is > executing. Are you sure? How did you verify this? -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From ned at nedbatchelder.com Tue Apr 15 12:36:21 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 15 Apr 2014 12:36:21 -0400 Subject: random.seed question (not reproducing same sequence) In-Reply-To: References: Message-ID: On 4/15/14 11:54 AM, Nick Mellor wrote: > Hi guys, > > (Python 2.7, Windows 7 64-bit) > > Here's a bit of code stress-testing a method addUpdate_special_to_cart. The test adds and updates random "specials" (multiple products bundled at an advantageous price) of various sizes to thousands of shopping carts, then restocks the whole darn lot. The test passes if the stock level afterwards is the same as it was before executing the code for all products. > > addUpdate_special_to_cart is working perfectly. But the test isn't. > > The test iterates over the same code twice, once with special_qty==4, once with special_qty==0, reseeding the Python random module number generator to a fixed seed (a string) between the iterations. special_qty==0 removes the special and restocks the products. The test relies on precisely the same random number sequence on both runs. > > Can you think of a reason why the random number generator should fall out of sync between the two iterations? Because that's what's happening by the look of it: occasionally products are returned to the wrong stockbin. No "random" module method is used anywhere else while this code is executing. > > When I assign something non-random to the stockbin parameter, the test passes. > > Best wishes, > > > > Nick > > for qty in [4, 0]: > random.seed(seed) > for cart in range(test_size): > for special in range(randrange(3)): > s.addUpdate_special_to_cart(cart=cart, stockbin=randrange(test_size), > special_id=randrange(test_size), special_qty=qty, > products=[(random.choice(PRODUCTS), random.choice(range(10))) > for r in range(randrange(7))]) > The best way to ensure repeatability of random numbers is to avoid the module-level functions, and instead create your own random.Random() instance to generate numbers. Then you can be certain it isn't being used by anything else. -- Ned Batchelder, http://nedbatchelder.com From fomcl at yahoo.com Tue Apr 15 13:21:56 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Tue, 15 Apr 2014 10:21:56 -0700 (PDT) Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> Message-ID: <1397582516.65434.YahooMailNeo@web163804.mail.gq1.yahoo.com> ----- Original Message ----- > From: Terry Reedy > To: python-list at python.org > Cc: > Sent: Tuesday, April 15, 2014 10:32 AM > Subject: Re: Martijn Faassen: The Call of Python 2.8 > > On 4/15/2014 1:03 AM, Marko Rauhamaa wrote: >> Terry Reedy : >> >>> Any decent system should have 3.4 available now. >> >> Really, now? Which system is that? > > 3.4.0 was released a month ago with Windows and Mac installers and > source for everything else. I know Ubuntu was testing the release > candidate so I presume it is or will very soon have 3.4 officially > available. Since there was a six month series of alpha, beta, and > candidate releases, with an approximate final release data, any > distribution that wanted to be up to date also could be. > > This is all quite aside from the fact that one should be able to unpack > a tarball and 'make xxx'. True, but in Debian Linux (so probably also Linux) one needs to install some zlib packages and some other stuff (https related IIRC) before compiling Python (at least with 3.3). So glad that pip (and setuptools too?) is part of the standard library in Python 3.4 (the zlib error became apparent when installing pip) Albert-Jan From __peter__ at web.de Tue Apr 15 13:34:41 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 15 Apr 2014 19:34:41 +0200 Subject: random.seed question (not reproducing same sequence) References: Message-ID: Nick Mellor wrote: > Hi guys, > > (Python 2.7, Windows 7 64-bit) > > Here's a bit of code stress-testing a method addUpdate_special_to_cart. > The test adds and updates random "specials" (multiple products bundled at > an advantageous price) of various sizes to thousands of shopping carts, > then restocks the whole darn lot. The test passes if the stock level > afterwards is the same as it was before executing the code for all > products. > > addUpdate_special_to_cart is working perfectly. But the test isn't. > > The test iterates over the same code twice, once with special_qty==4, once > with special_qty==0, reseeding the Python random module number generator > to a fixed seed (a string) between the iterations. special_qty==0 removes > the special and restocks the products. The test relies on precisely the > same random number sequence on both runs. > > Can you think of a reason why the random number generator should fall out > of sync between the two iterations? Because that's what's happening by the > look of it: occasionally products are returned to the wrong stockbin. No > "random" module method is used anywhere else while this code is executing. > > When I assign something non-random to the stockbin parameter, the test > passes. > > Best wishes, > > > > Nick > > for qty in [4, 0]: > random.seed(seed) > for cart in range(test_size): > for special in range(randrange(3)): > s.addUpdate_special_to_cart(cart=cart, > stockbin=randrange(test_size), > special_id=randrange(test_size), > special_qty=qty, > products=[(random.choice(PRODUCTS), > random.choice(range(10))) > for r in > range(randrange(7))]) An exotic option: I notice that randrange() is the only random function not qualified with the module name. If you are using a fancy auto-reloading web framework things can get out of sync: >>> import random >>> from random import randrange >>> random.seed(42) >>> [randrange(10) for _ in range(5)] [6, 0, 2, 2, 7] >>> random.seed(42) >>> [randrange(10) for _ in range(5)] [6, 0, 2, 2, 7] >>> reload(random) >>> random.seed(42) >>> [randrange(10) for _ in range(5)] [6, 8, 0, 4, 0] From phildobbin at gmail.com Tue Apr 15 14:18:47 2014 From: phildobbin at gmail.com (Phil Dobbin) Date: Tue, 15 Apr 2014 19:18:47 +0100 Subject: Simple question Message-ID: <534D7807.6050408@gmail.com> Hi, all. I've just started to learn Python (I'm reading Mark Lutz's 'Learning Python' from O'Reilly) & I'm confused as to this part: '>>> 0.1 + 0.1 + 0.1 - 0.3 5.55111.....' Using 'import Decimal' you can get a much closer result i.e. 'Decimal('0.0')' What I'm wondering is why the first calculation that arrives at '5.55111...' is so far out? Many thanks, Cheers, Phil... -- currently (ab)using CentOS 6.5, Debian Squeeze & Wheezy, Fedora 19 & 20, OS X Snow Leopard, RHEL 7, Ubuntu Precise & Saucy GnuGPG Key : http://phildobbin.org/publickey.asc Based in London, UK From zachary.ware+pylist at gmail.com Tue Apr 15 14:25:41 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Tue, 15 Apr 2014 13:25:41 -0500 Subject: Simple question In-Reply-To: <534D7807.6050408@gmail.com> References: <534D7807.6050408@gmail.com> Message-ID: On Tue, Apr 15, 2014 at 1:18 PM, Phil Dobbin wrote: > Hi, all. > > I've just started to learn Python (I'm reading Mark Lutz's 'Learning > Python' from O'Reilly) & I'm confused as to this part: > > '>>> 0.1 + 0.1 + 0.1 - 0.3 > 5.55111.....' > > Using 'import Decimal' you can get a much closer result i.e. > 'Decimal('0.0')' > > What I'm wondering is why the first calculation that arrives at > '5.55111...' is so far out? First, note that the "..." part of "5.55111..." is very important here, it's actually "5.55111...e-17" which means it's really approximately 0.000000000000000055111, which is really very close to the answer you'd expect from a human. To learn more about why Python doesn't give 0.0, read this: https://docs.python.org/3/tutorial/floatingpoint.html Hope this helps, -- Zach From rosuav at gmail.com Tue Apr 15 14:27:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Apr 2014 04:27:09 +1000 Subject: Simple question In-Reply-To: <534D7807.6050408@gmail.com> References: <534D7807.6050408@gmail.com> Message-ID: On Wed, Apr 16, 2014 at 4:18 AM, Phil Dobbin wrote: > '>>> 0.1 + 0.1 + 0.1 - 0.3 > 5.55111.....' > > What I'm wondering is why the first calculation that arrives at > '5.55111...' is so far out? There's something you're not seeing here. In full, the output I see is: >>> 0.1 + 0.1 + 0.1 - 0.3 5.551115123125783e-17 See that bit at the end? "e-17" means "times ten to the -17th power" - that is, move the decimal point 17 places to the left. So the actual value is: >>> "%50.50f"%(0.1 + 0.1 + 0.1 - 0.3) '0.00000000000000005551115123125782702118158340454102' It's not actually as far out as you think; in fact, that's incredibly close to zero. A full explanation of why floating point arithmetic does this can be found in many places on the internet, but the main thing to note is that it really isn't showing 5.5. ChrisA From joel.goldstick at gmail.com Tue Apr 15 14:28:24 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 15 Apr 2014 14:28:24 -0400 Subject: Simple question In-Reply-To: <534D7807.6050408@gmail.com> References: <534D7807.6050408@gmail.com> Message-ID: On Apr 15, 2014 2:19 PM, "Phil Dobbin" wrote: > > Hi, all. > > I've just started to learn Python (I'm reading Mark Lutz's 'Learning > Python' from O'Reilly) & I'm confused as to this part: > > '>>> 0.1 + 0.1 + 0.1 - 0.3 > 5.55111.....' > It's not. Look at the end of the result. It's scientific notation for a very small number > Using 'import Decimal' you can get a much closer result i.e. > 'Decimal('0.0')' > > What I'm wondering is why the first calculation that arrives at > '5.55111...' is so far out? > > Many thanks, > > Cheers, > > Phil... > > -- > currently (ab)using > CentOS 6.5, Debian Squeeze & Wheezy, Fedora 19 & 20, OS X Snow Leopard, > RHEL 7, Ubuntu Precise & Saucy > GnuGPG Key : http://phildobbin.org/publickey.asc > Based in London, UK > > -- > https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Tue Apr 15 14:30:36 2014 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 15 Apr 2014 19:30:36 +0100 Subject: Simple question In-Reply-To: <534D7807.6050408@gmail.com> References: <534D7807.6050408@gmail.com> Message-ID: On 2014-04-15 19:18, Phil Dobbin wrote: > Hi, all. > > I've just started to learn Python (I'm reading Mark Lutz's 'Learning > Python' from O'Reilly) & I'm confused as to this part: > > '>>> 0.1 + 0.1 + 0.1 - 0.3 > 5.55111.....' > > Using 'import Decimal' you can get a much closer result i.e. > 'Decimal('0.0')' > > What I'm wondering is why the first calculation that arrives at > '5.55111...' is so far out? The `...` elides the exponent: >>> 0.1 + 0.1 + 0.1 - 0.3 5.551115123125783e-17 If you copied that verbatim directly out of a book, that's just sloppy editing. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From phildobbin at gmail.com Tue Apr 15 14:31:36 2014 From: phildobbin at gmail.com (Phil Dobbin) Date: Tue, 15 Apr 2014 19:31:36 +0100 Subject: Simple question In-Reply-To: References: <534D7807.6050408@gmail.com> Message-ID: <534D7B08.5030909@gmail.com> On 15/04/2014 19:25, Zachary Ware wrote: > On Tue, Apr 15, 2014 at 1:18 PM, Phil Dobbin wrote: >> Hi, all. >> >> I've just started to learn Python (I'm reading Mark Lutz's 'Learning >> Python' from O'Reilly) & I'm confused as to this part: >> >> '>>> 0.1 + 0.1 + 0.1 - 0.3 >> 5.55111.....' >> >> Using 'import Decimal' you can get a much closer result i.e. >> 'Decimal('0.0')' >> >> What I'm wondering is why the first calculation that arrives at >> '5.55111...' is so far out? > > First, note that the "..." part of "5.55111..." is very important > here, it's actually "5.55111...e-17" which means it's really > approximately 0.000000000000000055111, which is really very close to > the answer you'd expect from a human. To learn more about why Python > doesn't give 0.0, read this: > https://docs.python.org/3/tutorial/floatingpoint.html > > Hope this helps, > Hi, Zach. I saw the 'e-17' appended to the end but was unsure of its meaning ( quite a number of things are introduced in the book with clarification of their meaning not forthcoming 'til later on). Thank you for the link. It'll be very helpful. Cheers, Phil... -- currently (ab)using CentOS 6.5, Debian Squeeze & Wheezy, Fedora 19 & 20, OS X Snow Leopard, RHEL 7, Ubuntu Precise & Saucy GnuGPG Key : http://phildobbin.org/publickey.asc Based in London, UK From python.list at tim.thechases.com Tue Apr 15 14:33:40 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 15 Apr 2014 13:33:40 -0500 Subject: Simple question In-Reply-To: <534D7807.6050408@gmail.com> References: <534D7807.6050408@gmail.com> Message-ID: <20140415133340.05de0dc3@bigbox.christie.dr> On 2014-04-15 19:18, Phil Dobbin wrote: > I'm confused as to this part: > > '>>> 0.1 + 0.1 + 0.1 - 0.3 > 5.55111.....' > > What I'm wondering is why the first calculation that arrives at > '5.55111...' is so far out? You omit one key detail in your "....", the "e-17" which means that is 5.55111... times 10^-17 which is a REALLY small number. To better show that, have it formatted to place: >>> "%55.55f" % (0.1 + 0.1 + 0.1 - 0.3) '0.0000000000000000555111512312578270211815834045410156250' For most engineering purposes, that's effectively zero. It comes about because of how floating-point numbers are represented internally. You can read a lot more than anybody should want to know at [1]. By using the Decimal module, you remove some of that imprecision. -tkc [1] http://en.wikipedia.org/wiki/Ieee_float From harrismh777 at gmail.com Tue Apr 15 14:32:14 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 15 Apr 2014 13:32:14 -0500 Subject: Martijn Faassen: The Call of Python 2.8 References: Message-ID: On 4/14/14 2:32 PM, Phil Dobbin wrote: > On a related note, Guido announced today that there will be no 2.8 & > that the eol for 2.7 will be 2020. > Can you site the announcement? Thanks From phildobbin at gmail.com Tue Apr 15 14:38:43 2014 From: phildobbin at gmail.com (Phil Dobbin) Date: Tue, 15 Apr 2014 19:38:43 +0100 Subject: Simple question In-Reply-To: References: <534D7807.6050408@gmail.com> Message-ID: <534D7CB3.3060409@gmail.com> On 15/04/2014 19:30, Robert Kern wrote: > On 2014-04-15 19:18, Phil Dobbin wrote: >> Hi, all. >> >> I've just started to learn Python (I'm reading Mark Lutz's 'Learning >> Python' from O'Reilly) & I'm confused as to this part: >> >> '>>> 0.1 + 0.1 + 0.1 - 0.3 >> 5.55111.....' >> >> Using 'import Decimal' you can get a much closer result i.e. >> 'Decimal('0.0')' >> >> What I'm wondering is why the first calculation that arrives at >> '5.55111...' is so far out? > > The `...` elides the exponent: > > >>> 0.1 + 0.1 + 0.1 - 0.3 > 5.551115123125783e-17 > > If you copied that verbatim directly out of a book, that's just sloppy > editing. > No, the ellipses are sloppy editing on my part done purely for brevity. Unfortunately they elided the relevant part, the meaning of which was, prior to these conversations, lost on me. Thanks to all who replied. Cheers, Phil... -- currently (ab)using CentOS 6.5, Debian Squeeze & Wheezy, Fedora 19 & 20, OS X Snow Leopard, RHEL 7, Ubuntu Precise & Saucy GnuGPG Key : http://phildobbin.org/publickey.asc Based in London, UK From rosuav at gmail.com Tue Apr 15 14:41:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Apr 2014 04:41:50 +1000 Subject: Simple question In-Reply-To: <534D7B08.5030909@gmail.com> References: <534D7807.6050408@gmail.com> <534D7B08.5030909@gmail.com> Message-ID: On Wed, Apr 16, 2014 at 4:31 AM, Phil Dobbin wrote: > I saw the 'e-17' appended to the end but was unsure of its meaning ( > quite a number of things are introduced in the book with clarification > of their meaning not forthcoming 'til later on). Recommendation: If you don't understand something, keep it there :) You can just copy and paste from the Python interactive interpreter (command line or IDLE) straight into the email; it'll be easier to explain, that way. This is *especially* true of tracebacks. You might not see the difference, but to us, it's often hugely helpful to see the entire exception report. ChrisA From tjreedy at udel.edu Tue Apr 15 15:01:55 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 15 Apr 2014 15:01:55 -0400 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: <1397582516.65434.YahooMailNeo@web163804.mail.gq1.yahoo.com> References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> <1397582516.65434.YahooMailNeo@web163804.mail.gq1.yahoo.com> Message-ID: On 4/15/2014 1:21 PM, Albert-Jan Roskam wrote: >> This is all quite aside from the fact that one should be able to >> unpack a tarball and 'make xxx'. > > True, but in Debian Linux (so probably also Linux) one needs to > install some zlib packages and some other stuff (https related IIRC) > before compiling Python (at least with 3.3). On windows, I can compile Python without the 3rd party dependencies installed. (They are also mostly installed by one .bat file.) The compiler will report errors for what is missing, and the corresponding imports (like 'import zlib') from the missing dlls will fail, but python.exe is built and otherwise runs fine. Are things different on *nix -- all or nothing? In any case, once the dependencies are installed, they should still be there if one upgrades with patch release. > So glad that pip (and setuptools too?) is part of the standard > library in Python 3.4 (the zlib error became apparent when installing > pip) -- Terry Jan Reedy From phildobbin at gmail.com Tue Apr 15 15:02:51 2014 From: phildobbin at gmail.com (Phil Dobbin) Date: Tue, 15 Apr 2014 20:02:51 +0100 Subject: Simple question In-Reply-To: References: <534D7807.6050408@gmail.com> <534D7B08.5030909@gmail.com> Message-ID: <534D825B.5020401@gmail.com> On 15/04/2014 19:41, Chris Angelico wrote: > On Wed, Apr 16, 2014 at 4:31 AM, Phil Dobbin wrote: >> I saw the 'e-17' appended to the end but was unsure of its meaning ( >> quite a number of things are introduced in the book with clarification >> of their meaning not forthcoming 'til later on). > > Recommendation: If you don't understand something, keep it there :) > You can just copy and paste from the Python interactive interpreter > (command line or IDLE) straight into the email; it'll be easier to > explain, that way. > > This is *especially* true of tracebacks. You might not see the > difference, but to us, it's often hugely helpful to see the entire > exception report. Good advice. Truth is I'm writing emails on my laptop & attempting Python on a Desktop machine so I lazily copied by eye. My mistake. Cheers, Phil... -- currently (ab)using CentOS 6.5, Debian Squeeze & Wheezy, Fedora 19 & 20, OS X Snow Leopard, RHEL 7, Ubuntu Precise & Saucy GnuGPG Key : http://phildobbin.org/publickey.asc Based in London, UK From rosuav at gmail.com Tue Apr 15 15:07:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Apr 2014 05:07:53 +1000 Subject: Simple question In-Reply-To: <534D825B.5020401@gmail.com> References: <534D7807.6050408@gmail.com> <534D7B08.5030909@gmail.com> <534D825B.5020401@gmail.com> Message-ID: On Wed, Apr 16, 2014 at 5:02 AM, Phil Dobbin wrote: > On 15/04/2014 19:41, Chris Angelico wrote: > >> Recommendation: If you don't understand something, keep it there :) >> You can just copy and paste from the Python interactive interpreter >> (command line or IDLE) straight into the email; it'll be easier to >> explain, that way. >> >> This is *especially* true of tracebacks. You might not see the >> difference, but to us, it's often hugely helpful to see the entire >> exception report. > > Good advice. > > Truth is I'm writing emails on my laptop & attempting Python on a > Desktop machine so I lazily copied by eye. My mistake. Understandable. I currently am using two consoles (laptop at my right hand, desktop in front of me), and every now and then I want to copy and paste across them :) I mean, shared clipboard works just fine across all my VM guests (and as I type that, Disney's cast is singing "Be our guest" in my background music), it even works across remote desktop, but for some reason, swinging my hands 90 degrees doesn't transfer the clipboard. This strikes me as a major flaw in human beings. ChrisA From phildobbin at gmail.com Tue Apr 15 15:16:06 2014 From: phildobbin at gmail.com (Phil Dobbin) Date: Tue, 15 Apr 2014 20:16:06 +0100 Subject: Simple question In-Reply-To: References: <534D7807.6050408@gmail.com> <534D7B08.5030909@gmail.com> <534D825B.5020401@gmail.com> Message-ID: <534D8576.7090408@gmail.com> On 15/04/2014 20:07, Chris Angelico wrote: > On Wed, Apr 16, 2014 at 5:02 AM, Phil Dobbin wrote: >> On 15/04/2014 19:41, Chris Angelico wrote: >> >>> Recommendation: If you don't understand something, keep it there :) >>> You can just copy and paste from the Python interactive interpreter >>> (command line or IDLE) straight into the email; it'll be easier to >>> explain, that way. >>> >>> This is *especially* true of tracebacks. You might not see the >>> difference, but to us, it's often hugely helpful to see the entire >>> exception report. >> >> Good advice. >> >> Truth is I'm writing emails on my laptop & attempting Python on a >> Desktop machine so I lazily copied by eye. My mistake. > > Understandable. I currently am using two consoles (laptop at my right > hand, desktop in front of me), and every now and then I want to copy > and paste across them :) I mean, shared clipboard works just fine > across all my VM guests (and as I type that, Disney's cast is singing > "Be our guest" in my background music), it even works across remote > desktop, but for some reason, swinging my hands 90 degrees doesn't > transfer the clipboard. This strikes me as a major flaw in human > beings. :-) Couldn't agree more. Not enough thought put into that one whoever did it :-) Cheers, Phil... -- currently (ab)using CentOS 6.5, Debian Squeeze & Wheezy, Fedora 19 & 20, OS X Snow Leopard, RHEL 7, Ubuntu Precise & Saucy GnuGPG Key : http://phildobbin.org/publickey.asc Based in London, UK From tjreedy at udel.edu Tue Apr 15 15:29:41 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 15 Apr 2014 15:29:41 -0400 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: <85eh0yx1wh.fsf@benfinney.id.au> References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> <85eh0yx1wh.fsf@benfinney.id.au> Message-ID: On 4/15/2014 7:33 AM, Ben Finney wrote: > Terry Reedy writes: > >> 3.4.0 was released a month ago with Windows and Mac installers and >> source for everything else. I know Ubuntu was testing the release >> candidate so I presume it is or will very soon have 3.4 officially >> available. Since there was a six month series of alpha, beta, and >> candidate releases, with an approximate final release data, any >> distribution that wanted to be up to date also could be. > > Those assertions assume that: > > * operating systems have stable releases every few months; and > > * they have a zero-length process to get a stable release of Python into > the stable OS release; and > > * the user is always running the latest stable OS version immediately > after its release. No, I was not talking about replacing the system python. Only about having a .rpm or .deb or whatever available to make an alternate install. My comments are a response to someone saying he could not use Python3 because his system only had ancient 3.2 available and he needed to use a module that requires 3.3. If he was telling the truth, this strikes me as ridiculous. > When, in reality, the OS team will need quite a long time to ensure the > stable Python release works smoothly with all of the rest of the OS; For a standalone non-system install, I cannot imagine what you are talking about. CPython is primarily developed on Linux. It is continuous tested on multiple buildbots that include several *nix and in particular linux distributions (https://www.python.org/dev/buildbot/). I believe it more stable on linux than anything else, certainly more than on Windows. CPython x.y.0 is released after a month of candidate testing. When it is released, it definitely works on multiple linux distributions, or it would not be released. I believe distutils has options to create some package manager bundles (.rpm, .deb?, ???) and that we once hosted such on the site on day 1, along with a windows binary. I believe we no longer do because linux distributions proliferated and said that they would rather host python bundles in their own package manager systems. -- Terry Jan Reedy From tjreedy at udel.edu Tue Apr 15 15:37:49 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 15 Apr 2014 15:37:49 -0400 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: Message-ID: On 4/15/2014 2:32 PM, Mark H Harris wrote: > On 4/14/14 2:32 PM, Phil Dobbin wrote: >> On a related note, Guido announced today that there will be no 2.8 & >> that the eol for 2.7 will be 2020. >> > > Can you site the announcement? It is part of a thread on pydev list. -- Terry Jan Reedy From gregory.j.baker at gmail.com Tue Apr 15 15:37:53 2014 From: gregory.j.baker at gmail.com (Novocastrian_Nomad) Date: Tue, 15 Apr 2014 12:37:53 -0700 (PDT) Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: Message-ID: On Tuesday, April 15, 2014 12:32:14 PM UTC-6, Mark H. Harris wrote: > On 4/14/14 2:32 PM, Phil Dobbin wrote: > > On a related note, Guido announced today that there will be no 2.8 & > > that the eol for 2.7 will be 2020. > > > > Can you site the announcement? > > Thanks http://hg.python.org/peps/rev/76d43e52d978?utm_content=buffer55d59&utm_medium=social&utm_source=facebook.com&utm_campaign=buffer From bv4bv4bv4 at gmail.com Tue Apr 15 15:41:02 2014 From: bv4bv4bv4 at gmail.com (bv4bv4bv4 at gmail.com) Date: Tue, 15 Apr 2014 12:41:02 -0700 (PDT) Subject: The Purpose Of Life & Muslim Spoken Word & The Daily Reminder Message-ID: The Purpose Of Life & Muslim Spoken Word & The Daily Reminder http://www.youtube.com/watch?v=Wdhk2y6zFg4 Thank you From tjreedy at udel.edu Tue Apr 15 15:48:06 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 15 Apr 2014 15:48:06 -0400 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: <87y4z8koi0.fsf@elektro.pacujo.net> <85ioqbw2eb.fsf@benfinney.id.au> Message-ID: On 4/15/2014 5:05 AM, Chris Angelico wrote: > On Tue, Apr 15, 2014 at 6:33 PM, Terry Reedy wrote: >> On 4/15/2014 2:08 AM, Ben Finney wrote: >>> >>> Terry Reedy writes: >>> >>>> The 'mistake' is your OS, whatever it is, not providing 3.3. It is >>>> already so old that it is off bugfix maintenance. Any decent system >>>> should have 3.4 available now. >>> >>> >>> I think you mean ?? should have Python 3.3 available now?, yes? >> >> >> ??? why would you think that??? My installed 3.4.0 for Windows is dated >> March 16. > > Debian's current stable (Wheezy) was released 2013/05/04, and the > latest version release of it (7.4) was 2014/02/08. Both those dates > precede 2014/03/16, so you don't get 3.4 in Wheezy. (Actually, you > don't even get 3.3, presumably because its launch date of 2012/09/29 > missed the Wheezy feature freeze in mid-2012.) Debian Jessie (current > testing) ships 3.3 and 3.4, with the 'python3' package giving you 3.3. There are three things a distribution can do with a new Python version: 1. Push it on people. 2. Allow people who need it to easily get it. 3. Actively hide it and discourage its use. I happen to think 2) is generally the right answer. -- Terry Jan Reedy From harrismh777 at gmail.com Tue Apr 15 15:54:53 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 15 Apr 2014 14:54:53 -0500 Subject: Martijn Faassen: The Call of Python 2.8 References: Message-ID: On 4/15/14 2:37 PM, Novocastrian_Nomad wrote: > On Tuesday, April 15, 2014 12:32:14 PM UTC-6, Mark H. Harris wrote: >> >> Can you site the announcement? >> >> Thanks > > http://hg.python.org/peps/rev/76d43e52d978?utm_content=buffer55d59&utm_medium=social&utm_source=facebook.com&utm_campaign=buffer > Thanks, guys. I am noticing the call to 2.8 from time to time (blogs). All along I have been seeing the reluctance to migrate to 3.x as either stubborn or lazy; or both. I don't think so any longer. Seems like the reluctance to migrate stems from dependencies. Is there a list of primary dependencies ? As an example: Is 'twisted' a dependency? ie., twisted does not support 3.x consequently 'I' can't port my stuff to 3.x because 'twisted' isn't there yer. There are others, gevent, maybe. Has anyone taken an inventory of dependencies that must support 3.x before other code(s) can be ported? Maybe there could be an on-line questionnaire regarding perceived dependencies? marcus From tjreedy at udel.edu Tue Apr 15 17:02:45 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 15 Apr 2014 17:02:45 -0400 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: Message-ID: On 4/15/2014 3:54 PM, Mark H Harris wrote: > I don't think so any longer. Seems like the reluctance to migrate stems > from dependencies. Is there a list of primary dependencies ? https://python3wos.appspot.com/ -- Terry Jan Reedy From ned at nedbatchelder.com Tue Apr 15 17:03:55 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 15 Apr 2014 17:03:55 -0400 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: Message-ID: On 4/15/14 3:54 PM, Mark H Harris wrote: > On 4/15/14 2:37 PM, Novocastrian_Nomad wrote: >> On Tuesday, April 15, 2014 12:32:14 PM UTC-6, Mark H. Harris wrote: >>> >>> Can you site the announcement? >>> >>> Thanks >> >> http://hg.python.org/peps/rev/76d43e52d978?utm_content=buffer55d59&utm_medium=social&utm_source=facebook.com&utm_campaign=buffer >> >> > > Thanks, guys. > > I am noticing the call to 2.8 from time to time (blogs). All along I > have been seeing the reluctance to migrate to 3.x as either stubborn or > lazy; or both. > > I don't think so any longer. Seems like the reluctance to migrate stems > from dependencies. Is there a list of primary dependencies ? > > As an example: Is 'twisted' a dependency? ie., twisted does not support > 3.x consequently 'I' can't port my stuff to 3.x because 'twisted' isn't > there yer. There are others, gevent, maybe. Has anyone taken an > inventory of dependencies that must support 3.x before other code(s) can > be ported? Maybe there could be an on-line questionnaire regarding > perceived dependencies? The Python Wall-Of-Shame/Wall-Of-Superpowers shows popular packages, and their Python 3 status: http://python3wos.appspot.com/ > > marcus -- Ned Batchelder, http://nedbatchelder.com From joshua at landau.ws Tue Apr 15 17:34:19 2014 From: joshua at landau.ws (Joshua Landau) Date: Tue, 15 Apr 2014 22:34:19 +0100 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: <87r44zgp5y.fsf@elektro.pacujo.net> References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> Message-ID: On 15 April 2014 06:03, Marko Rauhamaa wrote: > Terry Reedy : > >> Any decent system should have 3.4 available now. > > Really, now? Which system is that? Arch is on 3.4 *default*. $> python Python 3.4.0 (default, Mar 17 2014, 23:20:09) [...] From ned at nedbatchelder.com Tue Apr 15 18:18:16 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 15 Apr 2014 18:18:16 -0400 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> Message-ID: On 4/15/14 5:34 PM, Joshua Landau wrote: > On 15 April 2014 06:03, Marko Rauhamaa wrote: >> Terry Reedy : >> >>> Any decent system should have 3.4 available now. >> >> Really, now? Which system is that? > > Arch is on 3.4 *default*. > > $> python > Python 3.4.0 (default, Mar 17 2014, 23:20:09) > [...] > Yeah, that's the wrong way to do it, and they shouldn't have done that. "python" needs to mean Python 2.x for a long time. -- Ned Batchelder, http://nedbatchelder.com From harrismh777 at gmail.com Tue Apr 15 18:17:10 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 15 Apr 2014 17:17:10 -0500 Subject: Martijn Faassen: The Call of Python 2.8 References: Message-ID: On 4/15/14 4:02 PM, Terry Reedy wrote: > > https://python3wos.appspot.com/ > That's what I thought. Its really about getting the super-power wall fixed up; everything else will fall in place. I do think that Guido might be positioning himself as an enabler, of sorts. I can see extending through 2015... I think extending support for 2.7 through 2020 is ridiculous. The trouble with the super-power wall is that if Guido extends toooo much, the super-powers will slack off because the dead-line appears further out than it really is. All I'm saying is a little pressure might be a good thing. marcus From aberg010 at my.hennepintech.edu Tue Apr 15 17:38:26 2014 From: aberg010 at my.hennepintech.edu (Andrew Berg) Date: Tue, 15 Apr 2014 16:38:26 -0500 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: Message-ID: <534DA6D2.3030701@my.hennepintech.edu> On 2014.04.15 16:02, Terry Reedy wrote: > https://python3wos.appspot.com/ There seems to be a difference of opinion between this page and the Twisted devs on what the "Python 2 only" classifier for PyPI means. -- CPython 3.4.0 | Windows NT 6.2.9200 / FreeBSD 10.0 From aberg010 at my.hennepintech.edu Tue Apr 15 18:32:57 2014 From: aberg010 at my.hennepintech.edu (Andrew Berg) Date: Tue, 15 Apr 2014 17:32:57 -0500 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> Message-ID: <534DB399.2010403@my.hennepintech.edu> On 2014.04.15 17:18, Ned Batchelder wrote: > Yeah, that's the wrong way to do it, and they shouldn't have done that. > "python" needs to mean Python 2.x for a long time. Or maybe explicit is better than implicit: # python zsh: command not found: python # which python2.7 /usr/local/bin/python2.7 # which python3.4 /usr/local/bin/python3.4 -- CPython 3.4.0 | Windows NT 6.2.9200 / FreeBSD 10.0 From joshua at landau.ws Tue Apr 15 19:11:36 2014 From: joshua at landau.ws (Joshua Landau) Date: Wed, 16 Apr 2014 00:11:36 +0100 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> Message-ID: On 15 April 2014 23:18, Ned Batchelder wrote: > On 4/15/14 5:34 PM, Joshua Landau wrote: >> Arch is on 3.4 *default*. >> >> $> python >> Python 3.4.0 (default, Mar 17 2014, 23:20:09) >> [...] >> > Yeah, that's the wrong way to do it, and they shouldn't have done that. > "python" needs to mean Python 2.x for a long time. Why? The only things that break are things outside of the official repos, and the vast majority of the user repository works flawlessly. If I get something from the source, I normally run it explicitly ("python the_thing") and on the very rare occasion it breaks (when it's 2.x and uses "python" to mean "python2") I can trivially patch or wrap it, and file a bug report. The python = python3 choice of Arch is not what takes up maintenance time, and it's good to prepare developers ahead of time. That's what rolling release is all about: getting the best and preparing the rest. From drsalists at gmail.com Tue Apr 15 20:07:50 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 15 Apr 2014 17:07:50 -0700 Subject: random.seed question (not reproducing same sequence) In-Reply-To: References: Message-ID: You could easily provide your own random number generator, if you don't need cryptographic-strength random numbers. EG: http://stromberg.dnsalias.org/svn/lcgrng/trunk/lcgrng.py That way you can be certain nothing else is using it. On Tue, Apr 15, 2014 at 8:54 AM, Nick Mellor wrote: > Hi guys, > > (Python 2.7, Windows 7 64-bit) > > Here's a bit of code stress-testing a method addUpdate_special_to_cart. The test adds and updates random "specials" (multiple products bundled at an advantageous price) of various sizes to thousands of shopping carts, then restocks the whole darn lot. The test passes if the stock level afterwards is the same as it was before executing the code for all products. > > addUpdate_special_to_cart is working perfectly. But the test isn't. > > The test iterates over the same code twice, once with special_qty==4, once with special_qty==0, reseeding the Python random module number generator to a fixed seed (a string) between the iterations. special_qty==0 removes the special and restocks the products. The test relies on precisely the same random number sequence on both runs. > > Can you think of a reason why the random number generator should fall out of sync between the two iterations? Because that's what's happening by the look of it: occasionally products are returned to the wrong stockbin. No "random" module method is used anywhere else while this code is executing. > > When I assign something non-random to the stockbin parameter, the test passes. > > Best wishes, > > > > Nick > > for qty in [4, 0]: > random.seed(seed) > for cart in range(test_size): > for special in range(randrange(3)): > s.addUpdate_special_to_cart(cart=cart, stockbin=randrange(test_size), > special_id=randrange(test_size), special_qty=qty, > products=[(random.choice(PRODUCTS), random.choice(range(10))) > for r in range(randrange(7))]) > -- > https://mail.python.org/mailman/listinfo/python-list From ned at nedbatchelder.com Tue Apr 15 20:39:41 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 15 Apr 2014 20:39:41 -0400 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> Message-ID: On 4/15/14 7:11 PM, Joshua Landau wrote: > On 15 April 2014 23:18, Ned Batchelder wrote: >> On 4/15/14 5:34 PM, Joshua Landau wrote: >>> Arch is on 3.4 *default*. >>> >>> $> python >>> Python 3.4.0 (default, Mar 17 2014, 23:20:09) >>> [...] >>> >> Yeah, that's the wrong way to do it, and they shouldn't have done that. >> "python" needs to mean Python 2.x for a long time. > > Why? > > The only things that break are things outside of the official repos, > and the vast majority of the user repository works flawlessly. If I > get something from the source, I normally run it explicitly ("python > the_thing") and on the very rare occasion it breaks (when it's 2.x and > uses "python" to mean "python2") I can trivially patch or wrap it, and > file a bug report. > > The python = python3 choice of Arch is not what takes up maintenance > time, and it's good to prepare developers ahead of time. That's what > rolling release is all about: getting the best and preparing the rest. > The problem is files that use shebang lines: #!/usr/bin/python or: #!/usr/bin/env python If these are Python 2 files, they now don't work. Keep in mind, these might not be files that you have written, they may have been installed as part of another package, or written long ago. For the official statement on "python" meaning Python 2, and more on why, see PEP 394: 'The "python" Command on Unix-Like Systems': http://legacy.python.org/dev/peps/pep-0394/ -- Ned Batchelder, http://nedbatchelder.com From jeanpierreda at gmail.com Tue Apr 15 20:42:17 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 15 Apr 2014 17:42:17 -0700 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> Message-ID: On Tue, Apr 15, 2014 at 4:11 PM, Joshua Landau wrote: > On 15 April 2014 23:18, Ned Batchelder wrote: >> On 4/15/14 5:34 PM, Joshua Landau wrote: >>> Arch is on 3.4 *default*. >>> >>> $> python >>> Python 3.4.0 (default, Mar 17 2014, 23:20:09) >>> [...] >>> >> Yeah, that's the wrong way to do it, and they shouldn't have done that. >> "python" needs to mean Python 2.x for a long time. > > Why? > > The only things that break are things outside of the official repos, Yes. Software included in Arch, and programs installed via distutils, will both work correctly under Arch. However, it breaks any 2.x code that is expected to run without being installed via distutils and doesn't use the "python2" executable. Which used to be any 2.x program, since "python2" originally didn't even exist in many OSes. It also, at the time of introduction, broke all installed software that wasn't part of Arch itself. I have a few problems with what they did. I don't like how Arch created a situation where it was impossible to support Arch and Debian at the same time with standalone Python 2.x programs (due to a missing python2 and differing python in Debian). I don't like how the migration was not communicated sufficiently clearly to users[*], so that when they saw weird Python errors, they came to the Python community instead of to Arch, overwhelming #python (if not other places) with support requests. (We had to temporarily ban Arch questions to stop people from asking.) I don't like how their new and unusual executable naming scheme forced into existence a PEP [1] to figure out how to bring Python and Debian into line, and I don't like how Debian was forced to do extra work to make life easier for Python 2.x developers and resolve problems that only existed because of what Arch did. They caused a lot of grief, and for what? As far as I can tell, it's was a marketing gimmick -- Arch gets to look cool by being "bleeding edge", and everyone else pays the price. It's worth stating clearly: there is actually no technical benefit to changing what the python symlink points to. If we want to do such a thing, it is for cultural reasons, and there is no urgency to it. It can be done over an extremely long period of time. [*] One might also ask why they didn't do a phase where python2 was python 2.x, python3 was python 3.x, and python was 2.x but also gave a warning to upgrade your stuff because the meaning of the symlink was changing. There is no good reason. The stated reason was that warnings are annoying -- so they broke everything instead of giving warnings. [2] [1] http://legacy.python.org/dev/peps/pep-0394/ [2] https://mail.python.org/pipermail/python-dev/2010-November/105299.html -- Devin From ned at nedbatchelder.com Tue Apr 15 20:48:06 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 15 Apr 2014 20:48:06 -0400 Subject: random.seed question (not reproducing same sequence) In-Reply-To: References: Message-ID: On 4/15/14 8:07 PM, Dan Stromberg wrote: > You could easily provide your own random number generator, if you > don't need cryptographic-strength random numbers. > > EG: > http://stromberg.dnsalias.org/svn/lcgrng/trunk/lcgrng.py > > That way you can be certain nothing else is using it. There's no need to pull in a new implementation. The stdlib module is perfectly willing to give you your own private random number sequence to use. -- Ned Batchelder, http://nedbatchelder.com From thebalancepro at gmail.com Tue Apr 15 21:05:19 2014 From: thebalancepro at gmail.com (Nick Mellor) Date: Tue, 15 Apr 2014 18:05:19 -0700 (PDT) Subject: random.seed question (not reproducing same sequence) In-Reply-To: References: Message-ID: Thanks John and others, Replies much appreciated. I don't know how it could affect the results, but the function being tested is using redis. And I am running the test code under PyCharm, so perhaps using the module-level random number generator wasn't such a good idea. Live and learn. In response to your question, John, all I know is that my own code doesn't use the random module outside of this code fragment. Ned, thanks for the tip about creating a new instance of Random(). The test failures are still happening when the stockbins are randomised (as in code below.) That is suggesting that my code is somehow at fault. Peter, I am using PyCharm as I said. But using a new Random() object to generate the sequence doesn't solve the problem apparently. The code now looks like this: rnd = random.Random() ... for qty in [4, 0]: rnd.seed(seed) for cart in range(test_size): for special in range(rnd.randrange(3)): s.addUpdate_special_to_cart(cart=cart, stockbin=rnd.randrange(test_size), special_id=rnd.randrange(test_size), special_qty=qty, products=[(rnd.choice(PRODUCTS), rnd.choice(range(10))) for r in range(rnd.randrange(7))]) Cheers, Nick From steve+comp.lang.python at pearwood.info Tue Apr 15 21:18:18 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Apr 2014 01:18:18 GMT Subject: Martijn Faassen: The Call of Python 2.8 References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> Message-ID: <534dda5a$0$29993$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Apr 2014 18:18:16 -0400, Ned Batchelder wrote: > On 4/15/14 5:34 PM, Joshua Landau wrote: >> On 15 April 2014 06:03, Marko Rauhamaa wrote: >>> Terry Reedy : >>> >>>> Any decent system should have 3.4 available now. >>> >>> Really, now? Which system is that? >> >> Arch is on 3.4 *default*. >> >> $> python >> Python 3.4.0 (default, Mar 17 2014, 23:20:09) [...] >> >> > Yeah, that's the wrong way to do it, and they shouldn't have done that. > "python" needs to mean Python 2.x for a long time. That's a matter of opinion :-) But Arch is considered pretty gung-ho in this matter, even by people (like me) who want "python" to mean "the latest version" rather than "something old and decrepit". I recall jokes back when Arch first moved to Python 3 as their system Python, that Arch was the bleeding-edge Linux distro for those who found Slackware too tame and unadventurous. For the avoidance of doubt: Python 2.7 is not "old and decripit". Yet. But some day it will be. When that time comes, I want "python" to mean Python 3.6 or 3.7 or 4.2, or whatever is the most recent version, not 2.7 or 1.5. -- Steven From steve+comp.lang.python at pearwood.info Tue Apr 15 21:21:35 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Apr 2014 01:21:35 GMT Subject: Martijn Faassen: The Call of Python 2.8 References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> Message-ID: <534ddb1f$0$29993$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Apr 2014 17:32:57 -0500, Andrew Berg wrote: > On 2014.04.15 17:18, Ned Batchelder wrote: >> Yeah, that's the wrong way to do it, and they shouldn't have done that. >> "python" needs to mean Python 2.x for a long time. > Or maybe explicit is better than implicit: > > # python > zsh: command not found: python > # which python2.7 > /usr/local/bin/python2.7 > # which python3.4 > /usr/local/bin/python3.4 If you really meant that, you would have typed "/usr/bin/which2.16 python" (or whatever the location and version of which on your system). -- Steven From joshua at landau.ws Tue Apr 15 22:27:35 2014 From: joshua at landau.ws (Joshua Landau) Date: Wed, 16 Apr 2014 03:27:35 +0100 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> Message-ID: On 16 April 2014 01:42, Devin Jeanpierre wrote: > Yes. Software included in Arch, and programs installed via distutils, > will both work correctly under Arch. [...] > > I don't like how Arch > created a situation where it was impossible to support Arch and Debian > at the same time with standalone Python 2.x programs (due to a missing > python2 and differing python in Debian). Let the developers aim at Debian and other mainstream distros and Arch will clean it up for its own use. Isn't that how it normally works? This did, however, quickly result in "python2" symlinks, which I think is extremely good in the long run to have ingrained in people's habits. > I don't like how the > migration was not communicated sufficiently clearly to users[*], so > that when they saw weird Python errors, they came to the Python > community instead of to Arch That's not expected Arch user behaviour ;). > I don't like how their new and > unusual executable naming scheme forced into existence a PEP [1] to > figure out how to bring Python and Debian into line, and I don't like > how Debian was forced to do extra work to make life easier for Python > 2.x developers and resolve problems that only existed because of what > Arch did. I don't agree entirely. Arch was early, perhaps earlier than reasonable, but "python2" was going to be needed soon anyway, especially since it significantly aids adoption of the version-prepended names. > It's worth stating clearly: there is actually no technical benefit to > changing what the python symlink points to. If we want to do such a > thing, it is for cultural reasons, and there is no urgency to it. It > can be done over an extremely long period of time. This is Arch. The fact that it *can* be done over a long period of time falls far behind the "cultural reasons" in level of importance. > [*] One might also ask why they didn't do a phase where python2 was > python 2.x, python3 was python 3.x, and python was 2.x but also gave a > warning to upgrade your stuff because the meaning of the symlink was > changing. There is no good reason. The stated reason was that warnings > are annoying -- so they broke everything instead of giving warnings. [2] > > [2] https://mail.python.org/pipermail/python-dev/2010-November/105299.html Thanks for the read; I found it rather entertaining. Apologies about the #python grief. I disagree with you about the warnings. Arch is made to move fast and this is made abundantly clear: @https://wiki.archlinux.org/index.php/The_Arch_Way > This user-centric design necessarily implies a certain "do-it-yourself" approach to using the Arch distribution. Rather than pursuing assistance or requesting a new feature to be implemented by developers, Arch Linux users have a tendency to solve problems themselves and generously share the results with the community and development team ? a "do first, then ask" philosophy. This is especially true for user-contributed packages found in the Arch User Repository ? the official Arch Linux repository for community-maintained packages. If people want to run Arch but don't want the Arch way, then there's not much we can do about it. Arch isn't going to compromise its demographic because a different demographic is also using it. From steve+comp.lang.python at pearwood.info Tue Apr 15 22:51:45 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Apr 2014 02:51:45 GMT Subject: Martijn Faassen: The Call of Python 2.8 References: Message-ID: <534df041$0$29993$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Apr 2014 14:54:53 -0500, Mark H Harris wrote: > I am noticing the call to 2.8 from time to time (blogs). All along I > have been seeing the reluctance to migrate to 3.x as either stubborn or > lazy; or both. Migrating to 3.x can be a fair amount of work. Not as much work as migrating to a new language, you get to keep probably 90-99% of the code, but it's not always easy either. Converting "print spam" to "print(spam)" is the trivial part of it. The biggest change between Python 2.x and 3.x is the bytes to Unicode shift, and that is *not trivial*. Python 2.x tries very hard to make bytes and strings interoperate even when doing so is the wrong thing to do. So there is a lot of Python 2 code that is *broken* with respect to strings, but *seems okay* so long as you only test it using pure ASCII. Python 3 no longer tries to hide the difference, it forces you to confront the fact that bytes and strings are not the same. To people raised on ASCII- only programming standards, that's a huge paradigm shift, and a confusing one. There's a lot to learn, a lot of pain if you don't learn it, and there can be a lot of effort needed to migrate string code to Python 3. (Depending on what your code actually does. It is remarkable just how much string code you can write that works identically in 2.x and 3.x. Basic string handling remains basic in both.) The Python ecosystem is a lot bigger than ASCII users, and everyone else had to suffer with Python 2's string handling so ASCII users don't have to do anything special. With Python 3, everyone is in the same boat. If all your data is ASCII, you might be resentful of the need to go to all this trouble for no apparent benefit, and resentful of Python 3 forcing you to deal it. But whether you are glad of the changes or wish it was 1959 and you could forget all about the non-ASCII world[1], there is no doubt that the effort required can be painful. So migrating costs time, and effort, and money. If you have a 100-line script, your experience is likely to be very different from somebody having to migrate a 100,000 line application. People are reluctant to spend that sort of time and money without clear benefit, and for many people, Python 2 is "good enough". Apart from Unicode, which many people do not need, appreciate or even want[2], the benefits of Python 3 are incremental, not revolutionary, and the cost/benefit ratio is on the wrong side to justify migration. This is why Python 2.7 has got such extended support, and why the core developers are spending so much effort trying to decrease the cost of migration and increase the benefit. But, ultimately, some people will decide to never migrate their application to 3.x, because the cost will always exceed the benefit. That's okay. That's the great thing about software. So long as you can find hardware that will run Python 2.7, you can keep running 2.7 for ever. Or 2.3, or 1.5. > I don't think so any longer. Seems like the reluctance to migrate stems > from dependencies. Not anymore. Most -- not all, but the majority -- now support 3.x. Now the reluctance stems from cost/benefit. If it takes four people a month to migrate your application, and you pay them $40 an hour (a relatively low price for software developers, I know some who make in the vicinity of $200 an hour), that's a direct cost of $25K. Plus the indirect cost of stuff that they could have been working on in that time but aren't. Would you pay twenty-five thousand dollars for an upgrade that runs a bit slower but otherwise has no new functionality that you care about? This is why Alex Gaynor calls Python 2.7 "the new Cobol". I expect that most, but not all, small and medium sized Python applications will eventually be migrated to 3.x, and new applications of any size will be written in 3.x, but many existing big Python apps will stay on 2.7 forever. [1] The non-ASCII world includes the USA. Even in the US, there are common American-English symbols which cannot be written using pure ASCII, the most obvious being ? the cent symbol. [2] Sadly, there are still people who consider Unicode to be unnecessary. Why can't everyone just learn to write in English? Or if they won't, why can't I just ignore them and hope they go away? -- Steven From steve+comp.lang.python at pearwood.info Tue Apr 15 22:52:28 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Apr 2014 02:52:28 GMT Subject: Martijn Faassen: The Call of Python 2.8 References: <87y4z8koi0.fsf@elektro.pacujo.net> <85ioqbw2eb.fsf@benfinney.id.au> Message-ID: <534df06b$0$29993$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Apr 2014 15:48:06 -0400, Terry Reedy wrote: > On 4/15/2014 5:05 AM, Chris Angelico wrote: >> On Tue, Apr 15, 2014 at 6:33 PM, Terry Reedy wrote: >>> On 4/15/2014 2:08 AM, Ben Finney wrote: >>>> >>>> Terry Reedy writes: >>>> >>>>> The 'mistake' is your OS, whatever it is, not providing 3.3. It is >>>>> already so old that it is off bugfix maintenance. Any decent system >>>>> should have 3.4 available now. >>>> >>>> >>>> I think you mean ?? should have Python 3.3 available now?, yes? >>> >>> >>> ??? why would you think that??? My installed 3.4.0 for Windows is >>> dated March 16. >> >> Debian's current stable (Wheezy) was released 2013/05/04, and the >> latest version release of it (7.4) was 2014/02/08. Both those dates >> precede 2014/03/16, so you don't get 3.4 in Wheezy. (Actually, you >> don't even get 3.3, presumably because its launch date of 2012/09/29 >> missed the Wheezy feature freeze in mid-2012.) Debian Jessie (current >> testing) ships 3.3 and 3.4, with the 'python3' package giving you 3.3. > > There are three things a distribution can do with a new Python version: > 1. Push it on people. > 2. Allow people who need it to easily get it. > 3. Actively hide it and discourage its use. > > I happen to think 2) is generally the right answer. How would they do #3? Patch all the web browsers to fake a 404 Not Found when you go to the Python website and try to download it? I'm actually asking a serious question. How does a distro "actively hide" something publicly available on the Internet? Note that, on Linux (when you talk about "distributions", you probably don't mean OS X or Windows) all the compiler tools needed to install from source are readily available, so anyone who wants to install a Python version not supported by their distro can do so. Many people don't wish to install anything outside of their distro's supported packages, but that's their choice, not the distro imposing anything on them. -- Steven From kushal.kumaran at gmail.com Tue Apr 15 23:19:13 2014 From: kushal.kumaran at gmail.com (Kushal Kumaran) Date: Wed, 16 Apr 2014 08:49:13 +0530 Subject: Simple question In-Reply-To: References: <534D7807.6050408@gmail.com> <534D7B08.5030909@gmail.com> <534D825B.5020401@gmail.com> Message-ID: <6d473df5-a1d8-429e-90df-60bd2c24bbae@email.android.com> On April 16, 2014 12:37:53 AM GMT+05:30, Chris Angelico wrote: >On Wed, Apr 16, 2014 at 5:02 AM, Phil Dobbin >wrote: >> On 15/04/2014 19:41, Chris Angelico wrote: >> >>> Recommendation: If you don't understand something, keep it there :) >>> You can just copy and paste from the Python interactive interpreter >>> (command line or IDLE) straight into the email; it'll be easier to >>> explain, that way. >>> >>> This is *especially* true of tracebacks. You might not see the >>> difference, but to us, it's often hugely helpful to see the entire >>> exception report. >> >> Good advice. >> >> Truth is I'm writing emails on my laptop & attempting Python on a >> Desktop machine so I lazily copied by eye. My mistake. > >Understandable. I currently am using two consoles (laptop at my right >hand, desktop in front of me), and every now and then I want to copy >and paste across them :) I mean, shared clipboard works just fine >across all my VM guests (and as I type that, Disney's cast is singing >"Be our guest" in my background music), it even works across remote >desktop, but for some reason, swinging my hands 90 degrees doesn't >transfer the clipboard. This strikes me as a major flaw in human >beings. > You want synergy. http://synergy-foss.org/ -- Sent from my Android device with K-9 Mail. Please excuse my brevity. From gordon at panix.com Wed Apr 16 00:32:57 2014 From: gordon at panix.com (John Gordon) Date: Wed, 16 Apr 2014 04:32:57 +0000 (UTC) Subject: random.seed question (not reproducing same sequence) References: Message-ID: In Nick Mellor writes: > In response to your question, John, all I know is that my own code doesn't > use the random module outside of this code fragment. Does addUpdate_special_to_cart() use any random methods? In any case, a further test would be to strip out all the business logic and leave only the calls to random, and see if the results still differ. Something like this: rnd = random.Random() for qty in [4, 0]: print "qty is %s" % qty rnd.seed(seed) print "seed is %s" % seed for cart in range(test_size): print "cart is %s " % cart for special in range(rnd.randrange(3)): print "special is %s " % special print "stockbin is %s" % rnd.randrange(test_size) print "special_id is %s" % rnd.randrange(test_size) print "products is %s" % [(rnd.choice(PRODUCTS), rnd.choice(range(10))) for r in range(rnd.randrange(7))]) Run that code sample and see if the results differ when qty is 4 vs 0. -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From rosuav at gmail.com Wed Apr 16 02:03:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Apr 2014 16:03:33 +1000 Subject: Simple question In-Reply-To: <6d473df5-a1d8-429e-90df-60bd2c24bbae@email.android.com> References: <534D7807.6050408@gmail.com> <534D7B08.5030909@gmail.com> <534D825B.5020401@gmail.com> <6d473df5-a1d8-429e-90df-60bd2c24bbae@email.android.com> Message-ID: On Wed, Apr 16, 2014 at 1:19 PM, Kushal Kumaran wrote: >>Understandable. I currently am using two consoles (laptop at my right >>hand, desktop in front of me), and every now and then I want to copy >>and paste across them :) I mean, shared clipboard works just fine >>across all my VM guests (and as I type that, Disney's cast is singing >>"Be our guest" in my background music), it even works across remote >>desktop, but for some reason, swinging my hands 90 degrees doesn't >>transfer the clipboard. This strikes me as a major flaw in human >>beings. >> > > You want synergy. http://synergy-foss.org/ Usually I want separate keyboard and mouse, so that I can be playing Command & Conquer Renegade on one system while responding to emails on the other (hold W so Havoc keeps walking, read through emails by scrolling with right hand...); it's just the clipboard. It would, of course, be possible to write a clipboard viewer program for whichever platform - say, OS/2 - and have it connect via a TCP/IP socket to a program on another system - say, a Linux box - that has a little hidden window and puts stuff onto the clipboard. I will neither confirm nor deny having actually done this... *twiddles thumbs* ChrisA From rosuav at gmail.com Wed Apr 16 02:14:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Apr 2014 16:14:42 +1000 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: <534df041$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <534df041$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 16, 2014 at 12:51 PM, Steven D'Aprano wrote: > Converting "print spam" to "print(spam)" is the trivial part of it. The > biggest change between Python 2.x and 3.x is the bytes to Unicode shift, > and that is *not trivial*. Python 2.x tries very hard to make bytes and > strings interoperate even when doing so is the wrong thing to do. So > there is a lot of Python 2 code that is *broken* with respect to strings, > but *seems okay* so long as you only test it using pure ASCII. Python 3 > no longer tries to hide the difference, it forces you to confront the > fact that bytes and strings are not the same. To people raised on ASCII- > only programming standards, that's a huge paradigm shift, and a confusing > one. There's a lot to learn, a lot of pain if you don't learn it, and > there can be a lot of effort needed to migrate string code to Python 3. Has anyone ever had the same "oh great, now I have to push everyone through a paradigm shift" feeling about anything else? The only one I can think of is shifting my whole family off Windows file sharing (just accessing files everywhere) onto wholesale use of source control (have a local copy, and push your changes). > (Depending on what your code actually does. It is remarkable just how > much string code you can write that works identically in 2.x and 3.x. > Basic string handling remains basic in both.) With PEP 461 (slated for 3.5), that's going to get even easier. Not only will a simple double-quoted string "do the right thing" on both platforms, but both b"binary" and u"unicode" will support the same percent-formatting as well. But you do have to limit your definition of "2.x"; a lot of that commonality is the result of deliberate design, and NOT just "oh hey look it works", which means that 2.4 and 3.4 are very different. I respect and do not envy those who have to support both RHEL and Arch... ChrisA From rosuav at gmail.com Wed Apr 16 02:22:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Apr 2014 16:22:59 +1000 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: <534df06b$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <87y4z8koi0.fsf@elektro.pacujo.net> <85ioqbw2eb.fsf@benfinney.id.au> <534df06b$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 16, 2014 at 12:52 PM, Steven D'Aprano wrote: > I'm actually asking a serious question. How does a distro "actively hide" > something publicly available on the Internet? Note that, on Linux (when > you talk about "distributions", you probably don't mean OS X or Windows) > all the compiler tools needed to install from source are readily > available, so anyone who wants to install a Python version not supported > by their distro can do so. Many people don't wish to install anything > outside of their distro's supported packages, but that's their choice, > not the distro imposing anything on them. I'd say it's not so much "actively hide" as just "abandon people to their own devices". It's all very well to say "well hey, just go and compile it from source"; this assumes two things: 1) The available source code will compile on your platform 2) The user knows how to compile code. The first is true of the platforms supported by python.org, but that's not the OS/distribution helping you to get Python - that's Python helping you to get Python. The second... that's where things like "apt-get build-dep" come in, but mainly there's a general understanding among end users that compiling code is haaaaaaard. Some cultures have this more strongly than others... sometimes for good reason. (I had stupid amounts of trouble trying to get a C compiler going on OS X. A non-programmer, doing the same job, might well give up, and I wouldn't argue.) Compiling from source without a package manager fetching all the appropriate libraries means an iterative process of "compile or build, see what the error is, figure out what's missing, fetch it, GOTO 10". For me, that's life; that's something I've done on a number of different systems, and I know lots of the clues and/or the tools for figuring things out. For many non-programmers, though, if there's no binary package, they won't use the software. ChrisA From wxjmfauth at gmail.com Wed Apr 16 02:30:38 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 15 Apr 2014 23:30:38 -0700 (PDT) Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: <87y4z8koi0.fsf@elektro.pacujo.net> <85ioqbw2eb.fsf@benfinney.id.au> <534df06b$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: ---- It is more than clear to me, Python did and does not understand the "unicode case". jmf From aberg010 at my.hennepintech.edu Wed Apr 16 03:32:00 2014 From: aberg010 at my.hennepintech.edu (Andrew Berg) Date: Wed, 16 Apr 2014 02:32:00 -0500 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: <534ddb1f$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> <534ddb1f$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <534E31F0.7010105@my.hennepintech.edu> On 2014.04.15 20:21, Steven D'Aprano wrote: > On Tue, 15 Apr 2014 17:32:57 -0500, Andrew Berg wrote: > >> On 2014.04.15 17:18, Ned Batchelder wrote: >>> Yeah, that's the wrong way to do it, and they shouldn't have done that. >>> "python" needs to mean Python 2.x for a long time. >> Or maybe explicit is better than implicit: >> >> # python >> zsh: command not found: python >> # which python2.7 >> /usr/local/bin/python2.7 >> # which python3.4 >> /usr/local/bin/python3.4 > > If you really meant that, you would have typed "/usr/bin/which2.16 > python" (or whatever the location and version of which on your system). Are you sure about that? # which which which: shell built-in command Unless I'm forgetting some more explicit way of calling a command built into the shell. -- CPython 3.4.0 | Windows NT 6.2.9200 / FreeBSD 10.0 From alihanif799 at gmail.com Wed Apr 16 03:45:54 2014 From: alihanif799 at gmail.com (ali hanif) Date: Wed, 16 Apr 2014 12:45:54 +0500 Subject: Attribute error while executing python script Message-ID: Hi i am a student and working on GNU..I have a python code which i want to run in GNU radio companion but i am unable to search for the right block to execute that code...can anyone help me with that??When I execute the same python code(not in GNU), I get the following error: AttributeError: 'top_block_sptr' object has no attribute 'wxgui_' If anyone knows about this,plz send a mail to alihanif799 at gmail.com....thnx in advance..the code is as shown: #!/usr/bin/env pythonfrom gnuradio import blocksfrom gnuradio import eng_notationfrom gnuradio import grfrom gnuradio import uhd#from gnuradio import windowfrom gnuradio.eng_option import eng_option#from gnuradio.gr import firdesfrom gnuradio.wxgui import formsfrom gnuradio.wxgui import waterfallsink2from grc_gnuradio import wxgui as grc_wxguifrom optparse import OptionParserimport wx class top_block(grc_wxgui.top_block_gui): def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ### ############################################### self.variable_slider_1 = variable_slider_1 = 32 self.variable_slider_0 = variable_slider_0 = 0 self.samp_rate = samp_rate = 21e6 self.gain = gain = variable_slider_1 self.delay_length = delay_length= variable_slider_0 ################################################## # Blocks ################################################## self.wxgui_waterfallsink2_0_0 = waterfallsink2.waterfall_sink_c( self.GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Output Waterfall Plot", ) self.GridAdd(self.wxgui_waterfallsink2_0_0.win, 0, 10, 10, 10) self.wxgui_ waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Input Waterfall Plot", ) self.GridAdd(self.wxgui_waterfallsink2_0.win, 0, 0, 10, 10) _variable_slider_1_sizer = wx.BoxSizer(wx.VERTICAL) self._variable_slider_1_text_box = forms.text_box( parent=self.GetWin(), sizer=_variable_slider_1_sizer, value=self.variable_slider_1, callback=self.set_variable_slider_1, label="Output Gain", converter=forms.float_converter(), proportion=0, ) self._variable_slider_1_slider = forms.slider( parent=self.GetWin(), sizer=_variable_slider_1_sizer, value=self.variable_slider_1, callback=self.set_variable_slider_1, minimum=0, maximum=32, num_steps=31, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_variable_slider_1_sizer, 12, 10, 1, 9) _variable_sl ider_0_sizer = wx.BoxSizer(wx.VERTICAL) self._variable_slider_0_text_box = forms.text_box( parent=self.GetWin(), sizer=_variable_slider_0_sizer, value=self.variable_slider_0, callback=self.set_variable_slider_0, label="Delay Length", converter=forms.int_converter(), proportion=0, ) self._variable_slider_0_slider = forms.slider( parent=self.GetWin(), sizer=_variable_slider_0_sizer, value=self.variable_slider_0, callback=self.set_variable_slider_0, minimum=0, maximum=710000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=int, proportion=1, ) self.GridAdd(_variable_slider_0_sizer, 10, 10, 1, 9) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(2.28e9, 0) self.uhd_usrp_source_0.set_gain(0, 0) self.uhd_usrp_sink_0 = uhd.usrp_sink( device_addr="", stream_args =uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_sink_0.set_samp_rate(samp_rate) self.uhd_usrp_sink_0.set_center_freq(2.28e9, 0) self.uhd_usrp_sink_0.set_gain(gain, 0) self.gr_file_source_0_0 = gr.file_source( gr.sizeof_gr_complex*1,"/home/ubuntu/radar-rx3.capture", True) self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1,"/home/ubuntu/radar-rx3.capture", True) self.gr_delay_0_0 = gr.delay(gr.sizeof_gr_complex*1, delay_length) self.blocks_mult iply_xx_0 = blocks.multiply_vcc(1) ################################################## # Connections ################################################## self.connect((self.uhd_usrp_source_0, 0), (self.wxgui_waterfallsink2_0, 0)) self.connect((self.gr_file_source_0_0, 0), (self.gr_delay_0_0, 0)) self.connect((self.gr_file_source_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.gr_delay_0_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_multiply_xx_0, 0), (self.uhd_usrp_sink_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.wxgui_waterfallsink2_0_0, 0)) def get_variable_slider_1(self): return self.variable_slider_1 def set_variable_slider_1(self, variable_slider_1): self.variable_slider_1 = variable_slider_1 self.set_gain(self.variable_slider_1) self._variable_slider_1_slider.set_value(self.variable_slider_1) self._variable_slider_1_text_box.set_value(self.variable_slider_1) def get_variable_slider_0(self): return self.variable_slider_0 def set_variable_slider_0(self, variable_slider_0): self.variable_slider_0 = variable_slider_0 self.set_delay_length(self.variable_slider_0) self._variable_slider_0_slider.set_value(self.variable_slider_0) self._variable_slider_0_text_box.set_value(self.variable_slider_0) def get_samp_rate(self): return self.samp_rate def set_samp_rate(self, samp_rate): self.samp_rate = samp_rate self.wxgui_waterfallsink2_0.set_sample_rate(self.samp_rate) self.wxgui_waterfallsink2_0_0.set_sample_rate(self.samp_rate) self.uhd_usrp_sink_0.set_samp_rate(self.samp_rate) self.uhd_usrp_source_0.set_samp_rate(self.samp_rate) def get_gain(self): return self.gain def set_gain(self, gain): self.gain = gain self.uhd_usrp_sink_0.set_gain(self.gain, 0) def get_delay_length(self): return self.delay_length def set_delay_length(self, delay_length): self.delay_length = delay_length self.gr_delay_0_0.set_delay(self.delay_length)if __name__ == '__main__': parser = OptionParser(option_class=eng_option,usage="%prog: [options]") (options, args) = parser.parse_args() tb = top_block() tb.Run(True) ALI -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Apr 16 04:02:06 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Apr 2014 18:02:06 +1000 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: <534E31F0.7010105@my.hennepintech.edu> References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> <534ddb1f$0$29993$c3e8da3$5496439d@news.astraweb.com> <534E31F0.7010105@my.hennepintech.edu> Message-ID: On Wed, Apr 16, 2014 at 5:32 PM, Andrew Berg wrote: >> If you really meant that, you would have typed "/usr/bin/which2.16 >> python" (or whatever the location and version of which on your system). > Are you sure about that? > # which which > which: shell built-in command > Unless I'm forgetting some more explicit way of calling a command built into the shell. Hmm, interesting. That's not the case for me: rosuav at sikorsky:~$ which which /usr/bin/which Debian Wheezy. ChrisA From rustompmody at gmail.com Wed Apr 16 04:07:42 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 16 Apr 2014 01:07:42 -0700 (PDT) Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> <534ddb1f$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5c0f4a5d-0ba8-439a-b04a-92d5c3c96a6f@googlegroups.com> On Wednesday, April 16, 2014 1:02:00 PM UTC+5:30, Andrew Berg wrote: > On 2014.04.15 20:21, Steven D'Aprano wrote: > > > On Tue, 15 Apr 2014 17:32:57 -0500, Andrew Berg wrote: > > > > > >> On 2014.04.15 17:18, Ned Batchelder wrote: > > >>> Yeah, that's the wrong way to do it, and they shouldn't have done that. > > >>> "python" needs to mean Python 2.x for a long time. > > >> Or maybe explicit is better than implicit: > > >> > > >> # python > > >> zsh: command not found: python > > >> # which python2.7 > > >> /usr/local/bin/python2.7 > >> # which python3.4 > >> /usr/local/bin/python3.4 > > If you really meant that, you would have typed "/usr/bin/which2.16 > > python" (or whatever the location and version of which on your system). > > Are you sure about that? > # which which > which: shell built-in command > Unless I'm forgetting some more explicit way of calling a command built into the shell. Not out here: $ which which /usr/bin/which $ ls -l /usr/bin/which lrwxrwxrwx 1 root root 10 Jul 28 2013 /usr/bin/which -> /bin/which Though there is no evidence of which-versionitis which is what Steven is implying?? From rosuav at gmail.com Wed Apr 16 04:12:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Apr 2014 18:12:00 +1000 Subject: Attribute error while executing python script In-Reply-To: References: Message-ID: On Wed, Apr 16, 2014 at 5:45 PM, ali hanif wrote: > Hi i am a student and working on GNU..I have a python code which i want to > run in GNU radio companion but i am unable to search for the right block to > execute that code...can anyone help me with that??When I execute the same > python code(not in GNU), I get the following error: > > AttributeError: 'top_block_sptr' object has no attribute 'wxgui_' > > If anyone knows about this,plz send a mail to alihanif799 at gmail.com....thnx > in advance..the code is as shown: Several points. I'll get to the one that you asked about. Firstly, please don't ask us to send you direct mail. I'm letting you off on that one and cc'ing you, but a lot of people won't. If you want a response, read the newsgroup/mailing list; that's what participation means. (There are a few lists where cc'ing is the convention, so you don't have to subscribe to hear the responses. This is not normal for mailing lists, and definitely not for newsgroups, so it's safer to assume you have to join.) Secondly: "GNU" is a project and an operating system, not a particular program. See http://www.gnu.org/ for more info. You're talking about "GNU Radio Companion", which may be either http://gnuradio.org/redmine/projects/gnuradio/wiki or http://gnuradio.org/redmine/projects/gnuradio/wiki/GNURadioCompanion and is not really clear. Posting a link to what you're talking about would help enormously. Thirdly: When you get an error from Python, it comes with a full traceback, pinpointing the failing line. Copy and paste the entire traceback, not just the final line, as it helps us significantly. (But in this case, I did figure out what was going on.) Finally, you'll find it a lot easier to debug programs if you cut the problem code down. Check out http://www.sscce.org/ for more info on that. Often you'll find the problem yourself as you cut the code down; if not, you can at least post a short, simple snippet, which we can more easily debug. (Note that sometimes a problem really does depend on the size of the code. I've had some of these. But then you can still post your results: "deleting any line from this code prevents the bug from happening".) > self.wxgui_waterfallsink2_0_0 = waterfallsink2.waterfall_sink_c( > self.GetWin(), > baseband_freq=0, > dynamic_range=100, > ref_level=0, > ref_scale=2.0, > sample_rate=samp_rate, > fft_size=512, > fft_rate=15, > average=False, > avg_alpha=None, > title="Output Waterfall Plot", > ) The layout here is what's tripping you up. Either your mailer has destroyed structure, or this is almost unreadably tangled. And it results in this next problem: > self.wxgui_ > waterfallsink2_0 = waterfallsink2.waterfall_sink_c( > self.GetWin(), > baseband_freq=0, > dynamic_range=100, > ref_level=0, > ref_scale=2.0, > sample_rate=samp_rate, > fft_size=512, > fft_rate=15, > average=False, > avg_alpha=None, > title="Input Waterfall Plot", > ) You've broken this in a place that doesn't work. The traceback points you exactly to the failing line, and that's where the problem exists. ChrisA From steve at pearwood.info Wed Apr 16 04:13:42 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 16 Apr 2014 08:13:42 GMT Subject: Martijn Faassen: The Call of Python 2.8 References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> <534ddb1f$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <534e3bb6$0$11109$c3e8da3@news.astraweb.com> On Wed, 16 Apr 2014 02:32:00 -0500, Andrew Berg wrote: > On 2014.04.15 20:21, Steven D'Aprano wrote: >> On Tue, 15 Apr 2014 17:32:57 -0500, Andrew Berg wrote: >> >>> On 2014.04.15 17:18, Ned Batchelder wrote: >>>> Yeah, that's the wrong way to do it, and they shouldn't have done >>>> that. >>>> "python" needs to mean Python 2.x for a long time. >>> Or maybe explicit is better than implicit: >>> >>> # python >>> zsh: command not found: python >>> # which python2.7 >>> /usr/local/bin/python2.7 >>> # which python3.4 >>> /usr/local/bin/python3.4 >> >> If you really meant that, you would have typed "/usr/bin/which2.16 >> python" (or whatever the location and version of which on your system). > Are you sure about that? > # which which > which: shell built-in command > Unless I'm forgetting some more explicit way of calling a command built > into the shell. I've tried it on two different systems: steve at runes:~$ which which /usr/bin/which although I see you are running as root: steve at runes:~$ su - Password: root at runes:~# which which /usr/bin/which Nope, that makes no difference. In any case, you're missing my point, which is not *where* the which binary lives, but the fact that you're calling some specific version, located in some specific place (even if that place is a virtual place inside the shell) implicitly rather than explicitly. Which is usually (but not always!) what we want for an interactive shell. Who wants to be typing out explicit paths to versioned binaries *all the time*? -- Steven From aberg010 at my.hennepintech.edu Wed Apr 16 04:42:54 2014 From: aberg010 at my.hennepintech.edu (Andrew Berg) Date: Wed, 16 Apr 2014 03:42:54 -0500 Subject: Martijn Faassen: The Call of Python 2.8 In-Reply-To: References: <87y4z8koi0.fsf@elektro.pacujo.net> <87r44zgp5y.fsf@elektro.pacujo.net> <534ddb1f$0$29993$c3e8da3$5496439d@news.astraweb.com> <534E31F0.7010105@my.hennepintech.edu> Message-ID: <534E428E.7090307@my.hennepintech.edu> On 2014.04.16 03:02, Chris Angelico wrote: > Hmm, interesting. That's not the case for me: > > rosuav at sikorsky:~$ which which > /usr/bin/which That's because bash either does not have a builtin which or it is not enabled by default. I switched to zsh a while ago. I do still, of course, have a system which, which is at /usr/bin/which, and which is the which that a shell which does not have a builtin which will use. -- CPython 3.4.0 | Windows NT 6.2.9200 / FreeBSD 10.0 From acewebacademy1 at gmail.com Wed Apr 16 05:29:32 2014 From: acewebacademy1 at gmail.com (Ace Webacademy) Date: Wed, 16 Apr 2014 02:29:32 -0700 (PDT) Subject: Web Designing Training Institutes in Hyderabad-Acewebacademy Message-ID: <7de0b69e-27eb-4412-8474-eb60df41664f@googlegroups.com> For professional courses in web designing and development at an affordable price choose Ace web academy one of the best web designing institutes in Hyderabad. Call: 7660-966-660. From ludi at linuxmail.org Wed Apr 16 06:47:03 2014 From: ludi at linuxmail.org (=?UTF-8?B?0JLQu9Cw0YLQutC+INCh0YLQsNC90LrQvtCy0LjRnA==?=) Date: Wed, 16 Apr 2014 12:47:03 +0200 Subject: subprocess help Message-ID: Hello, I'm having some sort of 'problem' when using subprocess calls. This is the code snipet that i am using: capture_server1 = '''xvfb-run --auto-servernum ... ''' server1_download = subprocess.Popen(shlex.split(capture_server1),stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out_s1, err_s1 = server1_download.communicate() time.sleep(2) capture_server2 = '''xvfb-run --auto-servernum .... ''' server2_download = subprocess.Popen(shlex.split(capture_server2), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out_s2, err_s2 = server2_download.communicate() The problem is the following: - The program runs in a loop, where subprocess is called - It runs for X days, sometimes 3 days, sometimes 5 days - After that i get the following exception: File "/usr/lib/python2.7/subprocess.py", line 1091, in pipe_cloexec r, w = os.pipe() OSError: [Errno 24] Too many open files How can i reproduce this on a local machine, and how to make sure that i wont have any errors like this? P.S. Version 2.7 is used with this program -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Apr 16 06:55:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Apr 2014 20:55:52 +1000 Subject: subprocess help In-Reply-To: References: Message-ID: On Wed, Apr 16, 2014 at 8:47 PM, ?????? ????????? wrote: > capture_server1 = '''xvfb-run --auto-servernum ... ''' > server1_download = subprocess.Popen(shlex.split(capture_server1) Separate to your actual problem: Is there a reason for splitting like that, rather than simply using a list of separate arguments? That would be a lot safer and easier; no going through the hassles of quoting and splitting. Your exact problem is likely to be due to unclosed files. I don't know enough about .communicate() to know whether it closes everything immediately or not, but it looks like you're progressively opening more and more and more pipes. ChrisA From steve+comp.lang.python at pearwood.info Wed Apr 16 08:06:16 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Apr 2014 12:06:16 GMT Subject: subprocess help References: Message-ID: <534e7238$0$29993$c3e8da3$5496439d@news.astraweb.com> On Wed, 16 Apr 2014 12:47:03 +0200, ?????? ????????? wrote: > Hello, > I'm having some sort of 'problem' when using subprocess calls. This is > the code snipet that i am using: > > capture_server1 = '''xvfb-run --auto-servernum ... ''' > server1_download = subprocess.Popen(shlex.split(capture_server1), > stdin=subprocess.PIPE, > stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > > out_s1, err_s1 = server1_download.communicate() > time.sleep(2) What's the difference between the server1 code (shown above) and the server2 code (not shown, but identical as far as I can tell)? [...] > The problem is the following: > - The program runs in a loop, where subprocess is called - It runs for X > days, sometimes 3 days, sometimes 5 days - After that i get the > following exception: > > File "/usr/lib/python2.7/subprocess.py", line 1091, in pipe_cloexec r, w > = os.pipe() > OSError: [Errno 24] Too many open files You have to identify what files are remaining open. What does the xvfb- run process do? What are the rest of the arguments? My guess is that, depending on the arguments, sometimes xvfb-run leaves files open even after the process terminates. You should monitor the open files with lsof which is available on most Linux systems. I don't know how to do that on other operating systems. -- Steven From josephlkremer at gmail.com Wed Apr 16 09:50:25 2014 From: josephlkremer at gmail.com (josephlkremer at gmail.com) Date: Wed, 16 Apr 2014 06:50:25 -0700 (PDT) Subject: Tutorials for Reorganizing Spreadsheet Data Message-ID: <4c4b4c31-2a49-4ba1-93b4-16573116acff@googlegroups.com> Hello, I'm a high school physics teacher and while I've played with Python enough to make a rock paper scissors program or animation of a bouncing ball (with air resistance!), I've never used it to work with data from a spreadsheet. I have a large spreadsheet with a number of different student responses to a weekly prompt in various cells depending on which question they chose to answer. I'd like to organize these responses into something that make it easy for students to look back through their responses over time, and see how they've changed. This is obviously possible in Python, but I don't know where to begin learning the details of what I'll need to know to build it. Can anyone give me a specific recommendation of tutorials where I might begin? Thanks! Joe From joel.goldstick at gmail.com Wed Apr 16 10:09:13 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 16 Apr 2014 10:09:13 -0400 Subject: Tutorials for Reorganizing Spreadsheet Data In-Reply-To: <4c4b4c31-2a49-4ba1-93b4-16573116acff@googlegroups.com> References: <4c4b4c31-2a49-4ba1-93b4-16573116acff@googlegroups.com> Message-ID: On Apr 16, 2014 9:55 AM, wrote: > > Hello, I'm a high school physics teacher and while I've played with Python enough to make a rock paper scissors program or animation of a bouncing ball (with air resistance!), I've never used it to work with data from a spreadsheet. > > I have a large spreadsheet with a number of different student responses to a weekly prompt in various cells depending on which question they chose to answer. I'd like to organize these responses into something that make it easy for students to look back through their responses over time, and see how they've changed. > > This is obviously possible in Python, but I don't know where to begin learning the details of what I'll need to know to build it. Can anyone give me a specific recommendation of tutorials where I might begin? > The package xlrd will read your Excel files > Thanks! > > Joe > -- > https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Apr 16 10:16:34 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 16 Apr 2014 10:16:34 -0400 Subject: Tutorials for Reorganizing Spreadsheet Data In-Reply-To: <4c4b4c31-2a49-4ba1-93b4-16573116acff@googlegroups.com> References: <4c4b4c31-2a49-4ba1-93b4-16573116acff@googlegroups.com> Message-ID: On 4/16/2014 9:50 AM, josephlkremer at gmail.com wrote: > Hello, I'm a high school physics teacher and while I've played with Python enough to make a rock paper scissors program or animation of a bouncing ball (with air resistance!), I've never used it to work with data from a spreadsheet. > > I have a large spreadsheet with a number of different student responses to a weekly prompt in various cells depending on which question they chose to answer. I'd like to organize these responses into something that make it easy for students to look back through their responses over time, and see how they've changed. > > This is obviously possible in Python, but I don't know where to begin learning the details of what I'll need to know to build it. Can anyone give me a specific recommendation of tutorials where I might begin? Is your spreadsheet actually on sheets (paper) or in a program? If the latter, you should be about to output the data as a 'comma-separated variable' (csv) file and read it in python with the csv module. If you want to work with the data directly in the spreadsheet file, the details depend on the OS and program. -- Terry Jan Reedy From jahree1129 at gmail.com Wed Apr 16 13:56:50 2014 From: jahree1129 at gmail.com (J W Burton) Date: Wed, 16 Apr 2014 10:56:50 -0700 (PDT) Subject: import serial failure Message-ID: <8b5b5c61-02f6-4250-8751-124b555a74fd@googlegroups.com> I have installed both Python 2.7 AND Python 3.3 and the corresponding pyserial files from ihttps://pypi.python.org/packages/any/p/pyserial/pyserial-2.7.win32.exe#md5=21555387937eeb79126cde25abee4b35n my for 2.7 When I look in my Python27/Lib/site-packages/serial folder I see package files but when I run a program using import serial, I get an error Traceback (most recent call last): File "C:\Users\Jahree\serial.py", line 2, in import serial File "C:\Users\Jahree\serial.py", line 5, in ser = serial.Serial( AttributeError: 'module' object has no attribute 'Serial' I'm guessing there is a path not set correctly - I'M STUCK Please help. Thanks ps: the following is serial.py file I'm using for testing. import time import serial # configure the serial connections (the parameters differs on the device you are connecting to) ser = serial.Serial( port='/dev/ttyUSB1', baudrate=19200, parity=serial.PARITY_ODD, stopbits=serial.STOPBITS_TWO, bytesize=serial.SEVENBITS ) ser.open() ser.isOpen() print('Enter your commands below.\r\nInsert "exit" to leave the application.') input=1 while 1 : # get keyboard input input = raw_input(">> ") input = input(">> ") if input == 'exit': ser.close() exit() else: # send the character to the device # (note that I happend a \r\n carriage return and line feed to the characters - this is requested by my device) ser.write(input + '\r\n') out = '' # let's wait one second before reading output (let's give device time to answer) time.sleep(2) while ser.inWaiting() > 0: out += ser.read(4) if out != '': print(">>" ,out) From zachary.ware+pylist at gmail.com Wed Apr 16 14:08:22 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Wed, 16 Apr 2014 13:08:22 -0500 Subject: import serial failure In-Reply-To: <8b5b5c61-02f6-4250-8751-124b555a74fd@googlegroups.com> References: <8b5b5c61-02f6-4250-8751-124b555a74fd@googlegroups.com> Message-ID: On Wed, Apr 16, 2014 at 12:56 PM, J W Burton wrote: > I have installed both Python 2.7 AND Python 3.3 and the corresponding pyserial files from > > ihttps://pypi.python.org/packages/any/p/pyserial/pyserial-2.7.win32.exe#md5=21555387937eeb79126cde25abee4b35n my > > for 2.7 > > When I look in my Python27/Lib/site-packages/serial folder I see > package files > > but when I run a program using import serial, I get an error > Traceback (most recent call last): > File "C:\Users\Jahree\serial.py", line 2, in > import serial > File "C:\Users\Jahree\serial.py", line 5, in > ser = serial.Serial( > AttributeError: 'module' object has no attribute 'Serial' > > I'm guessing there is a path not set correctly - I'M STUCK > > Please help. > > Thanks > > ps: the following is serial.py file I'm using for testing. > > import time > import serial Your file is named serial.py, so "import serial" in that file will try to import itself. You can see this in the traceback you posted, everything is coming from "C:\Users\Jahree\serial.py". Rename your serial.py and things should work as expected. Hope this helps, -- Zach From __peter__ at web.de Wed Apr 16 14:15:29 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 16 Apr 2014 20:15:29 +0200 Subject: import serial failure References: <8b5b5c61-02f6-4250-8751-124b555a74fd@googlegroups.com> Message-ID: J W Burton wrote: > I have installed both Python 2.7 AND Python 3.3 and the corresponding > pyserial files from > > ihttps://pypi.python.org/packages/any/p/pyserial/pyserial-2.7.win32.exe#md5=21555387937eeb79126cde25abee4b35n > my > > for 2.7 > > When I look in my Python27/Lib/site-packages/serial folder I see > package files > > but when I run a program using import serial, I get an error > Traceback (most recent call last): > File "C:\Users\Jahree\serial.py", line 2, in > import serial > File "C:\Users\Jahree\serial.py", line 5, in > ser = serial.Serial( > AttributeError: 'module' object has no attribute 'Serial' > > I'm guessing there is a path not set correctly - I'M STUCK > > Please help. > > Thanks > > ps: the following is serial.py file I'm using for testing. Your choice of filename is unfortunate ;) > import time > import serial The file is importing itself here. Rename your C:\Users\Jahree\serial.py to something unique, say C:\Users\Jahree\myserial.py delete C:\Users\Jahree\serial.pyc and everything should be OK. From demianbrecht at gmail.com Wed Apr 16 18:17:00 2014 From: demianbrecht at gmail.com (Demian Brecht) Date: Wed, 16 Apr 2014 15:17:00 -0700 Subject: [ANN] JOSE Message-ID: Hi all, jose is a Python Javascript Object Signing and Encryption (JOSE, https://datatracker.ietf.org/wg/jose/charter/) implementation, intended to support token-based authentication. This library implements JWS and JWEs along with a subset of the encryption/authentication algorithms recommended by the JOSE framework. Code: https://github.com/Demonware/jose Docs: http://jose.readthedocs.org/en/latest PyPI: https://pypi.python.org/pypi/jose? -- Demian Brecht http://demianbrecht.github.com From miki.tebeka at gmail.com Thu Apr 17 03:26:11 2014 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 17 Apr 2014 00:26:11 -0700 (PDT) Subject: [ann] pypi2u - Get notified on new version of packages Message-ID: Greetings, http://pypi2u.appspot.com/ is a simple service that notifies you on new versions of packages you're interested in. You can view the code, fill bugs and suggest ideas at https://bitbucket.org/tebeka/pypi2u Hope you find it useful, -- Miki From inferno.daemon at gmail.com Thu Apr 17 07:10:43 2014 From: inferno.daemon at gmail.com (=?UTF-8?B?0JLQu9Cw0YLQutC+INCh0YLQsNC90LrQvtCy0LjRnA==?=) Date: Thu, 17 Apr 2014 13:10:43 +0200 Subject: subprocess help Message-ID: > > > > ---------- Forwarded message ---------- >> From: Steven D'Aprano >> To: python-list at python.org >> Cc: >> Date: 16 Apr 2014 12:06:16 GMT >> Subject: Re: subprocess help >> On Wed, 16 Apr 2014 12:47:03 +0200, ?????? ????????? wrote: >> > Hello, >> > I'm having some sort of 'problem' when using subprocess calls. This is >> > the code snipet that i am using: >> > >> > capture_server1 = '''xvfb-run --auto-servernum ... ''' >> > server1_download = subprocess.Popen(shlex.split(capture_server1), >> > stdin=subprocess.PIPE, >> > stdout=subprocess.PIPE, >> > stderr=subprocess.PIPE) >> > >> > out_s1, err_s1 = server1_download.communicate() >> > time.sleep(2) >> What's the difference between the server1 code (shown above) and the >> server2 code (not shown, but identical as far as I can tell)? >> You have to identify what files are remaining open. What does the xvfb- >> run process do? What are the rest of the arguments? >> My guess is that, depending on the arguments, sometimes xvfb-run leaves >> files open even after the process terminates. You should monitor the open >> files with lsof which is available on most Linux systems. I don't know >> how to do that on other operating systems. >> My guess is that, depending on the arguments, sometimes xvfb-run leaves >> files open even after the process terminates. You should monitor the open >> files with lsof which is available on most Linux systems. I don't know >> how to do that on other operating systems. >> -- >> Steven > > > -- https://mail.python.org/mailman/listinfo/python-list xvfb-run accepts some parameters and calls CutyCapt with parameters for it The command is this: xvfb-run --auto-servernum --server-num=55 --server-args "-screen 0, > 1024x768x24" {0} --url="{1}" --private-browsing=on --out={2} So server1, opens a process with CutyCapt which points to server1 address/url, does its thing and saves the result in out Server2 in the other hand has a different address/url, different server-num, and different out As a workarround i've added close_fds=True, preexec_fn=os.setsid, and after communicate(), i am doing os.killpg(server1.pid, signal.SIGUSR1) Although i am not sure if this will work 100% because i have to wait X days until something crashes Any ideas are welcomed P.S. After adding os.killpg, lsof and ps aux dont show more than 4 or 5 xvfb and cutycapt processes while running Thanks and Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From Bernd.Moennicke at claas.com Thu Apr 17 09:19:20 2014 From: Bernd.Moennicke at claas.com (Bernd.Moennicke at claas.com) Date: Thu, 17 Apr 2014 15:19:20 +0200 Subject: problem in event handling on change of variable value. Message-ID: hello sirjee, i have read You solution for handling of events from CANoe in python. I've implemented and its work correctly when I waiting in a msgbox (0, "Finished the Test", "Info", 16). I will implement it in a loop with a sleep time. The standard python function of the sleep blocks the actual task and the event handling dosn't work. Now I search for a solution to start the event class in a extra task with treahding.Thread. I've write a simple claas for testing of this: class Tester (threading.Thread): def __init__ (self, variable): threading.Thread.__init__ (self) self.__debug = True self.__env_event = None self.__appl = win32com.client.Dispatch ('CANoe.Application') self.__env = self.__appl.Environment self.__var_name = variable self.__var = self.__env.GetVariable (variable) def run (self): if self.__var != None: self.__env_event = win32com.client.WithEvents (self.__var, Tester) print 'run' i = 0 while True: pass time.sleep (10) print i i = i + 1 def OnChange (self, value): if self._debug: print ('VariableEvents:OnChange now called with %s' %value) a = Tester ('dummy') a.start () The run() dosn't work. I can't register the COM event. Have You a solution for this? The claas tester works without self.__env_event = win32com.client.WithEvents (self.__var, Tester). Regards, Bernd -------------- next part -------------- An HTML attachment was scrubbed... URL: From haiticare2011 at gmail.com Thu Apr 17 12:20:21 2014 From: haiticare2011 at gmail.com (haiticare2011 at gmail.com) Date: Thu, 17 Apr 2014 09:20:21 -0700 (PDT) Subject: networking question: 2-way messaging w/o wireless modem config? Message-ID: <8fe95840-5a60-4387-8b56-d683904ba474@googlegroups.com> I have a Raspberry Pi board with a wireless usb modem on it. I wish to be able to message 2-way with the board from across the internet, without having to open ports on the wireless modem. Is there a way to do this? I have been looking at udp, but imagine that a udp packet is allowed in, but not out? The amount of data transmission I want is very small, maybe lt 30 bytes. So a client http request could include this data? I have been looking at messaging systems like MQTT as well, but don't know if they require opening a port in the typical modem-router. Any ideas appreciated! From harrismh777 at gmail.com Thu Apr 17 12:38:46 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 17 Apr 2014 11:38:46 -0500 Subject: networking question: 2-way messaging w/o wireless modem config? References: <8fe95840-5a60-4387-8b56-d683904ba474@googlegroups.com> Message-ID: On 4/17/14 11:20 AM, haiticare2011 at gmail.com wrote: > I have a Raspberry Pi board with a wireless usb modem on it. > I wish to be able to message 2-way with the board from > across the internet, without having to open ports on the wireless modem. Is there > a way to do this? I have been looking at udp, but imagine that a udp packet is > allowed in, but not out? > The amount of data transmission I want is very small, maybe lt 30 bytes. The answer depends on how you setup your wireless modem | router. There are many ways to set this up depending on your project goals. If you're trying to setup a sniffer (well, just don't do that, its not nice). If you were trying to setup a micro server on my network (for instance), well, you couln't, because I don't permit the outgoing connection without authorization and port (actually, same is true for incoming connections. I would have to setup auth and port for you to connect your Pi as a micro server on my wireless network. Most public access points are blocked (peer to peer) too (if they're smart). For legitimate non trivial setups (not experiments) you want to control the connection with auth and ports. A word of caution about udp. If the data you are sending is contained in one datagram (one packet), then no problem; however, if you are sending multiple packets over the WAN it can be a big problem because the upd in|out does not guarantee correct packet ordering. Is there a python question in here somewhere? marcus From jcasale at activenetwerx.com Thu Apr 17 13:58:49 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 17 Apr 2014 17:58:49 +0000 Subject: Soap list and soap users on this list Message-ID: <2966d22f950544d3a70d68d7c84010f0@exch.activenetwerx.com> Seems the soap list is a little quiet and the moderator is mia regardless. Are there many soap users on this list familiar with Spyne or does anyone know the most optimal place to post such questions? Thanks! jlc From rosuav at gmail.com Thu Apr 17 14:07:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 18 Apr 2014 04:07:31 +1000 Subject: Soap list and soap users on this list In-Reply-To: <2966d22f950544d3a70d68d7c84010f0@exch.activenetwerx.com> References: <2966d22f950544d3a70d68d7c84010f0@exch.activenetwerx.com> Message-ID: On Fri, Apr 18, 2014 at 3:58 AM, Joseph L. Casale wrote: > Seems the soap list is a little quiet and the moderator is mia regardless. > > Are there many soap users on this list familiar with Spyne or does anyone > know the most optimal place to post such questions? I've used SOAP, but not with Python. (I've also used soap, but never with any form of python. Snakes can stay dirty for all I care.) Wouldn't really call myself a "soap user", tbh. Is your question regarding anything at all Python, or are you just looking for helpful nerds? :) ChrisA From jcasale at activenetwerx.com Thu Apr 17 14:34:38 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 17 Apr 2014 18:34:38 +0000 Subject: Soap list and soap users on this list In-Reply-To: References: <2966d22f950544d3a70d68d7c84010f0@exch.activenetwerx.com>, Message-ID: > Is your question > regarding anything at all Python, or are you just looking for helpful > nerds? :) Hi Chris, Thanks for responding. I've been looking at Spyne to produce a service that can accept a request formatted as follows: Where I am interested in the ID attribute of the attr tag as well as _all_ the varying xml within the data tags. The docs are good, but a bit thin on more intricate examples. Maybe your previous soap experience might lead you to a tip that would eternally in debt me to you:) I have only ever done the most simplest work with soap and or ajax and hence got away with not knowing much... Thanks again for your help! jlc From harrismh777 at gmail.com Thu Apr 17 14:31:52 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 17 Apr 2014 13:31:52 -0500 Subject: Soap list and soap users on this list References: Message-ID: On 4/17/14 12:58 PM, Joseph L. Casale wrote: > Seems the soap list is a little quiet and the moderator is mia regardless. > > Are there many soap users on this list familiar with Spyne or does anyone > know the most optimal place to post such questions? Read first. You can try : > http://spyne.io/docs/2.10/ > https://pythonhosted.org/Soapbox/ google is our friend. There are lots of links in the above, tutorials, &c. Also, you might do some additional searching on PyPI... lots of SOAP packages (simple object access protocol). Spyne uses SOAP. marcus From jcasale at activenetwerx.com Thu Apr 17 14:48:26 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 17 Apr 2014 18:48:26 +0000 Subject: Soap list and soap users on this list In-Reply-To: References: , Message-ID: <02cb4c799cdb409b90f476f85cc7e374@exch.activenetwerx.com> >Read first. > > >You can try : > > > http://spyne.io/docs/2.10/ > > > https://pythonhosted.org/Soapbox/ Thanks Marcus, I assure you I have been reading but missed soapbox, I'll keep hacking away, thanks for the pointer. jlc From haiticare2011 at gmail.com Thu Apr 17 22:56:35 2014 From: haiticare2011 at gmail.com (haiticare2011 at gmail.com) Date: Thu, 17 Apr 2014 19:56:35 -0700 (PDT) Subject: networking question: 2-way messaging w/o wireless modem config? In-Reply-To: References: <8fe95840-5a60-4387-8b56-d683904ba474@googlegroups.com> Message-ID: <59e90e46-5043-43af-9aa5-e1daf61e2e90@googlegroups.com> On Thursday, April 17, 2014 12:38:46 PM UTC-4, Mark H. Harris wrote: > On 4/17/14 11:20 AM, hxaiticzzare2011 at gmail.com wrote: > > > I have a Raspberry Pi board with a wireless usb modem on it. > > > I wish to be able to message 2-way with the board from > > > across the internet, without having to open ports on the wireless modem. Is there > > > a way to do this? I have been looking at udp, but imagine that a udp packet is > > > allowed in, but not out? > > > The amount of data transmission I want is very small, maybe lt 30 bytes. > > > > The answer depends on how you setup your wireless modem | router. There > > are many ways to set this up depending on your project goals. If you're > > trying to setup a sniffer (well, just don't do that, its not nice). > > > > If you were trying to setup a micro server on my network (for instance), > > well, you couln't, because I don't permit the outgoing connection > > without authorization and port (actually, same is true for incoming > > connections. I would have to setup auth and port for you to connect your > > Pi as a micro server on my wireless network. Most public access points > > are blocked (peer to peer) too (if they're smart). > > > > For legitimate non trivial setups (not experiments) you want to control > > the connection with auth and ports. > > > > A word of caution about udp. If the data you are sending is contained in > > one datagram (one packet), then no problem; however, if you are sending > > multiple packets over the WAN it can be a big problem because the upd > > in|out does not guarantee correct packet ordering. > > > > Is there a python question in here somewhere? > > > > marcus Thanks - I am just trying to design a consumer product where the consumer does not have to fiddle with their modem, ie, plug'n'play. Usually, with consumer modems, you can do http client activity. (just connect another PC to the local network.) So I guess I could iniate a http request from the Pi. I just wondered if there were other protocols that would allow me to just communicate with the Pi. As far as sniffers etc., I adhere to a complete personal honesty - that's my policy, as anything else just won't do. I hope to program the item in Python, though I'm wondering if C is better for network programming. Thanks for help. jb From rosuav at gmail.com Thu Apr 17 23:04:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 18 Apr 2014 13:04:50 +1000 Subject: networking question: 2-way messaging w/o wireless modem config? In-Reply-To: <59e90e46-5043-43af-9aa5-e1daf61e2e90@googlegroups.com> References: <8fe95840-5a60-4387-8b56-d683904ba474@googlegroups.com> <59e90e46-5043-43af-9aa5-e1daf61e2e90@googlegroups.com> Message-ID: On Fri, Apr 18, 2014 at 12:56 PM, wrote: > As far as sniffers etc., I adhere to a complete personal honesty - that's my > policy, as anything else just won't do. I hope to program the item in Python, > though I'm wondering if C is better for network programming. Not at all. I'd definitely recommend doing networking code in Python. You can do basic TCP/IP sockets pretty much the same way in every language, but with high level languages like Python, you get extra facilities that C won't give - most notably, the urllib.request module [1]. Same goes for quite a few other high level protocols. Take the easy way out! ChrisA [1] https://docs.python.org/3/library/urllib.request.html From Egon.Frerich at gmx.de Fri Apr 18 06:07:07 2014 From: Egon.Frerich at gmx.de (Egon Frerich) Date: Fri, 18 Apr 2014 12:07:07 +0200 Subject: module and namespace Message-ID: An HTML attachment was scrubbed... URL: From francescapochecchio at mail.com Fri Apr 18 07:15:11 2014 From: francescapochecchio at mail.com (francescapochecchio at mail.com) Date: Fri, 18 Apr 2014 04:15:11 -0700 (PDT) Subject: -- redacted -- Message-ID: <9549b5bc-b22e-436f-b699-8cc9714d3dbd@googlegroups.com> -- redacted -- From francescapochecchio at mail.com Fri Apr 18 07:19:09 2014 From: francescapochecchio at mail.com (FEDERICO TRABUCCO KAIROS MILAN) Date: Fri, 18 Apr 2014 04:19:09 -0700 (PDT) Subject: -- redacted -- Message-ID: <68f91a40-933f-4c27-866f-ef432dd92fc5@googlegroups.com> -- redacted -- From __peter__ at web.de Fri Apr 18 07:48:40 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 18 Apr 2014 13:48:40 +0200 Subject: module and namespace References: Message-ID: Egon Frerich wrote: [Egon, please post in plain test, not html. Thank you] > I have a problem with a namespace. There is a module mptt (actally from > Django). If I import this module with the interpreter it tells me the > namespace: > > Python 3.3.5 (default, Apr 12 2014, 23:34:20) > [GCC 4.6.3] on linux > Type "help", "copyright", "credits" or "license" for more information. > > import mptt > print(mptt) > > > > > If I import mptt in my program then there is no ImportError but the > namespace is broken: > > > > (This is the output with print after the import). > > What is the meaning? When does this happened? Basically Python 3 allows for packages to omit the __init__.py $ mkdir aaa $ python3 -c'import aaa; print(aaa)' $ touch aaa/__init__.py $ python3 -c'import aaa; print(aaa)' Namespace packages have advantages when you want to merge submodules from multiple places into one package. See for the details. Your actual problem is probably that the parent directory for the mptt package is not in your sys.path, but an unrelated directory with a mptt subdirectory (that may not contain any python code) is. This is the disadvantage of namespace packages -- any old directory may be mistaken for a package. As to fixing the problem -- I don't know much about django, but you may need to invoke the interactive interpreter with $ python3 manage.py shell From gwhite at ti.com Fri Apr 18 12:18:17 2014 From: gwhite at ti.com (gwhite) Date: Fri, 18 Apr 2014 09:18:17 -0700 (PDT) Subject: TeX $\times$ symbol not working in matplotlib? Message-ID: <622d3b45-e5e6-4c3d-b65c-485128f15b32@googlegroups.com> Hi, I am trying to understand how to get the TeX "\times" symbol to work. It is in the title() string in the code I pasted in. The "\circ" symbol seems fine, by comparison. "\times" ends up as "imes" in the figure title. I am probably doing something dumb (hey, maybe a lot of dumb things!), but if you can spot and describe my mistake, I would be quite happy about that. Thank you. # (Using Python 2.7.5 via pythonxy. w7-64) ---------------------------------- import numpy as np import matplotlib.pyplot as plt Qs_rr = np.array([0.]) Qs_ri = np.array([0.]) Es_rr = np.array([-6.352844845095E-02,\ -6.352844845095E-02,\ -9.917112781473E-01,\ -1.008084892264E+00,\ -5.534164139252E-02,\ -5.534164139252E-02]) Es_ri = np.array([ 9.329580097745E-01,\ -9.329580097745E-01,\ 0.000000000000E+00,\ 0.000000000000E+00,\ 1.070772729531E+00,\ -1.070772729531E+00]) plt.hold(False) figs_open = plt.get_fignums() axes_obj=plt.figure(figs_open[0]).gca() lh1 = plt.plot(Qs_rr, Qs_ri, 'ro',\ Es_rr, Es_ri, 'rx') lh1[0].set_markerfacecolor('w') lh1[0].set_markeredgecolor('r') lh1[0].set_markersize(9.0) lh1[0].set_markeredgewidth(0.75) lh1[1].set_markersize(9.0) lh1[1].set_markeredgewidth(0.75) plt.axis([-1.2, 0.2, -1.2, 1.2]) plt.grid(True) plt.title('$\mathrm{poles}$ $(\times)$ \ $\mathrm{\&}$ $\mathrm{zeros}$ \ $(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',\ fontsize=16) plt.xlabel(r'$\sigma$', fontsize=16) plt.ylabel(r'$\mathrm{j}\omega$', fontsize=16) plt.show() From kwpolska at gmail.com Fri Apr 18 12:24:55 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Fri, 18 Apr 2014 18:24:55 +0200 Subject: TeX $\times$ symbol not working in matplotlib? In-Reply-To: <622d3b45-e5e6-4c3d-b65c-485128f15b32@googlegroups.com> References: <622d3b45-e5e6-4c3d-b65c-485128f15b32@googlegroups.com> Message-ID: On Fri, Apr 18, 2014 at 6:18 PM, gwhite wrote: > I am trying to understand how to get the TeX "\times" symbol to work. It is in the title() string in the code I pasted in. The "\circ" symbol seems fine, by comparison. "\times" ends up as "imes" in the figure title. > > I am probably doing something dumb (hey, maybe a lot of dumb things!), but if you can spot and describe my mistake, I would be quite happy about that. > plt.title('$\mathrm{poles}$ $(\times)$ \ > $\mathrm{\&}$ $\mathrm{zeros}$ \ > $(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',\ > fontsize=16) You?re using a regular string. In which backspaces can be used in escapes. \t is one of those escapes, it is the tab character. In order to fix, add the letter "r" before the opening quote. Like this: > plt.title(r'$\mathrm{poles}$ $(\times)$ \ > $\mathrm{\&}$ $\mathrm{zeros}$ \ > $(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',\ > fontsize=16) Moreover, in the next two things, you already did it right in the first place: > plt.xlabel(r'$\sigma$', fontsize=16) > plt.ylabel(r'$\mathrm{j}\omega$', fontsize=16) -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From gwhite at ti.com Fri Apr 18 12:48:39 2014 From: gwhite at ti.com (gwhite) Date: Fri, 18 Apr 2014 09:48:39 -0700 (PDT) Subject: TeX $\times$ symbol not working in matplotlib? In-Reply-To: References: <622d3b45-e5e6-4c3d-b65c-485128f15b32@googlegroups.com> Message-ID: On Friday, April 18, 2014 9:24:55 AM UTC-7, Chris "Kwpolska" Warrick wrote: > On Fri, Apr 18, 2014 at 6:18 PM, gwhite wrote: > > > I am trying to understand how to get the TeX "\times" symbol to work. It is in the title() string in the code I pasted in. The "\circ" symbol seems fine, by comparison. "\times" ends up as "imes" in the figure title. > > > > I am probably doing something dumb (hey, maybe a lot of dumb things!), but if you can spot and describe my mistake, I would be quite happy about that. > > > plt.title('$\mathrm{poles}$ $(\times)$ \ > > $\mathrm{\&}$ $\mathrm{zeros}$ \ > > $(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',\ > > fontsize=16) > > You're using a regular string. In which backspaces can be used in > escapes. \t is one of those escapes, it is the tab character. In > order to fix, add the letter "r" before the opening quote. Like this: > > > plt.title(r'$\mathrm{poles}$ $(\times)$ \ > > $\mathrm{\&}$ $\mathrm{zeros}$ \ > > $(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',\ > > fontsize=16) > > Moreover, in the next two things, you already did it right in the first place: > > > plt.xlabel(r'$\sigma$', fontsize=16) > > plt.ylabel(r'$\mathrm{j}\omega$', fontsize=16) Thanks Chris! That worked. I faked myself out since the $(\circ)$ worked *without* the little r prefix. I was blind to it. I guess the difference must be there is no \c thingy to override \circ, so it just does the circle. Thanks for the note on how the r prefix works. I knew I would screw myself sooner or later on that. Getting regular text mixed with math text, but with the same font (in regular or italic) is a bit clumsy, I suppose. (I mean getting the spaces in.) At least I can do it. I did this too, and it also seems to work: plt.title(' '.join([r'$\mathrm{poles}$', r'$(\times)$',\ r'$\mathrm{\&}$', r'$\mathrm{zeros}$', r'$(\circ)$', r'$\mathrm{of}$',\ r'$T(s)T(-s)$']), fontsize=16) From __peter__ at web.de Fri Apr 18 13:04:17 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 18 Apr 2014 19:04:17 +0200 Subject: TeX $\times$ symbol not working in matplotlib? References: <622d3b45-e5e6-4c3d-b65c-485128f15b32@googlegroups.com> Message-ID: gwhite wrote: > plt.title(' '.join([r'$\mathrm{poles}$', r'$(\times)$',\ > r'$\mathrm{\&}$', r'$\mathrm{zeros}$', > r'$(\circ)$', r'$\mathrm{of}$',\ > r'$T(s)T(-s)$']), fontsize=16) Note that adjacent string literals on the same line or inside parentheses are automatically concatenated by the compiler. So you may write the above as plt.title( r'$\mathrm{poles}$ $(\times)$ ' r'$\mathrm{\&}$ $\mathrm{zeros}$ ' r'$(\circ)$ $\mathrm{of}$ $T(s)T(-s)$', fontsize=16) Even if you leave everything else as is you don't need any backslashes at the end of the line. From davea at davea.name Fri Apr 18 13:15:50 2014 From: davea at davea.name (Dave Angel) Date: Fri, 18 Apr 2014 13:15:50 -0400 (EDT) Subject: TeX $\times$ symbol not working in matplotlib? References: <622d3b45-e5e6-4c3d-b65c-485128f15b32@googlegroups.com> Message-ID: gwhite Wrote in message: > Hi, > > I am trying to understand how to get the TeX "\times" symbol to work. It is in the title() string in the code I pasted in. The "\circ" symbol seems fine, by comparison. "\times" ends up as "imes" in the figure title. > > I am probably doing something dumb (hey, maybe a lot of dumb things!), but if you can spot and describe my mistake, I would be quite happy about that. > You want a raw string, as you did correctly in two other places in the code. A raw string tells Python not to use the backslash as an escape. (Chris said backspace, but he meant backslash) You specify raw string by the letter r just before the quote. > > plt.title('$\mathrm{poles}$ $(\times)$ \ > $\mathrm{\&}$ $\mathrm{zeros}$ \ > $(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',\ > fontsize=16) > Change to: plt.title(r'$\mathrm{poles}$ $(\times)$ \ $\mathrm{\&}$ $\mathrm{zeros}$ \ $(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',\ fontsize=16) -- DaveA From egon at frerich.eu Wed Apr 16 13:10:41 2014 From: egon at frerich.eu (Egon Frerich) Date: Wed, 16 Apr 2014 19:10:41 +0200 Subject: module and namespace Message-ID: <534EB991.1000709@frerich.eu> If I use the interpreter I get: Python 3.3.5 (default, Apr 12 2014, 23:34:20) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import mptt >>> print(mptt) >>> But if I import mptt in my program the print-statement gives What is the meaning? When does this happened? Egon From egon at frerich.eu Wed Apr 16 06:38:26 2014 From: egon at frerich.eu (Egon Frerich) Date: Wed, 16 Apr 2014 12:38:26 +0200 Subject: module and namespace Message-ID: <534E5DA2.7050205@frerich.eu> If I use the interpreter I get: Python 3.3.5 (default, Apr 12 2014, 23:34:20) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import mptt >>> print(mptt) >>> But if I import mptt in my program the print-statement gives What is the meaning? When does this happened? Egon -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2385 bytes Desc: S/MIME Cryptographic Signature URL: From egon at frerich.eu Fri Apr 18 03:34:50 2014 From: egon at frerich.eu (Egon Frerich) Date: Fri, 18 Apr 2014 09:34:50 +0200 Subject: module and namespace Message-ID: <5350D59A.9010102@frerich.eu> I have a problem with a namespace. There is a module mptt (actally from Django). If I import this module with the interpreter it tells me the namespace: Python 3.3.5 (default, Apr 12 2014, 23:34:20) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import mptt >>> print(mptt) >>> If I import mptt in my program then there is no ImportError but the namespace is broken: (This is the output with print after the import). What is the meaning? When does this happened? Egon From davea at davea.name Fri Apr 18 15:18:11 2014 From: davea at davea.name (Dave Angel) Date: Fri, 18 Apr 2014 15:18:11 -0400 (EDT) Subject: module and namespace References: <5350D59A.9010102@frerich.eu> Message-ID: Egon Frerich Wrote in message: > I have a problem with a namespace. > So you started 4 separate threads to complain about it? Keep any further remarks on the thread where you got a useful response. -- DaveA From egon at frerich.eu Fri Apr 18 16:14:33 2014 From: egon at frerich.eu (Egon Frerich) Date: Fri, 18 Apr 2014 22:14:33 +0200 Subject: module and namespace In-Reply-To: References: <5350D59A.9010102@frerich.eu> Message-ID: <535187A9.5090200@frerich.eu> Am 18.04.2014 21:18, schrieb Dave Angel: > Egon Frerich Wrote in message: >> I have a problem with a namespace. >> > > So you started 4 separate threads to complain about it? Keep any > further remarks on the thread where you got a useful response. > > > Excuse me for that. The mail server doesn't deliver the mails so I have used another mail account (which sends the mail in HTML - soory). Then the mail server got unblocked so all emails were sent. Sorry Egon -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2385 bytes Desc: S/MIME Cryptographic Signature URL: From gwhite at ti.com Fri Apr 18 19:14:51 2014 From: gwhite at ti.com (gwhite) Date: Fri, 18 Apr 2014 16:14:51 -0700 (PDT) Subject: TeX $\times$ symbol not working in matplotlib? In-Reply-To: References: <622d3b45-e5e6-4c3d-b65c-485128f15b32@googlegroups.com> Message-ID: <4877d951-8d91-49e6-8a05-07e0262c7a4d@googlegroups.com> On Friday, April 18, 2014 10:04:17 AM UTC-7, Peter Otten wrote: > gwhite wrote: > > > plt.title(' '.join([r'$\mathrm{poles}$', r'$(\times)$',\ > > r'$\mathrm{\&}$', r'$\mathrm{zeros}$', > > r'$(\circ)$', r'$\mathrm{of}$',\ > > r'$T(s)T(-s)$']), fontsize=16) > > Note that adjacent string literals on the same line or inside parentheses > are automatically concatenated by the compiler. So you may write the above > as > > plt.title( > r'$\mathrm{poles}$ $(\times)$ ' > r'$\mathrm{\&}$ $\mathrm{zeros}$ ' > r'$(\circ)$ $\mathrm{of}$ $T(s)T(-s)$', > fontsize=16) > > Even if you leave everything else as is you don't need any backslashes at > the end of the line. Well even if it had been right, I omitted one (backslash). I'm such a newb/hack. lol. No animals were harmed. Yeah, I have noticed that they don't seem to be needed, but I think I remember reading "someplace-somewhere" that a backslash means a line continuation, and perhaps I saw some author put them in. So I did it out of trying to be "strict." I'm not sure when a backslash continuation might be needed, or if that requirement has been designed out of Python. Anyway, thanks to all for the notes! From papillion at gmail.com Fri Apr 18 23:28:05 2014 From: papillion at gmail.com (Anthony Papillion) Date: Fri, 18 Apr 2014 22:28:05 -0500 Subject: Why Python 3? Message-ID: Hello Everyone, So I've been working with Python for a while and I'm starting to take on more and more serious projects with it. I've been reading a lot about Python 2 vs Python 3 and the community kind of seems split on which should be used. Some say 'Python 3 is the future, use it for everything now' and other say 'Python 3 is the future but you can't do everything in it now so use Python 2'. What is the general feel of /this/ community? I'm about to start a large scale Python project. Should it be done in 2 or 3? What are the benefits, aside from the 'it's the future' argument? Thanks, Anthony From orgnut at yahoo.com Fri Apr 18 23:46:13 2014 From: orgnut at yahoo.com (Larry Hudson) Date: Fri, 18 Apr 2014 20:46:13 -0700 Subject: TeX $\times$ symbol not working in matplotlib? In-Reply-To: <4877d951-8d91-49e6-8a05-07e0262c7a4d@googlegroups.com> References: <622d3b45-e5e6-4c3d-b65c-485128f15b32@googlegroups.com> <4877d951-8d91-49e6-8a05-07e0262c7a4d@googlegroups.com> Message-ID: <9OadnY52jYobbMzOnZ2dnUVZ_qKdnZ2d@giganews.com> On 04/18/2014 04:14 PM, gwhite wrote: [snip] > Yeah, I have noticed that they don't seem to be needed, but I think I remember reading "someplace-somewhere" that a backslash means a line continuation, and perhaps I saw some author put them in. So I did it out of trying to be "strict." > > I'm not sure when a backslash continuation might be needed, or if that requirement has been designed out of Python. > ['they' meaning trailing backslashes] No, 'they' are still definitely in Python, but can usually be avoided. As already mentioned, strings are automatically concatenated if they are separated by only whitespace (spaces/tabs/newlines). But there is a difference between this concatenation and using a trailing backslash. For example: print('this, that, ' 'the other') gives -> 'this, that, the other' print('this, that, \ the other') gives -> 'this, that, the other' The leading whitespace in the second example is significant, but is ignored in the first. The other places you can avoid the trailing backslash is within brackets, ie. (), [] or {}. Here you can split at any 'natural' position, that is following a comma, dot or an operator. ['spam', 'eggs', 'bacon'] gives -> ['spam', 'eggs', 'bacon'] --------- [2 + 3, 'spam'] gives -> [5, 'spam'] --------- print('this' and 'that' or 'other') gives -> 'that' --------- print('{}'. format('spam')) gives -> 'spam' These examples are somewhat contrived, but they do show what I'm talking about. Of course, you can still use the trailing backslash method, but when you can avoid it it usually looks cleaner. Besides simply using either method to split long lines, it is often used to line things up, either for the appearance or for documentation. Here is a dictionary example of what I mean (and the backslash method will NOT work here): d = {1 : 'one', # Describe this key/value pair 2 : 'two', # Describe this one 3 : 'three' # Etc. } Play around in the interactive mode to check out how this splitting works. -=- Larry -=- From ryan at ryanhiebert.com Sat Apr 19 00:04:43 2014 From: ryan at ryanhiebert.com (Ryan Hiebert) Date: Fri, 18 Apr 2014 23:04:43 -0500 Subject: Why Python 3? In-Reply-To: References: Message-ID: If you are starting a new project, I'd highly encourage you to use Python 3. It is a stable, well supported, and beautiful language, and gives you the full power of the innovation that is current in the Python world. Python 2 is still well supported (for a while to come), but you won't have the same access to new features and ideas that you would on Python 3. The only reason that I'd still be on Python 2 is if I absolutely had to use a library that for some reason is not yet working on Python 3. Even then, I'd work hard to try and write it in Python 3 style Python 2, because I'd want to be on Python 3 as soon as possible. On Fri, Apr 18, 2014 at 10:28 PM, Anthony Papillion wrote: > Hello Everyone, > > So I've been working with Python for a while and I'm starting to take > on more and more serious projects with it. I've been reading a lot > about Python 2 vs Python 3 and the community kind of seems split on > which should be used. > > Some say 'Python 3 is the future, use it for everything now' and other > say 'Python 3 is the future but you can't do everything in it now so > use Python 2'. > > What is the general feel of /this/ community? I'm about to start a > large scale Python project. Should it be done in 2 or 3? What are the > benefits, aside from the 'it's the future' argument? > > Thanks, > Anthony > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aberg010 at my.hennepintech.edu Sat Apr 19 00:49:22 2014 From: aberg010 at my.hennepintech.edu (Andrew Berg) Date: Fri, 18 Apr 2014 23:49:22 -0500 Subject: Why Python 3? In-Reply-To: References: Message-ID: <53520052.8030407@my.hennepintech.edu> On 2014.04.18 22:28, Anthony Papillion wrote: > What is the general feel of /this/ community? I'm about to start a > large scale Python project. Should it be done in 2 or 3? What are the > benefits, aside from the 'it's the future' argument? Python 3 is not the future; it is the present. If you're developing an application, just use Python 3.4 and don't look back unless you absolutely positively *need* one of the big libraries that doesn't fully support Python 3 yet. The smaller ones either support it or have been replaced, and the few remaining (e.g., Twisted, Django) are getting there. Python 2 still exists because there are very large existing projects (some public, some private) that are not able to use Python 3 for some reason (like heavy dependence on a third-party that doesn't support Python 3). If you are developing a new library, the decision is not likely going to be easy, but in general, I'd say the larger it is, the more you should lean toward not having Python 2 support. Of course, there are going to be other factors such as your audience and what, if any, third-party libraries you will need yourself. It's an awkward time to write a new library since supporting both 2 and 3 is a major pain, and Python 2 is eventually going away, but you will still have a significant amount of people who will want to use the library with things that can't support Python 3. Use Python 2 if you must, but know that you will end up needing to migrate to Python 3 eventually. It used to be that support for Python 3 among third-party libraries was small, but that is no longer true: http://python3wos.appspot.com/ -- CPython 3.4.0 | Windows NT 6.2.9200 / FreeBSD 10.0 From ethan at stoneleaf.us Sat Apr 19 00:50:09 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 18 Apr 2014 21:50:09 -0700 Subject: Why Python 3? In-Reply-To: References: Message-ID: <53520081.1020007@stoneleaf.us> On 04/18/2014 08:28 PM, Anthony Papillion wrote: > > What is the general feel of /this/ community? I'm about to start a > large scale Python project. Should it be done in 2 or 3? What are the > benefits, aside from the 'it's the future' argument? This community is also split. ;) Use Python 3 if you can. The best reason not to is if you have some critical library that you absolutely need and it's not yet available on 3. In which case, program as if your code base was going to run on both 2 and 3 so you can update easily once your dependency upgrades. -- ~Ethan~ From no.email at nospam.invalid Sat Apr 19 02:40:18 2014 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 18 Apr 2014 23:40:18 -0700 Subject: Why Python 3? References: Message-ID: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Anthony Papillion writes: > Some say 'Python 3 is the future, use it for everything now' and other > say 'Python 3 is the future but you can't do everything in it now so > use Python 2'. Python 3 is generally better than Python 2, except for a few packages that haven't been ported. That said, I don't know anyone who actually uses Python 3. I don't think it's a matter of wanting to use some problematic package, or having particular technical concerns. It's just that the improvement from 2 to 3 is rather small, and 2 works perfectly well and people are used to it, so they keep using it. There are nice tools that help port your codebase from 2 to 3 with fairly little effort. But, you can also keep your codebase on 2 with zero effort. So people choose zero over fairly little. If you're starting a new project and you get to choose between 2 and 3, other things equal I'd say use 3. I've kept using 2 basically because it's the path of least resistance. I'm somewhat following the 3 situation and of course I'd use 3 if I were doing something that benefited from it, but so far it hasn't been an issue. Eventually the main Linux distros will include 3 instead of 2 by default, and we'll probably see more migration then. Right now I type "python" and get 2, so I use it. From rosuav at gmail.com Sat Apr 19 03:34:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Apr 2014 17:34:36 +1000 Subject: Why Python 3? In-Reply-To: <7x8ur1esa5.fsf@ruckus.brouhaha.com> References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On Sat, Apr 19, 2014 at 4:40 PM, Paul Rubin wrote: > If you're starting a new project and you get to choose between 2 and 3, > other things equal I'd say use 3. I've kept using 2 basically because > it's the path of least resistance. I'm somewhat following the 3 > situation and of course I'd use 3 if I were doing something that > benefited from it, but so far it hasn't been an issue. > > Eventually the main Linux distros will include 3 instead of 2 by > default, and we'll probably see more migration then. Right now I type > "python" and get 2, so I use it. Several of the main distros are already including Python 3 by default (eg Ubuntu), but when you type "python", you still get Python 2, for reasons of compatibility. (See PEP 394.) As long as you set your shebang to say python3, it'll work just fine. I strongly recommend going for Python 3 unless something actually stops you from doing so. If you absolutely must use Python 2, try to aim for a minimum of 2.6 or 2.7, and start your program with this line: from __future__ import print_function, unicode_literals, division That'll make Python 2.6/2.7 behave like Python 3.x in three ways: firstly, "print" will be a function instead of a statement (and it's more powerful than the statement form, as well as being more flexible); secondly, quoted strings will be Unicode strings, not byte strings (that'll help you to start thinking about what's bytes and what's text, which is an important distinction in Python 3); and thirdly, though less important than the others, the division of two integers will result in a floating point, not an integer. I personally think the last one was a mistake on Python 3's part (why bless float specifically? what if you're working with integers and decimal.Decimals?), but if you're going to move to Python 3, you may as well have your code start working that way, so you get used to typing // to divide integers and get an integer (floor division). But if you possibly can, aim for Python 3. Every new version adds features, and new versions within the 3.x line break very little (generally only what would have been working with a bug anyway, like narrow Unicode builds of 3.2 becoming universal on 3.3). If you aim for 3.2 today, and tomorrow try to run your code on 3.4, chances are it'll work. The main thing is, know what's a text string and what's a string of bytes; that's critical in 3.x, but not in 2.x. Force yourself to think about that, and your code will be more reliable - regardless of even what language you write it in. ChrisA From ian.g.kelly at gmail.com Sat Apr 19 05:25:11 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 19 Apr 2014 03:25:11 -0600 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On Sat, Apr 19, 2014 at 1:34 AM, Chris Angelico wrote: > That'll make Python 2.6/2.7 behave like Python 3.x in three ways: > firstly, "print" will be a function instead of a statement (and it's > more powerful than the statement form, as well as being more > flexible); secondly, quoted strings will be Unicode strings, not byte > strings (that'll help you to start thinking about what's bytes and > what's text, which is an important distinction in Python 3); and > thirdly, though less important than the others, the division of two > integers will result in a floating point, not an integer. I personally > think the last one was a mistake on Python 3's part (why bless float > specifically? what if you're working with integers and > decimal.Decimals?), but if you're going to move to Python 3, you may > as well have your code start working that way, so you get used to > typing // to divide integers and get an integer (floor division). If you're working with decimals, then the result is a decimal. If one side is an integer and the other is a decimal, then the result is still a decimal. Similarly if one of the operands is a fraction, then the result is a fraction. The change from / denoting "classic division" to "true division" really only affects the case where both operands are integers, so far as I'm aware. If you want to divide two integers and get a decimal result, then convert one or both of them to decimals first; you would have needed to do the same with classic division. We also gained a consistent and explicit way to differentiate between the two different styles of division that classic division represented, as opposed to picking at run-time based on type. As for "why float" specifically, the division __future__ import has been around since 2.2, longer than either decimals or fractions. From rosuav at gmail.com Sat Apr 19 05:37:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Apr 2014 19:37:31 +1000 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On Sat, Apr 19, 2014 at 7:25 PM, Ian Kelly wrote: > The change from / denoting "classic > division" to "true division" really only affects the case where both > operands are integers, so far as I'm aware. If you want to divide two > integers and get a decimal result, then convert one or both of them to > decimals first; you would have needed to do the same with classic > division. If float were a perfect superset of int, and the only logical superset when you want non-integers, then it'd be fine. But if you're mixing int and Decimal, you have to explicitly convert, whereas if you're mixing int and float, you don't. Why is it required to be explicit with Decimal but not float? Of all the possible alternate types, why float? Only because... > As for "why float" specifically, the division __future__ import has > been around since 2.2, longer than either decimals or fractions. ... it already existed. There's no particular reason to up-cast to float, specifically, and it can cause problems with large integers - either by losing accuracy, or by outright overflowing. Suppose you take an integer, multiply it by 10, and divide it by 5. In theory, that's the same as multiplying by 2, right? Mathematically it is. In C it might not be, because the multiplication might overflow; but Python, like a number of other modern languages, has an integer type that won't overflow. In Python 2, doing the obvious thing works: x * 10 / 5 == x * 2 In Python 3, you have to say "Oh but I want my integer division to result in an integer": x * 10 // 5 == x * 2 Yes, I can see that it's nice for simple interactive use. You type "1/2" and you get back 0.5. But doesn't it just exchange one set of problems ("dividing integers by integers rounds") for another set ("floating point arithmetic isn't real number arithmetic")? Anyway. While I think it was a mistake to bless float in that way, I'm aware that it isn't going to change. Which is why, for anyone who's looking at starting a project fresh, I recommend "from __future__ import division", as it'll make the port to Py3 that much easier. ChrisA From marko at pacujo.net Sat Apr 19 05:59:18 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 19 Apr 2014 12:59:18 +0300 Subject: Why Python 3? References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: <87d2gdej2h.fsf@elektro.pacujo.net> Ian Kelly : > On Sat, Apr 19, 2014 at 1:34 AM, Chris Angelico wrote: >> if you're going to move to Python 3, you may as well have your code >> start working that way, so you get used to typing // to divide >> integers and get an integer (floor division). > > [...] > > We also gained a consistent and explicit way to differentiate between > the two different styles of division that classic division > represented, as opposed to picking at run-time based on type. Very often when integer division is needed, so is the remainder. Then, it is good to remember the builtin divmod() function: https://docs.python.org/3.4/library/functions.html#divmod In fact, divmod() goes a long way toward removing the need for // and % in Python code. Marko From ben+python at benfinney.id.au Sat Apr 19 07:05:41 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 19 Apr 2014 21:05:41 +1000 Subject: Why Python 3? References: Message-ID: <8561m5wpdm.fsf@benfinney.id.au> Anthony Papillion writes: > So I've been working with Python for a while and I'm starting to take > on more and more serious projects with it. I've been reading a lot > about Python 2 vs Python 3 and the community kind of seems split on > which should be used. The community is in transition; the direction is clear, but different people have different situations. > Some say 'Python 3 is the future, use it for everything now' and other > say 'Python 3 is the future but you can't do everything in it now so > use Python 2'. Well, it's clear: Python 3 is uncontroversially the future :-) Also: Python 3 is the only path which is currently being maintained as a target for new code. Python 2 is in bug-fix mode only, has been for years, will not be supported indefinitely, and will never get new features. Python 3 support is already excellent now, is getting better all the time, and Python 2 is losing ground and will continue to do so. > What is the general feel of /this/ community? I'd advise: that's less important than the specific needs of what *you* will be doing. If you can drop Python 2 for your specific project, do so; if you can't yet, set yourself up such that you can drop Python 2 as soon as feasible, and agitate for the blockers to be removed ASAP. > I'm about to start a large scale Python project. Should it be done in > 2 or 3? What are the benefits, aside from the 'it's the future' > argument? * Python 3 (unlike Python 2) gets Unicode right. This makes it almost unique among today's programming languages, and has become essential for 21st century programming. Any programs you begin today ? in any programming language ? can expect to be used with international text, and increasingly so as time goes on. Unicode is the only game in town for freely mixing all writing systems of the world. You need Unicode to be correct to the core of the language. * Python 3 (unlike Python 2) comes with support for virtual Python environments, namespace packages, third-party package installation, and other improvements that make it much simpler to deploy complex projects (which you'll likely need sooner than you think with any new project). * Python 3 (unlike Python 2) has more secure and efficient parallel and concurrent processing: multiprocessing, asynchronous processing, generator delegation, and ?futures? all make it a more capable, reliable, and expressive language for distributed programming. * Python 3 (unlike Python 2) has a better-kept house: its standard library, exception hierarchy, bytecode files and extension modules, and import mechanics, have all undergone consolidation and are more predictable and uniform across implementations. There are many other benefits. See for a discussion of how to determine whether it's yet time for you to go with Python 3. In brief though, from that last document: Short version: Python 2.x is legacy, Python 3.x is the present and future of the language [?] Which version you ought to use is mostly dependent on what you want to get done. If you can do exactly what you want with Python 3.x, great! -- \ ?Spam will be a thing of the past in two years' time.? ?Bill | `\ Gates, 2004-01-24 | _o__) | Ben Finney From rustompmody at gmail.com Sat Apr 19 07:43:05 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 19 Apr 2014 04:43:05 -0700 (PDT) Subject: Why Python 3? In-Reply-To: References: Message-ID: <7af58b58-c773-4638-bea7-1b66619b88ac@googlegroups.com> On Saturday, April 19, 2014 4:35:41 PM UTC+5:30, Ben Finney wrote: > Well, it's clear: Python 3 is uncontroversially the future :-) Also: > \ "Spam will be a thing of the past in two years' time." --Bill | > `\ Gates, 2004-01-24 | > _o__) | > !!!!!!!!!!!!!!!!!!!!!!!!! I wonder if the main content of your post was the post or this footer?!?! From hayesstw at telkomsa.net Sat Apr 19 07:53:01 2014 From: hayesstw at telkomsa.net (Steve Hayes) Date: Sat, 19 Apr 2014 13:53:01 +0200 Subject: Why Python 3? References: Message-ID: On Fri, 18 Apr 2014 22:28:05 -0500, Anthony Papillion wrote: >Hello Everyone, > >So I've been working with Python for a while and I'm starting to take >on more and more serious projects with it. I've been reading a lot >about Python 2 vs Python 3 and the community kind of seems split on >which should be used. > >Some say 'Python 3 is the future, use it for everything now' and other >say 'Python 3 is the future but you can't do everything in it now so >use Python 2'. Yes, that made me more or less abandon my attempt to learn Python. I had Python 3 on my computer (came on one of those freebie discs you get with magazines, I think) and my son had a book on it, so I thought with the program and the instructions I should be able to learn something. It took me a week, with some help from this forum, to get the Print statement to work. -- Steve Hayes from Tshwane, South Africa Web: http://www.khanya.org.za/stevesig.htm Blog: http://khanya.wordpress.com E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk From bgailer at gmail.com Sat Apr 19 08:33:44 2014 From: bgailer at gmail.com (bob gailer) Date: Sat, 19 Apr 2014 08:33:44 -0400 Subject: module and namespace In-Reply-To: <534E5DA2.7050205@frerich.eu> References: <534E5DA2.7050205@frerich.eu> Message-ID: <53526D28.908@gmail.com> On 4/16/2014 6:38 AM, Egon Frerich wrote: > If I use the interpreter I get: > > Python 3.3.5 (default, Apr 12 2014, 23:34:20) > [GCC 4.6.3] on linux > Type "help", "copyright", "credits" or "license" for more information. > import mptt > print(mptt) > > > > But if I import mptt in my program the print-statement gives > > > > What is the meaning? When does this happened? I can't reproduce that behavior. Running a script with just those 2 lines in gives me the same result as running in the interactive session. Please post the program. Otherwise we are shooting in the dark. Also note print is a function not a statement. Be sure to: - Place your answers following the relevant text. - Delete old text that is no longer relevant. - Ensure a copy of your reply goes to the list. From rosuav at gmail.com Sat Apr 19 08:46:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Apr 2014 22:46:51 +1000 Subject: Why Python 3? In-Reply-To: References: Message-ID: On Sat, Apr 19, 2014 at 9:53 PM, Steve Hayes wrote: >>Some say 'Python 3 is the future, use it for everything now' and other >>say 'Python 3 is the future but you can't do everything in it now so >>use Python 2'. > > Yes, that made me more or less abandon my attempt to learn Python. > > I had Python 3 on my computer (came on one of those freebie discs you get with > magazines, I think) and my son had a book on it, so I thought with the program > and the instructions I should be able to learn something. > > It took me a week, with some help from this forum, to get the Print statement > to work. If your book and your interpreter didn't match, then that's a problem, just as if you were working with different versions of any other software. (Can you imagine reading through a Microsoft Excel tutorial and trying to do the exercises in a different version of Excel?) The print statement wouldn't work because there isn't one; the print *function* will work quite happily, though. All you need is for someone to explain it to you as a function, and you'll be fine. ChrisA From ian at feete.org Sat Apr 19 08:58:54 2014 From: ian at feete.org (Ian Foote) Date: Sat, 19 Apr 2014 13:58:54 +0100 Subject: Why Python 3? In-Reply-To: <53520052.8030407@my.hennepintech.edu> References: <53520052.8030407@my.hennepintech.edu> Message-ID: <5352730E.8080101@feete.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 19/04/14 05:49, Andrew Berg wrote: > On 2014.04.18 22:28, Anthony Papillion wrote: >> What is the general feel of /this/ community? I'm about to start >> a large scale Python project. Should it be done in 2 or 3? What >> are the benefits, aside from the 'it's the future' argument? > Python 3 is not the future; it is the present. If you're developing > an application, just use Python 3.4 and don't look back unless you > absolutely positively *need* one of the big libraries that doesn't > fully support Python 3 yet. The smaller ones either support it or > have been replaced, and the few remaining (e.g., Twisted, Django) > are getting there. Django has been there since 1.5. My company has been using python3 in production since 1.6 was released. There have been a few other third party libraries we've wanted to use but can't, but we've been able to work around that. Regards, Ian F -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJTUnMOAAoJEODsV4MF7PWzhEsH/infLqjUcGh+vSTaMNEvjuRn /vqaxiok5/9opocoDtBbK707rpJz55V+NP1ajhso0llhLlQ1T7XyAK2QQthfvcTd FIyn7uw7ud5nofivXUkkO3g9FoHRASZnAc9mXZGGV7O1RKjA3YvEccOakJKpq/jC UYzBYLOfkUzLYV9yQPaE5Dxt/rRmO1NLNzdBMXXTBOy4s6hd+B+TSCCgAgGy05ZJ yNePgO98N2wq7W/iG4EAw409rxXYxR0cAHNSID7+m1omSTPls4PV+jyIfmoS+eBl 6nWkqjVw3yw2cF0gBs1k/sjxPZ/aXOjD1FxpIhBOvh+upNieFSP0AT2X5R3NRnw= =wW3W -----END PGP SIGNATURE----- From aberg010 at my.hennepintech.edu Sat Apr 19 09:10:40 2014 From: aberg010 at my.hennepintech.edu (Andrew Berg) Date: Sat, 19 Apr 2014 08:10:40 -0500 Subject: Why Python 3? In-Reply-To: <5352730E.8080101@feete.org> References: <53520052.8030407@my.hennepintech.edu> <5352730E.8080101@feete.org> Message-ID: <535275D0.7060701@my.hennepintech.edu> On 2014.04.19 07:58, Ian Foote wrote: > Django has been there since 1.5. My company has been using python3 in > production since 1.6 was released. There have been a few other third > party libraries we've wanted to use but can't, but we've been able to > work around that. I guess I'm a bit behind the times then. Last I checked, only certain parts of it were working on Python 3. Nice to hear that it fully supports Python 3 now. :) -- CPython 3.4.0 | Windows NT 6.2.9200 / FreeBSD 10.0 From esj at harvee.org Sat Apr 19 09:06:47 2014 From: esj at harvee.org (Eric S. Johansson) Date: Sat, 19 Apr 2014 09:06:47 -0400 Subject: converting old project to Python 3 was: Re: Why Python 3? In-Reply-To: References: Message-ID: <535274E7.20305@harvee.org> On 4/19/2014 12:04 AM, Ryan Hiebert wrote: > If you are starting a new project, I'd highly encourage you to use > Python 3. It is a stable, well supported, and beautiful language, and > gives you the full power of the innovation that is current in the > Python world. Python 2 is still well supported (for a while to come), > but you won't have the same access to new features and ideas that you > would on Python 3. > > The only reason that I'd still be on Python 2 is if I absolutely had > to use a library that for some reason is not yet working on Python 3. > Even then, I'd work hard to try and write it in Python 3 style Python > 2, because I'd want to be on Python 3 as soon as possible. The Python extensions to NaturallySpeaking are combination of C++ for a COM interface and Python for grammar management. http://qh.antenna.nl/unimacro/implementation_and_acceptance_of_natlink.pdf How hard is it to convert from C++ extensions for 2.x to 3.x? are there any tools to help with the process? Thanks for any insights. --- eric From roy at panix.com Sat Apr 19 09:26:53 2014 From: roy at panix.com (Roy Smith) Date: Sat, 19 Apr 2014 09:26:53 -0400 Subject: Why Python 3? References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: Chris Angelico wrote: > I strongly recommend going for Python 3 unless something actually > stops you from doing so. One of the problems is you don't know in advance if something is going to stop you. By committing to P3 now, you are eliminating from possible future use, all of those third-party modules which only support P2. And you don't know which of those you'll need until you sometime in the future. It's rare to find a modern, actively maintained module which doesn't either support P3 already, or at least has that on its roadmap, but there's a lot of old stuff out there which is still very useful. > If you absolutely must use Python 2, try to > aim for a minimum of 2.6 or 2.7 That I absolutely agree with. Unless I had some specific legacy use case I needed to continue to support, I wouldn't waste any time worrying about 2.5 support, and we're quickly reaching the point where the same can be said about 2.6. > and start your program with this line: > > from __future__ import print_function, unicode_literals, division That seems reasonable, but be prepared for possible unicode issues. There is code out there in third party modules which makes unicode-unfriendly assumptions about strings. For example: https://github.com/brandon-rhodes/pyephem/issues/35 I'm not saying don't use unicode_literals (we do), just we aware that you might have to explicitly cast things to str() once in a while. From rosuav at gmail.com Sat Apr 19 09:42:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Apr 2014 23:42:47 +1000 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On Sat, Apr 19, 2014 at 11:26 PM, Roy Smith wrote: > Chris Angelico wrote: > >> I strongly recommend going for Python 3 unless something actually >> stops you from doing so. > > One of the problems is you don't know in advance if something is going > to stop you. By committing to P3 now, you are eliminating from possible > future use, all of those third-party modules which only support P2. And > you don't know which of those you'll need until you sometime in the > future. Conversely, committing to Py2 now eliminates from possible future use all modules which support only Py3. Is there strong evidence that one of those groups is larger than the other? >> If you absolutely must use Python 2, try to >> aim for a minimum of 2.6 or 2.7 > > That I absolutely agree with. Unless I had some specific legacy use > case I needed to continue to support, I wouldn't waste any time worrying > about 2.5 support, and we're quickly reaching the point where the same > can be said about 2.6. Red Hat? :) Though that's likely to be the last bastion of ancient Python out there, soon. Debian Squeeze (oldstable) ships with 2.6, so if you aim for 2.6+, you should catch all the distros that derive from Debian (the current Debian stable, Wheezy, ships with 2.7). But Red Hat will be supporting older Pythons for a good while. >> and start your program with this line: >> >> from __future__ import print_function, unicode_literals, division > > That seems reasonable, but be prepared for possible unicode issues. > There is code out there in third party modules which makes > unicode-unfriendly assumptions about strings. Right. It's not the magic line that fixes everything; if it were, Python 3 wouldn't be a big deal at all. Go Py3 if you can, but if you can't, at least make your double-quoted strings Unicode strings, and then you have a chance to find problems. ChrisA From gwhite at ti.com Sat Apr 19 10:26:01 2014 From: gwhite at ti.com (gwhite) Date: Sat, 19 Apr 2014 07:26:01 -0700 (PDT) Subject: TeX $\times$ symbol not working in matplotlib? In-Reply-To: <9OadnY52jYobbMzOnZ2dnUVZ_qKdnZ2d@giganews.com> References: <622d3b45-e5e6-4c3d-b65c-485128f15b32@googlegroups.com> <4877d951-8d91-49e6-8a05-07e0262c7a4d@googlegroups.com> <9OadnY52jYobbMzOnZ2dnUVZ_qKdnZ2d@giganews.com> Message-ID: <75462c07-8498-4102-8618-3f12617478fb@googlegroups.com> On Friday, April 18, 2014 8:46:13 PM UTC-7, Larry Hudson wrote: > On 04/18/2014 04:14 PM, gwhite wrote: > > > [snip] > > I'm not sure when a backslash continuation might be needed, or if that requirement has been designed out of Python. > > ['they' meaning trailing backslashes] > > No, 'they' are still definitely in Python, but can usually be avoided. > > As already mentioned, strings are automatically concatenated if they are separated by only > whitespace (spaces/tabs/newlines). But there is a difference between this concatenation and > using a trailing backslash. For example: > > print('this, that, ' > 'the other') > > gives -> 'this, that, the other' > > print('this, that, \ > the other') > > gives -> 'this, that, the other' > > The leading whitespace in the second example is significant, but is ignored in the first. > > The other places you can avoid the trailing backslash is within brackets, ie. (), [] or {}. > Here you can split at any 'natural' position, that is following a comma, dot or an operator. > > ['spam', > 'eggs', > 'bacon'] > > gives -> ['spam', 'eggs', 'bacon'] > > --------- > [2 + > 3, > 'spam'] > > gives -> [5, 'spam'] > > --------- > print('this' and > 'that' or > 'other') > > gives -> 'that' > > --------- > print('{}'. > format('spam')) > > gives -> 'spam' > > These examples are somewhat contrived, but they do show what I'm talking about. > > Of course, you can still use the trailing backslash method, but when you can avoid it it usually > looks cleaner. Besides simply using either method to split long lines, it is often used to line > things up, either for the appearance or for documentation. Here is a dictionary example of what > I mean (and the backslash method will NOT work here): > > d = {1 : 'one', # Describe this key/value pair > 2 : 'two', # Describe this one > 3 : 'three' # Etc. > } > > Play around in the interactive mode to check out how this splitting works. Thank you, Larry. Your concise examples are nicely illustrative of the essentials. I appreciate the explanation. Thanks again to everyone. If I had the time, I would become a Python addict. From rantingrickjohnson at gmail.com Sat Apr 19 10:41:21 2014 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 19 Apr 2014 07:41:21 -0700 (PDT) Subject: Why Python 3? In-Reply-To: References: Message-ID: <40981385-93be-4ea2-9db0-1c8783e11df0@googlegroups.com> On Friday, April 18, 2014 10:28:05 PM UTC-5, Anthony Papillion wrote: > Hello Everyone, > So I've been working with Python for a while and I'm starting to take > on more and more serious projects with it. I've been reading a lot > about Python 2 vs Python 3 and the community kind of seems split on > which should be used. > Some say 'Python 3 is the future, use it for everything now' and other > say 'Python 3 is the future but you can't do everything in it now so > use Python 2'. > What is the general feel of /this/ community? I'm about to start a > large scale Python project. Should it be done in 2 or 3? What are the > benefits, aside from the 'it's the future' argument? Python 3000 is the direct result of a hubris that even surpasses Hitler's boneheaded attempt to fight the war on two fronts. Yes, most of us agree that the changes are "positive evolution" HOWEVER, are these minor repairs REALLY worth polarizing a vibrant community and causing Python's propagation to stagnate? HELL NO! Who would want to choose Python for a scripting language for their project when EVEN the community cannot agree on which version is best to use? But even *IF* every respected member was a total "high-knee smooching tool" of GvR parroting off that "Python 3000 is the best!", we cannot ignore the functionality concerns that will result from choosing between 2x or 3x. NOBODY IS ACTIVELY CHOOSING PYTHON ANYMORE FOLKS! Python is destined to destroy itself internally JUST like the American society is currently destroying itself, and what a travesty, since Python was the shining light of what a program should be. THE REVOLUTION WILL NOT BE TELEVISED! Python is set to become extinct because GvR bought his time machine AFTER infecting the code base with a print statement -- thanks Guido, thanks for everything! Maybe next time you should consider buying bean stalk beans instead! From egon at frerich.eu Sat Apr 19 10:49:51 2014 From: egon at frerich.eu (Egon Frerich) Date: Sat, 19 Apr 2014 16:49:51 +0200 Subject: module and namespace In-Reply-To: References: Message-ID: <53528D0F.3020706@frerich.eu> Am 18.04.2014 13:48, schrieb Peter Otten: > Egon Frerich wrote: > > > Basically Python 3 allows for packages to omit the __init__.py > > $ mkdir aaa > $ python3 -c'import aaa; print(aaa)' > > $ touch aaa/__init__.py > $ python3 -c'import aaa; print(aaa)' > > > Namespace packages have advantages when you want to merge submodules from > multiple places into one package. See > for the details. > > Your actual problem is probably that the parent directory for the mptt > package is not in your sys.path, The init-file in the parent directory was copied and had got the wrong ownership. Thanks Peter Egon -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2385 bytes Desc: S/MIME Cryptographic Signature URL: From egon at frerich.eu Sat Apr 19 10:55:54 2014 From: egon at frerich.eu (Egon Frerich) Date: Sat, 19 Apr 2014 16:55:54 +0200 Subject: module and namespace In-Reply-To: <53526D28.908@gmail.com> References: <534E5DA2.7050205@frerich.eu> <53526D28.908@gmail.com> Message-ID: <53528E7A.9090605@frerich.eu> Am 19.04.2014 14:33, schrieb bob gailer: > On 4/16/2014 6:38 AM, Egon Frerich wrote: >> If I use the interpreter I get: >> >> Python 3.3.5 (default, Apr 12 2014, 23:34:20) >> [GCC 4.6.3] on linux >> Type "help", "copyright", "credits" or "license" for more information. >> import mptt >> print(mptt) >> >> >> >> But if I import mptt in my program the print-statement gives >> >> >> >> What is the meaning? When does this happened? > I can't reproduce that behavior. Running a script with just those 2 > lines in gives me the same result as running in the interactive session. > > Please post the program. Otherwise we are shooting in the dark. > > Also note print is a function not a statement. > > Be sure to: > - Place your answers following the relevant text. > - Delete old text that is no longer relevant. > - Ensure a copy of your reply goes to the list. > Bob, Peter Otten gave the hint. The __init__.py in the parent dictionary have got the wrong ownership so it was not accessible. Egon -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2385 bytes Desc: S/MIME Cryptographic Signature URL: From rustompmody at gmail.com Sat Apr 19 11:59:30 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 19 Apr 2014 08:59:30 -0700 (PDT) Subject: Why Python 3? In-Reply-To: References: Message-ID: <0dcc2544-7328-4db8-8389-d4fef8b9fac6@googlegroups.com> On Saturday, April 19, 2014 5:23:01 PM UTC+5:30, Steve Hayes wrote: > It took me a week, with some help from this forum, to get the Print statement > to work. How long does it take one to learn to drive a car? To play the piano? To become a brain surgeon? No I am not exactly in the "gung-ho over python 3" camp However if you dont start out learning programming with an estimate of work somewhere between learning to: - drive-a-car - play-the-piano you are setting yourself up for failure. But its equally unreasonable to expect to learn programming more easy than to drive a car. From breamoreboy at yahoo.co.uk Sat Apr 19 12:15:14 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 19 Apr 2014 17:15:14 +0100 Subject: converting old project to Python 3 was: Re: Why Python 3? In-Reply-To: <535274E7.20305@harvee.org> References: <535274E7.20305@harvee.org> Message-ID: On 19/04/2014 14:06, Eric S. Johansson wrote: > > On 4/19/2014 12:04 AM, Ryan Hiebert wrote: >> If you are starting a new project, I'd highly encourage you to use >> Python 3. It is a stable, well supported, and beautiful language, and >> gives you the full power of the innovation that is current in the >> Python world. Python 2 is still well supported (for a while to come), >> but you won't have the same access to new features and ideas that you >> would on Python 3. >> >> The only reason that I'd still be on Python 2 is if I absolutely had >> to use a library that for some reason is not yet working on Python 3. >> Even then, I'd work hard to try and write it in Python 3 style Python >> 2, because I'd want to be on Python 3 as soon as possible. > > The Python extensions to NaturallySpeaking are combination of C++ for a > COM interface and Python for grammar management. > http://qh.antenna.nl/unimacro/implementation_and_acceptance_of_natlink.pdf > > How hard is it to convert from C++ extensions for 2.x to 3.x? are there > any tools to help with the process? > > Thanks for any insights. > > --- eric > https://docs.python.org/3/howto/cporting.html -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From tjreedy at udel.edu Sat Apr 19 13:23:33 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 19 Apr 2014 13:23:33 -0400 Subject: Why Python 3? In-Reply-To: <7x8ur1esa5.fsf@ruckus.brouhaha.com> References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On 4/19/2014 2:40 AM, Paul Rubin wrote: > That said, I don't know anyone who actually uses Python 3. I have no idea who you know ;-) LibreOffice bundles 3.3. So anyone who does Python scripting in LibreOffice is using Python 3. Actually, I believe LO uses Python internally for some of its scripting. If so, everyone using LO is indirectly using 3.3. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Sat Apr 19 13:31:33 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 19 Apr 2014 18:31:33 +0100 Subject: Why Python 3? In-Reply-To: <7x8ur1esa5.fsf@ruckus.brouhaha.com> References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On 19/04/2014 07:40, Paul Rubin wrote: > > That said, I don't know anyone who actually uses Python 3. > You do now :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Sat Apr 19 13:53:22 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 20 Apr 2014 03:53:22 +1000 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Apr 20, 2014 at 3:23 AM, Terry Reedy wrote: > LibreOffice bundles 3.3. So anyone who does Python scripting in LibreOffice > is using Python 3. This much I agree with... > Actually, I believe LO uses Python internally for some of > its scripting. If so, everyone using LO is indirectly using 3.3. ... but this is kinda pushing it, I think. You're not *using* it any more than you're using Python whenever you post to Savoynet [1] - after all, Savoynet is a Mailman list, and Mailman runs on Python. But all those theatre people don't become Python users because of that. I'd have to say that "using Python 3" means writing code that runs in Python 3. So the LO people would, by your statement, be using Py3.3, as would anyone who actually writes LO scripts; but someone who just fires up LO, edits a document in the WYSIWYG editor, and goes about his business, isn't really using Python. Though the broader definition does have its uses. It's fun to explain to someone how that little device that shows him a map and where he is on it is depending on both special and general relativity. (GPS signals are strongly based on time, and the satellites are moving relative to the observer, and gravity is weaker up there.) But you're not really making use of the science yourself, you're depending on someone else having made use of it - same as you can hop on an airliner without understanding the physics of flight, much less the effects of birdstrike on jet engines. You're just glad that someone, somewhere, has worked all that out :) ChrisA [1] http://savoynet.oakapplepress.com/ From fomcl at yahoo.com Sat Apr 19 13:57:53 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Sat, 19 Apr 2014 10:57:53 -0700 (PDT) Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: <1397930273.12010.YahooMailNeo@web163803.mail.gq1.yahoo.com> ----- Original Message ----- > From: Chris Angelico > To: > Cc: "python-list at python.org" > Sent: Saturday, April 19, 2014 3:42 PM > Subject: Re: Why Python 3? > Right. It's not the magic line that fixes everything; if it were, > Python 3 wouldn't be a big deal at all. Go Py3 if you can, but if you > can't, at least make your double-quoted strings Unicode strings, and > then you have a chance to find problems. Totally agree. It's not that hard at all. I consider it true craftmanship that Guido had the guts break backward compatibility and clean up some mistakes. Compare this with CRAN R, where so much illogical S-plus stuff is present (word count for "historical anomaly": 1000+ ;-). Am I the only one who always thinks of Rogers' Diffusion of Innovations curve with these Python2/3 debates? http://en.wikipedia.org/wiki/File:Diffusion_of_ideas.svg. source: http://en.wikipedia.org/wiki/Diffusion_of_innovations From ian.g.kelly at gmail.com Sat Apr 19 15:58:24 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 19 Apr 2014 13:58:24 -0600 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On Sat, Apr 19, 2014 at 3:37 AM, Chris Angelico wrote: > On Sat, Apr 19, 2014 at 7:25 PM, Ian Kelly wrote: >> The change from / denoting "classic >> division" to "true division" really only affects the case where both >> operands are integers, so far as I'm aware. If you want to divide two >> integers and get a decimal result, then convert one or both of them to >> decimals first; you would have needed to do the same with classic >> division. > > If float were a perfect superset of int, and the only logical superset > when you want non-integers, then it'd be fine. Decimal is also not a perfect superset of int (although I believe it is a superset of the intersection of int and float). Even if it were, I'm not sure it would be appropriate to bless Decimal in this way either, because they have no place in Python's number type hierarchy: >>> from decimal import Decimal >>> from numbers import Real >>> isinstance(Decimal('1.23'), Real) False > But if you're mixing > int and Decimal, you have to explicitly convert, whereas if you're > mixing int and float, you don't. Why is it required to be explicit > with Decimal but not float? Of all the possible alternate types, why > float? Only because... > >> As for "why float" specifically, the division __future__ import has >> been around since 2.2, longer than either decimals or fractions. > > ... it already existed. There's no particular reason to up-cast to > float, specifically, and it can cause problems with large integers - > either by losing accuracy, or by outright overflowing. The authors of PEP 238 expressed their hope that when a rational type (i.e. Fraction) was implemented, it would become the result type for true division on two integers. I don't know why that never came to pass; perhaps performance considerations won out. > In Python 3, you have to say "Oh but I want my integer division to > result in an integer": > > x * 10 // 5 == x * 2 Technically this says "I want the result of floor division", not "I want the result as an integer". If you apply the floor division operator to a non-int type, you'll get a non-int result. It just so happens that the result of floor division of two integers can be given as an integer, whereas the result of true division cannot. Considering that Fraction and Decimal did not exist yet, what type do you think the PEP 238 implementers should have chosen for the result of dividing two ints? If float is not acceptable, and int is not acceptable (which was the whole point of the PEP), then the only alternative I can see would have been to raise a TypeError and force the user to upcast explicitly. In that case, dividing arbitrary ints using floating-point math would not be possible for those ints that are outside the range of floats; you would get OverflowError on the upcast operation, regardless of whether the result of division would be within the range of a float. > Yes, I can see that it's nice for simple interactive use. More importantly, it's useful for implementers of generic mathematical routines. If you're passed arbitrary inputs, you don't have to check the types of the values you were given and then branch if both of the values you were about to divide happened to be ints just because the division operator arbitrarily does something different on ints. From rosuav at gmail.com Sat Apr 19 16:31:07 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 20 Apr 2014 06:31:07 +1000 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Apr 20, 2014 at 5:58 AM, Ian Kelly wrote: > Considering that Fraction and Decimal did not exist yet, what type do > you think the PEP 238 implementers should have chosen for the result > of dividing two ints? If float is not acceptable, and int is not > acceptable (which was the whole point of the PEP), then the only > alternative I can see would have been to raise a TypeError and force > the user to upcast explicitly. In that case, dividing arbitrary ints > using floating-point math would not be possible for those ints that > are outside the range of floats; you would get OverflowError on the > upcast operation, regardless of whether the result of division would > be within the range of a float. > >> Yes, I can see that it's nice for simple interactive use. > > More importantly, it's useful for implementers of generic mathematical > routines. If you're passed arbitrary inputs, you don't have to check > the types of the values you were given and then branch if both of the > values you were about to divide happened to be ints just because the > division operator arbitrarily does something different on ints. Or you just cast one of them to float. That way you're sure you're working with floats. The main trouble is that float is not a perfect superset of int. If it were, then it really would be upcasting, same as turning a float into a complex is; there's no downside, other than performance. If I'd been in charge, I would have simply let int/int continue to return an int, as that's the one thing that is guaranteed not to behave differently on different input values. Python 3 fixed Unicode handling by ensuring that mixing text and bytes would cause problems straight away, rather than waiting until you get a character with a codepoint higher than U+00FF; 3.3 went further and made sure you wouldn't get problems by going past U+FFFF even on Windows. I think we all agree (well, all bar the trolls) that that was a good thing. So why do we have this sort of thing go weird? def always_true(x): assert type(x) is int return x*10/2 == x*5 In Python 2, I believe that will indeed be always true, for any integer x. (Yeah, there's a naughty type check in there. I'm talking about integers, mmkay?) In Python 3, it might not be. >>> always_true(2**53) True >>> always_true(2**53+1) False (32-bit Windows, because I'm on the laptop. Other Pythons, other CPUs, etc, may have different points where that happens, but the same will happen.) So either you keep a very close eye on everything to make sure you don't have floats infecting your calculations, or you ignore the problem and then start seeing odd stuff happen with specific numbers. I'd rather have to explicitly request floating-point division; that way, you get issues a lot sooner and more simply. "Why is 34/10 equal to 3?" is a lot easier to explain than "Why does my program not work when I give it numbers with lots of data encoded in them, when it works fine with sequential numbers from zero?". (Imagine if you work with invoice numbers, for instance, and your code is fine; but if you encode the date into the first eight digits, then put the store number in the next three, register number in the next three, and then the last three are sequential. Should work the same, right?) Anyway, way too late to change now. That ship sailed in 2.2 or thereabouts. ChrisA From ian.g.kelly at gmail.com Sat Apr 19 16:38:35 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 19 Apr 2014 14:38:35 -0600 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On Sat, Apr 19, 2014 at 2:31 PM, Chris Angelico wrote: > On Sun, Apr 20, 2014 at 5:58 AM, Ian Kelly wrote: >> Considering that Fraction and Decimal did not exist yet, what type do >> you think the PEP 238 implementers should have chosen for the result >> of dividing two ints? If float is not acceptable, and int is not >> acceptable (which was the whole point of the PEP), then the only >> alternative I can see would have been to raise a TypeError and force >> the user to upcast explicitly. In that case, dividing arbitrary ints >> using floating-point math would not be possible for those ints that >> are outside the range of floats; you would get OverflowError on the >> upcast operation, regardless of whether the result of division would >> be within the range of a float. >> >>> Yes, I can see that it's nice for simple interactive use. >> >> More importantly, it's useful for implementers of generic mathematical >> routines. If you're passed arbitrary inputs, you don't have to check >> the types of the values you were given and then branch if both of the >> values you were about to divide happened to be ints just because the >> division operator arbitrarily does something different on ints. > > Or you just cast one of them to float. That way you're sure you're > working with floats. Which is inappropriate if the type passed in was a Decimal or a complex. From rosuav at gmail.com Sat Apr 19 16:53:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 20 Apr 2014 06:53:00 +1000 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Apr 20, 2014 at 6:38 AM, Ian Kelly wrote: >> Or you just cast one of them to float. That way you're sure you're >> working with floats. > > Which is inappropriate if the type passed in was a Decimal or a complex. In that case, you already have a special case in your code, so whether that special case is handled by the language or by your code makes little difference. Is your function so generic that it has to be able to handle float, Decimal, or complex, and not care about the difference, and yet has to ensure that int divided by int doesn't yield int? Then say so; put in that special check. Personally, I've yet to meet any non-toy example of a function that needs that exact handling; most code doesn't ever think about complex numbers, and a lot of things look for one specific type: >>> "asdf"*3.0 Traceback (most recent call last): File "", line 1, in "asdf"*3.0 TypeError: can't multiply sequence by non-int of type 'float' Maybe it's not your code that should be caring about what happens when you divide two integers, but the calling code. If you're asking for the average of a list of numbers, and they're all integers, and the avg() function truncates to integer, then the solution is to use sum() and explicitly cast to floating point before dividing. Why should the language handle that? It's no different from trying to sum a bunch of different numeric types: >>> sum([1.0,decimal.Decimal("1")]) Traceback (most recent call last): File "", line 1, in sum([1.0,decimal.Decimal("1")]) TypeError: unsupported operand type(s) for +: 'float' and 'decimal.Decimal' The language doesn't specify a means of resolving the conflict between float and Decimal, but for some reason the division of two integers is blessed with a language feature. Again, it would make perfect sense if float were a perfect superset of int, so that you could simply declare that 1.0 and 1 behave absolutely identically in all arithmetic (they already hash and compare equally), but that's not the case, so I don't see that division should try to pretend they are. ChrisA From greg.ewing at canterbury.ac.nz Sat Apr 19 21:06:47 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 20 Apr 2014 13:06:47 +1200 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: Chris Angelico wrote: > I'd rather have to explicitly request floating-point division; When you write / in Python 3, you *are* explicitly requesting floating-point division. Similarly, when you write // you're explicitly requesting integer division. I don't see the problem. You write whatever you mean and it does what you tell it to do. > So either you keep a very close eye on everything to make sure you > don't have floats infecting your calculations, If you have something that works exclusively on ints and someone passes you a float, and you don't check for that, you'll have problems anyway even if no division is involved at all. There's no way that Python 3 division can *introduce* a float into an integer calculation unless you write / somewhere where you really meant //. But that's the same kind of mistake as calling foo() when you meant to call bar(). You can't blame the language for that. > but if you > encode the date into the first eight digits, then put the store number > in the next three, register number in the next three, and then the > last three are sequential. Should work the same, right?) It'll work fine as long as you use // when extracting the parts. If you use / then you're *explicitly* saying to do the calculation in floating point, which would not be a sane thing to do. -- Greg From rosuav at gmail.com Sat Apr 19 21:28:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 20 Apr 2014 11:28:28 +1000 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Apr 20, 2014 at 11:06 AM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> I'd rather have to explicitly request floating-point division; > > > When you write / in Python 3, you *are* explicitly requesting > floating-point division. > > Similarly, when you write // you're explicitly requesting > integer division. > > I don't see the problem. You write whatever you mean and it > does what you tell it to do. Truncating vs true is not the same as int vs float. If you mean to explicitly request float division, you call float() on one or both arguments. You're being explicit about something different. ChrisA From greg.ewing at canterbury.ac.nz Sat Apr 19 21:35:57 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 20 Apr 2014 13:35:57 +1200 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: Chris Angelico wrote: > Is your function so generic that it has to be able > to handle float, Decimal, or complex, and not care about the > difference, and yet has to ensure that int divided by int doesn't > yield int? It doesn't have to be that generic to cause pain. Even if you're only dealing with floats, the old way meant you had to stick float() calls all over the place in order to be sure your divisions do what you want. Not only does that clutter up and obscure the code, it's needlessy inefficient, since *most* of the time they don't do anything. There's also the annoyance that there's more than one obvious way to do it. Do you write float(x)/y or x/float(y)? Or do you go for a more symmetrical look and write float(x)/float(y), even though it's redundant? The new way makes *all* of that go away. The only downside is that you need to keep your wits about you and select the appropriate operator whenever you write a division. But you had to think about that *anyway* under the old system, or risk having your divisions silently do the wrong thing under some circumstances -- and the remedy for that was very clunky and inefficient. I'm thoroughly convinced that the *old* way was the mistake, and changing it was the right thing to do. > The language doesn't specify a means of resolving the conflict between > float and Decimal, but for some reason the division of two integers is > blessed with a language feature. No, it's not. What the language does is recognise that there are two kinds of division frequently used, and that the vast majority of the time you know *when you write the code* which one you intend. To support this, it provides two operators. It's still up to the types concerned to implement those operators in a useful way. The built-in int and float types cooperate to make // mean integer division and / mean float division, because that's the most convenient meanings for them on those types. Other types are free to do what makes the most sense for them. -- Greg From torriem at gmail.com Sat Apr 19 22:34:05 2014 From: torriem at gmail.com (Michael Torrie) Date: Sat, 19 Apr 2014 20:34:05 -0600 Subject: Why Python 3? In-Reply-To: <53520052.8030407@my.hennepintech.edu> References: <53520052.8030407@my.hennepintech.edu> Message-ID: <5353321D.40903@gmail.com> On 04/18/2014 10:49 PM, Andrew Berg wrote: > Python 3 is not the future; it is the present. If you're developing > an application, just use Python 3.4 and don't look back unless you > absolutely positively *need* one of the big libraries that doesn't > fully support Python 3 yet. Depends on what OS you want to be running on. I don't know of any currently-supported Enterprise distributions (long-term support) that ship with Python 3.4. Few ship Python 3.3 yet. For example, RHEL 6 is Red Hat's most current enterprise distribution and it does not yet even ship Python 2.7, to say nothing of Python 3. RHEL 7 has python 2.7 as the default system dependency, and currently does not yet have any python3 packages in the official main repo, though I imagine it will probably show up, as it is in Fedora 19, which RHEL7 is based on. Of course you can easily install Python3 on most any distro, either from third-party repos or source, neither of which would be allowed in the enterprise I last worked in, unless the repo was trusted and vetted. One could ship a compiled python 3.[34] interpreter with one's package I suppose. With Windows it's quite different. There's no system python to start with so you can either bundle python with your app, or require one of the official python 3.[34] packages as a prerequisite. It's the conservative nature of LTS distributions that slows the adoption of Python 3. Especially in server space. From no.email at nospam.invalid Sat Apr 19 23:25:32 2014 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 19 Apr 2014 20:25:32 -0700 Subject: Why Python 3? References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: <7xha5od6mr.fsf@ruckus.brouhaha.com> Terry Reedy writes: > LibreOffice bundles 3.3. So anyone who does Python scripting in > LibreOffice is using Python 3. Actually, I believe LO uses Python > internally for some of its scripting. If so, everyone using LO is > indirectly using 3.3. I didn't even know LO supported Python scripting, but I wouldn't count such indirect use anyway. I meant I don't know any Python programmers (at least in person) who use Python 3 for their daily coding. I think this is mostly because they (and I) use whatever is in the OS distro, and that is generally still 2.6 or 2.7. From tjreedy at udel.edu Sun Apr 20 00:17:17 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 20 Apr 2014 00:17:17 -0400 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On 4/19/2014 9:06 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> I'd rather have to explicitly request floating-point division; > > When you write / in Python 3, you *are* explicitly requesting > floating-point division. > > Similarly, when you write // you're explicitly requesting > integer division. One is requesting 'floor division' >>> 3.0//2.0 1.0 To me, calling that integer division is a bit misleading in that one might expect the result, at least, to be an int rather than a float. (Yes, it is an integer-valued float.) -- Terry Jan Reedy From ian at feete.org Sun Apr 20 04:47:02 2014 From: ian at feete.org (Ian Foote) Date: Sun, 20 Apr 2014 09:47:02 +0100 Subject: Why Python 3? In-Reply-To: <5353321D.40903@gmail.com> References: <53520052.8030407@my.hennepintech.edu> <5353321D.40903@gmail.com> Message-ID: <53538986.7050000@feete.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 20/04/14 03:34, Michael Torrie wrote: > On 04/18/2014 10:49 PM, Andrew Berg wrote: >> Python 3 is not the future; it is the present. If you're >> developing an application, just use Python 3.4 and don't look >> back unless you absolutely positively *need* one of the big >> libraries that doesn't fully support Python 3 yet. > > Depends on what OS you want to be running on. I don't know of any > currently-supported Enterprise distributions (long-term support) > that ship with Python 3.4. I don't know if you'd count it as an "Enterprise" distribution, but ubuntu 14.04 (LTS) ships with python 3.4 (and 2.7). Regards, Ian F -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJTU4mGAAoJEODsV4MF7PWzR2sIAL4P0DhzWr5b7T4tfxSFWvlM A31VEwh1MiL8qQKi+ukzm1lumnqF0VZG5a8VYOrq9F/AgbPmkmdaJ3vwlNSZYYrq X6E0zdszTbnK6ec3zNHsqhWd7id/vzyJG5OQkDgg7K9dHY2r2lYfneIUhKvGy01q 6kaqWWXs77UIeWam2amjhtAMsUZtte/828CoIugHBdZgUhmbbNA8PK6/38w6BSgw 3NzT2kCz0298jqPUUZw++pap0Bb/9tQ+Ceps6KKeCE3QJ12Qn7Viv7TnrpQQnkeT Wt56VWoS9VGodB8h7ozHFGeA11VePN9YdLeM+CuUqNsOxXhuean7ysMiazMU30s= =mv5B -----END PGP SIGNATURE----- From ben+python at benfinney.id.au Sun Apr 20 05:15:10 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 20 Apr 2014 19:15:10 +1000 Subject: Why Python 3? References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <7xha5od6mr.fsf@ruckus.brouhaha.com> Message-ID: <851twswee9.fsf@benfinney.id.au> Paul Rubin writes: > [people I know] use whatever is in the OS distro, and that is > generally still 2.6 or 2.7. When the OS contains *both* Python 2 and Python 3, does Python 3 count as ?in the OS?? Or will you only count Python 3 as ?in the OS? when Python 2 is not present at all in the OS? I think your description isn't accurate. Python 3 is very likely in the OS also, so you are using some other criterion to decide to use the legacy Python 2 instead of the current Python 3 also supplied with the OS. -- \ Moriarty: ?Forty thousand million billion dollars? That money | `\ must be worth a fortune!? ?The Goon Show, _The Sale of | _o__) Manhattan_ | Ben Finney From steve+comp.lang.python at pearwood.info Sun Apr 20 05:43:46 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Apr 2014 09:43:46 GMT Subject: Why Python 3? References: Message-ID: <535396d1$0$29993$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Apr 2014 21:50:09 -0700, Ethan Furman wrote: > Use Python 3 if you can. The best reason not to is if you have some > critical library that you absolutely need and it's not yet available on > 3. That's good advice, but it isn't just applicable to Python 3, it applies to *any* critical library that does not support recent versions of Python. Suppose you have a library that only supports Python 2.2, 2.3 and 2.4, and you cannot do without that library or reinvent it yourself. Then you would surely use Python 2.4. That shouldn't be seen as a rejection of all the versions from 2.5 onwards, but a painful and necessary decision due to the requirement to use that library. In practice, most libraries that don't support 2.5 and better are more or less abandoned. But you might still choose to use an abandoned library because it works and you don't need to worry about security updates. So really the advice comes down to: - if you can, use the latest version of Python, which is 3.4; - if you must, use the version of Python provided by your operating system, which could be anything from Python 2.3 to 3.3; - if you have no choice except to use a library that only supports version X, then use version X, no matter what X happens to be. None of this should be controversial. It should be common sense. (There are, of course, a few difficult questions relating to what counts as "must". You may weigh up the cost of doing without that annoyingly old library versus the benefit of using a more recent Python version, and decide that maybe you can do without it. Or not.) -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Sun Apr 20 05:59:00 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Apr 2014 09:59:00 GMT Subject: Why Python 3? References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: <53539a64$0$29993$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Apr 2014 23:40:18 -0700, Paul Rubin wrote: > It's just that the improvement > from 2 to 3 is rather small, and 2 works perfectly well and people are > used to it, so they keep using it. Spoken like a true ASCII user :-) The "killer feature" of Python 3 is improved handling of Unicode, which now brings Python 3 firmly into the (very small) group of programming languages with first-class support for more than 128 different characters by default. Unfortunately, that made handling byte strings a bit more painful, but 3.4 improves that, and 3.5 ought to fix it. People doing a lot of mixed Unicode text + bytes handling should pay attention to what goes on over the next 18 months, because the Python core developers are looking to fix the text/byte pain points. Your feedback is wanted. > There are nice tools that help port > your codebase from 2 to 3 with fairly little effort. But, you can also > keep your codebase on 2 with zero effort. So people choose zero over > fairly little. True. But for anyone wanting long term language support, a little bit of effort today will save them a lot of effort in six years time. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Sun Apr 20 06:07:07 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Apr 2014 10:07:07 GMT Subject: Why Python 3? References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: <53539c4b$0$29993$c3e8da3$5496439d@news.astraweb.com> On Sat, 19 Apr 2014 09:26:53 -0400, Roy Smith wrote: > One of the problems is you don't know in advance if something is going > to stop you. By committing to P3 now, you are eliminating from possible > future use, all of those third-party modules which only support P2. And > you don't know which of those you'll need until you sometime in the > future. I believe this is more of an issue in theory than in practice. My on-line web portal app could potentially use any of a thousand different Python 2.x only libraries, but in practice I'm probably only going to use half a dozen libraries, or fewer, and know very early in the design phase what I need (web templating software, yes, library to control radio telescopes, probably not). And I'm likely to eliminate from contention most libraries that seem unsupported or abandoned, and if they only support Python 2 five years since the introduction of Python 3, they better have a good reason for it. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Sun Apr 20 07:02:49 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Apr 2014 11:02:49 GMT Subject: Integer and float division [was Re: Why Python 3?] References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: <5353a958$0$29993$c3e8da3$5496439d@news.astraweb.com> On Sat, 19 Apr 2014 19:37:31 +1000, Chris Angelico wrote: > On Sat, Apr 19, 2014 at 7:25 PM, Ian Kelly > wrote: >> The change from / denoting "classic >> division" to "true division" really only affects the case where both >> operands are integers, so far as I'm aware. If you want to divide two >> integers and get a decimal result, then convert one or both of them to >> decimals first; you would have needed to do the same with classic >> division. > > If float were a perfect superset of int, and the only logical superset > when you want non-integers, then it'd be fine. But if you're mixing int > and Decimal, you have to explicitly convert, I don't think so. Operations on mixed int/Decimal arguments return Decimal. There's no conversion needed except to get the original Decimal number in the first place. (Decimal is not a built-in and there's no literal syntax for them.) py> from decimal import Decimal as D py> x, y = 1, D(2) py> x/y Decimal('0.5') py> x//y Decimal('0') > whereas if you're mixing > int and float, you don't. Why is it required to be explicit with Decimal > but not float? Of all the possible alternate types, why float? Only > because... Because float is built-in and Decimal is not. Because Decimal wasn't introduced until Python 2.4 while the change to the division operator was first begun back in Python 2.2. http://python.org/dev/peps/pep-0238/ Guido writes about why his decision to emulate C's division operator was a mistake: http://python-history.blogspot.com.au/2009/03/problem-with-integer-division.html >> As for "why float" specifically, the division __future__ import has >> been around since 2.2, longer than either decimals or fractions. > > ... it already existed. There's no particular reason to up-cast to > float, specifically, and it can cause problems with large integers - > either by losing accuracy, or by outright overflowing. If you reject C integer division, you have to do *something* with 1/2. Ideally you'll get a number numerically equal to one half. It can't be a Decimal, or a Fraction, because back in 2001 there were no Decimal or Fraction types, and even now in 2014 they aren't built-ins. (Besides, both of those choices have other disadvantages. Fractions are potentially slow and painful, with excessive accuracy. See Guido's comments in his blog post above. And Decimal uses base 10 floating point, which is less suitable for serious numeric work than base 2 floats.) > Suppose you take an integer, multiply it by 10, and divide it by 5. In > theory, that's the same as multiplying by 2, right? That's a bit of a contrived example. But go on. > Mathematically it > is. In C it might not be, because the multiplication might overflow; but > Python, like a number of other modern languages, has an integer type > that won't overflow. Only since, um, version 2.2 I think. I don't have 2.1 easily available, but here's 1.5: [steve at ando ~]$ python1.5 Python 1.5.2 (#1, Aug 27 2012, 09:09:18) [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> 2**31*10 Traceback (innermost last): File "", line 1, in ? OverflowError: integer pow() So don't forget the historical context of what you are discussing. > In Python 2, doing the obvious thing works: > > x * 10 / 5 == x * 2 Ignoring old versions of Python 2.x, correct. But that is a contrived example. Mathematically x/5*10 also equals 2*x, but not with C division semantics. This is with Python 2.7: >>> x = 7 >>> x/5*10, x*10/5, x*2 (10, 14, 14) Let's try it with true (calculator) division: >>> x/5*10, x*10/5, x*2 (14.0, 14.0, 14) With a bit of effort, I'm sure you can find values of x where they are not all equal, but that's because floats only have a finite precision. In general, true division is less surprising and causes fewer unexpected truncation errors. > In Python 3, you have to say "Oh but I want my integer division to > result in an integer": > > x * 10 // 5 == x * 2 No, // doesn't mean "divide and coerce to an integer", it is *truncating* division. The type being truncated may choose to return an int, but that's not compulsory: >>> from decimal import Decimal as D >>> x = D("23.5") >>> x/4, x//4 (Decimal('5.875'), Decimal('5')) > Yes, I can see that it's nice for simple interactive use. You type "1/2" > and you get back 0.5. But doesn't it just exchange one set of problems > ("dividing integers by integers rounds") It doesn't round, it truncates. [steve at ando ~]$ python2.7 -c "print round(799.0/100)" 8.0 [steve at ando ~]$ python2.7 -c "print 799/100" 7 > for another set ("floating > point arithmetic isn't real number arithmetic")? It's not like that avoiding that problem is an option. -- Steven D'Aprano http://import-that.dreamwidth.org/ From python.list at tim.thechases.com Sun Apr 20 08:06:06 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 20 Apr 2014 07:06:06 -0500 Subject: Why Python 3? In-Reply-To: <535396d1$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <535396d1$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140420070606.78e99270@bigbox.christie.dr> On 2014-04-20 09:43, Steven D'Aprano wrote: > So really the advice comes down to: > > - if you can, use the latest version of Python, which is 3.4; > > - if you must, use the version of Python provided by your operating > system, which could be anything from Python 2.3 to 3.3; > > - if you have no choice except to use a library that only supports > version X, then use version X, no matter what X happens to be. > > > None of this should be controversial. It should be common sense. This. Except for the fact that what should be common sense often ends up being controversial on c.l.p ;-) -tkc From zdoor at xs4all.nl Sun Apr 20 08:35:19 2014 From: zdoor at xs4all.nl (Alex van der Spek) Date: Sun, 20 Apr 2014 14:35:19 +0200 Subject: ctypes: returning an array from a subroutine Message-ID: <5353bf06$0$2830$e4fe514c@news2.news.xs4all.nl> I have a C code function like this: ++++++++++++++++++++++++++ int __declspec(dllexport) __stdcall bnd2prb(float *in, float *out, int init) {enum {OK, Error, Not_Valid}; ... return(OK): } ++++++++++++++++++++++++++ And in Python I am trying to call this C function: ++++++++++++++++++++++++++ import ctypes import struct import array _snns = ctypes.windll.LoadLibrary(r'C:\MSDEV\Projects\Cyctrac\Debug\Cyctrac.dll') _cosm = getattr(_snns, '_bnd2prb at 12') _cosm.argtypes = (ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float), ctypes.c_long) _cosm.restype = ctypes.c_float def snns(indata, outdat): """Calls the neural net, returns a vector of 4. """ global _cosm init = ctypes.c_long(0) ilen = len(indata) olen = len(outdat) itype = ctypes.c_float * ilen otype = ctypes.c_float * olen iok = _cosm(itype(*indata), ctypes.pointer(otype(*outdat)), init) if not iok: return True else: return False indata = [0.5 for x in range(31)] outdat = [0.0 for x in range(4)] indata[1]=3.14 ok = snns(indata, outdat) if ok: print indata print outdat +++++++++++++++++++++++++++++++ This executes but leaves the outdat array unchanged. Obviously I haven't understood ctypes well enough. Returning arrays from FORTRAN I routinely do through a string_buffer. That works very well but did not work here at all. Any and all help welcome. Alex van der Spek From jpiitula at ling.helsinki.fi Sun Apr 20 08:38:03 2014 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 20 Apr 2014 15:38:03 +0300 Subject: Integer and float division [was Re: Why Python 3?] References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <5353a958$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > It doesn't round, it truncates. > > [steve at ando ~]$ python2.7 -c "print round(799.0/100)" > 8.0 > [steve at ando ~]$ python2.7 -c "print 799/100" > 7 Seems it floors rather than truncates: $ python2.7 -c "from math import trunc;print trunc(799./-100)" -7 $ python2.7 -c "from math import floor;print floor(799./-100)" -8.0 $ python2.7 -c "print 799/-100" -8 $ python3.2 -c "print(799//-100)" -8 From torriem at gmail.com Sun Apr 20 09:46:14 2014 From: torriem at gmail.com (Michael Torrie) Date: Sun, 20 Apr 2014 07:46:14 -0600 Subject: Why Python 3? In-Reply-To: <53538986.7050000@feete.org> References: <53520052.8030407@my.hennepintech.edu> <5353321D.40903@gmail.com> <53538986.7050000@feete.org> Message-ID: <5353CFA6.3060901@gmail.com> On 04/20/2014 02:47 AM, Ian Foote wrote: >> Depends on what OS you want to be running on. I don't know of any >> currently-supported Enterprise distributions (long-term support) >> that ship with Python 3.4. > > I don't know if you'd count it as an "Enterprise" distribution, but > ubuntu 14.04 (LTS) ships with python 3.4 (and 2.7). And I hope RHEL 7 will also ship Python 3.3 or 3.4 when it's finished. Of course if it does, it will be stuck with that version for the next 5-10 years. But that's the nature of software in this space. I say this as I work on a server that's running RHEL 5 still. :) From steve+comp.lang.python at pearwood.info Sun Apr 20 11:09:36 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Apr 2014 15:09:36 GMT Subject: Integer and float division [was Re: Why Python 3?] References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <5353a958$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5353e32f$0$29993$c3e8da3$5496439d@news.astraweb.com> On Sun, 20 Apr 2014 15:38:03 +0300, Jussi Piitulainen wrote: > Steven D'Aprano writes: > >> It doesn't round, it truncates. >> >> [steve at ando ~]$ python2.7 -c "print round(799.0/100)" 8.0 >> [steve at ando ~]$ python2.7 -c "print 799/100" 7 > > Seems it floors rather than truncates: > > $ python2.7 -c "from math import trunc;print trunc(799./-100)" -7 > $ python2.7 -c "from math import floor;print floor(799./-100)" -8.0 > $ python2.7 -c "print 799/-100" > -8 > > $ python3.2 -c "print(799//-100)" > -8 Ah yes, so it does. Sorry for the confusion. This has been reported as a bug at least twice, but it is actually working as intended. // floors, not truncates towards zero. http://bugs.python.org/issue19446 http://bugs.python.org/issue19574 -- Steven D'Aprano http://import-that.dreamwidth.org/ From zdoor at xs4all.nl Sun Apr 20 11:36:23 2014 From: zdoor at xs4all.nl (Alex van der Spek) Date: Sun, 20 Apr 2014 17:36:23 +0200 Subject: ctypes: returning an array from a subroutine In-Reply-To: <5353bf06$0$2830$e4fe514c@news2.news.xs4all.nl> References: <5353bf06$0$2830$e4fe514c@news2.news.xs4all.nl> Message-ID: <5353e979$0$2922$e4fe514c@news2.news.xs4all.nl> Many hours later I found a working solutions in ctypes: The below makes sense to me but I am still at a loss why the first solution did not work. Anybody willing to explain for my better understanding? Regards, Alex van der Spek ++++++++++++++++++++++++++++++++++++++++++++ _snns = ctypes.windll.LoadLibrary(r'C:\MSDEV\Projects\Cyctrac\Debug\Cyctrac.dll') _cosm = getattr(_snns, '_bnd2prb at 12') _cosm.restype = ctypes.c_int def snns(indata, outdat): """Calls the neural net, returns a vector of 4. """ global _cosm init = ctypes.c_long(0) odat = (ctypes.c_float * len(outdat))(*outdat) idat = (ctypes.c_float * len(indata))(*indata) iok = _cosm(ctypes.byref(idat), ctypes.byref(odat), init) for i, x in enumerate(odat): outdat[i] = x if not iok: return odat else: return False indata = [0.5 for x in range(31)] outdat = [0.0 for x in range(4)] ok = snns(indata, outdat) if ok: print indata print outdat +++++++++++++++++++++++++++++++++++++++ "Alex van der Spek" wrote in message news:5353bf06$0$2830$e4fe514c at news2.news.xs4all.nl... >I have a C code function like this: > > ++++++++++++++++++++++++++ > > int __declspec(dllexport) __stdcall bnd2prb(float *in, float *out, int > init) > {enum {OK, Error, Not_Valid}; > ... > return(OK): > } > > ++++++++++++++++++++++++++ > > And in Python I am trying to call this C function: > > ++++++++++++++++++++++++++ > > import ctypes > import struct > import array > > _snns = > ctypes.windll.LoadLibrary(r'C:\MSDEV\Projects\Cyctrac\Debug\Cyctrac.dll') > > _cosm = getattr(_snns, '_bnd2prb at 12') > > _cosm.argtypes = (ctypes.POINTER(ctypes.c_float), > ctypes.POINTER(ctypes.c_float), > ctypes.c_long) > > _cosm.restype = ctypes.c_float > > def snns(indata, outdat): > """Calls the neural net, returns a vector of 4. > > """ > global _cosm > > init = ctypes.c_long(0) > > ilen = len(indata) > olen = len(outdat) > > itype = ctypes.c_float * ilen > otype = ctypes.c_float * olen > > iok = _cosm(itype(*indata), ctypes.pointer(otype(*outdat)), init) > > if not iok: > return True > else: > return False > > indata = [0.5 for x in range(31)] > outdat = [0.0 for x in range(4)] > > indata[1]=3.14 > > ok = snns(indata, outdat) > > if ok: > print indata > print outdat > > +++++++++++++++++++++++++++++++ > > This executes but leaves the outdat array unchanged. > > Obviously I haven't understood ctypes well enough. > > Returning arrays from FORTRAN I routinely do through a string_buffer. > > That works very well but did not work here at all. > > Any and all help welcome. > > Alex van der Spek From ian.g.kelly at gmail.com Sun Apr 20 12:22:29 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 20 Apr 2014 10:22:29 -0600 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On Apr 19, 2014 2:54 PM, "Chris Angelico" wrote: > > On Sun, Apr 20, 2014 at 6:38 AM, Ian Kelly wrote: > >> Or you just cast one of them to float. That way you're sure you're > >> working with floats. > > > > Which is inappropriate if the type passed in was a Decimal or a complex. > > In that case, you already have a special case in your code, so whether > that special case is handled by the language or by your code makes > little difference. Is your function so generic that it has to be able > to handle float, Decimal, or complex, and not care about the > difference, and yet has to ensure that int divided by int doesn't > yield int? Then say so; put in that special check. Personally, I've > yet to meet any non-toy example of a function that needs that exact > handling; most code doesn't ever think about complex numbers, and a > lot of things look for one specific type: When I'm writing a generic average function, I probably don't know whether it will ever be used to average complex numbers. That shouldn't matter, because I should be able to rely on this code working for whatever numeric type I pass in: def average(values): return sum(values) / len(values) This works for decimals, it works for fractions, it works for complex numbers, it works for numpy types, and in Python 3 it works for ints. > Maybe it's not your code that should be caring about what happens when > you divide two integers, but the calling code. If you're asking for > the average of a list of numbers, and they're all integers, and the > avg() function truncates to integer, then the solution is to use sum() > and explicitly cast to floating point before dividing. First, that's not equivalent. Try the following in Python 3: values = [int(sys.float_info.max / 10)] * 20 print(average(values)) Now try this: print(average(map(float, values))) I don't have an interpreter handy to test, but I expect the former to produce the correct result and the latter to raise OverflowError on the call to sum. Second, why should the calling code have to worry about this implementation detail anyway? The point of a generic function is that it's generic. -------------- next part -------------- An HTML attachment was scrubbed... URL: From miki.tebeka at gmail.com Sun Apr 20 12:36:34 2014 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sun, 20 Apr 2014 09:36:34 -0700 (PDT) Subject: [OT] Testing and credentials best practices? Message-ID: <267e12d3-ea01-4886-bfa7-5c7270adbe92@googlegroups.com> Greetings, How do you deal with tests (both on dev machine and Jenkins) that need credentials (such as AWS keys)?. I know of the following methods: 1. Test user with known (stored in source control) limited credentials 2. ~/.secrets (or any other known location) RC file which is not in source control 3. Credentials service (such as ZooKeeper) accessed only from VPN 4. Credentials pre user encrypted (gpg) and stored in source control What method are you using? Are there any best practices in the subject? Thanks, -- Miki From python at mrabarnett.plus.com Sun Apr 20 12:41:09 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 20 Apr 2014 17:41:09 +0100 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: <5353F8A5.8000504@mrabarnett.plus.com> On 2014-04-20 17:22, Ian Kelly wrote: > > On Apr 19, 2014 2:54 PM, "Chris Angelico" > wrote: > > > > On Sun, Apr 20, 2014 at 6:38 AM, Ian Kelly > wrote: > > >> Or you just cast one of them to float. That way you're sure you're > > >> working with floats. > > > > > > Which is inappropriate if the type passed in was a Decimal or a > complex. > > > > In that case, you already have a special case in your code, so whether > > that special case is handled by the language or by your code makes > > little difference. Is your function so generic that it has to be able > > to handle float, Decimal, or complex, and not care about the > > difference, and yet has to ensure that int divided by int doesn't > > yield int? Then say so; put in that special check. Personally, I've > > yet to meet any non-toy example of a function that needs that exact > > handling; most code doesn't ever think about complex numbers, and a > > lot of things look for one specific type: > > When I'm writing a generic average function, I probably don't know > whether it will ever be used to average complex numbers. That shouldn't > matter, because I should be able to rely on this code working for > whatever numeric type I pass in: > > def average(values): > return sum(values) / len(values) > > This works for decimals, it works for fractions, it works for complex > numbers, it works for numpy types, and in Python 3 it works for ints. > > > Maybe it's not your code that should be caring about what happens when > > you divide two integers, but the calling code. If you're asking for > > the average of a list of numbers, and they're all integers, and the > > avg() function truncates to integer, then the solution is to use sum() > > and explicitly cast to floating point before dividing. > > First, that's not equivalent. Try the following in Python 3: > > values = [int(sys.float_info.max / 10)] * 20 > print(average(values)) > > Now try this: > > print(average(map(float, values))) > > I don't have an interpreter handy to test, but I expect the former to > produce the correct result and the latter to raise OverflowError on the > call to sum. > Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> def average(values): ... return sum(values) / len(values) ... >>> values = [int(sys.float_info.max / 10)] * 20 >>> print(average(values)) 1.7976931348623158e+307 >>> print(average(map(float, values))) Traceback (most recent call last): File "", line 1, in File "", line 2, in average TypeError: object of type 'map' has no len() >>> print(average(list(map(float, values)))) inf >>> In fact, that's true back to Python 3.1 > Second, why should the calling code have to worry about this > implementation detail anyway? The point of a generic function is that > it's generic. > From rosuav at gmail.com Sun Apr 20 12:45:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Apr 2014 02:45:24 +1000 Subject: [OT] Testing and credentials best practices? In-Reply-To: <267e12d3-ea01-4886-bfa7-5c7270adbe92@googlegroups.com> References: <267e12d3-ea01-4886-bfa7-5c7270adbe92@googlegroups.com> Message-ID: On Mon, Apr 21, 2014 at 2:36 AM, Miki Tebeka wrote: > How do you deal with tests (both on dev machine and Jenkins) that need credentials (such as AWS keys)?. I know of the following methods: > > 1. Test user with known (stored in source control) limited credentials > 2. ~/.secrets (or any other known location) RC file which is not in source control > 3. Credentials service (such as ZooKeeper) accessed only from VPN > 4. Credentials pre user encrypted (gpg) and stored in source control I've done several of these. Another option that may work in some contexts is to mock the test altogether; have a server that simulates whatever you needed credentials for, and accepts a key of all zeroes or equivalent. Obviously that key can happily go into the source code :) ChrisA From rosuav at gmail.com Sun Apr 20 12:46:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Apr 2014 02:46:54 +1000 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On Mon, Apr 21, 2014 at 2:22 AM, Ian Kelly wrote: > When I'm writing a generic average function, I probably don't know whether > it will ever be used to average complex numbers. This keeps coming up in these discussions. How often do you really write a function that generic? And if you do, isn't it doing something so simple that it's then the caller's responsibility (not the function's, and not the language's) to ensure that it gets the right result? ChrisA From dihedral88888 at gmail.com Sun Apr 20 13:27:55 2014 From: dihedral88888 at gmail.com (CHIN Dihedral) Date: Sun, 20 Apr 2014 10:27:55 -0700 (PDT) Subject: Why Python 3? In-Reply-To: References: Message-ID: <5a91d3c3-9924-4d07-a921-fca01bace12e@googlegroups.com> On Saturday, April 19, 2014 12:50:09 PM UTC+8, Ethan Furman wrote: > On 04/18/2014 08:28 PM, Anthony Papillion wrote: > > > > > > What is the general feel of /this/ community? I'm about to start a > > > large scale Python project. Should it be done in 2 or 3? What are the > > > benefits, aside from the 'it's the future' argument? > > > > This community is also split. ;) > > > > Use Python 3 if you can. The best reason not to is if you have some critical library that you absolutely need and it's > > not yet available on 3. In which case, program as if your code base was going to run on both 2 and 3 so you can update > > easily once your dependency upgrades. > > > > -- > > ~Ethan~ OK, I'll suggest to use Python 2.7X with pytoexe buldled as an executable to be called by the shell from Python 3.X for programs that need to mix Python 2.X and Python 3.X together. From Bernd-Waterkamp at web.de Sun Apr 20 14:02:38 2014 From: Bernd-Waterkamp at web.de (Bernd Waterkamp) Date: Sun, 20 Apr 2014 20:02:38 +0200 Subject: Why Python 3? References: <53520052.8030407@my.hennepintech.edu> Message-ID: <19kpl0kpudqpd.1n26010eiecq6.dlg@40tude.net> Michael Torrie schrieb: > For example, RHEL 6 is Red Hat's most current enterprise distribution and > it does not yet even ship Python 2.7, to say nothing of Python 3. RHEL > 7 has python 2.7 as the default system dependency, and currently does > not yet have any python3 packages in the official main repo, python2.7 and python3.3 are availabe in "RedHat Software Collections": https://access.redhat.com/site/documentation/en-US/Red_Hat_Software_Collections/1/html/1.0_Release_Notes/chap-RHSCL.html http://developerblog.redhat.com/2014/02/18/migrate-to-python3-w-rhscl/ So there is at least a chance if you want to (or have to) use "official" packages from the distributor. Regards, Bernd From ivriabtsov at gmail.com Sun Apr 20 14:43:37 2014 From: ivriabtsov at gmail.com (Ivan Ivanivich) Date: Sun, 20 Apr 2014 11:43:37 -0700 (PDT) Subject: symple programming task Message-ID: hi all, i have simple programming task: [quot] If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. [/quote] this task from http://projecteuler.net/ site I wrote a solution in python http://pastebin.com/QXtNuRWU this script returned correctly result if "basis < 10", but if "basis < 1000" result is 266333 and it is not correctly answer on site http://projecteuler.net it is my script problem or site not working correctly? thanks sorry for my english From rosuav at gmail.com Sun Apr 20 15:02:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Apr 2014 05:02:25 +1000 Subject: symple programming task In-Reply-To: References: Message-ID: On Mon, Apr 21, 2014 at 4:43 AM, Ivan Ivanivich wrote: > [quot] > If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. > > Find the sum of all the multiples of 3 or 5 below 1000. > [/quote] > > this task from http://projecteuler.net/ site > > I wrote a solution in python > > http://pastebin.com/QXtNuRWU > > this script returned correctly result if "basis < 10", but if "basis < 1000" result is 266333 and it is not correctly answer on site http://projecteuler.net Try listing the actual numbers you're summing, and check if there's a problem there. Are all the numbers you expect appearing? Are any you don't want there? (I can see exactly what your problem is, but I'd rather give hints rather than simply tell you outright what's wrong.) ChrisA From __peter__ at web.de Sun Apr 20 15:11:09 2014 From: __peter__ at web.de (Peter Otten) Date: Sun, 20 Apr 2014 21:11:09 +0200 Subject: symple programming task References: Message-ID: Ivan Ivanivich wrote: > hi all, i have simple programming task: > > [quot] > If we list all the natural numbers below 10 that are multiples of 3 or 5, > we get 3, 5, 6 and 9. The sum of these multiples is 23. > > Find the sum of all the multiples of 3 or 5 below 1000. > [/quote] > > this task from http://projecteuler.net/ site > > I wrote a solution in python > > http://pastebin.com/QXtNuRWU [for small scripts it is fine to include them directly in your post] > #!/usr/bin/env python3.2 > > total = 0 > for divider in 3, 5: > basis=divider > while basis < 1000: > mod = basis % divider > if mod == 0: > total = total + basis > print("total = ", total, "basis = ", basis) > > basis += 1 > > print("total", total) > this script returned correctly result if "basis < 10", but if "basis < > 1000" result is 266333 and it is not correctly answer on site > http://projecteuler.net > > it is my script problem or site not working correctly? Your script. Try it for the numbers below 20, say, and then compare to a result you calculated with pen and paper. Or look closely at the output produced by the line > print("total = ", total, "basis = ", basis) in your code. From joel.goldstick at gmail.com Sun Apr 20 15:15:27 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 20 Apr 2014 15:15:27 -0400 Subject: symple programming task In-Reply-To: References: Message-ID: On Sun, Apr 20, 2014 at 3:02 PM, Chris Angelico wrote: > On Mon, Apr 21, 2014 at 4:43 AM, Ivan Ivanivich > wrote: > > [quot] > > If we list all the natural numbers below 10 that are multiples of 3 or > 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. > > > > Find the sum of all the multiples of 3 or 5 below 1000. > > [/quote] > > > > this task from http://projecteuler.net/ site > > > > I wrote a solution in python > > > > http://pastebin.com/QXtNuRWU > > > > this script returned correctly result if "basis < 10", but if "basis < > 1000" result is 266333 and it is not correctly answer on site > http://projecteuler.net > > Try listing the actual numbers you're summing, and check if there's a > problem there. Are all the numbers you expect appearing? Are any you > don't want there? > > (I can see exactly what your problem is, but I'd rather give hints > rather than simply tell you outright what's wrong.) > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > I second Chris's comments. Also, better to paste your code in email. More people will look at it, especially since it is short. It looks like you are looping thru all the numbers twice -- once for each divisor. You don't need to do that. You can loop thru and test for each divisor on each loop. You might want to ditch the while loop and use a for loop over a range: for i in range(1000): Its a more pythonic idiom. Also use 4 spaces, not 8 for indents. Minor points. Print() is your friend -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ivriabtsov at gmail.com Sun Apr 20 15:27:31 2014 From: ivriabtsov at gmail.com (Ivan Ivanivich) Date: Sun, 20 Apr 2014 12:27:31 -0700 (PDT) Subject: symple programming task In-Reply-To: References: Message-ID: <313537d1-28f6-47fe-82d9-20e4cba41f73@googlegroups.com> On Sunday, April 20, 2014 10:43:37 PM UTC+4, Ivan Ivanivich wrote: > hi all, i have simple programming task: > > > > [quot] > > If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. > > > > Find the sum of all the multiples of 3 or 5 below 1000. > > [/quote] > > > > this task from http://projecteuler.net/ site > > > > I wrote a solution in python > > > > http://pastebin.com/QXtNuRWU > > > > this script returned correctly result if "basis < 10", but if "basis < 1000" result is 266333 and it is not correctly answer on site http://projecteuler.net > > > > it is my script problem or site not working correctly? > > > > thanks > > > > sorry for my english thanks, i found the bag From torriem at gmail.com Sun Apr 20 16:05:31 2014 From: torriem at gmail.com (Michael Torrie) Date: Sun, 20 Apr 2014 14:05:31 -0600 Subject: Why Python 3? In-Reply-To: <19kpl0kpudqpd.1n26010eiecq6.dlg@40tude.net> References: <53520052.8030407@my.hennepintech.edu> <19kpl0kpudqpd.1n26010eiecq6.dlg@40tude.net> Message-ID: <5354288B.7090108@gmail.com> On 04/20/2014 12:02 PM, Bernd Waterkamp wrote: > Michael Torrie schrieb: > >> For example, RHEL 6 is Red Hat's most current enterprise distribution and >> it does not yet even ship Python 2.7, to say nothing of Python 3. RHEL >> 7 has python 2.7 as the default system dependency, and currently does >> not yet have any python3 packages in the official main repo, > > python2.7 and python3.3 are availabe in "RedHat Software Collections": > > https://access.redhat.com/site/documentation/en-US/Red_Hat_Software_Collections/1/html/1.0_Release_Notes/chap-RHSCL.html > http://developerblog.redhat.com/2014/02/18/migrate-to-python3-w-rhscl/ > > So there is at least a chance if you want to (or have to) use "official" > packages from the distributor. Brilliant! Thanks. From roy at panix.com Sun Apr 20 17:32:31 2014 From: roy at panix.com (Roy Smith) Date: Sun, 20 Apr 2014 14:32:31 -0700 Subject: [OT] Testing and credentials best practices? References: <267e12d3-ea01-4886-bfa7-5c7270adbe92@googlegroups.com> Message-ID: In article <267e12d3-ea01-4886-bfa7-5c7270adbe92 at googlegroups.com>, Miki Tebeka wrote: > Greetings, > > How do you deal with tests (both on dev machine and Jenkins) that need > credentials (such as AWS keys)?. I know of the following methods: > > 1. Test user with known (stored in source control) limited credentials > 2. ~/.secrets (or any other known location) RC file which is not in source > control > 3. Credentials service (such as ZooKeeper) accessed only from VPN > 4. Credentials pre user encrypted (gpg) and stored in source control > > What method are you using? Are there any best practices in the subject? We've been looking at using etcd to store credentials (essentially the same solution as zookeeper). It seems like the right way to go. So far, my impression of etcd is "neat, promising, not ready for prime time yet" (to be fair, the etcd folks don't claim it's stable yet). ZooKeeper at least has the advantage of being in production use for a long time, so it should be pretty bullet-proof. From roy at panix.com Sun Apr 20 17:40:38 2014 From: roy at panix.com (Roy Smith) Date: Sun, 20 Apr 2014 14:40:38 -0700 Subject: Why Python 3? References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: In article , Chris Angelico wrote: > On Mon, Apr 21, 2014 at 2:22 AM, Ian Kelly wrote: > > When I'm writing a generic average function, I probably don't know whether > > it will ever be used to average complex numbers. > > This keeps coming up in these discussions. How often do you really > write a function that generic? And if you do, isn't it doing something > so simple that it's then the caller's responsibility (not the > function's, and not the language's) to ensure that it gets the right > result? > > ChrisA Hmmm. Taking the average of a set of complex numbers has a reasonable physical meaning. But, once you start down that path, I'm not sure how far you can go before things no long make sense. What's the standard deviation of a set of complex numbers? Does that even have any meaning? From tjreedy at udel.edu Sun Apr 20 17:58:04 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 20 Apr 2014 17:58:04 -0400 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On 4/20/2014 5:40 PM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Mon, Apr 21, 2014 at 2:22 AM, Ian Kelly wrote: >>> When I'm writing a generic average function, I probably don't know whether >>> it will ever be used to average complex numbers. >> >> This keeps coming up in these discussions. How often do you really >> write a function that generic? And if you do, isn't it doing something >> so simple that it's then the caller's responsibility (not the >> function's, and not the language's) to ensure that it gets the right >> result? >> >> ChrisA > > Hmmm. Taking the average of a set of complex numbers has a reasonable > physical meaning. But, once you start down that path, I'm not sure how > far you can go before things no long make sense. What's the standard > deviation of a set of complex numbers? Does that even have any meaning? One can either calculate variance from the sum of squared distances from the mean point, or calculate x and y deviations separately and calculate the covariance matrix thereof. -- Terry Jan Reedy From Richard at Damon-Family.org Sun Apr 20 18:02:40 2014 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 20 Apr 2014 18:02:40 -0400 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: <4uX4v.46265$rL7.31213@en-nntp-16.dc1.easynews.com> On 4/20/14, 5:40 PM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Mon, Apr 21, 2014 at 2:22 AM, Ian Kelly wrote: >>> When I'm writing a generic average function, I probably don't know whether >>> it will ever be used to average complex numbers. >> >> This keeps coming up in these discussions. How often do you really >> write a function that generic? And if you do, isn't it doing something >> so simple that it's then the caller's responsibility (not the >> function's, and not the language's) to ensure that it gets the right >> result? >> >> ChrisA > > Hmmm. Taking the average of a set of complex numbers has a reasonable > physical meaning. But, once you start down that path, I'm not sure how > far you can go before things no long make sense. What's the standard > deviation of a set of complex numbers? Does that even have any meaning? > If you thing of the Standard Deviation being the Root Mean Norm2 of the deviations, it has a very similar meaning as to over the reals, a measure of the "spread" of the values. From marianoa.dangelo at gmail.com Sun Apr 20 18:34:38 2014 From: marianoa.dangelo at gmail.com (Mariano DAngelo) Date: Sun, 20 Apr 2014 15:34:38 -0700 (PDT) Subject: how to string format when string have { Message-ID: <2075921a-dd3e-4788-86fb-e751ad98ee0e@googlegroups.com> I have the following string: nginx_conf = ''' server { listen 80; server_name dev.{project_url}; location / { proxy_pass http://127.0.0.1:8080; include /etc/nginx/proxy.conf; } location /media { alias /home/mariano/PycharmProjects/{project_name}/{project_name}/media; expires 30d; } location /static { alias /home/mariano/PycharmProjects/{project_name}/{project_name}/static; expires 30d; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }''' And I want to format like this: context = { "project_name":project_name, "project_url":project_url, } nginx_conf.format(**context) but since the string have { i can't. Is there a way to solve this? From rosuav at gmail.com Sun Apr 20 18:41:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Apr 2014 08:41:27 +1000 Subject: how to string format when string have { In-Reply-To: <2075921a-dd3e-4788-86fb-e751ad98ee0e@googlegroups.com> References: <2075921a-dd3e-4788-86fb-e751ad98ee0e@googlegroups.com> Message-ID: On Mon, Apr 21, 2014 at 8:34 AM, Mariano DAngelo wrote: > And I want to format like this: > > context = { > "project_name":project_name, > "project_url":project_url, > } > > nginx_conf.format(**context) > > > but since the string have { i can't. > Is there a way to solve this? Are you in full control of the source string? You can escape the braces as explained here: https://docs.python.org/3.4/library/string.html#format-string-syntax If you're not in full control (eg if it comes from a user's input), or if you don't like the idea of doubling all your braces, you could switch to percent-formatting, or some other form of interpolation. But the easiest would be to simply escape them. ChrisA From greg.ewing at canterbury.ac.nz Sun Apr 20 18:52:11 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 21 Apr 2014 10:52:11 +1200 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: Chris Angelico wrote: > Truncating vs true is not the same as int vs float. If you mean to > explicitly request float division, you call float() on one or both > arguments. You're being explicit about something different. If you know you're dealing with either ints or floats, which is true in the vast majority of cases, then you know that / will always perform float division. As for why int/int should yield float and not some other type, float is alreay special -- it's built-in and has syntactic support in the form of literals. It's the most obvious choice. If a version of Python were ever to exist in which floating-point literals produced Decimals instead of floats, then int/int would produce a Decimal. -- Greg From greg.ewing at canterbury.ac.nz Sun Apr 20 19:13:23 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 21 Apr 2014 11:13:23 +1200 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: Terry Reedy wrote: > On 4/19/2014 9:06 PM, Gregory Ewing wrote: > >> Similarly, when you write // you're explicitly requesting >> integer division. > > One is requesting 'floor division' > > >>> 3.0//2.0 > 1.0 In general that's true, but I'm talking about a context in which you have some expectations as to the types of the operands. Most of the time, there are two possible scenarios: 1) The algorithm operates on integers, and the contract is that you only get passed ints. In that case, you use // and know that the result will be an int. 2) The algorithm operates on non-integers, and the contract is that you get passed either ints or floats, with ints being understood as standing in for floats. In that case, you use / and know that it will perform float division and return a float. If someone passes you a float in case (1) it's true that // won't return an int, but then they've violated the contract. -- Greg From rosuav at gmail.com Sun Apr 20 19:24:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Apr 2014 09:24:09 +1000 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On Mon, Apr 21, 2014 at 8:52 AM, Gregory Ewing wrote: > Chris Angelico wrote: > >> Truncating vs true is not the same as int vs float. If you mean to >> explicitly request float division, you call float() on one or both >> arguments. You're being explicit about something different. > > > If you know you're dealing with either ints or floats, > which is true in the vast majority of cases, then you > know that / will always perform float division. And that's what I mean about the common non-trivial case. It's easy enough to come up with contrived or trivial cases that use any types, but in most cases, it'd be fine to explicitly call float() on one of the operands to explicitly request floating-point division. Choosing between two division operators is not the same thing as choosing a data type. Explicitly choosing float division: x / float(y) Explicitly choosing to truncate: math.trunc(x / y) Both explicit forms can be done cleanly without empowering the language with the magic of int/int->float. ChrisA From python.list at tim.thechases.com Sun Apr 20 19:43:44 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 20 Apr 2014 18:43:44 -0500 Subject: how to string format when string have { In-Reply-To: <2075921a-dd3e-4788-86fb-e751ad98ee0e@googlegroups.com> References: <2075921a-dd3e-4788-86fb-e751ad98ee0e@googlegroups.com> Message-ID: <20140420184344.316dcb5e@bigbox.christie.dr> On 2014-04-20 15:34, Mariano DAngelo wrote: > I have the following string: ... > but since the string have { i can't. > Is there a way to solve this? I second Chris Angelico's suggestion about using the older percent formatting: nginx_conf = ''' server { listen 80; server_name dev.%(project_url)s; location / { proxy_pass http://127.0.0.1:8080; include /etc/nginx/proxy.conf; } location /media { alias /home/mariano/PycharmProjects/%(project_name)s/%(project_name)s/media; expires 30d; } location /static { alias /home/mariano/PycharmProjects/%(project_name)s/%(project_name)s/static; expires 30d; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }''' context = { "project_name":project_name, "project_url":project_url, } print(nginx_conf % context) -tkc From greg.ewing at canterbury.ac.nz Sun Apr 20 19:44:07 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 21 Apr 2014 11:44:07 +1200 Subject: Integer and float division [was Re: Why Python 3?] In-Reply-To: <5353a958$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <5353a958$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: > On Sat, 19 Apr 2014 19:37:31 +1000, Chris Angelico wrote: > >>In Python 3, you have to say "Oh but I want my integer division to >>result in an integer": I don't see why that's such a big hardship. There are clear advantages to having an explicit way to request non-floor division. Whatever way is chosen for that, some other way has to be chosen to request floor division. One could debate whether it would have been better to make / mean floor division and invent something else for non-floor division, but then some people would complain "Oh, but I have to say I want my float division to return a float!" Either way requires people to make some changes in their habits. -- Greg From walterhurry at lavabit.com Sun Apr 20 19:50:45 2014 From: walterhurry at lavabit.com (Walter Hurry) Date: Sun, 20 Apr 2014 23:50:45 +0000 (UTC) Subject: Why Python 3? References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <7xha5od6mr.fsf@ruckus.brouhaha.com> Message-ID: On Sat, 19 Apr 2014 20:25:32 -0700, Paul Rubin wrote: > Terry Reedy writes: >> LibreOffice bundles 3.3. So anyone who does Python scripting in >> LibreOffice is using Python 3. Actually, I believe LO uses Python >> internally for some of its scripting. If so, everyone using LO is >> indirectly using 3.3. > > I didn't even know LO supported Python scripting, but I wouldn't count > such indirect use anyway. I meant I don't know any Python programmers > (at least in person) who use Python 3 for their daily coding. I think > this is mostly because they (and I) use whatever is in the OS distro, > and that is generally still 2.6 or 2.7. I would use Python 3 in a flash if only wxPython would support it. From greg.ewing at canterbury.ac.nz Sun Apr 20 19:56:43 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 21 Apr 2014 11:56:43 +1200 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: Ian Kelly wrote: > def average(values): > return sum(values) / len(values) > > This works for decimals, it works for fractions, it works for complex > numbers, it works for numpy types, and in Python 3 it works for ints. That depends on what you mean by "works". I would actually find it rather disturbing if an average() function implicitly used floor division when given all ints. The reason is that people often use ints as stand-ins for floats in computations that are conceptually non-integer. So a general-purpose function like average(), given a list of ints, has no way of knowing whether they're intended to be interpreted as ints or floats. To my way of thinking, floor division is a specialised operation that is only wanted in particular circumstances. It's rare that I would actually want it done in the context of taking an average, and if I do, I would rather be explicit about it using e.g. int(floor(average(...)) or a specialised int_average() function. -- Greg From rosuav at gmail.com Sun Apr 20 20:00:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Apr 2014 10:00:01 +1000 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <7xha5od6mr.fsf@ruckus.brouhaha.com> Message-ID: On Mon, Apr 21, 2014 at 9:50 AM, Walter Hurry wrote: > I would use Python 3 in a flash if only wxPython would support it. There seems to be a "Project Phoenix" (found it at the other end of a Google search) with that goal. I've no idea what its status is, but you could help that project along by expressing interest and maybe helping with their bug tracker, or hosting a buildbot (they seem to use the same buildbot software that Python uses), or something like that. If you're really serious about wanting Python 3 support, go the whole way and actually help to port it! ChrisA From tjreedy at udel.edu Sun Apr 20 20:09:25 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 20 Apr 2014 20:09:25 -0400 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On 4/20/2014 7:13 PM, Gregory Ewing wrote: > Terry Reedy wrote: >> On 4/19/2014 9:06 PM, Gregory Ewing wrote: >> >>> Similarly, when you write // you're explicitly requesting >>> integer division. >> >> One is requesting 'floor division' >> >> >>> 3.0//2.0 >> 1.0 The name 'floor division' and the float result are intentional, not accidents. > In general that's true, but I'm talking about a context > in which you have some expectations as to the types of the > operands. > > Most of the time, there are two possible scenarios: > > 1) The algorithm operates on integers, and the contract is > that you only get passed ints. In that case, you use // > and know that the result will be an int. > > 2) The algorithm operates on non-integers, and the contract > is that you get passed either ints or floats, with ints being > understood as standing in for floats. In that case, you > use / and know that it will perform float division and > return a float. > > If someone passes you a float in case (1) it's true that > // won't return an int, but then they've violated the > contract. Not necessarily if the float has an integer value. The intention of the change was to make the value of number operations less dependent on the type of the operands. Where the result type does matter is if the result is used, for example, in indexing -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Sun Apr 20 20:11:51 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 21 Apr 2014 01:11:51 +0100 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <7xha5od6mr.fsf@ruckus.brouhaha.com> Message-ID: On 21/04/2014 00:50, Walter Hurry wrote: > On Sat, 19 Apr 2014 20:25:32 -0700, Paul Rubin wrote: > >> Terry Reedy writes: >>> LibreOffice bundles 3.3. So anyone who does Python scripting in >>> LibreOffice is using Python 3. Actually, I believe LO uses Python >>> internally for some of its scripting. If so, everyone using LO is >>> indirectly using 3.3. >> >> I didn't even know LO supported Python scripting, but I wouldn't count >> such indirect use anyway. I meant I don't know any Python programmers >> (at least in person) who use Python 3 for their daily coding. I think >> this is mostly because they (and I) use whatever is in the OS distro, >> and that is generally still 2.6 or 2.7. > > I would use Python 3 in a flash if only wxPython would support it. > It's getting there with the Phoenix project. Snapshots available here http://wxpython.org/Phoenix/snapshot-builds/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From greg.ewing at canterbury.ac.nz Sun Apr 20 20:22:24 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 21 Apr 2014 12:22:24 +1200 Subject: Why Python 3? In-Reply-To: <4uX4v.46265$rL7.31213@en-nntp-16.dc1.easynews.com> References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <4uX4v.46265$rL7.31213@en-nntp-16.dc1.easynews.com> Message-ID: Richard Damon wrote: > If you thing of the Standard Deviation being the Root Mean Norm2 of the > deviations, it has a very similar meaning as to over the reals, a > measure of the "spread" of the values. NumPy appears to handle this: http://docs.scipy.org/doc/numpy/reference/generated/numpy.std.html See the comment on that page about complex numbers. So yes, it is meaningful and apparently people use it. -- Greg From ian.g.kelly at gmail.com Sun Apr 20 20:29:05 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 20 Apr 2014 18:29:05 -0600 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: On Apr 20, 2014 8:01 PM, "Gregory Ewing" wrote: > > Ian Kelly wrote: > >> def average(values): >> return sum(values) / len(values) >> >> This works for decimals, it works for fractions, it works for complex numbers, it works for numpy types, and in Python 3 it works for ints. > > > That depends on what you mean by "works". I would actually > find it rather disturbing if an average() function implicitly > used floor division when given all ints. The code above never uses floor division in Python 3. Therefore it "works". -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sun Apr 20 22:13:56 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Apr 2014 02:13:56 GMT Subject: Why Python 3? References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: <53547ee3$0$29993$c3e8da3$5496439d@news.astraweb.com> On Sun, 20 Apr 2014 14:40:38 -0700, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Mon, Apr 21, 2014 at 2:22 AM, Ian Kelly >> wrote: >> > When I'm writing a generic average function, I probably don't know >> > whether it will ever be used to average complex numbers. >> >> This keeps coming up in these discussions. How often do you really >> write a function that generic? And if you do, isn't it doing something >> so simple that it's then the caller's responsibility (not the >> function's, and not the language's) to ensure that it gets the right >> result? >> >> ChrisA > > Hmmm. Taking the average of a set of complex numbers has a reasonable > physical meaning. But, once you start down that path, I'm not sure how > far you can go before things no long make sense. What's the standard > deviation of a set of complex numbers? Does that even have any meaning? Yes it does. Stdev is a measure of scale of the distribution, and is always real and non-negative. For complex values, you can calculate it using: (abs(x - mean))**2 which is how numpy does it, or from the complex conjugate: x1 = x-mean x1.conj()*x1 which is how Matlab does it. http://docs.scipy.org/doc/numpy/reference/generated/numpy.std.html http://www.mathworks.com.au/matlabcentral/newsreader/view_thread/57323 Hence the variance is always non-negative, and the standard deviation is always real. See also: https://en.wikipedia.org/wiki/Variance#Generalizations -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Sun Apr 20 23:43:17 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Apr 2014 03:43:17 GMT Subject: Why Python 3? References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Message-ID: <535493d4$0$29993$c3e8da3$5496439d@news.astraweb.com> On Mon, 21 Apr 2014 09:24:09 +1000, Chris Angelico wrote: > On Mon, Apr 21, 2014 at 8:52 AM, Gregory Ewing > wrote: >> Chris Angelico wrote: >> >>> Truncating vs true is not the same as int vs float. If you mean to >>> explicitly request float division, you call float() on one or both >>> arguments. You're being explicit about something different. >> >> >> If you know you're dealing with either ints or floats, which is true in >> the vast majority of cases, then you know that / will always perform >> float division. > > And that's what I mean about the common non-trivial case. It's easy > enough to come up with contrived or trivial cases that use any types, > but in most cases, it'd be fine to explicitly call float() on one of the > operands to explicitly request floating-point division. Choosing between > two division operators is not the same thing as choosing a data type. Nobody says that they are. Choosing between / and // means to choose between two different operator. / performs true division, the sort that you learn about in school (modulo the usual floating point issues -- floats are not mathematical reals). // performs division which floors towards negative infinity. (For positive values, that's equivalent to truncation.) Hence the two special methods: __truediv__ and __floordiv__ (plus the reversed __r*__ versions). I think you need to stop thinking about "integer division", because (1) "integer division" is not well-defined, and (2) in the general case, // doesn't return an int, although it should return a value that is integer valued. Why is integer division not well-defined? Because division of integers doesn't necessarily return an integer: the integers are not closed with the division operator. Cases like 10/5 are easy, that's just 2. What about 11/5 or -7/3? I can think of at least six things that "integer division" might do in those cases: - round to nearest, ties round to even ("banker's rounding"); - round to nearest, ties round to odd; - round towards positive infinity (ceiling); - round towards negative infinity (floor); - round towards zero (truncate); - raise an exception; so before talking about "integer division" we have to decide which of those apply. Python doesn't talk about integer division, well not officially, but talks about *floor division*. The nice thing about this is that there's no requirement that it return an actual int: py> 11.0//2 5.0 just an integer-valued value. It's up to the class to decide how it works. > Explicitly choosing float division: > > x / float(y) But here you're not choosing an *operator*, you're choosing a *type*. With this model, how do I distinguish between floor division and true division using, say, Fractions? py> from fractions import Fraction as F py> F(1799, 27)/F(3) # True division. Fraction(1799, 81) py> F(1799, 27)//F(3) # Floor division. 22 Converting to floats is not an option, since (1) it returns a float, not a Fraction, and (2) it introduces rounding errors: py> F(1799, 27)/F(3) == F(1799, 27)/3.0 False [...] > Both explicit forms can be done cleanly without empowering the language > with the magic of int/int->float. It's hardly magic, and I really am having difficult in working out exactly what your objection to it is. Is it really as simple as "operations on ints should only return ints, like in C"? -- Steven D'Aprano http://import-that.dreamwidth.org/ From nobody at someplace.invalid Mon Apr 21 00:08:03 2014 From: nobody at someplace.invalid (HoneyMonster) Date: Mon, 21 Apr 2014 04:08:03 +0000 (UTC) Subject: Why Python 3? References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <7xha5od6mr.fsf@ruckus.brouhaha.com> Message-ID: On Mon, 21 Apr 2014 10:00:01 +1000, Chris Angelico wrote: > On Mon, Apr 21, 2014 at 9:50 AM, Walter Hurry > wrote: >> I would use Python 3 in a flash if only wxPython would support it. > > There seems to be a "Project Phoenix" (found it at the other end of a > Google search) with that goal. I've no idea what its status is, but you > could help that project along by expressing interest and maybe helping > with their bug tracker, or hosting a buildbot (they seem to use the same > buildbot software that Python uses), or something like that. If you're > really serious about wanting Python 3 support, go the whole way and > actually help to port it! Yes, I'm keeping an eye on Fawkes*. Alas, my skillset is not up to your other suggestions, but thanks. * http://harrypotter.wikia.com/wiki/Fawkes From rosuav at gmail.com Mon Apr 21 00:43:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Apr 2014 14:43:59 +1000 Subject: Why Python 3? In-Reply-To: <535493d4$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <535493d4$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Apr 21, 2014 at 1:43 PM, Steven D'Aprano wrote: >> Explicitly choosing float division: >> >> x / float(y) > > But here you're not choosing an *operator*, you're choosing a *type*. > With this model, how do I distinguish between floor division and true > division using, say, Fractions? Earlier it was said that having both / and // lets you explicitly choose whether you want a float result or an int by picking an operator. I'm saying that's not so; the operator and the type aren't quite orthogonal, but close to. ChrisA From rosuav at gmail.com Mon Apr 21 00:48:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Apr 2014 14:48:34 +1000 Subject: Why Python 3? In-Reply-To: <535493d4$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <535493d4$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Apr 21, 2014 at 1:43 PM, Steven D'Aprano wrote: >> Both explicit forms can be done cleanly without empowering the language >> with the magic of int/int->float. > > It's hardly magic, and I really am having difficult in working out > exactly what your objection to it is. Is it really as simple as > "operations on ints should only return ints, like in C"? All other basic arithmetic operations on two numbers of the same type results in another number of that type. You wouldn't expect the product of two Fractions to be a Decimal, nor the sum of two complex numbers be a float (even if it results in an imaginary part of zero, it'll still be a complex: (1+2j) + (2-2j) --> (3+0j) not 3.0). There's just one special case: dividing an integer by an integer yields a float, if and only if you use truediv. It sticks out as an exception. ChrisA From __peter__ at web.de Mon Apr 21 04:51:06 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 21 Apr 2014 10:51:06 +0200 Subject: how to string format when string have { References: <2075921a-dd3e-4788-86fb-e751ad98ee0e@googlegroups.com> Message-ID: Chris Angelico wrote: > On Mon, Apr 21, 2014 at 8:34 AM, Mariano DAngelo > wrote: >> And I want to format like this: >> >> context = { >> "project_name":project_name, >> "project_url":project_url, >> } >> >> nginx_conf.format(**context) >> >> >> but since the string have { i can't. >> Is there a way to solve this? > > Are you in full control of the source string? You can escape the > braces as explained here: > > https://docs.python.org/3.4/library/string.html#format-string-syntax > > If you're not in full control (eg if it comes from a user's input), or > if you don't like the idea of doubling all your braces, you could > switch to percent-formatting, or some other form of interpolation. But > the easiest would be to simply escape them. Some regex gymnastics in the morning (not recommended): >>> print(nginx_conf) server { listen 80; server_name dev.{project_url}; location / { proxy_pass http://127.0.0.1:8080; include /etc/nginx/proxy.conf; } location /media { alias /home/mariano/PycharmProjects/{project_name}/{project_name}/media; expires 30d; } location /static { alias /home/mariano/PycharmProjects/{project_name}/{project_name}/static; expires 30d; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } >>> fmt = re.compile(r"((\{)(?!\w)|(?>> print(fmt) server {{ listen 80; server_name dev.{project_url}; location / {{ proxy_pass http://127.0.0.1:8080; include /etc/nginx/proxy.conf; }} location /media {{ alias /home/mariano/PycharmProjects/{project_name}/{project_name}/media; expires 30d; }} location /static {{ alias /home/mariano/PycharmProjects/{project_name}/{project_name}/static; expires 30d; }} error_page 500 502 503 504 /50x.html; location = /50x.html {{ root html; }} }} >>> print(fmt.format(project_name="MYPROJECT", project_url="MYPROJECT.COM")) server { listen 80; server_name dev.MYPROJECT.COM; location / { proxy_pass http://127.0.0.1:8080; include /etc/nginx/proxy.conf; } location /media { alias /home/mariano/PycharmProjects/MYPROJECT/MYPROJECT/media; expires 30d; } location /static { alias /home/mariano/PycharmProjects/MYPROJECT/MYPROJECT/static; expires 30d; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } From rosuav at gmail.com Mon Apr 21 04:56:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Apr 2014 18:56:11 +1000 Subject: how to string format when string have { In-Reply-To: References: <2075921a-dd3e-4788-86fb-e751ad98ee0e@googlegroups.com> Message-ID: On Mon, Apr 21, 2014 at 6:51 PM, Peter Otten <__peter__ at web.de> wrote: > Some regex gymnastics in the morning (not recommended): You ask me to believe that a regex would be the best solution here? There's no use trying; one CAN'T believe impossible things. ChrisA (There goes the shawl again!) From papillion at gmail.com Mon Apr 21 05:33:10 2014 From: papillion at gmail.com (Anthony Papillion) Date: Mon, 21 Apr 2014 04:33:10 -0500 Subject: Read TLS cert serial number? Message-ID: <7261BAC8-84C5-4513-8EE9-071470D3C3EC@gmail.com> Is there a way to read the serial number of a TLS cert my app receives? Anthony Sent from my mobile device From wxjmfauth at gmail.com Mon Apr 21 05:42:51 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 21 Apr 2014 02:42:51 -0700 (PDT) Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <535493d4$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: wxPhoenix. The funny side of wxPhoenix is, that it *also* has its own understanding of unicode and it finally only succeeds to produce mojibakes. I've tried to explained... (I was an early wxPython user from wxPython 2.0 (!). I used, tested, reported about, all wxPython versions up to the shift to the wxPython 2.9 "unicode only" versions, then I gave up). -------------- Something else. I'm ready to bet, the unicode related bugs I found in Python 3 (core Python) are still here in five years from now. -------------- Something else, part 2. IDLE. Ten seconds to make it crashing, just by using unicode. -------------- Working with Python 2.7 + third party libs (even in iso-8859-1) *in* a pure "cp1252 mode", including source code is a very, very solid experience. -------------- The "Microsoft", "Adobe", foundries... , and in the "open software", the golang, ruby2, TeX unicode engines, all are working very correctly and smoothly with unicode. jmf PS Yes, I'm aware such comments are not really "fair play". From joshua at landau.ws Mon Apr 21 07:43:04 2014 From: joshua at landau.ws (Joshua Landau) Date: Mon, 21 Apr 2014 12:43:04 +0100 Subject: symple programming task In-Reply-To: <313537d1-28f6-47fe-82d9-20e4cba41f73@googlegroups.com> References: <313537d1-28f6-47fe-82d9-20e4cba41f73@googlegroups.com> Message-ID: On 20 April 2014 20:27, Ivan Ivanivich wrote: > thanks, i found the bag G'day. This [https://xkcd.com/979/] applies to threads ending in "nvm, solved it" too. I know the problem in your case isn't likely to be widely useful, but there are other benefits of pointing out what you've done. For example the list members can tell you if your solution misses anything. From ivriabtsov at gmail.com Mon Apr 21 09:21:14 2014 From: ivriabtsov at gmail.com (Ivan Ivanivich) Date: Mon, 21 Apr 2014 06:21:14 -0700 (PDT) Subject: symple programming task In-Reply-To: References: Message-ID: <7f496a70-6b85-4bc9-bf33-7aeaad813d11@googlegroups.com> On Sunday, April 20, 2014 10:43:37 PM UTC+4, Ivan Ivanivich wrote: > hi all, i have simple programming task: > > > > [quot] > > If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. > > > > Find the sum of all the multiples of 3 or 5 below 1000. > > [/quote] > > > > this task from http://projecteuler.net/ site > > > > I wrote a solution in python > > > > http://pastebin.com/QXtNuRWU > > > > this script returned correctly result if "basis < 10", but if "basis < 1000" result is 266333 and it is not correctly answer on site http://projecteuler.net > > > > it is my script problem or site not working correctly? > > > > thanks > > > > sorry for my english my bag is: Adding twice the same elements to the total for exemple: for divider in 3, 5: basis=divider while basis < 1000: mod = basis % divider if mod == 0: total = total + basis if "basis" is 15, then "mod" == 0 twice - when the "divider" is 3 and 15 my new version of script: total = 0 div1 = 3 div2 = 5 for basis in range(0, 1000): mod = basis % div1 if mod == 0: total = total + basis continue mod = basis % div2 if mod == 0: total = total + basis continue print("total = ", total) From sschwarzer at sschwarzer.net Mon Apr 21 09:23:06 2014 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Mon, 21 Apr 2014 15:23:06 +0200 Subject: Recommended exception for objects that can't be pickled Message-ID: <53551BBA.8000205@sschwarzer.net> Hi, Recently, I got a request [1] to support pickling of `FTPHost` instances in my `ftplib` library. I explained in the ticket why I think it's a bad idea and now want to make explicit that `FTPHost` objects can't be pickled. The usual way to do this seems to be defining a `__getstate__` method and raise an exception there. Now the question is "which exception?" and my research left me a bit confused. I didn't find a recommendation for this on the web, not even in the Python documentation for the `pickle` module [2]. The only hint is that the documentation states: """ The pickle module defines three exceptions: exception pickle.PickleError Common base class for the other pickling exceptions. It inherits Exception. exception pickle.PicklingError Error raised when an unpicklable object is encountered by Pickler. It inherits PickleError. Refer to What can be pickled and unpickled? to learn what kinds of objects can be pickled. exception pickle.UnpicklingError Error raised when there is a problem unpickling an object, such as a data corruption or a security violation. It inherits PickleError. Note that other exceptions may also be raised during unpickling, including (but not necessarily limited to) AttributeError, EOFError, ImportError, and IndexError. """ This sounds like unpicklable objects should raise a `PicklingError`. Indeed, if I do this, `pickle.dumps` gives me (my own) `PicklingError`: Python 3.3.2 (default, Nov 8 2013, 13:38:57) [GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pickle >>> class X: ... def __getstate__(self): ... raise pickle.PicklingError("can't pickle X objects") ... >>> x = X() >>> pickle.dumps(x) Traceback (most recent call last): File "", line 1, in File "", line 3, in __getstate__ _pickle.PicklingError: can't pickle X objects What now confuses me is that most, if not all, objects from the standard library that aren't picklable raise a `TypeError` when I try to pickle them: >>> fobj = open("/etc/passwd") >>> pickle.dumps(fobj) Traceback (most recent call last): File "", line 1, in TypeError: cannot serialize '_io.TextIOWrapper' object >>> import socket >>> s = socket.socket() >>> pickle.dumps(s) Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python3.3/socket.py", line 116, in __getstate__ raise TypeError("Cannot serialize socket object") TypeError: Cannot serialize socket object So the documentation for the `pickle` module (to me) implies I should raise a `PicklingError` while the standard library usually seems to use a `TypeError`. When I grep through the library files for `PicklingError`, I get very few hits, most of them in `pickle.py`: $ find /usr/lib64/python3.3 -name "*.py" -exec grep -H PicklingError {} \; /usr/lib64/python3.3/site-packages/numpy/numarray/session.py: except (pickle.PicklingError, TypeError, SystemError): /usr/lib64/python3.3/pickle.py:__all__ = ["PickleError", "PicklingError", "UnpicklingError", "Pickler", /usr/lib64/python3.3/pickle.py:class PicklingError(PickleError): /usr/lib64/python3.3/pickle.py: raise PicklingError("Pickler.__init__() was not called by " /usr/lib64/python3.3/pickle.py: raise PicklingError("Can't pickle %r object: %r" % /usr/lib64/python3.3/pickle.py: raise PicklingError("%s must return string or tuple" % reduce) /usr/lib64/python3.3/pickle.py: raise PicklingError("Tuple returned by %s must have " /usr/lib64/python3.3/pickle.py: raise PicklingError("args from save_reduce() should be a tuple") /usr/lib64/python3.3/pickle.py: raise PicklingError("func from save_reduce() should be callable") /usr/lib64/python3.3/pickle.py: raise PicklingError( /usr/lib64/python3.3/pickle.py: raise PicklingError( /usr/lib64/python3.3/pickle.py: raise PicklingError( /usr/lib64/python3.3/pickle.py: raise PicklingError( /usr/lib64/python3.3/pickle.py: raise PicklingError( /usr/lib64/python3.3/idlelib/rpc.py: except pickle.PicklingError: Which exception would you raise for an object that can't be pickled and why? [1] http://ftputil.sschwarzer.net/trac/ticket/75 [2] https://docs.python.org/3.4/library/pickle.html Best regards, Stefan From python.list at tim.thechases.com Mon Apr 21 09:39:10 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 21 Apr 2014 08:39:10 -0500 Subject: symple programming task In-Reply-To: <7f496a70-6b85-4bc9-bf33-7aeaad813d11@googlegroups.com> References: <7f496a70-6b85-4bc9-bf33-7aeaad813d11@googlegroups.com> Message-ID: <20140421083910.01ac5e8e@bigbox.christie.dr> On 2014-04-21 06:21, Ivan Ivanivich wrote: > > Find the sum of all the multiples of 3 or 5 below 1000. > my new version of script: > > total = 0 > div1 = 3 > div2 = 5 > for basis in range(0, 1000): > mod = basis % div1 > if mod == 0: > total = total + basis > continue > mod = basis % div2 > if mod == 0: > total = total + basis > continue > > > > print("total = ", total) Now that you have a working solution, I don't mind giving my more pythonic solution: sum(dividend for dividend in range(1000) if any(dividend % divisor == 0 for divisor in (3, 5))) which succinctly states the problem and makes it easy to add/remove/change the divisors in one place rather than having to define multiple variables to hold them and "if" statements to evaluate them. -tkc From rosuav at gmail.com Mon Apr 21 09:43:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Apr 2014 23:43:50 +1000 Subject: symple programming task In-Reply-To: <7f496a70-6b85-4bc9-bf33-7aeaad813d11@googlegroups.com> References: <7f496a70-6b85-4bc9-bf33-7aeaad813d11@googlegroups.com> Message-ID: On Mon, Apr 21, 2014 at 11:21 PM, Ivan Ivanivich wrote: > if "basis" is 15, then "mod" == 0 twice - when the "divider" is 3 and 15 Good! Yes, you worked out exactly what the problem is. :) There are ways to simplify your code, but it's now giving the correct result, so that's the most important thing. ChrisA From skip at pobox.com Mon Apr 21 10:06:14 2014 From: skip at pobox.com (Skip Montanaro) Date: Mon, 21 Apr 2014 09:06:14 -0500 Subject: selective (inheriting?) dir()? Message-ID: Before I get up to my neck in gators over this, I was hoping perhaps someone already had a solution. Suppose I have two classes, A and B, the latter inheriting from the former: class A: def __init__(self): self.x = 0 class B(A): def __init__(self): A.__init__(self) self.y = 1 inst_b = B() Now, dir(inst_b) will list both 'x' and 'y' as attributes (along with the various under under attributes). Without examining the source, is it possible to define some kind of "selective" dir, with a API like def selective_dir(inst, class_): pass which will list only those attributes of inst which were first defined in (some method defined by) class_? The output of calls with different class_ args would yield different lists: selective_dir(inst_b, B) -> ['y'] selective_dir(inst_b, A) -> ['x'] I'm thinking some sort of gymnastics with inspect might do the trick, but after a quick skim of that module's functions nothing leapt out at me. OTOH, working through the code objects for the methods looks potentially promising: >>> B.__init__.im_func.func_code.co_names ('A', '__init__', 'y') >>> A.__init__.im_func.func_code.co_names ('x',) Thx, Skip From ne0stigmine at 163.com Mon Apr 21 10:13:08 2014 From: ne0stigmine at 163.com (lee) Date: Mon, 21 Apr 2014 22:13:08 +0800 (CST) Subject: which book to read next?? Message-ID: <2e926609.d361.14584a21eae.Coremail.ne0stigmine@163.com> Hi, I have read the book 'a byte of python' and now I want to read another book. But I just get confused about which one to read next. There is a book list below? 1, pro python 2, python algorithms 3, python cookbook 4, the python standard library by examples which one is suitable for me?? Or I need to start a project with pygame or flask? Thanks for your help! -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Apr 21 10:38:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Apr 2014 00:38:16 +1000 Subject: selective (inheriting?) dir()? In-Reply-To: References: Message-ID: On Tue, Apr 22, 2014 at 12:06 AM, Skip Montanaro wrote: > Without examining the source, is > it possible to define some kind of "selective" dir, with a API like > > def selective_dir(inst, class_): pass > > which will list only those attributes of inst which were first defined > in (some method defined by) class_? The output of calls with different > class_ args would yield different lists: > > selective_dir(inst_b, B) -> ['y'] > > selective_dir(inst_b, A) -> ['x'] > > I'm thinking some sort of gymnastics with inspect might do the trick, > but after a quick skim of that module's functions nothing leapt out at > me. Hmm. Interesting. Fundamentally, attributes in Python don't give you anything about which class they were defined in... by default. However, it ought to be possible to play around with the metaclass; it could detect that you're creating a new attribute and record that somewhere. But if you know that all the attributes you care about are set in __init__, you could do some analysis on that, as you were looking at. Might turn out to be a lot of work to dig through the compiled code, though. ChrisA From steve+comp.lang.python at pearwood.info Mon Apr 21 11:28:52 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Apr 2014 15:28:52 GMT Subject: selective (inheriting?) dir()? References: Message-ID: <53553933$0$29993$c3e8da3$5496439d@news.astraweb.com> On Mon, 21 Apr 2014 09:06:14 -0500, Skip Montanaro wrote: [...] > Now, dir(inst_b) will list both 'x' and 'y' as attributes (along with > the various under under attributes). Without examining the source, is it > possible to define some kind of "selective" dir, with a API like > > def selective_dir(inst, class_): pass > > which will list only those attributes of inst which were first defined > in (some method defined by) class_? The output of calls with different > class_ args would yield different lists: > > selective_dir(inst_b, B) -> ['y'] > > selective_dir(inst_b, A) -> ['x'] In general, no. There's no way of telling what method added an attribute after the event has taken place: given that instance.__dict__ has a key "x", how do you know how it got there? You may be able to do this cooperatively: have both A and B define a __dir__ method which lists only the attributes they contribute, then call dir(A) or dir(B) as necessary. Or, if you find yourself in the position of having an instance of both A and B, say, a and b, you can compare dir(a) and dir(b). Anything in the later but not in the former probably was added by B not A. I say "probably" because one might have things like this: class A: def __init__(self): if type(self) is not A: self.y = "Surprise!" self.x = "something" and of course don't forget that attributes can be added by external entities too: instance = A() instance.z = "bet you forgot about this" > I'm thinking some sort of gymnastics with inspect might do the trick, > but after a quick skim of that module's functions nothing leapt out at > me. OTOH, working through the code objects for the methods looks > potentially promising: > >>>> B.__init__.im_func.func_code.co_names > ('A', '__init__', 'y') >>>> A.__init__.im_func.func_code.co_names > ('x',) You may have a bit of difficulty with classes that write directly to the __dict__, or use setattr, or eval. -- Steven D'Aprano http://import-that.dreamwidth.org/ From alan.gauld at btinternet.com Mon Apr 21 11:41:22 2014 From: alan.gauld at btinternet.com (Alan Gauld) Date: Mon, 21 Apr 2014 16:41:22 +0100 Subject: which book to read next?? In-Reply-To: <2e926609.d361.14584a21eae.Coremail.ne0stigmine@163.com> References: <2e926609.d361.14584a21eae.Coremail.ne0stigmine@163.com> Message-ID: On 21/04/14 15:13, lee wrote: > Hi, I have read the book 'a byte of python' and now I want to read > another book. But I just get confused about which one to read next. > There is a book list below? > 1, pro python > 2, python algorithms > 3, python cookbook > 4, the python standard library by examples > which one is suitable for me?? We would need to know a lot more about you. What is your skill level in programming (as opposed to python)? What are your areas of interest? What is your preferred teaching style? In depth background detail or surface level but hands-on style? Book choice is always a very personal thing. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos From skip at pobox.com Mon Apr 21 11:52:49 2014 From: skip at pobox.com (Skip Montanaro) Date: Mon, 21 Apr 2014 10:52:49 -0500 Subject: selective (inheriting?) dir()? In-Reply-To: <53553933$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <53553933$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: Thanks for the responses. I'm not really interested in perfection here. I do most of my programming in a mature internally developed platform written in Python. As the platform has grown and approaches to different problems have changed 12-15 year period, some of the classes which are instantiated have grown quite a few attributes which are not interesting on a day-to-day basis. As I often query my objects at runtime and use dir() to jog my memory about what's changing, it would be nice to eliminate most attributes defined by and only used by base classes. Thanks for the suggestion of writing a custom __dir__ method. I hadn't considered that. It was fairly straightforward to build its attribute list on-the-fly, taking a snapshot of attributes just after the base class __init__ method was call, and again after initialization was complete. The only trick was to leave __dir__ undefined until after that little dance was complete. Skip On Mon, Apr 21, 2014 at 10:28 AM, Steven D'Aprano wrote: > On Mon, 21 Apr 2014 09:06:14 -0500, Skip Montanaro wrote: > > [...] >> Now, dir(inst_b) will list both 'x' and 'y' as attributes (along with >> the various under under attributes). Without examining the source, is it >> possible to define some kind of "selective" dir, with a API like >> >> def selective_dir(inst, class_): pass >> >> which will list only those attributes of inst which were first defined >> in (some method defined by) class_? The output of calls with different >> class_ args would yield different lists: >> >> selective_dir(inst_b, B) -> ['y'] >> >> selective_dir(inst_b, A) -> ['x'] > > In general, no. There's no way of telling what method added an attribute > after the event has taken place: given that instance.__dict__ has a key > "x", how do you know how it got there? > > You may be able to do this cooperatively: have both A and B define a > __dir__ method which lists only the attributes they contribute, then call > dir(A) or dir(B) as necessary. > > Or, if you find yourself in the position of having an instance of both A > and B, say, a and b, you can compare dir(a) and dir(b). Anything in the > later but not in the former probably was added by B not A. > > I say "probably" because one might have things like this: > > class A: > def __init__(self): > if type(self) is not A: > self.y = "Surprise!" > self.x = "something" > > and of course don't forget that attributes can be added by external > entities too: > > instance = A() > instance.z = "bet you forgot about this" > > >> I'm thinking some sort of gymnastics with inspect might do the trick, >> but after a quick skim of that module's functions nothing leapt out at >> me. OTOH, working through the code objects for the methods looks >> potentially promising: >> >>>>> B.__init__.im_func.func_code.co_names >> ('A', '__init__', 'y') >>>>> A.__init__.im_func.func_code.co_names >> ('x',) > > > You may have a bit of difficulty with classes that write directly to the > __dict__, or use setattr, or eval. > > > > -- > Steven D'Aprano > http://import-that.dreamwidth.org/ > -- > https://mail.python.org/mailman/listinfo/python-list From joel.goldstick at gmail.com Mon Apr 21 12:08:38 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 21 Apr 2014 12:08:38 -0400 Subject: which book to read next?? In-Reply-To: References: <2e926609.d361.14584a21eae.Coremail.ne0stigmine@163.com> Message-ID: On Mon, Apr 21, 2014 at 11:41 AM, Alan Gauld wrote: > On 21/04/14 15:13, lee wrote: > >> Hi, I have read the book 'a byte of python' and now I want to read >> another book. But I just get confused about which one to read next. >> There is a book list below? >> 1, pro python >> 2, python algorithms >> 3, python cookbook >> 4, the python standard library by examples >> which one is suitable for me?? >> > > We would need to know a lot more about you. > What is your skill level in programming (as opposed to python)? > What are your areas of interest? > What is your preferred teaching style? In depth background > detail or surface level but hands-on style? > > Book choice is always a very personal thing. > > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.flickr.com/photos/alangauldphotos > > -- > https://mail.python.org/mailman/listinfo/python-list > Don't forget to look at the python.org site: https://wiki.python.org/moin/BeginnersGuide -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Mon Apr 21 12:20:02 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 21 Apr 2014 11:20:02 -0500 Subject: which book to read next?? In-Reply-To: <2e926609.d361.14584a21eae.Coremail.ne0stigmine@163.com> References: <2e926609.d361.14584a21eae.Coremail.ne0stigmine@163.com> Message-ID: <20140421112002.55eb5554@bigbox.christie.dr> On 2014-04-21 22:13, lee wrote: > Hi, I have read the book 'a byte of python' and now I want to read > another book. But I just get confused about which one to read next. > There is a book list below? 1, pro python > 2, python algorithms > 3, python cookbook > 4, the python standard library by examples > which one is suitable for me?? > Or I need to start a project with pygame or flask? Once you've got the basics (which it seems like you do have now), I'd find a problem you have and use Python to solve it. E.g.: Problem: I'm bored Solution: write yourself a game in pygame P: I want to create a website to do X S: Use django/flask to do such P: I want to answer some questions about this set of data S: write some Python code to parse the data & produce answers P: I'm poor S: use Python to solve problems for other people and have them pay you You can keep reading books, but if you don't have something to actually create from using this knowledge, it's a somewhat worthless academic exercise. -tkc From rosuav at gmail.com Mon Apr 21 12:22:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Apr 2014 02:22:35 +1000 Subject: which book to read next?? In-Reply-To: <20140421112002.55eb5554@bigbox.christie.dr> References: <2e926609.d361.14584a21eae.Coremail.ne0stigmine@163.com> <20140421112002.55eb5554@bigbox.christie.dr> Message-ID: On Tue, Apr 22, 2014 at 2:20 AM, Tim Chase wrote: > Problem: I'm bored > Solution: write yourself a game in pygame Alternative solution: Join python-ideas as well as python-list, and pledge to read *every* post. ChrisA From breamoreboy at yahoo.co.uk Mon Apr 21 13:10:51 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 21 Apr 2014 18:10:51 +0100 Subject: which book to read next?? In-Reply-To: References: <2e926609.d361.14584a21eae.Coremail.ne0stigmine@163.com> <20140421112002.55eb5554@bigbox.christie.dr> Message-ID: On 21/04/2014 17:22, Chris Angelico wrote: > On Tue, Apr 22, 2014 at 2:20 AM, Tim Chase > wrote: >> Problem: I'm bored >> Solution: write yourself a game in pygame > > Alternative solution: Join python-ideas as well as python-list, and > pledge to read *every* post. > > ChrisA > Alternative alternative solution: Join python-bugs as well as python-list, and pledge to help out on *every* issue seen :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ne0stigmine at 163.com Mon Apr 21 12:57:45 2014 From: ne0stigmine at 163.com (lee) Date: Tue, 22 Apr 2014 00:57:45 +0800 Subject: which book to read next?? Message-ID: <1398099463493.pleh5lfn50d3mados3bjem2p@android.mail.163.com> Thanks for all of the respones, Writing a game in pygame is a good idea. Thank you! -- ?? Android ???? -------------- next part -------------- An HTML attachment was scrubbed... URL: From miki.tebeka at gmail.com Mon Apr 21 15:03:17 2014 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 21 Apr 2014 12:03:17 -0700 (PDT) Subject: [OT] Testing and credentials best practices? In-Reply-To: References: <267e12d3-ea01-4886-bfa7-5c7270adbe92@googlegroups.com> Message-ID: >> How do you deal with tests (both on dev machine and Jenkins) that need credentials (such as AWS keys)?. > I've done several of these. Another option that may work in some > contexts is to mock the test altogether; Thanks, but mocking is last resort for me, it reduces the value of testing greatly and has the burden of catching up with the mocked service. From tjreedy at udel.edu Mon Apr 21 17:08:17 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 21 Apr 2014 17:08:17 -0400 Subject: Recommended exception for objects that can't be pickled In-Reply-To: <53551BBA.8000205@sschwarzer.net> References: <53551BBA.8000205@sschwarzer.net> Message-ID: On 4/21/2014 9:23 AM, Stefan Schwarzer wrote: > Hi, > > Recently, I got a request [1] to support pickling of > `FTPHost` instances in my `ftplib` library. > > I explained in the ticket why I think it's a bad idea and > now want to make explicit that `FTPHost` objects can't be > pickled. The usual way to do this seems to be defining a > `__getstate__` method and raise an exception there. > > Now the question is "which exception?" and my research left > me a bit confused. I didn't find a recommendation for this > on the web, not even in the Python documentation for the > `pickle` module [2]. The only hint is that the documentation > states: > > """ > The pickle module defines three exceptions: > > exception pickle.PickleError > > Common base class for the other pickling exceptions. It > inherits Exception. > > exception pickle.PicklingError > > Error raised when an unpicklable object is encountered > by Pickler. It inherits PickleError. I am going to read this as 'unpicklable as determined by Pickler', possibly due to a bug in the objects methods. > Refer to What can be pickled and unpickled? to learn > what kinds of objects can be pickled. > > exception pickle.UnpicklingError > > Error raised when there is a problem unpickling an > object, such as a data corruption or a security > violation. It inherits PickleError. > > Note that other exceptions may also be raised during > unpickling, including (but not necessarily limited to) > AttributeError, EOFError, ImportError, and IndexError. > """ > > This sounds like unpicklable objects should raise a > `PicklingError`. Indeed, if I do this, `pickle.dumps` > gives me (my own) `PicklingError`: > > Python 3.3.2 (default, Nov 8 2013, 13:38:57) > [GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import pickle > >>> class X: > ... def __getstate__(self): > ... raise pickle.PicklingError("can't pickle X objects") > ... > >>> x = X() > >>> pickle.dumps(x) > Traceback (most recent call last): > File "", line 1, in > File "", line 3, in __getstate__ > _pickle.PicklingError: can't pickle X objects > > What now confuses me is that most, if not all, objects from > the standard library that aren't picklable raise a > `TypeError` when I try to pickle them: > > >>> fobj = open("/etc/passwd") > >>> pickle.dumps(fobj) > Traceback (most recent call last): > File "", line 1, in > TypeError: cannot serialize '_io.TextIOWrapper' object > > >>> import socket > >>> s = socket.socket() > >>> pickle.dumps(s) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib64/python3.3/socket.py", line 116, in __getstate__ > raise TypeError("Cannot serialize socket object") > TypeError: Cannot serialize socket object I would just copy the socket.__getstate__, with a revised message. > So the documentation for the `pickle` module (to me) implies > I should raise a `PicklingError` while the standard library > usually seems to use a `TypeError`. When I grep through the > library files for `PicklingError`, I get very few hits, most > of them in `pickle.py`: This suggests that the exception is intended for use by Pickler, and not by user code. The reason is pretty subtle and not explained in the doc. See below. > $ find /usr/lib64/python3.3 -name "*.py" -exec grep -H PicklingError {} \; > /usr/lib64/python3.3/site-packages/numpy/numarray/session.py: except (pickle.PicklingError, TypeError, SystemError): > /usr/lib64/python3.3/pickle.py:__all__ = ["PickleError", "PicklingError", "UnpicklingError", "Pickler", > /usr/lib64/python3.3/pickle.py:class PicklingError(PickleError): > /usr/lib64/python3.3/pickle.py: raise PicklingError("Pickler.__init__() was not called by " > /usr/lib64/python3.3/pickle.py: raise PicklingError("Can't pickle %r object: %r" % > /usr/lib64/python3.3/pickle.py: raise PicklingError("%s must return string or tuple" % reduce) > /usr/lib64/python3.3/pickle.py: raise PicklingError("Tuple returned by %s must have " > /usr/lib64/python3.3/pickle.py: raise PicklingError("args from save_reduce() should be a tuple") > /usr/lib64/python3.3/pickle.py: raise PicklingError("func from save_reduce() should be callable") Most of the above look like bugs in code intended to work with Pickle. In other words, if you user gets a TypeError, the user has made a mistake by trying to pickle your object. If you tried to make your object picklable, and users got PicklingError, that would indicate a bug in your class code, not the users' use of your class. > /usr/lib64/python3.3/pickle.py: raise PicklingError( > /usr/lib64/python3.3/pickle.py: raise PicklingError( > /usr/lib64/python3.3/pickle.py: raise PicklingError( > /usr/lib64/python3.3/pickle.py: raise PicklingError( > /usr/lib64/python3.3/pickle.py: raise PicklingError( > /usr/lib64/python3.3/idlelib/rpc.py: except pickle.PicklingError: > > Which exception would you raise for an object that can't be > pickled and why? TypeError, as explained above. > [1] http://ftputil.sschwarzer.net/trac/ticket/75 > [2] https://docs.python.org/3.4/library/pickle.html -- Terry Jan Reedy From tjreedy at udel.edu Mon Apr 21 17:16:47 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 21 Apr 2014 17:16:47 -0400 Subject: selective (inheriting?) dir()? In-Reply-To: References: Message-ID: On 4/21/2014 10:06 AM, Skip Montanaro wrote: > Before I get up to my neck in gators over this, I was hoping perhaps > someone already had a solution. Suppose I have two classes, A and B, > the latter inheriting from the former: > > class A: > def __init__(self): > self.x = 0 > > class B(A): > def __init__(self): > A.__init__(self) > self.y = 1 > > inst_b = B() > > Now, dir(inst_b) will list both 'x' and 'y' as attributes (along with > the various under under attributes). Without examining the source, is > it possible to define some kind of "selective" dir, with a API like > > def selective_dir(inst, class_): pass > > which will list only those attributes of inst which were first defined > in (some method defined by) class_? The output of calls with different > class_ args would yield different lists: > > selective_dir(inst_b, B) -> ['y'] > > selective_dir(inst_b, A) -> ['x'] > > I'm thinking some sort of gymnastics with inspect might do the trick, > but after a quick skim of that module's functions nothing leapt out at > me. OTOH, working through the code objects for the methods looks > potentially promising: > >>>> B.__init__.im_func.func_code.co_names > ('A', '__init__', 'y') >>>> A.__init__.im_func.func_code.co_names > ('x',) You can permanently affect dir(ob) with a special method. object.__dir__(self) Called when dir() is called on the object. A sequence must be returned. dir() converts the returned sequence to a list and sorts it. From outside the class, you get the attributes defined directly in a class klass as the difference of set(dir(klass) and the union of set(dir(base)) for base in klass.__bases__. To include attributes set in __new__ and __init__, replace klass with klass(). -- Terry Jan Reedy From emile at fenx.com Mon Apr 21 17:32:06 2014 From: emile at fenx.com (Emile van Sebille) Date: Mon, 21 Apr 2014 14:32:06 -0700 Subject: which book to read next?? In-Reply-To: <2e926609.d361.14584a21eae.Coremail.ne0stigmine@163.com> References: <2e926609.d361.14584a21eae.Coremail.ne0stigmine@163.com> Message-ID: On 4/21/2014 7:13 AM, lee wrote: > 4, the python standard library by examples I'd take this on -- it provides a comprehensive overview of what's where in the standard library which you'll likely use a lot. > which one is suitable for me?? That we can't answer. :) Emile From greg.ewing at canterbury.ac.nz Mon Apr 21 17:58:12 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 22 Apr 2014 09:58:12 +1200 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <535493d4$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > Earlier it was said that having both / and // lets you explicitly > choose whether you want a float result or an int by picking an > operator. I'm saying that's not so; the operator and the type aren't > quite orthogonal, but close to. I don't think I said that, or if I did I was using sloppy language. As someone pointed out a couple of posts ago, it's not really about types, it's about selecting which *operation* you want to perform. Ordinary division and floor division are very different operations, and you want to be sure you get the right one. -- Greg From greg.ewing at canterbury.ac.nz Mon Apr 21 18:28:57 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 22 Apr 2014 10:28:57 +1200 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <535493d4$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > All other basic arithmetic operations on two numbers of the same type > results in another number of that type. ... There's > just one special case: dividing an integer by an integer yields a > float, if and only if you use truediv. It sticks out as an exception. I take your point, but I think this is a case where practicality beats purity by a large margin. The idea that arithmetic should always give a result of the same type is all very nice in theory, but it just isn't practical where division is concerned. The reason it doesn't work well is because of the automatic promotion of ints to floats when they meet other floats. This leads to a style where people often use ints to stand for int-valued floats and expect them to be promoted where necessary. Things would be different if ints and floats were completely separate types, like str and bytes, but that would be extremely inconvenient. I used a language like that once, and it wasn't a pleasant experience. -- Greg From rosuav at gmail.com Mon Apr 21 18:43:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Apr 2014 08:43:09 +1000 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <535493d4$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 22, 2014 at 8:28 AM, Gregory Ewing wrote: > The reason it doesn't work well is because of the > automatic promotion of ints to floats when they meet > other floats. This leads to a style where people often > use ints to stand for int-valued floats and expect > them to be promoted where necessary. > > Things would be different if ints and floats were > completely separate types, like str and bytes, but > that would be extremely inconvenient. I used a language > like that once, and it wasn't a pleasant experience. I do see that there are two sides to this. The question of "Is 1.0 equal to 1?" has a very obvious answer... whichever answer you go with, it's absolutely obvious! (Yes! They're the same number, of course they're equal! vs No! They're completely different representations, like 1 and "1" and "\1" are all different!) Separating the types makes very good sense, and unifying them makes very good sense, and for different reasons. Unifying them in as many ways as possible means you don't need the syntactic salt of ".0" on every number; you should be able to add 2.5+1 and get 3.5, just as if you'd added 2.5+1.0. And that's fine. Separating them also makes sense, though; it means that an operation on Type X and Type Y will behave equally sanely regardless of the values of those objects. As it is, we have the case that most lowish integers have equivalent floats (all integers within the range that most people use them), and beyond that, you have problems. This is, in my opinion, analogous to a UTF-16 string type; if you work with strings of nothing but BMP characters, everything works perfectly, but put in an astral character and things may or may not work. A lot of operations will work fine, but just a few will break. Python 3 has fixed that by giving us the pain of transition *right at the beginning*; you look at Text and at Bytes as completely separate things. People who like their ASCII like the idea that the letter "A" is equivalent to the byte 0x41. It's convenient, it's easy. But it leads to problems later. Now, the analogy does break down a bit in that it's probably more likely that a program will have to deal with non-ASCII characters than with integers that can't be represented in IEEE double precision. But would you rather have to deal with the problem straight away, or when your program is some day given a much bigger number to swallow, and it quietly rounds it off to the nearest multiple of 8? ChrisA From ikorot01 at gmail.com Mon Apr 21 22:38:40 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 21 Apr 2014 19:38:40 -0700 Subject: How to properly get the microseconds from the timestamps? Message-ID: Hi, ALL, C:\Documents and Settings\Igor.FORDANWORK\My Documents\GitHub\webapp\django\mysql_db_loader>python Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import datetime >>> datetime.datetime.fromtimestamp(1092787200) datetime.datetime(2004, 8, 17, 17, 0) >>> datetime.datetime.fromtimestamp(1092787200/1000.0) datetime.datetime(1970, 1, 13, 7, 33, 7, 200000) Is there a way to know if the timestamp has a microseconds? Thank you. From rustompmody at gmail.com Mon Apr 21 23:57:39 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 21 Apr 2014 20:57:39 -0700 (PDT) Subject: Unicode in Python In-Reply-To: <53539a64$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <53539a64$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sunday, April 20, 2014 3:29:00 PM UTC+5:30, Steven D'Aprano wrote: > On Fri, 18 Apr 2014 23:40:18 -0700, Paul Rubin wrote: > > > It's just that the improvement > > from 2 to 3 is rather small, and 2 works perfectly well and people are > > used to it, so they keep using it. > > > Spoken like a true ASCII user :-) Heh! > > The "killer feature" of Python 3 is improved handling of Unicode, which > now brings Python 3 firmly into the (very small) group of programming > languages with first-class support for more than 128 different characters > by default. As a unicode user (ok wannabe unicode user :D ) Ive written up some unicode ideas that have been discussed here in the last couple of weeks: http://blog.languager.org/2014/04/unicoded-python.html If Ive non or misattributed some ideas please excuse and let me know! From tjreedy at udel.edu Tue Apr 22 01:44:17 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 22 Apr 2014 01:44:17 -0400 Subject: Unicode in Python In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <53539a64$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/21/2014 11:57 PM, Rustom Mody wrote: > As a unicode user (ok wannabe unicode user :D ) Ive > written up some unicode ideas that have been discussed here in the > last couple of weeks: > > http://blog.languager.org/2014/04/unicoded-python.html "With python 3 we are at a stage where python programs can support unicode well however python program- source is still completely ASCII." In Python 3, "Python reads program text as Unicode code points; the encoding of a source file can be given by an encoding declaration and defaults to UTF-8". Why start off with an erroneous statement, which you even know and show is erroneous? -- Terry Jan Reedy From greg.ewing at canterbury.ac.nz Tue Apr 22 02:03:32 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 22 Apr 2014 18:03:32 +1200 Subject: Why Python 3? In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <535493d4$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > As it > is, we have the case that most lowish integers have equivalent floats > (all integers within the range that most people use them), and beyond > that, you have problems. No, I don't. I'm not talking about representing ints using floats, I'm talking about representing floats using ints. *Every* possible integer-valued float value can be written exactly as a Python int. It doesn't matter that there are some ints that can't be represented as floats, because when I'm writing an int literal as a shorthand for a float, I'm not going to be using any of those values -- or if I do, I'm willing to accept the resulting loss of precision, because in my mind they're *not* ints, they're floats. > But > would you rather have to deal with the problem straight away, or when > your program is some day given a much bigger number to swallow, and it > quietly rounds it off to the nearest multiple of 8? I don't understand what problem you're imagining here. Any program that needs to do exact calculations with integer values should work with ints throughout and use // or divmod() if it needs to do any division. Nothing will get unexpectedly rounded off then. -- Greg From steve at pearwood.info Tue Apr 22 02:11:56 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 22 Apr 2014 06:11:56 GMT Subject: Unicode in Python References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <53539a64$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5356082c$0$11109$c3e8da3@news.astraweb.com> On Mon, 21 Apr 2014 20:57:39 -0700, Rustom Mody wrote: > As a unicode user (ok wannabe unicode user :D ) Ive written up some > unicode ideas that have been discussed here in the last couple of weeks: > > http://blog.languager.org/2014/04/unicoded-python.html What you are talking about is not handling Unicode with Python, but extending the programming language to allow non-English *letters* to be used as if they were *symbols*. That's very problematic, since it assumes that nobody would ever want to use non-English letters in an alphanumeric context. You write: [quote] Now to move ahead! We dont[sic] want >>> ? = 1 >>> ? 1 We want >>> (?x : x+1)(2) 3 [end quote] (Speak for yourself.) But this is a problem. Suppose I want to use a Greek word as a variable, as Python allows me to do: ????? = "a word" Or perhaps as the parameter to a function. Take the random.expovariate function, which currently takes an argument "lambd" (since lambda is a reserved word). I might write instead: def expovariate(self, ?): ... After all, ? is an ordinary letter of the (Greek) alphabet, why shouldn't it be used in variable names? But if "?x" is syntax for "lambda x", then I'm going to get syntax errors: ????? = "a word" => like: lambda ???? = "a word" def expovariate(self, ?): => like: def expovariate(self, lambda): both of which are obviously syntax errors. This is as hostile to Greek-using programmers as deciding that "f" should be reserved for functions would be to English-using programmers: # space between the f and the function name is not needed fspam(x, y): ... class Thingy: f__init__(selF): ... fmethod(selF, arg): return arg + 1 Notice that I can't even write "self" any more, since that gives a syntax error. Presumable "if" is okay, as it is a keyword. Using Unicode *symbols* rather than non-English letters is less of a problem, since they aren't valid in identifiers. More comments to follow later. -- Steven From rustompmody at gmail.com Tue Apr 22 02:18:34 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 21 Apr 2014 23:18:34 -0700 (PDT) Subject: Unicode in Python In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <53539a64$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7a873fe6-a2fa-4c77-bb3a-b00eab2f7cff@googlegroups.com> On Tuesday, April 22, 2014 11:14:17 AM UTC+5:30, Terry Reedy wrote: > On 4/21/2014 11:57 PM, Rustom Mody wrote: > > As a unicode user (ok wannabe unicode user :D ) Ive > > written up some unicode ideas that have been discussed here in the > > last couple of weeks: > > http://blog.languager.org/2014/04/unicoded-python.html > "With python 3 we are at a stage where python programs can support > unicode well however python program- source is still completely ASCII." > In Python 3, "Python reads program text as Unicode code points; the > encoding of a source file can be given by an encoding declaration and > defaults to UTF-8". Why start off with an erroneous statement, which you > even know and show is erroneous? Ok Ive reworded it to make it clear that I am referring to the character-sets and not encodings. From ian.g.kelly at gmail.com Tue Apr 22 02:31:06 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 22 Apr 2014 00:31:06 -0600 Subject: Unicode in Python In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <53539a64$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 22, 2014 12:01 AM, "Rustom Mody" wrote: > As a unicode user (ok wannabe unicode user :D ) Ive > written up some unicode ideas that have been discussed here in the > last couple of weeks: > > http://blog.languager.org/2014/04/unicoded-python.html I'm reminded of this satire: http://www.ojohaven.com/fun/spelling.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Apr 22 02:32:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Apr 2014 16:32:58 +1000 Subject: Unicode in Python In-Reply-To: <7a873fe6-a2fa-4c77-bb3a-b00eab2f7cff@googlegroups.com> References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <53539a64$0$29993$c3e8da3$5496439d@news.astraweb.com> <7a873fe6-a2fa-4c77-bb3a-b00eab2f7cff@googlegroups.com> Message-ID: On Tue, Apr 22, 2014 at 4:18 PM, Rustom Mody wrote: > Ive reworded it to make it clear that I am referring to the character-sets and > not encodings. It's still false, and was in Python 2 as well. The only difference on that front is that, in the absence of an encoding cookie, Python 2 defaults to ASCII while Python 3 defaults to UTF-8. PEP 263 explains the feature as it was added to Py2; PEP 3120 makes the change to a UTF-8 default. Python source code is Unicode text, and has been since 2001 and Python 2.3. ChrisA From rustompmody at gmail.com Tue Apr 22 02:30:45 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 21 Apr 2014 23:30:45 -0700 (PDT) Subject: Unicode in Python In-Reply-To: <5356082c$0$11109$c3e8da3@news.astraweb.com> References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <53539a64$0$29993$c3e8da3$5496439d@news.astraweb.com> <5356082c$0$11109$c3e8da3@news.astraweb.com> Message-ID: <9f94f6b0-ba35-41dc-95a5-48018412fdf6@googlegroups.com> On Tuesday, April 22, 2014 11:41:56 AM UTC+5:30, Steven D'Aprano wrote: > On Mon, 21 Apr 2014 20:57:39 -0700, Rustom Mody wrote: > > As a unicode user (ok wannabe unicode user :D ) Ive written up some > > unicode ideas that have been discussed here in the last couple of weeks: > > http://blog.languager.org/2014/04/unicoded-python.html > What you are talking about is not handling Unicode with Python, but > extending the programming language to allow non-English *letters* to be > used as if they were *symbols*. > That's very problematic, since it assumes that nobody would ever want to > use non-English letters in an alphanumeric context. You write: > [quote] > Now to move ahead! > We dont[sic] want > >>> ? = 1 > >>> ? > 1 > We want > >>> (?x : x+1)(2) > 3 > [end quote] > (Speak for yourself.) But this is a problem. Suppose I want to use a > Greek word as a variable, as Python allows me to do: > ????? = "a word" > Or perhaps as the parameter to a function. Take the random.expovariate > function, which currently takes an argument "lambd" (since lambda is a > reserved word). I might write instead: > def expovariate(self, ?): ... > After all, ? is an ordinary letter of the (Greek) alphabet, why shouldn't > it be used in variable names? But if "?x" is syntax for "lambda x", then > I'm going to get syntax errors: > ????? = "a word" > => like: lambda ???? = "a word" > def expovariate(self, ?): > => like: def expovariate(self, lambda): > both of which are obviously syntax errors. > This is as hostile to Greek-using programmers as deciding that "f" should > be reserved for functions would be to English-using programmers: > # space between the f and the function name is not needed > fspam(x, y): > ... > class Thingy: > f__init__(selF): > ... > fmethod(selF, arg): > return arg + 1 > Notice that I can't even write "self" any more, since that gives a syntax > error. Presumable "if" is okay, as it is a keyword. > Using Unicode *symbols* rather than non-English letters is less of a > problem, since they aren't valid in identifiers. Ok point taken. So instead of using ? (0x3bb) we should use ? (0x1d740) or something thereabouts like ? From rosuav at gmail.com Tue Apr 22 02:44:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Apr 2014 16:44:03 +1000 Subject: Unicode in Python In-Reply-To: <9f94f6b0-ba35-41dc-95a5-48018412fdf6@googlegroups.com> References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <53539a64$0$29993$c3e8da3$5496439d@news.astraweb.com> <5356082c$0$11109$c3e8da3@news.astraweb.com> <9f94f6b0-ba35-41dc-95a5-48018412fdf6@googlegroups.com> Message-ID: On Tue, Apr 22, 2014 at 4:30 PM, Rustom Mody wrote: > So instead of using ? (0x3bb) we should use ? (0x1d740) or something thereabouts like ? You still have a major problem: How do you type that? It gives you very little advantage over the word "lambda", it introduces readability issues, it's impossible for most people to type (and programming with a palette of arbitrary syntactic tokens isn't my idea of fun), it's harder for a new programmer to get docs for (especially if s/he reads the file in the wrong encoding), and all in all, it's a pretty poor substitute for a word. ChrisA From mok-kong.shen at t-online.de Tue Apr 22 04:36:09 2014 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Tue, 22 Apr 2014 10:36:09 +0200 Subject: Running programs on mobile phones Message-ID: I have seen by chance a number of years ago a book on Python programming for running on mobile phones (of a certain producer only). What is the current state of the art in that? Could someone kindly give a few good literature references? Thanks in advance. M. K. Shen From wxjmfauth at gmail.com Tue Apr 22 05:07:58 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 22 Apr 2014 02:07:58 -0700 (PDT) Subject: Unicode in Python In-Reply-To: <9f94f6b0-ba35-41dc-95a5-48018412fdf6@googlegroups.com> References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <53539a64$0$29993$c3e8da3$5496439d@news.astraweb.com> <5356082c$0$11109$c3e8da3@news.astraweb.com> <9f94f6b0-ba35-41dc-95a5-48018412fdf6@googlegroups.com> Message-ID: <4e5ab7e6-a144-4709-8a6f-7bd540891ed2@googlegroups.com> Le mardi 22 avril 2014 08:30:45 UTC+2, Rustom Mody a ?crit?: > > > @ rusy > "Ive reworded it to make it clear that I am referring to the character-sets and not encodings." Very good, excellent, comment. An healthy coding scheme can only work properly with a unique characters set and the coding is achieved with the help of a unique operator. There is no other way to do it and that's the reason why we have to live today with all these coding schemes (unicode or not). Note: A coding scheme can be much more complex than the coding of "raw" characters (eg. CID fonts). > "So instead of using ? (0x3bb) we should use ? (0x1d740) or something thereabouts like ?" This is a very good understanding of unicode. The letter lambda is not the mathematical symbole lambda. Another example, the micro sign is not the greek letter mu which is not the mathematical mu. Shorly, it's maybe not a bad idea to use a plain ascii "lambda" instead of a wrong unicode point. jmf From vlastimil.brom at gmail.com Tue Apr 22 05:15:17 2014 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 22 Apr 2014 11:15:17 +0200 Subject: How to properly get the microseconds from the timestamps? In-Reply-To: References: Message-ID: 2014-04-22 4:38 GMT+02:00 Igor Korot : ... >>>> datetime.datetime.fromtimestamp(1092787200/1000.0) > datetime.datetime(1970, 1, 13, 7, 33, 7, 200000) > > Is there a way to know if the timestamp has a microseconds? > > Thank you. > -- Hi, I believe, in these cases, you can just test, whether there is a non-integer part in the timestamp in seconds, which will be stored as microseconds accordingly. >>> 1092787200/1000.0 1092787.2 0.2 s is stored (and shown in repr(...)) as 200000 microseconds. There are some peculiarities in handling date and time calculations reliably as well as in the floating point math, but they don't seem to be involved here. From aveinfosys at gmail.com Tue Apr 22 05:21:01 2014 From: aveinfosys at gmail.com (aveinfosys at gmail.com) Date: Tue, 22 Apr 2014 02:21:01 -0700 (PDT) Subject: Best Website Design Services by Professional Web Designing Company Message-ID: <15695c48-33e6-4aa6-bf45-30f3faacfb4f@googlegroups.com> Ave Infosys is a leading professional in Web Designing Company in Hyderabad India for the E-Business Industry.Ave Infosys are providing Best Website Development and Design Services in Hyderabad.Our company offers the Best Web Design & Development services, Web Hosting Services,Responsive and Mobile Designing services,Ecommerce websites services,Digital Marketing Services,Website Design Services. We have intensive web design and web skills merging with the quality essence of expertise should have component to help you to ascertain your internet presence or take it to the next level.we are the Best Web Design Company in Hyderabad. For More Details : Please contact: (+91) 40 40275321 Email : info at aveinfosys.com Web : http://aveinfosys.com/website-design From rustompmody at gmail.com Tue Apr 22 05:23:33 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 22 Apr 2014 02:23:33 -0700 (PDT) Subject: Unicode in Python In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <53539a64$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <644ffa99-8288-460a-afb7-b9c208765892@googlegroups.com> On Tuesday, April 22, 2014 12:01:06 PM UTC+5:30, Ian wrote: > On Apr 22, 2014 12:01 AM, "Rustom Mody" wrote: > > As a unicode user (ok wannabe unicode user :D ) Ive > > written up some unicode ideas that have been discussed here in the > > last couple of weeks: > > http://blog.languager.org/2014/04/unicoded-python.html > I'm reminded of this satire: > http://www.ojohaven.com/fun/spelling.html Ha Ha!! Thanks much for that. Ive been looking for that for years but had no starting point for a search [For some reason I always thought it was Bernard Shaw] From sylvain.thenault at logilab.fr Tue Apr 22 06:04:52 2014 From: sylvain.thenault at logilab.fr (Sylvain =?utf-8?B?VGjDqW5hdWx0?=) Date: Tue, 22 Apr 2014 12:04:52 +0200 Subject: =?utf-8?B?W0FOTl3CoFB5bGlu?= =?utf-8?Q?t?= 1.2 released Message-ID: <20140422100452.GD9494@logilab.fr> Hi there, Pylint 1.2 has been uploaded to pypi by the end of the last week! More info on this heavy release on http://www.logilab.org/blogentry/240019. As usual, feedback and comments welcome. Enjoy! -- Sylvain Th?nault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42) Formations Python, Debian, M?th. Agiles: http://www.logilab.fr/formations D?veloppement logiciel sur mesure: http://www.logilab.fr/services CubicWeb, the semantic web framework: http://www.cubicweb.org From antoon.pardon at rece.vub.ac.be Tue Apr 22 06:29:56 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 22 Apr 2014 12:29:56 +0200 Subject: Strange syntax error, occurs only when script is executed directly Message-ID: <535644A4.6060901@rece.vub.ac.be> I am workin on a solaris 11 machine. The python version is 2.7.6 path to python is /opt/local/bin/python. These are the 15 first lines of the script: #! /opt/local/bin/python class vslice(object): def __init__(self, fun): self.fun = fun def __getitem__(self, inx): if not isinstance(inx, tuple): inx = inx, #if return self.fun(*inx) #end __getitem__ #end __vslice__ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Now if I execute the script by explicitly calling the interpreter everything works fine. # /opt/local/bin/python /usr/local/bin/ldapwatch /opt/local/log/openldap.log | head Apr 21 15:12:38 conn=110982 fd=125 ACCEPT from IP=10.0.59.10:46238 (IP=10.0.128.65:389) Apr 21 15:12:38 conn=110982 op=0 BIND dn="uid=anonymous,ou=local,ou=people,o=global" method=128 Apr 21 15:12:38 conn=110982 op=0 BIND dn="uid=anonymous,ou=local,ou=people,o=global" mech=SIMPLE ssf=0 Apr 21 15:12:38 conn=110982 op=0 RESULT tag=97 err=0 text= Apr 21 15:12:38 conn=110982 op=1 SRCH base="ou=people,o=global" scope=2 deref=0 filter="(uid=anonymous)" Apr 21 15:12:38 conn=110982 op=1 SEARCH RESULT tag=101 err=0 nentries=1 text= Apr 21 15:12:38 conn=110982 op=2 UNBIND Apr 21 15:12:38 conn=110982 fd=125 closed ==== Apr 21 15:12:57 conn=110983 fd=125 ACCEPT from IP=10.1.28.235:39616 (IP=10.0.128.65:389) =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= However if I call the script directly and want the #! line do its work I get the following error. # /usr/local/bin/ldapwatch /opt/local/log/openldap.log | head /usr/local/bin/ldapwatch: line 3: syntax error near unexpected token `(' /usr/local/bin/ldapwatch: line 3: `class vslice(object):' I have no idea what is going on here. The persmision for /usr/local/bin/ldapwatch look fine: # ls -l /usr/local/bin/ldapwatch -rwxr-xr-x 1 root root 2092 Apr 22 10:05 /usr/local/bin/ldapwatch Does anyone have an idea where I should look to fix this? -- Antoon Pardon From mail at timgolden.me.uk Tue Apr 22 06:35:43 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 22 Apr 2014 11:35:43 +0100 Subject: Strange syntax error, occurs only when script is executed directly In-Reply-To: <535644A4.6060901@rece.vub.ac.be> References: <535644A4.6060901@rece.vub.ac.be> Message-ID: <535645FF.4060902@timgolden.me.uk> On 22/04/2014 11:29, Antoon Pardon wrote: > I am workin on a solaris 11 machine. The python version is 2.7.6 > path to python is /opt/local/bin/python. > > These are the 15 first lines of the script: > > #! /opt/local/bin/python > > class vslice(object): > > def __init__(self, fun): > self.fun = fun > > def __getitem__(self, inx): > if not isinstance(inx, tuple): > inx = inx, > #if > return self.fun(*inx) > #end __getitem__ > #end __vslice__ > > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= > > Now if I execute the script by explicitly calling the interpreter > everything works fine. > > # /opt/local/bin/python /usr/local/bin/ldapwatch /opt/local/log/openldap.log | head > Apr 21 15:12:38 conn=110982 fd=125 ACCEPT from IP=10.0.59.10:46238 (IP=10.0.128.65:389) > Apr 21 15:12:38 conn=110982 op=0 BIND dn="uid=anonymous,ou=local,ou=people,o=global" method=128 > Apr 21 15:12:38 conn=110982 op=0 BIND dn="uid=anonymous,ou=local,ou=people,o=global" mech=SIMPLE ssf=0 > Apr 21 15:12:38 conn=110982 op=0 RESULT tag=97 err=0 text= > Apr 21 15:12:38 conn=110982 op=1 SRCH base="ou=people,o=global" scope=2 deref=0 filter="(uid=anonymous)" > Apr 21 15:12:38 conn=110982 op=1 SEARCH RESULT tag=101 err=0 nentries=1 text= > Apr 21 15:12:38 conn=110982 op=2 UNBIND > Apr 21 15:12:38 conn=110982 fd=125 closed > ==== > Apr 21 15:12:57 conn=110983 fd=125 ACCEPT from IP=10.1.28.235:39616 (IP=10.0.128.65:389) > > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= > > However if I call the script directly and want the #! line do its work I get the following error. > > # /usr/local/bin/ldapwatch /opt/local/log/openldap.log | head > /usr/local/bin/ldapwatch: line 3: syntax error near unexpected token `(' > /usr/local/bin/ldapwatch: line 3: `class vslice(object):' > > I have no idea what is going on here. The persmision for /usr/local/bin/ldapwatch look fine: > # ls -l /usr/local/bin/ldapwatch -rwxr-xr-x 1 root root 2092 Apr 22 10:05 /usr/local/bin/ldapwatch Look for a dodgy line-feed / cr (or some other non-visible control character) at the end of the shebang line? TJG From frank at chagford.com Tue Apr 22 06:42:27 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 22 Apr 2014 12:42:27 +0200 Subject: Strange syntax error, occurs only when script is executed directly References: <535644A4.6060901@rece.vub.ac.be> Message-ID: "Antoon Pardon" wrote in message news:535644A4.6060901 at rece.vub.ac.be... >I am workin on a solaris 11 machine. The python version is 2.7.6 > path to python is /opt/local/bin/python. > [...] > > Now if I execute the script by explicitly calling the interpreter > everything works fine. > [...] > > However if I call the script directly and want the #! line do its work I > get the following error. > > # /usr/local/bin/ldapwatch /opt/local/log/openldap.log | head > /usr/local/bin/ldapwatch: line 3: syntax error near unexpected token `(' > /usr/local/bin/ldapwatch: line 3: `class vslice(object):' > I had something similar and it turned out that my script had 'CRLF' line endings instead of 'LF' only, and this caused the problem. I believe that the problem has nothing to do with python, but with how the shell interprets the '#!' line. My editor allows me to re-save a file using a different format, so I saved it as 'unix', reran it, and it worked. HTH Frank Millman From antoon.pardon at rece.vub.ac.be Tue Apr 22 07:26:46 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 22 Apr 2014 13:26:46 +0200 Subject: Strange syntax error, occurs only when script is executed directly In-Reply-To: References: <535644A4.6060901@rece.vub.ac.be> Message-ID: <535651F6.1010505@rece.vub.ac.be> On 22-04-14 12:42, Frank Millman wrote: > "Antoon Pardon" wrote in message > news:535644A4.6060901 at rece.vub.ac.be... >> I am workin on a solaris 11 machine. The python version is 2.7.6 >> path to python is /opt/local/bin/python. >> > [...] >> Now if I execute the script by explicitly calling the interpreter >> everything works fine. >> > [...] >> However if I call the script directly and want the #! line do its work I >> get the following error. >> >> # /usr/local/bin/ldapwatch /opt/local/log/openldap.log | head >> /usr/local/bin/ldapwatch: line 3: syntax error near unexpected token `(' >> /usr/local/bin/ldapwatch: line 3: `class vslice(object):' >> > I had something similar and it turned out that my script had 'CRLF' line > endings instead of 'LF' only, and this caused the problem. I believe that > the problem has nothing to do with python, but with how the shell interprets > the '#!' line. > > My editor allows me to re-save a file using a different format, so I saved > it as 'unix', reran it, and it worked. My editor shows me a CR in the file. Just to be sure I used od -c on the file, this is the result: # od -c /usr/local/bin/ldapwatch | head -30 0000000 # ! / o p t / l o c a l / b i 0000020 n / p y t h o n \n \n c l a s s 0000040 v s l i c e ( o b j e c t ) : \n 0000060 \n \t d e f _ _ i n i t _ _ ( s 0000100 e l f , f u n ) : \n \t \t s e l 0000120 f . f u n = f u n \n \n \t d e 0000140 f _ _ g e t i t e m _ _ ( s e 0000160 l f , i n x ) : \n \t \t i f n 0000200 o t i s i n s t a n c e ( i n 0000220 x , t u p l e ) : \n \t \t \t i n 0000240 x = i n x , \n \t \t # i f \n \t 0000260 \t r e t u r n s e l f . f u n 0000300 ( * i n x ) \n \t # e n d _ _ g 0000320 e t i t e m _ _ \n # e n d _ _ 0000340 v s l i c e _ _ \n \n @ v s l i c 0000360 e \n d e f p r o j e c t ( l s 0000400 t , * a r g v ) : \n \t r e s u 0000420 l t = [ ] \n \t f o r a r g 0000440 i n a r g v : \n \t \t t m p 0000460 = l s t [ a r g ] \n \t \t i f 0000500 i s i n s t a n c e ( a r g , 0000520 s l i c e ) : \n \t \t \t r e s u l 0000540 t . e x t e n d ( t m p ) \n \t \t 0000560 e l s e : \n \t \t \t r e s u l t . 0000600 a p p e n d ( t m p ) \n \t \t # i 0000620 f \n \t # f o r \n \t r e t u r n 0000640 r e s u l t \n # e n d p r o j 0000660 e c t \n \t \t \n i m p o r t s y 0000700 s \n \n d e f I s N o n e ( a r 0000720 g ) : \n \t r e t u r n a r g =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- I see nothing that can cause a problem. I tried to search more specifically for troublesome characters but that didn't turn up anything. # od -c /usr/local/bin/ldapwatch | head -30 | grep '\\[^nt]' # So all special characters are either newlines or tabs. -- Antoon Pardon From rosuav at gmail.com Tue Apr 22 08:09:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Apr 2014 22:09:52 +1000 Subject: Strange syntax error, occurs only when script is executed directly In-Reply-To: <535644A4.6060901@rece.vub.ac.be> References: <535644A4.6060901@rece.vub.ac.be> Message-ID: On Tue, Apr 22, 2014 at 8:29 PM, Antoon Pardon wrote: > However if I call the script directly and want the #! line do its work I get the following error. > > # /usr/local/bin/ldapwatch /opt/local/log/openldap.log | head > /usr/local/bin/ldapwatch: line 3: syntax error near unexpected token `(' > /usr/local/bin/ldapwatch: line 3: `class vslice(object):' That looks like bash trying to run Python code, so I'd look at something being wrong with the shebang processing. What's /opt/local/bin/python? Is it a symlink to something else? Some systems won't allow any such dereferencing, others (including modern Linux) allow a maximum of ten or thereabouts, counting one for every symlink or shebang'd script. If /opt/local/bin/python is a bouncer script that itself has a shebang, that might be your problem. ChrisA From antoon.pardon at rece.vub.ac.be Tue Apr 22 08:21:34 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 22 Apr 2014 14:21:34 +0200 Subject: Strange syntax error, occurs only when script is executed directly [solved] In-Reply-To: References: <535644A4.6060901@rece.vub.ac.be> Message-ID: <53565ECE.2060307@rece.vub.ac.be> On 22-04-14 14:09, Chris Angelico wrote: > On Tue, Apr 22, 2014 at 8:29 PM, Antoon Pardon > wrote: >> However if I call the script directly and want the #! line do its work I get the following error. >> >> # /usr/local/bin/ldapwatch /opt/local/log/openldap.log | head >> /usr/local/bin/ldapwatch: line 3: syntax error near unexpected token `(' >> /usr/local/bin/ldapwatch: line 3: `class vslice(object):' > That looks like bash trying to run Python code, so I'd look at > something being wrong with the shebang processing. What's > /opt/local/bin/python? Is it a symlink to something else? Some systems > won't allow any such dereferencing, others (including modern Linux) > allow a maximum of ten or thereabouts, counting one for every symlink > or shebang'd script. If /opt/local/bin/python is a bouncer script that > itself has a shebang, that might be your problem. > > ChrisA Yes that was it. I changed the first line of my script to: #!/opt/local/bin/python2.7 and it now works. Thanks. -- Antoon Pardon From steve+comp.lang.python at pearwood.info Tue Apr 22 08:21:40 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Apr 2014 12:21:40 GMT Subject: Unicode in Python References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <53539a64$0$29993$c3e8da3$5496439d@news.astraweb.com> <5356082c$0$11109$c3e8da3@news.astraweb.com> <9f94f6b0-ba35-41dc-95a5-48018412fdf6@googlegroups.com> <4e5ab7e6-a144-4709-8a6f-7bd540891ed2@googlegroups.com> Message-ID: <53565ed4$0$29993$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Apr 2014 02:07:58 -0700, wxjmfauth wrote: > Le mardi 22 avril 2014 08:30:45 UTC+2, Rustom Mody a ?crit?: >> >> >> >> > @ rusy > >> "Ive reworded it to make it clear that I am referring to the > character-sets and not encodings." > > Very good, excellent, comment. An healthy coding scheme can only work > properly with a unique characters set and the coding is achieved with > the help of a unique operator. There is no other way to do it and that's > the reason why we have to live today with all these coding schemes > (unicode or not). Note: A coding scheme can be much more complex than > the coding of "raw" characters (eg. CID fonts). >> "So instead of using ? (0x3bb) we should use ? (0x1d740) or >> something thereabouts like ?" For those who cannot see them, they are: py> unicodedata.name('\U0001d740') 'MATHEMATICAL BOLD ITALIC SMALL LAMDA' py> unicodedata.name('\U0001d706') 'MATHEMATICAL ITALIC SMALL LAMDA' ("LAMDA" is the official Unicode name for Lambda.) > This is a very good understanding of unicode. The letter lambda is not > the mathematical symbole lambda. Another example, the micro sign is not > the greek letter mu which is not the mathematical mu. Depends what you mean by "is not". The micro sign is a legacy compatibility character, we shouldn't use it except for compatibility with legacy (non-Unicode) character sets. Instead, we should use the NFKC or NFKD normalization forms to convert it to the recommended character. py> import unicodedata py> a = '\N{GREEK SMALL LETTER MU}' # Preferred py> b = '\N{MICRO SIGN}' # Legacy py> a == b False py> unicodedata.normalize('NFKD', b) == a True py> unicodedata.normalize('NFKC', b) == a True As for the mathematical mu, there is no separate Unicode "maths symbol mu" so far as I am aware. One would simply use '\N{MICRO SIGN}' or '\N{GREEK SMALL LETTER MU}' to get a ?. Likewise, the ? used in mathematics is the Greek letter ?, not a separate symbol, just like the Latin letter x and the x used in mathematics are the same. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Tue Apr 22 08:26:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Apr 2014 22:26:54 +1000 Subject: Strange syntax error, occurs only when script is executed directly [solved] In-Reply-To: <53565ECE.2060307@rece.vub.ac.be> References: <535644A4.6060901@rece.vub.ac.be> <53565ECE.2060307@rece.vub.ac.be> Message-ID: On Tue, Apr 22, 2014 at 10:21 PM, Antoon Pardon wrote: > Yes that was it. I changed the first line of my script to: > > #!/opt/local/bin/python2.7 > > and it now works. Excellent! Shebangs are *extremely* specific, so you may want to consider using "/usr/bin/env python" to get a bit more flexibility. (Or "python2" or "python2.7" in place of "python", depending on how specific you want to be.) ChrisA From steve+comp.lang.python at pearwood.info Tue Apr 22 08:36:42 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Apr 2014 12:36:42 GMT Subject: Strange syntax error, occurs only when script is executed directly References: Message-ID: <5356625a$0$29993$c3e8da3$5496439d@news.astraweb.com> On Tue, 22 Apr 2014 12:29:56 +0200, Antoon Pardon wrote: > I am workin on a solaris 11 machine. The python version is 2.7.6 path to > python is /opt/local/bin/python. Are you sure about that? You ought to double check that /opt/local/bin/ python is what you think it is, and not (say) a symlink to a different binary. > These are the 15 first lines of the script: > > #! /opt/local/bin/python This being Solaris, what happens if you remove the space between the hash- bang and the path? On Linux it makes no difference, but Solaris tends to be a bit more idiosyncratic about things like this. [...] > However if I call the script directly and want the #! line do its work I > get the following error. > > # /usr/local/bin/ldapwatch /opt/local/log/openldap.log | head > /usr/local/bin/ldapwatch: line 3: syntax error near unexpected token `(' > /usr/local/bin/ldapwatch: line 3: `class vslice(object):' That's not a Python syntax error, so its something else failing before Python gets to see it. The only way I can reproduce this is to execute Python code using sh: [steve at ando ~]$ cat ./test2 class X(object): pass print X [steve at ando ~]$ ./test2 ./test2: line 1: syntax error near unexpected token `(' ./test2: line 1: `class X(object):' > Does anyone have an idea where I should look to fix this? Ask your local Solaris expert :-) This appears to be the same symptoms: http://www.linuxmisc.com/12-unix-shell/581d028236386dae.htm -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Tue Apr 22 08:52:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Apr 2014 22:52:28 +1000 Subject: Strange syntax error, occurs only when script is executed directly In-Reply-To: <5356625a$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <5356625a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 22, 2014 at 10:36 PM, Steven D'Aprano wrote: >> These are the 15 first lines of the script: >> >> #! /opt/local/bin/python > > This being Solaris, what happens if you remove the space between the hash- > bang and the path? On Linux it makes no difference, but Solaris tends to > be a bit more idiosyncratic about things like this. I'm pretty sure the POSIX standard stipulates that a space there is optional. Should be no difference between "#!/" and "#! /" on any compliant OS. (But I can't right now find a citation for that, so I may be wrong.) ChrisA From antoon.pardon at rece.vub.ac.be Tue Apr 22 09:01:45 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 22 Apr 2014 15:01:45 +0200 Subject: Strange syntax error, occurs only when script is executed directly [solved] In-Reply-To: References: <535644A4.6060901@rece.vub.ac.be> <53565ECE.2060307@rece.vub.ac.be> Message-ID: <53566839.9010508@rece.vub.ac.be> On 22-04-14 14:26, Chris Angelico wrote: > On Tue, Apr 22, 2014 at 10:21 PM, Antoon Pardon > wrote: >> Yes that was it. I changed the first line of my script to: >> >> #!/opt/local/bin/python2.7 >> >> and it now works. > Excellent! Shebangs are *extremely* specific, so you may want to > consider using "/usr/bin/env python" to get a bit more flexibility. The problem with that is that it doesn't work if python is not on the (standard) path, like in this case. -- Antoon Pardon From rosuav at gmail.com Tue Apr 22 09:07:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Apr 2014 23:07:31 +1000 Subject: Strange syntax error, occurs only when script is executed directly [solved] In-Reply-To: <53566839.9010508@rece.vub.ac.be> References: <535644A4.6060901@rece.vub.ac.be> <53565ECE.2060307@rece.vub.ac.be> <53566839.9010508@rece.vub.ac.be> Message-ID: On Tue, Apr 22, 2014 at 11:01 PM, Antoon Pardon wrote: > On 22-04-14 14:26, Chris Angelico wrote: > >> On Tue, Apr 22, 2014 at 10:21 PM, Antoon Pardon >> wrote: >>> Yes that was it. I changed the first line of my script to: >>> >>> #!/opt/local/bin/python2.7 >>> >>> and it now works. >> Excellent! Shebangs are *extremely* specific, so you may want to >> consider using "/usr/bin/env python" to get a bit more flexibility. > > The problem with that is that it doesn't work if python is not on > the (standard) path, like in this case. Ah! Well, that's why I said "consider using" rather than "you should use" :) ChrisA From python.list at tim.thechases.com Tue Apr 22 09:22:58 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 22 Apr 2014 08:22:58 -0500 Subject: Strange syntax error, occurs only when script is executed directly In-Reply-To: References: <5356625a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140422082258.53104558@bigbox.christie.dr> On 2014-04-22 22:52, Chris Angelico wrote: > I'm pretty sure the POSIX standard stipulates that a space there is > optional. Should be no difference between "#!/" and "#! /" on any > compliant OS. (But I can't right now find a citation for that, so I > may be wrong.) I wondered this too, so went researching and found this: http://en.wikipedia.org/wiki/Shebang_%28Unix%29#Magic_number which said that there was actually some contention that the space was required, but that the specs state that both with-and-without are permissible. -tkc From rosuav at gmail.com Tue Apr 22 09:26:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Apr 2014 23:26:43 +1000 Subject: Strange syntax error, occurs only when script is executed directly In-Reply-To: <20140422082258.53104558@bigbox.christie.dr> References: <5356625a$0$29993$c3e8da3$5496439d@news.astraweb.com> <20140422082258.53104558@bigbox.christie.dr> Message-ID: On Tue, Apr 22, 2014 at 11:22 PM, Tim Chase wrote: > On 2014-04-22 22:52, Chris Angelico wrote: >> I'm pretty sure the POSIX standard stipulates that a space there is >> optional. Should be no difference between "#!/" and "#! /" on any >> compliant OS. (But I can't right now find a citation for that, so I >> may be wrong.) > > I wondered this too, so went researching and found this: > > http://en.wikipedia.org/wiki/Shebang_%28Unix%29#Magic_number > > which said that there was actually some contention that the space was > required, but that the specs state that both with-and-without are > permissible. Yeah, I read the Wikipedia page, but was looking for a citable standards document, and didn't find one. (Which may just mean I didn't look hard enough. Wasn't going to spend an hour on it.) ChrisA From alister.nospam.ware at ntlworld.com Tue Apr 22 09:40:32 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 22 Apr 2014 13:40:32 GMT Subject: Best Website Design Services by Professional Web Designing Company References: <15695c48-33e6-4aa6-bf45-30f3faacfb4f@googlegroups.com> Message-ID: On Tue, 22 Apr 2014 02:21:01 -0700, aveinfosys wrote: > Ave Infosys is a leading professional in Web Designing Company in > Hyderabad India for the > > E-Business Industry.Ave Infosys are providing Best Website Development > and Design Services > > in Hyderabad.Our company offers the Best Web Design & Development > services, Web Hosting > > Services,Responsive and Mobile Designing services,Ecommerce websites > services,Digital > > Marketing Services,Website Design Services. We have intensive web design > and web skills > > merging with the quality essence of expertise should have component to > help you to ascertain > > your internet presence or take it to the next level.we are the Best Web > Design Company in > > Hyderabad. > > For More Details : > > Please contact: (+91) 40 40275321 > > Email : info at aveinfosys.com > > Web : http://aveinfosys.com/website-design Considering the poor quality of your own site it is hardly surprising that you have to resorts to spamming a totally unrelated newsgroup/ mailing list. -- Cache miss - please take better aim next time From nispray at gmail.com Tue Apr 22 10:37:03 2014 From: nispray at gmail.com (Wesley) Date: Tue, 22 Apr 2014 07:37:03 -0700 (PDT) Subject: Google open positions at Shanghai/China ? Message-ID: Hi guys, Anybody know if there are openning positions at Shanghai, China? Just ask for one of my friend in case someone here woring for Google:-) Although see some opened positions from google career, seems no actaully hire going on. Thanks. Wesley From rosuav at gmail.com Tue Apr 22 10:35:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Apr 2014 00:35:37 +1000 Subject: Best Website Design Services by Professional Web Designing Company In-Reply-To: References: <15695c48-33e6-4aa6-bf45-30f3faacfb4f@googlegroups.com> Message-ID: On Tue, Apr 22, 2014 at 11:40 PM, alister wrote: > Considering the poor quality of your own site it is hardly surprising > that you have to resorts to spamming a totally unrelated newsgroup/ > mailing list. If you *must* respond to spam, please at least trim out the URLs so they don't get free exposure... ChrisA From alister.nospam.ware at ntlworld.com Tue Apr 22 10:47:40 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 22 Apr 2014 14:47:40 GMT Subject: Best Website Design Services by Professional Web Designing Company References: <15695c48-33e6-4aa6-bf45-30f3faacfb4f@googlegroups.com> Message-ID: On Wed, 23 Apr 2014 00:35:37 +1000, Chris Angelico wrote: > On Tue, Apr 22, 2014 at 11:40 PM, alister > wrote: >> Considering the poor quality of your own site it is hardly surprising >> that you have to resorts to spamming a totally unrelated newsgroup/ >> mailing list. > > If you *must* respond to spam, please at least trim out the URLs so they > don't get free exposure... > > ChrisA Sorry :-( -- In the force if Yoda's so strong, construct a sentence with words in the proper order then why can't he? From wxjmfauth at gmail.com Tue Apr 22 11:28:32 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 22 Apr 2014 08:28:32 -0700 (PDT) Subject: Unicode in Python In-Reply-To: <53565ed4$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <53539a64$0$29993$c3e8da3$5496439d@news.astraweb.com> <5356082c$0$11109$c3e8da3@news.astraweb.com> <9f94f6b0-ba35-41dc-95a5-48018412fdf6@googlegroups.com> <4e5ab7e6-a144-4709-8a6f-7bd540891ed2@googlegroups.com> <53565ed4$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: Le mardi 22 avril 2014 14:21:40 UTC+2, Steven D'Aprano a ?crit?: > On Tue, 22 Apr 2014 02:07:58 -0700, wxjmfauth wrote: > > > > > Le mardi 22 avril 2014 08:30:45 UTC+2, Rustom Mody a ?crit?: > > >> > > >> > > >> > > >> > > > @ rusy > > > > > >> "Ive reworded it to make it clear that I am referring to the > > > character-sets and not encodings." > > > > > > Very good, excellent, comment. An healthy coding scheme can only work > > > properly with a unique characters set and the coding is achieved with > > > the help of a unique operator. There is no other way to do it and that's > > > the reason why we have to live today with all these coding schemes > > > (unicode or not). Note: A coding scheme can be much more complex than > > > the coding of "raw" characters (eg. CID fonts). > > >> "So instead of using ? (0x3bb) we should use ? (0x1d740) or > > >> something thereabouts like ?" > > > > For those who cannot see them, they are: > > > > py> unicodedata.name('\U0001d740') > > 'MATHEMATICAL BOLD ITALIC SMALL LAMDA' > > py> unicodedata.name('\U0001d706') > > 'MATHEMATICAL ITALIC SMALL LAMDA' > > > > > > ("LAMDA" is the official Unicode name for Lambda.) > > > > > > > This is a very good understanding of unicode. The letter lambda is not > > > the mathematical symbole lambda. Another example, the micro sign is not > > > the greek letter mu which is not the mathematical mu. > > > > Depends what you mean by "is not". The micro sign is a legacy > > compatibility character, we shouldn't use it except for compatibility > > with legacy (non-Unicode) character sets. Instead, we should use the NFKC > > or NFKD normalization forms to convert it to the recommended character. > > > > > > py> import unicodedata > > py> a = '\N{GREEK SMALL LETTER MU}' # Preferred > > py> b = '\N{MICRO SIGN}' # Legacy > > py> a == b > > False > > py> unicodedata.normalize('NFKD', b) == a > > True > > py> unicodedata.normalize('NFKC', b) == a > > True > > > > As for the mathematical mu, there is no separate Unicode "maths symbol > > mu" so far as I am aware. One would simply use '\N{MICRO SIGN}' or > > '\N{GREEK SMALL LETTER MU}' to get a ?. > > > > Likewise, the ? used in mathematics is the Greek letter ?, not a separate > > symbol, just like the Latin letter x and the x used in mathematics are > > the same. > > Normalization is working fine, but it proofs nothing, it has to use some convention. There are several code points ranges (latin + greek), which can be used for mathematical purpose (different mu's). If you are interested, search for "unimath-symbols.pdf" on CTAN (I have all this stuff on my hd). ... "Likewise, the ? used in mathematics is the Greek letter ?, not a separate symbol, just like the Latin letter x and the x used in mathematics are the same. "... just like the Latin letter x and the x used in mathematics are the same. ... Oh! Definitively not. A tool with an unicode engine able to produce "math text" will certainly not use the same code point for a "textual x" or for a "mathematical x", even if one enter/type/hit the same "x". To be exaggeratedly stict, the real question is to know if a used "lambda" or "x" belongs to a "math unicode range" or not. This is quite a different approach. (Please no confusion with a "text litteral variable x"). A text processing tool will notice the difference, it will use different fonts. jmf From miki.tebeka at gmail.com Tue Apr 22 11:32:40 2014 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 22 Apr 2014 08:32:40 -0700 (PDT) Subject: Running programs on mobile phones In-Reply-To: References: Message-ID: > I have seen by chance a number of years ago a book on Python programming > for running on mobile phones (of a certain producer only). What is the > current state of the art in that? Could someone kindly give a few good > literature references? Thanks in advance. I'm not an expert, but take a look at http://kivy.org/. From rustompmody at gmail.com Tue Apr 22 14:09:13 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 22 Apr 2014 11:09:13 -0700 (PDT) Subject: Unicode in Python In-Reply-To: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> <53539a64$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4990bd59-1ad4-42d6-acfc-0ad161e8d938@googlegroups.com> On Tuesday, April 22, 2014 12:01:06 PM UTC+5:30, Ian wrote: > On Apr 22, 2014 12:01 AM, "Rustom Mody" wrote: > > As a unicode user (ok wannabe unicode user :D ) Ive > > written up some unicode ideas that have been discussed here in the > > last couple of weeks: > > http://blog.languager.org/2014/04/unicoded-python.html > I'm reminded of this satire: > http://www.ojohaven.com/fun/spelling.html At the risk of 'explaining the joke' I believe it becomes comical due to the cumulating effect of suggesting ? for assignment and then using that. Since I dont like its look in any fonts that I can check, I am returning the (subsequent) examples to to good (or bad) old = Also the ? is unnecessarily contentions. Been replaced by more straightforward introductory examples. From samrobertsmith at gmail.com Tue Apr 22 15:04:39 2014 From: samrobertsmith at gmail.com (linda.s) Date: Tue, 22 Apr 2014 15:04:39 -0400 Subject: analyse Chinese language using Python code Message-ID: How to analyse Chinese language using Python code? -------------- next part -------------- An HTML attachment was scrubbed... URL: From haiticare2011 at gmail.com Tue Apr 22 18:43:38 2014 From: haiticare2011 at gmail.com (haiticare2011 at gmail.com) Date: Tue, 22 Apr 2014 15:43:38 -0700 (PDT) Subject: analyse Chinese language using Python code In-Reply-To: References: Message-ID: <703bc69f-28cd-46f6-8f93-451d20a9d0c3@googlegroups.com> On Tuesday, April 22, 2014 3:04:39 PM UTC-4, linda.s wrote: > How to analyse Chinese language using Python code? You will need to program a pattern recognizer system. Are you interested in spoken chinese or written Kanji? xie xie JB From mbg1708 at planetmail.com Tue Apr 22 19:08:29 2014 From: mbg1708 at planetmail.com (mbg1708 at planetmail.com) Date: Tue, 22 Apr 2014 16:08:29 -0700 (PDT) Subject: Glade on Windows using Python Message-ID: <62715f8a-8e45-4150-a3c9-ca1183fc6abb@googlegroups.com> Using Windows 8.1 Update. I've loaded ActiveState python (version 2.7) --- installed OK. I don't need Glade, but I do want to use some Glade XML and run the python application. To run a Glade application this needs: from gi.repository import Gtk gi.repository is not available to import. Where can I find gi.repository?....all searches to date have come up empty! Mary From travisgriggs at gmail.com Tue Apr 22 20:05:44 2014 From: travisgriggs at gmail.com (Travis Griggs) Date: Tue, 22 Apr 2014 17:05:44 -0700 Subject: Why does isoformat() optionally not print the fractional seconds? Message-ID: <06945DEA-7DCA-4C35-AD6F-0ECEE74CAAEC@gmail.com> Python(3) let me down today. Better to be explicit, and all that, didn?t pan out for me. I have time series data being recorded in a mongo database (I love pymongo). I have an iOS app that consumes the data. Since JSON doesn?t have a time format, I have to stringify the times when transmitting between the two. To parse it on the obj-c side, I use NSDateFormatter *parser = [NSDateFormatter new]; parser = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; [parser setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.S?]; NSDate *date = [parser dateFromString: thatJsonString]; Which was working swimmingly, until I started getting occasional and infrequent nil dates at times. I thought I had a storage issue or something with my REST api, or the server, or something. But it was simply now and then again, why 1000?s of data points, I managed to get 0 milliseconds from time to time, which resulted in the isoformat() I was using to suddenly leave off the .S part of the string. And since the parse then failed, the iOS side decided it wasn?t valid and returned a nil. Haven?t decided where/how I?ll work around it yet, but the isoformat() seemed unpythonic to me today. Thanks for hearing me whine. From root at 127.0.0.1 Tue Apr 22 21:28:29 2014 From: root at 127.0.0.1 (Andrew Cooper) Date: Wed, 23 Apr 2014 02:28:29 +0100 Subject: Strange syntax error, occurs only when script is executed directly In-Reply-To: References: <5356625a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 22/04/2014 13:52, Chris Angelico wrote: > On Tue, Apr 22, 2014 at 10:36 PM, Steven D'Aprano > wrote: >>> These are the 15 first lines of the script: >>> >>> #! /opt/local/bin/python >> >> This being Solaris, what happens if you remove the space between the hash- >> bang and the path? On Linux it makes no difference, but Solaris tends to >> be a bit more idiosyncratic about things like this. > > I'm pretty sure the POSIX standard stipulates that a space there is > optional. Should be no difference between "#!/" and "#! /" on any > compliant OS. (But I can't right now find a citation for that, so I > may be wrong.) > > ChrisA > man execve 4.3BSD implicitly mandates a space given its description of the shebang line, while POSIX simply implies the presence of a space. I have recently had to check this point. All current kernel implementations I cared to check would strip whitespace around the interpreter, although Solaris was not one such implementation. ~Andrew From root at 127.0.0.1 Tue Apr 22 21:42:13 2014 From: root at 127.0.0.1 (Andrew Cooper) Date: Wed, 23 Apr 2014 02:42:13 +0100 Subject: Strange syntax error, occurs only when script is executed directly [solved] In-Reply-To: References: <535644A4.6060901@rece.vub.ac.be> <53565ECE.2060307@rece.vub.ac.be> Message-ID: <53571A75.8090902@127.0.0.1> On 22/04/2q014 13:26, Chris Angelico wrote: > On Tue, Apr 22, 2014 at 10:21 PM, Antoon Pardon > wrote: >> Yes that was it. I changed the first line of my script to: >> >> #!/opt/local/bin/python2.7 >> >> and it now works. > > Excellent! Shebangs are *extremely* specific, so you may want to > consider using "/usr/bin/env python" to get a bit more flexibility. > (Or "python2" or "python2.7" in place of "python", depending on how > specific you want to be.) > > ChrisA > `man execve` "The interpreter must be a valid pathname for an executable which is not itself a script." This is (presumably) to avoid recursive walks of the filesystem trying to locate a valid interpreter to splat over the virtual address space of the currently executing process. ~Andrew From root at 127.0.0.1 Tue Apr 22 21:42:36 2014 From: root at 127.0.0.1 (Andrew Cooper) Date: Wed, 23 Apr 2014 02:42:36 +0100 Subject: Strange syntax error, occurs only when script is executed directly [solved] In-Reply-To: References: <535644A4.6060901@rece.vub.ac.be> <53565ECE.2060307@rece.vub.ac.be> Message-ID: On 22/04/2q014 13:26, Chris Angelico wrote: > On Tue, Apr 22, 2014 at 10:21 PM, Antoon Pardon > wrote: >> Yes that was it. I changed the first line of my script to: >> >> #!/opt/local/bin/python2.7 >> >> and it now works. > > Excellent! Shebangs are *extremely* specific, so you may want to > consider using "/usr/bin/env python" to get a bit more flexibility. > (Or "python2" or "python2.7" in place of "python", depending on how > specific you want to be.) > > ChrisA > `man execve` "The interpreter must be a valid pathname for an executable which is not itself a script." This is (presumably) to avoid recursive walks of the filesystem trying to locate a valid interpreter to splat over the virtual address space of the currently executing process. ~Andrew From python at mrabarnett.plus.com Tue Apr 22 22:50:28 2014 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 23 Apr 2014 03:50:28 +0100 Subject: Why does isoformat() optionally not print the fractional seconds? In-Reply-To: <06945DEA-7DCA-4C35-AD6F-0ECEE74CAAEC@gmail.com> References: <06945DEA-7DCA-4C35-AD6F-0ECEE74CAAEC@gmail.com> Message-ID: <53572A74.9040007@mrabarnett.plus.com> On 2014-04-23 01:05, Travis Griggs wrote: > Python(3) let me down today. Better to be explicit, and all that, didn?t pan out for me. > > I have time series data being recorded in a mongo database (I love pymongo). I have an iOS app that consumes the data. Since JSON doesn?t have a time format, I have to stringify the times when transmitting between the two. To parse it on the obj-c side, I use > > NSDateFormatter *parser = [NSDateFormatter new]; > parser = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; > [parser setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.S?]; > NSDate *date = [parser dateFromString: thatJsonString]; > > Which was working swimmingly, until I started getting occasional and infrequent nil dates at times. I thought I had a storage issue or something with my REST api, or the server, or something. But it was simply now and then again, why 1000?s of data points, I managed to get 0 milliseconds from time to time, which resulted in the isoformat() I was using to suddenly leave off the .S part of the string. And since the parse then failed, the iOS side decided it wasn?t valid and returned a nil. > > Haven?t decided where/how I?ll work around it yet, but the isoformat() seemed unpythonic to me today. > > Thanks for hearing me whine. > Omitting fractional seconds is permitted by the standard. There was a thread last year about it: Making datetime __str__ and isoformat more consistent https://mail.python.org/pipermail//python-ideas/2013-November/023913.html From rustompmody at gmail.com Wed Apr 23 01:31:41 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 22 Apr 2014 22:31:41 -0700 (PDT) Subject: Unicode in Python Message-ID: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> Chris Angelico wrote: > it's impossible for most people to type (and programming with a palette > of arbitrary syntactic tokens isn't my idea of fun)... Where's the suggestion to use a "palette of arbitrary tokens" ? I just tried a greek keyboard; ie do $ setxkbmap -option "grp:switch,grp:alt_shift_toggle,grp_led:scroll" -layout "us,gr" Thereafter typing abcdefghijklmnopqrstuvwxyz after a Shift-Alt gives ????????????????;????????? One more Shift-Alt and back to roman IOW the extra typing cost for greek letters is negligible over the corresponding roman ones Of course - One would need to define such a keyboard (setxkb) - One would have to find similar technologies for other OSes (Im on debian; even ubuntu/unity grabs too many keys) From sailor at lists.xtsubasa.org Wed Apr 23 01:39:04 2014 From: sailor at lists.xtsubasa.org (Pavel Volkov) Date: Wed, 23 Apr 2014 09:39:04 +0400 Subject: =?iso-8859-1?Q?object().=5F=5Fdict=5F=5F?= Message-ID: <51d9b7f1-3511-4110-adb2-aa2226bd7a3c@lists.xtsubasa.org> There are some basics about Python objects I don't understand. Consider this snippet: >>> class X: pass ... >>> x = X() >>> dir(x) ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__'] >>> x.foo = 11 And now I want to make a simple object in a shorter way, without declaring X class: >>> y = object() >>> dir(y) ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__'] >>> y.foo = 12 Traceback (most recent call last): File "", line 1, in AttributeError: 'object' object has no attribute 'foo' The attribute list is different now and there's no __dict__ and the object does not accept new attributes. Please explain what's going on. From rosuav at gmail.com Wed Apr 23 01:50:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Apr 2014 15:50:35 +1000 Subject: Unicode in Python In-Reply-To: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> Message-ID: On Wed, Apr 23, 2014 at 3:31 PM, Rustom Mody wrote: > Chris Angelico wrote: >> it's impossible for most people to type (and programming with a palette >> of arbitrary syntactic tokens isn't my idea of fun)... > > Where's the suggestion to use a "palette of arbitrary tokens" ? > > I just tried a greek keyboard; ie do > $ setxkbmap -option "grp:switch,grp:alt_shift_toggle,grp_led:scroll" -layout "us,gr" > > Thereafter typing > abcdefghijklmnopqrstuvwxyz > after a Shift-Alt > gives > ????????????????;????????? > > One more Shift-Alt and back to roman Okay. Now what about your other symbols? Your alternative assignment operator, for instance. How do you type that? ChrisA From steve at pearwood.info Wed Apr 23 01:52:33 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 23 Apr 2014 05:52:33 GMT Subject: Unicode in Python References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> Message-ID: <53575521$0$11109$c3e8da3@news.astraweb.com> On Tue, 22 Apr 2014 22:31:41 -0700, Rustom Mody wrote: > Chris Angelico wrote: >> it's impossible for most people to type (and programming with a palette >> of arbitrary syntactic tokens isn't my idea of fun)... > > Where's the suggestion to use a "palette of arbitrary tokens" ? > > I just tried a greek keyboard; ie do > $ setxkbmap -option "grp:switch,grp:alt_shift_toggle,grp_led:scroll" > -layout "us,gr" > > Thereafter typing > abcdefghijklmnopqrstuvwxyz > after a Shift-Alt > gives > ????????????????;????????? > > One more Shift-Alt and back to roman > > IOW the extra typing cost for greek letters is negligible over the > corresponding roman ones 25 Unicode characters down, 1114000+ to go :-) There's not just the keyboard mapping. There's the mental cost of knowing which keyboard mapping you need ("is it Greek, Hebrew, or maths symbols?"), the cost of remembering the mapping from the keys you see on the keyboard to the keys they are mapped to ("is ? mapped to O or W?") and so forth. If you know lambda-calculus, you might associate ? with functions, but if you don't, it's as obfuscated as associating ? with raising exceptions. if not isinstance(obj, int): ?TypeError("expected an int, got %r" % type(obj)) -- Steven From ben at benfinney.id.au Wed Apr 23 02:09:14 2014 From: ben at benfinney.id.au (Ben Finney) Date: Wed, 23 Apr 2014 16:09:14 +1000 Subject: object().__dict__ References: <51d9b7f1-3511-4110-adb2-aa2226bd7a3c@lists.xtsubasa.org> Message-ID: <85vbu0mvat.fsf@benfinney.id.au> Pavel Volkov writes: > The attribute list is different now and there's no __dict__ and the > object does not accept new attributes. > Please explain what's going on. It's a leaky abstraction, unfortunately. By default, all user-defined types will provide their instances with a ?__dict__? attribute, whic is a mapping to store the instance's attributes. But some types don't have that, and ?object? is one of them. It deliberately overrides the default behaviour, and has no ?__dict__? for its instances. >>> foo = object() >>> foo.bar = "spam" Traceback (most recent call last): File "", line 1, in AttributeError: 'object' object has no attribute 'bar' >>> foo.__dict__ Traceback (most recent call last): File "", line 1, in AttributeError: 'object' object has no attribute '__dict__' Your user-defined types, even though they inherit from ?object?, will get a ?__dict__? as normal:: >>> class Bag: >>> """ A simple type to hold attributes. """ >>> Bag.__mro__ (, ) >>> foo = Bag() >>> foo.bar = "spam" >>> foo.__dict__ {'bar': 'spam'} See the discussion of ?__slots__?, and note also that it's not recommended to use this unless you know exactly why you need it . I consider it a wart of Python that its ?object? instances lack the ability to gain arbitrary attributes in the way you expect. -- \ ?Every man would like to be God, if it were possible; some few | `\ find it difficult to admit the impossibility.? ?Bertrand | _o__) Russell, _Power: A New Social Analysis_, 1938 | Ben Finney From cs at zip.com.au Wed Apr 23 02:11:23 2014 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 23 Apr 2014 16:11:23 +1000 Subject: object().__dict__ In-Reply-To: <51d9b7f1-3511-4110-adb2-aa2226bd7a3c@lists.xtsubasa.org> References: <51d9b7f1-3511-4110-adb2-aa2226bd7a3c@lists.xtsubasa.org> Message-ID: <20140423061123.GA47008@cskk.homeip.net> On 23Apr2014 09:39, Pavel Volkov wrote: >There are some basics about Python objects I don't understand. >Consider this snippet: > >>>>class X: pass >... >>>>x = X() >>>>dir(x) >['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', >'__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', >'__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', >'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', >'__sizeof__', '__str__', '__subclasshook__', '__weakref__'] >>>>x.foo = 11 > >And now I want to make a simple object in a shorter way, without >declaring X class: > >>>>y = object() >>>>dir(y) >['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', >'__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', >'__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', >'__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', >'__subclasshook__'] >>>>y.foo = 12 >Traceback (most recent call last): > File "", line 1, in >AttributeError: 'object' object has no attribute 'foo' > >The attribute list is different now and there's no __dict__ and the >object does not accept new attributes. >Please explain what's going on. The base "object" class has a fixed set of attributes; you can't add more. Almost every other class lets you add attributes, but the price for that is that it is slightly in memory footprint and slower to access. Look up the "__slots__" dunder var in the Python doco index: https://docs.python.org/3/glossary.html#term-slots You'll see it as a (rarely used, mostly discouraged) way to force a fixed set of attributes onto a class. As with object, this brings a smaller memory footprint and faster attribute access, but the price is flexibility. Cheers, Cameron Simpson Try being nothing but bored for 4 hours straight, and then tell me that there's no fear involved. - dave at elxr.jpl.nasa.gov (Dave Hayes) From jeanpierreda at gmail.com Wed Apr 23 02:19:44 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 22 Apr 2014 23:19:44 -0700 Subject: Unicode in Python In-Reply-To: <53575521$0$11109$c3e8da3@news.astraweb.com> References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <53575521$0$11109$c3e8da3@news.astraweb.com> Message-ID: On Tue, Apr 22, 2014 at 10:52 PM, Steven D'Aprano wrote: > There's not just the keyboard mapping. There's the mental cost of knowing > which keyboard mapping you need ("is it Greek, Hebrew, or maths > symbols?"), the cost of remembering the mapping from the keys you see on > the keyboard to the keys they are mapped to ("is ? mapped to O or W?") > and so forth. If you know lambda-calculus, you might associate ? with > functions, [...] Or if you know Python and the name of the letter ("lambda"). But yes, typing out the special characters is annoying. I just use words. The only downside to using words is, how do you specify capital versus lowercase letters? "Gamma = ..." violates the style guide! :( -- Devin From ben at benfinney.id.au Wed Apr 23 02:41:41 2014 From: ben at benfinney.id.au (Ben Finney) Date: Wed, 23 Apr 2014 16:41:41 +1000 Subject: Unicode in Python References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <53575521$0$11109$c3e8da3@news.astraweb.com> Message-ID: <85r44omtsq.fsf@benfinney.id.au> Devin Jeanpierre writes: > But yes, typing out the special characters is annoying. I just use > words. I use words that describe the meaning, where feasible. > The only downside to using words is, how do you specify capital > versus lowercase letters? Why do you need to, for an identifier? If uppercase gamma is semantically different from lowercase gamma for identifying a value, then both are too terse and the meaning should be spelled out in a better chosen semantic name. -- \ ?Some people have a problem, and they think ?I know, I'll use | `\ Perl!?. Now they have some number of problems but they're not | _o__) sure whether it's a string or an integer.? ?Benno Rice, 2011 | Ben Finney From rustompmody at gmail.com Wed Apr 23 02:57:46 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 22 Apr 2014 23:57:46 -0700 (PDT) Subject: Unicode in Python In-Reply-To: References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> Message-ID: <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> On Wednesday, April 23, 2014 11:22:33 AM UTC+5:30, Steven D'Aprano wrote: > 25 Unicode characters down, 1114000+ to go :-) The question would arise if there was some suggestion to add 1114000(+) characters to the syntactic/lexical definition of python. IOW while its true that unicode is a character-set, its better to think of it as a repertory -- here is the universal set from which a choice is available. On Wednesday, April 23, 2014 11:20:35 AM UTC+5:30, Chris Angelico wrote: > On Wed, Apr 23, 2014 at 3:31 PM, Rustom Mody wrote: > > Chris Angelico wrote: > >> it's impossible for most people to type (and programming with a palette > >> of arbitrary syntactic tokens isn't my idea of fun)... > > Where's the suggestion to use a "palette of arbitrary tokens" ? > > I just tried a greek keyboard; ie do > > $ setxkbmap -option "grp:switch,grp:alt_shift_toggle,grp_led:scroll" -layout "us,gr" > > Thereafter typing > > abcdefghijklmnopqrstuvwxyz > > after a Shift-Alt > > gives > > ????????????????;????????? > > One more Shift-Alt and back to roman > Okay. Now what about your other symbols? Your alternative assignment > operator, for instance. How do you type that? In case you missed it, I said: > Of course > - One would need to define such a keyboard (setxkb) > - One would have to find similar technologies for other OSes In more detail: In our normal use of a US-104 keyboard, every letter 'costs' something. eg 'a' costs 1 keystroke 'A' costs 2 (Shift+a) Most people do not count that as a significant cost. and when kids come on this list and talk smsese -- i wanna do so-n-so we chide them for keystrokes at the cost of readability. In such a (default) setup typing a ? or ? is not possible at all without something like a char-picker and at best has an ergonomic cost that is an order of magnitude higher than the 'naturally available' characters. On the other hand when/if a keyboard mapping is defined in which the characters that are commonly needed are available, it is reasonable to expect the ?,? to cost no more than 2 strokes each (ie about as much as an 'A'; slightly more than an 'a'. Which means that '?' is expected to cost about the same as 'or' and ? to cost less than an 'and' Readability is another question altogether. Random example from my machine calendar.py line 99 If one finds this: return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) more readable than return year%4=0 ? (year%100?0 ? year%100 = 0) then perhaps the following is the most preferred? COMPUTE YEAR MODULO 4 EQUALS 0 AND YEAR MODULO 100 NOT EQUAL TO ZERO OR YEAR MODULO 100 EQUAL to 0 IOW COBOL is desirable? From rosuav at gmail.com Wed Apr 23 03:06:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Apr 2014 17:06:43 +1000 Subject: Unicode in Python In-Reply-To: <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> Message-ID: On Wed, Apr 23, 2014 at 4:57 PM, Rustom Mody wrote: > In such a (default) setup typing a ? or ? is not possible at all without > something like a char-picker and at best has an ergonomic cost that is an > order of magnitude higher than the 'naturally available' characters. > > On the other hand when/if a keyboard mapping is defined in which > the characters that are commonly needed are available, it is > reasonable to expect the ?,? to cost no more than 2 strokes each > (ie about as much as an 'A'; slightly more than an 'a'. Which means > that '?' is expected to cost about the same as 'or' and ? to cost less than an 'and' So how much effort are you going to go to for, effectively, the same end result? You can type "or" with the same keystrokes, and it takes zero setup work and zero memorization (you may forget which keystroke you set up for ?, but I doubt you'll forget how to spell "or", even if you think it means gold/yellow). Where's the benefit? I'm seriously not seeing it. ChrisA From steve at pearwood.info Wed Apr 23 03:29:33 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 23 Apr 2014 07:29:33 GMT Subject: Unicode in Python References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> Message-ID: <53576bdd$0$11109$c3e8da3@news.astraweb.com> On Tue, 22 Apr 2014 23:57:46 -0700, Rustom Mody wrote: > perhaps the following is the most preferred? > > COMPUTE YEAR MODULO 4 EQUALS 0 AND YEAR MODULO 100 NOT EQUAL TO ZERO OR > YEAR MODULO 100 EQUAL to 0 > > IOW COBOL is desirable? If the only choices are COBOL on one hand and the mutant offspring of Perl and APL on the other, I'd vote for COBOL. But surely they aren't the only options, and it is possible to find a happy medium which is neither excessively verbose nor painfully, cryptically terse. Remember that we're talking about general purpose programming here. There are domains which favour terseness and a vast number of symbols, e.g. mathematics, but most programming is not in that domain, even when it uses tools from that domain. -- Steve From dhananjay.c.joshi at gmail.com Wed Apr 23 03:53:51 2014 From: dhananjay.c.joshi at gmail.com (Dhananjay) Date: Wed, 23 Apr 2014 15:53:51 +0800 Subject: how to write list in a file Message-ID: Hello everyone, I am trying hard to write a list to a file as follows: def average_ELECT(pwd): os.chdir(pwd) files = filter(os.path.isfile, os.listdir('./')) folders = filter(os.path.isdir, os.listdir('./')) eelec = 0.0; evdw = 0.0; EELEC = []; elecutoff = []; g = Gnuplot.Gnuplot() for f1 in files: # if f1[21:23]=='12': if f1[27:29]==sys.argv[1]: # vdw cutoff remains constant; see 2nd column of output fl1 = open(f1,'r').readlines() # print len(fl1) for i in range(1, len(fl1)): fl1[i]=fl1[i].split() eelec = eelec + float(fl1[i][1]) evdw = evdw + float(fl1[i][2]) #print fl1[i][1], fl1[i][2] avg_eelec = eelec/40 avg_evdw = evdw/40 # print eelec, evdw # print f1[21:23], f1[27:29], avg_eelec, avg_evdw print f1[21:23], f1[27:29], avg_eelec # EELEC.append(avg_eelec); elecutoff.append(float(f1[21:23])) eelec=0.0; evde=0.0; a = f1[21:23]+' '+f1[27:29]+' '+str(avg_eelec) EELEC.append(a) print sorted(EELEC) with open('EElect_elec12-40_vdwxxx.dat','w') as wr: for i in EELEC: print i wr.write("%s\n" % i) wr.close() The script is printing "print sorted(EELEC)" as well as "print f1[21:23], f1[27:29], avg_eelec" very well. However, for some reason, I neither see any file (expected to see EElect_elec12-40_vdwxxx.dat as per the script) generated nor any error message. Could anyone suggest me correction here. Thanking you in advance. -- DJ -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at pearwood.info Wed Apr 23 03:53:00 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 23 Apr 2014 07:53:00 GMT Subject: Unicode in Python References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> Message-ID: <5357715c$0$11109$c3e8da3@news.astraweb.com> On Tue, 22 Apr 2014 23:57:46 -0700, Rustom Mody wrote: > On the other hand when/if a keyboard mapping is defined in which the > characters that are commonly needed are available, it is reasonable to > expect the ?,? to cost no more than 2 strokes each (ie about as much as > an 'A'; slightly more than an 'a'. Which means that '?' is expected to > cost about the same as 'or' and ? to cost less than an 'and' Oh, a further thought... Consider your example: return year%4=0 ? (year%100?0 ? year%100 = 0) vs return year%4=0 and (year%100!=0 or year%100 = 0) [aside: personally I like ? and if there was a platform independent way to type it in any editor, I'd much prefer it over != or <> ] Apart from the memorization problem, which I've already touched on, there is the mode problem. Keyboard layouts are modes, and you're swapping modes. Every time you swap modes, there is a small mental cost. Think of it as an interrupt which has to be caught, pausing the current thought and starting a new one. So rather than: char char char char char char char ... you have: char char char INTERRUPT char INTERRUPT char char char ... which is a heavier cost that it appears from just counting keystrokes. Of course, the more experienced you become, the smaller that cost will be, but it will never be quite as low as just a "regular" keystroke. Normally, when people use multiple keyboards, its because that interrupt cost is amortized over a significant amount of typing: INTERRUPT (English layout) paragraph paragraph paragraph paragraph INTERRUPT (Greek layout) paragraph paragraph paragraph INTERRUPT (English again) paragraph ... and possibly even lost in the noise of a far greater interrupt, namely task-switching from one application to another. So it's manageable. But switching layouts for a single character is likely to be far more painful, especially for casual users of that layout. Based on an extremely generous estimate that I use "lambda" four times in 100 lines of code, I might use ? perhaps once in a thousand non-Greek characters. Similarly, I might use ? or ? maybe once per hundred characters. That means I'm unlikely to ever get familiar enough with those that the cost of two interrupts per use will be negligible. -- Steven From dpalao.python at gmail.com Wed Apr 23 04:40:44 2014 From: dpalao.python at gmail.com (David Palao) Date: Wed, 23 Apr 2014 10:40:44 +0200 Subject: how to write list in a file In-Reply-To: References: Message-ID: 2014-04-23 9:53 GMT+02:00 Dhananjay : > Hello everyone, > > I am trying hard to write a list to a file as follows: > > > def average_ELECT(pwd): > os.chdir(pwd) > files = filter(os.path.isfile, os.listdir('./')) > folders = filter(os.path.isdir, os.listdir('./')) > eelec = 0.0; evdw = 0.0; EELEC = []; elecutoff = []; > g = Gnuplot.Gnuplot() > for f1 in files: > # if f1[21:23]=='12': > if f1[27:29]==sys.argv[1]: # vdw cutoff remains constant; see 2nd > column of output > fl1 = open(f1,'r').readlines() > # print len(fl1) > > for i in range(1, len(fl1)): > fl1[i]=fl1[i].split() > eelec = eelec + float(fl1[i][1]) > evdw = evdw + float(fl1[i][2]) > #print fl1[i][1], fl1[i][2] > avg_eelec = eelec/40 > avg_evdw = evdw/40 > # print eelec, evdw > # print f1[21:23], f1[27:29], avg_eelec, avg_evdw > print f1[21:23], f1[27:29], avg_eelec > # EELEC.append(avg_eelec); elecutoff.append(float(f1[21:23])) > eelec=0.0; evde=0.0; > a = f1[21:23]+' '+f1[27:29]+' '+str(avg_eelec) > EELEC.append(a) > print sorted(EELEC) > with open('EElect_elec12-40_vdwxxx.dat','w') as wr: > for i in EELEC: > print i > wr.write("%s\n" % i) > wr.close() > > > The script is printing "print sorted(EELEC)" as well as "print f1[21:23], > f1[27:29], avg_eelec" very well. > However, for some reason, I neither see any file (expected to see > EElect_elec12-40_vdwxxx.dat as per the script) generated nor any error > message. > > Could anyone suggest me correction here. > > Thanking you in advance. > > -- DJ > > > > -- > https://mail.python.org/mailman/listinfo/python-list > A couple of minor points: * You don't need "wr.close()" after the "with open(...) as wr:" block. * Are you sure that you are looking in the right directory? * Why do you need the "g = Gnuplot.Gnuplot()" line? It looks to me that you have skipped some things while doing copy and paste? Best regards From duncan.booth at invalid.invalid Wed Apr 23 04:56:07 2014 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 23 Apr 2014 08:56:07 GMT Subject: object().__dict_ References: Message-ID: Pavel Volkov wrote: > There are some basics about Python objects I don't understand. > Consider this snippet: > >>>> class X: pass > ... >>>> x = X() >>>> dir(x) > ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', > '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', > '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', > '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', > '__sizeof__', '__str__', '__subclasshook__', '__weakref__'] >>>> x.foo = 11 > > And now I want to make a simple object in a shorter way, without > declaring X class: > >>>> y = object() >>>> dir(y) > ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', > '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', > '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', > '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', > '__subclasshook__'] >>>> y.foo = 12 > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'object' object has no attribute 'foo' > > The attribute list is different now and there's no __dict__ and the > object does not accept new attributes. > Please explain what's going on. > > Not all classes have a __dict__ attribute. Mostly builtin classes (e.g. tuple, list, int, ...), but also if you have an class using __slots__ which subclasses a class with no __dict__ it won't have a __dict__. Subclasses don't remove attributes, they only add them (although in Python you can bend that rule it still applies here). Therefore for any classes to not have a __dict__ attribute the ultimate base class 'object' has to not have a __dict__. The consequence, as you found out, is that you cannot add attributes to an instance of 'object()', you have to create at least an empty subclass which doesn't include a `__slots__` attribute to get a class that can accept arbitrary attributes. -- Duncan Booth From elearn2014 at gmail.com Wed Apr 23 07:23:42 2014 From: elearn2014 at gmail.com (length power) Date: Wed, 23 Apr 2014 19:23:42 +0800 Subject: why my cur.executescript can not run? Message-ID: When cur.execute be used, i get right output. import sqlite3 con=sqlite3.connect(":memory:") cur=con.cursor() sql1="attach database 'g:\\workspace\\data\\Cinfo.sqlite' as Cinfo;" sql2="select * from Cinfo.ipo;" cur.execute(sql1) cur.execute(sql2) con.commit() x=cur.fetchall()print(x) When i change it into cur.executescript, nothing can get. import sqlite3 con=sqlite3.connect(":memory:") cur=con.cursor() sql_script=""" attach database 'g:\\workspace\\data\\Cinfo.sqlite' as Cinfo; select * from Cinfo.ipo;""" cur.executescript(sql_script) con.commit() x=cur.fetchall()print(x) I want to know why? please download the attachment and save it in g:\\workspace\\data\\Cinfo.sqlite to test my code,then you can draw the conclusion. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Cinfo.zip Type: application/zip Size: 662632 bytes Desc: not available URL: From amirouche.boubekki at gmail.com Wed Apr 23 09:48:32 2014 From: amirouche.boubekki at gmail.com (Amirouche Boubekki) Date: Wed, 23 Apr 2014 15:48:32 +0200 Subject: object().__dict__ In-Reply-To: <20140423061123.GA47008@cskk.homeip.net> References: <51d9b7f1-3511-4110-adb2-aa2226bd7a3c@lists.xtsubasa.org> <20140423061123.GA47008@cskk.homeip.net> Message-ID: 2014-04-23 8:11 GMT+02:00 Cameron Simpson : > On 23Apr2014 09:39, Pavel Volkov wrote: > >> There are some basics about Python objects I don't understand. >> Consider this snippet: >> >> class X: pass >>>>> >>>> ... >> >>> x = X() >>>>> dir(x) >>>>> >>>> ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', >> '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', >> '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', >> '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', >> '__str__', '__subclasshook__', '__weakref__'] >> >>> x.foo = 11 >>>>> >>>> >> And now I want to make a simple object in a shorter way, without >> declaring X class: >> > If you don't want to go through the usual syntax that defines classes you can use the equivalent code using type to dynamically create a class: MyClassObject = type('MyClassObject', (object,), dict()) Mind the fact that MyClassObject is a specific kind of object: a class, a priori, not harmful in anyway > >> y = object() >>>>> dir(y) >>>>> >>>> ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', >> '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', >> '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', >> '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', >> '__subclasshook__'] >> >>> y.foo = 12 >>>>> >>>> Traceback (most recent call last): >> File "", line 1, in >> AttributeError: 'object' object has no attribute 'foo' >> >> The attribute list is different now and there's no __dict__ and the >> object does not accept new attributes. >> Please explain what's going on. >> > > The base "object" class has a fixed set of attributes; you can't add more. > Just like any other builtin type: int, float etc... which also means you can't add method to them dynamically. Mind the fact that an instance of object is still useful to implement efficient SENTINEL objects > > Almost every other class lets you add attributes, but the price for that > is that it is slightly in memory footprint and slower to access. > class defined in Python except if you define a __slots__ > > Look up the "__slots__" dunder var in the Python doco index: > > https://docs.python.org/3/glossary.html#term-slots > > You'll see it as a (rarely used, mostly discouraged) way to force a fixed > set of attributes onto a class. As with object, this brings a smaller > memory footprint and faster attribute access, but the price is flexibility. > True, still can be the only way to save few MB or... GB without falling back to C or PyPy. Have a look at PyPy to how to save memory (and speed things up) without slots: http://morepypy.blogspot.fr/2010/11/efficiently-implementing-python-objects.html In Python 3 there is a class that is equivalent to: class foo(object): pass simple object with a __dict__, I can't find it anymore and also there is SimpleNamespaceclass. To sum up: - If you want to create a sentinel value, use object() - If you want to create an object to hold values and access them as attributes, use something like SimpleNamespace > Cheers, > Cameron Simpson > > Try being nothing but bored for 4 hours straight, and then tell me that > there's no fear involved. - dave at elxr.jpl.nasa.gov (Dave Hayes) > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pconnell at gmail.com Wed Apr 23 09:59:35 2014 From: pconnell at gmail.com (Phil Connell) Date: Wed, 23 Apr 2014 14:59:35 +0100 Subject: object().__dict__ In-Reply-To: References: <51d9b7f1-3511-4110-adb2-aa2226bd7a3c@lists.xtsubasa.org> <20140423061123.GA47008@cskk.homeip.net> Message-ID: <20140423135935.GA17819@phconnel-ws.cisco.com> On Wed, Apr 23, 2014 at 03:48:32PM +0200, Amirouche Boubekki wrote: > 2014-04-23 8:11 GMT+02:00 Cameron Simpson : > > Look up the "__slots__" dunder var in the Python doco index: > > > > https://docs.python.org/3/glossary.html#term-slots > > > > You'll see it as a (rarely used, mostly discouraged) way to force a fixed > > set of attributes onto a class. As with object, this brings a smaller > > memory footprint and faster attribute access, but the price is flexibility. > > > > True, still can be the only way to save few MB or... GB without falling > back to C or PyPy. > > Have a look at PyPy to how to save memory (and speed things up) without > slots: > http://morepypy.blogspot.fr/2010/11/efficiently-implementing-python-objects.html Is there any analysis of how this balances increased memory usage from the JIT vs the CPython VM (with a reasonable amount of code)? I'd thought that one of the main disadvantages of PyPy was drastically increased memory usage for any decent-sized program. Would be interested to know if this was not the case :) Cheers, Phil From amirouche.boubekki at gmail.com Wed Apr 23 10:21:26 2014 From: amirouche.boubekki at gmail.com (Amirouche Boubekki) Date: Wed, 23 Apr 2014 16:21:26 +0200 Subject: object().__dict__ In-Reply-To: <20140423135935.GA17819@phconnel-ws.cisco.com> References: <51d9b7f1-3511-4110-adb2-aa2226bd7a3c@lists.xtsubasa.org> <20140423061123.GA47008@cskk.homeip.net> <20140423135935.GA17819@phconnel-ws.cisco.com> Message-ID: 2014-04-23 15:59 GMT+02:00 Phil Connell : > On Wed, Apr 23, 2014 at 03:48:32PM +0200, Amirouche Boubekki wrote: > > 2014-04-23 8:11 GMT+02:00 Cameron Simpson : > > > Look up the "__slots__" dunder var in the Python doco index: > > > > > > https://docs.python.org/3/glossary.html#term-slots > > > > > > You'll see it as a (rarely used, mostly discouraged) way to force a > fixed > > > set of attributes onto a class. As with object, this brings a smaller > > > memory footprint and faster attribute access, but the price is > flexibility. > > > > > > > True, still can be the only way to save few MB or... GB without falling > > back to C or PyPy. > > > > Have a look at PyPy to how to save memory (and speed things up) without > > slots: > > > http://morepypy.blogspot.fr/2010/11/efficiently-implementing-python-objects.html > > Is there any analysis of how this balances increased memory usage from the > JIT > vs the CPython VM (with a reasonable amount of code)? > > I'd thought that one of the main disadvantages of PyPy was drastically > increased memory usage for any decent-sized program. Would be interested to > know if this was not the case :) > I have a similar thought, I don't how that memory consumption increase (a constant? a factor? probably both...) but if the program use an absurd amount of memory even in CPython then PyPy will be able to catchup based on comment #1 of a PyPy core dev in http://tech.oyster.com/save-ram-with-python-slots/ see also http://pypy.readthedocs.org/en/latest/interpreter-optimizations.html#dictionary-optimizations Still it requires more analysis. When does PyPy trigger the optimization? > > > Cheers, > Phil > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pconnell at gmail.com Wed Apr 23 11:50:47 2014 From: pconnell at gmail.com (Phil Connell) Date: Wed, 23 Apr 2014 16:50:47 +0100 Subject: object().__dict__ In-Reply-To: References: <51d9b7f1-3511-4110-adb2-aa2226bd7a3c@lists.xtsubasa.org> <20140423061123.GA47008@cskk.homeip.net> <20140423135935.GA17819@phconnel-ws.cisco.com> Message-ID: <20140423155047.GA19822@phconnel-ws.cisco.com> On Wed, Apr 23, 2014 at 04:21:26PM +0200, Amirouche Boubekki wrote: > 2014-04-23 15:59 GMT+02:00 Phil Connell : > > > On Wed, Apr 23, 2014 at 03:48:32PM +0200, Amirouche Boubekki wrote: > > > 2014-04-23 8:11 GMT+02:00 Cameron Simpson : > > > > Look up the "__slots__" dunder var in the Python doco index: > > > > > > > > https://docs.python.org/3/glossary.html#term-slots > > > > > > > > You'll see it as a (rarely used, mostly discouraged) way to force a > > fixed > > > > set of attributes onto a class. As with object, this brings a smaller > > > > memory footprint and faster attribute access, but the price is > > flexibility. > > > > > > > > > > True, still can be the only way to save few MB or... GB without falling > > > back to C or PyPy. > > > > > > Have a look at PyPy to how to save memory (and speed things up) without > > > slots: > > > > > http://morepypy.blogspot.fr/2010/11/efficiently-implementing-python-objects.html > > > > Is there any analysis of how this balances increased memory usage from the > > JIT > > vs the CPython VM (with a reasonable amount of code)? > > > > I'd thought that one of the main disadvantages of PyPy was drastically > > increased memory usage for any decent-sized program. Would be interested to > > know if this was not the case :) > > > > I have a similar thought, I don't how that memory consumption increase (a > constant? a factor? probably both...) > > but if the program use an absurd amount of memory even in CPython then PyPy > will be able to catchup based on comment #1 of a PyPy core dev in > http://tech.oyster.com/save-ram-with-python-slots/ see also > http://pypy.readthedocs.org/en/latest/interpreter-optimizations.html#dictionary-optimizations Absolutely. For long-running code manipulating large amounts of data I can imagine the PyPy optimisations being a win. On the other hand, if the code/data ratio is larger, CPython may well win in terms of memory use. > > Still it requires more analysis. When does PyPy trigger the optimization? Indeed. Without measuring this is all idle speculation ;) From rustompmody at gmail.com Wed Apr 23 13:59:13 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 23 Apr 2014 10:59:13 -0700 (PDT) Subject: Unicode in Python In-Reply-To: <5357715c$0$11109$c3e8da3@news.astraweb.com> References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> <5357715c$0$11109$c3e8da3@news.astraweb.com> Message-ID: On Wednesday, April 23, 2014 1:23:00 PM UTC+5:30, Steven D'Aprano wrote: > On Tue, 22 Apr 2014 23:57:46 -0700, Rustom Mody wrote: > > On the other hand when/if a keyboard mapping is defined in which the > > characters that are commonly needed are available, it is reasonable to > > expect the ?,? to cost no more than 2 strokes each (ie about as much as > > an 'A'; slightly more than an 'a'. Which means that '?' is expected to > > cost about the same as 'or' and ? to cost less than an 'and' > Oh, a further thought... > Consider your example: > return year%4=0 ? (year%100?0 ? year%100 = 0) > vs > return year%4=0 and (year%100!=0 or year%100 = 0) > [aside: personally I like ? and if there was a platform independent way > to type it in any editor, I'd much prefer it over != or <> ] > Apart from the memorization problem, which I've already touched on, there > is the mode problem. Keyboard layouts are modes, and you're swapping > modes. Every time you swap modes, there is a small mental cost. Think of > it as an interrupt which has to be caught, pausing the current thought > and starting a new one. So rather than: > char char char char char char char ... > you have: > char char char INTERRUPT > char INTERRUPT > char char char ... > which is a heavier cost that it appears from just counting keystrokes. Of > course, the more experienced you become, the smaller that cost will be, > but it will never be quite as low as just a "regular" keystroke. > Normally, when people use multiple keyboards, its because that interrupt > cost is amortized over a significant amount of typing: > INTERRUPT (English layout) > paragraph paragraph paragraph paragraph > INTERRUPT (Greek layout) > paragraph paragraph paragraph > INTERRUPT (English again) > paragraph ... > and possibly even lost in the noise of a far greater interrupt, namely > task-switching from one application to another. So it's manageable. But > switching layouts for a single character is likely to be far more > painful, especially for casual users of that layout. > Based on an extremely generous estimate that I use "lambda" four times in > 100 lines of code, I might use ? perhaps once in a thousand non-Greek > characters. Similarly, I might use ? or ? maybe once per hundred > characters. That means I'm unlikely to ever get familiar enough with > those that the cost of two interrupts per use will be negligible. Its gratifying to see an argument whose framing is cognitive-based! More on that later. For now: mode/modeless Yes most of us prefer the Shift key to the Caps Lock even for stretches of capitals. So analogously here is a modeless solution Earlier I found this mode-switching version $ setxkbmap -option "grp:switch,grp:alt_shift_toggle,grp_led:scroll" -layout "us,gr" this makes Shift-Alt the mode-switcher This one on the other hand $ setxkbmap -layout "us,gr" -option "grp:switch" will make right-alt behave like 'Greek-Shift' ie typing abcdefghijklmnopqrstuvwxyz with RAlt depressed throughout, produces ????????????????;????????? This makes the a Greek letter's ergonomic cost identical to a capital English letter's: For Greek use RAlt the way one uses Shift for English. Notes: 1. Tried on Debian and Ubuntu -- Recent Ubuntus are rather more ill-mannered in the way they appropriates keys. Still it works as far as I can see. 2. ';' ?? ie semicolon is produced from 'q'? Whats that semicolon doing there?? But then Greek is -- well -- Greek to me! (As is xkb!) From abhishek1899 at gmail.com Wed Apr 23 14:08:29 2014 From: abhishek1899 at gmail.com (Reginaldo) Date: Wed, 23 Apr 2014 11:08:29 -0700 (PDT) Subject: App segmentation fault (CentOS 6.5) Message-ID: <34645889-9400-4d02-8577-ee29a723c447@googlegroups.com> Hi, I have a GUI app that is written using wx. When I run it on CentOS 6.5, the following error messages are displayed and the app closes: (python:10096): Pango-WARNING **: shaping failure, expect ugly output. shape-engine='BasicEngineFc', font='DejaVu Sans 10.9990234375', text='' (python:10096): Pango-CRITICAL **: pango_layout_get_line_count: assertion `layout != NULL' failed (python:10096): Gdk-CRITICAL **: IA__gdk_draw_layout: assertion `PANGO_IS_LAYOUT (layout)' failed Segmentation fault I checked if this was a font issue, but the font is installed on the system. I use an idle thread in my application. Could some let me know what the problem may be in this case? Thank you! Python Version used: 2.6.6 wxPython Version used: 2.8.11 From harrismh777 at gmail.com Wed Apr 23 15:46:59 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 23 Apr 2014 14:46:59 -0500 Subject: App segmentation fault (CentOS 6.5) References: <34645889-9400-4d02-8577-ee29a723c447@googlegroups.com> Message-ID: On 4/23/14 1:08 PM, Reginaldo wrote: > > I have a GUI app that is written using wx. When I run it on CentOS 6.5, the following error messages are displayed and the app closes: Only fails on CentOS ? > I use an idle thread in my application. Is your CentOS launching idle with -n switch ? What is different on this setup ? Have you tried more than one CentOS system? > marcus From dihedral88888 at gmail.com Wed Apr 23 16:25:05 2014 From: dihedral88888 at gmail.com (CHIN Dihedral) Date: Wed, 23 Apr 2014 13:25:05 -0700 (PDT) Subject: object().__dict__ In-Reply-To: References: <51d9b7f1-3511-4110-adb2-aa2226bd7a3c@lists.xtsubasa.org> <20140423061123.GA47008@cskk.homeip.net> <20140423135935.GA17819@phconnel-ws.cisco.com> Message-ID: On Wednesday, April 23, 2014 10:21:26 PM UTC+8, Amirouche Boubekki wrote: > 2014-04-23 15:59 GMT+02:00 Phil Connell : > > > > On Wed, Apr 23, 2014 at 03:48:32PM +0200, Amirouche Boubekki wrote: > > > 2014-04-23 8:11 GMT+02:00 Cameron Simpson : > > > > > Look up the "__slots__" dunder var in the Python doco index: > > > > > > > > ? https://docs.python.org/3/glossary.html#term-slots > > > > > > > > You'll see it as a (rarely used, mostly discouraged) way to force a fixed > > > > set of attributes onto a class. As with object, this brings a smaller > > > > memory footprint and faster attribute access, but the price is flexibility. > > > > > > > > > > True, still can be the only way to save few MB or... GB without falling > > > back to C or PyPy. > > > > > > Have a look at PyPy to how to save memory (and speed things up) without > > > slots: > > > http://morepypy.blogspot.fr/2010/11/efficiently-implementing-python-objects.html > > > > Is there any analysis of how this balances increased memory usage from the JIT > > vs the CPython VM (with a reasonable amount of code)? > > > > I'd thought that one of the main disadvantages of PyPy was drastically > > increased memory usage for any decent-sized program. Would be interested to > > know if this was not the case :) > > > > I have a similar thought, I don't how that memory consumption increase (a constant? a factor? probably both...) > > but if the program use an absurd amount of memory even in CPython then PyPy will be able to catchup based on comment #1 of a PyPy core dev in http://tech.oyster.com/save-ram-with-python-slots/ see also http://pypy.readthedocs.org/en/latest/interpreter-optimizations.html#dictionary-optimizations > > > > > Still it requires more analysis. When does PyPy trigger the optimization? > > ? > > > > > > > Cheers, > > Phil > > > > -- > > https://mail.python.org/mailman/listinfo/python-list The auto-code generation of valid python codes in PyPy is helpful in CAD/CAM and non-idiot robot brains. From tim.thelion at gmail.com Wed Apr 23 16:57:09 2014 From: tim.thelion at gmail.com (tim.thelion at gmail.com) Date: Wed, 23 Apr 2014 13:57:09 -0700 (PDT) Subject: Moving to an OOP model from an classically imperitive one Message-ID: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> Hello, I am currently writting a program called subuser(subuser.org), which is written as classically imperative code. Subuser is, essentially, a package manager. It installs and updates programs from repositories. I have a set of source files https://github.com/subuser-security/subuser/tree/master/logic/subuserCommands/subuserlib which have functions in them. Each function does something to a program, it identifies the program by the programs name. For example, I have an installProgram function defined as such: def installProgram(programName, useCache): Now I've run into a flaw in this model. There are certain situations where a "programName" is not a unique identifier. It is possible for two repositories to each have a program with the same name. Obviously, I could go through my code and replace all use of the string "programName" with a tuple of (programName, repository). Or I could define a new class with two attributes: programName and repository, and pass such a simple object arround, or pass a dictionary. However, I think this would be better solved by moving fully to an OOP model. That is, I would have a SubuserProgram class which had methods such as "install", "describe", "isInstalled"... There is one problem though. Currently, I have these functions logically organized into source files, each between 40 and 170 LOC. I fear that if I were to put all of these functions into one class, than I would have a single, very large source file. I don't like working with large source files for practicall reasons. If I am to define the class SubuserProgram in the file SubuserProgram.py, I do not want all of run.py to be moved into that file as well. I thought about keeping each method in a separate file, much as I do now, something like: ################### #FileA.py ################### def a(self): blah ################### #FileB.py ################### def b(self): blah ################### #Class.py ################### import FileA, FileB class C: a=FileA.a b=FileB.b This works, but I find that it is hard to read. When I come across FileA, and I see "self" it just seems very confusing. I suffer a bout of "who-am-i"ism. I asked on IRC and it was sugested that I use multiple classes, however I see no logical way to separate a SubuserProgram object into multiple classes. So I thought I would seek your advice. Tim From breamoreboy at yahoo.co.uk Wed Apr 23 17:15:03 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 23 Apr 2014 22:15:03 +0100 Subject: Moving to an OOP model from an classically imperitive one In-Reply-To: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> References: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> Message-ID: On 23/04/2014 21:57, tim.thelion at gmail.com wrote: > Hello, > > I am currently writting a program called subuser(subuser.org), which is written as classically imperative code. Subuser is, essentially, a package manager. It installs and updates programs from repositories. > > I have a set of source files https://github.com/subuser-security/subuser/tree/master/logic/subuserCommands/subuserlib which have functions in them. Each function does something to a program, it identifies the program by the programs name. For example, I have an installProgram function defined as such: > > def installProgram(programName, useCache): > > Now I've run into a flaw in this model. There are certain situations where a "programName" is not a unique identifier. It is possible for two repositories to each have a program with the same name. Obviously, I could go through my code and replace all use of the string "programName" with a tuple of (programName, repository). Or I could define a new class with two attributes: programName and repository, and pass such a simple object arround, or pass a dictionary. However, I think this would be better solved by moving fully to an OOP model. That is, I would have a SubuserProgram class which had methods such as "install", "describe", "isInstalled"... > > There is one problem though. Currently, I have these functions logically organized into source files, each between 40 and 170 LOC. I fear that if I were to put all of these functions into one class, than I would have a single, very large source file. I don't like working with large source files for practicall reasons. If I am to define the class SubuserProgram in the file SubuserProgram.py, I do not want all of run.py to be moved into that file as well. > > I thought about keeping each method in a separate file, much as I do now, something like: > > ################### > #FileA.py > ################### > def a(self): > blah > > ################### > #FileB.py > ################### > def b(self): > blah > > ################### > #Class.py > ################### > import FileA, FileB > class C: > a=FileA.a > b=FileB.b > > This works, but I find that it is hard to read. When I come across FileA, and I see "self" it just seems very confusing. I suffer a bout of "who-am-i"ism. > > I asked on IRC and it was sugested that I use multiple classes, however I see no logical way to separate a SubuserProgram object into multiple classes. > > So I thought I would seek your advice. > > Tim > You're writing Python, not Java, so put your code into one file and stop messing about. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ian.g.kelly at gmail.com Wed Apr 23 17:23:24 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 23 Apr 2014 15:23:24 -0600 Subject: Moving to an OOP model from an classically imperitive one In-Reply-To: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> References: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> Message-ID: On Apr 23, 2014 5:01 PM, wrote: > I asked on IRC and it was sugested that I use multiple classes, however I see no logical way to separate a SubuserProgram object into multiple classes. You say you already have the methods logically separated into files. How about adding one abstract class per file, and then letting SubuserProgram inherit from each of those individual classes? As another alternative that you haven't mentioned yet, you could create a decorator to be applied to each method, which will inject it into the class at the time it is defined. The explicitness of the decorator solves your confusion problem of "why does this function use self". It creates a couple of new problems though: 1) reading the class won't tell you what methods it contains; and 2) making sure the class is fully constructed before it is used becomes tricky. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Wed Apr 23 17:42:45 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 23 Apr 2014 14:42:45 -0700 Subject: Moving to an OOP model from an classically imperitive one In-Reply-To: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> References: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> Message-ID: <535833D5.7040500@stoneleaf.us> On 04/23/2014 01:57 PM, tim.thelion at gmail.com wrote: > > There is one problem though. Currently, I have these functions logically > organized into source files, each between 40 and 170 LOC. I fear that if > I were to put all of these functions into one class, than I would have a > single, very large source file. I don't like working with large source > files for practicall reasons. I'm curious what these practical reasons are. One my smallest source files has 870 lines in it, my largest nearly 9000. If the problem is your editor, you should seriously consider switching. -- ~Ethan~ From python at mrabarnett.plus.com Wed Apr 23 19:08:27 2014 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 24 Apr 2014 00:08:27 +0100 Subject: Moving to an OOP model from an classically imperitive one In-Reply-To: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> References: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> Message-ID: <535847EB.6000401@mrabarnett.plus.com> On 2014-04-23 21:57, tim.thelion at gmail.com wrote: > Hello, > > I am currently writting a program called subuser(subuser.org), which > is written as classically imperative code. Subuser is, essentially, > a package manager. It installs and updates programs from > repositories. > > I have a set of source files > https://github.com/subuser-security/subuser/tree/master/logic/subuserCommands/subuserlib > which have functions in them. Each function does something to a > program, it identifies the program by the programs name. For > example, I have an installProgram function defined as such: > > def installProgram(programName, useCache): > > Now I've run into a flaw in this model. There are certain situations > where a "programName" is not a unique identifier. It is possible for > two repositories to each have a program with the same name. > Obviously, I could go through my code and replace all use of the > string "programName" with a tuple of (programName, repository). Or I > could define a new class with two attributes: programName and > repository, and pass such a simple object arround, or pass a > dictionary. However, I think this would be better solved by moving > fully to an OOP model. That is, I would have a SubuserProgram class > which had methods such as "install", "describe", "isInstalled"... > [snip] Could you make the program name unique just by combining it with the repository name in a single string? From rosuav at gmail.com Wed Apr 23 19:12:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Apr 2014 09:12:18 +1000 Subject: Moving to an OOP model from an classically imperitive one In-Reply-To: <535833D5.7040500@stoneleaf.us> References: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> <535833D5.7040500@stoneleaf.us> Message-ID: On Thu, Apr 24, 2014 at 7:42 AM, Ethan Furman wrote: > On 04/23/2014 01:57 PM, tim.thelion at gmail.com wrote: >> >> >> There is one problem though. Currently, I have these functions logically >> organized into source files, each between 40 and 170 LOC. I fear that if >> I were to put all of these functions into one class, than I would have a >> single, very large source file. I don't like working with large source >> files for practicall reasons. > > > I'm curious what these practical reasons are. One my smallest source files > has 870 lines in it, my largest nearly 9000. > > If the problem is your editor, you should seriously consider switching. It's probably not the case here, but one good reason for splitting a file into pieces is to allow separate people or systems to update different parts. Lots of Linux programs support either /etc/foobar.conf or /etc/foobar.conf.d/ where the former is one file and the latter is a directory of separate files, generally deemed to be concatenated to the main config file. (Example: /etc/apt/sources.list and /etc/apt/sources.list.d/ - the main config for your Debian repositories, the directory for additional ones for VirtualBox or PostgreSQL.) It's easier to allow someone to completely overwrite a file than to try to merge changes. But that's not often the case with source code. ChrisA From tjreedy at udel.edu Wed Apr 23 19:50:41 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 23 Apr 2014 19:50:41 -0400 Subject: how to write list in a file In-Reply-To: References: Message-ID: On 4/23/2014 3:53 AM, Dhananjay wrote: > Hello everyone, > > I am trying hard to write a list to a file as follows: > > > def average_ELECT(pwd): > os.chdir(pwd) I would 'print pwd' to make sure where files are being opened. > files = filter(os.path.isfile, os.listdir('./')) > folders = filter(os.path.isdir, os.listdir('./')) > eelec = 0.0; evdw = 0.0; EELEC = []; elecutoff = []; > g = Gnuplot.Gnuplot() > for f1 in files: > # if f1[21:23]=='12': > if f1[27:29]==sys.argv[1]: # vdw cutoff remains constant; see > 2nd column of output > fl1 = open(f1,'r').readlines() > # print len(fl1) > > for i in range(1, len(fl1)): > fl1[i]=fl1[i].split() > eelec = eelec + float(fl1[i][1]) > evdw = evdw + float(fl1[i][2]) > #print fl1[i][1], fl1[i][2] > avg_eelec = eelec/40 > avg_evdw = evdw/40 > # print eelec, evdw > # print f1[21:23], f1[27:29], avg_eelec, avg_evdw > print f1[21:23], f1[27:29], avg_eelec > # EELEC.append(avg_eelec); elecutoff.append(float(f1[21:23])) > eelec=0.0; evde=0.0; > a = f1[21:23]+' '+f1[27:29]+' '+str(avg_eelec) > EELEC.append(a) > print sorted(EELEC) > with open('EElect_elec12-40_vdwxxx.dat','w') as wr: > for i in EELEC: > print i > wr.write("%s\n" % i) > wr.close() > > > The script is printing "print sorted(EELEC)" as well as "print > f1[21:23], f1[27:29], avg_eelec" very well. > However, for some reason, I neither see any file (expected to see > EElect_elec12-40_vdwxxx.dat as per the script) generated nor any error > message. > > Could anyone suggest me correction here. > > Thanking you in advance. > > -- DJ > > > > -- Terry Jan Reedy From tjreedy at udel.edu Wed Apr 23 19:59:01 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 23 Apr 2014 19:59:01 -0400 Subject: why my cur.executescript can not run? In-Reply-To: References: Message-ID: On 4/23/2014 7:23 AM, length power wrote: > please download the attachment Cinfo.zip. Please do not post with attachments. This is a text list, and binary attachments can be a vehicle for malware. Instead, reduce your code to the minimum necessary to exhibit the problem and include it in the post, or if still too large, include a link to a storage location on the web where it can be viewed in a browser before downloading. -- Terry Jan Reedy From tjreedy at udel.edu Wed Apr 23 20:09:03 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 23 Apr 2014 20:09:03 -0400 Subject: App segmentation fault (CentOS 6.5) In-Reply-To: References: <34645889-9400-4d02-8577-ee29a723c447@googlegroups.com> Message-ID: On 4/23/2014 3:46 PM, Mark H Harris wrote: > On 4/23/14 1:08 PM, Reginaldo wrote: >> >> I have a GUI app that is written using wx. When I run it on CentOS >> 6.5, the following error messages are displayed and the app closes: > > Only fails on CentOS ? > > >> I use an idle thread in my application. > > Is your CentOS launching idle with -n switch ? I am quite sure that his 'idle thread' had nothing to do with Idle. Rather, it should be a thread that runs when the app is otherwise idle. However, if he were trying to run wx and Idle/tk in the same process, I would expect problems. -- Terry Jan Reedy From greg.ewing at canterbury.ac.nz Wed Apr 23 20:21:06 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 24 Apr 2014 12:21:06 +1200 Subject: Moving to an OOP model from an classically imperitive one In-Reply-To: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> References: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> Message-ID: tim.thelion at gmail.com wrote: > I think this would be better solved > by moving fully to an OOP model. That is, I would have a SubuserProgram > class which had methods such as "install", "describe", "isInstalled"... This wouldn't necessarily be better. Don't be taken in by the "everything is better as a class" kind of dogma that seems to prevail in some circles. If all you do is take a bunch of module-level functions and put them into a single class, you haven't really changed anything. It's still the same design, you've just arranged the source differently. There are a couple of good reasons for turning a function into a method. One is if it embodies implementation details that you want to keep separated from the rest of the program. But if *all* of your code is inside the class, there isn't any "rest of the program" to keep it separate from. Another is if you want to be able to override it in subclasses. If there were different kinds of SubuserProgram that needed to be installed in different ways, for example, it would make sense to structure this as a collection of classes with an install() method. But even then, you don't have to put all the installation code in the classes -- the methods could just be stubs that call out to different module-level functions if you wanted. A reasonable compromise might be to keep the *data* assocated with a SubuserProgram in a class, maybe together with a few methods that are tightly coupled to it, but have the major pieces of functionality such as install() implemented by separate functions that operate *on* the class, rather than being inside it. > Currently, I have these functions logically > organized into source files, each between 40 and 170 LOC. That's quite small as these things typically go. You can afford to make them somewhat larger; I tend to find that files start to get unwieldy around 1000 lines or so. -- Greg From greg.ewing at canterbury.ac.nz Wed Apr 23 20:26:46 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 24 Apr 2014 12:26:46 +1200 Subject: Moving to an OOP model from an classically imperitive one In-Reply-To: References: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> Message-ID: Ian Kelly wrote: > How > about adding one abstract class per file, and then letting > SubuserProgram inherit from each of those individual classes? I'd recommend against that kind of thing, because it makes the code hard to follow. With module-level functions, you can tell where any given function is coming from by looking at the imports (as long as you haven't used 'import *', which is a bad idea for this very reason). But if you're looking at a method call on a class that inherits from half a dozen base classes, it's hard to tell which class it's implemented in. In other words, massively multiple inheritance is the OO equivalent of 'import *'. The same goes for any scheme for injecting methods into a class after defining it, only more so, because the reader won't be expecting weird things like that. -- Greg From justin.ezequiel at gmail.com Wed Apr 23 20:58:38 2014 From: justin.ezequiel at gmail.com (Justin Ezequiel) Date: Wed, 23 Apr 2014 17:58:38 -0700 (PDT) Subject: retrieve source code from code object as returned by compile() Message-ID: <4dfca89b-82c6-42f4-aedb-2fe82a7f7dc1@googlegroups.com> Is there a way to get the original source? I am trying to retrieve the main script from a py2exe'd old program. The programmer neglected to commit to SVN before leaving. Using "Easy Python Decompiler" I am able to get the source for the imported modules. Using "Resources Viewer" from PlexData and some code I am able to retrieve the code object. I am however stumped as to how to retrieve the source from this code object. PythonWin 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32. Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for further copyright information. >>> s = 'import time\nprint time.time()\n' >>> c = compile(s, 'foo.py', 'exec') >>> exec(c) 1398299623.77 >>> c at 01E5C5C0, file "foo.py", line 1> >>> for n in dir(c): ... if n.startswith('_'): continue ... print n ... a = getattr(c, n) ... print type(a) ... print `a` ... print ... co_argcount 0 co_cellvars () co_code 'd\x00\x00d\x01\x00k\x00\x00Z\x00\x00e\x00\x00i\x00\x00\x83\x00\x00GHd\x01\x00S' co_consts (-1, None) co_filename 'foo.py' co_firstlineno 1 co_flags 64 co_freevars () co_lnotab '\x0c\x01' co_name '' co_names ('time',) co_nlocals 0 co_stacksize 2 co_varnames () >>> len(s) 30 >>> len(c.co_code) 27 >>> From nispray at gmail.com Wed Apr 23 21:31:24 2014 From: nispray at gmail.com (Wesley) Date: Wed, 23 Apr 2014 18:31:24 -0700 (PDT) Subject: App segmentation fault (CentOS 6.5) In-Reply-To: <34645889-9400-4d02-8577-ee29a723c447@googlegroups.com> References: <34645889-9400-4d02-8577-ee29a723c447@googlegroups.com> Message-ID: ? 2014?4?24????UTC+8??2?08?29??Reginaldo??? > Hi, > > > > I have a GUI app that is written using wx. When I run it on CentOS 6.5, the following error messages are displayed and the app closes: > > > > (python:10096): Pango-WARNING **: shaping failure, expect ugly output. shape-engine='BasicEngineFc', font='DejaVu Sans 10.9990234375', text='' > > > > (python:10096): Pango-CRITICAL **: pango_layout_get_line_count: assertion `layout != NULL' failed > > > > (python:10096): Gdk-CRITICAL **: IA__gdk_draw_layout: assertion `PANGO_IS_LAYOUT (layout)' failed > > Segmentation fault > > > > I checked if this was a font issue, but the font is installed on the system. > > > > I use an idle thread in my application. > > > > Could some let me know what the problem may be in this case? Thank you! > > > > Python Version used: 2.6.6 > > wxPython Version used: 2.8.11 Maybe you can gdb python attach the running pid and check the backtrace. Severay days ago, I use this guy to address thread hang and memory leak issues. Just say here if that helps. From davea at davea.name Wed Apr 23 21:45:38 2014 From: davea at davea.name (Dave Angel) Date: Wed, 23 Apr 2014 21:45:38 -0400 (EDT) Subject: how to write list in a file References: Message-ID: Terry Reedy Wrote in message: > On 4/23/2014 3:53 AM, Dhananjay wrote: >> Hello everyone, >> >> I am trying hard to write a list to a file as follows: >> >> >> def average_ELECT(pwd): >> os.chdir(pwd) > > I would 'print pwd' to make sure where files are being opened. > >> files = filter(os.path.isfile, os.listdir('./')) >> I wouldn't. I've seen too many flaky problems to trust os.chdir in real code. I think the op should build each filename with os.path.append or similar. All paths used for actual file operations should either be absolute, or strictly relative to the user's cwd when the script started. And even the latter is suspect when you're anywhere near Windows. -- DaveA From davea at davea.name Wed Apr 23 22:01:34 2014 From: davea at davea.name (Dave Angel) Date: Wed, 23 Apr 2014 22:01:34 -0400 (EDT) Subject: Moving to an OOP model from an classically imperitive one References: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> Message-ID: tim.thelion at gmail.com Wrote in message: > I don't really understand your problem or your examples, but others apparently do. So I'll just make a few comments. > > There is one problem though. Currently, I have these functions logically organized into source files, each between 40 and 170 LOC. I fear that if I were to put all of these functions into one class, than I would have a single, very large source file. I don't like working with large source files for practicall reasons. Definitely limit your source file size. 10k lines is probably a good limit. > If I am to define the class SubuserProgram in the file SubuserProgram.py, That's a big mistake right there. Never let the module name match the class name. If you really only happen to have a single class in the file, then just use lower case for the filename. -- DaveA From greg.ewing at canterbury.ac.nz Thu Apr 24 01:53:38 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 24 Apr 2014 17:53:38 +1200 Subject: retrieve source code from code object as returned by compile() In-Reply-To: <4dfca89b-82c6-42f4-aedb-2fe82a7f7dc1@googlegroups.com> References: <4dfca89b-82c6-42f4-aedb-2fe82a7f7dc1@googlegroups.com> Message-ID: Justin Ezequiel wrote: > Using "Easy Python Decompiler" I am able to get the source for the imported > modules. Using "Resources Viewer" from PlexData and some code I am able to > retrieve the code object. I am however stumped as to how to retrieve the > source from this code object. Easy Python Decompiler should be able to do that, but you may need to delve into its innards a bit to find an entry point where you can feed in a code object. Alternatively you could create a .pyc file out of the code object and then use Easy Python Decompiler on that. The following snippet of code should do that: import marshal import py_compile import time with open('output.pyc', 'wb') as fc: fc.write('\0\0\0\0') py_compile.wr_long(fc, long(time.time())) marshal.dump(codeobject, fc) fc.flush() fc.seek(0, 0) fc.write(py_compile.MAGIC) (Taken from: http://stackoverflow.com/questions/8627835/generate-pyc-from-python-ast) -- Greg From tim.thelion at gmail.com Thu Apr 24 03:21:18 2014 From: tim.thelion at gmail.com (tim.thelion at gmail.com) Date: Thu, 24 Apr 2014 00:21:18 -0700 (PDT) Subject: Moving to an OOP model from an classically imperitive one In-Reply-To: References: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> Message-ID: <6bf23ea5-e534-486e-adc9-675fe97fa414@googlegroups.com> > [snip] > > Could you make the program name unique just by combining it with the > > repository name in a single string? In my case I cannot. But there is a larger reason why I wouldn't do this: It would mean adding a special character that could not be included in the repository name, that is, if I were to create a "unique-program-name" string which was of the format repo+"-"+programName then the repo name could not have the "-" symbol in it. Tim From tim.thelion at gmail.com Thu Apr 24 03:32:48 2014 From: tim.thelion at gmail.com (tim.thelion at gmail.com) Date: Thu, 24 Apr 2014 00:32:48 -0700 (PDT) Subject: Moving to an OOP model from an classically imperitive one In-Reply-To: References: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> Message-ID: <3220d8af-5961-410b-9e79-93a69c029672@googlegroups.com> > I'm curious what these practical reasons are. One my smallest source files has 870 lines in it, my largest nearly 9000. > > > > If the problem is your editor, you should seriously consider switching. > I think that the main reasons for doing so are as follows: git status provides much more usefull output when the source files are separate. If all your code is in one file, than git status tells you nothing about what has changed, yet git diff will provide you with overly verbose output. The seccond reason is that when refactoring code, it is much easier to manage a todo list when one knows which files have been processed already/what needs to be processed. This is especially true if the refactor will take several days or be done by several people. Tim From rosuav at gmail.com Thu Apr 24 03:36:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 Apr 2014 17:36:29 +1000 Subject: Moving to an OOP model from an classically imperitive one In-Reply-To: <6bf23ea5-e534-486e-adc9-675fe97fa414@googlegroups.com> References: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> <6bf23ea5-e534-486e-adc9-675fe97fa414@googlegroups.com> Message-ID: On Thu, Apr 24, 2014 at 5:21 PM, wrote: >> [snip] >> >> Could you make the program name unique just by combining it with the >> >> repository name in a single string? > > In my case I cannot. But there is a larger reason why I wouldn't do this: It would mean adding a special character that could not be included in the repository name, that is, if I were to create a "unique-program-name" string which was of the format repo+"-"+programName then the repo name could not have the "-" symbol in it. > Can you, then, simply substitute a tuple for the string? Instead of comparing program name strings, compare tuples of (repo, program_name) - it should work just fine. ChrisA From info at egenix.com Thu Apr 24 04:47:05 2014 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Thu, 24 Apr 2014 10:47:05 +0200 Subject: ANN: eGenix mxODBC Connect 2.0.5 - Python ODBC Database Interface Message-ID: <5358CF89.9040802@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC Connect Python ODBC Database Interface Version 2.0.5 mxODBC Connect is our commercially supported client-server product for connecting Python applications to relational databases in a truly platform independent way. This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-Connect-2.0.5-GA.html ________________________________________________________________________ INTRODUCTION The mxODBC Connect Database Interface for Python allows users to easily connect Python applications to all major databases on the market today in a highly portable, convenient and secure way. Python Database Connectivity the Easy Way ----------------------------------------- Unlike our mxODBC Python extension, mxODBC Connect is designed as client-server application, so you no longer need to find production quality ODBC drivers for all the platforms you target with your Python application. Instead you use an easy to install royalty-free Python client library which connects directly to the mxODBC Connect database server over the network. This makes mxODBC Connect a great basis for writing cross-platform multi-tier database applications and utilities in Python, especially if you run applications that need to communicate with databases such as MS SQL Server and MS Access, Oracle Database, IBM DB2 and Informix, Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more, that run on Windows or Linux machines. Ideal for Database Driven Client Applications --------------------------------------------- By removing the need to install and configure ODBC drivers on the client side and dealing with complicated network setups for each set of drivers, mxODBC Connect greatly simplifies deployment of database driven client applications, while at the same time making the network communication between client and database server more efficient and more secure. For more information, please have a look at the mxODBC Connect product page, in particular, the full list of available features. For more information, please see the product page: http://www.egenix.com/products/python/mxODBCConnect/ ________________________________________________________________________ NEWS The 2.0.5 release of mxODBC Connect includes the following enhancements and fixes: Security Enhancements --------------------- * Upgraded client and server to the most recent eGenix pyOpenSSL Distribution 0.13.3.1.0.1.7 (see http://egenix.com/go54 for details) to address the recently found Heartbleed Bug in OpenSSL 1.0.1 - 1.0.1f: - CVE-2014-0160 ("Heartbleed Bug"): A missing bounds check in the handling of the TLS heartbeat extension can be used to reveal up to 64kB of memory to a connected client or server. This issue did not affect versions of OpenSSL prior to 1.0.1. For information, also have a look at the Heartbleed Bug website: http://heartbleed.com/ For the full set of changes, please check the mxODBC Connect change log: http://www.egenix.com/products/python/mxODBCConnect/changelog.html mxODBC Connect 2.0 Highlights ----------------------------- mxODBC Connect 2.0 was released on 2012-08-20. These are the most important highlights: * mxODBC Connect Server now uses mxODBC 3.2 internally and makes its API available in the mxODBC Connect Client. This is a major step forward from the mxODBC 3.0 version used in mxODBC Connect Server 1.0. * We've added native Windows x64 builds. * mxODBC Connect Client now integrates directly with gevent, allowing client applications to run asynchronous tasks while performing remote database queries. Please see the release announcement for full details: http://www.egenix.com/company/news/eGenix-mxODBC-Connect-2.0.0-GA.html ________________________________________________________________________ UPGRADING You are encouraged to upgrade to this latest mxODBC Connect release. When upgrading, please always upgrade both the server and the client installations to the same version - even for patch level releases. Customers who have purchased mxODBC Connect 2.0 licenses can continue to use their licenses with this patch level release. Customers who have purchased mxODBC Connect 1.x licenses can request 20% discount coupons for upgrade purchases. Please contact the eGenix.com Sales Team (sales at egenix.com) with your existing license serials for details. Users of our stand-alone mxODBC product will have to purchase new licenses from our online shop in order to use mxODBC Connect. You can request 30-day evaluation licenses by visiting our web-site or writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. http://www.egenix.com/products/python/mxODBCConnect/#Evaluation ________________________________________________________________________ DOWNLOADS The download archives as well as instructions for installation and configuration of the product can be found on the product page: http://www.egenix.com/products/python/mxODBCConnect/ If you want to try the package, jump straight to the download instructions: https://cms.egenix.com/products/python/mxODBCConnect/#Download Fully functional evaluation licenses for the mxODBC Connect Server are available free of charge: http://www.egenix.com/products/python/mxODBCConnect/#Evaluation mxODBC Connect Client is always free of charge. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. _______________________________________________________________________ INFORMATION About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert project services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From steve at pearwood.info Thu Apr 24 05:08:22 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 24 Apr 2014 09:08:22 GMT Subject: Moving to an OOP model from an classically imperitive one References: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> <6bf23ea5-e534-486e-adc9-675fe97fa414@googlegroups.com> Message-ID: <5358d486$0$11109$c3e8da3@news.astraweb.com> On Thu, 24 Apr 2014 00:21:18 -0700, tim.thelion wrote: >> [snip] >> >> Could you make the program name unique just by combining it with the >> >> repository name in a single string? > > In my case I cannot. But there is a larger reason why I wouldn't do > this: It would mean adding a special character that could not be > included in the repository name, Do you support \n or \r or \0 in repo names? If not, then there you go, three special characters to choose from. But I suspect that a tuple of (repo_name, program_name) will be better. -- Steven From info at egenix.com Thu Apr 24 05:56:16 2014 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Thu, 24 Apr 2014 11:56:16 +0200 Subject: ANN: Python Meeting =?UTF-8?B?RMO8c3NlbGRvcmYgLSAyOS4wNC4yMDE0?= Message-ID: <5358DFC0.8070707@egenix.com> [This announcement is in German since it targets a local user group meeting in D?sseldorf, Germany] ________________________________________________________________________ ANK?NDIGUNG Python Meeting D?sseldorf http://pyddf.de/ Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosph?re. Dienstag, 29.04.2014, 19:00 Uhr Raum 1, 2.OG im B?rgerhaus Stadtteilzentrum Bilk D?sseldorfer Arcaden, Bachstr. 145, 40217 D?sseldorf Diese Nachricht ist auch online verf?gbar: http://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2014-04-29 ________________________________________________________________________ NEUIGKEITEN * Bereits angemeldete Vortr?ge: Charlie Clark "Status openpyxl, bzw. L?sung neuer Probleme" "IndexedList - eine Liste optimiert f?r "in" Abfragen" "Bericht von der PyCon 2014 in Montreal" Marc-Andre Lemburg "Python Code mit lib2to3 modernisieren" "DDOS Attacken mit Python bek?mpfen" "Bericht von der FOSDEM 2014" Wir suchen noch weitere Vortr?ge. Bei Interesse, bitte unter info at pyddf.de melden. * Ge?nderte Startzeit: Dieses Mal treffen wir uns erst um 19:00 Uhr im B?rgerhaus in den D?sseldorfer Arcaden, da wir keinen Termin f?r 18 Uhr bekommen haben. Hier eine kurze Beschreibung: Das B?rgerhaus teilt sich den Eingang mit dem Schwimmbad und befindet sich an der Seite der Tiefgarageneinfahrt der D?sseldorfer Arcaden. ?ber dem Eingang steht ein gro?es ?Schwimm?'in Bilk? Logo. Hinter der T?r direkt links zu den zwei Aufz?gen, dann in den 2. Stock hochfahren. Der Eingang zum Raum 1 liegt direkt links, wenn man aus dem Aufzug kommt. Google Street View: http://bit.ly/11sCfiw ________________________________________________________________________ EINLEITUNG Das Python Meeting D?sseldorf ist eine regelm??ige Veranstaltung in D?sseldorf, die sich an Python Begeisterte aus der Region wendet: * http://pyddf.de/ Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: * http://www.youtube.com/pyddf/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: * http://www.egenix.com/ * http://www.clark-consulting.eu/ ________________________________________________________________________ PROGRAMM Das Python Meeting D?sseldorf nutzt eine Mischung aus Open Space und Lightning Talks, wobei die Gewitter bei uns auch schon mal 20 Minuten dauern k?nnen ;-). Lightning Talks k?nnen vorher angemeldet werden, oder auch spontan w?hrend des Treffens eingebracht werden. Ein Beamer mit XGA Aufl?sung steht zur Verf?gung. Folien bitte als PDF auf USB Stick mitbringen. Lightning Talk Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ KOSTENBETEILIGUNG Das Python Meeting D?sseldorf wird von Python Nutzern f?r Python Nutzer veranstaltet. Um die Kosten zumindest teilweise zu refinanzieren, bitten wir die Teilnehmer um einen Beitrag in H?he von EUR 10,00 inkl. 19% Mwst, Sch?ler und Studenten zahlen EUR 5,00 inkl. 19% Mwst. Wir m?chten alle Teilnehmer bitten, den Betrag in bar mitzubringen. ________________________________________________________________________ ANMELDUNG Da wir nur f?r ca. 20 Personen Sitzpl?tze haben, m?chten wir bitten, sich per EMail anzumelden. Damit wird keine Verpflichtung eingegangen. Es erleichtert uns allerdings die Planung. Meeting Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ WEITERE INFORMATIONEN Weitere Informationen finden Sie auf der Webseite des Meetings: http://pyddf.de/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From info at wingware.com Thu Apr 24 08:56:26 2014 From: info at wingware.com (Wingware) Date: Thu, 24 Apr 2014 08:56:26 -0400 Subject: ANN: Wing IDE 5.0.6 released Message-ID: <535909FA.70304@wingware.com> Hi, Wingware has released version 5.0.6 of Wing IDE, our cross-platform integrated development environment for the Python programming language. Wing IDE includes a professional quality code editor with vi, emacs, visual studio, and other key bindings, auto-completion, call tips, goto-definition, find uses, refactoring, context-aware auto-editing, a powerful graphical debugger, version control, unit testing, search, and many other features. For details see http://wingware.com/ Changes in this minor release include: * New auto-editing operation for starting a new block when ':' is pressed while a range of lines is selected. This also auto-enters 'except:' if 'try' is then entered. * Offer completion on argument names in a def * New Editor > Block Comment Style preference option to use PEP8 style indented '# ' for commenting out code * On OS X, Wing no longer quits when the last window is closed, to match the standard for Mac applications * Restart correctly after downloading patches * Pick up changes made in the debug dialog when debugging a named entry point * Avoid hiding file selection auto-completer popup too soon * Set sys.path[0] correctly in Python Shell on OS X and Linux * Fix cleanup after auto-invocation that spans multiple lines * About 15 other bug fixes For details see http://wingware.com/pub/wingide/5.0.6/CHANGELOG.txt A summary of new features in Wing 5: * Redesigned GUI based on Qt and PySide * Native GUI on OS X (and better overall OS-native look and feel) * Tools and editors can be dragged around * Toolbar and editor and Project context menus are configurable * Optional mode that opens different sets of files in each editor split * Sharable color palettes and syntax highlighting configurations * Auto-editing is on by default (except some operations that have a learning curve) * Named file sets * Sharable launch configurations * Named entry points * More control over unit testing environment * Lockable editor splits * Initial preferences dialog for new users * Support for Python 3.4 * Support for Django 1.6 * Support for matplotlib on Anaconda and with MacOSX backend * Improved Source Assistant with PEP 287 docstring rendering and return types * Improved integrated and PDF documentation For more information on what's new in Wing 5, see http://wingware.com/wingide/whatsnew Free trial: http://wingware.com/wingide/trial Downloads: http://wingware.com/downloads Feature list: http://wingware.com/wingide/features Sales: http://wingware.com/store/purchase Upgrades: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at support at wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE The Intelligent Development Environment for Python Programmers wingware.com From __peter__ at web.de Thu Apr 24 11:10:56 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 24 Apr 2014 17:10:56 +0200 Subject: why my cur.executescript can not run? References: Message-ID: length power wrote: > When cur.execute be used, i get right output. > > import sqlite3 > con=sqlite3.connect(":memory:") > cur=con.cursor() > sql1="attach database 'g:\\workspace\\data\\Cinfo.sqlite' as Cinfo;" > sql2="select * from Cinfo.ipo;" > cur.execute(sql1) > cur.execute(sql2) > con.commit() > x=cur.fetchall()print(x) > > When i change it into cur.executescript, nothing can get. > > import sqlite3 > con=sqlite3.connect(":memory:") > cur=con.cursor() > sql_script=""" > attach database 'g:\\workspace\\data\\Cinfo.sqlite' as Cinfo; > select * from Cinfo.ipo;""" > cur.executescript(sql_script) > con.commit() > x=cur.fetchall()print(x) > > I want to know why? The difference has nothing to do with your specific code, as the following minimal example shows: >>> import sqlite3 >>> cs = sqlite3.connect(":memory:").cursor() >>> cs.execute("select 42;").fetchall() [(42,)] >>> cs.executescript("select 42;").fetchall() [] The docs don't say so explicitly, but my guess is that executescript() is meant to execute sql statements for their side effect (like populating a database) only, not to return a result. Please file a bug report if you want a clarification in the docs. From rohit782192 at gmail.com Thu Apr 24 11:32:55 2014 From: rohit782192 at gmail.com (rohit782192 at gmail.com) Date: Thu, 24 Apr 2014 08:32:55 -0700 (PDT) Subject: Installing PyGame? In-Reply-To: <5c069831-8cab-43da-a4f9-ccec68cdc101@googlegroups.com> References: <5c069831-8cab-43da-a4f9-ccec68cdc101@googlegroups.com> Message-ID: On Saturday, June 8, 2013 9:37:44 PM UTC+5:30, Eam onn wrote: > Perhaps this isn't the right place to post this, but it's the only place I could find. > > > > I asked yesterday or the day before about Python Game Development, and have found a few tutorials on PyGame. Now I have a bigger problem: HOW THE HECK DO I INSTALL PYGAME!?!?! System Details: > > > > * Mac OS X 10.8.4 Mountain Lion > > * 4GB DDR3 RAM > > > > I do have Window's installed, as well as Ubuntu 11.04 but I would like to use Mac OS X if possible. I've tried using MacPorts, Fink, the Mac DMG, source installing, installing NumPY, just about every way possible. I can't seem to get it working, I keep getting an error in all my versions of IDLE. I've tried: > > > > * IDLE 2.5 > > * IDLE 2.7.2 > > * IDLE 2.7.3 > > * IDLE 3.1 > > * IDLE 3.3.1 > > > > None of the versions work. I'm using PyGame 1.9.1. > > > > Thanks! Any help is appreciated! From tim.thelion at gmail.com Thu Apr 24 12:53:19 2014 From: tim.thelion at gmail.com (tim.thelion at gmail.com) Date: Thu, 24 Apr 2014 09:53:19 -0700 (PDT) Subject: Moving to an OOP model from an classically imperitive one In-Reply-To: References: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> Message-ID: <89bbe51e-2f07-4d80-844d-2e252733cace@googlegroups.com> > A reasonable compromise might be to keep the *data* assocated > > with a SubuserProgram in a class, maybe together with a few > > methods that are tightly coupled to it, but have the major > > pieces of functionality such as install() implemented by > > separate functions that operate *on* the class, rather than > > being inside it. > I think this is sound advice. I'm still not sure what I'll come up with. One of the other reasons why an OOP model might be right for me is that of caching. I currently load a lot of attributes regarding programs from disk, and I do so multiple times, I could either pass those attributes around, OR, using a class, I could store those attributes in the object after loading them just once. I have no experience with OOP except in the domain of GUIs(where it seems inescapable, all major toolkits use OOP), so I'm not yet sure how this will turn out. Tim From tjreedy at udel.edu Thu Apr 24 15:15:09 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 24 Apr 2014 15:15:09 -0400 Subject: Installing PyGame? In-Reply-To: References: <5c069831-8cab-43da-a4f9-ccec68cdc101@googlegroups.com> Message-ID: On 4/24/2014 11:32 AM, rohit782192 at gmail.com wrote: When you post, please do more than just quote. If you are relaying a private email, please say so. > On Saturday, June 8, 2013 9:37:44 PM UTC+5:30, Eam onn wrote: I did not see the original post, if indeed there was a public one. [snip pygame/numpy problems] ... >> I do have Window's installed, as well as Ubuntu 11.04 but I would >> like to use Mac OS X if possible. I've tried using MacPorts, Fink, >> the Mac DMG, source installing, installing NumPY, just about every >> way possible. I can't seem to get it working, I keep getting an >> error in all my versions of IDLE. I've tried: >> * IDLE 2.5 >> * IDLE 2.7.2 >> * IDLE 2.7.3 >> * IDLE 3.1 >> * IDLE 3.3.1 Idle depends on tkinter. Tkinter depends on having a tcl/tk that works, at least for tkinter. The following page has essential info about getting the right tcl/tk installed. https://www.python.org/download/mac/tcltk -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Thu Apr 24 21:17:45 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Apr 2014 01:17:45 GMT Subject: Installing PyGame? References: <5c069831-8cab-43da-a4f9-ccec68cdc101@googlegroups.com> Message-ID: <5359b7b8$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 24 Apr 2014 15:15:09 -0400, Terry Reedy wrote: > On 4/24/2014 11:32 AM, rohit782192 at gmail.com wrote: > > When you post, please do more than just quote. If you are relaying a > private email, please say so. > >> On Saturday, June 8, 2013 9:37:44 PM UTC+5:30, Eam onn wrote: > > I did not see the original post, if indeed there was a public one. Check out the date. It was over ten months ago. -- Steven D'Aprano http://import-that.dreamwidth.org/ From greg.ewing at canterbury.ac.nz Thu Apr 24 21:44:48 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 25 Apr 2014 13:44:48 +1200 Subject: Installing PyGame? In-Reply-To: References: <5c069831-8cab-43da-a4f9-ccec68cdc101@googlegroups.com> Message-ID: rohit782192 at gmail.com wrote: > On Saturday, June 8, 2013 9:37:44 PM UTC+5:30, Eam onn wrote: > >> Now I have a bigger problem: HOW THE HECK >> DO I INSTALL PYGAME!?!?! System Details: >> >> I've tried using MacPorts, Fink, the Mac DMG, >> source installing, installing NumPY, just about every way possible. My advice would be to steer clear of things like Fink and MacPorts and do things the native MacOSX way wherever possible. That means using a framework installation of Python and framework versions of the various libraries that PyGame uses. There are a number of steps to getting pygame working: 1) Make sure you have a working framework installation of an appropriate version of Python. I installed mine from source, but a binary installation should work too. Depending on your MacOSX version, the system python might be sufficient. 2) Install framework versions of the SDL library and other libraries that pygame uses. You may need to hunt around a bit, but you should be able to find DMG installers for all of these. In my /Library/Frameworks I have: SDL.framework SDL-QD.framework SDL_image.framework SDL_mixer.framework SDL_net.framework SDL_ttf.framework 3) Install pygame itself with the usual 'python setup.py install'. If you have all the relevant libraries, the installer will auto detect them and use them. At the end, it will tell you which ones it couldn't find. Pygame will work without some of them, but those features won't be available. You can add more libraries and run setup.py again if you need to. 4) Specific games may require other Python libraries such as Numpy etc. -- Greg From greg.ewing at canterbury.ac.nz Thu Apr 24 21:47:36 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 25 Apr 2014 13:47:36 +1200 Subject: Installing PyGame? In-Reply-To: References: <5c069831-8cab-43da-a4f9-ccec68cdc101@googlegroups.com> Message-ID: Terry Reedy wrote: > Idle depends on tkinter. Tkinter depends on having a tcl/tk that works, > at least for tkinter. The following page has essential info about > getting the right tcl/tk installed. > https://www.python.org/download/mac/tcltk Also keep in mind that you don't *have* to use IDLE at all. I do all my Python development on MacOSX using BBEdit Lite and the Terminal. If nothing else, you can try out pygame that way to see whether your problem is a pygame-related one or something else. -- Greg From nad at acm.org Thu Apr 24 22:38:09 2014 From: nad at acm.org (Ned Deily) Date: Thu, 24 Apr 2014 19:38:09 -0700 Subject: Installing PyGame? References: <5c069831-8cab-43da-a4f9-ccec68cdc101@googlegroups.com> Message-ID: In article , Gregory Ewing wrote: > My advice would be to steer clear of things like Fink and MacPorts > and do things the native MacOSX way wherever possible. That means > using a framework installation of Python and framework versions of > the various libraries that PyGame uses. FYI, MacPorts Pythons are framework installations. And I disagree that installing a bunch of disparate software from various sources via binary installers and/or source is to be preferred to a modern third-party package manager on OS X like MacPorts or Homebrew. That's just setting yourself up for a long-term maintenance headache. What could be easier than: sudo port install py27-game -- Ned Deily, nad at acm.org From justin.ezequiel at gmail.com Thu Apr 24 22:50:15 2014 From: justin.ezequiel at gmail.com (Justin Ezequiel) Date: Thu, 24 Apr 2014 19:50:15 -0700 (PDT) Subject: retrieve source code from code object as returned by compile() In-Reply-To: References: <4dfca89b-82c6-42f4-aedb-2fe82a7f7dc1@googlegroups.com> Message-ID: <3abe4779-a237-4113-aaf0-24990895151f@googlegroups.com> On Thursday, April 24, 2014 1:53:38 PM UTC+8, Gregory Ewing wrote: > Alternatively you could create a .pyc file out of the code > object and then use Easy Python Decompiler on that. The > following snippet of code should do that: > > (Taken from: > > http://stackoverflow.com/questions/8627835/generate-pyc-from-python-ast) Woohoo! Success! Thank you Greg! From ryan at ryanhiebert.com Thu Apr 24 23:59:04 2014 From: ryan at ryanhiebert.com (Ryan Hiebert) Date: Thu, 24 Apr 2014 22:59:04 -0500 Subject: Installing PyGame? In-Reply-To: References: <5c069831-8cab-43da-a4f9-ccec68cdc101@googlegroups.com> Message-ID: On Thu, Apr 24, 2014 at 9:38 PM, Ned Deily wrote: > In article , > Gregory Ewing wrote: > > My advice would be to steer clear of things like Fink and MacPorts > > and do things the native MacOSX way wherever possible. That means > > using a framework installation of Python and framework versions of > > the various libraries that PyGame uses. > > FYI, MacPorts Pythons are framework installations. And I disagree that > installing a bunch of disparate software from various sources via binary > installers and/or source is to be preferred to a modern third-party > package manager on OS X like MacPorts or Homebrew. That's just setting > yourself up for a long-term maintenance headache. What could be easier > than: > > sudo port install py27-game > > I'd love to hear more about Greg's take on MacPorts. I've chosen to use MacPorts because it keeps things separate, because when things get hosed using the system libraries, I don't have to erase my whole system to get back to a "vanilla" OS X install. Unfortunately, it seems like the differences in which libraries are used, what options are enabled at library build time, etc, make it difficult to ensure that things always work when you try to use the stuff built-in to the system, and untangling the Homebrew mess can be painful. -------------- next part -------------- An HTML attachment was scrubbed... URL: From smortaz at exchange.microsoft.com Fri Apr 25 02:36:44 2014 From: smortaz at exchange.microsoft.com (Shahrokh Mortazavi) Date: Fri, 25 Apr 2014 06:36:44 +0000 Subject: The PTVS gang (from microsoft) would like to hear from python-list users! In-Reply-To: <900ce9443e284900b5b709c44fb67c69@DFM-DB3MBX15-08.exchange.corp.microsoft.com> References: <900ce9443e284900b5b709c44fb67c69@DFM-DB3MBX15-08.exchange.corp.microsoft.com> Message-ID: <9d6b1f6cca8649ab9e9a955115906f9d@DFM-DB3MBX15-08.exchange.corp.microsoft.com> ? Hi - we're a few engineers (not marketers!) that work on Python Tools for Visual Studio (http://pytools.codeplex.com). It's a free & OSS plug-in that turns VS into a decent Python IDE. It has some nice features like mixed-mode Python/C++ debugging, debugging on Linux from Visual Studio and IPython integration. Some of our users have been encouraging us to enhance PTVS and add support for some "Data Science" focused features & scenarios. As such we'd *love* to get your input regarding your current stack, workflow and pain points before taking the next steps. It does not matter if you use Windows, Visual Studio, love/hate Microsoft - we'd just love to understand your environment a bit better especially if you use tools like Excel, R, Matlab, Mathematica, numpy, scipy, Pandas, ... As a thank you, 50 people will be randomly selected to receive a $5 Starbucks Coffee card! Here is a link to the survey which should take about 2 minutes to complete. https://www.surveymonkey.com/s/VSForDataScience If you know others that might be interested in taking this survey, *please* forward it to them - much appreciated. Thanks for your participation! -------------- next part -------------- An HTML attachment was scrubbed... URL: From balmukund151 at gmail.com Fri Apr 25 02:39:12 2014 From: balmukund151 at gmail.com (Code) Date: Thu, 24 Apr 2014 23:39:12 -0700 (PDT) Subject: Executing pl/sql script File in python without sqlclient Message-ID: Is there a way to execute pl/sql Script files through Python without sqlclient. i have checked cx_oracle and i guess it requires oracle client, so is there a way to execute without oracle client. From deepika at cdot.in Fri Apr 25 02:13:28 2014 From: deepika at cdot.in (Deepika Nagpal) Date: Fri, 25 Apr 2014 11:43:28 +0530 Subject: soap library for python-3.x Message-ID: <20140425060942.M51755@cdot.in> Hi, We have to start a project of developing a soap server in python-3.x for which I am looking for a soap server side library. Please let me know what are the options available and which of these libraries are actively maintained. Thanks. Regards, Deepika Nagpal -------------------------------------------------------------------------------- ::Disclaimer:: -------------------------------------------------------------------------------- The contents of this email and any attachment(s) are confidential and intended for the named recipient(s) only. It shall not attach any liability on C-DOT. Any views or opinions presented in this email are solely those of the author and may not necessarily reflect the opinions of C-DOT. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. -------------------------------------------------------------------------------- From jcasale at activenetwerx.com Fri Apr 25 07:44:26 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Fri, 25 Apr 2014 11:44:26 +0000 Subject: Executing pl/sql script File in python without sqlclient In-Reply-To: References: Message-ID: <7158ed86060d4292b0436b20fea89e26@exch.activenetwerx.com> > Is there a way to execute pl/sql Script files through Python without sqlclient. https://code.google.com/p/pypyodbc/ might work for you... > i have checked cx_oracle and i guess it requires oracle client, so is there a way to execute without oracle client. Right, as the name implies it uses the oci interface and hence needs that library available. jlc From lepto.python at gmail.com Fri Apr 25 09:07:53 2014 From: lepto.python at gmail.com (oyster) Date: Fri, 25 Apr 2014 21:07:53 +0800 Subject: how to split this kind of text into sections Message-ID: I have a long text, which should be splitted into some sections, where all sections have a pattern like following with different KEY. And the /n/r can not be used to split I don't know whether this can be done easily, for example by using RE module [demo text starts] a line we do not need I am section axax I am section bbb, we can find that the first 2 lines of this section all startswith 'I am section' .....(and here goes many other text)... let's continue to let's continue, yeah .....(and here goes many other text)... I am using python I am using perl .....(and here goes many other text)... [demo text ends] the above text should be splitted as a LIST with 3 items, and I also need to know the KEY for LIST is ['I am section', 'let's continue', 'I am using']: lst=[ '''I am section axax I am section bbb, we can find that the first 2 lines of this section all startswith 'I am section' .....(and here goes many other text)...''', '''let's continue to let's continue, yeah .....(and here goes many other text)...''', '''I am using python I am using perl .....(and here goes many other text)...''' ] I hope I have state myself clear. Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Fri Apr 25 09:18:22 2014 From: roy at panix.com (Roy Smith) Date: Fri, 25 Apr 2014 09:18:22 -0400 Subject: how to split this kind of text into sections References: Message-ID: In article , oyster wrote: > I have a long text, which should be splitted into some sections, where > all sections have a pattern like following with different KEY. And the /n/r > can not be used to split > > I don't know whether this can be done easily, for example by using RE module > > [demo text starts] > a line we do not need > I am section axax > I am section bbb, we can find that the first 2 lines of this section all > startswith 'I am section' > .....(and here goes many other text)... > let's continue to > let's continue, yeah > .....(and here goes many other text)... > I am using python > I am using perl > .....(and here goes many other text)... > [demo text ends] This kind of looks like a standard INI file. Check out https://docs.python.org/2/library/configparser.html, it may do what you need. From rosuav at gmail.com Fri Apr 25 09:31:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 Apr 2014 23:31:58 +1000 Subject: how to split this kind of text into sections In-Reply-To: References: Message-ID: On Fri, Apr 25, 2014 at 11:07 PM, oyster wrote: > the above text should be splitted as a LIST with 3 items, and I also need to > know the KEY for LIST is ['I am section', 'let's continue', 'I am using']: It's not perfectly clear, but I think I have some idea of what you're trying to do. Let me restate what I think you want, and you can tell be if it's correct. You have a file which consists of a number of lines. Some of those lines begin with the string "I am section", others begin "let's continue", and others begin "I am using". You want to collect those three sets of lines; inside each collection, every line will have that same prefix. Is that correct? If so, we can certainly help you with that. If not, please clarify. :) ChrisA From matt.pounsett at gmail.com Fri Apr 25 09:43:12 2014 From: matt.pounsett at gmail.com (Matthew Pounsett) Date: Fri, 25 Apr 2014 06:43:12 -0700 (PDT) Subject: MacOS 10.9.2: threading error using python.org 2.7.6 distribution Message-ID: I've run into a threading error in some code when I run it on MacOS that works flawlessly on a *BSD system running the same version of python. I'm running the python 2.7.6 for MacOS distribution from python.org's downloads page. I have tried to reproduce the error with a simple example, but so far haven't been able to find the element or my code that triggers the error. I'm hoping someone can suggest some things to try and/or look at. Googling for "pyton" and the error returns exactly two pages, neither of which are any help. When I run it through the debugger, I'm getting the following from inside threading.start(). python fails to provide a stack trace when I step into _start_new_thread(), which is a pointer to thread.start_new_thread(). It looks like threading.__bootstrap_inner() may be throwing an exception which thread.start_new_thread() is unable to handle, and for some reason the stack is missing so I get no stack trace explaining the error. It looks like thread.start_new_thread() is in the binary object, so I can't actually step into it and find where the error is occurring. > /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py(745)start() -> _start_new_thread(self.__bootstrap, ()) (Pdb) s > /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py(750)start() -> self.__started.wait() (Pdb) Warning: No stack to get attribute from Warning: No stack to get attribute from Warning: No stack to get attribute from Warning: No stack to get attribute from Warning: No stack to get attribute from Warning: No stack to get attribute from Warning: No stack to get attribute from Warning: No stack to get attribute from Warning: No stack to get attribute from Warning: No stack to get attribute from Warning: No stack to get attribute from Warning: No stack to get attribute from Warning: No stack to get attribute from Warning: No stack to get attribute from Warning: No stack to get attribute from Warning: No stack to get attribute from Warning: No stack to get attribute from Warning: No stack to get attribute from My test code (which works) follows the exact same structure as the failing code, making the same calls to the threading module's objects' methods: ---- import threading class MyThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): print "MyThread runs and exits." def main(): try: t = MyThread() t.start() except Exception as e: print "Failed with {!r}".format(e) if __name__ == '__main__': main() ---- The actual thread object that's failing looks like this: class RTF2TXT(threading.Thread): """ Takes a directory path and a Queue as arguments. The directory should be a collection of RTF files, which will be read one-by-one, converted to text, and each output line will be appended in order to the Queue. """ def __init__(self, path, queue): threading.Thread.__init__(self) self.path = path self.queue = queue def run(self): logger = logging.getLogger('RTF2TXT') if not os.path.isdir(self.path): raise TypeError, "supplied path must be a directory" for f in sorted(os.listdir(self.path)): ff = os.path.join(self.path, f) args = [ UNRTF_BIN, '-P', '.', '-t', 'unrtf.text', ff ] logger.debug("Processing file {} with args {!r}".format(f, args)) p1 = subprocess.Popen( args, stdout=subprocess.PIPE, universal_newlines=True) output = p1.communicate()[0] try: output = output.decode('utf-8', 'ignore') except Exception as err: logger.error("Failed to decode output: {}".format(err)) logger.error("Output was: {!r}".format(output)) for line in output.split("\n"): line = line.strip() self.queue.put(line) self.queue.put("") Note: I only run one instance of this thread. The Queue object is used to pass work off to another thread for later processing. If I insert that object into the test code and run it instead of MyThread(), I get the error. I can't see anything in there that should cause problems for the threading module though... especially since this runs fine on another system with the same version of python. Any thoughts on what's going on here? From ben at benfinney.id.au Fri Apr 25 09:48:27 2014 From: ben at benfinney.id.au (Ben Finney) Date: Fri, 25 Apr 2014 23:48:27 +1000 Subject: soap library for python-3.x References: <20140425060942.M51755@cdot.in> Message-ID: <8538h1mses.fsf@benfinney.id.au> "Deepika Nagpal" writes: > We have to start a project of developing a soap server in python-3.x > for which I am looking for a soap server side library. Please let me > know what are the options available and which of these libraries are > actively maintained. Thanks. You can start with . Good hunting! > -------------------------------------------------------------------------------- > ::Disclaimer:: > -------------------------------------------------------------------------------- > The contents of this email and any attachment(s) are confidential and > intended for the named recipient(s) only. It shall not [?] This is nonsense (you deliberately sent this message to a public forum), and obnoxious in its demands. Please ensure your future messages are sent without this boilerplate. -- \ ?I used to think that the brain was the most wonderful organ in | `\ my body. Then I realized who was telling me this.? ?Emo Philips | _o__) | Ben Finney From rosuav at gmail.com Fri Apr 25 10:05:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 26 Apr 2014 00:05:03 +1000 Subject: MacOS 10.9.2: threading error using python.org 2.7.6 distribution In-Reply-To: References: Message-ID: On Fri, Apr 25, 2014 at 11:43 PM, Matthew Pounsett wrote: > If I insert that object into the test code and run it instead of MyThread(), I get the error. I can't see anything in there that should cause problems for the threading module though... especially since this runs fine on another system with the same version of python. > > Any thoughts on what's going on here? First culprit I'd look at is the mixing of subprocess and threading. It's entirely possible that something goes messy when you fork from a thread. Separately: You're attempting a very messy charset decode there. You attempt to decode as UTF-8, errors ignored, and if that fails, you log an error... and continue on with the original bytes. You're risking shooting yourself in the foot there; I would recommend you have an explicit fall-back (maybe re-decode as Latin-1??), so the next code is guaranteed to be working with Unicode. Currently, it might get a unicode or a str. ChrisA From jamiemitchell1604 at gmail.com Fri Apr 25 10:07:54 2014 From: jamiemitchell1604 at gmail.com (Jamie Mitchell) Date: Fri, 25 Apr 2014 07:07:54 -0700 (PDT) Subject: len() of unsized object - ks test Message-ID: <9a3176b8-5011-497e-977c-15bac17fca6a@googlegroups.com> Hello all, I am trying to perform a Kolmogorov-Smirnov test in Python but I'm having a few difficulties. # My files are netCDF so I import them as follows: control=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/south_west/swhcontrol_swest_concatannavg_1D.nc','r') # The string is simply a 1D array # Then performing the ks test: kstest(control,'norm') # I then get the following error: File "", line 1, in File "/usr/local/sci/lib/python2.7/site-packages/scipy/stats/stats.py", line 3413, in kstest N = len(vals) TypeError: len() of unsized object Any ideas on why this isn't working would be great. Thanks, Jamie From python.list at tim.thechases.com Fri Apr 25 10:14:28 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 25 Apr 2014 09:14:28 -0500 Subject: how to split this kind of text into sections In-Reply-To: References: Message-ID: <20140425091428.5b70e712@bigbox.christie.dr> On 2014-04-25 23:31, Chris Angelico wrote: > On Fri, Apr 25, 2014 at 11:07 PM, oyster > wrote: > > the above text should be splitted as a LIST with 3 items, and I > > also need to know the KEY for LIST is ['I am section', 'let's > > continue', 'I am using']: > > It's not perfectly clear, but I think I have some idea of what > you're trying to do. Let me restate what I think you want, and you > can tell be if it's correct. > > You have a file which consists of a number of lines. Some of those > lines begin with the string "I am section", others begin "let's > continue", and others begin "I am using". You want to collect those > three sets of lines; inside each collection, every line will have > that same prefix. > > Is that correct? If so, we can certainly help you with that. If not, > please clarify. :) My reading of it (and it took me several tries) was that two subsequent lines would begin with the same N words. Something like the following regexp: ^(\w.{8,}).*\n\1.* as the delimiter (choosing "6" arbitrarily as an indication of a minimum match length to). A naive (and untested) bit of code might look something like MIN_LEN = 6 def overlap(s1, s2): chars = [] for c1, c2 in zip(s1,s2): if c1 != c2: break chars.append(c1) return ''.join(chars) prevline = "" output_number = 1 output = defaultdict(list) key = None with open("input.txt") as f: for line in f: if len(line) >= MIN_LEN and prevline[:MIN_LEN] == line[:MIN_LEN]: key = overlap(prevline, line) output[key].append(line) prevline = line There are some edge-cases such as when multiple sections are delimited by the same overlap, but this should build up a defaultdict keyed by the delimiters with the corresponding lines as the values. -tkc From python at mrabarnett.plus.com Fri Apr 25 11:13:28 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 25 Apr 2014 16:13:28 +0100 Subject: len() of unsized object - ks test In-Reply-To: <9a3176b8-5011-497e-977c-15bac17fca6a@googlegroups.com> References: <9a3176b8-5011-497e-977c-15bac17fca6a@googlegroups.com> Message-ID: <535A7B98.6030501@mrabarnett.plus.com> On 2014-04-25 15:07, Jamie Mitchell wrote: > Hello all, > > I am trying to perform a Kolmogorov-Smirnov test in Python but I'm having a few difficulties. > > # My files are netCDF so I import them as follows: > > control=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/south_west/swhcontrol_swest_concatannavg_1D.nc','r') > A brief look at the documentation online says that 'control' is an instance that _describes_ the dataset: """A netCDF Dataset is a collection of dimensions, groups, variables and attributes. Together they describe the meaning of data and relations among data fields stored in a netCDF file.""" So I don't think that it's the data itself. > # The string is simply a 1D array > > # Then performing the ks test: > > kstest(control,'norm') > > # I then get the following error: > > File "", line 1, in > File "/usr/local/sci/lib/python2.7/site-packages/scipy/stats/stats.py", line 3413, in kstest > N = len(vals) > TypeError: len() of unsized object > > Any ideas on why this isn't working would be great. > From jpiitula at ling.helsinki.fi Fri Apr 25 11:17:09 2014 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 25 Apr 2014 18:17:09 +0300 Subject: how to split this kind of text into sections References: Message-ID: oyster writes: > I have a long text, which should be splitted into some sections, where > all sections have a pattern like following with different KEY. itertools.groupby, if you know how to extract a key from a given line. > And the /n/r can not be used to split Yet you seem to want to have each line as a unit? You could group lines straight from some file object using itertools.groupby and then ''.join each group. (It's \n and \r, and \r\n when they are both there, but you can just let Python read the lines.) From steve+comp.lang.python at pearwood.info Fri Apr 25 11:18:33 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Apr 2014 15:18:33 GMT Subject: how to split this kind of text into sections References: Message-ID: <535a7cc8$0$29965$c3e8da3$5496439d@news.astraweb.com> On Fri, 25 Apr 2014 21:07:53 +0800, oyster wrote: > I have a long text, which should be splitted into some sections, where > all sections have a pattern like following with different KEY. And the > /n/r can not be used to split > > I don't know whether this can be done easily, for example by using RE > module [... snip example ...] > I hope I have state myself clear. Clear as mud. I'm afraid I have no idea what you mean. Can you explain the decision that you make to decide whether a line is included, or excluded, or part of a section? > [demo text starts] > a line we do not need How do we decide whether the line is ignored? Is it the literal text "a line we do not need"? for line in lines: if line == "a line we do not need\n": # ignore this line continue > I am section axax > I am section bbb, we can find that the first 2 lines of this section all > startswith 'I am section' Again, is this the *literal* text that you expect? > .....(and here goes many other text)... let's continue to > let's continue, yeah > .....(and here goes many other text)... > I am using python > I am using perl > .....(and here goes many other text)... > [demo text ends] > > the above text should be splitted as a LIST with 3 items, and I also > need to know the KEY for LIST is ['I am section', 'let's continue', 'I > am using']: How do you decide that they are the keys? > lst=[ > '''I am section axax > I am section bbb, we can find that the first 2 lines of this section all > startswith 'I am section' > .....(and here goes many other text)...''', > > '''let's continue to > let's continue, yeah > .....(and here goes many other text)...''', > > > '''I am using python > I am using perl > .....(and here goes many other text)...''' > ] Perhaps it would be better if you show a more realistic example. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Fri Apr 25 11:26:31 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Apr 2014 15:26:31 GMT Subject: len() of unsized object - ks test References: <9a3176b8-5011-497e-977c-15bac17fca6a@googlegroups.com> Message-ID: <535a7ea6$0$29965$c3e8da3$5496439d@news.astraweb.com> On Fri, 25 Apr 2014 07:07:54 -0700, Jamie Mitchell wrote: > Hello all, > > I am trying to perform a Kolmogorov-Smirnov test in Python but I'm > having a few difficulties. > > # My files are netCDF so I import them as follows: > > control=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/ south_west/swhcontrol_swest_concatannavg_1D.nc','r') > > # The string is simply a 1D array > > # Then performing the ks test: > > kstest(control,'norm') > > # I then get the following error: > > File "", line 1, in > File > "/usr/local/sci/lib/python2.7/site-packages/scipy/stats/stats.py", > line 3413, in kstest > N = len(vals) > TypeError: len() of unsized object > > Any ideas on why this isn't working would be great. My guess is that you are calling len() on something that doesn't have a length :-) But seriously, first of, what does "vals" contain? Look at the documentation for the kstest function. Does it have a parameter called "vals"? If so, what argument are you providing for that? Make sure that it is what you expect it is. What does the documentation for netCDF4.Dataset say? Perhaps you have to *read* from the file, not just open it? control = netCDF4.Dataset(filename,'r') data = control.read() # Perhaps this? kstest(data,'norm') But I'm just guessing. You'll need to read the documentation to see what arguments are expected, then you'll need to check what arguments you're actually providing. Doing: print(repr(control)) may help. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Fri Apr 25 11:32:48 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Apr 2014 15:32:48 GMT Subject: how to split this kind of text into sections References: Message-ID: <535a801f$0$29965$c3e8da3$5496439d@news.astraweb.com> On Fri, 25 Apr 2014 09:18:22 -0400, Roy Smith wrote: > In article , > oyster wrote: >> [demo text starts] >> a line we do not need >> I am section axax >> I am section bbb, we can find that the first 2 lines of this section >> all startswith 'I am section' >> .....(and here goes many other text)... let's continue to >> let's continue, yeah >> .....(and here goes many other text)... >> I am using python >> I am using perl >> .....(and here goes many other text)... >> [demo text ends] > > This kind of looks like a standard INI file. I don't think so. INI files are a collection of KEY=VALUE or KEY:VALUE pairs, and the example above shows nothing like that. The only thing which is even vaguely ini-like is the header [demo text starts], and my reading of that is that it is *not* part of the file, but just an indication that the OP is giving a demo. -- Steven D'Aprano http://import-that.dreamwidth.org/ From jamiemitchell1604 at gmail.com Fri Apr 25 12:23:59 2014 From: jamiemitchell1604 at gmail.com (Jamie Mitchell) Date: Fri, 25 Apr 2014 09:23:59 -0700 (PDT) Subject: len() of unsized object - ks test In-Reply-To: <9a3176b8-5011-497e-977c-15bac17fca6a@googlegroups.com> References: <9a3176b8-5011-497e-977c-15bac17fca6a@googlegroups.com> Message-ID: <757dec5e-d4a1-468e-99b9-5f954c0c1dba@googlegroups.com> On Friday, April 25, 2014 3:07:54 PM UTC+1, Jamie Mitchell wrote: > Hello all, > > > > I am trying to perform a Kolmogorov-Smirnov test in Python but I'm having a few difficulties. > > > > # My files are netCDF so I import them as follows: > > > > control=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/south_west/swhcontrol_swest_concatannavg_1D.nc','r') > > > > # The string is simply a 1D array > > > > # Then performing the ks test: > > > > kstest(control,'norm') > > > > # I then get the following error: > > > > File "", line 1, in > > File "/usr/local/sci/lib/python2.7/site-packages/scipy/stats/stats.py", line 3413, in kstest > > N = len(vals) > > TypeError: len() of unsized object > > > > Any ideas on why this isn't working would be great. > > > > Thanks, > > > > Jamie Thanks for your help. Steven your right I wasn't reading in the file on netCDF4.Dataset, I was just opening it. I have rectified it now - a silly mistake! Thanks again, Jamie From robin at reportlab.com Fri Apr 25 12:30:45 2014 From: robin at reportlab.com (Robin Becker) Date: Fri, 25 Apr 2014 17:30:45 +0100 Subject: possible bug in re expression? Message-ID: <535A8DB5.4090109@chamonix.reportlab.co.uk> Whilst translating some javascript code I find that this A=re.compile('.{1,+3}').findall(p) doesn't give any error, but doesn't manage to find the strings in p that I want len(A)==>0, the correct translation should have been A=re.compile('.{1,3}').findall(p) which works fine. should re.compile('.{1,+3}') raise an error? It doesn't on python 2.7 or 3.3. -- Robin Becker From rosuav at gmail.com Fri Apr 25 12:55:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 26 Apr 2014 02:55:09 +1000 Subject: possible bug in re expression? In-Reply-To: <535A8DB5.4090109@chamonix.reportlab.co.uk> References: <535A8DB5.4090109@chamonix.reportlab.co.uk> Message-ID: On Sat, Apr 26, 2014 at 2:30 AM, Robin Becker wrote: > Whilst translating some javascript code I find that this > > A=re.compile('.{1,+3}').findall(p) > > doesn't give any error, but doesn't manage to find the strings in p that I > want len(A)==>0, the correct translation should have been > > A=re.compile('.{1,3}').findall(p) > > which works fine. > > should > > re.compile('.{1,+3}') > > raise an error? It doesn't on python 2.7 or 3.3. I would say the surprising part is that your js code doesn't mind an extraneous character in the regex. In a brace like that, negative numbers have no meaning, so I would expect the definition of the regex to look for digits, not "anything that can be parsed as a number". So you've uncovered a bug in your code that just happened to work in js. Should it raise an error? Good question. Quite possibly it should, unless that has some other meaning that I'm not familiar with. Do you know how it's being interpreted? I'm not entirely sure what you mean by "len(A)==>0", as ==> isn't an operator in Python or JS. Best way to continue, I think, would be to use regular expression matching (rather than findall'ing) and something other than dot, and tabulate input strings, expected result (match or no match), what JS does, and what Python does. For instance: Regex: "^a{1,3}$" "": Not expected, not Python "a": Expected, Python "aa": Expected, Python "aaa": Expected, Python "aaaa": Not expected, not Python Just what we'd expect. Now try the same thing with the plus in there. I'm finding that none of the above strings yields a match. Maybe there's something else being matched? ChrisA From amirouche.boubekki at gmail.com Fri Apr 25 13:21:25 2014 From: amirouche.boubekki at gmail.com (Amirouche Boubekki) Date: Fri, 25 Apr 2014 19:21:25 +0200 Subject: Moving to an OOP model from an classically imperitive one In-Reply-To: <89bbe51e-2f07-4d80-844d-2e252733cace@googlegroups.com> References: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> <89bbe51e-2f07-4d80-844d-2e252733cace@googlegroups.com> Message-ID: H?llo, I have no definitive answer regarding the OOP/functional mismatch. 2014-04-24 18:53 GMT+02:00 : > > A reasonable compromise might be to keep the *data* assocated > > > > with a SubuserProgram in a class, maybe together with a few > > > > methods that are tightly coupled to it, but have the major > > > > pieces of functionality such as install() implemented by > > > > separate functions that operate *on* the class, rather than > > > > being inside it. > > > > I think this is sound advice. I'm still not sure what I'll come up with. > > One of the other reasons why an OOP model might be right for me is that of > caching. I currently load a lot of attributes regarding programs from > disk, and I do so multiple times, I could either pass those attributes > around, OR, using a class, I could store those attributes in the object > after loading them just once. You could also use a generator with a somekind of memoization/cache. > I have no experience with OOP except in the domain of GUIs (where it seems > inescapable, all major toolkits use OOP) I have some experience in GUIs with Python in a proprietary framework. I have a bias for OOP and Python in particular. I started exploring Scheme through Guile and other languages more or less. I am asking myself the question "what is the interest of functional programming or so called". Scheme doesn't enforce functional code or immutability. It's actually "more open" somewhat because of the macro system among other things. Outside any performance considerations or implementations details like GIL. Scheme and (all?) *LISP don't use the infix notation*. probably because you can work around it but IMO not fully. The infix notations allows to write things like: people.move_to(paris). It's easy to read, as ?Subject Verb Complement?... Class based OOP is prefered because of that, in a lot of situations. IMO, if OOP won, it's because of readability, and in particular Class based OOP. JavaScript OOP is useless in asynchronous context, see http://repl.it/Rrf/2. Maybe you can work around this feature with JavaScript descriptors easly, I did not try that. so I'm not yet sure how this will turn out. > I skimmed through the code, but it's very superficial reading, like I installed pycharm to ask for help...: - CamelCase is usually for class names. That said, sometime variable holding classes are called my_object_class or my_object_factory - I think permissions.py would be easier to read with a class... or a function that initialize the dictionary as intented and just use dict methods onward. - To I read code, I have a systematic method I call gunshot/destructive/production rules/function inlining/develop (as the dual of factorize). I started with subuser.py, I got: http://dpaste.com/1797075/ def getSubuserCommands(): """ Returns a list of commands that may be called by the user. """ def isPathToSubuserCommand(path): directory, executableName = os.path.split(path) return executableName.startswith("subuser-") externalCommandPaths = queryPATH(isPathToSubuserCommand) externalCommands = [] subuserPrefixLength=len("subuser-") for externalCommandPath in externalCommandPaths: commandDir, executableName = os.path.split(externalCommandPath) commandName = executableName[subuserPrefixLength:] externalCommands.append(commandName) external_subuser_commands = list(set(externalCommands)) return list(set( os.listdir(paths.getSubuserCommandsDir())).difference(nonCommands)) + external_subuser_commands It's kind of easier to read. Gremlin is a DSL that allows to navigate a graph. That's exactly what happens here (and all the time long now ).wrapped_ in(tesseract). I'd like to write the above as: >>> subuser.commands = (subuser.path.directories + subuser.user.path.directories).filter(is_command).distinct().memoize() I think it's possible in Ruby. I'm quite interested by the subject. Elm language (see reactconf) and your graphical IDEis very interesting, do you know about Domain Specific Modeling Forum ? I started to put some thinking grouped together. Also I started proto-py to gather code ideas, but it's still offline. My plan is to mimick subuser to see, what happens. Can be of interest Scala @ Systems @ Twitter Nice project by the way, with a better "see also" section that I could do :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From amirouche.boubekki at gmail.com Fri Apr 25 12:34:59 2014 From: amirouche.boubekki at gmail.com (Amirouche Boubekki) Date: Fri, 25 Apr 2014 18:34:59 +0200 Subject: retrieve source code from code object as returned by compile() In-Reply-To: <3abe4779-a237-4113-aaf0-24990895151f@googlegroups.com> References: <4dfca89b-82c6-42f4-aedb-2fe82a7f7dc1@googlegroups.com> <3abe4779-a237-4113-aaf0-24990895151f@googlegroups.com> Message-ID: in python3, I do inspect.getsource(object) [doc], I don't know the limitations. On Python 2, there is meta . My interest is different, I use to retrieve the definition of function to submit it to a database, instead of stored procedures, but I have the source of the code. It can also be used to retrieve the ast. 2014-04-25 4:50 GMT+02:00 Justin Ezequiel : > On Thursday, April 24, 2014 1:53:38 PM UTC+8, Gregory Ewing wrote: > > Alternatively you could create a .pyc file out of the code > > object and then use Easy Python Decompiler on that. The > > following snippet of code should do that: > > > > (Taken from: > > > > http://stackoverflow.com/questions/8627835/generate-pyc-from-python-ast) > > Woohoo! Success! Thank you Greg! > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri Apr 25 13:52:56 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 25 Apr 2014 13:52:56 -0400 Subject: how to split this kind of text into sections In-Reply-To: References: Message-ID: On 4/25/2014 9:07 AM, oyster wrote: > I have a long text, which should be splitted into some sections, where > all sections have a pattern like following with different KEY. Computers are worse at reading your mind than humans. If you can write rules that another person could follow, THEN we could help you translate the rules to Python. If you have 1 moderate length file or a few short files, I would edit them by hand to remove ignore lines and put a blank line between sections. A program to do the rest would then be easy. > the above text should be splitted as a LIST with 3 items, and I also > need to know the KEY for LIST is ['I am section', 'let's continue', 'I > am using']: This suggests that the rule for keys is 'first 3 words of a line, with contractions counted as 2 words'. Correct? Another possible rule is 'a member of the following list: ...', as you gave above but presumably expanded. -- Terry Jan Reedy From charleshixsn at earthlink.net Fri Apr 25 13:53:46 2014 From: charleshixsn at earthlink.net (Charles Hixson) Date: Fri, 25 Apr 2014 10:53:46 -0700 Subject: Proper deletion of selected items during map iteration in for loop Message-ID: <535AA12A.1030203@earthlink.net> What is the proper way to delete selected items during iteration of a map? What I want to do is: for (k, v) in m.items(): if f(k): # do some processing of v and save result elsewhere del m[k] But this gives (as should be expected): RuntimeError: dictionary changed size during iteration In the past I've accumulated the keys to be deleted in a separate list, but this time there are likely to be a large number of them, so is there some better way? -- Charles Hixson From python at mrabarnett.plus.com Fri Apr 25 13:57:23 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 25 Apr 2014 18:57:23 +0100 Subject: possible bug in re expression? In-Reply-To: References: <535A8DB5.4090109@chamonix.reportlab.co.uk> Message-ID: <535AA203.2050707@mrabarnett.plus.com> On 2014-04-25 17:55, Chris Angelico wrote: > On Sat, Apr 26, 2014 at 2:30 AM, Robin Becker wrote: >> Whilst translating some javascript code I find that this >> >> A=re.compile('.{1,+3}').findall(p) >> >> doesn't give any error, but doesn't manage to find the strings in p that I >> want len(A)==>0, the correct translation should have been >> >> A=re.compile('.{1,3}').findall(p) >> >> which works fine. >> >> should >> >> re.compile('.{1,+3}') >> >> raise an error? It doesn't on python 2.7 or 3.3. > > I would say the surprising part is that your js code doesn't mind an > extraneous character in the regex. In a brace like that, negative > numbers have no meaning, so I would expect the definition of the regex > to look for digits, not "anything that can be parsed as a number". So > you've uncovered a bug in your code that just happened to work in js. > > Should it raise an error? Good question. Quite possibly it should, > unless that has some other meaning that I'm not familiar with. Do you > know how it's being interpreted? I'm not entirely sure what you mean > by "len(A)==>0", as ==> isn't an operator in Python or JS. Best way to > continue, I think, would be to use regular expression matching (rather > than findall'ing) and something other than dot, and tabulate input > strings, expected result (match or no match), what JS does, and what > Python does. For instance: > > Regex: "^a{1,3}$" > > "": Not expected, not Python > "a": Expected, Python > "aa": Expected, Python > "aaa": Expected, Python > "aaaa": Not expected, not Python > > Just what we'd expect. Now try the same thing with the plus in there. > I'm finding that none of the above strings yields a match. Maybe > there's something else being matched? > The DEBUG flag helps to show what's happening: >>> r = re.compile('.{1,+3}', flags=re.DEBUG) any None literal 123 literal 49 max_repeat 1 4294967295 literal 44 literal 51 literal 125 When it's parsing the pattern it's doing this: . OK, match any character { Looks like the start of a quantifier 1 OK, the minimum count , OK, the maximum count probably follows + Error; it looks like the '{' was a literal Trying again from the brace: { Literal 1 Literal , Literal + Repeat the previous item one or more times 3 Literal } Literal From rosuav at gmail.com Fri Apr 25 14:00:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 26 Apr 2014 04:00:53 +1000 Subject: Proper deletion of selected items during map iteration in for loop In-Reply-To: <535AA12A.1030203@earthlink.net> References: <535AA12A.1030203@earthlink.net> Message-ID: On Sat, Apr 26, 2014 at 3:53 AM, Charles Hixson wrote: > What is the proper way to delete selected items during iteration of a map? > What I want to do is: > > for (k, v) in m.items(): > if f(k): > # do some processing of v and save result elsewhere > del m[k] > > But this gives (as should be expected): > RuntimeError: dictionary changed size during iteration > In the past I've accumulated the keys to be deleted in a separate list, but > this time there are likely to be a large number of them, so is there some > better way? One easy way is to explicitly coalesce the items() view into a list: for k, v in list(m.items()): That would work, but you effectively duplicate your entire dictionary into a list. More likely, you should simply snapshot the keys: for k in list(m): # Your example code isn't using v, but I # assume the real code does v = m[k] if f(k): # as above del m[k] This and your previous technique of accumulating a delete-me list would be the two standard ways to filter a dictionary with a loop. (I say "with a loop" because there's a third way to filter a dictionary, and that's with a comprehension. But I don't know of a really clean way to save v elsewhere for the cases where the dict isn't keeping that key.) ChrisA From mrabarnett at mrabarnett.plus.com Fri Apr 25 14:04:40 2014 From: mrabarnett at mrabarnett.plus.com (Matthew Barnett) Date: Fri, 25 Apr 2014 19:04:40 +0100 Subject: Proper deletion of selected items during map iteration in for loop In-Reply-To: <535AA12A.1030203@earthlink.net> References: <535AA12A.1030203@earthlink.net> Message-ID: <535AA3B8.3080308@mrabarnett.plus.com> On 2014-04-25 18:53, Charles Hixson wrote: > What is the proper way to delete selected items during iteration of a > map? What I want to do is: > > for (k, v) in m.items(): > if f(k): > # do some processing of v and save result elsewhere > del m[k] > > But this gives (as should be expected): > RuntimeError: dictionary changed size during iteration > In the past I've accumulated the keys to be deleted in a separate list, > but this time there are likely to be a large number of them, so is there > some better way? > The other way is to build a new dictionary. Actually, there's a third way. Iterate over a snapshot: for (k, v) in list(m.items()): if f(k): # do some processing of v and save result elsewhere del m[k] From tjreedy at udel.edu Fri Apr 25 14:32:30 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 25 Apr 2014 14:32:30 -0400 Subject: possible bug in re expression? In-Reply-To: <535A8DB5.4090109@chamonix.reportlab.co.uk> References: <535A8DB5.4090109@chamonix.reportlab.co.uk> Message-ID: On 4/25/2014 12:30 PM, Robin Becker wrote: > Whilst translating some javascript code I find that this > > A=re.compile('.{1,+3}').findall(p) > > doesn't give any error, but doesn't manage to find the strings in p that > I want len(A)==>0, the correct translation should have been > > A=re.compile('.{1,3}').findall(p) > > which works fine. > > should > > re.compile('.{1,+3}') > > raise an error? It doesn't on python 2.7 or 3.3. And it should not because it is not an error. '+' means 'match 1 or more occurrences of the preceding re' and the preceding re is ','. >>> re.match('a{1,+3}', 'a{1,,,3}').group() 'a{1,,,3}' I suppose that one could argue that '{' alone should be treated as special immediately, and not just when a matching '}' is found, and should disable other special meanings. I wonder what JS does if there is no matching '}'? -- Terry Jan Reedy From chris at simplistix.co.uk Fri Apr 25 14:48:48 2014 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 25 Apr 2014 19:48:48 +0100 Subject: xlutils 1.7.0 released! Message-ID: <535AAE10.6000703@simplistix.co.uk> Hi All, I'm pleased to announce the release of xlutils 1.7.1: http://pypi.python.org/pypi/xlutils/1.7.1 This release has a couple of small changes: - Add support for time cells in when using View classes. - Add support for ``.xlsx`` files when using View classes, at the expense of formatting information being available. Full docs here: http://pythonhosted.org/xlutils/ Details of all things Python and Excel related can be found here: http://www.python-excel.org/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From chris at simplistix.co.uk Fri Apr 25 14:50:52 2014 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 25 Apr 2014 19:50:52 +0100 Subject: xlutils 1.7.1 released! In-Reply-To: <535AAE10.6000703@simplistix.co.uk> References: <535AAE10.6000703@simplistix.co.uk> Message-ID: <535AAE8C.80708@simplistix.co.uk> *sigh* subject line fail... On 25/04/2014 19:48, Chris Withers wrote: > Hi All, > > I'm pleased to announce the release of xlutils 1.7.1: > > http://pypi.python.org/pypi/xlutils/1.7.1 > > This release has a couple of small changes: > > - Add support for time cells in when using View classes. > > - Add support for ``.xlsx`` files when using View classes, at the > expense of formatting information being available. > > Full docs here: > > http://pythonhosted.org/xlutils/ > > Details of all things Python and Excel related can be found here: > > http://www.python-excel.org/ > > cheers, > > Chris > -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From tjreedy at udel.edu Fri Apr 25 14:50:57 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 25 Apr 2014 14:50:57 -0400 Subject: Proper deletion of selected items during map iteration in for loop In-Reply-To: <535AA3B8.3080308@mrabarnett.plus.com> References: <535AA12A.1030203@earthlink.net> <535AA3B8.3080308@mrabarnett.plus.com> Message-ID: On 4/25/2014 2:04 PM, Matthew Barnett wrote: > On 2014-04-25 18:53, Charles Hixson wrote: >> What is the proper way to delete selected items during iteration of a >> map? What I want to do is: >> >> for (k, v) in m.items(): >> if f(k): >> # do some processing of v and save result elsewhere >> del m[k] >> >> But this gives (as should be expected): >> RuntimeError: dictionary changed size during iteration >> In the past I've accumulated the keys to be deleted in a separate list, >> but this time there are likely to be a large number of them, so is there >> some better way? >> > The other way is to build a new dictionary. If you expect to delete more than half the keys *and* if there are no other references to the dict, such that you need the particular object mutated, this might be better. > Actually, there's a third way. Iterate over a snapshot: > > for (k, v) in list(m.items()): > if f(k): > # do some processing of v and save result elsewhere > del m[k] Since a pre-snapshot of items or even just keys will be longer than a list of keys to be deleted, I would stick with the latter. -- Terry Jan Reedy From nad at acm.org Fri Apr 25 14:58:56 2014 From: nad at acm.org (Ned Deily) Date: Fri, 25 Apr 2014 11:58:56 -0700 Subject: MacOS 10.9.2: threading error using python.org 2.7.6 distribution References: Message-ID: In article , Chris Angelico wrote: > On Fri, Apr 25, 2014 at 11:43 PM, Matthew Pounsett > wrote: > > If I insert that object into the test code and run it instead of > > MyThread(), I get the error. I can't see anything in there that should > > cause problems for the threading module though... especially since this > > runs fine on another system with the same version of python. > > > > Any thoughts on what's going on here? > > First culprit I'd look at is the mixing of subprocess and threading. > It's entirely possible that something goes messy when you fork from a > thread. FWIW, the Python 2 version of subprocess is known to be thread-unsafe. There is a Py2 backport available on PyPI of the improved Python 3 subprocess module: http://bugs.python.org/issue20318 https://pypi.python.org/pypi/subprocess32/ -- Ned Deily, nad at acm.org From python.list at tim.thechases.com Fri Apr 25 15:22:59 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 25 Apr 2014 14:22:59 -0500 Subject: Proper deletion of selected items during map iteration in for loop In-Reply-To: References: <535AA12A.1030203@earthlink.net> <535AA3B8.3080308@mrabarnett.plus.com> Message-ID: <20140425142259.2a2a0e8d@bigbox.christie.dr> On 2014-04-25 14:50, Terry Reedy wrote: > If you expect to delete more than half the keys *and* if there are > no other references to the dict, such that you need the particular > object mutated, this might be better. If that's your precondition, then it might be better to do something like keep = {} for (k, v) in m.items(): if f(k): # do some processing of v and save result elsewhere else: keep[k] = v m.clear() m.update(keep) del keep # optionally free this back up when done This would allow things that refer to "m" to retain the same reference, but should have the same result as deleting them without having to duplicate what the OP describes as a large volume of data. Either way, the options are mostly 1) clone the entire .items() into a list, and iterate over that for deleting from your underlying view (what Chris & Matthew suggest) 2) iterate over the items, storing up the ones to delete and delete them all at the end (what the OP mentions having tried before) 3) iterate over the items, storing up the ones to keep, delete the rest, and then put the kept ones back (what I code above) The choice between #2 and #3 hinge on whether you expect to delete more than half the items. If you plan to delete more than half, store the ones to keep (#3); if you plan to delete less than half, store the ones to delete (#2). -tkc From greg.ewing at canterbury.ac.nz Fri Apr 25 19:42:33 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 26 Apr 2014 11:42:33 +1200 Subject: Installing PyGame? In-Reply-To: References: <5c069831-8cab-43da-a4f9-ccec68cdc101@googlegroups.com> Message-ID: Ned Deily wrote: > I disagree that > installing a bunch of disparate software from various sources via binary > installers and/or source is to be preferred to a modern third-party > package manager on OS X like MacPorts or Homebrew. That's just setting > yourself up for a long-term maintenance headache. What could be easier > than: > > sudo port install py27-game That's fine if it works, but the OP said he'd already tried various things like that and they *didn't* work for him. And I've had trouble in the past with MacPorts and/or Fink (can't remember exactly which one it was) installing libraries that were incompatible with other things I use and messing them up, so I've learned to be wary of them. Those problems were probably due to some unusual features of my setup, and wouldn't occur for most other people. But because I don't use those tools, I can't give any recommendations about how to troubleshoot them. All I can do is explain what works for me. -- Greg From greg.ewing at canterbury.ac.nz Fri Apr 25 19:57:21 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 26 Apr 2014 11:57:21 +1200 Subject: Installing PyGame? In-Reply-To: References: <5c069831-8cab-43da-a4f9-ccec68cdc101@googlegroups.com> Message-ID: Ryan Hiebert wrote: > I've chosen to use > MacPorts because it keeps things separate, because when things get hosed > using the system libraries, I don't have to erase my whole system to get > back to a "vanilla" OS X install. I don't know what you're doing to hose your system that badly. I've never had a problem that couldn't be fixed by deleting whatever the last thing was I added that caused it. Also the problems I had with one of the third-party package managers was because it *didn't* keep its own stuff properly separated. It installed libraries on my regular library path so that they got picked up by things that they weren't appropriate for. I'm not saying that MacPorts is a bad thing. If it's the *only* thing you use, it's probably fine. But I use a wide variety of libraries, not all of them available that way, and many of them installed from source, and I find it's less hassle overall to do everything the native MacOSX way wherever possible. -- Greg From greg.ewing at canterbury.ac.nz Fri Apr 25 20:03:10 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 26 Apr 2014 12:03:10 +1200 Subject: retrieve source code from code object as returned by compile() In-Reply-To: References: <4dfca89b-82c6-42f4-aedb-2fe82a7f7dc1@googlegroups.com> <3abe4779-a237-4113-aaf0-24990895151f@googlegroups.com> Message-ID: Amirouche Boubekki wrote: > in python3, I do inspect.getsource(object) [doc > ], I > don't know the limitations. The limitation relevant here is that it requires the original source file to be present. :-) -- Greg From teddybubu at gmail.com Fri Apr 25 22:16:46 2014 From: teddybubu at gmail.com (tad na) Date: Fri, 25 Apr 2014 19:16:46 -0700 (PDT) Subject: feedparser error Message-ID: <4f7cfadc-6b9b-488a-b2cd-b90dd53acbfc@googlegroups.com> python 2.7.2 The following code has an error and I can not figure out why: import feedparser d = feedparser.parse('http://bl.ocks.org/mbostock.rss') numb = len(d['entries']) for post in d.entries: print post.pubDate+"\n" ----------------------------------- the error is : print post.pubDate+"\n" File "build\bdist.win32\egg\feedparser.py", line 416, in __getattr__ raise AttributeError, "object has no attribute '%s'" % key AttributeError: object has no attribute 'pubDate' ----------------------------------- The only thing I can think of is feedparser does not like uppercase(pubDate)????? I can not change someone else's rss. What can I do here? From johnjsal at gmail.com Fri Apr 25 22:48:53 2014 From: johnjsal at gmail.com (John Salerno) Date: Fri, 25 Apr 2014 19:48:53 -0700 (PDT) Subject: Using Python to get push notifications from an RSS feed? Message-ID: As a little project for myself (and to help get immediate player notes for my fantasy baseball team), I'm wondering what modules I might need to do this. Basically, I'd like to get immediate notification when a new player note has been added to an RSS feed. Since it will only be for specified players, I suppose I would use something like ElementTree to read the data and figure out if the update is about a relevant player, but how do I check the RSS feed (constantly) in the first place? I was reading a little about Universal Feed Parser, but I'm still not sure about how to do the "push" notification aspect. I'd like immediate notifications if possible, or will I have to settle for periodically checking the feed? If the latter, how do I ensure I only check the newest updates since the last time, and not everything? Thanks! John From tfischer.ncku at gmail.com Sat Apr 26 00:45:18 2014 From: tfischer.ncku at gmail.com (tfischer.ncku at gmail.com) Date: Fri, 25 Apr 2014 21:45:18 -0700 (PDT) Subject: Play back and record sound *at the same time* for n seconds Message-ID: <3e30ad3b-8511-4622-acb5-b162a30cc580@googlegroups.com> Hello, to program an art project that involves sound feedback I need a way to get a python script to to play back and to record sound *at the same time* for n seconds. Which strategy/sound module would you recommend, and could you post dummy code that shows how to get it to play and record simultaneously? Thanks a lot! Tom From ben at benfinney.id.au Sat Apr 26 01:59:38 2014 From: ben at benfinney.id.au (Ben Finney) Date: Sat, 26 Apr 2014 15:59:38 +1000 Subject: Play back and record sound *at the same time* for n seconds References: <3e30ad3b-8511-4622-acb5-b162a30cc580@googlegroups.com> Message-ID: <85sip0ljg5.fsf@benfinney.id.au> tfischer.ncku at gmail.com writes: > to program an art project that involves sound feedback I need a way to > get a python script to to play back and to record sound *at the same > time* for n seconds. This is largely unrelated to whether you use Python. Rather, you need to know what operating system (OS) services are available on your chosen OS, that will allow the capability you're asking for. Then, once you know what OS service to use for simultaneous sound channels, you can look for a way to use Python to interface with that. What OS will you be using? I know that the JACK library has the capabilities you're asking about, which would make GNU+Linux a good choice. -- \ ?As the most participatory form of mass speech yet developed, | `\ the Internet deserves the highest protection from governmental | _o__) intrusion.? ?U.S. District Court Judge Dalzell | Ben Finney From akonsta at icloud.com Sat Apr 26 01:50:06 2014 From: akonsta at icloud.com (Andrew Konstantaras) Date: Sat, 26 Apr 2014 05:50:06 +0000 (GMT) Subject: Help with changes in traceback stack from Python 2.7 to Python 3.x Message-ID: <9fb27984-1b9e-402b-aa4d-7ca4f26e2386@me.com> I wrote the following code that works in Python 2.7 that takes the variables passed to the function into a dictionary. The following call: strA = 'a' intA = 1 dctA = makeDict(strA, intA) produces the following dictionary: {'strA':'a', 'intA':1} To access the names passed into the function, I had to find the information by parsing through the stack. The code that used to work is: from traceback import extract_stack def makeDict(*args): strAllStack = str(extract_stack()) intNumLevels = len(extract_stack()) intLevel = 0 blnFinished = False while not blnFinished: strStack = str(extract_stack()[intLevel]) if strStack.find("makeDict(")>0: blnFinished = True intLevel += 1 if intLevel >= intNumLevels: blnFinished = True strStartText = "= makeDict(" intLen = len(strStartText) intOpenParenLoc = strStack.find(strStartText) intCloseParenLoc = strStack.find(")", intOpenParenLoc) strArgs = strStack[ intOpenParenLoc+intLen : intCloseParenLoc ].strip() lstVarNames = strArgs.split(",") lstVarNames = [ s.strip() for s in lstVarNames ] if len(lstVarNames) == len(args): tplArgs = map(None, lstVarNames, args) newDict = dict(tplArgs) return newDict else: return "Error, argument name-value mismatch in function 'makeDict'. lstVarNames: " + str(lstVarNames) + "\n args: " + str(args), strAllStack The same code does not work in Python 3.3.4. I have tried parsing through the stack information and frames and I can't find any reference to the names of the arguments passed to the function. I have tried inspecting the function and other functions in the standard modules, but I can't seem to find anything that will provide this information. Can anyone point me in the direction to find this information? Any help is appreciated. ---Andrew ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From anddamNOALPASTICCIODICARNE+gruppi at brapi.net Sat Apr 26 02:57:39 2014 From: anddamNOALPASTICCIODICARNE+gruppi at brapi.net (Andrea D'Amore) Date: Sat, 26 Apr 2014 08:57:39 +0200 Subject: Installing PyGame? References: Message-ID: On 2014-04-25 23:57:21 +0000, Gregory Ewing said: > I don't know what you're doing to hose your system that badly. > I've never had a problem that couldn't be fixed by deleting > whatever the last thing was I added that caused it. The actual problem with the "native MacOSX way" is that there's no official way to uninstall a package once it's installed. > Also the problems I had with one of the third-party package > managers was because it *didn't* keep its own stuff properly > separated. It installed libraries on my regular library path > so that they got picked up by things that they weren't > appropriate for. This most likely was not MacPorts, its default install path is not checked by dyld by default. > But I use a wide > variety of libraries, not all of them available that way, > and many of them installed from source, and I find it's > less hassle overall to do everything the native MacOSX way > wherever possible. Well, the "native" MacOSX way would probably be registering a package via installer(8) not compiling from source. As long as you're comfortable with your system then it's good for you. In my experience the more libraries/software I install the more useful a package manager becomes in terms of stray files left when upgrading or uninstalling. I use a mix of MacPorts to provide the base tools and virtualenv for project-specific pypi libraries. -- Andrea From anddamNOALPASTICCIODICARNE+gruppi at brapi.net Sat Apr 26 03:07:44 2014 From: anddamNOALPASTICCIODICARNE+gruppi at brapi.net (Andrea D'Amore) Date: Sat, 26 Apr 2014 09:07:44 +0200 Subject: Installing PyGame? References: Message-ID: On 2014-04-25 23:42:33 +0000, Gregory Ewing said: > That's fine if it works, but the OP said he'd already tried > various things like that and they *didn't* work for him. By reading the "original" message (the empty reply with full quote of a ten months earlier message) I couldn't figure what the OP actually did, he says "just about every way possible", or what his "an error" actually is. Most likely all those methods are good, I'd rather fix any of those by providing further info than switch to another one looking for a magical solution. -- Andrea From wxjmfauth at gmail.com Sat Apr 26 03:15:51 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 26 Apr 2014 00:15:51 -0700 (PDT) Subject: Unicode in Python In-Reply-To: References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> <5357715c$0$11109$c3e8da3@news.astraweb.com> Message-ID: <03bb12d8-93be-4ef6-94ae-4a02789aea2d@googlegroups.com> ========== I wrote once 90 % of Python 2 apps (a generic term) supposed to process text, strings are not working. In Python 3, that's 100 %. It is somehow only by chance, apps may give the illusion they are properly working. jmf From steve+comp.lang.python at pearwood.info Sat Apr 26 03:24:35 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Apr 2014 07:24:35 GMT Subject: possible bug in re expression? References: <535A8DB5.4090109@chamonix.reportlab.co.uk> Message-ID: <535b5f33$0$29965$c3e8da3$5496439d@news.astraweb.com> On Fri, 25 Apr 2014 14:32:30 -0400, Terry Reedy wrote: > On 4/25/2014 12:30 PM, Robin Becker wrote: [...] >> should >> >> re.compile('.{1,+3}') >> >> raise an error? It doesn't on python 2.7 or 3.3. > > And it should not because it is not an error. '+' means 'match 1 or more > occurrences of the preceding re' and the preceding re is ','. Actually, no. Braces have special meaning, and are used to specify a number of matches. R{m,n} matches from m to n repetitions of the preceding regex R: py> re.search('(spam){2,4}', 'spam-spamspamspam-spam').group() 'spamspamspam' This surprises me: > >>> re.match('a{1,+3}', 'a{1,,,3}').group() > 'a{1,,,3}' I would have expected that either +3 would have been interpreted as just "3", or that it would have been an invalid regex. It appears that what is happening is that if the braces cannot be interpreted as a repetition group, they are interpreted as regular characters. Those sort of silent errors is why I hate programming in regexes. > I suppose that one could argue that '{' alone should be treated as > special immediately, and not just when a matching '}' is found, and > should disable other special meanings. I wonder what JS does if there is > no matching '}'? Probably silently do the wrong thing :-) -- Steven D'Aprano http://import-that.dreamwidth.org/ From frank at chagford.com Sat Apr 26 03:45:07 2014 From: frank at chagford.com (Frank Millman) Date: Sat, 26 Apr 2014 09:45:07 +0200 Subject: Unicode in Python References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> <5357715c$0$11109$c3e8da3@news.astraweb.com> <03bb12d8-93be-4ef6-94ae-4a02789aea2d@googlegroups.com> Message-ID: wrote in message news:03bb12d8-93be-4ef6-94ae-4a02789aea2d at googlegroups.com... > ========== > > I wrote once 90 % of Python 2 apps (a generic term) supposed to > process text, strings are not working. > > In Python 3, that's 100 %. It is somehow only by chance, apps may > give the illusion they are properly working. > It is quite frustrating when you make these statements without explaining what you mean by 'not working'. It would be really useful if you could spell out - 1. what you did 2. what you expected to happen 3. what actually happened Frank Millman From ben at benfinney.id.au Sat Apr 26 03:50:01 2014 From: ben at benfinney.id.au (Ben Finney) Date: Sat, 26 Apr 2014 17:50:01 +1000 Subject: Unicode in Python References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> <5357715c$0$11109$c3e8da3@news.astraweb.com> <03bb12d8-93be-4ef6-94ae-4a02789aea2d@googlegroups.com> Message-ID: <85fvl0lec6.fsf@benfinney.id.au> "Frank Millman" writes: > wrote [?] > It is quite frustrating when you make these statements without > explaining what you mean by 'not working'. Please do not engage ?wxjmfauth? on this topic; he is an amply-demonstrated troll with nothing tangible to back up his incessant complaints about Unicode in Python. He is best ignored, IMO. -- \ ?As the evening sky faded from a salmon color to a sort of | `\ flint gray, I thought back to the salmon I caught that morning, | _o__) and how gray he was, and how I named him Flint.? ?Jack Handey | Ben Finney From ned at nedbatchelder.com Sat Apr 26 08:10:33 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 26 Apr 2014 08:10:33 -0400 Subject: Help with changes in traceback stack from Python 2.7 to Python 3.x In-Reply-To: <9fb27984-1b9e-402b-aa4d-7ca4f26e2386@me.com> References: <9fb27984-1b9e-402b-aa4d-7ca4f26e2386@me.com> Message-ID: On 4/26/14 1:50 AM, Andrew Konstantaras wrote: > I wrote the following code that works in Python 2.7 that takes the > variables passed to the function into a dictionary. The following call: > > strA = 'a' > intA = 1 > dctA = makeDict(strA, intA) > > produces the following dictionary: > > {'strA':'a', 'intA':1} > > To access the names passed into the function, I had to find the > information by parsing through the stack. The code that used to work is: > > from traceback import extract_stack > > def makeDict(*args): > strAllStack = str(extract_stack()) > intNumLevels = len(extract_stack()) > intLevel = 0 > blnFinished = False > while not blnFinished: > strStack = str(extract_stack()[intLevel]) > if strStack.find("makeDict(")>0: > blnFinished = True > intLevel += 1 > if intLevel >= intNumLevels: > blnFinished = True > strStartText = "= makeDict(" > intLen = len(strStartText) > intOpenParenLoc = strStack.find(strStartText) > intCloseParenLoc = strStack.find(")", intOpenParenLoc) > strArgs = strStack[ intOpenParenLoc+intLen : intCloseParenLoc ].strip() > lstVarNames = strArgs.split(",") > lstVarNames = [ s.strip() for s in lstVarNames ] > if len(lstVarNames) == len(args): > tplArgs = map(None, lstVarNames, args) > newDict = dict(tplArgs) > return newDict > else: > return "Error, argument name-value mismatch in function 'makeDict'. > lstVarNames: " + str(lstVarNames) + "\n args: " + str(args), strAllStack > > The same code does not work in Python 3.3.4. I have tried parsing > through the stack information and frames and I can't find any reference > to the names of the arguments passed to the function. I have tried > inspecting the function and other functions in the standard modules, but > I can't seem to find anything that will provide this information. 1) This is a very strange function. Instead of going to all this trouble, why not use: dctA = dict(strA=strA, intA=intA) Yes, you have to repeat the names, but you'd be done by now, it works on both versions of Python, and people reading your code would understand what it does. 2) Why is your code examining the entire stack? The frame you want is the one just above you. Why are you stringifying the tuple produced by extract_stack when the source line you want is the fourth element? Why are you using a while loop and a counter to iterate over elements of a list? 3) In the error case you return a tuple when the caller is expecting a dict? Why not raise an exception? 4) Your code only works if makeDict is assigned to a name. When I first tried it, I used "print(makeDict(...))", and it failed completely. 5) You haven't mentioned what goes wrong on Python 3, but when I tried it, I got: Traceback (most recent call last): File "foo3.py", line 34, in d = makeDict(a, b) File "foo3.py", line 27, in makeDict newDict = dict(list(tplArgs)) TypeError: 'NoneType' object is not callable Looking at your code, I see: tplArgs = map(None, lstVarNames, args) I didn't realize map accepted a callable of None (TIL!), but it no longer does in Python 3. You'll have to do this a different way. But seriously: just use dict() and be done with it. There's a lot here that can be much simpler if you learn to use Python as it was meant to be used. You are swimming upstream, there are easier ways. > > Can anyone point me in the direction to find this information? Any help > is appreciated. > > ---Andrew > > > -- Ned Batchelder, http://nedbatchelder.com From ian.g.kelly at gmail.com Sat Apr 26 09:38:29 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 26 Apr 2014 09:38:29 -0400 Subject: Unicode in Python In-Reply-To: References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> <5357715c$0$11109$c3e8da3@news.astraweb.com> <03bb12d8-93be-4ef6-94ae-4a02789aea2d@googlegroups.com> Message-ID: On Apr 26, 2014 3:46 AM, "Frank Millman" wrote: > > > wrote in message > news:03bb12d8-93be-4ef6-94ae-4a02789aea2d at googlegroups.com... > > ========== > > > > I wrote once 90 % of Python 2 apps (a generic term) supposed to > > process text, strings are not working. > > > > In Python 3, that's 100 %. It is somehow only by chance, apps may > > give the illusion they are properly working. > > > > It is quite frustrating when you make these statements without explaining > what you mean by 'not working'. As far as anybody has been able to determine, what jmf means by "not working" is that strings containing the ? character are handled less efficiently than strings that do not contain it in certain contrived test cases. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Sat Apr 26 11:13:52 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 26 Apr 2014 11:13:52 -0400 Subject: Help with changes in traceback stack from Python 2.7 to Python 3.x In-Reply-To: References: <9fb27984-1b9e-402b-aa4d-7ca4f26e2386@me.com> Message-ID: On Apr 26, 2014 8:12 AM, "Ned Batchelder" wrote: > Looking at your code, I see: > > > tplArgs = map(None, lstVarNames, args) > > I didn't realize map accepted a callable of None (TIL!), but it no longer does in Python 3. You'll have to do this a different way. The Python 3 replacement for map(None, ...) is itertools.zip_longest. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lepto.python at gmail.com Sat Apr 26 11:53:14 2014 From: lepto.python at gmail.com (oyster) Date: Sat, 26 Apr 2014 23:53:14 +0800 Subject: how to split this kind of text into sections Message-ID: First of all, thank you all for your answers. I received python mail-list in a daily digest, so it is not easy for me to quote your mail separately. I will try to explain my situation to my best, but English is not my native language, I don't know whether I can make it clear at last. Every SECTION starts with 2 special lines; these 2 lines is special because they have some same characters (the length is not const for different section) at the beginning; these same characters is called the KEY for this section. For every 2 neighbor sections, they have different KEYs. After these 2 special lines, some paragraph is followed. Paragraph does not have any KEYs. So, a section = 2 special lines with KEYs at the beginning + some paragraph without KEYs However there maybe some paragraph before the first section, which I do not need and want to drop it I need a method to split the whole text into SECTIONs and to know all the KEYs I have tried to solve this problem via re module, but failed. Maybe I can make you understand me clearly by showing the regular expression object reobj = re.compile(r"(?P[^\r\n]*?)[^\r\n]*?\r\n(?P=bookname)[^\r\n]*?\r\n.*?", re.DOTALL) which can get the first 2 lines of a section, but fail to get the rest of a section which does not have any KEYs at the begin. The hard part for me is to express "paragraph does not have KEYs". Even I can get the first 2 line, I think regular expression is expensive for my text. That is all. I hope get some more suggestions. Thanks. [demo text starts] a line we do not need I am section axax I am section bbb (and here goes many other text)... let's continue to let's continue, yeah .....(and here goes many other text)... I am using python I am using perl .....(and here goes many other text)... Programming is hard Programming is easy How do you thing? I do?t know [demo text ends] the above text should be splited to a LIST with 4 items, and I also need to know the KEY for LIST is ['I am section ', 'let's continue', 'I am using ', ' Programming is ']: lst=[ '''a line we do not need I am section axax I am section bbb (and here goes many other text)... ''', '''let's continue to let's continue, yeah .....(and here goes many other text)... ''', '''I am using python I am using perl .....(and here goes many other text)... ''', '''Programming is hard Programming is easy How do you thing? I do?t know''' ] From kushal.kumaran at gmail.com Sat Apr 26 12:47:57 2014 From: kushal.kumaran at gmail.com (Kushal Kumaran) Date: Sat, 26 Apr 2014 22:17:57 +0530 Subject: feedparser error In-Reply-To: <4f7cfadc-6b9b-488a-b2cd-b90dd53acbfc@googlegroups.com> References: <4f7cfadc-6b9b-488a-b2cd-b90dd53acbfc@googlegroups.com> Message-ID: <535be348.089de00a.6973.0f00@mx.google.com> tad na writes: > python 2.7.2 > > The following code has an error and I can not figure out why: > > import feedparser > d = feedparser.parse('http://bl.ocks.org/mbostock.rss') > numb = len(d['entries']) > for post in d.entries: > print post.pubDate+"\n" > > ----------------------------------- > the error is : > > print post.pubDate+"\n" > File "build\bdist.win32\egg\feedparser.py", line 416, in __getattr__ > raise AttributeError, "object has no attribute '%s'" % key > AttributeError: object has no attribute 'pubDate' > > ----------------------------------- > > The only thing I can think of is feedparser does not like uppercase(pubDate)????? > I can not change someone else's rss. What can I do here? You want post.published, or post.published_parsed. See the feedparser documentation here: https://pythonhosted.org/feedparser/reference-entry-published.html -- regards, kushal -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 472 bytes Desc: not available URL: From python at mrabarnett.plus.com Sat Apr 26 12:55:35 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 26 Apr 2014 17:55:35 +0100 Subject: feedparser error In-Reply-To: <4f7cfadc-6b9b-488a-b2cd-b90dd53acbfc@googlegroups.com> References: <4f7cfadc-6b9b-488a-b2cd-b90dd53acbfc@googlegroups.com> Message-ID: <535BE507.3070608@mrabarnett.plus.com> On 2014-04-26 03:16, tad na wrote: > python 2.7.2 > > The following code has an error and I can not figure out why: > > import feedparser > d = feedparser.parse('http://bl.ocks.org/mbostock.rss') > numb = len(d['entries']) > for post in d.entries: > print post.pubDate+"\n" > > ----------------------------------- > the error is : > > print post.pubDate+"\n" > File "build\bdist.win32\egg\feedparser.py", line 416, in __getattr__ > raise AttributeError, "object has no attribute '%s'" % key > AttributeError: object has no attribute 'pubDate' > > ----------------------------------- > > The only thing I can think of is feedparser does not like uppercase(pubDate)????? > I can not change someone else's rss. What can I do here? > Print dir(post) to see what attributes it has. From python.list at tim.thechases.com Sat Apr 26 12:59:56 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 26 Apr 2014 11:59:56 -0500 Subject: how to split this kind of text into sections In-Reply-To: References: Message-ID: <20140426115956.0ec51bbb@bigbox.christie.dr> On 2014-04-26 23:53, oyster wrote: > I will try to explain my situation to my best, but English is not my > native language, I don't know whether I can make it clear at last. Your follow-up reply made much more sense and your written English is far better than many native speakers'. :-) > Every SECTION starts with 2 special lines; these 2 lines is special > because they have some same characters (the length is not const for > different section) at the beginning; these same characters is called > the KEY for this section. For every 2 neighbor sections, they have > different KEYs. I suspect you have a minimum number of characters (or words) to consider, otherwise a single character duplicated at the beginning of the line would delimit a section, such as abcd afgh because they share the commonality of an "a". The code I provided earlier should give you what you describe. I've tweaked and tested, and provided it below. Note that I require a minimum overlap of 6 characters (MIN_LEN). It also gathers the initial stuff (that you want to discard) under the empty key, so you can either delete that, or ignore it. > I need a method to split the whole text into SECTIONs and to know > all the KEYs > > I have tried to solve this problem via re module I don't think the re module will be as much help here. -tkc from collections import defaultdict import itertools as it MIN_LEN = 6 def overlap(s1, s2): "Given 2 strings, return the initial overlap between them" return ''.join( c1 for c1, c2 in it.takewhile( lambda pair: pair[0] == pair[1], it.izip(s1, s2) ) ) prevline = "" # the initial key under which preamble gets stored output = defaultdict(list) key = None with open("data.txt") as f: for line in f: if len(line) >= MIN_LEN and prevline[:MIN_LEN] == line[:MIN_LEN]: key = overlap(prevline, line) output[key].append(line) prevline = line for k,v in output.items(): print str(k).center(60,'=') print ''.join(v) . From teddybubu at gmail.com Sat Apr 26 15:22:48 2014 From: teddybubu at gmail.com (tad na) Date: Sat, 26 Apr 2014 12:22:48 -0700 (PDT) Subject: feedparser error In-Reply-To: References: <4f7cfadc-6b9b-488a-b2cd-b90dd53acbfc@googlegroups.com> Message-ID: You guys are good. thanks. ======================================= On Saturday, April 26, 2014 11:55:35 AM UTC-5, MRAB wrote: On 2014-04-26 03:16, tad na wrote: python 2.7.2 The following code has an error and I can not figure out why: import feedparser d = feedparser.parse('http://bl.ocks.org/mbostock.rss') numb = len(d['entries']) for post in d.entries: print post.pubDate+"\n" ----------------------------------- the error is : print post.pubDate+"\n" File "build\bdist.win32\egg\feedparser.py", line 416, in __getattr__ raise AttributeError, "object has no attribute '%s'" % key AttributeError: object has no attribute 'pubDate' ----------------------------------- The only thing I can think of is feedparser does not like uppercase(pubDate)????? I can not change someone else's rss. What can I do here? Print dir(post) to see what attributes it has. From charleshixsn at earthlink.net Sat Apr 26 15:25:27 2014 From: charleshixsn at earthlink.net (Charles Hixson) Date: Sat, 26 Apr 2014 12:25:27 -0700 Subject: Proper deletion of selected items during map iteration in for loop: Thanks to all In-Reply-To: <535AA12A.1030203@earthlink.net> References: <535AA12A.1030203@earthlink.net> Message-ID: <535C0827.3010800@earthlink.net> On 04/25/2014 10:53 AM, Charles Hixson wrote: > What is the proper way to delete selected items during iteration of a > map? What I want to do is: > > for (k, v) in m.items(): > if f(k): > # do some processing of v and save result elsewhere > del m[k] > > But this gives (as should be expected): > RuntimeError: dictionary changed size during iteration > In the past I've accumulated the keys to be deleted in a separate > list, but this time there are likely to be a large number of them, so > is there some better way? > Going over the various responses, it looks like saving the "to be deleted" keys to a list, and then iterating over that to delete is the best answer. I expect that I'll be deleting around 1/3 during each iteration of the process...and then adding new ones back in. There shouldn't be a really huge number of deletions on any particular pass, but it will be looped through many times...so if there were any better way to do this, it would speed things up considerably...but it's not really surprising that there doesn't appear to be. So now it translates into (approximately, not yet tested): toDel = [] for (k, v) in m.items(): if f(k): # do some processing of v and save result elsewhere toDel.append(k) else: # do something else for k in toDel: del m[k] toDel = None -- Charles Hixson From python.list at tim.thechases.com Sat Apr 26 16:24:03 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 26 Apr 2014 15:24:03 -0500 Subject: Proper deletion of selected items during map iteration in for loop: Thanks to all In-Reply-To: <535C0827.3010800@earthlink.net> References: <535AA12A.1030203@earthlink.net> <535C0827.3010800@earthlink.net> Message-ID: <20140426152403.39aab87e@bigbox.christie.dr> On 2014-04-26 12:25, Charles Hixson wrote: > I expect that I'll be deleting around 1/3 during > each iteration of the process...and then adding new ones back in. > There shouldn't be a really huge number of deletions on any > particular pass, but it will be looped through many times... If you have further details on what triggers the "adding new ones back in", and what changes or remains the same between various passes, there might be room for optimization elsewhere. -tkc From __peter__ at web.de Sat Apr 26 17:30:57 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 26 Apr 2014 23:30:57 +0200 Subject: Proper deletion of selected items during map iteration in for loop References: <535AA12A.1030203@earthlink.net> Message-ID: Charles Hixson wrote: > What is the proper way to delete selected items during iteration of a > map? What I want to do is: > > for (k, v) in m.items(): > if f(k): > # do some processing of v and save result elsewhere > del m[k] > > But this gives (as should be expected): > RuntimeError: dictionary changed size during iteration > In the past I've accumulated the keys to be deleted in a separate list, > but this time there are likely to be a large number of them, so is there > some better way? It just struck me that you can store the keys to be deleted as values in the same dict. That way you need no extra memory: def delete_items(d, keys): keys = iter(keys) try: first = prev = next(keys) except StopIteration: return for key in keys: d[prev] = prev = key d[prev] = first key = first while True: key = d.pop(key) if key is first: break if __name__ == "__main__": import string data = dict(zip(range(10), string.ascii_lowercase)) print("original data:", data) print("removing odd items...") delete_items(data, keys=(k for k in data if k % 2)) print("modified data:", data) print("delete no items...") delete_items(data, []) print("modified data:", data) print("delete a single item (6)...") delete_items(data, [6]) print("modified data:", data) print("delete all items...") delete_items(data, data) print("modified data:", data) While I think I am a genius* in practice this approach will probably not be the most effective. (*) (Un)fortunately that feeling never lasts longer than a few minutes ;) From steve+comp.lang.python at pearwood.info Sat Apr 26 22:14:02 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Apr 2014 02:14:02 GMT Subject: Proper deletion of selected items during map iteration in for loop: Thanks to all References: <535AA12A.1030203@earthlink.net> Message-ID: <535c67e9$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sat, 26 Apr 2014 12:25:27 -0700, Charles Hixson wrote: > On 04/25/2014 10:53 AM, Charles Hixson wrote: >> What is the proper way to delete selected items during iteration of a >> map? What I want to do is: >> >> for (k, v) in m.items(): >> if f(k): >> # do some processing of v and save result elsewhere >> del m[k] >> >> But this gives (as should be expected): >> RuntimeError: dictionary changed size during iteration >> In the past I've accumulated the keys to be deleted in a separate list, >> but this time there are likely to be a large number of them, so is >> there some better way? >> >> > Going over the various responses, it looks like saving the "to be > deleted" keys to a list, and then iterating over that to delete is the > best answer. I don't think that there is any one "best" answer that always applies. "My dict has three items, and I'll be deleting most of them" is likely to have different performance characteristics from "My dict has three billion items, and I'll be deleting two [or two billion] of them". So how much time do you want to spend tuning this for optimum performance (or memory use, or programmer time)? Or is "good enough" good enough? I think the two obviously good enough approaches are: - save a "to be deleted" list, then delete those keys; - copy the "not to be deleted" items into a new dict My intuition is that the second will probably be faster, unless your dict is truly monstrously big. Not millions, but tens or hundreds or thousands of millions of items, depending on how much memory your computer has. You've already got a code snippet using the "to be deleted" list, here's how I would do the other way: new = {} for k, v in m.items(): if f(k): process(v) else: new[k] = v m.clear() m.update(new) del new If you don't care about modifying the existing dict, but can afford to write in a more functional style, you don't even need to bother doing that m.clear(), m.update(new). Just return the new dict, stop using the old one (it will be garbage collected), and use the new one. Oh, in case you're wondering, this will be more efficient than it may seem, because the actual data in the dict isn't copied. The only things being copied are references to the keys and values, not the keys and values themselves. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Sat Apr 26 22:49:08 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 27 Apr 2014 12:49:08 +1000 Subject: Proper deletion of selected items during map iteration in for loop: Thanks to all In-Reply-To: <535c67e9$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <535AA12A.1030203@earthlink.net> <535c67e9$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 27, 2014 at 12:14 PM, Steven D'Aprano wrote: > I think the two obviously good enough approaches are: > > - save a "to be deleted" list, then delete those keys; > > - copy the "not to be deleted" items into a new dict For a small enough dict that the performance question doesn't matter, I'd go with the other option: iterate over a snapshot of the keys. Compare: # Naive approach: for k in d: if f(k): del d[k] # Snapshot of keys: for k in list(d): if f(k): del d[k] No extra loop at the end, no switching out and in of contents, just one little change in the loop header. Obviously you don't want to do this when you're deleting two out of three billion, but for smallish dicts, that won't make a visible change. ChrisA From steve+comp.lang.python at pearwood.info Sat Apr 26 22:49:31 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Apr 2014 02:49:31 GMT Subject: how to split this kind of text into sections References: Message-ID: <535c703a$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sat, 26 Apr 2014 23:53:14 +0800, oyster wrote: > Every SECTION starts with 2 special lines; these 2 lines is special > because they have some same characters (the length is not const for > different section) at the beginning; these same characters is called the > KEY for this section. For every 2 neighbor sections, they have different > KEYs. > > After these 2 special lines, some paragraph is followed. Paragraph does > not have any KEYs. > > So, a section = 2 special lines with KEYs at the beginning + some > paragraph without KEYs > > However there maybe some paragraph before the first section, which I do > not need and want to drop it > > I need a method to split the whole text into SECTIONs and to know all > the KEYs Let me try to describe how I would solve this, in English. I would look at each pair of lines (1st + 2nd, 2nd + 3rd, 3rd + 4th, etc.) looking for a pair of lines with matching prefixes. E.g.: "This line matches the next" "This line matches the previous" do match, because they both start with "This line matches the ". Question: how many characters in common counts as a match? "This line matches the next" "That previous line matches this line" have a common prefix of "Th", two characters. Is that a match? So let me start with a function to extract the matching prefix, if there is one. It returns '' if there is no match, and the prefix (the KEY) if there is one: def extract_key(line1, line2): """Return the key from two matching lines, or '' if not matching.""" # Assume they need five characters in common. if line1[:5] == line2[:5]: return line1[:5] return '' I'm pretty much guessing that this is how you decide there's a match. I don't know if five characters is too many or two few, or if you need a more complicated test. It seems that you want to match as many characters as possible. I'll leave you to adjust this function to work exactly as needed. Now we iterate over the text in pairs of lines. We need somewhere to hold the the lines in each section, so I'm going to use a dict of lists of lines. As a bonus, I'm going to collect the ignored lines using a key of None. However, I do assume that all keys are unique. It should be easy enough to adjust the following to handle non-unique keys. (Use a list of lists, rather than a dict, and save the keys in a separate list.) Lastly, the way it handles lines at the beginning of a section is not exactly the way you want it. This puts the *first* line of the section as the *last* line of the previous section. I will leave you to sort out that problem. from collections import OrderedDict section = [] sections = OrderedDict() sections[None] = section lines = iter(text.split('\n')) prev_line = '' for line in lines: key = extract_key(prev_line, line) if key == '': # No match, so we're still in the same section as before. section.append(line) else: # Match, so we start a new section. section = [line] sections[key] = section prev_line = line -- Steven D'Aprano http://import-that.dreamwidth.org/ From roy at panix.com Sat Apr 26 22:57:14 2014 From: roy at panix.com (Roy Smith) Date: Sat, 26 Apr 2014 22:57:14 -0400 Subject: Proper deletion of selected items during map iteration in for loop: Thanks to all References: <535AA12A.1030203@earthlink.net> <535c67e9$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <535c67e9$0$29965$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > I think the two obviously good enough approaches are: > > - save a "to be deleted" list, then delete those keys; > > - copy the "not to be deleted" items into a new dict There is a third possibility: Iterate over the dict, storing keys to be deleted in a list, but break out after the list reaches N items. Delete those keys from the dict. Repeat the whole process until you reach the end of the dictionary before you reach N saved keys. It's going to take multiple (perhaps many) passes over the dict, but it will limit the amount of extra memory used. In the extreme case, if N=1, with k keys in the dict, it will turn a process which is O(k) in time and O(k) in extra memory into one which is O(k^2) in time and O(1) in extra memory. Is that a good tradeoff? Only your hairdresser knows for sure. From umamahesh833 at gmail.com Sun Apr 27 03:16:41 2014 From: umamahesh833 at gmail.com (uma mahesh) Date: Sun, 27 Apr 2014 00:16:41 -0700 (PDT) Subject: need help in adding xlrd file to the dictionary. Message-ID: <742984fa-6c69-47f7-bf13-ccc53c86711d@googlegroups.com> Hello guys, I am new to python scripting. I am trying to take data from excel sheet. To do this I understand that xlrd need to add to the dictionary. I was unable to do this. I have downloaded the file and stuck there. Please let me know how can I do this. tell me the procedure. Regards Mahesh From steve+comp.lang.python at pearwood.info Sun Apr 27 04:48:47 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Apr 2014 08:48:47 GMT Subject: need help in adding xlrd file to the dictionary. References: <742984fa-6c69-47f7-bf13-ccc53c86711d@googlegroups.com> Message-ID: <535cc46f$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sun, 27 Apr 2014 00:16:41 -0700, uma mahesh wrote: > Hello guys, > > I am new to python scripting. I am trying to take data from excel sheet. > > To do this I understand that xlrd need to add to the dictionary. I was > unable to do this. I have downloaded the file and stuck there. > > Please let me know how can I do this. tell me the procedure. Are you using Linux? Macintosh? Unix? Windows? Python 2 or Python 3? What version? Is that the only Python installation on your system, or do you have others? What file did you download? The .tar.gz file? The .zip file? The Windows installer? Something else? Where did you download it from? Where did you download it to? What did you do next? What have you tried, and what happened when you tried? -- Steven D'Aprano http://import-that.dreamwidth.org/ From ikorot01 at gmail.com Sun Apr 27 05:38:27 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Sun, 27 Apr 2014 02:38:27 -0700 Subject: Sorting list alphabetically Message-ID: Hi, ALL, I need to perform a subj. Looking at the Google I found following thread with explanation: http://stackoverflow.com/questions/36139/how-do-i-sort-a-list-of-strings-in-python However, doing this in my python shell produces an error: C:\Documents and Settings\Igor.FORDANWORK\My Documents\GitHub\webapp>python Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import locale >>> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') Traceback (most recent call last): File "", line 1, in File "c:\python27\lib\locale.py", line 547, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting >>> What is wrong with this? Thank you. From kevin.p.dwyer at gmail.com Sun Apr 27 06:40:07 2014 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sun, 27 Apr 2014 11:40:07 +0100 Subject: Sorting list alphabetically References: Message-ID: Igor Korot wrote: > Hi, ALL, > I need to perform a subj. > Looking at the Google I found following thread with explanation: > > http://stackoverflow.com/questions/36139/how-do-i-sort-a-list-of-strings- in-python > > However, doing this in my python shell produces an error: > > C:\Documents and Settings\Igor.FORDANWORK\My > Documents\GitHub\webapp>python Python 2.7.5 (default, May 15 2013, > 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import locale >>>> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') > Traceback (most recent call last): > File "", line 1, in > File "c:\python27\lib\locale.py", line 547, in setlocale > return _setlocale(category, locale) > locale.Error: unsupported locale setting >>>> > > What is wrong with this? > > Thank you. Hello Igor, Windows maintains it's own names for locales, so you need to supply the Windows name if you're workong on Windows. You might find these links helpful: http://stackoverflow.com/questions/19709026/how-can-i-list-all-available- windows-locales-in-python-console https://mail.python.org/pipermail/python-list/2009-February/525427.html Cheers, Kev From __peter__ at web.de Sun Apr 27 06:45:05 2014 From: __peter__ at web.de (Peter Otten) Date: Sun, 27 Apr 2014 12:45:05 +0200 Subject: Sorting list alphabetically References: Message-ID: Igor Korot wrote: > Hi, ALL, > I need to perform a subj. > Looking at the Google I found following thread with explanation: > > http://stackoverflow.com/questions/36139/how-do-i-sort-a-list-of-strings-in-python > > However, doing this in my python shell produces an error: > > C:\Documents and Settings\Igor.FORDANWORK\My > Documents\GitHub\webapp>python Python 2.7.5 (default, May 15 2013, > 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import locale >>>> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') > Traceback (most recent call last): > File "", line 1, in > File "c:\python27\lib\locale.py", line 547, in setlocale > return _setlocale(category, locale) > locale.Error: unsupported locale setting >>>> > > What is wrong with this? The page you link to is pretty clear about it: locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') # vary depending on your lang/locale Sort order and encoding may vary from country to country, os to os, machine to machine. As the error message says, 'en_US.UTF-8' is not a locale supported on your machine. I suggest that you try using the default: >>> import locale >>> defaultlocale = locale.getdefaultlocale() >>> defaultlocale ('de_DE', 'UTF-8') >>> locale.setlocale(locale.LC_ALL, defaultlocale) 'de_DE.UTF-8' >>> encoding = defaultlocale[1] >>> words = u"A a B b ? ?".split() >>> print "".join(sorted(words)) ABab?? >>> print "".join(sorted(words, key=lambda s: locale.strxfrm(s.encode(encoding)))) aA??bB From matt.pounsett at gmail.com Sun Apr 27 10:16:48 2014 From: matt.pounsett at gmail.com (Matthew Pounsett) Date: Sun, 27 Apr 2014 07:16:48 -0700 (PDT) Subject: MacOS 10.9.2: threading error using python.org 2.7.6 distribution In-Reply-To: References: Message-ID: <675725e3-38d2-4d81-bf64-f6d903d4a684@googlegroups.com> On Friday, 25 April 2014 10:05:03 UTC-4, Chris Angelico wrote: > First culprit I'd look at is the mixing of subprocess and threading. > It's entirely possible that something goes messy when you fork from a > thread. I liked the theory, but I've run some tests and can't reproduce the error that way. I'm using all the elements in my test code that the real code runs, and I can't get the same error. Even when I deliberately break things I'm getting a proper exception with stack trace. class MyThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): logger = logging.getLogger("thread") p1 = subprocess.Popen( shlex.split( 'echo "MyThread calls echo."'), stdout=subprocess.PIPE, universal_newlines=True) logger.debug( p1.communicate()[0].decode('utf-8', 'ignore' )) logger.debug( "MyThread runs and exits." ) def main(): console = logging.StreamHandler() console.setFormatter( logging.Formatter('%(asctime)s [%(name)-12s] %(message)s', '%T')) logger = logging.getLogger() logger.addHandler(console) logger.setLevel(logging.NOTSET) try: t = MyThread() #t = RTF2TXT("../data/SRD/rtf/", Queue.Queue()) t.start() except Exception as e: logger.error( "Failed with {!r}".format(e)) if __name__ == '__main__': main() > Separately: You're attempting a very messy charset decode there. You > attempt to decode as UTF-8, errors ignored, and if that fails, you log > an error... and continue on with the original bytes. You're risking > shooting yourself in the foot there; I would recommend you have an > explicit fall-back (maybe re-decode as Latin-1??), so the next code is > guaranteed to be working with Unicode. Currently, it might get a > unicode or a str. Yeah, that was a logic error on my part that I hadn't got around to noticing, since I'd been concentrating on the stuff that was actively breaking. That should have been in an else: block on the end of the try. From matt.pounsett at gmail.com Sun Apr 27 10:18:21 2014 From: matt.pounsett at gmail.com (Matthew Pounsett) Date: Sun, 27 Apr 2014 07:18:21 -0700 (PDT) Subject: MacOS 10.9.2: threading error using python.org 2.7.6 distribution In-Reply-To: References: Message-ID: On Friday, 25 April 2014 14:58:56 UTC-4, Ned Deily wrote: > FWIW, the Python 2 version of subprocess is known to be thread-unsafe. > There is a Py2 backport available on PyPI of the improved Python 3 > subprocess module: Since that't the only thread that calls anything in subprocess, and I'm only running one instance of the thread, I'm not too concerned about how threadsafe subprocess is. In this case it shouldn't matter. Thanks for the info though.. that might be handy at some future point. From wxjmfauth at gmail.com Sun Apr 27 10:29:40 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 27 Apr 2014 07:29:40 -0700 (PDT) Subject: Unicode in Python In-Reply-To: References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> <5357715c$0$11109$c3e8da3@news.astraweb.com> <03bb12d8-93be-4ef6-94ae-4a02789aea2d@googlegroups.com> Message-ID: Le samedi 26 avril 2014 15:38:29 UTC+2, Ian a ?crit : > On Apr 26, 2014 3:46 AM, "Frank Millman" wrote: > > > > > > > > > wrote in message > > > news:03bb12d8-93be-4ef6-94ae-4a02789aea2d at googlegroups.com... > > > > ========== > > > > > > > > I wrote once 90 % of Python 2 apps (a generic term) supposed to > > > > process text, strings are not working. > > > > > > > > In Python 3, that's 100 %. It is somehow only by chance, apps may > > > > give the illusion they are properly working. > > > > > > > > > > It is quite frustrating when you make these statements without explaining > > > what you mean by 'not working'. > > As far as anybody has been able to determine, what jmf means by "not working" is that strings containing the EURO character are handled less efficiently than strings that do not contain it in certain contrived test cases. ----- 'EURO SIGN' ? No, it's just a character! From rosuav at gmail.com Sun Apr 27 10:33:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 28 Apr 2014 00:33:38 +1000 Subject: MacOS 10.9.2: threading error using python.org 2.7.6 distribution In-Reply-To: <675725e3-38d2-4d81-bf64-f6d903d4a684@googlegroups.com> References: <675725e3-38d2-4d81-bf64-f6d903d4a684@googlegroups.com> Message-ID: On Mon, Apr 28, 2014 at 12:16 AM, Matthew Pounsett wrote: > On Friday, 25 April 2014 10:05:03 UTC-4, Chris Angelico wrote: >> First culprit I'd look at is the mixing of subprocess and threading. >> It's entirely possible that something goes messy when you fork from a >> thread. > > I liked the theory, but I've run some tests and can't reproduce the error that way. I'm using all the elements in my test code that the real code runs, and I can't get the same error. Even when I deliberately break things I'm getting a proper exception with stack trace. > In most contexts, "thread unsafe" simply means that you can't use the same facilities simultaneously from two threads (eg a lot of database connection libraries are thread unsafe with regard to a single connection, as they'll simply write to a pipe or socket and then read a response from it). But processes and threads are, on many systems, linked. Just the act of spinning off a new thread and then forking can potentially cause problems. Those are the exact sorts of issues that you'll see when you switch OSes, as it's the underlying thread/process model that's significant. (Particularly of note is that Windows is *very* different from Unix-based systems, in that subprocess management is not done by forking. But not applicable here.) You may want to have a look at subprocess32, which Ned pointed out. I haven't checked, but I would guess that its API is identical to subprocess's, so it should be a drop-in replacement ("import subprocess32 as subprocess"). If that produces the exact same results, then it's (probably) not thread-safety that's the problem. >> Separately: You're attempting a very messy charset decode there. You >> attempt to decode as UTF-8, errors ignored, and if that fails, you log >> an error... and continue on with the original bytes. You're risking >> shooting yourself in the foot there; I would recommend you have an >> explicit fall-back (maybe re-decode as Latin-1??), so the next code is >> guaranteed to be working with Unicode. Currently, it might get a >> unicode or a str. > > Yeah, that was a logic error on my part that I hadn't got around to noticing, since I'd been concentrating on the stuff that was actively breaking. That should have been in an else: block on the end of the try. > Ah good. Keeping bytes versus text separate is something that becomes particularly important in Python 3, so I always like to encourage people to get them straight even in Py2. It'll save you some hassle later on. ChrisA From ranasaani at gmail.com Sun Apr 27 11:44:59 2014 From: ranasaani at gmail.com (ranasaani at gmail.com) Date: Sun, 27 Apr 2014 08:44:59 -0700 (PDT) Subject: How to get final URL after redirection In-Reply-To: References: Message-ID: <249157bf-e7d4-41c6-8991-bf3467d8f408@googlegroups.com> Hi Nsihant, I need your help, can I get your email address? From joel.goldstick at gmail.com Sun Apr 27 11:55:39 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 27 Apr 2014 11:55:39 -0400 Subject: How to get final URL after redirection In-Reply-To: <249157bf-e7d4-41c6-8991-bf3467d8f408@googlegroups.com> References: <249157bf-e7d4-41c6-8991-bf3467d8f408@googlegroups.com> Message-ID: Huh? His email is in his post On Apr 27, 2014 11:45 AM, wrote: > Hi Nsihant, I need your help, can I get your email address? > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Sun Apr 27 13:39:24 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 27 Apr 2014 10:39:24 -0700 (PDT) Subject: Unicode in Python In-Reply-To: References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> <5357715c$0$11109$c3e8da3@news.astraweb.com> Message-ID: On Wednesday, April 23, 2014 11:29:13 PM UTC+5:30, Rustom Mody wrote: > On Wednesday, April 23, 2014 1:23:00 PM UTC+5:30, Steven D'Aprano wrote: > > On Tue, 22 Apr 2014 23:57:46 -0700, Rustom Mody wrote: > > > On the other hand when/if a keyboard mapping is defined in which the > > > characters that are commonly needed are available, it is reasonable to > > > expect the ?,? to cost no more than 2 strokes each (ie about as much as > > > an 'A'; slightly more than an 'a'. Which means that '?' is expected to > > > cost about the same as 'or' and ? to cost less than an 'and' > > Oh, a further thought... > > Consider your example: > > return year%4=0 ? (year%100?0 ? year%100 = 0) > > vs > > return year%4=0 and (year%100!=0 or year%100 = 0) > > [aside: personally I like ? and if there was a platform independent way > > to type it in any editor, I'd much prefer it over != or <> ] I checked haskell and find the unicode support is better. For variables (ie identifiers) python and haskell are much the same: Python3: >>> ? = 1 >>> ? 1 Haskell: Prelude> let ? = 1 Prelude> ? 1 However in haskell one can also do this unlike python: *Main> 2 ? 3 True All that's needed to make this work is this set of new-in-terms-of-old definitions: [The -- is comments for those things that dont work as one may wish] -------------- import qualified Data.Set as Set -- Experimenting with Unicode in Haskell source -- Numbers x ? y = x /= y x ? y = x <= y x ? y = x >= y x ? y = divMod x y x ? y = x ^ y x ? y = x * y -- readability hmmm !!! ? = pi -- ? x = floor x -- ? x = ceiling x -- Lists xs ? ys = xs ++ ys n ? xs = take n xs n ? xs = drop n xs -- Bools x ? y = x && y x ? y = y || y -- ?x = not x -- Sets x ? s = x `Set.member` s s ? t = s `Set.union` t s ? t = s `Set.intersection` t s ? t = s `Set.isSubsetOf` t s ? t = s `Set.isProperSubsetOf` t s ? t = not (s `Set.isSubsetOf` t) -- ? = Set.null From ranasaani at gmail.com Sun Apr 27 13:41:57 2014 From: ranasaani at gmail.com (Rana Muhammad Usman) Date: Sun, 27 Apr 2014 22:41:57 +0500 Subject: How to get final URL after redirection In-Reply-To: References: <249157bf-e7d4-41c6-8991-bf3467d8f408@googlegroups.com> Message-ID: Not visible to me, can you tell me please? On Sun, Apr 27, 2014 at 8:55 PM, Joel Goldstick wrote: > Huh? His email is in his post > On Apr 27, 2014 11:45 AM, wrote: > >> Hi Nsihant, I need your help, can I get your email address? >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From denismfmcmahon at gmail.com Sun Apr 27 14:04:15 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sun, 27 Apr 2014 18:04:15 +0000 (UTC) Subject: How to get final URL after redirection References: <249157bf-e7d4-41c6-8991-bf3467d8f408@googlegroups.com> Message-ID: On Sun, 27 Apr 2014 22:41:57 +0500, Rana Muhammad Usman wrote: > On Sun, Apr 27, 2014 at 8:55 PM, Joel Goldstick > wrote: >> wrote: >>> Hi Nsihant, I need your help, can I get your email address? >> Huh? His email is in his post On Apr 27, 2014 11:45 AM, > Not visible to me, can you tell me please? Get some clues about usenet[see below]. Then you'd be able to see his email address. [1] Don't use google groups to access usenet messages, use an nntp client that talks to real newsservers. [2] Learn not to top post. [3] See 1, 2. [4] see [3] [5] repeat to infinity, referencing previous item each time. pythonically: while isUsingGoogleGroups or isTopPosting: stop_doing_that() -- Denis McMahon, denismfmcmahon at gmail.com From edgrsprj at ix.netcom.com Sun Apr 27 14:37:34 2014 From: edgrsprj at ix.netcom.com (E.D.G.) Date: Sun, 27 Apr 2014 13:37:34 -0500 Subject: Disaster Mitigation Program - Apr. 27, 2014 In-Reply-To: <9JydndajLf5n1sDOnZ2dnUVZ_oqdnZ2d@earthlink.com> References: <9JydndajLf5n1sDOnZ2dnUVZ_oqdnZ2d@earthlink.com> Message-ID: "E.D.G." wrote in message news:9JydndajLf5n1sDOnZ2dnUVZ_oqdnZ2d at earthlink.com... A PROPOSED INTERNET-BASED DISASTER ANTICIPATION AND RESPONSE COMPUTER PROGRAM Posted by E.D.G. on April 27, 2014 http://www.freewebs.com/eq-forecasting/Disaster_Response_System.html http://www.freewebs.com/eq-forecasting/Science_Organization.html http://www.freewebs.com/eq-forecasting/DSAT.html TABLE OF CONTENTS --- Information For Newsgroup Readers --- Introductory Comments --- A Proposed Internet-Based Disaster Anticipation And Response Computer Program --- How This Proposed Disaster Mitigation Program Would Work --- Participation In This Effort --- Additional Information For Newsgroup Posters --- Final Comments INFORMATION FOR NEWSGROUP READERS It would be appreciated if you would forward copies of this report to any government agencies, nongovernmental organizations, news services, commercial and university computer programming groups, and individual researchers that you feel might be interested in the subject matter. It is recommended that people who would like to post a response to this report should read the "ADDITIONAL INFORMATION FOR NEWSGROUP POSTERS" section of the report before they post their responses. The URLs in this report are indirect. They are often used in my public notices in part in the hope that this will help reduce the amount of spam mail that has to be dealt with each day. And indirect URLs also make it possible to change the address of an actual web page without having to circulate a notice letting everyone know about that. It is only necessary to change the internal address in the indirect URL. If those indirect URLs do not work with your Internet browser then if you wish you can contact me by E-mail for direct addresses. Webs.com is apparently posting advertisements to the bottoms of web pages at my Freewebs.com site. I don't have any arrangement with Webs.com for those advertisements to be there and would prefer that they were not present. However, it is a free site. So it would not be fair to complain. The statements in this report are expressions of personal opinion. INTRODUCTORY COMMENTS Most of this report was written quite a while ago but never posted to any newsgroups because other efforts have had a higher priority. While watching news reports related to that recent deadly Korea area ship sinking I decided to go looking in my files for the report, update it, and post it to a number of computer language newsgroups. This report discusses an effort to have a powerful and sophisticated Internet-based computer program created that could be used by governments and nongovernmental organizations such as hospitals around the world to anticipate and more rapidly respond to health and life-threatening situations such as that ship sinking. Those situations could range from serious automobile traffic accidents up to major aircraft crashes, floods, disease outbreaks, earthquakes, and hurricanes. A PROPOSED INTERNET-BASED DISASTER ANTICIPATION AND RESPONSE COMPUTER PROGRAM http://www.freewebs.com/eq-forecasting/Disaster_Response_System.html Professional and even amateur computer programmers around the world might be some of the most important unsung heroes of modern times. They develop and maintain the computer programs that are used by virtually every government, nongovernmental organization, hospital, doctor, and independent researcher around the world. The Internet itself is perhaps the most extraordinary communications resource ever developed. And it could be described as a complex, interlinking group of computer programs. In spite of all of the extraordinary work they are doing and how important their efforts are to everyone on the planet, computer programmers probably rarely get any recognition outside of their own field. I can't recall a Nobel Prize ever being awarded to a computer programmer. The proposed Internet-based disaster anticipation and response computer program discussed in this report is something that could conceivably change that and provide programmers around the world with something that they could point to and claim that they themselves were the people who were responsible for the program's development, not some government. Government, university, private corporation, and even independent programmers could take part in the development of this proposed disaster mitigation program. However, the actual program might need to be run by some independent organization such as the proposed science information related nonprofit foundations discussed on the web page that the following URL points to: http://www.freewebs.com/eq-forecasting/Science_Organization.html HOW THIS PROPOSED DISASTER MITIGATION PROGRAM WOULD WORK Versions of the proposed disaster mitigation program would actually be running at the same time on a number of Internet server computers and other types of computers around the world. They would constantly interact with and share data with one another. And if one got disabled by an event such as an earthquake that destroyed important computers or damaged some national or international fiber optics communications cable then one or more of the other computers would start doing the work that the affected computers etc. had been doing. Information regarding events such as rainfall around the world would be constantly fed into the system. And that way, devastating floods could be anticipated. Information regarding events such as aircraft crashes and even serious automobile traffic accidents would also be constantly fed into the system. The Internet-based disaster mitigation computer program would monitor events that were taking place around the world and generate a warning, for example, when it determined that unusually large amounts of rain had fallen in some area in a short period of time. And there was a reasonable probability that there could be a destructive flood downstream from the area. As explained on my web page, when the disaster mitigation program determined that there had been an aircraft crash in a large city the program would instantly generate an initial disaster response plan and send versions of the plan to the appropriate government agencies and hospitals etc. And it would also contact specially trained disaster response workers in the affected area and ask them to travel to certain locations and report on what they were seeing or help with efforts to temporarily limit access to selected major highways so that emergency response vehicles could travel down them at a high rate of speed without risking hitting or being slowed by other traffic on the highway. The disaster mitigation program would have internal routines that protected the privacy of individuals such as a person whose house had caught fire. Information like that would not be circulated through the global group of programs. It would be dealt with by the version of the program that was running on just one or a few computers. And that information could then be deleted from even those computers' files if desired. My web page goes into sufficient detail regarding how the program might work that it should not be necessary to discuss its operation any further in this newsgroup report. PARTICIPATION IN THIS EFFORT I myself know enough about Internet server-based computer program development that in theory I could develop this type of computer program. However, my personal disaster mitigation efforts are more focused on providing other researchers around the world with detailed plans for what can be done to anticipate and respond to a variety of health and life-threatening problems. For example, for a number of years I have been running the informal earthquake forecasting program associated with the web page pointed to by the following URL. And I am attempting to explain to governments around the world how they themselves could run such a program. http://www.freewebs.com/eq-forecasting/Data.html For several other examples, the following website reports discuss energy development related efforts: http://www.freewebs.com/eq-forecasting/Energy-Islands.html http://www.freewebs.com/eq-forecasting/Nuclear-Energy.html And as the following news report shows, one of those efforts related to the development of human-shaped robots that could safely go into crippled nuclear power plants and make repairs looks like it might now have been at least partially successful: http://www.cbsnews.com/news/pentagon-introduces-atlas-its-new-robo-sapien/ To understand why the U.S. Department of Energy would not be the department developing those repair robots I believe that a person would need to understand how energy politics work here in the U.S. and elsewhere. I could provide at least some help with efforts to get this proposed disaster mitigation program developed. For example, I can store additional program details that people send me, on my disaster mitigation program web page. However, I would not be able to take charge of the overall effort or run the nonprofit foundation that might administer the disaster mitigation computer program. Like everyone, there are limits to the amount of free time that I have available. Computer programming groups around the world such as university computer programming departments could work with one another in order to get this proposed disaster mitigation program developed. How they communicated with one another regarding their efforts would be up to them. However, from looking at different sites around the web it appears to me that the GitHub website might be a good place to start. https://github.com ADDITIONAL INFORMATION FOR NEWSGROUP POSTERS Copies of or references to this report are being posted to quite a few newsgroups including comp.lang.misc. It is recommended that people posting newsgroup responses to this report post them to only their main computer program language newsgroup plus the comp.lang.misc newsgroup, or just comp.lang.misc by itself. The comp.lang.misc newsgroup appears to be rarely used. And if copies of everyone's responses are posted there then that should enable everyone to visit that single newsgroup and easily see what is being discussed in all of the other newsgroups. They won't each get filled with responses posted to all of the others. FINAL COMMENTS Question: If a major traffic accident or an aircraft related disaster were to occur in your own city, what would type of response would there be? Answer: In virtually every location on the planet the accident would likely be responded to by local authorities using whatever resources they had in that area. And during the time that it took them to determine exactly what had happened and what needed to be done, lives could be lost that might have been saved had their responses been faster and better organized. In the case of a cataclysmic disaster such as a major earthquake, dramatically reduced response times might make it possible to save tremendous number of lives. So, it is my opinion that this type of Internet-based disaster mitigation computer program is needed by just about everyone on the planet. There might be organizations such as FEMA here in the U.S. that are already trying to get some type of organized disaster mitigation computer program developed. However, a sizeable percentage of cities around the world, large and small, are connected to the Internet. And if you live in one of those cities where this type of coordinated disaster response system is not available to you then it means that as far as you are concerned, it doesn't yet exist. The basic concept for the proposed program is relatively simple. And it would not be that expensive to develop and run compared to the number of lives and the amount of disaster response money that might be saved. Two Questions 1. Why doesn't this type of globally useful program already exist? 2. Why did it take so long for the U.S. Government to get its "Affordable Care Act" website fully operational? Of all of the technologies that we have, computer programming is likely one of the easiest to work with. If you have a good general development plan then if you want to make faster progress you can just divide your programming efforts into smaller and smaller parts and bring in more computer programmers to work on the various parts. Proposed Answers For Those Two Questions A detailed discussion of why computer programs like this proposed Internet-based disaster mitigation program and other important programs have not yet been created or why existing programs took so long to get running can be found in the report that the following URL points to: http://www.freewebs.com/eq-forecasting/DSAT.html DSAT in this case stands of "Department Of Science And Technology." That above report contains a detailed description of proposed government agencies that might help us solve or at least better manage many of these "slow technical progress" problems. At this point, a final appropriate question might be: Would computer programmers around the world like to work together to get the Internet-based disaster mitigation computer program described in this report developed, and in the process get some much-deserved public recognition for their efforts? From akonsta at icloud.com Sun Apr 27 14:56:39 2014 From: akonsta at icloud.com (Andrew Konstantaras) Date: Sun, 27 Apr 2014 18:56:39 +0000 (GMT) Subject: Help with changes in traceback stack from Python 2.7 to Python 3.x In-Reply-To: Message-ID: Thanks for the response and I can certainly see that this old code can be improved, but I respectfully disagree on the utility of this function. The flexibility of passing any number of arguments to the function and returning a dictionary is much easier than writing out dict(x=x, y=y, ...n=n). I also believe that "makeDict" makes my code very readable. My question is around finding the names of the variables passed to a function from within the function. I have spent many hours looking on the web looking for where in the frames and stacks this information is stored. Does anyone have any insight where/how I can find the variables associated with the arguments in dctA = makeDict(strA, intA) from within the function def makeDict(*args): .... #need to find the variable names "strA" and "intA" in this context ---Andrew ? On Apr 26, 2014, at 05:10 AM, Ned Batchelder wrote: > On 4/26/14 1:50 AM, Andrew Konstantaras wrote: > > I wrote the following code that works in Python 2.7 that takes the > > variables passed to the function into a dictionary. The following call: > > > > strA = 'a' > > intA = 1 > > dctA = makeDict(strA, intA) > > > > produces the following dictionary: > > > > {'strA':'a', 'intA':1} > > > > To access the names passed into the function, I had to find the > > information by parsing through the stack. The code that used to work is: > > > > from traceback import extract_stack > > > > def makeDict(*args): > > strAllStack = str(extract_stack()) > > intNumLevels = len(extract_stack()) > > intLevel = 0 > > blnFinished = False > > while not blnFinished: > > strStack = str(extract_stack()[intLevel]) > > if strStack.find("makeDict(") >0: > > blnFinished = True > > intLevel += 1 > > if intLevel >= intNumLevels: > > blnFinished = True > > strStartText = "= makeDict(" > > intLen = len(strStartText) > > intOpenParenLoc = strStack.find(strStartText) > > intCloseParenLoc = strStack.find(")", intOpenParenLoc) > > strArgs = strStack[ intOpenParenLoc+intLen : intCloseParenLoc ].strip() > > lstVarNames = strArgs.split(",") > > lstVarNames = [ s.strip() for s in lstVarNames ] > > if len(lstVarNames) == len(args): > > tplArgs = map(None, lstVarNames, args) > > newDict = dict(tplArgs) > > return newDict > > else: > > return "Error, argument name-value mismatch in function 'makeDict'. > > lstVarNames: " + str(lstVarNames) + "\n args: " + str(args), strAllStack > > > > The same code does not work in Python 3.3.4. I have tried parsing > > through the stack information and frames and I can't find any reference > > to the names of the arguments passed to the function. I have tried > > inspecting the function and other functions in the standard modules, but > > I can't seem to find anything that will provide this information. > > 1) This is a very strange function. Instead of going to all this > trouble, why not use: > > dctA = dict(strA=strA, intA=intA) > > Yes, you have to repeat the names, but you'd be done by now, it works on > both versions of Python, and people reading your code would understand > what it does. > > 2) Why is your code examining the entire stack? The frame you want is > the one just above you. Why are you stringifying the tuple produced by > extract_stack when the source line you want is the fourth element? Why > are you using a while loop and a counter to iterate over elements of a list? > > 3) In the error case you return a tuple when the caller is expecting a > dict? Why not raise an exception? > > 4) Your code only works if makeDict is assigned to a name. When I first > tried it, I used "print(makeDict(...))", and it failed completely. > > 5) You haven't mentioned what goes wrong on Python 3, but when I tried > it, I got: > > Traceback (most recent call last): > File "foo3.py", line 34, in > d = makeDict(a, b) > File "foo3.py", line 27, in makeDict > newDict = dict(list(tplArgs)) > TypeError: 'NoneType' object is not callable > > Looking at your code, I see: > > tplArgs = map(None, lstVarNames, args) > > I didn't realize map accepted a callable of None (TIL!), but it no > longer does in Python 3. You'll have to do this a different way. > > But seriously: just use dict() and be done with it. There's a lot here > that can be much simpler if you learn to use Python as it was meant to > be used. You are swimming upstream, there are easier ways. > > > > > Can anyone point me in the direction to find this information? Any help > > is appreciated. > > > > ---Andrew > > > > > > > > > -- > Ned Batchelder, http://nedbatchelder.com > > -- > https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Apr 27 16:18:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 28 Apr 2014 06:18:16 +1000 Subject: Help with changes in traceback stack from Python 2.7 to Python 3.x In-Reply-To: References: Message-ID: On Mon, Apr 28, 2014 at 4:56 AM, Andrew Konstantaras wrote: > Thanks for the response and I can certainly see that this old code can be > improved, but I respectfully disagree on the utility of this function. The > flexibility of passing any number of arguments to the function and returning > a dictionary is much easier than writing out dict(x=x, y=y, ...n=n). I also > believe that "makeDict" makes my code very readable. There is another option. You could pass a set of strings and a dictionary of all locals, and have it fetch them. However, I personally disagree about the readability; yes, it's nice and clean, but it does something which 99% of Python programmers won't expect. It's like writing a numeric type in C++ and then overloading the + operator to concatenate the decimal representations. > My question is around finding the names of the variables passed to a > function from within the function. I have spent many hours looking on the > web looking for where in the frames and stacks this information is stored. > Does anyone have any insight where/how I can find the variables associated > with the arguments in > > dctA = makeDict(strA, intA) > > from within the function > > def makeDict(*args): > .... #need to find the variable names "strA" and "intA" in this > context It isn't stored. What would be the names provided if, for instance, you do this: dctA = makeDict("literal", intA + intB) ? There is no name for a literal or an expression. One of the principles of Python is that an object is itself, regardless of the name used to reference it. You're violating that by peeking into the source code; you're fundamentally going against what every Python programmer will expect. Please don't do this. Take a step back, see what problem you're really trying to solve, and solve that problem another way. Maybe a simple DSL will help here, or possibly even just string interpolation, depending on what you're trying to do. If you need help, show us some of the code that uses makeDict, and we can advise. Just please don't inflict makeDict onto any subsequent maintainer. ChrisA From tjreedy at udel.edu Sun Apr 27 16:48:24 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 27 Apr 2014 16:48:24 -0400 Subject: Sorting list alphabetically In-Reply-To: References: Message-ID: On 4/27/2014 6:40 AM, Kev Dwyer wrote: > Igor Korot wrote: > >> Hi, ALL, >> I need to perform a subj. >> Looking at the Google I found following thread with explanation: >> >> http://stackoverflow.com/questions/36139/how-do-i-sort-a-list-of-strings- > in-python >> >> However, doing this in my python shell produces an error: >> >> C:\Documents and Settings\Igor.FORDANWORK\My >> Documents\GitHub\webapp>python Python 2.7.5 (default, May 15 2013, >> 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import locale >>>>> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') >> Traceback (most recent call last): >> File "", line 1, in >> File "c:\python27\lib\locale.py", line 547, in setlocale >> return _setlocale(category, locale) >> locale.Error: unsupported locale setting >>>>> >> >> What is wrong with this? >> >> Thank you. > > > Hello Igor, > > Windows maintains it's own names for locales, so you need to > supply the Windows name if you're workong on Windows. > > You might find these links helpful: > > http://stackoverflow.com/questions/19709026/how-can-i-list-all-available- > windows-locales-in-python-console This one says to look at locale.locala_alias, but that is not helpful. >>> for k, v in la.items(): if v.startswith ('en') and 'UTF' in v: print(k, " # ", v) universal.utf8 at ucs4 # en_US.UTF-8 But that local does not work on my machine. >>> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') Traceback (most recent call last): File "", line 1, in locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') File "C:\Programs\Python34\lib\locale.py", line 592, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting locale.locale_alias must not be machine limited. > https://mail.python.org/pipermail/python-list/2009-February/525427.html This merely says to look at a now dead link. -- Terry Jan Reedy From akonsta at icloud.com Sun Apr 27 17:51:54 2014 From: akonsta at icloud.com (Andrew Konstantaras) Date: Sun, 27 Apr 2014 21:51:54 +0000 (GMT) Subject: Help with changes in traceback stack from Python 2.7 to Python 3.x In-Reply-To: Message-ID: <06134705-e2b1-4a2f-adb6-bec4faa96e83@me.com> I guess I am missing something big as I am looking for a shorthand way of doing the following: dctA = dict(x=x, y=y, ... n=n) This is, as I understand it a very natural way of using a dictionary. It seems that this syntax is unnecessarily redundant and hence my goal of writing something more compact. Perhaps the way I am doing it is a little unorthodox, but the ultimate use of a dictionary is, as I understand it, completely in line with how dictionaries were designed to be used. In my other code, I often use these dictionaries to pass arguments to functions and return results. It allows me great flexibility without breaking existing code. I pack a dictionary before passing and unpack when retrieving. I will give the locals approach a try, it seems a little more clumsy than simply passing the variables to the function. Thanks again for your input. ---Andrew? On Apr 27, 2014, at 01:18 PM, Chris Angelico wrote: > On Mon, Apr 28, 2014 at 4:56 AM, Andrew Konstantaras wrote: > > Thanks for the response and I can certainly see that this old code can be > > improved, but I respectfully disagree on the utility of this function. The > > flexibility of passing any number of arguments to the function and returning > > a dictionary is much easier than writing out dict(x=x, y=y, ...n=n). I also > > believe that "makeDict" makes my code very readable. > > There is another option. You could pass a set of strings and a > dictionary of all locals, and have it fetch them. However, I > personally disagree about the readability; yes, it's nice and clean, > but it does something which 99% of Python programmers won't expect. > It's like writing a numeric type in C++ and then overloading the + > operator to concatenate the decimal representations. > > > My question is around finding the names of the variables passed to a > > function from within the function. I have spent many hours looking on the > > web looking for where in the frames and stacks this information is stored. > > Does anyone have any insight where/how I can find the variables associated > > with the arguments in > > > > dctA = makeDict(strA, intA) > > > > from within the function > > > > def makeDict(*args): > > .... #need to find the variable names "strA" and "intA" in this > > context > > It isn't stored. What would be the names provided if, for instance, you do this: > > dctA = makeDict("literal", intA + intB) > > ? There is no name for a literal or an expression. One of the > principles of Python is that an object is itself, regardless of the > name used to reference it. You're violating that by peeking into the > source code; you're fundamentally going against what every Python > programmer will expect. > > Please don't do this. Take a step back, see what problem you're really > trying to solve, and solve that problem another way. Maybe a simple > DSL will help here, or possibly even just string interpolation, > depending on what you're trying to do. If you need help, show us some > of the code that uses makeDict, and we can advise. > > Just please don't inflict makeDict onto any subsequent maintainer. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Apr 27 18:00:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 28 Apr 2014 08:00:52 +1000 Subject: Help with changes in traceback stack from Python 2.7 to Python 3.x In-Reply-To: <06134705-e2b1-4a2f-adb6-bec4faa96e83@me.com> References: <06134705-e2b1-4a2f-adb6-bec4faa96e83@me.com> Message-ID: On Mon, Apr 28, 2014 at 7:51 AM, Andrew Konstantaras wrote: > I will give the locals approach a try, it seems a little more clumsy than > simply passing the variables to the function. This is your fundamental misunderstanding that's led to all of this. You do not "pass variables to a function"; you pass objects. As far as Python's concerned, there's no difference between these functions: def foo(): a = 42 return f(a) def bar(): b = 42 return f(b) def quux(): return f(42) Each one passes the integer 42 to f(). The fact that it's referenced by different names is utterly meaningless. It's the object 42, not the name a or b, that gets passed in to the function. At best, your makeDict will be fragile. It can be broken by all sorts of unrelated changes. At worst, it's horribly misleading to other programmers. ChrisA From steve+comp.lang.python at pearwood.info Sun Apr 27 22:11:30 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Apr 2014 02:11:30 GMT Subject: Help with changes in traceback stack from Python 2.7 to Python 3.x References: Message-ID: <535db8d2$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sun, 27 Apr 2014 21:51:54 +0000, Andrew Konstantaras wrote: > I guess I am missing something big as I am looking for a shorthand way > of doing the following: > > dctA = dict(x=x, y=y, ... n=n) > > This is, as I understand it a very natural way of using a dictionary. Would you prefer this? dctA = {'x': x, 'y': y, 'n': n} > It seems that this syntax is unnecessarily redundant [...] > I will give the locals approach a try, it seems a little more clumsy > than simply passing the variables to the function. If you think that, it's because you haven't really thought it through completely. Possibly you don't quite understand Python's execution model fully, or you're used to languages which have a different execution model, or worst of all, you're used to a language which blesses dirty runtime hacks as "features". Suppose we could pass variables directly to the constructor, like this: a = b = 2 L = [1, 2, 3] dctA = dict(a, b, L[1], 2, 1+1) Obviously all five values are 2, but what are the keys? A language with a static compiler and pass-by-name behaviour, like Algol, might be able to tell that the first argument comes from a variable called 'a' and the second from a variable called 'b'. But languages with pass-by-value behaviour, like C, cannot. Likewise, Python cannot tell the name of the object. The dict construct receives five arguments, all bound to the object 2. (That might be the same object five times, or five distinct objects, all with the same value of 2.) The objects don't know what names they are bound to: they might be bound to zero, one, or more names. If they're bound to zero names, what name should the dict constructor invent for them? If they're bound to two or more names, which name should the dict constructor use? So as you can see, in general the dict constructor *cannot* infer a unique name for the argument. In some cases it may be able to guess, or arbitrarily pick one out of many, using implementation hacks that are not standard across all versions and implementations of Python. A hack that works in CPython probably won't work in Jython, and one that works in IronPython probably won't work in PyPy. Objects don't have a unique name, so the very concept of getting "the name" of a value is dubious, and has to rely on a dirty hack. Nevertheless, as you have discovered, you can do so in CPython. Presumably there is a different hack that would work in IronPython, Jython, Cython, PyPy, Nuitka, Unladen Swallow, ... so perhaps it could be declared that, dirty hack or not, it should be part of the language. Should it? Consider the unlimited number of variations on: dict(key=value) dict(name=value) dict(age=value) dict(a=value) dict(b=value) dict(arg=value) dict(param=value) dict(foo=value) dict(bar=value) [...] dict(value=value) Why is that last case so special that the dict constructor should guess that when you type "dict(value)" it wasn't a mistake, but that you actually intended "dict(value=value)" rather than key=value or name=value? You should consider the Zen of Python for a glimpse into the design principles that the creators of Python tend to follow as a rule: http://legacy.python.org/dev/peps/pep-0020/ See how many of the design principles are violated by a feature that guesses the key name if not supplied. Other languages may make other choices. I think that makes them worse languages. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Sun Apr 27 22:19:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 28 Apr 2014 12:19:02 +1000 Subject: Help with changes in traceback stack from Python 2.7 to Python 3.x In-Reply-To: <535db8d2$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <535db8d2$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Apr 28, 2014 at 12:11 PM, Steven D'Aprano wrote: > Suppose we could pass variables directly to the constructor, like this: > > a = b = 2 > L = [1, 2, 3] > dctA = dict(a, b, L[1], 2, 1+1) > > Obviously all five values are 2, but what are the keys? > > The dict construct > receives five arguments, all bound to the object 2. (That might be the > same object five times, or five distinct objects, all with the same value > of 2.) Just to nit-pick: A conforming Python implementation might pass up to four distinct objects, but the first two MUST be the same object. :) ChrisA From joshua at landau.ws Mon Apr 28 02:22:52 2014 From: joshua at landau.ws (Joshua Landau) Date: Mon, 28 Apr 2014 07:22:52 +0100 Subject: Inconsistent viewkeys behaviour Message-ID: Is there any reference for this strange behaviour on Python 2: >>> set() < dict().viewkeys() Traceback (most recent call last): File "", line 1, in TypeError: can only compare to a set >>> dict().viewkeys() > set() False ? From kevin.p.dwyer at gmail.com Mon Apr 28 02:33:35 2014 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Mon, 28 Apr 2014 07:33:35 +0100 Subject: Sorting list alphabetically References: Message-ID: Terry Reedy wrote: > On 4/27/2014 6:40 AM, Kev Dwyer wrote: >> Igor Korot wrote: >> >>> Hi, ALL, >>> I need to perform a subj. >>> Looking at the Google I found following thread with explanation: >>> >>> http://stackoverflow.com/questions/36139/how-do-i-sort-a-list-of- strings- >> in-python >>> >>> However, doing this in my python shell produces an error: >>> >>> C:\Documents and Settings\Igor.FORDANWORK\My >>> Documents\GitHub\webapp>python Python 2.7.5 (default, May 15 2013, >>> 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> import locale >>>>>> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') >>> Traceback (most recent call last): >>> File "", line 1, in >>> File "c:\python27\lib\locale.py", line 547, in setlocale >>> return _setlocale(category, locale) >>> locale.Error: unsupported locale setting >>>>>> >>> >>> What is wrong with this? >>> >>> Thank you. >> >> >> Hello Igor, >> >> Windows maintains it's own names for locales, so you need to >> supply the Windows name if you're workong on Windows. >> >> You might find these links helpful: >> >> http://stackoverflow.com/questions/19709026/how-can-i-list-all-available- >> windows-locales-in-python-console > > This one says to look at locale.locala_alias, but that is not helpful. > > >>> for k, v in la.items(): > if v.startswith ('en') and 'UTF' in v: > print(k, " # ", v) > > universal.utf8 at ucs4 # en_US.UTF-8 > > But that local does not work on my machine. > > >>> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') > Traceback (most recent call last): > File "", line 1, in > locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') > File "C:\Programs\Python34\lib\locale.py", line 592, in setlocale > return _setlocale(category, locale) > locale.Error: unsupported locale setting > > locale.locale_alias must not be machine limited. > >> https://mail.python.org/pipermail/python-list/2009-February/525427.html > > This merely says to look at a now dead link. My mistake for not checking the link; this one works: http://msdn.microsoft.com/en-us/library/hzz3tw78 > Hello Terry, Regarding your second point, my mistake in not checking the link: I'd seen a similar one elsewhere and assumed they were the same. This link should work: http://msdn.microsoft.com/en-us/library/hzz3tw78 As to your first point, you're right, it seems setlocale(locale.LC_ALL, 'en_US.UTF-8') doesn't work on Windows. It seems the locale name needs to be one of the aliases provided at http://msdn.microsoft.com/en-us/library/39cwe7zf, so for example locale.setlocale(locale.LC_ALL, 'usa') returns 'English_United States.1252'. Do you know if this is something people programming on Windows should just be aware of, or is there a case for a hint of some kind in the locale module documentation? Cheers, Kev From steve at pearwood.info Mon Apr 28 03:20:14 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 28 Apr 2014 07:20:14 GMT Subject: Help with changes in traceback stack from Python 2.7 to Python 3.x References: <535db8d2$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <535e012d$0$11109$c3e8da3@news.astraweb.com> On Mon, 28 Apr 2014 12:19:02 +1000, Chris Angelico wrote: > On Mon, Apr 28, 2014 at 12:11 PM, Steven D'Aprano > wrote: >> Suppose we could pass variables directly to the constructor, like this: >> >> a = b = 2 >> L = [1, 2, 3] >> dctA = dict(a, b, L[1], 2, 1+1) >> >> Obviously all five values are 2, but what are the keys? >> >> The dict construct >> receives five arguments, all bound to the object 2. (That might be the >> same object five times, or five distinct objects, all with the same >> value of 2.) > > Just to nit-pick: A conforming Python implementation might pass up to > four distinct objects, but the first two MUST be the same object. :) So it does, thanks for the correction. -- Steven From wxjmfauth at gmail.com Mon Apr 28 04:57:15 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 28 Apr 2014 01:57:15 -0700 (PDT) Subject: Unicode in Python In-Reply-To: References: <0f253434-5e7d-4eea-88e1-7997fec2bd2d@googlegroups.com> <773afa7d-4b6d-4d67-8d40-ea90b335a1a2@googlegroups.com> <5357715c$0$11109$c3e8da3@news.astraweb.com> <03bb12d8-93be-4ef6-94ae-4a02789aea2d@googlegroups.com> Message-ID: Le samedi 26 avril 2014 15:38:29 UTC+2, Ian a ?crit : > On Apr 26, 2014 3:46 AM, "Frank Millman" wrote: > > > > > > > > > wrote in message > > > news:03bb12d8-93be-4ef6-94ae-4a02789aea2d at googlegroups.com... > > > > ========== > > > > > > > > I wrote once 90 % of Python 2 apps (a generic term) supposed to > > > > process text, strings are not working. > > > > > > > > In Python 3, that's 100 %. It is somehow only by chance, apps may > > > > give the illusion they are properly working. > > > > > > > > > > It is quite frustrating when you make these statements without explaining > > > what you mean by 'not working'. > > As far as anybody has been able to determine, what jmf means by "not working" is that strings containing the EURO character are handled less efficiently than strings that do not contain it in certain contrived test cases. ---- Python 2.7 + cp1252: - Solid and coherent system (nothing to do with the Euro). Python 3: - It missed the unicode shift. - Covering the whole unicode range will not make Python a unicode compliant product. - Flexible String Representation (a problem per se), a mathematical absurditiy which does the opposite of the coding schemes endorsed by Unicord.org (sheet of paper and pencil!) - Very deeply buggy (quadrature of the circle problem). Positive side: - A very nice tool to teach the coding of characters and unicode. jmf From robin at reportlab.com Mon Apr 28 05:47:54 2014 From: robin at reportlab.com (Robin Becker) Date: Mon, 28 Apr 2014 10:47:54 +0100 Subject: possible bug in re expression? In-Reply-To: References: <535A8DB5.4090109@chamonix.reportlab.co.uk> Message-ID: <535E23CA.6040004@chamonix.reportlab.co.uk> On 25/04/2014 19:32, Terry Reedy wrote: .......... > I suppose that one could argue that '{' alone should be treated as special > immediately, and not just when a matching '}' is found, and should disable other > special meanings. I wonder what JS does if there is no matching '}'? > well in fact I suspect this is my mistranslation of the original new RegExp('.{1,' + (+size) + '}', 'g') my hacked up translator doesn't know what that means. I suspect that (+size) is an attempt to force size to an integer prior to it being forced to a string. I used to believe that conversion was always written 0-x, but experimentally (+"3") ends up as 3 not "3". Naively, I imagined that re would complain about ambiguous regular expressions, but in the regexp world n problems --> n+1 problems almost surely so I should have anticipated it :) Does this in fact that almost any broken regexp specification will silently fail because re will reset and consider any metacharacter as literal? -- Robin Becker From tjreedy at udel.edu Mon Apr 28 06:28:48 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 28 Apr 2014 06:28:48 -0400 Subject: Inconsistent viewkeys behaviour In-Reply-To: References: Message-ID: On 4/28/2014 2:22 AM, Joshua Landau wrote: > Is there any reference for this strange behaviour on Python 2: > > >>> set() < dict().viewkeys() > Traceback (most recent call last): > File "", line 1, in > TypeError: can only compare to a set > >>> dict().viewkeys() > set() > False The left operand determines the result. The manual specifies that < and > do not have to be consistent. But I suspect that when 3.x dict.keys() was backported to 2.7.0, no one thought to update set, whereas the backported key view code already had the comparison. -- Terry Jan Reedy From duncan.booth at invalid.invalid Mon Apr 28 06:48:58 2014 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 28 Apr 2014 10:48:58 GMT Subject: Proper deletion of selected items during map iteration in for loop: Thanks to all References: <535AA12A.1030203@earthlink.net> <535c67e9$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > # Snapshot of keys: > for k in list(d): > if f(k): del d[k] > > No extra loop at the end, no switching out and in of contents, just > one little change in the loop header. Obviously you don't want to do > this when you're deleting two out of three billion, but for smallish > dicts, that won't make a visible change. Even if you have three billion keys, the extra memory needed to create a list that references those keys is going to be a lot less than the memory used by the keys themselves. For example if the keys are 6 character strings then each string needs I think at least 45 bytes (64 bit Python 2.x, up to double that in Python 3.x) but the list only needs one 8 byte pointer per key. I would always choose this simple solution until such time as it is proved to be a problem. -- Duncan Booth From steve+comp.lang.python at pearwood.info Mon Apr 28 07:49:11 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Apr 2014 11:49:11 GMT Subject: possible bug in re expression? References: <535A8DB5.4090109@chamonix.reportlab.co.uk> Message-ID: <535e4037$0$29965$c3e8da3$5496439d@news.astraweb.com> On Mon, 28 Apr 2014 10:47:54 +0100, Robin Becker wrote: > Does this in fact that almost any broken regexp specification will > silently fail because re will reset and consider any metacharacter as > literal? Well, I don't know about "almost any", but at least some broken regexes will explicitly fail: py> import re py> re.search('*', "123*4") Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.3/re.py", line 161, in search return _compile(pattern, flags).search(string) [...] File "/usr/local/lib/python3.3/sre_parse.py", line 552, in _parse raise error("nothing to repeat") sre_constants.error: nothing to repeat (For brevity I have abbreviated the traceback.) -- Steven D'Aprano http://import-that.dreamwidth.org/ From dimmaim at gmail.com Mon Apr 28 08:52:02 2014 From: dimmaim at gmail.com (dimmaim at gmail.com) Date: Mon, 28 Apr 2014 05:52:02 -0700 (PDT) Subject: problem with regex Message-ID: i want to find a specific urls from a txt file but i have some issus. First when i take just two lines from the file with copy paste and assign it to a variable like this and it works only with triple quotes test='''_*_n.jpg","timelineCoverPhoto":"{\"focus\":{\"x\":0.5,\"y\":0.386925795053},\"photo\":{\"__type__\":{\"name\":\"Photo\"},\"image_lowres\":{\"uri\":\"https://fbcdn-photos-f-a.akamaihd.net/*-*-*/*_*_*_a.jpg\",\"width\":180,\"height\":179}}}","subscribeStatus":"IS_SUBSCRIBED","smallPictureUrl":"https://fbcdn-profile-a.akamaihd.net/*-*-*/s100x100/*_*_*_s.jpg","contactId":"*==","contactType":"USER","friendshipStatus":"ARE_FRIENDS","graphApiWriteId":"contact_*:*:*","hugePictureUrl":"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-frc3/*_*_*_n.jpg","profileFbid":"1284503586","isMobilePushable":"NO","lookupKey":null,"name":{"displayName":"* *","firstName":"*","lastName":"*"},"nameSearchTokens":["*","*"],"phones":[],"phoneticName":{"displayName":null,"firstName":null,"lastName":null},"isMemorialized":false,"communicationRank":1.1144714,"canViewerSendGift":false,"canMessage":true} *=={"bigPictureUrl":"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/*.*.*.*/s200x200/*_*_*_n.jpg","timelineCoverPhoto":"{\"focus\":{\"x\":0.5,\"y\":0.49137931034483},\"photo\":{\"__type__\":{\"name\":\"Photo\"},\"image_lowres\":{\"uri\":\"https://fbcdn-photos-h-a.akamaihd.net/*-*-*/*_*_*_a.jpg\",\"width\":180,\"height\":135}}}","subscribeStatus":"IS_SUBSCRIBED","smallPictureUrl":"https://fbcdn-profile-a.akamaihd.net/*-*-*/*.*.*.*/s100x100/*_*_*_a.jpg","contactId":"*==","contactType":"USER","friendshipStatus":"ARE_FRIENDS","graphApiWriteId":"contact_*:*:*","hugePictureUrl":"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/c0.0.540.540/*_*_*_n.jpg","profileFbid":"*","isMobilePushable":"YES","lookupKey":null,"name":{"displayName":"* *","firstName":"*","lastName":"*"},"nameSearchTokens":["*","*"],"phones":[],"phoneticName":{"displayName":null,"firstName":null,"lastName":null},"isMemorialized":false,"communicationRank":1.2158813,"canViewerSendGift":false,"canMessage":true}''' uri = re.findall(r'''uri\":\"https://fbcdn-(a-z|photos)?([^\'" >]+)''',test) print uri it works fine and i have my result [('photos', '-f-a.akamaihd.net/*-*-*/*_*_*_a.jpg'), ('photos', '-h-a.akamaihd.net/*-*-*/*_*_*_a.jpg')] but if a take those lines and save it into a txt file like the original is without the quotes and do the following datafile=open('a.txt','r') data_array='' for line in datafile: data_array=data_array+line uri = re.findall(r'''uri\":\"https://fbcdn-(a-z|photos)?([^\'" >]+)''',data_array) after printing uri it gives an empty list,. what to do to make it work for the lines of a txt file From dimmaim at gmail.com Mon Apr 28 08:54:43 2014 From: dimmaim at gmail.com (dimmaim at gmail.com) Date: Mon, 28 Apr 2014 05:54:43 -0700 (PDT) Subject: problem with regex Message-ID: i want to find a specific urls from a txt file but i have some issus. First when i take just two lines from the file with copy paste and assign it to a variable like this and it works only with triple quotes test='''_*_n.jpg","timelineCoverPhoto":"{\"focus\":{\"x\":0.5,\"y\":0.386925795053},\"photo\":{\"__type__\":{\"name\":\"Photo\"},\"image_lowres\":{\"uri\":\"https://fbcdn-photos-f-a.akamaihd.net/*-*-*/*_*_*_a.jpg\",\"width\":180,\"height\":179}}}","subscribeStatus":"IS_SUBSCRIBED","smallPictureUrl":"https://fbcdn-profile-a.akamaihd.net/*-*-*/s100x100/*_*_*_s.jpg","contactId":"*==","contactType":"USER","friendshipStatus":"ARE_FRIENDS","graphApiWriteId":"contact_*:*:*","hugePictureUrl":"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-frc3/*_*_*_n.jpg","profileFbid":"*","isMobilePushable":"NO","lookupKey":null,"name":{"displayName":"* *","firstName":"*","lastName":"*"},"nameSearchTokens":["*","*"],"phones":[],"phoneticName":{"displayName":null,"firstName":null,"lastName":null},"isMemorialized":false,"communicationRank":1.1144714,"canViewerSendGift":false,"canMessage":true} *=={"bigPictureUrl":"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/*.*.*.*/s200x200/*_*_*_n.jpg","timelineCoverPhoto":"{\"focus\":{\"x\":0.5,\"y\":0.49137931034483},\"photo\":{\"__type__\":{\"name\":\"Photo\"},\"image_lowres\":{\"uri\":\"https://fbcdn-photos-h-a.akamaihd.net/*-*-*/*_*_*_a.jpg\",\"width\":180,\"height\":135}}}","subscribeStatus":"IS_SUBSCRIBED","smallPictureUrl":"https://fbcdn-profile-a.akamaihd.net/*-*-*/*.*.*.*/s100x100/*_*_*_a.jpg","contactId":"*==","contactType":"USER","friendshipStatus":"ARE_FRIENDS","graphApiWriteId":"contact_*:*:*","hugePictureUrl":"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/c0.0.540.540/*_*_*_n.jpg","profileFbid":"*","isMobilePushable":"YES","lookupKey":null,"name":{"displayName":"* *","firstName":"*","lastName":"*"},"nameSearchTokens":["*","*"],"phones":[],"phoneticName":{"displayName":null,"firstName":null,"lastName":null},"isMemorialized":false,"communicationRank":1.2158813,"canViewerSendGift":false,"canMessage":true}''' uri = re.findall(r'''uri\":\"https://fbcdn-(a-z|photos)?([^\'" >]+)''',test) print uri it works fine and i have my result [('photos', '-f-a.akamaihd.net/*-*-*/*_*_*_a.jpg'), ('photos', '-h-a.akamaihd.net/*-*-*/*_*_*_a.jpg')] but if a take those lines and save it into a txt file like the original is without the quotes and do the following datafile=open('a.txt','r') data_array='' for line in datafile: data_array=data_array+line uri = re.findall(r'''uri\":\"https://fbcdn-(a-z|photos)?([^\'" >]+)''',data_array) after printing uri it gives an empty list,. what to do to make it work for the lines of a txt file From roy at panix.com Mon Apr 28 09:03:57 2014 From: roy at panix.com (Roy Smith) Date: Mon, 28 Apr 2014 09:03:57 -0400 Subject: problem with regex References: Message-ID: In article , dimmaim at gmail.com wrote: > i want to find a specific urls from a txt file but i have some issus. First > when i take just two lines from the file with copy paste and assign it to a > variable like this and it works only with triple quotes > > test='''''' [...] > but if a take those lines and save it into a txt file like the original is > without the quotes [it doesn't work] I suspect this has nothing to do with regular expressions, but it's just about string management. The first thing you want to do is verify that the text you are reading in from the file is the same as the text you have in triple quotes. So, write a program like this: test='''''' datafile=open('a.txt','r') data_array='' for line in datafile: data_array=data_array+line print test == data_array If that prints True, then you've got the same text in both cases (and you can go on to looking for other problems). I suspect it will print False, though. So, now your task is to figure out where those two strings differ. Maybe something like: for c1, c2 in zip(test, data_array): print c1 == c2, repr(c1), repr(c2) and look for the first place they're not the same. Hopefully that will give you a clue what's going wrong. From mboyd02255 at gmail.com Mon Apr 28 09:04:02 2014 From: mboyd02255 at gmail.com (mboyd02255 at gmail.com) Date: Mon, 28 Apr 2014 06:04:02 -0700 (PDT) Subject: Convert numpy array to single number Message-ID: <088cdf75-f196-404b-ba77-567559f431d8@googlegroups.com> I have a numpy array consisting of 1s and zeros for representing binary numbers: e.g. >>> binary array([ 1., 0., 1., 0.]) I wish the array to be in the form 1010, so it can be manipulated. I do not want to use built in binary converters as I am trying to build my own. From robin at reportlab.com Mon Apr 28 09:06:08 2014 From: robin at reportlab.com (Robin Becker) Date: Mon, 28 Apr 2014 14:06:08 +0100 Subject: possible bug in re expression? In-Reply-To: <535e4037$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <535A8DB5.4090109@chamonix.reportlab.co.uk> <535e4037$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <535E5240.3030609@chamonix.reportlab.co.uk> On 28/04/2014 12:49, Steven D'Aprano wrote: ...... > > Well, I don't know about "almost any", but at least some broken regexes > will explicitly fail: > > > > py> import re ........ > sre_constants.error: nothing to repeat > > (For brevity I have abbreviated the traceback.) > so there is intent to catch some specification errors. I've abandoned this translation anyhow as all that was intended was to split the string into non-overlapping strings of size at most k. I find this works faster than the regexp even if the regexp is pre-compiled. [p[i:i+k] for i in xrange(0,len(p),k)] -- Robin Becker From steve+comp.lang.python at pearwood.info Mon Apr 28 10:16:08 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Apr 2014 14:16:08 GMT Subject: Convert numpy array to single number References: <088cdf75-f196-404b-ba77-567559f431d8@googlegroups.com> Message-ID: <535e62a8$0$29965$c3e8da3$5496439d@news.astraweb.com> On Mon, 28 Apr 2014 06:04:02 -0700, mboyd02255 wrote: > I have a numpy array consisting of 1s and zeros for representing binary > numbers: > > e.g. > > >>> binary > array([ 1., 0., 1., 0.]) > > I wish the array to be in the form 1010, so it can be manipulated. > > I do not want to use built in binary converters as I am trying to build > my own. Did you have a question, or are you just sharing? -- Steven D'Aprano http://import-that.dreamwidth.org/ From roy at panix.com Mon Apr 28 12:00:23 2014 From: roy at panix.com (Roy Smith) Date: Mon, 28 Apr 2014 12:00:23 -0400 Subject: Significant digits in a float? Message-ID: I'm using Python 2.7 I have a bunch of floating point values. For example, here's a few (printed as reprs): 38.0 41.2586 40.75280000000001 49.25 33.795199999999994 36.837199999999996 34.1489 45.5 Fundamentally, these numbers have between 0 and 4 decimal digits of precision, and I want to be able to intuit how many each has, ignoring the obvious floating point roundoff problems. Thus, I want to map: 38.0 ==> 0 41.2586 ==> 4 40.75280000000001 ==> 4 49.25 ==> 2 33.795199999999994 ==> 4 36.837199999999996 ==> 4 34.1489 ==> 4 45.5 ==> 1 Is there any clean way to do that? The best I've come up with so far is to str() them and parse the remaining string to see how many digits it put after the decimal point. The numbers are given to me as Python floats; I have no control over that. I'm willing to accept that fact that I won't be able to differentiate between float("38.0") and float("38.0000"). Both of those map to 1, which is OK for my purposes. --- Roy Smith roy at panix.com From ned at nedbatchelder.com Mon Apr 28 12:07:14 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 28 Apr 2014 12:07:14 -0400 Subject: Significant digits in a float? In-Reply-To: References: Message-ID: On 4/28/14 12:00 PM, Roy Smith wrote: > Fundamentally, these numbers have between 0 and 4 decimal digits of precision, and I want to be able to intuit how many each has, ignoring the obvious floating point roundoff problems. Thus, I want to map: > > 38.0 ==> 0 > 41.2586 ==> 4 > 40.75280000000001 ==> 4 > 49.25 ==> 2 > 33.795199999999994 ==> 4 > 36.837199999999996 ==> 4 > 34.1489 ==> 4 > 45.5 ==> 1 > > Is there any clean way to do that? The best I've come up with so far is to str() them and parse the remaining string to see how many digits it put after the decimal point. That sounds like a pretty clean way: len(str(num).partition(".")[2]), though it also sounds like you understand all of the inaccuracies in that technique. -- Ned Batchelder, http://nedbatchelder.com From rosuav at gmail.com Mon Apr 28 12:28:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 29 Apr 2014 02:28:59 +1000 Subject: Significant digits in a float? In-Reply-To: References: Message-ID: On Tue, Apr 29, 2014 at 2:00 AM, Roy Smith wrote: > I have a bunch of floating point values. For example, here's a few (printed as reprs): > > 38.0 > 41.2586 > 40.75280000000001 > 49.25 > 33.795199999999994 > 36.837199999999996 > 34.1489 > 45.5 > > Fundamentally, these numbers have between 0 and 4 decimal digits of precision... Terminology question: Why do you count only what's after the decimal point? I would describe these as having between 2 and 6 significant figures. Will they always have two digits before the decimal, or does your precision really care only about what's after it? Of course, there would still remain the problem of describing 49.25 with 6 sig figs, in the same way that it's hard to explain to someone that you really do need to leave in five minutes (but if you said you had to leave in six minutes, they'd believe you to be accurate to the minute). But I assume that's not part of the question. ChrisA From tmcdon4ld at gmail.com Mon Apr 28 12:32:03 2014 From: tmcdon4ld at gmail.com (Timothy McDonald) Date: Mon, 28 Apr 2014 09:32:03 -0700 (PDT) Subject: Heartbleed and the windows distributions on python.org Message-ID: I am building a cherrypy app that is testing as vulnerable to the heartbleed exploit. The app is running on the 64 bit 3.3.5 Windows distribution of python. An updated version of 64 bit Python 3.3.x for Windows or an updated pyopenssl? I am kind of surprised the distribution on python.org hasen't been updated. Here is the thread on the issue from the cherrypy-users group. From roy at panix.com Mon Apr 28 14:31:49 2014 From: roy at panix.com (Roy Smith) Date: Mon, 28 Apr 2014 11:31:49 -0700 (PDT) Subject: Significant digits in a float? In-Reply-To: References: Message-ID: <3368085f-e841-4ba1-a37e-12bae8d58746@googlegroups.com> On Monday, April 28, 2014 12:28:59 PM UTC-4, Chris Angelico wrote: > Terminology question: Why do you count only what's after the decimal > point? I would describe these as having between 2 and 6 significant > figures. Will they always have two digits before the decimal, or does > your precision really care only about what's after it? Hmmm, yeah, I was being sloppy in my description. Definitely would have gotten points off in physics class for being so sloppy :-) No, there's not always two digits before the decimal. Could be anywhere from 0 to 3 digits before. What I'm really after is how many digits are after the decimal point. From roy at panix.com Mon Apr 28 14:39:30 2014 From: roy at panix.com (Roy Smith) Date: Mon, 28 Apr 2014 11:39:30 -0700 (PDT) Subject: Significant digits in a float? In-Reply-To: References: Message-ID: <238c9d43-9182-42f7-a4b4-4b73e4cf2a92@googlegroups.com> On Monday, April 28, 2014 12:07:14 PM UTC-4, Ned Batchelder wrote: > On 4/28/14 12:00 PM, Roy Smith wrote: >> 38.0 ==> 0 >> [...] >> Is there any clean way to do that? The best I've come up with so far is to str() them and parse the >> remaining string to see how many digits it put after the decimal point. > > That sounds like a pretty clean way: len(str(num).partition(".")[2]), > though it also sounds like you understand all of the inaccuracies in Well, it's actually, a little uglier, because I want to map 38.0 ==>0, so I need to special case that. The other annoying thing about using str() is its behavior isn't well defined. It looks like it does the right thing, but I imagine the details could change in a different implementation. From ned at nedbatchelder.com Mon Apr 28 15:00:38 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 28 Apr 2014 15:00:38 -0400 Subject: Significant digits in a float? In-Reply-To: <238c9d43-9182-42f7-a4b4-4b73e4cf2a92@googlegroups.com> References: <238c9d43-9182-42f7-a4b4-4b73e4cf2a92@googlegroups.com> Message-ID: On 4/28/14 2:39 PM, Roy Smith wrote: > On Monday, April 28, 2014 12:07:14 PM UTC-4, Ned Batchelder wrote: > >> On 4/28/14 12:00 PM, Roy Smith wrote: >>> 38.0 ==> 0 >>> [...] >>> Is there any clean way to do that? The best I've come up with so far is to str() them and parse the >>> remaining string to see how many digits it put after the decimal point. >> >> That sounds like a pretty clean way: len(str(num).partition(".")[2]), >> though it also sounds like you understand all of the inaccuracies in > > Well, it's actually, a little uglier, because I want to map 38.0 ==>0, so I need to special case that. Ah, right. > > The other annoying thing about using str() is its behavior isn't well defined. It looks like it does the right thing, but I imagine the details could change in a different implementation. > I don't have a reference, but in recent Pythons, str() was specifically changed to guarantee that it produces the shortest string that when re-interpreted as a float, produces the same float. -- Ned Batchelder, http://nedbatchelder.com From davea at davea.name Mon Apr 28 15:09:15 2014 From: davea at davea.name (Dave Angel) Date: Mon, 28 Apr 2014 15:09:15 -0400 (EDT) Subject: Significant digits in a float? References: Message-ID: Roy Smith Wrote in message: > I'm using Python 2.7 > > I have a bunch of floating point values. For example, here's a few (printed as reprs): > > 38.0 > 41.2586 > 40.75280000000001 > 49.25 > 33.795199999999994 > 36.837199999999996 > 34.1489 > 45.5 > > Fundamentally, these numbers have between 0 and 4 decimal digits of precision, and I want to be able to intuit how many each has, ignoring the obvious floating point roundoff problems. Thus, I want to map: > > 38.0 ==> 0 > 41.2586 ==> 4 > 40.75280000000001 ==> 4 > 49.25 ==> 2 > 33.795199999999994 ==> 4 > 36.837199999999996 ==> 4 > 34.1489 ==> 4 > 45.5 ==> 1 > > Is there any clean way to do that? The best I've come up with so far is to str() them and parse the remaining string to see how many digits it put after the decimal point. > > The numbers are given to me as Python floats; I have no control over that. I'm willing to accept that fact that I won't be able to differentiate between float("38.0") and float("38.0000"). Both of those map to 1, which is OK for my purposes. > Ignoring the unexpected terminology, you seem to be looking for the number of decimal places, and you're not interested in 2100 ==> -2 If you know something about the possible range of the numbers, and/or you know the valid range of decimal places, then you should convert to string in a way that will round the 3rd, 5th, and 6th values. Then if the string has no decimal, the answer is 0. If there are any trailing zeroes, strip them. Then just count digits after the decimal point. Without such limits, there can be no unique algorithm, and thus no correct code. -- DaveA From davea at davea.name Mon Apr 28 15:19:13 2014 From: davea at davea.name (Dave Angel) Date: Mon, 28 Apr 2014 15:19:13 -0400 (EDT) Subject: Convert numpy array to single number References: <088cdf75-f196-404b-ba77-567559f431d8@googlegroups.com> Message-ID: mboyd02255 at gmail.com Wrote in message: > I have a numpy array consisting of 1s and zeros for representing binary numbers: > > e.g. > > >>> binary > array([ 1., 0., 1., 0.]) > > I wish the array to be in the form 1010, so it can be manipulated. > > I do not want to use built in binary converters as I am trying to build my own. > One thousand and ten is an int, not an array. So is 10, but it seems a more likely value you might be trying for. As for using the builtin binary converters, you'd better be a lot more specific, as you cannot even print an int in decimal form without utilizing them. The number is in binary already. Please copy the exact problem and constraints, as well as what you've written so far and what's wrong with it. -- DaveA From nad at acm.org Mon Apr 28 15:15:10 2014 From: nad at acm.org (Ned Deily) Date: Mon, 28 Apr 2014 12:15:10 -0700 Subject: Heartbleed and the windows distributions on python.org References: Message-ID: In article , Timothy McDonald wrote: > I am building a cherrypy app that is testing as vulnerable to the heartbleed > exploit. The app is running on the 64 bit 3.3.5 Windows distribution of > python. An updated version of 64 bit Python 3.3.x for Windows or an updated > pyopenssl? I am kind of surprised the distribution on python.org hasen't been > updated. The current release of Python 3 is 3.4.0. A 3.4.1 maintenance release, with OpenSSL updated in the Windows installer, is planned for final release in mid-May. Python 3.3.x is now in security-fix-only mode which means only source fixes for security problems are released as needed and no further binary installers for Windows or OS X are produced. (The Python 2 Windows installer is not affected since it bundles an older, pre-heartbleed version of OpenSSL.) -- Ned Deily, nad at acm.org From davea at davea.name Mon Apr 28 15:33:46 2014 From: davea at davea.name (Dave Angel) Date: Mon, 28 Apr 2014 15:33:46 -0400 (EDT) Subject: problem with regex References: Message-ID: dimmaim at gmail.com Wrote in message: > i want to find a specific urls from a txt file but i have some issus. First when i take just two lines from the file with copy paste and assign it to a variable like this and it works only with triple quotes > > test='''_*_n.jpg","timelineCoverPhoto":"{\"focus\":{\"x\":0.5,\"y\":0.386925795053},\"photo\":{\"__type__\":{\"name\":\"Photo\"},\"image_lowres\":{\"uri\":\"https://fbcdn-photos-f-a.akamaihd.net/*-*-* Why did you start a second thread with similar content two minutes after the first? Do you expect us to compare the two messages and figure out what you changed, or were you just impatient for a response? I only check in here about 6 times a day, and I imagine some might be even less often. Your test string literal has lots of backslashes in it, which get interpreted into escape sequences in a literal, but not in a file. If that's really what the file looks like, you're going to want to use a raw string. I agree with Roy, you're probably not getting the same string the two ways. -- DaveA From ned at nedbatchelder.com Mon Apr 28 15:35:54 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 28 Apr 2014 15:35:54 -0400 Subject: Help with changes in traceback stack from Python 2.7 to Python 3.x In-Reply-To: <06134705-e2b1-4a2f-adb6-bec4faa96e83@me.com> References: <06134705-e2b1-4a2f-adb6-bec4faa96e83@me.com> Message-ID: On 4/27/14 5:51 PM, Andrew Konstantaras wrote: > I guess I am missing something big as I am looking for a shorthand way > of doing the following: > > dctA = dict(x=x, y=y, ... n=n) > Yes, your makeDict(x, y) is a shorthand for dict(x=x, y=y), but there are many things you can do with dict that you can't do with makeDict. What is the makeDict equivalent of: dict(x=12, y=self.y, z=a+b) The code you have allows you more compact expression, but it brings fragility and surprise. > This is, as I understand it a very natural way of using a dictionary. > It seems that this syntax is unnecessarily redundant and hence my goal > of writing something more compact. Perhaps the way I am doing it is a > little unorthodox, but the ultimate use of a dictionary is, as I > understand it, completely in line with how dictionaries were designed to > be used. In my other code, I often use these dictionaries to pass > arguments to functions and return results. It allows me great > flexibility without breaking existing code. I pack a dictionary before > passing and unpack when retrieving. Perhaps you want to create a class instead? If you find yourself passing more than a handful of arguments to a function, and especially more than a handful of values returned from a function, then a class with methods might be a better way to combine state and behavior. Also, keep in mind that you can return a tuple from a function if you want to return two or three values and assign them to names: x, y, z = compute_xyz() You mention unpacking your dictionary after the function call. How do you do that? Isn't that a cumbersome and repetitive operation? > > I will give the locals approach a try, it seems a little more clumsy > than simply passing the variables to the function. > > Thanks again for your input. > > ---Andrew BTW, it's a little easier to follow the threads of conversation if you put your responses after the text you are responding to. This is known as bottom-posting, and is preferred to top-posting as you did here. -- Ned Batchelder, http://nedbatchelder.com From akonsta at icloud.com Mon Apr 28 15:50:05 2014 From: akonsta at icloud.com (Andrew Konstantaras) Date: Mon, 28 Apr 2014 19:50:05 +0000 (GMT) Subject: Help with changes in traceback stack from Python 2.7 to Python 3.x In-Reply-To: Message-ID: <5f1efb2f-9b35-44bb-b9fc-ae03777a595a@me.com> On Apr 28, 2014, at 12:36 PM, Ned Batchelder wrote: > On 4/27/14 5:51 PM, Andrew Konstantaras wrote: > > I guess I am missing something big as I am looking for a shorthand way > > of doing the following: > > > > dctA = dict(x=x, y=y, ... n=n) > > > > Yes, your makeDict(x, y) is a shorthand for dict(x=x, y=y), but there > are many things you can do with dict that you can't do with makeDict. > What is the makeDict equivalent of: > > dict(x=12, y=self.y, z=a+b) > > The code you have allows you more compact expression, but it brings > fragility and surprise. > > > This is, as I understand it a very natural way of using a dictionary. > > It seems that this syntax is unnecessarily redundant and hence my goal > > of writing something more compact. Perhaps the way I am doing it is a > > little unorthodox, but the ultimate use of a dictionary is, as I > > understand it, completely in line with how dictionaries were designed to > > be used. In my other code, I often use these dictionaries to pass > > arguments to functions and return results. It allows me great > > flexibility without breaking existing code. I pack a dictionary before > > passing and unpack when retrieving. > > Perhaps you want to create a class instead? If you find yourself > passing more than a handful of arguments to a function, and especially > more than a handful of values returned from a function, then a class > with methods might be a better way to combine state and behavior. > > Also, keep in mind that you can return a tuple from a function if you > want to return two or three values and assign them to names: > > x, y, z = compute_xyz() > > You mention unpacking your dictionary after the function call. How do > you do that? Isn't that a cumbersome and repetitive operation? One of the reasons I like using the dictionary over the tuple is that if I have a function that grows in functionality (i.e., I decide to return more data for new scenarios), I can just add the new object to the dictionary and I don't have to worry about changing the code every where else that used to call the function. Actually, that is one of the nice features of using a dictionary, I can check if the key is there and if it is pull it out. As I was dusting off this old code, I considered trying to implement this functionality through by creating a class. I never liked going through the stack, it seemed hacky, but I came to love using dictionaries as they have some great built in features. Again, thanks for the advice and I will focus on the class implementation. ? > > > > > I will give the locals approach a try, it seems a little more clumsy > > than simply passing the variables to the function. > > > > Thanks again for your input. > > > > ---Andrew > > BTW, it's a little easier to follow the threads of conversation if you > put your responses after the text you are responding to. This is known > as bottom-posting, and is preferred to top-posting as you did here. > > > -- > Ned Batchelder, http://nedbatchelder.com > > -- > https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Apr 28 17:11:29 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 28 Apr 2014 17:11:29 -0400 Subject: Sorting list alphabetically In-Reply-To: References: Message-ID: On 4/28/2014 2:33 AM, Kev Dwyer wrote: > Hello Terry, > > Regarding your second point, my mistake in not checking the link: > I'd seen a similar one elsewhere and assumed they were the same. > > This link should work: > http://msdn.microsoft.com/en-us/library/hzz3tw78 > > > As to your first point, you're right, it seems setlocale(locale.LC_ALL, > 'en_US.UTF-8') doesn't work on Windows. From what I read of the link above and http://msdn.microsoft.com/en-US/goglobal/bb896001.aspx given therein, I am going to guess that .UTF-8 is not supported for any language. > It seems the locale name needs to be one of the aliases provided > at http://msdn.microsoft.com/en-us/library/39cwe7zf, so for example > locale.setlocale(locale.LC_ALL, 'usa') returns > 'English_United States.1252'. > > Do you know if this is something people programming on Windows > should just be aware of, or is there a case for a hint of some > kind in the locale module documentation? *Definitely the latter. Perhaps you could open an issue with a specific suggestion. -- Terry Jan Reedy From burak.arslan at arskom.com.tr Mon Apr 28 17:14:45 2014 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Tue, 29 Apr 2014 00:14:45 +0300 Subject: Soap list and soap users on this list In-Reply-To: References: <2966d22f950544d3a70d68d7c84010f0@exch.activenetwerx.com>, Message-ID: <535EC4C5.6000906@arskom.com.tr> Hi Joseph, Sorry for the late response, I seem to have missed this post. On 04/17/14 21:34, Joseph L. Casale wrote: > I've been looking at Spyne to produce a service that > can accept a request formatted as follows: > > > > > > > > > > > https://gist.github.com/plq/11384113 Unfortunately, you need the latest Spyne from https://github.com/arskom/spyne, this doesn't work with 2.10 2.11 is due around end of may, beginning of june. Ping back if you got any other questions. Best, Burak From jcasale at activenetwerx.com Mon Apr 28 17:59:12 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Mon, 28 Apr 2014 21:59:12 +0000 Subject: Soap list and soap users on this list In-Reply-To: <535EC4C5.6000906@arskom.com.tr> References: <2966d22f950544d3a70d68d7c84010f0@exch.activenetwerx.com>, , <535EC4C5.6000906@arskom.com.tr> Message-ID: > https://gist.github.com/plq/11384113 > > Unfortunately, you need the latest Spyne from > https://github.com/arskom/spyne, this doesn't work with 2.10 > > 2.11 is due around end of may, beginning of june. > > Ping back if you got any other questions. Burak, Thanks a ton! I've just pulled this down and started working through it. Much appreciated! jlc From rosuav at gmail.com Mon Apr 28 18:41:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 29 Apr 2014 08:41:30 +1000 Subject: Help with changes in traceback stack from Python 2.7 to Python 3.x In-Reply-To: <5f1efb2f-9b35-44bb-b9fc-ae03777a595a@me.com> References: <5f1efb2f-9b35-44bb-b9fc-ae03777a595a@me.com> Message-ID: On Tue, Apr 29, 2014 at 5:50 AM, Andrew Konstantaras wrote: > Actually, that is one of the nice features of using a dictionary, I can > check if the key is there and if it is pull it out. As I was dusting off > this old code, I considered trying to implement this functionality through > by creating a class. I never liked going through the stack, it seemed > hacky, but I came to love using dictionaries as they have some great built > in features. In that case, consider using function named arguments. You can simply list a whole lot of args with defaults, and then provide values for the exact ones you want: def f(a=1, b=2, c=3, d=4, e=5): print("My args are",a,b,c,d,e) f() # all defaults, like an empty dict f(d=123) # all defaults but one f(10,20,e=7) # specify the early ones positionally if you always pass those This is a really REALLY handy feature. ChrisA From matt.pounsett at gmail.com Mon Apr 28 18:50:27 2014 From: matt.pounsett at gmail.com (Matthew Pounsett) Date: Mon, 28 Apr 2014 15:50:27 -0700 (PDT) Subject: MacOS 10.9.2: threading error using python.org 2.7.6 distribution In-Reply-To: References: <675725e3-38d2-4d81-bf64-f6d903d4a684@googlegroups.com> Message-ID: On Sunday, 27 April 2014 10:33:38 UTC-4, Chris Angelico wrote: > In most contexts, "thread unsafe" simply means that you can't use the > same facilities simultaneously from two threads (eg a lot of database > connection libraries are thread unsafe with regard to a single > connection, as they'll simply write to a pipe or socket and then read > a response from it). But processes and threads are, on many systems, > linked. Just the act of spinning off a new thread and then forking can > potentially cause problems. Those are the exact sorts of issues that > you'll see when you switch OSes, as it's the underlying thread/process > model that's significant. (Particularly of note is that Windows is > *very* different from Unix-based systems, in that subprocess > management is not done by forking. But not applicable here.) > Thanks, I'll keep all that in mind. I have to wonder how much of a problem it is here though, since I was able to demonstrate a functioning fork inside a new thread further up in the discussion. I have a new development that I find interesting, and I'm wondering if you still think it's the same problem. I have taken that threading object and turned it into a normal function definition. It's still forking the external tool, but it's doing so in the main thread, and it is finished execution before any other threads are created. And I'm still getting the same error. Turns out it's not coming from the threading module, but from the subprocess module instead. Specifically, like 709 of /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py which is this: try: self._execute_child(args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite) except Exception: I get the "Warning: No stack to get attribute from" twice when that self._execute_child() call is made. I've tried stepping into it to narrow it down further, but I'm getting weird behaviour from the debugger that I've never seen before once I do that. It's making it hard to track down exactly where the error is occurring. Interestingly, it's not actually raising an exception there. The except block is not being run. From rosuav at gmail.com Mon Apr 28 19:00:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 29 Apr 2014 09:00:31 +1000 Subject: MacOS 10.9.2: threading error using python.org 2.7.6 distribution In-Reply-To: References: <675725e3-38d2-4d81-bf64-f6d903d4a684@googlegroups.com> Message-ID: On Tue, Apr 29, 2014 at 8:50 AM, Matthew Pounsett wrote: > Thanks, I'll keep all that in mind. I have to wonder how much of a problem it is here though, since I was able to demonstrate a functioning fork inside a new thread further up in the discussion. > Yeah, it's really hard to pin down sometimes. I once discovered a problem whereby I was unable to spin off subprocesses that did certain things, but I could do a trivial subprocess (I think I fork/exec'd to the echo command or something) and that worked fine. Turned out to be a bug in one of my signal handlers, but the error was being reported at the point of the forking. > I have a new development that I find interesting, and I'm wondering if you still think it's the same problem. > > I have taken that threading object and turned it into a normal function definition. It's still forking the external tool, but it's doing so in the main thread, and it is finished execution before any other threads are created. And I'm still getting the same error. > Interesting. That ought to eliminate all possibility of thread-vs-process issues. Can you post the smallest piece of code that exhibits the same failure? ChrisA From greg.ewing at canterbury.ac.nz Mon Apr 28 20:08:49 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 29 Apr 2014 12:08:49 +1200 Subject: Inconsistent viewkeys behaviour In-Reply-To: References: Message-ID: Terry Reedy wrote: > The left operand determines the result. The manual specifies that < and > > do not have to be consistent. But I suspect that when 3.x dict.keys() > was backported to 2.7.0, no one thought to update set, whereas the > backported key view code already had the comparison. The question is why set() is raising an exception instead of returning NotImplemented to give the other operand a chance. -- Greg From steve+comp.lang.python at pearwood.info Mon Apr 28 22:34:07 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Apr 2014 02:34:07 GMT Subject: Significant digits in a float? References: Message-ID: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> On Mon, 28 Apr 2014 12:00:23 -0400, Roy Smith wrote: [...] > Fundamentally, these numbers have between 0 and 4 decimal digits of > precision, I'm surprised that you have a source of data with variable precision, especially one that varies by a factor of TEN THOUSAND. The difference between 0 and 4 decimal digits is equivalent to measuring some lengths to the nearest metre, some to the nearest centimetre, and some to the nearest 0.1 of a millimetre. That's very unusual and I don't know what justification you have for combining such a mix of data sources. One possible interpretation of your post is that you have a source of floats, where all the numbers are actually measured to the same precision, and you've simply misinterpreted the fact that some of them look like they have less precision. Since you indicate that 4 decimal digits is the maximum, I'm going with 4 decimal digits. So if your data includes the float 23.5, that's 23.5 measured to a precision of four decimal places (that is, it's 23.5000, not 23.5001 or 23.4999). On the other hand, if you're getting your values as *strings*, that's another story. If you can trust the strings, they'll tell you how many decimal places: "23.5" is only one decimal place, "23.5000" is four. But then what to make of your later example? > 40.75280000000001 ==> 4 Python floats (C doubles) are quite capable of distinguishing between 40.7528 and 40.75280000000001. They are distinct numbers: py> 40.75280000000001 - 40.7528 7.105427357601002e-15 so if a number is recorded as 40.75280000000001 presumably it is because it was measured as 40.75280000000001. (How that precision can be justified, I don't know! Does it come from the Large Hadron Collider?) If it were intended to be 40.7528, I expect it would have be recorded as 40.7528. What reason do you have to think that something recorded to 14 decimal places was only intended to have been recorded to 4? Without knowing more about how your data is generated, I can't advise you much, but the whole scenario as you have described it makes me think that *somebody* is doing something wrong. Perhaps you need to explain why you're doing this, as it seems numerically broken. > Is there any clean way to do that? The best I've come up with so far is > to str() them and parse the remaining string to see how many digits it > put after the decimal point. I really think you need to go back to the source. Trying to infer the precision of the measurements from the accident of the string formatting seems pretty dubious to me. But I suppose if you wanted to infer the number of digits after the decimal place, excluding trailing zeroes (why, I do not understand), up to a maximum of four digits, then you could do: s = "%.4f" % number # rounds to four decimal places s = s.rstrip("0") # ignore trailing zeroes, whether significant or not count = len(s.split(".")[1]) Assuming all the numbers fit in the range where they are shown in non- exponential format. If you have to handle numbers like 1.23e19 as well, you'll have to parse the string more carefully. (Keep in mind that most floats above a certain size are all integer-valued.) > The numbers are given to me as Python floats; I have no control over > that. If that's the case, what makes you think that two floats from the same data set were measured to different precision? Given that you don't see strings, only floats, I would say that your problem is unsolvable. Whether I measure something to one decimal place and get 23.5, or four decimal places and get 23.5000, the float you see will be the same. Perhaps you ought to be using Decimal rather than float. Floats have a fixed precision, while Decimals can be configured. Then the right way to answer your question is to inspect the number: py> from decimal import Decimal as D py> x = D("23.5000") py> x.as_tuple() DecimalTuple(sign=0, digits=(2, 3, 5, 0, 0, 0), exponent=-4) The number of decimal digits precision is -exponent. > I'm willing to accept that fact that I won't be able to differentiate > between float("38.0") and float("38.0000"). Both of those map to 1, > which is OK for my purposes. That seems... well, "bizarre and wrong" are the only words that come to mind. If I were recording data as "38.0000" and you told me I had measured it to only one decimal place accuracy, I wouldn't be too pleased. Maybe if I understood the context better? How about 38.12 and 38.1200? By the way, you contradict yourself here. Earlier, you described 38.0 as having zero decimal places (which is wrong). Here you describe it as having one, which is correct, and then in a later post you describe it as having zero decimal places again. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ben at benfinney.id.au Mon Apr 28 23:23:07 2014 From: ben at benfinney.id.au (Ben Finney) Date: Tue, 29 Apr 2014 13:23:07 +1000 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85ppk0keec.fsf@benfinney.id.au> Steven D'Aprano writes: > By the way, you contradict yourself here. Earlier, you described 38.0 as > having zero decimal places (which is wrong). Here you describe it as > having one, which is correct, and then in a later post you describe it as > having zero decimal places again. I get the impression that this is at the core of the misunderstanding. Having a number's representation ending in ??.0? does not mean zero decimal places; it has exactly one. The value's representation contains the digit ?0? after the decimal point, but that digit is significant to the precision of the representation. If the problem could be stated such that ?38.0? and ?38? and ?38.000? are consistently described with the correct number of decimal digits of precision (in those examples: one, zero, and three), maybe the discussion would make more sense. -- \ ?Men never do evil so completely and cheerfully as when they do | `\ it from religious conviction.? ?Blaise Pascal (1623?1662), | _o__) Pens?es, #894. | Ben Finney From steve at pearwood.info Tue Apr 29 01:43:19 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 29 Apr 2014 05:43:19 GMT Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <535f3bf7$0$11109$c3e8da3@news.astraweb.com> On Tue, 29 Apr 2014 13:23:07 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> By the way, you contradict yourself here. Earlier, you described 38.0 >> as having zero decimal places (which is wrong). Here you describe it as >> having one, which is correct, and then in a later post you describe it >> as having zero decimal places again. > > I get the impression that this is at the core of the misunderstanding. > Having a number's representation ending in ??.0? does not mean zero > decimal places; it has exactly one. The value's representation contains > the digit ?0? after the decimal point, but that digit is significant to > the precision of the representation. > > If the problem could be stated such that ?38.0? and ?38? and ?38.000? > are consistently described with the correct number of decimal digits of > precision (in those examples: one, zero, and three), maybe the > discussion would make more sense. It's actually trickier than that. Digits of precision can refer to measurement error, or to the underlying storage type. Python floats are C doubles, so they have 64 bits of precision (approximately 17 decimal digits, if I remember correctly) regardless of the precision of the measurement. The OP (Roy) is, I think, trying to guess the measurement precision after the fact, given a float. If the measurement error really does differ from value to value, I don't think he'll have much luck: given a float like 23.0, all we can say is that it has *at least* zero significant decimal places. 23.1 has at least one, 23.1111 has at least four. If you can put an upper bound on the precision, as Roy indicates he can, then perhaps a reasonable approach is to convert to a string rounded to four decimal places, then strip trailing zeroes: py> x = 1234.1 # actual internal is closer to 1234.099999999999909 py> ("%.4f" % x).rstrip('0') '1234.1' then count the number of digits after the dot. (This assumes that the string formatting routines are correctly rounded, which they should be on *most* platforms.) But again, this only gives a lower bound to the number of significant digits -- it's at least one, but might be more. -- Steven From kevin.p.dwyer at gmail.com Tue Apr 29 02:02:43 2014 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Tue, 29 Apr 2014 07:02:43 +0100 Subject: Sorting list alphabetically References: Message-ID: Terry Reedy wrote: > On 4/28/2014 2:33 AM, Kev Dwyer wrote: > >> Hello Terry, >> >> Regarding your second point, my mistake in not checking the link: >> I'd seen a similar one elsewhere and assumed they were the same. >> >> This link should work: >> http://msdn.microsoft.com/en-us/library/hzz3tw78 >> >> >> As to your first point, you're right, it seems setlocale(locale.LC_ALL, >> 'en_US.UTF-8') doesn't work on Windows. > > From what I read of the link above and > http://msdn.microsoft.com/en-US/goglobal/bb896001.aspx > given therein, I am going to guess that .UTF-8 is not supported for any > language. > >> It seems the locale name needs to be one of the aliases provided >> at http://msdn.microsoft.com/en-us/library/39cwe7zf, so for example >> locale.setlocale(locale.LC_ALL, 'usa') returns >> 'English_United States.1252'. >> >> Do you know if this is something people programming on Windows >> should just be aware of, or is there a case for a hint of some >> kind in the locale module documentation? > > *Definitely the latter. Perhaps you could open an issue with a specific > suggestion. > Thanks! I'll try to write something up this weekend. From wxjmfauth at gmail.com Tue Apr 29 04:31:52 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 29 Apr 2014 01:31:52 -0700 (PDT) Subject: [bugs] Last week... Message-ID: <477157e9-2c36-477b-90b7-a2bd265969c8@googlegroups.com> Last week I found three "bugs" related to the coding of characters / unicode (Py 3). Bugs, that are making impossible to write safe code when manipulating text/strings as Python is supposed to do. Safe code == not broken, nothing to do with a "regression". jmf From nad at acm.org Tue Apr 29 04:57:41 2014 From: nad at acm.org (Ned Deily) Date: Tue, 29 Apr 2014 01:57:41 -0700 Subject: [bugs] Last week... References: <477157e9-2c36-477b-90b7-a2bd265969c8@googlegroups.com> Message-ID: In article <477157e9-2c36-477b-90b7-a2bd265969c8 at googlegroups.com>, wxjmfauth at gmail.com wrote: > Last week I found three "bugs" related to the coding of > characters / unicode (Py 3). > > Bugs, that are making impossible to write safe code > when manipulating text/strings as Python is supposed > to do. If you believe you have found unreported bugs in Python, please open issues for them on the Python bug tracker: http://bugs.python.org Mentioning them here with no details helps no one. -- Ned Deily, nad at acm.org From ned at nedbatchelder.com Tue Apr 29 06:31:02 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 29 Apr 2014 06:31:02 -0400 Subject: [bugs] Last week... In-Reply-To: References: <477157e9-2c36-477b-90b7-a2bd265969c8@googlegroups.com> Message-ID: On 4/29/14 4:57 AM, Ned Deily wrote: > In article <477157e9-2c36-477b-90b7-a2bd265969c8 at googlegroups.com>, > wxjmfauth at gmail.com wrote: >> Last week I found three "bugs" related to the coding of >> characters / unicode (Py 3). >> >> Bugs, that are making impossible to write safe code >> when manipulating text/strings as Python is supposed >> to do. > > If you believe you have found unreported bugs in Python, please open > issues for them on the Python bug tracker: > > http://bugs.python.org > > Mentioning them here with no details helps no one. > Once you've created the issues in the bug tracker, post the links here. I know some of us will be interested to follow their progress. We all want to see Python be the best it can be. -- Ned Batchelder, http://nedbatchelder.com From rustompmody at gmail.com Tue Apr 29 07:14:48 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 29 Apr 2014 04:14:48 -0700 (PDT) Subject: Cant type unicode with compose anymore Message-ID: <5ddd865f-043b-4b04-85b1-ecb0d03fc40d@googlegroups.com> For some time now I have this in my X startup programs: $ setxkbmap -option compose:menu After this I can type (in mostly any window) for example: (with MN being the windows-menu key) MN.. gives ... ie an ellipses MN--. gives - ie an en dash MN--- gives -- ie an em dash Not to mention all the e" giving ? etc etc - all the goodies at /usr/share/X11/locale/$LANG/Compose Now suddenly its stopped working. ie it works in most other X apps but not in emacs I thought there may be a race-condition between the setxkb and emacs which are both in my startup programs. So I ran the setxkb command by hand from a shell and (re)started emacs from the shell No luck: The compose works outside emacs Doesn't work inside Any clues? Its the same for emacs 23 and 24 From rustompmody at gmail.com Tue Apr 29 07:15:41 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 29 Apr 2014 04:15:41 -0700 (PDT) Subject: Cant type unicode with compose anymore In-Reply-To: <5ddd865f-043b-4b04-85b1-ecb0d03fc40d@googlegroups.com> References: <5ddd865f-043b-4b04-85b1-ecb0d03fc40d@googlegroups.com> Message-ID: On Tuesday, April 29, 2014 4:44:48 PM UTC+5:30, Rustom Mody wrote: > > Any clues? > > > Its the same for emacs 23 and 24 Whoops! Wrong list :-) From rustompmody at gmail.com Tue Apr 29 07:18:51 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 29 Apr 2014 04:18:51 -0700 (PDT) Subject: Cant type unicode with compose anymore Message-ID: <7989c46d-eb49-4b3a-a560-dd05b140b087@googlegroups.com> For some time now I have this in my X startup programs: $ setxkbmap -option compose:menu After this I can type (in mostly any window) for example: (with MN being the windows-menu key) MN.. gives ... ie an ellipses MN--. gives - ie an en dash MN--- gives -- ie an em dash Not to mention all the e" giving ? etc etc - all the unicode goodies at /usr/share/X11/locale/$LANG/Compose Now suddenly its stopped working. ie it works in most other X apps but not in emacs I thought there may be a race-condition between the setxkb and emacs which are both in my startup programs. So I ran the setxkb command by hand from a shell and (re)started emacs from the shell No luck: The compose works outside emacs Doesn't work inside Any clues? Its the same for emacs 23 and 24 From rustompmody at gmail.com Tue Apr 29 07:28:03 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 29 Apr 2014 04:28:03 -0700 (PDT) Subject: Cant type unicode with compose anymore In-Reply-To: <7989c46d-eb49-4b3a-a560-dd05b140b087@googlegroups.com> References: <7989c46d-eb49-4b3a-a560-dd05b140b087@googlegroups.com> Message-ID: <535b2ff9-e89f-448a-917d-0915f9bbe471@googlegroups.com> On Tuesday, April 29, 2014 4:48:51 PM UTC+5:30, Rustom Mody wrote: Ive done it a second time !?! Probably related to the temp being a cool > 40 ?C From roy at panix.com Tue Apr 29 09:38:33 2014 From: roy at panix.com (Roy Smith) Date: Tue, 29 Apr 2014 09:38:33 -0400 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <535f0f9f$0$29965$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Mon, 28 Apr 2014 12:00:23 -0400, Roy Smith wrote: > > [...] > > Fundamentally, these numbers have between 0 and 4 decimal digits of > > precision, > > I'm surprised that you have a source of data with variable precision, > especially one that varies by a factor of TEN THOUSAND. OK, you're surprised. > I don't know what justification you have for combining such a > mix of data sources. Because that's the data that was given to me. Real life data is messy. > One possible interpretation of your post is that you have a source of > floats, where all the numbers are actually measured to the same > precision, and you've simply misinterpreted the fact that some of them > look like they have less precision. Another possibility is that they're latitude/longitude coordinates, some of which are given to the whole degree, some of which are given to greater precision, all the way down to the ten-thousandth of a degree. > What reason do you have to think that something recorded to 14 > decimal places was only intended to have been recorded to 4? Because I understand the physical measurement these numbers represent. Sometimes, Steve, you have to assume that when somebody asks a question, they actually have asked the question then intended to ask. > Perhaps you need to explain why you're doing this, as it seems > numerically broken. These are latitude and longitude coordinates of locations. Some locations are known to a specific street address. Some are known to a city. Some are only known to the country. So, for example, the 38.0 value represents the latitude, to the nearest whole degree, of the geographic center of the contiguous United States. > I really think you need to go back to the source. Trying to infer the > precision of the measurements from the accident of the string formatting > seems pretty dubious to me. Sure it is. But, like I said, real-life data is messy. You can wring your hands and say, "this data sucks, I can't use it", or you can figure out some way to deal with it. Which is the whole point of my post. The best I've come up with is inferring something from the string formatting and I'm hoping there might be something better I might do. > But I suppose if you wanted to infer the number of digits after the > decimal place, excluding trailing zeroes (why, I do not understand), up > to a maximum of four digits, then you could do: > > s = "%.4f" % number # rounds to four decimal places > s = s.rstrip("0") # ignore trailing zeroes, whether significant or not > count = len(s.split(".")[1]) This at least seems a little more robust than just calling str(). Thank you :-) > Assuming all the numbers fit in the range where they are shown in non- > exponential format. They're latitude/longitude, so they all fall into [-180, 180]. > Perhaps you ought to be using Decimal rather than float. Like I said, "The numbers are given to me as Python floats; I have no control over that". > > I'm willing to accept that fact that I won't be able to differentiate > > between float("38.0") and float("38.0000"). Both of those map to 1, > > which is OK for my purposes. > > That seems... well, "bizarre and wrong" are the only words that come to > mind. I'm trying to intuit, from the values I've been given, which coordinates are likely to be accurate to within a few miles. I'm willing to accept a few false negatives. If the number is float("38"), I'm willing to accept that it might actually be float("38.0000"), and I might be throwing out a good data point that I don't need to. For the purpose I'm using the data for, excluding the occasional good data point won't hurt me. Including the occasional bad one, will. > By the way, you contradict yourself here. Earlier, you described 38.0 as > having zero decimal places (which is wrong). Here you describe it as > having one, which is correct, and then in a later post you describe it as > having zero decimal places again. I was sloppy there. I was copy-pasting data from my program output. Observe: >>> print float("38") 38.0 In standard engineering parlance, the string "38" represents a number with a precision of +/- 1 unit. Unfortunately, Python's default str() representation turns this into "38.0", which implies +/- 0.1 unit. Floats represented as strings (at least in some disciplines, such as engineering) include more information than just the value. By the number of trailing zeros, they also include information about the precision of the measurement. That information is lost when the string is converted to a IEEE float. I'm trying to intuit that information back, and as I mentioned earlier, am willing to accept that the intuiting process will be imperfect. There is real-life value in imperfect processes. From werotizy at freent.dd Tue Apr 29 11:42:17 2014 From: werotizy at freent.dd (Tom P) Date: Tue, 29 Apr 2014 17:42:17 +0200 Subject: Convert numpy array to single number In-Reply-To: <088cdf75-f196-404b-ba77-567559f431d8@googlegroups.com> References: <088cdf75-f196-404b-ba77-567559f431d8@googlegroups.com> Message-ID: On 28.04.2014 15:04, mboyd02255 at gmail.com wrote: > I have a numpy array consisting of 1s and zeros for representing binary numbers: > > e.g. > > >>> binary > array([ 1., 0., 1., 0.]) > > I wish the array to be in the form 1010, so it can be manipulated. > > I do not want to use built in binary converters as I am trying to build my own. > Do you mean that each element in the array represents a power of two? So array([ 1., 0., 1., 0.]) represents 2^3 + 2 = 6 decimal? From webe3vt at aim.com Tue Apr 29 11:28:30 2014 From: webe3vt at aim.com (Brent S. Elmer Ph.D.) Date: Tue, 29 Apr 2014 11:28:30 -0400 Subject: how to build and install multiple micro-level major.minor versions of Python Message-ID: <1398785310.2673.16.camel@belmer> I have built and installed Python on AIX as well as installed a stack of Python tools. The version I installed is 2.7.2. Everything is working fine but I want to install Python 2.7.6 and the tool stack. Before I installed 2.7.2, I installed 2.6.x. I was able to install the 2.7.2 and 2.6.x side by side because they have different minor numbers. This allowed me to be able to thoroughly test 2.7.2 before pointing the link for python to it. Now however, I can't see an easy way to install 2.7.6 beside the 2.7.2 since by default, Python installs only to the minor number so if I install 2.7.6, it will overwrite 2.7.2 since they will both install to 2.7. I have tried editing the configuration files configure.ac and configure to set VERSION, PYTHON_VERSION, and PACKAGE_VERSION to 2.7.6. This actually seemed to work fine so I ended up with 2.7.6 installed beside 2.7. However, when I tried to install other python packages using a command like: python2.7.6 setup.py install the python2.7.6 binary was used for the install but the setup wrote the package library to .../lib/python2.7 not .../lib/python2.7.6. I thought maybe it had something to do with bin/python-config pointing to bin/python-config2.7, so I pointed python-config to python-config2.7.6 but that didn't help. Is there a way to do what I want to do (i.e. install 2.7.6 beside 2.7)? From robin at reportlab.com Tue Apr 29 12:17:10 2014 From: robin at reportlab.com (Robin Becker) Date: Tue, 29 Apr 2014 17:17:10 +0100 Subject: where to put global testing value Message-ID: <535FD086.7000003@chamonix.reportlab.co.uk> A user complains that under AppEngine I'm not allowed to import __main__. I can fix this issue merely by putting a try block around the offending import which is only used like this import __main__ testing = getattr(__main__,'_rl_testing',False) del __main__ this is only used as a hack way, during testing, to modify the behaviour of the importing module (a proxy for a C extension). During testing we keep both the C version and the supposed replacement of various functions so they can be tested against each other https://bitbucket.org/rptlab/reportlab/src/default/src/reportlab/lib/rl_accel.py Is there a more reasonable way to allow changes to module level globals before the import takes place? I guess since this module is supposed only to be imported by reportlab we can put this sort of thing onto the reportlab module itself, but that could possibly lead to import loops. Any ideas? -- Robin Becker From vlastimil.brom at gmail.com Tue Apr 29 12:18:20 2014 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 29 Apr 2014 18:18:20 +0200 Subject: Significant digits in a float? In-Reply-To: References: Message-ID: 2014-04-28 18:00 GMT+02:00 Roy Smith : > I'm using Python 2.7 > > I have a bunch of floating point values. For example, here's a few (printed as reprs): > > 38.0 > 41.2586 > 40.75280000000001 > 49.25 > 33.795199999999994 > 36.837199999999996 > 34.1489 > 45.5 > > Fundamentally, these numbers have between 0 and 4 decimal digits of precision, and I want to be able to intuit how many each has, ignoring the obvious floating point roundoff problems. Thus, I want to map: > > 38.0 ==> 0 > 41.2586 ==> 4 > 40.75280000000001 ==> 4 > 49.25 ==> 2 > 33.795199999999994 ==> 4 > 36.837199999999996 ==> 4 > 34.1489 ==> 4 > 45.5 ==> 1 > > Is there any clean way to do that? The best I've come up with so far is to str() them and parse the remaining string to see how many digits it put after the decimal point. > > The numbers are given to me as Python floats; I have no control over that. I'm willing to accept that fact that I won't be able to differentiate between float("38.0") and float("38.0000"). Both of those map to 1, which is OK for my purposes. > > --- > Roy Smith > roy at panix.com > Hi, I doubt, many would consider a string/regex approach very clean here, but anyway; hopefully the results conform to your specs (as far as I understood it correctly). Alternatively, the floats can be rounded before, if e.g. 39.9999999 could be a false positive for 4-digits precision. hth, vbr = = = = = = = >>> for fl in (38.0, 41.2586, 40.75280000000001, 49.25, 33.795199999999994, 36.837199999999996, 34.1489, 45.5, 40.0010, 39.00000009, 39.9999999, 38.00009, 40.0100, 41.2000, 43.0001): ... print repr(fl), "==>", len(re.match(r"^-?\d+\.([0-9]{0,4})(? 0 41.2586 ==> 4 40.75280000000001 ==> 4 49.25 ==> 2 33.795199999999994 ==> 4 36.837199999999996 ==> 4 34.1489 ==> 4 45.5 ==> 1 40.001 ==> 3 39.00000009 ==> 0 39.9999999 ==> 4 38.00009 ==> 0 40.01 ==> 2 41.2 ==> 1 43.0001 ==> 4 >>> = = = = = = = From rosuav at gmail.com Tue Apr 29 12:30:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Apr 2014 02:30:12 +1000 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 29, 2014 at 11:38 PM, Roy Smith wrote: > I'm trying to intuit, from the values I've been given, which coordinates > are likely to be accurate to within a few miles. I'm willing to accept > a few false negatives. If the number is float("38"), I'm willing to > accept that it might actually be float("38.0000"), and I might be > throwing out a good data point that I don't need to. You have one chance in ten, repeatably, of losing a digit. That is, roughly 10% of your four-decimal figures will appear to be three-decimal, and 1% of them will appear to be two-decimal, and so on. Is that "a few" false negatives? It feels like a lot IMO. But then, there's no alternative - the information's already gone. ChrisA From ned at nedbatchelder.com Tue Apr 29 12:32:35 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 29 Apr 2014 12:32:35 -0400 Subject: where to put global testing value In-Reply-To: <535FD086.7000003@chamonix.reportlab.co.uk> References: <535FD086.7000003@chamonix.reportlab.co.uk> Message-ID: On 4/29/14 12:17 PM, Robin Becker wrote: > A user complains that under AppEngine I'm not allowed to import __main__. > > I can fix this issue merely by putting a try block around the offending > import which is only used like this > > > import __main__ > testing = getattr(__main__,'_rl_testing',False) > del __main__ > > this is only used as a hack way, during testing, to modify the behaviour > of the importing module (a proxy for a C extension). During testing we > keep both the C version and the supposed replacement of various > functions so they can be tested against each other > > https://bitbucket.org/rptlab/reportlab/src/default/src/reportlab/lib/rl_accel.py > > > Is there a more reasonable way to allow changes to module level globals > before the import takes place? I guess since this module is supposed > only to be imported by reportlab we can put this sort of thing onto the > reportlab module itself, but that could possibly lead to import loops. > > Any ideas? In coverage.py, I used environment variables to control that kind of behavior. -- Ned Batchelder, http://nedbatchelder.com From ned at nedbatchelder.com Tue Apr 29 12:47:22 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 29 Apr 2014 12:47:22 -0400 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/29/14 12:30 PM, Chris Angelico wrote: > On Tue, Apr 29, 2014 at 11:38 PM, Roy Smith wrote: >> I'm trying to intuit, from the values I've been given, which coordinates >> are likely to be accurate to within a few miles. I'm willing to accept >> a few false negatives. If the number is float("38"), I'm willing to >> accept that it might actually be float("38.0000"), and I might be >> throwing out a good data point that I don't need to. > > You have one chance in ten, repeatably, of losing a digit. That is, > roughly 10% of your four-decimal figures will appear to be > three-decimal, and 1% of them will appear to be two-decimal, and so > on. Is that "a few" false negatives? It feels like a lot IMO. But > then, there's no alternative - the information's already gone. > Reminds me of the story that the first survey of Mt. Everest resulted in a height of exactly 29,000 feet, but to avoid the appearance of an estimate, they reported it as 29,002: http://www.jstor.org/stable/2684102 -- Ned Batchelder, http://nedbatchelder.com From rosuav at gmail.com Tue Apr 29 12:59:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Apr 2014 02:59:47 +1000 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 30, 2014 at 2:47 AM, Ned Batchelder wrote: > Reminds me of the story that the first survey of Mt. Everest resulted in a > height of exactly 29,000 feet, but to avoid the appearance of an estimate, > they reported it as 29,002: http://www.jstor.org/stable/2684102 Yeah. Exactly the same phenomenon as I was referring to earlier when I said that you never tell someone you need to leave in five minutes - if you say six minutes, you'll be away sooner. ChrisA From wxjmfauth at gmail.com Tue Apr 29 13:37:38 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 29 Apr 2014 10:37:38 -0700 (PDT) Subject: Unicode 7 Message-ID: Let see how Python is ready for the next Unicode version (Unicode 7.0.0.Beta). >>> timeit.repeat("(x*1000 + y)[:-1]", setup="x = 'abc'; y = 'z'") [1.4027834829454946, 1.38714224331963, 1.3822586635296261] >>> timeit.repeat("(x*1000 + y)[:-1]", setup="x = 'abc'; y = '\u0fce'") [5.462776291480395, 5.4479432055423445, 5.447874284053398] >>> >>> >>> # more interesting >>> timeit.repeat("(x*1000 + y)[:-1]",\ ... setup="x = 'abc'.encode('utf-8'); y = '\u0fce'.encode('utf-8')") [1.3496489533188765, 1.328654286266783, 1.3300913977710707] >>> Note 1: "lookup" is not the problem. Note 2: From Unicode.org : "[...] We strongly encourage [...] and test them with their programs [...]" -> Done. jmf From python.list at tim.thechases.com Tue Apr 29 13:59:23 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 29 Apr 2014 12:59:23 -0500 Subject: Unicode 7 In-Reply-To: References: Message-ID: <20140429125923.52ceec9b@bigbox.christie.dr> On 2014-04-29 10:37, wxjmfauth at gmail.com wrote: > >>> timeit.repeat("(x*1000 + y)[:-1]", setup="x = 'abc'; y = 'z'") > [1.4027834829454946, 1.38714224331963, 1.3822586635296261] > >>> timeit.repeat("(x*1000 + y)[:-1]", setup="x = 'abc'; y = > >>> '\u0fce'") > [5.462776291480395, 5.4479432055423445, 5.447874284053398] > >>> > >>> > >>> # more interesting > >>> timeit.repeat("(x*1000 + y)[:-1]",\ > ... setup="x = 'abc'.encode('utf-8'); y = > '\u0fce'.encode('utf-8')") [1.3496489533188765, 1.328654286266783, > 1.3300913977710707] > >>> While I dislike feeding the troll, what I see here is: on your machine, all unicode manipulations in the test should take ~5.4 seconds. But Python notices that some of your strings *don't* require a full 32-bits and thus optimizes those operations, cutting about 75% of the processing time (wow...4-bytes-per-char to 1-byte-per-char, I wonder where that 75% savings comes from). So rather than highlight any *problem* with Python, your [mostly worthless microbenchmark non-realworld] tests show that Python's unicode implementation is awesome. Still waiting to see an actual bug-report as mentioned on the other thread. -tkc From python at mrabarnett.plus.com Tue Apr 29 14:12:43 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 29 Apr 2014 19:12:43 +0100 Subject: Unicode 7 In-Reply-To: References: Message-ID: <535FEB9B.8010607@mrabarnett.plus.com> On 2014-04-29 18:37, wxjmfauth at gmail.com wrote: > Let see how Python is ready for the next Unicode version > (Unicode 7.0.0.Beta). > > >>>> timeit.repeat("(x*1000 + y)[:-1]", setup="x = 'abc'; y = 'z'") > [1.4027834829454946, 1.38714224331963, 1.3822586635296261] >>>> timeit.repeat("(x*1000 + y)[:-1]", setup="x = 'abc'; y = '\u0fce'") > [5.462776291480395, 5.4479432055423445, 5.447874284053398] >>>> >>>> >>>> # more interesting >>>> timeit.repeat("(x*1000 + y)[:-1]",\ > ... setup="x = 'abc'.encode('utf-8'); y = '\u0fce'.encode('utf-8')") > [1.3496489533188765, 1.328654286266783, 1.3300913977710707] >>>> > Although the third example is the fastest, it's also the wrong way to handle Unicode: >>> x = 'abc'.encode('utf-8'); y = '\u0fce'.encode('utf-8') >>> t = (x*1000 + y)[:-1].decode('utf-8') Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 3000-3001: unex pected end of data > Note 1: "lookup" is not the problem. > > Note 2: From Unicode.org : "[...] We strongly encourage [...] and test > them with their programs [...]" > > -> Done. > > jmf > From nad at acm.org Tue Apr 29 14:35:11 2014 From: nad at acm.org (Ned Deily) Date: Tue, 29 Apr 2014 11:35:11 -0700 Subject: how to build and install multiple micro-level major.minor versions of Python References: <1398785310.2673.16.camel@belmer> Message-ID: In article <1398785310.2673.16.camel at belmer>, "Brent S. Elmer Ph.D." wrote: > Is there a way to do what I want to do (i.e. install 2.7.6 beside 2.7)? The usual way to support multiple micro versions is to build and install to a different location on your system by using: ./configure --prefix=/new/path There is nothing magical about /usr/local or /usr other than that /usr/bin and /usr/local/bin are usually included in default $PATH. If you use a non-default prefix, it's also probably best to avoid using --enable-shared to minimize the chances of confusion with shared library loading. -- Ned Deily, nad at acm.org From webe3vt at aim.com Tue Apr 29 14:53:13 2014 From: webe3vt at aim.com (Brent S. Elmer Ph.D.) Date: Tue, 29 Apr 2014 14:53:13 -0400 Subject: how to build and install multiple micro-level major.minor versions of Python In-Reply-To: References: <1398785310.2673.16.camel@belmer> Message-ID: <1398797593.9215.2.camel@belmer> On Tue, 2014-04-29 at 11:35 -0700, Ned Deily wrote: > In article <1398785310.2673.16.camel at belmer>, > "Brent S. Elmer Ph.D." wrote: > > Is there a way to do what I want to do (i.e. install 2.7.6 beside 2.7)? > > The usual way to support multiple micro versions is to build and install > to a different location on your system by using: > > ./configure --prefix=/new/path > > There is nothing magical about /usr/local or /usr other than that > /usr/bin and /usr/local/bin are usually included in default $PATH. If > you use a non-default prefix, it's also probably best to avoid using > --enable-shared to minimize the chances of confusion with shared library > loading. > > -- > Ned Deily, > nad at acm.org > Yes, I already use --prefix to build to a different path. I guess that is what I need to do but I would rather have a way to have the build and install process install to the micro level. Brent From harrismh777 at gmail.com Tue Apr 29 15:53:21 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 29 Apr 2014 14:53:21 -0500 Subject: how to build and install multiple micro-level major.minor versions of Python References: <1398785310.2673.16.camel@belmer> Message-ID: On 4/29/14 1:53 PM, Brent S. Elmer Ph.D. wrote: > Yes, I already use --prefix to build to a different path. I guess that > is what I need to do but I would rather have a way to have the build and > install process install to the micro level. > example only, Use --prefix /usr/local/2.7.6/ Use --prefix /usr/local/2.7.2/ &c., Both of the 2.7 installs will be 2.7, but it doesn't matter because they will (each one) be installed under a different micro level. ... works great. marcus From harrismh777 at gmail.com Tue Apr 29 15:57:14 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 29 Apr 2014 14:57:14 -0500 Subject: how to build and install multiple micro-level major.minor versions of Python References: <1398785310.2673.16.camel@belmer> Message-ID: On 4/29/14 1:53 PM, Brent S. Elmer Ph.D. wrote: > I would rather have a way to have the build and > install process install to the micro level. > I agree. On the other hand, is there really a special need to thoroughly test against a micro level. I have the latest 2.6, 2.7, 3.2, 3.3, 3.4 ... there might a critical reason for splitting hairs, but honestly, probably not. From a24061 at ducksburg.com Tue Apr 29 16:16:08 2014 From: a24061 at ducksburg.com (Adam Funk) Date: Tue, 29 Apr 2014 21:16:08 +0100 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8td53bxud5.ln2@news.ducksburg.com> On 2014-04-29, Roy Smith wrote: > Another possibility is that they're latitude/longitude coordinates, some > of which are given to the whole degree, some of which are given to > greater precision, all the way down to the ten-thousandth of a degree. That makes sense. 1? of longitude is about 111 km at the equator, 78?km at 45?N or S, & 0?km at the poles. "A man pitches his tent, walks 1 km south, walks 1 km east, kills a bear, & walks 1 km north, where he's back at his tent. What color is the bear?" ;-) -- War is God's way of teaching Americans geography. [Ambrose Bierce] From harrismh777 at gmail.com Tue Apr 29 16:39:08 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 29 Apr 2014 15:39:08 -0500 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: On 4/29/14 3:16 PM, Adam Funk wrote: > "A man pitches his tent, walks 1 km south, walks 1 km east, kills a > bear, & walks 1 km north, where he's back at his tent. What color is > the bear?" ;-) > Who manufactured the tent? marcus From nad at acm.org Tue Apr 29 15:13:26 2014 From: nad at acm.org (Ned Deily) Date: Tue, 29 Apr 2014 12:13:26 -0700 Subject: how to build and install multiple micro-level major.minor versions of Python In-Reply-To: <1398797593.9215.2.camel@belmer> References: <1398785310.2673.16.camel@belmer> <1398797593.9215.2.camel@belmer> Message-ID: On Apr 29, 2014, at 11:53 , Brent S. Elmer Ph.D. wrote: > Yes, I already use --prefix to build to a different path. I guess that > is what I need to do but I would rather have a way to have the build and > install process install to the micro level. Python deliberately does not provide a way to install to the micro level as an important "contract" in the Python maintenance and release process is to maintain ABI compatibility among maintenance (i.j.k) releases in the same major release series (i.j). We sometimes fail in that but we do try really hard to make it painless to move from i.j.k to i.j.x. That's also why we only supply fixes for the most recent micro release. -- Ned Deily nad at acm.org -- [] From ryan at ryanhiebert.com Tue Apr 29 16:42:04 2014 From: ryan at ryanhiebert.com (Ryan Hiebert) Date: Tue, 29 Apr 2014 15:42:04 -0500 Subject: Significant digits in a float? In-Reply-To: <8td53bxud5.ln2@news.ducksburg.com> References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: On Tue, Apr 29, 2014 at 3:16 PM, Adam Funk wrote: > > "A man pitches his tent, walks 1 km south, walks 1 km east, kills a > bear, & walks 1 km north, where he's back at his tent. What color is > the bear?" ;-) Skin or Fur? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Apr 29 17:15:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Apr 2014 07:15:11 +1000 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: On Wed, Apr 30, 2014 at 6:39 AM, Mark H Harris wrote: > On 4/29/14 3:16 PM, Adam Funk wrote: >> >> "A man pitches his tent, walks 1 km south, walks 1 km east, kills a >> bear, & walks 1 km north, where he's back at his tent. What color is >> the bear?" ;-) >> > > Who manufactured the tent? A man pitches his tent 1 km south and kills a bear with it. Clearly that wasn't a tent, it was a cricket ball. ChrisA From greg.ewing at canterbury.ac.nz Tue Apr 29 17:45:40 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 30 Apr 2014 09:45:40 +1200 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ned Batchelder wrote: > Reminds me of the story that the first survey of Mt. Everest resulted in > a height of exactly 29,000 feet, but to avoid the appearance of an > estimate, they reported it as 29,002: http://www.jstor.org/stable/2684102 They could have said it was 29.000 kilofeet. -- Greg From emile at fenx.com Tue Apr 29 18:42:25 2014 From: emile at fenx.com (emile) Date: Tue, 29 Apr 2014 15:42:25 -0700 Subject: Significant digits in a float? In-Reply-To: <8td53bxud5.ln2@news.ducksburg.com> References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: On 04/29/2014 01:16 PM, Adam Funk wrote: > "A man pitches his tent, walks 1 km south, walks 1 km east, kills a > bear, & walks 1 km north, where he's back at his tent. What color is > the bear?" ;-) From how many locations on Earth can someone walk one mile south, one mile east, and one mile north and end up at their starting point? Emile From rosuav at gmail.com Tue Apr 29 18:51:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Apr 2014 08:51:32 +1000 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: On Wed, Apr 30, 2014 at 8:42 AM, emile wrote: > On 04/29/2014 01:16 PM, Adam Funk wrote: > >> "A man pitches his tent, walks 1 km south, walks 1 km east, kills a >> bear, & walks 1 km north, where he's back at his tent. What color is >> the bear?" ;-) > > > From how many locations on Earth can someone walk one mile south, one mile > east, and one mile north and end up at their starting point? Any point where the mile east takes you an exact number of times around the globe. So, anywhere exactly one mile north of that, which is a number of circles not far from the south pole. ChrisA From arielin82 at gmail.com Tue Apr 29 17:05:24 2014 From: arielin82 at gmail.com (=?ISO-8859-1?Q?Ariel_Arga=F1araz?=) Date: Tue, 29 Apr 2014 21:05:24 +0000 Subject: Problems with ZODB, I can not persist and object accessed from 2 threads Message-ID: Hello, I am sorry I am stuck in this. And I need some help I want to persist an Object with ZODB, the object can be accessed from 2 different threads. The ZODB manual says: A multi-threaded program should open a separate Connection instance for each thread. Different threads can then modify objects and commit their modifications independently. But there isn't an example of how to create a connection for each thread. Can someone tell me how to connect to the same DB from 2 threads?? I attached an example of what I am trying to do. And I get this error. Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 763, in run self.__target(*self.__args, **self.__kwargs) File "main.py", line 33, in thread_1 storage = FileStorage("/tmp/asdasd.fs") File "/usr/lib/python2.7/site-packages/ZODB/FileStorage/FileStorage.py", line 164, in *_init_* self._lock_file = LockFile(file_name + '.lock') File "/usr/lib/python2.7/site-packages/zc/lockfile/__init__.py", line 84, in *_init_* _lock_file(fp) File "/usr/lib/python2.7/site-packages/zc/lockfile/__init__.py", line 59, in _lock_file raise LockError("Couldn't lock %r" % file.name) LockError: Couldn't lock '/tmp/asdasd.fs.lock' IF I don't connect in the "thread_1" class I can change things but sometimes the changes from the main thread are not commited. When I debug, I can see that when a change is made from the Second thread, the "transaction_manager" creates a new Transaction here: #manager.py def get(self): """ See ITransactionManager. """ if self._txn is None: self._txn = Transaction(self._synchs, self) return self._txn When it happens that commit Seems to be executed succesfully but it doest save the changes to the DB. -- Ariel Arga?araz -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: main.py Type: application/x-download Size: 2115 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: objects.py Type: application/x-download Size: 1853 bytes Desc: not available URL: From breamoreboy at yahoo.co.uk Tue Apr 29 19:34:41 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 30 Apr 2014 00:34:41 +0100 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: On 29/04/2014 23:42, emile wrote: > On 04/29/2014 01:16 PM, Adam Funk wrote: > >> "A man pitches his tent, walks 1 km south, walks 1 km east, kills a >> bear, & walks 1 km north, where he's back at his tent. What color is >> the bear?" ;-) > > From how many locations on Earth can someone walk one mile south, one > mile east, and one mile north and end up at their starting point? > > Emile > Haven't you heard of The Triangular Earth Society? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From roy at panix.com Tue Apr 29 19:53:57 2014 From: roy at panix.com (Roy Smith) Date: Tue, 29 Apr 2014 19:53:57 -0400 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: > On Tue, Apr 29, 2014 at 11:38 PM, Roy Smith wrote: > > I'm trying to intuit, from the values I've been given, which coordinates > > are likely to be accurate to within a few miles. I'm willing to accept > > a few false negatives. If the number is float("38"), I'm willing to > > accept that it might actually be float("38.0000"), and I might be > > throwing out a good data point that I don't need to. > > You have one chance in ten, repeatably, of losing a digit. That is, > roughly 10% of your four-decimal figures will appear to be > three-decimal, and 1% of them will appear to be two-decimal, and so > on. Is that "a few" false negatives? You're looking at it the wrong way. It's not that the glass is 10% empty, it's that it's 90% full, and 90% is a lot of good data :-) From rosuav at gmail.com Tue Apr 29 20:13:08 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Apr 2014 10:13:08 +1000 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 30, 2014 at 9:53 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Tue, Apr 29, 2014 at 11:38 PM, Roy Smith wrote: >> > I'm trying to intuit, from the values I've been given, which coordinates >> > are likely to be accurate to within a few miles. I'm willing to accept >> > a few false negatives. If the number is float("38"), I'm willing to >> > accept that it might actually be float("38.0000"), and I might be >> > throwing out a good data point that I don't need to. >> >> You have one chance in ten, repeatably, of losing a digit. That is, >> roughly 10% of your four-decimal figures will appear to be >> three-decimal, and 1% of them will appear to be two-decimal, and so >> on. Is that "a few" false negatives? > > You're looking at it the wrong way. It's not that the glass is 10% > empty, it's that it's 90% full, and 90% is a lot of good data :-) Hah! That's one way of looking at it. At least you don't have to worry about junk digits getting in. The greatest precision you're working with is three digits before the decimal and four after, and a Python float can handle that easily. (Which is what I was concerned about when I first queried your terminology - four digits to the right of the decimal and, say, 10-12 to the left, and you're starting to see problems.) ChrisA From ben at benfinney.id.au Tue Apr 29 20:13:34 2014 From: ben at benfinney.id.au (Ben Finney) Date: Wed, 30 Apr 2014 10:13:34 +1000 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85bnvjk72p.fsf@benfinney.id.au> Roy Smith writes: > In article , > Chris Angelico wrote: > > > You have one chance in ten, repeatably, of losing a digit. That is, > > roughly 10% of your four-decimal figures will appear to be > > three-decimal, and 1% of them will appear to be two-decimal, and so > > on. Is that "a few" false negatives? > > You're looking at it the wrong way. It's not that the glass is 10% > empty, it's that it's 90% full, and 90% is a lot of good data :-) The problem is you won't know *which* 90% is accurate, and which 10% is inaccurate. This is very different from the glass, where it's evident which part is good. So, I can't see that you have any choice but to say that *any* of the precision predictions should expect, on average, to be (10 + 1 + ?) percent inaccurate. And you can't know which ones. Is that an acceptable error rate? -- \ ?If you don't fail at least 90 percent of the time, you're not | `\ aiming high enough.? ?Alan Kay | _o__) | Ben Finney From rosuav at gmail.com Tue Apr 29 20:17:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Apr 2014 10:17:55 +1000 Subject: Significant digits in a float? In-Reply-To: <85bnvjk72p.fsf@benfinney.id.au> References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <85bnvjk72p.fsf@benfinney.id.au> Message-ID: On Wed, Apr 30, 2014 at 10:13 AM, Ben Finney wrote: > The problem is you won't know *which* 90% is accurate, and which 10% is > inaccurate. This is very different from the glass, where it's evident > which part is good. > > So, I can't see that you have any choice but to say that *any* of the > precision predictions should expect, on average, to be (10 + 1 + ?) > percent inaccurate. And you can't know which ones. Is that an acceptable > error rate? But they're all going to be *at least* as accurate as the algorithm says. A figure of 31.4 will be treated as 1 decimal, even though it might really have been accurate to 4; but a figure of 27.1828 won't be incorrectly reported as having only 2 decimals. ChrisA From ben at benfinney.id.au Tue Apr 29 20:20:28 2014 From: ben at benfinney.id.au (Ben Finney) Date: Wed, 30 Apr 2014 10:20:28 +1000 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <85bnvjk72p.fsf@benfinney.id.au> Message-ID: <857g67k6r7.fsf@benfinney.id.au> Ben Finney writes: > The problem is you won't know *which* 90% is accurate, and which 10% is > inaccurate. This is very different from the glass, where it's evident > which part is good. Hmm. Re-reading the suggestion, I see that it is fairly predictable which estimates of precision will be inaccurate: the ones which end in explicit zeroes are more uncertain in their intended precision. -- \ ?[F]reedom of speech does not entail freedom to have your ideas | `\ accepted by governments and incorporated into law and policy.? | _o__) ?Russell Blackford, 2010-03-06 | Ben Finney From roy at panix.com Tue Apr 29 20:42:33 2014 From: roy at panix.com (Roy Smith) Date: Tue, 29 Apr 2014 20:42:33 -0400 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> Message-ID: In article , Dennis Lee Bieber wrote: > in a physics or chemistry class the recommended result is > > 1.1 * 2.2 => 2.4 More than recommended. In my physics class, if you put down more significant digits than the input data justified, you got the problem marked wrong. > (one reason slide-rules were acceptable for so long -- and even my high > school trig course only required slide-rule significance even though half > the class had scientific calculators [costing >$100, when a Sterling > slide-rule could still be had for <$10]) Sterling? Snort. K&E was the way to go. From rosuav at gmail.com Tue Apr 29 20:45:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Apr 2014 10:45:58 +1000 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: On Wed, Apr 30, 2014 at 10:37 AM, Dennis Lee Bieber wrote: > On Wed, 30 Apr 2014 08:51:32 +1000, Chris Angelico > declaimed the following: > >> >>Any point where the mile east takes you an exact number of times >>around the globe. So, anywhere exactly one mile north of that, which >>is a number of circles not far from the south pole. >> > Yeah, but he'd have had to bring his own bear... > > Bears and Penguins don't mix. Seals, OTOH, are food to the bears, and > eat the penquins. Maybe the bear was an antarctic researcher who ate Merida's cake? That'd change anyone's fate... ChrisA From roy at panix.com Tue Apr 29 20:45:30 2014 From: roy at panix.com (Roy Smith) Date: Tue, 29 Apr 2014 20:45:30 -0400 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: In article <8td53bxud5.ln2 at news.ducksburg.com>, Adam Funk wrote: > On 2014-04-29, Roy Smith wrote: > > > Another possibility is that they're latitude/longitude coordinates, some > > of which are given to the whole degree, some of which are given to > > greater precision, all the way down to the ten-thousandth of a degree. > > That makes sense. 1?? of longitude is about 111 km at the equator, > 78??km at 45??N or S, & 0??km at the poles. > > > "A man pitches his tent, walks 1 km south, walks 1 km east, kills a > bear, & walks 1 km north, where he's back at his tent. What color is > the bear?" ;-) Assuming he shot the bear, red. From roy at panix.com Tue Apr 29 20:48:28 2014 From: roy at panix.com (Roy Smith) Date: Tue, 29 Apr 2014 20:48:28 -0400 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: In article , Chris Angelico wrote: > On Wed, Apr 30, 2014 at 10:37 AM, Dennis Lee Bieber > wrote: > > On Wed, 30 Apr 2014 08:51:32 +1000, Chris Angelico > > declaimed the following: > > > >> > >>Any point where the mile east takes you an exact number of times > >>around the globe. So, anywhere exactly one mile north of that, which > >>is a number of circles not far from the south pole. > >> > > Yeah, but he'd have had to bring his own bear... > > > > Bears and Penguins don't mix. Seals, OTOH, are food to the bears, > > and > > eat the penquins. > > Maybe the bear was an antarctic researcher who ate Merida's cake? > That'd change anyone's fate... > > ChrisA The cake is a lie. From larry.martell at gmail.com Tue Apr 29 20:57:32 2014 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 29 Apr 2014 18:57:32 -0600 Subject: pyodbc connect string Message-ID: I am having a problem building a connect string for pyodbc. It works when everything is hard coded, but if I build the connect string it fails. This works: pyodbc.connect('DRIVER=FreeTDS;' 'SERVER=xx.xx.xx.xx;' 'PORT=1433;' 'DATABASE=blah;' 'UID=foo;' 'PWD=bar;') But this does not: pyodbc.connect(conn_str) Where conn_str is: 'DRIVER=FreeTDS;' 'SERVER=xx.xx.xx.xx;' 'PORT=1433;' 'DATABASE=blah;' 'UID=foo;' 'PWD=bar;' conn_str is constructed with: conn_str = "'DRIVER=%s;' 'SERVER=%s;' 'PORT=%s;' 'DATABASE=%s;' 'UID=%s;' 'PWD=%s;'" \ % (RECIPE_DB['DRIVER'], RECIPE_DB['SERVER'], RECIPE_DB['PORT'], RECIPE_DB['DATABASE'], RECIPE_DB['USER'], RECIPE_DB['PASSWORD']) Anyone have any ideas as to why this doesn't work. From rosuav at gmail.com Tue Apr 29 21:09:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Apr 2014 11:09:48 +1000 Subject: pyodbc connect string In-Reply-To: References: Message-ID: On Wed, Apr 30, 2014 at 10:57 AM, Larry Martell wrote: > This works: > > pyodbc.connect('DRIVER=FreeTDS;' 'SERVER=xx.xx.xx.xx;' 'PORT=1433;' > 'DATABASE=blah;' 'UID=foo;' 'PWD=bar;') > > But this does not: > > pyodbc.connect(conn_str) > > conn_str is constructed with: > > conn_str = "'DRIVER=%s;' 'SERVER=%s;' 'PORT=%s;' 'DATABASE=%s;' > 'UID=%s;' 'PWD=%s;'" \ > % (RECIPE_DB['DRIVER'], RECIPE_DB['SERVER'], > RECIPE_DB['PORT'], RECIPE_DB['DATABASE'], > RECIPE_DB['USER'], RECIPE_DB['PASSWORD']) > > Anyone have any ideas as to why this doesn't work. Start by printing out conn_str. That'll tell you if it's actually coming out the way you think it is. I can see where the problem probably is (assuming these are faithful copy/pastes), in the form of an extra double quote; but actually print them out and see what you're getting. ChrisA From ben at benfinney.id.au Tue Apr 29 21:14:36 2014 From: ben at benfinney.id.au (Ben Finney) Date: Wed, 30 Apr 2014 11:14:36 +1000 Subject: pyodbc connect string References: Message-ID: <85wqe7ipoj.fsf@benfinney.id.au> Larry Martell writes: > I am having a problem building a connect string for pyodbc. It works > when everything is hard coded, but if I build the connect string it > fails. > > This works: > > pyodbc.connect('DRIVER=FreeTDS;' 'SERVER=xx.xx.xx.xx;' 'PORT=1433;' > 'DATABASE=blah;' 'UID=foo;' 'PWD=bar;') This calls the function with a single string, "DRIVER=FreeTDS;SERVER=xx.xx.xx.xx;PORT=1433;DATABASE=blah;UID=foo;PWD=bar;". Remember that consecutive, whitespace-separated, quote-delimited fragments specify the construction of a single string literal:: >>> 'foo' 'foo' >>> 'foo' 'bar' 'foobar' >>> 'foo' 'bar' 'baz' 'foobarbaz' See the reference for how this concatenation occurs . > But this does not: > > pyodbc.connect(conn_str) > > Where conn_str is: > > 'DRIVER=FreeTDS;' 'SERVER=xx.xx.xx.xx;' 'PORT=1433;' 'DATABASE=blah;' > 'UID=foo;' 'PWD=bar;' This string is different, because it contains a whole lot of quotation marks and whitespace not in the string you show in the first example. > conn_str is constructed with: > > conn_str = "'DRIVER=%s;' 'SERVER=%s;' 'PORT=%s;' 'DATABASE=%s;' > 'UID=%s;' 'PWD=%s;'" \ > % (RECIPE_DB['DRIVER'], RECIPE_DB['SERVER'], > RECIPE_DB['PORT'], RECIPE_DB['DATABASE'], > RECIPE_DB['USER'], RECIPE_DB['PASSWORD']) Remove the extraneous quotes and whitespace, which were not in the original string you showed above. On a separate point: Since you have string keys for the mapping, you can make the interpolation more readable:: conn_str = ( "DRIVER=%(DRIVER)s;SERVER=%(SERVER)s;PORT=%(PORT)s;" "DATABASE=%(DATABASE)s;UID=%(USER)s;PWD=%(PASSWORD)s;" ) % RECIPE_DB since the named placeholders will be looked up by key in the ?RECIPE_DB? mapping. There are other improvements to suggest, but I don't want to distract from the main point of the post. -- \ ?The fact that I have no remedy for all the sorrows of the | `\ world is no reason for my accepting yours. It simply supports | _o__) the strong probability that yours is a fake.? ?Henry L. Mencken | Ben Finney From larry.martell at gmail.com Tue Apr 29 21:15:18 2014 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 29 Apr 2014 19:15:18 -0600 Subject: pyodbc connect string In-Reply-To: References: Message-ID: On Tue, Apr 29, 2014 at 7:09 PM, Chris Angelico wrote: > On Wed, Apr 30, 2014 at 10:57 AM, Larry Martell wrote: >> This works: >> >> pyodbc.connect('DRIVER=FreeTDS;' 'SERVER=xx.xx.xx.xx;' 'PORT=1433;' >> 'DATABASE=blah;' 'UID=foo;' 'PWD=bar;') >> >> But this does not: >> >> pyodbc.connect(conn_str) >> >> conn_str is constructed with: >> >> conn_str = "'DRIVER=%s;' 'SERVER=%s;' 'PORT=%s;' 'DATABASE=%s;' >> 'UID=%s;' 'PWD=%s;'" \ >> % (RECIPE_DB['DRIVER'], RECIPE_DB['SERVER'], >> RECIPE_DB['PORT'], RECIPE_DB['DATABASE'], >> RECIPE_DB['USER'], RECIPE_DB['PASSWORD']) >> >> Anyone have any ideas as to why this doesn't work. > > Start by printing out conn_str. That'll tell you if it's actually > coming out the way you think it is. I can see where the problem > probably is (assuming these are faithful copy/pastes), in the form of > an extra double quote; but actually print them out and see what you're > getting. When I print conn_str out it does not have the double quotes, But I was able to solve this by doing this: pyodbc.connect('DRIVER=' + RECIPE_DB['DRIVER'] + ';' + 'SERVER=' + RECIPE_DB['SERVER'] + ';' + 'PORT=' + RECIPE_DB['PORT'] + ';' + 'DATABASE=' + RECIPE_DB['DATABASE'] + ';' + 'UID=' + RECIPE_DB['USER'] + ';' + 'PWD=' + RECIPE_DB['PASSWORD'] + ';') ' Thanks. From larry.martell at gmail.com Tue Apr 29 21:25:51 2014 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 29 Apr 2014 19:25:51 -0600 Subject: pyodbc connect string In-Reply-To: <85wqe7ipoj.fsf@benfinney.id.au> References: <85wqe7ipoj.fsf@benfinney.id.au> Message-ID: On Tue, Apr 29, 2014 at 7:14 PM, Ben Finney wrote: > Larry Martell writes: > >> I am having a problem building a connect string for pyodbc. It works >> when everything is hard coded, but if I build the connect string it >> fails. >> >> This works: >> >> pyodbc.connect('DRIVER=FreeTDS;' 'SERVER=xx.xx.xx.xx;' 'PORT=1433;' >> 'DATABASE=blah;' 'UID=foo;' 'PWD=bar;') > > This calls the function with a single string, > "DRIVER=FreeTDS;SERVER=xx.xx.xx.xx;PORT=1433;DATABASE=blah;UID=foo;PWD=bar;". > > Remember that consecutive, whitespace-separated, quote-delimited > fragments specify the construction of a single string literal:: > > >>> 'foo' > 'foo' > >>> 'foo' 'bar' > 'foobar' > >>> 'foo' 'bar' 'baz' > 'foobarbaz' > > See the reference for how this concatenation occurs > . > >> But this does not: >> >> pyodbc.connect(conn_str) >> >> Where conn_str is: >> >> 'DRIVER=FreeTDS;' 'SERVER=xx.xx.xx.xx;' 'PORT=1433;' 'DATABASE=blah;' >> 'UID=foo;' 'PWD=bar;' > > This string is different, because it contains a whole lot of quotation > marks and whitespace not in the string you show in the first example. > >> conn_str is constructed with: >> >> conn_str = "'DRIVER=%s;' 'SERVER=%s;' 'PORT=%s;' 'DATABASE=%s;' >> 'UID=%s;' 'PWD=%s;'" \ >> % (RECIPE_DB['DRIVER'], RECIPE_DB['SERVER'], >> RECIPE_DB['PORT'], RECIPE_DB['DATABASE'], >> RECIPE_DB['USER'], RECIPE_DB['PASSWORD']) > > Remove the extraneous quotes and whitespace, which were not in the > original string you showed above. > > On a separate point: Since you have string keys for the mapping, you can > make the interpolation more readable:: > > conn_str = ( > "DRIVER=%(DRIVER)s;SERVER=%(SERVER)s;PORT=%(PORT)s;" > "DATABASE=%(DATABASE)s;UID=%(USER)s;PWD=%(PASSWORD)s;" > ) % RECIPE_DB > > since the named placeholders will be looked up by key in the ?RECIPE_DB? > mapping. > > There are other improvements to suggest, but I don't want to distract > from the main point of the post. Thanks for the explanation. From pleasedontspam at isp.com Tue Apr 29 22:37:17 2014 From: pleasedontspam at isp.com (pleasedontspam at isp.com) Date: Tue, 29 Apr 2014 19:37:17 -0700 (PDT) Subject: Bug in Decimal?? Message-ID: <973d2677-03c6-464a-8c88-f07282806468@googlegroups.com> Hello, I believe I found a bug in the Decimal library. The natural logarithm results seem to be off in a certain range, as compared with Wolfram Alpha. Here's an example: from decimal import * getcontext().prec=2016 one=Decimal(1) number=Decimal('1e-1007') partial=(one+number)/(one-number) final.ln() The result should be 2.00000... with all zeroes and 7 at the end. Instead, I'm getting 1.999999.. with 2 digits different at the end. I checked that this happens for any 1e-N with N relatively large (above about 300 it starts showing bad digits at the end. Set the precision even higher and you'll see more digits off, it seems for number=10^-N, the error begins around 10^(-2N). The partial result (1+x)/(1-x) is correct to the number of digits specified, so it seems ln() is having accuracy problems. Can other people confirm this or is it just my imagination? I tested with python 2.7.5 in XUbuntu, and also with my own build of mpdecimal 2.4.0 (latest, built from source). I compared the results with wolfram Alpha, and also with an open source arbitrary precision calculator, which matches Alpha results. From steve+comp.lang.python at pearwood.info Tue Apr 29 22:50:58 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Apr 2014 02:50:58 GMT Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53606512$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 29 Apr 2014 09:38:33 -0400, Roy Smith wrote: > > What reason do you have to think that something recorded to 14 decimal > > places was only intended to have been recorded to 4? > > Because I understand the physical measurement these numbers represent. > Sometimes, Steve, you have to assume that when somebody asks a question, > they actually have asked the question then intended to ask. Heh, having been in *exactly* your situation of having people questioning my constraints, I can sympathise with your frustration. I was pretty frustrated too. But I've also been in situations where I've been so close to a question that I couldn't see the big picture, and a few dumb questions made me realise that in fact I was missing something obvious which changed the situation completely. To paraphrase: Me: How do I square the circle with only a compass and straightedge? Them: You can't. It's impossible. Are you sure you need only use compass and straightedge? Can you use a rolling circle and a marked ruler? Me: Come come, I've told you my requirements, compass and straightedge only. Now solve my problem! Them: Does it have to be in Euclidean space? Why don't you perform the construction in Gauss-Bolyai-Lobachevsky space? Me: Perhaps a rolling circle and ruler isn't such a bad idea... http://www.cut-the-knot.org/impossible/sq_circle.shtml http://mathworld.wolfram.com/CircleSquaring.html :-) -- Steven D'Aprano http://import-that.dreamwidth.org/ From ethan at stoneleaf.us Tue Apr 29 22:31:31 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 29 Apr 2014 19:31:31 -0700 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: <53606083.4000509@stoneleaf.us> On 04/29/2014 03:51 PM, Chris Angelico wrote: > On Wed, Apr 30, 2014 at 8:42 AM, emile wrote: >> On 04/29/2014 01:16 PM, Adam Funk wrote: >> >>> "A man pitches his tent, walks 1 km south, walks 1 km east, kills a >>> bear, & walks 1 km north, where he's back at his tent. What color is >>> the bear?" ;-) >> >> >> From how many locations on Earth can someone walk one mile south, one mile >> east, and one mile north and end up at their starting point? > > Any point where the mile east takes you an exact number of times > around the globe. So, anywhere exactly one mile north of that, which > is a number of circles not far from the south pole. Perhaps my geography is rusty, but I was under the impression that one cannot travel south if one is at the South Pole (axial, not magnetic). -- ~Ethan~ From steve+comp.lang.python at pearwood.info Tue Apr 29 22:59:58 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Apr 2014 02:59:58 GMT Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: <5360672e$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 29 Apr 2014 19:31:31 -0700, Ethan Furman wrote: > Perhaps my geography is rusty, but I was under the impression that one > cannot travel south if one is at the South Pole (axial, not magnetic). Possibly with a rocket aimed straight up. -- Steven D'Aprano http://import-that.dreamwidth.org/ From roy at panix.com Tue Apr 29 23:30:31 2014 From: roy at panix.com (Roy Smith) Date: Tue, 29 Apr 2014 23:30:31 -0400 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <5360672e$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <5360672e$0$29965$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Tue, 29 Apr 2014 19:31:31 -0700, Ethan Furman wrote: > > > Perhaps my geography is rusty, but I was under the impression that one > > cannot travel south if one is at the South Pole (axial, not magnetic). > > Possibly with a rocket aimed straight up. No, with a rocket aimed straight up, you go north. To go south, you need a rocket aimed straight down. From steve+comp.lang.python at pearwood.info Tue Apr 29 23:39:12 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Apr 2014 03:39:12 GMT Subject: Bug in Decimal?? References: <973d2677-03c6-464a-8c88-f07282806468@googlegroups.com> Message-ID: <53607060$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 29 Apr 2014 19:37:17 -0700, pleasedontspam wrote: > from decimal import * > getcontext().prec=2016 > one=Decimal(1) > number=Decimal('1e-1007') > partial=(one+number)/(one-number) > final.ln() What's final? Did you mean partial? When I try it in Python 3.3, I get: py> from decimal import * py> getcontext().prec=2016 py> one = Decimal(1) py> number = Decimal('1e-1007') py> partial = (one+number)/(one-number) py> partial.ln() Decimal('1.9999[...]9999987E-1007') with a lot of 9s deleted for brevity. > The result should be 2.00000... with all zeroes and 7 at the end. Can you demonstrate exactly how you tested it on Wolfram-Alpha, because I cannot reproduce that. When I try it with ln((1+1e-1007)/(1-1e-1007)), the decimal expansion shown starts off as: 2.00000000000000000000000000000000000000000000000000000... ? 10^-1007 By repeatedly clicking "More digits", I get: 2.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000... ? 10^-1007 For brevity, I will truncate some repeated digits from this point on. 1.99999999999999999[...]999999999999999999999999999999999999999999999... ? 10^-1007 as above, except with even more nines (477 of them if I have calculated correctly) 2.00000000000000000[...]0000000000000000000000000000000000000000000000... ? 10^-1007 as above, with even more zeroes and finally the last available approximation is 2.000000[...]000000666666[...]666666... ? 10^-1007 with a lot of zeroes and sixes not shown. But not ending in 7. > Instead, I'm getting 1.999999.. with 2 digits different at the end. Well, it's hard to say exactly what's going on, since Wolfram Alpha doesn't show the context, but it looks like Python's version may agree with two out of the seven decimal approximations Alpha makes available. This suggests to me that it's a representation issue. [...] > Can other people confirm this or is it just my imagination? I tested > with python 2.7.5 in XUbuntu, and also with my own build of mpdecimal > 2.4.0 (latest, built from source). I compared the results with wolfram > Alpha, and also with an open source arbitrary precision calculator, > which matches Alpha results. I think it's worth raising a ticket for it on the bug tracker. I think it would help if you can provide a link or instructions to how to replicate this in Alpha, also give the name and version number of the arbitrary precision calculator you used. Anything that can be used to replicate your results. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Tue Apr 29 23:03:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Apr 2014 13:03:44 +1000 Subject: Significant digits in a float? In-Reply-To: <53606083.4000509@stoneleaf.us> References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <53606083.4000509@stoneleaf.us> Message-ID: On Wed, Apr 30, 2014 at 12:31 PM, Ethan Furman wrote: > On 04/29/2014 03:51 PM, Chris Angelico wrote: >> Any point where the mile east takes you an exact number of times >> around the globe. So, anywhere exactly one mile north of that, which >> is a number of circles not far from the south pole. > > Perhaps my geography is rusty, but I was under the impression that one > cannot travel south if one is at the South Pole (axial, not magnetic). Correct, but there's a place not far from the South Pole where the circumference of the earth (travelling east) will be exactly one mile. I could calculate where that would be on a perfect sphere, but earth isn't, so I'll just say "near the South Pole". If you start exactly one mile north of that circle, then you can accomplish the original challenge. Also, if your mile east takes you exactly twice around the circumference, you still achieve the same thing, so there's another circle (one mile north of *that* circle), and another at the three-times-around circle, etc. But I think a better answer is New York City. You start out lost, you go a mile south, a mile east, a mile north, and you are again lost. ChrisA From rosuav at gmail.com Tue Apr 29 23:40:22 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Apr 2014 13:40:22 +1000 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <5360672e$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 30, 2014 at 1:30 PM, Roy Smith wrote: > In article <5360672e$0$29965$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> On Tue, 29 Apr 2014 19:31:31 -0700, Ethan Furman wrote: >> >> > Perhaps my geography is rusty, but I was under the impression that one >> > cannot travel south if one is at the South Pole (axial, not magnetic). >> >> Possibly with a rocket aimed straight up. > > No, with a rocket aimed straight up, you go north. To go south, you > need a rocket aimed straight down. If I ever go travelling with you guys, I am NOT letting you navigate. ChrisA From rustompmody at gmail.com Wed Apr 30 00:53:22 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 29 Apr 2014 21:53:22 -0700 (PDT) Subject: Unicode 7 In-Reply-To: References: Message-ID: On Tuesday, April 29, 2014 11:29:23 PM UTC+5:30, Tim Chase wrote: > While I dislike feeding the troll, what I see here is: Since its Unicode-troll time, here's my contribution http://blog.languager.org/2014/04/unicode-and-unix-assumption.html :-) More seriously, since Ive quoted some esteemed members of this list explicitly (Steven) and the list in general, please let me know if something is inaccurate or inappropriate From fanny at itprovent.com Wed Apr 30 01:10:28 2014 From: fanny at itprovent.com (fanny at itprovent.com) Date: Tue, 29 Apr 2014 22:10:28 -0700 (PDT) Subject: segmentation fault, executable python file In-Reply-To: References: <49ded36a-5c07-4421-874a-5c3fb518efd5@googlegroups.com> Message-ID: I try gdb the executable file in another machine and get this: Error -3 from inflate: incorrect header check Error decompresing struct if I do gdb in my machine (where I generate the executable file) I get nothing, and the app work correctly. I try to search about that, but i don't get it. Could any of you please let me know how to fix this? Thank u before From wxjmfauth at gmail.com Wed Apr 30 03:06:41 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 30 Apr 2014 00:06:41 -0700 (PDT) Subject: Unicode 7 In-Reply-To: References: Message-ID: <4fc3221d-9b2e-4c95-9d36-c10a8fca7259@googlegroups.com> @ Time Chase I'm perfectly aware about what I'm doing. @ MRAB "...Although the third example is the fastest, it's also the wrong way to handle Unicode: ..." Maybe that's exactly the opposite. It illustrates very well, the quality of coding schemes endorsed by Unicode.org. I deliberately choose utf-8. >>> sys.getsizeof('\u0fce') 40 >>> sys.getsizeof('\u0fce'.encode('utf-8')) 20 >>> sys.getsizeof('\u0fce'.encode('utf-16-be')) 19 >>> sys.getsizeof('\u0fce'.encode('utf-32-be')) 21 >>> Q. How to save memory without wasting time in encoding? By using products using natively the unicode coding schemes? Are you understanding unicode? Or are you understanding unicode via Python? --- A Tibetan monk [*] using Py32: >>> timeit.repeat("(x*1000 + y)[:-1]", setup="x = 'abc'; y = 'z'") [2.3394840182882186, 2.3145832750782653, 2.3207231951529685] >>> timeit.repeat("(x*1000 + y)[:-1]", setup="x = 'abc'; y = '\u0fce'") [2.328517624800078, 2.3169403900011076, 2.317586282812048] >>> [*] Your curiosity has certainly shown, what this code point means. For the others: U+0FCE TIBETAN SIGN RDEL NAG RDEL DKAR signifies good luck earlier, bad luck later (My comment: Good luck with Python or bad luck with Python) jmf From greg.ewing at canterbury.ac.nz Wed Apr 30 03:59:46 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 30 Apr 2014 19:59:46 +1200 Subject: Bug in Decimal?? In-Reply-To: <973d2677-03c6-464a-8c88-f07282806468@googlegroups.com> References: <973d2677-03c6-464a-8c88-f07282806468@googlegroups.com> Message-ID: pleasedontspam at isp.com wrote: > I compared the results with wolfram Alpha, and > also with an open source arbitrary precision calculator, which matches Alpha > results. Decimal is *not* an arbitrary precision data type, so you can't expect exact results from it. You can set the precision to be very large, but it's still essentially a floating point type, and as such you can expect the last few digits to depend heavily on the details of the algorithm used. -- Greg From greg.ewing at canterbury.ac.nz Wed Apr 30 04:14:56 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 30 Apr 2014 20:14:56 +1200 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: Chris Angelico wrote: > Any point where the mile east takes you an exact number of times > around the globe. So, anywhere exactly one mile north of that, which > is a number of circles not far from the south pole. True, but there are no bears in Antarctica, so that rules out all the south-pole solutions. I think there are still multiple solutions, though. The bear may have been spray-painted by activists trying to protect it from polar trophy hunters. -- Greg From rosuav at gmail.com Wed Apr 30 04:27:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Apr 2014 18:27:24 +1000 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: On Wed, Apr 30, 2014 at 6:14 PM, Gregory Ewing wrote: > Chris Angelico wrote: > >> Any point where the mile east takes you an exact number of times >> around the globe. So, anywhere exactly one mile north of that, which >> is a number of circles not far from the south pole. > > > True, but there are no bears in Antarctica, so that > rules out all the south-pole solutions. > > I think there are still multiple solutions, though. > The bear may have been spray-painted by activists > trying to protect it from polar trophy hunters. Well, I did suggest it might have been a black bear: http://img2.wikia.nocookie.net/__cb20130411125035/disney/images/8/88/Brave-brave-31312503-800-486.png But spray paint would work too... ChrisA From alister.nospam.ware at ntlworld.com Wed Apr 30 05:03:41 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 30 Apr 2014 09:03:41 GMT Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: On Tue, 29 Apr 2014 15:42:25 -0700, emile wrote: > On 04/29/2014 01:16 PM, Adam Funk wrote: > >> "A man pitches his tent, walks 1 km south, walks 1 km east, kills a >> bear, & walks 1 km north, where he's back at his tent. What color is >> the bear?" ;-) > > From how many locations on Earth can someone walk one mile south, one > mile east, and one mile north and end up at their starting point? > > Emile there are an infinite number of locations where this can happen (although only one where you will find a bear.) -- Gomme's Laws: (1) A backscratcher will always find new itches. (2) Time accelerates. (3) The weather at home improves as soon as you go away. From varun7rs at gmail.com Wed Apr 30 05:30:04 2014 From: varun7rs at gmail.com (varun7rs at gmail.com) Date: Wed, 30 Apr 2014 02:30:04 -0700 (PDT) Subject: Designing a network in Python Message-ID: <8ab783e8-a36e-49e5-a329-2c4d98df8537@googlegroups.com> Hello Friends I would like to design a network given the topology and the source I use is http://sndlib.zib.de/home.action I have managed to read most of the important data in the xml onto lists. Now, I have two lists, Source and Destination and I'd like to create bi-directional links between them. My code is as below. And moreover, I'd like to assign some kind of a bandwidth capacity to the links and similarly, storage and processing capacity to the nodes. So, I generated some random integers for them. I don't know how to proceed further to design the topology. I'd prefer to do the topology design in another .py file probably. I'd be glad if you guys could lend me a helping hand. import sys import xml.dom.minidom as dom import string #from xml.dom.minidom import getDOMimplementation from xml.dom import minidom from xml.dom.minidom import parse import os import random class PHY_NODES: def __init__(self, nodeID, x, y, capacity_proc, capacity_stor, capacity_switch): self.nodeID = nodeID self.x = x self.y = y self.linklist = [] self.capacity_proc = capacity_proc self.capacity_stor = capacity_stor self.capacity_switch = capacity_switch class PHY_LINKS: def __init__(self, linkID, source, destination, capacity_bdw): self.linkID = linkID self.source = source self.destination = destination self.capacity_bdw = capacity_bdw # Reading Nodes Read_Data = minidom.parse("germany50.xml") nodelist = Read_Data.getElementsByTagName("node") corenodes = [] for node in nodelist : corenodes.append(node.getAttribute("id")) nodeid = node.getAttribute("id") xCoordinates = node.getElementsByTagName("x") [0] yCoordinates = node.getElementsByTagName("y") [0] proc = random.randint(20, 40) stor = random.randint(40, 80) switch = random.randint(60, 90) nodeobj = PHY_NODES(nodeid, xCoordinates, yCoordinates, proc, stor, switch) # Reading Links linklist = Read_Data.getElementsByTagName("link") links = [] sources = [] destinations = [] capacity_link = [] for link in linklist : linkid = link.getAttribute("id") Source = link.getElementsByTagName("source") [0] Destination = link.getElementsByTagName("target") [0] Capacity = link.getElementsByTagName("capacity") [0] linkobj = PHY_LINKS(linkid, Source, Destination, Capacity) sources.append(Source.firstChild.data) destinations.append(Destination.firstChild.data) capacity_link.append(Capacity.firstChild.data) From square.steve at gmail.com Wed Apr 30 07:39:40 2014 From: square.steve at gmail.com (Steve Simmons) Date: Wed, 30 Apr 2014 12:39:40 +0100 Subject: Slightly OT - using PyUIC from Eclipse Message-ID: <5360E0FC.70802@gmail.com> I'm trying to set up a new dev environment using Windows 7; Eclipse (Kepler); Python 3.3; PyDev and PyQt 5 and I've hit an issue getting PyUIC to generate a python Qt class from within Eclipse. I'm using the following setup process (from Google Groups) modified to match my PyQt5 configuration: 1. Click Run -> External Tools -> External Tools Configurations ... 2. In the resulting dialog, click 'New' icon in the top left 3. Under 'Name' put 'PyUIC' 4. Under 'Location' enter 'C:\Program Files\Python\2.5\Python.exe' or the path to your Python executable (probably C:\Python25\Python.exe) 5. Under 'Arguments' enter '"C:\Program Files\Python\2.5\Lib\site- packages\PyQt4\uic\pyuic.py" "${resource_loc}"' substituting the path to your PyQt4 installation - be sure also to include the double quotes 6. Change to the 'Common' tab and check 'File' under 'Standard Input/ Output' and enter '${resource_loc}.py' 7. Change to the 'Build' tab and uncheck 'Build before launch' 8. Change to the 'Refresh' tab and check 'Refresh resources upon completion' 9. Click 'Apply' then 'Run' and I'm getting the following traceback: Traceback (most recent call last): File "D:\Development\Python33\Lib\site-packages\PyQt5\uic\pyuic.py", line 28, in from .driver import Driver SystemError: Parent module '' not loaded, cannot perform relative import I tried this on Qt4 a week or so ago and it worked OK but Qt5 is giving me an error message, so I guess I've either mis-transcribed or there's a difference in the directory structure betwee PyQt4 & PyQt5. I'm more interested to learn how to read the traceback (insightfully) and track it to the source of the problem, although it would be good to have it working too!! Steve Simmons PS Also posted to PyQT list. From roy at panix.com Wed Apr 30 08:01:39 2014 From: roy at panix.com (Roy Smith) Date: Wed, 30 Apr 2014 08:01:39 -0400 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <53606083.4000509@stoneleaf.us> Message-ID: In article , Chris Angelico wrote: > But I think a better answer is New York City. You start out lost, you > go a mile south, a mile east, a mile north, and you are again lost. Only in Queens. From pleasedontspam at isp.com Wed Apr 30 08:01:55 2014 From: pleasedontspam at isp.com (pleasedontspam at isp.com) Date: Wed, 30 Apr 2014 05:01:55 -0700 (PDT) Subject: Bug in Decimal?? In-Reply-To: <53607060$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <973d2677-03c6-464a-8c88-f07282806468@googlegroups.com> <53607060$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1744e932-3f92-4320-b58d-797818ad98f6@googlegroups.com> On Tuesday, April 29, 2014 11:39:12 PM UTC-4, Steven D'Aprano wrote: > On Tue, 29 Apr 2014 19:37:17 -0700, pleasedontspam wrote: > > > > > from decimal import * > > > getcontext().prec=2016 > > > one=Decimal(1) > > > number=Decimal('1e-1007') > > > partial=(one+number)/(one-number) > > > final.ln() > > > > What's final? Did you mean partial? Final is my final result: ln((1+x)/(1-x)) I called the quotient partial because I wanted to investigate if perhaps the result of the division (that's my partial result) had a rounding error, which would throw off the ln(). > > > > When I try it in Python 3.3, I get: > > > > py> from decimal import * > > py> getcontext().prec=2016 > > py> one = Decimal(1) > > py> number = Decimal('1e-1007') > > py> partial = (one+number)/(one-number) > > py> partial.ln() > > Decimal('1.9999[...]9999987E-1007') > > > > with a lot of 9s deleted for brevity. > > > > > The result should be 2.00000... with all zeroes and 7 at the end. > > > > Can you demonstrate exactly how you tested it on Wolfram-Alpha, because I > > cannot reproduce that. When I try it with ln((1+1e-1007)/(1-1e-1007)), That's exactly how you test it. The result should be 2.0000... 7 (at 2016 digits precision, at higher precisions it will continue adding another 2014 sixes until the digits become something else. This is from the definition of the yperbolic arc tangent: atanh(x) = 1/2 * ln ( (1+x)/(1-x) ) As it turns out to be the ln() part of 1e-N is the integer 2, followed by 2N zeroes, then followed by 2N-1 sixes, then a 0, a seven, then another group of around 2N sixes (I didn't actually count them), then other interesting digit patterns. Try with 1e-1007 using 4000 digits or more and you'll see python giving a better result... but there's a 4 in the middle of the sixes! That 4 shouldn't be there. getcontext().prec=4000, then do the rest the same (you need to recalculate the partial result at the higher precision too). > > the decimal expansion shown starts off as: > > > > 2.00000000000000000000000000000000000000000000000000000... ? 10^-1007 > > > > By repeatedly clicking "More digits", I get: > > > > 2.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000... > > ? 10^-1007 > > > > For brevity, I will truncate some repeated digits from this point on. > > > > > > 1.99999999999999999[...]999999999999999999999999999999999999999999999... > > ? 10^-1007 > > > > as above, except with even more nines (477 of them if I have calculated > > correctly) > You're correct! It seems Alpha has its own problems too. Depending on the precision, it's giving the correct or incorrect result, changing as you hit 'more digits'. I can imagine this could happen because the (1+x)/(1-x) ratio becomes 1. followed by 2N zeroes, then a 2, then 2N zeroes, then another 2, etc. If the precision is such that your last digit just includes the next 2 or not, it can throw the result off a little bit. But this should self-correct as the precision goes higher, as it does in Wolfram Alpha. But python is giving bad data even with very high precision, as I mentioned above with 4000 digits, there's a bad digit in the middle of the sixes, at much less precision than the required by the system (hundreds of digits less). > > > 2.00000000000000000[...]0000000000000000000000000000000000000000000000... > > ? 10^-1007 > > > > as above, with even more zeroes > > > > and finally the last available approximation is > > > > 2.000000[...]000000666666[...]666666... ? 10^-1007 > > > > with a lot of zeroes and sixes not shown. But not ending in 7. Ending in 7 is because I had exactly 2016 digits precision, and 2016 is 2*1007+1, so exactly the last digit was the first 6 of the 6666666... which becomes 7 because it was correctly rounded. > > > > > > > Instead, I'm getting 1.999999.. with 2 digits different at the end. > > > > Well, it's hard to say exactly what's going on, since Wolfram Alpha > > doesn't show the context, but it looks like Python's version may agree > > with two out of the seven decimal approximations Alpha makes available. > > This suggests to me that it's a representation issue. > Definitely not a representation issue. I'm working on a high precision calculator, and was using mpdecimal to generate tables for the CORDIC method, (the tables have atanh(1e-N) for N=1..Precision) and that's how I stumbled upon this issue, the last 2/3 of my tables were consistently showing the wrong results. And I'm not printing the numbers, I'm accessing the digits directly from the data structures, so what you see is exactly what gets calculated, this is not a problem with printing. It might be a printing issue in Alpha, since they probably use binary numbers (GMP and the like), as opposed to decimal like python. > > > > > [...] > > > Can other people confirm this or is it just my imagination? I tested > > > with python 2.7.5 in XUbuntu, and also with my own build of mpdecimal > > > 2.4.0 (latest, built from source). I compared the results with wolfram > > > Alpha, and also with an open source arbitrary precision calculator, > > > which matches Alpha results. > > > > I think it's worth raising a ticket for it on the bug tracker. > > > > I think it would help if you can provide a link or instructions to how to > > replicate this in Alpha, You already did it right! ln((1+1e-1007)/(1-1e-1007)) > also give the name and version number of the > > arbitrary precision calculator you used. Anything that can be used to > > replicate your results. I used this to double check: http://preccalc.sourceforge.net I think you replicated my results perfectly and confirmed something is going on. I'm now especially baffled at the number 4 that appeared in the middle of the sixes, using 4000 for the precision. I just checked this with python 2.7.6 running on PC-BSD 10, and it's confirmed. So it's not a problem with the compiler used for the build either (PC-BSD/FreeBSD used Clang 3.3, XUbuntu used GCC). > > > > > > > > -- > > Steven D'Aprano > > http://import-that.dreamwidth.org/ From pleasedontspam at isp.com Wed Apr 30 08:13:03 2014 From: pleasedontspam at isp.com (pleasedontspam at isp.com) Date: Wed, 30 Apr 2014 05:13:03 -0700 (PDT) Subject: Bug in Decimal?? In-Reply-To: <53607060$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <973d2677-03c6-464a-8c88-f07282806468@googlegroups.com> <53607060$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tuesday, April 29, 2014 11:39:12 PM UTC-4, Steven D'Aprano wrote: > On Tue, 29 Apr 2014 19:37:17 -0700, pleasedontspam wrote: > > > > > from decimal import * > > > getcontext().prec=2016 > > > one=Decimal(1) > > > number=Decimal('1e-1007') > > > partial=(one+number)/(one-number) > > > final.ln() > > > > What's final? Did you mean partial? I see what you mean now. Sorry, I meant final=partial.ln() From jcasale at activenetwerx.com Wed Apr 30 08:28:28 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Wed, 30 Apr 2014 12:28:28 +0000 Subject: Designing a network in Python In-Reply-To: <8ab783e8-a36e-49e5-a329-2c4d98df8537@googlegroups.com> References: <8ab783e8-a36e-49e5-a329-2c4d98df8537@googlegroups.com> Message-ID: <5f646e93fd5d4a6280fba6458cf4e6c8@exch.activenetwerx.com> > I have managed to read most of the important data in the xml onto lists. > Now, I have two lists, Source and Destination and I'd like to create bi-directional > links between them. > And moreover, I'd like to assign some kind of a bandwidth capacity to the links and > similarly, storage and processing capacity to the nodes. I don't know anything about your use case or data really, but from the above I already know I would shove this all into a database, adding tables with relations and mining data based on relations becomes trivial. More importantly, it also then becomes easily extensible without refactoring as your requirements change. Just my opinion, jlc From breamoreboy at yahoo.co.uk Wed Apr 30 09:05:16 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 30 Apr 2014 14:05:16 +0100 Subject: Significant digits in a float? In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: On 30/04/2014 09:14, Gregory Ewing wrote: > Chris Angelico wrote: > >> Any point where the mile east takes you an exact number of times >> around the globe. So, anywhere exactly one mile north of that, which >> is a number of circles not far from the south pole. > > True, but there are no bears in Antarctica, so that > rules out all the south-pole solutions. > > I think there are still multiple solutions, though. > The bear may have been spray-painted by activists > trying to protect it from polar trophy hunters. > Couldn't this kill the bear? My source is the book and film Goldfinger. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From chris.hinsley at gmail.com Wed Apr 30 09:28:58 2014 From: chris.hinsley at gmail.com (Chris Hinsley) Date: Wed, 30 Apr 2014 14:28:58 +0100 Subject: First attempt at a Python prog (Chess) References: <2013021323250974803-chrishinsley@gmailcom> Message-ID: <201404301428587277-chrishinsley@gmailcom> On 2013-02-15 05:05:27 +0000, Rick Johnson said: > On Thursday, February 14, 2013 11:48:10 AM UTC-6, Chris Hinsley wrote: > >> Is a Python list as fast as a bytearray? > > Why would you care about that now? Are you running this code on the > Xerox Alto? Excuse me for the sarcasm but your post title has perplexed > me: > > "First attempt at a Python prog (Chess)"Okay, but how does that translate to: > "The fastest, most efficient, most brain fricked python code ever > released in the form of a game, that just happens to look an awful lot > like C source"? > > http://en.wikipedia.org/wiki/Optimization_%28computer_science%29#When_to_optimize > > > Why bother to use Python if what you really want to write is C code? If > you want to write good code (not just python), you need to write code > that is maintainable. Yes i KNOW, this is just some stupid chess game, > but i can assure you that this style of code is only going to harm your > evolution. This code is obfuscated at best and BF'ed at worst. And > forget about the algorithms for now, the first problems to address are > superficial. > > First of all your naming conventions suck. You've used the "interface" > style for every function in this game so i can't /easily/ eyeball parse > the /real/ interface functions from the helper functions -- and i'm not > going to even try, because i don't read ugly code! Try to learn the > Python style guide as soon as you can (In particular pay attention to > naming conventions): > > http://www.python.org/dev/peps/pep-0008/ > > Secondly this game could benefit from some OOP paradigm (not sure if > are familiar with OOP or not???). But don't go bat-crazy with OOP! You > don't need an object to represent /every/ single piece on the board > (That would be nuts!). You need just enough OOP to encapsulate the data > and create a proper interface. > A good litmus test is based on the "three little bears": > > "Papa bears bed is too hard" > > A hard utilization of paradigms wields too little OOP and therefore > ends up being too difficult (aka: "hard") to maintain because there is > no logical interface; just a massive collection of functions stuffed > into global space until BF reaches critical mass and you're forced to > do a complete re-write! (Of course sometimes you don't need OOP at all, > just interface) > "Mama bears bed is too soft" > > A soft utilization of paradigms wields too much OOP whereby you are > surrounded by big FAT objects which are smothering you to death, and > they smell because they cannot properly wash themselves between the > rolls of fat. > > "but baby bears is just right" > Ahhh, the blissful comfort of a paradigm utilization that is "just > right". This is where your code should be, you want a level of OOP > usage that is "just right" for the occasion; not any more, not any less. > ## START EXAMPLE CODE ## > class GameBoard(???): > def __init__(self): > self.board = self._createBoard() > def __str__(self): > """Override:""" > # return a string represention of the board > # suitable for writing to stdout > def _createBoard(self): > """Internal:""" > self.board = [blah] > def make_move(self, piece, vector): > """Interface: move a game piece based on vector""" > # Find and move the piece. Whether the pieces > # are objects or not doesn't matter. > class GamePiece(object): > def __init__(self, typename, color): > self.typeName = typeName > self.color = color > self.captureFlag = self._computeFlag() > > > def main(): > board = Board() > playing = True > while playing is not False > i = input('PieceName - MoveVec:') > n, v = parse(i) > result = board.make_move(n, v) > if result == 'GameOver': > playing = False > else: > # clear the stdout > str(board) > > if __name__ == '__main__: > main() > ## END EXAMPLE CODE ## > > And now you have the added benefit of exporting the objects for use elsewhere. Wow, such vitriol for such a simple bear to cope with ! Maybe Papa bear would like to try some humility ! This was my very first Python prog, and my first chess prog and my attempt to learn somthing about Generators ! Do youtself a favour and leave the Python comunity for the good of the language ! Chris From ethan at stoneleaf.us Wed Apr 30 09:14:23 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 30 Apr 2014 06:14:23 -0700 Subject: Off-topic circumnavigating the earth in a mile or less [was Re: Significant digits in a float?] In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: <5360F72F.2000102@stoneleaf.us> On 04/29/2014 03:51 PM, Chris Angelico wrote: > On Wed, Apr 30, 2014 at 8:42 AM, emile wrote: >> On 04/29/2014 01:16 PM, Adam Funk wrote: >> >>> "A man pitches his tent, walks 1 km south, walks 1 km east, kills a >>> bear, & walks 1 km north, where he's back at his tent. What color is >>> the bear?" ;-) >> >> >> From how many locations on Earth can someone walk one mile south, one mile >> east, and one mile north and end up at their starting point? > > Any point where the mile east takes you an exact number of times > around the globe. So, anywhere exactly one mile north of that, which > is a number of circles not far from the south pole. It is my contention, completely unbacked by actual research, that if you find such a spot (heading a mile east takes you an integral number of times around the pole), that there is not enough Earth left to walk a mile north so that you could then turn-around a walk a mile south to get back to such a location. -- ~Ethan~ From ethan at stoneleaf.us Wed Apr 30 10:02:20 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 30 Apr 2014 07:02:20 -0700 Subject: Off-topic circumnavigating the earth in a mile or less [was Re: Significant digits in a float?] In-Reply-To: <5360F72F.2000102@stoneleaf.us> References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <5360F72F.2000102@stoneleaf.us> Message-ID: <5361026C.3090606@stoneleaf.us> On 04/30/2014 06:14 AM, Ethan Furman wrote: > On 04/29/2014 03:51 PM, Chris Angelico wrote: >> On Wed, Apr 30, 2014 at 8:42 AM, emile wrote: >>> On 04/29/2014 01:16 PM, Adam Funk wrote: >>> >>>> "A man pitches his tent, walks 1 km south, walks 1 km east, kills a >>>> bear, & walks 1 km north, where he's back at his tent. What color is >>>> the bear?" ;-) >>> >>> >>> From how many locations on Earth can someone walk one mile south, one mile >>> east, and one mile north and end up at their starting point? >> >> Any point where the mile east takes you an exact number of times >> around the globe. So, anywhere exactly one mile north of that, which >> is a number of circles not far from the south pole. > > It is my contention, completely unbacked by actual research, that if you find such a spot (heading a mile east takes you > an integral number of times around the pole), that there is not enough Earth left to walk a mile north so that you could > then turn-around a walk a mile south to get back to such a location. Wow. It's amazing how writing something down, wrongly (I originally had north and south reversed), correcting it, letting some time pass (enough to post the message so one can be properly embarrassed ;), and then rereading it later can make something so much clearer! Or maybe it was the morning caffeine. Hmmm. At any rate, I withdraw my contention, it is clear to me now (at least until the caffeine wears off). -- ~Ethan~ From varun7rs at gmail.com Wed Apr 30 10:57:43 2014 From: varun7rs at gmail.com (varun7rs at gmail.com) Date: Wed, 30 Apr 2014 07:57:43 -0700 (PDT) Subject: Designing a network in Python In-Reply-To: References: <8ab783e8-a36e-49e5-a329-2c4d98df8537@googlegroups.com> Message-ID: <6b386a23-ee11-46df-ade7-6cb235df4a18@googlegroups.com> I don't know how to do that stuff in python. Basically, I'm trying to pull certain data from the xml file like the node-name, source, destination and the capacity. Since, I am done with that part, I now want to have a link between source and destination and assign capacity to it. eg., [a,b,c,d,e] [l,m,n,o,p] [5,2,3,4,5] I need something like a - l: 5, b - m: 2,....I don't know how to describe this exactly but I hope this would give you a rough idea. After this, I put the stuff back into an xml but this time only there are more parameters and looks more detailed.... Like nodeID = Aachen...stor_capacity = 100, proc_capacity = 200, switch_capacity = 190...etc From harrismh777 at gmail.com Wed Apr 30 11:03:31 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 30 Apr 2014 10:03:31 -0500 Subject: Designing a network in Python References: <8ab783e8-a36e-49e5-a329-2c4d98df8537@googlegroups.com> <6b386a23-ee11-46df-ade7-6cb235df4a18@googlegroups.com> Message-ID: On 4/30/14 9:57 AM, varun7rs at gmail.com wrote: > I don't know how to do that stuff in python. Always a good time to learn. Let the database do the work for you; try not to re-invent the relational database wheel. Access the database via python-sql: https://pypi.python.org/pypi/python-sql/ marcus From harrismh777 at gmail.com Wed Apr 30 11:15:16 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 30 Apr 2014 10:15:16 -0500 Subject: First attempt at a Python prog (Chess) References: <2013021323250974803-chrishinsley@gmailcom> <201404301428587277-chrishinsley@gmailcom> Message-ID: On 4/30/14 8:28 AM, Chris Hinsley wrote: > On 2013-02-15 05:05:27 +0000, Rick Johnson said: >> >> First of all your naming conventions suck. You've used the "interface" >> style for every function in this game so i can't /easily/ eyeball >> parse the /real/ interface functions from the helper functions -- and >> i'm not going to even try, because i don't read ugly code! Try to >> learn the Python style guide as soon as you can (In particular pay >> attention to naming conventions): > Wow, such vitriol for such a simple bear to cope with ! > > Maybe Papa bear would like to try some humility ! > > This was my very first Python prog, and my first chess prog and my > attempt to learn somthing about Generators ! Do youtself a favour and > leave the Python comunity for the good of the language ! > > Chris > Chris, you might want to try another list: https://mail.python.org/mailman/listinfo/tutor The folks on this list are friendly, but tough. They are not generally arrogant, but many of them are experts (or core python developers) and most of them are worth listening to. The list mentioned above is for folks who are learning python and who have basic questions or want basic clarifications. (they are gentler too) :) marcus From robert.kern at gmail.com Wed Apr 30 11:55:17 2014 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 30 Apr 2014 16:55:17 +0100 Subject: First attempt at a Python prog (Chess) In-Reply-To: References: <2013021323250974803-chrishinsley@gmailcom> <201404301428587277-chrishinsley@gmailcom> Message-ID: On 2014-04-30 16:15, Mark H Harris wrote: > On 4/30/14 8:28 AM, Chris Hinsley wrote: >> On 2013-02-15 05:05:27 +0000, Rick Johnson said: >>> >>> First of all your naming conventions suck. You've used the "interface" >>> style for every function in this game so i can't /easily/ eyeball >>> parse the /real/ interface functions from the helper functions -- and >>> i'm not going to even try, because i don't read ugly code! Try to >>> learn the Python style guide as soon as you can (In particular pay >>> attention to naming conventions): > >> Wow, such vitriol for such a simple bear to cope with ! >> >> Maybe Papa bear would like to try some humility ! >> >> This was my very first Python prog, and my first chess prog and my >> attempt to learn somthing about Generators ! Do youtself a favour and >> leave the Python comunity for the good of the language ! >> >> Chris >> > > Chris, you might want to try another list: > > https://mail.python.org/mailman/listinfo/tutor > > > The folks on this list are friendly, but tough. They are not generally arrogant, > but many of them are experts (or core python developers) and most of them are > worth listening to. The list mentioned above is for folks who are learning > python and who have basic questions or want basic clarifications. (they are > gentler too) :) It's also worth noting that Rick Johnson is a well-known troll here and *not* representative of this group. He was deliberately insulting Chris, not being "tough" but helpful. He is not worth listening to. He is to be killfiled and ignored. Chris, I'm sorry you ran into him on your first introduction to this community. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From rosuav at gmail.com Wed Apr 30 10:27:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 1 May 2014 00:27:17 +1000 Subject: Off-topic circumnavigating the earth in a mile or less [was Re: Significant digits in a float?] In-Reply-To: <5360F72F.2000102@stoneleaf.us> References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <5360F72F.2000102@stoneleaf.us> Message-ID: On Wed, Apr 30, 2014 at 11:14 PM, Ethan Furman wrote: >> Any point where the mile east takes you an exact number of times >> around the globe. So, anywhere exactly one mile north of that, which >> is a number of circles not far from the south pole. > > > It is my contention, completely unbacked by actual research, that if you > find such a spot (heading a mile east takes you an integral number of times > around the pole), that there is not enough Earth left to walk a mile north > so that you could then turn-around a walk a mile south to get back to such a > location. The circle where the distance is exactly one mile will be fairly near the south pole. There should be plenty of planet a mile to the north of that. If the earth were a perfect sphere, the place we're looking for is the place where cutting across the sphere is 1/? miles. The radius of the earth is approximately 4000 miles (give or take). So we're looking for the place where the chord across a radius 4000 circle is 1/?; that means the triangle formed by a radius of the earth and half of 1/? and an unknown side (the distance from the centre of the earth to the point where the chord meets it - a smidge less than 4000, but the exact distance is immaterial) is a right triangle. Trig functions to the rescue! We want latitude 90?-(asin 1/8000?). It's practically at the south pole: 89.9977? south (89?59'52"). Are my calculations correct? ChrisA From invalid at invalid.invalid Wed Apr 30 14:18:15 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 30 Apr 2014 18:18:15 +0000 (UTC) Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-04-29, Roy Smith wrote: >> What reason do you have to think that something recorded to 14 >> decimal places was only intended to have been recorded to 4? > > Because I understand the physical measurement these numbers represent. > Sometimes, Steve, you have to assume that when somebody asks a question, > they actually have asked the question then intended to ask. Sometimes. But the smart money bets against it -- especially when people are asking about floating point. :) It doesn't sound to me like you have enough information to reliably do what you want to do, but parsing the string representation is probably the best way to go. -- Grant Edwards grant.b.edwards Yow! HELLO KITTY gang at terrorizes town, family gmail.com STICKERED to death! From invalid at invalid.invalid Wed Apr 30 14:19:02 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 30 Apr 2014 18:19:02 +0000 (UTC) Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-04-29, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Tue, Apr 29, 2014 at 11:38 PM, Roy Smith wrote: >> > I'm trying to intuit, from the values I've been given, which coordinates >> > are likely to be accurate to within a few miles. I'm willing to accept >> > a few false negatives. If the number is float("38"), I'm willing to >> > accept that it might actually be float("38.0000"), and I might be >> > throwing out a good data point that I don't need to. >> >> You have one chance in ten, repeatably, of losing a digit. That is, >> roughly 10% of your four-decimal figures will appear to be >> three-decimal, and 1% of them will appear to be two-decimal, and so >> on. Is that "a few" false negatives? > > You're looking at it the wrong way. It's not that the glass is 10% > empty, it's that it's 90% full, and 90% is a lot of good data :-) If you know _which_ is the good data and which is the bad... -- Grant Edwards grant.b.edwards Yow! I'm sitting on my at SPEED QUEEN ... To me, gmail.com it's ENJOYABLE ... I'm WARM ... I'm VIBRATORY ... From invalid at invalid.invalid Wed Apr 30 14:21:49 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 30 Apr 2014 18:21:49 +0000 (UTC) Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> Message-ID: On 2014-04-29, emile wrote: > On 04/29/2014 01:16 PM, Adam Funk wrote: > >> "A man pitches his tent, walks 1 km south, walks 1 km east, kills a >> bear, & walks 1 km north, where he's back at his tent. What color is >> the bear?" ;-) > > From how many locations on Earth can someone walk one mile south, one > mile east, and one mile north and end up at their starting point? I'm pretty sure there are places in London like that. At least that's what it seemed like to somebody from the midwestern US where the streets are layed out on a grid. -- Grant Edwards grant.b.edwards Yow! It's a hole all the at way to downtown Burbank! gmail.com From jcasale at activenetwerx.com Wed Apr 30 14:38:07 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Wed, 30 Apr 2014 18:38:07 +0000 Subject: Designing a network in Python In-Reply-To: <6b386a23-ee11-46df-ade7-6cb235df4a18@googlegroups.com> References: <8ab783e8-a36e-49e5-a329-2c4d98df8537@googlegroups.com> , <6b386a23-ee11-46df-ade7-6cb235df4a18@googlegroups.com> Message-ID: <50c0bd6917a24ae7b4e053e409202866@exch.activenetwerx.com> > I don't know how to do that stuff in python. Basically, I'm trying to pull certain data from the > xml file like the node-name, source, destination and the capacity. Since, I am done with that > part, I now want to have a link between source and destination and assign capacity to it. I dont mind writing you an SQLite schema and accessor class, can you define your data in a tabular format and mail it to me offline, we add relationships etc as we go. Hopefully it inspires you to adopt this approach in the future as it often proves powerful. jlc From python.list at tim.thechases.com Wed Apr 30 14:48:48 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 30 Apr 2014 13:48:48 -0500 Subject: Unicode 7 In-Reply-To: <4fc3221d-9b2e-4c95-9d36-c10a8fca7259@googlegroups.com> References: <4fc3221d-9b2e-4c95-9d36-c10a8fca7259@googlegroups.com> Message-ID: <20140430134848.2bb66e1c@bigbox.christie.dr> On 2014-04-30 00:06, wxjmfauth at gmail.com wrote: > @ Time Chase > > I'm perfectly aware about what I'm doing. Apparently, you're quite adept at appending superfluous characters to sensible strings...did you benchmark your email composition, too? ;-) -tkc (aka "Tim", not "Time") From rosuav at gmail.com Wed Apr 30 15:10:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 1 May 2014 05:10:05 +1000 Subject: Off-topic circumnavigating the earth in a mile or less [was Re: Significant digits in a float?] In-Reply-To: <5361026C.3090606@stoneleaf.us> References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <5360F72F.2000102@stoneleaf.us> <5361026C.3090606@stoneleaf.us> Message-ID: On Thu, May 1, 2014 at 12:02 AM, Ethan Furman wrote: > Wow. It's amazing how writing something down, wrongly (I originally had > north and south reversed), correcting it, letting some time pass (enough to > post the message so one can be properly embarrassed ;), and then rereading > it later can make something so much clearer! > > Or maybe it was the morning caffeine. Hmmm. > > At any rate, I withdraw my contention, it is clear to me now (at least until > the caffeine wears off). It's also amazing how much fun it can be to dig into the actual mathematics, as a means of dispelling a perceived error :) So, thank you for posting that, because it forced me to actually map things out (in my head - didn't feel like using pen-and-paper geometry, even though this is the most literal form of geo-metry possible) and figure out exactly how many degrees of latitude it takes. Good fun! ChrisA From fabiofz at gmail.com Wed Apr 30 18:49:42 2014 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Wed, 30 Apr 2014 19:49:42 -0300 Subject: Slightly OT - using PyUIC from Eclipse In-Reply-To: <5360E0FC.70802@gmail.com> References: <5360E0FC.70802@gmail.com> Message-ID: On Wed, Apr 30, 2014 at 8:39 AM, Steve Simmons wrote: > I'm trying to set up a new dev environment using Windows 7; Eclipse > (Kepler); Python 3.3; PyDev and PyQt 5 and I've hit an issue getting PyUIC > to generate a python Qt class from within Eclipse. > > I'm using the following setup process (from Google Groups) modified to > match my PyQt5 configuration: > > 1. Click Run -> External Tools -> External Tools Configurations ... > 2. In the resulting dialog, click 'New' icon in the top left > 3. Under 'Name' put 'PyUIC' > 4. Under 'Location' enter 'C:\Program Files\Python\2.5\Python.exe' or > the path to your Python executable (probably C:\Python25\Python.exe) > 5. Under 'Arguments' enter '"C:\Program Files\Python\2.5\Lib\site- > packages\PyQt4\uic\pyuic.py" "${resource_loc}"' substituting the path > to your PyQt4 installation - be sure also to include the double quotes > 6. Change to the 'Common' tab and check 'File' under 'Standard Input/ > Output' and enter '${resource_loc}.py' > 7. Change to the 'Build' tab and uncheck 'Build before launch' > 8. Change to the 'Refresh' tab and check 'Refresh resources upon > completion' > 9. Click 'Apply' then 'Run' > > and I'm getting the following traceback: > > Traceback (most recent call last): > File "D:\Development\Python33\Lib\site-packages\PyQt5\uic\pyuic.py", > line 28, in > from .driver import Driver > SystemError: Parent module '' not loaded, cannot perform relative import > > I tried this on Qt4 a week or so ago and it worked OK but Qt5 is giving me > an error message, so I guess I've either mis-transcribed or there's a > difference in the directory structure betwee PyQt4 & PyQt5. > > I'm more interested to learn how to read the traceback (insightfully) and > track it to the source of the problem, although it would be good to have it > working too!! > > Steve Simmons > > PS Also posted to PyQT list. > -- > https://mail.python.org/mailman/listinfo/python-list > The problem is that a main module cannot perform relative imports on Python. To overcome that limitation, Python created a workaround to execute a module with: python -m 'module.name' So, If you execute Python as: python -m PyQt5.uic.pyuic (instead of "python C:\Program Files\Python\2.5\Lib\site-packages\PyQt5\uic\pyuic.py") it should work. If you want, you can read an answer on http://stackoverflow.com/questions/14132789/python-relative-imports-for-the-billionth-timefor more details on why it doesn't work and the other way does... Cheers, Fabio -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Wed Apr 30 19:32:46 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 30 Apr 2014 16:32:46 -0700 Subject: unittest weirdness In-Reply-To: <531F78E9.5020103@stoneleaf.us> References: <531F78E9.5020103@stoneleaf.us> Message-ID: <5361881E.7000105@stoneleaf.us> On 03/11/2014 01:58 PM, Ethan Furman wrote: > > So I finally got enough data and enough of an understanding to write some unit tests for my code. > The weird behavior I'm getting: > > - when a test fails, I get the E or F, but no summary at the end > (if the failure occurs in setUpClass before my tested routines > are actually called, I get the summary; if I run a test method > individually I get the summary) > > - I have two classes, but only one is being exercised > > - occasionally, one of my gvim windows is unceremoniously killed > (survived only by its swap file) > > I'm running the tests under sudo as the routines expect to be run that way. > > Anybody have any ideas? For posterity's sake: I added a .close() method to the class being tested which destroys its big data structures; then I added a tearDownClass method to the unittest. That seems to have done the trick with getting the tests to /all/ run, and by apps don't suddenly disappear. :) -- ~Ethan~ From square.steve at gmail.com Wed Apr 30 20:49:25 2014 From: square.steve at gmail.com (Steve Simmons) Date: Thu, 01 May 2014 01:49:25 +0100 Subject: Slightly OT - using PyUIC from Eclipse In-Reply-To: References: <5360E0FC.70802@gmail.com> Message-ID: <53619A15.7010403@gmail.com> An HTML attachment was scrubbed... URL: From ryan at ryanhiebert.com Wed Apr 30 11:24:48 2014 From: ryan at ryanhiebert.com (Ryan Hiebert) Date: Wed, 30 Apr 2014 10:24:48 -0500 Subject: Off-topic circumnavigating the earth in a mile or less [was Re: Significant digits in a float?] In-Reply-To: <5361026C.3090606@stoneleaf.us> References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <5360F72F.2000102@stoneleaf.us> <5361026C.3090606@stoneleaf.us> Message-ID: On Wed, Apr 30, 2014 at 9:02 AM, Ethan Furman wrote: > On 04/30/2014 06:14 AM, Ethan Furman wrote: > >> On 04/29/2014 03:51 PM, Chris Angelico wrote: >> >>> On Wed, Apr 30, 2014 at 8:42 AM, emile wrote: >>> >>>> On 04/29/2014 01:16 PM, Adam Funk wrote: >>>> >>>> "A man pitches his tent, walks 1 km south, walks 1 km east, kills a >>>>> bear, & walks 1 km north, where he's back at his tent. What color is >>>>> the bear?" ;-) >>>>> >>>> >>>> >>>> From how many locations on Earth can someone walk one mile south, one >>>> mile >>>> east, and one mile north and end up at their starting point? >>>> >>> >>> Any point where the mile east takes you an exact number of times >>> around the globe. So, anywhere exactly one mile north of that, which >>> is a number of circles not far from the south pole. >>> >> >> It is my contention, completely unbacked by actual research, that if you >> find such a spot (heading a mile east takes you >> an integral number of times around the pole), that there is not enough >> Earth left to walk a mile north so that you could >> then turn-around a walk a mile south to get back to such a location. >> > > Wow. It's amazing how writing something down, wrongly (I originally had > north and south reversed), correcting it, letting some time pass (enough to > post the message so one can be properly embarrassed ;), and then rereading > it later can make something so much clearer! > > Or maybe it was the morning caffeine. Hmmm. > > At any rate, I withdraw my contention, it is clear to me now (at least > until the caffeine wears off). > > Sure, but that still leaves the nagging problem that there aren't any Polar Bears in Antarctica (as someone else pointed out). This man must have brought a bear with him. Perhaps the story is something like this: A man near the south pole takes his dear friend and pet bear for a walk. He'd gone to great lengths to bring his pet bear with him to his Antarctic expedition, and his bear is his best friend, and sole companion, save for the constant, biting cold. They walk toward the pole, then begin their excursion eastward, encircling the pole. As the man grows weary, and decides to head back, a legion of penguins collaborate with a host of Weddell seals to be rid of their uninvited guests. It isn't clear what the man did to cause those seals to rise against him, but it must have been some dire feat, for Weddell seals are not easily frightened. After a fierce battle, the man and his bear (well, mostly the bear) manage to defend themselves against the attacking throng. However, the new peace realizes a terrible fate: his bear is mortally wounded, and is suffering immensely. The man, loving his friend dearly, shoots his solitary compatriot, and weeps as he watches the blood turn his dear bear's fur an ominous red. Overcome with grief, he heads back north to his tent to mourn his loss, and to arrange his trip north to the populated tropics, where he hopes to forget his troubles, and the place where he lost his closet pal, a bear. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Wed Apr 30 19:46:50 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 30 Apr 2014 17:46:50 -0600 Subject: Off-topic circumnavigating the earth in a mile or less [was Re: Significant digits in a float?] In-Reply-To: <5360F72F.2000102@stoneleaf.us> References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <5360F72F.2000102@stoneleaf.us> Message-ID: On Wed, Apr 30, 2014 at 7:14 AM, Ethan Furman wrote: > On 04/29/2014 03:51 PM, Chris Angelico wrote: >> >> On Wed, Apr 30, 2014 at 8:42 AM, emile wrote: >>> >>> On 04/29/2014 01:16 PM, Adam Funk wrote: >>> >>>> "A man pitches his tent, walks 1 km south, walks 1 km east, kills a >>>> bear, & walks 1 km north, where he's back at his tent. What color is >>>> the bear?" ;-) >>> >>> >>> >>> From how many locations on Earth can someone walk one mile south, one >>> mile >>> east, and one mile north and end up at their starting point? >> >> >> Any point where the mile east takes you an exact number of times >> around the globe. So, anywhere exactly one mile north of that, which >> is a number of circles not far from the south pole. It also works if your starting point is (precisely) the north pole. I believe that's the canonical answer to the riddle, since there are no bears in Antarctica. From steve+comp.lang.python at pearwood.info Wed Apr 30 21:50:18 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 May 2014 01:50:18 GMT Subject: Slightly OT - using PyUIC from Eclipse References: <5360E0FC.70802@gmail.com> Message-ID: <5361a85a$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 01 May 2014 01:49:25 +0100, Steve Simmons wrote: > > > > > >
>
On 30/04/2014 23:49, Fabio Zadrozny > wrote:
>
>
cite="mid:CANXBEFrqndqCeT-9Hgqz7jRCZcmp8nz4VE+ebf-BKsYr54qQqQ > @mail.gmail.com" > type="cite"> And that's about where I stopped reading. I'm sorry Steve, but you're writing to a programmer's forum here, and you should be sending in plain text, not so-called "rich text" (actually HTML code, as you can see). At the very least, if you absolutely must send HTML code, you should instruct your mail program to also send plain text. People are reading this via Usenet and email and possibly using other ways as well. Depending on how they are receiving your post, sending HTML may be considered rude and a breach of etiquette (e.g. text-based news groups typically ban binary attachments, including HTML), or their client may not support HTML, or they may simply choose not to receive or read such posts. (Pure HTML is one of the most reliable signs of spam email.) So I'm afraid that I have no idea what you were trying to say in your post. Manually deciphering the message from the markup was too painful. I'm not likely to be the only one. If you would care to try again using plain text, you may get a better response rate. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ethan at stoneleaf.us Wed Apr 30 22:12:01 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 30 Apr 2014 19:12:01 -0700 Subject: freeze.py Message-ID: <5361AD71.7000704@stoneleaf.us> I'm running ubuntu 13.04, I have installed python2.7-dev and python2.7-example, but when I try to run freeze.py I get: Error: needed directory /usr/lib/python2.7/config not found I have the source for Python2.7 which I configured and built, but a search in that tree for a config file was fruitless. Any help greatly appreciated. -- ~Ethan~ From tjreedy at udel.edu Wed Apr 30 22:20:57 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 30 Apr 2014 22:20:57 -0400 Subject: Off-topic circumnavigating the earth in a mile or less [was Re: Significant digits in a float?] In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <5360F72F.2000102@stoneleaf.us> Message-ID: On 4/30/2014 7:46 PM, Ian Kelly wrote: > It also works if your starting point is (precisely) the north pole. I > believe that's the canonical answer to the riddle, since there are no > bears in Antarctica. For the most part, there are no bears within a mile of the North Pole either. "they are rare north of 88?" (ie, 140 miles from pole). https://en.wikipedia.org/wiki/Polar_bears They mostly hunt in or near open water, near the coastlines. I find it amusing that someone noticed and posted an alternate, non-canonical solution. How might a bear be near the south pole? As long as we are being creative, suppose some jokester mounts a near life-size stuffed black bear, made of cold-tolerant artificial materials, near but not at the South Pole. The intent is to give fright to naive newcomers. Someone walking in a radius 1/2pi circle about the pole might easily see it. -- Terry Jan Reedy From rosuav at gmail.com Wed Apr 30 21:57:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 1 May 2014 11:57:53 +1000 Subject: Off-topic circumnavigating the earth in a mile or less [was Re: Significant digits in a float?] In-Reply-To: References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <8td53bxud5.ln2@news.ducksburg.com> <5360F72F.2000102@stoneleaf.us> Message-ID: On Thu, May 1, 2014 at 9:46 AM, Ian Kelly wrote: > It also works if your starting point is (precisely) the north pole. I > believe that's the canonical answer to the riddle, since there are no > bears in Antarctica. Yeah but that's way too obvious! Anyway, it's rather hard to navigate due south from the north pole. Which way do you go? How do you know you're still going due south? Will the rocket even light in that climate? Important questions must be answered! ChrisA From ben at benfinney.id.au Wed Apr 30 22:42:38 2014 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 01 May 2014 12:42:38 +1000 Subject: freeze.py References: <5361AD71.7000704@stoneleaf.us> Message-ID: <858uqmi5i9.fsf@benfinney.id.au> Ethan Furman writes: > I'm running ubuntu 13.04, I have installed python2.7-dev and > python2.7-example, but when I try to run freeze.py I get: > > Error: needed directory /usr/lib/python2.7/config not found Where is ?freeze.py?? Is there documentation provided for the installation of that tool? What exact command do you issue in order to run it? -- \ ?I fly Air Bizarre. You buy a combination one-way round-trip | `\ ticket. Leave any Monday, and they bring you back the previous | _o__) Friday. That way you still have the weekend.? ?Steven Wright | Ben Finney From harrismh777 at gmail.com Wed Apr 30 23:03:45 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 30 Apr 2014 22:03:45 -0500 Subject: Slightly OT - using PyUIC from Eclipse References: <5360E0FC.70802@gmail.com> <5361a85a$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/30/14 8:50 PM, Steven D'Aprano wrote: > On Thu, 01 May 2014 01:49:25 +0100, Steve Simmons wrote: > >> >> >> >> >> >>
>>
On 30/04/2014 23:49, Fabio Zadrozny >> wrote:
>>
>>
> cite="mid:CANXBEFrqndqCeT-9Hgqz7jRCZcmp8nz4VE+ebf-BKsYr54qQqQ >> @mail.gmail.com" >> type="cite"> > > And that's about where I stopped reading. Post as quote: > I'm trying to set up a new dev environment using Windows 7; > Eclipse (Kepler); Python 3.3; PyDev and PyQt 5 and I've hit an > issue getting PyUIC to generate a python Qt class from within Eclipse. > > I'm using the following setup process (from Google Groups) modified > to match my PyQt5 configuration: > > 1. Click Run -> External Tools -> External Tools Configurations ... > 2. In the resulting dialog, click 'New' icon in the top left > 3. Under 'Name' put 'PyUIC' > 4. Under 'Location' enter 'C:\Program Files\Python\2.5\Python.exe' or > the path to your Python executable (probably C:\Python25\Python.exe) > 5. Under 'Arguments' enter '"C:\Program Files\Python\2.5\Lib\site- > packages\PyQt4\uic\pyuic.py" "${resource_loc}"' substituting the path > to your PyQt4 installation - be sure also to include the double quotes > 6. Change to the 'Common' tab and check 'File' under 'Standard Input/ > Output' and enter '${resource_loc}.py' > 7. Change to the 'Build' tab and uncheck 'Build before launch' > 8. Change to the 'Refresh' tab and check 'Refresh resources upon > completion' > 9. Click 'Apply' then 'Run' > and I'm getting the following traceback: > Traceback (most recent call last): > File "D:\Development\Python33\Lib\site-packages\PyQt5\uic\pyuic.py", > line 28, in > from .driver import Driver > SystemError: Parent module '' not loaded, cannot perform relative import > I tried this on Qt4 a week or so ago and it worked OK but Qt5 is giving me > an error message, so I guess I've either mis-transcribed or there's a difference > in the directory structure betwee PyQt4 & PyQt5. > > I'm more interested to learn how to read the traceback (insightfully) and > track it to the source of the problem, although it would be good to have it working too!! > > Steve Simmons > > PS Also posted to PyQT list. Cheers From ethan at stoneleaf.us Wed Apr 30 22:50:09 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 30 Apr 2014 19:50:09 -0700 Subject: freeze.py In-Reply-To: <858uqmi5i9.fsf@benfinney.id.au> References: <5361AD71.7000704@stoneleaf.us> <858uqmi5i9.fsf@benfinney.id.au> Message-ID: <5361B661.8000700@stoneleaf.us> On 04/30/2014 07:42 PM, Ben Finney wrote: > Ethan Furman writes: > >> I'm running ubuntu 13.04, I have installed python2.7-dev and >> python2.7-example, but when I try to run freeze.py I get: >> >> Error: needed directory /usr/lib/python2.7/config not found > > Where is ?freeze.py?? Is there documentation provided for the > installation of that tool? > > What exact command do you issue in order to run it? I think I have that part of it solved: make libainstall # not sure this was necessary, but it (re)copies # the wanted files into /usr/local/ib/python2.7/config .../python2.7/Tools/freeze/freeze.py -P /usr/local/ # so freeze looks in the right place Now I just have to figure out how to get _ctypes included... -- ~Ethan~ From harrismh777 at gmail.com Wed Apr 30 23:54:21 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Wed, 30 Apr 2014 22:54:21 -0500 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> Message-ID: On 4/30/14 7:02 PM, Dennis Lee Bieber wrote: >>> Sterling? Snort. K&E was the way to go. Absolutely, snort. I still have my K&E (Keuffel & Esser Co. N.Y.); made of wood... (when ships were wood, and men were steel, and sheep ran scared) ... to get to the S L T scales I have to pull the slide out (turn it over) and reinsert it. You're right, the CF and DF scales are missing, but the A B scales have the ? symbol where it should be (more or less). Mine is the 4058 C model, and you're right... has maths equivalents and conversions printed on the back... > I've misplaced the Sterling, but I'm fairly sure it was a deci-trig > log-log model. My high school '74 was the last class to learn the slide-rule using the Sterling (we paid a deposit to use the school's). I returned my Sterling to the teacher at year-end and got my deposit back. They are all probably in an old card-board box in the basement. I should ask. > > In the last 15-20 years I've added NIB versions of Faber-Castell 1/54 > Darmstadt, Pickett N-803-ES Dual-Base Log-Log, Pickett Cleveland Institute > of Electronics N-515-T, and a pair of Sama&Etani/Concise circular pocket > rules (models 200 and 600). I received my Pickett Model N4-T Vector-Type Log Log Dual-Base Speed Rule as a graduation | birthday gift... off to college with a leather cased slip stick hanging from my belt (I was invincable). Mine had the CF/m DF/m scales also -- folded at 2.3, the loge of 10 with ? where it should be (more or less). Copyright 1959... that baby was the king of slide rules... I pull it out from time to time, just for warm feelings. > > Heh... I wonder if the VEs would have noticed the CIE rule had lots of > electronics formulas on the back, if I'd taken it to the exam session where > I passed both General and Amateur Extra tests. I couldn't take a calculator > -- all of mine were programmable. But the slide-rule I took was just about > as perplexing to the VEs. > I carried my slide rule to my general class exam as well. The VE inspected it to be sure that certain stuff was not written in pencil between the scales! True story. Its not required today, of course, but I can still send/receive at 20 wpm. marcus W0MHH '73 From no.email at nospam.invalid Wed Apr 30 23:56:39 2014 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 30 Apr 2014 20:56:39 -0700 Subject: Significant digits in a float? References: <535f0f9f$0$29965$c3e8da3$5496439d@news.astraweb.com> <535f3bf7$0$11109$c3e8da3@news.astraweb.com> Message-ID: <7xeh0ekv7s.fsf@ruckus.brouhaha.com> Mark H Harris writes: > I received my Pickett Model N4-T Vector-Type Log Log Dual-Base > Speed Rule as a graduation | birthday gift... There is a nice Javascript simulation of the N4-ES here: http://www.antiquark.com/sliderule/sim/n4es/virtual-n4es.html Some other models are also on that site.