Re: Don't feed the troll...

2013-06-27 Thread Ian Kelly
On Wed, Jun 26, 2013 at 1:46 PM, Antoon Pardon wrote: > But you didn't even go to the trouble of trying to find out > what those concerns would be and how strong people feel about > them. You just took your assumptions about those concerns for > granted and proceeded from there. Jumping back in h

Re: Don't feed the troll...

2013-06-29 Thread Ian Kelly
On Thu, Jun 27, 2013 at 12:13 PM, Antoon Pardon wrote: > So what do you think would be a good approach towards people > who are behaving in conflict with this wish of yours? Just > bluntly call them worse than the troll or try to approach them > in a way that is less likely to antangonize them? I

Re: Closures in leu of pointers?

2013-06-29 Thread Ian Kelly
On Sat, Jun 29, 2013 at 11:02 AM, Antoon Pardon wrote: > Op 29-06-13 16:02, Michael Torrie schreef: > >> >> The real problem here is that you don't understand how python variables >> work. And in fact, python does not have variables. It has names that >> bind to objects. > > > I don't understand

Re: Closures in leu of pointers?

2013-06-29 Thread Ian Kelly
On Sat, Jun 29, 2013 at 1:33 PM, Steven D'Aprano wrote: > On Sat, 29 Jun 2013 12:20:45 -0700, cts.private.yahoo wrote: >> Without wanting to analyze it in too much depth now, I >> would want a local keyword to allow me to know I was protecting my >> variables, and a way to specify other scopes, wi

Re: Closures in leu of pointers?

2013-06-29 Thread Ian Kelly
On Sat, Jun 29, 2013 at 2:53 PM, Terry Reedy wrote: > # The alternative for either program or people is a 1-pass + backtracking > process where all understandings are kept provisional until the end of the > body and revised as required. 2 passes are simpler. Or simply an explicit declaration of s

Re: Closures in leu of pointers?

2013-06-29 Thread Ian Kelly
On Sat, Jun 29, 2013 at 10:32 PM, Terry Reedy wrote: > On 6/29/2013 5:21 PM, Ian Kelly wrote: >> Or simply an explicit declaration of scope at the beginning of the >> function definition. > > One of the reasons I switched to Python was to not have to do that, or > hardly

Re: Closures in leu of pointers?

2013-06-29 Thread Ian Kelly
On Sun, Jun 30, 2013 at 12:11 AM, Terry Reedy wrote: > On 6/30/2013 1:46 AM, Ian Kelly wrote: > >> On a related note, I think that generator functions should in some way >> be explicitly marked as such in the declaration, rather than needing >> to scan the entire f

Re: Closures in leu of pointers?

2013-06-30 Thread Ian Kelly
On Sun, Jun 30, 2013 at 4:07 AM, Antoon Pardon wrote: > I don't think this reference is as strong as you think it is. Here is > a paragraph somewhat lower: > > ] If a name is bound in a block, it is a local variable of that block, > ] unless declared as nonlocal. If a name is bound at the module l

Re: Closures in leu of pointers?

2013-06-30 Thread Ian Kelly
On Sun, Jun 30, 2013 at 11:13 AM, Ian Kelly wrote: > On Sun, Jun 30, 2013 at 4:07 AM, Antoon Pardon > wrote: >> I don't think this reference is as strong as you think it is. Here is >> a paragraph somewhat lower: >> >> ] If a name is bound in a block, i

Re: Stupid ways to spell simple code

2013-06-30 Thread Ian Kelly
On Sun, Jun 30, 2013 at 9:20 AM, Chris Angelico wrote: > Yeah, I cannot seriously imagine that the stdlib does anything like > the example I gave :) Pity nobody else is offering further examples, I > thought this might be a fun thread. Well, there is the "this" module. But its code is not *that*

Re: Don't feed the troll...

2013-06-30 Thread Ian Kelly
On Sun, Jun 30, 2013 at 11:25 AM, Antoon Pardon wrote: >>> So what do you think would be a good approach towards people >>> who are behaving in conflict with this wish of yours? Just >>> bluntly call them worse than the troll or try to approach them >>> in a way that is less likely to antangonize

Re: math functions with non numeric args

2013-06-30 Thread Ian Kelly
On Sun, Jun 30, 2013 at 12:46 PM, Andrew Z wrote: > Hello, > > print max(-10, 10) > 10 > print max('-10', 10) > -10 > > My guess max converts string to number bye decoding each of the characters > to it's ASCII equivalent? No, it leaves the types as they are but simply considers strings to be "gr

Re: Regular expression negative look-ahead

2013-07-01 Thread Ian Kelly
On Mon, Jul 1, 2013 at 8:27 PM, Jason Friedman wrote: > Found this: > http://stackoverflow.com/questions/13871833/negative-lookahead-assertion-not-working-in-python. > > This pattern seems to work: > pattern = re.compile(r"^(?!.*(CTL|DEL|RUN))") > > But I am not sure why. > > > On Mon, Jul 1, 2013

Re: python adds an extra half space when reading from a string or list

2013-07-02 Thread Ian Kelly
On Tue, Jul 2, 2013 at 12:54 AM, Antoon Pardon wrote: > Why about you just ignore me? > > Serious, a lot of people here seem to think that if someone is bothered > by someone else, the bothered person should just ignore the botherer. > > That is until something starts bothering these people themse

Re: how to calculate reputation

2013-07-02 Thread Ian Kelly
On Tue, Jul 2, 2013 at 3:43 PM, Surya Kasturi wrote: > Hi all, this seems to be quite stupid question but I am "confused".. > We set the initial value to 0, +1 for up-vote and -1 for down-vote! nice. > > I have a list of bool values True, False (True for up vote, False for > down-vote).. submitted

Re: how to calculate reputation

2013-07-02 Thread Ian Kelly
On Tue, Jul 2, 2013 at 4:19 PM, Surya Kasturi wrote: > I think I didnt explain it clearly.. let me make it clear.. > > 1. The database we are using is having BooleanField for it!! so, cant do > anything > 2. I am not looking for sorting algorithms .. just simple math :) It sounds > crazy but let m

Re: [SPOILERS] Python easter eggs

2013-07-03 Thread Ian Kelly
On Wed, Jul 3, 2013 at 8:03 AM, Ian Foote wrote: > On 03/07/13 14:29, Steven D'Aprano wrote: >> >> Most people are familiar with: >> >> import this >> >> >> and sometimes even with: >> >> from __future__ import braces >> >> >> But I'm aware of at least three more. Anyone care to give them? >> >> >

Re: [SPOILERS] Python easter eggs

2013-07-03 Thread Ian Kelly
On Wed, Jul 3, 2013 at 10:14 AM, Ian Kelly wrote: > On Wed, Jul 3, 2013 at 8:03 AM, Ian Foote wrote: >> On 03/07/13 14:29, Steven D'Aprano wrote: >>> >>> Most people are familiar with: >>> >>> import this >>> >>> >>> a

Re: DOS or not? [was Re: How to tell Script to use pythonw.exe ?]

2013-07-03 Thread Ian Kelly
On Wed, Jul 3, 2013 at 4:11 PM, Dennis Lee Bieber wrote: > On 03 Jul 2013 13:19:26 GMT, Steven D'Aprano > declaimed the following: > >>On Wed, 03 Jul 2013 14:00:49 +0100, Tim Golden wrote: >> >>> Goodness, I doubt if you'll find anyone who can seriously make a case >>> that the Windows command pr

Re: Default scope of variables

2013-07-04 Thread Ian Kelly
On Wed, Jul 3, 2013 at 11:32 PM, Steven D'Aprano wrote: >> Python lets you do that across but not within functions. >> >> But Javascript/ECMAScript/whatever doesn't give you that. A var >> declaration makes it function-local, no matter where the declaration is. >> That's pointless. C++, on the oth

Re: How to check for threads being finished?

2013-07-05 Thread Ian Kelly
On Fri, Jul 5, 2013 at 10:59 AM, Steven D'Aprano wrote: > I have a pool of worker threads, created like this: > > threads = [MyThread(*args) for i in range(numthreads)] > for t in threads: > t.start() > > > I then block until the threads are all done: > > while any(t.isAlive() for t in threads

Re: calculating binomial coefficients using itertools

2013-07-06 Thread Ian Kelly
On Fri, Jul 5, 2013 at 4:58 PM, Robert Hunter wrote: > from itertools import count, repeat, izip, starmap > > def binomial(n): > """Calculate list of Nth-order binomial coefficients using itertools.""" > > l = range(2) > for _ in xrange(n): > indices = izip(count(-1), count(1),

Re: Editor Ergonomics [was: Important features for editors]

2013-07-06 Thread Ian Kelly
On Sat, Jul 6, 2013 at 9:04 AM, rusi wrote: > On Saturday, July 6, 2013 7:40:39 PM UTC+5:30, Skip Montanaro wrote: >> > The fact that rms has crippling RSI should indicate that >> > emacs' ergonomics is not right. >> >> Kind of a small sample size, don't you think? Hopefully we can kill >> this me

Re: homework + obfuscation ... this might work ...

2013-07-08 Thread Ian Kelly
On Mon, Jul 8, 2013 at 2:43 PM, Skip Montanaro wrote: > I have an idea. Take the threads where students ask the list to do > their homework for them (but don't have the cojones to admit that's > what they are doing), and merge them with the obfuscated Python idea. > A group of people could come u

Re: Default scope of variables

2013-07-09 Thread Ian Kelly
On Tue, Jul 9, 2013 at 1:35 AM, Frank Millman wrote: > When any of them need any database access, whether for reading or for > updating, they execute the following - > > with db_session as conn: > conn.transaction_active = True # this line must be added if > updating > conn.cu

Re: the general development using Python

2013-07-09 Thread Ian Kelly
On Mon, Jul 8, 2013 at 10:46 PM, CM wrote: >> There are projects that "bundle" the CPython interpreter with your >> project, but this makes those files really big. > > Maybe 5-20 MB. That's a lot bigger than a few hundred K, but it's not that > important to keep size down, really. Funny story:

Re: Default scope of variables

2013-07-09 Thread Ian Kelly
On Tue, Jul 9, 2013 at 10:07 AM, Ethan Furman wrote: > You could also do it like this: > > def updating(self): > self.transaction_active = True > return self Yes, that would be simpler. I was all set to point out why this doesn't work, and then I noticed that the location of

Re: Default scope of variables

2013-07-09 Thread Ian Kelly
On Tue, Jul 9, 2013 at 11:23 AM, Ethan Furman wrote: > On 07/09/2013 09:44 AM, Ian Kelly wrote: >> >> On Tue, Jul 9, 2013 at 10:07 AM, Ethan Furman wrote: >>> >>> You could also do it like this: >>> >>> def updating(self): >>>

Re: multiprocessing

2013-07-09 Thread Ian Kelly
On Tue, Jul 9, 2013 at 12:09 PM, wrote: > I am a beginner with Python, coming from R, and I am having problems with > parallelization with the multiprocessing module. I know that other people > have asked similar questions but the answers were mostly over my head. > > Here is my problem: I trie

Re: Recursive class | can you modify self directly?

2013-07-09 Thread Ian Kelly
On Tue, Jul 9, 2013 at 4:01 PM, Russel Walker wrote: > Sorry for the vague title. Probably best to just show you the code that > explains it better. > > This is a simplified example of what I want to do: > > > # THIS DOESN'T WORK > from random import choice > > class Expr(object): > """ >

Re: Recursive class | can you modify self directly?

2013-07-09 Thread Ian Kelly
On Tue, Jul 9, 2013 at 4:18 PM, Ian Kelly wrote: > If you actually want to modify the current object, you would need to > do something like: > > def expand(self): > import copy > self.expr = Expr(self.expr, self.op, self.val) >

Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 2:32 AM, Mats Peterson wrote: > Chris Angelico wrote: >> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson wrote: >>> A moderator who calls himself “animuson” on Stack Overflow doesn’t >>> want to face the truth. He has deleted all my postings regarding Python >>> regular ex

Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 2:42 AM, Mats Peterson wrote: > Chris Angelico wrote: >> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson wrote: >>> A moderator who calls himself “animuson” on Stack Overflow doesn’t >>> want to face the truth. He has deleted all my postings regarding Python >>> regular ex

Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 2:46 AM, Mats Peterson wrote: >> Then they would have full control of this list and what gets pos > > Ahhh so this is pos, right? Telling the truth? Interesting. I don't know what you mean by that, but since the joke appears to have flown over your head, I'll explain i

Re: Default scope of variables

2013-07-10 Thread Ian Kelly
On Tue, Jul 9, 2013 at 11:54 PM, Frank Millman wrote: > You had me worried there for a moment, as that is obviously an error. > > Then I checked my actual code, and I find that I mis-transcribed it. It > actually looks like this - > > with db_session as conn: > db_session.transaction_a

Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 6:06 AM, Mats Peterson wrote: > Joshua Landau wrote: >> If you actually can satisfy these basic standards for a comparison (as >> I'm sure any competent person with so much bravo could) I'd be willing >> to converse with you. I'd like to see these results where Python comp

Re: Prime number generator

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 8:00 AM, Chris Angelico wrote: > And now for something completely different. > > I knocked together a prime number generator, just for the fun of it, > that works like a Sieve of Eratosthenes but unbounded. It keeps track > of all known primes and the "next composite" that

Re: Prime number generator

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 10:16 AM, Ian Kelly wrote: > The other interesting thing about my sieve is that it's a recursive > generator. I'll dig it up later and share it. As promised. Apologies for the excessive commenting. As noted, this implementation is a recursive generato

Re: Prime number generator

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 11:47 AM, Joshua Landau wrote: >>> If you care about speed, you might want to check the heapq module. Removing >>> the smallest item and inserting a new item in a heap both cost O(log(N)) >>> time, while finding the minimum in a dictionary requires iterating over the >>>

Re: the general development using Python

2013-07-10 Thread Ian Kelly
On Tue, Jul 9, 2013 at 10:49 PM, CM wrote: > Can all the installation of the runtimes be done with an installer that is > itself an .exe, like with PyInstaller? If so, that's probably fine. It should be noted that PyInstaller is confusingly named. It actually creates standalone executables, no

Re: Recursive class | can you modify self directly?

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 4:50 PM, Russel Walker wrote: > def append(self, x): > if len(self) < 3: > list.append(self, x) > else: > oldself = LRExpression(*self) > self.__init__(oldself) > self.append(x) It's probably not wise to b

Re: xslice idea | a generator slice

2013-07-11 Thread Ian Kelly
On Thu, Jul 11, 2013 at 8:52 AM, Russel Walker wrote: > Just some dribble, nothing major. > > I like using slices but I also noticed that a slice expression returns a new > sequence. > > I sometimes find myself using them in a for loop like this: > > > seq = range(10) > for even in seq[::2]: >

Re: xslice idea | a generator slice

2013-07-11 Thread Ian Kelly
On Thu, Jul 11, 2013 at 10:34 AM, Oscar Benjamin wrote: > On 11 July 2013 17:21, Russel Walker wrote: >> To confess, this is the second time I've made the mistake of trying to >> implement generator like functionality of a builtin when there already is on >> in itertools. Need to start studying

Re: xslice idea | a generator slice

2013-07-11 Thread Ian Kelly
On Thu, Jul 11, 2013 at 1:58 PM, Fábio Santos wrote: > Isn't all of itertools implemented in C? If we are not using a python-level > and not-so-fast __getitem__ I would wager the C version is a lot faster. > > And if the input is indexable could I assume that it is not too large to > have around i

Re: Callable or not callable, that is the question!

2013-07-12 Thread Ian Kelly
On Thu, Jul 11, 2013 at 8:12 PM, Steven D'Aprano wrote: > On Thu, 11 Jul 2013 15:05:59 +0200, Ulrich Eckhardt wrote: > >> Hello! >> >> I just stumbled over a case where Python (2.7 and 3.3 on MS Windows) >> fail to detect that an object is a function, using the callable() >> builtin function. Inve

Re: GeoIP2 for retrieving city and region ?

2013-07-12 Thread Ian Kelly
On Fri, Jul 12, 2013 at 10:32 AM, Νικόλας wrote: > > I know i have asked before but hwta i get is ISP city not visitors precise > city. > > GeoLiteCity.dat isnt accurate that's why it comes for free. > i must somehow get access to GeoIPCity.dat which is the full version. > > And of course it can b

Re: Is this a bug?

2013-07-16 Thread Ian Kelly
On Tue, Jul 16, 2013 at 9:25 AM, Jack Bates wrote: > Ah, thank you Chris Angelico for explaining how this is like what happens > with default arguments to a function and Joshua Landau for pointing out how > assignments inside class bodies refer to properties of "self" on the LHS. It > makes sense

Re: Storing a very large number

2013-07-17 Thread Ian Kelly
On Wed, Jul 17, 2013 at 1:21 PM, Hasit Mistry wrote: > I came across a problem that requires me to store a very large number (say >>10^100). How do I do it efficiently? Both the int and Decimal types support arbitrary precision. Floats do not. > And also, how do I select a particular number (sa

Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition

2013-07-18 Thread Ian Kelly
On Jul 18, 2013 4:23 PM, "CTSB01" wrote: > > File "", line 2 > ... rtn = [] > ^ The "..." is the continuation prompt from the interactive interpreter, not part of the code. Don't paste it into Python. -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition

2013-07-18 Thread Ian Kelly
On Thu, Jul 18, 2013 at 5:04 PM, CTSB01 wrote: > Thanks Ian. That worked regarding that issue. Now I have an 'invalid > syntax' issue unfortunately. > >>> def phi_m(x,m): > rtn = [] > for n2 in range(0, len(x)*m - 2): > n = n2 / m > r = n2 - n * m > rtn.appen

Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition

2013-07-18 Thread Ian Kelly
On Thu, Jul 18, 2013 at 5:42 PM, Ian Kelly wrote: > On Thu, Jul 18, 2013 at 5:04 PM, CTSB01 wrote: >> Thanks Ian. That worked regarding that issue. Now I have an 'invalid >> syntax' issue unfortunately. >> >>>> def phi_m(x,m): >>

Re: Python 3: dict & dict.keys()

2013-07-24 Thread Ian Kelly
On Tue, Jul 23, 2013 at 8:11 PM, Steven D'Aprano wrote: > Basically, views are set-like, not list-like. The keys and items views are set-like. The values view is not. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3: dict & dict.keys()

2013-07-24 Thread Ian Kelly
On Wed, Jul 24, 2013 at 8:58 AM, Skip Montanaro wrote: >> What do you mean? Why would you want to create a temporary list just to >> iterate over it explicitly or implicitly (set, sorted, max,...)? > > Because while iterating over the keys, he might also want to add or > delete keys to/from the di

Re: Python 3: dict & dict.keys()

2013-07-25 Thread Ian Kelly
On Thu, Jul 25, 2013 at 2:13 AM, Peter Otten <__pete...@web.de> wrote: > Chris Angelico wrote: > >> On Thu, Jul 25, 2013 at 5:04 PM, Steven D'Aprano >> wrote: >>> - Views support efficient (O(1) in the case of keys) membership testing, >>> which neither iterkeys() nor Python2 keys() does. >> >> To

Re: RE Module Performance

2013-07-25 Thread Ian Kelly
On Wed, Jul 24, 2013 at 9:34 AM, Chris Angelico wrote: > On Thu, Jul 25, 2013 at 12:17 AM, David Hutto wrote: >> I've screwed up plenty of times in python, but can write code like a pro >> when I'm feeling better(on SSI and medicaid). An editor can be built simply, >> but it's preference that mak

Re: RE Module Performance

2013-07-25 Thread Ian Kelly
On Thu, Jul 25, 2013 at 12:18 PM, Steven D'Aprano wrote: > On Fri, 26 Jul 2013 01:36:07 +1000, Chris Angelico wrote: > >> On Fri, Jul 26, 2013 at 1:26 AM, Steven D'Aprano >> wrote: >>> On Thu, 25 Jul 2013 14:36:25 +0100, Jeremy Sanders wrote: "To conserve memory, Emacs does not hold fixed-le

Re: RE Module Performance

2013-07-25 Thread Ian Kelly
On Thu, Jul 25, 2013 at 8:48 PM, Steven D'Aprano wrote: > UTF-8 uses a flexible representation on a character-by-character basis. > When parsing UTF-8, one needs to look at EVERY character to decide how > many bytes you need to read. In Python 3, the flexible representation is > on a string-by-str

Re: How would I do this?

2013-07-25 Thread Ian Kelly
On Thu, Jul 25, 2013 at 9:16 PM, John Doe wrote: > Hey guys, > > I;m working on making a chess program and I hit a wall. I have no idea how to > get the position of the chess pieces. I have the chess board 1-8 and A-H for > black as well as 1-8 and a-h for white. i just have to figure out how to

Re: How would I do this?

2013-07-25 Thread Ian Kelly
On Thu, Jul 25, 2013 at 9:40 PM, wrote: > Thank you for the quick reply. Unfortunately I'm still a little confused... > How might I implement that into my current code? Where you print spaces indicating an empty space, you need to look up the current square in the board data structure to see wh

Re: RE Module Performance

2013-07-26 Thread Ian Kelly
On Fri, Jul 26, 2013 at 9:37 PM, Steven D'Aprano wrote: > See the similarity now? Both flexibly change the width used by code- > points, UTF-8 based on the code-point itself regardless of the rest of > the string, Python based on the largest code-point in the string. No, I think we're just using

Re: RE Module Performance

2013-07-27 Thread Ian Kelly
On Sat, Jul 27, 2013 at 12:21 PM, wrote: > Back to utf. utfs are not only elements of a unique set of encoded > code points. They have an interesting feature. Each "utf chunk" > holds intrisically the character (in fact the code point) it is > supposed to represent. In utf-32, the obvious case, i

Re: Unexpected results comparing float to Fraction

2013-07-29 Thread Ian Kelly
On Mon, Jul 29, 2013 at 9:43 AM, Steven D'Aprano wrote: > Comparing floats to Fractions gives unexpected results: > > # Python 3.3 > py> from fractions import Fraction > py> 1/3 == Fraction(1, 3) > False > > but: > > py> 1/3 == float(Fraction(1, 3)) > True > > > I expected that float-to-Fraction c

Re: Unexpected results comparing float to Fraction

2013-07-29 Thread Ian Kelly
On Mon, Jul 29, 2013 at 10:20 AM, Chris Angelico wrote: > On Mon, Jul 29, 2013 at 5:09 PM, MRAB wrote: >> I'm surprised that Fraction(1/3) != Fraction(1, 3); after all, floats >> are approximate anyway, and the float value 1/3 is more likely to be >> Fraction(1, 3) than Fraction(6004799503160661,

Re: collections.Counter surprisingly slow

2013-07-29 Thread Ian Kelly
On Mon, Jul 29, 2013 at 5:49 AM, Joshua Landau wrote: > Also, couldn't Counter just extend from defaultdict? It could, but I expect the C helper function in 3.4 will be faster since it doesn't even need to call __missing__ in the first place. And the cost (both in terms of maintenance and run-tim

Re: Unexpected results comparing float to Fraction

2013-07-29 Thread Ian Kelly
On Mon, Jul 29, 2013 at 11:04 AM, MRAB wrote: > On 29/07/2013 17:40, Ian Kelly wrote: >> At the point where the float is exactly equal to the value you get >> from the floating-point division 1/3. If it's some other float then >> the user didn't get there by

Re: Unexpected results comparing float to Fraction

2013-07-29 Thread Ian Kelly
On Mon, Jul 29, 2013 at 12:16 PM, Rotwang wrote: > On 29/07/2013 17:40, Ian Kelly wrote: >> At the point where the float is exactly equal to the value you get >> from the floating-point division 1/3. > > > But the interpreter has no way of knowing that the value 1/3 tha

Re: Unexpected results comparing float to Fraction

2013-07-29 Thread Ian Kelly
On Jul 29, 2013 1:37 PM, "Serhiy Storchaka" wrote: > > 29.07.13 19:09, MRAB написав(ла): > >> I'm surprised that Fraction(1/3) != Fraction(1, 3); after all, floats >> are approximate anyway, and the float value 1/3 is more likely to be >> Fraction(1, 3) than Fraction(6004799503160661, 180143985094

Re: Pyglet on Python3.x, problems

2013-07-29 Thread Ian Kelly
On Mon, Jul 29, 2013 at 4:04 PM, John Ladasky wrote: > pyglet-1.2alpha1/examples/programming_guide/hello_world.py runs fine. > > pyglet-1.2alpha1/examples/programming_guide/image_viewer.py also runs fine. > > pyglet-1.2alpha1/examples/programming_guide/animation.py produces an error. > Here's th

Re: Share Code: Laptop Lid State

2013-07-30 Thread Ian Kelly
On Jul 30, 2013 10:06 AM, "Chris Angelico" wrote: > > On Tue, Jul 30, 2013 at 3:06 PM, Devyn Collier Johnson > wrote: > > Aloha everyone! > > > >I attached a script that I thought I could share with everyone for your > > help. This Python3 script only works on Unix systems. It prints the curr

Re: OrderedEnum examples

2013-07-30 Thread Ian Kelly
On Tue, Jul 30, 2013 at 12:18 PM, Bas van der Wulp wrote: > Replacing each occurrence of self._value with either self._value_ or > self.value in the examples seems to make them work as expected. > > Are both examples incorrect, or not intended to work in Python 2.x? The _value attribute was renam

Re: Prime number generator

2013-07-31 Thread Ian Kelly
On Tue, Jul 30, 2013 at 4:58 AM, Albert van der Horst wrote: > Notice that all values from i on are possibly present. > So you are better off with a list indexed by forthcoming i's and > each item containing a list of primes. What you do then, more or less, > is keep track of all dividers of prime

Re: Is it that easy to install Python ?

2013-07-31 Thread Ian Kelly
On Wed, Jul 31, 2013 at 4:08 AM, wrote: > OK thanks for your answers. > So Python is not a daemon. Is it? No. > Does it have a config file? Not as such. Arbitrary site-specific customization can be done by creating a sitecustomize module, but this is not standard. There are also some environ

Re: Is it that easy to install Python ?

2013-07-31 Thread Ian Kelly
On Wed, Jul 31, 2013 at 10:44 AM, Ian Kelly wrote: > and then set the PYTHONHOME environment variable to /usr/lib. Rather, just /usr. -- http://mail.python.org/mailman/listinfo/python-list

Re: Repository of non-standard modules.

2013-07-31 Thread Ian Kelly
On Wed, Jul 31, 2013 at 5:02 AM, Chris Angelico wrote: > On Wed, Jul 31, 2013 at 11:53 AM, Gabor Urban wrote: >> Hi, >> >> I am to start a new free-time project in the next couple of weeks. I am >> ready to use open accessible Python modules not wanting to reinvent the weel >> :-) >> Is there any

Re: Lambda function Turing completeness

2013-07-31 Thread Ian Kelly
On Wed, Jul 31, 2013 at 12:53 AM, Musical Notation wrote: > Is it possible to write a Turing-complete lambda function (which does not > depend on named functions) in Python? Yes, lambda functions are Turing-complete. You can get anonymous recursion by defining the function to take a recursive f

Re: Py3.3 unicode literal and input()

2012-06-20 Thread Ian Kelly
On Jun 18, 2012 8:07 AM, "jmfauth" wrote: > A string is a string, a "piece of text", period. > > I do not see why a unicode literal and an (well, I do not > know how the call it) a "normal class " should behave > differently in code source or as an answer to an input(). Strings are a data type th

Re: Is python a interpreted or compiled language?

2012-06-20 Thread Ian Kelly
On Wed, Jun 20, 2012 at 5:30 PM, gmspro wrote: > > Hi, > > Is python a interpreted or compiled language? Like other languages that use a VM bytecode, it's a little bit of both. The actual Python code is compiled into Python bytecode. The bytecode is interpreted. > What does happen after this c

Re: Is python a interpreted or compiled language?

2012-06-20 Thread Ian Kelly
On Wed, Jun 20, 2012 at 7:27 PM, Chris Angelico wrote: > Java's bytecode and source code are two distinct languages, both well > documented and separately usable (and with their own distinct > limitations - there are things you can do in Java bytecode that you > cannot do in Java source). I can t

Re: How can i call array_length to get the length of array object?

2012-06-23 Thread Ian Kelly
On Sat, Jun 23, 2012 at 8:23 PM, gmspro wrote: > I'm trying to call this function, > http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657 > > Is that possible to call that function? > > I know it's possible to do: > >>>len(arr) You call it just like that. array_length is th

Re: Why has python3 been created as a seperate language where there is still python2.7 ?

2012-06-27 Thread Ian Kelly
On Jun 27, 2012 9:57 PM, wrote: > [1] of course that is when using `filestr.count("print")` -- I assume that the word "print" is not used excessively in comments or docstrings. Someone else can do a less naive search if they like. Or as part of a longer name, e.g. the traceback.print_* family of

Re: code review

2012-07-02 Thread Ian Kelly
On Sat, Jun 30, 2012 at 2:50 PM, Thomas Jollans wrote: > Which of the two comparisons is done first anyway? > "In the face of ambiguity, refuse the temptation to guess." I would consider that a pro, not a con, because the C-like way is much worse in this regard. Using operator chaining, is "1 <

Evolution (was: code review)

2012-07-03 Thread Ian Kelly
On Mon, Jul 2, 2012 at 1:35 PM, Rick Johnson wrote: > I am reminded of a story: A few years back a very nice old woman > offered to give me her typewriter. She said: "i might need to type a > letter one day and it would good to have around". It was a nice > typewriter for 1956, but she had no idea

Re: code review

2012-07-03 Thread Ian Kelly
On Tue, Jul 3, 2012 at 11:53 AM, Kushal Kumaran wrote: > On Sat, Jun 30, 2012 at 3:34 PM, Alister wrote: >> On Fri, 29 Jun 2012 09:03:22 -0600, Littlefield, Tyler wrote: >> >>> On 6/29/2012 1:31 AM, Steven D'Aprano wrote: On Thu, 28 Jun 2012 20:58:15 -0700, alex23 wrote: > On Jun 29

Re: code review

2012-07-03 Thread Ian Kelly
On Tue, Jul 3, 2012 at 12:18 PM, John Gordon wrote: > In Kushal Kumaran > writes: > >> I haven't actually seen the rest of the code, but I would like to >> point out that applications placing maximum length limits on passwords >> are extremely annoying. > > As a practical matter, doesn't there

Re: Why site-packages?

2012-07-03 Thread Ian Kelly
On Tue, Jul 3, 2012 at 2:40 PM, Dan Stromberg wrote: > > Why is it that so much 3rd party python code gets installed to > site-packages? Because that's what site-packages is for? > Even for things that are almost certainly going to be used by a single > application? > > Even for things you might

Re: Why site-packages?

2012-07-03 Thread Ian Kelly
On Tue, Jul 3, 2012 at 3:34 PM, Dan Stromberg wrote: > If it was intended to be reusable code, I'd think it -should- go in > site-packages. > > But so much code in site-packages isn't intended to be reusable. Can you give some examples? Looking through my site-packages directory, everything in t

Re: Why site-packages?

2012-07-03 Thread Ian Kelly
On Tue, Jul 3, 2012 at 4:38 PM, Dan Stromberg wrote: >> Right now this all seems highly speculative to me. I think it might >> be informative, either to you or to me, to do an actual timing test. >> Why don't you try setting up two side-by-side installations of Python, >> one with all the site-pa

Re: Why site-packages?

2012-07-03 Thread Ian Kelly
On Tue, Jul 3, 2012 at 5:06 PM, Ian Kelly wrote: > On Tue, Jul 3, 2012 at 4:38 PM, Dan Stromberg wrote: >>> Right now this all seems highly speculative to me. I think it might >>> be informative, either to you or to me, to do an actual timing test. >>> Why don&#x

Re: simpler increment of time values?

2012-07-05 Thread Ian Kelly
On Thu, Jul 5, 2012 at 7:56 AM, Chris Angelico wrote: > I'm not familiar with the Python classes (I tend to think in terms of > language-agnostic algorithms first, and specific libraries/modules/etc > second), but if you're working with simple integer seconds, your > datelessness is just modulo ar

Re: Question about weakref

2012-07-06 Thread Ian Kelly
On Fri, Jul 6, 2012 at 1:00 AM, Frank Millman wrote: > I have investigated a bit further, and now I have a clue as to what is > happening, though not a full understanding. > > If you use 'b = weakref.ref(obj)', 'b' refers to the weak reference, and > 'b()' refers to the referenced object. > > If y

Re: Question about weakref

2012-07-06 Thread Ian Kelly
On Fri, Jul 6, 2012 at 11:04 AM, Ian Kelly wrote: > On that, I'm really not sure. I tried to reproduce the problem > locally and wasn't able to. What build of Python are you using, and > on what platform? I spoke too soon, I am able to reproduce it. I think what's go

Re: Question about weakref

2012-07-06 Thread Ian Kelly
On Fri, Jul 6, 2012 at 11:48 AM, Ian Kelly wrote: > def del_b(self, b): > for i, x in enumerate(self.array): > if b is x: > del self.array[i] That should probably have an explicit break on the end: def del_b(self, b): for i, x

Re: Python Interview Questions

2012-07-10 Thread Ian Kelly
On Tue, Jul 10, 2012 at 4:26 PM, Dennis Lee Bieber wrote: > On Tue, 10 Jul 2012 09:05:50 -0700, Ethan Furman > declaimed the following in gmane.comp.python.general: > >> As an example from today, if someone claimed to have 5+ years of Python >> experience, but didn't know that 'with' was standard

Re: lambda in list comprehension acting funny

2012-07-11 Thread Ian Kelly
On Wed, Jul 11, 2012 at 4:28 AM, Colin J. Williams wrote: > I don't understand why you would expect 1, 2, 4. Because: funcs[0](2) == 2 ** 0 == 1 funcs[1](2) == 2 ** 1 == 2 funcs[2](2) == 2 ** 2 == 4 > Perhaps parentheses will help the order of evaluation: > > funcs = [(lambda x: x**i) for i in

Re: lambda in list comprehension acting funny

2012-07-12 Thread Ian Kelly
On Wed, Jul 11, 2012 at 9:59 PM, Steven D'Aprano wrote: > On Wed, 11 Jul 2012 08:41:57 +0200, Daniel Fetchinson wrote: > >> funcs = [ lambda x: x**i for i in range( 5 ) ] > > Here's another solution: > > from functools import partial > funcs = [partial(lambda i, x: x**i, i) for i in range(5)] > >

Re: lambda in list comprehension acting funny

2012-07-13 Thread Ian Kelly
On Fri, Jul 13, 2012 at 11:53 AM, Hans Mulder wrote: > The function `function` refers to a variable `VERBOSE` that > isn't local. In some programming langauages, the interpreter > would then scan the call stack at run-time, looking for a scope > where that name is defined. It would find the loca

Re: code review

2012-07-14 Thread Ian Kelly
On Fri, Jul 13, 2012 at 5:09 PM, Terry Reedy wrote: > >> From now on, for each operator I would have to remember wether it >> is a supposedly comparison operator or not. > > > I believe the following rule is true: if a op b is True or False raises, I don't follow. Raises what? > then op is a po

Re: Implicit conversion to boolean in if and while statements

2012-07-15 Thread Ian Kelly
On Sun, Jul 15, 2012 at 4:56 AM, Steven D'Aprano wrote: > (For the record, I can only think of one trap for the unwary: time > objects are false at *exactly* midnight.) Ugh, that's irritating. I can't think of any scenario where I would ever want the semantics "if timeval (is not midnight):". T

Re: Request for useful functions on dicts

2012-07-15 Thread Ian Kelly
On Sat, Jul 14, 2012 at 5:56 PM, Leif wrote: > Hi, everybody. I am trying to collect all the functions I've found useful for > working with dicts into a library: > > https://github.com/leifp/dictutil > > If you have a favorite dict-related func / class, or know of similar > projects, please let

Re: Implicit conversion to boolean in if and while statements

2012-07-15 Thread Ian Kelly
On Sun, Jul 15, 2012 at 11:16 AM, Andrew Berg wrote: > On 7/15/2012 11:19 AM, Ian Kelly wrote: >> Ugh, that's irritating. I can't think of any scenario where I would >> ever want the semantics "if timeval (is not midnight):". > It&#

<    1   2   3   4   5   6   7   8   9   10   >