473,378 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Decrease code redundancy without breaking references

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+'/media/'
VIDEO_FILES_URL = 'http://'+SITE_DOMAIN+'/video/'
VIDEO_FILES_ROOT = '/clients/'+SITE_FOLDER+'/video'
__________________________________

The first 4 settings are unique to every setting file.

The last 4 lines (TEMPLATE_DIRS - MEDIA_ROOT) are always based on the
SITE_FOLDER and SITE_DOMAIN and are the same in all my config files.

How can I separate the last 4 lines repetitive lines (I need to DRY
the code)?

Frank
http://vizualbod.com
Oct 12 '08 #1
2 915
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.SITE_FOLDER+'/video'
Without more information about how your code is structured, it's hard
to give more precise advice.

Cheers,
Chris
--
Follow the path of the Iguana...
http://rebertia.com
On Sat, Oct 11, 2008 at 7:28 PM, <bm*******@gmail.comwrote:
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+'/media/'
VIDEO_FILES_URL = 'http://'+SITE_DOMAIN+'/video/'
VIDEO_FILES_ROOT = '/clients/'+SITE_FOLDER+'/video'
__________________________________

The first 4 settings are unique to every setting file.

The last 4 lines (TEMPLATE_DIRS - MEDIA_ROOT) are always based on the
SITE_FOLDER and SITE_DOMAIN and are the same in all my config files.

How can I separate the last 4 lines repetitive lines (I need to DRY
the code)?

Frank
http://vizualbod.com
--
http://mail.python.org/mailman/listinfo/python-list
Oct 12 '08 #2
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 they never clash
/clients/client2/settings.py
/clients/client3/settings.py
....
Now how to remove the repetitive bork, bork, bork if it relies on the
clients settings.
I am still learning python, help appreciated.

Oct 12 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
13
by: python | last post by:
hello and thanks for reading this, i have been a dos/windows user using some form of the basic language for 30 years now. i own and run a small programming company and there is one feature that...
52
by: entropy123 | last post by:
Hey all, I'm working with some legacy C code and I would like to compile it as a CPP file. I get the following error message: driver.cpp:87: cannot convert `void *' to `GenericStruct *' in...
14
by: nullptr | last post by:
Hi, As an exercise, I've written a program implementing run-length encoding. I would be more that happy to hear your comments, suggestions, etc Thanks, --- #include <stdio.h> #include...
25
by: Alvin Bruney | last post by:
C# is great but it does have some short comings. Here, I examine one of them which I definitely think is a shortcoming. Coming from C++, there seems to be no equivalent in C# to separate code...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
5
by: Alex Glass | last post by:
I'm concerned a commercial application I've completed could be stolen by deobsfuscation. However it's not clear to me what information is gained when my .net executable is deobsfuscated...
4
by: Dave White | last post by:
Hello Everyone, I have the following 3 tables setup:(Thanks Marsh!) Students Table StudentID (1 to many) Last First Class (Class Name) Period ( 1 to 8)
3
by: lee.walczak | last post by:
Hi, I have just started writing a GUI using wxpython after finding a limitation using Tkinter. I have read most tutorials on wxpython and slowly becoming accustomed considering I started with...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.