in
functions and classes/methods?
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
):
kwargs['spam'] = eggs
func(*args, **kwargs)
return decorated
@deco
def test(parrot, spam):
print parrot, spam
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 29 Jul 2007 18:27:25 -0700, CC wrote:
Marc 'BlackJack' Rintsch wrote:
I'd use `string.printable` and remove the invisible characters like '\n'
or '\t'.
What is `string.printable` ? There is no printable method to strings,
though I had hoped there would be. I don't yet know how
, callback=lambda msg: None):
callback('Start processing.')
for percent in xrange(0, 101):
callback('finished %d%%...' % percent)
callback('Done.')
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
'exceptions.TypeError': unsupported operand type(s) for -: 'Decimal' and
'Decimal'
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, 30 Jul 2007 06:32:55 -0400, Steve Holden wrote:
[x for x in xrange(0, 101)] == [y for y in xrange(101)]
True
First I thought: Why the unnecessary list comprehension but to my surprise:
In [33]: xrange(42) == xrange(42)
Out[33]: False
That's strange.
Ciao,
Marc 'BlackJack
On Mon, 30 Jul 2007 11:16:01 -0400, Steve Holden wrote:
Marc 'BlackJack' Rintsch wrote:
First I thought: Why the unnecessary list comprehension but to my surprise:
In [33]: xrange(42) == xrange(42)
Out[33]: False
That's strange.
Not so strange really. The two xrange objects
in parens., while
non-printing chars with no escapes will be shown with nothing in parens.
For escaping:
In [90]: '\n'.encode('string-escape')
Out[90]: '\\n'
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
the argument into a tuple
if you *really* need a tuple, or just use it as sequence or via iterator.
And pay attention to errors of course.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
` objects. `unicode` is already decoded. If you
want to feed `unicode` objects to an XML parser, simply encode it before
passing it.
The question remains why you have serialized XML as `unicode` in the
first place as it is about bytes not unicode characters.
Ciao,
Marc 'BlackJack' Rintsch
you can use `itertools.groupby()` to
get the groups and write them to several files. Otherwise if the files
can be read into memory completely you can sort in memory and then use
`itertools.groupby()`.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, 27 Jul 2007 12:15:25 +0200, Bruno Desthuilliers wrote:
4/ print //-+alibaba sinage[4:].startswith('a')
print //-+alibaba sinage.startswith('a', 4)
This does not create an extra string from the slicing.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo
by available
memory.
In [59]: 2**128
Out[59]: 340282366920938463463374607431768211456L
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
of a given regular
expression, would it be a good idea?
No regular expressions are not a very good idea. They get very
complicated very quickly while often still miss some corner cases.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
actually
iterate over the object.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 25 Jul 2007 15:46:14 -0400, Carsten Haese wrote:
On Wed, 2007-07-25 at 19:11 +, Marc 'BlackJack' Rintsch wrote:
And just calling `iter()` doesn't work either:
In [72]: class A:
: def __getitem__(self, key):
: if key == 42:
: return
On Wed, 25 Jul 2007 10:47:33 -0700, Paddy wrote:
But then,what would _0 be, the number 0 or the name _0 analagous to
a0
Of course the name because numbers have to start with a digit or a dot.
Otherwise this would break backwards compatibility.
Ciao,
Marc 'BlackJack' Rintsch
--
http
')
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
should stop searching the explanation within Python or
`ElementTree` and accept having a broken XML file on your disk. :-)
Have you checked the local XML file with something like `xmllint` or
another XML parser already?
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman
and print
it.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 24 Jul 2007 02:26:15 -0700, NetHead wrote:
The code below is WRONG, but hopefully illustrates what I am trying to
achieve.
Any suggestions how to code this is an efficient and maintainable (and
correct) manner?
[…]
for i in wildcards:
for j in i:
try:
somehow. I'd
use base64. It's available as codec for `str.encode()`/`str.decode()`.
In [10]: '\x00\xff\xaa'
Out[10]: '\x00\xff\xaa'
In [11]: '\x00\xff\xaa'.encode('base64')
Out[11]: 'AP+q\n'
In [12]: _.decode('base64')
Out[12]: '\x00\xff\xaa'
Ciao,
Marc 'BlackJack' Rintsch
--
http
())
Reduces the unnecessary instantiation of `myobject` to false objects.
May be not good enough.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
of course. ;-)
In [6]: import copy
In [7]: a = [[1, 2], [3, 4]]
In [8]: b = a[:]
In [9]: c = copy.deepcopy(a)
In [10]: a[0][1] = 42
In [11]: a
Out[11]: [[1, 42], [3, 4]]
In [12]: b
Out[12]: [[1, 42], [3, 4]]
In [13]: c
Out[13]: [[1, 2], [3, 4]]
Ciao,
Marc 'BlackJack' Rintsch
--
http
',))
In [10]: len(a)
Out[10]: 80
In [11]: print a
params
param
valuestringhello world/string/value
/param
/params
Even with some additional boilerplate like XML declaration etc. there is
still a little bit room until 10 kB are reached. :-)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org
'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
optimizations.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
with so much machine details, don't
have to manage memory, don't need extra indexes for looping over lists and
so on. And the crashes are much gentler, telling me what the error is
and where instead of a simple segfault or totally messed up results.
Ciao,
Marc 'BlackJack' Rintsch
--
http
to write and read the text
files in binary mode or they break if taken across platform boundaries
because of the different line endings in Linux and Windows for instance.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
:
data = self.current_file.read(size)
result += data
if len(data) != size:
self.current_file = self.files.pop()
size = size - len(data)
return result
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python
``==`` to do with `cmp()` here?
The return of `cmp()` is an integer that cannot and should not be seen as
boolean value.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 11 Jul 2007 16:52:32 +, flit wrote:
That seems to be a good idea, but I am afraid the web hosting does not
have the csv modules..
The `csv` module is part of the standard library.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
]: gmpy.digits(a, 2).zfill(16)
Out[16]: '000101100100'
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
'
In [11]: a
Out[11]: '\x00'
In [12]: ord(a)
Out[12]: 0
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
ElementTree to output the XHTML code I need it to?
Then either Firefox is broken or you don't declare your XHTML properly and
Firefox thinks it's HTML.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
items:
1: erik
2: viking
3: ham
4: spam and eggs
5: He said Ni!
6: line one
'line two' is the only item in the next record then.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
is a right single quotation mark and not
an apostrophe.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
this:
erik,viking,ham, spam and eggs,He said Ni!,line one
line two
That's 5 elements:
1: eric
2: viking
3: ham, spam and eggs
4: He said Ni!
5: line one
line two
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
. The parenthesis are just necessary for the literal empty tuple
and if the syntax would be ambiguous otherwise.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
but unless we know what you are going to
do with these data structures it's hard to tell if it is really the best
translation.
`PF.buffer` might be better a string or an `array.array`. And is `BLOCK`
really just a structure with *one* member? Looks a bit odd IMHO.
Ciao,
Marc 'BlackJack
while loops?
This question doesn't make much sense to me. Do ``while`` loops block
other threads? No of course not.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
guessed, I want a list of (no
parameter) functions, each of which returns its index in the list.)
Default arguments are evaluated when the function is defined:
In [15]: x = [lambda x=i: x for i in xrange(10)]
In [16]: x[0]()
Out[16]: 0
In [17]: x[5]()
Out[17]: 5
Ciao,
Marc 'BlackJack
see -- readability is the problem. :-)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
possible to give a regular expression for names you don't care if they are
unused.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
efficiently if the sets intersect without actually *doing*
the intersection.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
for item in set_b)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
in module?
It's built into the interpreter executable.
In [85]: import _sre
In [86]: _sre
Out[86]: module '_sre' (built-in)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
encoding used by your operating system.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
if the
input comes from a user it's a security hole. `float()` is the function
to use here.
`mean()` does not work as you try to divide a list by a number.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
3000. And this change may be already in a Python 2.x
before P3K.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
am using a set or are
sets represented by a hash table?
Sets are implemented as hash tables.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
('tag2')
writer.end('tag1')
writer.end('document')
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
names are local and which are attributes.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
* `__dict__` like Neil does.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
``
is neat too. Something I really miss in everyday programming in Python,
not. ;-)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
. It seems a
common error from people used to declare variables at that level in other
languages.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
objects. `map()`, `reduce()`, list comprehension work on arbitrary
iterables so how do you expect SIMD instructions handle this? Even simple
lists contain objects and those don't have to be of the same type.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python
In [EMAIL PROTECTED], Bytter wrote:
Marc 'BlackJack' Rintsch escreveu:
In [EMAIL PROTECTED], Bytter wrote:
Is there any ID ongoing about using SIMD [1] instructions, like SSE
[2], to speed up Python, especially regarding functional features,
like list comprehension, map and reduce, etc
,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
at that line and ignore the rest. There are 604 (!)
errors, some about table rows, before this line. So the parser may be
confused at this point and be already in an internal state that sees that
line in a completely different light than you do.
Ciao,
Marc 'BlackJack' Rintsch
--
http
embed src=url quality=highpluginspage=http://www.macromedia.com/go/;
getflashplayer=getflashplayer type=application/x-shockwave-flash
width=640 height=400 bgcolor=#00 scale=showall
/embed
/param/object]
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python
'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
that unreadable and magic instead
of the perfect readable ``for k, v in some_dict.iteritems():``?
And I don't see why it should be ``**``!?
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
In [EMAIL PROTECTED], Diez B. Roggisch wrote:
No need to create the intermediate list, a generator expression works just
fine:
a = tuple(i for i in range(10))
But `range()` creates the intermediate list anyway. ;-)
a = tuple(xrange(10))
Ciao,
Marc 'BlackJack' Rintsch
--
http
it!? :-)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
In [EMAIL PROTECTED], Jeff Rollin wrote:
Why do I not see my messages with attached files in the newsgroup, and is
there any way to configure this?
No, most news servers strip attachments from postings in non-binary
groups. It's a plain text medium.
Ciao,
Marc 'BlackJack' Rintsch
of the code I would say you just have an
`__init__()` and all other ``def``\s are local functions to that method.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
In [EMAIL PROTECTED], Terry Reedy
wrote:
| Should I import this to see how
| many principles this behavior violates?
???
If you meant 'report' (on SF), please do not.
I think he meant ``import this`` at the Python interpreter.
Ciao,
Marc 'BlackJack' Rintsch
--
http
interactive, it is right
s = u'张三'
why?
Does the coding comment match the actual encoding of the source file?
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
`!?
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
no attribute
'__dict__'.
That's because you used `__slots__`. One of the drawbacks of `__slots__`.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
to work there.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
them from a
database etc.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
intent here because it still gives `float` results
if used with at least one `float` as operands:
In [1]: 10.0 // 2
Out[1]: 5.0
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
data too I guess.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
() of unsized object
any suggestions are appreciated,
Yes, don't try iterating over objects that are not iterable. ;-)
What you *can* do is iterating over lists, tuples or other iterables with
just one element in them. Try ``a = [1]``.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org
of course.
mylist = ['Fred','bill','PAUL','albert']
mylist.sort(key=lambda el: el.lower())
So this becomes:
def keyfunc(el):
return el.lower()
mylist.sort(key=keyfunc)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
the function.
If you have a function or callable you call it with the call operator,
which are parenthesis:
In [8]: int
Out[8]: type 'int'
In [9]: int()
Out[9]: 0
For a random selection of an element from a list look at the
`random.choice()` function.
Ciao,
Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Steven
D'Aprano wrote:
Is there a general Pythonic idiom for efficiently walking over part of a
sequence without copying it first? Should there be?
What about using `itertools.islice()`:
for e in islice(a, 4):
pass
Ciao,
Marc 'BlackJack' Rintsch
--
http
an optional argument. Just make sure your derived type
does to and passes this to the base class `__init__()`. Then you can
create an instance like this:
a = MyList([[1, 2, 3], [4, 5, 6, 7]])
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
and dynamic nature of Python to the point where the source starts to get
unreadable and too magic, AFAIK there's no special pythonic
recommendation. :-)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
coding
practice.
What do you mean by use? Implement them to override behavior? Yes,
that's their purpose. Invent new magic names? No of course not, they are
special for a reason: preventing name clashes with the user's names.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org
only if it's
not possible otherwise. But cyclic imports are bad anyway. :-)
And if the import is *really* expensive and only needed in some special
circumstances.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
an exception instead of the surprise.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
In [EMAIL PROTECTED], per9000 wrote:
On Jun 4, 9:11 am, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
In [EMAIL PROTECTED], per9000 wrote:
[...]
So another question emerges:
* is the use of magic names encouraged and/or part of good coding
practice.
What do you mean by use
In [EMAIL PROTECTED], Peter Otten wrote:
Marc 'BlackJack' Rintsch wrote:
from itertools import count
from sys import maxint
c = count(maxint)
c.next()
2147483647
c.next()
-2147483648
What I find most disturbing here, is that it happens silently. I would
have expected an exception
:
/usr/local/lib/python2.4/lib-dynload $ python2.5
Python 2.5 (r25:51908, Oct 3 2006, 08:48:09)
[GCC 3.3.3 (SuSE Linux)] on linux2
Seems to be the same Python version, just build three days earlier and
with a different GCC version. Weird.
Ciao,
Marc 'BlackJack' Rintsch
--
http
'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
be
prevented and abusing a list comprehension or `map()` just for side
effects and not for building a list with meaningful content.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
hand there is the
convention to name functions and methods as verbs that are doing
something.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
801 - 900 of 1496 matches
Mail list logo