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

XML File -- dictionary edit/search

-b
I am trying to put together a python program that will be able to ask
for a word and its definition, then save that information into an xml
file for reference. I am not down right set on the file being in xml
format, but xml is the first thing that comes to mind, since I do not
want to use a MySQL database. I think xml will be easy to search and
return a word's definition--another reason why xml comes to mind first
after MySQL databases. Please, if you have any suggestions to what
python-xml libraries I might use to program this small app with, then
by all means voice your thoughts. Thank you very much for your time.

Aug 28 '07 #1
2 1470
On Aug 28, 6:15 am, -b <bradfo...@gmail.comwrote:
I am trying to put together a python program that will be able to ask
for a word and its definition, then save that information into an xml
file for reference. I am not down right set on the file being in xml
format, but xml is the first thing that comes to mind, since I do not
want to use a MySQL database. I think xml will be easy to search and
return a word's definition--another reason why xml comes to mind first
after MySQL databases. Please, if you have any suggestions to what
python-xml libraries I might use to program this small app with, then
by all means voice your thoughts. Thank you very much for your time.
A simple yaml file might just do the trick.
Your yaml file shall look like the following:

Word-def.yaml
word1: word1's definition
word2: word2's definition
...
...
...
Use pyyaml to handle yaml files.
--------
import yaml
worddefs = yaml.load( open( "word-def.yaml", "r" ).read() )
print worddefs
--------

worddefs will be a dictionary of words (with definitions as values, of
course). You cannot get a better representation.
To add a definition, you can as well add keys to the worddefs
dictionary and use "dump" method to write to the yaml file. Or you
could just write to the file directly (as the format is simple in this
case). But I suggest former.

Did this solve your problem?
-Brevity is the soul of wit.
Nagarajan.

Aug 28 '07 #2
On 8/28/07, Nagarajan <na****@gmail.comwrote:
A simple yaml file might just do the trick.
Your yaml file shall look like the following:

Word-def.yaml
word1: word1's definition
word2: word2's definition
..
..
..
Use pyyaml to handle yaml files.
--------
import yaml
worddefs = yaml.load( open( "word-def.yaml", "r" ).read() )
print worddefs
--------

I agree with the suggestion for yaml!
Since definitions are to be inputed by the users, it could be better
to use yaml.safe_load() to reduce the risks...

francesco
Aug 28 '07 #3

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

Similar topics

4
by: Fuzzyman | last post by:
There have been a couple of config file 'systems' announced recently, that focus on building more powerful and complex configuration files. ConfigObj is a module to enable you to much more *simply*...
7
by: Lowell Kirsh | last post by:
I have a script which I use to find all duplicates of files within a given directory and all its subdirectories. It seems like it's longer than it needs to be but I can't figure out how to shorten...
20
by: Brian Burgess | last post by:
Hi all, Anyone know if this is possible? If so, on which page would the cookie be? .. On the page calling a function defined in the include file? thanks in advance.. -BB
1
by: Djam | last post by:
Hi, I need your help to build a dictionary on mysal database to have an efficient keyword search engine. Thanks :-) Djam
12
by: teoryn | last post by:
I've been spending today learning python and as an exercise I've ported a program I wrote in java that unscrambles a word. Before describing the problem, here's the code: *--beginning of file--*...
1
by: j | last post by:
Hi, I've been trying to do line/character counts on documents that are being uploaded. As well as the "counting" I also have to remove certain sections from the file. So, firstly I was working...
3
by: galadhad | last post by:
Okay, here goes. I'm new to Python (and relatively new to programming/scripting in general - I understand basics, but complex concepts are still beyond my limited knowledge). I am working on a...
0
by: moconno5 | last post by:
Hello again, I am still working on my same project and have run into another little problem. I have created a flat file with data from a server, each line looks like this: BLAT Search Results ...
2
by: Shriphani | last post by:
Hello all, I am trying to create a script that looks at specific strings in a file like: msgid "I am a disco dancer." and compares the part in quotes to the keys in a dictionary, finds the...
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: 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
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.