<div><br></div><div>Thank you for your inputs Dave. That's really helpful. Reply in-line below: </div><br><br><div class="gmail_quote">On Sun, Feb 10, 2013 at 11:56 PM, Dave Angel <span dir="ltr"><<a href="mailto:davea@davea.name" target="_blank">davea@davea.name</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 02/11/2013 12:14 AM, neubyr wrote:<br>
</div><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I have a text file with each line in following format:<br>
<br>
Book Name, Author Name, Genre, Publication Date<br>
<br>
I would like to perform following queries on this file:<br>
  * Get all books written by an author<br>
  * Remove all books of an author<br>
  * Get information about a book (pretty print matching line!)<br>
  * Get books of particular genre<br>
<br>
Also, I would like to add and delete entries in this file. I am not<br>
planning to use any database for this purpose and would like to get better<br>
grasp on file parsing and classes/OOP.<br>
</blockquote>
<br></div>
I take it from this that this is a class assignment, and that neither speed nor enormous data capacity nor concurrent operation is a requirement.  But your professor may have other requirements that you haven't told us about.</blockquote>
<div><br></div><div>Not a class assignment, just picked up this problem as a learning exercise. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
<br>
<br>
I need some help in creating classes<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
and following are my initial thoughts:<br>
<br>
# Create a class for Book object<br>
class Book:<br>
   atributes: name, author_name, genre, publication-date<br>
<br>
# Create<br>
Author:<br>
  attribute(s): name<br>
</blockquote>
<br></div>
Is this in order to save space, since each Book instance can then have a reference to an Author object, rather than a reference to a string containing the Author's name.<br>
<br>
If you deem this class useful, then don't you also want one for Genre ?</blockquote><div><br></div><div><br></div><div>Hmm.. I didn't think about saving space by reference an object. I created separate class thinking from database/ORM perspective. I am not planning to use it right now anyway, but if I was creating a non-trivial application with database models then I would have had Books tables, Authors tables etc.. </div>
<div><br></div><div>I think I don't need it here though.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
# Create class for reading and writing to the file<br>
class Booksfile:<br>
   methods: ??<br>
</blockquote>
<br></div>
Why ?  Are you transliterating this from Java ?</blockquote><div><br></div><div><br></div><div>Scrapped that class - adding add/list/delete methods in Book class. Thanks for pointing it out. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
* How do I associate/relate Book and Author classes so that it will help me<br>
in getting information like 'get list of books written by an author'? Data<br>
attribute?<br>
</blockquote>
<br></div>
If performance doesn't matter, then create one list of Book instances, and search it for whichever characteristics you like.<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
* Should I create a new Booksfile object for reading, writing and deleting<br>
entries in the file OR add corresponding methods to the book object itself?<br>
</blockquote>
<br></div>
Neither, a pair of regular functions will do fine.  One that loads when you start the program, and another that saves the file when you exit. If you really expect to update the file incrementally, deleting entries in it, then think hard about your decision to roll your own database.  A text file isn't random access.<div class="im">
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I am not planning to use SQLite or any database and would like to use text<br>
file only. Appreciate any help on designing such application.<br>
<br>
<br>
</blockquote>
<br></div>
The real question is where you might proceed after meeting these first requirements.  For example, if you expect the list to grow to a few hundred million entries, then you'll need to be very careful about layout.  And starting and exiting the program would be very slow, since you can do nothing till all the data has been loaded in and converted to objects.<br>

<br>
Or perhaps you'll want to have another file with additional author data, associated with the first by carefully spelling the author's name the same in all cases.  In that case, having a separate Author class makes great sense.  So if you expect to grow in that direction, then you should create the class now, even though it has only one attribute.<span class="HOEnZb"><font color="#888888"><br>

<br>
<br>
-- <br>
DaveA</font></span><div class="HOEnZb"><div class="h5"><br>
______________________________<u></u>_________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org" target="_blank">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/tutor</a><br>
</div></div></blockquote></div><br><div><br></div><div>- N</div>