Editing File

akameswaran at gmail.com akameswaran at gmail.com
Wed Jul 12 11:08:31 EDT 2006


D wrote:
> Thanks, guys.  So overall, would it just be easier (and not too rigged)
> if any changes were made by just editing the text file?  I want to do
> this project the right way, but if it's going to be a big pain to
> implement the edit function, just modifying the text file directly
> isn't that big of a deal..
have you used pickle?  if the data is as simple as you say it is, you
will be able to read the pickle file.  2nd, it will be a lot less code
really.  You just load and unpickle the file into a variable.  After
any edit in the gui, repickle it to the same file.  You would have to
do the same if you edited the text file, except you would need a couple
of lines code to parse the string, etc.

check here for a simple example :
http://wiki.python.org/moin/UsingPickle

>
> akameswaran at gmail.com wrote:
> > D wrote:
> > > Hi, I currently have a Python app with a Tkinter GUI frontend that I
> > > use for system administration.  Everytime it launches, it reads a text
> > > file which contains info about each host I wish to monitor - each field
> > > (such as IP, hostname, etc.) is delimited by !!.  Now, I want to be
> > > able to edit host information from within the GUI - what would  be the
> > > best way to go about this?  Basically I just need to either edit the
> > > original host line, or write a new host line and delete the
> > > original..thanks!
> >
> > Might be overkill - but pickle the  data memeber that contains the
> > information.  If you use text instead of binary pickling it should
> > still be editable by hand.  for a single line of text it may be a bit
> > much - but it's still probably quicker than opening a file, parsing
> > etc.




More information about the Python-list mailing list