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

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

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

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: 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 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: 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

Re: method = Klass.othermethod considered PITA

2005-06-04 Thread Leif K-Brooks
John J. Lee wrote: > class Klass: > > def _makeLoudNoise(self, *blah): > ... > > woof = _makeLoudNoise > > [...] > > At least in 2.3 (and 2.4, AFAIK), you can't pickle classes that do > this. Works for me: Python 2.3.5 (#2, May 4 2005, 08:51:39) [GCC 3.3.5 (Debian 1:3.3.5-12)

Re: About size of Unicode string

2005-06-06 Thread Leif K-Brooks
Frank Abel Cancio Bello wrote: > request.add_header('content-encoding', 'UTF-8') The Content-Encoding header is for things like "gzip", not for specifying the text encoding. Use the charset parameter to the Content-Type header for that, as in "Content-Type: text/plain; charset=utf-8". -- ht

Re: case/switch statement?

2005-06-11 Thread Leif K-Brooks
Joe Stevenson wrote: > I skimmed through the docs for Python, and I did not find anything like > a case or switch statement. I assume there is one and that I just > missed it. Can someone please point me to the appropriate document, or > post an example? I don't relish the idea especially lon

Re: splitting delimited strings

2005-06-15 Thread Leif K-Brooks
Mark Harrison wrote: > What is the best way to process a text file of delimited strings? > I've got a file where strings are quoted with at-signs, @like [EMAIL > PROTECTED] > At-signs in the string are represented as doubled @@. >>> import re >>> _at_re = re.compile('(?>> def split_at_line(line):

Re: Called function conditional testing (if) of form variables problem

2005-06-15 Thread Leif K-Brooks
Eduardo Biano wrote: > def foo(request): > ans01 = request.get_form_var("ans01") > if ans01 == 4: > ans_1 = 1 > return ans_1 ans01 will be a string ("4"), not an int (4). -- http://mail.python.org/mailman/listinfo/python-list

Regex for repeated character?

2005-06-16 Thread Leif K-Brooks
How do I make a regular expression which will match the same character repeated one or more times, instead of matching repetitions of any (possibly non-same) characters like ".+" does? In other words, I want a pattern like this: >>> re.findall(".+", "foo") # not what I want ['foo'] >>> re.finda

Re: Generating .pyo from .py

2005-06-16 Thread Leif K-Brooks
skn wrote: > Does the python compiler provide an option to generate a .pyo(optimized byte > code file) from a .py (source file)? > > For generating .pyc I know that I only have to pass the source file name as > an argument to py_compile.py. py_compile.py checks __debug__ to decide whether to use

Re: Overcoming herpetophobia (or what's up w/ Python scopes)?

2005-06-18 Thread Leif K-Brooks
Steven D'Aprano wrote: > The language is *always* spelt without the "a", and usually all in > lower-case: perl. The language is title-cased (Perl), but the standard interpreter is written in all lowercase (perl). Sort of like the distinction between Python and CPython. -- http://mail.python.org/m

Re: UTF-8

2007-03-10 Thread Leif K-Brooks
Laurent Pointal wrote: > You should prefer to put > # -*- coding: utf-8 -*- > at the begining of your sources files. With that you are ok with all Python > installations, whatever be the defautl encoding. > Hope this will become mandatory in a future Python version. The default encoding

Re: dict.items() vs dict.iteritems and similar questions

2007-03-14 Thread Leif K-Brooks
Laurent Pointal wrote: > Both work, you may prefer xrange/iteritems for iteration on large > collections, you may prefer range/items when processing of the result > value explicitly need a list (ex. calculate its length) or when you are > going to manipulate the original container in the loop. xra

Re: Converting a list to a dictionary

2007-03-14 Thread Leif K-Brooks
Samuel wrote: > This does not work: > > res_dict = dict([r.get_id(), r for r in res_list]) This does: res_dict = dict([(r.get_id(), r) for r in res_list]) -- http://mail.python.org/mailman/listinfo/python-list

Re: No module named ...

2007-03-20 Thread Leif K-Brooks
gtb wrote: > I was having trouble with the 'no module named' error message when > trying to import and noticed that other successful imports were > pulling from .py files that had the dot replaced with $ and .class > appended to the name. Actually in one case it picked up a .pyc file > then created

YouTube showing repr() of a tuple

2007-03-29 Thread Leif K-Brooks
Thought this might amuse some of you: I'd heard that YouTube uses Python, but it's fun to see proof of that, even if it comes in the form of a minor bug. -- http://mail.python.org/mailman/listinfo/python-list

Re: YouTube showing repr() of a tuple

2007-03-29 Thread Leif K-Brooks
Leif K-Brooks wrote: > Thought this might amuse some of you: > > <http://youtube.com/results?search_query=korect+my+speling> Better example: <http://youtube.com/results?search_query=korect+my+speling%C2%A1> -- http://mail.python.org/mailman/listinfo/python-list

Re: YouTube showing repr() of a tuple

2007-04-02 Thread Leif K-Brooks
Paul Boddie wrote: > On 2 Apr, 16:19, Steve Holden <[EMAIL PROTECTED]> wrote: >> Both fixed by the time I managed to follow the links. > > There wasn't much to see, and putting apostrophes into the input > didn't seem to cause "proper" repr() behaviour. So I suspect that the > Python resemblance w

Legally correct way of copying stdlib module?

2007-01-10 Thread Leif K-Brooks
I'm writing a package where I need to use the uuid module. Unfortunately, that module is only available in Python 2.5, and my package needs to be compatible with 2.4. I'm planning to copy it from Python 2.5's stdlib into my package, and import it like this: try: import uuid except ImportEr

Re: __getattr__ equivalent for a module

2007-01-15 Thread Leif K-Brooks
Maksim Kasimov wrote: > so my question is: how to tune up a module get default attribute if we > try to get access to not actually exists attribute of a module? You could wrap it in an object, but that's a bit of a hack. import sys class Foo(object): def __init__(self, wrapped): s

Re: Convert from unicode chars to HTML entities

2007-01-28 Thread Leif K-Brooks
Steven D'Aprano wrote: > I have a string containing Latin-1 characters: > > s = u"© and many more..." > > I want to convert it to HTML entities: > > result => > "© and many more..." > > Decimal/hex escapes would be acceptable: > "© and many more..." > "© and many more..." >>> s = u"© and many

Re: Random passwords generation (Python vs Perl) =)

2007-01-28 Thread Leif K-Brooks
NoName wrote: > from random import choice > import string > print ''.join([choice(string.letters+string.digits) for i in > range(1,8)]) > > !!generate password once :( So add a while true: line. > who can write this smaller or without 'import'? Why are those your goals? -- http://mail.python.

Re: Convert from unicode chars to HTML entities

2007-01-28 Thread Leif K-Brooks
Steven D'Aprano wrote: > A few issues: > > (1) It doesn't seem to be reversible: > '© and many more...'.decode('latin-1') > u'© and many more...' > > What should I do instead? Unfortunately, there's nothing in the standard library that can do that, as far as I know. You'll have to write y

Re: HTMLParser's start_tag method never called ?

2007-02-06 Thread Leif K-Brooks
ychaouche wrote: > class ParseurHTML(HTMLParser): > def __init__(self): > HTMLParser.__init__(self) > > def start_body(self,attrs): > print "this is my body" def start_tag(self, name, attrs): if name == 'body': print "this is my body" -- http://mail.python.o

Re: 'IF' Syntax For Alternative Conditions

2007-02-07 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > However, I cannot find, nor create by trial-and-error, the syntax for > alternative conditions that are ORed; e.g., > > if cond1 OR if cond2: > do_something. if cond1 or cond2: do_something() -- http://mail.python.org/mailman/listinfo/python-list

Re: begin to parse a web page not entirely downloaded

2007-02-08 Thread Leif K-Brooks
k0mp wrote: > Is there a way to retrieve a web page and before it is entirely > downloaded, begin to test if a specific string is present and if yes > stop the download ? > I believe that urllib.openurl(url) will retrieve the whole page before > the program goes to the next statement. Use urllib.u

Re: begin to parse a web page not entirely downloaded

2007-02-08 Thread Leif K-Brooks
k0mp wrote: > It seems to take more time when I use read(size) than just read. > I think in both case urllib.openurl retrieve the whole page. Google's home page is very small, so it's not really a great test of that. Here's a test downloading the first 512 bytes of an Ubuntu ISO (beware of wrap)

Re: default mutable arguments

2007-02-08 Thread Leif K-Brooks
Gigs_ wrote: > I read that this is not the same: > def functionF(argString="abc", argList = None): > if argList is None: argList = [] # < this > ... > def functionF(argString="abc", argList=None): > argList = argList or [] # and this > ... > > Why

Re: def obj()

2007-02-08 Thread Leif K-Brooks
Gert Cuykens wrote: > def obj(): >return {'data':'hello', >'add':add(v)} > > def add(v): >data=data+v > > if __name__ == '__main__': >test=obj() >test.add('world') >print test.data > > I don't know why but i have one of does none class c programing style > mo

Re: About getattr()

2007-02-11 Thread Leif K-Brooks
Jm lists wrote: > Since I can write the statement like: > print os.path.isdir.__doc__ > Test whether a path is a directory > > Why do I still need the getattr() func as below? > print getattr(os.path,"isdir").__doc__ > Test whether a path is a directory You don't. getattr() is only us

<    1   2   3   >