[Tutor] About classes and databases
Hallo all! Long time since I last dabbled in python :-( I was thinking of a possible solution to a problem I have: I could make a Class which contains, amongst other things, a couple of datetime.datetime objects. The class also will have to contain an element taken from a Tuple and various elements taken from a series of dictionaries. First problem: when creating each instance of the class I have to pass it the information necessary to create the correct datetime objects - how would I do this? Second problem: I would find myself to be working with something in the order of 500 instances of this class contemporaneously, how do I create them "automatically" from a series of data and once I've created them how do I grab the correct one when I need it? Or do you think my approach is all wrong, and it would be better for me not to use classes at all and to store the data in a database? But is it possible to store datetime objects and dictionaries in a database? Thanks for any comments. Michele ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Dictionaries versus classes
Hi all, after a longish pause I've taken up my pet python project again (must say that the decisive factor was the discovery of how easy it is to code the GUI with QT designer and pyqt). The core of the problem I'm facing, however, is not the GUI, it is conceptual. In the end my program will have to create a printed representation of a certain number of "things" which are characterized by each having a time attribute (moment when they start, moment when they end); each "thing" will have to be filled in by a certain content, chosen from a user defined list of possibilities; however each thing will also have to have a series of other attributes ... which will change during the process of assigning content (for instance: once content 'A' is assigned to foo, bar immediately following may well change some attribute ... BUT the effect of content A on foo and bar may well be different from the effect of content B. Naturally if content A is present in a certain thing it can't be present in a contemporaneaous one... sounds a mess ? It is ... also, the rules by which A and B influence the content will have to be modifiable by the user.) At the moment I am collecting user input into a dictionary of lists. The question is: do you believe it would be better to code a series of functions to interact with my dictionary and keep data, attributes etc. in lists therein, or would it be more efficient to create an appointment class, create a new instance of each class for each appointment, and eventually store each instance in a dictionary ? Where could I read up something about relative advantages / disadvantages of each approach ? Thanks for any hints. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Graph theory
Hallo all! It's a long time since I last wrote here. I have been thinking about a problem, and I'm wondering what the best approach for a pythonic solution would be. The actual problem is very complex, but the very first step in the solution would be to come up with a simple way of handling graphs. For example, given that: Definition 1: A network is a figure made up of points (vertices) connected by non-intersecting curves (arcs). Definition 2: A vertex is called odd if it has an odd number of arcs leading to it, other wise it is called even. Definition 3: An Euler path is a continuous path that passes through every arc once and only once. Given the following theorems: Theorem 1: If a network has more than two odd vertices, it does not have an Euler path. Theorem 2: If a network has two or zero odd vertices, it has at least one Euler path. In particular, if a network has exactly two odd vertices, then its Euler paths can only start on one of the odd vertices, and end on the other -- (Euler circuit). Which would be the best approach for representing figures such as those found here ( http://mathforum.org/isaac/problems/bridges2.html ) such that one could elaborate a script capable of finding and describing paths in the figure? For example, Euler paths. I realize that it is quite feasable to do this, but would take a lot of coding - vertices and arcs could be represented as instances of respective classes, and so forth. But is there an elegant and simple solution already out there? -- Michele Alzetta ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor