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
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
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
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
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
[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
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
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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
g/doc/2.4.2/tut/node5.html#SECTION005140000
-Kirk McDonald
--
http://mail.python.org/mailman/listinfo/python-list
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
;
> 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
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
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
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
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
&
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
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
_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
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
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
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
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
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
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
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
>>> 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
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
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
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...)
>
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
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
45 matches
Mail list logo