secondary bacterial
infections, but they are not effective against viruses.
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
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
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
(dict.fromkeys('me')))
{'e': None, 'm': None}
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
,
...
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
to a Perl group instead.
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
. 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
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
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
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
:
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
= ...
@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
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
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
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
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
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
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
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
main code.
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
[ord(c)] for c in text)
except IndexError:
return False
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
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
types have a __dict__.
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
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
in Python.
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
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
%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
private version.
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
for other base classes are passed through.
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
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
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
(1.1*1.1)
1.2102
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
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
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
.
without the parentheses it is a syntax error.
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
decorator.
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
():
... 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
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
.__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
' 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
to the method in Base.
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
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
'.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
: bar() got multiple values for keyword argument 'y'
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
it.
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
couldn't use inheritance to group exceptions.
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
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
!= 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
,
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
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
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
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
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
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
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
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
editing).
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
.
Reported as issue 11272: http://bugs.python.org/issue11272
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
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
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
file_html(c):
...
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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
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
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
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
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
.
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
')
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
(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
()
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
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
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
and [true-clause] or [false-clause])[0]
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
:
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
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
that are also micro-obfuscations are always the
best. :^)
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
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
, x, y):
self.x = x
self.y = y
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
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
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
')
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
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
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
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
, %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
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
101 - 200 of 1755 matches
Mail list logo