Re: Alternative to standard C for

2005-02-17 Thread Kent Johnson
James Stroud wrote: It seems I need constructs like this all of the time i = 0 while i len(somelist): if oughta_pop_it(somelist[i]): somelist.pop(i) else: i += 1 There has to be a better way... somelist[:] = [ item for item in somelist if not oughta_pop_it(item) ] Kent --

Re: more os.walk() issues... probably user error

2005-02-16 Thread Kent Johnson
rbt wrote: rbt wrote: This function is intended to remove unwanted files and dirs from os.walk(). It will return correctly *IF* I leave the 'for fs in fs_objects' statement out (basically leave out the entire purpose of the function). It's odd, when the program goes into that statment... even

Re: more os.walk() issues... probably user error

2005-02-16 Thread Kent Johnson
rbt wrote: ## for fs in fs_objects: ## ##for f in fs[2]: ##if f in file_skip_list: ##print f ##fs[2].remove(f) ## ##for d in fs[1]: ##if d in dir_skip_list: ##print d ##

Re: Can't subclass datetime.datetime?

2005-02-14 Thread Kent Johnson
Grant Edwards wrote: Is it true that a datetime object can convert itself into a string, but not the other way around? IOW, there's no simple way to take the output from str(d) and turn it back into d? According to this thread, a patch has been checked in that adds strptime() to datetime. So

Re: Newbie help

2005-02-14 Thread Kent Johnson
Chad Everett wrote: Nope, I am trying to learn it on my own. I am using the book by Michael Dawson. You might be interested in the Python tutor mailing list which is specifically intended for beginners. http://mail.python.org/mailman/listinfo/tutor Kent --

Re: Newbie help

2005-02-14 Thread Kent Johnson
Kent Johnson wrote: You might be interested in the Python tutor mailing list which is specifically intended for beginners. http://mail.python.org/mailman/listinfo/tutor Ah, I don't mean to imply that this list is unfriendly to beginners, or that you are not welcome here! Just pointing out

Re: changing __call__ on demand

2005-02-13 Thread Kent Johnson
Stefan Behnel wrote: Hi! This somewhat puzzles me: Python 2.4 (#1, Feb 3 2005, 16:47:05) [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2 Type help, copyright, credits or license for more information. . class test(object): ... def __init__(self): ... self.__call__ = self.__call1 ... def

Re: Second posting - Howto connect to MsSQL

2005-02-13 Thread Kent Johnson
John Fabiani wrote: Hi, Since this is (sort of) my second request it must not be an easy solution. Are there others using Python to connect MsSQL? At the moment I'd accept even a windows solution - although, I'm looking for a Linux solution. On Windows, you can use

Re: Is this a bug? BOM decoded with UTF8

2005-02-11 Thread Kent Johnson
Diez B. Roggisch wrote: I know its easy (string.replace()) but why does UTF-16 do it on its own then? Is that according to Unicode standard or just Python convention? BOM is microsoft-proprietary crap. Uh, no. BOM is part of the Unicode standard. The intent is to allow consumers of Unicode text

Re: Name of type of object

2005-02-10 Thread Kent Johnson
Jive Dadson wrote: I don't think I've quite got it. The application I'm writing has some similarities to an interactive shell. Like an interactive shell, it executes arbitrary code that it receives from an input stream. When it gets an exception, it should create an informative message,

Re: Big development in the GUI realm

2005-02-08 Thread Kent Johnson
Fredrik Lundh wrote: Robert Kern wrote: Fair enough. The only time I've seen it in dead-tree print was in Heinlein's _Time Enough For Love_, unattributed to anyone else. Amazon.com search inside the book finds no hits for malice in this book.

Subclassing cElementTree.Element

2005-02-07 Thread Kent Johnson
Is it possible to subclass cElementTree.Element? I tried import cElementTree as et class Elt(et.Element): ... pass ... Traceback (most recent call last): File stdin, line 1, in ? TypeError: Error when calling the metaclass bases cannot create 'builtin_function_or_method' instances I

Re: changing local namespace of a function

2005-02-06 Thread Kent Johnson
Bo Peng wrote: Kent Johnson wrote: You are still including the compile overhead in fun2. If you want to see how fast the compiled code is you should take the definition of myfun out of fun2: I assumed that most of the time will be spent on N times execution of myfunc. Doh! Right. Kent -- http

Re: changing local namespace of a function

2005-02-05 Thread Kent Johnson
Bo Peng wrote: Dear list, I have many dictionaries with the same set of keys and I would like to write a function to calculate something based on these values. For example, I have a = {'x':1, 'y':2} b = {'x':3, 'y':3} def fun(dict): dict['z'] = dict['x'] + dict['y'] fun(a) and fun(b) will set

Re: changing local namespace of a function

2005-02-05 Thread Kent Johnson
Bo Peng wrote: Yes. I thought of using exec or eval. If there are a dozen statements, def fun(d): exec 'z = x + y' in globals(), d seems to be more readable than def fun(d): d['z'] = d['x'] + d['y'] But how severe will the performance penalty be? You can precompile the string using compile(),

Re: changing local namespace of a function

2005-02-05 Thread Kent Johnson
Bo Peng wrote: Exec is slow since compiling the string and calls to globals() use a lot of time. The last one is most elegant but __getattr__ and __setattr__ are costly. The 'evil hack' solution is good since accessing x and y takes no additional time. Previous comparison was not completely

Re: Possible additions to the standard library? (WAS: About standardlibrary improvement)

2005-02-04 Thread Kent Johnson
Daniel Bickett wrote: |def reverse( self ): | |Return a reversed copy of string. | |string = [ x for x in self.__str__() ] |string.reverse() |return ''.join( string ) def reverse(self): return self[::-1] Kent --

Re: Startying with Python, need some pointers with manipulating strings

2005-01-27 Thread Kent Johnson
Benji99 wrote: I've managed to load the html source I want into an object called htmlsource using: import urllib sock = urllib.urlopen(URL Link) htmlSource = sock.read() sock.close() I'm assuming that htmlSource is a string with \n at the end of each line. NOTE: I've become very accustomed

Re: fast list lookup

2005-01-26 Thread Kent Johnson
Klaus Neuner wrote: Hello, what is the fastest way to determine whether list l (with len(l)3) contains a certain element? If you can use a set or dict instead of a list this test will be much faster. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: re.search - just skip it

2005-01-26 Thread Kent Johnson
[EMAIL PROTECTED] wrote: Input is this: SET1_S_W CHAR(1) NOT NULL, SET2_S_W CHAR(1) NOT NULL, SET3_S_W CHAR(1) NOT NULL, SET4_S_W CHAR(1) NOT NULL, ; .py says: import re, string, sys s_ora = re.compile('.*S_W.*') lines = open(y.sql).readlines() for i in range(len(lines)): try: if

Re: Help With Python

2005-01-26 Thread Kent Johnson
Thomas Guettler wrote: # No comma at the end: mylist=[] for i in range(511): mylist.append(Spam) or just mylist = [Spam] * 511 Kent print , .join(mylist) Thomas -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with saving and restoring program state

2005-01-25 Thread Kent Johnson
Jacob H wrote: Hello list... I'm developing an adventure game in Python (which of course is lots of fun). One of the features is the ability to save games and restore the saves later. I'm using the pickle module to implement this. Capturing current program state and neatly replacing it later is

Re: Overloading ctor doesn't work?

2005-01-21 Thread Kent Johnson
Nick Craig-Wood wrote: Martin Häcker [EMAIL PROTECTED] wrote: Now I thought, just overide the ctor of datetime so that year, month and day are static and everything should work as far as I need it. That is, it could work - though I seem to be unable to overide the ctor. :( Its a bug!

Re: xml parsing escape characters

2005-01-20 Thread Kent Johnson
Luis P. Mendes wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 this is the xml document: ?xml version=1.0 encoding=utf-8? string xmlns=http://www..;lt;DataSetgt; ~ lt;Ordergt; ~ lt;Customergt;439lt;/Customergt; (... others ...) ~ lt;/Ordergt; lt;/DataSetgt;/string This is an

Re: xml parsing escape characters

2005-01-20 Thread Kent Johnson
Irmen de Jong wrote: Kent Johnson wrote: [...] This is an XML document containing a single tag, string, whose content is text containing entity-escaped XML. This is *not* an XML document containing tags DataSet, Order, Customer, etc. All the behaviour you are seeing is a consequence

Re: Overloading ctor doesn't work?

2005-01-20 Thread Kent Johnson
Martin Häcker wrote: Hi there, I just tried to run this code and failed miserably - though I dunno why. Could any of you please enlighten me why this doesn't work? Here is a simpler test case. I'm mystified too: from datetime import datetime class time (datetime): def __init__(self, hours=0,

Re: Overloading ctor doesn't work?

2005-01-20 Thread Kent Johnson
Paul McGuire wrote: Kent Johnson [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Martin Häcker wrote: Hi there, I just tried to run this code and failed miserably - though I dunno why. Could any of you please enlighten me why this doesn't work? Here is a simpler test case. I'm mystified

Re: [csv module] duplication of end of line character in output file generated

2005-01-11 Thread Kent Johnson
simon.alexandre wrote: Hi all, I use csv module included in python 2.3. I use the writer and encouter the following problem: in my output file (.csv) there is a duplication of the end of line character, so when I open the csv file in Ms-Excel a blank line is inserted between each data line. From

Re: Python unicode

2005-01-11 Thread Kent Johnson
[EMAIL PROTECTED] wrote: Kent: I don't think so. You have hacked an attribute with latin-1 characters in it, but you haven't actually created an identifier. No, I really created an identifier. For instance I can create a global name in this way: globals()[è]=1 globals()[è] 1 Maybe I'm splitting

Re: Speed revisited

2005-01-09 Thread Kent Johnson
Andrea Griffini wrote: I've to admit that I also found strange that deleting the first element from a list is not O(1) in python. My wild guess was that the extra addition and normalization required to have insertion in amortized O(1) and deletion in O(1) at both ends of a random access sequence

Re: Please Contribute Python Documentation!

2005-01-09 Thread Kent Johnson
Aahz wrote: In article [EMAIL PROTECTED], Tony Meyer [EMAIL PROTECTED] wrote: I don't think I've seen such a statement before - the stuff I've seen all indicates that one should be submitting proper LaTeX docs/patches. If plain-text contributions are welcome, could this be added to the doc about

Re: Tkinter: passing parameters to menu commands

2005-01-08 Thread Kent Johnson
Philippe C. Martin wrote: menu.add_cascade(label=File, menu=filemenu) filemenu.add_command(label=New, command=lambda: callback('New')) filemenu.add_command(label=Open..., command=lambda: Of course you could do this with named forwarding functions if you prefer I'm not sure what 'named forwarding

Re: Tkinter: passing parameters to menu commands

2005-01-07 Thread Kent Johnson
Philippe C. Martin wrote: I have many menu items and would like them all to call the same method -However, I need the method called to react differently depending on the menu item selected. Since the menu command functions do not seem to receive any type of event style object, is there some type

Re: The Industry choice

2005-01-04 Thread Kent Johnson
Alex Martelli wrote: Roy Smith [EMAIL PROTECTED] wrote: Stefan Axelsson [EMAIL PROTECTED] wrote: Yes, ignoring most of the debate about static vs. dynamic typing, I've also longed for 'use strict'. You can use __slots__ to get the effect you're after. Well, sort of; it only works for instance

Re: Jython IronPython Under Active Development?

2004-12-27 Thread Kent Johnson
Steve Holden wrote: Just a little further background. The Python Software Foundation recently awarded a grant to help to bring Jython into line with the current CPython release. Is information publicly available about this and other PSF grants? I don't see any announcement on the PSF web site

Re: Jython performance

2004-12-23 Thread Kent Johnson
Sean Blakey wrote: On Wed, 22 Dec 2004 17:03:55 -0200, Gabriel Cosentino de Barros [EMAIL PROTECTED] wrote: On the Best GUI for small-scale accounting app? tread some people mentioned jython. I went to read about it, but i was wondering if anyone has any real project done with it and can give real

Re: mathmatical expressions evaluation

2004-12-23 Thread Kent Johnson
Tonino wrote: thanks all for the info - and yes - speed is not really an issue and no - it is not an implementation of a complete financial system - but rather a small subset of a investment portfolio management system developed by another company ... What I am trying to achieve is to parse a

Re: Lambda going out of fashion

2004-12-23 Thread Kent Johnson
Robin Becker wrote: Alex Martelli wrote: . By the way, if that's very important to you, you might enjoy Mozart (http://www.mozart-oz.org/) .very interesting, but it wants to make me install emacs. :( Apparently you can also use oz with a compiler and runtime engine...see

Re: getopt: Make argument mandatory

2004-12-16 Thread Kent Johnson
Frans Englich wrote: On Wednesday 15 December 2004 14:07, Diez B. Roggisch wrote: In my use of getopt.getopt, I would like to make a certain parameter mandatory. I know how to specify such that a parameter must have a value if it's specified, but I also want to make the parameter itself

Re: How do I convert characters into integers?

2004-12-14 Thread Kent Johnson
Markus Zeindl wrote: I have got a string from the user, for example Hi!. Now I get every character with a loop: code 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

Re: gather information from various files efficiently

2004-12-13 Thread Kent Johnson
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

Re: Wrapper objects

2004-12-10 Thread Kent Johnson
Nick Coghlan wrote: Simon Brunning wrote: This work - http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52295? Only for old-style classes, though. If you inherit from object or another builtin, that recipe fails. Could you explain, please? I thought __getattr__ worked the same with new-

Re: converting html escape sequences to unicode characters

2004-12-09 Thread Kent Johnson
harrelson wrote: I have a list of about 2500 html escape sequences (decimal) that I need to convert to utf-8. Stuff like: #48708; #54665; #44592; #47196; #48372; #45244; #44144; #50640; #50836; #45236; #47732; #44552; #51060; #50620; #47560; #51648; #51104; Anyone know what the decimal is

Re: Import a module without executing it?

2004-12-08 Thread Kent Johnson
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 functions

Re: Import a module without executing it?

2004-12-07 Thread Kent Johnson
Jay O'Connor wrote: The real question, I suppose, is what is a good technique to find what modules and classes implement or refer to particular names You might like to try ctags. I have had a good experience with it. It's not as automatic as I would like - you have to build a cross-reference

Re: string slicing

2004-12-05 Thread Kent Johnson
Ishwor wrote: s = 'hello' m = s[:] m is s True I discussed the *is* operator with some of the pythoners before as well but it is somewhat different than what i intended it to do. The LP2E by Mark David says - m gets a *full top-level copy* of a sequence object- an object with the same value but

Re: string slicing

2004-12-05 Thread Kent Johnson
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 get a different result

<    2   3   4   5   6   7