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: __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: 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: [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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: [ 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: [ 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: 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: 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: 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: 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: 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: 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: 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 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: 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: Python & unicode

2005-01-10 Thread Leif K-Brooks
John Roth wrote: It doesn't work because Python scripts must be in ASCII except for the contents of string literals. Having a function name in anything but ASCII isn't supported. To nit-pick a bit, identifiers can be in Unicode; they're simply confined to digits and plain Latin letters. -- http://

Re: Python & unicode

2005-01-11 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: So is the support of Unicode in virtually every computer language because they don't support ... digits except 0..9. Hex digits aren't 0..9. Python 2.4 (#2, Dec 3 2004, 17:59:05) [GCC 3.3.5 (Debian 1:3.3.5-2)] on linux2 Type "help", "copyright", "credits" or "license" for

Re: counting items

2005-01-12 Thread Leif K-Brooks
Paul McGuire wrote: Considering how often this comes up, might there be a place for some sort of flatten() routine in the std dist, perhaps itertools? A problem I see is that itertools tries to work across all iterable types, but flattening can't always be a generalized operation. For instance, a

Re: Octal notation: severe deprecation

2005-01-13 Thread Leif K-Brooks
Tim Roberts wrote: Stephen Thorne <[EMAIL PROTECTED]> wrote: I would actually like to see pychecker pick up conceptual errors like this: import datetime datetime.datetime(2005, 04,04) Why is that a conceptual error? Syntactically, this could be a valid call to a function. Even if you have parsed

Re: how to control the mouse pointer with python?

2005-01-13 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: Anybody know a way to control the mouse pointer (move it around and click on things) using python? It depends on your operating system. For Windows, you'll want to use a Python module to access the Win32 API. The relevant API function is documented at http://tinyurl.com/j

Re: One-Shot Property?

2005-01-18 Thread Leif K-Brooks
Kevin Smith wrote: I have many cases in my code where I use a property for calculating a value on-demand. Quite a few of these only need to be called once. After that the value is always the same. In these properties, I set a variable in the instance as a cached value and return that value on

Solutions for data storage?

2005-01-18 Thread Leif K-Brooks
I'm writing a relatively simple multi-user public Web application with Python. It's a rewrite of a similar application which used PHP+MySQL (not particularly clean code, either). My opinions on various Web frameworks tends to vary with the phase of the moon, but currently, I'm planning to use Q

Re: Solutions for data storage?

2005-01-19 Thread Leif K-Brooks
Robert Brewer wrote: Try svn://casadeamor.com/dejavu/trunk if you want a truly Pythonic query syntax. Wait a couple of days, and I'll have version 1.3 ready and online at http://www.aminus.org/rbre/python -- lots of changes from 1.2.6 which is there now, but at least you can read old docs online no

Re: Unbinding multiple variables

2005-01-20 Thread Leif K-Brooks
John Hunter wrote: >>>del locals()['x'] The locals() dictionary will only modify values in a module's top-level code (i.e. when the expression "locals() is globals()" is true). -- http://mail.python.org/mailman/listinfo/python-list

Re: What YAML engine do you use?

2005-01-22 Thread Leif K-Brooks
Bengt Richter wrote: I thought XML was a good idea, but IMO requiring quotes around even integer attribute values was an unfortunate decision. I think it helps guard against incompetent authors who wouldn't understand when they're required to use quotes and when they're not. I see HTML pages all

Re: Quoting sql queries with the DB-API

2005-01-23 Thread Leif K-Brooks
snacktime wrote: I'm used to using the perl DBI and not very familiar with the python DB-API. I am using PyGreSQL. My question is what is the standard way to quote strings in sql queries? I didn't see any quoting functions in the DB-API docs. Is quoting handled internally by the PyGreSQL module

Re: set, dict and other structures

2005-01-31 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: I'm frequently using Py2.4 sets, I find them quite useful, and I like them, even if they seem a little slower than dicts. They look exactly the same speed-wise to me: >>> t1 = Timer('randrange(100) in foo', 'from random import randrange; foo = set(xrange(1000))') >>> t2 =

Re: empty classes as c structs?

2005-02-04 Thread Leif K-Brooks
Alan McIntyre wrote: You could do something like this: blah = type('Struct', (), {})() blah.some_field = x I think I'd only do this if I needed to construct objects at runtime based on information that I don't have at compile time, since the two lines of code for your empty class would probably b

Word for a non-iterator iterable?

2005-02-05 Thread Leif K-Brooks
Is there a word for an iterable object which isn't also an iterator, and therefor can be iterated over multiple times without being exhausted? "Sequence" is close, but a non-iterator iterable could technically provide an __iter__ method without implementing the sequence protocol, so it's not qu

Re: Multiple constructors

2005-02-06 Thread Leif K-Brooks
Philip Smith wrote: I don't seem to be able to define multiple versions of __init__ in my matrix class (ie to initialise either from a list of values or from 2 dimensions (rows/columns)). You could either use an if statement with *args: class Matrix(object): def __init__(self, *args):

Re: Multiple constructors

2005-02-06 Thread Leif K-Brooks
Leif K-Brooks wrote: @classmethod def from_pair(self, rows, columns): return Matrix([rows, columns]) # Or with the right argument Er... I'm not sure why I named that argument "self", it should be "cls" if you don't want to confuse any

Re: Shortcut to initialize variables

2005-06-19 Thread Leif K-Brooks
Kent Johnson wrote: > letters = {} > for letter in ascii_lowercase: > letters[letter] = 0 Or more simply: letters = dict.fromkeys(ascii_lowercase, 0) -- http://mail.python.org/mailman/listinfo/python-list

Re: Can we pass some arguments to system("cmdline")?

2005-06-20 Thread Leif K-Brooks
Didier C wrote: > E.g in Perl, we can do something like: > > $dir="/home/cypher"; > > system("ls $dir"); > > Is there a way to reproduce the same thing in Python? system("ls %s" % dir) But you should really be using subprocess for security (so that if dir=="/home/foo; rm -rf /" nothing bad wil

Re: subprocess.call(*args **kwargs) on Linux

2005-06-20 Thread Leif K-Brooks
McBooCzech wrote: > This is easy. Subprocess function "call" looks: > returncode = subprocess.call(["/root/dex/dex","/dev/ttyS0", > "blabla.txt"]) > and it runs smoothly. > > The problem starts when I am trying to add 1>/dev/null 2>/dev/null > parameters to suppres output sendings. from subproces

Re: a dictionary from a list

2005-06-24 Thread Leif K-Brooks
David Bear wrote: > Is there an easy way to create a dictionary object with the members of > 'alist' being the keys in the dictionary, and the value of the keys set to > null? adict = dict.fromkeys(alist) -- http://mail.python.org/mailman/listinfo/python-list

Re: execute python code and save the stdout as a string

2005-06-25 Thread Leif K-Brooks
jwaixs wrote: > I've a question. Can I execute a part of a python code and put it's > output in a string? >>> import sys >>> from cStringIO import StringIO >>> >>> def exec_and_get_output(code): ... old_stdout = sys.stdout ... sys.stdout = StringIO() ... try: ... exec c

Re: is there an equivalent of javascript's this["myMethod"] for the currently running script?

2005-07-05 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > I'd like to dynamically find and invoke a method in a Python CGI. getattr(self, methodName)() But make sure to validate user input first, of course. -- http://mail.python.org/mailman/listinfo/python-list

Re: Conditionally implementing __iter__ in new style classes

2005-07-06 Thread Leif K-Brooks
Thomas Heller wrote: > I forgot to mention this: The Base class also implements a __getitem__ > method which should be used for iteration if the .Iterator method in the > subclass is not available. So it seems impossible to raise an exception > in the __iter__ method if .Iterator is not found - __

Re: Use cases for del

2005-07-06 Thread Leif K-Brooks
Grant Edwards wrote: > 1) So I know whether an parameter was passed in or not. Perhaps >it's not considered good Pythonic style, but I like to use a >single method for both get and set operations. With no >parameters, it's a get. With a parameter, it's a set: > >class demo: >

Re: Use cases for del

2005-07-06 Thread Leif K-Brooks
Grant Edwards wrote: > On 2005-07-07, Leif K-Brooks <[EMAIL PROTECTED]> wrote: >>_NOVALUE = object() >>class demo: >>def foo(v=_NOVALUE): >>if v is _NOVALUE: >>return self.v >>else: >>self.v = v >

Re: removing list comprehensions in Python 3.0

2005-07-08 Thread Leif K-Brooks
Kay Schluehr wrote: > Well, I want to offer a more radical proposal: why not free squared > braces from the burden of representing lists at all? It should be > sufficient to write > list() > > list() So then what would the expression list('foo') mean? Would it be equivalent to ['foo'] (if so

Re: removing list comprehensions in Python 3.0

2005-07-08 Thread Leif K-Brooks
Kay Schluehr wrote: list.from_str("abc") > > list("a", "b", "c" ) I assume we'll also have list.from_list, list.from_tuple, list.from_genexp, list.from_xrange, etc.? -- http://mail.python.org/mailman/listinfo/python-list

Re: goto

2005-07-18 Thread Leif K-Brooks
rbt wrote: > IMO, most of the people who deride goto do so because they heard or read > where someone else did. 1 GOTO 17 2 mean,GOTO 5 3 couldGOTO 6 4 with GOTO 7 5 what GOTO 3 6 possibly GOTO 24 7 you! GOTO 21 8 that GOTO 18 9 really,

Re: How to send a query to the browser from time to time?

2005-07-19 Thread Leif K-Brooks
Admin wrote: > I am creating a chat application like Messenger for the web (using the > browser) and I'm wondering if there is a way to receive new messages > from time to time from the server other than refreshing the page each 5 > sec. Here's a pretty basic example I wrote a while ago using Tw

Re: Web Framework Reviews

2005-07-19 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: >>Templating engines like ZPT prefer to put some code in the template, >>Nevow prefers to put code in python and allow you to write some xhtml in >>python too. > > Oh yeah, now I remeber, I think this is a controversial idea. One important thing to realise about Nevow is

Re: Retaining an object

2005-08-09 Thread Leif K-Brooks
sysfault wrote: > I'm using os.popen() to open that program via the syntax: > os.popen('pidof var_name', 'r'), but as you know var_name is not > expanded within single quotes, os.popen('pidof %s' % var_name, 'r') -- http://mail.python.org/mailman/listinfo/python-list

Re: Bizarre error from help()

2005-08-09 Thread Leif K-Brooks
Roy Smith wrote: > No, that works fine. But, now I can't even reproduce the error I reported > earlier (when I try, I get the help message as expected). And, yes, that > was with a brand new interpreter session. Strange. Perhaps you were running Python from a directory with a file called strin

Re: Sandboxes

2005-08-20 Thread Leif K-Brooks
42 wrote: > I was wondering if it would be effective to pre-parse incoming scripts > and reject those containing "import"? getattr(__builtins__, '__imp' + 'ort__')('dangerousmodule') -- http://mail.python.org/mailman/listinfo/python-list

Re: Sandboxes

2005-08-22 Thread Leif K-Brooks
42 wrote: > FWIW I've already given up on making python secure. I agree that odds > are extremely high that I've missed something. I'm just curious to see > what one of the holes I left is, preferably without wading through > hundreds of pages :) f = [x for x in [].__class__.__bases__[0].__subc

Re: argument matching question

2005-08-25 Thread Leif K-Brooks
Learning Python wrote: > A code like this: > > def adder(**varargs): > sum=varargs[varargs.keys()[0]] > for next in varargs.keys()[1:]: > sum=sum+varargs[next] > return sum > > print adder( "first","second",'third') > > How to pass arguments to a functions that

Re: Any projects to provide Javascript-style client-side browser access via Python?

2005-08-26 Thread Leif K-Brooks
Kenneth McDonald wrote: > I'm curious about this because, quite aside their function as web > browsers, it is now possible to build some very useable interfaces > using browsers with HTML, CSS, and JavaScript. (The biggest problem is > still the lack of a decent text widget.) However, JavaScript

Re: execute commands independantly

2005-09-06 Thread Leif K-Brooks
Mike Tammerman wrote: > Hi, > > I am trying to execute an executable or a pyton script inside my > program. I looked at the subprocess and os module. But all the > functions in these modules blocks my application. subprocess doesn't block unless you call .wait(): from subprocess import Popen pro

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

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: 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: 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: 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: 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: 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: OT: why are LAMP sites slow?

2005-02-06 Thread Leif K-Brooks
Paul Rubin wrote: I notice that lots of the medium-largish sites (from hobbyist BBS's to sites like Slashdot, Wikipedia, etc.) built using this approach are painfully slow even using seriously powerful server hardware. Yet compared to a really large site like Ebay or Hotmail (to say nothing of Go

Re: trolltech comitment

2005-02-08 Thread Leif K-Brooks
Gabriel B. wrote: What it they revoke this license [on Qt]? They can't. It's the GPL. what it windows longhorn has a non-backwardcompatible GDI API and a newer version of Qt must be used, and that newer version does not have a gpl version? What if Wx does that? What if Tk does? What if GTK does? If

Re: What's wrong with `is not None`?

2005-02-08 Thread Leif K-Brooks
Frans Englich wrote: runner.py:587: Using is not None, may not always work It's a PyChecker bug relating to None being a constant in 2.4: . -- http://mail.python.org/mailman/listinfo/python-list

Re: [NooB] a Variable in multiple quotes...

2005-02-13 Thread Leif K-Brooks
administrata wrote: Is it possible? I tried... I = "John" print \ """ I used to love pizza""" Error occurs!!! No error occurs; it prints "I used to love pizza", as would be expected. Oh: from the subject line, I'm guessing that you want it to say "John used to love pizza" instead? In that case,

Re: multi threading in multi processor (computer)

2005-02-14 Thread Leif K-Brooks
Irmen de Jong wrote: the GIL must die. I couldn't resist: http://www.razorvine.net/img/GIL.jpg Neither could I: http://ecritters.biz/diegil.png (In case it's not entirely obvious, the stick figure just slices the GIL into two pieces with his sword, causing its blood to splatter on the wall.) -- ht

Re: Why doesn't join() call str() on its arguments?

2005-02-17 Thread Leif K-Brooks
Leo Breebaart wrote: What I can't find an explanation for is why str.join() doesn't automatically call str() on its arguments I don't really like that idea for the reasons others have stated. But a related and (IMHO) more Pythonic idea would be to allow arbitrary objects to be str.join()ed if the

Re: Accessing files installed with distutils

2005-02-22 Thread Leif K-Brooks
Frans Englich wrote: This is silly. How do I access data files I've installed with distutils? In a portable, generic way, I want to find out what is the following path on most systems: /usr/local/lib/python2.4/lib/site-packages/foo/bar.txt Assuming your module is also in site-packages/foo, I wou

Re: On eval and its substitution of globals

2005-02-23 Thread Leif K-Brooks
Paddy wrote: I had to do as you suggest but I was thinking either it was a kludge, and there should be a 'deep' substitution of globals, or that there was a good reason for it to work as it does and some magician would tell me. If there was deep substitution of globals, how would functions importe

Re: function expression with 2 arguments

2005-02-26 Thread Leif K-Brooks
Xah Lee wrote: lambda x, y: x + y that's what i was looking for. ... once i have a lambda expr, how to apply it to arguments? http://python.org/doc/current/ref/calls.html -- http://mail.python.org/mailman/listinfo/python-list

Re: GOTO (was Re: Appeal for python developers)

2005-03-05 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: Goto is useful [...] when there is a clean-up section of a function that should be executed for various error conditions. Like this? def foo(): f = open('foo.txt') try: # do stuff with f finally: f.close() -- http://mail.python.org/mailman/listin

Re: function expression with 2 arguments

2005-03-06 Thread Leif K-Brooks
Xah Lee wrote: if i understand correctly, forms such as (lambda x,y:x+y)(a,b) can only be gained thru experience? and not documented directly anywhere in the official docs? The official documentation can't list every possible permutation of the various syntactic constructs. It does explain parenth

Re: IndexedCatalog and ZEO

2005-03-06 Thread Leif K-Brooks
Almad wrote: Hello, I'm trying to use IndexedCatalog [http://www.async.com.br/projects/IndexedCatalog/] in my CherryPy [http://www.cherrypy.org] application. As Zodb support access just from one Python thread, I must either use just one CherryPy thread (slow), or use ZEO. However, if I understan

Re: Wishlist item: itertools.flatten

2005-03-14 Thread Leif K-Brooks
Michael Spencer wrote: if hasattr(item,"__iter__"): # Avoids iterating over strings That's probably the cleanest way to avoid strings, but it's unfortunately not a good idea IMHO. Many objects (IndexedCatalog's Result objects are what I'm concerned about, but there are undoubtedly ot

Re: Licensing Python code under the Python license

2005-03-14 Thread Leif K-Brooks
Harlin Seritt wrote: If this is for making money, make it either a proprietary license or BSD. If you're giving it away and expect nothing for it except maybe fame, do GPL. You're kidding, right? How does the BSD license possibly offer more protection for a commercial program than the GPL does? --

Re: __getitem__ method on (meta)classes

2005-03-14 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: Why doesn't this work? def foo(lst): ... class baz(object): ... def __getitem__(cls, idx): return cls.lst[idx] ... __getitem__=classmethod(__getitem__) ... baz.lst = lst ... return baz ... I thought x[y] and x.__getitem__(y) were supposed to always be synonym

Re: unicode converting

2005-03-15 Thread Leif K-Brooks
Maxim Kasimov wrote: Diez B. Roggisch wrote: Maxim Kasimov wrote: there are a few questions i can find answer in manual: 1. how to define which is internal encoding of python unicode strings (UTF-8, UTF-16 ...) It shouldn't be your concern - but you can specify it using " ./configure --enable-uni

Re: iterable terminology (for language lawyers)

2005-03-16 Thread Leif K-Brooks
Michele Simionato wrote: According to the standand library (http://docs.python.org/lib/typeiter.html) an *iterable* is something with an __iter__ method. This means that strings are *not* iterable. In general, the definitions people in the Python community tend to use are: Iterable: An object whic

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

  1   2   3   >