Bug/Patch: Problem with xml/__init__.py when using freeze.py

2008-01-31 Thread glomde
Hi, I tried to do freeze.py for my script that uses ElementTree. But got the this error: File "/usr/lib/python2.5/xml/__init__.py", line 45, in _xmlplus.__path__.extend(__path__) AttributeError: 'str' object has no attribute 'extend' The reason seems that _xmlplus.__path__ is a string a

runscript module, where are the docs...

2008-01-29 Thread glomde
Hi! I am going through some code and found import runscript BUT I cant find and information about this module. I searched Google did a grep in the /usr/lib/python directory. What is the purpose of this module and where can I find information about it. Or the source. Best regards, Toni -- htt

possible to overide setattr in local scope?

2008-01-22 Thread glomde
In a class it is poosible to override setattr, so that you can decide how you should handle setting of variables. Is this possible to do outside of an class on module level. mysetattr(obj, var, value): print "Hello" So that test = 5 would print Hello -- http://mail.python.org/mailman/listi

Re: is it possible to set namespace to an object.

2008-01-22 Thread glomde
On 21 Jan, 22:00, George Sakkis <[EMAIL PROTECTED]> wrote: > On Jan 21, 2:52 pm, glomde <[EMAIL PROTECTED]> wrote: > > > > > On 21 Jan, 20:16, George Sakkis <[EMAIL PROTECTED]> wrote: > > > > On Jan 21, 1:56 pm, glomde <[EMAIL PROTECTED]> wr

Re: is it possible to set namespace to an object.

2008-01-21 Thread glomde
On 21 Jan, 20:16, George Sakkis <[EMAIL PROTECTED]> wrote: > On Jan 21, 1:56 pm, glomde <[EMAIL PROTECTED]> wrote: > > > > > On 21 Jan, 18:59, Wildemar Wildenburger > > > <[EMAIL PROTECTED]> wrote: > > > glomde wrote: > > > > Hi

Re: is it possible to set namespace to an object.

2008-01-21 Thread glomde
On 21 Jan, 18:59, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > glomde wrote: > > Hi, > > > is it somehow possible to set the current namespace so that is in an > > object. > > [snip] > > set namespace testObj > > Name = "Test"

is it possible to set namespace to an object.

2008-01-21 Thread glomde
Hi, is it somehow possible to set the current namespace so that is in an object. Somthing like. class Test(): testObj = Test() set namespace testObj Name = "Test" Name would set testObj.Name to "Test". I was thinking this could be done with the with statement somehow (without using

Re: How to set a class inheritance at instance creation?

2007-05-29 Thread glomde
On 29 Maj, 22:45, Steve Holden <[EMAIL PROTECTED]> wrote: > glomde wrote: > > Hi I wonder if you can set what subclass a class should > > have at instance creation. > > > The problem is that I have something like: > > > class CoreLang(): > > def A

Re: How to set a class inheritance at instance creation?

2007-05-29 Thread glomde
On 29 Maj, 19:20, Ramashish Baranwal <[EMAIL PROTECTED]> wrote: > On May 29, 8:52 pm, glomde <[EMAIL PROTECTED]> wrote: > > > > > Hi I wonder if you can set what subclass a class should > > have at instance creation. > > > The problem is tha

Re: How to set a class inheritance at instance creation?

2007-05-29 Thread glomde
t calls submethods. and thes submethods should be overriden by the subclasses. So I cant change the name on the submethods. > > On May 29, 8:52 am, glomde <[EMAIL PROTECTED]> wrote: > > > Hi I wonder if you can set what subclass a class should > > have at instance crea

How to set a class inheritance at instance creation?

2007-05-29 Thread glomde
Hi I wonder if you can set what subclass a class should have at instance creation. The problem is that I have something like: class CoreLang(): def AssignVar(self, var, value): pass class Lang1(CoreLang): def AssignVar(self, var, value): return var, "=", value class

Re: Good idea to use a class as function with __new__?

2007-05-28 Thread glomde
Gabriel Genellina wrote: > def __call__(self, *args, **kwds): > return self.__TemplateMethod(*args, **kwds) > > x = Template()(prefix="foo") > or perhaps: > x = Template(prefix="foo")() > > I think the extra () improves readability - it's clear that x comes from a > function call, it

Good idea to use a class as function with __new__?

2007-05-28 Thread glomde
Hi, I am implementing som code generation and want to to use some variant of the template method pattern. What I came up with is to have a class with the common part in a method and the subclasses can then override the Customize methods to do their own special part. Now to the question I use the

Re: Why doesnt __getattr__ with decorator dont call __get_method in decorator

2007-03-29 Thread glomde
> To get python to run the __get__ method I think you have to call > __getattr__ explicitly: > a.__getattr__('test') > > If you do: > a.test > python follows a different routine: it checks for the existence of the > attribute, then check if there is a __getattr__ attribute. Now the > speculative b

Re: Why doesnt __getattr__ with decorator dont call __get_method in decorator

2007-03-28 Thread glomde
On Mar 28, 4:47 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > glomde <[EMAIL PROTECTED]> wrote: > > Hi, > > > I tried to write a decorator for that should be for methods but for > > some reasons > > it doens seem to work when you try to do it on the __getatt

Why doesnt __getattr__ with decorator dont call __get_method in decorator

2007-03-28 Thread glomde
Hi, I tried to write a decorator for that should be for methods but for some reasons it doens seem to work when you try to do it on the __getattr__ method in a class. Could anybody give some hints why this is? Example: class decoratorTest(object): def __init__(self, func): self.func =

Re: Proposal for new operators to python that add syntactic sugar for hierarcical data.

2006-05-18 Thread glomde
So I read trough all of the make PEP and make would support the syntax i propose.. and more generic and better in many ways. Since it was rejected I have to continue live with my preprocessor... >From the make PEP . Allowing this sort of customization could allow XML to be written without rep

Re: Proposal for new operators to python that add syntactic sugar for hierarcical data.

2006-05-18 Thread glomde
> We already have this (quite close to) this syntax: > > class (super): > = * > [class *] > > There's also the Zope3 'implements' trick, that allow to modify the > class namespace without assignement: > > class : > (*args, **kw)* > > So what you want is very certainly doable without any syntax

Re: Proposal for new operators to python that add syntactic sugar for hierarcical data.

2006-05-18 Thread glomde
> What you are trying to achieve is to make syntactic sugar for making namespace > definitions look nicer. But: the way you are trying to do so isn't pythonic, > because there isn't one obvious way how your proposal works; you're not even > specifying a proper semantic interpretation of your syntax

Re: Proposal for new operators to python that add syntactic sugar for hierarcical data.

2006-05-18 Thread glomde
I'm answering two of you posts here... > Sweet Lord, have mercy ! > > > Which should create myList = [[0..9], {0:0, ... 9:9}] > > myList = [ > range(10), > dict((i, i) for i in range(10)) > ] > Let's talk about readability My code was just to show that the proposal is not only for HTML

Re: Proposal for new operators to python that add syntactic sugar for hierarcical data.

2006-05-18 Thread glomde
> What about writing a mini-language that gets translated to Python? Think of > Cheetah, which does exactly this (albeit not being limited to templating HTML > data). I have implemented my proposal as preprocessor. And it works fine. But my proposal in not only for HTML it can be used for all hier

Re: Proposal for new operators to python that add syntactic sugar for hierarcical data.

2006-05-18 Thread glomde
> Adding ugly and unintuitive "operators" to try to turn a general purpose > programming language into a half-backed unusable HTML templating > language is of course *much* more pythonic... IT is not only for HTML. I do think html and xml are the biggest creators of hierarcical treestructures. But

Re: Proposal for new operators to python that add syntactic sugar for hierarcical data.

2006-05-18 Thread glomde
> Here's a nice stan example, taken from Kieran Holland's tutorial > http://www.kieranholland.com/code/documentation/nevow-stan/ I took a quick look and it looks nice as long as your page is static. But I couldnt se how you could mix in python code seamlessy when creating your tree. But I might b

Re: Proposal for new operators to python that add syntactic sugar for hierarcical data.

2006-05-18 Thread glomde
> What about using data for nodes and '=' for attributes ? > Would look like: > > > > Page Title > > > Hello World > > > > > I think that with the added syntax you get better view of the html > > page. > > indeed !-) I dont think it is very pythonic :-). You dont use endtags

Re: Proposal for new operators to python that add syntactic sugar for hierarcical data.

2006-05-18 Thread glomde
> You also repeat yourself: head("head"), title("title"), body("body") > > What about this: > > # build a tree structure > root = ET.Element("html") > !root > !head > !title > if A is True: > &text = "Page A" > else: > &text = "Page B" > !body > &bgc

Re: Proposal for new operators to python that add syntactic sugar for hierarcical data.

2006-05-18 Thread glomde
> You can put any python expression in there, and in the Node class you can do > what you want. But the main advantage is any python code not only expressions. In addition to that you get nice flow style. Can set variables which you later use as want. > Seems that you are after a templating-syste

Re: Proposal for new operators to python that add syntactic sugar for hierarcical data.

2006-05-18 Thread glomde
Actually we did start of with YAML, but realised that we need to have the power of a programming language aswell. But I wanted to come up with something that looked very clos to YAML since I find it quite readable. I have implemented the syntax, but as a preprocessor for python and it works quite

Re: Proposal for new operators to python that add syntactic sugar for hierarcical data.

2006-05-18 Thread glomde
But you cant mix python code in there when creating the nodes. That is when it gets quite ugly an unreadable according to me. But I also relly do think that this: # build a tree structure root = ET.Element("html") *!*root: *!*head("head"): *!*title("title): *=*text

Re: Proposal for new operators to python that add syntactic sugar for hierarcical data.

2006-05-17 Thread glomde
There are some difference which are quite essential. First of all I dont se how you set attributes with that and then I dont see how you can mix python code with the creation. So how do you do this: root = ET.Element("html") *!*root: *!*head("head"): *!*title("title): fo

Proposal for new operators to python that add syntactic sugar for hierarcical data.

2006-05-17 Thread glomde
i I would like to extend python so that you could create hiercical tree structures (XML, HTML etc) easier and that resulting code would be more readable than how you write today with packages like elementtree and xist. I dont want to replace the packages but the packages could be used with the new

Re: Tabs versus Spaces in Source Code ('semantic' vs. arbitrary indentation)

2006-05-17 Thread glomde
> But generally, I don't do layout like that. I'd do: > >--->cursor.execute( >--->--->--->'select id, item, amount, field4, >--->--->--->'from table1 where amount>100' >--->) > >Which keeps looking fine, no matter what tab size, and without mixing >tabs and spaces. > Which only wor

Re: compiling module from string and put into namespace

2006-05-13 Thread glomde
Ok, now I think I know what I need to do. I need to create a variable in the calling functions locals. So how do I get access to the calles locals dictionary? Is it possible? -- http://mail.python.org/mailman/listinfo/python-list

Re: compiling module from string and put into namespace

2006-05-13 Thread glomde
> I dont want the caller to call import but a function. come again? >>> type (__builtins__.__import__) I didnt mean that __import__ isnt a function, but that I want to make a function called ImoprtFile that actually does something very similar that what __import__. So to rephrsase the questi

Re: compiling module from string and put into namespace

2006-05-12 Thread glomde
Tanks but that isn't what I am looking for. I really want a function that you can call and imports the module into the calling functions namespace. I dont want the caller to call import but a function. -- http://mail.python.org/mailman/listinfo/python-list

compiling module from string and put into namespace

2006-05-12 Thread glomde
Hi, I want to create a function that preprocesses a file and then imports the parsed file. What I found out is that you can do something like this: def ImportFile(fileName): parsedCode = Parser(fileName).Parse() module = new.module(name) exec parsedCode in module.__dict__ sys.mod

Re: What to use for adding syntax for hierarcical trees, metaclasses, tokenize.py or PLY?

2006-05-09 Thread glomde
Thanks, but the thing is that I want to have the syntactical sugar. And I think that you could use elementtree or xist or any other python tree structure module at the bottom. It could be quite generic. And with the syntactical sugar I find it a lot more readable. A little bit like yaml, but you

What to use for adding syntax for hierarcical trees, metaclasses, tokenize.py or PLY?

2006-05-09 Thread glomde
Hi I would like to extend python so that you could create hiercical tree structures (XML, HTML etc) easier and that resulting code would be more readable. The syntax i would like is something like the below: # Example creating html tree '*!*' is an operator that creates an new node '*=*' is an o