Re: withhacks module (Re: Code redundancy)

2010-04-21 Thread python
Ryan, > So if you don't care about portability or about that dirty feeling you get > from messing with the Python internals, then have at it :-) Warnings aside, its very clever code. Thanks for sharing! Malcolm -- http://mail.python.org/mailman/listinfo/python-list

Re: withhacks module (Re: Code redundancy)

2010-04-21 Thread Ryan Kelly
On Wed, 2010-04-21 at 19:43 -0400, pyt...@bdurham.com wrote: > Ryan, > > Your withhacks module looks very interesting. > http://pypi.python.org/pypi/withhacks > > What are your specific concerns about its use? Are there portability > concerns? It combines two things you just don't see in respec

withhacks module (Re: Code redundancy)

2010-04-21 Thread python
Ryan, Your withhacks module looks very interesting. http://pypi.python.org/pypi/withhacks What are your specific concerns about its use? Are there portability concerns? Malcolm -- http://mail.python.org/mailman/listinfo/python-list

Re: Code redundancy

2010-04-21 Thread Alan Harris-Reid
Ryan Kelly wrote: On Tue, 2010-04-20 at 14:43 +0100, Alan Harris-Reid wrote: Hi, During my Python (3.1) programming I often find myself having to repeat code such as... class1.attr1 = 1 class1.attr2 = 2 class1.attr3 = 3 class1.attr4 = 4 etc. Is there any way to achieve the same result wi

Re: Code redundancy

2010-04-21 Thread Ryan Kelly
On Tue, 2010-04-20 at 14:43 +0100, Alan Harris-Reid wrote: > Hi, > > During my Python (3.1) programming I often find myself having to repeat > code such as... > > class1.attr1 = 1 > class1.attr2 = 2 > class1.attr3 = 3 > class1.attr4 = 4 > etc. > > Is there any way to achieve the same result wit

Re: Re: Code redundancy

2010-04-21 Thread Alan Harris-Reid
Andreas Löscher wrote: You can do something like this: class A(): pass inst=) exec(""" ... a= ... b=2 ... c=3 ... d=4 ... """) in inst.__dict__ inst.a 1 This executes the Statement in the exec function and uses inst.__dict__ as namespace. But be aware, that this

Re: Code redundancy

2010-04-21 Thread Andreas Löscher
You can do something like this: >>> class A(): pass >>> inst=A() >>> exec(""" ... a=1 ... b=2 ... c=3 ... d=4 ... """) in inst.__dict__ >>> inst.a 1 >>> This executes the Statement in the exec function and uses inst.__dict__ as namespace. But be aware, that this is not recommended. If you mess w

Re: Code redundancy

2010-04-21 Thread Jean-Michel Pichavant
Alan Harris-Reid wrote: Jean-Michel Pichavant wrote: Alan Harris-Reid wrote: Hi, During my Python (3.1) programming I often find myself having to repeat code such as... class1.attr1 = 1 class1.attr2 = 2 class1.attr3 = 3 class1.attr4 = 4 etc. Is there any way to achieve the same result with

Re: Code redundancy

2010-04-20 Thread Alan Harris-Reid
Ethan Furman wrote: Alan Harris-Reid wrote: The code is not usually in class.__init__ (otherwise I would have used the self. prefix), but I like your self.__dict__.update(...) solution and I'll try and remember it. The code I was thinking of goes something like as follows (don't have a speci

Re: Code redundancy

2010-04-20 Thread Alan Harris-Reid
Chris Rebert wrote: On Tue, Apr 20, 2010 at 2:59 PM, Alan Harris-Reid wrote: Stefan Behnel wrote: Alan Harris-Reid, 20.04.2010 15:43: During my Python (3.1) programming I often find myself having to repeat code such as... class1.attr1 = 1 class1.attr2 = 2 class1.attr3 = 3 clas

Re: Code redundancy

2010-04-20 Thread Alan Harris-Reid
Xavier Ho wrote: On Wed, Apr 21, 2010 at 7:59 AM, Alan Harris-Reid mailto:aharrisr...@googlemail.com>> wrote: The code is not usually in class.__init__ (otherwise I would have used the self. prefix) Alan, if your variables are not usually in __init__, what's preventing you from using

Re: Code redundancy

2010-04-20 Thread Ethan Furman
Alan Harris-Reid wrote: The code is not usually in class.__init__ (otherwise I would have used the self. prefix), but I like your self.__dict__.update(...) solution and I'll try and remember it. The code I was thinking of goes something like as follows (don't have a specific example to hand,

Re: Re: Code redundancy

2010-04-20 Thread Chris Rebert
On Tue, Apr 20, 2010 at 2:59 PM, Alan Harris-Reid wrote: > Stefan Behnel wrote: >> Alan Harris-Reid, 20.04.2010 15:43: >>> During my Python (3.1) programming I often find myself having to repeat >>> code such as... >>> >>> class1.attr1 = 1 >>> class1.attr2 = 2 >>> class1.attr3 = 3 >>> class1.attr4

Re: Re: Code redundancy

2010-04-20 Thread Xavier Ho
On Wed, Apr 21, 2010 at 7:59 AM, Alan Harris-Reid < aharrisr...@googlemail.com> wrote: > The code is not usually in class.__init__ (otherwise I would have used the > self. prefix) Alan, if your variables are not usually in __init__, what's preventing you from using class variables like this: >>

Re: Re: Code redundancy

2010-04-20 Thread Alan Harris-Reid
Stefan Behnel wrote: Alan Harris-Reid, 20.04.2010 15:43: During my Python (3.1) programming I often find myself having to repeat code such as... class1.attr1 = 1 class1.attr2 = 2 class1.attr3 = 3 class1.attr4 = 4 etc. Is there any way to achieve the same result without having to repeat the cla

Re: Re: Code redundancy

2010-04-20 Thread Alan Harris-Reid
Iain King wrote: On Apr 20, 2:43 pm, Alan Harris-Reid wrote: Hi, During my Python (3.1) programming I often find myself having to repeat code such as... class1.attr1 = class1.attr2 = class1.attr3 = class1.attr4 = etc. Is there any way to achieve the same result without having to repeat th

Re: Re: Code redundancy

2010-04-20 Thread Alan Harris-Reid
Peter Otten wrote: Alan Harris-Reid wrote: Hi, During my Python (3.1) programming I often find myself having to repeat code such as... class1.attr1 = 1 class1.attr2 = 2 class1.attr3 = 3 class1.attr4 = 4 etc. Is there any way to achieve the same result without having to repeat the class1 p

Re: Code redundancy

2010-04-20 Thread Alan Harris-Reid
Jean-Michel Pichavant wrote: Alan Harris-Reid wrote: Hi, During my Python (3.1) programming I often find myself having to repeat code such as... class1.attr1 = 1 class1.attr2 = 2 class1.attr3 = 3 class1.attr4 = 4 etc. Is there any way to achieve the same result without having to repeat the

Re: Code redundancy

2010-04-20 Thread Jean-Michel Pichavant
Alan Harris-Reid wrote: Hi, During my Python (3.1) programming I often find myself having to repeat code such as... class1.attr1 = 1 class1.attr2 = 2 class1.attr3 = 3 class1.attr4 = 4 etc. Is there any way to achieve the same result without having to repeat the class1 prefix? Before Python

Re: Code redundancy

2010-04-20 Thread Peter Otten
Alan Harris-Reid wrote: > Hi, > > During my Python (3.1) programming I often find myself having to repeat > code such as... > > class1.attr1 = 1 > class1.attr2 = 2 > class1.attr3 = 3 > class1.attr4 = 4 > etc. > > Is there any way to achieve the same result without having to repeat the > class1

Re: Code redundancy

2010-04-20 Thread Iain King
On Apr 20, 2:43 pm, Alan Harris-Reid wrote: > Hi, > > During my Python (3.1) programming I often find myself having to repeat > code such as... > > class1.attr1 = 1 > class1.attr2 = 2 > class1.attr3 = 3 > class1.attr4 = 4 > etc. > > Is there any way to achieve the same result without having to rep

Re: Code redundancy

2010-04-20 Thread Stefan Behnel
Alan Harris-Reid, 20.04.2010 15:43: During my Python (3.1) programming I often find myself having to repeat code such as... class1.attr1 = 1 class1.attr2 = 2 class1.attr3 = 3 class1.attr4 = 4 etc. Is there any way to achieve the same result without having to repeat the class1 prefix? Before Pyt

Code redundancy

2010-04-20 Thread Alan Harris-Reid
Hi, During my Python (3.1) programming I often find myself having to repeat code such as... class1.attr1 = 1 class1.attr2 = 2 class1.attr3 = 3 class1.attr4 = 4 etc. Is there any way to achieve the same result without having to repeat the class1 prefix? Before Python my previous main languag

Re: Decrease code redundancy without breaking references

2008-10-12 Thread Frank Malina @ vizualbod.com
There is the following source structure: /packages/... /packages/global_settings.py # this is the global settings file imported from each client settings file /clients/... /clients/client1/settings.py # client specific settings file (see code above), each client is running in its own process so th

Re: Decrease code redundancy without breaking references

2008-10-11 Thread Chris Rebert
for cfg in settings_modules: cfg.TEMPLATE_DIRS = ("/clients/"+ cfg.SITE_FOLDER+"/templates", "/packages/apps/templates") cfg.MEDIA_FILES_PREFIX = 'http://'+ cfg.SITE_DOMAIN+'/media/' cfg.VIDEO_FILES_URL = 'http://'+ cfg.SITE_DOMAIN+'/video/' cfg.VIDEO_FILES_ROOT = '/clients/'+ cfg.S

Decrease code redundancy without breaking references

2008-10-11 Thread bmalinova
My settings file --- from global_settings import * SITE_FOLDER = 'mypipe' SITE_DOMAIN = 'localhost' SITE_NAME = 'My Pipe' SITE_ID = 1 TEMPLATE_DIRS = ("/clients/"+SITE_FOLDER+"/templates", "/packages/apps/ templates") MEDIA_FILES_PREFIX = 'http://'+SITE_DOMAIN+'/medi