Re: aligning SGML to text

2006-06-18 Thread Steven Bethard
Steven Bethard wrote: > I have some plain text data and some SGML markup for that text that I > need to align. (The SGML doesn't maintain the original whitespace, so I > have to do some alignment; I can't just calculate the indices directly.) [snip] > Note that the SGML i

Re: Formatted string to object

2006-06-19 Thread Steven Bethard
janama wrote: > can such a thing be done somehow? > > aaa = self.aaa > bbb = %s.%s % ('parent', 'bbb') > > Can you use strings or %s strings like in the above or > > aaa = 'string' > aaa.%s() % 'upper' Use the getattr() function:: >>> class parent(object): ... class bbb(object):

Re: returning index of minimum in a list of lists

2006-06-21 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Is there a simple python function to return the list index of the > minimum entry in a list of lists? > ie, for [[3,3,3,3], [3,3,3,1], [3,3,3,3]] to return 2,4. > Or, same question but just for a list of numbers, not a list of lists. In Python 2.5: Python 2.5a2 (trun

Re: returning index of minimum in a list of lists

2006-06-21 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > [EMAIL PROTECTED] wrote: >> Is there a simple python function to return the list index of the >> minimum entry in a list of lists? >> ie, for [[3,3,3,3], [3,3,3,1], [3,3,3,3]] to return 2,4. >> Or, same question but just for a list of numbers, not a list of lists. > >

Re: The code that could not be...

2006-06-22 Thread Steven Bethard
Alex A. Naanou wrote: > The object's __dict__ can only be a dict derivative and at that none of > the Python's mapping API will be used (the dict is accessed directly). [snip] > I wrote a patch some time back, it appears rather stable and is being > production tested. > > you can download it here:

Re: Registry of Methods via Decorators

2006-06-22 Thread Steven Bethard
bayerj wrote: > I want to make a registry of methods of a class during creation. I think you're going to need a metaclass for this, e.g.:: >>> import inspect >>> def registered(func): ... func.registered = True ... return func ... >>> class RegisterFuncs(type): ... def __init__(cls

Re: String negative indices?

2006-06-23 Thread Steven D'Aprano
ightly less sloppy, infinitesimals are zero, but not all the same zero. When doing calculus with complex numbers, it is very important to distinguish which direction you are taking your limits in, and so lim z -> 0+0i is not necessarily the same as lim z -> 0-0i. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Clearing pythonwin environment

2006-06-23 Thread Steven Bethard
Network Ninja wrote: > I want to restart the environment occasionally to default (like I > restarted pythonwin). I wrote this script. I know why it doesn't work, > cause it deletes my variable (item) on each iteration. My question is: > is it possible to do this? What other things might I try? > >

Re: String negative indices?

2006-06-24 Thread Steven D'Aprano
On Sat, 24 Jun 2006 05:36:17 -0700, Filip Wasilewski wrote: > Steven D'Aprano wrote: >> On Fri, 23 Jun 2006 02:17:39 -0700, Filip Wasilewski wrote: >> >> > [EMAIL PROTECTED] wrote: >> > >> >> Logically, I should be able to enter x[-2:-0] to get th

Re: 2Qs

2006-06-24 Thread Steven D'Aprano
e of the values is negative. In either case the first test will fail. There are no circumstances where each of x, y and z are greater than 10 but the sum is zero; nor are there any circumstances where the sum is zero but x, y and z are still all greater than 10. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: String negative indices?

2006-06-25 Thread Steven D'Aprano
On Sat, 24 Jun 2006 21:15:17 -0700, Erik Max Francis wrote: > Steven D'Aprano wrote: > >> In mathematics, well, maybe... certainly in the Real number system, there >> is no difference, and +0 and -0 are just two ways of writing the same >> thing. In the hyperreals

Re: optparse multiple arguments

2006-06-30 Thread Steven Bethard
Ritesh Raj Sarraf wrote: > Now if someone uses it as: > ./foo --my-option a b c > > I want somehow to store all the three arguments Currently optparse doesn't support options with an arbitrary number of arguments. I'm currently working on a optparse-inspired replacement which does support this

Re: Concatenating strings

2006-06-30 Thread Steven Bethard
John Henry wrote: > I have a list of strings (some 10,000+) and I need to concatenate them > together into one very long string. The obvious method would be, for > example: > > alist=["ab","cd","ef",.,"zzz"] > blist = "" > for x in alist: >blist += x > > But is there a cleaner and faster

doctest, sys.stderr, SystemExit and unused return values

2006-07-01 Thread Steven Bethard
I have an optparse-like module and though I have a full unittest-style suite of tests for it, I'd also like to be able to run doctest on the documentation to make sure my examples all work. However, I see that doctest (1) doesn't capture anything from sys.stderr, and (2) unlike the normal inte

python-dev Summary for 2006-05-16 through 2006-05-31

2006-07-01 Thread Steven Bethard
python-dev Summary for 2006-05-16 through 2006-05-31 .. contents:: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2006-05-16_2006-05-31] = Announcements =

Re: List Manipulation

2006-07-04 Thread Steven D'Aprano
On Tue, 04 Jul 2006 07:01:55 -0700, Roman wrote: > I would appreciate it if somebody could tell me where I went wrong in > the following snipet: > > When I run I get no result What do you mean? Does it print None? > cnt = 0 > p=[] > reader = csv.reader(file("f:\webserver\inp.txt"), dialect="exc

Re: converting file formats to txt

2006-07-04 Thread Steven D'Aprano
-- maybe it will help. If you explain your needs in a little more detail, perhaps people can give you answers which are a little more helpful. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: fonction in python

2006-07-04 Thread Steven D'Aprano
squares curve fitting" and "linear regression". That's just two methods out of many. Some curve-fitting methods also estimate the error between the predicted curve and the data points; you could then try all of the methods and pick the one with the least error. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Can anyone please analyse this program for me (write a pseudocode for it).

2006-07-04 Thread Steven D'Aprano
t this piece of code was made up of 24 lines of actual code (including lines containing only a single brace) but 29 lines of legalise? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: built in zip function speed

2006-07-04 Thread Steven D'Aprano
ule uses. That means zip has to convert every one of those 800,000 floats into rich Python float objects. This won't matter for small sets of data, but with 800,000 of them, it all adds up. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

RE: ascii character - removing chars from string

2006-07-04 Thread Steven D'Aprano
tring.replace can't/doesn't > handle non-ascii chars. i'm still looking for a way to search/replace > non-ascii chars... Seems to work for me: >>> c = u'\xa0' >>> s = "hello " + c + " world" >>> s u'hello \xa0 world' >>> s.replace(c, "?") u'hello ? world' -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Code design for a sub-class of built-ins

2006-07-04 Thread Steven D'Aprano
built-in types without needing to write the same bit of code for each and every method? Am I approaching this the wrong way? Is there a better design I could be using? Thanks, -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

RE: ascii character - removing chars from string

2006-07-04 Thread Steven D'Aprano
g from unicode to ordinary strings is NOT the same -- the *character* chr(160) is not a valid ASCII character, since ASCII only uses the range chr(0) through chr(127). If this is confusing to you, you're not alone. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

RE: defining multi dimensional array

2006-07-04 Thread Steven D'Aprano
thing is that each of the inner lists are DIFFERENT lists that just happen to share the same value (ten None items), rather than the same list repeated ten times. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Code design for a sub-class of built-ins

2006-07-04 Thread Steven D'Aprano
On Tue, 04 Jul 2006 19:26:36 +0200, Bruno Desthuilliers wrote: > Steven D'Aprano wrote: >> I'm having problems with sub-classes of built-in types. >> >> Here is a contrived example of my subclass. It isn't supposed >> to be practical, useful code, b

Re: Code design for a sub-class of built-ins

2006-07-04 Thread Steven D'Aprano
I meant -- it was a copy-and-paste and I didn't clean it up correctly. Thanks, -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Detupleize a tuple for argument list

2006-07-05 Thread Steven D'Aprano
On Wed, 05 Jul 2006 14:01:27 +0200, Marco Wahl wrote: > Hi, > > I want to give a tuple to a function where the function > expects the respective tuple-size number of arguments. > > The following session illustrates what I want to do and > the respective failure. > > Python 2.4.1 (#7, Aug 3 20

Re: Code design for a sub-class of built-ins

2006-07-05 Thread Steven D'Aprano
gt; would be something like: That's great, thanks. You've given me an angle of attack to take and see where it leads. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Code design for a sub-class of built-ins

2006-07-05 Thread Steven D'Aprano
On Wed, 05 Jul 2006 11:41:47 +0200, Bruno Desthuilliers wrote: > Steven D'Aprano wrote: >> On Tue, 04 Jul 2006 19:26:36 +0200, Bruno Desthuilliers wrote: >> >> >>>Steven D'Aprano wrote: >>> >>>>I'm having problems with sub-cla

Re: setting variables from a tuple NEWB

2006-07-07 Thread Steven D'Aprano
'aeiou' > CONS = ''bcdfgh' Why don't you just do that? VOWELS = 'aeiou' CONS = 'bcdfgh' What benefit do you gain by stuffing your variables into tuples? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: searching for strings (in a tuple) in a string

2006-07-07 Thread Steven D'Aprano
found." else: print "No items found." However, keep in mind that "in" has a subtly different effect in strings and tuples. "x" in ("x", "y") is true, but "x" in ("xy", "yy") is not, as you would expect. However, the situation for strings isn't quite the same: "x" in "x y" is true, but so is "x" in "xx yy". One way around that is to convert your string a into a list: a = 'xfsdfyysd asd x' a = a.split() # split on any whitespace and now your tests will behave as you expected. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: eval to dict problems NEWB going crazy !

2006-07-07 Thread Steven D'Aprano
",") key1, value1 = a.strip().split(":") key2, value2 = b.strip().split(":") return {key1.strip(): value1.strip(), key2.strip(): value2.strip()} def parse_list(s): """Parse a list with two items exactly.""" s = s.strip() assert s.startswith("[") assert s.endswith("]") a, b = s[1:-1].split(",") return [a.strip(), b.strip()] # Expected format is something like: # [tuple(string, integer), tuple(string, dict(string: string)] L = parse_list(s) T0 = parse_tuple(L[0]) T1 = parse_tuple(L[1]) T0 = (T0[0], int(T0[1])) T1 = (T1[0], parse_dict(T1[1])) return [T0, T1] That's a bit more work than eval, but I believe it is worth it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: split a line, respecting double quotes

2006-07-07 Thread Steven Bethard
Jim wrote: > Is there some easy way to split a line, keeping together double-quoted > strings? > > I'm thinking of > 'a b c "d e"' --> ['a','b','c','d e'] > . I'd also like > 'a b c "d \" e"' --> ['a','b','c','d " e'] > which omits any s.split('"')-based construct that I could come up with.

Re: Attaching functions to objects as methods

2006-07-07 Thread Steven Bethard
tac-tics wrote: > Python is a crazy language when it comes to object versatility. I know > I can do: > class test: > ...def __init__(self): > ... pass x = test() def fun(): > ... print "fun" x.fun = fun x.fun() > fun > > However, experimenting shows that t

Re: eval to dict problems NEWB going crazy !

2006-07-07 Thread Steven D'Aprano
On Fri, 07 Jul 2006 19:57:02 +0200, Fredrik Lundh wrote: > Steven D'Aprano wrote: > >> Personally, I would never use eval on any string I didn't write myself. If >> I was thinking about evaluating a user-string, I would always write a >> function to parse the s

Re: eval to dict problems NEWB going crazy !

2006-07-07 Thread Steven D'Aprano
ions -- my rule of thumb (yours may be different) is that any time I expect arbitrary data, eval is the right tool for the job, but if I expect *specific* data, I use something else. Imagine if the only way to get an integer was by calling eval on the string -- I think we'd all agree that would be a bad move. Instead we have a function which does nothing but convert strings (well, any object really) to integers: int. It would be great if Python included tools to do the same for dicts and lists, reducing the need for people to use a sledge-hammer. Anyway, my point was that you, the developer, have to weigh up the costs and benefits of eval over a custom parser. The benefit is that eval is already there, built-in and debugged. The costs are that it can be insecure, and that it doesn't give you fine control over what data you parse or how forgiving the parser is. After that, the decision is yours. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Attaching functions to objects as methods

2006-07-07 Thread Steven Bethard
John Machin wrote: > Injecting a "private" method into a particular instance is not much more > complicated: > > >>> def own(self, arg): > ...print "own" > ...self.ozz = arg > ... > >>> p = K() > >>> import types > >>> p.metho = types.MethodType(own, p) > >>> p.metho("plugh") > own >

python-dev Summary for 2006-06-01 through 2006-06-15

2006-07-08 Thread Steven Bethard
python-dev Summary for 2006-06-01 through 2006-06-15 .. contents:: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2006-06-01_2006-06-15] = Announcements = --- Pyth

Re: Inheritance error: class Foo has no attribute "bar"

2006-07-09 Thread Steven D'Aprano
: self.attribs = self.default_attribs.copy() Now there is one copy of default character attributes, shared by the class and all it's instances, plus each instance has it's own unique set of values which can be modified without affecting the defaults. Hope this clears things up for you. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: can't pickle instancemethod objects

2006-07-09 Thread Steven D'Aprano
t you post the complete stack trace of the exception? Chances are it will contain much useful information. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: can't pickle instancemethod objects

2006-07-09 Thread Steven D'Aprano
cts" when I try to pickle a method. Possibly that's just a change in error message, which is not guaranteed to be constant across Python versions. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: can't pickle instancemethod objects

2006-07-09 Thread Steven D'Aprano
): self.L = [1, "a", X.method] # note the lack of ()s pop = X() Otherwise, I'm working blind without knowing more about your class. Here's a thought: comment out every attribute in your class, and then try pickling it. If it succeeds, uncomment just *one* attrib

Re: language design question

2006-07-09 Thread Steven Bethard
Gregory Guthrie wrote: > For example, >- why is len() not a member function of strings? Instead one says len(w). Why would ``x.len()`` be any more convenient than ``len(x)``? Your preference here seems pretty arbitrary. > - Why doesn't sort() return a value? > > This would allow thing

Re: language design question

2006-07-09 Thread Steven D'Aprano
ing else? Be prepared to justify why your choice is suitable not just for *this* dictionary, but for *all* dictionaries. > I am curious why these "obvious" conveniences are not present. :-) > Thansk for any context or insight. Perhaps the best way to understand the Python philosophy is to call up an interpreter and execute "import this" at the prompt. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: language design question

2006-07-09 Thread Steven D'Aprano
a recent (version 2.2 I think?) addition to Python. You have to think about the functionality available back in the days when the decision to make len() a function was made, not based on what functionality is available a decade later. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: language design question

2006-07-09 Thread Steven Bethard
guthrie wrote: > Steven Bethard wrote: >> Why would ``x.len()`` be any more convenient than ``len(x)``? Your >> preference here seems pretty arbitrary. > -- Perhaps; > but having all standard operations as a method seems more regular (to > me), and allows a simple chain

Re: language design question

2006-07-09 Thread Steven Bethard
Terry Reedy wrote: > "Gregory Guthrie" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> - why is len() not a member function of strings? Instead one says >> len(w). > > Consider map(len, ('abc', (1,2,3), [1,2], {1:2})) > [3, 3, 2, 1] > > Now try to rewrite this using meth

Re: function that modifies a string

2006-07-10 Thread Steven D'Aprano
ay to solve the problem. Of course, another right way would be to have mutable strings in Python. I understand why strings need to be immutable in order to work with dicts, but is there any reason why (hypothetical) mutable strings should be avoided in situations where they aren't needed as dictionary keys? Python has mutable lists and immutable tuples, mutable sets and immutable frozen sets, but no mutable string type. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: function that modifies a string

2006-07-10 Thread Steven D'Aprano
On Mon, 10 Jul 2006 15:23:36 +0100, Sion Arrowsmith wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: >>Of course, another right way would be to have mutable strings in Python. > > What significant advantage would mutable strings have over StringIO > and wrappin

Re: function that modifies a string

2006-07-10 Thread Steven D'Aprano
er, I should point out that the methods available to array.array('c') are quite limited compared to the methods available to strings. Still, it would make a good basis to start with, and far better than my initial thought of a list of chars. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: language design question

2006-07-10 Thread Steven Bethard
Bryan wrote: > Steven Bethard wrote: > >> The advantage of a functional form over a method shows up when you >> write a function that works on a variety of different types. Below are >> implementations of "list()", "sorted()" and "join()&q

Re: language design question

2006-07-10 Thread Steven Bethard
Paul Rubin wrote: > Steven Bethard <[EMAIL PROTECTED]> writes: >> If len() were a method of string objects, you could try using the >> unbound method and writing this as:: >> >> >>> sorted(['aaa', 'bb', 'c'], key=str

Re: function that modifies a string

2006-07-10 Thread Steven D'Aprano
the worst that can happen is that people will write inefficient code, and they'll be caught out by the same sort of things that surprise newbies about lists. E.g. using a list as a default value in function definitions. > Use them only when their benefits outweigh their risks. That goes with

Re: Relying on the behaviour of empty container in conditional statements

2006-07-11 Thread Steven D'Aprano
quot; or similar. But they are comparatively rare. Why force simple true/false tests into that idiom? > My own feeling is that I am willing to work with the behaviours defined > by Python, and treat the use of len in these cases as excessive > duplication (this is however, quite a minor

Re: Restricted Access

2006-07-11 Thread Steven D'Aprano
*hard*. As far as I know, even Microsoft has never attempted it. And for all of Sun's resources and talent, security holes are sometimes found even in Java. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: how do you get the name of a dictionary?

2006-08-24 Thread Steven D'Aprano
On Wed, 23 Aug 2006 11:16:17 +0200, Sybren Stuvel wrote: > Steven D'Aprano enlightened us with: >> But an upside is that it would enable more useful error messages, at least >> sometimes. Here's some trivial pseudo-code: >> >> def foo(a): >> assert

Re: how do you get the name of a dictionary?

2006-08-24 Thread Steven D'Aprano
On Wed, 23 Aug 2006 12:16:45 +0200, Fredrik Lundh wrote: > Steven D'Aprano wrote: > >> Here's a traceback. One of the arguments to spam() is too small. Can you >> tell which one just by looking at the traceback? >> >>>>> a, b, c, d = range(4) >

Re: sum and strings

2006-08-24 Thread Steven D'Aprano
one of the nice things about the language: it *suggests* what to do, but doesn't *insist* it knows what you want better than you do. -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list

Re: a new object definition

2006-09-01 Thread Steven Bethard
Sylvain Ferriol wrote: > hello everybody, > > i want to talk with you about a question i have in mind and i do not > find a answer. it 's simple: > why do we not have a beatiful syntax for object definition as we have > for class definition ? > > we can define a class in python in 2 ways: > 1. b

Re: a new object definition

2006-09-06 Thread Steven Bethard
Sylvain Ferriol wrote: > with the 'make' syntax, it will be really easy to translate a program or > a data structure defined in XML format into python syntax. Only if there are no ordering constraints and no need for multiple elements with the same name. The make statement was built to mirror t

Re: change property after inheritance

2006-09-07 Thread Steven Bethard
David Isaac wrote: > Le mercredi 06 septembre 2006 16:33, Alan Isaac a écrit : >>> Suppose a class has properties and I want to change the >>> setter in a derived class. If the base class is mine, I can do this: >>> http://www.kylev.com/2004/10/13/fun-with-python-properties/ >>> Should I? (I.e., i

Re: change property after inheritance

2006-09-07 Thread Steven Bethard
George Sakkis wrote: > Steven Bethard wrote: > >> David Isaac wrote: >>> Le mercredi 06 septembre 2006 16:33, Alan Isaac a écrit : >>>>> Suppose a class has properties and I want to change the >>>>> setter in a derived class. If the base class

Re: change property after inheritance

2006-09-08 Thread Steven Bethard
Maric Michaud wrote: > Le jeudi 07 septembre 2006 15:33, Steven Bethard a écrit : >> Well, lambda's not going away[1], > > Sure, they won't. > >> but there's no *need* for lambda here. >> It could be written as:: > > Le jeudi 07 septem

Re: Request for tips on my first python script.

2006-09-09 Thread Steven Bethard
Lex Hider wrote: > try: > opts, args = getopt.getopt(sys.argv[1:], "l:", > ["latest=", "notfound"]) > except getopt.GetoptError: > sys.exit(2) > #usage() > > for opt, arg in opts: > if opt in (

Re: Refactoring Dilemma

2006-09-11 Thread Steven Bethard
Kamilche wrote: > Is there any reason NOT to do this that I may be unaware of? [snip] > # --- Module 2.py > # 'Self' module processing > import sys > var = 0 > self = sys.modules[__name__] > > def MyRoutine(): > self.var = 1 > > MyRoutine() > print var Looks basically fi

Re: best way of testing a program exists before using it?

2006-09-11 Thread Steven Bethard
Hari Sekhon wrote: > I am writing a wrapper to a binary command to run it and then do > something with the xml output from it. > > What is the best way of making sure that the command is installed on the > system before I try to execute it, like the python equivalent of the > unix command "whic

pickle and instancemethod objects

2006-09-13 Thread Steven Bethard
I'd like to be able to pickle instancemethod objects mainly because I want to be able to delay a call like ``foo(spam, badger)`` by dumping ``foo``, ``spam`` and ``badger`` to disk and loading them again later. Sometimes the callable ``foo`` is actually a bound method, e.g. ``bar.baz``, but in

Re: pickle and instancemethod objects

2006-09-13 Thread Steven Bethard
Martin v. Löwis wrote: > Steven Bethard schrieb: >> Does this approach seem sound? Am I going to run into some weird >> problems doing it this way? > > It's good, but I think rebuilding the object through > new.instancemethod should be even better. > > py>

Re: Dice gen and analyser script for RPGs: comments sought

2006-09-13 Thread Steven Bethard
George Sakkis wrote: > * [personal preference]: Don't leave space between *every* operator in > expressions, group them based on precedence. E.g. instead of "(n * > sigmaSq - sigma * sigma) / (n * n)", I read it easier as "(n*sigmaSq - > sigma*sigma) / (n*n). The spaced-out version is more `PEP 8`

Re: Are Python's reserved words reserved in places they dont need tobe?

2006-09-14 Thread Steven D'Aprano
omplain that they want to have identifiers in bold too, why can't they create a name "\x0breturn", and somebody will come up with an even more complicated scheme for accommodating them... wash, rinse, repeat. -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list

Re: Statistical distribution of object size

2006-09-14 Thread Steven D'Aprano
ou get the memory size of each object? -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list

Re: Pre-defining an action to take when an expected error occurs

2006-09-14 Thread Steven D'Aprano
(u)) p = str(soup.findAll('span', "sale")) for row in re.findall('\$\d+\.\d\d', p): ws.write(r,0,row) # what's r? did you mean rx? Now call this: for rx in range(sh.nrows): rx += 1 # but see my comments above... try:

Re: high level, fast XML package for Python?

2006-09-15 Thread Steven Bethard
Diez B. Roggisch wrote: > Gleb Rybkin wrote: > >> I searched online, but couldn't really find a standard package for >> working with Python and XML -- everybody seems to suggest different >> ones. >> >> Is there a standard xml package for Python? Preferably high-level, fast >> and that can parse i

Re: high level, fast XML package for Python?

2006-09-17 Thread Steven Bethard
Martin v. Löwis wrote: > Gleb Rybkin schrieb: >> I searched online, but couldn't really find a standard package for >> working with Python and XML -- everybody seems to suggest different >> ones. >> >> Is there a standard xml package for Python? Preferably high-level, fast >> and that can parse in-

Re: why a main() function?

2006-09-19 Thread Steven Bethard
Steve Holden wrote: > [EMAIL PROTECTED] wrote: >> I think I read a suggestion somewhere to wrap the code where a Python >> script starts in a main() function, so one has >> >> def main(): >> print "hi" >> >> main() >> >> instead of >> >> print "hi" >> >> What are the advantages of doing this? >

Re: License / Registration key enabled software

2006-09-23 Thread Steven D'Aprano
r you if your users just stop using the software and use a competing product instead. If the answer is Yes, then go on to question 2: Q2. Are you sure? If the answer is still Yes, then read this and see if it helps: http://en.wikipedia.org/wiki/Keygen -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: grabbing random words

2006-09-23 Thread Steven D'Aprano
th, sort of as if we could say in English "therearelanguageswhichallowyou" to "sticktogetherwordsintoasinglewordofindefinitelength". Such languages might be said to have an infinite number of words, in some sense.) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Difficulty with maxsplit default value for str.split

2006-09-23 Thread Steven D'Aprano
lt Is it safe for me to pass -1 as the default to maxsplit, meaning "unlimited splits"? Should the docs be fixed to mention that? Thanks, -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: unicode, bytes redux

2006-09-25 Thread Steven D'Aprano
optimization. Your computer has probably got well in excess of 100MB, and you're worried about duplicating a few hundred or thousand (or even hundred thousand) bytes for a few milliseconds (just long enough to grab the length)? -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list

Re: Verify an e-mail-adress - syntax and dns

2006-09-25 Thread Steven D'Aprano
like a password and ask the user to type it twice. That will protect against simple typos and input errors. For everything else, send to it and see what happens. -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list

Re: Difficulty with maxsplit default value for str.split

2006-09-25 Thread Steven D'Aprano
lit(*args) > post_processing() > return result Thanks Fredrik, that's *exactly* the sort of insight I was lacking. And now that you've shown me, I can't believe how obvious it is. -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list

Re: Leave the putdowns in the Perl community, the Python world does not need them

2006-09-25 Thread Steven Bethard
metaperl wrote: > I was shocked to see the personal insults hurled in this thread: > http://groups.google.com/group/comp.lang.python/browse_thread/thread/d0758cb9545cad4b I see that this is a Fredrik Lundh thread. I've felt the same way before, but Fredrik has been around a long time[1] and if y

Re: A critique of cgi.escape

2006-09-25 Thread Steven D'Aprano
pect the (presumed) bad behaviour can be fixed gradually? Now that we've got that out of the way, can we CALMLY and RATIONALLY discuss whether cgi.escape is or isn't broken? Or, more specifically, UNDER WHAT CIRCUMSTANCES it does the wrong thing? -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list

Re: Verify an e-mail-adress - syntax and dns

2006-09-25 Thread Steven D'Aprano
On Mon, 25 Sep 2006 16:11:38 +0200, Christophe wrote: > Steven D'Aprano a écrit : >> By memory, in an thread about the same topic just a few days ago, Fredrik >> Lundh posted a link to Perl's FAQs that suggests a method for "validating" >> email addres

Re: License / Registration key enabled software

2006-09-25 Thread Steven D'Aprano
ily one of those, but that's not up to me to decide.) -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list

Re: Makin search on the other site and getting data and writing in xml

2006-09-25 Thread Steven D'Aprano
e is worthless), they can. But the point is, I see no ethical nor legal reason why a user can't create a script which is called MANUALLY by the user and does what a browser does, namely send and receive data from websites (which may or may not include Google). And that, it seems to me, is what the Original Poster wanted. -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list

Re: does anybody earn a living programming in python?

2006-09-27 Thread Steven D'Aprano
and there's countless other people I know here in Melbourne in > the same position. Countless people? Are we talking aleph-zero people (countable infinity) or one of the uncountable infinities? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: does anybody earn a living programming in python?

2006-09-27 Thread Steven D'Aprano
On Wed, 27 Sep 2006 09:17:28 -0400, Roy Smith wrote: > In article > <[EMAIL PROTECTED]>, > Steven D'Aprano <[EMAIL PROTECTED]> wrote: > >> On Tue, 26 Sep 2006 22:00:55 +1000, Anthony Baxter wrote: >> >> > This seems to be a very, very silly

Re: Top and Bottom Values [PEP: 326]

2006-09-27 Thread Steven D'Aprano
def __str__(self): return self.name def __gt__(self, other): return len(str(self)) > len(str(other)) and then you'll have problems: >>> bottom = Funny("Bottom") >>> Top > bottom True >>> bottom > Top True As far as I can see, the only way to avoid edge cases like this is for Top (and Bottom) to be built-ins that are special-cased by Python. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Difference between two dates in seconds

2006-09-27 Thread Steven D'Aprano
at depends on just how often you need to convert days to or from seconds. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: optparse

2006-09-27 Thread Steven Bethard
rick wrote: > Consider the following piece of code: > > parser = optparse.OptionParser(usage="usage: %prog > [options]", add_help_option=False) > parser.add_option("-d", type="string", action="store", dest="DELIM", > default="|", help="single character delimiter in quotes (default: |)") > (opt

Re: loop beats generator expr creating large dict!?

2006-10-03 Thread Steven Bethard
David Isaac wrote: > Does George's example raise the question: > why do dictionaries not implement efficient creation > for two common cases? > > - Making a dict from two sequences of the same length. > - Making a dict from a sequence and a function > (as in George's example in this thread). Ma

Re: Can't get around "IndexError: list index out of range"

2006-10-03 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > I'm trying to get this bit of code to work without triggering the > IndexError. > > import shutil, os, sys > > if sys.argv[1] != None: > ver = sys.argv[1] > else: > ver = '2.14' Something like:: if len(sys.argv) > 1: ver = sys.argv[1] else:

Re: remove a list from a list

2006-11-17 Thread Steven D'Aprano
ou have to make a copy of the list on every iteration because you are changing it in place; otherwise you change the values you are testing against, and the second iteration onwards doesn't have to remove anything. (All code above untested. Use at own risk.) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: decompiler

2006-11-18 Thread Steven D'Aprano
On Fri, 17 Nov 2006 20:08:25 -0800, jim wrote: > Is there such thing as a free decompile that I can run in windows xp Yes. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: decompiler

2006-11-18 Thread Steven D'Aprano
On Sat, 18 Nov 2006 07:42:58 -0800, jim wrote: > where can I find a free decompile that I can run in windows xp Here: http://catb.org/esr/faqs/smart-questions.html -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: tempfile.NamedTemporaryFile wont work

2006-11-19 Thread Steven D'Aprano
it, but strings returns different error messages. Is it possible this is a bug in strings? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: tempfile.NamedTemporaryFile wont work

2006-11-19 Thread Steven D'Aprano
On Sun, 19 Nov 2006 13:18:39 +0100, Bjoern Schliessmann wrote: > Imbaud Pierre wrote: > >> tf = tempfile.NamedTemporaryFile() >> tfName = tf.name >> [...] >> print >> sys.stderr, '%s: %s' % (tfName, ['no', >> 'yes'][os.path.exists(tfName)]) >> s

Re: a few extensions for the itertools

2006-11-19 Thread Steven D'Aprano
ice would be so much cleaner if it took keyword arguments.) > heads(iterable) -> iterator over all heads > tails(iterable) -> iterator over all tails What would you use these for? > fcain(funct,*functs) -> function(...,***) > fcain(f1,f2,...,fn)(*args,*kwargs) equals f1(f2(...fn(*args,*kwargs))) The usual term for this is function composition. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Note about getattr and '.'

2006-11-21 Thread Steven D'Aprano
here will be such a dictionary in any > future CPython version. > (Would be good.) Why would it be good? How many bugs have you found that were caused by this behaviour? -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list

<    93   94   95   96   97   98   99   100   101   102   >