Re: Question on try/except

2006-08-07 Thread Kirk McDonald
t; Is there some particular use in catching an exception and immediately > re-raising it? Why catch it at all? > > /Dan > All I can think of is that it changes the traceback to point to the re-raise and not the original raise. -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: what is the keyword "is" for?

2006-08-15 Thread Kirk McDonald
certain small integers when you might not expect it to; this is done in the interests of efficiency. If you only compare the /values/ of numbers (with ==), then you will never notice this. >>> a = 1 >>> b = 1 >>> c = 100 >>> d = 100 >>> a is b True >>> c is d False -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

TypeCheck vs IsInstance in C API

2006-05-29 Thread Kirk McDonald
can take a tuple as the second argument and check the type of the first argument against every item in the tuple. I also see that TypeCheck was added in version 2.2. Why was it added? Its functionality already seems covered by IsInstance. Is it a new-style vs. old-style class thing? -Kir

API functions not working as expected

2006-06-15 Thread Kirk McDonald
when using this function. Am I missing something here? Is there, in fact, no point to these InPlace* functions? -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Turning a callback function into a generator

2006-07-02 Thread Kirk McDonald
n the callback mechanism. The function is an existing interface, and I cannot change it. I want to somehow, in some way, provide an iteration interface to this function. Thoughts? -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: Turning a callback function into a generator

2006-07-03 Thread Kirk McDonald
[EMAIL PROTECTED] wrote: > Peter Otten wrote: > >>Kirk McDonald wrote: >> >> >>>Let's say I have a function that takes a callback function as a >>>parameter, and uses it to describe an iteration: >>> >>>def func(ca

Re: Turning a callback function into a generator

2006-07-03 Thread Kirk McDonald
Alex Martelli wrote: > Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote: > > >>In article <[EMAIL PROTECTED]>, >> Kirk McDonald <[EMAIL PROTECTED]> wrote: >> >> >>>I want to somehow, in some way, provide an iteration interface to thi

Re: Augument assignment versus regular assignment

2006-07-07 Thread Kirk McDonald
nagy wrote: > I do the following. First create lists x,y,z. Then add an element to x > using the augumented assignment operator. This causes all the other > lists to be changed also. > But if I use the assignment x=x+[4] instead of using the augumented > assignment, the y and z lists do not change.

Re: Augument assignment versus regular assignment

2006-07-08 Thread Kirk McDonald
inding it to the name 'x'. The list [2], previously bound to 'x', is no longer bound to anything, so Python frees it. The augmented assignment, as I went over previously, attempts to modify the list object directly. Any names bound to the object (or any other objects tha

Re: Augument assignment versus regular assignment

2006-07-08 Thread Kirk McDonald
Frank Millman wrote: > nagy wrote: > >>Thanks, Kirk. >>I considered the += as only a shorthand notation for the assignment >>operator. >>Since for lists + is simply a concatetation, I am not sure it x=x+[2] >>is creating a brand >>new list. Could you refer me to any documentation on this? >>Thanks

Returning a value from code string

2006-01-27 Thread Kirk McDonald
t b(n=4) c(arg='foo') # EOF $ python test.py 10 7 arg = foo If I wanted to simplify the 'noreturn' example (well, if there were more lines of code this might make it simpler), I could have defined it like this: noreturn = """\ locals().update(kwargs) print 'arg = %s' % arg""" -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: Returning a value from code string

2006-01-27 Thread Kirk McDonald
Steven D'Aprano wrote: > On Fri, 27 Jan 2006 20:33:53 -0800, Kirk McDonald wrote: > > >> Say I have a database containing chunks of Python code. I already >> have a way to easily load, edit, and save them. > > > Why? I am implementing an Everything Engine-l

Re: Returning a value from code string

2006-01-28 Thread Kirk McDonald
aise an AccessDenied exception and expect something down the line to deal with it, so I can define what the "access denied" node is in a central place, but you get the idea.) If the operation resulted in a new node being created, it might return the new node. &c. Sorry if I tend to ramble, heh. :-) -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: MYSql, CGI web page search code not working

2006-01-28 Thread Kirk McDonald
Fred wrote: > No matter what I type in the form text box (or even if I leave it > blank) I get all the records. Try this: #!/usr/local/bin/python print "Content-Type: text/html\n" import MySQLdb import cgi db=MySQLdb.connect(host = 'localhost', db = 'phone') cursor=db.cursor() cursor.execute("Se

Re: MYSql, CGI web page search code not working

2006-01-28 Thread Kirk McDonald
Fred wrote: > Yeah, I already tried that (except you have a , after name. > > Your code produces the same error: > > NameError: name 'name' is not defined > > I know I am close!! Just missing some small thing... > Oh, duh. I forgot something: #!/usr/local/bin/python print "Content-Type: text

Re: Returning a value from code string

2006-01-28 Thread Kirk McDonald
Max wrote: > Kirk McDonald wrote: > >> Another kind of node (I'm still deciding >> whether to call them Codenodes or Opcodes or maybe Pynodes) is a chunk >> of code that can be asked to run itself, and which can be edited, on >> the fly, from within the we

Re: MYSql, CGI web page search code not working

2006-01-28 Thread Kirk McDonald
ot;Select * from phone where name like %%s% order by > name", > (form['name'].value,)) > > But it blows up... > This should work: cursor.execute("Select * from phone where name like %s order by name", ('%'+form['name'].value+'%',)) -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: MYSql, CGI web page search code not working

2006-01-28 Thread Kirk McDonald
Dennis Lee Bieber wrote: > On Sat, 28 Jan 2006 10:14:44 -0800, Kirk McDonald <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > > >>The comma is intentional: the MySQLdb wants the argument(s) as a tuple. > > > The DB-API wants

Re: String Manipulation Help!

2006-01-28 Thread Kirk McDonald
s[i] == '\n': nl.append(i) return tuple(nl) Your example returns: (0, 64, 65, 80, 81) This probably isn't as fast as a regex, but at least it works. -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: Decoupling the version of the file from the name of the module.

2006-01-28 Thread Kirk McDonald
up your old versions to other filenames or something. Or, if you really want to do this right, you could install Subversion. :-) -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: Decoupling the version of the file from the name of the module.

2006-01-28 Thread Kirk McDonald
new version, then rename the current circle.py as circle-1.1.py, and lather, rinse, repeat. However, I'd still look into a version control system like Subversion. It can do all of this for you. -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: Returning a value from code string

2006-01-29 Thread Kirk McDonald
back to the database-stored PSP document in which the form was found (if the form wants it to), letting the PSP document deal with it. That should be adequate. In short, I learned something about exec and namespaces that I'm not actually going to use. Hooray! -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: Storing lines from a text file

2006-01-29 Thread Kirk McDonald
g/doc/2.4.2/tut/node5.html#SECTION005140000 -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: Storing lines from a text file

2006-01-29 Thread Kirk McDonald
t; You're thinking too hard. Say you want to read in all the lines from the file object f and just print them out one at a time: lines = f.getlines() for line in lines: print line Simple. -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: Storing lines from a text file

2006-01-29 Thread Kirk McDonald
; > When I debug it the error I get is the following: >AttributeError: 'file' object has no attribute 'getlines' > D'oh! That's because the method is readlines(). Stupid brain: log = open('C:\log_0.txt') lines = log.readlines() for li

URL Character Decoding

2006-01-29 Thread Kirk McDonald
ely used to them. This is clearer to me, at least.) I guess what I'm asking is: Is there a library function (in Python or mod_python) that knows how to do this? Or, failing that, is there a different regex I could use to get rid of the substitution function? -Kirk McDonald -- http://mail.pyth

Re: URL Character Decoding

2006-01-29 Thread Kirk McDonald
Kirk McDonald wrote: > If you have a link such as, e.g.: > > Main menu! > > The space will be translated to the character code '%20' when you later > retrieve the GET data. Not knowing if there was a library function that > would convert these back to their actu

Re: URL Character Decoding

2006-01-29 Thread Kirk McDonald
Kirk McDonald wrote: > Actually, I just noticed this doesn't really work at all. The URL > character codes are in hex, so not only does the regex not match what it > should, but sub_func fails miserably. See why I wanted a library function? > > -Kirk McDonald Not to keep ta

Re: URL Character Decoding

2006-01-29 Thread Kirk McDonald
Paul McGuire wrote: > "Kirk McDonald" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>If you have a link such as, e.g.: >> >>Main menu! >> >>The space will be translated to the character code '%20' when you later &

Introspection with classes

2006-01-31 Thread Kirk McDonald
f the User class wanted its own attributes (say, a password), they would just get added to the end. This is my third stab at the problem (the first was mentioned above, the second was basically the same as this but dbInfo was an instance variable instead of a class variable which, uh, w

Re: OO conventions

2006-02-01 Thread Kirk McDonald
e() image.close() And, in addition, there would be an image.open() method. In the above, __init__ just calls it on its own when the filename is specified. (Though, of course, I'm not at all familiar with the PIL module; there might be more stuff going on behind the scenes with the way they do it.) -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: cgi - secure sessions

2006-02-01 Thread Kirk McDonald
_python supports sessions: http://www.modpython.org/live/current/doc-html/pyapi-sess.html I've been playing with them recently, and they seem to work. :-) -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: cgi - secure sessions

2006-02-01 Thread Kirk McDonald
on has a built-in Cookie module: http://www.python.org/doc/2.4.2/lib/module-Cookie.html It may simplify matters. -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: nDimensional sparse histogram in python.

2006-02-01 Thread Kirk McDonald
le code: sortedList = [(v, k) for k, v in self.histo.items()] sortedList.sort() Should do it... -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: nDimensional sparse histogram in python.

2006-02-01 Thread Kirk McDonald
sto = {} def update(self, point): self.histo[point] = self.histo.get(point, 0) + 1 def get(self, point): return self.histo.get(point, 0) dict.get's default return value is your friend. -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: nDimensional sparse histogram in python.

2006-02-01 Thread Kirk McDonald
is actually unordered; a C++ std::map this ain't. To sort its elements, you need to build a list of the items and sort that, e.g.: items = [(v, k) for k, v in self.histo.items()] items.sort() This will give you a list of (value, key) tuples sorted by value. -Kirk McDonald -- http://mai

Re: Automatic class attribute

2006-02-03 Thread Kirk McDonald
them ? > Thanks a lot, > Franck By an astounding coincidence, I was just working on a similar problem. Metaclasses can do this, no problem: class M(type): def __init__(cls, name, bases, dict): cls.observers = [] def showObservers(cls): print cls.observers

Re: Global variables, Classes, inheritance

2006-02-03 Thread Kirk McDonald
able. > class Foo: > def __init(self): > i = 12345 > ... > (You forgot the trailing __, but whatever. :-) This binds the name 'i' to the local namespace of the __init__ function. It is just like any other local variable in a function. Namespaces in Python are really great. It is worth reading up on globals() and locals() if you don't get them yet. -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: python's library support

2006-02-03 Thread Kirk McDonald
software_hardware/numarray The standard library can do quite a lot, and if it fails you, there's more than likely a third-party library available. -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: UnboundMethodType and MethodType

2006-02-07 Thread Kirk McDonald
>>> b.bar > >>> type(b.bar) >>> id(B.bar) -1211888788 >>> id(b.bar) -1211888788 It's the same function, whether it's bound or not. Thus, it should always have the same type. It's simply called in different ways. You can just as easily say: >>> B.bar(b) As: >>> b.bar() -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: UnboundMethodType and MethodType

2006-02-08 Thread Kirk McDonald
is is tricky stuff, nobody should expect to understand > it thoroughly without both study and testing. > > --Scott David Daniels > [EMAIL PROTECTED] You know what? That makes perfect sense. Thank you. -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: calculating on matrix indices

2006-02-17 Thread Kirk McDonald
the line where you assign t to: t = arange(0, 20, .1, 'f') I'm not sure why it doesn't figure that own on its own (since it obviously does hold floats), but this does cause it to work. -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: embedding python in HTML

2006-02-17 Thread Kirk McDonald
John Salerno wrote: > bruno at modulix wrote: > >> You've got to understand that Python is *not* a 'ServerPage' language >> (-> php, asp, jsp etc) in itself. Your server can now run python, fine, >> but *how* ? CGI ? FastCGI ? mod_python ? other ? (hint: it's probably >> just plain old CGI...) >

Re: 2-dimensional data structures

2006-02-18 Thread Kirk McDonald
mproved, such as using the // floor division operator rather than /, not using global variables, and so on. What can I say? It was a straight conversion from C++. I hardly knew what "Pythonic" meant.) -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list

Re: setting file permissions on a web server

2006-04-30 Thread Kirk McDonald
scendants don't have permissions any more than DOS does. (Except with respect to Windows network file-sharing.) (Heh, I checked just before posting this and someone beat me to it. Here's my post anyway.) :-) -Kirk McDonald -- http://mail.python.org/mailman/listinfo/python-list