Re: 0 == False but [] != False?

2007-05-29 Thread Donn Cave
In article <[EMAIL PROTECTED]>, Erik Max Francis <[EMAIL PROTECTED]> wrote: > Donn Cave wrote: > > > Not that it is of no historical interest to review all these > > reasonable arguments, but allow me to restore the context quote > > from my follow-up:

Re: Who told str() to round my int()'s!!!

2007-08-15 Thread Donn Cave
he way we render objects as text strings, a priori. If there is any such thing, it depends completely on the context. To invite the author of an object to devise a text rendition that will be humane (friendly, readable or whatever) is to waste his or her time. There are better ways to conceive of this str/repr distinction, and they've been discussed to death. python.org documentation will probably never be fixed. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: imaplib & Received: header(s)???

2007-08-19 Thread Donn Cave
an you retrieve other fields that way? Does the one you're looking for appear in the data if you get the whole header, for example with 'RFC822.HEADER'? It certainly does in my Python IMAP client, and this would have at least helped you refine your question. Donn Cave -- http://mail.python.org/mailman/listinfo/python-list

Re: Dialog with a process via subprocess.Popen blocks forever

2007-03-02 Thread Donn Cave
fer to use a > different thread for reading its output. Right - `I used threads to solve my problem, and now I have two problems.' It can work for some variations on this problem, but not the majority of them. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Dialog with a process via subprocess.Popen blocks forever

2007-03-06 Thread Donn Cave
In article <[EMAIL PROTECTED]>, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Fri, 02 Mar 2007 14:38:59 -0300, Donn Cave <[EMAIL PROTECTED]> > escribió: > > > In article <[EMAIL PROTECTED]>, > > "Gabriel Genellina"

Re: tuples, index method, Python's design

2007-04-12 Thread Donn Cave
index method. This suggests a missing > method, does it not? Who has not done this? > Name yourself! I am pleased to find myself in this company. My name is Donn Cave. I have been using Python since version 1.1, though frankly I haven't used it a lot in recent years. I have a confess

Re: tuples, index method, Python's design

2007-04-12 Thread Donn Cave
ngly that > this shouldn't be understood in terms of type similarities. Well, yes - consider for example the "tm" tuple returned from time.localtime() - it's all integers, but heterogeneous as could be - tm[0] is Year, tm[1] is Month, etc., and it turns out that not on

Re: tuples, index method, Python's design

2007-04-16 Thread Donn Cave
In article <[EMAIL PROTECTED]>, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > "Donn Cave" <[EMAIL PROTECTED]> wrote: > > > > > Well, yes - consider for example the "tm" tuple returned > > from time.localtime() - it

Re: Would Anonymous Functions Help in Learning Programming/Python?

2007-09-21 Thread Donn Cave
rameter binding should be implemented, so you could say dotted = string.join('.') ... v = dotted(['comp', 'lang', 'python']) As you probably well know, that isn't my idea, it's a common functional programming language idiom. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

A class question

2007-10-29 Thread Donn Ingle
Hello, Is there a way I can, for debugging, access the instance variable name from within a class? E.g: Class X: def debug(self): print "My instance var is %s" % (some magic Python stuff) So that: >>>x = X() >>>x.debug() >>>My Instance var is x ( Without passing the name in like: x=X(name="x

Re: A class question

2007-10-29 Thread Donn Ingle
bump :) -- http://mail.python.org/mailman/listinfo/python-list

Re: A class question

2007-10-29 Thread Donn Ingle
> vzcbeg vafcrpg > > qrs _svaq(senzr, bow): > sbe anzr, inyhr va senzr.s_ybpnyf.vgrevgrzf(): > vs inyhr vf bow: > erghea anzr > sbe anzr, inyhr va senzr.s_tybonyf.vgrevgrzf(): > vs inyhr vf bow: > erghea anzr > envfr XrlReebe("Bowrpg abg sbhaq va

Re: A class question

2007-10-29 Thread Donn Ingle
> for humans: Sweet. Thanks, I'll give it a go. It's only for debugging and will make life easier. \d -- http://mail.python.org/mailman/listinfo/python-list

Re: A class question

2007-10-29 Thread Donn Ingle
> While Java's variable declarations bear a superficial (syntactical) > similarity to C, their semantics is in fact equivalent to the > object-reference semantics we know in Python. I come from Z80A/GWBASIC/VB and a little C, I would describe a Python variable as a pointer - in that it contains t

Re: How to find out if another process is using a file

2007-01-18 Thread Donn Cave
appropriate one. > > Use os.open with the O_EXCL flag; will fail if the other process has the > file still open (and will fail if another process is reading the file, too, > not just if someone is writing). O_EXCL fails if the file exists at all - whether closed or open. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: How to find out if another process is using a file

2007-01-18 Thread Donn Cave
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Nick Maclaren) wrote: > In article <[EMAIL PROTECTED]>, > Donn Cave <[EMAIL PROTECTED]> writes: > |> In article <[EMAIL PROTECTED]>, > |> "Gabriel Genellina" <[EMAIL PROTECTED]> wro

Re: Is any python like linux shell?

2007-01-22 Thread Donn Cave
In article <[EMAIL PROTECTED]>, James Stroud <[EMAIL PROTECTED]> wrote: ... > Paddy wrote:' > > Frank, > > IPython is great, but it is not a replacement for a shell like bash. If > > you have a Linux system then you still need to know the rudiments of > > bash > > Or better yet, csh. ;) Careful

Re: Repr or Str ?

2007-02-06 Thread Donn Cave
str() to force data to string type (that's what I mean by conversion.) If the object can't sensibly be converted to string type, then normally __str__ is omitted, and defaults to __repr__. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: IOError: [Errno 4] Interrupted system call

2007-02-07 Thread Donn Cave
't have signal handlers, sounds like a horrible idea to me. If your code has a signal handler for SIGCHLD, try to get rid of that - the handler itself is causing your problem. OO (Object Oriented?) doesn't have anything to do with the problem, that I can think of. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: os.popen and broken pipes

2007-02-09 Thread Donn Cave
les do not fulfill certain > critereia causing so_somehting() to return before the entire file is > processed. Most programming environments don't have this problem, though. If you like, your program can undo what Python does: signal.signal(signal.SIGPIPE, signal.SIG_DFL) for file

Re: f---ing typechecking

2007-02-15 Thread Donn Cave
gument handling, no. We know that without having to know anything about t, and not much about f. This is characteristic of tuple applications. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: f---ing typechecking

2007-02-16 Thread Donn Cave
In article <[EMAIL PROTECTED]>, Paul Rubin <http://[EMAIL PROTECTED]> wrote: > Donn Cave <[EMAIL PROTECTED]> writes: > > If t is a valid argument tuple for function f, then can t[1:] > > also be a valid argument tuple for function f? > > > > Fo

Re: IOError: [Errno 4] Interrupted system call

2007-02-16 Thread Donn Cave
gt; i'm struggling to figure this out. can you recommend any possible > methods of preventing this? for instance, could acquiring a thread > lock before calling popen solve the problem? No. Did you look at the text of the post you responded to here? What do you think about that advice? Do

Re: f---ing typechecking

2007-02-16 Thread Donn Cave
In article <[EMAIL PROTECTED]>, Paul Rubin <http://[EMAIL PROTECTED]> wrote: > Donn Cave <[EMAIL PROTECTED]> writes: > > Unpredictable? How do you manage to write functions in this case? > > Are all your formal parameter lists like (*a), with logic to d

Re: IOError: [Errno 4] Interrupted system call

2007-02-16 Thread Donn Cave
d that restart loop, actually reading one line at a time and appending to the line list. I'm not sure that's totally bulletproof - probably will work, but if you need a sure thing, I would go to UNIX I/O (posix.read), in a loop, and then split the concatenated results by newline. Or, of course if you could shut down the signals... Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: f---ing typechecking

2007-02-17 Thread Donn Cave
Quoth Paul Rubin <http://[EMAIL PROTECTED]>: | Donn Cave <[EMAIL PROTECTED]> writes: | > What this proves is that you can implement | > an argument list at run time, but it by no means changes the | > nature of the argument list as a sequence. | | Right, it's treated a

Re: Approaches of interprocess communication

2007-02-17 Thread Donn Cave
gh the loopback interface anyway, invariably regardless of host network implementation? Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

parsing string to a list of objects - help!

2007-11-05 Thread Donn Ingle
e - they are properties for every underscore I have glanced around at parsing and all the tech-speak confuses the heck out of me. I am not too smart and would appreciate any help that steers away from cold theory and simply hits at this problem. Donn. -- http://mail.python.org/mailman/listinfo/python-list

Re: parsing string to a list of objects - help!

2007-11-05 Thread Donn Ingle
Wow Paul, you have given me much to chew. I'll start testing it in my slow way -- it looks so simple! Thank you. \d -- http://mail.python.org/mailman/listinfo/python-list

Re: parsing string to a list of objects - help!

2007-11-05 Thread Donn Ingle
Paul, I quickly slapped your example into a py file for a first-glance test and the first part works, but the second gives me the error below. Could I have an old version of pyparser? I will dig into it anyway, just being lazy :) code: from pyparsing import * frame = Literal("#") tween = Word("-"

Re: parsing string to a list of objects - help!

2007-11-05 Thread Donn Ingle
Wow Paul, you have given me much to chew. I'll start testing it in my slow way -- it looks so simple! Thank you. \d -- http://mail.python.org/mailman/listinfo/python-list

pyparsing frames and tweens - take 2

2007-11-05 Thread Donn Ingle
Paul, > frame = Literal("#") > tween = Word("-") # that is, it is a "word" composed of 1 or more -'s > copy = Literal("=") > blank = Literal("_") > > animation = OneOrMore((frame + Optional( > (tween + FollowedBy(frame)) | > OneOrMore(copy | blank) ) ) ) I found that this form insists on having

Insane crazy question - printing commands

2007-11-06 Thread Donn Ingle
Hi, I'm doing something odd with pycairo and friends and I want to see what commands are coming out of my objects. Here's some code: class Box: def draw() self.context.set_source_rgb(1, 0, 0) self.context.rectangle(0, 00, 50, 50) self.context.fill() Box.draw() draws a red box, all fine. B

Re: Insane crazy question - printing commands

2007-11-06 Thread Donn Ingle
Thanks for the replies -- Python, is there anything it can't do? :D \d -- http://mail.python.org/mailman/listinfo/python-list

pyparsing and svg

2007-11-08 Thread Donn Ingle
Hi - I have been trying, but I need some help: Here's my test code to parse an SVG path element, can anyone steer me right? d1=""" M 209.12237 , 172.2415 L 286.76739 , 153.51369 L 286.76739 , 275.88534 L 209.12237 , 294.45058 L 209.12237 , 172.2415 z """ #Try it with no enters d1="""M 209.12

Re: easy 3D graphics for rendering geometry?

2007-11-08 Thread Donn Ingle
> I recommend taking a look at Blender 3D: http://www.blender.org/ Oh yeah, Blender is THE way to go. It's fantastic. \d -- http://mail.python.org/mailman/listinfo/python-list

Global variables within classes.

2007-11-09 Thread Donn Ingle
Hi, I'm getting myself really confused. I have three classes. Two of them need to reference the third, like so: Canvas ---> Stack <--- Thing I am doing this right now: s = Stack() And then within I am referring directly to the global variable 's' (and again from Thing). Now, this works, but i

Re: Global variables within classes.

2007-11-09 Thread Donn Ingle
>> I thought this might be a case for multiple inheritance > ??? Well, in terms of having Canvas and Thing inherit from Stack and thereby (somehow, not sure how) they would both have access to Stack.stack (a list) > wrt/ all Thing instances having to refer to a same Stack instance, > there's a pr

Re: Global variables within classes.

2007-11-09 Thread Donn Ingle
> I guess you mean "instances", not "classes". Yes. > Err...Perhaps a dumb question, but what about passing the "common > objects" to initializers ? > s = Stack() > c = Canvas(s) > t = Thing(s) Okay, I see where you're going. It's better than what I have at the moment. Thanks. \d -- http://m

Re: Global variables within classes.

2007-11-10 Thread Donn Ingle
Very interesting reply. I must ask a few questions, interleaved: > If you mean that all instances of Class Canvas and Thing will share > the *same* Stack, I think we can do it kind of like this: What's the difference between "same Stack" and "same instance of Stack"? I thought I knew what an insta

Re: Global variables within classes.

2007-11-10 Thread Donn Ingle
> The first creates an attribute of the class, the second creates an > attribute in the instance. Given that, can you clarify this: class Test: attribute = "original value" class Bob: def __init__(self): self.ref = Test() class Jim: def __init__(self): se

Re: Global variables within classes.

2007-11-10 Thread Donn Ingle
Included again for clarity: >> class Test: >> attribute = "original value" >> >> class Bob: >> def __init__(self): >> self.ref = Test() >> >> class Jim: >> def __init__(self): >> self.ref = Test() >> >> b = Bob() >> j = Jim() >> >> print b.ref.att

Re: Global variables within classes.

2007-11-10 Thread Donn Ingle
Thanks for your time and patience Marc, that was some hotshot ascii art. I'll have to take some time to digest this. \d -- http://mail.python.org/mailman/listinfo/python-list

Override method name and original method access

2007-11-12 Thread Donn Ingle
In an unusual twist of code I have a subclass which overrides a method but it also needs to call the original method: class One: def add (self, stuff): self.stuff.append(stuff) class Two(One): def __init__(self, otherstuff): (otherstuff) #otherstuff must go into list within the parent. #Th

Re: Override method name and original method access

2007-11-12 Thread Donn Ingle
> You need to be a new-style class (that is, you must inherit from > object) for super() to work. Problem is that my classes inherit already, from others I wrote. So, should I explicitly put (object) into the ones at the top? > Other than that, you are using it > correctly here. Well, even with

Re: Override method name and original method access

2007-11-13 Thread Donn Ingle
> One.add(self, otherstuff) Ah! Thanks - that makes more sense. Much appreciated. /d -- http://mail.python.org/mailman/listinfo/python-list

Re: Override method name and original method access

2007-11-13 Thread Donn Ingle
Chris Mellon wrote: > The use of super() > (and new style classes) should be the default implementation, To get some clarity on this subject, how do I make sure my classes are "new"? I've got the idea that my hierarchy must start from a base-class that explicitly derives from Object and not . I'

Looking for docs

2007-11-16 Thread Donn Ingle
Hi, I have seen strange looking things in various Python code like: staticmethod and also lines starting with an @ sign, just before method defs - I can't find an example right now. I have Python 2.5 installed with it's docs, but I can't find any discussion of 'new style' classes and other info.

Re: overriding methods - two questions

2007-11-16 Thread Donn Ingle
> for child in self.childrens: > if 'foo' in child.__class__.__dict__: > child.foo() Bruno, you're the man! I really must take the time to look into all those under-under score things! Thanks. /d -- http://mail.python.org/mailman/listinfo/python-list

overriding methods - two questions

2007-11-16 Thread Donn Ingle
Hi, Here's a framework for the questions: --- In a module, part of an API --- class Basis ( object ): def foo ( self, arg ): pass --- In user's own code --- class Child ( Basis ): def foo ( self, not, sure ): ... Question 1: Given that the user of the API can choose to override foo() or

Re: overriding methods - two questions

2007-11-16 Thread Donn Ingle
>This may help (on an old Python version): class Sam: pass class Judy: > ...def foo(self): pass > ... children = [Sam(), Judy(), Sam()] for child in children: hasattr(child, "foo") > ... > False > True > False That's not what my tests are showing. While Sam has no foo, it's

Re: overriding methods - two questions

2007-11-16 Thread Donn Ingle
> Actually, Python is complaining about your user's poor choice of > argument names. 'not' is a reserved keyword. My example was poor, but my actual test code did't use 'not'. Python simply checks the use of foo() to the local sig of foo() and does not go up the chain. This is understandable and

Re: overriding methods - two questions

2007-11-16 Thread Donn Ingle
>> While technically possible (using inspect.getargspec), trying to make >> your code idiot-proof is a lost fight and a pure waste of time. > Worse: it's actually counter-productive! > The whole idea of being able to subclass a class means that the user > should be able to override foo() *includi

Re: Global variables within classes.

2007-11-16 Thread Donn Ingle
Very interesting reply. I must ask a few questions, interleaved: > If you mean that all instances of Class Canvas and Thing will share > the *same* Stack, I think we can do it kind of like this: What's the difference between "same Stack" and "same instance of Stack"? I thought I knew what an insta

Re: overriding methods - two questions

2007-11-16 Thread Donn Ingle
> I am curious as to why you want to go through such contortions.  What > do you gain. for obj in list: if obj has a foo() method: a = something b = figureitout ( ) object.foo ( a, b ) I am accepting objects of any class on a stack. Depending on their nature I want to call certain methods

Re: overriding methods - two questions

2007-11-17 Thread Donn Ingle
> This is strictly a documentation matter, in my mind. Python does not > offer any means to enforce the calling sequence of an "override method". Yes, I hear you. > You might be able to wrap YOUR calling code with a try/except block > to trap errors if the callback doesn't like the "documented AP

Re: overriding methods - two questions

2007-11-17 Thread Donn Ingle
> *not* being called by the user but *by* my API (in a timeout loop). > > You don't know that. How can you possibly guarantee that the user won't > find some other use for the draw() method Well, as per your good examples, I would answer that as the parameters passed to draw() grow in number, so

Re: overriding methods - two questions

2007-11-17 Thread Donn Ingle
Thanks, good tips all-round. I have it working okay at the moment with all the suggestions. It may break in future, but that's another day :) /d -- http://mail.python.org/mailman/listinfo/python-list

Re: Python too complex ?!?!?!

2007-11-17 Thread Donn Ingle
I dunno about your dog :) but Python libs are not too demanding. From a Gnu/Linux pov with package managers things are quite simple. My wish is to find a way to make that even easier because the packaged modules are not always up to date. If the Cheese Shop could supply downloads of modules and

Re: python debugging...

2007-11-17 Thread Donn Ingle
I don't know if this will help you, but if you can, install "Eric". It's an IDE that I often use and you can do point and click debugging with breakpoints and nice displays of all vars and whatnot as you go. Much easier than fiddling with the debugger manually. /d -- http://mail.python.org/mail

Re: which Python ? asks beginner

2007-11-17 Thread Donn Ingle
> plans are afoot You know, I've always wanted ask; if plans are afoot, what are hands? :D Sorry, it's late. /d -- http://mail.python.org/mailman/listinfo/python-list

Re: Python too complex ?!?!?!

2007-11-17 Thread Donn Ingle
> Interesting idea, although it's not something I'd want included and > turned on by default. Should certainly be possible, though, with a > little __import__ magic. Well, since we're shooting the sh*t :), I tried in my one and only released app (Fonty Python) to wrap the imports in try clauses an

Re: which Python ? asks beginner

2007-11-18 Thread Donn Ingle
>> You know, I've always wanted ask; if plans are afoot, what are hands? > The answer, seeing as it's late, is that whisky is at hand. Ha. Brilliant answer! It also explains decorators :D /d -- http://mail.python.org/mailman/listinfo/python-list

Re: Function stopping a function

2007-11-22 Thread Donn Ingle
> For instance, lenghty_function() executes, when an > external event triggers cancel(), which is supposed to > abruptly stop lengthy_function(), reset some variables > and exit immediately. I would set a variable someplace (perhaps globally) that gets tested in lengthy_function()'s loop and issues

Catching a segfault in a Python library

2007-11-23 Thread Donn Ingle
Yo, An app of mine relies on PIL. When PIL hits a certain problem font (for unknown reasons as of now) it tends to segfault and no amount of try/except will keep my wxPython app alive. My first thought is to start the app from a bash script that will check the return value of my wxPython app and

Re: Catching a segfault in a Python library

2007-11-23 Thread Donn Ingle
> Run your app under a debugger and figure out what is making it crash. Already done, the code within PIL is causing the crash. It gets ugly and out of my remit. It's a freetype/Pil thing and I simply want to a way to catch it when it happens. Since a segfault ends the process, I am asking about "

Re: Is there pointer * in Python?

2007-11-23 Thread Donn Ingle
> think inside Python... Assuming you *can* think while being slowly crushed and digested :D \d -- http://mail.python.org/mailman/listinfo/python-list

Re: Catching a segfault in a Python library

2007-11-23 Thread Donn Ingle
> Well I think you should actually debug it, or at least reproduce it > and send a bug report to the PIL folks, It was a while ago, and if memory serves I did that, but memory fails. > but anyway you can use > os.wait() to get the exit status and recognize the seg fault. Okay, that's a good start

Re: Catching a segfault in a Python library

2007-11-23 Thread Donn Ingle
> You may have to roll your own fork/exec to start the wxpython, instead > of using popen or the subprocess module.  I'm not terribly conversant > in those modules but they may start a shell which would isolate your > program from the wxpython exit code. Hrmm... Neither am I, that's why I asked her

Re: Catching a segfault in a Python library

2007-11-24 Thread Donn Ingle
> I think the idea is, certain fonts in his collection may be corrupt, > and he wants to just scan through and load them, ignoring the ones > that make the program crash.   Ya got me! Sheesh, I can't hide anywhere :D > The bug in this case lies with a third > party and isn't something he can easi

Re: Catching a segfault in a Python library

2007-11-24 Thread Donn Ingle
Paul Rubin wrote: > then maybe your trap-and-restart approach can keep things usable for a > while. Trap and restart gracefully is the road I want to take. If my app (FP) chokes on a font (it will have made a note before doing what kills it, because I know the 'danger' areas ) and then will die. Th

Re: Catching a segfault in a Python library

2007-11-24 Thread Donn Ingle
MrJean1 wrote: > Try catching SIGSEGV using the Python signal module > > An example (for SIGALRM) is on the next page > > However, it may not work since a SIGSEGV fault is pretty much the end > of everything T

basic if stuff- testing ranges

2007-11-25 Thread Donn Ingle
Sheesh, I've been going spare trying to find how to do this short-hand: if 0 > x < 20: print "within" So that x must be > 0 and < 20. I usually do: if x > 0 and x < 20: print "within" What's the rule? Does it even exist? I read something like it recently on the list but can't find it, that's whe

Re: basic if stuff- testing ranges

2007-11-25 Thread Donn Ingle
> you mean : 0 < x < 20 ? Yes. I had gotten the impression that there was some Python form of: if NUMBER test VAR test NUMBER: Part of the question was to discover if I was smoking my socks :) > x in range(1,20) ? Sure, that's okay, but it has clarity issues, and is calling a func. >> but then a

Re: basic if stuff- testing ranges

2007-11-25 Thread Donn Ingle
Mel wrote: > if 0 < x < 20: > ? I take it I was tripping then. That's okay, it seemed a little too weird anyway :) \d -- http://mail.python.org/mailman/listinfo/python-list

Re: basic if stuff- testing ranges

2007-11-25 Thread Donn Ingle
> > if 0 > x: print "within" > Ah, I didn't know you could one could use the sarcasm.xml module and then use tags to influence Python commands. Most interesting... import sarcasm.xml I.fartIn( Your.Direction( general ) ) :D \d -- http://mail.python.org/mailman/listinfo/python-list

Re: basic if stuff- testing ranges

2007-11-25 Thread Donn Ingle
>> if 0 > x < 20: print "within" > That means "if x LESS THAN 0 and x < 20". Oh, bugger. It's tricky. > So try > if 0 < x < 20: Thanks. I was flipping signs in my tests, but I guess I flipped both and got myself all confused. > Likely manuals: Tutorial & Reference > Tutorial: check contents,

Re: basic if stuff- testing ranges

2007-11-26 Thread Donn Ingle
> The output of the following program might help: Hey, nifty! Thanks Paddy. \d -- http://mail.python.org/mailman/listinfo/python-list

Re: Need to call functions/class_methods etc using string ref :How

2007-11-26 Thread Donn Ingle
Well, I don't know all the answers, but you can start here: def boobs(): print "Oohh little birds!" b="boobs" >>>eval(b)() Ohhh little birds! Naturally, eval is going to run anything... Even code to format your drive. HTH \d -- http://mail.python.org/mailman/listinfo/python-list

Re: Need to call functions/class_methods etc using string ref :How

2007-11-26 Thread Donn Ingle
> I see someone already showed you eval.  Eval is evil.  Don't use it. > Especially if the functions are coming to you from a public URL! Yes, I suggested to him (by email) this: thisinstance =  SomeObject.__class__.__dict__ for f in yourlist:  if f in thisinstance: eval(f)(params) Which would

Re: Need to call functions/class_methods etc using string ref :How

2007-11-26 Thread Donn Ingle
> target = > for funcname in funclist: > func = getattr(target, funcname, None) > if callable(func): > func(*args, **kwargs) Nice. 'callable' is new to me. Live and learn :) \d -- http://mail.python.org/mailman/listinfo/python-list

Re: How to Teach Python "Variables"

2007-11-27 Thread Donn Cave
someone who learns Python concepts in terms of explanations like `boxes' or `pointers' or whatnot is at some disadvantage while that lasts, like translating a foreign language to your own instead of attaching meaning directly. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Gnu/Linux dialogue boxes in python

2007-11-30 Thread Donn Ingle
Paul Boddie wrote: > I didn't proceed any > further than a simple wrapping around KDialog, Zenity and Xdialog, > since the aim is to cover more than the usual UNIX-like platforms. > However, I could make that code available separately Thanks for the feedback and the links. I'd like to use your code

Re: Gnu/Linux dialogue boxes in python

2007-11-30 Thread Donn Ingle
> [1] http://www.python.org/pypi/desktop Oh, just saw this link and fetched the code -- will have a look around. \d -- http://mail.python.org/mailman/listinfo/python-list

Gnu/Linux dialogue boxes in python

2007-11-30 Thread Donn Ingle
Hi, Okay, so I am in the mood to try this: Inform the user about what modules the app requires in a graphical dialogue that can vary depending on what the system already has installed. (It will fail-to output on cli) I am running Kubuntu and I seem to have 'kdialog' installed by default (not sure

Re: Gnu/Linux dialogue boxes in python

2007-12-01 Thread Donn Ingle
Paul Boddie wrote: > but I'll > either upload a new release, or I'll make the code available > separately. Thanks, give me a shout when you do -- if you remember! \d -- http://mail.python.org/mailman/listinfo/python-list

i18n a Python app

2007-12-02 Thread Donn Ingle
Hi, I have been going spare looking for a tutorial or howto from my pov as a total beginner to i18n. I understand that one must use gettext, but there seems to be no good info about *how* one uses it. What command line utilities does one use to: 1. make a .pot file 2. make a .mo file Are there

Re: i18n a Python app

2007-12-02 Thread Donn Ingle
Another thought, how would one provide translations for doc strings? class Boo: """This class goes Boo!""" Can one do this, which does not seem likely: class Boo: _( "This class goes Boo!" ) \d -- http://mail.python.org/mailman/listinfo/python-list

Re: Gnu/Linux dialogue boxes in python

2007-12-02 Thread Donn Ingle
> But why?  Either > > (a) your program has a GUI and can display a dialogue box by itself > (b) your program has a GUI but has problems opening even a tiny part > of it (missing modules?), and should output diagnostics on the terminal > (c) your program is console-based, or a daemon or something,

String formatting with %s

2007-12-02 Thread Donn Ingle
Hi, I'm sure I one read somewhere that there is a simple way to set the order of replacements withing a string *without* using a dictionary. What I mean is: >>> s = "%s and %s" % ( "A", "B" ) >>> print s A and B Now, is there something quick like: >>> s = "%s/2 and %s/1" % ( "A", "B" ) >>> print

Re: String formatting with %s

2007-12-02 Thread Donn Ingle
> but not Python, AFAIK Damn! \d -- http://mail.python.org/mailman/listinfo/python-list

pprinting objects

2007-12-08 Thread Donn Ingle
Hi, Is there a way to get a dump of the insides of an object? I thought pprint would do it. If I had a class like this: class t: def __init__(self): self.x=1 self.y=2 self.obj = SomeOtherObj() Then it could display it as: t, x,1, y,2, obj, Or something like that -- a complete output

Re: pprinting objects

2007-12-08 Thread Donn Ingle
> AFAIK you have to roll your own. Here is a very rudimentary example: Very cool, thanks. \d -- http://mail.python.org/mailman/listinfo/python-list

setattr getattr confusion

2007-12-08 Thread Donn Ingle
Hi, Here's some code, it's broken: class Key( object ): def __init__(self): self.props = KeyProps() def __getattr__(self, v): return getattr( self.props,v ) def __setattr__(self,var,val): object.__setattr__(self.props,var,val) class KeyProps(object):

Re: setattr getattr confusion

2007-12-08 Thread Donn Ingle
> So you might want to describe your use-case. Um.. I wanted an object with Key to hold other data. I wanted a way to set that *other* data within Key without having to specify the "object in-between" everytime. k1.x = "ni!" should perform: k1.props.x = "ni!" and print k1.x should perform: print

Re: pprinting objects

2007-12-08 Thread Donn Ingle
> Define a __repr__ or __str__ method for the class Yes, then I could include the code John Machin suggested in there: for attr, value in sorted(self.__dict__.iteritems()): blah That will do nicely. Thanks all. \d -- http://mail.python.org/mailman/listinfo/python-list

callback confusion

2007-12-08 Thread Donn Ingle
Hi, I have two modules, the second is imported by the first. Let's call them one.py and two.py (two being my API) In the first I register a function into the second. [in one.py] def boo(): ... ... two.register( boo ) two.startLoop() In two.py it starts a loop (GTK timeout), so processing remains

Re: setattr getattr confusion

2007-12-08 Thread Donn Ingle
> class Key(object): > def __init__self): > self.__dict__['props'] = KeyProps() Okay - that's weird. Is there another way to spin this? > def __setattr__(self,var,val): > setattr(self.props,var,val) Perhaps by changing this one? \d -- http://mail.python.org/mailman/listinfo/python-list

Re: Basic animation in Python - how to

2007-12-08 Thread Donn Ingle
> Please refer me to some basic Python code for animation like that . You are in for a wild ride! Depending on your platform you can use dozens of different tools. Try wxPython, pyCairo, pyGTK and PIL (Python Imaging Library) for the most capable. Basically you are looking at a fairly complex thin

Re: setattr getattr confusion

2007-12-08 Thread Donn Ingle
Thanks Bruno, I had to keep coding, so I used the long form [Object.subobject.property = blah] anyway. It's long-winded, but unambiguous. \d -- http://mail.python.org/mailman/listinfo/python-list

<    1   2   3   4   5   >