473,385 Members | 1,912 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,385 software developers and data experts.

refactoring question

Hi, I'm doing a sort of symbolic linking app in Windows for my own
enjoyment, and figured I would do it in python for the same reason +
learning the language.

The following functions could obviously do with some refactoring. One
obvious thing would be to make wordsetter and wordsforfolder more
generic, and just pass a few extra parameters. But that seems sort of
stupid.

Any suggestions on refactoring here? other improvements?
def getwordslist(word):
thisword = wordpath + word + ".xml"
if exists(thisword):
doc = xml.dom.minidom.parse(thisword)
loc = doc.childNodes[0]
for i in range(0, len(loc.childNodes)):
if (loc.childNodes[i].firstChild.data == thispath):
break
else:
wordsetter(thisword,doc,loc)
else :
doc = xml.dom.minidom.Document()
loc = doc.createElementNS("", "locations")
doc.appendChild(loc)
wordsetter(thisword,doc,loc)

return None

def getfolderwords(word):

if exists(normpath(folderwords)):
doc = xml.dom.minidom.parse(folderwords)
loc = doc.childNodes[0]
wordsforfolder(word,doc,loc)
else :

doc = xml.dom.minidom.Document()
loc = doc.createElementNS("", "wordlist")
doc.appendChild(loc)
xml.dom.ext.PrettyPrint(doc, open(normpath(folderwords), "w"))
wordsforfolder(word,doc,loc)

return None
def wordsetter(word,doc,loc):
thisloc = doc.createElementNS("", "location")
xexpr= "//location[.='" + thispath + "']"

xp = Evaluate(xexpr,doc.documentElement)
if len(xp) < 1:

loc.appendChild(thisloc)
text = doc.createTextNode(thispath)
thisloc.appendChild(text)
fi = open(word, "w")
fi.write(doc.toxml())
def wordsforfolder(word,doc,loc):
thisloc = doc.createElementNS("", "word")
xexpr= "//word[.='" + word + "']"

xp = Evaluate(xexpr,doc.documentElement)
if len(xp) < 1:

loc.appendChild(thisloc)
text = doc.createTextNode(word)
thisloc.appendChild(text)
fi = open(folderwords, "w")
fi.write(doc.toxml())
Cheers,

Bryan Rasmussen
May 4 '06 #1
0 963

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

Similar topics

9
by: Peter Dembinski | last post by:
I am trying to write Master Thesis on refactoring Python code. Where should I look for information? -- http://www.dembiński.prv.pl
4
by: | last post by:
Hi, Refactoring a winform causes problems if moving this form to a subdirectory in the same project. What is the workaround for this and will this be fixed in future? Thanks /BOB
0
by: Andre Baresel | last post by:
Hello together, just a year ago I was searching arround for a tool supporting refactoring for c++. I've seen implementations for java and was impressed how an IDE can help with such a feature....
2
by: Sachin Garg | last post by:
Hi, I was trying to find (like many others here) a tool for refactoring C++ code as I have lately been noticing that I spend most of my coding time doing refactoring and some refactoring which...
11
by: Master of C++ | last post by:
Hi, I am writing a simulation package in C++, and so far I've written about 8000 lines of code and have about 30 classes. I haven't used C++ exceptions so far (for various reasons). The only two...
6
by: Dean Ware | last post by:
Hi, I am part way through developing a C++ application. I am developing it on my own and using VC++ 6.0. I am now at the stage where I wish to start tidying up my code. I have lots of...
8
by: Frank Rizzo | last post by:
I keep hearing this term thrown around. What does it mean in the context of code? Can someone provide a definition and example using concrete code? Thanks.
15
by: Simon Cooke | last post by:
Does anyone know of any tools for refactoring header files? We're using a third party codebase at work, and pretty much every file includes a 50Mb precompiled header file. I'm looking for a tool...
3
Frinavale
by: Frinavale | last post by:
I have been researching the best approach to migrating a VB6 application into a VB.NET application. There is a lot of information out there but most of it recommends that you "train in the migration...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.