Re: Help me understand this

2007-01-30 Thread Neil Cerutti
ar documentation. > These are the relevant rules: > > attributeref ::= primary "." identifier > > primary ::= atom | attributeref | subscription | slicing | call > > atom ::= identifier | literal | enclosure > > literal ::= stringliteral | integer | longinteger |

Re: division by 7 efficiently ???

2007-02-02 Thread Neil Cerutti
t; 9 >>>> div7 (77) > 10 >>>> div7 (700) > 98 >>>> div7 (7) > 0 >>>> div7 (10) > 1 >>>> div7 (14) > 1 >>>> div7 (21) > 2 >>>> div7 (700) > 98 >>>> div7 (7000) > 984 > Heh, heh. That&

Re: How do I print out in the standard output coloured lines

2007-02-02 Thread Neil Cerutti
the phrase "Windows curses" is used, I > expect. On Windows, there's pdcurses for DOS or ncurses for the Cygwin platform, but I don't know how to get either to work with Python. Far simpler to get working in Windows is Fredrik Lundh's Console. http://www.effbot.org/downloads/#console If you're using Windowd 98 or earlier there are versions of a Python readline library that provide cursor addressing and color using the ANSI excape sequences. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: need help on a data structure problem

2007-02-02 Thread Neil Cerutti
ost here: > > Better, you should discuss it in your class, with your teacher. Also: comp.algorithms is the usual Usenet place for discussion of algorithms and data structures. However most of the talk there is pretty high-falutin'. -- Neil Cerutti It isn't pollution that is hur

Re: Overloading the tilde operator?

2007-02-02 Thread Neil Cerutti
erators, including defining precedence level and associativity (I can't think of the name right now). C++, for example, works the same way as Python here. You can override most of the operators, but you cannot change their arity, associativity, or precedence level. -- Neil Cerutti Let us

Re: newbie/ merging lists of lists with items in common

2007-02-02 Thread Neil Cerutti
y of not assuming the alist was sorted already. This could be a one-liner if you wanted to be evil. def bundle_alist(seq): """ Bundle together some alist tails. >>> seq = [['a', '13'], ['a', '3'], ['b', '6

Re: newbie/ merging lists of lists with items in common

2007-02-02 Thread Neil Cerutti
On 2007-02-02, Laurent Pointal <[EMAIL PROTECTED]> wrote: > Neil Cerutti a écrit : >> On 2007-02-02, ardief <[EMAIL PROTECTED]> wrote: > > >> This is a job for... duhn-duhn-DH! Captain CHAOS! >> >> Er... I mean itertools.groupby. >> >

Re: Writing "pythonish" code

2007-02-02 Thread Neil Cerutti
d" > which makes it more difficult for other code (even subclasses!) > to access the member. Difficult though -- not impossible. I think it's best to never use such names in new code. Python's mangling is troubled, since it uses unqualified names in the mangle, resulting in

Re: Checking default arguments

2007-02-02 Thread Neil Cerutti
roviding defaults, but using positional arguments. Here's a silly example, which returns a tuple if the user supplies the second argument, and a list otherwise. def foo(x, *args): if len(args) == 0: y_provided = True y = "bar" else: y_provided = False y = args[0]

Re: How to suppress "DeprecationWarning: Old style callback, use cb_func(ok, store) instead"

2007-02-03 Thread Neil Cerutti
gs("ignore", message="Old style callback, use >> cb_func(ok, store) instead") > > Or you can be more aggressive and filter out all DeprecationWarnings: > warnings.simplefilter("ignore",DeprecationWarning) > (same as using option -Wignore

Re: confused about resizing array in Python

2007-02-05 Thread Neil Cerutti
r to avoid heart, head and stomach aches. A reference counted pointer type will come fairly close to Python semantics. -- Neil Cerutti Eddie Robinson is about one word: winning and losing. --Eddie Robinson's agent Paul Collier -- http://mail.python.org/mailman/listinfo/python-list

Re: HELP NEEDED ... Regd. Regular expressions PyQt

2007-02-05 Thread Neil Cerutti
On 2007-02-03, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I am trying to work out a regular expression in a PyQt > environment for time in hh:mm:ss format. Any suggestions? After you find your time in hh:mm:ss format, be sure to check out time.strptime for a quick conversio

Re: Trouble fixing a broken ASCII string - "replace" mode in codec not working.

2007-02-06 Thread Neil Cerutti
;> asciitable = string.maketrans(''.join(chr(a) for a in xrange(127, 256)), ...'?'*127) You'd only want to do that once. Then to strip off the non-ascii: sitetext.translate(asciitable) I used a similar solution in an application I'm working on that must uses a Latin-1 byte-encoding internally, but displays on stdout in ascii. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Vim search under cursor

2007-02-07 Thread Neil Cerutti
s.error and pressing * on top of error > searches for os.error rather than error. How to set this, any Idea? It's will to break things, but you can do this by editing the iskeyword string and adding in the '.'. :h 'iskeyword'. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: doctests for interactive functions

2007-02-08 Thread Neil Cerutti
run automatically. What I've done in these cases is create a file containing my test input, and before running the doctests I remap sys.stdin to my file of test data. Then you don't need test code cluttering up your functions. -- Neil Cerutti We don't necessarily discriminate. We simpl

Re: doctests for interactive functions

2007-02-09 Thread Neil Cerutti
ue. > > Is this the sort of thing you mean, or is this the sort of > coupling you suggest I avoid? It has to be coupled somewhere. This seems like a good place to do it. The private methods can all be tested individually, so the doctests for get can be quite simple, or even absent. Note that sequestering the test input in a file doesn't allow for good examples, unfortunately. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Is Python for me?

2007-02-09 Thread Neil Cerutti
ambition a bit, at first. Firts write a program to rank complete sets of poker hands. That should hold you for a while. -- Neil Cerutti The recording I listened to had Alfred Brendel doing the dirty work of performing this sonata (Liszt B minor) --Music Lit Essay -- http://mail.python.org/mailman/listinfo/python-list

Re: How to find all the same words in a text?

2007-02-11 Thread Neil Cerutti
n find words in strings. The last thing to do is to search those actual words for the word you're looking for. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: gvim: doc string editing

2007-02-11 Thread Neil Cerutti
s composed. Do :h format_comments for the full dope. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expressions

2007-02-12 Thread Neil Cerutti
ions is to implement them. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: searching a list of lists as a two-dimensional array?

2007-02-12 Thread Neil Cerutti
the >> occupancy word. Normally you'd have separate occupancy words >> for your own pieces and your opponent's. > > In defense of the less efficient suggestions, he did say he had > to use a list of lists. But what you describe is pretty cool. Precomputing and storing the adjecent indexes for each square would be a possible hybrid solution. In effect every square would contain pointers to all its neighbors. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Vim scripting with python

2007-02-12 Thread Neil Cerutti
rint > 'Hello'", and got "E319: Sorry, the command is not available in > this version" The latest Windows build has the Python bindings included. The one I have is version 7.0. Earlier Windows binaries didn't generally have it. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: c++ for python programmers

2007-02-13 Thread Neil Cerutti
rup _The C++ Programming language_. -- 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: multiple inheritance of a dynamic list of classes?

2007-02-13 Thread Neil Cerutti
notonicity did not hold. URL:http://www.python.org/download/releases/2.3/mro/ -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: float print formatting

2007-02-13 Thread Neil Cerutti
On 2007-02-13, hg <[EMAIL PROTECTED]> wrote: > Hi, > > Considering the float 0.0, I would like to print 00.00. > > I tried '%02.02f' % 0.0 ... but I get 0.00 > > Any clue ? Yes. How wide (total) is "0.00", compared to "00.00"? -- Neil C

Re: float print formatting

2007-02-13 Thread Neil Cerutti
On 2007-02-13, hg <[EMAIL PROTECTED]> wrote: > Neil Cerutti wrote: > >> On 2007-02-13, hg <[EMAIL PROTECTED]> wrote: >>> Hi, >>> >>> Considering the float 0.0, I would like to print 00.00. >>> >>> I tried '%02.02f' %

Re: c++ for python programmers

2007-02-14 Thread Neil Cerutti
hate to switch back. Of course it has its warts and cancers, but it's an awesome accomplishment. And you *can* get harder-to-use C versions that are basically portable. -- Neil Cerutti A billion here, a billion there, sooner or later it adds up to real money. --Everett Dirksen -- http://mail.python.org/mailman/listinfo/python-list

Re: Recursive calls and stack

2007-02-14 Thread Neil Cerutti
urn sum(seq[1:], accum+s[0]) Since no state must be retained by sum when calling sum, it's a tail call. The last version translates more or less directly into a dumb while loop. I don't believe Python does tail call optimization; at least it isn't document that it does it. -- Neil Cer

Re: rot13 in a more Pythonic style?

2007-02-14 Thread Neil Cerutti
itself, it's just a convenient > substitute example for the real job-specific task. No, I don't > have to do it with lambdas, but it would be nice if the final > function was a lambda. How would it being a lambda help you? -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: multiple inheritance of a dynamic list of classes?

2007-02-14 Thread Neil Cerutti
On 2007-02-14, Peter Otten <[EMAIL PROTECTED]> wrote: > Neil Cerutti wrote: > >> On 2007-02-13, Peter Otten <[EMAIL PROTECTED]> wrote: >>> Well, what problems ocurring with >>> >>> class A: pass >>> class B: pass >>> class C(

Re: c++ for python programmers

2007-02-14 Thread Neil Cerutti
7;s not already stated in _The C++ Programming Language_. Granted, TCPL is so dense that it wasn't until *after* reading _Effective C++_ (Scott Meyers), that I noticed this. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: f---ing typechecking

2007-02-15 Thread Neil Cerutti
m the operation in place "whenever possible", so there are objects for which a conversion to .extend wouldn't work, and you'd get an actual call of the + operation followed by the assignment operation. -- Neil Cerutti I don't know what to expect right now, but we as players have to do what we've got to do to make sure that the pot is spread equally. --Jim Jackson -- http://mail.python.org/mailman/listinfo/python-list

Re: f---ing typechecking

2007-02-15 Thread Neil Cerutti
keys are the same sort of thing. Even though they aren't in any sequence, it's still useful to iterate over them. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Method overloading?

2007-02-15 Thread Neil Cerutti
mally in the context of C++ as "function overloading", though it's really "identifier overloading where identifier refers to a function or member function". What Python provides is dynamic polymorphism of names with single-dispatch. I think. ;-) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Recursive calls and stack

2007-02-15 Thread Neil Cerutti
On 2007-02-15, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > En Wed, 14 Feb 2007 10:41:53 -0300, Neil Cerutti <[EMAIL PROTECTED]> > escribió: >> So the effect is that mutual recursion isn't actually any >> harder. > > But some kind of language suppo

Re: multiple inheritance of a dynamic list of classes?

2007-02-15 Thread Neil Cerutti
e = 'in' That code sets me to thinking I'll get good mileage from: class Stream(object): ... class InStream(object): ... class OutStream(object): ... class InOutStream(object): ... I always get myself into trouble when I try to design a class hierarchy *before* I see

Re: Recursive calls and stack

2007-02-15 Thread Neil Cerutti
On 2007-02-15, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > En Thu, 15 Feb 2007 13:37:19 -0300, Neil Cerutti <[EMAIL PROTECTED]> > escribió: > >> On 2007-02-15, Gabriel Genellina <[EMAIL PROTECTED]> wrote: >>> En Wed, 14 Feb 2007 10:41:53 -0300, Nei

Re: Recursive calls and stack

2007-02-15 Thread Neil Cerutti
support either. Mutual recursion (and generic tail call > elimination) require some sort of external support: one can't > eliminate the call just by transforming the program. Ah, I see now. Had my blinders on. -- Neil Cerutti Low Self-Esteem Support Group will meet Thursd

Re: why I don't like range/xrange

2007-02-16 Thread Neil Cerutti
hand form of > "pre; while(cond) {code; post;}" > Which translated to Python would be: > > pre > while cond: > code > post No, when you consider the continue statement, which which Python also supports. for (pre; cond; post) { continue; } That's not an

Re: Help Required for Choosing Programming Language

2007-02-16 Thread Neil Cerutti
ell, what else did you excect a denizen of a Python group to tell you?) -- Neil Cerutti Baseball has the great advantage over cricket of being sooner ended. --George Bernard Shaw -- http://mail.python.org/mailman/listinfo/python-list

Re: eval('000052') = 42?

2007-02-21 Thread Neil Cerutti
You know, it's just the answer to the ultimate question of > Life, the universe, and everything. Yeah, but I was hoping the question would've turned out better. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: f---ing typechecking

2007-02-21 Thread Neil Cerutti
asonable counterexample ;-) > > I don't think its reasonable - its just an accident of implementation.. Yup. It's analogous to the way you can do hill-starts with a manual transmission, but not with an automatic transmission. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Convert to binary and convert back to strings

2007-02-22 Thread Neil Cerutti
you can encode the string with rot13 twice. >> >> >> > > Like this? ;) > > >>> s = "Python" ; u = unicode(s, "ascii") ; u > u'Python' > >>> u.encode('rot13') > 'Clguba' > >>> u.

Re: CSV(???)

2007-02-23 Thread Neil Cerutti
(); output undefined > if csvline is in invalid format""" > > s = indexedstring(csvline) > res = [] > > while not s.eos(): >res.append(s.getfield()) > > return res You'll be happy to know that iterators and list comprehensions will make your code

Re: Pep 3105: the end of print?

2007-02-26 Thread Neil Cerutti
break too much >> old code. > > While that's true, C++ compiler vendors, for example, take > backwards compatibility significantly less seriously, it seems > to me. Compiler vendors usually take care of their customers with compiler switches that enable backwards compatibility. -

Re: CSV(???)

2007-02-26 Thread Neil Cerutti
On 2007-02-24, David C Ullrich <[EMAIL PROTECTED]> wrote: > On 23 Feb 2007 19:13:10 +0100, Neil Cerutti <[EMAIL PROTECTED]> wrote: > >>On 2007-02-23, David C Ullrich <[EMAIL PROTECTED]> wrote: >>> Is there a csvlib out there somewhere? >>> >

Re: Lists: Converting Double to Single

2007-02-27 Thread Neil Cerutti
L = [pow(2, -x) for x in L] >>> "%40.40f" % mean1(*L) '0.012109375000' >>> "%40.40f" % mean2(*L) '0.012109375200' Offhand, I think the first is "righter". Weird! -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Is pyparsing really a recursive descent parser?

2007-11-03 Thread Neil Cerutti
he first alternative, > word followed by grammar, failed. Level 3 then moves on to see if > word followed by the literal 'end' matches, and it does - success! > > Here's where I am stuck now. In the original grammar that you posted, > which you want to render into this behavior, grammar is defined as: > > grammar = OneOrMore(Word(alphas)) + Literal('end') Is there not an ambiguity in the grammar? In EBNF: goal --> WORD { WORD } END WORD is '[a-zA-Z]+' END is 'end' I think it is fine that PyParsing can't guess what the composer of that grammar meant. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Is pyparsing really a recursive descent parser?

2007-11-03 Thread Neil Cerutti
On 2007-11-04, Just Another Victim of the Ambient Morality <[EMAIL PROTECTED]> wrote: > > "Neil Cerutti" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> On 2007-11-03, Paul McGuire <[EMAIL PROTECTED]> wrote: >>> On Nov 3, 12

Re: Is pyparsing really a recursive descent parser?

2007-11-04 Thread Neil Cerutti
On 2007-11-04, Kay Schluehr <[EMAIL PROTECTED]> wrote: > On 4 Nov., 03:07, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> I wouldn't characterize it as pretending. How would you parse: >> >> hello end hello end >> >> "WORD END WORD END"

Re: Is pyparsing really a recursive descent parser?

2007-11-04 Thread Neil Cerutti
it's usually > not. That is to say, as long as it is rare that 'end' is used > not at the end of the string, this will simply parse and, yet, > pyparsing will consistently fail to parse it... I believe there's no cure for the confusion you're having except for implementing a parser for your proposed grammar. Alternatively, try implementing your grammar in one of your other favorite parser generators. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Is pyparsing really a recursive descent parser?

2007-11-04 Thread Neil Cerutti
On 2007-11-04, Just Another Victim of the Ambient Morality <[EMAIL PROTECTED]> wrote: > "Neil Cerutti" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> I believe there's no cure for the confusion you're having except >> f

Re: Is pyparsing really a recursive descent parser?

2007-11-04 Thread Neil Cerutti
On 2007-11-05, Just Another Victim of the Ambient Morality <[EMAIL PROTECTED]> wrote: > > "Neil Cerutti" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> On 2007-11-04, Just Another Victim of the Ambient Morality >> <[EMAIL PROTECTED

Re: Is pyparsing really a recursive descent parser?

2007-11-04 Thread Neil Cerutti
27;t use Python to write > fast code, I use it to write code fast. > If _you_ "don't like to compromise speed for implementation > simplicity" then you have a plethora choices available to you. > What about the guy who needs to parse correctly and is > unconcerned about speed? You have to be concerned about speed when something runs so slowly in common circumstances compared to other well-known algotithms that you can't practically wait for an answer. Would you consider bubble-sort a suitable general-purpose sorting algorithm for Python? -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Is pyparsing really a recursive descent parser?

2007-11-04 Thread Neil Cerutti
On 2007-11-05, Neil Cerutti <[EMAIL PROTECTED]> wrote: > def Ack(x, y): > """ The Ackermann function. Creates a humongous mess even > with quite tiny numbers. """ > if x < 0 or y < 0: > raise ValueError('non-negativ

Re: Is pyparsing really a recursive descent parser?

2007-11-05 Thread Neil Cerutti
On 2007-11-05, Just Another Victim of the Ambient Morality <[EMAIL PROTECTED]> wrote: > "Neil Cerutti" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> There are different kinds of recursion. Compare: > > While interesting, none of t

Re: Is pyparsing really a recursive descent parser?

2007-11-06 Thread Neil Cerutti
e as a backend for the library you're currently working on. http://www.cpsc.ucalgary.ca/~aycock/spark/ -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Populating huge data structures from disk

2007-11-06 Thread Neil Cerutti
and once the mlock finishes bringing important-data into RAM, at > the speed of your disk I/O subsystem, all accesses to x will be > hits against RAM. > > > Any thoughts? Disable the garbage collector, use a while loop and manual index instead of an iterator, preallocate your list, e.g., [None]*1, and hope they don't have blasters! -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Is pyparsing really a recursive descent parser?

2007-11-07 Thread Neil Cerutti
On 2007-11-07, Just Another Victim of the Ambient Morality <[EMAIL PROTECTED]> wrote: > "Neil Cerutti" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> You might be interested in the Early parsing algorithm. It is >> more efficient than t

Re: Binary search tree

2007-11-09 Thread Neil Cerutti
into a set. You can check for existence (very fast) > and at the end it is easy to sort. The set is likely the way to go. Python's library support for binary search trees consists of the bisect module. -- Neil Cerutti Ask about our plans for owning your home --sign at mortgage company -- http://mail.python.org/mailman/listinfo/python-list

Re: Some "pythonic" suggestions for Python

2007-11-10 Thread Neil Cerutti
oop constructs are plenty proliferate. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Convert some Python code to C++

2007-11-13 Thread Neil Cerutti
t; the types for the arguments passed into the function as well. > > I think lists are called arrays in C++. I don't know what the > "set" equivalent is though. It is called set, oddly enough. ;) There's an overload of the set::insert function that takes a couple of iterators that will serve for Python's update method. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Design Patterns - composition vs. inheritance

2007-11-16 Thread Neil Cerutti
Auto method, something that depends on an attribute of Tire, you must make that information available directly through the Axle interface. The benefit is that this lowers the coupling between classes. The Tire interface can change completely without affecting the Auto class. > BUT... Just lo

Re: timing puzzle

2007-11-16 Thread Neil Cerutti
On 2007-11-16, Robin Becker <[EMAIL PROTECTED]> wrote: > Neil Cerutti wrote: > ... > > > see why. >> >> You are no longer making m copies of active_nodes. > > my profiling indicated that the main problem was the removes. Yeah, I should've adde

Re: timing puzzle

2007-11-16 Thread Neil Cerutti
le of a sequence, you would normally choose a linked list. Python doesn't provide much support for linked lists, unfortunately. Instead, filter your list. It looks like you can't use filter directly, so just do it manually. for i in xrange(m): ... saved_nodes = []

Re: timing puzzle

2007-11-16 Thread Neil Cerutti
On 2007-11-16, Neil Cerutti <[EMAIL PROTECTED]> wrote: > Instead, filter your list. It looks like you can't use filter > directly, so just do it manually. > >for i in xrange(m): >... >saved_nodes = [] >for A in active_nodes[:]: I

Re: Python Design Patterns - composition vs. inheritance

2007-11-17 Thread Neil Cerutti
ith equal width and height is still a rectangle, in a strongly typed language. -- Neil cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: What is python?????

2007-11-17 Thread Neil Cerutti
Oh...here we are. Oh! Ha, ha, ha, very good. Ha, ha, ha, > very good. What a good punchline. Pity we missed that. def punchline(): return random.choice(['What's all this, then?', 'Do you want to come back to my place?']) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: implement random selection in Python

2007-11-19 Thread Neil Cerutti
)] """ begin, end, _ = probs[i] diff = end - begin j = i+1 while j < len(probs): begin, end, index = probs[j] probs[j] = (begin-diff, end-diff, index) j += 1 del probs[i] This was the most simple-minded approach I could think of, so it mi

s[i:j:t] = t stipulation

2007-11-20 Thread Neil Cerutti
ss complexity to the already complex slicing rules (kudos for 'slice.indices', though curses that the method isn't cross-referenced in more places). -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: s[i:j:t] = t stipulation

2007-11-21 Thread Neil Cerutti
On 2007-11-20, Terry Reedy <[EMAIL PROTECTED]> wrote: > "Neil Cerutti" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >| s[i:j:t] = t (1) t must have the same length as the slice it is > replacing. > > This is essentially the same rule as re

Re: eof

2007-11-21 Thread Neil Cerutti
. > In Ruby it's f.eof: > > In Ruby: >>> f = File.open("jopa") >=> # >>> f.read() >=> "jopa\n" >>> f.eof >=> true > > Is there a Python analog? Yes. >>> f = file('jopa') >>> f.read() &

Re: eof

2007-11-22 Thread Neil Cerutti
buried, decayed, and there's a fig tree growing out of the gravesight. Have a fig. > It's faster than Ruby, otherwise they're similar. When Ruby > X.Y gets faster, it'll be a tough call to between 'em. I use > Python to accomplish things I know how, with algori

Re: eof

2007-11-22 Thread Neil Cerutti
in an error state, yet naive C programmers often write code like: while (!f.feof()) { /* Read a line and process it. } ...and are flumoxed by the way it fails to work. I think Python is well rid of such a seldomly useful source of confusion. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: the annoying, verbose self

2007-11-23 Thread Neil Cerutti
redesign. def sum_of_squares(*args): return sum(arg*args for arg in args) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: eof

2007-11-23 Thread Neil Cerutti
sume it'll do the right thing if our file ends in \n. What > if the last line is not \n-terminated? Nothing bad happens as far as I know, but it may depend on the underlying clib. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: How to Teach Python "Variables"

2007-11-27 Thread Neil Cerutti
mphasis"), > but of the sort that take a paragraph or two of > explanation/clarification -- not a completely new model. There are more differences than similarities. Pointers are are a low-level mechanism suitable for many purposes, referencing values amongst them. Python identifiers are a high-level machanism, suitable for only one purpose. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: the annoying, verbose self

2007-11-27 Thread Neil Cerutti
(dict(var1=5, var2="a value", var3 = stuff, )) > > Someone else ? Or are we done with this DeadHorse ? I was really upset about having to type 'self' all the time, until I learned that in ABC, one of Python's precursors, you had to use '__anInstanceOf_This_TYP

Re: A bug in Python's regular expression engine?

2007-11-27 Thread Neil Cerutti
that errors are in your own code. Blaming library code and language implementations will get you nowhere most of the time. Hint 2: regular expressions and Python strings use the same escape character. Hint 3: Consult the Python documentation about raw strings, and what they are meant for. -

Re: How to Teach Python "Variables"

2007-11-28 Thread Neil Cerutti
increment x ? Not only that, you can't point x at any other object at all. That's not a Python variable either. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: How to Teach Python "Variables"

2007-11-28 Thread Neil Cerutti
On 2007-11-28, hdante <[EMAIL PROTECTED]> wrote: > On Nov 28, 1:42 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> On 2007-11-28, hdante <[EMAIL PROTECTED]> wrote: >> >> >> >> > On Nov 28, 1:09 am, Steven D'Aprano >> ><[EMAIL PR

Re: Tip of the day generator.

2007-11-28 Thread Neil Cerutti
tepath = homedir + '/quotes.txt' qfile = file(quotepath) quotelist = [] for quote in qfile: quotelist.append(quote) qfile.close() sigfile = file(sigpath, "w") sigfile.write("-- \n") sigfile.write("Neil Cerutti\n") random.seed() if random.choice([True, False])

Re: Tip of the day generator.

2007-11-28 Thread Neil Cerutti
On 2007-11-28, Neil Cerutti <[EMAIL PROTECTED]> wrote: > import textwrap > import random > import os > > print "Sigswap v0.4" > [...] Yikes! That program was in dire need of Pythonification. It must have been written early in my Pythonology. -- Neil Cerutti

Re: How do I not make a list?

2007-11-29 Thread Neil Cerutti
> on it (do an operation on each of the elements) and then pass > it onto something else that expects and iterable. I'm pretty > sure this something else doesn't need a list, either, and just > wants to iterate over elements. Try itertools.imap. something_else(imap(do_op

Re: Embedding Python - Passing by Reference

2007-11-29 Thread Neil Cerutti
and I know how to use PyArg_ParseTuple to get the value of a. > But how do I update the value of a in C? I tried (greatly > simplified): You cannot do it. You'll have to insist on a boxed value of some kind, like one stored in a list or an object. Python equivalent: >>> def foo(

Re: Oh no, my code is being published ... help!

2007-11-30 Thread Neil Cerutti
fer to > write the common 2.Xish way and let 2to3 do the work. Output ought be centralized to support maintenance, solving the 3.0 compatibility problem as a side-effect. So the above would be something like: my_print("Error Squeezing %s..." % the_thingy) With my_print defined approp

Re: "Python" is not a good name, should rename to "Athon"

2007-12-01 Thread Neil Cerutti
; afterwards. Bjarne was only interested in the side-effect. Anyhow, Pythonistas know it should've been called "C+=1". -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: "Python" is not a good name, should rename to "Athon"

2007-12-03 Thread Neil Cerutti
you than it does about him. He is widely regarded -- by > physicists and many other scientists -- not only as a > scientist, but as the most important one who ever lived. To paraphrase Bertrand Russell, Newton was too successful. Over-veneration of Newton was eventually an impediment to

Re: "Python" is not a good name, should rename to "Athon"

2007-12-03 Thread Neil Cerutti
is obvious troll... I didn't think of it as a troll, but as a humor piece. So I tried to think of a funny response, but failed. Others jumped in to fill the gap, and well... things progressed from there. But your opinion is noted. ;) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: "Python" is not a good name, should rename to "Athon"

2007-12-03 Thread Neil Cerutti
scientific method is that it doesn't explain how to come up with theories. You need luck, genius, or both. The same applies to language naming. There's no theory of good language names (except for a short list of don'ts); you have to attempt it and see what happens. -- Neil Cerutt

Re: read lines

2007-12-04 Thread Neil Cerutti
ith_statement import sys from operator import itemgetter from contextmanager import closing with closing(file(sys.argv[1])) as fp: table = [(int(i), float(n)) for i, n in (line.split() for line in fp)] print table print "maximum =", max(table, key=itemgetter(1)) print "minimum =", min(table, key=itemgetter(1)) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: An Object's Type

2007-12-05 Thread Neil Cerutti
ices (except I suppose the return type also change, er... except for strings--oh never mind). -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: How to split string

2007-12-05 Thread Neil Cerutti
On 2007-12-05, Tim Chase <[EMAIL PROTECTED]> wrote: > http://docs.python.org/lib/module-textwrap.html > > The Python library has already done all the heavy lifting--no > need to re-invent the wheel. Well no, clearly we need xwrap methods and a ctextwrap module. ;) -- Nei

Re: Best way to merge/sort two sorted lists?...

2007-12-06 Thread Neil Cerutti
ix]) aix += 1 while bix < bstop: rval.append(b[bix]) bix += 1 return rval It should beat ResortEverything consistently once the lists become larger than a certain size. Do you get better results at all with the above function? -- Neil Cerutti The audience is asked to remain seated until the end of the recession. --Church Bulletin Blooper -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to merge/sort two sorted lists?...

2007-12-06 Thread Neil Cerutti
hon/Recipe/491285 > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305269 That's fairly awesome. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to merge/sort two sorted lists?...

2007-12-06 Thread Neil Cerutti
On 2007-12-06, Neil Cerutti <[EMAIL PROTECTED]> wrote: > It should beat ResortEverything consistently once the lists > become larger than a certain size. Do you get better results at > all with the above function? With psyco, my merge_sorted becamse faster than relying on timsor

Re: Best way to merge/sort two sorted lists?...

2007-12-06 Thread Neil Cerutti
On 2007-12-06, Aaron Watters <[EMAIL PROTECTED]> wrote: > On Dec 6, 2:14 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> On 2007-12-06, Raymond Hettinger <[EMAIL PROTECTED]> wrote: >> > See recipes: >> >http://aspn.activestate.com/ASPN/Cookbook/Python/

Re: __iadd__ useless in sub-classed int

2007-12-06 Thread Neil Cerutti
te a bunch of methods to > perform in-place modifications. Looks like I stuck, however. You have to implement only the operations you actually use. So to save yourself drudge-work, use fewer operations. ;-) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: File to dict

2007-12-07 Thread Neil Cerutti
ew years ago, I spent two > days writing my own (SquaredWheel(tm) of course) csv > reader/writer... before realizing there was such a thing as the > csv module :-/ > > Should have known better... But probably it has made you a better person. ;) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: New subclass vs option in __init__

2007-12-07 Thread Neil Cerutti
gt; > Good question. The major factor in the tipping point is clarity. And simplicity. The two major factors in deciding the tipping point are: clarity, simplicity, and extensibility. ... The THREE major tipping point factors ARE: clarity, simplicity, extensibility. And efficiency. Among the many fact

<    5   6   7   8   9   10   11   12   >