On 2007-12-07, Duncan Booth <[EMAIL PROTECTED]> wrote:
> Neil Cerutti <[EMAIL PROTECTED]> wrote:
>
>> On 2007-12-07, Duncan Booth <[EMAIL PROTECTED]> wrote:
>>> from __future__ import with_statement
>>>
>>> def loaddomainowners(domain):
>
On 2007-12-07, Duncan Booth <[EMAIL PROTECTED]> wrote:
> from __future__ import with_statement
>
> def loaddomainowners(domain):
> with open('/etc/virtual/domainowners','r') as infile:
I've been thinking I have to use contextlib.closing for
au
incomprehensible, so I looked it up in
perldoc. Anyhow, Python doesn't have it. Combining printing
various verboseness of usage messages with setting exit codes
with calling the exit function seems a little bizarre.
But I believe optparse will handle parsing arguments and printing
usage message
rce, or perhaps Raymond is reading and could explain.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2007-12-10, Neil Cerutti <[EMAIL PROTECTED]> wrote:
> On 2007-12-09, Just Another Victim of the Ambient Morality
><[EMAIL PROTECTED]> wrote:
>> I'm looking for a linked list implementation. Something
>> iterable with constant time insertion anywhere in the
On 2007-12-10, Peter Otten <[EMAIL PROTECTED]> wrote:
> Neil Cerutti wrote:
>> [linked lists] don't work well with Python iterators, which
>> aren't suitable for a linked list's purposes--so you have to
>> give up the happy-joy for loop syntax in f
ed the reverse dict anyway.
It wouldn't be merely an optimization if reverse lookups and
mutations were interleaved.
--
Neil Cerutti
You only get a once-in-a-lifetime opportunity so many times. --Ike Taylor
--
http://mail.python.org/mailman/listinfo/python-list
On 2007-12-10, Duncan Booth <[EMAIL PROTECTED]> wrote:
> Neil Cerutti <[EMAIL PROTECTED]> wrote:
>> Python's iterators are unsuitable for mutating the linked list
>> while iterating--the only major application of linked lists.
>> Wrapping in a generator won
On 2007-12-10, Peter Otten <[EMAIL PROTECTED]> wrote:
> Neil Cerutti wrote:
>>> def test():
>>> ll = LinkedList([random.randint(1,1000) for i in range(10)])
>>>
>>> for el in ll:
>>> if el.value%2==0:
>>>
On 2007-12-10, Neil Cerutti <[EMAIL PROTECTED]> wrote:
> On 2007-12-10, Peter Otten <[EMAIL PROTECTED]> wrote:
>> Neil Cerutti wrote:
>>>> def test():
>>>> ll = LinkedList([random.randint(1,1000) for i in range(10)])
>>>
erators, though I like making the method
completely invisible).
I do have one last question about a doubly-linked list. Would you
have to perform any tricks (del statements) to get the garbage
collector to collect every node, or will it just work?
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
t and next would (probably) have to be statements
(or statement suites) rather than expressions. Hence, the cool
innovations of iterators and generators, which otherwise might
not have found a home in Python. I wonder what programming Python
was like before iterators sometimes.
However, did you have a
On 2007-12-11, Duncan Booth <[EMAIL PROTECTED]> wrote:
> Neil Cerutti <[EMAIL PROTECTED]> wrote:
>> If you put an instrumented iterator through, say, reversed or
>> sorted, you'd lose the ability to use it to modify the list
>
> I think that is kind o
On 2007-12-10, Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
> Neil Cerutti <[EMAIL PROTECTED]> writes:
>
>> Anyhow, implementing linked lists in Python is not challenging, but
>> they don't work well with Python iterators, which aren't suitable
>> for a
r
(mostly as a fun parsing exercise), used that for a while, and
then threw it out.
I advise you to spend time staring at the examples, and use the
simplest example the suits your needs. Also search this archives
of this group for examples.
--
Neil Cerutti
The pastor will preach his farewell messa
e process is less cumbersome now, though it was bewildering
at first working with Excel in Python. Actually, surprises still
crop up now and then, mostly to do with cell types. The advantage
of working with csv was that everything was a string.
--
Neil Cerutti
The world is more like it is now th
avior,
i.e., if you call __init__, you'll initialize the container?
deque's behavior doesn't make sense to me.
--
Neil Cerutti
One of the causes of the American Revolution was the English put tacks in
their tea. --History Exam Blooper
--
http://mail.python.org/mailman/listinfo/python-list
_(...) initializes x; see x.__class__.__doc__ for signature
--
Neil Cerutti
A song fest was hell at the Methodist church Wednesday. --Church Bulletin
Blooper
--
http://mail.python.org/mailman/listinfo/python-list
CSV files can be read in by basically anything.
When I have a choice, I use simple tab-delimited text files. The
usually irrelevent limitation is the inability to embed tabs or
newlines in fields. The relevant advantage is the simplicity.
--
Neil Cerutti
The recording I listened to had Alfre
On 2007-12-12, Shane Geiger <[EMAIL PROTECTED]> wrote:
> Neil Cerutti wrote:
>> On 2007-12-12, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>>
>>> John Machin <[EMAIL PROTECTED]> wrote:
>>>
>>>> For that purpose, CSV files are
On 2007-12-12, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> On Dec 12, 7:22 am, Neil Cerutti <[EMAIL PROTECTED]> wrote:
>> List and deque disagree on what __init__ does. Which one is
>> right?
>
> File a bug report and assign to me.
Will do. Registration in pro
e EOF when it
attempts to read data.
> ftp.storlines(command, outfile)
outfile.close()
--
Neil Cerutti
Henry VII found walking difficult because he had an abbess on his knee.
--History Exam Blooper
--
http://mail.python.org/mailman/listinfo/python-list
): return -1
> return int(mktime(strptime(s, "%y%m%d")))
An inefficient parsing technique is probably to blame. You first
inspect the line to make sure it is valid, then you inspect it
(number of column type) times to discover what data type it
contains, and then you inspect it *again* to finally translate
it.
> And here is parseValue (will using a hash-based dispatch make
> it much faster?):
Not much.
You should be able to validate, recognize and translate all in
one pass. Get pyparsing to help, if need be.
What does your data look like?
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2007-12-12, John Machin <[EMAIL PROTECTED]> wrote:
> On Dec 13, 12:58 am, Neil Cerutti <[EMAIL PROTECTED]> wrote:
>> On 2007-12-12, John Machin <[EMAIL PROTECTED]> wrote:
>>
>> >> It's clear that I am thinking to completely different usages
>
rmally:
>>> hasattr(Language, 'iterpreted')
False
>>> hasattr(Implementation, 'interpreted')
True
;-)
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
. It also (doesn't really) know how to figure out
what's a string and what isn't.
The auto-indenter is often smarter about syntax, but knows just a
small subset of syntax rules, enought to do proper indenting. For
some languages, e.g., Python, that's a fairly small subset. For
others, it's cumbersomely large and Vim's support is cruddy.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2007-12-13, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> Neil Cerutti a écrit :
>> On 2007-12-13, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>>> I have repeatedly argued in the past that we do ourselves a
>>> disservice by describing Python a
ing out the list of overlaps, even if you knew, a
priori, that all elements overlapped, is an O(N**2) operation. So
I don't think a better algorithm exists for the worst case.
--
Neil Cerutti
You only get a once-in-a-lifetime opportunity so many times. --Ike Taylor
--
http://mail.python.org/mailman/listinfo/python-list
er. Try the following:
import sys
import csv
writer = csv.writer(sys.stdout, delimiter=' ', quotechar="'",
quoting=csv.QUOTE_ALL)
writer.writerow(sys.argv)
You might want to set a few more of the dialect options, too,
e.g., in case an arg contains
10
i = 0, j = 11
...
i = 9, j = 19
import sys
from itertools import izip
for i, j in izip(xrange(10), xrange(10, 20)):
sys.stdout.write("i = %d, j = %d\n", (i, j))
--
Neil Cerutti
To succeed in the world it is not enough to be stupid, you must also be well-
mannered. --Voltaire
--
http://mail.python.org/mailman/listinfo/python-list
e a legitimate complaint when using LarchTree.__le__
results in an attribute error?
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
nt meters (3 over quarter, or 2 over dotted
quarter).
And... er... Python doesn't need a time signature data type. But
rationals would be quite nifty. ;-)
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
d, i.e., it uses only the comparison
operation being implemented to compare contained objects.
When implementing a mutable sequence in Python, the rule of thumb
seems to be "do as lists do," so as of the Python's current
implementation, there's a small limit on the p
y, does this language have a BNF,
> or some other form of grammar definition?
Might I suggest: laughs evilly, rubbing hands together?
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
w to
> do this!
There are free C lexers and parsers available (e.g., gcc). I
recommend them to you. Gluing a real C parser into your Python
code might be easier than writing one. Not that it's impossible
to discover C comments with your own special-purpose, simple
parser (see Exercise 1-23 in
Using a regular expression would be quick if you know how.
Or use str.find and slicing.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
gt;generator below.
>
> I have to say that I have found this to be a surprisingly common need as
> well. Would this be an appropriate construct to add to itertools?
>
Something similar is already contained in the itertools recipes page.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
horrendous, though? Considering that
the "poorly performing" solution seems to be the functionality that the
uninformed expect, perhaps they *want* it to perform that way?
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
ut it's pretty simple to use named slices to get at
the data.
identifier = slice(0, 8)
timestamp = slice(8, 18)
t = slice(18, 21)
c = slice(21, 24)
resource_name = slice(24, 35)
description = slice(35)
for line in file:
line = line.rstrip("\n")
print "id:", line[id
On Jan 1, 2008 6:54 PM, Neil Cerutti <[EMAIL PROTECTED]> wrote:
> There's no standard Python tool for reading and writing fixed-length field
> "flatfile" data files, but it's pretty simple to use named slices to get at
> the data.
>
> identifier = s
mented sets in
> C/C++ and need a starting point on how to do it right. Could somebody
> give me a starting point?
#include
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
ral Programming FAQ for
further information.
http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
t really expensive to check the property? That would mitigate against
the filter solution and for the other one I posted.
This seems to be a case of trying to solve a data problem functionally. It'd
be better to store your data differently if this will be a frequent
operation and you simply can't afford to call the predicate on all the
elements.
Incidentally, try not to shadow builtin names like 'property'.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 4, 2008 3:47 PM, Neil Cerutti <[EMAIL PROTECTED]> wrote:
> On Jan 4, 2008 2:55 PM, <[EMAIL PROTECTED]> wrote:
>
> > Hello,
> > This is a question for the best method (in terms of performance
> > only) to choose a random element from a list among those
s D(A, B): pass
> ...
> Traceback (most recent call last):
> File "", line 1, in
> TypeError: Error when calling the metaclass bases
>Cannot create a consistent method resolution
> order (MRO) for bases A, B
The mro of new-style classes changed between Python 2
nk implicit this-> is somewhat more defensible. If 'this' were not a
pointer, perhaps C++ wouldn't have chosen impliciticity..
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
lented figure skater skates.
>
> Would you Python old-timers try to agree on a word or two that
> completes:
>
> The best thing about Python is ___.
...its bundled library.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
filename, 'w')
> > >
> > > But it's not working.
>
> Yep, defining "not working" is always helpful! :)
>
> I want to have all 3 files open at the same time. I will write to each of
> the files later in my script but just the last file is op
ion is to_separate_words_with_underscore,
> but some code uses lowerCamelCase instead.
>
> I tended to dislike the underscore convention, but after forcing
> myself to use it for a while I'm starting to appreciate its beauty.
Conventions get broken when there's a good r
).suppress()
pair = Group(word + sep + word)
pairs = delimitedList(pair, '_')
print ','.join(':'.join(t) for t in
pairs.parseString('hi_cat_bye_dog').asList())
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
).suppress()
pair = Group(word + sep + word)
pairs = delimitedList(pair, '_')
print ','.join(':'.join(t) for t in
pairs.parseString('hi_cat_bye_dog').asList())
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
"
Remember that comments have to maintained along with the rest of the
code, so unnecessary ones just create more work for you. Any time you
can replace a comment with self-explanatory code, you should.
Here's a vast improvement:
class TemperatureSenseTester(ar_test.AR_TEST):
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
nimplemented rich comparison between disparate types is
(usually) not. It could be made to work with one object fulfilling
both functions, but then the name would be wrong for one case or the
other.
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
bably why collections.defaultdict
is so popular.
>>> def f():
...return 7
...
>>> d = defaultdict(f, a=1)
>>> d['a']
1
>>> d['b']
7
get and setdefault aren't needed when using a default dict, and the
default factory is called only when needed.
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
x27;s constructor initialization lists are the closest thing to
Python's __new__. They can perform tasks for which Python might need
__new__. For example, a class member that's a reference must be
initialized in the initialization list, because it cannot be set once
the body of the constructor begins.
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
, then binary search may be
feasible (though not actually recommended for such small list).
import bisect
i = bisect.bisect_left(L, ('b', '00'))
if i[0] == 'b':
del L[i]
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 15, 2008 4:28 AM, John Machin <[EMAIL PROTECTED]> wrote:
> On Jan 15, 9:58 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
> > Module StringIO is your friend.
>
> and cStringIO is your ?
... friend +1?
--
Neil Cerutti <[EMAIL PROTECTED]&g
;>> s
> set([1, 2, 3, 4, 5, 6])
>
> Why is that? Doesn't the |= operator essentially map to an update() call?
No, according to 3.7 Set Types, s | t maps to s.union(t).
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
nal, which works fine when the
operand is not a set.
But set_ior specifically punts non-sets before calling set_update_internal.
So this is a bug in set_update or in set_ior. They can't both be
right.
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 15, 2008 12:06 PM, Chris M <[EMAIL PROTECTED]> wrote:
> On Jan 15, 11:51 am, "Neil Cerutti" <[EMAIL PROTECTED]> wrote:
> >
> > So this is a bug in set_update or in set_ior. They can't both be
> > right.
> >
>
> It's not a b
, but bear in mind that Python's "references" may
be rebound to new objects, which is quite different from the usual
behavior of references.
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
re module. There are some scanf-like
libraries for Python available on the net, e.g.,
http://hkn.eecs.berkeley.edu/~dyoo/python/scanf/. None of them have
become popular enough with Python users to make it into the standard
distribution.
An excellent tool that can be used in these cases is pyp
On Jan 16, 2008 7:58 AM, <[EMAIL PROTECTED]> wrote:
> On Jan 16, 1:21 pm, "Neil Cerutti" <[EMAIL PROTECTED]> wrote:
> > In the following function, a is rebound with an assignment statement,
> > while b is mutated, i.e., changed, with an assignment statement
it__(self, extern_rep):
# parse or translate extern_rep into ...
self.name = ...
self.age = ...
# Use a dictionary instead of parallel lists.
self.data = {...}
def process(self):
# Do what you need to do.
fstream = open('thedatafile')
f
None]
DICT = {}
for Type in C.TYPES:
C.DICT.update((E, Type) for E in [1])
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 17, 2008 10:44 AM, Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
> "Neil Cerutti" <[EMAIL PROTECTED]> writes:
>
> > You cannot access a class's class variables in it's class-statement
> > scope, since the name of the type is not bound until a
On Jan 17, 2008 10:23 AM, Neil Cerutti <[EMAIL PROTECTED]> wrote:
> You cannot access a class's class variables in it's class-statement
> scope, since the name of the type is not bound until after the class
> statement is completed.
Arrgh! I hate making the "its&qu
On Jan 17, 2008 11:08 AM, <[EMAIL PROTECTED]> wrote:
> On Jan 17, 4:59 pm, "Neil Cerutti" <[EMAIL PROTECTED]> wrote:
> > Generator expressions, unlike list comprehensions, have their own
> > scope so that they don't "leak" names to the enclosing
gt;>> class C:
... @staticmethod
... def f1(): pass
... print f1
...
>>> print C.f1
The class statement's local namespace is pretty strange. I think I
mightl go back to pretending there isn't one.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
rguments",
which would be hard to guess without already knowing what's going
wrong, or "python gotchas pitfalls", which is a good general purpose
search for when you can't understand what's happening in simple code.
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
have any code to show, write some. Unless it's a quine, a
program won't write itself.
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
On 1/18/08, Ross Ridge <[EMAIL PROTECTED]> wrote:
> Neil Cerutti <[EMAIL PROTECTED]> wrote:
> >The decoration is setting the class type's f1 attribute correctly, but
> >doing something strange in the local namespace.
> >
> >>>> class C:
> >
pass. All the failing
tests might be kind of depressing, though. Personally, I haven't
really given top-down a fair shake, so I don't know which approach
reveals my stupid design mistakes faster.
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 29, 2008 2:06 PM, Neal Becker <[EMAIL PROTECTED]> wrote:
> I want python code that given an instance of a type, prints the type name,
> like:
>
> typename (0) -> 'int'
typename = lambda x: type(x).__name__
--
Neil Cerutti <[EMAIL PROTECTED]>
--
ht
mullet:
i = 0
while i < len(a):
if a[i] == 99:
del a[i]
else:
i += 1
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
On 30 Jan 2008 05:20:49 -0800, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> "Neil Cerutti" <[EMAIL PROTECTED]> writes:
> > Or one can put on his bellbottoms, horn-rimmed glasses, and wear a mullet:
> >
> > i = 0
> > while i
< iy else (iy, ix))
else:
break
y += 1
x += 1
return rv
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
There's nothing terribly wrong with it, I guess, but it does look
"hairier" when really it isn't.
Moreover, "invalid syntax" is a bit terse--but probably it's not worth
it to complicate the grammar just for a better error message.
Finally, any ideas for a p
On Feb 1, 2008 3:16 PM, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> On Feb 1, 2:44 pm, "Neil Cerutti" <[EMAIL PROTECTED]> wrote:
> > Here's another contender, basically the same as yours, but spelled
> > without iterators.
> >
> > def o
;Ophidian," for the snake connection,
> or, possibly, "Circus," from "Monty Python's Flying Circus."
Given your stated goals, I like "Phyton."
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
def to_tagged_format(self):
...
for k, v in d.iteritems():
d[k] = v.to_tagged_format()
You can also get the dynamic polymorphism without invoking inheritance
by specifying a protocol that the values in your dict must implement,
instead. Protocols are plentiful in Python, perhaps more popular than
type hierarchies.
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
face. In that case, inheritance often saves boilerplate cide
rather than increases it.
It's also misnomered as duck-typing (clearly it should be nomed quack-typing).
--
Neil Cerutti <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list
s as a starting point, if you want to use Python.
> There are many good reasons why someone might want to use a general
> purpose language like Python to write a text adventure,
Yes.
> such as so
> they're not stuck with a quasi hack of a language if they have to do
> somethin
On Tue, Apr 15, 2008 at 9:25 AM, Carl Banks <[EMAIL PROTECTED]> wrote:
> On Apr 11, 12:08 pm, "Neil Cerutti" <[EMAIL PROTECTED]> wrote:
> > > such as so
> > > they're not stuck with a quasi hack of a language if they have to do
> > > so
, you can do something like:
:set tabstop=4
:set expandtab
:retab
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
en(lst[j]):
i -= len(lst[j])
j += 1
lst[j][i] = val
def get_flattened(lst, i):
j = 0
while i >= len(lst[j]):
i -= len(lst[j])
j += 1
return lst[j][i]
A "view" should be easier to use and debug than your current
flatten, mutate and unflatten approach.
The abov
that so I'll leave it for others.
from __future__ import with_statement
# Etc.
for (exten, list) in files.iteritems():
with open('extensions-%s.txt' % exten,'w') as f:
f.write('\n'.join(list))
f.write('\n')
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
ocs...
No, sets are unordered in Python.
You'll need to sort them when you need them sorted, or keep a
sorted list separately.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2009-12-07, W. eWatson wrote:
> See Subject.
> def StackImages(self):
> self.Upload("P")
> self.after_id = self.master.after(1,self.GetFrameOne)
It's a violation of the Law of Demeter.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2009-12-07, Neil Cerutti wrote:
> On 2009-12-07, W. eWatson wrote:
>> See Subject.
>> def StackImages(self):
>> self.Upload("P")
>> self.after_id = self.master.after(1,self.GetFrameOne)
>
> It's a violation of the
On 2009-12-11, Grant Edwards wrote:
> [s[1:-1] for s in l if (s[0] == s[-1] == '*')]
That last bit doesn't work right, does it, since an == expression
evaluates to True or False, no the true or false value itself?
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2009-12-11, Grant Edwards wrote:
> On 2009-12-11, Neil Cerutti wrote:
>> On 2009-12-11, Grant Edwards wrote:
>>> [s[1:-1] for s in l if (s[0] == s[-1] == '*')]
>>
>> That last bit doesn't work right, does it, since an == expression
>> eva
nfig(p.join(p.dirname(__file__),'logging.cfg'))
__file__ is undefined in your example code, so I'm not getting
the same exception as you.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2009-12-15, Neil Cerutti wrote:
> On 2009-12-15, Peter wrote:
>> on python 2.6 the following code raises an AttributeError:
>>
>> #!/usr/bin/env python
>> import os.path as p
>> import logging, logging.config
>>
>>
>&g
I think a programming language does encourage a certain kind of
code. Good code in one language can be poor in another.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
ides information that
> might be useful when you're debugging a program. This is
> better:
>
>fname = 'red.txt'
>inpf = open(fname, "r")
Alternatively:
>>> infile = open("red.txt", "r")
>>> infile.name
'red.txt'
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
ry minute so that it'll start with the next
> letter, eg. display the list from A...Zdigits the first time,
> then B...ZAdigits, etc.
Resorting is more work than is needed. Just choose a different
starting index each time you display the names, and set up your
lister to wrap-around to
On 2010-01-22, Steven D'Aprano wrote:
> On Fri, 22 Jan 2010 13:35:26 +0000, Neil Cerutti wrote:
>> On 2010-01-22, Gilles Ganault wrote:
>>> Hello
>>>
>>> I use a dictionary to keep a list of users connected to a web site.
>>>
>>> To avoi
names. A random starting position is thus
more fair *and* more efficient. ;)
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
x27;/spam', '/eggs')
You'll have to do something else, for example:
>>> s = re.compile(r'(?:[a-zA-Z]:)')
>>> n = re.compile(r'[\\/]\w+')
>>> m = s.match('c:/tmp/spam/eggs')
>>> n.findall(m.string[m.end():])
['/tmp', '/spam', '/eggs']
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
1001 - 1100 of 1188 matches
Mail list logo