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

parsing string to a list of objects - help!

2007-11-05 Thread Donn Ingle
Hi, I really hope someone can help me -- I'm stuck. I have written three versions of code over a week and still can't get past this problem, it's blocking my path to getting other code written. This might be a little hairy, but I'll try to keep it short. Situation: I want to pass a string to a

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

Re: callback confusion

2007-12-08 Thread Donn Ingle
> As far as I can tell, you have a bit more code in boo, and somewhere in > that code (after the print statement), you rebind the name 'kills'. Okay, yes: def boo() kills += 1 print kills > the absence of a global declaration, this makes this name a local > variable. I think I see what you mean

import X between submodules in a package

2007-12-18 Thread Donn Ingle
Hi, I'm sure this is a FAQ, but I have just not found clarity on the web/docs. (using monospaced type to show the tree) trunk:$ tree . fp |-- fontypython | |-- __init__.py | |-- cli.py | |-- config.py (I start it all with ./fp) fp says: import cli cli.py says: import os import config con

Re: Gnu/Linux dialogue boxes in python

2007-12-18 Thread Donn Ingle
> I've now uploaded a new release of the desktop module which is now, in > fact, a package: Thanks Paul, I saw it via the cheese shop rss. I have been too busy to read this list for a week. I will have a look in due course. \d -- http://mail.python.org/mailman/listinfo/python-list

Re: import X between submodules in a package

2007-12-19 Thread Donn Ingle
Chris wrote: > print cli.os.environ['HOME'] I was really confused by your reply until I saw the cli.os part. Okay, I see what you mean. \d -- http://mail.python.org/mailman/listinfo/python-list

Re: import X between submodules in a package

2007-12-19 Thread Donn Ingle
> would be a VeryBadThing(tm). :) > Having explicits imports in each module is good wrt/ readability. Okay, I can accept that. I worry that it's opening the module file over and over again - or does it open it once and kind of re-point to it when it hits a second import of the same thing? > pac

Re: import X between submodules in a package

2007-12-19 Thread Donn Ingle
> You guess. When fisrt imported, the module's source is executed, a > module object is created and stored in sys.modules, and the needed names > are inserted into the importing module's namespace. Next times the > module is "served" directly from sys.modules. Peachy, thanks. \d -- http://mail.

Sorting Objects by property using locale

2007-12-21 Thread Donn Ingle
Hi, Well, I'm beat. I can't wrap my head around this stuff. I need to create a list that will contain objects sorted by a "name" property that is in the alphabetical order of the user's locale. I used to have a simple list that I got from os.listdir and I could do this: l = os.listdir(".") l.so

Re: Sorting Objects by property using locale

2007-12-21 Thread Donn Ingle
In follow-up: I think this should work: # -*- coding: utf8 -*- import locale locale.setlocale( locale.LC_ALL, "" ) class Test(object): def __init__(self,nam): self.name = nam def __cmp__(self, other): return cmp(self.name, other.name) l = [ Test("ABILENE.ttf"), Te

Re: Sorting Objects by property using locale

2007-12-21 Thread Donn Ingle
> Which is even more correct than I hoped for -- in Norwegian, aa is > pronounced the same as å (which is the 29th letter in the Norwegian > alphabet) and is sorted according to pronunciation. Much appreciated bjorn. \d -- http://mail.python.org/mailman/listinfo/python-list

i18n questions

2007-12-28 Thread Donn Ingle
Hi, A soon-to-be happy new year to everyone! I'm 100% new to this i18n lark and my approach so far has been to create a .mo file per module in my app. My thinking was, why load one huge .mo file when a single module only needs a few strings? Since then, it seems, I have made the wrong decision.

Re: i18n questions

2007-12-28 Thread Donn Ingle
Thanks for taking the time to post those links. I have read most of them before. They don't seem to cover the basic issue in my OP, but i18n on Python is a dark art and maybe there's something I missed. \d -- http://mail.python.org/mailman/listinfo/python-list

Re: i18n questions

2007-12-28 Thread Donn Ingle
Is there a group better suited to gettext/i18n questions of this sort? Just wondering because I have little time left to finish my "December" project! > How does one 'merge' gettext.translations objects together? Or is that > insane? > > What's the best way to handle a project with multiple domai

Re: i18n questions

2007-12-29 Thread Donn Ingle
Thorsten Kampe wrote: > gettext.textdomain('optparse') > gettext.install('script', unicode = True) They speak of a 'global' domain in the docs, but (as is my usual beef with the Python docs -- see PHP docs for sterling help) there is no clarity. It *sounds* like there can be a .mo file for *eve

LANG, locale, unicode, setup.py and Debian packaging

2008-01-12 Thread Donn Ingle
Hello, I hope someone can illuminate this situation for me. Here's the nutshell: 1. On start I call locale.setlocale(locale.LC_ALL,''), the getlocale. 2. If this returns "C" or anything without 'utf8' in it, then things start to go downhill: 2a. The app assumes unicode objects internally. i.e.

piping into a python script

2008-01-24 Thread Donn Ingle
Hi, (Gnu/Linux - Python 2.4/5) Given these two examples: 1. ./fui.py *.py 2. ls *.py | ./fui.py How can I capture a list of the arguments? I need to get all the strings (file or dir names) passed via the normal command line and any that may come from a pipe. There is a third case: 3. ls *.jpg |

Re: piping into a python script

2008-01-24 Thread Donn Ingle
> Try the fileinput module. I did give the fileinput module a go, but I can't find much info on it and the help is ... well, it's python help ;) > in goes to its stdin where it is processed if it has an argument of - > fileinput works that way Okay, I did think of the dash, but did not know how to

Re: piping into a python script

2008-01-24 Thread Donn Ingle
Paddy wrote: > ls *.a | ./fui.py -f - *.b To be sure I grok this: I am seeing the single dash as a placeholder for where all the piped filenames will go, so *.b happens after *.a has been expanded and they all get fed to -f, right? I'm also guessing you mean that I should detect the single dash an

Re: piping into a python script

2008-01-24 Thread Donn Ingle
Paddy wrote: > fileinput is set to process each file a line at a time unfortunately. Wow. So there seems to be no solution to my OP. I'm amazed, I would have thought a simple list of strings, one from stdin and one from the args, would be easy to get. I *really* don't want to open each file, that

Re: piping into a python script

2008-01-25 Thread Donn Ingle
Nick Craig-Wood wrote: > This iterates over the lines of all files listed in sys.argv[1:], > defaulting to sys.stdin if the list is empty. If a filename is '-', it > is also replaced by sys.stdin. To specify an alternative list of > filenames, pass it as the first argument to input(). A single fil

Re: piping into a python script

2008-01-25 Thread Donn Ingle
Hexamorph wrote: > It's a bit clumsy, but seems to do what I guess you want. Hey, thanks for that! I will have a go. \d -- http://mail.python.org/mailman/listinfo/python-list