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
Carl Banks wrote:
> Martin Miller wrote:
> > Carl Banks wrote:
> >
> > > Martin Miller wrote:
> > > > ### non-redundant example ###
> > > > import sys
> > > >
> > > > class Pin:
> > > > def __init__(self,
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
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
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
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
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
[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
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
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
[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
[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
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
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
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
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
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
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
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,
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
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
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
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
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
[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
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
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
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
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
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
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
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
[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
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
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
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
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)
> > .
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
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
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
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
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
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
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
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
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
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
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
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'
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
50 matches
Mail list logo