Re: help

2013-01-07 Thread Ian Kelly
On Mon, Jan 7, 2013 at 12:37 PM, Chris Angelico wrote: > On Tue, Jan 8, 2013 at 10:35 AM, wrote: >> download wxpython but whenever I try to use it I get this I’m a beginner in >> python pls I need help. >> >> ImportError: DLL load failed: %1 is not a valid Win32 application. > > Did you download

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2013-01-08 Thread Ian Kelly
On Tue, Jan 8, 2013 at 12:16 PM, Neal Becker wrote: > Did you intend to give anyone permission to use the code? I see only a > copyright notice, but no permissions. It also says "Licence: python, Copyright notice may not be altered." Which suggests to me that the intent is that it be licensed u

Re: How to tell how many weeks apart two datetimes are?

2013-01-08 Thread Ian Kelly
On Tue, Jan 8, 2013 at 2:22 PM, Roy Smith wrote: > How do you tell how many weeks apart two datetimes (t1 and t2) are? > The "obvious" solution would be: > > weeks = (t2 - t1) / timedelta(days=7) > > but that doesn't appear to be allowed. Is there some fundamental > reason why timedelta division

Re: How to tell how many weeks apart two datetimes are?

2013-01-08 Thread Ian Kelly
On Tue, Jan 8, 2013 at 2:33 PM, Ian Kelly wrote: > On Tue, Jan 8, 2013 at 2:22 PM, Roy Smith wrote: >> How do you tell how many weeks apart two datetimes (t1 and t2) are? >> The "obvious" solution would be: >> >> weeks = (t2 - t1) / timedelta(days=7) >&g

Re: average time calculation??

2013-01-10 Thread Ian Kelly
On Thu, Jan 10, 2013 at 1:31 PM, pmec wrote: > Hi Oscar, again I do apologize for my beginner mistakes, I've changed the > code taking in consideration some of your and MRAB suggestions. > > Could you give me an example on how could I use the datetime.timedelta > function in this particular case

Re: String concatenation benchmarking weirdness

2013-01-11 Thread Ian Kelly
On Fri, Jan 11, 2013 at 12:03 PM, Rotwang wrote: > Hi all, > > the other day I 2to3'ed some code and found it ran much slower in 3.3.0 than > 2.7.2. I fixed the problem but in the process of trying to diagnose it I've > stumbled upon something weird that I hope someone here can explain to me. In >

Re: Dependency management in Python?

2013-01-11 Thread Ian Foote
n. I also like to use virtualenvwrapper for convenience, but it isn't necessary. Ian F -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: Module access syntax

2013-01-11 Thread Ian Kelly
On Fri, Jan 11, 2013 at 9:34 PM, Rick Johnson wrote: > No the rules are: > * "Colon" must be used to access a "module" (or a package). > * "Dot" must be used to access a "module member". What about module a that does not natively contain module b, but imports it as a member like so? a.py

Re: PyWart: Import resolution order

2013-01-11 Thread Ian Kelly
On Fri, Jan 11, 2013 at 10:28 PM, Rick Johnson wrote: > On Friday, January 11, 2013 12:30:27 AM UTC-6, Chris Angelico wrote: >> Why is it better to import from the current directory first? > > Opps. I was not explicit enough with my explanation :). I meant, "look in the > current directory FIRST

Re: String concatenation benchmarking weirdness

2013-01-12 Thread Ian Kelly
On Sat, Jan 12, 2013 at 1:38 AM, wrote: > The difference between a correct (coherent) unicode handling and ... This thread was about byte string concatenation, not unicode, so your rant is not even on-topic here. -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: Module access syntax

2013-01-14 Thread Ian Kelly
On Sun, Jan 13, 2013 at 10:22 PM, Rick Johnson wrote: > You are missing the point of this syntax. The colon is to access MODULE > NAMESPACE. The dot is to access MODULE MEMBERS. A module CAN BE another > module's MEMBER. > > You are also unable to grasp this simple logical fact: Once you arrive

Re: PyWart: Module access syntax

2013-01-14 Thread Ian Kelly
On Mon, Jan 14, 2013 at 11:51 AM, Ian Kelly wrote: >> Because modules and objects are not the same and someone who is reading the >> source code NEEDS to know which "path members" are /modules/ and which "path >> members" are /objects/. And he needs to kn

Re: PyWart: Module access syntax

2013-01-14 Thread Ian Kelly
On Mon, Jan 14, 2013 at 12:35 PM, D'Arcy J.M. Cain wrote: > On Mon, 14 Jan 2013 11:51:50 -0700 > Ian Kelly wrote: >> On Sun, Jan 13, 2013 at 10:22 PM, Rick Johnson >> wrote: > ...Whatever > >> If you want us to understand the syntax, then you need to defi

Re: code explanation

2013-01-14 Thread Ian Kelly
On Mon, Jan 14, 2013 at 9:51 PM, Rodrick Brown wrote: > import sys > > PY3K = sys.version_info >= (3,) > > > methods = set([ > "__iter__", > "__len__", > "__contains__", > > "__lt__", > "__le__", > "__eq__", > "__ne__", > "__gt__", > "__ge__", > > "__add__",

Re: Is there a more elegant way to handle determing fail status?

2013-01-15 Thread Ian Kelly
On Tue, Jan 15, 2013 at 4:24 PM, J wrote: > The exit code determination above works, but it just feels inelegant. > It feels like there's a better way of implementing that, but I can't > come up with one that still honors the fail level properly (e.g. other > solutions will fail on medium, but won

Re: Beginner Tutorials

2013-01-18 Thread Ian Foote
r reason you disable right-click with javascript? Regards, Ian F -- http://mail.python.org/mailman/listinfo/python-list

Re: Beginner Tutorials

2013-01-18 Thread Ian Foote
7;s my output: >>> name = input("What is your name? ") What is your name? Ian >>> print("Hello" + name + "!") HelloIan! Your final print should be: print("Hello " + name + "!") Regards, Ian F -- http://mail.python.org/mailman/listinfo/python-list

Re: finding abc's

2013-01-25 Thread Ian Kelly
On Fri, Jan 25, 2013 at 10:40 AM, lars van gemerden wrote: > Hi all, > > i was writing a function to determine the common base class of a number > classes: > [...] > > and ran common_base(int, float), hoping to get numbers.Number. > > this did not work because abstract base classes are not always

Re: Retrieving an object from a set

2013-01-25 Thread Ian Kelly
On Fri, Jan 25, 2013 at 4:14 PM, Arnaud Delobelle wrote: > Dear Pythoneers, > > I've got a seemingly simple problem, but for which I cannot find a > simple solution. > > I have a set of objects (say S) containing an object which is equal to > a given object (say x). So > > x in S > > is true.

Re: Retrieving an object from a set

2013-01-25 Thread Ian Kelly
On Fri, Jan 25, 2013 at 4:30 PM, Ian Kelly wrote: > On Fri, Jan 25, 2013 at 4:14 PM, Arnaud Delobelle wrote: >> Dear Pythoneers, >> >> I've got a seemingly simple problem, but for which I cannot find a >> simple solution. >> >> I have a set of objects

Re: Retrieving an object from a set

2013-01-25 Thread Ian Kelly
On Fri, Jan 25, 2013 at 4:45 PM, MRAB wrote: > You could first limit the search to only those which it could be: > > S & set([y]) > > A search would be: > f = [m for m in S & set([y]) if m is y][0] f is y > True But in practice he won't have y, only x. So that would have to be: >>

Re: A new script which creates Python 3.3 venvs with Distribute and pip installed in them

2013-01-30 Thread Ian Kelly
On Wed, Jan 30, 2013 at 1:09 PM, Vinay Sajip wrote: > Python 3.3 includes a script, pyvenv, which is used to create virtual > environments. However, Distribute and pip are not installed in such > environments - because, though they are popular, they are third-party > packages - not part of Pyth

Re: help

2013-01-30 Thread Ian Kelly
On Wed, Jan 30, 2013 at 2:16 PM, wrote: > Hi everyone! I don't mean to intrude, but ive heard great things about this > group and ive stumped myself with my python code. > > heres my code: It would be helpful if you would also include the error that you get when trying to run the code. > globa

Re: while True or while 1

2012-01-23 Thread Ian Kelly
ns to be made, including rewriting parts of the program in C. "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil" -- Donald Knuth Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Using an object inside a class

2012-01-23 Thread Ian Kelly
ute; in the second case, an instance attribute. Either way, it would then be accessed simply as "self.foo". Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Using an object inside a class

2012-01-23 Thread Ian Kelly
> will create a 'MyApp' instance and then bind it to the name 'foo'. > Until that binding occurs, the name 'foo' doesn't exist. What MRAB said; also note that there is no need to bind your wx.App instance to a name at all, because you can retrieve it globall

Re: Using an object inside a class

2012-01-23 Thread Ian Kelly
call has returned, so the result of that call has not actually been assigned to "app" yet. I suggest using wx.GetApp() instead. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Using an object inside a class

2012-01-23 Thread Ian Kelly
On Mon, Jan 23, 2012 at 2:52 PM, Jonno wrote: > On Mon, Jan 23, 2012 at 3:42 PM, Ian Kelly wrote: >> >> Exactly.  The line "app = MyApp(0)" creates a MyApp instance and then >> assigns it to "app".  As part of the MyApp creation process, it >>

Re: Using an object inside a class

2012-01-23 Thread Ian Kelly
he latter and remove the reliance on finding the correct frame? Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: The devolution of English language and slothful c.l.p behaviors exposed!

2012-01-23 Thread Ian Kelly
On Mon, Jan 23, 2012 at 10:57 PM, Rick Johnson wrote: > > Here is a grep A grep? What is a grep? That word is not in any of my dictionaries. Are you perhaps carelessly invoking the neologism of referring to an execution of the "grep" UNIX program as "a grep"? > from the month of September 2011

Re: PyWart: Python regular expression syntax is not intuitive.

2012-01-25 Thread Ian Kelly
t; {NG.name}  # Named Group Reference > {#...}  # Comment > {>+...}  # Positive Look Ahead Assertion > {>-...}  # Negative Look Ahead Assertion > {<+...}  # Positive Look Behind Assertion > {<-...}  # Positive Look Behind Assertion > {(id/name)yes-pat|no-pat} >

Re: The devolution of English language and slothful c.l.p behaviors exposed!

2012-01-25 Thread Ian Kelly
ther meaning in other contexts is flatly ridiculous. The editors at dictionary.com disagree with you too: """ Usage Note The qualifying adverb pretty, meaning “fairly or moderately” has been in general use since the late 16th century. Although most common in informal speech and writi

Re: PyWart: Python regular expression syntax is not intuitive.

2012-01-25 Thread Ian Kelly
re inherently unpythonic. While your reimplementation may be more intuitive to you, I don't think that it's more pythonic at all. > Window dressing is important Ian, if not, then shop owners would not > continue to show displays in their shop windows. What does window >

Re: The devolution of English language and slothful c.l.p behaviors exposed!

2012-01-25 Thread Ian Kelly
On Wed, Jan 25, 2012 at 4:23 PM, Rick Johnson wrote: > Only to you. In my world, the "pleasurable aspects of a tangible > object" can have no effect on my opinion of the difficulty of a task. Then your world is not the real world, that being the one that is actually described by every dictionary

Re: The devolution of English language and slothful c.l.p behaviors exposed!

2012-01-25 Thread Ian Kelly
On Wed, Jan 25, 2012 at 6:00 PM, Rick Johnson wrote: > On Jan 25, 6:20 pm, Ian Kelly wrote: >> On Wed, Jan 25, 2012 at 4:23 PM, Rick Johnson > >> > """I was frightened that the finals might be difficult this year, >> > however to my surprise, they

Re: The devolution of English language and slothful c.l.p behaviors exposed!

2012-01-25 Thread Ian Kelly
wo posts), that means that he is not just a troll, but a successful troll. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: contextlib.contextmanager and try/finally

2012-01-31 Thread Ian Kelly
On Tue, Jan 31, 2012 at 2:07 PM, Prasad, Ramit wrote: >>Like Neil mentioned, a contextmanager generator is wrapped with an >>__exit__ method that is guaranteed to be called and that explicitly >>resumes or closes the generator.  So as long as your contextmanager >>generator is properly written (i.

Re: except clause syntax question

2012-01-31 Thread Ian Kelly
docs are written the way that they are, but if you check the code, you can see that PyTuple_SetItem will raise a SystemError if the reference count is anything other than 1. So I think that it is only meant to be used with similar caution and restraint. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: except clause syntax question

2012-01-31 Thread Ian Kelly
On Tue, Jan 31, 2012 at 6:09 PM, Ian Kelly wrote: > On Tue, Jan 31, 2012 at 5:53 PM, Chris Angelico wrote: >> On Wed, Feb 1, 2012 at 9:03 AM, Duncan Booth >> wrote: >>> Abitrarily nested tuples of exceptions cannot contain loops so the code >>> simply needs to

Re: 'class' named tuple

2012-01-31 Thread Ian Kelly
r assignment, use __setitem__. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about name scope

2012-02-01 Thread Ian Kelly
; f('pass') Traceback (most recent call last): File "", line 1, in File "", line 3, in f NameError: global name 'a' is not defined >>> def f(x): ... locals()['a'] = 4 ... print a ... exec x ... >>> f('pass')

Re: Question about name scope

2012-02-01 Thread Ian Kelly
directly reference it as 'a', though, since the result would be either that it would try to look up a global with that name, or the compiler would consider it a local, optimize it, and then you could no longer assign it via locals(). Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about name scope

2012-02-01 Thread Ian Kelly
On Wed, Feb 1, 2012 at 3:53 PM, Ethan Furman wrote: > --> def f(x, y): > > ...     locals()[x] = y > ...     print(vars()) > ...     exec('print (' + x + ')') > ...     print(x) > ... > --> f('a', 42) > > {'y': 42, 'x': 'a', 'a': 42} > 42 > a > > Indeed -- the point to keep in mind is that locals(

Re: Question about name scope

2012-02-01 Thread Ian Kelly
On Wed, Feb 1, 2012 at 4:41 PM, Ethan Furman wrote: > I'm not sure what you mean by temporary: > > --> def f(x, y): > > ...     frob = None > ...     loc = locals() > ...     loc[x] = y > ...     print(loc) > ...     print(locals()) > ...     print(loc) > ...     print(locals()) > ... > --> > -->

Re: SnakeScript? (CoffeeScript for Python)

2012-02-02 Thread Ian Kelly
n. > Then how are you going to maintain the code? Maintain the compiled > code or the source? As with all compiled software, you maintain the input, not the output. > And proving that your translator is always correct That's what unit tests are for. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Common LISP-style closures with Python

2012-02-05 Thread Ian Kelly
> Yes, I do know that, but then it would not be a closure :-) Sure it is. Where do you think it looks up the function object? Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: iterating over list with one mising value

2012-02-07 Thread Ian Kelly
rate through pairs instead of individual elements? It sounds like it is not very flexible. I would recommend instead using the "grouper" recipe from the itertools documentation: http://docs.python.org/library/itertools.html#recipes Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: frozendict

2012-02-08 Thread Ian Kelly
def __iter__(self): return iter(self.__dict) def __getitem__(self, key): return self.__dict[key] def __hash__(self): return hash(frozenset(self.__dict.iteritems())) def __repr__(self): return 'frozendict(%r)' % (self.__dict,) Not extensiv

Re: frozendict

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 8:19 AM, Nathan Rice wrote: > As I said, two dictionaries created from the same input will be the > same... That's an implementation detail, not a guarantee. It will hold for current versions of CPython but not necessarily for other Python implementations. -- http://mail.

Re: Apparent "double imports" (was: Naming convention for in-house modules (Newbie question))

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 11:53 AM, HoneyMonster wrote: > One issue I have run into, which may or may not be a problem: I am > finding that modules in the in-house "library" package sometimes have to > import modules like sys and os, which are also imported by the "calling" > module. Is this a proble

Re: round down to nearest number

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 5:30 PM, noydb wrote: > How do you round down ALWAYS to nearest 100?  Like, if I have number > 3268, I want that rounded down to 3200.  I'm doing my rounding like round(3268, -2) > But, how to round DOWN? >>> 3268 // 100 * 100 3200 For more complicated cases, Decimal

Re: round down to nearest number

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 6:43 PM, Chris Rebert wrote: > On Thu, Feb 9, 2012 at 5:23 PM, noydb wrote: >> hmmm, okay. >> >> So how would you round UP always?  Say the number is 3219, so you want >> 3300 returned. > > http://stackoverflow.com/questions/17944/how-to-round-up-the-result-of-integer-divis

Re: round down to nearest number

2012-02-09 Thread Ian Kelly
are of though is that while the "round down" formula works interchangeably for ints and floats, the "round up" formula does not. >>> (3300.5 + 99) // 100 * 100 3300.0 A more consistent alternative is to negate the number, round down, and then negate again. >>> -(-(3300.5) // 100 * 100) 3400.0 Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Removing items from a list

2012-02-10 Thread Ian Kelly
move(i) ... 0 2 4 6 8 >>> x [1, 3, 5, 7, 9] Had you attempted to remove any of the odd numbers as well, it would have failed. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: problems with shelve(), collections.defaultdict, self

2012-02-11 Thread Ian Kelly
o arguments, this results in the error you see. There are a couple of ways you could fix this. The first would be to change the signature of the __init__ method to take an optional argument accepting the default factory instead of hard-coding it, like this: def __init__(self, default_factory=int):

Re: problems with shelve(), collections.defaultdict, self

2012-02-11 Thread Ian Kelly
On Sat, Feb 11, 2012 at 10:46 AM, Ian Kelly wrote: > The problem is that defaultdict defines a custom __reduce__ method > which is used by the pickle protocol to determine how the object > should be reconstructed.  It uses this to reconstruct the defaultdict > with the same default

Re: problems with shelve(), collections.defaultdict, self

2012-02-11 Thread Ian Kelly
On Sat, Feb 11, 2012 at 10:54 AM, Ian Kelly wrote: > class Dog(dict): > >    def __missing__(self): >        return 0 Sorry, that should have been: class Dog(dict): def __missing__(self, key): return 0 Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Ian Kelly
I hate being suckered in by trolls, but this paragraph demands a response. On Mon, Feb 13, 2012 at 9:01 AM, Rick Johnson wrote: > You are born with rights. Life, Liberty, and the pursuit of happiness. > Healthcare care is NOT a right, healthcare is a privileged. If you deprive a person of access

Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Ian Kelly
[Reply sent off-list, partly because this is way off-topic, but also because python-list rejected my response as spam] -- http://mail.python.org/mailman/listinfo/python-list

Re: name of a sorting algorithm

2012-02-14 Thread Ian Kelly
the list do not "bubble up" as they would in bubble sort. Rather, they jump around somewhat randomly until they are finally selected for the current sort index. I agree with Arnaud -- this is a selection sort variant that saves a local variable (the index of the minimum element) by placing it at the current sort index instead -- at the cost of doing additional swaps. Probably not a good trade-off in Python (but then again, no pure Python sort algorithm is likely to perform better than the built-in). Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: name of a sorting algorithm

2012-02-14 Thread Ian Kelly
On Tue, Feb 14, 2012 at 11:10 AM, Jabba Laci wrote: > Hi, > >> Either you're misremembering, or the algorithm you programmed 43 years >> ago was not actually bubble sort.  Quoting from Wikipedia: >> >> """ >> Bubble sort, also known as sinking sort, is a simple sorting algorithm >> that works by r

Re: Complexity question on Python 3 lists

2012-02-15 Thread Ian Kelly
more than 1 element) ? I believe the behavior in CPython is that if the array is full, the capacity is doubled, but I'm not certain, and that would be an implementation detail in any case. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: writing to a file from within nested loops

2012-02-15 Thread Ian Kelly
On Wed, Feb 15, 2012 at 1:12 PM, Rituparna Sengupta wrote: > Hi, > > I'm working on this code and I keep getting an error. It might be some very > basic thing but I was wondering if someone could help. Its a loop within a > loop. The part outside the innermost loop gets printed fine, but the par

Re: Complexity question on Python 3 lists

2012-02-15 Thread Ian Kelly
On Wed, Feb 15, 2012 at 1:28 PM, Dennis Lee Bieber wrote: > On Wed, 15 Feb 2012 11:11:27 -0800, Chris Rebert > wrote: > > >>"The growth pattern is: 0, 4, 8, 16, 25, 35, 46, 58, 72, 88, …" >>    -- list_resize() >> >        Rather perverse, is it not? The first set is plain doubling, but > then yo

Re: Wanted: Criticism of code for a Python module, plus a Mac tester

2012-02-15 Thread Ian Kelly
ut then I realized that the indirection allows you to easily sort the cards in the desired order, so that should be left alone. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: format a measurement result and its error in "scientific" way

2012-02-15 Thread Ian Kelly
+ value_str[index:] else: return value_str + error_str >>> format_error(1.03789291, 0.00089) '1.0379(9)' >>> format_error(103789291, 1000) '1.03789(1)E+08' I haven't tested this thoroughly, so use at your own risk. :-) Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Wanted: Criticism of code for a Python module, plus a Mac tester

2012-02-15 Thread Ian Kelly
itertools.izip(itertools.cycle(DEALERS), rotating(VULNERABILITIES)), 16)) But I don't know that it's really worth the added complexity. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-16 Thread Ian Kelly
On Wed, Feb 15, 2012 at 8:04 AM, Rick Johnson wrote: > I have PROVEN that when people FIGHT back, they will NOT be subjects > to tyranny; race has NOTHING to do with it. I gave one example in > history where people would rather die than be subjected to tyranny, > there are many more. "GIVE ME FREE

Re: format a measurement result and its error in "scientific" way

2012-02-16 Thread Ian Kelly
wo digits: > >>>> format_error( '1.34883', '0.0098' ) > '1.349(10)' > > But in this case I'd like to see 1.35(1) A small adjustment to the scale fixes that. Also tidied up the string formatting part: import decimal def format_error(value, error): value = decimal.Decimal(value) error = decimal.Decimal(error) error_scale = error.adjusted() error_scale += error.scaleb(-error_scale).to_integral().adjusted() value_str = str(value.quantize(decimal.Decimal("1E%d" % error_scale))) error_str = '(%d)' % error.scaleb(-error_scale).to_integral() if 'E' in value_str: index = value_str.index('E') return value_str[:index] + error_str + value_str[index:] else: return value_str + error_str Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: format a measurement result and its error in "scientific" way

2012-02-16 Thread Ian Kelly
On Thu, Feb 16, 2012 at 3:21 PM, Daniel Fetchinson wrote: > Thanks, it's simpler indeed, but gives me an error for value=1.267, > error=0.08: > > Traceback (most recent call last): >  File "/home/fetchinson/bin/format_error", line 26, in >    print format_error( sys.argv[1], sys.argv[2] ) >  Fil

Re: Python code file prototype

2012-02-17 Thread Ian Kelly
bang has to be the first thing in the file to be useful. As it is above, it might as well not be there. I would suggest also including a doc string in the skeleton. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-17 Thread Ian Kelly
On Fri, Feb 17, 2012 at 6:13 PM, Rick Johnson wrote: > > On Mon, Feb 13, 2012 at 7:23 PM, Ian Kelly > wrote: >> On Mon, Feb 13, 2012 at 2:01 PM, Rick Johnson >> I make a middle-class income and do not feel that I am anywhere near >> being "enslaved" by my in

Re: Python math is off by .000000000000045

2012-02-22 Thread Ian Kelly
On Wed, Feb 22, 2012 at 11:13 AM, Alec Taylor wrote: > Simple mathematical problem, + and - only: > 1800.00-1041.00-555.74+530.74-794.95 > -60.9500045 > > That's wrong. > > Proof > http://www.wolframalpha.com/input/?i=1800.00-1041.00-555.74%2B530.74-794.95 > -60.95 aka (-(1219/20)) >

Re: sum() requires number, not simply __add__

2012-02-23 Thread Ian Kelly
in sum doesn't do this. We really don't need to replace it, though. If you want a different sum behavior, just write your own. def sum(iterable, *args): return reduce(operator.add, iterable, *args) >>> sum([3,4]) 7 >>> sum([3,4], 12) 19 >>> sum(['hello', 'world']) 'helloworld' Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: sum() requires number, not simply __add__

2012-02-23 Thread Ian Kelly
def sum(iterable, start=object()): if start is sum.func_defaults[0]: ... Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: Language missing maximum constant of numeric types!

2012-02-24 Thread Ian Kelly
y) except EntityNotFound: pass closest_object = min(all_entities, key=lambda e: distance(player.pos, e.pos)) Especially given that all_entities should be reusable in other contexts. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: pickle handling multiple objects ..

2012-02-27 Thread Ian Kelly
made it just two seconds ago. While that's true, if your pickle is untrusted then a ValueError from unpacking is the least of your worries. You should never attempt to load an untrusted pickle in the first place, as doing so allows it to execute arbitrary code on your system. Cheers, Ian --

Re: Question about circular imports

2012-02-27 Thread Ian Kelly
ions won't be called until the module is fully imported. It does add some overhead to the functions, basically the cost of a dict lookup. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about circular imports

2012-02-27 Thread Ian Kelly
from b are not going to change that. Python does some magic so that you can do "import b.c" inside d while b.c is still importing without resulting in infinite recursion, but the success of the import does not signify that b.c is actually available yet. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: America's CONTEMPTUOUS KANGAROO courts VERSUS ISRAELI courts (in JEW-vs-JEW case)

2012-02-27 Thread Ian Kelly
On Mon, Feb 27, 2012 at 8:13 PM, Tonico wrote: > Idiot Please don't reply to spam. You're just making it show up in the inboxes of those of us who already have these idiots kill-filed. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is this the proper way to use a class method?

2012-03-02 Thread Ian Kelly
called without arguments is equivalent to super(, self) -- it collects the value of self from the current stack frame. So self is able to be passed in because the super object implicitly knows what self is. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: What's the best way to write this regular expression?

2012-03-06 Thread Ian Kelly
rt tags, end tags, and text, with no guarantee that the tags will actually correspond in any meaningful way. lxml can be used to output an actual hierarchical structure that may be easier to manipulate and extract data from. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Python recursive tree, linked list thingy

2012-03-07 Thread Ian Kelly
On Wed, Mar 7, 2012 at 12:49 PM, Wanderer wrote: > I have a list of defective CCD pixels and I need to find clusters > where a cluster is a group of adjacent defective pixels. This seems to > me to be a classic linked list tree search.I take a pixel from the > defective list and check if an adjace

Re: Python recursive tree, linked list thingy

2012-03-07 Thread Ian Kelly
On Wed, Mar 7, 2012 at 1:03 PM, Ian Kelly wrote: > A set of defective pixels would be the probable choice, since it > offers efficient membership testing. Some actual code, using a recursive generator: def get_cluster(defective, pixel): yield pixel (row, column) = pixel for ad

Re: What's the best way to write this regular expression?

2012-03-07 Thread Ian Kelly
On Wed, Mar 7, 2012 at 1:39 PM, John Salerno wrote: > Ok, first major roadblock. I have no idea how to install Beautiful > Soup or lxml on Windows! All I can find are .tar files. Based on what > I've read, I can use the easy_setup module to install these types of > files, but when I went to downlo

Re: What's the best way to write this regular expression?

2012-03-07 Thread Ian Kelly
On Wed, Mar 7, 2012 at 2:11 PM, John Salerno wrote: > The only files included in the .tar.gz file is a .tar file of the same > name. So I guess the setup option doesn't exist for these particular > packages. The setup.py file (as well as the other files) would be inside the .tar file. Unlike a W

Re: Invalid syntax error

2012-03-10 Thread Ian Kelly
On Sat, Mar 10, 2012 at 6:17 AM, Günther Dietrich wrote: > In article > <46758542-1bd6-43fe-8e80-bcf14b7d8...@pi6g2000pbc.googlegroups.com>, >  sl33k wrote: > >>I'm trying project euler problem 3 and I've hit the wall with this >>error. What could be the problem here? >> >> l=[] > num=6008514

Re: newb __init__ inheritance

2012-03-11 Thread Ian Kelly
(C): pass In Python 3, classic classes have been removed, and so all four of the classes above would be new-style. > 2. Is the mro function available only on python3? No, but it is available only on new-style classes. If you try it on a classic class, you'll get an AttributeError.

Re: newb __init__ inheritance

2012-03-11 Thread Ian Kelly
On Sun, Mar 11, 2012 at 5:40 AM, Ian Kelly wrote: >> 2. Is the mro function available only on python3? > > No, but it is available only on new-style classes.  If you try it on a > classic class, you'll get an AttributeError. And by the way, you probably shouldn't cal

Re: concatenate function

2012-03-13 Thread Ian Kelly
On Tue, Mar 13, 2012 at 8:35 AM, ferreirafm wrote: > Hi List, > I've coded three functions that I would like to concatenate. I mean, run > them one after another. The third function depends on the results of the > second function, which depends on the results of the first one. When I call > one fu

Re: Enchancement suggestion for argparse: intuit type from default

2012-03-14 Thread Ian Kelly
int, the type should be int? And even if you manage to get the inference working flawlessly and expectedly for append, what about custom actions? It seems to me that there are a large number of edge cases here that will end up hurting predictability for the end user. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Questions about the use of descriptors.

2012-03-15 Thread Ian Kelly
his: class MyDialog(wx.Dialog): name = TextDescriptor('_name') description = TextDescriptor('_description') address = TextDescriptor('_address') def __init__(self, ...): # Build the dialog along with the _name, _description, and _address controls... Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Context Manager getting str instead of AttributeError instance

2012-03-15 Thread Ian Kelly
On Thu, Mar 15, 2012 at 1:10 PM, Prasad, Ramit wrote: >> Prasad, Ramit wrote: >> >> > So I have a context manager used to catch errors >> > >> > def __exit__( self, exceptionClass, exception, tracebackObject ): >> >     if isinstance( exception, self.exceptionClasses ): >> >          #do something

Re: Context Manager getting str instead of AttributeError instance

2012-03-15 Thread Ian Kelly
On Thu, Mar 15, 2012 at 2:25 PM, Prasad, Ramit wrote: >> > ... >> > (, "'A' object has no attribute 'x'", >> ) >> > AttributeError: 'A' object has no attribute 'x' >> > >> > As you can see, I am

Re: Why not use juxtaposition to indicate function application

2012-03-16 Thread Ian Kelly
On Fri, Mar 16, 2012 at 10:45 AM, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 17:31:06 +0100, Kiuhnm wrote: > >> You wouldn't, because Haskel's way is more regular and makes a lot of >> sense: parentheses are for grouping and that's it. > > If f is a function which normally takes (for the sake of

Re: avoid import short-circuiting

2012-03-16 Thread Ian Kelly
ement and doesn't import the dependencies.. > Any hints? You didn't actually monkey-patch it. You just created a local called __import__ that stores a wrapped version of the function. You need to actually replace it in the __builtin__ module: import __builtin__ __builtin__.__import__ = my_import Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get a reference of the 'owner' class to which a method belongs in Python 3.X?

2012-03-18 Thread Ian Kelly
cls.__dict__ at line(#ref3). No, type.__new__ does not call type.__init__ at all. Rather, it is type.__new__ that is responsible for copying the dict, not type.__init__. For this reason you should override type.__new__ in your metaclass, not type.__init__. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Currying in Python

2012-03-19 Thread Ian Kelly
ames "cur" and "curr" are terrible. Good names should describe what the function does without being too onerous to type, and the addition of the duplicate "r" is not an obvious mnemonic for remembering that the first one prohibits duplicate keyword arguments and the second one allows them. Why not more descriptive names like "curry" and "curry_unique"? That's all I've got. All in all, it's pretty decent for a Python newbie. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: List comprehension/genexp inconsistency.

2012-03-20 Thread Ian Kelly
second iterator, however, is recreated on every iteration of the first iterator, so it can't be pre-built in that manner. It does get created in the generator scope, and when that happens it blows up because it can't find the variable, just like the function example above. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Odd strip behavior

2012-03-22 Thread Ian Kelly
On Thu, Mar 22, 2012 at 1:48 PM, Rodrick Brown wrote: > Why wasnt the t removed ? Because str.strip() only removes leading or trailing characters. If you want to remove all the t's, use str.replace: 'this is a test'.replace('t', '') Cheers, Ian -- h

<    3   4   5   6   7   8   9   10   11   12   >