ocks()
[(0, 0, 2), (4, 2, 1), (13, 3, 1), (14, 4, 0)]
You should test for len(sm.get_matching_blocks()) == 4 (the last element is a
dummy)
Kent
--
http://mail.python.org/mailman/listinfo/python-list
> Windows, IE can be automated via COM - see
> <http://www.mayukhbose.com/python/IEC/> for example
Also http://pamie.sourceforge.net/
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ormally you get the desired result:
dirList = ['depth1','depth2','depth3']
string = """position"""
for x in dirList:
string += '>> %s'% x
Kent
--
http://mail.python.org/mailman/listinfo/python-list
hive.html
If you mean the practice, Google is your friend. Countless books and articles
have been written
about unit testing.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
trict.dtd";>
>
>
>
If you are using CGI you can set the Content-Type header directly. Before you
output your HTML do
print "Content-Type: text/html; charset=UTF-8"
print # blank line, end of headers
Kent
--
http://mail.python.org/mailman/listinfo/python-list
or a preview of the issues this raises.
http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/475d065fa7871e63/c2fc42fefe114d38?hl=en#c2fc42fefe114d38
Kent
--
http://mail.python.org/mailman/listinfo/python-list
t Timer.timeit() calls the function being timed 100 times.
That's a lot of "hello
time test" =:-)
Kent
--
http://mail.python.org/mailman/listinfo/python-list
text = self.ent.get() # get text form entry in this window
> d.entry.insert(0, text)# must insert in other window
>
> d = First() #First window
The problem is that First.__init__() never returns so the instance of First is
never bound to d.
Take the line
self.root.mainloop()
out of First.__init__() and and the line
d.root.mainloop()
at the end of the program and it will work as you expect.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
oor with
long strings:
>>> import re
>>> re.search('0.*1.*0.*1', '0100')
<_sre.SRE_Match object at 0x008D9BF0>
>>> _.span()
(0, 10)
Put the chars of the search string in groups if you need to know where they
were found.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
> Hi Kent,
> Thanks for that. But We are considering [..., 0, 101, 0, 0, 0, 0, 0] ->
> [13,18] .In fact if you look at the list, the histogram ends at 15 that
> is [0,101,0] --> [13,15]. Dont you think so.
>
Well you consider ..., 0, 4, 9, 2
e = value
# Get the last group if any
if i > startIx:
groups.append( [startIx, i] )
return groups
values = [ 0, 72, 2, 4, 9, 2, 0, 0, 42, 26, 0, 282,
23, 0, 101, 0, 0, 0, 0, 0]
print findPeaks(values)
## prints:
[[0, 2], [2, 7], [7, 10], [10
down the search for me. All I seem to be finding are other
> platforms and/or not standalone.
Maybe you are looking for RegexPlor:
http://python.net/~gherman/RegexPlor.html
Kent
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
> I have this code:
>
> import xml.parsers.expat
> parser = xml.parsers.expat.ParserCreate(encoding="UTF-8")
> text = unicode("þórður",'UTF-8')
I think you want
text = u"þórður".encode('UTF-8')
so
2 l';glise Saint Andr; della Valle' sur le cadre craie noire,
> plume et encre brune, lavis brun rehauss; de blanc sur papier brun
> 190 x 228 mm. (7 1/2 x 9 in.)
>
> Can anyone give me a lead on how to convert the entity references into
> something that will make it thr
Tim Henderson wrote:
> Hello
>
> I want to creat a program that can inspect a set of classes that i have
> made and spit out a savable version of these classes. To do this I need
> to be able to inspect each class and get all of its instance data as
> well as information about a particular meathod
>>> import re
>>> s = '{1:1} Random text here. {1:2} More text here. and so on.'
>>> re.split(r'\{[^}]+\}', s)
['', ' Random text here. ', ' More text here. and so on.']
If you want to be a little stricter in what you a
is very
difficult to create a meaningful score.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
\AppendTimes.bmp
f:/tutor\ArtOfWar.txt
etc...
http://www.jorendorff.com/articles/python/path/
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Maksim Kasimov wrote:
sorry for my question, but i've read the documentation, and can't find
where is the explanation of how it is exactly works (but of course i do
believe you). If it is buit in function, can i see the source code of
the method to find it out?
Kent Johnson w
Maksim Kasimov wrote:
Kent Johnson wrote:
> for line in open(path):
the line of your example raise another question: opened file will be
read at once time, as method readlines() do, or it will be read line by
line as method readline() do.
It will be read line by line as readline() does.
as
ibly put things in focus
for me? Thanks.
You might be interested in this essay which gives some motivation for
simple use of classes:
http://www.pycs.net/users/323/stories/15.html
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
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
installed, or need both of them?
The end-user needs the JRE, not Python.
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
,c in zip(tup1, tup2, tup3):
...
Kent
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
)
(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
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
:
... adict.update({num:1})
and
adict[num] = 1
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,
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
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
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
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
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
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
(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
id', geneid
# Throw away the element, we're done with it
elem.clear()
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
inter/
Kent
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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-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
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
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
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
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
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
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
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
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
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
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
A, you can say
classobj = getattr(ModuleA, classname)
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
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
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
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
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
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
$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
buf1)
return buf1
elif index == 2:
print "Buffer: %s" % (buf2)
return buf2
Kent
--
http://mail.python.org/mailman/listinfo/python-list
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
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
://infohost.nmt.edu/tcc/help/pubs/tkinter/
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
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
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
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
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
n attacks where MyValue
might contain malicious SQL.
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'
Something like
re.sub(r'^([A-Z])', r'~\1', target)
should do it.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
opinion on that point.
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
--
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
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
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
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
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
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
"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
kbook already.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ass:
def set_them(self):
somefile.set_them(self)
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
'', output_fn=output):
output_fn(output=output)
Kent
--
http://mail.python.org/mailman/listinfo/python-list
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...
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
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
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
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
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'
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
601 - 700 of 792 matches
Mail list logo