Re: Generators and propagation of exceptions

2011-04-09 Thread Kent Johnson
On Apr 8, 3:47 pm, r wrote: > I'm already making something like this (that is, if I understand you > correctly). In the example below (an "almost" real code this time, I > made too many mistakes before) all the Expressions (including the > Error one) implement an 'eval' method that gets called by

Re: unittest setup

2005-09-30 Thread Kent Johnson
paul kölle wrote: > hi all, > > I noticed that setUp() and tearDown() is run before and after *earch* > test* method in my TestCase subclasses. I'd like to run them *once* for > each TestCase subclass. How do I do that. One way to do this is to make a TestSuite subclass that includes your startup

Re: Not defined

2005-10-01 Thread Kent Johnson
Rob wrote: > When trying the basic tutorial for cgkit I always seem to get a not defined > error as follows. > > Pythonwin GUI > > from cgkit import * Sphere() > > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'Sphere' is not defined Which version of c

Re: Will python never intend to support private, protected andpublic?

2005-10-03 Thread Kent Johnson
Mike Meyer wrote: > Paul Rubin writes: > That's not what privilege separation means. It means that the privileged objects stay secure even when the unprivileged part of the program is completely controlled by an attacker. >>> >>>In which case, what's "privat

Re: Nicer way of strip and replace?

2005-10-11 Thread Kent Johnson
Markus Rosenstihl wrote: > Hi, > I wonder if i can make this nicer: > > euro=euro + float(string.replace(string.strip(rechnung[element][10], > '"'), ',' , '.')) You can use the str methods instead of functions from the string module: euro=euro + float(rechnung[element][10].strip('"').replac

Re: are there internal functions for these ?

2005-10-11 Thread Kent Johnson
black wrote: > hi all~ > > i wrote some functions for copying and moving files caz' i didnt find > concret functions within the doc. but i think these operations are > simple and important so there may be some internal ones i didnt know. > anyone could figure me out ? See the os, os.path and shu

Re: Python adodb

2005-10-12 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > In trying to use the adodb module, I have had good success. However I > need to access a database with a username and password at this time. I have used a connection string like this to connect to MS SQL Server from adodb: connStrSQLServer = r"Provider=SQLOLEDB.1; User

Re: Looking for a Python mentor

2005-10-13 Thread Kent Johnson
LenS wrote: > Hello > > Was wandering if there is any place where some one could go to get > mentoring on python coding. I have started coding in python but I am > the only one in the shop using it. So there is no one around to look > over my code give suggestions on improvement, in style, logi

Re: Problem splitting a string

2005-10-15 Thread Kent Johnson
Alex Martelli wrote: > Using sum on lists is DEFINITELY slow -- avoid it like the plague. > > If you have a list of lists LOL, DON'T use sum(LOL, []), but rather > > [x for x in y for y in LOL] Should be >>> lol = [[1,2],[3,4]] >>> [x for y in lol for x in y] [1, 2, 3, 4] The outer loop comes

Re: Problem splitting a string

2005-10-15 Thread Kent Johnson
Steven D'Aprano wrote: > On Sat, 15 Oct 2005 10:51:41 +0200, Alex Martelli wrote: >>[ x for x in y.split('_') for y in z.split(' ') ] > > py> mystr = 'this_NP is_VL funny_JJ' > py> [x for x in y.split('_') for y in mystr.split(' ')] > Traceback (most recent call last): > File "", line 1, in ? >

Re: Outdated documentation

2005-10-17 Thread Kent Johnson
Laszlo Zsolt Nagy wrote: > Is this the good place to post? Follow the "About this document" link at the bottom of any page of Python docs for information about submitting change requests. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: ordered keywords?

2005-10-17 Thread Kent Johnson
Ron Adam wrote: > drawshapes( triangle=3, square=4, color=red, > polygon(triangle, color), > polygon(square, color) ) > > This comes close to the same pattern used in SVG and other formats where > you have definitions before expressions. Why is this better than the obviou

Re: unittest of file-reading function

2005-10-18 Thread Kent Johnson
Helge Stenstroem wrote: > Say I have a function > > def f(filename): > result = openFileAndProcessContents(filename) > return result > > Can that function be unit tested without having a real file as input? If you can refactor openFileAndProcessContents() so it looks like this: def openF

Re: [newbie]Is there a module for print object in a readable format?

2005-10-19 Thread Kent Johnson
Micah Elliott wrote: > On Oct 20, Steven D'Aprano wrote: > >>That's not what I get. What are you using? >> >>py> pprint.pprint([1,2,3,4,[0,1,2], 5], width=1, indent=4) >>Traceback (most recent call last): >> File "", line 1, in ? >>TypeError: pprint() got an unexpected keyword argument 'width' >

Re: parser question

2005-10-19 Thread Kent Johnson
Micah Elliott wrote: > You might be able to tackle this easily enough with REs if your > structures don't nest arbitrarily. It's hard to tell if this deserves > a formal grammar based on the example. If it does, you could try PLY > (which I've had a pleasant experienc

Re: Python variables are bound to types when used?

2005-10-19 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > So I want to define a method that takes a "boolean" in a module, eg. > > def getDBName(l2): > ... > > Now, in Python variables are bound to types when used, right? > > Eg. > x = 10 # makes it an INT > whereas > x = "hello" # makes it a string You don't have it quite r

Re: need some advice on x y plot

2005-10-20 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > how ? > i have tried to use unix timestamps, and i have also tried with > DateTime objects > do i need to use a scale that isn't linear (default in most) ? > how do i putt this off ? Here is some code that works for me. It plots multiple datasets against time. The input

Re: sort problem

2005-10-20 Thread Kent Johnson
Michele Petrazzo wrote: > Lasse Vågsæther Karlsen wrote: > >> How about: >> >> list.sort(key=lambda x: x[3]) Better to use key=operator.itemgetter(3) > Yes, on my linux-test-box it work, but I my developer pc I don't have > the 2.4 yet. I think that this is a good reason for update :) or learn

Re: Question on re.IGNORECASE

2005-10-20 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Hi, > > I'm having some problems with basic RE in python. I was wondering > whether > somebody could provide a hint on what's going wrong with the following > script. Comments are included. > > TIA. > -myself > > >>python2.3 > > Python 2.3.4 (#1, Nov 18 2004, 13:39:3

Re: ANN: Beginning Python (Practical Python 2.0)

2005-10-21 Thread Kent Johnson
Magnus Lie Hetland wrote: > I guess it has actually been out for a while -- I just haven't > received my copies yet... Anyways: My book, "Beginning Python: From > Novice to Professional" (Apress, 2005) is now out. Apress is offering a $10 rebate if you purchase the book before October 30. See for

Re: Binding a variable?

2005-10-21 Thread Kent Johnson
Paul Dale wrote: > > Hi everyone, > > Is it possible to bind a list member or variable to a variable such that No, Python variables don't work that way. > > temp = 5 The name 'temp' is now bound to the integer 5. Think of temp as a pointer to an integer object with value 5. > > list = [ temp

Re: need some advice on x y plot

2005-10-21 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > i am running a query on a database and making a list of time, value > pairs > kinda like this > plot_points = ([time, value], [time, value], [time, value]) > gnuplot complains that it needs a float for one of the values. > i can plot just the value, and it shows up ( no x

Re: Redirect os.system output

2005-10-21 Thread Kent Johnson
jas wrote: > I would like to redirect the output from os.system to a variable, but > am having trouble. I tried using os.popen(..).read() ...but that > doesn't give me exactly what i want. Here is an example using subprocess: http://groups.google.com/group/comp.lang.python/msg/9fa3a3c287e8e2a3?hl

Re: Python vs Ruby

2005-10-21 Thread Kent Johnson
Casey Hawthorne wrote: > I have heard, but have not been able to verify that if a program is > about > 10,000 lines in C++ > it is about > 5,000 lines in Java > and it is about > 3,000 lines in Python (Ruby to?) My experience is that Java:Python is roughly 2:1, the highest I have seen (on small b

Re: coloring a complex number

2005-10-21 Thread Kent Johnson
Arthur wrote: > Spending the morning avoiding responsibilities, and seeing what it would > take to color some complex numbers. > > class color_complex(complex): > def __init__(self,*args,**kws): > complex.__init__(*args) > self.color=kws.get('color', 'BLUE'

Re: Python vs Ruby

2005-10-21 Thread Kent Johnson
Bryan wrote: > i would not say sion's ratio of 5:1 is dubious. for what it's worth, > i've written i pretty complex program in jython over the last year. > jython compiles to java source code and the number of generated java > lines to the jython lines is 4:1. Ugh. The code generated by jytho

Re: Module Importing Question

2005-10-22 Thread Kent Johnson
James Stroud wrote: > Hello All, > > I have two modules that I use interchangably depending on the circumstances. > These modules are imported by yet another module. I want the "importation" of > these two alternatives to be mutually exclusive and dependent on the state of > the "outermost modu

Re: Question about inheritance...

2005-10-22 Thread Kent Johnson
KraftDiner wrote: > This is what I've got so far: > class Rect(Shape): > def __init__(self): > super(self.__class__, self).__init__() Should be super(Rect, self).__init__() > def render(self): > super(self.__class__, self).render() ditto In this exampl

Re: Tricky Areas in Python

2005-10-24 Thread Kent Johnson
Steven D'Aprano wrote: > Alex Martelli wrote: > Those two are easy. However, and this is where I show my hard-won > ignorance, and admit that I don't see the problem with the property > examples: > >> class Base(object) >> def getFoo(self): ... >> def setFoo(self): ... >>

Re: High Order Messages in Python

2005-10-24 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > counting that out(regardless whether it is (dis)advantage or not), what > else a block can do but not a named function ? My limited understanding is that the advantage is - simpler syntax - high level of integration into the standard library (*many* methods that take cl

Re: output from external commands

2005-10-24 Thread Kent Johnson
darren kirby wrote: > quoth the James Colannino: >>So, for example, in Perl I could do something like: >> >>@files = `ls`; >> >>So I guess I'm looking for something similiar to the backticks in Perl. >>Forgive me if I've asked something that's a bit basic for this list. >>Any help would be greatly

Re: Redirect os.system output

2005-10-24 Thread Kent Johnson
ies of HELP commands to cmd.exe, captures the output of the commands and saves it to a file. What did I miss? Kent > > > Kent Johnson wrote: > >>jas wrote: >> >>>I would like to redirect the output from os.system to a variable, but >>>am having tr

Re: Redirect os.system output

2005-10-24 Thread Kent Johnson
jas wrote: > Ok, I tried this... > > C:\>python > Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] > on win32 > Type "help", "copyright", "credits" or "license" for more information. > import subprocess as sp p = sp.Popen("cmd", stdout=sp.PIPE) result = p.com

Re: XML Tree Discovery (script, tool, __?)

2005-10-26 Thread Kent Johnson
Istvan Albert wrote: > All I can add to this is: > > - don't use SAX unless your document is huge > - don't use DOM unless someone is putting a gun to your head +1 QOTW -- http://mail.python.org/mailman/listinfo/python-list

Re: Scanning a file

2005-10-28 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > I want to scan a file byte for byte for occurences of the the four byte > pattern 0x0100. data = sys.stdin.read() print data.count('\x00\x00\x01\x00') Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: OEM character set issue

2005-10-28 Thread Kent Johnson
Dennis Lee Bieber wrote: > On Fri, 28 Oct 2005 15:55:56 +0200, "Ladvánszky Károly" <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > >>On my hungarian Win2k, some of the accented characters of the file names >>appear incorrectly when Python is driven from the command line. Ho

Re: extracting numbers from a file, excluding fixed words

2005-10-29 Thread Kent Johnson
dawenliu wrote: > Hi, I have a file with this content: > xxx xx x xxx > 1 > 0 > 0 > 0 > 1 > 1 > 0 > (many more 1's and 0's to follow) > y yy yyy yy y yyy > > The x's and y's are FIXED and known words which I will ignore, such as > "This is the start of the file"

Re: Function returns none

2005-10-31 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > I'm trying to write a website updating script, but when I run the > script, my function to search the DOM tree returns None instead of what > it should. When you call findelement() recursively you have to return the value from the recursive call to the next caller up. S

Re: frozenset/subclassing/keyword args

2005-10-31 Thread Kent Johnson
Mark E. Fenner wrote: > Speaking of which, in the docs at the bottom of the description of the > builtin set/frozenset, there is a link to a page describing differences > between the builtin sets and the sets module sets. This link is broken > locally and on the python.org docs. > Locally, it read

Re: Flat file, Python accessible database?

2005-11-01 Thread Kent Johnson
Karlo Lozovina wrote: > I've been Googling around for _small_, flat file (no server processes), > SQL-like database which can be easily access from Python. Speed and > perforamnce are of no issue, most important is that all data is contained > within single file and no server binary has to run i

Re: Object-Relational Mapping API for Python

2005-11-02 Thread Kent Johnson
Aquarius wrote: > I explored Java's Hibernate a bit and I was intrigued by how you can > map entity objects to database tables, preserving all the relations and > constraits. I am interested if there is something like this for Python > - I noticed some APIs in the "Cheeseshop", but most of them wer

Re: Learning multiple languages (question for general discussion)

2005-11-03 Thread Kent Johnson
John Salerno wrote: > I thought it might be interesting to get some opinions on when you know > when you're "done" learning a language. I've been learning C# for a few > months (albeit not intensively) and I feel I have a good grasp of the > language in general. Never? When you move on? You ca

Re: How can I do this in Python?

2005-11-05 Thread Kent Johnson
Lad wrote: > Can you please explain in more details (1) choice? If you are using CGI you might be interested in the VoidSpace logintools which seems to handle much of this process. See http://www.voidspace.org.uk/python/logintools.html#no-login-no-access Kent -- http://mail.python.org/mailman/l

Re: Calling Class' Child Methods

2005-11-05 Thread Kent Johnson
Steve Holden wrote: > Andrea Gavana wrote: >> The class "Custom" has a lot of methods (functions), but the user >> won't call >> directly this class, he/she will call the MainClass class to construct >> the >> GUI app. However, all the methods that the user can call refer to the >> "Custom" class

Re: re sub help

2005-11-05 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > hi > > i have a string : > a = > "this\nis\na\nsentence[startdelim]this\nis\nanother[enddelim]this\nis\n" > > inside the string, there are "\n". I don't want to substitute the '\n' > in between > the [startdelim] and [enddelim] to ''. I only want to get rid of the > '\n

Re: modifying source at runtime - jython case

2005-11-05 Thread Kent Johnson
Jan Gregor wrote: > Hello folks > > I want to apply changes in my source code without stopping jython > and JVM. Preferable are modifications directly to instances of > classes. My application is a desktop app using swing library. Can you be more specific? Python and Jython allow classes to be

Re: modifying source at runtime - jython case

2005-11-06 Thread Kent Johnson
Jan Gregor wrote: > my typical scenario is that my swing application is running, and i see > some error or chance for improvement - modify sources of app, stop and run > application again. > so task is to reload class defitions (from source files) and modify also > existing instances (their methods

Re: Pylab and pyserial plot in real time

2005-11-06 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Hiya, > > I've got a PIC microcontroller reading me humidity data via rs232, this > is in ASCII format. I can view this data easily using hyperterminal or > pyserial and convert it to its value (relative humidty with ord(input)) > > But what im trying to do is plot the

Re: need help extracting data from a text file

2005-11-07 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Hey there, > i have a text file with a bunch of values scattered throughout it. > i am needing to pull out a value that is in parenthesis right after a > certain word, > like the first time the word 'foo' is found, retrieve the values in the > next set of parenthesis (bar

Re: Regular expression question -- exclude substring

2005-11-07 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Hi, > > I'm having trouble extracting substrings using regular expression. Here > is my problem: > > Want to find the substring that is immediately before a given > substring. For example: from > "00 noise1 01 noise2 00 target 01 target_mark", > want to get > "00 target

Re: Regular expression question -- exclude substring

2005-11-07 Thread Kent Johnson
James Stroud wrote: > On Monday 07 November 2005 16:18, [EMAIL PROTECTED] wrote: > >>Ya, for some reason your non-greedy "?" doesn't seem to be taking. >>This works: >> >>re.sub('(.*)(00.*?01) target_mark', r'\2', your_string) > > > The non-greedy is actually acting as expected. This is because

Confusion about __call__ and attribute lookup

2005-11-10 Thread Kent Johnson
I am learning about metaclasses and there is something that confuses me. I understand that if I define a __call__ method for a class, then instances of the class become callable using function syntax: >>> class Foo(object): ... def __call__(self): ... print 'Called Foo' ... >>> f=Foo(

Re: Confusion about __call__ and attribute lookup

2005-11-10 Thread Kent Johnson
Leif K-Brooks wrote: > New-style classes look up special methods on the class, not on the instance: For my future reference, is this documented somewhere in the standard docs? Thanks, Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Confusion about __call__ and attribute lookup

2005-11-13 Thread Kent Johnson
John J. Lee wrote: > Kent Johnson <[EMAIL PROTECTED]> writes: > >>Leif K-Brooks wrote: >> >>>New-style classes look up special methods on the class, not on the instance: >> >>For my future reference, is this documented somewhere in the standard doc

Re: Python Book

2005-11-13 Thread Kent Johnson
David Rasmussen wrote: > What is the best book for Python newbies (seasoned programmer in other > languages)? I like Learning Python. Python in a Nutshell is good if you want something brief. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: generate HTML

2005-11-15 Thread Kent Johnson
Jim wrote: > Perhaps you are trying to do this: > 'text to go here: %s' % ('text',) > ? For that you need a double-quoted string: > "text to go here: %s" % ('text',) Uh, no, not in Python: >>> 'text to go here: %s' % ('text',) 'text to go here: text' >>> "text to go here: %s" % ('text',) 't

Re: Need advice on subclassing code

2005-11-15 Thread Kent Johnson
Rusty Shackleford wrote: > Hi -- > > We have some code that returns an object of a different class, depending > on some parameters. For example: > > if param x is 1 and y is 1, we make an object of class C_1_1. > if param x is 1 and y is 2, we make an object of class C_1_2. > > C_1_1 and C_1_2

Re: searching for files on Windows with Python

2005-11-17 Thread Kent Johnson
Shane wrote: > I've been giving Google a good workout with no luck. I would like to > be able to search a Windows filesystem for filenames, returning a > list off absolute paths to the found files, something like:> > def findFiles(filename, pathToSearch): > ... > ... > return foundF

Re: searching for files on Windows with Python

2005-11-19 Thread Kent Johnson
Peter Hansen wrote: > Kent Johnson wrote: >> import path >> files = path.path(pathToSearch).walkfiles(filename) > > A minor enhancement (IMHO) (though I certainly agree with Kent's > recommendation here): since there is nothing else of interest in the > "

Re: Web-based client code execution

2005-11-20 Thread Kent Johnson
Stephen Kellett wrote: > In message <[EMAIL PROTECTED]>, Steve > <[EMAIL PROTECTED]> writes > >> AJAX works because browsers can execute javascript. I don't know of a >> browser that can execute python. Basically your stuck with java or >> javascript because everything else really isn't cross p

Re: Is there a way to create a button in either pygame or livewires?

2005-11-20 Thread Kent Johnson
Nathan Pinno wrote: > Hey all, > > Is there a way to create a button in either pygame or livewires, that is > able to be clicked and when clicked sends a command to restart the program? Maybe something here: http://www.pygame.org/wiki/gui Kent -- http://mail.python.org/mailman/listinfo/python-

Re: Web-based client code execution

2005-11-20 Thread Kent Johnson
Paul Watson wrote: > Kent Johnson wrote: >> Stephen Kellett wrote: >>> ActiveState do a version of Python that can run in a script tag like >>> JavaScript and VBScript. This requires Windows Scripting Host. They >>> also do a similar thing for Perl, n

Re: Web-based client code execution

2005-11-21 Thread Kent Johnson
Paul Watson wrote: > My desire to have the code distributed through a web page is just to > ensure that the user is running the correct version and has not hacked > it in any way. I suppose I can checksum the local client application > and compare it with what is on the server. Then, make a wa

Persist a class (not an instance)

2005-11-25 Thread Kent Johnson
Is there a way to persist a class definition (not a class instance, the actual class) so it can be restored later? A naive approach using pickle doesn't work: >>> import pickle >>> class Foo(object): ... def show(self): ... print "I'm a Foo" ... >>> p = pickle.dumps(Foo) >>> p 'c__ma

Re: Python book for a non-programmer

2005-11-25 Thread Kent Johnson
Simon Brunning wrote: > I have a non-programming friend who wants to learn Python. It's been > so long since I've been in her shoes that I don't feel qualified to > judge the books aimed at people in her situation. Python Programming for the absolute beginner http://premierpressbooks.com/ptr_deta

Re: Persist a class (not an instance)

2005-11-25 Thread Kent Johnson
Sybren Stuvel wrote: > Kent Johnson enlightened us with: > >>Is there a way to persist a class definition (not a class instance, >>the actual class) so it can be restored later? > > > From the docs: > > "Similarly, classes are pickled by named refere

No apos in htmlentitydefs

2005-11-28 Thread Kent Johnson
I see that htmlentitydefs.name2codepoint does not include 'apos' as one of the recognized names. Is this intentional or a bug? In fact ' is not a recognized entity in HTML 4.01; see this list: http://www.w3.org/TR/html4/sgml/entities.html#misc But it is recognized in XHTML 1.0: http://www.w3.org

Re: Looking for good beginner's tutorial

2005-11-29 Thread Kent Johnson
Roy Smith wrote: > My wife wants to learn Python. Can anybody suggest a good tutorial > for her to read? She's a PhD molecular biologist who is a pretty > advanced Unix user. She mucks about with Perl scripts doing things > like text processing and even some simple CGI scripts, but has no > form

Re: How to list currently defined classes, methods etc

2005-12-02 Thread Kent Johnson
Deep wrote: > I have been looking a bit and am stuck at this point. > > Given a string, how do i find what is the string bound to. > Let me give an example. > > def deep(): > print "Hello" > > now inspect.ismethod(deep) returns true. (As it should). > But if I am trying to make a list of al

Re: Detect character encoding

2005-12-05 Thread Kent Johnson
Martin P. Hellwig wrote: > I read or heard (can't remember the origin) that MS IE has a quite good > implementation of guessing the language en character encoding of web > pages when there not or falsely specified. Yes, I think that's right. In my experience MS Word does a very good job of gues

Re: Is there an equivalent to Java Webstart in Python?

2005-12-05 Thread Kent Johnson
Nic Bar wrote: > The problem with Jython is that I can only live inside the aplet > virtual machine, Only if you are writing an applet. > I need a full features application with access to the local computer > resources. You can do this with Jython and JWS. Write your app in Jython, deploy with

Re: Is there an equivalent to Java Webstart in Python?

2005-12-05 Thread Kent Johnson
Renato wrote: > What use is Java WebStart, exactly? It's a way to deploy a Java app from a web site. Assuming the user has Java installed, the app can be launched just by clicking a link on a web page. The jar files are cached locally so they are only downloaded once, the user can make desktop

Re: Is there an equivalent to Java Webstart in Python?

2005-12-06 Thread Kent Johnson
Ravi Teja wrote: > Hi Kent, > Too complicated example :-). Jythonc works just fine to create a > regular jar file that you can reference in your jnlp file. If it works for you, good. I have never been able to compile a real app with jythonc and I gave up on it long ago. Kent -- http://mail.py

Re: Documentation suggestions

2005-12-07 Thread Kent Johnson
Steve Holden wrote: > BartlebyScrivener wrote: >> Now you are on a page with promising-looking links that all start with >> "BeginnersGuide," but the first three are not warm welcomes, they are >> housekeeping matters about where you can take courses or how to >> download Python for people who don'

Re: Mutability of function arguments?

2005-12-08 Thread Kent Johnson
Mike Meyer wrote: > "ex_ottoyuhr" <[EMAIL PROTECTED]> writes: > >>I'm trying to create a function that can take arguments, say, foo and >>bar, and modify the original copies of foo and bar as well as its local >>versions -- the equivalent of C++ funct(&foo, &bar). > > > C++'s '&' causes an argum

Re: Encoding of file names

2005-12-08 Thread Kent Johnson
utabintarbo wrote: > Here is my situation: > > I am trying to programatically access files created on an IBM AIX > system, stored on a Sun OS 5.8 fileserver, through a samba-mapped drive > on a Win32 system. Not confused? OK, let's move on... ;-) > > When I ask for an os.listdir() of a relevant d

Re: Documentation suggestions

2005-12-08 Thread Kent Johnson
A.M. Kuchling wrote: > On Wed, 07 Dec 2005 12:10:18 -0500, > Kent Johnson <[EMAIL PROTECTED]> wrote: > >>OK I'll bite. That Beginners Guide page has bugged me for a long time. >>It's a wiki page but it is marked as immutable so I can't change

Re: Another newbie question

2005-12-08 Thread Kent Johnson
Steven D'Aprano wrote: > On Wed, 07 Dec 2005 23:58:02 -0500, Mike Meyer wrote: >>>1) The stmt "board.Blist[10].DrawQueen(board.Blist[10].b1)" seems >>>awkward. Is there another way (cleaner, more intuitive) to get the >>>same thing done? >> >>Yes. Reaching through objects to do things is usually a

Re: How to detect the presence of a html file

2005-12-09 Thread Kent Johnson
Phoe6 wrote: > Operating System: Windows > Python version: 2.4 > > I have bookmarks.html and wumpus.c under my c: > > When I tried to check the presence of the bookmarks.html, I fail. > > os.path.isfile('c:\bookmarks.html') > > False > os.path.isfile('c:\wumpus.c') > > True The prob

Re: Catching error text like that shown in console?

2005-12-09 Thread Kent Johnson
Peter A. Schott wrote: > I know there's got to be an easy way to do this - I want a way to catch the > error text that would normally be shown in an interactive session and put that > value into a string I can use later. I've tried just using a catch statement > and trying to convert the output to

Re: How to detect the presence of a html file

2005-12-09 Thread Kent Johnson
Peter Hansen wrote: > Kent Johnson wrote: > >> The simplest fix is to use raw strings for all your Windows path needs: >> os.path.isfile(r'c:\bookmarks.html') >> os.path.isfile(r'c:\wumpus.c') > > > Simpler still is almost always t

Re: Proposal: Inline Import

2005-12-09 Thread Kent Johnson
Shane Hathaway wrote: > Mike Meyer wrote: > >> Shane Hathaway <[EMAIL PROTECTED]> writes: >> >>> That syntax is verbose and avoided by most coders because of the speed >>> penalty. >> >> What speed penalty? "import re" is a cheap operation, every time but >> the first one in a program. > > I'm ta

Re: newby question: Splitting a string - separator

2005-12-09 Thread Kent Johnson
James Stroud wrote: > The one I like best goes like this: > > py> data = "Guido van Rossum Tim Peters Thomas Liesner" > py> names = [n for n in data.split() if n] > py> names > ['Guido', 'van', 'Rossum', 'Tim', 'Peters', 'Thomas', 'Liesner'] > > I think it is theoretically faster (and more p

Re: Managing import statements

2005-12-10 Thread Kent Johnson
Jean-Paul Calderone wrote: > On Sat, 10 Dec 2005 02:21:39 -0700, Shane Hathaway > <[EMAIL PROTECTED]> wrote: >> How about PyLint / PyChecker? Can I configure one of them to tell me >> only about missing / extra imports? Last time I used one of those >> tools, it spewed excessively pedantic warni

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: 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 of

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 forwar

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 wa

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 abou

Re: Python & unicode

2005-01-11 Thread Kent Johnson
[EMAIL PROTECTED] wrote: I forgot to add the following: setattr(C, "Ã", u"The letter Ã") getattr(C, "Ã") u'The letter \xe8' print getattr(C, "Ã") The letter à But try this: >>> C.à File "", line 1 C.â ^ SyntaxError: invalid syntax Python identifiers can be generic strings, including

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 th

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 splitti

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: http://www..";> ~ ~ 439 (... others ...) ~ This is an XML document containing a single tag, , whose content is text containing en

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, , whose content is text containing entity-escaped XML. This is *not* an XML document containing tags , , , etc. All the behaviour you are seeing is a consequence of this. You need to unescape the

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, min

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 s

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! http:

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 pro

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 s_ora.search(lin

  1   2   3   4   5   6   7   >