Updating file objects automatically
Jorge Luiz Godoy Filho
godoy at ieee.org
Wed Dec 29 22:15:16 EST 2004
Hi,
I have the following situation where I only open the file on the Search
class (where it should be used more often) and I want to reutilize search
methods to find the exact location of where the changes should occur. In
code terms, I have something like:
===============================================================================
class Search(object):
def __init__(self, fileToRead):
self.fileToRead = open(fileToRead)
(definition of several search methods)
class Writer(Search):
def __init__(self, fileToRead, fileToWrite=None):
super(Writer, self).__init__(fileToRead)
super(Search, self).__init__(fileToRead)
(definition of write methods)
def exampleMethod(self):
place = self.searchSomeParticularCondition() # method from Search
place.change.values('old', 'new')
self.fileToRead.write(all_things) # object from Search
search = Search('someFile')
print "Information:", search.something()
change = Writer('someFile')
change.exampleMethod()
# here if I do another search, with "search.something('id')" I get the old
# value ...
print search.something('id') # prints old data
# ... I want the new one, so I reassign the search instance:
search = Search('someFile')
print search.something('id') # prints new data
===============================================================================
Is there something I can do to change all instances of the Search class?
Are there different alternatives for such a "thing"?
Thanks in advance,
--
Godoy. <godoy at ieee.org>
More information about the Python-list
mailing list