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

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

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

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: 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: 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: How to Read Bytes from a file

2007-03-01 Thread Leif K-Brooks
Alex Martelli wrote: > You should probaby prepare before the loop a mapping from char to number > of 1 bits in that char: > > m = {} > for c in range(256): > m[c] = countones(c) Wouldn't a list be more efficient? m = [countones(c) for c in xrange(256)] -- http://mail.python.org/mailman/listin

Re: Lists: Converting Double to Single

2007-02-26 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > So I have lists that look like this: [1, 2, 3, 4, 5]. When I > concatenate lists, I end up with a list of lists that looks like > this: [[1, 2, 3. 4, 5]. [6, 7. 8, 9. 10]]. Really? >>> [1, 2, 3, 4, 5] + [6, 7, 8, 9, 10] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > Then, I aver

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

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

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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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-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: 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: 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: 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: 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: 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: 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: 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-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: 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: enumerate() question

2006-05-22 Thread Leif K-Brooks
Gregory Petrosyan wrote: > Hello! > I have a question for the developer[s] of enumerate(). Consider the > following code: > > for x,y in coords(dots): > print x, y > > When I want to iterate over enumerated sequence I expect this to work: > > for i,x,y in enumerate(coords(dots)): > print

Re: Multi-line lambda proposal.

2006-05-08 Thread Leif K-Brooks
Kaz Kylheku wrote: > But suppose that the expression and the multi-line lambda body are > reordered? That is to say, the expression is written normally, and the > mlambda expressions in it serve as /markers/ indicating that body > material follows. This results in the most Python-like solution. I

Re: which is better, string concatentation or substitution?

2006-05-07 Thread Leif K-Brooks
fuzzylollipop wrote: > niether .join() is the fastest Please quote what you're replying to. No, it's the slowest: [EMAIL PROTECTED]:~$ python -m timeit "'%s\n\n' % 'foobar'" 100 loops, best of 3: 0.607 usec per loop [EMAIL PROTECTED]:~$ python -m timeit "'' + 'foobar' + '\n\n'" 100 loops

Re: which is better, string concatentation or substitution?

2006-05-07 Thread Leif K-Brooks
John Salerno wrote: > My initial feeling is that concatenation might take longer than > substitution Doesn't look that way: [EMAIL PROTECTED]:~$ python -m timeit "'%s\n\n' % 'foobar'" 100 loops, best of 3: 0.6 usec per loop [EMAIL PROTECTED]:~$ python -m timeit "'' + 'foobar' + '\n\n'" 1

Re: scope of variables

2006-05-03 Thread Leif K-Brooks
Gary Wessle wrote: > the example was an in-accuretlly representation of a the problem I am > having. my apologies. > > a = [] > def prnt(): >print len(a) > prnt > > > I expect to get 0 "the length of list a" Python requires parenthesis to call a function. >>> a = [] >>> def prnt(

Re: modifying iterator value.

2006-04-26 Thread Leif K-Brooks
chun ping wang wrote: > i want to modify an iterator value. > > for x in someList >x = 1 for index, value in enumerate(someList): someList[index] = 1 -- http://mail.python.org/mailman/listinfo/python-list

Re: Inexplicable behaviour of

2006-04-23 Thread Leif K-Brooks
Fabiano Sidler wrote: > Have a look to the following lines of code: > --- snip --- > class Foo: pass > def bar(): pass > Foo.bar = bar > --- snap --- > > Why does 'bar.__get__(Foo) is Foo.bar' evaluate to False here? Did I > misunderstand the descriptor protocol? bar.__get__(None, Bar) is what yo

Re: How to determine if a line of python code is a continuation of the line above it

2006-04-09 Thread Leif K-Brooks
Sandra-24 wrote: > I'm not sure how complex this is, I've been brainstorming a little, and > I've come up with: from tokenize import generate_tokens, NL, NEWLINE from cStringIO import StringIO def code_lines(source): """Takes Python source code (as either a string or file-like object) a

Re: how to convert string

2006-04-05 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > I want to print number 0 to 9 in one line like this > 0 1 2 3 4 5 6 7 8 9 > > if I do like this, it prints in different lines > > for i in xrange(10): > print i for i in xrange(10): print i, > so i tried like this > > str = "" > for i in xrange(10): > st

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

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

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 execute an EXE via os.system() with spaces in the directory name?

2005-12-04 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > This comes up from time to time. The brain damage is all Windows', > not Python's. It's perfectly reasonable behavior, and it also applies to Linux. The shell uses spaces to separate arguments; how do you expect it to know that you want a space to be part of the progra

Re: How to execute an EXE via os.system() with spaces in the directory name?

2005-12-04 Thread Leif K-Brooks
Leif K-Brooks wrote: > It's perfectly reasonable behavior, and it also applies to Linux. The > shell uses spaces to separate arguments; how do you expect it to know > that you want a space to be part of the program's name unless you escape it? I'm sorry, disregard my messa

Re: python speed

2005-12-01 Thread Leif K-Brooks
Krystian wrote: >>I would also like to see Half Life 2 in pure Python. > > or even quake1, do you think it could have any chances to run > smoothly? If can run at a reasonably speed, yes. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to convert a "long in a string" to a "long"?

2005-11-18 Thread Leif K-Brooks
Sion Arrowsmith wrote: > Steven Bethard <[EMAIL PROTECTED]> wrote: > >>[EMAIL PROTECTED] wrote: >> >>>s = long("0xL") >>>ValueError: invalid literal for long(): 0xL >>> >int("0x", 0) >> >>4294967295L > > So why does the base argument to int() (or long()) default to >

Re: Parse file into array

2005-11-14 Thread Leif K-Brooks
Leif K-Brooks wrote: > line = line.rsplit('\r\n') Er, that should be line.rstrip, not line.rsplit. -- http://mail.python.org/mailman/listinfo/python-list

Re: Parse file into array

2005-11-14 Thread Leif K-Brooks
amfr wrote: > I was wondering how i could parse the contents of a file into an array. > the file would look something like this: > > gif:image/gif > html:text/html > jpg:image/jpeg > ... > > As you can see, it contains the mime type and the file extension > seperated by commas, 1 per line. I wa

Re: list of lambda

2005-11-11 Thread Leif K-Brooks
jena wrote: > hello, > when i create list of lambdas: > l=[lambda:x.upper() for x in ['a','b','c']] > then l[0]() returns 'C', i think, it should be 'A' Fredrik Lundh provided the general solution, but in this specific case, the simplest solution is: l = [x.upper for x in ['a', 'b', 'c']] -- htt

Re: Recompile AST?

2005-11-10 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > Is it possible to recompile the AST generated by compiler.parse, back > into code or an executable code object? Into a bytecode object: >>> from compiler.pycodegen import ModuleCodeGenerator >>> from compiler.misc import set_filename >>> from compiler import parse >

Re: Confusion about __call__ and attribute lookup

2005-11-10 Thread Leif K-Brooks
Kent Johnson wrote: > But why doesn't Foo.__call__ shadow type.__call__? Normally an instance > attribute takes precedence over a class attribute. Is it something > special about how function call syntax is handled internally, or do all > special methods work this way, or is there something else go

Re: [ x for x in xrange(10) when p(x) ]

2005-11-10 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > Leif K-Brooks wrote: > >>[EMAIL PROTECTED] wrote: >> >>>thanks. that is what I am doing now, in a more generic form : >>> >>>takewhile(p, (x for x in xrange(1))) >> >>How does a useless generator expressi

Re: [ x for x in xrange(10) when p(x) ]

2005-11-10 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > George Sakkis wrote: > >list(takewhile(p, xrange(1000))) >> >>[0, 1] > > thanks. that is what I am doing now, in a more generic form : > > takewhile(p, (x for x in xrange(1))) How does a useless generator expression make it more generic? -- http://mail

Re: how to stop a loop with ESC key? [newbie]

2005-11-08 Thread Leif K-Brooks
mo wrote: > Can somebody explain how to stop a WHILE loop in running program by pressing > ESC key? On Unix-like systems try: import termios, fcntl, sys, os fd = sys.stdin.fileno() oldterm = termios.tcgetattr(fd) newattr = termios.tcgetattr(fd) newattr[3] = newattr[3] & ~termios.ICANON & ~termio

Re: overloading *something

2005-11-07 Thread Leif K-Brooks
James Stroud wrote: > Hello All, > > How does one make an arbitrary class (e.g. class myclass(object)) behave like > a list in method calls with the "*something" operator? What I mean is: > > myobj = myclass() > > doit(*myobj) Make it iterable: >>> class Foo(object): ... def __iter__(se

Re: Converting a List into a String

2005-11-05 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > list = ['f', 'e', 'd', 'c', 'b', 'a'] > > How can i convert it into a string so the output is > > fedcba print ''.join(list) -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I do this in Python?

2005-11-04 Thread Leif K-Brooks
Steve Holden wrote: > Another alternative might be to serve a script that sent the browser > back 2 pages in its history, as long as server state hasn't changed in > the meantime. What about users with JavaScript disabled? -- http://mail.python.org/mailman/listinfo/python-list

Re: I Need Motivation Part 2

2005-11-04 Thread Leif K-Brooks
Sybren Stuvel wrote: > There are over 2800 header files on my system in /usr/include. What do > you mean "a limited number of header files"? I assume he's saying that the number is < ∞. (Of course, the same is true of Python modules unless you use a special __import__ hook or something...) -- htt

Re: dictionary that have functions with arguments

2005-11-02 Thread Leif K-Brooks
Alex Martelli wrote: > execfunc = { 'key1' : (func1, ()), > 'key2' : (func2, args) } > > now, something like: > > f, a = execfunc[k] > f(**a) > > will work for either key. Shouldn't func1's args be a dictionary, not a tuple? -- http://mail.python.org/mailman/listinfo/pytho

Re: Converting 2bit hex representation to integer ?

2005-10-19 Thread Leif K-Brooks
Madhusudan Singh wrote: > I am using binascii.b2a_hex to convert some binary data to hex. The > result is a two bit hex representation (i. e., without the leading > 0x). Surely you mean two-byte? > How do I convert the resulting two bit representation into an integer > ? int(foo, 16) -- http://

Re: newbie regex

2005-10-17 Thread Leif K-Brooks
Leif K-Brooks wrote: > [EMAIL PROTECTED] wrote: > >>I want to filter some strings,but i don t know how to use compile >>method. > > Why not? Sorry: I misread that as not _wanting_ to use the compile method. -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie regex

2005-10-17 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > I want to filter some strings,but i don t know how to use compile > method. Why not? > first character must be [a-zA-z] group and others can only be digits or > letters. if re.search('^[a-zA-Z][a-zA-Z0-9]*$', foo): print "Valid string." else: print "Invalid str

Re: Changing an AST

2005-10-10 Thread Leif K-Brooks
beza1e1 wrote: > Is it possible compiler.parse a statement, then change and then > execute/resolve it? This should work: >>> from compiler.pycodegen import ModuleCodeGenerator >>> from compiler.misc import set_filename >>> from compiler import parse >>> >>> tree = parse('foo = 42') >>> set

Re: os.access with wildcards

2005-10-06 Thread Leif K-Brooks
mike wrote: > i'd like to use > >os.access(path,mode) > > where path may contain linux style wildcards. os.access(glob.glob(path), mode) -- http://mail.python.org/mailman/listinfo/python-list

Re: Python eats gator.

2005-10-05 Thread Leif K-Brooks
Sam wrote: > http://www.wnbc.com/family/5060215/detail.html > > I know there's an on-topic joke in here somewhere, but I'm having some > problem finding it, at the moment. > > You may take a crack at it, if you'd like… Hmm... has anyone ever written a spyware removal tool in Python? -- http://m

Re: 2 class with same name in different module

2005-10-05 Thread Leif K-Brooks
Iyer, Prasad C wrote: > I have a class in a module which is getting imported in main module. > How do you differentiate between the 2 class import foo import bar foo.TheClass().dostuff() bar.TheClass().dostuff() -- http://mail.python.org/mailman/listinfo/python-list

Re: Distributing programs

2005-10-02 Thread Leif K-Brooks
Jeff Schwab wrote: > Sorta, but not really. Typically, you might distribute the source (.py) > files, but if you don't want to do that, you can distribute the > compiled .pyc files instead. Python creates these files automatically > when your modules are imported. But remember that Python bytec

Re: [Info] PEP 308 accepted - new conditional expressions

2005-10-01 Thread Leif K-Brooks
Sam wrote: > And "foo if bar" is Perl-ish; yet, even Perl has the ? : operators. What _isn't_ Perl-ish? -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with syntax warnings

2005-09-29 Thread Leif K-Brooks
Ivan Shevanski wrote: > is there a way to turn off syntax warnings or just make them not > visible? import warnings warnings.filterwarnings('ignore', category=SyntaxWarning) -- http://mail.python.org/mailman/listinfo/python-list

Re: __call__ in module?

2005-09-27 Thread Leif K-Brooks
ncf wrote: > I have a feeling that this is highly unlikely, but does anyone in here > know if it's possible to directly call a module, or will I have to wrap > it up in a class? You could use trickery with sys.modules to automatically wrap it in a class: import sys from types import ModuleType c

Re: replacments for stdio?

2005-09-23 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: >i was wondering if anyone have written a GUI module that can > function as a replacment for stdin/stdout? ie. has a file like > interface, by which one could just assaign it to sys.stdout or > sys.stdin and have all your prints and raw_inputs and other such things > sh

Re: execute commands and return output

2005-09-10 Thread Leif K-Brooks
billiejoex wrote: > Thank you for your help but I'm searching a different way. > Moreover it doesn't work always (for exaple: try a 'dir' command). > Because of I'm implementing a remote shell the > [[os.popen('command').read()]] rapresents the best for me because it can > also accepts arguments

Re: execute commands and return output

2005-09-10 Thread Leif K-Brooks
billiejoex wrote: > Hi all. I'm searching for a portable (working on *nix and win32) function > that executes a system command and encapsulate its output into a string. > Searching for the web I found this: > > os.popen('command').read() > > It is perfect but when che command return an error the

Re: using % operator to print possibly unitialized data attributes

2005-09-09 Thread Leif K-Brooks
Adam Monsen wrote: > class J: > name = '' > value = '' > def __str__(self): > vals = self.__class__.__dict__ > vals.update(self.__dict__) > return 'name="%(name)s" value="%(value)s' % vals This will update the class's attributes with instance attributes when str

Re: How to dynamicly define function and call the function?

2005-09-08 Thread Leif K-Brooks
FAN wrote: > class test: > def __init__(self): > exec("def dfunc(msg):\n\tprint msg\nprint 'exec def function'") > dfunc('Msg in init ...') # it work > > def show(self, msg): > dfunc(msg) # doesn't work ! >

Re: reading the last line of a file

2005-09-08 Thread Leif K-Brooks
Xah Lee wrote: > i switched to system call with tail because originally i was using a > pure Python solution > > inF = gzip.GzipFile(ff, 'rb'); > s=inF.readlines() > inF.close() > last_line=s[-1] > > and since the log file is 100 megabytes it takes a long time

Re: Generators and Decorators doing my head in ..

2005-09-06 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > Im trying to create a decorator that counts the number of times a > function is run. Your code doesn't work because decorators are run at function creation time, not at function run time. Try this instead: from itertools import count def logFunctionCalls(function):

Re: Replacement for lambda - 'def' as an expression?

2005-09-06 Thread Leif K-Brooks
Sybren Stuvel wrote: > It also allows for dynamic function creation in cases where a name > would not be available. What cases are those? -- http://mail.python.org/mailman/listinfo/python-list

  1   2   3   >