473,324 Members | 2,257 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,324 software developers and data experts.

Updating file objects automatically


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. <go***@ieee.org>

Jul 18 '05 #1
3 1174
On Thu, 2004-12-30 at 11:15, Jorge Luiz Godoy Filho wrote:
Is there something I can do to change all instances of the Search class?
Are there different alternatives for such a "thing"?


I couldn't really catch your explanation, but mention of changing all
instances of a class suggests that you may be in a situation where you
need to modify the class, not its instances. There are two methods I use
when I have to change things across all instances:

def A(object):
"A class that provides a variable shared by all instances,
and a method of changing it using a normal method and, for
example's sake, a class method."""

class_level_variable = True

def __init__(self):
pass

def getvalue(self):
return self.class_level_variable

def setvalue(self, newval):
self.__class__.class_level_variable = newval

def setvaluecls(cls, newval):
cls.class_level_variable = newval
setvaluecls = classmethod(setvaluecls)

sevaluecls and setvalue look the same to callers calling them on an
instance of the class.

I have no idea if that's actually appropriate for your needs, it's just
a stab in the dark, but perhaps it might be.

--
Craig Ringer

Jul 18 '05 #2
Craig Ringer, Quinta 30 Dezembro 2004 06:27, wrote:
I couldn't really catch your explanation, but mention of changing all
instances of a class suggests that you may be in a situation where you
need to modify the class, not its instances. There are two methods I use
when I have to change things across all instances:
I'm sorry. It was late here and I've been coding this and other things for
near 14h in a row... I think that even I wouldn't understand that if I
weren't working with it :-)
I have no idea if that's actually appropriate for your needs, it's just
a stab in the dark, but perhaps it might be.


It helps, yes. Putting the object on the class instead of on an instance of
it might (I'm 99.9% sure) solve the problem. (I have already done that for
other object that is shared, but I didn't remember doing that for this)
Thank you. You helped a lot to make me "see" it :-)

--
Godoy. <go***@ieee.org>

Jul 18 '05 #3
Jorge Luiz Godoy Filho, Quinta 30 Dezembro 2004 09:20, wrote:
It helps, yes. Putting the object on the class instead of on an instance
of
it might (I'm 99.9% sure) solve the problem. (I have already done that
for other object that is shared, but I didn't remember doing that for
this)


And, as expected, it worked. Thanks for the help, Craig.

--
Godoy. <go***@ieee.org>

Jul 18 '05 #4

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

Similar topics

6
by: Hennie de Nooijer | last post by:
Hi, Currently we're a building a metadatadriven datawarehouse in SQL Server 2000. We're investigating the possibility of the updating tables with enormeous number of updates and insert and the...
1
by: Ryan Malone | last post by:
Hi Ive got a custom collection class (inherits ArrayList) that contains a collection of Customer Objects. My Question is, if I populate that class with a dataset and I make modifications to the...
3
by: | last post by:
Hello, I have created an ASP.NET 2.0 application that utilized a Gridview Control to display and update/delete data. The problem I am having is that the gridview control is displaying the data...
0
by: OmniTech via .NET 247 | last post by:
I am having trouble updating lines in a richtextbox. The rtb.lines.setvalue("text", linenumber) runs, but does not update the control in the form. The code follows... This apps automatically...
1
by: Hone | last post by:
I've built a core set of assemblies that are shared by multiple ASP.NET web applications on a production server. These assemblies are updated quite frequently, as I am continually adding to and...
5
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
4
by: somanyusernamesaretakenal | last post by:
What I am trying to achieve: Basically I have generated a report in access. This report needs to be updated using excel. (Updating the new data, not changing existing data) What I did was I...
16
by: Stevo | last post by:
I'm guessing this is a laughably obvious answer to many here, but it's not to me (and I don't have a server or any knowledge of PHP to be able to try it). It's not strictly a PHP question, but...
7
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.