Re: File to dict

2007-12-07 Thread Neil Cerutti
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): >

Re: File to dict

2007-12-07 Thread Neil Cerutti
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

Re: Equivalent of perl's Pod::Usage?

2007-12-08 Thread Neil Cerutti
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

Re: Are Python deques linked lists?

2007-12-09 Thread Neil Cerutti
rce, or perhaps Raymond is reading and could explain. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Are Python deques linked lists?

2007-12-10 Thread Neil Cerutti
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

Re: Are Python deques linked lists?

2007-12-10 Thread Neil Cerutti
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

Re: searching a value of a dict (each value is a list)

2007-12-10 Thread Neil Cerutti
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

Re: Are Python deques linked lists?

2007-12-10 Thread Neil Cerutti
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

Re: Are Python deques linked lists?

2007-12-10 Thread Neil Cerutti
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: >>>

Re: Are Python deques linked lists?

2007-12-10 Thread Neil Cerutti
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)]) >>>

Re: Are Python deques linked lists?

2007-12-11 Thread Neil Cerutti
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

Re: "do" as a keyword

2007-12-11 Thread Neil Cerutti
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

Re: Are Python deques linked lists?

2007-12-11 Thread Neil Cerutti
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

Re: Are Python deques linked lists?

2007-12-12 Thread Neil Cerutti
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

Re: Is anyone happy with csv module?

2007-12-12 Thread Neil Cerutti
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

Re: Is anyone happy with csv module?

2007-12-12 Thread Neil Cerutti
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

__init__ method for containers

2007-12-12 Thread Neil Cerutti
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

Re: __init__ method for containers

2007-12-12 Thread Neil Cerutti
_(...) 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

Re: Is anyone happy with csv module?

2007-12-12 Thread Neil Cerutti
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

Re: Is anyone happy with csv module?

2007-12-12 Thread Neil Cerutti
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

Re: __init__ method for containers

2007-12-12 Thread Neil Cerutti
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

Re: mimicking a file in memory

2007-12-12 Thread Neil Cerutti
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

Re: efficient data loading with Python, is that possible possible?

2007-12-13 Thread Neil Cerutti
): 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

Re: Is anyone happy with csv module?

2007-12-13 Thread Neil Cerutti
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 >

Re: Is Python really a scripting language?

2007-12-13 Thread Neil Cerutti
rmally: >>> hasattr(Language, 'iterpreted') False >>> hasattr(Implementation, 'interpreted') True ;-) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Pascal code checker!

2007-12-13 Thread Neil Cerutti
. 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

Re: Is Python really a scripting language?

2007-12-13 Thread Neil Cerutti
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

Re: Finding overlapping times...

2007-12-14 Thread Neil Cerutti
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

Re: simple string formatting question

2007-12-14 Thread Neil Cerutti
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

Re: Loops and things

2007-12-14 Thread Neil Cerutti
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

container.___le___ can use only <=?

2007-12-14 Thread Neil Cerutti
e a legitimate complaint when using LarchTree.__le__ results in an attribute error? -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT] Fractions on musical notation

2007-12-17 Thread Neil Cerutti
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

Re: container.___le___ can use only <=?

2007-12-19 Thread Neil Cerutti
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

Re: Another newbie design question

2007-12-19 Thread Neil Cerutti
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

Re: replace c-style comments with newlines (regexp)

2007-12-21 Thread Neil Cerutti
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

Re: Extract a number from a complicated string

2007-12-21 Thread Neil Cerutti
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

Re: getting n items at a time from a generator

2007-12-29 Thread Neil Cerutti
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

Re: Bizarre behavior with mutable default arguments

2008-01-01 Thread Neil Cerutti
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

Re: pyparsing question

2008-01-01 Thread Neil Cerutti
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

Re: pyparsing question

2008-01-01 Thread Neil Cerutti
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

Re: Details about pythons set implementation

2008-01-04 Thread Neil Cerutti
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

Re: How Does This Static Variable Work?

2008-01-04 Thread Neil Cerutti
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

Re: fastest method to choose a random element

2008-01-04 Thread Neil Cerutti
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

Re: fastest method to choose a random element

2008-01-04 Thread Neil Cerutti
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

Re: MRO Error on Multiple Inheritance?

2008-01-04 Thread Neil Cerutti
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

Re: Basic inheritance question

2008-01-06 Thread Neil Cerutti
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

Re: Python's great, in a word

2008-01-07 Thread Neil Cerutti
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

Re: Open a List of Files

2008-01-08 Thread Neil Cerutti
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

Re: I'm searching for Python style guidelines

2008-01-08 Thread Neil Cerutti
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

Re: alternating string replace

2008-01-09 Thread Neil Cerutti
).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

Re: alternating string replace

2008-01-09 Thread Neil Cerutti
).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

Re: docstrings style question

2008-01-10 Thread Neil Cerutti
" 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

Re: NotImplimentedError

2008-01-14 Thread Neil Cerutti
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

Re: short path evaluation, why is f() called here: dict(a=1).get('a', f())

2008-01-14 Thread Neil Cerutti
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

Re: __init__ explanation please

2008-01-14 Thread Neil Cerutti
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

Re: common problem - elegant solution sought

2008-01-15 Thread Neil Cerutti
, 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

Re: Append zip files together, just get the binary data (in memory)

2008-01-15 Thread Neil Cerutti
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

Re: Why this apparent assymetry in set operations?

2008-01-15 Thread Neil Cerutti
;>> 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

Re: Why this apparent assymetry in set operations?

2008-01-15 Thread Neil Cerutti
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

Re: Why this apparent assymetry in set operations?

2008-01-15 Thread Neil Cerutti
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

Re: no pass-values calling?

2008-01-16 Thread Neil Cerutti
, 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: Generic string import like in strptime?

2008-01-16 Thread Neil Cerutti
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

Re: no pass-values calling?

2008-01-16 Thread Neil Cerutti
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

Re: Python help for a C++ programmer

2008-01-16 Thread Neil Cerutti
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

Re: Is this a bug, or is it me?

2008-01-17 Thread Neil Cerutti
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

Re: Is this a bug, or is it me?

2008-01-17 Thread Neil Cerutti
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

Re: Is this a bug, or is it me?

2008-01-17 Thread Neil Cerutti
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

Re: Is this a bug, or is it me?

2008-01-17 Thread Neil Cerutti
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

Re: Is this a bug, or is it me?

2008-01-18 Thread Neil Cerutti
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

Re: Bug in __init__?

2008-01-18 Thread Neil Cerutti
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

Re: Filtering two files with uncommon column

2008-01-18 Thread Neil Cerutti
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

Re: Is this a bug, or is it me?

2008-01-18 Thread Neil Cerutti
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: > >

Re: Test driven development

2008-01-24 Thread Neil Cerutti
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

Re: typename

2008-01-29 Thread Neil Cerutti
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

Re: Removal of element from list while traversing causes the next element to be skipped

2008-01-30 Thread Neil Cerutti
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

Re: Removal of element from list while traversing causes the next element to be skipped

2008-01-30 Thread Neil Cerutti
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

Re: How to identify which numbers in a list are within each others' range

2008-02-01 Thread Neil Cerutti
< iy else (iy, ix)) else: break y += 1 x += 1 return rv -- Neil Cerutti <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Nested compound statements.

2008-02-01 Thread Neil Cerutti
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

Re: How to identify which numbers in a list are within each others' range

2008-02-01 Thread Neil Cerutti
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

Re: Project naming suggestions?

2008-02-05 Thread Neil Cerutti
;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

Re: Checking if a variable is a dictionary

2008-03-06 Thread Neil Cerutti
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

Re: Checking if a variable is a dictionary

2008-03-06 Thread Neil Cerutti
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

Re: text adventure game problem

2008-04-11 Thread Neil Cerutti
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

Re: text adventure game problem

2008-04-16 Thread Neil Cerutti
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

Re: how to format a python source file with tools?

2009-11-30 Thread Neil Cerutti
, you can do something like: :set tabstop=4 :set expandtab :retab -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: flattening and rebuilding a simple list of lists

2009-11-30 Thread Neil Cerutti
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

Re: slightly OT: Python BootCamp

2009-12-04 Thread Neil Cerutti
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

Re: More elegant solution for diffing two sequences

2009-12-04 Thread Neil Cerutti
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

Re: What is the significance of after() in this code?

2009-12-07 Thread Neil Cerutti
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

Re: What is the significance of after() in this code?

2009-12-07 Thread Neil Cerutti
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

Re: a list/re problem

2009-12-12 Thread Neil Cerutti
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

Re: a list/re problem

2009-12-15 Thread Neil Cerutti
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

Re: AttributeError: logging module bug ?

2009-12-15 Thread Neil Cerutti
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

Re: AttributeError: logging module bug ?

2009-12-15 Thread Neil Cerutti
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

Re: Object Relational Mappers are evil (a meditation)

2009-12-17 Thread Neil Cerutti
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

Re: Dynamic text color

2010-01-06 Thread Neil Cerutti
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

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Neil Cerutti
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

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Neil Cerutti
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

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Neil Cerutti
names. A random starting position is thus more fair *and* more efficient. ;) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Regexp and multiple groups (with repeats)

2009-11-20 Thread Neil Cerutti
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

<    6   7   8   9   10   11   12   >