Re: regular expression problem

2005-05-31 Thread Kent Johnson
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

Re: scripting browsers from Python

2005-05-31 Thread Kent Johnson
> 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

Re: how to prepend string to a string?

2005-05-30 Thread Kent Johnson
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

Re: Is pyunit still usable?

2005-05-30 Thread Kent Johnson
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

Re: write html-headers (utf-8)

2005-05-30 Thread Kent Johnson
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

Re: Help with choice of suitable Architecture

2005-05-28 Thread Kent Johnson
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

Re: using timeit for a function in a class

2005-05-26 Thread Kent Johnson
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

Re: Access from one class to methode of other class

2005-05-26 Thread Kent Johnson
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

Re: searching substrings with interpositions

2005-05-24 Thread Kent Johnson
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

Re: min max of a list

2005-05-06 Thread Kent Johnson
[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

Re: min max of a list

2005-05-06 Thread Kent Johnson
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

Re: Regular Expression tools?

2005-05-04 Thread Kent Johnson
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

Re: xml.parsers.expat and utf-8

2005-05-03 Thread Kent Johnson
[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

Re: xmlrpclib and decoding entity references

2005-05-03 Thread Kent Johnson
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

Re: Inspect Python Classes for instance data information

2005-05-03 Thread Kent Johnson
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

Re: Using wildcards...

2005-05-02 Thread Kent Johnson
>>> 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

Re: compare two voices

2005-05-01 Thread Kent Johnson
is very difficult to create a meaningful score. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Directory in Windows

2005-04-30 Thread Kent Johnson
\AppendTimes.bmp f:/tutor\ArtOfWar.txt etc... http://www.jorendorff.com/articles/python/path/ Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: large dictionary creation takes a LOT of time.

2005-04-30 Thread Kent Johnson
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

Re: large dictionary creation takes a LOT of time.

2005-04-29 Thread Kent Johnson
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

Re: OOP

2005-04-29 Thread Kent Johnson
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

Re: large dictionary creation takes a LOT of time.

2005-04-29 Thread Kent Johnson
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

Re: Problem with sending a variable(python) while using html

2005-04-28 Thread Kent Johnson
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

Re: Can .py be complied?

2005-04-27 Thread Kent Johnson
installed, or need both of them? The end-user needs the JRE, not Python. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Do I need a nested lambda to do this?

2005-04-26 Thread Kent Johnson
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

Re: Multiple tuples for one for statement

2005-04-24 Thread Kent Johnson
,c in zip(tup1, tup2, tup3): ... Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Variables

2005-04-24 Thread Kent Johnson
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

Re: Variables

2005-04-23 Thread Kent Johnson
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

Re: Unicode problems, yet again

2005-04-23 Thread Kent Johnson
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

Re: XML parsing per record

2005-04-23 Thread Kent Johnson
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

Re: time.strftime in 2.4.1 claims data out of range when not

2005-04-22 Thread Kent Johnson
) (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

Smooth upgrade to New Version

2005-04-21 Thread kent sin
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

Re: Dictionary question.

2005-04-21 Thread Kent Johnson
: ... adict.update({num:1}) and adict[num] = 1 Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: A smallish Tkinter question

2005-04-21 Thread Kent Johnson
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,

Re: Private class?

2005-04-21 Thread Kent Johnson
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

Re: Design advice for unit test asserters

2005-04-21 Thread Kent Johnson
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

Re: Using Jython in Ant Build Process

2005-04-21 Thread Kent Johnson
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

Re: Python instances

2005-04-21 Thread Kent Johnson
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

Re: Array of Chars to String

2005-04-20 Thread Kent Johnson
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

Re: Faster os.walk()

2005-04-20 Thread Kent Johnson
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

Re: Python instances

2005-04-20 Thread Kent Johnson
(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

Re: XML parsing per record

2005-04-20 Thread Kent Johnson
id', geneid # Throw away the element, we're done with it elem.clear() Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Encoding Questions

2005-04-19 Thread Kent Johnson
:-) 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

Re: Update Label when Scale value changes

2005-04-19 Thread Kent Johnson
inter/ Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: uploading/streaming a file to a java servlet

2005-04-19 Thread Kent Johnson
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

Re: Can a function be called within a function ?

2005-04-18 Thread Kent Johnson
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

Re: pydoc preference for triple double over triple single quotes--anyreason?

2005-04-18 Thread Kent Johnson
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

Re: Accessing multidimensional lists with an index list

2005-04-17 Thread Kent Johnson
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

Re: pydoc preference for triple double over triple single quotes-- anyreason?

2005-04-17 Thread Kent Johnson
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

Re: sscanf needed

2005-04-17 Thread Kent Johnson
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

Re: Pattern Matching Given # of Characters and no String Input; useRegularExpressions?

2005-04-17 Thread Kent Johnson
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

Re: pydoc preference for triple double over triple single quotes -- anyreason?

2005-04-16 Thread Kent Johnson
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

Re:

2005-04-16 Thread Kent Johnson
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

Re: XML parsing per record

2005-04-16 Thread Kent Johnson
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

Re: pre-PEP: Suite-Based Keywords

2005-04-15 Thread Kent Johnson
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

Re: problem running the cgi module

2005-03-31 Thread Kent Johnson
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

Re: Optimisation Hints (dict processing and strings)

2005-03-30 Thread Kent Johnson
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

Re: What's the best GUI toolkit in Python,Tkinter,wxPython,QT,GTK?

2005-03-30 Thread Kent Johnson
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

Re: Which is easier? Translating from C++ or from Java...

2005-03-28 Thread Kent Johnson
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

Re: newbie question: how to get the class instance given a moduleobject?

2005-03-28 Thread Kent Johnson
A, you can say classobj = getattr(ModuleA, classname) Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Get document as normal text and not as binary data

2005-03-28 Thread Kent Johnson
- 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

Re: Python slogan, was Re: Grouping code by indentation - feature or ******?

2005-03-26 Thread Kent Johnson
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

Re: Python slogan, was Re: Grouping code by indentation - feature or ******?

2005-03-26 Thread Kent Johnson
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

Re: left padding zeroes on a string...

2005-03-25 Thread Kent Johnson
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

Re: breaking up is hard to do

2005-03-25 Thread Kent Johnson
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

Re: breaking up is hard to do

2005-03-25 Thread Kent Johnson
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

Re: Grouping code by indentation - feature or ******?

2005-03-25 Thread Kent Johnson
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

Re: escape single and double quotes

2005-03-24 Thread Kent Johnson
$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

Re: newbie help

2005-03-24 Thread Kent Johnson
buf1) return buf1 elif index == 2: print "Buffer: %s" % (buf2) return buf2 Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Suggestions for a Java programmer

2005-03-24 Thread Kent Johnson
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

Re: string join() method

2005-03-24 Thread Kent Johnson
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

Re: Simple account program

2005-03-24 Thread Kent Johnson
://infohost.nmt.edu/tcc/help/pubs/tkinter/ Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Overloaded Constructors?!?

2005-03-20 Thread Kent Johnson
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

Re: Pre-PEP: Dictionary accumulator methods

2005-03-19 Thread Kent Johnson
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

Re: Pre-PEP: Dictionary accumulator methods

2005-03-19 Thread Kent Johnson
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

Re: create/access dynamic growth list

2005-03-19 Thread Kent Johnson
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

Re: Simple XML-to-Python conversion

2005-03-19 Thread Kent Johnson
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

Re: MySQL problem

2005-03-18 Thread Kent Johnson
n attacks where MyValue might contain malicious SQL. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: list of unique non-subset sets

2005-03-17 Thread Kent Johnson
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'

Re: I can do it in sed...

2005-03-17 Thread Kent Johnson
Something like re.sub(r'^([A-Z])', r'~\1', target) should do it. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Good use for Jython

2005-03-16 Thread Kent Johnson
opinion on that point. Kent -- http://mail.python.org/mailman/listinfo/python-list

When is a thread garbage collected?

2005-03-16 Thread Kent Johnson
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 --

Re: Python becoming less Lisp-like

2005-03-15 Thread Kent Johnson
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

Re: RotatingFileHandler and logging config file

2005-03-15 Thread Kent Johnson
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

Re: Encodings and printing unicode

2005-03-14 Thread Kent Johnson
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

Re: Bind Escape to Exit

2005-03-13 Thread Kent Johnson
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

Re: a RegEx puzzle

2005-03-11 Thread Kent Johnson
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

Re: Is there a short-circuiting dictionary "get" method?

2005-03-09 Thread Kent Johnson
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

Re: Working on a log in script to my webpage

2005-03-09 Thread Kent Johnson
"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

Re: Best way to make a list unique?

2005-03-09 Thread Kent Johnson
kbook already. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: looking for way to include many times some .py code fromanotherpython code

2005-03-08 Thread Kent Johnson
ass: def set_them(self): somefile.set_them(self) Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: looking for way to include many times some .py code from anotherpython code

2005-03-08 Thread Kent Johnson
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

Re: parameter name conflict. How to solve?

2005-03-08 Thread Kent Johnson
'', output_fn=output): output_fn(output=output) Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: shuffle the lines of a large file

2005-03-07 Thread Kent Johnson
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...

Re: reversed heapification?

2005-03-07 Thread Kent Johnson
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

Re: reversed heapification?

2005-03-07 Thread Kent Johnson
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

Re: function with a state

2005-03-06 Thread Kent Johnson
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

Re: function with a state

2005-03-06 Thread Kent Johnson
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

Re: Can a method in one class change an object in another class?

2005-03-06 Thread Kent Johnson
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'

Re: Equality operator

2005-03-05 Thread Kent Johnson
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

<    2   3   4   5   6   7   8   >