Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-16 Thread eryksun
On Sat, Feb 16, 2013 at 1:21 AM, Steven D'Aprano st...@pearwood.info wrote: while atexit can be set anywhere and isn't obvious. It's also somewhat risky, since you never know when some library you import will silently replace it with their own hook. Use try/finally if the task is clearer that

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-16 Thread Steven D'Aprano
On 16/02/13 19:32, eryksun wrote: On Sat, Feb 16, 2013 at 1:21 AM, Steven D'Apranost...@pearwood.info wrote: while atexit can be set anywhere and isn't obvious. It's also somewhat risky, since you never know when some library you import will silently replace it with their own hook. Use

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-15 Thread Alan Gauld
On 15/02/13 03:09, neubyr wrote: I do have a doubt regarding this - e.g. how would I implement this if my program/application is web based. For example, loading the text file during web server start and stop. For a long running process like a web server this is probably the wrong approach.

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-15 Thread Steven D'Aprano
On 15/02/13 16:38, eryksun wrote: On Thu, Feb 14, 2013 at 4:33 PM, Prasad, Ramit ramit.pra...@jpmorgan.com wrote: My knee jerk response is a try/finally block, but I am sure there are better ways. The atexit.register decorator hooks sys.exitfunc: http://docs.python.org/2/library/atexit I

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-14 Thread Prasad, Ramit
neubyr wrote: I am not sure how to save an object in memory to a file before exiting the program. Any examples or related documentation links would be really helpful. I am guessing it would be using some kind of before teardown method, but not sure about it. Any help? Look at the pickle or

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-14 Thread Dave Angel
On 02/14/2013 12:35 PM, Prasad, Ramit wrote: neubyr wrote: I am not sure how to save an object in memory to a file before exiting the program. Any examples or related documentation links would be really helpful. I am guessing it would be using some kind of before teardown method, but not sure

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-14 Thread Prasad, Ramit
Dave Angel wrote: On 02/14/2013 12:35 PM, Prasad, Ramit wrote: neubyr wrote: I am not sure how to save an object in memory to a file before exiting the program. Any examples or related documentation links would be really helpful. I am guessing it would be using some kind of before

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-14 Thread Dave Angel
On 02/14/2013 04:33 PM, Prasad, Ramit wrote: Dave Angel wrote: On 02/14/2013 12:35 PM, Prasad, Ramit wrote: neubyr wrote: I am not sure how to save an object in memory to a file before exiting the program. Any examples or related documentation links would be really helpful. I am guessing it

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-14 Thread neubyr
On Wed, Feb 13, 2013 at 1:55 PM, Alan Gauld alan.ga...@btinternet.comwrote: On 13/02/13 19:14, neubyr wrote: I am not sure how to save an object in memory to a file before exiting the program. Any examples or related documentation links would be really helpful. I am guessing it would be

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-14 Thread neubyr
On Thu, Feb 14, 2013 at 4:05 PM, Dave Angel da...@davea.name wrote: On 02/14/2013 04:33 PM, Prasad, Ramit wrote: Dave Angel wrote: On 02/14/2013 12:35 PM, Prasad, Ramit wrote: neubyr wrote: I am not sure how to save an object in memory to a file before exiting the program. Any examples

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-14 Thread eryksun
On Thu, Feb 14, 2013 at 4:33 PM, Prasad, Ramit ramit.pra...@jpmorgan.com wrote: My knee jerk response is a try/finally block, but I am sure there are better ways. The atexit.register decorator hooks sys.exitfunc: http://docs.python.org/2/library/atexit Registered atexit functions are run

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-13 Thread neubyr
On Tue, Feb 12, 2013 at 4:56 PM, Steven D'Aprano st...@pearwood.infowrote: On 13/02/13 04:32, neubyr wrote: I am not following your comment on opening books file twice in list_by_author method. I have opened it only once and then reading each line while checking for a regex match. Am I

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-13 Thread Alan Gauld
On 13/02/13 19:14, neubyr wrote: I am not sure how to save an object in memory to a file before exiting the program. Any examples or related documentation links would be really helpful. I am guessing it would be using some kind of before teardown method, but not sure about it. Any help? If

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-12 Thread eryksun
On Mon, Feb 11, 2013 at 8:56 PM, Alan Gauld alan.ga...@btinternet.com wrote: (One of the unfortunate features of Python's implementation of class methods is that you can call them from an instance which doesn't really make sense! IMHO) Smalltalk derives a metaclass for the class methods, in

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-12 Thread neubyr
On Mon, Feb 11, 2013 at 7:34 PM, Steven D'Aprano st...@pearwood.infowrote: On 12/02/13 10:16, Alan Gauld wrote: On 11/02/13 22:49, neubyr wrote: is right approach to implement 'list_by_author' function as a class method is typically used as an alternative constructor. Not at all that is

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-12 Thread Dave Angel
On 02/12/2013 12:32 PM, neubyr wrote: On Mon, Feb 11, 2013 at 7:34 PM, Steven D'Aprano st...@pearwood.infowrote: snip I am not following your comment on opening books file twice in list_by_author method. I have opened it only once and then reading each line while checking for a regex match.

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-12 Thread Steven D'Aprano
On 13/02/13 04:32, neubyr wrote: I am not following your comment on opening books file twice in list_by_author method. I have opened it only once and then reading each line while checking for a regex match. Am I missing something? You open the catalog file once to read the books in the first

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-11 Thread Alan Gauld
On 11/02/13 05:14, neubyr wrote: I have a text file with each line in following format: Book Name, Author Name, Genre, Publication Date I would like to perform following queries on this file: * Get all books written by an author * Remove all books of an author * Get information about a

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-11 Thread Dave Angel
On 02/11/2013 01:19 PM, Alan Gauld wrote: On 11/02/13 05:14, neubyr wrote: snip * How do I associate/relate Book and Author classes so that it will help me in getting information like 'get list of books written by an author'? Data attribute? I woudn't have a separate Author class but, if

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-11 Thread neubyr
Thank you for your inputs Dave. That's really helpful. Reply in-line below: On Sun, Feb 10, 2013 at 11:56 PM, Dave Angel da...@davea.name wrote: On 02/11/2013 12:14 AM, neubyr wrote: I have a text file with each line in following format: Book Name, Author Name, Genre, Publication Date I

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-11 Thread neubyr
On Mon, Feb 11, 2013 at 12:36 PM, Dave Angel da...@davea.name wrote: On 02/11/2013 01:19 PM, Alan Gauld wrote: On 11/02/13 05:14, neubyr wrote: snip * How do I associate/relate Book and Author classes so that it will help me in getting information like 'get list of books written by an

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-11 Thread Alan Gauld
On 11/02/13 22:49, neubyr wrote: is right approach to implement 'list_by_author' function as a class method is typically used as an alternative constructor. Not at all that is only one use case for class methods. A class method is *any* method that operates on the whole class of objects -

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-11 Thread neubyr
On Mon, Feb 11, 2013 at 5:16 PM, Alan Gauld alan.ga...@btinternet.comwrote: On 11/02/13 22:49, neubyr wrote: is right approach to implement 'list_by_author' function as a class method is typically used as an alternative constructor. Not at all that is only one use case for class methods.

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-11 Thread Steven D'Aprano
On 11/02/13 16:14, neubyr wrote: I have a text file with each line in following format: Book Name, Author Name, Genre, Publication Date I would like to perform following queries on this file: * Get all books written by an author * Remove all books of an author * Get information about a

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-11 Thread neubyr
On Mon, Feb 11, 2013 at 6:58 PM, Steven D'Aprano st...@pearwood.infowrote: On 11/02/13 16:14, neubyr wrote: I have a text file with each line in following format: Book Name, Author Name, Genre, Publication Date I would like to perform following queries on this file: * Get all books

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-11 Thread Steven D'Aprano
On 12/02/13 10:16, Alan Gauld wrote: On 11/02/13 22:49, neubyr wrote: is right approach to implement 'list_by_author' function as a class method is typically used as an alternative constructor. Not at all that is only one use case for class methods. A class method is *any* method that

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-11 Thread Alan Gauld
On 12/02/13 01:34, Steven D'Aprano wrote: If the class keeps a list of all instances, then the class method could walk the list and operate on each instance in turn. (But why would you do that?) Because its how classes work in some languages (like smalltalk). The class object represents all

[Tutor] associating two objects without ORM and processing a text file

2013-02-10 Thread neubyr
I have a text file with each line in following format: Book Name, Author Name, Genre, Publication Date I would like to perform following queries on this file: * Get all books written by an author * Remove all books of an author * Get information about a book (pretty print matching line!) *

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-10 Thread Mitya Sirenef
On 02/11/2013 12:14 AM, neubyr wrote: I have a text file with each line in following format: Book Name, Author Name, Genre, Publication Date I would like to perform following queries on this file: * Get all books written by an author * Remove all books of an author * Get information

Re: [Tutor] associating two objects without ORM and processing a text file

2013-02-10 Thread Dave Angel
On 02/11/2013 12:14 AM, neubyr wrote: I have a text file with each line in following format: Book Name, Author Name, Genre, Publication Date I would like to perform following queries on this file: * Get all books written by an author * Remove all books of an author * Get information