Re: About Databases...

2005-03-16 Thread Leif B. Kristensen
#x27;d recommend a closer study of PostgreSQL for anyone interested in a good RDBMS. I have been using MySQL for several years, but have recently come to appreciate all the advanced features of PostgreSQL that still is kind of "vaporware" in MySQL. -- Leif Biberg Kristensen just another glo

Re: fastest postgresql module

2005-03-17 Thread Leif B. Kristensen
it link, the server is on a 10/10mbit, and > i have a ping of 245ms average. > maybe pypgsql does too much backand forth, i don't know. You might want to try psycopg, it's claimed to be optimized for speed. -- Leif Biberg Kristensen just another global village idiot -- http://mail.python.org/mailman/listinfo/python-list

Re: fastest postgresql module

2005-03-17 Thread Leif B. Kristensen
Timothy Smith skrev: > my only issue with psycopg, is last time i looked they had no win32 > port? Uh, in that case, maybe you should consider changing platform? 8^) -- Leif Biberg Kristensen just another global village idiot -- http://mail.python.org/mailman/listinfo/python-list

Re: html escape sequences

2005-03-18 Thread Leif K-Brooks
Will McGugan wrote: I'd like to replace html escape sequences, like   and ' with single characters. Is there a dictionary defined somewhere I can use to replace these sequences? How about this? import re from htmlentitydefs import name2codepoint _entity_re = re.compile(r'&(?:(#)(\d+)|([^;]+));')

Re: How to create stuffit files on Linux?

2005-03-19 Thread Leif K-Brooks
Noah wrote: The problem is that my users want to see .sit files. I know it's sort of silly. Zip files are foreign and frightening to them. Would Stuffit open zip files renamed to .sit? -- http://mail.python.org/mailman/listinfo/python-list

Re: Variable Variable

2005-03-19 Thread Leif K-Brooks
Tanteauguri wrote: Hi List, is there in python a variable variable like in PHP ($$var)? What I want to do is something like that: pc=["a","b","c"] for i in pc: i = anyclass() a.shutdown() b.update() Use a dictionary: stuff = {} pc = ['a', 'b', 'c'] for i in pc: stuff[i] = anyclass() stuff['

Re: Syntax for extracting multiple items from a dictionary

2004-11-30 Thread Leif K-Brooks
shark wrote: row = {"fname" : "Frank", "lname" : "Jones", "city" : "Hoboken", "state" : "Alaska"} cols = ("city", "state") Is there a best-practices way to ask for an object containing only the keys named in cols out of row? In other words, to get this: {"city" : "Hoboken", "state" : "Alaska"} Why

Re: Protecting Python source

2004-11-30 Thread Leif K-Brooks
Grant Edwards wrote: On 2004-11-29, Peter Maas <[EMAIL PROTECTED]> wrote: If the "reverse engineering" argument boils down to "protecting source doesn't make sense" then why does Microsoft try so hard to protect its sources? To avoid embarassment. +1 QOTW (Everyone else was doing it, I just wanted

Re: Overriding properties

2004-12-11 Thread Leif K-Brooks
Nick Patavalis wrote: Why does the following print "0 0" instead of "0 1"? What is the canonical way to rewrite it in order to get what I obviously expect? class C(object): value = property(get_value, set_value) class CC(C): def set_value(self, val): c.value = -1 cc.value =

Re: Recursive structures

2004-12-20 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: While using some nested data structures, I've seen that I'd like to have a function that tells me if a given data structure contains one or more cyclic references (a way to recognise a cycle in a graph is to do a depth-first search, marking vertices along the way. An alread

Oddity in 2.4 with eval('None')

2004-12-20 Thread Leif K-Brooks
In Python 2.4, although None can't be directly assigned to, globals()['None'] can still be; however, that won't change the value of the expression "None" in ordinary statements. Except with the eval function, it seems: Python 2.4 (#2, Dec 3 2004, 17:59:05) [GCC 3.3.5 (Debian 1:3.3.5-2)] on lin

Re: Oddity in 2.4 with eval('None')

2004-12-20 Thread Leif K-Brooks
Steve Holden wrote: Yes. "print eval('None')" is printing the value of None as defined in your module's global namespace: Right, but why? The expression "None" doesn't worry about the global namespace when used in normal code; why does it when used in eval()ed code? -- http://mail.python.org/mail

Re: BASIC vs Python

2004-12-20 Thread Leif K-Brooks
Mike Meyer wrote: They do have a first-class function-like object called an agent. But to use a standard method as an agent, you have to wrap it. Just curious, but how does a method get wrapped in an agent if methods aren't first-class objects? Subclassing the agent base class with a new run meth

Re: String backslash characters

2004-12-24 Thread Leif K-Brooks
PD wrote: Hello, I am new to python, but i am quite curious about the following. suppose you had print '\378' which should not work because \377 is the max. then it displays two characters (an 8 and a heart in my case...). What else does'nt quite make sense is that if this is an octal why is an 8 a

Re: Convert all images to JPEG

2004-12-28 Thread Leif K-Brooks
Thomas wrote: im = Image.open(srcImage) # might be png, gif etc, for instance test1.png im.thumbnail(size, Image.ANTIALIAS) # size is 640x480 im.save(targetName, "JPEG") # targetname is test1.jpg produces an exception. Any clues? The problem is that test1.png is a paletted image, and JPEGs can only

Re: Why tuples use parentheses ()'s instead of something else like <>'s?

2004-12-28 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: Wouldn't it have been better to define tuples with <>'s or {}'s or something else to avoid this confusion?? The way I see it, tuples are just a way of having a function return multiple values at once. When you think of them that way, you don't even need parenthesis: def

Re: Wikipedia - conversion of in SQL database stored data to HTML

2005-03-21 Thread Leif K-Brooks
Claudio Grondi wrote: Is there an already available script/tool able to extract records and generate proper HTML code out of the data stored in the Wikipedia SQL data base? They're not in Python, but there are a couple of tools available here: . By the way: has someone suc

escape single and double quotes

2005-03-24 Thread Leif B. Kristensen
e.escape() method, but it escapes far too much, including spaces and accented characters. I only want to escape single and double quotes, everything else should be acceptable to the database. -- Leif Biberg Kristensen http://solumslekt.org/ -- http://mail.python.org/mailman/listinfo/python-list

Re: escape single and double quotes

2005-03-24 Thread Leif B. Kristensen
pdate names set suffix='%s' where name_id=%s" % \ (escape(row[4]), row[1])) elif row[2] == 5: # name part = 'patronym' query = ("update names set patronym='%s' where name_id=%s" % \ (escape

Re: escape single and double quotes

2005-03-24 Thread Leif B. Kristensen
row in result: query = "update names set %s=%%s where name_id=%%s" % \ name_part[row[1]-1] sql.execute(query, (row[2], row[0])) sql.commit() connection.close() -- Leif Biberg Kristensen http://solumslekt.org/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Python for a 10-14 years old?

2005-03-24 Thread Leif B. Kristensen
gramming. If you've got any idea what I should push to her to get her fascinated about _real_ programming, I'd be obliged. Or maybe her head isn't screwed together that way, what do I know. -- Leif Biberg Kristensen http://solumslekt.org/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Python docs [was: function with a state]

2005-03-24 Thread Leif K-Brooks
Xah Lee wrote: The word âobjectâ has generic English meaning as well might have very technical meaning in a language. In Python, it does not have very pronounced technical meaning. For example, there's a chapter in Python Library Ref titled â2. Built-In Objectsâ, and under it a section â2.1 Built-i

Re: Specifying __slots__ in a dynamically generated type

2005-03-27 Thread Leif K-Brooks
Ron Garret wrote: I need to dynamically generate new types at run time. I can do this in two ways. I can use the "type" constructor, or I can generate a "class" statement as a string and feed that to the exec function. The former technique is much cleaner all else being equal, but I want to b

Problem with national characters

2005-03-31 Thread Leif B. Kristensen
he interactive shell reveals this: [EMAIL PROTECTED] leif $ python Python 2.3.4 (#1, Feb 7 2005, 21:31:38) [GCC 3.3.5 (Gentoo Linux 3.3.5-r1, ssp-3.3.2-3, pie-8.7.7.1)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >&g

Re: Problem with national characters

2005-03-31 Thread Leif B. Kristensen
[EMAIL PROTECTED] wrote: > put > > import sys > sys.setdefaultencoding('UTF-8') > > into sitecustomize.py in the top level of your PYTHONPATH . Uh ... it doesn't seem like I've got PYTHONPATH defined on my system in the first place: [EMAIL PROTECTED] leif

Re: Problem with national characters

2005-03-31 Thread Leif B. Kristensen
ory, and followed your instructions. The first time I got an error message due to a typo. I corrected it, and now Python starts without an error message. But it didn't solve my problem with the uppercase Ø at all. Is there something else I have to do? -- Leif Biberg Kristensen http://solumslekt.org/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with national characters

2005-03-31 Thread Leif B. Kristensen
Leif B. Kristensen skrev: >Is there something else I have to do? Please forgive me for talking with myself here :-) I should have looked up Unicode in "Learning Python" before I asked. This seems to work: >>> u'før'.upper() u'F\xd8R' >>> u

Re: __init__ method and raising exceptions

2005-03-31 Thread Leif K-Brooks
NavyJay wrote: I have a simple for-loop, which instantiates a class object each iteration. As part of my class constructor, __init__(), I check for valid input settings. If there is a problem with this iteration, I want to abort the loop, but equivalently 'continue' on in the for-loop. I can't us

Re: Simple thread-safe counter?

2005-04-02 Thread Leif K-Brooks
Artie Gold wrote: Skip Montanaro wrote: counter = Queue.Queue() def f(): i = counter.get() I think you need: i = counter.get(True) The default value for the "block" argument to Queue.get is True. -- http://mail.python.org/mailman/listinfo/python-list

Re: Use string in URLs

2005-04-07 Thread Leif K-Brooks
Markus Franz wrote: I want to use the string "rüffer" in a get-request, so I tried to encode it. My problem: But with urllib.quote I always get "r%FCffer", but I want to get "r%C3%BCffer" (with is correct in my opinion). urllib.quote(u'rüffer'.encode('utf8')) -- http://mail.python.org/mailman/li

Re: How to name Exceptions that aren't Errors

2005-04-08 Thread Leif K-Brooks
Steve Holden wrote: I've even used an exception called Continue to overcome an irksome restriction in the language (you used not to be able to continue a loop from an except clause). Out of curiosity, how could you use an exception to do that? I would think you would need to catch it and then use

Re: unknown encoding problem

2005-04-08 Thread Leif K-Brooks
Uwe Mayer wrote: Hi, I need to read in a text file which seems to be stored in some unknown encoding. Opening and reading the files content returns: f.read() '\x00 \x00 \x00<\x00l\x00o\x00g\x00E\x00n\x00t\x00r\x00y\x00... Each character has a \x00 prepended to it. I suspect its some kind of unicod

Re: text processing problem

2005-04-08 Thread Leif K-Brooks
Maurice LING wrote: I'm looking for a way to do this: I need to scan a text (paragraph or so) and look for occurrences of " ()". That is, if the text just before the open bracket is the same as the text in the brackets, then I have to delete the brackets, with the text in it. How's this? import

Re: Problem with national characters

2005-04-09 Thread Leif B. Kristensen
ntoo Linux for two years without ever setting the locale, - but now I've finally gotten around to write my own /etc/env.d/02locale file :-) > Notice that things are more difficult in the Windows terminal window, > as this uses an encoding different from the one that the system&#x

Why does StringIO discard its initial value?

2005-04-10 Thread Leif K-Brooks
When StringIO gets an initial value passed to its constructor, it seems to discard it after the first call to .write(). For instance: >>> from StringIO import StringIO >>> buffer = StringIO('foo') >>> buffer.getvalue() 'foo' >>> buffer.write('bar') >>> buffer.getvalue() 'bar' >>> buffer.write('ba

Re: pre-PEP: Simple Thunks

2005-04-15 Thread Leif K-Brooks
Brian Sabbey wrote: Thunk statements contain a new keyword, 'do', as in the example below. The body of the thunk is the suite in the 'do' statement; it gets passed to the function appearing next to 'do'. The thunk gets inserted as the first argument to the function, reminiscent of the way 'self'

Re: pre-PEP: Suite-Based Keywords

2005-04-15 Thread Leif K-Brooks
Brian Sabbey wrote: class C(object): x = property(): doc = "I'm the 'x' property." def fget(self): return self.__x def fset(self, value): self.__x = value def fdel(self): del self.__x After seeing this example, I think I'll go on a killing spree

Re: sscanf needed

2005-04-17 Thread Leif B. Kristensen
Uwe Mayer skrev: > Hi, > > I've got a ISO 8601 formatted date-time string which I need to read > into a datetime object. Look up time.strptime, it does exactly what you want. -- Leif Biberg Kristensen http://solumslekt.org/ -- http://mail.python.org/mailman/listinfo/python-list

Re: How to run Python in Windows w/o popping a DOS box?

2005-04-19 Thread Leif B. Kristensen
Paul Rubin skrev: > Question: is there any simple way to arrange to launch the app from > the desktop, without also launching a DOS box? Just use the .pyw extension instead of .py, and the DOS box automagically disappears -- or so I have been told ... -- Leif Biberg Kristense

Re: Python or PHP?

2005-04-23 Thread Leif B. Kristensen
Lad skrev: > Is anyone capable of providing Python advantages over PHP if there are > any? Much more compact and yet much more readable code, making it easier to maintain and extend your programs. -- Leif Biberg Kristensen http://solumslekt.org/ -- http://mail.python.org/mailman/li

Re: Python or PHP?

2005-04-23 Thread Leif K-Brooks
Lad wrote: Is anyone capable of providing Python advantages over PHP if there are any? Python is a programming language in more ways than simple Turing completeness. PHP isn't. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python or PHP?

2005-04-23 Thread Leif K-Brooks
Mage wrote: However one of the worst cases is the sql injection attack. And sql injections must be handled neither by php nor by python but by the programmer. But Python's DB-API (the standard way to connect to an SQL database from Python) makes escaping SQL strings automatic. You can do this: cu

Re: Python or PHP?

2005-04-23 Thread Leif K-Brooks
John Bokma wrote: Not. Perl and Java use similar methods where one can specify place holders, and pass on the data unescaped. But still injection is possible. How? -- http://mail.python.org/mailman/listinfo/python-list

Re: Python or PHP?

2005-04-23 Thread Leif K-Brooks
John Bokma wrote: my $sort = $cgi->param( "sort" ); my $query = "SELECT * FROM table WHERE id=? ORDER BY $sort"; And the equivalent Python code: cursor.execute('SELECT * FROM table WHERE id=%%s ORDER BY %s' % sort, [some_id]) You're right, of course, about being *able* to write code with SQL inj

Re: Python or PHP?

2005-04-23 Thread Leif Biberg Kristensen
Leif K-Brooks skrev: > But Python's DB-API (the standard way to connect to an SQL database > from Python) makes escaping SQL strings automatic. You can do this: > > cursor.execute('UPDATE foo SET bar=%s WHERE id=%s', ["foo'bar", 123]) So. I've been

Re: Python or PHP?

2005-04-23 Thread Leif K-Brooks
Peter Ammon wrote: I'm bewildered why you haven't mentioned magic quotes. A one line change to the configuration file can render your PHP site almost entirely immune to SQL injection attacks. PHP's magic quotes is one of the most poorly-designed features I can think of. Instead of magically esc

Re: HTML cleaner?

2005-04-25 Thread Leif K-Brooks
Ivan Voras wrote: Is there a HTML clean/tidy library or module written in pure python? I found mxTidy, but it's a interface to command-line tool. What I'm searching is something that will accept a list of allowed tags and/or attributes and strip the rest from HTML string. Here's a module I wrote

Re: Order of elements in a dict

2005-04-26 Thread Leif K-Brooks
Marcio Rosa da Silva wrote: So, my question is: if I use keys() and values() it will give me the keys and values in the same order? It should work fine with the current implementation of dictionaries, but (AFAIK) it's not guaranteed to work by the mapping protocol. So theoretically, it could bre

Re: Reusing object methods?

2005-04-29 Thread Leif K-Brooks
Ivan Voras wrote: I want to 'reuse' the same method from class A in class B, and without introducing a common ancestor for both of them - is this possible in an elegant, straightforward way? >>> import new >>> >>> class A: ... def foo(self): ... print "Hello, %s!" % self.__class__.__n

Re: Python Challenge ahead [NEW] for riddle lovers

2005-04-30 Thread Leif K-Brooks
pythonchallenge wrote: For the riddles' lovers among you, you are most invited to take part in the Python Challenge, the first python programming riddle on the net. You are invited to take part in it at: http://www.pythonchallenge.com Very neat, I love things like this. Level 5 is maddening. Keep u

Re: OO in Python? ^^

2005-12-10 Thread Leif K-Brooks
Heiko Wundram wrote: > Fredrik Lundh wrote: >>Matthias Kaeppler wrote: >>>polymorphism seems to be missing in Python >> >>QOTW! > > Let's have some UQOTW: the un-quote of the week! ;-) +1 -- http://mail.python.org/mailman/listinfo/python-list

Re: how to convert string like '\u5927' to unicode string u'\u5927'

2005-12-27 Thread Leif K-Brooks
Chris Song wrote: > Here's my solution > > _unicodeRe = re.compile("(\\\u[\da-f]{4})") > def unisub(mo): > return unichr(int(mo.group(1)[2:],16)) > > unicodeStrFromNetwork = '\u5927' > unicodeStrNative = _unicodeRe(unisub, unicodeStrFromNetwork) > > But I think there must be a more straigh

Python shell interpreting delete key as tilde?

2006-01-20 Thread Leif K-Brooks
I'm running Python 2.3.5 and 2.4.1 under Debian Sarge. Instead of deleting the character after the cursor, pressing my "delete" key in an interactive Python window causes a system beep and inserts a tilde character. This behavior occurs across all of the terminals I've tried (xterm, Konsole, real L

Re: range() is not the best way to check range?

2006-07-17 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > or is there an alternative use of range() or something similar that can > be as fast? You could use xrange: [EMAIL PROTECTED]:~$ python -m timeit -n1 "1 in range(1)" 1 loops, best of 3: 260 usec per loop [EMAIL PROTECTED]:~$ python -m timeit -n1 "1 in xr

Re: function v. method

2006-07-18 Thread Leif K-Brooks
danielx wrote: > This is still a little bit of magic, which gets me thinking again about > the stuff I self-censored. Since the dot syntax does something special > and unexpected in my case, why not use some more dot-magic to implement > privates? Privates don't have to be entirely absent from Klas

Re: range() is not the best way to check range?

2006-07-18 Thread Leif K-Brooks
Grant Edwards wrote: > Using xrange as somebody else suggested is also insane. Sorry about that, I somehow got the misguided notion that xrange defines its own __contains__, so that it would be about the same speed as using comparison operators directly. I figured the OP might have a better rea

Re: operator overloading + - / * = etc...

2006-10-10 Thread Leif K-Brooks
Paul Rubin wrote: > The symbols on the left side of = signs are called variables even in > Haskell, where they don't "vary" (you can't change the value of a > variable once you have set it). FWIW, that's the original, mathematical meaning of the word 'variable'. They _do_ vary, but only when you

Re: pretty basic instantiation question

2006-10-23 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > let's say i have a class, and i need to create a different number of > instances (changes every time - and i can't know the number in advance) in > a loop. > a function receives the number of instances that are needed, and creates > them like, > a=Myclass() > b=Myclass()

Re: How to get each pixel value from a picture file!

2006-10-23 Thread Leif K-Brooks
Lucas wrote: > 1)I just copy the tutorial to run "print pix[44,55]". I really dont > know why they wrote that?! What tutorial? Where does it say that? -- http://mail.python.org/mailman/listinfo/python-list

Re: The format of filename

2006-10-24 Thread Leif K-Brooks
Neil Cerutti wrote: > Where can I find documentation of what Python accepts as the > filename argument to the builtin function file? Python will accept whatever the OS accepts. > As an example, I'm aware (through osmosis?) that I can use '/' as > a directory separator in filenames on both Unix an

Re: The format of filename

2006-10-24 Thread Leif K-Brooks
Neil Cerutti wrote: > Is translation of '/' to '\\' a feature of Windows or Python? It's a feature of Windows, but it isn't a translation. Both slashes are valid path separators on Windows; backslashes are just the canonical form. -- http://mail.python.org/mailman/listinfo/python-list

Re: Sending Dictionary via Network

2006-10-25 Thread Leif K-Brooks
Frithiof Andreas Jensen wrote: >> "mumebuhi" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> The simplejson module is really cool and simple to use. This is great! > > JUST what I need for some configuration files!! > Thanks for the link (die, configparse, dieee). I would person

Re: what is "@param" in docstrings?

2006-10-28 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > What does the "@param" mean? It looks like something meant to be > machine readable. Alas, googling on "@param" doesn't work... It looks > at first like a decorator, but that doesn't make much sense. It's Epydoc's Epytext markup: . --

Re: Random image text generation?

2006-11-12 Thread Leif K-Brooks
Steven D'Aprano wrote: > For a text only solution, consider putting up a natural language question > such as: > > What is the third letter of 'national'? > What is four plus two? > How many eggs in a dozen? > Fill in the blank: Mary had a little its fleece was white as snow. > Cat, Dog, Apple

Re: Random image text generation?

2006-11-12 Thread Leif K-Brooks
Ben Finney wrote: > Leif K-Brooks <[EMAIL PROTECTED]> writes: > >> Steven D'Aprano wrote: >>> For a text only solution, consider putting up a natural language >>> question >> That wouldn't work as a true CAPTCHA (Completely Automated *Publi

Re: Question about unreasonable slowness

2006-11-16 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > i = 0 > while (i < 20): > i = i + 1 for i in xrange(20): > (shellIn, shellOut) = os.popen4("/bin/sh -c ':'") # for testing, the > spawned shell does nothing > print 'next' > # for line in shellOut: > # print line > > On my system (AIX 5.1 if it matters, w

Re: TSV to HTML

2006-05-31 Thread Leif K-Brooks
Brian wrote: > I was wondering if anyone here on the group could point me in a > direction that would expllaing how to use python to convert a tsv file > to html. I have been searching for a resource but have only seen > information on dealing with converting csv to tsv. Specifically I want > to

Re: Pythondocs.info : collaborative Python documentation project

2006-09-16 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > I am a bit disapointed with the current Python online documentation. I > have read many messages of people complaining about the documentation, > it's lack of examples and the use of complicated sentences that you > need to read 10 times before understanding what it means

Re: Python programs always open source?

2006-09-18 Thread Leif K-Brooks
Ben Finney wrote: > So long as you're not distributing some or all of Python itself, or a > derivative work, the license for Python has no legal effect on what > license you choose for your own work. How many Python programs use nothing from the standard library? -- http://mail.python.org/mailman

Re: Python programs always open source?

2006-09-18 Thread Leif K-Brooks
Steve Holden wrote: > Leif K-Brooks wrote: >> Ben Finney wrote: >> >>> So long as you're not distributing some or all of Python itself, or a >>> derivative work, the license for Python has no legal effect on what >>> license you choose for your

Re: Reverse a String?

2006-09-23 Thread Leif K-Brooks
Gregory Piñero wrote: > Is my mind playing tricks on me? I really remember being able to > reverse a string as in: > > text='greg' > print text.reverse() >>> 'gerg' That method has never existed AFAIK. Maybe you're thinking of the reverse() method on lists? In any case, the you can reverse stri

Re: unicode, bytes redux

2006-09-25 Thread Leif K-Brooks
Paul Rubin wrote: > Duncan Booth explains why that doesn't work. But I don't see any big > problem with a byte count function that lets you specify an encoding: > > u = buf.decode('UTF-8') > # ... later ... > u.bytes('UTF-8') -> 3 > u.bytes('UCS-4') -> 4 > > That avoids creat

Re: Auto color selection PIL

2006-09-27 Thread Leif K-Brooks
Xiaolei wrote: > I'm trying to plot some points in an image. Each point has an > associating type and I'd like to have different colors (preferrably of > high contrast) for different types. The number of types in the data > file is unknown a priori. Is there a way to do this at runtime? How abo

Re: Auto color selection PIL

2006-09-27 Thread Leif K-Brooks
Xiaolei wrote: > I'm trying to plot some points in an image. Each point has an > associating type and I'd like to have different colors (preferrably of > high contrast) for different types. The number of types in the data > file is unknown a priori. Is there a way to do this at runtime? If you

Re: Auto color selection PIL

2006-09-28 Thread Leif K-Brooks
Gabriel Genellina wrote: > Try this. It first chooses 0, 1/2, then 1/4, 3/4, then */8... > It's the best I could make if you don't know the number of colors > beforehand. If you *do* know how many colors, your previous response is OK. Um, that's the same thing my second suggestion does: >>> h

Re: How to find number of characters in a unicode string?

2006-09-29 Thread Leif K-Brooks
Lawrence D'Oliveiro wrote: > Hmmm, for some reason > > len(u"C\u0327") > > returns 2. Is len(unicodedata.normalize('NFC', u"C\u0327")) what you want? -- http://mail.python.org/mailman/listinfo/python-list

Re: Looping over a list question

2006-10-03 Thread Leif K-Brooks
Tim Williams wrote: > Maybe > def myfunc(txt): > ... print txt > ... datafiles = ['1.txt','2.txt','3.txt','4.tst'] null = [myfunc(i) for i in datafiles if '.txt' in i] > 1.txt > 2.txt > 3.txt Ew. List comprehensions with side effects are very icky. -- http://mail.python.or

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

2006-10-03 Thread Leif K-Brooks
[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' Catch it: try: ver = sys.argv[1] except IndexError: ver = '2.14' -- htt

Re: A Universe Set

2006-10-04 Thread Leif K-Brooks
Jorgen Grahn wrote: > - infinite xrange()s itertools.count()? -- http://mail.python.org/mailman/listinfo/python-list

Re: YouTube written in Python

2006-12-12 Thread Leif K-Brooks
Terry Reedy wrote: > In a thread on the PyDev list, Guido van Rossum today wrote: >> And I just found out (after everyone else probably :-) that YouTube is >> almost entirely written in Python. (And now I can rub shoulders with >> the developers since they're all Googlers now... :-) Interesting. I

Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread Leif K-Brooks
Tim Chase wrote: >>> Comparing file system paths as strings is very brittle. >> >> Why do you say that? Are you thinking of something like this? >> >> /home//user/somedirectory/../file >> /home/user/file > > Or even > > ~/file ~ is interpreted as "my home directory" by the shell, but when it

Re: Colons, indentation and reformatting.

2007-01-09 Thread Leif K-Brooks
Paddy wrote: > Thinking about it a little, it seems that a colon followed by > non-indented code that has just been pasted in could also be used by a > Python-aware editor as a flag to re-indent the pasted code. How would it reindent this code? if foo: print "Foo!" if bar: print "Bar!" Like thi

Re: Proper class initialization

2006-03-01 Thread Leif K-Brooks
Steven Bethard wrote: > class A(object): > def _get_sum(): > return sum(xrange(10)) > sum = _get_sum() What's wrong with sum = sum(xrange(10))? -- http://mail.python.org/mailman/listinfo/python-list

Re: slicing the end of a string in a list

2006-03-02 Thread Leif K-Brooks
Ben Cartwright wrote: > No, since the line variable is unused. This: > > i = 0 > for line in switches: > line = switches[i][:-1] > i += 1 > > Would be better written as: > > for i in range(len(switches)): > switches[i] = switches[i][:-1] This is better, IMHO: for i, sw

Re: My personal candidate for QOTW (was: Python interpreter in Basic or a Python-2-Basic translator.)

2005-05-01 Thread Leif Biberg Kristensen
must be >>"safe." Any other development environments (such as Java, Perl, > . > . > . This is clear evidence supporting the theory that being in charge of security and being able to think have no significant correlation. And, yes: +1 QOTW from me, too. -- Leif Biberg Kristensen -- http://mail.python.org/mailman/listinfo/python-list

Re: Documenting Python code.

2005-05-03 Thread Leif K-Brooks
Isaac Rodriguez wrote: > Are there any standarized ways of documenting Python code? When I check the > __doc__ attribute of the standard modules, the results are kind of plain. Is > everyone using this style? See . Epydoc has a simple language for documentation t

Re: Python Challenge ahead [NEW] for riddle lovers

2005-05-03 Thread Leif K-Brooks
Chris McAloney wrote: > Okay, so I've been working on level seven for a LONG time now. I've > decoded the first message to get the hint for the next level. Using the > same tactics, then I decode the hint as well, but there are non-printable > characters. Frira be srjre pbcvrf bs gur fnzr cvkry

Re: empty lists vs empty generators

2005-05-04 Thread Leif K-Brooks
Jeremy Bowers wrote: > def __init__(self, generator): > self.generator = generator You'll want to use iter(generator) there in order to handle reiterables. -- http://mail.python.org/mailman/listinfo/python-list

Re: empty lists vs empty generators

2005-05-04 Thread Leif K-Brooks
Jeremy Bowers wrote: > On Wed, 04 May 2005 13:45:00 +0000, Leif K-Brooks wrote: > > >>Jeremy Bowers wrote: >> >>>def __init__(self, generator): >>>self.generator = generator >> >>You'll want to use iter(generator) there in

Re: globbing multiple wildcards

2005-05-07 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > I have a path spec similar to '/home/*/.mozilla/*/*/cache*/*' (this > will probably look familiar to *nix users) with multiple wildcards. I > am finding it difficult gathering ALL file pathnames which match this > spec. Can anyone shed some light on this for a python noob

Re: Is isinstance always "considered harmful"?

2005-05-15 Thread Leif K-Brooks
Jordan Rastrick wrote: > Say you're writing, in Python, the extend() method for a Linked List > version of python's builtin list. Its really important to know what > kind of iterable youre being passed in - because if its another > Linked list, and you know it, you can connect the two in 0(1) time;

Re: what is addMethod ?

2005-05-23 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: >I saw some python open source project with many > self.addMethod() functions (with 3 paramters) > > What does self.addMethod() is good for ? It's not a standard method, so it's good for whatever the particular class you were looking at was using it for. We might be a

Re: Using properties

2005-05-25 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > name=property(getname,setname,None,None) > > However, it no longer works if I modify getname and setname to > > def getname(self): > return self.name > > def setname(self,newname="Port2"): > self.name=newname That's because you're actually

Re: Case Sensitive, Multiline Comments

2005-05-27 Thread Leif K-Brooks
John Roth wrote: > "Elliot Temple" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >> One other interesting thing about case sensitivity I don't think >> anyone has mentioned: in Python keywords are all lowercase already >> (the way I want to type them). In some other languages,

Re: search/replace in Python

2005-05-28 Thread Leif K-Brooks
Oliver Andrich wrote: > re.sub(r"(.*)",r" href=http://www.google.com/search?q=\1>\1", text) For real-world use you'll want to URL encode and entityify the text: import cgi import urllib def google_link(text): text = text.group(1) return '%s' % (cgi.escape(urllib.quote(text)),

Re: search/replace in Python (solved)

2005-05-28 Thread Leif K-Brooks
Vamsee Krishna Gomatam wrote: > text = re.sub( "([^<]*)", r' href="http://www.google.com/search?q=\1";>\1', text ) But see what happens when text contains spaces, or quotes, or ampersands, or... -- http://mail.python.org/mailman/listinfo/python-list

Re: Case Sensitive, Multiline Comments

2005-05-30 Thread Leif K-Brooks
Roy Smith wrote: > Just wait until the day you're trying to figure out why some C++ function > is behaving the way it is and you don't notice that a 50-line stretch of > code is commented out with /* at the top and */ at the bottom. The same thing's happened to me in Python when I accidentally i

Re: working with pointers

2005-05-31 Thread Leif K-Brooks
Michael wrote: > a=2 > b=a > b=0 That's more or less equivalent to this C++ code: int *a; int *b; a = new int; *a = 2; b = a; b = new int; *b = 0; -- http://mail.python.org/mailman/listinfo/python-list

Re: working with pointers

2005-06-01 Thread Leif K-Brooks
Duncan Booth wrote: > The constant integers are created in advance, not when you do the > assignment. But that's just an optimization, not Python's defined behavior. It seems more useful to me to think of all integers as being created at assignment time, even if CPython doesn't actually do that.

Re: Scope

2005-06-03 Thread Leif K-Brooks
Elliot Temple wrote: > I want to write a function, foo, so the following works: > > def main(): > n = 4 > foo(n) > print n > > #it prints 7 What's wrong with: def foo(n): return 7 def main(): n = 4 n = foo(n) print n Anything else (including the tricks involving mu

<    1   2   3   >