Re: Announcing: ACM SIGAPL apl 2007 -- Arrays and Objects

2007-05-31 Thread Mike Kent
The APL2007 URL was given incorrectly should be http://www.sigapl.org/apl2007.html -- http://mail.python.org/mailman/listinfo/python-list

Announcing: ACM SIGAPL apl 2007 -- Arrays and Objects

2007-05-27 Thread Mike Kent
de Congres, Montreal, Quebec, CANADA Conference hotel: Hyatt Regency Montreal Committee General Chair Guy Laroque [EMAIL PROTECTED] Program Chair Lynne C. Shaw[EMAIL PROTECTED] Treasurer Steven H. Rogers [EMAIL PROTECTED] Publici

Re: Join strings - very simple Q.

2007-03-23 Thread Mike Kent
On Mar 23, 2:37 pm, Paulo da Silva <[EMAIL PROTECTED]> wrote: > Hi! > > I was told in this NG that string is obsolet. I should use > str methods. > > So, how do I join a list of strings delimited by a given > char, let's say ','? > > Old way: > > l=['a','b','c'] > jl=string.join(l,',') > > New way?

Re: Pickle Problem

2007-03-15 Thread Mike Kent
On Mar 15, 11:13 am, "tonyr1988" <[EMAIL PROTECTED]> wrote: > if __name__=='__main__': > x = DemoClass > x.WriteToFile > You meant to create a DemoClass instance object, but instead, you obtained a reference to the class object. You want 'x = DemoClass()' instead. You meant to ca

Re: doxygen

2007-03-04 Thread Mike Kent
On Mar 4, 1:15 pm, Jan Danielsson <[EMAIL PROTECTED]> wrote: >When I run doxygen on my python files, it does document classes, but > not "standalone" functions. Look in the doxygen config file for your python project, named 'Doxyfile', for the config setting 'EXTRACT_ALL', and read the commen

Re: Is there any way to automatically create a transcript of an interactive Python session?

2007-02-18 Thread Kent Johnson
Jonathan Mark wrote: > Some languages, such as Scheme, permit you to make a transcript of an > interactive console session. Is there a way to do that in Python? > Maybe IPython's logging feature is what you want? http://ipython.scipy.org/doc/manual/node6.html#SECTION00066000

Re: multiple inheritance of a dynamic list of classes?

2007-02-12 Thread Kent Johnson
s: == help that this (Cmd) that That In your code you could use introspection to locate the plugin commands, something like PLUGIN_MODULES = map(__import__, PLUGIN_NAMES) for module in PLUGIN_MODULES: for name in dir(module): if name.startswith('do_')

Re: Array delete

2007-02-08 Thread Kent Johnson
# print the new list where duplicates are removed For longer lists the set() method will probably be faster as this one searches temp for each item. Kent > > def main(): > list, temp = [1, 1, 2, 4, 8, 8, 8, 8, 8, 8, 10], [] > for i in range(len(list)): >

Re: Unicode formatting for Strings

2007-02-05 Thread Kent Johnson
quot;Ataris Aqußticos #2.py", line 1 > SyntaxError: Non-ASCII character '\xff' in file Ataris Aqußticos #2.py > on line 1 It looks like you are saving the file in Unicode format (not utf-8) and Python is choking on the Byte Order Mark that Notepad puts at the beginning of the d

Re: in place-ness of list.append

2007-02-05 Thread Kent Johnson
- Use + : In [1]: a=[1,2] In [2]: b=a+[3] In [3]: a Out[3]: [1, 2] In [4]: b Out[4]: [1, 2, 3] Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Can I undecorate a function?

2007-01-29 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Matt> In some instances I want to access just the function f, though, > Matt> and catch the values before they've been decorated. > > def f(x): > return x * x > > @as_string > def fs(x): > return f(x) or just fs =

Re: Problems with ElementTree and ProcessingInstruction

2007-01-28 Thread Kent Tenney
On Jan 28, 7:46 pm, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > At Sunday 28/1/2007 11:28, Kent Tenney wrote: > > >I want to generate the following file; > > > > > > >stuff > > >How should I be doing this?open("filename","w"

Problems with ElementTree and ProcessingInstruction

2007-01-28 Thread Kent Tenney
Howdy, I want to generate the following file; stuff How should I be doing this? As far as I can tell, ElementTree() requires everything to be inside the root element (leo_file) Thanks, Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Learning Python book, new edition?

2007-01-11 Thread Kent Johnson
2.4 are in it, too. No, it is one version back from that. From the Preface to the second edition: "This edition has been thoroughly updated to reflect Python 2.2...in addition, discussion of anticipated changes in the upcoming 2.3 release have been incorporated." Kent -- http://mail.python.org/mailman/listinfo/python-list

Filename encoding on XP

2007-01-02 Thread kent sin
What encoding does the NTFS store the filename? I got some downloaded files, some with Chinese filename, I can not backup them to CD because the name is not accepted. I use walk, then print the filename, there are some ? in it, but some Chinese characters were display with no problem. I suspect t

Re: Some basic newbie questions...

2007-01-02 Thread Kent Johnson
ds-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list.htm Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Slowdown in Jython

2006-12-29 Thread Kent Johnson
s Task Manager or the equivalent. Jython is a Java application and you can increase the max heap available the same as for other java apps, using the command line switch -Xmx, e.g. -Xmx512m to set the max heap to 512 megabytes. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: One module per class, bad idea?

2006-12-25 Thread Kent Johnson
Carl Banks wrote: > Kent Johnson wrote: >> Carl Banks wrote: >>> Now, I think this is the best way to use modules, but you don't need to >>> use modules to do get higher-level organization; you could use packages >>> instead. It's a pain if you'

Re: One module per class, bad idea?

2006-12-22 Thread Kent Johnson
a module - but in general my major classes are each to a module. It does make the imports look funny - I tend to give the module the same name as the class, Java style, so I have from foo.bar.MyClass import MyClass but that is a minor point IMO. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Common Python Idioms

2006-12-15 Thread Kent Johnson
Fredrik Lundh wrote: > Stephen Eilert wrote: > >> I do think that, if it is faster, Python should translate >> "x.has_key(y)" to "y in x". > > http://svn.python.org/view/sandbox/trunk/2to3/fix_has_key.py?view=markup Seems to have moved to here: http://svn.python.org/view/sandbox/trunk/2to3/fixes

Re: reloading modules

2006-12-15 Thread Kent Johnson
;>> reload(main) > ### Execution Occurs ### If you edit music.py you will have to import music reload(music) to get the new music module, then reload(main) to run again. You could just type > python main.py at the command line each time you want to run, or use an editor that lets you run the program from within the editor. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Functions, callable objects, and bound/unbound methods

2006-12-01 Thread Kent Johnson
gly, and a callable class is the Right Thing -- if there's a > way to actually make it work. If the only reason for a callable class is to save a single value (the original function), you could instead store it as an attribute of the wrapper function. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Functions, callable objects, and bound/unbound methods

2006-12-01 Thread Kent Johnson
gly, and a callable class is the Right Thing -- if there's a > way to actually make it work. If the only reason for a callable class is to save a single value (the original function), you could instead store it as an attribute of the wrapper function. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: a quickie: range - x

2006-11-30 Thread Kent Johnson
Steven D'Aprano wrote: > On Wed, 29 Nov 2006 19:42:16 -0800, rjtucke wrote: > >> I want an iterable from 0 to N except for element m (<=M). > x = range(m-1) + range(m+1, N) Should be range(m) + range(m+1, N) Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: multi split function taking delimiter list

2006-11-14 Thread Kent Johnson
this, preferably without regexp? What do you have against regexp? re.split() does exactly what you want: In [1]: import re In [2]: re.split(r'(:=|\+)', 'a:=b+c') Out[2]: ['a', ':=', 'b', '+', 'c'] Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: conditional computation

2006-10-26 Thread Mike Kent
robert wrote: > I want to use a computation cache scheme like > > > o = CACHECOMPUTE complex-key-expr expensive-calc-expr > > > frequently and elegantly without writing complex-key-expr or > expensive-calc-expr twice. > So its ugly: > > _=complex-key-expr; o=cache.get(_) or > cache

Re: question about True values

2006-10-25 Thread Mike Kent
John Salerno wrote: > I'm a little confused. Why doesn't s evaluate to True in the first part, > but it does in the second? Is the first statement something different? > > >>> s = 'hello' > >>> s == True > False > >>> if s: > print 'hi' > > > hi > >>> > > Thanks. Excellent question!

Re: command text parsing and hints displaying on user input.

2006-10-17 Thread Kent Johnson
. > are being parsed as the same rule so the system will call a later > function with minutes=5 as parameter. Maybe one of these will help: http://cheeseshop.python.org/pypi/parsedatetime/0.7.4 http://cheeseshop.python.org/pypi/when/1 Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: why should dict not be callable?

2006-10-17 Thread Kent Johnson
ke an intermediary function: > > def key_fn(key): >return key_dict[key] Try key=key_dict.__getitem__ In [3]: d=dict(a=1,b=2) In [4]: d.__getitem__('a') Out[4]: 1 Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Book about database application development?

2006-10-17 Thread Kent Johnson
7;s readable for someone who > has learned programming ages ago with Pascal and is now using Python because > he _hates_ everything that remotely ressembles to any mutation of > C(++/#/Java). Examples are mostly Java and C#, sorry! Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: preemptive OOP?

2006-10-04 Thread Kent Johnson
Mark Elston wrote: > * Kent Johnson wrote (on 9/30/2006 2:04 PM): >> John Salerno wrote: >>> So my question in general is, is it a good idea to default to an OOP >>> design like my second example when you aren't even sure you will need >>> it? I know i

Re: preemptive OOP?

2006-09-30 Thread Kent Johnson
so clearly at work the difference between projects that practice YAGNI and those that are designed to meet any possible contingency. It's the difference between running with running shoes on or wet, muddy boots. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: windev vs python SOS

2006-09-29 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Hi Stéphane, > > stéphane bard wrote: >> hello, my boss ask me to prefer windev to python. >> I have to argue > > First, no matter how good is Python, you should not desagree with your > boss. > Second, Windew is quite good and fun, you will love it. Yes, the boss is a

Re: efficient text file search.

2006-09-11 Thread Kent Johnson
noro wrote: > Is there a more efficient method to find a string in a text file then: > > f=file('somefile') > for line in f: > if 'string' in line: > print 'FOUND' Probably better to read the whole file at once if it isn't too big: f = file('somefile') data = f.read() if 'string' in

Re: Looking for the Perfect Editor

2006-09-11 Thread Kent Johnson
Dick Moores wrote: > At 06:30 PM 9/10/2006, Kent Johnson wrote: >> Dick Moores wrote: >>> Also, why do you use TextPad instead of IDLE? >> You're kidding, right? > > No. Tell me, please. Macros? Comparing files? What else? OK...please, no one interpret this as

Re: Looking for the Perfect Editor

2006-09-10 Thread Kent Johnson
ad of IDLE? You're kidding, right? Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking for the Perfect Editor

2006-09-10 Thread Kent Johnson
le Init fldr: $FileDir regex to match output: ^.*"([^"]+)", *line ([0-9]+) with File: 1, Line: 2 Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Python newbie with a problem writing files

2006-09-03 Thread Mike Kent
> feed_list = open("feed_listing.conf","r") What could it be about the above line that means "Open this file for READ ONLY"? -- http://mail.python.org/mailman/listinfo/python-list

Status of Epydoc

2006-08-09 Thread Kent Tenney
ydoc 3.0 development? Thanks, Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: newb question: file searching

2006-08-08 Thread Mike Kent
[EMAIL PROTECTED] wrote: > I'm new at Python and I need a little advice. Part of the script I'm > trying to write needs to be aware of all the files of a certain > extension in the script's path and all sub-directories. What you want is os.walk(). http://www.python.org/doc/current/lib/os-file-d

Re: Finding the name of a class

2006-08-02 Thread Kent Johnson
om Daycos.TableCopier.copyfro import StateProcessor >>>> print StateProcessor.__class__.__name__ > type > > I'm looking for something that would print 'StateProcessor' but am not > having much luck. It looks like StateProcessor is a class; StateProcessor

Re: Process files in order

2006-07-27 Thread Mike Kent
How about using os.listdir to build a list of filenames, then sorting them by modification time (via os.stat)? -- http://mail.python.org/mailman/listinfo/python-list

Re: How to automate user input at the command prompt?

2006-07-21 Thread Mike Kent
[EMAIL PROTECTED] wrote: > You may want to look at pexpect: > > http://pexpect.sourceforge.net/ > > But I am not sure about its support on windows. To the best of my recent investigation, and an email exchange with the author of pexpect, it is NOT supported under Windows. -- http://mail.python.

Python proficiency test

2006-07-21 Thread Kent Johnson
o your feedback! > > Feel free to pass this along to your friends. > > Thanks in advance for your help and good luck! Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Multiplatform scripts: Can I avoid os.sep?

2006-07-13 Thread Mike Kent
gmax2006 wrote: > Hi, > > I am developing scripts that must run on both Linux and windows. > > My scripts contain lots of relative paths (such as log\\log.txt or > ctl\\table.ctl) If I use os.sep, it makes the code ugly. Is there any > tips or techniques to have Python automatically converts \\ to

Re: Advice for Python Reporting Tool

2006-07-12 Thread Mike Kent
rwboley wrote: > My question is: how can I make that graphing step easier? Ideally I'd > like the chart to exist on it's own page, but I have no idea where to > even begin to implement this. Any thoughts would be appreciated. I've seen several people recommend matplotlib for this kind of thing.

Re: 2 problems

2006-07-07 Thread Mike Kent
[EMAIL PROTECTED] wrote: > Hello,Im using Python 2.4.2 and I'm starting a few very basic > programs,but theres two problems I've not found the answers for. > My first problem is I need code that will count the number of letters > in a string and return that number to a variable. >>> s = "hello" >

Re: Easier way to save result of a function?

2006-07-04 Thread Mike Kent
James Mitchelhill wrote: > Sorry for the clunky subject line - I have a feeling that not knowing > the proper terms for this is part of my problem. > > I'm trying to write a class that analyses some data. I only want it to > do as much work as necessary, so it saves method results to a > dictionary

Re: List Manipulation

2006-07-04 Thread Mike Kent
Roman wrote: > Thanks for your help > > My intention is to create matrix based on parsed csv file. So, I would > like to have a list of columns (which are also lists). > > I have made the following changes and it still doesn't work. > > > cnt = 0 > p=[[], [], [], [], [], [], [], [], [], [], []] >

Re: List Manipulation

2006-07-04 Thread Mike Kent
Roman wrote: > I would appreciate it if somebody could tell me where I went wrong in > the following snipet: > > When I run I get no result > > cnt = 0 > p=[] > reader = csv.reader(file("f:\webserver\inp.txt"), dialect="excel", > quotechar="'", delimiter='\t') > for line in

Re: Standard Yes / No Windows Dialog box creation

2006-06-21 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > I found a way to create "Open File" or "Open Folder" windows dialog > boxes, but not to create an easier Yes / No dialog box... > Maybe someone has a solution for this? Maybe you would like EasyGui http://www.ferg.org/easygui/ Kent -- h

Re: unittest behaving oddly

2006-06-20 Thread Mike Kent
David Vincent wrote: > > import unittest > > > > class IntegerArithmenticTestCase(unittest.TestCase): > > def testAdd(self): ## test method names begin 'test*' > > assertEquals((1 + 2), 3) > > assertEquals(0 + 1, 1) assertEquals is a member function, inherited from unittest.T

Re: nested functions

2006-06-15 Thread Kent Johnson
FAST 0 (h) 12 RETURN_VALUE Thanks Fredrik! Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a better way of accessing functions in a module?

2006-06-13 Thread Kent Johnson
. Found the globals() built-in... You can also import __main__ tests = [x for x in dir(__main__) if x.endswith("test")] for test in tests: getattr(__main__, test)() but I second the suggestion of looking in to unittest or one of the other test frameworks. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a better way of accessing functions in a module?

2006-06-13 Thread Mike Kent
Yes, you can go that route. But since it appears that what you are doing is unit testing related, and you are interested in aranging for all of your unit test cases to be run automatically, I'd suggest using the unittest module. -- http://mail.python.org/mailman/listinfo/python-list

Re: Searching and manipulating lists of tuples

2006-06-12 Thread Mike Kent
MTD wrote: > Hello, > > I'm wondering if there's a quick way of resolving this problem. > > In a program, I have a list of tuples of form (str,int), where int is a > count of how often str occurs ... > So clearly that doesn't work... any ideas? Yes, use the proper tool for the job. Tuples are

Re: regexp questoin

2006-06-09 Thread Kent Johnson
gexp > compilation where input is unknown...? Maybe you want pat = re.compile(re.escape(userinput)) Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: secure xmlrpc server?

2006-06-09 Thread Kent Johnson
Kent Johnson wrote: > Laszlo Nagy wrote: >> But I do not know how to create an XML RPC server in Python that uses >> HTTPS for XML transports. > > This recent recipe seems to do exactly what you want: > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496786 It w

Re: secure xmlrpc server?

2006-06-09 Thread Kent Johnson
Laszlo Nagy wrote: > But I do not know how to create an XML RPC server in Python that uses > HTTPS for XML transports. This recent recipe seems to do exactly what you want: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496786 Kent -- http://mail.python.org/mailman/listinfo/

Re: Storing nothing in a dictionary and passing it to a function

2006-06-05 Thread Kent Johnson
try args = (name,) + params['args'] except KeyError: args = () params['func'](*args) Or include the 'name' parameter in the arg list and use an empty tuple for the arg to pwldef: 'exp' : {'func': self.arbtrandef, 'args':('exp', 2,4)},\ 'pwl' : {'func': self.pwldef, 'args': ()},\ for name, params in alldict.items(): params['func'](*args) Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: PQRC - Python Quick Reference Card - v 0.55

2006-06-04 Thread Kent Johnson
Laurent Pointal wrote: > And I'll maintain a fixed URL at > > http://laurent.pointal.org/python/pqrc/ Broken at the moment. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: [ANN] lxml 1.0 released

2006-06-02 Thread Kent Johnson
Stefan Behnel wrote: > Hallo everyone, > > I have the honour to announce the availability of lxml 1.0. > > http://codespeak.net/lxml/ > > It's downloadable from cheeseshop: > http://cheeseshop.python.org/pypi/lxml Are there any plans to offer a Windows inst

Re: Python for Visual Basic or C# programmers

2006-06-01 Thread Kent Johnson
ncs.html Also take a look at the section on string methods: http://docs.python.org/lib/string-methods.html Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: An oddity in list comparison and element assignment

2006-06-01 Thread Kent Johnson
[3]: a==b Out[3]: True In [4]: a/2 == b/2 Out[4]: False Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: os.walk trouble

2006-06-01 Thread Kent Johnson
kfiles('*.foo'): # process a .foo file here http://www.jorendorff.com/articles/python/path/index.html Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: problem with google api / xml

2006-05-31 Thread Mike Kent
robin wrote: > from SOAPpy import WSDL > WSDLFILE = '/pathtomy/googleapi/GoogleSearch.wsdl' > APIKEY = '' > _server = WSDL.Proxy(WSDLFILE) Robin, note this part of the URI set in WSDLFILE: '/pathtomy/googleapi'. Get it? 'path to my google api'. You must set this part to the actual path wh

Re: genexp performance problem?

2006-05-30 Thread Kent Johnson
; The generator comprehension needs to create a new generator each time > around. Reusing the generator doesn't give a correct answer; after the first sum() the generator is exhausted: In [1]: g=(int(L) for L in xrange(10)) In [2]: sum(g) Out[2]: 45 In [3]: sum(g) Out[3]: 0 Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Parsing python dictionary in Java using JPython

2006-05-26 Thread Kent Johnson
existing dictionaries only using JPython libraries. How do you access the dictionary files from Python? The same thing may work in Jython. For example importing the file, if it is Python syntax, should work in Jython; also I think format 0 (text) and format 1 pickles are compatible with Jython. Kent

Re: Speed up this code?

2006-05-26 Thread Kent Johnson
for membership in a set is much faster than searching a large list. - Find a better algorithm ;) Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Anyone compiling Python 2.3 on an SCO OpenServer 5 box?

2006-05-25 Thread Mike Kent
I need to compile Python on OpenServer 5 because I need to 'freeze' our Python app, and running 'freeze' requires a working, compilable source installation of Python. -- http://mail.python.org/mailman/listinfo/python-list

Anyone compiling Python 2.3 on an SCO OpenServer 5 box?

2006-05-25 Thread Mike Kent
If anyone is successfully compiling Pyton 2.3 on an SCO OpenServer 5 box, I'd appreciate hearing from you on how you managed to do it. So far, I'm unable to get a python that doesn't coredump. -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to handle exceptions with try/finally

2006-05-25 Thread Kent Johnson
Zameer wrote: > I wonder where the "else" goes in try..except..finally... > try / except / else / finally See the PEP: http://www.python.org/dev/peps/pep-0341/ Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding Upper-case characters in regexps, unicode friendly.

2006-05-25 Thread Kent Johnson
er instead of just the typical [A-Z], > which doesn't include, for example É. Is there a way to do this, or > do I have to stick with using the isupper method of the string class? > See http://tinyurl.com/7jqgt Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: NEWB: how to convert a string to dict (dictionary)

2006-05-24 Thread Kent Johnson
manstey wrote: > Hi, > > How do I convert a string like: > a="{'syllable': u'cv-i b.v^ y^-f', 'ketiv-qere': 'n', 'wordWTS': u'8'}" > > into a dictionary: > b={'syllable': u'cv-i b.v^ y^-f', 'ketiv-qere': 'n', 'wordWTS': u'8'} Try this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Reci

Re: can't figure out error: module has no attribute...

2006-05-23 Thread Kent Johnson
ting it seems to depend on from which partition I > start Python. Probably you have multiple copies of selfservicelabels.py or an old selfservicelabels.pyc that is being imported. Try import selfservicelabels print selfservicelabels.__file__ to see where the import is coming from. Kent

GUI viewer for profiler output?

2006-05-23 Thread Kent Johnson
Can anyone point me to a GUI program that allows viewing and browsing the output of the profiler? I know I have used one in the past but I can't seem to find it... Thanks, Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: grabbing portions of a file to output files

2006-05-22 Thread Kent Johnson
mething like this? out = None for line in open(...): if line.startswith('H'): if out: out.close() out = open(..., 'w') if out: out.write(line) out.close() Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: who can give me the detailed introduction of re modle?

2006-05-19 Thread Kent Johnson
softwindow wrote: > the re module is too large and difficult to study > > i need a detaild introduction. > http://www.amk.ca/python/howto/regex/ Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: List behaviour

2006-05-17 Thread Mike Kent
When you did: b = a[:] b was then a copy of a, rather than just a reference to the same a. But what does a contain? It contains two sublists -- that is, it contains references to two sublists. So b, which is now a copy of a, contains copies of the two references to the same two sublists. What y

Re: OOP and Tkinter

2006-05-15 Thread Kent Johnson
tribute, not a class attribute. You need to refer to self._listbox_1 from a CustomFront method, or change _listbox_1 to a class attribute if that is what you really want. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: any plans to make pprint() a builtin?

2006-05-14 Thread Kent Johnson
rrent/doc/misc.html#the-py-std-hook Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: retain values between fun calls

2006-05-14 Thread Kent Johnson
Alternately you can use an attribute of the function to save the state: In [35]: def f(a): : f.b += a : return f.b : In [36]: f.b=1 In [37]: f(1) Out[37]: 2 In [38]: f(2) Out[38]: 4 Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: glob() that traverses a folder tree

2006-05-11 Thread Kent Johnson
k a little harder: for f in path.path('.\InteropSolution').walkfiles(): if f.fnmatch('*.dll') or f.fnmatch('*.exe'): print f or maybe for f in path.path('.\InteropSolution').walkfiles(): if f.ext in ['.dll', '.exe']: print f http://www.jorendorff.com/articles/python/path/index.html Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: unittest: How to fail if environment does not allow execution?

2006-05-11 Thread Kent Johnson
sage explaining what is wrong. I would just use the file normally in the test. If it's not there you will get an IOError with a traceback and a helpful error message. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Memory leak in Python

2006-05-11 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Sure, are there any available simulators...since i am modifying some > stuff i thought of creating one of my own. But if you know some > exisiting simlators , those can be of great help to me. http://simpy.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/pyth

Re: reusing parts of a string in RE matches?

2006-05-10 Thread Kent Johnson
art = 0 while True: m = pattern.search(string, start) if not m: break ans.append( (m.start(), m.end()) ) start = m.start() + 1 print ans # => [(0, 2), (2, 4), (4, 6), (6, 8), (8, 10), (10, 12), (12, 14)] Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: data entry tool

2006-05-10 Thread Kent Johnson
se. > > This software tool needs to work on a variety of different computers; Win95, > Win98, WinXP, Mac, Linux. Take a look at Tkinter, it is pretty easy to get started with and good for making simple GUIs. Look at the csv module for writing the data to files. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: regular expressions, substituting and adding in one step?

2006-05-10 Thread Kent Johnson
John Salerno wrote: > Call > me crazy, but I'm interested in regular expressions right now. :) Not crazy at all. REs are a powerful and useful tool that every programmer should know how to use. They're just not the right tool for every job! Kent -- http://mail.python.org/

Re: Enumerating Regular Expressions

2006-05-09 Thread Kent Johnson
inations for hints). Filter with the regex. Halting is left as an exercise for the reader. (Halting when the length reaches a predetermined limit would be one way to do it.) Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: regular expressions, substituting and adding in one step?

2006-05-09 Thread Kent Johnson
paragraph + '\n\n'" In [20]: re.sub(r"'' \+ (.*?) \+ '\n\n'", r"'%s\n\n' % \1", test) Out[20]: "self.source += '%s\n\n' % paragraph" Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Global utility module/package

2006-05-09 Thread Kent Johnson
again which just moved the > ugliness to another position. This is fine. You don't need 'global' statements to read global variables, function1() can be simply def function1(): print debugFlag Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: the print statement

2006-05-07 Thread Kent Johnson
strophe character in another > character set? If so, which character set? \x92 is a right single quote in Windows cp1252. http://www.microsoft.com/globaldev/reference/sbcs/1252.mspx Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Designing Plug-in Systems in Python

2006-05-07 Thread Kent Johnson
> systems. One of these might be helpful: http://developer.berlios.de/projects/plugboard/ http://termie.pbwiki.com/SprinklesPy Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Replace

2006-05-06 Thread Kent Johnson
d =ffgtyuf == =tyryr =u=p ff" In [3]: re.sub('=.', '=#', s) Out[3]: 'tyrtrbd =#fgtyuf =# =#yryr =#=# ff' If the replacement char is not fixed then make the second argument to re.sub() be a callable that computes the replacement. PS str is not a good name

Re: string.find first before location

2006-05-03 Thread Kent Johnson
Gary Wessle wrote: > ps. is there a online doc or web page where one enters a method and it > returns the related docs? The index to the library reference is one place: http://docs.python.org/lib/genindex.html and of course help() in the interactive interpreter... Kent --

Re: strip newlines and blanks

2006-05-02 Thread Kent Johnson
on of the loop. (Though you will need a separate test to terminate the loop when there are no more lines.) You can iterate an open file directly; here is a shorter version: for line in open('test.dat'): line = line.rstrip('\n') if line: print line Kent >

Re: How do I take a directory name from a given dir?

2006-05-01 Thread Mike Kent
Python 2.4.2 (#1, Nov 29 2005, 14:04:55) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> d = "/home/testuser/projects" >>> os.path.basename(d) 'projects' >>> os.path.dirname(d) '/home/testuser' >>> --

Re: best way to determine sequence ordering?

2006-04-28 Thread Kent Johnson
I V wrote: > Incidentally, does python have a built-in to do a binary search on a > sorted list? Obviously it's not too tricky to write one, but it would be > nice if there was one implemented in C. See the bisect module. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expression help

2006-04-28 Thread Kent Johnson
rs is handling malformed html. Beautiful Soup is intended to handle malformed HTML and seems to do pretty well. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: can this be done without eval/exec?

2006-04-27 Thread Kent Johnson
Out[3]: 0 In [4]: lst[5]() Out[4]: 5 A list comp makes this IMO cleaner: In [5]: lst = [ lambda i=i: i for i in range(10) ] In [6]: lst[0]() Out[6]: 0 In [7]: lst[5]() Out[7]: 5 Kent -- http://mail.python.org/mailman/listinfo/python-list

<    1   2   3   4   5   6   7   8   >