italy wrote:
Why doesn't this statement execute in Python:
1 == not 0
I get a syntax error, but I don't know why.
Because == has higher precedence than 'not', so you are asking for
(1 == not) 0
Try
>>> 1 == (not 0)
True
Kent
Thanks,
Adam Roan
--
http://mail.python.org/mailman/listinfo/python-list
So you should have
self.a = second(self.a)(self.a)
The self.a parameter passed to second is never used. If you change
second.__init__ to
def __init__(self):
pass
then the call in update() will be
self.a = second()(self.a)
Kent
print 'afterwards, a is'
Patrick Useldinger wrote:
The short answer is to use the global statement:
globe=0
def myFun():
global globe
globe=globe+1
return globe
more elegant is:
globe=0
globe=myfun(globe)
def myFun(var):
return var+1
This mystifies me. What is myfun()? What is var intended to be?
Kent
--
http
Patrick Useldinger wrote:
Kent Johnson wrote:
globe=0
globe=myfun(globe)
def myFun(var):
return var+1
This mystifies me. What is myfun()? What is var intended to be?
myfun is an error ;-) should be myFun, of course.
var is parameter of function myFun. If you call myFun with variable
globe
ecorate pattern allows me to replace the "key"
option, I
do not see an obvious way to have heapq work in a reverse way without
making
assumptions on the data.
heapq.nlargest()
heapq.nsmallest()
?
Python 2.4 only
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Stefan Behnel wrote:
Kent Johnson wrote:
heapq.nlargest()
heapq.nsmallest()
On second thought, that doesn't actually get me very far. I do not know
in advance how many I must select since I need to remove duplicates
*after* sorting (they are not necessarily 'duplicate' enough to
he machines that I may use has 80G RAM.
So, using a dictionary will not help.
There was a thread a while ago about choosing random lines from a file without reading the whole
file into memory. Would that help? Instead of shuffling the file, shuffle the users. I can't find
the thread though...
'', output_fn=output):
output_fn(output=output)
Kent
--
http://mail.python.org/mailman/listinfo/python-list
c, d):
somefile2.base.__init__(self, a, b, c, d)
Kent
I know about module imports and reloads, but am not sure if this is the
right
way to go. Mainly, I want to assign to multiple object instances some
self bound
variables. Their values will be different, so I can't use global variables.
Mart
ass:
def set_them(self):
somefile.set_them(self)
Kent
--
http://mail.python.org/mailman/listinfo/python-list
kbook already.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
"Easy user
authentication and user login handling."
http://snakelets.sourceforge.net/
CherryPy is "a pythonic, object-oriented web development framework" that seems to be popular. A
recipe for password-protected pages in CherryPy is here:
http://www.cherrypy.org/wiki/Passwo
ou can get this to work I'm sure we can find other applications for such
'smart code' :-)
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Charles Hartman wrote:
I'm still shaky on some of sre's syntax. Here's the task: I've got
strings (never longer than about a dozen characters) that are guaranteed
to be made only of characters 'x' and '/'. In each string I want to find
the longest continuous stretch of pairs whose first characte
aster.bind('',self.quit)
def quit(self, event):
Frame.quit(self)
root=Tk()
app = Application(root)
app.mainloop()
Kent
This is the code that I used
-
from Tkinter import *
class Application(Frame):
def createWidgets(self):
s
52 or whatever, but not ascii). This means that print '£' works
fine, yet unicode('£') will raise the UnicodeDecodeError.
This uses sys.defaultencoding
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Rob Cranfill wrote:
[BTW, has anyone else noticed that RotatingFileHandler isn't documented
in the docs? All the other file handlers have at least a paragraph on
their options, but nothing for RFH!]
It is in the latest docs.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ould be an anonymous inner class programming to an interface. It's like Java in that it uses
five lines of code to do what Python can do in one.
Do you really prefer this verbosity to a lambda expression? Yikes!
Kent
--
http://mail.python.org/mailman/listinfo/python-list
that seems reasonable :-)
For example with this code:
def genpassenger(num):
for i in range(num):
passenger().start()
class passenger(threading.Thread):
def run:
#do something
will all the passenger threads run to completion, then be GCed?
Thanks,
Kent
--
opinion on that point.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Something like
re.sub(r'^([A-Z])', r'~\1', target)
should do it.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
eed to check for an existing set being a
subset of the set you are adding. A better test case is
s1=set(['a','b','c'])
s2=set(['a','c'])
s3=set(['a','d','e','f'])
s4=set(['r','k','l'
n attacks where MyValue
might contain malicious SQL.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
this style of access. Look at the examples in this
article:
http://www.xml.com/pub/a/2003/12/17/py-xml.html
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ist of macro_hashes, just use
macro_hash["some key"] = "some value"
You lose the order of values but gain much easier lookup.
Alternatively just create a list of (key, value) pairs with
macro_list = []
macro_list.append( ("some key", "some value") )
which preserves the order at the expense of easy random access.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
counting is an obvious use for the first. Consolidating a list of key, value pairs where the
values are ints requires the second.
Combining count() and appendlist() into one function eliminates the second
possibility.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
In my
experience this will be the typical usage:
d.appendlist(key, 'some value')
as opposed to your proposal which has to be written
d.appendlist(key, ['some value'])
The original allows values to be a sequence using
d.appendlist(key, *value_list)
Kent
--
http://mail.py
mplement __getitem__(), which is called with a value that is
constructed from the slice list, as follows."
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Nick Coghlan wrote:
Kent Johnson wrote:
Maybe instead of referring to mappings it should say "The primary must
implement __getitem__(), which is called with a value that is
constructed from the slice list, as follows."
In the section you mention, 'mapping' is equivalent
;> g=Gen()
>>> g.i
0
>>> iter=g()
>>> iter.next()
0
>>> g.i
0
>>> iter.next()
1
>>> g.i
1
HTH
Kent
--
http://mail.python.org/mailman/listinfo/python-list
e specific
email.
If your data is (or can be) created by an iterator, you can use this recipe to group the data into
batches of whatever size you choose and write the individual batches to the db.
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303279
Kent
Thanks,
Kevin
db.exec
(line)
# Yield the last section
yieldSection()
The problem is that yieldSection() now is the generator, and makeSections() is not, and the result
of calling yieldSection() is a new iterator, not the section...
Is there a way to do this or do I have to live with the duplication?
Thanks,
Ke
leases are very helpful.
They link to the PEPs which generally give a lot of detail about a change.
Quite a few recipes were contributed to the online Python Cookbook
demonstrating Python 2.4 features.
Kent
Thanks.
--
http://mail.python.org/mailman/listinfo/python-list
string. If you try it with a list you get a
different result:
>>> s=list('hello')
>>> s
['h', 'e', 'l', 'l', 'o']
>>> m=s[:]
>>> m
['h', 'e', 'l', 'l', 'o']
>>> m is s
False
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Ishwor wrote:
On Sun, 05 Dec 2004 09:44:13 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote:
This behaviour is due to the way strings are handled. In some cases strings are
'interned' which
lets the interpreter keep only a single copy of a string. If you try it with a
list you
ld a cross-reference table before you can use it - and it only finds
implementors, not referrers. It integrates with lots of editors, I have used it with TextPad.
http://ctags.sourceforge.net/
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Andy, this is a nice example. It prompted me to look at the docs for compiler.visitor. The docs are,
um, pretty bad. I'm going to attempt to clean them up a little. Would you mind if I include this
example?
Thanks,
Kent
Andy Gross wrote:
Here's a quick example that will pull out all
SYLLABLE JI
51104 HANGUL SYLLABLE JAM
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Keith Dart wrote:
try:
dict[a].append(b)
except KeyError:
dict[a] = [b]
or my favorite Python shortcut:
dict.setdefault(a, []).append(b)
Kent
--
http://mail.python.org/mailman/listinfo/python-list
"Python> "
You can do the same thing using a PYTHONSTARTUP file - see
http://docs.python.org/tut/node4.html#SECTION00424
You can change the prompts with
import sys
sys.ps1 = ' >>> '
sys.ps2 = ' ... '
Kent
--
http://mail.python.org/mailman/listinfo/python-list
s section seems to have been deleted from the Python 2.4
docs!
http://www.python.org/doc/2.3.4/lib/optparse-extending-examples.html
Kent
--
http://mail.python.org/mailman/listinfo/python-list
re - you have to
use the mouse for copy and paste!!
Kent
--
http://mail.python.org/mailman/listinfo/python-list
th new-
and old-style classes?
Thanks,
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Markus Zeindl wrote:
I have got a string from the user, for example "Hi!".
Now I get every character with a loop:
buffer = ""
for i in range(len(message)):
ch = message[i-1:i]
for ch in message:
...
is simpler and more idiomatic.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
e heavy lifting is done in Java libraries anyway -
primarily Swing, dom4j and Velocity in my case.
The initial import of a module is relatively slow and I often defer importing a module until it is
needed. Other than that I have been pleased with the performance.
Kent
--
http://mail.python.o
to parse a formula(s) and generate a
result ...
Why do you need to parse the formulas at runtime? It sounds like they are known in advance and you
could just write functions to implement the calculations.
Kent
I will look into the pyparsing suggested and maybe even leave out
numarrays for now - as
ozart-oz.org/documentation/apptut/index.html
Kent
--
http://mail.python.org/mailman/listinfo/python-list
site or in the grants-discuss mail list.
Thanks,
Kent
--
http://mail.python.org/mailman/listinfo/python-list
is supposed to do. Another way is to make two factory methods that
create instances of the class and do the correct initialization.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
://infohost.nmt.edu/tcc/help/pubs/tkinter/
Kent
--
http://mail.python.org/mailman/listinfo/python-list
uot;])
-
but this code works?:
-
self.output = []
self.setContentType("text/plain")
print ''.join(self.output)
The above line will create a blank line because of the extra newline from print.
Kent
as
ok "Python Cookbook" as a way to learn the Pythonic view. It
doesn't contrast Python with Java, but it gives many examples of idiomatic Python
Kent
--
http://mail.python.org/mailman/listinfo/python-list
buf1)
return buf1
elif index == 2:
print "Buffer: %s" % (buf2)
return buf2
Kent
--
http://mail.python.org/mailman/listinfo/python-list
$1/g;"?
Just for the record (even though it's not the right solution to your
problem), the Python equivalent is
re.sub('''(['"])''', r'\\\1', s)
Kent
--
http://mail.python.org/mailman/listinfo/python-list
anual alignment issues by preventing code formatters from managing
indentation?
http://www.python.org/doc/faq/general.html#why-does-python-use-indentation-for-grouping-of-statements
>>> from __future__ import braces
File "", line 1
SyntaxError: not a chance
Love it or
ed...
Another solution is to put your config data into some kind of object or structure that you pass
around to anyone who needs it.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ed...
Another solution is to put your config data into some kind of object or structure that you pass
around to anyone who needs it.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
er versions you can define your own:
>>> def rjust(s, l, c):
... return ( c*l + s )[-l:]
...
>>> rjust('3', 3, '0')
'003'
>>> rjust('32', 3, '0')
'032'
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ost authoritative citation I can find is from this page at The Churchill
Centre:
http://www.winstonchurchill.org/i4a/pages/index.cfm?pageid=591
Interestingly, this quote is not on their page of famous quotes:
http://www.winstonchurchill.org/i4a/pages/index.cfm?pageid=388
Kent
--
http://mail.python.org/mailman/listinfo/python-list
he quote on wikiquote, Churchill indicates that the sentiment is not original
with him:
"Indeed, it has been said that democracy is the worst form of government except all those other
forms that have been tried from time to time."
Note the "it has been said"...
Kent
--
http://mail.python.org/mailman/listinfo/python-list
- your sample looks like
utf-8-interpreted-as-latin-1. Try
contents = f.read().decode('utf-8')
Kent
My script was:
import urllib2
req = urllib2.Request(url)
f = urllib2.urlopen(req)
contents = f.read()
print contents
f.close()
Thanks!
Markus
--
http://mail.python.org/mailman/listinfo/python-list
A, you can say
classobj = getattr(ModuleA, classname)
Kent
--
http://mail.python.org/mailman/listinfo/python-list
y experience porting Java to Jython is that it mostly
involves deleting stuff :-)
I hacked together a script that does a lot of the work by applying a bunch of
regex replacements.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Fuzzyman wrote:
Undoubtably Wax :-)
Easier to learn than TKinter, with none of the limitations (it's built
on top of wxPython).
See http://zephyfalcon.org
http://zephyrfalcon.org/labs/wax.html works better.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
meit import Timer
for fn in [withItems, withKeys]:
name = fn.__name__
timer = Timer('%s(d)' % name, 'from __main__ import d, %s' % name)
print name, timer.timeit(1000)
##
I get
withItems 0.980311184801
withKeys 1.37672944466
Kent
--
http://mail.python.org/mailman/listinfo/python-list
uot;
- Open a dos console to the directory containing the cgi-bin directory
- run the command python -c "import CGIHTTPServer; CGIHTTPServer.test()"
(Don't do this with Python 2.4, it is broken - use 2.3 or 2.4.1)
Kent
--
And here is
s can be passed in a cleaner, easier way.
Examples
Using suite-based keyword arguments, the code
f(x = 1)
is equivalent to
f():
x = 1
ISTM the syntax is ambiguous. How do you interpret
if f():
x = 1
?
Is a suite alllowed only when a block could not be introduced in the current
en be able
to store the information in another object.
How should I do that?
You might be interested in this recipe using ElementTree:
http://online.effbot.org/2004_12_01_archive.htm#element-generator
Kent
--
http://mail.python.org/mailman/listinfo/python-list
o code the following, which works fine
for a single byte string. What can I do when I want to look for strings?
Use re.split() instead of str.split(). It uses any regex as the split
string:
>>> import re
>>> test = 'A big Fat CAt'
>>> re.split('[aA]', te
er.)
?? It works for me with triple-single quoted strings...from a quick look it appears that pydoc uses
inspect which looks at the __doc__ attribute; do your modules have __doc__ attributes?
Kent
--
http://mail.python.org/mailman/listinfo/python-list
x27;,
'dddfz']
>>> groupbyPrefix(names, 3)
[['cccat', 'cccap', 'cccan', 'cccbt'], ['ccddd'], ['dddfa', 'dddfg', 'dddfz']]
>>> groupbyPrefix(names, 2)
[['cccat', 'cccap', 'cccan', 'cccbt', 'ccddd'], ['dddfa', 'dddfg', 'dddfz']]
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Uwe Mayer wrote:
Hi,
I've got a ISO 8601 formatted date-time string which I need to read into a
datetime object.
Something like this (adjust the format to suit):
import datetime, time
dt = datetime.datetime(*time.strptime(data, "%Y-%m-%d %H:%M:%S")[:6])
Kent
--
http://mail.pyt
Brian van den Broek wrote:
Kent Johnson said unto the world upon 2005-04-16 16:41:
Brian van den Broek wrote:
I've just spent a frustrating bit of time figuring out why pydoc
didn't extract a description from my module docstrings. Even though I
had a well formed docstring (one line, f
rn l
Is there a more elegant or performant language construct to accomplish
my task?
def getNestedValue(l, indices):
for i in indices:
l = l[i] #In future versions, put error checking here
return l
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Brian van den Broek wrote:
Kent Johnson said unto the world upon 2005-04-17 16:17:
Brian van den Broek wrote:
Kent Johnson said unto the world upon 2005-04-16 16:41:
Brian van den Broek wrote:
I've just spent a frustrating bit of time figuring out why pydoc
didn't extract a descripti
Peter Moscatt wrote:
Is it possible to write code and allow a function to be called within
another like I have shown below ?
Yes, of course. In fact you do it six times in the code below, to call open(), readline(), append(),
close(), main() and populatelist().
Kent
Pete
def populatelist
atafile, 'rb')
data = f.read() # or whatever you need to do to get the actual data into a string
f.close()
req = urllib2.url_open(url, data)
result = req.read()
I get a successful XML response with the following code
Your description of the protocol doesn't say anything about X
inter/
Kent
--
http://mail.python.org/mailman/listinfo/python-list
:-) but it supports many encodings. The list is at
http://docs.python.org/lib/standard-encodings.html
Kent
--
http://mail.python.org/mailman/listinfo/python-list
id', geneid
# Throw away the element, we're done with it
elem.clear()
Kent
--
http://mail.python.org/mailman/listinfo/python-list
(where 'self' is available):
class MyClass:
def __init__(self):
self.list = []
def add(self, x):
self.list.append(x)
Kent
--
http://mail.python.org/mailman/listinfo/python-list
once for each item. The dirnames and filenames lists it yields could be lists of (name,
os.stat(path)) tuples so you would have the sizes available.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Michael Spencer wrote:
Anyway, here are the revised timings...
... print shell.timefunc(func_translate1, "Bob Carol Ted Alice" *
multiplier, 'adB')
What is shell.timefunc?
Thanks,
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Bengt Richter wrote:
The following shows nothing static anywhere, yet a class has been defined, an
instance created, and
__init__ called with initial value, and the value retrieved as an attribute of
the returned instance,
and it's all an expression.
>>> type('C', (), {'__init__': lambda
self,v
Maurice LING wrote:
I am looking for a way to use Jython in Ant build process. I have some
pure Python scripts (not using any C extensions) that I'll like to
incorporate into Java using Jython. I heard that this can be done but
you can I set up Ant to do this? Sorry, I'm no expert with Ant.
The
actually call the above method something like checkDoStuffIsFileTypeQ().
So, the convention I use is
- write assertSomething() primitives that just check a condition
- write checkSomething() methods that do some work and check the result
- build the actual tests using the above
Kent
--
http://ma
thods statically accessible.
One way to do this is to make an EventBus module and make __listeners, register() and fire() be
module attributes. Your client code would look like
import EventBus
...
EventBus.register(...)
EventBus.fire(...)
Kent
--
http://mail.python.org/mailman/listinfo/python-list
obal count
count += 1
label.configure(text=str(count))
# Schedule another callback
root.after(1000, update)
root=Tk()
label=Label(root,text="0")
label.pack()
b=Button(root,text="Bye",command='exit')
b.pack()
# Schedule the initial callback
root.after(1000,
:
... adict.update({num:1})
and
adict[num] = 1
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Python is now enter 2.4 era. It is greate, and I want to upgrade too.
However, everytime upgrading to a new version is a great pain. For
every version, we start to re-install what have been in our past
python.
Re-install all packages sometimes require searching for a new version
of binary which i
)
(2005, 5, 15, 0, 0, 0, 6, 135, -1)
strftime("%Y-%m-%d", _)
'2005-05-15'
or use datetime.date which only needs y, m, d:
>>> from datetime import date
>>> d=date(2005, 5, 15)
>>> d.strftime("%Y-%m-%d")
'2005-05-15'
Kent
--
http://mail.python.org/mailman/listinfo/python-list
act
and your example of what you want to end up with is not too clear either.
If you are having trouble with ElementTree I expect you will be completely lost with SAX,
ElementTree is much easier to work with and cElementTree is very fast.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
write
data.encode('iso8859-2') ?
(Does anyone else feel that python's unicode handling is, well...
suboptimal at least?)
It can be confusing and surprising, yes. Suboptimal...well, I wouldn't want to say that I could do
better...
Kent
--
http://mail.python.org/mailman/listinfo/python-list
atics; yet foo
is a variable, a name bound to a value which can change.
Sounds like you are having a stupid and meaningless argument with your friend. What you call foo
won't change what it is. He should learn Python, then he would understand the true zen of foo.
Kent
--
http://mail.python.o
ons.
If your friend (!) is open-minded enough to learn what the semantics of assignment actually are in
Python then you might be able to have a more productive conversation.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
,c in zip(tup1, tup2, tup3):
...
Kent
--
http://mail.python.org/mailman/listinfo/python-list
p and gen exp:
print [ tuple( (val, t[1]) for t in tt ) for val, tt in zip(vals, tab) ]
Kent
--
http://mail.python.org/mailman/listinfo/python-list
installed, or need both of them?
The end-user needs the JRE, not Python.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ning characters like &= will
cause trouble. So for the link I would use
from ulrlib import quote_plus
link = "" % (quote_plus(str(variable)),
quote_plus(str(variable_name)))
Then you may need urllib.unquote_plus() on the reading end depending on the
server.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
for word in line.split():
if frequency.has_key(word):
frequency[word] += 1
else:
frequency[word] = 1
print len(frequency), 'words'
Kent
--
http://mail.python.org/mailman/listinfo/python-list
201 - 300 of 792 matches
Mail list logo