Re: Python C Object Comparison

2005-01-07 Thread Anand K Rayudu
r the suggestion Regards, Anand Craig Ringer wrote: On Thu, 2005-01-06 at 18:34, Anand K Rayudu wrote: Here is my python code import myModule a=myModule.myAPI1("1") b=myModule.myAPI2("name") # basically both above functions return same C pointer. # so i want t

Re: Datetime module

2005-01-09 Thread Binu K S
The time module will do. >>> import time >>> time.ctime() 'Mon Jan 10 11:17:54 2005' Use strftime if you need to format the time differently. >>> time.strftime("%Y-%m-%d %H:%m:%S",time.localtime()) '2005-01-10 11:01:45' On 9 Jan 2005 21:46:12 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >

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

ANN: Leo 4.3-a1 released

2005-01-24 Thread Edward K. Ream
cOs X. Links: -- Leo: http://webpages.charter.net/edreamleo/front.html Home: http://sourceforge.net/projects/leo/ Download: http://sourceforge.net/project/showfiles.php?group_id=3458 CVS: http://sourceforge.net/cvs/?group_id=3458 Quotes: http://webpages.charter.net/edreamleo/test

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

Leo 4.3.1 released

2005-06-21 Thread Edward K. Ream
http://sourceforge.net/projects/leo/ Download: http://sourceforge.net/project/showfiles.php?group_id=3458 CVS: http://sourceforge.net/cvs/?group_id=3458 Quotes: http://webpages.charter.net/edreamleo/testimonials.html -----

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: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code

2005-07-02 Thread Gregory K. Johnson
articular function called __init__()? That seems more un-Pythonic to me than straightforward, idiomatic, but somewhat verbose boilerplate. An adoptargs([excluded=None]) builtin or similar seems much more viable. (Although even there I don't feel any pressing need: I'm content with "self.x = x".) -- Gregory K. Johnson -- http://mail.python.org/mailman/listinfo/python-list

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: Email client in Pyhton

2005-08-26 Thread Gregory K. Johnson
tudent. :-) The OP may be interested in the project Web site, with documentation and a pointer to the source in Python CVS: http://gkj.freeshell.org/soc/ -- Gregory K. Johnson -- http://mail.python.org/mailman/listinfo/python-list

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

New docs for Leo

2005-09-09 Thread Edward K. Ream
/forum.php?forum_id=10226 Edward Edward K. Ream email: [EMAIL PROTECTED] Leo: http://webpages.charter.net/edreamleo/front.html -- http://mail.python.org

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

ANN: Leo 4.3.2 beta 1

2005-09-12 Thread Edward K. Ream
t3 see: http://webpages.charter.net/edreamleo/rstplugin3.html - The spellpyx (spell checking) plugin is now much easier to use. - The vim and openWith plugins now use Python's subprocess module if it is present. - Improved the Pretty Printing command. - The usual assortment of bug fix

Re: Sorting Unix mailboxes

2005-09-15 Thread Gregory K. Johnson
. Until then, you could get the module from Python CVS, under nondist/sandbox/mailbox. More info is on the project Web site: http://gkj.freeshell.org/soc/ -- Gregory K. Johnson -- http://mail.python.org/mailman/listinfo/python-list

ANN: Leo 4.3.3 released

2005-09-21 Thread Edward K. Ream
nt. - Improved the Pretty Printing command. - The usual assortment of bug fixes. Edward ---- Edward K. Ream email: [EMAIL PROTECTED] Leo: http://webpages.charter.net/e

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

ANN: Leo 4.3-a3 Outlining IDE

2005-02-25 Thread Edward K. Ream
Links: -- Leo: http://webpages.charter.net/edreamleo/front.html Home: http://sourceforge.net/projects/leo/ Download: http://sourceforge.net/project/showfiles.php?group_id=3458 CVS: http://sourceforge.net/cvs/?group_id=3458 Quotes: http://webpages.charter.net/edreamleo/tes

Re: Leo 4.3-a3 Outlining IDE

2005-02-25 Thread Edward K. Ream
I really only posted this once to comp.lang.python. The duplicate appears to be the work of the Department of Redundancy Department. Edward Edward K. Ream email: [EMAIL PROTECTED] Leo: Literate Editor with Outlines Leo

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

2004-12-12 Thread Binu K S
If you are used to the C kind of for loops, avoid mistakes like this one: >>> for i in range(1,6): ... print i ... i+=2 ... 1 2 3 4 5 Obvious if you know you are iterating over a sequence. -- http://mail.python.org/mailman/listinfo/python-list

Re: Path problem

2004-12-12 Thread Binu K S
THONPATH." -Binu On Mon, 13 Dec 2004 18:03:30 +1100, Lars Yencken <[EMAIL PROTECTED]> wrote: > Hi Binu, > > On 13/12/2004, at 4:11 PM, Binu K S wrote: > > This should get you the module's path: > > > > import sys > > sys.modules['rpy']._

Re: Regular Expression

2004-12-14 Thread Binu K S
You can do this without regular expressions if you like >>> uptime='12:12:05 up 21 days, 16:31, 10 users, load average: 0.01, 0.02, 0.04' >>> load = uptime[uptime.find('load average:'):] >>> load 'load average: 0.01, 0.02, 0.04' >>> load = load.split(':') >>> load ['load average', ' 0.01, 0.02,

Re: spawn* or exec* and fork, what should I use and how ?

2004-12-15 Thread Binu K S
exec calls will replace the script process with the new process. >From the execv documentation: "These functions all execute a new program, replacing the current process; they do not return. On Unix, the new executable is loaded into the current process, and will have the same process ID as the ca

Re: ftp

2004-12-15 Thread Binu K S
Try retrbinary instead of retrlines in the original script (the one without write('\n')). retrlines fetches the file in ASCII mode and that must be altering the line terminations. On 15 Dec 2004 15:49:31 -0800, hawkmoon269 <[EMAIL PROTECTED]> wrote: > I would like to write a small ftp script that

Re: temp file name

2004-12-16 Thread Binu K S
Use the tempfile module instead. It is more secure. Check the documentation for tempfile.NamedTemporaryFile. If you are only looking to get a unique name and want to do the file management yourself, you may have to close the file opened by this function and reopen it. On Fri, 17 Dec 2004 17:21:53

Re: Avaliable free modules

2004-12-16 Thread Binu K S
Vaults of Parnassus: http://www.vex.net/parnassus/ On Thu, 16 Dec 2004 18:56:09 +0800, sam <[EMAIL PROTECTED]> wrote: > Hi group, > > Is there any site like cpan.org for python? > > Thanks > Sam > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listi

Re: Path problem

2004-12-12 Thread Binu K S
This should get you the module's path: import sys sys.modules['rpy'].__file__ On Mon, 13 Dec 2004 15:48:29 +1100, Lars Yencken <[EMAIL PROTECTED]> wrote: > Hello, > > I'm working on a project where my python modules are using persistent > files in the same directory. As an example, we're using r

Re: How do I convert characters into integers?

2004-12-15 Thread Binu K S
On Wed, 15 Dec 2004 23:59:13 -0500, Adam DePrince <[EMAIL PROTECTED]> wrote: > > message = [chr( (ord( x ) + 3 )%256) for x in message] > Minor correction: message = ''.join([chr( (ord( x ) + 3 )%256) for x in message]) -- 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 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

When was extended call syntax introduced?

2004-12-21 Thread Edward K. Ream
7;s new in Python' or the pep's has turned up this information. Thanks. Edward ---- Edward K. Ream email: [EMAIL PROTECTED] Leo: Literate Editor with Outlines Leo: http://webpages.charter.net/

Re: word to digit module

2004-12-21 Thread Binu K S
You'll find a script here: http://www.python.org/pycon/dc2004/papers/42/ex1-C/ Found it in the miscellany section at http://www.vex.net/parnassus/ (num2eng) On Wed, 22 Dec 2004 10:27:16 +0530, Gurpreet Sachdeva <[EMAIL PROTECTED]> wrote: > Is there any module available that converts word like 'one

Re: word to digit module

2004-12-21 Thread Binu K S
Oops! That just does the opposite of what you want. I guess you can tinker it a bit to do the reverse conversion unless someone suggests a better module. On Wed, 22 Dec 2004 10:41:46 +0530, Binu K S <[EMAIL PROTECTED]> wrote: > You'll find a script here: > http://www.python

Re: When was extended call syntax introduced?

2004-12-22 Thread Edward K. Ream
> > That was in Python 2.0, see Thanks very much, Martin. -- http://mail.python.org/mailman/listinfo/python-list

Re: String backslash characters

2004-12-23 Thread Binu K S
'\378' becomes a two character string. The first character is '\37' and the second character is '8'. >>> str = '\378' >>> str[0] '\x1f' >>> str[1] '8' >>> On 23 Dec 2004 20:53:13 -0800, PD <[EMAIL PROTECTED]> wrote: > Hello, > > I am new to python, but i am quite curious about the following. >

Re: Global variables and modules

2004-12-23 Thread Binu K S
Add these lines to test1.py and see what you get: import test2 print 'test2.glbl postinc ', test2.glbl This will work as you expect. Next try chaning glbl in test2 to a list (a mutable type). test2.py: glbl = [25] def inc_glbl(): global glbl glbl[0] = glbl[0] + 1 def get_glb

Re: String backslash characters

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

Re: Convert all images to JPEG

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

<    1   2   3   4   5   6   7   8   >