Re: New os.path.exists() behavior - bug or feature?

2007-01-24 Thread Martin Miller
FWIW, your code works correctly for me in all respects with Python 2.5 on Windows XP Pro. I no longer have Python 2.4.x installed, so can't easily do a comparison. Perhaps the problem has something to do with Python 2.5 with Windows 2K. -Martin On Dec 17 2006, 4:29 pm, "klappnase" <[EMAIL PROTE

Re: (newbie) Is there a way to prevent "name redundancy" in OOP ?

2007-01-10 Thread Martin Miller
Carl Banks wrote: > Martin Miller wrote: > > Carl Banks wrote: > > > > > Martin Miller wrote: > > > > ### non-redundant example ### > > > > import sys > > > > > > > > class Pin: > > > > def __init__(self,

Re: PDF rendering toolkit?

2007-01-07 Thread Martin Miller
Jorge Vargas wrote: > Hi > > I'm looking for a tool to take an actual .pdf file and display it in a > window (I'm using wxwidgets at the moment) > > [snip] How about just using Adobe's Acrobat Reader application which is freely available on most platforms? There's some related information about d

Re: Python cheatsheets

2007-01-07 Thread Martin Miller
gonzlobo wrote: > Curious if anyone has a python cheatsheet* published? I'm looking for > something that summarizes all commands/functions/attributes. Having > these printed on a 8" x 11" double-sided laminated paper is pretty > cool. > > * cheatsheet probably isn't the right word, but you get th

Re: Re:[OT] (newbie) Is there a way to prevent "name redundancy" in OOP ?

2007-01-07 Thread Martin Miller
Bruno Desthuilliers wrote: > Martin Miller a écrit : > (snip) > > > > Oh, contrair. > > I guess you mean "au contraire" ?-) > > (snip) FWIW "contrair" is how it's spelled in the Oxford English dictionary (I actually did look it up before

Re: (newbie) Is there a way to prevent "name redundancy" in OOP ?

2007-01-06 Thread Martin Miller
Carl Banks wrote: > Martin Miller wrote: > > ### non-redundant example ### > > import sys > > > > class Pin: > > def __init__(self, name, namespace=None): > > self.name = name > > if namespace == None: > > # de

Re: (newbie) Is there a way to prevent "name redundancy" in OOP ?

2007-01-05 Thread Martin Miller
Stef Mientki wrote: > Not sure I wrote the subject line correct, > but the examples might explain if not clear > > > *** first attempt *** > class pin: >def __init__ (self): > self.Name = 'Unknown Pin' > > aap = pin() # create an instance > aap.Name = 'aap'# set it's n

Re: Class constant for extension

2006-12-23 Thread Martin Miller
[EMAIL PROTECTED] wrote: > Hi, > > I have written a small prototype Python extension for a C-library. > > I have the methods all sorted out and it is working fine. > > In the C-library, they are various constants of types like string, > integer, float and matrix. I'd like to expose them as RE

Re: Character Encodings and display of strings

2006-11-14 Thread Martin Miller
It is possible derive your own string class from the built-in one and override what 'repr' does (and make it do whatever you want). Here's an example of what I mean: # Sample # # -*- coding: iso-8859-1 -*- # Special string class to override the default # representation method. Main purpo

Re: Make all files extension lower by a given directory name

2006-11-03 Thread Martin Miller
Tim Chase wrote, in part: > ... > I've found that Win32 doesn't often take a rename if the origin > and destination differ only in case[*]. Thus, to change the > case, I've had to do *two* renames...one to, say, prefix with an > underscore and change the case to my desired case, and then one > to

Re: batch tiff to jpeg conversion script

2006-01-12 Thread Martin Miller
[EMAIL PROTECTED] wrote: > Just curious... is PhotoShop _really_ recursive? We have dozens of > levels of sub-folders where the pics have been sorted and thousands of > pics. That's one reason I used os.walk() Yes, in the sense that there is an "Include All Subfolders" option for batch operation s

Re: batch tiff to jpeg conversion script

2006-01-11 Thread Martin Miller
[EMAIL PROTECTED] wrote: > Hi Peter. The guy who takes the pictures uses Photoshop to convert > tiffs to jpegs one by one. When he does a 'Maxium Quality' conversion > in Photoshop and I do a 100% quality conversion with Python and PIL, > the two converted files are almost identical and this is wha

Re: How do I redirect output to a file and to the console screen?

2005-12-28 Thread Martin Miller
The basic way to redirect output is to reassign a value to sys.stdout -- something along these lines: # redirect stdout to a disk file import sys saveout = sys.stdout outfile = open('output.txt', 'w') sys.stdout = outfile # output stuff print 'hello world' # resto

Re: Python IDE (was: PythonWin troubleshooting)

2005-12-15 Thread Martin Miller
You might want to also to consider the Komodo IDE from ActiveState (the same company that produces ActivePython and hosts the ASPN Cookbook). This isn't an endorsement -- I have no experience with it -- but its feature set looks good [see http://activestate.com/Products/Komodo]. If someone with

Re: (newbie) N-uples from list of lists

2005-12-02 Thread Martin Miller
tly. It is possible to talk about one "fastest" way, > but many times there isn't such a thing of one "best" way. > > Martin Miller wrote: > > FWIW, I found Steven Taschuk's solution easiest to understand regarding > > the question posed in your orig

Re: importing a method

2005-11-30 Thread Martin Miller
method/function: >>> o.z() <__main__.old instance at 0x009D5F30> So I stand corrected -- thank you. Best, -Martin == Alex Martelli wrote: > Martin Miller <[EMAIL PROTECTED]> wrote: > > > I'd like to point out to the OP that using a function&#x

Re: importing a method

2005-11-30 Thread Martin Miller
hon programs as types.MethodType. > ... [snip] Which, as you can see, claims that types.MethodType is actually an instance of a PyTypeObject (not the class instancemethod that help(types.MethodType) indicated). Best, -Martin Steven D'Aprano wrote: > On Mon, 28 Nov 2005 08:16:12 -0

Re: (newbie) N-uples from list of lists

2005-11-30 Thread Martin Miller
FWIW, I found Steven Taschuk's solution easiest to understand regarding the question posed in your original post -- namely how to solve the problem non-recursively with generators -- because it was similar to my own thinking about how to do it -- but suspect that Raymond Hettinger's is the likely t

Re: importing a method

2005-11-28 Thread Martin Miller
I'd like to point out to the OP that using a function's __get__ method this way only works with new-style classes and their instances...not with the example in the shown in original post. -Martin Alex Martelli wrote: > Flavio <[EMAIL PROTECTED]> wrote: > > > This "new" module sounds pretty cool,

Re: importing a method

2005-11-28 Thread Martin Miller
First of all,why do you think the new module is deprecated? (I can't find anything in the docs to indicate this.) As for using MethodType in the types module: There's nothing in the module documentation that suggests that you can call MethodType as a function as you suggest, only that it is the

Re: Default method arguments

2005-11-17 Thread Martin Miller
Mike Meyer wrote, in part:: > "Gregory Petrosyan" <[EMAIL PROTECTED]> writes: > ... > > 2) Is 'foo.s = n' a correct solution? It seems to be a little more > > elegant. (I tested it, and it worked well) > > It's basically the same solution. You're replacing binding a variable > with mutating an obj

Re: Default method arguments

2005-11-15 Thread Martin Miller
Alex Martelli wrote, in part: > If it's crucial to you to have some default argument value evaluated at > time X, then, by Python's simple rules, you know that you must arrange > for the 'def' statement itself to execute at time X. In this case, for > example, if being able to have self.data as th

Re: about widget construction kit

2005-11-11 Thread Martin Miller
Shi Mu wrote: > On 11/11/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > > 1. pass in the full path to the executable: > > > >cd tkinter3000-1.0-20031212 > >c:\python23\python setup.py install > > ... > > > still confused by th first way you mentioned. If I cd > tkinter3000-1.0-20031212, i w

Re: Invoking Python from Python

2005-11-08 Thread Martin Miller
John Henry wrote: > Hi all, > > I have a need to create a Python script on the fly from another Python > program and then execute the script so created. Do I need to invoke > Python through os.spawnl or is there a better way? When doing something similar to this I used the built-in 'execfile()' f

Signals and keyboard interupts

2005-10-27 Thread Martin Miller
[Using Windows XP and Python 2.4.1] I have question about the following code, which basically accomplished what what I want, which is to gracefully exit the main loop when the user presses either the control-c or control-break key: import signal import sys import time import traceback QUIT = Fal

Re: replacments for stdio?

2005-10-06 Thread Martin Miller
In what way would you like to get "stdin to work"? In Bryan's post in the Application(Frame).__init__() he binds some lambda functions to key strokes which allow control-C copying of text in the window. Seems like additonal application-specific things might be possible, but then the code would no

Re: replacments for stdio?

2005-10-05 Thread Martin Miller
Ido, I tried Bryan Olson's code [on Windows] from his last post to the "Catching stderr output from graphical apps" thread http://groups.google.com/group/comp.lang.python/msg/d61f1d5e02d84178>, and it seemed to work for stdout as well as stderr output. To enable its use with stdout, all I had to

Re: replacments for stdio?

2005-09-25 Thread Martin Miller
Here's a suggestion for you: Check out the comp.lang.py thread titled "Catching stderr output from graphical apps" at > http://groups.google.com/group/comp.lang.python/browse_frm/thread/1d63e12e15ca528b/7bf604115b5e914e#7bf604115b5e914e I strongly suspect that the code discussed could probably be

Re: Using '__mul__' within a class

2005-09-24 Thread Martin Miller
As others have pointed out, you are just reassigning a new value to the self argument in the Square() method shown. Instead, what you need to do is change the object that 'self' refers to within the method. To do this, change it to: def Square( self ): result = self * self self

Re: Open PDF

2005-09-23 Thread Martin Miller
IMHO, the fact that there is no way to wait for the application to finish is major deficiency with os.startfile() -- and why I often cannot use it instead of other techniques [such as the much more involved but limited os.spawnv() function]. I don't if if this is just a limitation of the implement

Re: Python linear algebra module -- requesting comments on interface

2005-09-09 Thread Martin Miller
Since one of the module's targeted applications is for 3D applications, I think there should be some specific support for applying the Matrix-vector product operation to a sequence of vectors instead of only one at a time -- and it should be possible to optimize the module's code for this common ca

Re: launching adobe reader with arguments from os.system call

2005-09-06 Thread Martin Miller
Greg Miller wrote: > Currently I am launching adobe reader using the following call: > os.system("path.file.pdf") > this works fine for opening the pdf doc at the beginning. We would like > to enhance this and open the document to either a page or a nameddest > in the doc. The syntax for that in t

Re: "Ordered" dicts

2005-08-10 Thread Martin Miller
[EMAIL PROTECTED] wrote: > > Lots and lots of people want ordered dicts it seems. Or at least, they > > want > > to be able to access their dictionary keys in order. > > [snipped lots of examples, nice pro-con lists, etc.] > > What do y'all think? > > I'll second the need for this. Although, what

Re: case/switch statement?

2005-06-22 Thread Martin Miller
Skip Montanaro wrote: > Terry> Yeah, and I find this even more so: > > Terry> case = { > Terry> 5: do_this, > Terry> 6: do_that, > Terry> } > Terry> case.get(x, do_default)() > > Terry> Which is looking pretty close to a case statement, anyway. > > S

Re: Add Properties to Instances?

2005-03-19 Thread Martin Miller
Bengt Richter wrote: > On 14 Mar 2005 13:07:29 -0800, "Martin Miller" <[EMAIL PROTECTED]> wrote: > > >Bengt Richter wrote, in part: > >> On 14 Mar 2005 01:19:23 -0800, "Martin Miller" > ><[EMAIL PROTECTED]> > >> wrote, in par

Re: Add Properties to Instances?

2005-03-14 Thread Martin Miller
Bengt Richter wrote, in part: > On 14 Mar 2005 01:19:23 -0800, "Martin Miller" <[EMAIL PROTECTED]> > wrote, in part: > >What still puzzles me, though, is why all the above to make properties > >work on instances is necessary in the first place. It's certainly

Re: Add Properties to Instances?

2005-03-14 Thread Martin Miller
In answer to my question about instance properties not working, Bengt Richter suggest using: > > >>> class InstProp(object): > > ... def __getattribute__(self, attr): > > ... p = object.__getattribute__(self, attr) > > ... if isinstance(p, property): return p.__get__(self) > > .

Re: Add Properties to Instances?

2005-03-12 Thread Martin Miller
So far a couple of people have asked: > What's the situation in which you think you want different properties > for different instances of the same class? Fair enough -- here goes: Essentially what I'm doing is implementing (yes, yet another ;-) 'enumeration' class using an an approach which invo

Add Properties to Instances?

2005-03-12 Thread Martin Miller
I'm trying to create some read-only instance specific properties, but the following attempt didn't work: > class Foobar(object): > pass > > foobar = Foobar() > foobar.x = property(fget=lambda: 42) > > print "foobar.x:", foobar.x Which results in the following ouput instead of '42': foobar.x

'class' argument optional for new.instancemethod?

2005-03-11 Thread Martin Miller
In section "3.27 new -- Creation of runtime internal objects" of the documentation that comes with Python 2.4 it says: > instancemethod(function, instance, class) > > This function will return a method object, bound to instance, or unbound if > instance is None. function must be callable. However

Re: Test for structure

2005-02-22 Thread Martin Miller
Nope, that isn't right either, in the sense that it handles all the cases properly, including "single string" vs "list of strings'. Guess this overly simplistic aslist() does not work after. I should have been more suspicious and cautious before posting. Sorry. Martin -- http://mail.python.org/m

Re: Test for structure

2005-02-22 Thread Martin Miller
Ooops. I left out an "*" on a statement in the new aslist() function. I should have written: def aslist(*args): return list(*args) # corrected def f(arg): args = aslist(arg) ... Sorry, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: Execute a list

2005-02-22 Thread Martin Miller
Here is how to execute code in a string, similar to what was shown in your example: >>> s = 'print "hello"' >>> exec s hello Hope this helps. -- http://mail.python.org/mailman/listinfo/python-list

Re: Test for structure

2005-02-22 Thread Martin Miller
At the end of his last post, Steve Bethard wrote: > That said, I find that in most cases, the better option is to use *args > in the original function though. For example: > > def f(arg): > args = aslist(arg) > ... > f(42) > f(['spam', 'eggs', 'ham']) > > could pro

Re: Test for structure

2005-02-21 Thread Martin Miller
or None argument Can this be improved or is there anything wrong or overly limiting about it? TIA, Martin = Steven Bethard wrote: > Terry Hancock wrote: > > But you probably shouldn't do that. You should probably just test to > > see if the object is it

Re: Test for structure

2005-02-21 Thread Martin Miller
t; see if the object is iterable --- does it have an __iter__ method? > > > > Which might look like this: > > > > if hasattr(a, '__iter__'): > > print "'a' quacks like a duck" > > Martin Miller top-posted: > > I do

Re: Test for structure

2005-02-20 Thread Martin Miller
I don't believe you can use the test for a __iter__ attribute in this case, for the following reason: >>> c1 = 'abc' >>> c2 = ['de', 'fgh', 'ijkl'] >>> hasattr(c1, '__iter__') False >>> hasattr(c2, '__iter__') True >>> for i in c1: print "i=%s is an element of c1" % repr(i) ... i='a' is an element

Re: Curses on Windows

2005-02-08 Thread Martin Miller
I just tried the flangy.com link and it appears to be OK now. Martin Peter wrote: > ... > One reply (in fact the only reply - thanks Tim Golden) suggested I > look at http://flangy.com/dev/python/curses/ -- http://mail.python.org/mailman/listinfo/python-list

Re: "pickle" vs. f.write()

2005-02-05 Thread Martin Miller
Marc 'BlackJack' Rintsch wrote: > ... > > I write __repr__() methods similar but I think a bit more readable: > > def __repr__(self): > return "%s(%r, %r, %r, %r)" % (self.__class__.__name__, self.name, > self.age, self.friends, self.comment) > > And it'

Re: "pickle" vs. f.write()

2005-02-01 Thread Martin Miller
On 1/26/05 at 1:48 pm, Terry Reedy wrote: > For basic builtin objects, repr(ob) generally produces a string that when > eval()ed will recreate the object. IE > eval(repr(ob) == ob # sometimes I've found extending this property to your own classes often fairly easy to implement (and useful). For