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 more

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

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

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

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

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

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

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

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 anyone reading your code. -- http://mail.python.org

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

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?

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://tinyurl.com/6dexc. -- 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, try doing

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

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/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...) --

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__(self): ...

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

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

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 expression make it more generic? xrange is only picked as an example. I may

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 going

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 tree =

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']] --

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 was

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

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

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

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

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: 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 http://www.abrahamjoffe.com.au/ben/canvascape/ 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 message. I failed to read the OP

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

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 straightforward

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 proc =

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 and hogs

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() is

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

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

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 bytecode

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

Re: os.access with wildcards

2005-10-07 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_filename('foo',

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 string.

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

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 modifying

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, they

Re: search/replace in Python

2005-05-28 Thread Leif K-Brooks
Oliver Andrich wrote: re.sub(rgoogle(.*)/google,ra href=http://www.google.com/search?q=\1\1/a, 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 'a href=%s%s/a' %

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

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 mutable

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)] on

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

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 long

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

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

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 will happen):

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 subprocess import call,

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 code in {}, {}

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

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 Apart from the change in the logic such that the set operation doesn't

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, how

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

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 that it

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

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

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 use dictionary

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

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

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

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

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

  1   2   >