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

2012-02-14 Thread Duncan Booth
secondary bacterial infections, but they are not effective against viruses. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: frozendict

2012-02-09 Thread Duncan Booth
hope you sort the items before putting them in a tuple, otherwise how do you handle two identical dicts that return their items in a different order? -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: frozendict

2012-02-09 Thread Duncan Booth
Nathan Rice nathan.alexander.r...@gmail.com wrote: On Thu, Feb 9, 2012 at 5:33 AM, Duncan Booth duncan.booth@invalid.invalid wrote: Nathan Rice nathan.alexander.r...@gmail.com wrote: I put dicts in sets all the time.  I just tuple the items, but that means you have to re-dict it on the way

Re: frozendict

2012-02-09 Thread Duncan Booth
(dict.fromkeys('me'))) {'e': None, 'm': None} -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: except clause syntax question

2012-01-31 Thread Duncan Booth
, ... except exceptions as e: # argh! Abitrarily nested tuples of exceptions cannot contain loops so the code simply needs to walk through the tuples until it finds a match. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

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

2012-01-25 Thread Duncan Booth
to a Perl group instead. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

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

2012-01-25 Thread Duncan Booth
. They violate our philosophy in too many places. Or we could implement de-facto standards where they exist. *plonk* -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: __future__ and __rdiv__

2012-01-23 Thread Duncan Booth
Terry Reedy tjre...@udel.edu wrote: But if you mean for Number to be like a float rather than int, do as you are (with / and __truediv__). Or even __rtruediv__ -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: access address from object and vice versa

2012-01-23 Thread Duncan Booth
if you could get at the address it wouldn't be much use as it may change at any time. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-19 Thread Duncan Booth
documentation, and a Daily Mail article about John Cleese and Eric Idle. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: re.sub(): replace longest match instead of leftmost match?

2011-12-19 Thread Duncan Booth
: ip6 = longest_match.replace(ip6, ':', 1) I think you got longest_match/ip6 backwards there. Anyway, for those who like brevity: try: ip6 = ip6.replace(max(re.findall('((?::?)+)', ip6), key=len), ':', 1) except ValueError: pass -- Duncan Booth http://kupuguy.blogspot.com -- http

Re: boolean from a function

2011-12-13 Thread Duncan Booth
= ... @property def is_a_bookum(self): return self.boojum hunted = Snark(whatever) Then you can write: if hunted.is_a_boojum: self.vanish_away() -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Verbose and flexible args and kwargs syntax

2011-12-11 Thread Duncan Booth
1, in module class C(list, dict): pass TypeError: multiple bases have instance lay-out conflict -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: WeakValueDict and threadsafety

2011-12-10 Thread Duncan Booth
with the same id as some previous value. In other words I think there's a problem here, but nothing to do with the lock. -- Duncan Booth -- http://mail.python.org/mailman/listinfo/python-list

Re: WeakValueDict and threadsafety

2011-12-10 Thread Duncan Booth
Darren Dale dsdal...@gmail.com wrote: On Dec 10, 11:19 am, Duncan Booth duncan.bo...@invalid.invalid wrote: Darren Dale dsdal...@gmail.com wrote: def get_data(oid): with reglock: data = registry.get(oid, None) if data is None: data = make_data(oid

Re: adding elements to set

2011-12-08 Thread Duncan Booth
methods you could still get in a mess by redefining one without the other. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: struct calcsize discrepency?

2011-12-04 Thread Duncan Booth
native format and byte order, and properly aligned by skipping pad bytes if necessary (according to the rules used by the C compiler). -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamically Generate Methods

2011-11-18 Thread Duncan Booth
other way to do this? Use operator.itemgetter: key_attrs = ['A', 'B'] import operator get_key = operator.itemgetter(*key_attrs) d = {'A': 42, 'B': 63, 'C': 99} get_key(d) (42, 63) -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: How to insert my own module in front of site eggs?

2011-11-17 Thread Duncan Booth
your code in a virtualenv? http://pypi.python.org/pypi/virtualenv -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: ctypes: catch system exit from C library

2011-11-03 Thread Duncan Booth
main code. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient, built-in way to determine if string has non-ASCII chars outside ASCII 32-127, CRLF, Tab?

2011-11-01 Thread Duncan Booth
[ord(c)] for c in text) except IndexError: return False -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient, built-in way to determine if string has non-ASCII chars outside ASCII 32-127, CRLF, Tab?

2011-11-01 Thread Duncan Booth
MRAB pyt...@mrabarnett.plus.com wrote: On 01/11/2011 18:54, Duncan Booth wrote: Steven D'Apranosteve+comp.lang.pyt...@pearwood.info wrote: LEGAL = ''.join(chr(n) for n in range(32, 128)) + '\n\r\t\f' MASK = ''.join('\01' if chr(n) in LEGAL else '\0' for n in range (128)) # Untested def

Re: __dict__ attribute for built-in types

2011-10-27 Thread Duncan Booth
types have a __dict__. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: __dict__ attribute for built-in types

2011-10-27 Thread Duncan Booth
Chris Angelico ros...@gmail.com wrote: On Thu, Oct 27, 2011 at 10:03 PM, Duncan Booth duncan.booth@invalid.invalid wrote: Types without a __dict__ use less memory. Also, if you couldn't have a type that didn't have a `__dict__` then any `dict` would also need its own `__dict__` which would

Re: Opportunity missed by Python ?

2011-10-13 Thread Duncan Booth
in Python. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Mixins

2011-09-23 Thread Duncan Booth
to a component architecture instead; and suggests that Django will do the same in a few years time. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Operator commutativity

2011-09-19 Thread Duncan Booth
%r + %r % (self, other) def __radd__(self, other): return %r + %r % (other, self) X() + 123 '__main__.X object at 0x029C45B0 + 123' 123 + X() '123 + __main__.X object at 0x02101910' -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman

Re: why ps/fname of a python interpreter changes across platforms?

2011-09-16 Thread Duncan Booth
private version. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: stackoverflow and c.l.py (was: GIL switch interval)

2011-09-14 Thread Duncan Booth
is the place to go. On Stackoverflow you would likely just have the question closed pdq. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: stackoverflow and c.l.py (was: GIL switch interval)

2011-09-14 Thread Duncan Booth
Roy Smith r...@panix.com wrote: In article Xns9F605E618E6B1duncanbooth@127.0.0.1, Duncan Booth duncan.booth@invalid.invalid wrote: If you want an answer to how to get a specific bit of code to work then Stackoverflow is better if only because people can see who has already answered so

Re: Idioms combining 'next(items)' and 'for item in items:'

2011-09-12 Thread Duncan Booth
end of input until you fail to read any more. See my answer to http://stackoverflow.com/questions/7365372/is-there-a-pythonic-way-of-knowing-when-the-first-and-last-loop-in-a-for-is-being/7365552#7365552 for a generator that wraps the lookahead. -- Duncan Booth http://kupuguy.blogspot.com

Re: TypeError: object.__init__() takes no parameters

2011-09-09 Thread Duncan Booth
for other base classes are passed through. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Create an index from a webpage [RANT, DNFTT]

2011-09-09 Thread Duncan Booth
a trivial task. Building a list by scanning a bunch of folders with html files is comparatively easy which is why that is almost always the preferred solution if possible. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: TypeError: object.__init__() takes no parameters

2011-09-09 Thread Duncan Booth
that. It only became an error in 2.6: [dbooth@localhost ~]$ python2.5 -c object().__init__(42) [dbooth@localhost ~]$ python2.6 -c object().__init__(42) Traceback (most recent call last): File string, line 1, in module TypeError: object.__init__() takes no parameters -- Duncan Booth http

Re: Floating point multiplication in python

2011-09-06 Thread Duncan Booth
(1.1*1.1) 1.2102 -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: How to install easy_install on windows ?

2011-08-17 Thread Duncan Booth
install module_name Or even just use: C:\Your Python Directory\scripts\easy_install install module_name as easy_install will also add a .exe to your Python's 'scripts' folder. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: surprising interaction between function scope and class namespace

2011-08-15 Thread Duncan Booth
of LOAD_FAST/STORE_FAST and LOAD_NAME looks first in local scope and then in global. I suspect that http://docs.python.org/reference/executionmodel.html#naming-and-binding should say something about this but it doesn't. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman

Re: allow line break at operators

2011-08-10 Thread Duncan Booth
. without the parentheses it is a syntax error. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: __set__ method is not called for class attribute access

2011-08-10 Thread Duncan Booth
when they shadow an instance attribute. You're (probably) thinking of __getattr__ which isn't invoked when an instance attribute exists. Yes, Peter Otten already corrected me on that point last Friday and I posted thanking him on Sunday. -- Duncan Booth http://kupuguy.blogspot.com -- http

Re: __set__ method is not called for class attribute access

2011-08-07 Thread Duncan Booth
Peter Otten __pete...@web.de wrote: Duncan Booth wrote: The descriptor protocol only works when a value is being accessed or set on an instance and there is no instance attribute of that name so the value is fetched from the underlying class. Unlike normal class attributes a descriptor

Re: __set__ method is not called for class attribute access

2011-08-05 Thread Duncan Booth
1, in module MyClass().x AttributeError: 'MyClass' object has no attribute 'x' -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-18 Thread Duncan Booth
today that... and they won't believe ya'. Acorn System One: 9 character 7 segment led display and 25 key keypad, 1Kb RAM, 512 bytes ROM. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Using decorators with argument in Python

2011-06-30 Thread Duncan Booth
decorator. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: what's the big deal for print()

2011-06-27 Thread Duncan Booth
(): ... print 1, ... sys.stdout.softspace=0 ... print 2, ... sys.stdout.softspace=0 ... print 3 ... foo() 123 -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: how to write to registry without admin rights on win vista/7

2011-06-24 Thread Duncan Booth
works. How can I do it to write to registry without Run As Admin ? This might give you some pointers: http://stackoverflow.com/questions/130763/request-uac-elevation-from-within-a-python-script -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: how to inherit docstrings?

2011-06-09 Thread Duncan Booth
.__doc__ = whatever Traceback (most recent call last): File stdin, line 1, in ? TypeError: attribute '__doc__' of 'type' objects is not writable -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: how to avoid leading white spaces

2011-06-08 Thread Duncan Booth
' in sys.modules) True C:\Python32python -c import sys; print('re' in sys.modules) True Steven is right to assert that there's a cost to loading it, but unless you jump through hoops it's not a cost you can avoid paying and still use Python. -- Duncan Booth http://kupuguy.blogspot.com -- http

Re: Updated blog post on how to use super()

2011-06-02 Thread Duncan Booth
to the method in Base. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's super() considered super!

2011-05-30 Thread Duncan Booth
an error if you attempt to overwrite it without first checking whether it exists. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: bug in str.startswith() and str.endswith()

2011-05-27 Thread Duncan Booth
'.startswith('abc', 0, 2) False Likewise the start parameter for endswith. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's super() considered super!

2011-05-27 Thread Duncan Booth
: bar() got multiple values for keyword argument 'y' -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's super() considered super!

2011-05-27 Thread Duncan Booth
it. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Why did Quora choose Python for its development?

2011-05-23 Thread Duncan Booth
been ordered to drop all but 3 of their 132 claims? It isn't at all obvious yet who is going to be 'screwed over hard'. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a set into list

2011-05-16 Thread Duncan Booth
is sorted by accident, while other list(set(...)) results are not. A minor change to your example makes it out of order even for integers: x = [7, 8, 9, 1, 4, 1] list(set(x)) [8, 9, 1, 4, 7] or for that mattter: list(set([3, 32, 4, 32, 5, 9, 2, 6])) [32, 2, 3, 4, 5, 6, 9] -- Duncan Booth http

Re: Why do directly imported variables behave differently than those attached to imported module?

2011-05-04 Thread Duncan Booth
deleted and any functions or methods that are still accessible will keep the globals alive as long as required. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: raise (type, value, traceback) and raise type, value, traceback

2011-05-03 Thread Duncan Booth
couldn't use inheritance to group exceptions. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: What other languages use the same data model as Python?

2011-05-02 Thread Duncan Booth
to alias I and A[I] in some recursive calls. Not nice. Fortunately even at that time it was mostly being taught as an oddity; real programming was of course done in Algol 68C or BCPL. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Equivalent code to the bool() built-in function

2011-04-28 Thread Duncan Booth
!= False != True False You can use 'sum(...)==1' for a larger number of values but do have to be careful that all of them are bools (or 0|1). -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Case study: debugging failed assertRaises bug

2011-04-26 Thread Duncan Booth
, assertRaises has a weird dual life as a context manager: I never knew that before today. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Equivalent code to the bool() built-in function

2011-04-18 Thread Duncan Booth
The code for the win32api made use of this fact to determine whether to pass int or bool types through to COM methods. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Guido rethinking removal of cmp from sort method

2011-03-28 Thread Duncan Booth
calls to 'sort'. e.g. data.sort(key=itemgetter(1), reverse=True) data.sort(key=itemgetter(0)) -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Abend with cls.__repr__ = cls.__str__ on Windows.

2011-03-18 Thread Duncan Booth
software exception (0xcfd) occurred in the application at location 0x1e08a325. Click on OK to terminate the program Click on CANCEL to debug the program So it looks to me to be a current bug. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo

Re: Get Path of current Script

2011-03-14 Thread Duncan Booth
a script (and might be what you want if you haven't changed it since the script started). -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Reference Cycles with instance method

2011-03-09 Thread Duncan Booth
so that whenever you call it later it gets the correct 'self' parameter. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

[issue11272] input() has trailing carriage return on windows

2011-02-23 Thread Duncan Booth
Duncan Booth kupu...@gmail.com added the comment: If anyone knows how to reproduce the two bugs with a short Python script, I can try to convert it into a test. If you don't mind kicking off some sub-processes then here's a script that shows the bugs. I couldn't figure out how to do

Re: Python fails on math

2011-02-22 Thread Duncan Booth
-- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: IDLE won't wrap lines of text

2011-02-21 Thread Duncan Booth
editing). -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: [RELEASED] Python 3.2

2011-02-21 Thread Duncan Booth
. Reported as issue 11272: http://bugs.python.org/issue11272 -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

[issue11272] input() has trailing carriage return on windows

2011-02-21 Thread Duncan Booth
New submission from Duncan Booth kupu...@gmail.com: In Python 3.2, the builtin function `input()` returns a string with a trailing '\r' on windows: C:\Python32python Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits

[issue11272] input() has trailing carriage return on windows

2011-02-21 Thread Duncan Booth
Duncan Booth kupu...@gmail.com added the comment: Yes, it does indeed look like stdin has been opened in binary mode. Just iterating over it also gives the spurious carriage returns: C:\Python32python Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32

Re: Method chaining on decorator got SyntaxError

2011-02-17 Thread Duncan Booth
file_html(c): ... -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Extending classes __init__behavior for newbies

2011-02-15 Thread Duncan Booth
to c.l.py! HEIL DER FUHRER! Godwin was right. You lose. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: lint warnings

2011-02-15 Thread Duncan Booth
have an expression that can be inlined you save the function call overhead with the list comprehension. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting getCSS Count Code from java to python

2011-02-02 Thread Duncan Booth
selenium and in Python the method that is needed is selenium.get_eval(...) -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP: possibility of inline using of a symbol instead of import

2011-01-06 Thread Duncan Booth
to be that: r1 = myFunc1(...) is unclear when you don't know where myfunc1 originates, so why don't you write: r1 = MyModule1.myFunc1(...) -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Trying to decide between PHP and Python

2011-01-05 Thread Duncan Booth
Nobody nob...@nowhere.com wrote: On Tue, 04 Jan 2011 12:20:42 -0800, Google Poster wrote: The indentation-as-block is unique, Not at all. It's also used in occam, Miranda, Haskell and F#. Also Yaml. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo

Re: type(d) != type(d.copy()) when type(d).issubclass(dict)

2010-12-27 Thread Duncan Booth
operated upon. It happens to be the former but it doesn't actually say. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: type(d) != type(d.copy()) when type(d).issubclass(dict)

2010-12-25 Thread Duncan Booth
to subclass a builtin class you need to be aware of this and override the behaviour where it matters. Why do you want to subclass a dict anyway? It is usually the wrong choice. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Keeping track of the N largest values

2010-12-25 Thread Duncan Booth
a theoretical running time point of view, or just a nicer way to code this in Python? How about: from heapq import nlargest top = nlargest(K, input()) It uses a heap so avoids completely resorting each time. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman

Re: True lists in python?

2010-12-20 Thread Duncan Booth
wouldn't know which direction to follow from each node when it comes to cutting the list into 3. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: How does GC affect generator context managers?

2010-11-30 Thread Duncan Booth
. def foo(): with open(foo) as foo: for line in foo: yield line ... bar = foo() print bar.next() del bar # May close the file now or maybe later... -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: SQLite date fields

2010-11-26 Thread Duncan Booth
') -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Inserting class namespace into method scope

2010-11-20 Thread Duncan Booth
(self): return x m = Magic() print(m.method()) # prints 'inside' Magic.x = new value print(m.method()) # still prints 'inside' -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Modifying Element In For List

2010-11-15 Thread Duncan Booth
() count = 0 for row in csv_rows: if not is_number(row[d.MeterID]): # or even: if row[d.MeterID]=='': row[d.MeterID] = 0 count += 1 print(Received {} bad meter ids.format(count)) return count -- Duncan Booth http://kupuguy.blogspot.com -- http

Re: hashkey/digest for a complex object

2010-10-06 Thread Duncan Booth
to combine hashkeys.) If you want to combine the hashes from several objects then the easiest way is just to create a tuple of the objects and hash it. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Overriding dict constructor

2010-09-21 Thread Duncan Booth
Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Mon, 20 Sep 2010 11:53:48 +, Duncan Booth wrote: I was going to suggest overriding items() (or iteritems() for Python 2.x), but while that is another hole that your values leak out it isn't the hole used by the dict

Re: Too much code - slicing

2010-09-21 Thread Duncan Booth
and [true-clause] or [false-clause])[0] -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Overriding dict constructor

2010-09-20 Thread Duncan Booth
: self._extra[k] = extra_data def __setitem__(self, key, value): super(MyDict, self).__setitem__(key, value) self._extra[key] = extra_data # plus extra methods then you only have to worry about catching all the mutators but not the accessors. -- Duncan Booth http

Re: default behavior

2010-07-30 Thread Duncan Booth
timeit -sone = 1 .conjugate one() 1000 loops, best of 3: 0.0972 usec per loop Micro-optimisation, the best excuse for ugly code... Nice one, but if you are going to micro-optimise why not save a few keystrokes while you're at it and use '1 .real' instead? -- Duncan Booth http

Re: default behavior

2010-07-30 Thread Duncan Booth
that are also micro-obfuscations are always the best. :^) -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Nice way to cast a homogeneous tuple

2010-07-28 Thread Duncan Booth
wheres pythonmonks wherespythonmo...@gmail.com wrote: 2. There is something like map(lambda x: int(x) without all the lambda function call overhead. (e.g., cast tuple)? Yes there is: lambda x: int(x) is just a roundabout way of writing int -- Duncan Booth http://kupuguy.blogspot.com

Re: hasattr + __getattr__: I think this is Python bug

2010-07-26 Thread Duncan Booth
, x, y): self.x = x self.y = y -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Easy questions from a python beginner

2010-07-23 Thread Duncan Booth
is that in Python you make the rebinding explicit by assigning to the names: x, y = foo(x, y) -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread Duncan Booth
want different behaviour you just need to define your own helper function that has the behaviour you desire. e.g. one that just looks in the object's dictionary so as to avoid returning true for properties or other such fancy attributes. -- Duncan Booth http://kupuguy.blogspot.com -- http

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread Duncan Booth
') if d is not None: return name in d return False -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Accumulate function in python

2010-07-19 Thread Duncan Booth
dhruvbird dhruvb...@gmail.com wrote: On Jul 19, 4:28 pm, Peter Otten __pete...@web.de wrote: dhruvbird wrote:   I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]   And would like to compute the cumulative sum of all the integers from index zero into another array. So for the

Re: Easy questions from a python beginner

2010-07-12 Thread Duncan Booth
you move to functions that actually do something useful: scheme, netloc, path, parms, query, fragment = urlparse(url) and there's even a convention for ignoring results we don't care about: head, _, tail = line.partition(':') -- Duncan Booth http://kupuguy.blogspot.com -- http

Re: Easy questions from a python beginner

2010-07-11 Thread Duncan Booth
wheres pythonmonks wherespythonmo...@gmail.com wrote: I'm an old Perl-hacker, and am trying to Dive in Python. I have some easy issues (Python 2.6) which probably can be answered in two seconds: 1.  Why is it that I cannot use print in booleans??  e.g.: True and print It is true! I

Re: Is This Open To SQL Injection?

2010-07-08 Thread Duncan Booth
, %s)' % (','.join (['%s'] * len(col_vals))) cursor.execute(sql, (store, user) + col_vals) which safely sanitises all of the data passed to the database. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are String Formatted Queries Considered So Magical?

2010-06-29 Thread Duncan Booth
the lambda expression as a callable delegate. (example cribbed from http://geekswithblogs.net/shahed/archive/2008/01/28/118992.aspx) -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

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